Skip to content

Commit

Permalink
Minor code refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
balysv committed Aug 26, 2014
1 parent 31ec566 commit ca2931e
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -76,5 +76,5 @@ public interface MaterialMenu {
/**
* @return {@link MaterialMenuDrawable} to be used for the menu
*/
public abstract MaterialMenuDrawable getDrawable();
public MaterialMenuDrawable getDrawable();
}
Original file line number Diff line number Diff line change
Expand Up @@ -184,21 +184,26 @@ private void drawMiddleLine(Canvas canvas, float ratio) {

switch (animationState) {
case BURGER_ARROW:
// rotate by 180 and shorten one end
rotation = transformationValue * ARROW_MID_LINE_ANGLE;
// rotate by 180
if (isMorphingForward()) {
rotation = ratio * ARROW_MID_LINE_ANGLE;
} else {
rotation = ARROW_MID_LINE_ANGLE + (1 - ratio) * ARROW_MID_LINE_ANGLE;
}
// shorten one end
stopX -= ratio * strokeWidth / 2;
break;
case BURGER_X:
// fade out
alpha = Math.max(0, Math.min(255, (int) ((1 - ratio) * 255)));
alpha = (int) ((1 - ratio) * 255);
break;
case ARROW_X:
// fade out and shorten one end
alpha = Math.max(0, Math.min(255, (int) ((1 - ratio) * 255)));
alpha = (int) ((1 - ratio) * 255);
startX += (1 - ratio) * strokeWidth / 2;
break;
case ARROW_CHECK:
if (transformationValue <= TRANSFORMATION_MID) {
if (isMorphingForward()) {
// rotate until required angle
rotation = ratio * CHECK_MIDDLE_ANGLE;
// lengthen both ends
Expand All @@ -214,6 +219,7 @@ private void drawMiddleLine(Canvas canvas, float ratio) {
pivotX = width / 2 + strokeWidth * 2;
break;
case BURGER_CHECK:
// rotate until required angle
rotation = ratio * CHECK_MIDDLE_ANGLE;
// lengthen both ends
startX += ratio * (dip4 + strokeWidth / 2);
Expand Down Expand Up @@ -255,7 +261,7 @@ private void drawTopLine(Canvas canvas, float ratio) {

switch (animationState) {
case BURGER_ARROW:
if (transformationValue <= TRANSFORMATION_MID) {
if (isMorphingForward()) {
// rotate until required angle
rotation = ratio * ARROW_BOT_LINE_ANGLE;
} else {
Expand Down Expand Up @@ -298,7 +304,7 @@ private void drawTopLine(Canvas canvas, float ratio) {
break;
case ARROW_CHECK:
// fade out
alpha = Math.max(0, Math.min(255, (int) ((1 - ratio) * 255)));
alpha = (int) ((1 - ratio) * 255);
// retain starting arrow configuration
rotation = ARROW_BOT_LINE_ANGLE;
pivotX = width / 2;
Expand All @@ -307,7 +313,8 @@ private void drawTopLine(Canvas canvas, float ratio) {
stopX -= dip3;
break;
case BURGER_CHECK:
alpha = Math.max(0, Math.min(255, (int) ((1 - ratio) * 255)));
// fade out
alpha = (int) ((1 - ratio) * 255);
break;
case X_CHECK:
// retain X configuration
Expand All @@ -318,7 +325,7 @@ private void drawTopLine(Canvas canvas, float ratio) {
stopX += dip3;

// fade out
alpha = Math.max(0, Math.min(255, (int) ((1 - ratio) * 255)));
alpha = (int) ((1 - ratio) * 255);
break;
}

Expand Down Expand Up @@ -346,7 +353,7 @@ private void drawBottomLine(Canvas canvas, float ratio) {

switch (animationState) {
case BURGER_ARROW:
if (transformationValue <= TRANSFORMATION_MID) {
if (isMorphingForward()) {
// rotate to required angle
rotation = ARROW_TOP_LINE_ANGLE * ratio;
} else {
Expand All @@ -362,7 +369,7 @@ private void drawBottomLine(Canvas canvas, float ratio) {
stopX = width - sidePadding - dip3 * ratio;
break;
case BURGER_X:
if (transformationValue <= TRANSFORMATION_MID) {
if (isMorphingForward()) {
// rotate around
rotation2 = -X_ROTATION_ANGLE * ratio;
} else {
Expand Down Expand Up @@ -419,11 +426,11 @@ private void drawBottomLine(Canvas canvas, float ratio) {
case X_CHECK:
// rotate from X to CHECK angles
rotation2 = -X_ROTATION_ANGLE * (1 - ratio);
rotation = X_BOT_LINE_ANGLE + ratio * (-X_BOT_LINE_ANGLE + CHECK_BOTTOM_ANGLE + ARROW_TOP_LINE_ANGLE);
rotation = X_BOT_LINE_ANGLE + (CHECK_BOTTOM_ANGLE + ARROW_TOP_LINE_ANGLE - X_BOT_LINE_ANGLE) * ratio;

// move pivot from X to CHECL
pivotX = sidePadding + dip4 + ratio * (-sidePadding - dip4 + width / 2 - strokeWidth);
pivotY = height - topPadding - dip3 + ratio * (-height + topPadding + dip3 + height / 2 - strokeWidth);
// move pivot from X to CHECK
pivotX = sidePadding + dip4 + (width / 2 - strokeWidth - sidePadding - dip4) * ratio;
pivotY = height - topPadding - dip3 + (topPadding + dip3 + height / 2 - strokeWidth - height) * ratio;

// shorten both ends
startX += dip3 - dip3 * (1 - ratio);
Expand Down Expand Up @@ -451,6 +458,10 @@ private void drawGrid(Canvas canvas) {
}
}

private boolean isMorphingForward() {
return transformationValue <= TRANSFORMATION_MID;
}

@Override public void setAlpha(int alpha) {
iconPaint.setAlpha(alpha);
}
Expand Down Expand Up @@ -510,7 +521,7 @@ public synchronized void setIconState(IconState iconState) {
transformationValue = TRANSFORMATION_MID;
break;
case CHECK:
animationState = AnimationState.ARROW_CHECK;
animationState = AnimationState.BURGER_CHECK;
transformationValue = TRANSFORMATION_MID;
}
currentIconState = iconState;
Expand Down

0 comments on commit ca2931e

Please sign in to comment.