diff options
author | John Spurlock <jspurlock@google.com> | 2013-09-18 16:33:57 -0400 |
---|---|---|
committer | John Spurlock <jspurlock@google.com> | 2013-09-19 11:28:54 -0400 |
commit | e631b41d8be2952db48df5838c6fb5d8df4645d1 (patch) | |
tree | 297689304283e5339f22e10b0b13a420084ce324 /packages | |
parent | a2d65108dd32a0836fe08f0c72efdd5c727dad44 (diff) | |
download | frameworks_base-e631b41d8be2952db48df5838c6fb5d8df4645d1.zip frameworks_base-e631b41d8be2952db48df5838c6fb5d8df4645d1.tar.gz frameworks_base-e631b41d8be2952db48df5838c6fb5d8df4645d1.tar.bz2 |
Draw gradient behind fully transparent system bars.
Use a transition-drawable to crossfade between the gradient and
solid color backgrounds, avoiding custom onDraw.
Rename colors to their final names. Since both bars now receive the
gradient treatment, centralize in base BarTransitions.
Bug:10602521
Change-Id: Id094fa1767eabab88a3709d6026c23858c83fb5b
Diffstat (limited to 'packages')
10 files changed, 126 insertions, 91 deletions
diff --git a/packages/SystemUI/res/layout-ldrtl/navigation_bar.xml b/packages/SystemUI/res/layout-ldrtl/navigation_bar.xml index 03ca729..765b274 100644 --- a/packages/SystemUI/res/layout-ldrtl/navigation_bar.xml +++ b/packages/SystemUI/res/layout-ldrtl/navigation_bar.xml @@ -23,7 +23,7 @@ xmlns:systemui="http://schemas.android.com/apk/res/com.android.systemui" android:layout_height="match_parent" android:layout_width="match_parent" - android:background="#FF000000" + android:background="@drawable/system_bar_background" > <FrameLayout android:id="@+id/rot0" diff --git a/packages/SystemUI/res/layout-sw600dp/navigation_bar.xml b/packages/SystemUI/res/layout-sw600dp/navigation_bar.xml index 47db1c7..9592b18 100644 --- a/packages/SystemUI/res/layout-sw600dp/navigation_bar.xml +++ b/packages/SystemUI/res/layout-sw600dp/navigation_bar.xml @@ -22,7 +22,7 @@ xmlns:systemui="http://schemas.android.com/apk/res/com.android.systemui" android:layout_height="match_parent" android:layout_width="match_parent" - android:background="#FF000000" + android:background="@drawable/system_bar_background" > <FrameLayout android:id="@+id/rot0" diff --git a/packages/SystemUI/res/layout/navigation_bar.xml b/packages/SystemUI/res/layout/navigation_bar.xml index 09923a7..5587f4e 100644 --- a/packages/SystemUI/res/layout/navigation_bar.xml +++ b/packages/SystemUI/res/layout/navigation_bar.xml @@ -23,7 +23,7 @@ xmlns:systemui="http://schemas.android.com/apk/res/com.android.systemui" android:layout_height="match_parent" android:layout_width="match_parent" - android:background="#FF000000" + android:background="@drawable/system_bar_background" > <FrameLayout android:id="@+id/rot0" diff --git a/packages/SystemUI/res/layout/status_bar.xml b/packages/SystemUI/res/layout/status_bar.xml index 4741cec..b3c2f6e 100644 --- a/packages/SystemUI/res/layout/status_bar.xml +++ b/packages/SystemUI/res/layout/status_bar.xml @@ -23,7 +23,7 @@ xmlns:android="http://schemas.android.com/apk/res/android" xmlns:systemui="http://schemas.android.com/apk/res/com.android.systemui" android:id="@+id/status_bar" - android:background="@drawable/status_bar_background" + android:background="@drawable/system_bar_background" android:orientation="vertical" android:focusable="true" android:descendantFocusability="afterDescendants" diff --git a/packages/SystemUI/res/values/colors.xml b/packages/SystemUI/res/values/colors.xml index 67a932a..4cd781a 100644 --- a/packages/SystemUI/res/values/colors.xml +++ b/packages/SystemUI/res/values/colors.xml @@ -19,11 +19,10 @@ <resources> <drawable name="notification_number_text_color">#ffffffff</drawable> <drawable name="ticker_background_color">#ff1d1d1d</drawable> - <drawable name="status_bar_background">#ff000000</drawable> - <color name="status_bar_background_semi_transparent">#66000000</color> - <color name="status_bar_background_transparent">#00000000</color> - <color name="navigation_bar_background_transparent_start">#7f000000</color> - <color name="navigation_bar_background_transparent_end">#00000000</color> + <drawable name="system_bar_background">#ff000000</drawable> + <color name="system_bar_background_semi_transparent">#66000000</color> <!-- 40% black --> + <color name="system_bar_background_gradient_start">#7f000000</color> <!-- 50% black --> + <color name="system_bar_background_gradient_end">#00000000</color> <color name="notification_panel_solid_background">#ff000000</color> <drawable name="status_bar_recents_app_thumbnail_background">#88000000</drawable> <color name="status_bar_recents_app_label_color">#ffffffff</color> diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/BarTransitions.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/BarTransitions.java index 212d704..0c25c83 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/BarTransitions.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/BarTransitions.java @@ -23,6 +23,9 @@ import android.app.ActivityManager; import android.content.res.Resources; import android.graphics.drawable.ColorDrawable; import android.graphics.drawable.Drawable; +import android.graphics.drawable.GradientDrawable; +import android.graphics.drawable.GradientDrawable.Orientation; +import android.graphics.drawable.TransitionDrawable; import android.util.Log; import android.view.View; @@ -30,37 +33,74 @@ import com.android.systemui.R; public class BarTransitions { private static final boolean DEBUG = false; + private static final boolean DEBUG_COLORS = false; public static final int MODE_OPAQUE = 0; public static final int MODE_SEMI_TRANSPARENT = 1; public static final int MODE_TRANSPARENT = 2; public static final int MODE_LIGHTS_OUT = 3; - protected static final int LIGHTS_IN_DURATION = 250; - protected static final int LIGHTS_OUT_DURATION = 750; + public static final int LIGHTS_IN_DURATION = 250; + public static final int LIGHTS_OUT_DURATION = 750; + public static final int BACKGROUND_DURATION = 200; private final String mTag; - protected final View mTarget; - protected final int mOpaque; - protected final int mSemiTransparent; + private final View mView; + private final boolean mSupportsTransitions = ActivityManager.isHighEndGfx(); + + private final int mOpaque; + private final int mSemiTransparent; + private final int mGradientStart; + private final int mGradientEnd; - protected Drawable mTransparent; private int mMode; - private ValueAnimator mBackgroundColorAnimator; + private ValueAnimator mColorDrawableAnimator; + private boolean mColorDrawableShowing; - private final AnimatorUpdateListener mBackgroundColorListener = new AnimatorUpdateListener() { + private final ColorDrawable mColorDrawable; + private final GradientDrawable mGradientDrawable; + private final TransitionDrawable mTransitionDrawable; + private final AnimatorUpdateListener mAnimatorListener = new AnimatorUpdateListener() { @Override public void onAnimationUpdate(ValueAnimator animator) { - mTarget.setBackgroundColor((Integer) animator.getAnimatedValue()); + mColorDrawable.setColor((Integer) animator.getAnimatedValue()); } }; - public BarTransitions(View target) { - mTag = "BarTransitions." + target.getClass().getSimpleName(); - mTarget = target; - final Resources res = target.getContext().getResources(); - mOpaque = res.getColor(R.drawable.status_bar_background); - mSemiTransparent = res.getColor(R.color.status_bar_background_semi_transparent); + public BarTransitions(View view) { + mTag = "BarTransitions." + view.getClass().getSimpleName(); + mView = view; + final Resources res = mView.getContext().getResources(); + + if (DEBUG_COLORS) { + mOpaque = 0xff0000ff; + mSemiTransparent = 0x7f0000ff; + mGradientStart = 0x7fff0000; + mGradientEnd = 0x7f00ff00; + } else { + mOpaque = res.getColor(R.drawable.system_bar_background); + mSemiTransparent = res.getColor(R.color.system_bar_background_semi_transparent); + mGradientStart = res.getColor(R.color.system_bar_background_gradient_start); + mGradientEnd = res.getColor(R.color.system_bar_background_gradient_end); + } + + mColorDrawable = new ColorDrawable(mOpaque); + mGradientDrawable = new GradientDrawable(Orientation.BOTTOM_TOP, + new int[] { mGradientStart, mGradientEnd }); + mTransitionDrawable = new TransitionDrawable( + new Drawable[] { mGradientDrawable, mColorDrawable }); + mTransitionDrawable.setCrossFadeEnabled(true); + mTransitionDrawable.resetTransition(); + if (mSupportsTransitions) { + mView.setBackground(mTransitionDrawable); + } + } + + protected void setOrientation(GradientDrawable.Orientation orientation) { + if (orientation.equals(mGradientDrawable.getOrientation())) return; // GD doesn't check + if (DEBUG) Log.d(mTag, "setOrientation " + orientation); + mGradientDrawable.mutate(); + mGradientDrawable.setOrientation(orientation); } public int getMode() { @@ -71,12 +111,14 @@ public class BarTransitions { if (mMode == mode) return; int oldMode = mMode; mMode = mode; - if (!ActivityManager.isHighEndGfx()) return; - if (DEBUG) Log.d(mTag, modeToString(oldMode) + " -> " + modeToString(mode)); - onTransition(oldMode, mMode, animate); + if (DEBUG) Log.d(mTag, String.format("%s -> %s animate=%s", + modeToString(oldMode), modeToString(mode), animate)); + if (mSupportsTransitions) { + onTransition(oldMode, mMode, animate); + } } - protected Integer getBackgroundColor(int mode) { + private Integer getBackgroundColor(int mode) { if (mode == MODE_SEMI_TRANSPARENT) return mSemiTransparent; if (mode == MODE_OPAQUE) return mOpaque; if (mode == MODE_LIGHTS_OUT) return mOpaque; @@ -84,32 +126,50 @@ public class BarTransitions { } protected void onTransition(int oldMode, int newMode, boolean animate) { - cancelBackgroundColorAnimation(); + applyModeBackground(oldMode, newMode, animate); + } + + protected void applyModeBackground(int oldMode, int newMode, boolean animate) { + if (DEBUG) Log.d(mTag, String.format("applyModeBackground %s animate=%s", + modeToString(newMode), animate)); + cancelColorAnimation(); Integer oldColor = getBackgroundColor(oldMode); Integer newColor = getBackgroundColor(newMode); - if (oldColor != null && newColor != null) { + if (newColor != null) { + if (animate && oldColor != null && !oldColor.equals(newColor)) { + startColorAnimation(oldColor, newColor); + } else if (!newColor.equals(mColorDrawable.getColor())) { + if (DEBUG) Log.d(mTag, String.format("setColor = %08x", newColor)); + mColorDrawable.setColor(newColor); + } + } + if (oldColor != null && newColor == null && mColorDrawableShowing) { + if (DEBUG) Log.d(mTag, "Hide color layer"); if (animate) { - startBackgroundColorAnimation(oldColor, newColor); + mTransitionDrawable.reverseTransition(BACKGROUND_DURATION); } else { - mTarget.setBackgroundColor(newColor); + mTransitionDrawable.resetTransition(); } - } else { - mTarget.setBackground(newMode == MODE_TRANSPARENT ? mTransparent - : newMode == MODE_SEMI_TRANSPARENT ? new ColorDrawable(mSemiTransparent) - : new ColorDrawable(mOpaque)); + mColorDrawableShowing = false; + } else if (oldColor == null && newColor != null && !mColorDrawableShowing) { + if (DEBUG) Log.d(mTag, "Show color layer"); + mTransitionDrawable.setCrossFadeEnabled(!animate); + mTransitionDrawable.startTransition(animate ? BACKGROUND_DURATION : 0); + mColorDrawableShowing = true; } } - private void startBackgroundColorAnimation(int from, int to) { - mBackgroundColorAnimator = ValueAnimator.ofObject(new ArgbEvaluator(), from, to); - mBackgroundColorAnimator.addUpdateListener(mBackgroundColorListener); - mBackgroundColorAnimator.start(); + private void startColorAnimation(int from, int to) { + if (DEBUG) Log.d(mTag, String.format("startColorAnimation %08x -> %08x", from, to)); + mColorDrawableAnimator = ValueAnimator.ofObject(new ArgbEvaluator(), from, to); + mColorDrawableAnimator.addUpdateListener(mAnimatorListener); + mColorDrawableAnimator.start(); } - private void cancelBackgroundColorAnimation() { - if (mBackgroundColorAnimator != null && mBackgroundColorAnimator.isStarted()) { - mBackgroundColorAnimator.cancel(); - mBackgroundColorAnimator = null; + private void cancelColorAnimation() { + if (mColorDrawableAnimator != null && mColorDrawableAnimator.isStarted()) { + mColorDrawableAnimator.cancel(); + mColorDrawableAnimator = null; } } diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/NavigationBarTransitions.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/NavigationBarTransitions.java index 085130b..040b750 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/NavigationBarTransitions.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/NavigationBarTransitions.java @@ -19,9 +19,6 @@ package com.android.systemui.statusbar.phone; import android.animation.Animator; import android.animation.AnimatorListenerAdapter; import android.content.Context; -import android.content.res.Resources; -import android.graphics.drawable.Drawable; -import android.graphics.drawable.GradientDrawable; import android.graphics.drawable.GradientDrawable.Orientation; import android.os.ServiceManager; import android.view.MotionEvent; @@ -33,12 +30,8 @@ import com.android.systemui.R; import com.android.systemui.statusbar.policy.KeyButtonView; public final class NavigationBarTransitions extends BarTransitions { - private static final boolean ENABLE_GRADIENT = false; // until we can smooth transition private final NavigationBarView mView; - private final Drawable mTransparentBottom; - private final Drawable mTransparentRight; - private final int mTransparentColor; private final IStatusBarService mBarService; private boolean mLightsOut; @@ -46,27 +39,18 @@ public final class NavigationBarTransitions extends BarTransitions { public NavigationBarTransitions(NavigationBarView view) { super(view); mView = view; - final Resources res = mView.getContext().getResources(); - final int[] gradientColors = new int[] { - res.getColor(R.color.navigation_bar_background_transparent_start), - res.getColor(R.color.navigation_bar_background_transparent_end) - }; - mTransparentBottom = new GradientDrawable(Orientation.BOTTOM_TOP, gradientColors); - mTransparentRight = new GradientDrawable(Orientation.RIGHT_LEFT, gradientColors); - mTransparentColor = res.getColor(R.color.status_bar_background_transparent); mBarService = IStatusBarService.Stub.asInterface( ServiceManager.getService(Context.STATUS_BAR_SERVICE)); } - public void setVertical(boolean isVertical) { - if (!ENABLE_GRADIENT) return; - mTransparent = isVertical ? mTransparentRight : mTransparentBottom; + public void init(boolean isVertical) { + setVertical(isVertical); + applyModeBackground(-1, getMode(), false /*animate*/); + applyMode(getMode(), false /*animate*/, true /*force*/); } - @Override - protected Integer getBackgroundColor(int mode) { - if (!ENABLE_GRADIENT && mode == MODE_TRANSPARENT) return mTransparentColor; - return super.getBackgroundColor(mode); + public void setVertical(boolean isVertical) { + setOrientation(isVertical ? Orientation.RIGHT_LEFT : Orientation.BOTTOM_TOP); } @Override @@ -75,10 +59,6 @@ public final class NavigationBarTransitions extends BarTransitions { applyMode(newMode, animate, false /*force*/); } - public void reapplyMode() { - applyMode(getMode(), false /*animate*/, true /*force*/); - } - private void applyMode(int mode, boolean animate, boolean force) { // apply to key buttons final boolean isOpaque = mode == MODE_OPAQUE || mode == MODE_LIGHTS_OUT; diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/NavigationBarView.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/NavigationBarView.java index b56d7be..4849674 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/NavigationBarView.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/NavigationBarView.java @@ -319,7 +319,7 @@ public class NavigationBarView extends LinearLayout { mDeadZone = (DeadZone) mCurrentView.findViewById(R.id.deadzone); // force the low profile & disabled states into compliance - mBarTransitions.reapplyMode(); + mBarTransitions.init(mVertical); setDisabledFlags(mDisabledFlags, true /* force */); setMenuVisibility(mShowMenu, true /* force */); @@ -328,7 +328,6 @@ public class NavigationBarView extends LinearLayout { } setNavigationIconHints(mNavigationIconHints, true); - mBarTransitions.setVertical(mVertical); } @Override diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBar.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBar.java index d15626b..8cc538f 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBar.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBar.java @@ -308,6 +308,7 @@ public class PhoneStatusBar extends BaseStatusBar implements DemoMode { private boolean mAutohideSuspended; private int mStatusBarMode; private int mNavigationBarMode; + private boolean mScreenOn; private final Runnable mAutohide = new Runnable() { @Override @@ -1894,7 +1895,7 @@ public class PhoneStatusBar extends BaseStatusBar implements DemoMode { private void checkBarMode(int mode, int windowState, BarTransitions transitions) { final boolean imeVisible = (mNavigationIconHints & NAVIGATION_HINT_BACK_ALT) != 0; final int finalMode = imeVisible ? MODE_OPAQUE : mode; - final boolean animate = windowState != WINDOW_STATE_HIDDEN; + final boolean animate = mScreenOn && windowState != WINDOW_STATE_HIDDEN; transitions.transitionTo(finalMode, animate); } @@ -2397,6 +2398,7 @@ public class PhoneStatusBar extends BaseStatusBar implements DemoMode { animateCollapsePanels(flags); } else if (Intent.ACTION_SCREEN_OFF.equals(action)) { + mScreenOn = false; // no waiting! makeExpandedInvisible(); notifyNavigationBarScreenOn(false); @@ -2414,6 +2416,7 @@ public class PhoneStatusBar extends BaseStatusBar implements DemoMode { updateShowSearchHoldoff(); } else if (Intent.ACTION_SCREEN_ON.equals(action)) { + mScreenOn = true; // work around problem where mDisplay.getRotation() is not stable while screen is off (bug 7086018) repositionNavigationBar(); notifyNavigationBarScreenOn(true); diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBarTransitions.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBarTransitions.java index b9ffd6e..a492d76 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBarTransitions.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBarTransitions.java @@ -20,19 +20,18 @@ import android.animation.Animator; import android.animation.AnimatorSet; import android.animation.ObjectAnimator; import android.content.res.Resources; -import android.util.Log; +import android.graphics.drawable.GradientDrawable.Orientation; import android.view.View; import com.android.systemui.R; public final class PhoneStatusBarTransitions extends BarTransitions { - private static final float ALPHA_WHEN_TRANSPARENT = 1; - private static final float ALPHA_WHEN_LIGHTS_OUT_BATTERY_CLOCK = 0.5f; - private static final float ALPHA_WHEN_LIGHTS_OUT_NON_BATTERY_CLOCK = 0; + private static final float ICON_ALPHA_WHEN_TRANSPARENT = 1; + private static final float ICON_ALPHA_WHEN_LIGHTS_OUT_BATTERY_CLOCK = 0.5f; + private static final float ICON_ALPHA_WHEN_LIGHTS_OUT_NON_BATTERY_CLOCK = 0; private final PhoneStatusBarView mView; - private final int mTransparent; - private final float mAlphaWhenOpaque; + private final float mIconAlphaWhenOpaque; private View mLeftSide, mStatusIcons, mSignalCluster, mBattery, mClock; private Animator mCurrentAnimation; @@ -41,8 +40,7 @@ public final class PhoneStatusBarTransitions extends BarTransitions { super(view); mView = view; final Resources res = mView.getContext().getResources(); - mTransparent = res.getColor(R.color.status_bar_background_transparent); - mAlphaWhenOpaque = res.getFraction(R.dimen.status_bar_icon_drawing_alpha, 1, 1); + mIconAlphaWhenOpaque = res.getFraction(R.dimen.status_bar_icon_drawing_alpha, 1, 1); } public void init() { @@ -51,27 +49,23 @@ public final class PhoneStatusBarTransitions extends BarTransitions { mSignalCluster = mView.findViewById(R.id.signal_cluster); mBattery = mView.findViewById(R.id.battery); mClock = mView.findViewById(R.id.clock); + setOrientation(Orientation.TOP_BOTTOM); + applyModeBackground(-1, getMode(), false /*animate*/); applyMode(getMode(), false /*animate*/); } - @Override - protected Integer getBackgroundColor(int mode) { - if (mode == MODE_TRANSPARENT) return mTransparent; - return super.getBackgroundColor(mode); - } - public ObjectAnimator animateTransitionTo(View v, float toAlpha) { return ObjectAnimator.ofFloat(v, "alpha", v.getAlpha(), toAlpha); } private float getNonBatteryClockAlphaFor(int mode) { - return mode == MODE_LIGHTS_OUT ? ALPHA_WHEN_LIGHTS_OUT_NON_BATTERY_CLOCK - : isTransparent(mode) ? ALPHA_WHEN_TRANSPARENT - : mAlphaWhenOpaque; + return mode == MODE_LIGHTS_OUT ? ICON_ALPHA_WHEN_LIGHTS_OUT_NON_BATTERY_CLOCK + : isTransparent(mode) ? ICON_ALPHA_WHEN_TRANSPARENT + : mIconAlphaWhenOpaque; } private float getBatteryClockAlpha(int mode) { - return mode == MODE_LIGHTS_OUT ? ALPHA_WHEN_LIGHTS_OUT_BATTERY_CLOCK + return mode == MODE_LIGHTS_OUT ? ICON_ALPHA_WHEN_LIGHTS_OUT_BATTERY_CLOCK : getNonBatteryClockAlphaFor(mode); } |