Transition between the bar colors should be a bit smoother now. Also cleaned up some methods.

This commit is contained in:
Karim Abou Zeid 2015-08-16 23:15:44 +02:00
commit b18be272bc
4 changed files with 55 additions and 72 deletions

View file

@ -28,6 +28,8 @@
<h3>Version 0.9.43 beta2</h3>
<ol>
<li><b>IMPROVEMENT:</b> Transition between the bar colors should be a bit smoother now.
</li>
<li><b>FIX:</b> Playlist view having wrong background color on dark theme.
</li>
<li><b>FIX:</b> Bottom bar sometimes disappearing from itself after changing the theme.

View file

@ -1,6 +1,7 @@
package com.kabouzeid.gramophone.ui.activities.base;
import android.animation.Animator;
import android.animation.AnimatorSet;
import android.annotation.SuppressLint;
import android.content.ComponentName;
import android.content.Intent;
@ -121,6 +122,8 @@ public abstract class AbsSlidingMusicPanelActivity extends AbsMusicServiceActivi
ImageButton shuffleButton;
@Bind(R.id.player_media_controller_container)
RelativeLayout mediaControllerContainer;
@Bind(R.id.player_media_controller_container_background)
View mediaControllerContainerBackground;
@Bind(R.id.player_footer_frame)
LinearLayout footerFrame;
@Bind(R.id.player_album_art_background)
@ -138,9 +141,9 @@ public abstract class AbsSlidingMusicPanelActivity extends AbsMusicServiceActivi
TextView songTotalTime;
SeekBar progressSlider;
private int lastFooterColor = -1;
private int lastTitleTextColor = -2;
private int lastCaptionTextColor = -2;
private int lastFooterColor;
private int lastTitleTextColor;
private int lastCaptionTextColor;
private int navigationBarColor;
private int taskColor;
@ -158,6 +161,8 @@ public abstract class AbsSlidingMusicPanelActivity extends AbsMusicServiceActivi
private PlayPauseDrawable playPauseDrawable;
private AnimatorSet colorTransitionAnimator;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
@ -554,7 +559,7 @@ public abstract class AbsSlidingMusicPanelActivity extends AbsMusicServiceActivi
private void setUpPlaybackControllerCard() {
playbackControllerCard.setVisibility(showPlaybackControllerCard ? View.VISIBLE : View.GONE);
mediaControllerContainer.setBackgroundColor(showPlaybackControllerCard ? Color.TRANSPARENT : ColorUtil.resolveColor(this, R.attr.music_controller_container_color));
mediaControllerContainerBackground.setVisibility(showPlaybackControllerCard ? View.GONE : View.VISIBLE);
}
private void setUpMusicControllers() {
@ -807,7 +812,6 @@ public abstract class AbsSlidingMusicPanelActivity extends AbsMusicServiceActivi
private void setColors(int color) {
animateColorChange(color);
animateTextColorChange(ColorUtil.getPrimaryTextColorForBackground(this, color), ColorUtil.getSecondaryTextColorForBackground(this, color));
if (slidingUpPanelLayout.getPanelState() == SlidingUpPanelLayout.PanelState.EXPANDED) {
super.notifyTaskColorChange(color);
@ -818,59 +822,39 @@ public abstract class AbsSlidingMusicPanelActivity extends AbsMusicServiceActivi
}
private void animateColorChange(final int newColor) {
if (lastFooterColor != -1 && lastFooterColor != newColor) {
ViewUtil.animateViewColor(footer, lastFooterColor, newColor);
if (opaqueToolBar) {
ViewUtil.animateViewColor(playerToolbar, lastFooterColor, newColor);
} else {
playerToolbar.setBackgroundColor(Color.TRANSPARENT);
}
if (opaqueStatusBar) {
int newStatusbarColor = newColor;
int oldStatusbarColor = lastFooterColor;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
newStatusbarColor = ColorUtil.shiftColorDown(newStatusbarColor);
oldStatusbarColor = ColorUtil.shiftColorDown(oldStatusbarColor);
}
ViewUtil.animateViewColor(playerStatusbar, oldStatusbarColor, newStatusbarColor);
} else {
playerStatusbar.setBackgroundColor(Color.TRANSPARENT);
}
} else {
footer.setBackgroundColor(newColor);
if (opaqueToolBar) {
playerToolbar.setBackgroundColor(newColor);
} else {
playerToolbar.setBackgroundColor(Color.TRANSPARENT);
}
if (opaqueStatusBar) {
int newStatusbarColor = newColor;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
newStatusbarColor = ColorUtil.shiftColorDown(newColor);
}
playerStatusbar.setBackgroundColor(newStatusbarColor);
} else {
playerStatusbar.setBackgroundColor(Color.TRANSPARENT);
}
if (colorTransitionAnimator != null && colorTransitionAnimator.isStarted()) {
colorTransitionAnimator.cancel();
}
colorTransitionAnimator = new AnimatorSet();
AnimatorSet.Builder animatorSetBuilder = colorTransitionAnimator.play(ViewUtil.createBackgroundColorTransition(footer, lastFooterColor, newColor));
if (opaqueToolBar) {
animatorSetBuilder.with(ViewUtil.createBackgroundColorTransition(playerToolbar, lastFooterColor, newColor));
} else {
playerToolbar.setBackgroundColor(Color.TRANSPARENT);
}
if (opaqueStatusBar) {
int newStatusbarColor = newColor;
int oldStatusbarColor = lastFooterColor;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
newStatusbarColor = ColorUtil.shiftColorDown(newStatusbarColor);
oldStatusbarColor = ColorUtil.shiftColorDown(oldStatusbarColor);
}
animatorSetBuilder.with(ViewUtil.createBackgroundColorTransition(playerStatusbar, oldStatusbarColor, newStatusbarColor));
} else {
playerStatusbar.setBackgroundColor(Color.TRANSPARENT);
}
int titleTextColor = ColorUtil.getPrimaryTextColorForBackground(this, newColor);
int captionTextColor = ColorUtil.getSecondaryTextColorForBackground(this, newColor);
animatorSetBuilder.with(ViewUtil.createTextColorTransition(songTitle, lastTitleTextColor, titleTextColor));
animatorSetBuilder.with(ViewUtil.createTextColorTransition(songText, lastCaptionTextColor, captionTextColor));
colorTransitionAnimator.start();
lastFooterColor = newColor;
}
private void animateTextColorChange(int titleTextColor, int captionTextColor) {
if (lastTitleTextColor != -2 && lastTitleTextColor != titleTextColor) {
ViewUtil.animateTextColor(songTitle, lastTitleTextColor, titleTextColor);
} else {
songTitle.setTextColor(titleTextColor);
}
if (lastCaptionTextColor != -2 && lastCaptionTextColor != captionTextColor) {
ViewUtil.animateTextColor(songText, lastCaptionTextColor, captionTextColor);
} else {
songText.setTextColor(captionTextColor);
}
lastTitleTextColor = titleTextColor;
lastCaptionTextColor = captionTextColor;
}

