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