Search in sources :

Example 1 with OnSingleFlingListener

use of com.github.chrisbanes.photoview.OnSingleFlingListener in project Tusky by Vavassor.

the class ViewMediaFragment method onCreateView.

@Override
public View onCreateView(LayoutInflater inflater, final ViewGroup container, Bundle savedInstanceState) {
    final View rootView = inflater.inflate(R.layout.fragment_view_media, container, false);
    ButterKnife.bind(this, rootView);
    Bundle arguments = getArguments();
    String url = arguments.getString("url");
    attacher = new PhotoViewAttacher(photoView);
    // Clicking outside the photo closes the viewer.
    attacher.setOnOutsidePhotoTapListener(new OnOutsidePhotoTapListener() {

        @Override
        public void onOutsidePhotoTap(ImageView imageView) {
            dismiss();
        }
    });
    /* A vertical swipe motion also closes the viewer. This is especially useful when the photo
         * mostly fills the screen so clicking outside is difficult. */
    attacher.setOnSingleFlingListener(new OnSingleFlingListener() {

        @Override
        public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
            if (Math.abs(velocityY) > Math.abs(velocityX)) {
                dismiss();
                return true;
            }
            return false;
        }
    });
    toolbar.setNavigationOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            dismiss();
        }
    });
    Picasso.with(getContext()).load(url).into(photoView, new Callback() {

        @Override
        public void onSuccess() {
            rootView.findViewById(R.id.view_media_progress).setVisibility(View.GONE);
            toolbar.setOnMenuItemClickListener(ViewMediaFragment.this);
            toolbar.inflateMenu(R.menu.view_media_tooblar);
            attacher.update();
        }

        @Override
        public void onError() {
        }
    });
    return rootView;
}
Also used : Callback(com.squareup.picasso.Callback) Bundle(android.os.Bundle) OnSingleFlingListener(com.github.chrisbanes.photoview.OnSingleFlingListener) ImageView(android.widget.ImageView) ImageView(android.widget.ImageView) BindView(butterknife.BindView) View(android.view.View) PhotoView(com.github.chrisbanes.photoview.PhotoView) PhotoViewAttacher(com.github.chrisbanes.photoview.PhotoViewAttacher) OnOutsidePhotoTapListener(com.github.chrisbanes.photoview.OnOutsidePhotoTapListener) MotionEvent(android.view.MotionEvent)

Aggregations

Bundle (android.os.Bundle)1 MotionEvent (android.view.MotionEvent)1 View (android.view.View)1 ImageView (android.widget.ImageView)1 BindView (butterknife.BindView)1 OnOutsidePhotoTapListener (com.github.chrisbanes.photoview.OnOutsidePhotoTapListener)1 OnSingleFlingListener (com.github.chrisbanes.photoview.OnSingleFlingListener)1 PhotoView (com.github.chrisbanes.photoview.PhotoView)1 PhotoViewAttacher (com.github.chrisbanes.photoview.PhotoViewAttacher)1 Callback (com.squareup.picasso.Callback)1