use of uk.co.senab.photoview.PhotoView in project boon by Wing-Li.
the class ImageAdapter method instantiateItem.
/**
* 加载View
*/
@Override
public Object instantiateItem(ViewGroup container, int position) {
final String imgUrl = imgs.get(position);
PhotoView photoView = new PhotoView(mContext);
photoView.setAdjustViewBounds(true);
ImgUtils.load(mContext, imgUrl, photoView);
photoView.setOnLongClickListener(new View.OnLongClickListener() {
@Override
public boolean onLongClick(View v) {
if (TextUtils.isEmpty(imgUrl)) {
Toast.makeText(mContext.getApplicationContext(), R.string.img_err, Toast.LENGTH_SHORT).show();
return false;
}
//
new AlertDialog.Builder(mContext).setTitle(mContext.getString(R.string.image_save)).setMessage(//
mContext.getString(R.string.image_save_msg)).setNegativeButton(mContext.getString(R.string.save), new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
ImgUtils.downloadImg(mContext, imgUrl, new ImgUtils.DownloadImage() {
@Override
public void downloadImage(File imgFile) {
if (imgFile != null) {
String path = MyApp.getAppPath();
String imgName = "boon_" + System.currentTimeMillis() + ".jpg";
File file = new File(path, imgName);
// 移动下载的图片到 目标路径
boolean moveFile = FileUtils.moveFile(imgFile.getAbsolutePath(), file.getAbsolutePath());
if (moveFile) {
mContext.sendBroadcast(new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE, Uri.fromFile(file)));
Toast.makeText(mContext.getApplicationContext(), R.string.save_success, Toast.LENGTH_SHORT).show();
} else {
Toast.makeText(mContext.getApplicationContext(), R.string.save_fail, Toast.LENGTH_SHORT).show();
}
} else {
Toast.makeText(mContext.getApplicationContext(), R.string.save_fail, Toast.LENGTH_SHORT).show();
}
}
});
}
}).setPositiveButton(mContext.getString(R.string.cancel), null).create().show();
return true;
}
});
((ViewPager) container).addView(photoView);
return photoView;
}
use of uk.co.senab.photoview.PhotoView in project ion by koush.
the class DeepZoomSample method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
PhotoView photoView = new PhotoView(this);
photoView.setMaximumScale(16);
setContentView(photoView);
final ProgressDialog dlg = new ProgressDialog(this);
dlg.setTitle("Loading...");
dlg.setIndeterminate(false);
dlg.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
dlg.show();
// this is going to load a 30mb download...
Ion.with(this).load("https://raw.githubusercontent.com/koush/ion/master/ion-sample/assets/telescope.jpg").progressDialog(dlg).setLogging("DeepZoom", Log.VERBOSE).withBitmap().deepZoom().intoImageView(photoView).setCallback(new FutureCallback<ImageView>() {
@Override
public void onCompleted(Exception e, ImageView result) {
dlg.cancel();
}
});
}
use of uk.co.senab.photoview.PhotoView in project weiciyuan by qii.
the class GalleryActivity method onBackPressed.
@Override
public void onBackPressed() {
if (rect == null || urls.size() > 1) {
super.onBackPressed();
return;
}
View view = pager.findViewWithTag(CURRENT_VISIBLE_PAGE);
final PhotoView imageView = (PhotoView) view.findViewById(R.id.image);
if (imageView == null || (!(imageView.getDrawable() instanceof BitmapDrawable))) {
super.onBackPressed();
return;
}
animateClose(imageView);
}
use of uk.co.senab.photoview.PhotoView in project weiciyuan by qii.
the class GalleryActivity method handlePage.
private void handlePage(int position, View contentView, boolean fromInstantiateItem) {
final PhotoView imageView = (PhotoView) contentView.findViewById(R.id.image);
imageView.setVisibility(View.INVISIBLE);
if (SettingUtility.allowClickToCloseGallery()) {
imageView.setOnPhotoTapListener(new PhotoViewAttacher.OnPhotoTapListener() {
@Override
public void onPhotoTap(View view, float x, float y) {
if (rect == null || imageView == null || (!(imageView.getDrawable() instanceof BitmapDrawable))) {
GalleryActivity.this.finish();
return;
}
animateClose(imageView);
}
});
}
WebView gif = (WebView) contentView.findViewById(R.id.gif);
gif.setBackgroundColor(getResources().getColor(R.color.transparent));
gif.setVisibility(View.INVISIBLE);
WebView large = (WebView) contentView.findViewById(R.id.large);
large.setBackgroundColor(getResources().getColor(R.color.transparent));
large.setVisibility(View.INVISIBLE);
large.setOverScrollMode(View.OVER_SCROLL_NEVER);
if (Utility.doThisDeviceOwnNavigationBar(GalleryActivity.this)) {
imageView.setPadding(0, 0, 0, Utility.dip2px(NAVIGATION_BAR_HEIGHT_DP_UNIT));
// webview has a bug, padding is ignored
gif.setPadding(0, 0, 0, Utility.dip2px(NAVIGATION_BAR_HEIGHT_DP_UNIT));
large.setPadding(0, 0, 0, Utility.dip2px(NAVIGATION_BAR_HEIGHT_DP_UNIT));
}
TextView wait = (TextView) contentView.findViewById(R.id.wait);
TextView readError = (TextView) contentView.findViewById(R.id.error);
String path = FileManager.getFilePathFromUrl(urls.get(position), FileLocationMethod.picture_large);
boolean shouldDownLoadPicture = !fromInstantiateItem || (fromInstantiateItem && Utility.isWifi(GalleryActivity.this));
// sometime picture is not downloaded completely, but android already can read it....
if (ImageUtility.isThisBitmapCanRead(path) && taskMap.get(urls.get(position)) == null && TaskCache.isThisUrlTaskFinished(urls.get(position))) {
wait.setVisibility(View.INVISIBLE);
readPicture(imageView, gif, large, readError, urls.get(position), path);
} else if (shouldDownLoadPicture) {
final CircleProgressView spinner = (CircleProgressView) contentView.findViewById(R.id.loading);
spinner.setVisibility(View.VISIBLE);
if (taskMap.get(urls.get(position)) == null) {
wait.setVisibility(View.VISIBLE);
PicSimpleBitmapWorkerTask task = new PicSimpleBitmapWorkerTask(imageView, gif, large, spinner, wait, readError, urls.get(position), taskMap);
taskMap.put(urls.get(position), task);
task.executeOnExecutor(MyAsyncTask.THREAD_POOL_EXECUTOR);
} else {
PicSimpleBitmapWorkerTask task = taskMap.get(urls.get(position));
task.setWidget(imageView, gif, spinner, wait, readError);
}
}
}
use of uk.co.senab.photoview.PhotoView in project JustAndroid by chinaltz.
the class PictureImagePreviewFragment method onCreateView.
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View contentView = inflater.inflate(R.layout.picture_fragment_image_preview, container, false);
final PhotoView imageView = (PhotoView) contentView.findViewById(R.id.preview_image);
LocalMedia media = (LocalMedia) getArguments().getSerializable(PictureConfig.EXTRA_MEDIA);
if (media.isCompressed()) {
// 压缩过,或者裁剪同时压缩过,以最终压缩过图片为准
path = media.getCompressPath();
} else {
path = media.getPath();
}
String pictureType = media.getPictureType();
isSave = getArguments().getBoolean("isSave");
directory_path = getArguments().getString(PictureConfig.DIRECTORY_PATH);
if (!isSave && path.startsWith("http")) {
showPleaseDialog();
}
boolean isGif = PictureMimeType.isGif(pictureType);
// 压缩过的gif就不是gif了
if (isGif && !media.isCompressed()) {
Glide.with(container.getContext()).load(path).asGif().override(480, 800).diskCacheStrategy(DiskCacheStrategy.SOURCE).priority(Priority.HIGH).into(imageView);
dismissDialog();
} else {
Glide.with(container.getContext()).load(path).asBitmap().diskCacheStrategy(DiskCacheStrategy.RESULT).into(new SimpleTarget<Bitmap>(480, 800) {
@Override
public void onResourceReady(Bitmap resource, GlideAnimation<? super Bitmap> glideAnimation) {
imageView.setImageBitmap(resource);
dismissDialog();
}
});
}
imageView.setOnViewTapListener(new PhotoViewAttacher.OnViewTapListener() {
@Override
public void onViewTap(View view, float x, float y) {
getActivity().finish();
getActivity().overridePendingTransition(0, R.anim.a3);
}
});
imageView.setOnLongClickListener(new View.OnLongClickListener() {
@Override
public boolean onLongClick(View v) {
// 内部预览不保存
if (!isSave) {
if (hasPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE)) {
showDownLoadDialog(path);
} else {
requestPermission(Constant.WRITE_EXTERNAL_STORAGE, Manifest.permission.WRITE_EXTERNAL_STORAGE);
}
}
return true;
}
});
return contentView;
}
Aggregations