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

added test environment for all combinations of shared element trans. #176

Merged
merged 6 commits into from
Oct 16, 2019
Merged
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
129 changes: 102 additions & 27 deletions BigImageViewer/src/main/java/com/github/piasy/biv/view/BigImageView.java
Original file line number Diff line number Diff line change
@@ -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) {
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.github.piasy.biv.view;

import androidx.annotation.UiThread;

@UiThread
public interface ImageShownCallback {

void onThumbnailShown();
void onMainImageShown();
}
Original file line number Diff line number Diff line change
@@ -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,29 +39,53 @@
*/
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:
return createStillImageView(context);
}
}

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);
}
}
}
Original file line number Diff line number Diff line change
@@ -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;
}
}
}
Loading