Merge "Fix rotation button background not showing after first boot." into qt-dev
This commit is contained in:
@@ -16,8 +16,10 @@
|
|||||||
|
|
||||||
package com.android.systemui.statusbar.phone;
|
package com.android.systemui.statusbar.phone;
|
||||||
|
|
||||||
|
import android.annotation.ColorInt;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.res.Resources;
|
import android.content.res.Resources;
|
||||||
|
import android.graphics.Color;
|
||||||
import android.graphics.PixelFormat;
|
import android.graphics.PixelFormat;
|
||||||
import android.view.ContextThemeWrapper;
|
import android.view.ContextThemeWrapper;
|
||||||
import android.view.Gravity;
|
import android.view.Gravity;
|
||||||
@@ -26,6 +28,7 @@ import android.view.Surface;
|
|||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.WindowManager;
|
import android.view.WindowManager;
|
||||||
|
|
||||||
|
import com.android.settingslib.Utils;
|
||||||
import com.android.systemui.R;
|
import com.android.systemui.R;
|
||||||
import com.android.systemui.statusbar.policy.KeyButtonDrawable;
|
import com.android.systemui.statusbar.policy.KeyButtonDrawable;
|
||||||
import com.android.systemui.statusbar.policy.KeyButtonView;
|
import com.android.systemui.statusbar.policy.KeyButtonView;
|
||||||
@@ -33,6 +36,8 @@ import com.android.systemui.statusbar.policy.KeyButtonView;
|
|||||||
/** Containing logic for the rotation button on the physical left bottom corner of the screen. */
|
/** Containing logic for the rotation button on the physical left bottom corner of the screen. */
|
||||||
public class FloatingRotationButton implements RotationButton {
|
public class FloatingRotationButton implements RotationButton {
|
||||||
|
|
||||||
|
private static final float BACKGROUND_ALPHA = 0.92f;
|
||||||
|
|
||||||
private final Context mContext;
|
private final Context mContext;
|
||||||
private final WindowManager mWindowManager;
|
private final WindowManager mWindowManager;
|
||||||
private final KeyButtonView mKeyButtonView;
|
private final KeyButtonView mKeyButtonView;
|
||||||
@@ -151,8 +156,18 @@ public class FloatingRotationButton implements RotationButton {
|
|||||||
public KeyButtonDrawable getImageDrawable() {
|
public KeyButtonDrawable getImageDrawable() {
|
||||||
Context context = new ContextThemeWrapper(mContext.getApplicationContext(),
|
Context context = new ContextThemeWrapper(mContext.getApplicationContext(),
|
||||||
mRotationButtonController.getStyleRes());
|
mRotationButtonController.getStyleRes());
|
||||||
return KeyButtonDrawable.create(context, R.drawable.ic_sysbar_rotate_button,
|
final int dualToneDarkTheme = Utils.getThemeAttr(context, R.attr.darkIconTheme);
|
||||||
false /* shadow */, true /* hasOvalBg */);
|
final int dualToneLightTheme = Utils.getThemeAttr(context, R.attr.lightIconTheme);
|
||||||
|
Context lightContext = new ContextThemeWrapper(context, dualToneLightTheme);
|
||||||
|
Context darkContext = new ContextThemeWrapper(context, dualToneDarkTheme);
|
||||||
|
@ColorInt int darkColor = Utils.getColorAttrDefaultColor(darkContext,
|
||||||
|
R.attr.singleToneColor);
|
||||||
|
Color ovalBackgroundColor = Color.valueOf(Color.red(darkColor), Color.green(darkColor),
|
||||||
|
Color.blue(darkColor), BACKGROUND_ALPHA);
|
||||||
|
|
||||||
|
return KeyButtonDrawable.create(lightContext,
|
||||||
|
Utils.getColorAttrDefaultColor(lightContext, R.attr.singleToneColor), darkColor,
|
||||||
|
R.drawable.ic_sysbar_rotate_button, false /* shadow */, ovalBackgroundColor);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -24,7 +24,6 @@ import android.content.Context;
|
|||||||
import android.view.ContextThemeWrapper;
|
import android.view.ContextThemeWrapper;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
|
|
||||||
import com.android.systemui.shared.system.QuickStepContract;
|
|
||||||
import com.android.systemui.statusbar.policy.KeyButtonDrawable;
|
import com.android.systemui.statusbar.policy.KeyButtonDrawable;
|
||||||
|
|
||||||
/** Containing logic for the rotation button in nav bar. */
|
/** Containing logic for the rotation button in nav bar. */
|
||||||
@@ -61,7 +60,7 @@ public class RotationContextButton extends ContextualButton implements
|
|||||||
Context context = new ContextThemeWrapper(getContext().getApplicationContext(),
|
Context context = new ContextThemeWrapper(getContext().getApplicationContext(),
|
||||||
mRotationButtonController.getStyleRes());
|
mRotationButtonController.getStyleRes());
|
||||||
return KeyButtonDrawable.create(context, mIconResId, false /* shadow */,
|
return KeyButtonDrawable.create(context, mIconResId, false /* shadow */,
|
||||||
QuickStepContract.isGesturalMode(mNavBarMode));
|
null /* ovalBackgroundColor */);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -82,9 +82,9 @@ public class KeyButtonDrawable extends Drawable {
|
|||||||
private AnimatedVectorDrawable mAnimatedDrawable;
|
private AnimatedVectorDrawable mAnimatedDrawable;
|
||||||
|
|
||||||
public KeyButtonDrawable(Drawable d, @ColorInt int lightColor, @ColorInt int darkColor,
|
public KeyButtonDrawable(Drawable d, @ColorInt int lightColor, @ColorInt int darkColor,
|
||||||
boolean horizontalFlip, boolean hasOvalBg) {
|
boolean horizontalFlip, Color ovalBackgroundColor) {
|
||||||
this(d, new ShadowDrawableState(lightColor, darkColor,
|
this(d, new ShadowDrawableState(lightColor, darkColor,
|
||||||
d instanceof AnimatedVectorDrawable, horizontalFlip, hasOvalBg));
|
d instanceof AnimatedVectorDrawable, horizontalFlip, ovalBackgroundColor));
|
||||||
}
|
}
|
||||||
|
|
||||||
private KeyButtonDrawable(Drawable d, ShadowDrawableState state) {
|
private KeyButtonDrawable(Drawable d, ShadowDrawableState state) {
|
||||||
@@ -166,7 +166,7 @@ public class KeyButtonDrawable extends Drawable {
|
|||||||
public void setColorFilter(ColorFilter colorFilter) {
|
public void setColorFilter(ColorFilter colorFilter) {
|
||||||
mIconPaint.setColorFilter(colorFilter);
|
mIconPaint.setColorFilter(colorFilter);
|
||||||
if (mAnimatedDrawable != null) {
|
if (mAnimatedDrawable != null) {
|
||||||
if (mState.mHasOvalBg) {
|
if (hasOvalBg()) {
|
||||||
mAnimatedDrawable.setColorFilter(
|
mAnimatedDrawable.setColorFilter(
|
||||||
new PorterDuffColorFilter(mState.mLightColor, PorterDuff.Mode.SRC_IN));
|
new PorterDuffColorFilter(mState.mLightColor, PorterDuff.Mode.SRC_IN));
|
||||||
} else {
|
} else {
|
||||||
@@ -212,15 +212,6 @@ public class KeyButtonDrawable extends Drawable {
|
|||||||
return mState.mBaseWidth + (mState.mShadowSize + Math.abs(mState.mShadowOffsetX)) * 2;
|
return mState.mBaseWidth + (mState.mShadowSize + Math.abs(mState.mShadowOffsetX)) * 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Return if the drawable has oval background. */
|
|
||||||
public boolean hasOvalBg() {
|
|
||||||
return mState.mHasOvalBg;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getDarkColor() {
|
|
||||||
return mState.mDarkColor;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean canAnimate() {
|
public boolean canAnimate() {
|
||||||
return mState.mSupportsAnimation;
|
return mState.mSupportsAnimation;
|
||||||
}
|
}
|
||||||
@@ -290,6 +281,14 @@ public class KeyButtonDrawable extends Drawable {
|
|||||||
return mState.canApplyTheme();
|
return mState.canApplyTheme();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ColorInt int getDrawableBackgroundColor() {
|
||||||
|
return mState.mOvalBackgroundColor.toArgb();
|
||||||
|
}
|
||||||
|
|
||||||
|
boolean hasOvalBg() {
|
||||||
|
return mState.mOvalBackgroundColor != null;
|
||||||
|
}
|
||||||
|
|
||||||
private void regenerateBitmapIconCache() {
|
private void regenerateBitmapIconCache() {
|
||||||
final int width = getIntrinsicWidth();
|
final int width = getIntrinsicWidth();
|
||||||
final int height = getIntrinsicHeight();
|
final int height = getIntrinsicHeight();
|
||||||
@@ -394,16 +393,16 @@ public class KeyButtonDrawable extends Drawable {
|
|||||||
final int mLightColor;
|
final int mLightColor;
|
||||||
final int mDarkColor;
|
final int mDarkColor;
|
||||||
final boolean mSupportsAnimation;
|
final boolean mSupportsAnimation;
|
||||||
final boolean mHasOvalBg;
|
final Color mOvalBackgroundColor;
|
||||||
|
|
||||||
public ShadowDrawableState(@ColorInt int lightColor, @ColorInt int darkColor,
|
public ShadowDrawableState(@ColorInt int lightColor, @ColorInt int darkColor,
|
||||||
boolean animated, boolean horizontalFlip, boolean hasOvalBg) {
|
boolean animated, boolean horizontalFlip, Color ovalBackgroundColor) {
|
||||||
mLightColor = lightColor;
|
mLightColor = lightColor;
|
||||||
mDarkColor = darkColor;
|
mDarkColor = darkColor;
|
||||||
mSupportsAnimation = animated;
|
mSupportsAnimation = animated;
|
||||||
mAlpha = 255;
|
mAlpha = 255;
|
||||||
mHorizontalFlip = horizontalFlip;
|
mHorizontalFlip = horizontalFlip;
|
||||||
mHasOvalBg = hasOvalBg;
|
mOvalBackgroundColor = ovalBackgroundColor;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -428,16 +427,17 @@ public class KeyButtonDrawable extends Drawable {
|
|||||||
* @param ctx Context to get the drawable and determine the dark and light theme
|
* @param ctx Context to get the drawable and determine the dark and light theme
|
||||||
* @param icon the icon resource id
|
* @param icon the icon resource id
|
||||||
* @param hasShadow if a shadow will appear with the drawable
|
* @param hasShadow if a shadow will appear with the drawable
|
||||||
* @param hasOvalBg if an oval bg will be drawn
|
* @param ovalBackgroundColor the color of the oval bg that will be drawn
|
||||||
* @return KeyButtonDrawable
|
* @return KeyButtonDrawable
|
||||||
*/
|
*/
|
||||||
public static KeyButtonDrawable create(@NonNull Context ctx, @DrawableRes int icon,
|
public static KeyButtonDrawable create(@NonNull Context ctx, @DrawableRes int icon,
|
||||||
boolean hasShadow, boolean hasOvalBg) {
|
boolean hasShadow, Color ovalBackgroundColor) {
|
||||||
final int dualToneDarkTheme = Utils.getThemeAttr(ctx, R.attr.darkIconTheme);
|
final int dualToneDarkTheme = Utils.getThemeAttr(ctx, R.attr.darkIconTheme);
|
||||||
final int dualToneLightTheme = Utils.getThemeAttr(ctx, R.attr.lightIconTheme);
|
final int dualToneLightTheme = Utils.getThemeAttr(ctx, R.attr.lightIconTheme);
|
||||||
Context lightContext = new ContextThemeWrapper(ctx, dualToneLightTheme);
|
Context lightContext = new ContextThemeWrapper(ctx, dualToneLightTheme);
|
||||||
Context darkContext = new ContextThemeWrapper(ctx, dualToneDarkTheme);
|
Context darkContext = new ContextThemeWrapper(ctx, dualToneDarkTheme);
|
||||||
return KeyButtonDrawable.create(lightContext, darkContext, icon, hasShadow, hasOvalBg);
|
return KeyButtonDrawable.create(lightContext, darkContext, icon, hasShadow,
|
||||||
|
ovalBackgroundColor);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -446,7 +446,7 @@ public class KeyButtonDrawable extends Drawable {
|
|||||||
*/
|
*/
|
||||||
public static KeyButtonDrawable create(@NonNull Context ctx, @DrawableRes int icon,
|
public static KeyButtonDrawable create(@NonNull Context ctx, @DrawableRes int icon,
|
||||||
boolean hasShadow) {
|
boolean hasShadow) {
|
||||||
return create(ctx, icon, hasShadow, false /* hasOvalBg */);
|
return create(ctx, icon, hasShadow, null /* ovalBackgroundColor */);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -454,11 +454,11 @@ public class KeyButtonDrawable extends Drawable {
|
|||||||
* {@link #create(Context, int, boolean, boolean)}.
|
* {@link #create(Context, int, boolean, boolean)}.
|
||||||
*/
|
*/
|
||||||
public static KeyButtonDrawable create(Context lightContext, Context darkContext,
|
public static KeyButtonDrawable create(Context lightContext, Context darkContext,
|
||||||
@DrawableRes int iconResId, boolean hasShadow, boolean hasOvalBg) {
|
@DrawableRes int iconResId, boolean hasShadow, Color ovalBackgroundColor) {
|
||||||
return create(lightContext,
|
return create(lightContext,
|
||||||
Utils.getColorAttrDefaultColor(lightContext, R.attr.singleToneColor),
|
Utils.getColorAttrDefaultColor(lightContext, R.attr.singleToneColor),
|
||||||
Utils.getColorAttrDefaultColor(darkContext, R.attr.singleToneColor),
|
Utils.getColorAttrDefaultColor(darkContext, R.attr.singleToneColor),
|
||||||
iconResId, hasShadow, hasOvalBg);
|
iconResId, hasShadow, ovalBackgroundColor);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -467,12 +467,12 @@ public class KeyButtonDrawable extends Drawable {
|
|||||||
*/
|
*/
|
||||||
public static KeyButtonDrawable create(Context context, @ColorInt int lightColor,
|
public static KeyButtonDrawable create(Context context, @ColorInt int lightColor,
|
||||||
@ColorInt int darkColor, @DrawableRes int iconResId, boolean hasShadow,
|
@ColorInt int darkColor, @DrawableRes int iconResId, boolean hasShadow,
|
||||||
boolean hasOvalBg) {
|
Color ovalBackgroundColor) {
|
||||||
final Resources res = context.getResources();
|
final Resources res = context.getResources();
|
||||||
boolean isRtl = res.getConfiguration().getLayoutDirection() == View.LAYOUT_DIRECTION_RTL;
|
boolean isRtl = res.getConfiguration().getLayoutDirection() == View.LAYOUT_DIRECTION_RTL;
|
||||||
Drawable d = context.getDrawable(iconResId);
|
Drawable d = context.getDrawable(iconResId);
|
||||||
final KeyButtonDrawable drawable = new KeyButtonDrawable(d, lightColor, darkColor,
|
final KeyButtonDrawable drawable = new KeyButtonDrawable(d, lightColor, darkColor,
|
||||||
isRtl && d.isAutoMirrored(), hasOvalBg);
|
isRtl && d.isAutoMirrored(), ovalBackgroundColor);
|
||||||
if (hasShadow) {
|
if (hasShadow) {
|
||||||
int offsetX = res.getDimensionPixelSize(R.dimen.nav_key_button_shadow_offset_x);
|
int offsetX = res.getDimensionPixelSize(R.dimen.nav_key_button_shadow_offset_x);
|
||||||
int offsetY = res.getDimensionPixelSize(R.dimen.nav_key_button_shadow_offset_y);
|
int offsetY = res.getDimensionPixelSize(R.dimen.nav_key_button_shadow_offset_y);
|
||||||
|
|||||||
@@ -79,6 +79,7 @@ public class KeyButtonView extends ImageView implements ButtonInterface {
|
|||||||
private final MetricsLogger mMetricsLogger = Dependency.get(MetricsLogger.class);
|
private final MetricsLogger mMetricsLogger = Dependency.get(MetricsLogger.class);
|
||||||
private final InputManager mInputManager;
|
private final InputManager mInputManager;
|
||||||
private final Paint mOvalBgPaint = new Paint(Paint.ANTI_ALIAS_FLAG | Paint.FILTER_BITMAP_FLAG);
|
private final Paint mOvalBgPaint = new Paint(Paint.ANTI_ALIAS_FLAG | Paint.FILTER_BITMAP_FLAG);
|
||||||
|
private float mDarkIntensity;
|
||||||
private boolean mHasOvalBg = false;
|
private boolean mHasOvalBg = false;
|
||||||
|
|
||||||
private final Runnable mCheckLongPress = new Runnable() {
|
private final Runnable mCheckLongPress = new Runnable() {
|
||||||
@@ -304,6 +305,23 @@ public class KeyButtonView extends ImageView implements ButtonInterface {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setImageDrawable(Drawable drawable) {
|
||||||
|
super.setImageDrawable(drawable);
|
||||||
|
|
||||||
|
if (drawable == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
KeyButtonDrawable keyButtonDrawable = (KeyButtonDrawable) drawable;
|
||||||
|
keyButtonDrawable.setDarkIntensity(mDarkIntensity);
|
||||||
|
mHasOvalBg = keyButtonDrawable.hasOvalBg();
|
||||||
|
if (mHasOvalBg) {
|
||||||
|
mOvalBgPaint.setColor(keyButtonDrawable.getDrawableBackgroundColor());
|
||||||
|
}
|
||||||
|
mRipple.setType(keyButtonDrawable.hasOvalBg() ? KeyButtonRipple.Type.OVAL
|
||||||
|
: KeyButtonRipple.Type.ROUNDED_RECT);
|
||||||
|
}
|
||||||
|
|
||||||
public void playSoundEffect(int soundConstant) {
|
public void playSoundEffect(int soundConstant) {
|
||||||
if (!mPlaySounds) return;
|
if (!mPlaySounds) return;
|
||||||
mAudioManager.playSoundEffect(soundConstant, ActivityManager.getCurrentUser());
|
mAudioManager.playSoundEffect(soundConstant, ActivityManager.getCurrentUser());
|
||||||
@@ -360,17 +378,11 @@ public class KeyButtonView extends ImageView implements ButtonInterface {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setDarkIntensity(float darkIntensity) {
|
public void setDarkIntensity(float darkIntensity) {
|
||||||
|
mDarkIntensity = darkIntensity;
|
||||||
|
|
||||||
Drawable drawable = getDrawable();
|
Drawable drawable = getDrawable();
|
||||||
if (drawable != null) {
|
if (drawable != null) {
|
||||||
KeyButtonDrawable keyButtonDrawable = (KeyButtonDrawable) drawable;
|
((KeyButtonDrawable) drawable).setDarkIntensity(darkIntensity);
|
||||||
keyButtonDrawable.setDarkIntensity(darkIntensity);
|
|
||||||
mHasOvalBg = keyButtonDrawable.hasOvalBg();
|
|
||||||
if (mHasOvalBg) {
|
|
||||||
mOvalBgPaint.setColor(keyButtonDrawable.getDarkColor());
|
|
||||||
}
|
|
||||||
mRipple.setType(keyButtonDrawable.hasOvalBg() ? KeyButtonRipple.Type.OVAL
|
|
||||||
: KeyButtonRipple.Type.ROUNDED_RECT);
|
|
||||||
|
|
||||||
// Since we reuse the same drawable for multiple views, we need to invalidate the view
|
// Since we reuse the same drawable for multiple views, we need to invalidate the view
|
||||||
// manually.
|
// manually.
|
||||||
invalidate();
|
invalidate();
|
||||||
|
|||||||
@@ -180,9 +180,9 @@ public class NavigationBarContextTest extends SysuiTestCase {
|
|||||||
final Drawable d = mock(Drawable.class);
|
final Drawable d = mock(Drawable.class);
|
||||||
final ContextualButton button = spy(mBtn0);
|
final ContextualButton button = spy(mBtn0);
|
||||||
final KeyButtonDrawable kbd1 = spy(new KeyButtonDrawable(d, unusedColor, unusedColor,
|
final KeyButtonDrawable kbd1 = spy(new KeyButtonDrawable(d, unusedColor, unusedColor,
|
||||||
false /* horizontalFlip */, false /* hasOvalBg */));
|
false /* horizontalFlip */, null /* ovalBackgroundColor */));
|
||||||
final KeyButtonDrawable kbd2 = spy(new KeyButtonDrawable(d, unusedColor, unusedColor,
|
final KeyButtonDrawable kbd2 = spy(new KeyButtonDrawable(d, unusedColor, unusedColor,
|
||||||
false /* horizontalFlip */, false /* hasOvalBg */));
|
false /* horizontalFlip */, null /* ovalBackgroundColor */));
|
||||||
kbd1.setDarkIntensity(TEST_DARK_INTENSITY);
|
kbd1.setDarkIntensity(TEST_DARK_INTENSITY);
|
||||||
kbd2.setDarkIntensity(0f);
|
kbd2.setDarkIntensity(0f);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user