Search in sources :

Example 6 with PhotoView

use of com.github.chrisbanes.photoview.PhotoView 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 7 with PhotoView

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

the class BigImagePagerActivity method onCreate.

@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_big_image_pager);
    // 延迟动画
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        postponeEnterTransition();
    }
    mEnterIndex = getIntent().getIntExtra(KEY_ENTER_INDEX, 0);
    mImageUrls = getIntent().getStringArrayListExtra(KEY_IMAGE_URLS);
    if (mImageUrls == null) {
        return;
    }
    mViewPager = (ViewPager) findViewById(R.id.viewPager);
    mViewPager.setOffscreenPageLimit(4);
    mPhotoViewMap = new SparseArray<>();
    mPagerAdapter = new PagerAdapter() {

        @Override
        public int getCount() {
            return mImageUrls.size();
        }

        @Override
        public boolean isViewFromObject(@NonNull View view, @NonNull Object object) {
            return view == object;
        }

        @NonNull
        @Override
        public Object instantiateItem(@NonNull ViewGroup container, int position) {
            PhotoView photoView = new PhotoView(container.getContext());
            // imageView.setLayoutParams(new ViewGroup.LayoutParams(
            // ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
            String imageUrl = mImageUrls.get(position);
            Glide.with(BigImagePagerActivity.this).load(imageUrl).into(photoView);
            if (mPhotoViewMap.get(position) != null) {
                mPhotoViewMap.remove(position);
            }
            mPhotoViewMap.put(position, photoView);
            photoView.setOnViewTapListener((view, x, y) -> {
                onBackPressed();
            });
            photoView.setOnLongClickListener(v -> {
                PhotoView pv = (PhotoView) v;
                if (pv.getDrawable() == null) {
                    return false;
                }
                View view = getLayoutInflater().inflate(R.layout.dialog_save_image, null);
                AlertDialog alertDialog = new AlertDialog.Builder(BigImagePagerActivity.this).setView(view).create();
                TextView textView = (TextView) view.findViewById(R.id.save_image_tv);
                textView.setOnClickListener(v1 -> {
                    saveImage(pv.getDrawable(), imageUrl);
                    alertDialog.dismiss();
                });
                alertDialog.show();
                return true;
            });
            if (position == mEnterIndex) {
                ViewCompat.setTransitionName(photoView, mImageUrls.get(position));
                setStartPostTransition(photoView);
            }
            container.addView(photoView);
            return photoView;
        }

        @Override
        public void destroyItem(@NonNull ViewGroup container, int position, @NonNull Object object) {
            if (mPhotoViewMap.get(position) != null) {
                mPhotoViewMap.remove(position);
            }
            container.removeView((View) object);
        }
    };
    mViewPager.setAdapter(mPagerAdapter);
    mViewPager.setCurrentItem(mEnterIndex);
}
Also used : Bundle(android.os.Bundle) ImageUtil(top.wefor.now.utils.ImageUtil) RxPermissions(com.tbruyelle.rxpermissions2.RxPermissions) Environment(android.os.Environment) ViewPager(android.support.v4.view.ViewPager) Intent(android.content.Intent) NonNull(android.support.annotation.NonNull) Drawable(android.graphics.drawable.Drawable) ArrayList(java.util.ArrayList) Manifest(android.Manifest) Map(java.util.Map) View(android.view.View) ViewCompat(android.support.v4.view.ViewCompat) Build(android.os.Build) SharedElementCallback(android.support.v4.app.SharedElementCallback) R(top.wefor.now.R) PhotoView(com.github.chrisbanes.photoview.PhotoView) ActivityOptionsCompat(android.support.v4.app.ActivityOptionsCompat) PagerAdapter(android.support.v4.view.PagerAdapter) ActivityCompat(android.support.v4.app.ActivityCompat) AppCompatActivity(android.support.v7.app.AppCompatActivity) ViewGroup(android.view.ViewGroup) SparseArray(android.util.SparseArray) List(java.util.List) App(top.wefor.now.App) AlertDialog(android.support.v7.app.AlertDialog) TextView(android.widget.TextView) Glide(com.bumptech.glide.Glide) ViewTreeObserver(android.view.ViewTreeObserver) BaseCompatActivity(top.wefor.now.ui.BaseCompatActivity) Nullable(android.support.annotation.Nullable) AlertDialog(android.support.v7.app.AlertDialog) ViewGroup(android.view.ViewGroup) View(android.view.View) PhotoView(com.github.chrisbanes.photoview.PhotoView) TextView(android.widget.TextView) PagerAdapter(android.support.v4.view.PagerAdapter) PhotoView(com.github.chrisbanes.photoview.PhotoView) NonNull(android.support.annotation.NonNull) TextView(android.widget.TextView)

