Commit 496a2d8bd6d6566cd0928fe925e7bdf9eacf3ed4
1 parent
d56bc607
兼容动图全屏预览
Showing
7 changed files
with
92 additions
and
36 deletions
app/strike/src/main/java/com/cnlive/strike/imgutil/SimplePrevActivity.java
| ... | ... | @@ -50,8 +50,8 @@ public class SimplePrevActivity extends BaseActivity { |
| 50 | 50 | list.add("https://b-ssl.duitang.com/uploads/item/201706/30/20170630181644_j4mh5.jpeg"); |
| 51 | 51 | |
| 52 | 52 | preView.overlayStatusBar(false) |
| 53 | - .imageData(list) | |
| 54 | - .imageLoader(new PhotoLoader()); | |
| 53 | + .imageData(list); | |
| 54 | +// .imageLoader(new PhotoLoader()); | |
| 55 | 55 | |
| 56 | 56 | adapter = new SimpleAutoGridAdapter<String, BaseAutoGridHolder>(list); |
| 57 | 57 | adapter.setImageLoader(new SimpleAutoGridAdapter.ImageLoader() { | ... | ... |
core/imageload/src/main/java/com/cnlive/core/activity/PreviewImageActivity.java
| ... | ... | @@ -5,9 +5,9 @@ import android.widget.ImageView; |
| 5 | 5 | import com.alibaba.android.arouter.facade.annotation.Route; |
| 6 | 6 | import com.cnlive.core.imageload.R; |
| 7 | 7 | import com.cnlive.core.imagepreview.ImagePreView; |
| 8 | -import com.cnlive.core.imagepreview.PhotoLoader; | |
| 9 | 8 | import com.cnlive.core.imagepreview.ViewerStatus; |
| 10 | 9 | import com.cnlive.core.imagepreview.listener.OnItemClickListener; |
| 10 | +import com.cnlive.core.imagepreview.listener.OnItemLongPressListener; | |
| 11 | 11 | import com.cnlive.core.libs.base.frame.activity.BaseActivity; |
| 12 | 12 | |
| 13 | 13 | import java.util.ArrayList; |
| ... | ... | @@ -32,10 +32,10 @@ public class PreviewImageActivity extends BaseActivity { |
| 32 | 32 | |
| 33 | 33 | preView.overlayStatusBar(false) |
| 34 | 34 | .imageData(list) |
| 35 | - .playExitAnim(false) | |
| 36 | - .imageLoader(new PhotoLoader()); | |
| 37 | - | |
| 35 | + .playExitAnim(false); | |
| 36 | +// .imageLoader(new PhotoLoader()); | |
| 38 | 37 | preView.watch(0); |
| 38 | + | |
| 39 | 39 | preView.setOnItemClickListener(new OnItemClickListener() { |
| 40 | 40 | @Override |
| 41 | 41 | public boolean onItemClick(int position, ImageView imageView) { |
| ... | ... | @@ -44,6 +44,13 @@ public class PreviewImageActivity extends BaseActivity { |
| 44 | 44 | return true; |
| 45 | 45 | } |
| 46 | 46 | }); |
| 47 | + | |
| 48 | + preView.setOnItemLongPressListener(new OnItemLongPressListener() { | |
| 49 | + @Override | |
| 50 | + public boolean onItemLongPress(int position, ImageView imageView) { | |
| 51 | + return false; | |
| 52 | + } | |
| 53 | + }); | |
| 47 | 54 | } |
| 48 | 55 | |
| 49 | 56 | @Override | ... | ... |
core/imageload/src/main/java/com/cnlive/core/imageload/loader/GlideLoader.java
| ... | ... | @@ -20,7 +20,6 @@ import com.bumptech.glide.RequestManager; |
| 20 | 20 | import com.bumptech.glide.load.Transformation; |
| 21 | 21 | import com.bumptech.glide.load.engine.cache.ExternalCacheDiskCacheFactory; |
| 22 | 22 | import com.bumptech.glide.load.engine.cache.InternalCacheDiskCacheFactory; |
| 23 | -import com.bumptech.glide.request.RequestOptions; | |
| 24 | 23 | import com.bumptech.glide.request.target.SimpleTarget; |
| 25 | 24 | import com.bumptech.glide.request.transition.Transition; |
| 26 | 25 | import com.cnlive.core.imageload.config.AnimationMode; |
| ... | ... | @@ -142,6 +141,9 @@ public class GlideLoader implements ILoader{ |
| 142 | 141 | if (config.getErrorResId() > 0) { |
| 143 | 142 | request.error(config.getErrorResId()); |
| 144 | 143 | } |
| 144 | +// else { | |
| 145 | +// request.error(R.drawable.preview_zwtp); | |
| 146 | +// } | |
| 145 | 147 | |
| 146 | 148 | // if(config.isGif()){ |
| 147 | 149 | // request.asGif(); | ... | ... |
core/imageload/src/main/java/com/cnlive/core/imagepreview/ImageDrawee.java
| 1 | 1 | package com.cnlive.core.imagepreview; |
| 2 | 2 | |
| 3 | 3 | import android.content.Context; |
| 4 | -import android.graphics.Bitmap; | |
| 5 | 4 | import android.graphics.drawable.Drawable; |
| 6 | -import android.util.Log; | |
| 7 | 5 | import android.widget.FrameLayout; |
| 8 | 6 | import android.widget.ImageView; |
| 9 | 7 | |
| 8 | +import com.bumptech.glide.Glide; | |
| 9 | +import com.bumptech.glide.load.DataSource; | |
| 10 | +import com.bumptech.glide.load.engine.GlideException; | |
| 11 | +import com.bumptech.glide.request.RequestListener; | |
| 12 | +import com.bumptech.glide.request.target.Target; | |
| 13 | +import com.cnlive.core.imageload.R; | |
| 10 | 14 | import com.cnlive.core.imagepreview.indexui.ProgressUI; |
| 11 | 15 | import com.github.chrisbanes.photoview.PhotoView; |
| 12 | 16 | |
| 13 | 17 | import androidx.annotation.NonNull; |
| 18 | +import androidx.annotation.Nullable; | |
| 14 | 19 | |
| 15 | 20 | /** |
| 16 | 21 | * created by hanyayun |
| ... | ... | @@ -91,30 +96,38 @@ public class ImageDrawee extends FrameLayout { |
| 91 | 96 | return imageView; |
| 92 | 97 | } |
| 93 | 98 | |
| 94 | - public void setImage(Object obj) { | |
| 99 | + public void setImage(Object obj, LoadImage.LoadCallback callback) { | |
| 95 | 100 | if (obj == null) { |
| 96 | 101 | return; |
| 97 | 102 | } |
| 98 | 103 | |
| 99 | -// if (obj instanceof Drawable || obj instanceof Bitmap || obj instanceof Integer || obj instanceof String) { | |
| 100 | -// ImageLoader.with(getContext()) | |
| 101 | -// .url((String) obj) | |
| 102 | -// .scale(ScaleMode.CENTER_CROP) | |
| 103 | -// .into(imageView); | |
| 104 | -//// Glide.with(getContext()).load(obj).into(imageView); | |
| 104 | + Glide.with(getContext()) | |
| 105 | + .load(obj) | |
| 106 | + .listener(new RequestListener<Drawable>() { | |
| 107 | + @Override | |
| 108 | + public boolean onLoadFailed(@Nullable GlideException e, Object model, Target<Drawable> target, boolean isFirstResource) { | |
| 109 | + callback.onLoadFailed(); | |
| 110 | + return false; | |
| 111 | + } | |
| 112 | + | |
| 113 | + @Override | |
| 114 | + public boolean onResourceReady(Drawable resource, Object model, Target<Drawable> target, DataSource dataSource, boolean isFirstResource) { | |
| 115 | + callback.onLoadSucceed(resource); | |
| 116 | + return false; | |
| 117 | + } | |
| 118 | + }) | |
| 119 | + .error(R.drawable.preview_zwtp) | |
| 120 | + .into(imageView); | |
| 121 | +// if (obj instanceof Drawable) { | |
| 122 | +// Glide.with(getContext()).load(obj).into(imageView); | |
| 123 | +//// imageView.setImageDrawable((Drawable) obj); | |
| 124 | +// } else if (obj instanceof Bitmap) { | |
| 125 | +// imageView.setImageBitmap((Bitmap) obj); | |
| 126 | +// } else if (obj instanceof Integer) { | |
| 127 | +// imageView.setImageResource((Integer) obj); | |
| 105 | 128 | // } else { |
| 106 | 129 | // Log.e("ImageDrawee", "Unable to identify picture resources."); |
| 107 | 130 | // } |
| 108 | - | |
| 109 | - if (obj instanceof Drawable) { | |
| 110 | - imageView.setImageDrawable((Drawable) obj); | |
| 111 | - } else if (obj instanceof Bitmap) { | |
| 112 | - imageView.setImageBitmap((Bitmap) obj); | |
| 113 | - } else if (obj instanceof Integer) { | |
| 114 | - imageView.setImageResource((Integer) obj); | |
| 115 | - } else { | |
| 116 | - Log.e("ImageDrawee", "Unable to identify picture resources."); | |
| 117 | - } | |
| 118 | 131 | } |
| 119 | 132 | |
| 120 | 133 | public float getScale() { | ... | ... |
core/imageload/src/main/java/com/cnlive/core/imagepreview/ImagePreView.java
| ... | ... | @@ -48,7 +48,7 @@ public class ImagePreView extends FrameLayout implements ViewPager.OnPageChangeL |
| 48 | 48 | private ProgressUI progressUI; |
| 49 | 49 | private ImageViewPager viewPager; |
| 50 | 50 | private ImagePagerAdapter mAdapter; |
| 51 | - private LoadImage mLoader; | |
| 51 | +// private LoadImage mLoader; | |
| 52 | 52 | private DragHandler mDragHandler; |
| 53 | 53 | |
| 54 | 54 | // 是否执行进场动画 |
| ... | ... | @@ -197,7 +197,7 @@ public class ImagePreView extends FrameLayout implements ViewPager.OnPageChangeL |
| 197 | 197 | } |
| 198 | 198 | |
| 199 | 199 | public ImagePreView imageLoader(@NonNull LoadImage loader) { |
| 200 | - this.mLoader = loader; | |
| 200 | +// this.mLoader = loader; | |
| 201 | 201 | return this; |
| 202 | 202 | } |
| 203 | 203 | |
| ... | ... | @@ -467,10 +467,13 @@ public class ImagePreView extends FrameLayout implements ViewPager.OnPageChangeL |
| 467 | 467 | if (mMinScale > 0) { |
| 468 | 468 | drawee.setMinScale(mMinScale); |
| 469 | 469 | } |
| 470 | - mLoader.displayImage(mSourceList.get(position).getImageSrc(), drawee.getImageView(), new LoadImage.LoadCallback() { | |
| 470 | + | |
| 471 | + | |
| 472 | + drawee.setImage(mSourceList.get(position).getImageSrc(),new LoadImage.LoadCallback(){ | |
| 473 | + | |
| 471 | 474 | @Override |
| 472 | 475 | public void onLoadStarted(Object placeholder) { |
| 473 | - drawee.setImage(placeholder); | |
| 476 | + | |
| 474 | 477 | } |
| 475 | 478 | |
| 476 | 479 | @Override |
| ... | ... | @@ -481,7 +484,6 @@ public class ImagePreView extends FrameLayout implements ViewPager.OnPageChangeL |
| 481 | 484 | @Override |
| 482 | 485 | public void onLoadSucceed(Object source) { |
| 483 | 486 | drawee.hideProgressUI(); |
| 484 | - drawee.setImage(source); | |
| 485 | 487 | if (mSourceList.get(position).getImageWidth() == 0 || |
| 486 | 488 | mSourceList.get(position).getImageHeight() == 0) { |
| 487 | 489 | Drawable drawable = drawee.getImageView().getDrawable(); |
| ... | ... | @@ -493,11 +495,43 @@ public class ImagePreView extends FrameLayout implements ViewPager.OnPageChangeL |
| 493 | 495 | } |
| 494 | 496 | |
| 495 | 497 | @Override |
| 496 | - public void onLoadFailed(Object error) { | |
| 498 | + public void onLoadFailed() { | |
| 497 | 499 | drawee.hideProgressUI(); |
| 498 | - drawee.setImage(error); | |
| 499 | 500 | } |
| 500 | 501 | }); |
| 502 | + | |
| 503 | + | |
| 504 | +// mLoader.displayImage(mSourceList.get(position).getImageSrc(), drawee.getImageView(), new LoadImage.LoadCallback() { | |
| 505 | +// @Override | |
| 506 | +// public void onLoadStarted(Object placeholder) { | |
| 507 | +// drawee.setImage(placeholder); | |
| 508 | +// } | |
| 509 | +// | |
| 510 | +// @Override | |
| 511 | +// public void onLoading(float progress) { | |
| 512 | +// drawee.handleProgress(progress); | |
| 513 | +// } | |
| 514 | +// | |
| 515 | +// @Override | |
| 516 | +// public void onLoadSucceed(Object source) { | |
| 517 | +// drawee.hideProgressUI(); | |
| 518 | +// drawee.setImage(source); | |
| 519 | +// if (mSourceList.get(position).getImageWidth() == 0 || | |
| 520 | +// mSourceList.get(position).getImageHeight() == 0) { | |
| 521 | +// Drawable drawable = drawee.getImageView().getDrawable(); | |
| 522 | +// if (drawable != null) { | |
| 523 | +// mSourceList.get(position).setImageWidth(drawable.getIntrinsicWidth()); | |
| 524 | +// mSourceList.get(position).setImageHeight(drawable.getIntrinsicHeight()); | |
| 525 | +// } | |
| 526 | +// } | |
| 527 | +// } | |
| 528 | +// | |
| 529 | +// @Override | |
| 530 | +// public void onLoadFailed(Object error) { | |
| 531 | +// drawee.hideProgressUI(); | |
| 532 | +//// drawee.setImage(error); | |
| 533 | +// } | |
| 534 | +// }); | |
| 501 | 535 | // 单击事件 |
| 502 | 536 | drawee.getImageView().setOnClickListener(new View.OnClickListener() { |
| 503 | 537 | @Override |
| ... | ... | @@ -762,7 +796,7 @@ public class ImagePreView extends FrameLayout implements ViewPager.OnPageChangeL |
| 762 | 796 | protected void onDetachedFromWindow() { |
| 763 | 797 | super.onDetachedFromWindow(); |
| 764 | 798 | mSourceList = null; |
| 765 | - mLoader = null; | |
| 799 | +// mLoader = null; | |
| 766 | 800 | reset(); |
| 767 | 801 | } |
| 768 | 802 | } | ... | ... |
core/imageload/src/main/java/com/cnlive/core/imagepreview/LoadImage.java
core/imageload/src/main/java/com/cnlive/core/imagepreview/PhotoLoader.java