diff --git a/BigImageViewer/src/main/java/com/github/piasy/biv/view/BigImageView.java b/BigImageViewer/src/main/java/com/github/piasy/biv/view/BigImageView.java
index cd3cba4..2e4a76d 100644
--- a/BigImageViewer/src/main/java/com/github/piasy/biv/view/BigImageView.java
+++ b/BigImageViewer/src/main/java/com/github/piasy/biv/view/BigImageView.java
@@ -42,7 +42,6 @@
import androidx.annotation.Keep;
import androidx.annotation.RequiresPermission;
import androidx.annotation.UiThread;
-import com.davemorrissey.labs.subscaleview.ImageSource;
import com.davemorrissey.labs.subscaleview.SubsamplingScaleImageView;
import com.github.piasy.biv.BigImageViewer;
import com.github.piasy.biv.R;
@@ -98,7 +97,10 @@ public class BigImageView extends FrameLayout implements ImageLoader.Callback {
private View mProgressIndicatorView;
private ImageView mFailureImageView;
+ private boolean mDelayMainImage = false;
+
private ImageSaveCallback mImageSaveCallback;
+ private ImageShownCallback mImageShownCallback;
private ImageLoader.Callback mUserCallback;
private File mCurrentImageFile;
private Uri mUri;
@@ -286,6 +288,10 @@ public void setImageSaveCallback(ImageSaveCallback imageSaveCallback) {
mImageSaveCallback = imageSaveCallback;
}
+ public void setImageShownCallback(ImageShownCallback imageCycleCallback) {
+ mImageShownCallback = imageCycleCallback;
+ }
+
public void setProgressIndicator(ProgressIndicator progressIndicator) {
mProgressIndicator = progressIndicator;
}
@@ -342,17 +348,34 @@ public void showImage(Uri uri) {
}
public void showImage(final Uri thumbnail, final Uri uri) {
+ showImage(thumbnail, uri, false);
+ }
+
+ public void showImage(final Uri thumbnail, final Uri uri, final boolean delayMainImage) {
mThumbnail = thumbnail;
mUri = uri;
clearThumbnailAndProgressIndicator();
- mImageLoader.loadImage(hashCode(), uri, mInternalCallback);
+
+ mDelayMainImage = delayMainImage;
+ if (mDelayMainImage) {
+ BigImageViewer.prefetch(uri);
+ mImageLoader.loadImage(hashCode(), thumbnail, mInternalCallback);
+ } else {
+ mImageLoader.loadImage(hashCode(), uri, mInternalCallback);
+ }
if (mFailureImageView != null) {
mFailureImageView.setVisibility(GONE);
}
}
+ public void loadMainImageNow() {
+
+ mDelayMainImage = false;
+ mImageLoader.loadImage(hashCode(), mUri, mInternalCallback);
+ }
+
public void cancel() {
mImageLoader.cancel(hashCode());
}
@@ -362,9 +385,9 @@ public SubsamplingScaleImageView getSSIV() {
}
@Override
- public void onCacheHit(final int imageType, File image) {
+ public void onCacheHit(final int imageType, final File image) {
mCurrentImageFile = image;
- doShowImage(imageType, image);
+ doShowImage(imageType, image, mDelayMainImage);
if (mUserCallback != null) {
mUserCallback.onCacheHit(imageType, image);
@@ -375,7 +398,7 @@ public void onCacheHit(final int imageType, File image) {
public void onCacheMiss(final int imageType, final File image) {
mCurrentImageFile = image;
mTempImages.add(image);
- doShowImage(imageType, image);
+ doShowImage(imageType, image, mDelayMainImage);
if (mUserCallback != null) {
mUserCallback.onCacheMiss(imageType, image);
@@ -386,8 +409,8 @@ public void onCacheMiss(final int imageType, final File image) {
public void onStart() {
// why show thumbnail in onStart? because we may not need download it from internet
if (mThumbnail != Uri.EMPTY) {
- mThumbnailView = mViewFactory.createThumbnailView(getContext(), mThumbnail,
- mThumbnailScaleType);
+ mThumbnailView = mViewFactory.createThumbnailView(getContext(), mThumbnailScaleType);
+ mViewFactory.loadThumbnailContent(mThumbnailView, mThumbnail);
if (mThumbnailView != null) {
addView(mThumbnailView, ViewGroup.LayoutParams.MATCH_PARENT,
ViewGroup.LayoutParams.MATCH_PARENT);
@@ -502,32 +525,84 @@ public void onAnimationRepeat(Animation animation) {
}
@UiThread
- private void doShowImage(final int imageType, final File image) {
- if (mMainView != null) {
- removeView(mMainView);
- }
+ private void doShowImage(final int imageType, final File image, final boolean useThumbnailView) {
- mMainView = mViewFactory.createMainView(getContext(), imageType, image, mInitScaleType);
- if (mMainView == null) {
- onFail(new RuntimeException("Image type not supported: "
- + ImageInfoExtractor.typeName(imageType)));
- return;
- }
+ if (useThumbnailView) {
+
+ if (mThumbnailView == null) {
+ mThumbnailView = mViewFactory.createThumbnailView(getContext(), mThumbnailScaleType);
+ }
+
+ if (mThumbnailView.getVisibility() != View.VISIBLE) {
+ mThumbnailView.setVisibility(View.VISIBLE);
+ }
+
+ if (mThumbnailView != null) {
+
+ if (!(mThumbnailView.getParent() == this)) {
+ addView(mThumbnailView, ViewGroup.LayoutParams.MATCH_PARENT,
+ ViewGroup.LayoutParams.MATCH_PARENT);
+ }
+
+ mThumbnailView.setOnClickListener(mOnClickListener);
+ mThumbnailView.setOnLongClickListener(mOnLongClickListener);
+
+ if (mThumbnailView instanceof ImageView) {
+ ((ImageView) mThumbnailView).setAdjustViewBounds(true);
+ ((ImageView) mThumbnailView).setScaleType(ImageView.ScaleType.FIT_START);
+
+ mViewFactory.loadThumbnailContent(mThumbnailView, Uri.fromFile(image));
+
+ if (mImageShownCallback != null) {
+ mImageShownCallback.onThumbnailShown();
+ }
+ }
+ }
+
+ } else {
- addView(mMainView, ViewGroup.LayoutParams.MATCH_PARENT,
- ViewGroup.LayoutParams.MATCH_PARENT);
- mMainView.setOnClickListener(mOnClickListener);
- mMainView.setOnLongClickListener(mOnLongClickListener);
+ if (mMainView != null) {
+ removeView(mMainView);
+ }
- if (mMainView instanceof SubsamplingScaleImageView) {
- mSSIV = (SubsamplingScaleImageView) mMainView;
+ mMainView = mViewFactory.createMainView(getContext(), imageType, mInitScaleType);
+ if (mMainView == null) {
+ onFail(new RuntimeException("Image type not supported: "
+ + ImageInfoExtractor.typeName(imageType)));
+ return;
+ }
- mSSIV.setMinimumTileDpi(160);
+ addView(mMainView, ViewGroup.LayoutParams.MATCH_PARENT,
+ ViewGroup.LayoutParams.MATCH_PARENT);
- setOptimizeDisplay(mOptimizeDisplay);
- setInitScaleType(mInitScaleType);
+ mMainView.setOnClickListener(mOnClickListener);
+ mMainView.setOnLongClickListener(mOnLongClickListener);
- mSSIV.setImage(ImageSource.uri(Uri.fromFile(image)));
+ if (mMainView instanceof SubsamplingScaleImageView) {
+ mSSIV = (SubsamplingScaleImageView) mMainView;
+
+ mSSIV.setMinimumTileDpi(160);
+
+ setOptimizeDisplay(mOptimizeDisplay);
+ setInitScaleType(mInitScaleType);
+
+ if (mViewFactory.isAnimatedContent(imageType)) {
+ mViewFactory.loadAnimatedContent(mSSIV, imageType, image);
+ } else {
+ mViewFactory.loadSillContent(mSSIV, Uri.fromFile(image));
+ }
+
+ if (mImageShownCallback != null) {
+ mImageShownCallback.onMainImageShown();
+ }
+ } else {
+
+ if (mViewFactory.isAnimatedContent(imageType)) {
+ mViewFactory.loadAnimatedContent(mMainView, imageType, image);
+ } else {
+ mViewFactory.loadSillContent(mMainView, Uri.fromFile(image));
+ }
+ }
}
if (mFailureImageView != null) {
diff --git a/BigImageViewer/src/main/java/com/github/piasy/biv/view/ImageShownCallback.java b/BigImageViewer/src/main/java/com/github/piasy/biv/view/ImageShownCallback.java
new file mode 100644
index 0000000..54714de
--- /dev/null
+++ b/BigImageViewer/src/main/java/com/github/piasy/biv/view/ImageShownCallback.java
@@ -0,0 +1,10 @@
+package com.github.piasy.biv.view;
+
+import androidx.annotation.UiThread;
+
+@UiThread
+public interface ImageShownCallback {
+
+ void onThumbnailShown();
+ void onMainImageShown();
+}
diff --git a/BigImageViewer/src/main/java/com/github/piasy/biv/view/ImageViewFactory.java b/BigImageViewer/src/main/java/com/github/piasy/biv/view/ImageViewFactory.java
index 2f6d187..bab8e00 100644
--- a/BigImageViewer/src/main/java/com/github/piasy/biv/view/ImageViewFactory.java
+++ b/BigImageViewer/src/main/java/com/github/piasy/biv/view/ImageViewFactory.java
@@ -28,6 +28,8 @@
import android.net.Uri;
import android.view.View;
import android.widget.ImageView;
+
+import com.davemorrissey.labs.subscaleview.ImageSource;
import com.davemorrissey.labs.subscaleview.SubsamplingScaleImageView;
import com.github.piasy.biv.metadata.ImageInfoExtractor;
import java.io.File;
@@ -37,12 +39,11 @@
*/
public class ImageViewFactory {
- public final View createMainView(Context context, int imageType, File imageFile,
- int initScaleType) {
+ public final View createMainView(final Context context, final int imageType, final int initScaleType) {
switch (imageType) {
case ImageInfoExtractor.TYPE_GIF:
case ImageInfoExtractor.TYPE_ANIMATED_WEBP:
- return createAnimatedImageView(context, imageType, imageFile, initScaleType);
+ return createAnimatedImageView(context, imageType, initScaleType);
case ImageInfoExtractor.TYPE_STILL_WEBP:
case ImageInfoExtractor.TYPE_STILL_IMAGE:
default:
@@ -50,16 +51,41 @@ public final View createMainView(Context context, int imageType, File imageFile,
}
}
- protected SubsamplingScaleImageView createStillImageView(Context context) {
+ public boolean isAnimatedContent(final int imageType) {
+ switch (imageType) {
+
+ case ImageInfoExtractor.TYPE_GIF:
+ case ImageInfoExtractor.TYPE_ANIMATED_WEBP:
+ return true;
+
+ default:
+ return false;
+ }
+ }
+
+ protected SubsamplingScaleImageView createStillImageView(final Context context) {
return new SubsamplingScaleImageView(context);
}
- protected View createAnimatedImageView(Context context, int imageType, File imageFile,
- int initScaleType) {
+ protected View createAnimatedImageView(final Context context, final int imageType, final int initScaleType) {
return null;
}
- public View createThumbnailView(Context context, Uri thumbnail, ImageView.ScaleType scaleType) {
- return null;
+ public void loadAnimatedContent(final View view, final int imageType, final File imageFile) {}
+
+ public void loadSillContent(final View view, final Uri uri) {
+ if (view instanceof SubsamplingScaleImageView) {
+ ((SubsamplingScaleImageView) view).setImage(ImageSource.uri(uri));
+ }
+ }
+
+ public View createThumbnailView(final Context context, final ImageView.ScaleType scaleType) {
+ return new ImageView(context);
+ }
+
+ public void loadThumbnailContent(final View view, final Uri thumbnail) {
+ if (view instanceof ImageView) {
+ ((ImageView) view).setImageURI(thumbnail);
+ }
}
}
diff --git a/FrescoImageViewFactory/src/main/java/com/github/piasy/biv/view/FrescoImageViewFactory.java b/FrescoImageViewFactory/src/main/java/com/github/piasy/biv/view/FrescoImageViewFactory.java
index 0024502..7a406bc 100644
--- a/FrescoImageViewFactory/src/main/java/com/github/piasy/biv/view/FrescoImageViewFactory.java
+++ b/FrescoImageViewFactory/src/main/java/com/github/piasy/biv/view/FrescoImageViewFactory.java
@@ -39,29 +39,29 @@
*/
public class FrescoImageViewFactory extends ImageViewFactory {
@Override
- protected View createAnimatedImageView(final Context context, final int imageType,
- final File imageFile, int initScaleType) {
- SimpleDraweeView view = new SimpleDraweeView(context);
- DraweeController controller = Fresco.newDraweeControllerBuilder()
- .setUri(Uri.parse("file://" + imageFile.getAbsolutePath()))
- .setAutoPlayAnimations(true)
- .build();
- view.setController(controller);
+ protected final View createAnimatedImageView(final Context context, final int imageType, int initScaleType) {
+ final SimpleDraweeView view = new SimpleDraweeView(context);
view.getHierarchy().setActualImageScaleType(scaleType(initScaleType));
return view;
}
@Override
- public View createThumbnailView(final Context context, final Uri thumbnail,
- final ImageView.ScaleType scaleType) {
- SimpleDraweeView thumbnailView = new SimpleDraweeView(context);
- DraweeController controller = Fresco.newDraweeControllerBuilder()
- .setUri(thumbnail)
- .build();
+ public final void loadAnimatedContent(final View view, final int imageType, final File imageFile) {
+ if (view instanceof SimpleDraweeView) {
+ final DraweeController controller = Fresco.newDraweeControllerBuilder()
+ .setUri(Uri.parse("file://" + imageFile.getAbsolutePath()))
+ .setAutoPlayAnimations(true)
+ .build();
+ ((SimpleDraweeView) view).setController(controller);
+ }
+ }
+
+ @Override
+ public final View createThumbnailView(final Context context, final ImageView.ScaleType scaleType) {
+ final ImageView thumbnailView = new ImageView(context);
if (scaleType != null) {
- thumbnailView.getHierarchy().setActualImageScaleType(scaleType(scaleType));
+ thumbnailView.setScaleType(scaleType);
}
- thumbnailView.setController(controller);
return thumbnailView;
}
@@ -84,24 +84,4 @@ private ScalingUtils.ScaleType scaleType(int value) {
return ScalingUtils.ScaleType.FIT_CENTER;
}
}
-
- private ScalingUtils.ScaleType scaleType(ImageView.ScaleType scaleType) {
- switch (scaleType) {
- case CENTER:
- return ScalingUtils.ScaleType.CENTER;
- case CENTER_CROP:
- return ScalingUtils.ScaleType.CENTER_CROP;
- case CENTER_INSIDE:
- return ScalingUtils.ScaleType.CENTER_INSIDE;
- case FIT_END:
- return ScalingUtils.ScaleType.FIT_END;
- case FIT_START:
- return ScalingUtils.ScaleType.FIT_START;
- case FIT_XY:
- return ScalingUtils.ScaleType.FIT_XY;
- case FIT_CENTER:
- default:
- return ScalingUtils.ScaleType.FIT_CENTER;
- }
- }
}
diff --git a/GlideImageViewFactory/src/main/java/com/github/piasy/biv/view/GlideImageViewFactory.java b/GlideImageViewFactory/src/main/java/com/github/piasy/biv/view/GlideImageViewFactory.java
index 9b00a60..ce8a3fe 100644
--- a/GlideImageViewFactory/src/main/java/com/github/piasy/biv/view/GlideImageViewFactory.java
+++ b/GlideImageViewFactory/src/main/java/com/github/piasy/biv/view/GlideImageViewFactory.java
@@ -38,36 +38,48 @@
*/
public class GlideImageViewFactory extends ImageViewFactory {
@Override
- protected View createAnimatedImageView(final Context context, final int imageType,
- final File imageFile, int initScaleType) {
+ protected final View createAnimatedImageView(final Context context, final int imageType, final int initScaleType) {
switch (imageType) {
- case ImageInfoExtractor.TYPE_GIF:
- GifImageView gifImageView = new GifImageView(context);
- gifImageView.setImageURI(Uri.parse("file://" + imageFile.getAbsolutePath()));
+ case ImageInfoExtractor.TYPE_GIF: {
+ final GifImageView gifImageView = new GifImageView(context);
gifImageView.setScaleType(BigImageView.scaleType(initScaleType));
return gifImageView;
- case ImageInfoExtractor.TYPE_ANIMATED_WEBP:
- ImageView imageView = new ImageView(context);
+ }
+ case ImageInfoExtractor.TYPE_ANIMATED_WEBP: {
+ final ImageView imageView = new ImageView(context);
imageView.setScaleType(BigImageView.scaleType(initScaleType));
- Glide.with(context)
- .load(imageFile)
- .into(imageView);
return imageView;
+ }
+ default:
+ return super.createAnimatedImageView(context, imageType, initScaleType);
+ }
+ }
+
+ @Override
+ public final void loadAnimatedContent(final View view, final int imageType, final File imageFile) {
+ switch (imageType) {
+ case ImageInfoExtractor.TYPE_GIF: {
+ ((GifImageView) view).setImageURI(Uri.parse("file://" + imageFile.getAbsolutePath()));
+ break;
+ }
+ case ImageInfoExtractor.TYPE_ANIMATED_WEBP: {
+ Glide.with(view.getContext())
+ .load(imageFile)
+ .into((ImageView) view);
+ break;
+ }
+
default:
- return super.createAnimatedImageView(context, imageType, imageFile, initScaleType);
+ super.loadAnimatedContent(view, imageType, imageFile);
}
}
@Override
- public View createThumbnailView(final Context context, final Uri thumbnail,
- final ImageView.ScaleType scaleType) {
- ImageView thumbnailView = new ImageView(context);
+ public final View createThumbnailView(final Context context, final ImageView.ScaleType scaleType) {
+ final ImageView thumbnailView = new ImageView(context);
if (scaleType != null) {
thumbnailView.setScaleType(scaleType);
}
- Glide.with(context)
- .load(thumbnail)
- .into(thumbnailView);
return thumbnailView;
}
}
diff --git a/app/build.gradle b/app/build.gradle
index 4600af6..5f02a2d 100644
--- a/app/build.gradle
+++ b/app/build.gradle
@@ -24,6 +24,7 @@
apply plugin: 'com.android.application'
apply plugin: 'com.github.ben-manes.versions'
+apply plugin: 'kotlin-android'
android {
compileSdkVersion rootProject.ext.androidCompileSdkVersion
@@ -72,8 +73,9 @@ android {
}
dependencies {
+ implementation "androidx.core:core-ktx:1.1.0"
implementation "androidx.appcompat:appcompat:1.1.0"
- implementation "androidx.recyclerview:recyclerview:1.0.0"
+ implementation "androidx.recyclerview:recyclerview:1.1.0-beta05"
implementation "com.google.android.material:material:$materialVersion"
implementation('com.tbruyelle.rxpermissions2:rxpermissions:0.9.5') {
diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml
index 44603d1..cc812da 100644
--- a/app/src/main/AndroidManifest.xml
+++ b/app/src/main/AndroidManifest.xml
@@ -23,8 +23,7 @@
~ SOFTWARE.
-->
+ package="com.github.piasy.biv.example">
@@ -52,6 +51,8 @@
+
+
\ No newline at end of file
diff --git a/app/src/main/java/com/github/piasy/biv/example/FirstAnimActivity.kt b/app/src/main/java/com/github/piasy/biv/example/FirstAnimActivity.kt
new file mode 100644
index 0000000..2dea0fd
--- /dev/null
+++ b/app/src/main/java/com/github/piasy/biv/example/FirstAnimActivity.kt
@@ -0,0 +1,87 @@
+package com.github.piasy.biv.example
+
+import android.os.Bundle
+import android.widget.CheckBox
+import android.widget.RadioButton
+import android.widget.Toast
+import androidx.appcompat.app.AppCompatActivity
+import com.bumptech.glide.Glide
+import com.facebook.drawee.backends.pipeline.Fresco
+import com.facebook.drawee.drawable.ScalingUtils
+import com.facebook.drawee.view.SimpleDraweeView
+
+class FirstAnimActivity : AppCompatActivity() {
+
+ companion object {
+ private const val THUMB_URL = "https://preview.redd.it/nahhvcadsbo21.jpg?width=216&crop=smart&auto=webp&s=c560e5774d7f43e178c1f0faad09315cdb86c203"
+ private const val SOURCE_URL = "https://i.redd.it/nahhvcadsbo21.jpg"
+ }
+
+ private val thumb by lazy { findViewById(R.id.thumbView) }
+
+ override fun onCreate(savedInstanceState: Bundle?) {
+ Fresco.initialize(this)
+
+ super.onCreate(savedInstanceState)
+ setContentView(R.layout.activity_anim_first)
+
+ val useGlide = findViewById(R.id.use_glide)
+ val useFresco = findViewById(R.id.use_fresco)
+ val useViewFactory = findViewById(R.id.check_use_view_factory)
+
+ thumb.setLegacyVisibilityHandlingEnabled(true)
+ thumb.setOnClickListener {
+
+ SecondAnimActivity.start(this, thumb,
+ THUMB_URL, SOURCE_URL,
+ useGlide.isChecked, useFresco.isChecked, useViewFactory.isChecked)
+ }
+
+ if (useGlide.isChecked) {
+ loadGlide()
+ }
+
+ if (useFresco.isChecked) {
+ loadFresco()
+ }
+
+ useGlide.setOnCheckedChangeListener { _, isChecked ->
+
+ if (isChecked) {
+ loadGlide()
+ }
+ }
+
+ useFresco.setOnCheckedChangeListener { _, isChecked ->
+
+ if (isChecked) {
+ loadFresco()
+ }
+ }
+ }
+
+ private fun loadGlide() {
+ val glide = Glide.with(this)
+ glide.asBitmap()
+ .load(THUMB_URL)
+ .into(thumb)
+
+ showToast("Loaded with Glide!")
+ }
+
+ private fun loadFresco() {
+
+ val controller = Fresco.newDraweeControllerBuilder()
+ .setUri(THUMB_URL)
+ .build()
+
+ thumb.hierarchy.actualImageScaleType = ScalingUtils.ScaleType.FIT_START
+ thumb.controller = controller
+
+ showToast("Loaded with Fresco!")
+ }
+
+ private fun showToast(text: String) {
+ Toast.makeText(this, text, Toast.LENGTH_SHORT).show()
+ }
+}
\ No newline at end of file
diff --git a/app/src/main/java/com/github/piasy/biv/example/LongImageActivity.java b/app/src/main/java/com/github/piasy/biv/example/LongImageActivity.java
index 0c7591e..3e48693 100644
--- a/app/src/main/java/com/github/piasy/biv/example/LongImageActivity.java
+++ b/app/src/main/java/com/github/piasy/biv/example/LongImageActivity.java
@@ -25,14 +25,16 @@
package com.github.piasy.biv.example;
import android.Manifest;
-import android.app.Dialog;
import android.net.Uri;
import android.os.Bundle;
+import android.view.LayoutInflater;
import android.view.View;
+import android.view.ViewGroup;
import android.view.WindowManager;
import android.widget.TextView;
import android.widget.Toast;
+import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AppCompatActivity;
import com.github.piasy.biv.BigImageViewer;
@@ -55,7 +57,7 @@ public class LongImageActivity extends AppCompatActivity {
private Disposable mPermissionRequest;
private Disposable mQrCodeDecode;
- private Dialog dialog;
+ private AlertDialog dialog;
@Override
protected void onCreate(Bundle savedInstanceState) {
@@ -73,36 +75,13 @@ public void onClick(View v) {
}
});
- dialog = new Dialog(this);
- dialog.setTitle(R.string.long_click_actions);
- dialog.setContentView(R.layout.dialog_long_image);
-
- final WindowManager.LayoutParams lp = new WindowManager.LayoutParams();
- lp.copyFrom(dialog.getWindow().getAttributes());
- lp.width = WindowManager.LayoutParams.MATCH_PARENT;
- dialog.getWindow().setAttributes(lp);
-
- final TextView textScan = dialog.findViewById(R.id.action_scan_qr);
- final TextView textSave = dialog.findViewById(R.id.action_save_image);
-
- textScan.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- decodeQrCode();
- }
- });
-
- textSave.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- saveImage();
- }
- });
-
mBigImageView.setOnLongClickListener(new View.OnLongClickListener() {
@Override
public boolean onLongClick(View v) {
+
+ dialog = showDialog();
dialog.show();
+
return true;
}
});
@@ -141,10 +120,6 @@ protected void onDestroy() {
disposePermissionRequest();
disposeQrCodeDecode();
- if (dialog.isShowing()) {
- dialog.dismiss();
- }
-
BigImageViewer.imageLoader().cancelAll();
}
@@ -195,6 +170,33 @@ public void accept(Throwable throwable) throws Exception {
});
}
+ private AlertDialog showDialog() {
+
+ final ViewGroup container = findViewById(R.id.container);
+ final AlertDialog.Builder builder = new AlertDialog.Builder(LongImageActivity.this);
+ final View rootView = LayoutInflater.from(LongImageActivity.this).inflate(R.layout.dialog_long_image, container, false);
+ builder.setView(rootView);
+
+ final TextView textScan = rootView.findViewById(R.id.action_scan_qr);
+ final TextView textSave = rootView.findViewById(R.id.action_save_image);
+
+ textScan.setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View v) {
+ decodeQrCode();
+ }
+ });
+
+ textSave.setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View v) {
+ saveImage();
+ }
+ });
+
+ return builder.create();
+ }
+
private void disposePermissionRequest() {
if (mPermissionRequest != null) {
mPermissionRequest.dispose();
diff --git a/app/src/main/java/com/github/piasy/biv/example/MainActivity.java b/app/src/main/java/com/github/piasy/biv/example/MainActivity.java
index 5c4a3ef..47b959f 100644
--- a/app/src/main/java/com/github/piasy/biv/example/MainActivity.java
+++ b/app/src/main/java/com/github/piasy/biv/example/MainActivity.java
@@ -84,5 +84,11 @@ public void onClick(View v) {
startActivity(new Intent(MainActivity.this, ImageTypesActivity.class));
}
});
+ findViewById(R.id.mSharedTransition).setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View v) {
+ startActivity(new Intent(MainActivity.this, FirstAnimActivity.class));
+ }
+ });
}
}
diff --git a/app/src/main/java/com/github/piasy/biv/example/SecondAnimActivity.kt b/app/src/main/java/com/github/piasy/biv/example/SecondAnimActivity.kt
new file mode 100644
index 0000000..870052d
--- /dev/null
+++ b/app/src/main/java/com/github/piasy/biv/example/SecondAnimActivity.kt
@@ -0,0 +1,176 @@
+package com.github.piasy.biv.example
+
+import android.app.Activity
+import android.app.SharedElementCallback
+import android.content.Intent
+import android.os.Build
+import android.os.Bundle
+import android.transition.Transition
+import android.util.Log
+import android.view.MenuItem
+import android.view.View
+import android.widget.ImageView
+import android.widget.Toast
+import androidx.appcompat.app.AppCompatActivity
+import androidx.core.app.ActivityOptionsCompat
+import androidx.core.net.toUri
+import com.facebook.drawee.backends.pipeline.Fresco
+import com.facebook.drawee.view.SimpleDraweeView
+import com.github.piasy.biv.BigImageViewer
+import com.github.piasy.biv.loader.fresco.FrescoImageLoader
+import com.github.piasy.biv.loader.glide.GlideImageLoader
+import com.github.piasy.biv.view.BigImageView
+import com.github.piasy.biv.view.FrescoImageViewFactory
+import com.github.piasy.biv.view.GlideImageViewFactory
+import com.github.piasy.biv.view.ImageShownCallback
+
+class SecondAnimActivity : AppCompatActivity() {
+
+ companion object {
+
+ private const val THUMB_PARAM = "intent_param_thumbnail"
+ private const val SOURCE_PARAM = "intent_param_source"
+
+ private const val FLAG_USEGLIDE = "intent_param_flag_use_glide"
+ private const val FLAG_USEFRESCO = "intent_param_flag_use_fresco"
+ private const val FLAG_USEVIEWFACTORY = "intent_param_flag_use_view_factory"
+
+ fun start(activity: Activity, imageView: ImageView,
+ thumbUrl: String, sourceUrl: String,
+ useGlide: Boolean, useFresco: Boolean, useViewFactory: Boolean) {
+
+ val intent = Intent(activity, SecondAnimActivity::class.java)
+ intent.putExtra(THUMB_PARAM, thumbUrl)
+ intent.putExtra(SOURCE_PARAM, sourceUrl)
+
+ intent.putExtra(FLAG_USEGLIDE, useGlide)
+ intent.putExtra(FLAG_USEFRESCO, useFresco)
+ intent.putExtra(FLAG_USEVIEWFACTORY, useViewFactory)
+
+ val transitionName = activity.resources.getString(R.string.transition_name)
+ val options = ActivityOptionsCompat.makeSceneTransitionAnimation(activity, imageView, transitionName)
+ val bundle = options.toBundle()
+
+ if (Build.VERSION.SDK_INT >= 16) {
+
+ if (Build.VERSION.SDK_INT >= 21) {
+ activity.setExitSharedElementCallback(object : SharedElementCallback() {
+
+ override fun onSharedElementEnd(
+ names: MutableList?,
+ elements: MutableList?,
+ snapshots: MutableList?
+ ) {
+ super.onSharedElementEnd(names, elements, snapshots)
+
+ elements?.forEach {
+ if (it is SimpleDraweeView) {
+ it.post { it.setVisibility(View.VISIBLE) }
+ }
+ }
+ }
+ })
+ }
+
+ activity.startActivity(intent, bundle)
+ } else {
+ Log.i("SecondAnimActivity", "Animation not available for this SDK Versions.")
+ }
+ }
+ }
+
+ private val thumbUrl by lazy { intent.getStringExtra(THUMB_PARAM)!! }
+ private val sourceUrl by lazy { intent.getStringExtra(SOURCE_PARAM)!! }
+
+ private val useGlide by lazy { intent.getBooleanExtra(FLAG_USEGLIDE, true) }
+ private val useFresco by lazy { intent.getBooleanExtra(FLAG_USEFRESCO, false) }
+ private val useViewFactory by lazy { intent.getBooleanExtra(FLAG_USEVIEWFACTORY, false) }
+
+ private val biv by lazy { findViewById(R.id.sourceView) }
+
+ override fun onCreate(savedInstanceState: Bundle?) {
+ Fresco.initialize(this)
+
+ super.onCreate(savedInstanceState)
+
+ if (useGlide) {
+ BigImageViewer.initialize(GlideImageLoader.with(applicationContext))
+ }
+
+ if (useFresco) {
+ BigImageViewer.initialize(FrescoImageLoader.with(applicationContext))
+ }
+
+ setContentView(R.layout.activity_anim_second)
+
+ if (Build.VERSION.SDK_INT >= 21) {
+
+ setEnterSharedElementCallback(object : SharedElementCallback() {
+
+ override fun onSharedElementEnd(
+ names: MutableList?,
+ elements: MutableList?,
+ snapshots: MutableList?
+ ) {
+ super.onSharedElementEnd(names, elements, snapshots)
+
+ elements?.forEach {
+ if (it is SimpleDraweeView) {
+ it.post { it.setVisibility(View.VISIBLE) }
+ }
+ }
+ }
+ })
+
+ window.sharedElementEnterTransition.addListener(object : Transition.TransitionListener {
+
+ override fun onTransitionStart(transition: Transition?) {}
+ override fun onTransitionCancel(transition: Transition?) {}
+ override fun onTransitionPause(transition: Transition?) {}
+ override fun onTransitionResume(transition: Transition?) {}
+
+ override fun onTransitionEnd(transition: Transition?) {
+
+ biv.loadMainImageNow()
+ }
+ })
+ }
+
+ if (useGlide && useViewFactory) {
+ biv.setImageViewFactory(GlideImageViewFactory())
+ }
+
+ if (useFresco && useViewFactory) {
+ biv.setImageViewFactory(FrescoImageViewFactory())
+ }
+
+ biv.setImageShownCallback(object : ImageShownCallback {
+
+ override fun onThumbnailShown() {
+ showToast("onThumbnailShown triggered!")
+ }
+
+ override fun onMainImageShown() {
+ showToast("onMainImageShown triggered!")
+ }
+ })
+
+ biv.showImage(thumbUrl.toUri(), sourceUrl.toUri(), true)
+ }
+
+ override fun onOptionsItemSelected(item: MenuItem): Boolean {
+
+ when(item.itemId) {
+ android.R.id.home -> {
+ supportFinishAfterTransition()
+ return true
+ }
+ }
+
+ return super.onOptionsItemSelected(item)
+ }
+
+ private fun showToast(text: String) {
+ Toast.makeText(this, text, Toast.LENGTH_SHORT).show()
+ }
+}
\ No newline at end of file
diff --git a/app/src/main/res/layout/activity_anim_first.xml b/app/src/main/res/layout/activity_anim_first.xml
new file mode 100644
index 0000000..149a2ca
--- /dev/null
+++ b/app/src/main/res/layout/activity_anim_first.xml
@@ -0,0 +1,63 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/app/src/main/res/layout/activity_anim_second.xml b/app/src/main/res/layout/activity_anim_second.xml
new file mode 100644
index 0000000..38e56ca
--- /dev/null
+++ b/app/src/main/res/layout/activity_anim_second.xml
@@ -0,0 +1,31 @@
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/app/src/main/res/layout/activity_big_image.xml b/app/src/main/res/layout/activity_big_image.xml
index 456665d..b375f9a 100644
--- a/app/src/main/res/layout/activity_big_image.xml
+++ b/app/src/main/res/layout/activity_big_image.xml
@@ -1,24 +1,25 @@
+
+
-
+ app:optimizeDisplay="true"
+ app:failureImage="@drawable/ic_cloud_off_white"
+ app:failureImageInitScaleType="center"
+ />
+ android:id="@+id/mBtnLoad"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:text="@string/bttn_load"
+ />
diff --git a/app/src/main/res/layout/activity_custom_ssiv.xml b/app/src/main/res/layout/activity_custom_ssiv.xml
index c54d2ce..688eff1 100644
--- a/app/src/main/res/layout/activity_custom_ssiv.xml
+++ b/app/src/main/res/layout/activity_custom_ssiv.xml
@@ -28,8 +28,7 @@
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
- tools:context="com.github.piasy.biv.example.CustomSSIVActivity"
- >
+ tools:context="com.github.piasy.biv.example.CustomSSIVActivity">
diff --git a/app/src/main/res/layout/activity_image_type.xml b/app/src/main/res/layout/activity_image_type.xml
index 2398142..d1b3c96 100644
--- a/app/src/main/res/layout/activity_image_type.xml
+++ b/app/src/main/res/layout/activity_image_type.xml
@@ -53,7 +53,7 @@
@@ -77,7 +77,7 @@
@@ -94,7 +94,7 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="10dp"
- android:text="load"
+ android:text="@string/bttn_load"
/>
diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml
index 411f0e4..6589e89 100644
--- a/app/src/main/res/layout/activity_main.xml
+++ b/app/src/main/res/layout/activity_main.xml
@@ -1,57 +1,72 @@
+ xmlns:android="http://schemas.android.com/apk/res/android"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
+ android:orientation="vertical"
+ >
-
-
-
+ android:id="@+id/mFresco"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:layout_margin="8dp"
+ android:text="@string/main_fresco"
+ />
+
+
+
+
diff --git a/app/src/main/res/layout/activity_scale_type.xml b/app/src/main/res/layout/activity_scale_type.xml
index 3e5cb43..77f72d7 100644
--- a/app/src/main/res/layout/activity_scale_type.xml
+++ b/app/src/main/res/layout/activity_scale_type.xml
@@ -4,8 +4,8 @@
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
- android:background="@android:color/black"
- >
+ android:background="@android:color/black">
+
diff --git a/app/src/main/res/layout/item_recycler_view.xml b/app/src/main/res/layout/item_recycler_view.xml
index b8c9cc0..c7ada93 100644
--- a/app/src/main/res/layout/item_recycler_view.xml
+++ b/app/src/main/res/layout/item_recycler_view.xml
@@ -1,9 +1,9 @@
+ xmlns:app="http://schemas.android.com/apk/res-auto"
+ android:orientation="vertical"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent">
-
- 64dp
-
diff --git a/app/src/main/res/values/dimens.xml b/app/src/main/res/values/dimens.xml
deleted file mode 100644
index 47c8224..0000000
--- a/app/src/main/res/values/dimens.xml
+++ /dev/null
@@ -1,5 +0,0 @@
-
-
- 16dp
- 16dp
-
diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml
index c0ee3fa..efeddef 100644
--- a/app/src/main/res/values/strings.xml
+++ b/app/src/main/res/values/strings.xml
@@ -1,13 +1,36 @@
BIV
+ fresco loader
+ glide loader
+ long image
+ scale type
+ image loader callback
+ Custom SSIV
+ Recycler
+ image types
+ shared elem. transition
+
+ Load
+
+ Use Glide
+ Use Fresco
+
+ Use view factory
+
+ Image Loader:
+ Image Type:
+ First Activity:
+ Second Activity:
+
+ shared_transition_element_view
+
+ Thumbnail Image
+ Source Image
+
Actions:
recognize qr code
save to gallery
-
- - @string/scan_qr_code
- - @string/save_image
-
centerCrop
centerInside
diff --git a/app/src/main/res/values/styles.xml b/app/src/main/res/values/styles.xml
index 1c56072..4292136 100644
--- a/app/src/main/res/values/styles.xml
+++ b/app/src/main/res/values/styles.xml
@@ -1,4 +1,4 @@
-
+
+
+
diff --git a/build.gradle b/build.gradle
index 6e85e3c..106e856 100644
--- a/build.gradle
+++ b/build.gradle
@@ -34,6 +34,8 @@ buildscript {
}
dependencies {
classpath 'com.android.tools.build:gradle:3.5.1'
+ classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.3.50"
+
classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.8.4'
classpath 'com.github.dcendents:android-maven-gradle-plugin:2.1'
@@ -87,6 +89,6 @@ ext {
frescoVersion = '2.0.0'
glideVersion = '4.10.0'
- okhttpVersion = '4.2.1'
+ okhttpVersion = '4.2.2'
ssivVersion = '3.10.0'
}