Skip to content

Commit

Permalink
Move morph methods and constants to lollipop animator
Browse files Browse the repository at this point in the history
  • Loading branch information
rubensousa committed Jun 10, 2018
1 parent 58289c3 commit 4d59ac5
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 40 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,6 @@

abstract class PreviewAnimator {

static final int MORPH_REVEAL_DURATION = 150;
static final int MORPH_MOVE_DURATION = 200;
static final int UNMORPH_MOVE_DURATION = 200;
static final int UNMORPH_UNREVEAL_DURATION = 150;

View morphView;
View previewFrameView;
FrameLayout previewFrameLayout;
Expand All @@ -48,31 +43,6 @@ public PreviewAnimator(ViewGroup parent, PreviewView previewView, View morphView

public abstract void hide();

/**
* Get the x position for the view that'll morph into the preview FrameLayout
*/
float getMorphStartX() {
float startX = getPreviewViewX() + previewView.getThumbOffset();
float endX = getPreviewViewX() + getPreviewViewWidth() - previewView.getThumbOffset();

float nextX = (endX - startX) * getWidthOffset(previewView.getProgress())
+ startX - previewView.getThumbOffset();

return nextX;
}

float getMorphEndX() {
return getFrameX() + previewFrameLayout.getWidth() / 2f - previewView.getThumbOffset();
}

float getMorphStartY() {
return ((View) previewView).getY() + previewView.getThumbOffset();
}

float getMorphEndY() {
return (int) (previewFrameLayout.getY() + previewFrameLayout.getHeight() / 2f);
}

/**
* Get x position for the preview frame. This method takes into account a margin
* that'll make the frame not move until the scrub position exceeds half of the frame's width.
Expand All @@ -84,12 +54,11 @@ float getFrameX() {
float low = previewFrameLayout.getLeft();
float high = parent.getWidth() - params.rightMargin - previewFrameLayout.getWidth();

float startX = getPreviewViewX() + previewView.getThumbOffset();
float endX = getPreviewViewX() + getPreviewViewWidth() - previewView.getThumbOffset();

float startX = getPreviewViewStartX() + previewView.getThumbOffset();
float endX = getPreviewViewEndX() - previewView.getThumbOffset();
float center = (endX - startX) * offset + startX;

float nextX = center - previewFrameLayout.getWidth() / 2f;

// Don't move if we still haven't reached half of the width
if (nextX < low) {
return low;
Expand All @@ -100,15 +69,15 @@ float getFrameX() {
}
}

float getPreviewViewX() {
float getPreviewViewStartX() {
return ((View) previewView).getX();
}

float getPreviewViewWidth() {
return ((View) previewView).getWidth();
float getPreviewViewEndX() {
return getPreviewViewStartX() + ((View) previewView).getWidth();
}

private float getWidthOffset(int progress) {
float getWidthOffset(int progress) {
return (float) progress / previewView.getMax();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@

class PreviewAnimatorImpl extends PreviewAnimator {

public static final int ALPHA_DURATION = 200;

private AnimatorListenerAdapter hideListener = new AnimatorListenerAdapter() {
@Override
public void onAnimationEnd(Animator animation) {
Expand All @@ -50,7 +52,7 @@ public void show() {
previewFrameLayout.setAlpha(0f);
previewFrameLayout.animate().cancel();
previewFrameLayout.animate()
.setDuration(MORPH_REVEAL_DURATION)
.setDuration(ALPHA_DURATION)
.alpha(1f)
.setListener(null);
}
Expand All @@ -60,7 +62,7 @@ public void hide() {
previewFrameLayout.setAlpha(1f);
previewFrameLayout.animate().cancel();
previewFrameLayout.animate()
.setDuration(UNMORPH_UNREVEAL_DURATION)
.setDuration(ALPHA_DURATION)
.alpha(0f)
.setListener(hideListener);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@

class PreviewAnimatorLollipopImpl extends PreviewAnimator {

static final int MORPH_REVEAL_DURATION = 150;
static final int MORPH_MOVE_DURATION = 200;
static final int UNMORPH_MOVE_DURATION = 200;
static final int UNMORPH_UNREVEAL_DURATION = 150;

private Animator.AnimatorListener showListener = new AnimatorListenerAdapter() {
@Override
public void onAnimationEnd(Animator animation) {
Expand Down Expand Up @@ -178,4 +183,28 @@ private int getCenterX(View view) {
private int getCenterY(View view) {
return view.getHeight() / 2;
}

/**
* Get the x position for the view that'll morph into the preview FrameLayout
*/
private float getMorphStartX() {
float startX = getPreviewViewStartX() + previewView.getThumbOffset();
float endX = getPreviewViewEndX() - previewView.getThumbOffset();
float nextX = (endX - startX) * getWidthOffset(previewView.getProgress())
+ startX - previewView.getThumbOffset();
return nextX;
}

private float getMorphEndX() {
return getFrameX() + previewFrameLayout.getWidth() / 2f - previewView.getThumbOffset();
}

private float getMorphStartY() {
return ((View) previewView).getY() + previewView.getThumbOffset();
}

private float getMorphEndY() {
return (int) (previewFrameLayout.getY() + previewFrameLayout.getHeight() / 2f);
}

}

0 comments on commit 4d59ac5

Please sign in to comment.