Skip to content

Commit

Permalink
Fix expand arrow alpha animation
Browse files Browse the repository at this point in the history
Signed-off-by: enricocid <enrico2588@gmail.com>
  • Loading branch information
enricocid committed Jun 14, 2018
1 parent 7e02260 commit 4d6a1ed
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
16 changes: 11 additions & 5 deletions project/app/src/main/java/com/iven/musicplayergo/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@
import android.view.ViewAnimationUtils;
import android.view.ViewTreeObserver;
import android.view.animation.Animation;
import android.view.animation.AnimationSet;
import android.view.animation.DecelerateInterpolator;
import android.view.animation.RotateAnimation;
import android.widget.FrameLayout;
import android.widget.ImageView;
Expand Down Expand Up @@ -649,13 +651,16 @@ public void expandArtistDetails(View v) {

private void rotateExpandImage(final boolean expand) {

final int ALPHA_DURATION = 100;
final int ALPHA_DURATION = 250;
final float PIVOT_VALUE = 0.5f;
final int PIVOT_TYPE = RotateAnimation.RELATIVE_TO_SELF;
final float from = expand ? 0.0f : 180.0f;
final float to = expand ? 180.0f : 0.0f;
final float originalAlpha = mExpandImage.getImageAlpha();

AnimationSet animSet = new AnimationSet(true);
animSet.setInterpolator(new DecelerateInterpolator());
animSet.setFillAfter(true);
animSet.setFillEnabled(true);
final RotateAnimation animRotate = new RotateAnimation(from, to, PIVOT_TYPE, PIVOT_VALUE, PIVOT_TYPE, PIVOT_VALUE);
animRotate.setDuration(ANIMATION_DURATION);
animRotate.setFillAfter(true);
Expand All @@ -664,23 +669,24 @@ private void rotateExpandImage(final boolean expand) {
public void onAnimationStart(Animation animation) {
if (!expand) {
mExpandImage.setVisibility(View.VISIBLE);
mExpandImage.animate().alpha(originalAlpha).setDuration(ALPHA_DURATION).start();
mExpandImage.animate().alpha(1.0f).setDuration(ALPHA_DURATION).start();
}
}

@Override
public void onAnimationEnd(Animation animation) {
if (expand) {
mExpandImage.animate().alpha(0.0f).setDuration(ALPHA_DURATION).start();
mExpandImage.setVisibility(View.GONE);
mExpandImage.setVisibility(View.INVISIBLE);
}
}

@Override
public void onAnimationRepeat(Animation animation) {
}
});
mExpandImage.startAnimation(animRotate);
animSet.addAnimation(animRotate);
mExpandImage.startAnimation(animSet);
}

private void revealView(final View viewToReveal, final View viewToHide, final boolean isSettings, boolean show) {
Expand Down
2 changes: 1 addition & 1 deletion project/app/src/main/res/layout/player_now_playing.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginEnd="2dp"
android:layout_weight="1"
android:orientation="vertical"
android:layout_marginEnd="2dp"
android:padding="4dp">

<TextView
Expand Down

0 comments on commit 4d6a1ed

Please sign in to comment.