View file

@ -1,5 +1,6 @@
package com.kabouzeid.gramophone.util;
import android.animation.Animator;
import android.animation.ArgbEvaluator;
import android.animation.ObjectAnimator;
import android.os.Build;
@ -29,36 +30,26 @@ import java.lang.reflect.Field;
* @author Karim Abou Zeid (kabouzeid)
*/
public class ViewUtil {
public static Animator createBackgroundColorTransition(final View v, final int startColor, final int endColor) {
return createColorAnimator(v, "backgroundColor", startColor, endColor);
}
public static Animator createTextColorTransition(final TextView v, final int startColor, final int endColor) {
return createColorAnimator(v, "textColor", startColor, endColor);
}
public final static int DEFAULT_COLOR_ANIMATION_DURATION = 500;
public static void animateViewColor(final View v, final int startColor, final int endColor) {
animateViewColor(v, startColor, endColor, DEFAULT_COLOR_ANIMATION_DURATION);
}
public static void animateViewColor(final View v, final int startColor, final int endColor, final int duration) {
ObjectAnimator animator = ObjectAnimator.ofObject(v, "backgroundColor",
private static Animator createColorAnimator(Object target, String propertyName, int startColor, int endColor) {
ObjectAnimator animator = ObjectAnimator.ofObject(target, propertyName,
new ArgbEvaluator(), startColor, endColor);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
animator.setInterpolator(new PathInterpolator(0.4f, 0f, 1f, 1f));
}
animator.setDuration(duration);
animator.start();
}
public static void animateTextColor(final TextView v, final int startColor, final int endColor) {
animateTextColor(v, startColor, endColor, DEFAULT_COLOR_ANIMATION_DURATION);
}
public static void animateTextColor(final TextView v, final int startColor, final int endColor, final int duration) {
ObjectAnimator animator = ObjectAnimator.ofObject(v, "textColor",
new ArgbEvaluator(), startColor, endColor);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
animator.setInterpolator(new PathInterpolator(0.4f, 0f, 1f, 1f));
}
animator.setDuration(duration);
animator.start();
animator.setDuration(DEFAULT_COLOR_ANIMATION_DURATION);
return animator;
}
public static void setBackgroundAlpha(@NonNull View view, float alpha, int baseColor) {

View file

@ -98,9 +98,14 @@
android:id="@+id/player_media_controller_container"
android:layout_width="match_parent"
android:layout_height="@dimen/media_controller_container_height"
android:background="?music_controller_container_color"
tools:ignore="ContentDescription,UnusedAttribute">
<View
android:id="@+id/player_media_controller_container_background"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="?music_controller_container_color" />
<android.support.v7.widget.CardView
android:id="@+id/player_playback_controller_card"
android:layout_width="match_parent"
@ -271,7 +276,8 @@
android:layout_width="match_parent"
android:layout_height="@dimen/status_bar_padding"
android:background="@android:color/transparent"
android:elevation="@dimen/toolbar_elevation" />
android:elevation="@dimen/toolbar_elevation"
tools:ignore="UnusedAttribute" />
<android.support.v7.widget.Toolbar
android:id="@+id/player_toolbar"