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;
}
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;
}
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;
}
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;
});
}
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;
}
Aggregations