Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

corrected exit tranisition animation with zoom #179

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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.
* <p>
Expand Down Expand Up @@ -114,6 +116,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;
Expand Down Expand Up @@ -166,6 +169,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()) {
Expand Down Expand Up @@ -386,6 +391,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;
Expand All @@ -412,7 +492,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,
Expand Down Expand Up @@ -536,14 +616,15 @@ 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);

mThumbnailView.setOnClickListener(mOnClickListener);
mThumbnailView.setOnLongClickListener(mOnLongClickListener);

if (mThumbnailView instanceof ImageView) {

mViewFactory.loadThumbnailContent(mThumbnailView, image);

if (mImageShownCallback != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
1 change: 1 addition & 0 deletions BigImageViewer/src/main/res/values/attrs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -58,5 +58,6 @@
<enum name="fitStart" value="5" />
<enum name="fitXY" value="6" />
</attr>
<attr name="thumbnailAdjustViewBounds" format="boolean"/>
</declare-styleable>
</resources>
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand All @@ -83,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:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -64,16 +63,11 @@ class FirstAnimFrescoActivity : AppCompatActivity() {
}
})

val useGlide = findViewById<RadioButton>(R.id.use_glide)
val useFresco = findViewById<RadioButton>(R.id.use_fresco)
val useViewFactory = findViewById<CheckBox>(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,
useGlide = false, useFresco = true, useViewFactory = useViewFactory.isChecked)
}

thumb.setLegacyVisibilityHandlingEnabled(true)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,40 +3,61 @@ 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

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<ImageView>(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 useGlide = findViewById<RadioButton>(R.id.use_glide)
val useFresco = findViewById<RadioButton>(R.id.use_fresco)
val useViewFactory = findViewById<CheckBox>(R.id.check_use_view_factory)
val useTallImage = findViewById<CheckBox>(R.id.check_use_tall_image)

thumb.setOnClickListener {
SecondAnimActivity.start(
this, thumb,
THUMB_URL, SOURCE_URL,
useGlide.isChecked, useFresco.isChecked, 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)
}
}
}
Loading