Apply bubble bar background alpha to stroke paint
Alpha was applied to fill paint only. Add it to stroke paint as well.
Introduce a new method in Utilities to map range of ints and not only
floats.
Bug: 345687278
Test: compare bubble bar shadow and stroke before and after change
Flag: com.android.wm.shell.enable_bubble_bar
Change-Id: I7c9e8d6337a857a661de0c945181cdd5ef2fd4ca
diff --git a/quickstep/src/com/android/launcher3/taskbar/bubbles/BubbleBarBackground.kt b/quickstep/src/com/android/launcher3/taskbar/bubbles/BubbleBarBackground.kt
index f08318e..249773d 100644
--- a/quickstep/src/com/android/launcher3/taskbar/bubbles/BubbleBarBackground.kt
+++ b/quickstep/src/com/android/launcher3/taskbar/bubbles/BubbleBarBackground.kt
@@ -43,9 +43,10 @@
private val arrowTipRadius: Float
private val arrowVisibleHeight: Float
- private val shadowAlpha: Float
- private var shadowBlur = 0f
- private var keyShadowDistance = 0f
+ private val strokeAlpha: Int
+ private val shadowAlpha: Int
+ private val shadowBlur: Float
+ private val keyShadowDistance: Float
private var arrowHeightFraction = 1f
var arrowPositionX: Float = 0f
@@ -105,13 +106,13 @@
strokePaint.strokeWidth = res.getDimension(R.dimen.transient_taskbar_stroke_width)
// apply theme alpha attributes
if (Utilities.isDarkTheme(context)) {
- strokePaint.alpha = DARK_THEME_STROKE_ALPHA
+ strokeAlpha = DARK_THEME_STROKE_ALPHA
shadowAlpha = DARK_THEME_SHADOW_ALPHA
} else {
- strokePaint.alpha = LIGHT_THEME_STROKE_ALPHA
+ strokeAlpha = LIGHT_THEME_STROKE_ALPHA
shadowAlpha = LIGHT_THEME_SHADOW_ALPHA
}
-
+ strokePaint.alpha = strokeAlpha
shadowBlur = res.getDimension(R.dimen.transient_taskbar_shadow_blur)
keyShadowDistance = res.getDimension(R.dimen.transient_taskbar_key_shadow_distance)
arrowWidth = res.getDimension(R.dimen.bubblebar_pointer_width)
@@ -132,15 +133,14 @@
override fun draw(canvas: Canvas) {
canvas.save()
- // TODO (b/277359345): Should animate the alpha similar to taskbar (see TaskbarDragLayer)
// Draw shadows.
val newShadowAlpha =
- mapToRange(fillPaint.alpha.toFloat(), 0f, 255f, 0f, shadowAlpha, Interpolators.LINEAR)
+ mapToRange(fillPaint.alpha, 0, 255, 0, shadowAlpha, Interpolators.LINEAR)
fillPaint.setShadowLayer(
shadowBlur,
0f,
keyShadowDistance,
- setColorAlphaBound(Color.BLACK, Math.round(newShadowAlpha))
+ setColorAlphaBound(Color.BLACK, newShadowAlpha),
)
// Create background path
val backgroundPath = Path()
@@ -172,7 +172,7 @@
arrowWidth,
scaledHeight,
arrowTipRadius,
- arrowPath
+ arrowPath,
)
// flip it horizontally
val pathTransform = Matrix()
@@ -196,6 +196,7 @@
override fun setAlpha(alpha: Int) {
fillPaint.alpha = alpha
+ strokePaint.alpha = mapToRange(alpha, 0, 255, 0, strokeAlpha, Interpolators.LINEAR)
invalidateSelf()
}
@@ -237,7 +238,7 @@
companion object {
private const val DARK_THEME_STROKE_ALPHA = 51
private const val LIGHT_THEME_STROKE_ALPHA = 41
- private const val DARK_THEME_SHADOW_ALPHA = 51f
- private const val LIGHT_THEME_SHADOW_ALPHA = 25f
+ private const val DARK_THEME_SHADOW_ALPHA = 51
+ private const val LIGHT_THEME_SHADOW_ALPHA = 25
}
}
diff --git a/src/com/android/launcher3/Utilities.java b/src/com/android/launcher3/Utilities.java
index f8ac48a..9698d20 100644
--- a/src/com/android/launcher3/Utilities.java
+++ b/src/com/android/launcher3/Utilities.java
@@ -420,6 +420,25 @@
return mapRange(interpolator.getInterpolation(progress), toMin, toMax);
}
+ /**
+ * Maps t from one range to another range.
+ * @param t The value to map.
+ * @param fromMin The lower bound of the range that t is being mapped from.
+ * @param fromMax The upper bound of the range that t is being mapped from.
+ * @param toMin The lower bound of the range that t is being mapped to.
+ * @param toMax The upper bound of the range that t is being mapped to.
+ * @return The mapped value of t.
+ */
+ public static int mapToRange(int t, int fromMin, int fromMax, int toMin, int toMax,
+ Interpolator interpolator) {
+ if (fromMin == fromMax || toMin == toMax) {
+ Log.e(TAG, "mapToRange: range has 0 length");
+ return toMin;
+ }
+ float progress = getProgress(t, fromMin, fromMax);
+ return (int) mapRange(interpolator.getInterpolation(progress), toMin, toMax);
+ }
+
/** Bounds t between a lower and upper bound and maps the result to a range. */
public static float mapBoundToRange(float t, float lowerBound, float upperBound,
float toMin, float toMax, Interpolator interpolator) {