From ea83710fd6a3fd7128636205bb5ce7d10d075cb7 Mon Sep 17 00:00:00 2001 From: luca Date: Sat, 19 Oct 2019 13:43:07 +0200 Subject: [PATCH 1/5] first debug and test --- .../github/piasy/biv/view/BigImageView.java | 10 ++++++-- .../piasy/biv/view/ImageViewFactory.java | 3 ++- BigImageViewer/src/main/res/values/attrs.xml | 1 + .../biv/view/FrescoImageViewFactory.java | 7 +++--- .../biv/example/FirstAnimFrescoActivity.kt | 10 ++------ .../biv/example/FirstAnimGlideActivity.kt | 10 ++------ .../piasy/biv/example/SecondAnimActivity.kt | 6 +++-- .../res/layout/activity_anim_first_fresco.xml | 24 ------------------- .../res/layout/activity_anim_first_glide.xml | 24 ------------------- .../main/res/layout/activity_anim_second.xml | 1 + 10 files changed, 24 insertions(+), 72 deletions(-) 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 53f74c5..1fec49a 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 @@ -114,6 +114,7 @@ public class BigImageView extends FrameLayout implements ImageLoader.Callback { private ProgressIndicator mProgressIndicator; private DisplayOptimizeListener mDisplayOptimizeListener; private int mInitScaleType; + private boolean mThumbnailAdjustViewBounds; private ImageView.ScaleType mThumbnailScaleType; private ImageView.ScaleType mFailureImageScaleType; private boolean mOptimizeDisplay; @@ -167,6 +168,8 @@ public BigImageView(Context context, AttributeSet attrs, int defStyleAttr) { mOptimizeDisplay = array.getBoolean(R.styleable.BigImageView_optimizeDisplay, true); mTapToRetry = array.getBoolean(R.styleable.BigImageView_tapToRetry, true); + mThumbnailAdjustViewBounds = array.getBoolean(R.styleable.BigImageView_thumbnailAdjustViewBounds, false); + array.recycle(); if (isInEditMode()) { @@ -413,7 +416,7 @@ 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(), mThumbnailScaleType, - true); + mThumbnailAdjustViewBounds, true); mViewFactory.loadThumbnailContent(mThumbnailView, mThumbnail); if (mThumbnailView != null) { addView(mThumbnailView, ViewGroup.LayoutParams.MATCH_PARENT, @@ -537,7 +540,7 @@ private void doShowImage(final int imageType, final File image, } mThumbnailView = mViewFactory.createThumbnailView(getContext(), mThumbnailScaleType, - false); + mThumbnailAdjustViewBounds,false); if (mThumbnailView != null) { addView(mThumbnailView, LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT); @@ -545,6 +548,9 @@ private void doShowImage(final int imageType, final File image, mThumbnailView.setOnLongClickListener(mOnLongClickListener); if (mThumbnailView instanceof ImageView) { + ((ImageView) mThumbnailView).setAdjustViewBounds(true); + ((ImageView) mThumbnailView).setScaleType(ImageView.ScaleType.FIT_START); + mViewFactory.loadThumbnailContent(mThumbnailView, image); if (mImageShownCallback != null) { 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 b25203a..d9174d3 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 @@ -80,8 +80,9 @@ public void loadAnimatedContent(final View view, final int imageType, final File } public View createThumbnailView(final Context context, final ImageView.ScaleType scaleType, - final boolean willLoadFromNetwork) { + final boolean adjustViewBounds, final boolean willLoadFromNetwork) { final ImageView thumbnailView = new ImageView(context); + thumbnailView.setAdjustViewBounds(adjustViewBounds); if (scaleType != null) { thumbnailView.setScaleType(scaleType); } diff --git a/BigImageViewer/src/main/res/values/attrs.xml b/BigImageViewer/src/main/res/values/attrs.xml index 8ab68ce..36d2d61 100644 --- a/BigImageViewer/src/main/res/values/attrs.xml +++ b/BigImageViewer/src/main/res/values/attrs.xml @@ -58,5 +58,6 @@ + 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 6b6c96d..aae447f 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 @@ -59,17 +59,18 @@ public final void loadAnimatedContent(final View view, final int imageType, } @Override - public final View createThumbnailView(final Context context, - final ImageView.ScaleType scaleType, final boolean willLoadFromNetwork) { + public final View createThumbnailView(final Context context, final ImageView.ScaleType scaleType, + final boolean adjustViewBounds, final boolean willLoadFromNetwork) { if (willLoadFromNetwork) { final SimpleDraweeView thumbnailView = new SimpleDraweeView(context); if (scaleType != null) { thumbnailView.getHierarchy().setActualImageScaleType(scaleType(scaleType)); + thumbnailView.setAdjustViewBounds(adjustViewBounds); } return thumbnailView; } else { - return super.createThumbnailView(context, scaleType, false); + return super.createThumbnailView(context, scaleType, adjustViewBounds, false); } } diff --git a/app/src/main/java/com/github/piasy/biv/example/FirstAnimFrescoActivity.kt b/app/src/main/java/com/github/piasy/biv/example/FirstAnimFrescoActivity.kt index 78b7afe..709b67d 100644 --- a/app/src/main/java/com/github/piasy/biv/example/FirstAnimFrescoActivity.kt +++ b/app/src/main/java/com/github/piasy/biv/example/FirstAnimFrescoActivity.kt @@ -27,7 +27,6 @@ package com.github.piasy.biv.example import android.os.Bundle import android.view.View import android.widget.CheckBox -import android.widget.RadioButton import androidx.appcompat.app.AppCompatActivity import androidx.core.app.ActivityCompat import androidx.core.app.SharedElementCallback @@ -64,16 +63,11 @@ class FirstAnimFrescoActivity : AppCompatActivity() { } }) - val useGlide = findViewById(R.id.use_glide) - val useFresco = findViewById(R.id.use_fresco) val useViewFactory = findViewById(R.id.check_use_view_factory) thumb.setOnClickListener { - SecondAnimActivity.start( - this, thumb, - THUMB_URL, SOURCE_URL, - useGlide.isChecked, useFresco.isChecked, useViewFactory.isChecked - ) + SecondAnimActivity.start(this, thumb, THUMB_URL, SOURCE_URL, + false, true, useViewFactory.isChecked) } thumb.setLegacyVisibilityHandlingEnabled(true) diff --git a/app/src/main/java/com/github/piasy/biv/example/FirstAnimGlideActivity.kt b/app/src/main/java/com/github/piasy/biv/example/FirstAnimGlideActivity.kt index d3898ec..7185369 100644 --- a/app/src/main/java/com/github/piasy/biv/example/FirstAnimGlideActivity.kt +++ b/app/src/main/java/com/github/piasy/biv/example/FirstAnimGlideActivity.kt @@ -3,7 +3,6 @@ package com.github.piasy.biv.example import android.os.Bundle import android.widget.CheckBox import android.widget.ImageView -import android.widget.RadioButton import androidx.appcompat.app.AppCompatActivity import com.bumptech.glide.Glide @@ -22,16 +21,11 @@ class FirstAnimGlideActivity : AppCompatActivity() { super.onCreate(savedInstanceState) setContentView(R.layout.activity_anim_first_glide) - val useGlide = findViewById(R.id.use_glide) - val useFresco = findViewById(R.id.use_fresco) val useViewFactory = findViewById(R.id.check_use_view_factory) thumb.setOnClickListener { - SecondAnimActivity.start( - this, thumb, - THUMB_URL, SOURCE_URL, - useGlide.isChecked, useFresco.isChecked, useViewFactory.isChecked - ) + SecondAnimActivity.start(this, thumb, THUMB_URL, SOURCE_URL, + true, false, useViewFactory.isChecked) } val glide = Glide.with(this) 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 index 870052d..664bf3b 100644 --- a/app/src/main/java/com/github/piasy/biv/example/SecondAnimActivity.kt +++ b/app/src/main/java/com/github/piasy/biv/example/SecondAnimActivity.kt @@ -53,7 +53,7 @@ class SecondAnimActivity : AppCompatActivity() { if (Build.VERSION.SDK_INT >= 16) { - if (Build.VERSION.SDK_INT >= 21) { + if (useFresco && Build.VERSION.SDK_INT >= 21) { activity.setExitSharedElementCallback(object : SharedElementCallback() { override fun onSharedElementEnd( @@ -89,7 +89,9 @@ class SecondAnimActivity : AppCompatActivity() { private val biv by lazy { findViewById(R.id.sourceView) } override fun onCreate(savedInstanceState: Bundle?) { - Fresco.initialize(this) + if (useFresco) { + Fresco.initialize(this) + } super.onCreate(savedInstanceState) diff --git a/app/src/main/res/layout/activity_anim_first_fresco.xml b/app/src/main/res/layout/activity_anim_first_fresco.xml index d678808..aac568b 100644 --- a/app/src/main/res/layout/activity_anim_first_fresco.xml +++ b/app/src/main/res/layout/activity_anim_first_fresco.xml @@ -42,30 +42,6 @@ android:text="@string/header_first_activity" /> - - - - - - - - - - - - - - - - \ No newline at end of file From 2a1b7fdbda5e3f3cbaab1ca0ca25f5e6e4431849 Mon Sep 17 00:00:00 2001 From: luca Date: Sat, 19 Oct 2019 19:00:17 +0200 Subject: [PATCH 2/5] fix transition --- .../github/piasy/biv/view/BigImageView.java | 2 -- .../piasy/biv/example/SecondAnimActivity.kt | 30 ++++++++++--------- .../main/res/layout/activity_anim_second.xml | 1 + 3 files changed, 17 insertions(+), 16 deletions(-) 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 1fec49a..1ad97d4 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 @@ -548,8 +548,6 @@ private void doShowImage(final int imageType, final File image, mThumbnailView.setOnLongClickListener(mOnLongClickListener); if (mThumbnailView instanceof ImageView) { - ((ImageView) mThumbnailView).setAdjustViewBounds(true); - ((ImageView) mThumbnailView).setScaleType(ImageView.ScaleType.FIT_START); mViewFactory.loadThumbnailContent(mThumbnailView, image); 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 index 664bf3b..9a23e07 100644 --- a/app/src/main/java/com/github/piasy/biv/example/SecondAnimActivity.kt +++ b/app/src/main/java/com/github/piasy/biv/example/SecondAnimActivity.kt @@ -107,22 +107,24 @@ class SecondAnimActivity : AppCompatActivity() { 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) } + if (useFresco) { + 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 { diff --git a/app/src/main/res/layout/activity_anim_second.xml b/app/src/main/res/layout/activity_anim_second.xml index 450b9a6..f0f355f 100644 --- a/app/src/main/res/layout/activity_anim_second.xml +++ b/app/src/main/res/layout/activity_anim_second.xml @@ -27,6 +27,7 @@ android:transitionName="@string/transition_name" android:contentDescription="@string/content_desc_source" app:thumbnailScaleType="fitStart" + app:thumbnailAdjustViewBounds="true" /> \ No newline at end of file From 6cb8e3c8726aad79f67e4f8574fbc9979d393753 Mon Sep 17 00:00:00 2001 From: luca Date: Tue, 22 Oct 2019 13:09:55 +0200 Subject: [PATCH 3/5] added scale control to biv, added to sample app scale out for exit animation --- .../github/piasy/biv/view/BigImageView.java | 77 +++++++++++++++++++ .../piasy/biv/example/SecondAnimActivity.kt | 63 +++++++++++++++ .../main/res/layout/activity_anim_second.xml | 34 ++++++++ app/src/main/res/values/strings.xml | 4 + 4 files changed, 178 insertions(+) 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 1ad97d4..22549d6 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 @@ -55,6 +55,8 @@ import java.util.ArrayList; import java.util.List; +import static com.davemorrissey.labs.subscaleview.SubsamplingScaleImageView.EASE_OUT_QUAD; + /** * Created by Piasy{github.com/Piasy} on 06/11/2016. *

@@ -390,6 +392,81 @@ public SubsamplingScaleImageView getSSIV() { return mSSIV; } + public boolean isZoomEnabled() { + if (mSSIV != null) { + return mSSIV.isZoomEnabled(); + } else { + return false; + } + } + + public float getCurrentScale() { + if(mSSIV != null) { + return mSSIV.getScale(); + } else { + return 0; + } + } + + public void animateMinScale(final int duration) { + animateMinScale(duration, null); + } + + public void animateMinScale(final int duration, + final SubsamplingScaleImageView.OnAnimationEventListener listener) { + + if (mSSIV != null && mSSIV.isReady()) { + animateToScale(mSSIV.getMinScale(), duration, listener); + } + } + + public void animateMaxScale(final int duration) { + animateMaxScale(duration, null); + } + + public void animateMaxScale(final int duration, + final SubsamplingScaleImageView.OnAnimationEventListener listener) { + + if (mSSIV != null && mSSIV.isReady()) { + animateToScale(mSSIV.getMaxScale(), duration, listener); + } + } + + public void animateToScale(final float scale, final int duration) { + animateToScale(scale, duration, null); + } + + public void animateToScale(final float scale, final int duration, + final SubsamplingScaleImageView.OnAnimationEventListener listener) { + + if (mSSIV != null && mSSIV.isReady()) { + final SubsamplingScaleImageView.AnimationBuilder builder = mSSIV.animateScale(scale); + if (builder != null) { + builder.withDuration(duration) + .withEasing(EASE_OUT_QUAD) + .withInterruptible(false) + .withOnAnimationEventListener(listener) + .start(); + } + } + } + + public float getMinScale() { + if (mSSIV != null) { + return mSSIV.getMinScale(); + } else { + return 0; + } + } + + public float getMaxScale() { + if (mSSIV != null) { + return mSSIV.getMaxScale(); + } else { + return 0; + } + } + @Override public void onCacheHit(final int imageType, final File image) { mCurrentImageFile = image; 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 index 9a23e07..6d6cb30 100644 --- a/app/src/main/java/com/github/piasy/biv/example/SecondAnimActivity.kt +++ b/app/src/main/java/com/github/piasy/biv/example/SecondAnimActivity.kt @@ -14,6 +14,7 @@ import android.widget.Toast import androidx.appcompat.app.AppCompatActivity import androidx.core.app.ActivityOptionsCompat import androidx.core.net.toUri +import com.davemorrissey.labs.subscaleview.SubsamplingScaleImageView import com.facebook.drawee.backends.pipeline.Fresco import com.facebook.drawee.view.SimpleDraweeView import com.github.piasy.biv.BigImageViewer @@ -23,6 +24,7 @@ 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 +import com.google.android.material.button.MaterialButton class SecondAnimActivity : AppCompatActivity() { @@ -35,6 +37,9 @@ class SecondAnimActivity : AppCompatActivity() { private const val FLAG_USEFRESCO = "intent_param_flag_use_fresco" private const val FLAG_USEVIEWFACTORY = "intent_param_flag_use_view_factory" + private const val ANIM_DURATION = 500 + private const val ANIM_QUICK_DURATION = 200 + fun start(activity: Activity, imageView: ImageView, thumbUrl: String, sourceUrl: String, useGlide: Boolean, useFresco: Boolean, useViewFactory: Boolean) { @@ -88,6 +93,10 @@ class SecondAnimActivity : AppCompatActivity() { private val biv by lazy { findViewById(R.id.sourceView) } + private val minScale by lazy { findViewById(R.id.min_scale) } + private val maxScale by lazy { findViewById(R.id.max_scale) } + private val halfScale by lazy { findViewById(R.id.half_scale) } + override fun onCreate(savedInstanceState: Bundle?) { if (useFresco) { Fresco.initialize(this) @@ -148,6 +157,25 @@ class SecondAnimActivity : AppCompatActivity() { biv.setImageViewFactory(FrescoImageViewFactory()) } + minScale.setOnClickListener { + if (biv.isZoomEnabled) { + biv.animateMinScale(ANIM_DURATION) + } + } + + maxScale.setOnClickListener { + if (biv.isZoomEnabled) { + biv.animateMaxScale(ANIM_DURATION) + } + } + + halfScale.setOnClickListener { + if (biv.isZoomEnabled) { + val halfScale = ((biv.maxScale - biv.minScale) / 2) + biv.minScale + biv.animateToScale(halfScale, ANIM_DURATION) + } + } + biv.setImageShownCallback(object : ImageShownCallback { override fun onThumbnailShown() { @@ -174,6 +202,41 @@ class SecondAnimActivity : AppCompatActivity() { return super.onOptionsItemSelected(item) } + override fun onBackPressed() { + setResultAndFinish() + } + + override fun onNavigateUp(): Boolean { + setResultAndFinish() + return true + } + + private fun setResultAndFinish() { + if (Build.VERSION.SDK_INT >= 21) { + + if (biv.currentScale == biv.minScale) { + + finishAfterTransition() + } else { + + biv.animateMinScale(ANIM_QUICK_DURATION, object : SubsamplingScaleImageView.OnAnimationEventListener { + + override fun onComplete() { + finishAfterTransition() + } + + override fun onInterruptedByUser() { + finishAfterTransition() + } + + override fun onInterruptedByNewAnim() { + finishAfterTransition() + } + }) + } + } + } + private fun showToast(text: String) { Toast.makeText(this, text, Toast.LENGTH_SHORT).show() } diff --git a/app/src/main/res/layout/activity_anim_second.xml b/app/src/main/res/layout/activity_anim_second.xml index f0f355f..c3688c0 100644 --- a/app/src/main/res/layout/activity_anim_second.xml +++ b/app/src/main/res/layout/activity_anim_second.xml @@ -19,6 +19,40 @@ android:text="@string/header_second_activity" /> + + + + + + + + + + recognize qr code save to gallery + Min Scale + Max Scale + Half Scale + centerCrop centerInside custom From c563d1fe85b9fe933f925727c67eab3dbd12bc0f Mon Sep 17 00:00:00 2001 From: luca Date: Sun, 8 Dec 2019 12:57:15 +0100 Subject: [PATCH 4/5] working sample, with tall images --- app/build.gradle | 4 +- .../biv/example/FirstAnimFrescoActivity.kt | 2 +- .../biv/example/FirstAnimGlideActivity.kt | 43 +++++++++++++++---- .../res/layout/activity_anim_first_glide.xml | 35 ++++++++++----- .../main/res/layout/activity_anim_second.xml | 5 +-- app/src/main/res/values/strings.xml | 1 + build.gradle | 6 +-- gradle/wrapper/gradle-wrapper.properties | 2 +- 8 files changed, 70 insertions(+), 28 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index bc39f8b..6b24c2a 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -31,7 +31,7 @@ android { buildToolsVersion rootProject.ext.androidBuildToolsVersion defaultConfig { - minSdkVersion 15 + minSdkVersion 17 targetSdkVersion rootProject.ext.targetSdkVersion versionCode rootProject.ext.releaseVersionCode versionName rootProject.ext.releaseVersionName @@ -89,7 +89,7 @@ dependencies { implementation 'io.reactivex.rxjava2:rxandroid:2.1.1' implementation 'com.github.piasy:RxQrCode:1.3.0' - debugImplementation 'com.squareup.leakcanary:leakcanary-android:2.0-beta-3' + debugImplementation 'com.squareup.leakcanary:leakcanary-android:2.0' implementation project(':BigImageViewer') implementation project(':FrescoImageLoader') diff --git a/app/src/main/java/com/github/piasy/biv/example/FirstAnimFrescoActivity.kt b/app/src/main/java/com/github/piasy/biv/example/FirstAnimFrescoActivity.kt index 709b67d..21a60d3 100644 --- a/app/src/main/java/com/github/piasy/biv/example/FirstAnimFrescoActivity.kt +++ b/app/src/main/java/com/github/piasy/biv/example/FirstAnimFrescoActivity.kt @@ -67,7 +67,7 @@ class FirstAnimFrescoActivity : AppCompatActivity() { thumb.setOnClickListener { SecondAnimActivity.start(this, thumb, THUMB_URL, SOURCE_URL, - false, true, useViewFactory.isChecked) + useGlide = false, useFresco = true, useViewFactory = useViewFactory.isChecked) } thumb.setLegacyVisibilityHandlingEnabled(true) diff --git a/app/src/main/java/com/github/piasy/biv/example/FirstAnimGlideActivity.kt b/app/src/main/java/com/github/piasy/biv/example/FirstAnimGlideActivity.kt index 7185369..d062090 100644 --- a/app/src/main/java/com/github/piasy/biv/example/FirstAnimGlideActivity.kt +++ b/app/src/main/java/com/github/piasy/biv/example/FirstAnimGlideActivity.kt @@ -10,27 +10,54 @@ class FirstAnimGlideActivity : AppCompatActivity() { companion object { private const val THUMB_URL = - "https://images.unsplash.com/photo-1497240299146-17ff4089466a?dpr=2&auto=compress,format&fit=crop&w=376" + "https://images.unsplash.com/photo-1497240299146-17ff4089466a?dpr=2&auto=compress,format&fit=crop&w=376" private const val SOURCE_URL = - "https://images.unsplash.com/photo-1497240299146-17ff4089466a" + "https://images.unsplash.com/photo-1497240299146-17ff4089466a" + + private const val THUMB_URL2 = + "https://preview.redd.it/k18ckrkhrzt31.jpg?width=640&crop=smart&auto=webp&s=32ee988aaf9dd0af480cc2df104e38fd8ce73b03" + private const val SOURCE_URL2 = + "https://i.redd.it/k18ckrkhrzt31.jpg" } private val thumb by lazy { findViewById(R.id.thumbView) } + private val glide by lazy { Glide.with(this) } override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_anim_first_glide) val useViewFactory = findViewById(R.id.check_use_view_factory) + val useTallImage = findViewById(R.id.check_use_tall_image) thumb.setOnClickListener { - SecondAnimActivity.start(this, thumb, THUMB_URL, SOURCE_URL, - true, false, useViewFactory.isChecked) + SecondAnimActivity.start(this, thumb, + thumbUrl = if (!useTallImage.isChecked) THUMB_URL else THUMB_URL2, + sourceUrl = if (!useTallImage.isChecked) SOURCE_URL else SOURCE_URL2, + useGlide = true, useFresco = false, useViewFactory = useViewFactory.isChecked + ) } - val glide = Glide.with(this) - glide.asBitmap() - .load(THUMB_URL) - .into(thumb) + useTallImage.setOnCheckedChangeListener { _, isChecked -> + + loadThumb(isChecked) + } + + loadThumb(useTallImage.isChecked) + } + + private fun loadThumb(isChecked: Boolean) { + + if (isChecked) { + + glide.asBitmap() + .load(THUMB_URL2) + .into(thumb) + } else { + + glide.asBitmap() + .load(THUMB_URL) + .into(thumb) + } } } \ No newline at end of file diff --git a/app/src/main/res/layout/activity_anim_first_glide.xml b/app/src/main/res/layout/activity_anim_first_glide.xml index 335dc91..82c6caf 100644 --- a/app/src/main/res/layout/activity_anim_first_glide.xml +++ b/app/src/main/res/layout/activity_anim_first_glide.xml @@ -18,22 +18,37 @@ android:text="@string/header_first_activity" /> - + + + + + + + \ 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 index c3688c0..5915916 100644 --- a/app/src/main/res/layout/activity_anim_second.xml +++ b/app/src/main/res/layout/activity_anim_second.xml @@ -56,12 +56,11 @@ \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 6f0cf26..9014329 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -18,6 +18,7 @@ Use Fresco Use view factory + Use tall image Image Loader: Image Type: diff --git a/build.gradle b/build.gradle index fd1cdaf..f13e277 100644 --- a/build.gradle +++ b/build.gradle @@ -33,8 +33,8 @@ buildscript { } } dependencies { - classpath 'com.android.tools.build:gradle:3.5.1' - classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.3.50" + classpath 'com.android.tools.build:gradle:3.5.3' + classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.3.61" classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.8.4' @@ -84,7 +84,7 @@ ext { minSdkVersion = 14 targetSdkVersion = 29 - materialVersion = '1.1.0-beta01' + materialVersion = '1.1.0-beta02' annotationVersion = '1.1.0' frescoVersion = '2.1.0' diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index a9eb35e..372b2c4 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-5.6.2-all.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-6.0.1-all.zip From b60dffc107cdf104ce993e904b22a099ed115e06 Mon Sep 17 00:00:00 2001 From: luca Date: Fri, 13 Dec 2019 20:55:18 +0100 Subject: [PATCH 5/5] added override on GlideImageViewFactory --- .../github/piasy/biv/view/FrescoImageViewFactory.java | 10 ++++++++++ .../github/piasy/biv/view/GlideImageViewFactory.java | 9 +++++++++ 2 files changed, 19 insertions(+) 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 aae447f..c6973dc 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 @@ -84,6 +84,16 @@ public void loadThumbnailContent(final View view, final Uri thumbnail) { } } + @Override + public void loadThumbnailContent(View view, File thumbnail) { + if (view instanceof SimpleDraweeView) { + final DraweeController controller = Fresco.newDraweeControllerBuilder() + .setUri(Uri.parse("file://" + thumbnail.getAbsolutePath())) + .build(); + ((SimpleDraweeView) view).setController(controller); + } + } + private ScalingUtils.ScaleType scaleType(int value) { switch (value) { case BigImageView.INIT_SCALE_TYPE_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 58acc26..b8a896b 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 @@ -89,4 +89,13 @@ public void loadThumbnailContent(final View view, final Uri thumbnail) { .into((ImageView) view); } } + + @Override + public void loadThumbnailContent(final View view, final File thumbnail) { + if (view instanceof ImageView) { + Glide.with(view.getContext()) + .load(thumbnail) + .into((ImageView) view); + } + } }