Prevent flat controls from animating on every show

This commit is contained in:
Eugene Cheung 2017-06-13 15:33:37 -04:00
commit 7b039741c3

View file

@ -67,6 +67,8 @@ public class FlatPlayerPlaybackControlsFragment extends AbsMusicServiceFragment
private AnimatorSet musicControllerAnimationSet; private AnimatorSet musicControllerAnimationSet;
private boolean hidden = false;
@Override @Override
public void onCreate(Bundle savedInstanceState) { public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
@ -253,25 +255,28 @@ public class FlatPlayerPlaybackControlsFragment extends AbsMusicServiceFragment
} }
public void show() { public void show() {
if (musicControllerAnimationSet == null) { if (hidden) {
TimeInterpolator interpolator = new FastOutSlowInInterpolator(); if (musicControllerAnimationSet == null) {
final int duration = 300; TimeInterpolator interpolator = new FastOutSlowInInterpolator();
final int duration = 300;
LinkedList<Animator> animators = new LinkedList<>(); LinkedList<Animator> animators = new LinkedList<>();
addAnimation(animators, playPauseButton, interpolator, duration, 0); addAnimation(animators, playPauseButton, interpolator, duration, 0);
addAnimation(animators, nextButton, interpolator, duration, 100); addAnimation(animators, nextButton, interpolator, duration, 100);
addAnimation(animators, prevButton, interpolator, duration, 100); addAnimation(animators, prevButton, interpolator, duration, 100);
addAnimation(animators, shuffleButton, interpolator, duration, 200); addAnimation(animators, shuffleButton, interpolator, duration, 200);
addAnimation(animators, repeatButton, interpolator, duration, 200); addAnimation(animators, repeatButton, interpolator, duration, 200);
musicControllerAnimationSet = new AnimatorSet();
musicControllerAnimationSet = new AnimatorSet(); musicControllerAnimationSet.playTogether(animators);
musicControllerAnimationSet.playTogether(animators); } else {
} else { musicControllerAnimationSet.cancel();
musicControllerAnimationSet.cancel(); }
musicControllerAnimationSet.start();
} }
musicControllerAnimationSet.start();
hidden = false;
} }
public void hide() { public void hide() {
@ -283,6 +288,8 @@ public class FlatPlayerPlaybackControlsFragment extends AbsMusicServiceFragment
prepareForAnimation(prevButton); prepareForAnimation(prevButton);
prepareForAnimation(shuffleButton); prepareForAnimation(shuffleButton);
prepareForAnimation(repeatButton); prepareForAnimation(repeatButton);
hidden = true;
} }
private static void addAnimation(Collection<Animator> animators, View view, TimeInterpolator interpolator, int duration, int delay) { private static void addAnimation(Collection<Animator> animators, View view, TimeInterpolator interpolator, int duration, int delay) {