Search in sources :

Example 1 with PhotoViewAttacher

use of com.github.chrisbanes.photoview.PhotoViewAttacher in project Palm300Heroes by nicolite.

the class ShowImageAdapter method instantiateItem.

@NonNull
@Override
public Object instantiateItem(@NonNull ViewGroup container, int position) {
    final PhotoView imageView = new PhotoView(context);
    final PhotoViewAttacher attacher = new PhotoViewAttacher(imageView);
    Glide.with(context).load(images.get(position)).placeholder(R.drawable.img_loading).error(R.drawable.img_error).skipMemoryCache(true).crossFade().centerCrop().into(new SimpleTarget<GlideDrawable>() {

        @Override
        public void onLoadStarted(Drawable placeholder) {
            super.onLoadStarted(placeholder);
            imageView.setImageDrawable(placeholder);
            attacher.update();
        }

        @Override
        public void onResourceReady(GlideDrawable resource, GlideAnimation<? super GlideDrawable> glideAnimation) {
            imageView.setImageDrawable(resource);
            attacher.update();
        }

        @Override
        public void onLoadFailed(Exception e, Drawable errorDrawable) {
            super.onLoadFailed(e, errorDrawable);
            imageView.setImageDrawable(errorDrawable);
            attacher.update();
        }
    });
    container.addView(imageView);
    return imageView;
}
Also used : PhotoView(com.github.chrisbanes.photoview.PhotoView) GlideDrawable(com.bumptech.glide.load.resource.drawable.GlideDrawable) Drawable(android.graphics.drawable.Drawable) PhotoViewAttacher(com.github.chrisbanes.photoview.PhotoViewAttacher) GlideDrawable(com.bumptech.glide.load.resource.drawable.GlideDrawable) NonNull(android.support.annotation.NonNull)

Example 2 with PhotoViewAttacher

use of com.github.chrisbanes.photoview.PhotoViewAttacher 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)

Example 3 with PhotoViewAttacher

use of com.github.chrisbanes.photoview.PhotoViewAttacher in project keleFanfou by kelefun.

the class ImagePreviewFragment method onCreateView.

@Nullable
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View contentView = inflater.inflate(R.layout.fragment_image_preview, container, false);
    final ImageView imageView = (ImageView) contentView.findViewById(R.id.preview_image);
    final PhotoViewAttacher mAttacher = new PhotoViewAttacher(imageView);
    Glide.with(container.getContext()).load(new File(getArguments().getString(PATH))).asBitmap().into(new SimpleTarget<Bitmap>(480, 800) {

        @Override
        public void onResourceReady(Bitmap resource, GlideAnimation<? super Bitmap> glideAnimation) {
            imageView.setImageBitmap(resource);
            mAttacher.update();
        }
    });
    mAttacher.setOnPhotoTapListener(new OnPhotoTapListener() {

        @Override
        public void onPhotoTap(ImageView view, float x, float y) {
            ImagePreviewActivity activity = (ImagePreviewActivity) getActivity();
            activity.switchBarVisibility();
        }
    });
    return contentView;
}
Also used : Bitmap(android.graphics.Bitmap) OnPhotoTapListener(com.github.chrisbanes.photoview.OnPhotoTapListener) ImageView(android.widget.ImageView) ImageView(android.widget.ImageView) View(android.view.View) PhotoViewAttacher(com.github.chrisbanes.photoview.PhotoViewAttacher) File(java.io.File) Nullable(android.support.annotation.Nullable)

Example 4 with PhotoViewAttacher

use of com.github.chrisbanes.photoview.PhotoViewAttacher in project Now by XunMengWinter.

the class BigImageActivity method setupPhotoAttacher.

private void setupPhotoAttacher() {
    mPhotoViewAttacher = new PhotoViewAttacher(mSimpleDraweeView);
    mPhotoViewAttacher.setOnViewTapListener((view, v, v1) -> {
        onBackPressed();
    });
    mPhotoViewAttacher.setOnLongClickListener(v -> {
        if (mImageDrawable == null) {
            return false;
        }
        View view = getLayoutInflater().inflate(R.layout.dialog_save_image, null);
        AlertDialog alertDialog = new AlertDialog.Builder(BigImageActivity.this).setView(view).create();
        TextView textView = (TextView) view.findViewById(R.id.save_image_tv);
        textView.setOnClickListener(v1 -> {
            saveImage();
            alertDialog.dismiss();
        });
        alertDialog.show();
        return true;
    });
}
Also used : AlertDialog(android.support.v7.app.AlertDialog) TextView(android.widget.TextView) PhotoViewAttacher(com.github.chrisbanes.photoview.PhotoViewAttacher) PhotoView(com.github.chrisbanes.photoview.PhotoView) TextView(android.widget.TextView) View(android.view.View)

