Skip to content

Commit

Permalink
Added speed up coefficient to fix "image to fill crop rect" animation.
Browse files Browse the repository at this point in the history
  • Loading branch information
shliama committed Feb 1, 2016
1 parent b994c72 commit 6f42014
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ buildscript {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.0.0-alpha8'
classpath 'com.android.tools.build:gradle:2.0.0-alpha9'

// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
Expand Down
23 changes: 20 additions & 3 deletions ucrop/src/main/java/com/yalantis/ucrop/view/CropImageView.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.util.AttributeSet;
import android.util.Log;

import com.yalantis.ucrop.R;
import com.yalantis.ucrop.util.CubicEasing;
Expand All @@ -27,7 +28,7 @@
public abstract class CropImageView extends TransformImageView {

public static final int DEFAULT_MAX_BITMAP_SIZE = 0;
public static final int DEFAULT_IMAGE_TO_CROP_BOUNDS_ANIM_DURATION = 777;
public static final int DEFAULT_IMAGE_TO_CROP_BOUNDS_ANIM_DURATION = 500;
public static final float DEFAULT_MAX_SCALE_MULTIPLIER = 10.0f;
public static final float SOURCE_IMAGE_ASPECT_RATIO = 0f;
public static final float DEFAULT_ASPECT_RATIO = SOURCE_IMAGE_ASPECT_RATIO;
Expand Down Expand Up @@ -509,6 +510,10 @@ private static class WrapCropBoundsRunnable implements Runnable {
private final float mDeltaScale;
private final boolean mWillBeImageInBoundsAfterTranslate;

private float mSpeedUpCoefficient = 1;

private static final String TAG = "WrapCropBoundsRunnable";

public WrapCropBoundsRunnable(CropImageView cropImageView,
long durationMs,
float oldX, float oldY,
Expand All @@ -527,6 +532,10 @@ public WrapCropBoundsRunnable(CropImageView cropImageView,
mOldScale = oldScale;
mDeltaScale = deltaScale;
mWillBeImageInBoundsAfterTranslate = willBeImageInBoundsAfterTranslate;

if (mCenterDiffY != 0 && mCenterDiffX != 0){
mSpeedUpCoefficient = Math.abs(mCenterDiffX / mCenterDiffY);
}
}

@Override
Expand All @@ -539,8 +548,16 @@ public void run() {
long now = System.currentTimeMillis();
float currentMs = Math.min(mDurationMs, now - mStartTime);

float newX = CubicEasing.easeOut(currentMs, 0, mCenterDiffX, mDurationMs);
float newY = CubicEasing.easeOut(currentMs, 0, mCenterDiffY, mDurationMs);
float newX, newY;
if (mSpeedUpCoefficient > 1) {
newX = CubicEasing.easeOut(currentMs, 0, mCenterDiffX, mDurationMs);
newY = CubicEasing.easeOut(currentMs, 0, mCenterDiffY, mDurationMs / mSpeedUpCoefficient);
newY = (Math.abs(newY) > Math.abs(mCenterDiffY)) ? mCenterDiffY : newY;
} else {
newX = CubicEasing.easeOut(currentMs, 0, mCenterDiffX, mDurationMs * mSpeedUpCoefficient);
newX = (Math.abs(newX) > Math.abs(mCenterDiffX)) ? mCenterDiffX : newX;
newY = CubicEasing.easeOut(currentMs, 0, mCenterDiffY, mDurationMs);
}
float newScale = CubicEasing.easeInOut(currentMs, 0, mDeltaScale, mDurationMs);

if (currentMs < mDurationMs) {
Expand Down

0 comments on commit 6f42014

Please sign in to comment.