Skip to content
This repository has been archived by the owner on Jul 29, 2020. It is now read-only.

Commit

Permalink
add possibility for call zoom using other image component
Browse files Browse the repository at this point in the history
  • Loading branch information
oliveiradev committed Aug 10, 2016
1 parent c0629ef commit b963347
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,15 @@

import android.app.Activity;
import android.content.Context;
import android.content.pm.ActivityInfo;
import android.content.res.TypedArray;
import android.graphics.Canvas;
import android.graphics.Rect;
import android.graphics.drawable.Drawable;
import android.os.Handler;
import android.support.v7.widget.Toolbar;
import android.util.AttributeSet;
import android.util.Log;
import android.view.ContextThemeWrapper;
import android.widget.ImageButton;

import com.github.oliveiradev.image_zoom.lib.R;
import com.github.oliveiradev.image_zoom.lib.animation.ZoomAnimation;

import java.util.Timer;
import java.util.TimerTask;

/**
* Created by felipe on 22/04/16.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.github.oliveiradev.image_zoom.lib.animation;
package com.github.oliveiradev.image_zoom.lib.widget;

import android.animation.Animator;
import android.animation.AnimatorListenerAdapter;
Expand Down Expand Up @@ -31,7 +31,7 @@ public final class ZoomAnimation {
private static boolean isLandScapeScreen;
private static ContentFrameLayout container;

public static void zoom(View view, Activity activity, boolean isLandScape) {
protected static void zoom(View view, Activity activity, boolean isLandScape) {
zoomImageFromThumb(view, activity, isLandScape);
}

Expand Down Expand Up @@ -90,6 +90,63 @@ public void onClick(View v) {

}

public static void zoom(View view, Drawable drawable, Activity activity, boolean isLandScape) {
zoomImageFromThumb(view, drawable, activity, isLandScape);
}

private static void zoomImageFromThumb(final View thumbView,final Drawable drawable, final Activity activity, boolean isLandScape) {
isLandScapeScreen = isLandScape;

if (mCurrentAnimator != null) {
mCurrentAnimator.cancel();
}

container = (ContentFrameLayout) activity.findViewById(android.R.id.content);

mImageZoom = new ImageView(thumbView.getContext());
mCurrentImage = ((BitmapDrawable)drawable).getBitmap();

final Rect startBounds = new Rect();
final Rect finalBounds = new Rect();
final Point globalOffset = new Point();

thumbView.getGlobalVisibleRect(startBounds);
container.getGlobalVisibleRect(finalBounds, globalOffset);
startBounds.offset(-globalOffset.x, -globalOffset.y);
finalBounds.offset(-globalOffset.x, -globalOffset.y);

final float startScale;
if ((float) finalBounds.width() / finalBounds.height()
> (float) startBounds.width() / startBounds.height()) {
startScale = (float) startBounds.height() / finalBounds.height();
float startWidth = startScale * finalBounds.width();
float deltaWidth = (startWidth - startBounds.width()) / 2;
startBounds.left -= deltaWidth;
startBounds.right += deltaWidth;
} else {
// Extend start bounds vertically
startScale = (float) startBounds.width() / finalBounds.width();
float startHeight = startScale * finalBounds.height();
float deltaHeight = (startHeight - startBounds.height()) / 2;
startBounds.top -= deltaHeight;
startBounds.bottom += deltaHeight;
}

final Pair<Rect, Rect> bounds = new Pair<>(startBounds, finalBounds);
thumbView.setAlpha(0f);

final float startScaleFinal = startScale;

zoomIn(mImageZoom, bounds, startScale);

mImageZoom.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
zoomOut(thumbView, (ImageView) v, bounds, startScaleFinal);
}
});

}

private static void zoomIn(final ImageView imageZoom, Pair<Rect, Rect> bounds, float startScale) {
if (isLandScapeScreen)
Expand Down

0 comments on commit b963347

Please sign in to comment.