Merge "Use nav bar color for invocation lights" into qt-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
31167d1d64
@@ -21,7 +21,6 @@ import static com.android.systemui.assist.AssistManager.DISMISS_REASON_INVOCATIO
|
|||||||
import android.animation.Animator;
|
import android.animation.Animator;
|
||||||
import android.animation.AnimatorListenerAdapter;
|
import android.animation.AnimatorListenerAdapter;
|
||||||
import android.animation.ValueAnimator;
|
import android.animation.ValueAnimator;
|
||||||
import android.annotation.ColorInt;
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.graphics.PixelFormat;
|
import android.graphics.PixelFormat;
|
||||||
import android.metrics.LogMaker;
|
import android.metrics.LogMaker;
|
||||||
@@ -52,6 +51,7 @@ public class DefaultUiController implements AssistManager.UiController {
|
|||||||
private static final long ANIM_DURATION_MS = 200;
|
private static final long ANIM_DURATION_MS = 200;
|
||||||
|
|
||||||
protected final FrameLayout mRoot;
|
protected final FrameLayout mRoot;
|
||||||
|
protected InvocationLightsView mInvocationLightsView;
|
||||||
|
|
||||||
private final WindowManager mWindowManager;
|
private final WindowManager mWindowManager;
|
||||||
private final WindowManager.LayoutParams mLayoutParams;
|
private final WindowManager.LayoutParams mLayoutParams;
|
||||||
@@ -62,7 +62,6 @@ public class DefaultUiController implements AssistManager.UiController {
|
|||||||
private float mLastInvocationProgress = 0;
|
private float mLastInvocationProgress = 0;
|
||||||
|
|
||||||
private ValueAnimator mInvocationAnimator = new ValueAnimator();
|
private ValueAnimator mInvocationAnimator = new ValueAnimator();
|
||||||
private InvocationLightsView mInvocationLightsView;
|
|
||||||
|
|
||||||
public DefaultUiController(Context context) {
|
public DefaultUiController(Context context) {
|
||||||
mRoot = new FrameLayout(context);
|
mRoot = new FrameLayout(context);
|
||||||
@@ -129,14 +128,6 @@ public class DefaultUiController implements AssistManager.UiController {
|
|||||||
updateAssistHandleVisibility();
|
updateAssistHandleVisibility();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Sets the colors of the four invocation lights, from left to right.
|
|
||||||
*/
|
|
||||||
public void setInvocationColors(@ColorInt int color1, @ColorInt int color2,
|
|
||||||
@ColorInt int color3, @ColorInt int color4) {
|
|
||||||
mInvocationLightsView.setColors(color1, color2, color3, color4);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected static void logInvocationProgressMetrics(
|
protected static void logInvocationProgressMetrics(
|
||||||
int type, float progress, boolean invocationWasInProgress) {
|
int type, float progress, boolean invocationWasInProgress) {
|
||||||
// Logs assistant invocation start.
|
// Logs assistant invocation start.
|
||||||
|
|||||||
@@ -16,24 +16,34 @@
|
|||||||
|
|
||||||
package com.android.systemui.assist.ui;
|
package com.android.systemui.assist.ui;
|
||||||
|
|
||||||
|
import android.animation.ArgbEvaluator;
|
||||||
import android.annotation.ColorInt;
|
import android.annotation.ColorInt;
|
||||||
|
import android.annotation.Nullable;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.graphics.Canvas;
|
import android.graphics.Canvas;
|
||||||
|
import android.graphics.Color;
|
||||||
import android.graphics.Paint;
|
import android.graphics.Paint;
|
||||||
import android.graphics.Path;
|
import android.graphics.Path;
|
||||||
import android.util.AttributeSet;
|
import android.util.AttributeSet;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.util.MathUtils;
|
import android.util.MathUtils;
|
||||||
|
import android.view.ContextThemeWrapper;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
|
|
||||||
|
import com.android.settingslib.Utils;
|
||||||
|
import com.android.systemui.Dependency;
|
||||||
import com.android.systemui.R;
|
import com.android.systemui.R;
|
||||||
|
import com.android.systemui.statusbar.NavigationBarController;
|
||||||
|
import com.android.systemui.statusbar.phone.NavigationBarFragment;
|
||||||
|
import com.android.systemui.statusbar.phone.NavigationBarTransitions;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Shows lights at the bottom of the phone, marking the invocation progress.
|
* Shows lights at the bottom of the phone, marking the invocation progress.
|
||||||
*/
|
*/
|
||||||
public class InvocationLightsView extends View {
|
public class InvocationLightsView extends View
|
||||||
|
implements NavigationBarTransitions.DarkIntensityListener {
|
||||||
|
|
||||||
private static final String TAG = "InvocationLightsView";
|
private static final String TAG = "InvocationLightsView";
|
||||||
|
|
||||||
@@ -49,9 +59,16 @@ public class InvocationLightsView extends View {
|
|||||||
// allocation on each frame.
|
// allocation on each frame.
|
||||||
private final Path mPath = new Path();
|
private final Path mPath = new Path();
|
||||||
private final int mViewHeight;
|
private final int mViewHeight;
|
||||||
|
private final int mStrokeWidth;
|
||||||
|
@ColorInt
|
||||||
|
private final int mLightColor;
|
||||||
|
@ColorInt
|
||||||
|
private final int mDarkColor;
|
||||||
|
|
||||||
// Allocate variable for screen location lookup to avoid memory alloc onDraw()
|
// Allocate variable for screen location lookup to avoid memory alloc onDraw()
|
||||||
private int[] mScreenLocation = new int[2];
|
private int[] mScreenLocation = new int[2];
|
||||||
|
private boolean mRegistered = false;
|
||||||
|
private boolean mUseNavBarColor = true;
|
||||||
|
|
||||||
public InvocationLightsView(Context context) {
|
public InvocationLightsView(Context context) {
|
||||||
this(context, null);
|
this(context, null);
|
||||||
@@ -69,8 +86,8 @@ public class InvocationLightsView extends View {
|
|||||||
int defStyleRes) {
|
int defStyleRes) {
|
||||||
super(context, attrs, defStyleAttr, defStyleRes);
|
super(context, attrs, defStyleAttr, defStyleRes);
|
||||||
|
|
||||||
int strokeWidth = DisplayUtils.convertDpToPx(LIGHT_HEIGHT_DP, context);
|
mStrokeWidth = DisplayUtils.convertDpToPx(LIGHT_HEIGHT_DP, context);
|
||||||
mPaint.setStrokeWidth(strokeWidth);
|
mPaint.setStrokeWidth(mStrokeWidth);
|
||||||
mPaint.setStyle(Paint.Style.STROKE);
|
mPaint.setStyle(Paint.Style.STROKE);
|
||||||
mPaint.setStrokeJoin(Paint.Join.MITER);
|
mPaint.setStrokeJoin(Paint.Join.MITER);
|
||||||
mPaint.setAntiAlias(true);
|
mPaint.setAntiAlias(true);
|
||||||
@@ -82,13 +99,19 @@ public class InvocationLightsView extends View {
|
|||||||
CircularCornerPathRenderer cornerPathRenderer = new CircularCornerPathRenderer(
|
CircularCornerPathRenderer cornerPathRenderer = new CircularCornerPathRenderer(
|
||||||
cornerRadiusBottom, cornerRadiusTop, displayWidth, displayHeight);
|
cornerRadiusBottom, cornerRadiusTop, displayWidth, displayHeight);
|
||||||
mGuide = new PerimeterPathGuide(context, cornerPathRenderer,
|
mGuide = new PerimeterPathGuide(context, cornerPathRenderer,
|
||||||
strokeWidth / 2, displayWidth, displayHeight);
|
mStrokeWidth / 2, displayWidth, displayHeight);
|
||||||
|
|
||||||
mViewHeight = Math.max(cornerRadiusBottom, cornerRadiusTop);
|
mViewHeight = Math.max(cornerRadiusBottom, cornerRadiusTop);
|
||||||
|
|
||||||
@ColorInt int lightColor = getResources().getColor(R.color.default_invocation_lights_color);
|
final int dualToneDarkTheme = Utils.getThemeAttr(mContext, R.attr.darkIconTheme);
|
||||||
|
final int dualToneLightTheme = Utils.getThemeAttr(mContext, R.attr.lightIconTheme);
|
||||||
|
Context lightContext = new ContextThemeWrapper(mContext, dualToneLightTheme);
|
||||||
|
Context darkContext = new ContextThemeWrapper(mContext, dualToneDarkTheme);
|
||||||
|
mLightColor = Utils.getColorAttrDefaultColor(lightContext, R.attr.singleToneColor);
|
||||||
|
mDarkColor = Utils.getColorAttrDefaultColor(darkContext, R.attr.singleToneColor);
|
||||||
|
|
||||||
for (int i = 0; i < 4; i++) {
|
for (int i = 0; i < 4; i++) {
|
||||||
mAssistInvocationLights.add(new EdgeLight(lightColor, 0, 0));
|
mAssistInvocationLights.add(new EdgeLight(Color.TRANSPARENT, 0, 0));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -100,6 +123,8 @@ public class InvocationLightsView extends View {
|
|||||||
if (progress == 0) {
|
if (progress == 0) {
|
||||||
setVisibility(View.GONE);
|
setVisibility(View.GONE);
|
||||||
} else {
|
} else {
|
||||||
|
attemptRegisterNavBarListener();
|
||||||
|
|
||||||
float cornerLengthNormalized =
|
float cornerLengthNormalized =
|
||||||
mGuide.getRegionWidth(PerimeterPathGuide.Region.BOTTOM_LEFT);
|
mGuide.getRegionWidth(PerimeterPathGuide.Region.BOTTOM_LEFT);
|
||||||
float arcLengthNormalized = cornerLengthNormalized * MINIMUM_CORNER_RATIO;
|
float arcLengthNormalized = cornerLengthNormalized * MINIMUM_CORNER_RATIO;
|
||||||
@@ -131,6 +156,21 @@ public class InvocationLightsView extends View {
|
|||||||
for (EdgeLight light : mAssistInvocationLights) {
|
for (EdgeLight light : mAssistInvocationLights) {
|
||||||
light.setLength(0);
|
light.setLength(0);
|
||||||
}
|
}
|
||||||
|
attemptUnregisterNavBarListener();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets all invocation lights to a single color. If color is null, uses the navigation bar
|
||||||
|
* color (updated when the nav bar color changes).
|
||||||
|
*/
|
||||||
|
public void setColors(@Nullable @ColorInt Integer color) {
|
||||||
|
if (color == null) {
|
||||||
|
mUseNavBarColor = true;
|
||||||
|
mPaint.setStrokeCap(Paint.Cap.BUTT);
|
||||||
|
attemptRegisterNavBarListener();
|
||||||
|
} else {
|
||||||
|
setColors(color, color, color, color);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -138,12 +178,25 @@ public class InvocationLightsView extends View {
|
|||||||
*/
|
*/
|
||||||
public void setColors(@ColorInt int color1, @ColorInt int color2,
|
public void setColors(@ColorInt int color1, @ColorInt int color2,
|
||||||
@ColorInt int color3, @ColorInt int color4) {
|
@ColorInt int color3, @ColorInt int color4) {
|
||||||
|
mUseNavBarColor = false;
|
||||||
|
attemptUnregisterNavBarListener();
|
||||||
mAssistInvocationLights.get(0).setColor(color1);
|
mAssistInvocationLights.get(0).setColor(color1);
|
||||||
mAssistInvocationLights.get(1).setColor(color2);
|
mAssistInvocationLights.get(1).setColor(color2);
|
||||||
mAssistInvocationLights.get(2).setColor(color3);
|
mAssistInvocationLights.get(2).setColor(color3);
|
||||||
mAssistInvocationLights.get(3).setColor(color4);
|
mAssistInvocationLights.get(3).setColor(color4);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reacts to changes in the navigation bar color
|
||||||
|
*
|
||||||
|
* @param darkIntensity 0 is the lightest color, 1 is the darkest.
|
||||||
|
*/
|
||||||
|
@Override // NavigationBarTransitions.DarkIntensityListener
|
||||||
|
public void onDarkIntensity(float darkIntensity) {
|
||||||
|
updateDarkness(darkIntensity);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onFinishInflate() {
|
protected void onFinishInflate() {
|
||||||
getLayoutParams().height = mViewHeight;
|
getLayoutParams().height = mViewHeight;
|
||||||
@@ -166,16 +219,20 @@ public class InvocationLightsView extends View {
|
|||||||
getLocationOnScreen(mScreenLocation);
|
getLocationOnScreen(mScreenLocation);
|
||||||
canvas.translate(-mScreenLocation[0], -mScreenLocation[1]);
|
canvas.translate(-mScreenLocation[0], -mScreenLocation[1]);
|
||||||
|
|
||||||
// if the lights are different colors, the inner ones need to be drawn last and with a
|
if (mUseNavBarColor) {
|
||||||
// square cap so that the join between lights is straight
|
for (EdgeLight light : mAssistInvocationLights) {
|
||||||
|
renderLight(light, canvas);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
mPaint.setStrokeCap(Paint.Cap.ROUND);
|
mPaint.setStrokeCap(Paint.Cap.ROUND);
|
||||||
renderLight(mAssistInvocationLights.get(0), canvas);
|
renderLight(mAssistInvocationLights.get(0), canvas);
|
||||||
renderLight(mAssistInvocationLights.get(3), canvas);
|
renderLight(mAssistInvocationLights.get(3), canvas);
|
||||||
|
|
||||||
mPaint.setStrokeCap(Paint.Cap.SQUARE);
|
mPaint.setStrokeCap(Paint.Cap.BUTT);
|
||||||
renderLight(mAssistInvocationLights.get(1), canvas);
|
renderLight(mAssistInvocationLights.get(1), canvas);
|
||||||
renderLight(mAssistInvocationLights.get(2), canvas);
|
renderLight(mAssistInvocationLights.get(2), canvas);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
protected void setLight(int index, float offset, float length) {
|
protected void setLight(int index, float offset, float length) {
|
||||||
if (index < 0 || index >= 4) {
|
if (index < 0 || index >= 4) {
|
||||||
@@ -185,10 +242,58 @@ public class InvocationLightsView extends View {
|
|||||||
mAssistInvocationLights.get(index).setLength(length);
|
mAssistInvocationLights.get(index).setLength(length);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Receives an intensity from 0 (lightest) to 1 (darkest) and sets the handle color
|
||||||
|
* appropriately. Intention is to match the home handle color.
|
||||||
|
*/
|
||||||
|
protected void updateDarkness(float darkIntensity) {
|
||||||
|
if (mUseNavBarColor) {
|
||||||
|
@ColorInt int invocationColor = (int) ArgbEvaluator.getInstance().evaluate(
|
||||||
|
darkIntensity, mLightColor, mDarkColor);
|
||||||
|
for (EdgeLight light : mAssistInvocationLights) {
|
||||||
|
light.setColor(invocationColor);
|
||||||
|
}
|
||||||
|
invalidate();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void renderLight(EdgeLight light, Canvas canvas) {
|
private void renderLight(EdgeLight light, Canvas canvas) {
|
||||||
mGuide.strokeSegment(mPath, light.getOffset(), light.getOffset() + light.getLength());
|
mGuide.strokeSegment(mPath, light.getOffset(), light.getOffset() + light.getLength());
|
||||||
mPaint.setColor(light.getColor());
|
mPaint.setColor(light.getColor());
|
||||||
canvas.drawPath(mPath, mPaint);
|
canvas.drawPath(mPath, mPaint);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void attemptRegisterNavBarListener() {
|
||||||
|
if (!mRegistered) {
|
||||||
|
NavigationBarController controller = Dependency.get(NavigationBarController.class);
|
||||||
|
if (controller == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
NavigationBarFragment navBar = controller.getDefaultNavigationBarFragment();
|
||||||
|
if (navBar == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
updateDarkness(navBar.getBarTransitions().addDarkIntensityListener(this));
|
||||||
|
mRegistered = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void attemptUnregisterNavBarListener() {
|
||||||
|
if (mRegistered) {
|
||||||
|
NavigationBarController controller = Dependency.get(NavigationBarController.class);
|
||||||
|
if (controller == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
NavigationBarFragment navBar = controller.getDefaultNavigationBarFragment();
|
||||||
|
if (navBar == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
navBar.getBarTransitions().removeDarkIntensityListener(this);
|
||||||
|
mRegistered = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -213,9 +213,12 @@ public final class NavigationBarTransitions extends BarTransitions implements
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Register {@code listener} to be notified when the color of nav bar elements changes.
|
* Register {@code listener} to be notified when the color of nav bar elements changes.
|
||||||
|
*
|
||||||
|
* Returns the current nav bar color.
|
||||||
*/
|
*/
|
||||||
public void addDarkIntensityListener(DarkIntensityListener listener) {
|
public float addDarkIntensityListener(DarkIntensityListener listener) {
|
||||||
mDarkIntensityListeners.add(listener);
|
mDarkIntensityListeners.add(listener);
|
||||||
|
return mLightTransitionsController.getCurrentDarkIntensity();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user