Merge "Lose navigation bar icon alpha in transparent modes." into klp-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
9bf6f5b05a
@@ -20,7 +20,7 @@
|
||||
<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_transient">#55000000</color>
|
||||
<color name="status_bar_background_semi_transparent">#55000000</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>
|
||||
|
||||
@@ -30,24 +30,24 @@ public class BarTransitions {
|
||||
private static final boolean DEBUG = false;
|
||||
|
||||
public static final int MODE_NORMAL = 0;
|
||||
public static final int MODE_TRANSIENT = 1;
|
||||
public static final int MODE_SEMI_TRANSPARENT = 1;
|
||||
public static final int MODE_TRANSPARENT = 2;
|
||||
|
||||
private final String mTag;
|
||||
private final View mTarget;
|
||||
private final Drawable mOpaque;
|
||||
private final Drawable mTransient;
|
||||
private final Drawable mSemiTransparent;
|
||||
|
||||
private Drawable mTransparent;
|
||||
protected Drawable mTransparent;
|
||||
private int mMode;
|
||||
|
||||
public BarTransitions(Context context, View target, Drawable transparent) {
|
||||
public BarTransitions(Context context, View target) {
|
||||
mTag = "BarTransitions." + target.getClass().getSimpleName();
|
||||
mTarget = target;
|
||||
final Resources res = context.getResources();
|
||||
mOpaque = new ColorDrawable(res.getColor(R.drawable.status_bar_background));
|
||||
mTransient = new ColorDrawable(res.getColor(R.color.status_bar_background_transient));
|
||||
mTransparent = transparent;
|
||||
mSemiTransparent =
|
||||
new ColorDrawable(res.getColor(R.color.status_bar_background_semi_transparent));
|
||||
}
|
||||
|
||||
public void setTransparent(Drawable transparent) {
|
||||
@@ -58,18 +58,25 @@ public class BarTransitions {
|
||||
}
|
||||
|
||||
public void transitionTo(int mode) {
|
||||
if (mMode == mode) return;
|
||||
int oldMode = mMode;
|
||||
mMode = mode;
|
||||
if (!ActivityManager.isHighEndGfx()) return;
|
||||
if (DEBUG) Log.d(mTag, "transitionTo " + modeToString(mode));
|
||||
Drawable background = mode == MODE_TRANSIENT ? mTransient
|
||||
: mode == MODE_TRANSPARENT ? mTransparent
|
||||
if (DEBUG) Log.d(mTag, String.format("transition from %s to %s",
|
||||
modeToString(oldMode), modeToString(mode)));
|
||||
onTransition(oldMode, mMode);
|
||||
}
|
||||
|
||||
protected void onTransition(int oldMode, int newMode) {
|
||||
Drawable background = newMode == MODE_SEMI_TRANSPARENT ? mSemiTransparent
|
||||
: newMode == MODE_TRANSPARENT ? mTransparent
|
||||
: mOpaque;
|
||||
mTarget.setBackground(background);
|
||||
}
|
||||
|
||||
public static String modeToString(int mode) {
|
||||
if (mode == MODE_NORMAL) return "MODE_NORMAL";
|
||||
if (mode == MODE_TRANSIENT) return "MODE_TRANSIENT";
|
||||
if (mode == MODE_SEMI_TRANSPARENT) return "MODE_SEMI_TRANSPARENT";
|
||||
if (mode == MODE_TRANSPARENT) return "MODE_TRANSPARENT";
|
||||
throw new IllegalArgumentException("Unknown mode " + mode);
|
||||
}
|
||||
|
||||
@@ -47,6 +47,7 @@ import com.android.systemui.R;
|
||||
import com.android.systemui.statusbar.BaseStatusBar;
|
||||
import com.android.systemui.statusbar.DelegateViewHelper;
|
||||
import com.android.systemui.statusbar.policy.DeadZone;
|
||||
import com.android.systemui.statusbar.policy.KeyButtonView;
|
||||
|
||||
import java.io.FileDescriptor;
|
||||
import java.io.PrintWriter;
|
||||
@@ -81,9 +82,7 @@ public class NavigationBarView extends LinearLayout {
|
||||
|
||||
private DelegateViewHelper mDelegateHelper;
|
||||
private DeadZone mDeadZone;
|
||||
private final BarTransitions mBarTransitions;
|
||||
private final Drawable mTransparent;
|
||||
private final Drawable mTransparentVertical;
|
||||
private final NavigationBarTransitions mBarTransitions;
|
||||
|
||||
// workaround for LayoutTransitions leaving the nav buttons in a weird state (bug 5549288)
|
||||
final static boolean WORKAROUND_INVALID_LAYOUT = true;
|
||||
@@ -112,6 +111,43 @@ public class NavigationBarView extends LinearLayout {
|
||||
}
|
||||
}
|
||||
|
||||
private final class NavigationBarTransitions extends BarTransitions {
|
||||
|
||||
private final Drawable mTransparentBottom;
|
||||
private final Drawable mTransparentRight;
|
||||
|
||||
public NavigationBarTransitions(Context context) {
|
||||
super(context, NavigationBarView.this);
|
||||
final Resources res = mContext.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);
|
||||
}
|
||||
|
||||
public void setVertical(boolean isVertical) {
|
||||
mTransparent = isVertical ? mTransparentRight : mTransparentBottom;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onTransition(int oldMode, int newMode) {
|
||||
super.onTransition(oldMode, newMode);
|
||||
final float alpha = newMode == MODE_NORMAL ? KeyButtonView.DEFAULT_QUIESCENT_ALPHA : 1f;
|
||||
setKeyButtonViewQuiescentAlpha(getBackButton(), alpha);
|
||||
setKeyButtonViewQuiescentAlpha(getHomeButton(), alpha);
|
||||
setKeyButtonViewQuiescentAlpha(getRecentsButton(), alpha);
|
||||
setKeyButtonViewQuiescentAlpha(getMenuButton(), alpha);
|
||||
}
|
||||
|
||||
private void setKeyButtonViewQuiescentAlpha(View button, float alpha) {
|
||||
if (button instanceof KeyButtonView) {
|
||||
((KeyButtonView) button).setQuiescentAlpha(alpha);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public NavigationBarView(Context context, AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
|
||||
@@ -130,13 +166,7 @@ public class NavigationBarView extends LinearLayout {
|
||||
|
||||
getIcons(res);
|
||||
|
||||
final int[] gradientColors = new int[] {
|
||||
res.getColor(R.color.navigation_bar_background_transparent_start),
|
||||
res.getColor(R.color.navigation_bar_background_transparent_end)
|
||||
};
|
||||
mTransparent = new GradientDrawable(Orientation.BOTTOM_TOP, gradientColors);
|
||||
mTransparentVertical = new GradientDrawable(Orientation.RIGHT_LEFT, gradientColors);
|
||||
mBarTransitions = new BarTransitions(context, this, mTransparent);
|
||||
mBarTransitions = new NavigationBarTransitions(context);
|
||||
}
|
||||
|
||||
public BarTransitions getBarTransitions() {
|
||||
@@ -423,7 +453,7 @@ public class NavigationBarView extends LinearLayout {
|
||||
}
|
||||
|
||||
setNavigationIconHints(mNavigationIconHints, true);
|
||||
mBarTransitions.setTransparent(mVertical ? mTransparentVertical : mTransparent);
|
||||
mBarTransitions.setVertical(mVertical);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
package com.android.systemui.statusbar.phone;
|
||||
|
||||
import static com.android.systemui.statusbar.phone.BarTransitions.MODE_NORMAL;
|
||||
import static com.android.systemui.statusbar.phone.BarTransitions.MODE_TRANSIENT;
|
||||
import static com.android.systemui.statusbar.phone.BarTransitions.MODE_SEMI_TRANSPARENT;
|
||||
import static com.android.systemui.statusbar.phone.BarTransitions.MODE_TRANSPARENT;
|
||||
|
||||
import android.animation.Animator;
|
||||
@@ -1912,7 +1912,7 @@ public class PhoneStatusBar extends BaseStatusBar {
|
||||
|
||||
if (sbMode != -1 || nbMode != -1) {
|
||||
// update transient bar autohide
|
||||
if (sbMode == MODE_TRANSIENT || nbMode == MODE_TRANSIENT) {
|
||||
if (sbMode == MODE_SEMI_TRANSPARENT || nbMode == MODE_SEMI_TRANSPARENT) {
|
||||
scheduleAutohide();
|
||||
} else {
|
||||
cancelAutohide();
|
||||
@@ -1936,7 +1936,7 @@ public class PhoneStatusBar extends BaseStatusBar {
|
||||
}
|
||||
|
||||
private int barMode(int vis, int transientFlag, int transparentFlag) {
|
||||
return (vis & transientFlag) != 0 ? MODE_TRANSIENT
|
||||
return (vis & transientFlag) != 0 ? MODE_SEMI_TRANSPARENT
|
||||
: (vis & transparentFlag) != 0 ? MODE_TRANSPARENT
|
||||
: MODE_NORMAL;
|
||||
}
|
||||
|
||||
@@ -46,7 +46,15 @@ public class PhoneStatusBarView extends PanelBar {
|
||||
PanelView mLastFullyOpenedPanel = null;
|
||||
PanelView mNotificationPanel, mSettingsPanel;
|
||||
private boolean mShouldFade;
|
||||
private final BarTransitions mBarTransitions;
|
||||
private final StatusBarTransitions mBarTransitions;
|
||||
|
||||
private final class StatusBarTransitions extends BarTransitions {
|
||||
public StatusBarTransitions(Context context) {
|
||||
super(context, PhoneStatusBarView.this);
|
||||
final Resources res = context.getResources();
|
||||
mTransparent = res.getDrawable(R.color.status_bar_background_transparent);
|
||||
}
|
||||
}
|
||||
|
||||
public PhoneStatusBarView(Context context, AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
@@ -60,8 +68,7 @@ public class PhoneStatusBarView extends PanelBar {
|
||||
mSettingsPanelDragzoneFrac = 0f;
|
||||
}
|
||||
mFullWidthNotifications = mSettingsPanelDragzoneFrac <= 0f;
|
||||
final Drawable transparent = res.getDrawable(R.color.status_bar_background_transparent);
|
||||
mBarTransitions = new BarTransitions(context, this, transparent);
|
||||
mBarTransitions = new StatusBarTransitions(context);
|
||||
}
|
||||
|
||||
public BarTransitions getBarTransitions() {
|
||||
|
||||
@@ -16,6 +16,9 @@
|
||||
|
||||
package com.android.systemui.statusbar.policy;
|
||||
|
||||
import android.animation.Animator;
|
||||
import android.animation.Animator.AnimatorListener;
|
||||
import android.animation.AnimatorListenerAdapter;
|
||||
import android.animation.AnimatorSet;
|
||||
import android.animation.ObjectAnimator;
|
||||
import android.content.Context;
|
||||
@@ -26,6 +29,7 @@ import android.graphics.drawable.Drawable;
|
||||
import android.hardware.input.InputManager;
|
||||
import android.os.SystemClock;
|
||||
import android.util.AttributeSet;
|
||||
import android.util.Log;
|
||||
import android.view.HapticFeedbackConstants;
|
||||
import android.view.InputDevice;
|
||||
import android.view.KeyCharacterMap;
|
||||
@@ -41,9 +45,10 @@ import com.android.systemui.R;
|
||||
|
||||
public class KeyButtonView extends ImageView {
|
||||
private static final String TAG = "StatusBar.KeyButtonView";
|
||||
private static final boolean DEBUG = false;
|
||||
|
||||
final float GLOW_MAX_SCALE_FACTOR = 1.8f;
|
||||
final float BUTTON_QUIESCENT_ALPHA = 0.70f;
|
||||
public static final float DEFAULT_QUIESCENT_ALPHA = 0.70f;
|
||||
|
||||
long mDownTime;
|
||||
int mCode;
|
||||
@@ -51,6 +56,7 @@ public class KeyButtonView extends ImageView {
|
||||
Drawable mGlowBG;
|
||||
int mGlowWidth, mGlowHeight;
|
||||
float mGlowAlpha = 0f, mGlowScale = 1f, mDrawingAlpha = 1f;
|
||||
float mQuiescentAlpha = DEFAULT_QUIESCENT_ALPHA;
|
||||
boolean mSupportsLongpress = true;
|
||||
RectF mRect = new RectF(0f,0f,0f,0f);
|
||||
AnimatorSet mPressedAnim;
|
||||
@@ -70,6 +76,15 @@ public class KeyButtonView extends ImageView {
|
||||
}
|
||||
};
|
||||
|
||||
private final AnimatorListener mRecoverToQuiescentListener = new AnimatorListenerAdapter() {
|
||||
@Override
|
||||
public void onAnimationEnd(Animator animation) {
|
||||
if (mQuiescentAlpha != mDrawingAlpha) {
|
||||
animateToQuiescent().setDuration(200).start();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
public KeyButtonView(Context context, AttributeSet attrs) {
|
||||
this(context, attrs, 0);
|
||||
}
|
||||
@@ -86,7 +101,7 @@ public class KeyButtonView extends ImageView {
|
||||
|
||||
mGlowBG = a.getDrawable(R.styleable.KeyButtonView_glowBackground);
|
||||
if (mGlowBG != null) {
|
||||
setDrawingAlpha(BUTTON_QUIESCENT_ALPHA);
|
||||
setDrawingAlpha(mQuiescentAlpha);
|
||||
mGlowWidth = mGlowBG.getIntrinsicWidth();
|
||||
mGlowHeight = mGlowBG.getIntrinsicHeight();
|
||||
}
|
||||
@@ -118,6 +133,16 @@ public class KeyButtonView extends ImageView {
|
||||
super.onDraw(canvas);
|
||||
}
|
||||
|
||||
public void setQuiescentAlpha(float alpha) {
|
||||
alpha = Math.min(Math.max(alpha, 0), 1);
|
||||
if (alpha == mQuiescentAlpha) return;
|
||||
mQuiescentAlpha = alpha;
|
||||
if (DEBUG) Log.d(TAG, "New quiescent alpha = " + mQuiescentAlpha);
|
||||
if (mGlowBG != null) {
|
||||
setDrawingAlpha(mQuiescentAlpha);
|
||||
}
|
||||
}
|
||||
|
||||
public float getDrawingAlpha() {
|
||||
if (mGlowBG == null) return 0;
|
||||
return mDrawingAlpha;
|
||||
@@ -172,6 +197,12 @@ public class KeyButtonView extends ImageView {
|
||||
}
|
||||
}
|
||||
|
||||
private ObjectAnimator animateToQuiescent() {
|
||||
ObjectAnimator anim = ObjectAnimator.ofFloat(this, "drawingAlpha", mQuiescentAlpha);
|
||||
anim.addListener(mRecoverToQuiescentListener); // mQuiescentAlpha may change mid-animation
|
||||
return anim;
|
||||
}
|
||||
|
||||
public void setPressed(boolean pressed) {
|
||||
if (mGlowBG != null) {
|
||||
if (pressed != isPressed()) {
|
||||
@@ -182,8 +213,8 @@ public class KeyButtonView extends ImageView {
|
||||
if (pressed) {
|
||||
if (mGlowScale < GLOW_MAX_SCALE_FACTOR)
|
||||
mGlowScale = GLOW_MAX_SCALE_FACTOR;
|
||||
if (mGlowAlpha < BUTTON_QUIESCENT_ALPHA)
|
||||
mGlowAlpha = BUTTON_QUIESCENT_ALPHA;
|
||||
if (mGlowAlpha < mQuiescentAlpha)
|
||||
mGlowAlpha = mQuiescentAlpha;
|
||||
setDrawingAlpha(1f);
|
||||
as.playTogether(
|
||||
ObjectAnimator.ofFloat(this, "glowAlpha", 1f),
|
||||
@@ -194,7 +225,7 @@ public class KeyButtonView extends ImageView {
|
||||
as.playTogether(
|
||||
ObjectAnimator.ofFloat(this, "glowAlpha", 0f),
|
||||
ObjectAnimator.ofFloat(this, "glowScale", 1f),
|
||||
ObjectAnimator.ofFloat(this, "drawingAlpha", BUTTON_QUIESCENT_ALPHA)
|
||||
animateToQuiescent()
|
||||
);
|
||||
as.setDuration(500);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user