Example 8 with PhotoView

use of com.github.chrisbanes.photoview.PhotoView in project open-event-android by fossasia.

the class ZoomableImageDialogFragment method onCreateView.

@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.fragment_zoomable_image, container, false);
    unbinder = ButterKnife.bind(this, view);
    String imageUri = this.getArguments().getString(ConstantStrings.IMAGE_ZOOM_KEY);
    Drawable placeholder = VectorDrawableCompat.create(getActivity().getResources(), R.drawable.ic_placeholder_24dp, null);
    if (imageUri != null) {
        Picasso.with(getContext()).load(Uri.parse(imageUri)).placeholder(placeholder).into(photoView);
    }
    return view;
}
Also used : Drawable(android.graphics.drawable.Drawable) PhotoView(com.github.chrisbanes.photoview.PhotoView) BindView(butterknife.BindView) View(android.view.View) Nullable(android.support.annotation.Nullable)

Example 9 with PhotoView

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

Example 10 with PhotoView

use of com.github.chrisbanes.photoview.PhotoView in project CustomViews by AndroidStudy233.

the class ImagePreviewAdapter method instantiateItem.

@Override
public Object instantiateItem(ViewGroup container, int position) {
    View view = LayoutInflater.from(context).inflate(R.layout.item_photoview, container, false);
    final ProgressBar pb = view.findViewById(R.id.pb);
    final PhotoView imageView = view.findViewById(R.id.pv);
    imageView.setOnPhotoTapListener(this);
    String info = this.imageInfo.get(position);
    if (info == null || "".equals(info) || info.endsWith("null")) {
        imageView.setImageResource(R.drawable.pic_deauft);
    } else {
        // RequestOptions requestOptions = new RequestOptions()
        // .dontAnimate()
        // .placeholder(R.drawable.ad_mall_nopicture) //占位符 也就是加载中的图片,可放个gif
        // .error(R.drawable.icon_me_default_avatar); //失败图片;
        GlideUtils.loadImg(context, info, imageView);
    }
    container.addView(view);
    return view;
}
Also used : PhotoView(com.github.chrisbanes.photoview.PhotoView) PhotoView(com.github.chrisbanes.photoview.PhotoView) ImageView(android.widget.ImageView) View(android.view.View) ProgressBar(android.widget.ProgressBar)

Aggregations

PhotoView (com.github.chrisbanes.photoview.PhotoView)14 View (android.view.View)11 ImageView (android.widget.ImageView)6 Drawable (android.graphics.drawable.Drawable)5 Bundle (android.os.Bundle)4 NonNull (android.support.annotation.NonNull)3 Nullable (android.support.annotation.Nullable)3 ViewGroup (android.view.ViewGroup)3 PhotoViewAttacher (com.github.chrisbanes.photoview.PhotoViewAttacher)3 Bitmap (android.graphics.Bitmap)2 PagerAdapter (android.support.v4.view.PagerAdapter)2 MotionEvent (android.view.MotionEvent)2 ProgressBar (android.widget.ProgressBar)2 TextView (android.widget.TextView)2 BindView (butterknife.BindView)2 TouchImageView (com.dante.custom.TouchImageView)2 OnOutsidePhotoTapListener (com.github.chrisbanes.photoview.OnOutsidePhotoTapListener)2 OnPhotoTapListener (com.github.chrisbanes.photoview.OnPhotoTapListener)2 OnSingleFlingListener (com.github.chrisbanes.photoview.OnSingleFlingListener)2 Callback (com.squareup.picasso.Callback)2