Example 5 with PhotoViewAttacher

use of com.github.chrisbanes.photoview.PhotoViewAttacher in project Tusky by tuskyapp.

the class ViewMediaFragment method onCreateView.

@Override
public View onCreateView(LayoutInflater inflater, final ViewGroup container, Bundle savedInstanceState) {
    rootView = inflater.inflate(R.layout.fragment_view_media, container, false);
    photoView = rootView.findViewById(R.id.view_media_image);
    final Bundle arguments = getArguments();
    final 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) {
            photoActionsListener.onDismiss();
        }
    });
    attacher.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            photoActionsListener.onPhotoTap();
        }
    });
    /* 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)) {
                photoActionsListener.onDismiss();
                return true;
            }
            return false;
        }
    });
    ViewCompat.setTransitionName(photoView, url);
    // If we are the view to be shown initially...
    if (arguments.getBoolean(ARG_START_POSTPONED_TRANSITION)) {
        // Try to load image from disk.
        Picasso.with(getContext()).load(url).noFade().networkPolicy(NetworkPolicy.OFFLINE).into(photoView, new Callback() {

            @Override
            public void onSuccess() {
                // if we loaded image from disk, we should check that view is attached.
                if (ViewCompat.isAttachedToWindow(photoView)) {
                    finishLoadingSuccessfully();
                } else {
                    // if view is not attached yet, wait for an attachment and
                    // start transition when it's finally ready.
                    photoView.addOnAttachStateChangeListener(new View.OnAttachStateChangeListener() {

                        @Override
                        public void onViewAttachedToWindow(View v) {
                            finishLoadingSuccessfully();
                            photoView.removeOnAttachStateChangeListener(this);
                        }

                        @Override
                        public void onViewDetachedFromWindow(View v) {
                        }
                    });
                }
            }

            @Override
            public void onError() {
                // if there's no image in cache, load from network and start transition
                // immediately.
                photoActionsListener.onBringUp();
                loadImageFromNetwork(url, photoView);
            }
        });
    } else {
        // if we're not initial page, don't bother.
        loadImageFromNetwork(url, photoView);
    }
    return rootView;
}
Also used : Bundle(android.os.Bundle) PhotoViewAttacher(com.github.chrisbanes.photoview.PhotoViewAttacher) PhotoView(com.github.chrisbanes.photoview.PhotoView) ImageView(android.widget.ImageView) View(android.view.View) MotionEvent(android.view.MotionEvent) Callback(com.squareup.picasso.Callback) OnSingleFlingListener(com.github.chrisbanes.photoview.OnSingleFlingListener) ImageView(android.widget.ImageView) OnOutsidePhotoTapListener(com.github.chrisbanes.photoview.OnOutsidePhotoTapListener)

Aggregations

PhotoViewAttacher (com.github.chrisbanes.photoview.PhotoViewAttacher)6 View (android.view.View)4 PhotoView (com.github.chrisbanes.photoview.PhotoView)4 ImageView (android.widget.ImageView)3 Bundle (android.os.Bundle)2 MotionEvent (android.view.MotionEvent)2 GlideDrawable (com.bumptech.glide.load.resource.drawable.GlideDrawable)2 OnOutsidePhotoTapListener (com.github.chrisbanes.photoview.OnOutsidePhotoTapListener)2 OnSingleFlingListener (com.github.chrisbanes.photoview.OnSingleFlingListener)2 Callback (com.squareup.picasso.Callback)2 File (java.io.File)2 ActivityNotFoundException (android.content.ActivityNotFoundException)1 Bitmap (android.graphics.Bitmap)1 BitmapFactory (android.graphics.BitmapFactory)1 Drawable (android.graphics.drawable.Drawable)1 NonNull (android.support.annotation.NonNull)1 Nullable (android.support.annotation.Nullable)1 AlertDialog (android.support.v7.app.AlertDialog)1 TextView (android.widget.TextView)1 BindView (butterknife.BindView)1