Merge "Implementing new visd for backlight indicator" into udc-dev am: 8f288adce3
Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/22959901 Change-Id: I3bdc3effda5c169fd9995bb7d580a0e5aa1cd105 Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
@@ -1730,15 +1730,15 @@
|
|||||||
<!-- Keyboard backlight indicator-->
|
<!-- Keyboard backlight indicator-->
|
||||||
<dimen name="backlight_indicator_root_corner_radius">48dp</dimen>
|
<dimen name="backlight_indicator_root_corner_radius">48dp</dimen>
|
||||||
<dimen name="backlight_indicator_root_vertical_padding">8dp</dimen>
|
<dimen name="backlight_indicator_root_vertical_padding">8dp</dimen>
|
||||||
<dimen name="backlight_indicator_root_horizontal_padding">4dp</dimen>
|
<dimen name="backlight_indicator_root_horizontal_padding">6dp</dimen>
|
||||||
<dimen name="backlight_indicator_icon_width">22dp</dimen>
|
<dimen name="backlight_indicator_icon_width">22dp</dimen>
|
||||||
<dimen name="backlight_indicator_icon_height">11dp</dimen>
|
<dimen name="backlight_indicator_icon_height">11dp</dimen>
|
||||||
<dimen name="backlight_indicator_icon_left_margin">2dp</dimen>
|
<dimen name="backlight_indicator_icon_padding">10dp</dimen>
|
||||||
<dimen name="backlight_indicator_step_width">52dp</dimen>
|
<dimen name="backlight_indicator_step_width">52dp</dimen>
|
||||||
<dimen name="backlight_indicator_step_height">40dp</dimen>
|
<dimen name="backlight_indicator_step_height">40dp</dimen>
|
||||||
<dimen name="backlight_indicator_step_horizontal_margin">4dp</dimen>
|
<dimen name="backlight_indicator_step_horizontal_margin">2dp</dimen>
|
||||||
<dimen name="backlight_indicator_step_small_radius">4dp</dimen>
|
<dimen name="backlight_indicator_step_small_radius">4dp</dimen>
|
||||||
<dimen name="backlight_indicator_step_large_radius">48dp</dimen>
|
<dimen name="backlight_indicator_step_large_radius">28dp</dimen>
|
||||||
|
|
||||||
<!-- Broadcast dialog -->
|
<!-- Broadcast dialog -->
|
||||||
<dimen name="broadcast_dialog_title_img_margin_top">18dp</dimen>
|
<dimen name="broadcast_dialog_title_img_margin_top">18dp</dimen>
|
||||||
|
|||||||
@@ -203,5 +203,8 @@
|
|||||||
|
|
||||||
<item type="id" name="log_access_dialog_allow_button" />
|
<item type="id" name="log_access_dialog_allow_button" />
|
||||||
<item type="id" name="log_access_dialog_deny_button" />
|
<item type="id" name="log_access_dialog_deny_button" />
|
||||||
|
|
||||||
|
<!-- keyboard backlight indicator-->
|
||||||
|
<item type="id" name="backlight_icon" />
|
||||||
</resources>
|
</resources>
|
||||||
|
|
||||||
|
|||||||
@@ -22,9 +22,12 @@ import android.annotation.ColorInt
|
|||||||
import android.app.Dialog
|
import android.app.Dialog
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.graphics.drawable.ShapeDrawable
|
import android.graphics.drawable.ShapeDrawable
|
||||||
|
import android.graphics.drawable.shapes.OvalShape
|
||||||
import android.graphics.drawable.shapes.RoundRectShape
|
import android.graphics.drawable.shapes.RoundRectShape
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import android.view.Gravity
|
import android.view.Gravity
|
||||||
|
import android.view.View
|
||||||
|
import android.view.ViewGroup.MarginLayoutParams
|
||||||
import android.view.Window
|
import android.view.Window
|
||||||
import android.view.WindowManager
|
import android.view.WindowManager
|
||||||
import android.widget.FrameLayout
|
import android.widget.FrameLayout
|
||||||
@@ -32,9 +35,10 @@ import android.widget.ImageView
|
|||||||
import android.widget.LinearLayout
|
import android.widget.LinearLayout
|
||||||
import android.widget.LinearLayout.LayoutParams
|
import android.widget.LinearLayout.LayoutParams
|
||||||
import android.widget.LinearLayout.LayoutParams.WRAP_CONTENT
|
import android.widget.LinearLayout.LayoutParams.WRAP_CONTENT
|
||||||
|
import androidx.annotation.IdRes
|
||||||
|
import androidx.core.view.setPadding
|
||||||
import com.android.settingslib.Utils
|
import com.android.settingslib.Utils
|
||||||
import com.android.systemui.R
|
import com.android.systemui.R
|
||||||
import com.android.systemui.util.children
|
|
||||||
|
|
||||||
class KeyboardBacklightDialog(
|
class KeyboardBacklightDialog(
|
||||||
context: Context,
|
context: Context,
|
||||||
@@ -51,7 +55,7 @@ class KeyboardBacklightDialog(
|
|||||||
private data class BacklightIconProperties(
|
private data class BacklightIconProperties(
|
||||||
val width: Int,
|
val width: Int,
|
||||||
val height: Int,
|
val height: Int,
|
||||||
val leftMargin: Int,
|
val padding: Int,
|
||||||
)
|
)
|
||||||
|
|
||||||
private data class StepViewProperties(
|
private data class StepViewProperties(
|
||||||
@@ -71,6 +75,7 @@ class KeyboardBacklightDialog(
|
|||||||
private lateinit var rootProperties: RootProperties
|
private lateinit var rootProperties: RootProperties
|
||||||
private lateinit var iconProperties: BacklightIconProperties
|
private lateinit var iconProperties: BacklightIconProperties
|
||||||
private lateinit var stepProperties: StepViewProperties
|
private lateinit var stepProperties: StepViewProperties
|
||||||
|
|
||||||
@ColorInt
|
@ColorInt
|
||||||
var filledRectangleColor = getColorFromStyle(com.android.internal.R.attr.materialColorPrimary)
|
var filledRectangleColor = getColorFromStyle(com.android.internal.R.attr.materialColorPrimary)
|
||||||
@ColorInt
|
@ColorInt
|
||||||
@@ -78,7 +83,16 @@ class KeyboardBacklightDialog(
|
|||||||
getColorFromStyle(com.android.internal.R.attr.materialColorOutlineVariant)
|
getColorFromStyle(com.android.internal.R.attr.materialColorOutlineVariant)
|
||||||
@ColorInt
|
@ColorInt
|
||||||
var backgroundColor = getColorFromStyle(com.android.internal.R.attr.materialColorSurfaceBright)
|
var backgroundColor = getColorFromStyle(com.android.internal.R.attr.materialColorSurfaceBright)
|
||||||
@ColorInt var iconColor = getColorFromStyle(com.android.internal.R.attr.materialColorOnPrimary)
|
@ColorInt
|
||||||
|
var defaultIconColor = getColorFromStyle(com.android.internal.R.attr.materialColorOnPrimary)
|
||||||
|
@ColorInt
|
||||||
|
var defaultIconBackgroundColor =
|
||||||
|
getColorFromStyle(com.android.internal.R.attr.materialColorPrimary)
|
||||||
|
@ColorInt
|
||||||
|
var dimmedIconColor = getColorFromStyle(com.android.internal.R.attr.materialColorOnSurface)
|
||||||
|
@ColorInt
|
||||||
|
var dimmedIconBackgroundColor =
|
||||||
|
getColorFromStyle(com.android.internal.R.attr.materialColorSurfaceDim)
|
||||||
|
|
||||||
init {
|
init {
|
||||||
currentLevel = initialCurrentLevel
|
currentLevel = initialCurrentLevel
|
||||||
@@ -111,8 +125,7 @@ class KeyboardBacklightDialog(
|
|||||||
BacklightIconProperties(
|
BacklightIconProperties(
|
||||||
width = getDimensionPixelSize(R.dimen.backlight_indicator_icon_width),
|
width = getDimensionPixelSize(R.dimen.backlight_indicator_icon_width),
|
||||||
height = getDimensionPixelSize(R.dimen.backlight_indicator_icon_height),
|
height = getDimensionPixelSize(R.dimen.backlight_indicator_icon_height),
|
||||||
leftMargin =
|
padding = getDimensionPixelSize(R.dimen.backlight_indicator_icon_padding),
|
||||||
getDimensionPixelSize(R.dimen.backlight_indicator_icon_left_margin),
|
|
||||||
)
|
)
|
||||||
stepProperties =
|
stepProperties =
|
||||||
StepViewProperties(
|
StepViewProperties(
|
||||||
@@ -139,24 +152,35 @@ class KeyboardBacklightDialog(
|
|||||||
if (maxLevel != max || forceRefresh) {
|
if (maxLevel != max || forceRefresh) {
|
||||||
maxLevel = max
|
maxLevel = max
|
||||||
rootView.removeAllViews()
|
rootView.removeAllViews()
|
||||||
|
rootView.addView(buildIconTile())
|
||||||
buildStepViews().forEach { rootView.addView(it) }
|
buildStepViews().forEach { rootView.addView(it) }
|
||||||
}
|
}
|
||||||
currentLevel = current
|
currentLevel = current
|
||||||
updateLevel()
|
updateIconTile()
|
||||||
|
updateStepColors()
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun updateLevel() {
|
private fun updateIconTile() {
|
||||||
rootView.children.forEachIndexed(
|
val iconTile = rootView.findViewById(BACKLIGHT_ICON_ID) as ImageView
|
||||||
action = { index, v ->
|
val backgroundDrawable = iconTile.background as ShapeDrawable
|
||||||
val drawable = v.background as ShapeDrawable
|
if (currentLevel == 0) {
|
||||||
if (index <= currentLevel) {
|
iconTile.setColorFilter(dimmedIconColor)
|
||||||
updateColor(drawable, filledRectangleColor)
|
updateColor(backgroundDrawable, dimmedIconBackgroundColor)
|
||||||
} else {
|
} else {
|
||||||
updateColor(drawable, emptyRectangleColor)
|
iconTile.setColorFilter(defaultIconColor)
|
||||||
|
updateColor(backgroundDrawable, defaultIconBackgroundColor)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun updateStepColors() {
|
||||||
|
(1 until rootView.childCount).forEach { index ->
|
||||||
|
val drawable = rootView.getChildAt(index).background as ShapeDrawable
|
||||||
|
updateColor(
|
||||||
|
drawable,
|
||||||
|
if (index <= currentLevel) filledRectangleColor else emptyRectangleColor,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private fun updateColor(drawable: ShapeDrawable, @ColorInt color: Int) {
|
private fun updateColor(drawable: ShapeDrawable, @ColorInt color: Int) {
|
||||||
if (drawable.paint.color != color) {
|
if (drawable.paint.color != color) {
|
||||||
@@ -192,9 +216,33 @@ class KeyboardBacklightDialog(
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun buildStepViews(): List<FrameLayout> {
|
private fun buildStepViews(): List<FrameLayout> {
|
||||||
val stepViews = (0..maxLevel).map { i -> createStepViewAt(i) }
|
return (1..maxLevel).map { i -> createStepViewAt(i) }
|
||||||
stepViews[0].addView(createBacklightIconView())
|
}
|
||||||
return stepViews
|
|
||||||
|
private fun buildIconTile(): View {
|
||||||
|
val diameter = stepProperties.height
|
||||||
|
val circleDrawable =
|
||||||
|
ShapeDrawable(OvalShape()).apply {
|
||||||
|
intrinsicHeight = diameter
|
||||||
|
intrinsicWidth = diameter
|
||||||
|
}
|
||||||
|
|
||||||
|
return ImageView(context).apply {
|
||||||
|
setImageResource(R.drawable.ic_keyboard_backlight)
|
||||||
|
id = BACKLIGHT_ICON_ID
|
||||||
|
setColorFilter(defaultIconColor)
|
||||||
|
setPadding(iconProperties.padding)
|
||||||
|
layoutParams =
|
||||||
|
MarginLayoutParams(diameter, diameter).apply {
|
||||||
|
setMargins(
|
||||||
|
/* left= */ stepProperties.horizontalMargin,
|
||||||
|
/* top= */ 0,
|
||||||
|
/* right= */ stepProperties.horizontalMargin,
|
||||||
|
/* bottom= */ 0
|
||||||
|
)
|
||||||
|
}
|
||||||
|
background = circleDrawable
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun createStepViewAt(i: Int): FrameLayout {
|
private fun createStepViewAt(i: Int): FrameLayout {
|
||||||
@@ -221,18 +269,6 @@ class KeyboardBacklightDialog(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun createBacklightIconView(): ImageView {
|
|
||||||
return ImageView(context).apply {
|
|
||||||
setImageResource(R.drawable.ic_keyboard_backlight)
|
|
||||||
setColorFilter(iconColor)
|
|
||||||
layoutParams =
|
|
||||||
FrameLayout.LayoutParams(iconProperties.width, iconProperties.height).apply {
|
|
||||||
gravity = Gravity.CENTER
|
|
||||||
leftMargin = iconProperties.leftMargin
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun setWindowPosition() {
|
private fun setWindowPosition() {
|
||||||
window?.apply {
|
window?.apply {
|
||||||
setGravity(Gravity.BOTTOM or Gravity.CENTER_HORIZONTAL)
|
setGravity(Gravity.BOTTOM or Gravity.CENTER_HORIZONTAL)
|
||||||
@@ -262,30 +298,29 @@ class KeyboardBacklightDialog(
|
|||||||
private fun radiiForIndex(i: Int, last: Int): FloatArray {
|
private fun radiiForIndex(i: Int, last: Int): FloatArray {
|
||||||
val smallRadius = stepProperties.smallRadius
|
val smallRadius = stepProperties.smallRadius
|
||||||
val largeRadius = stepProperties.largeRadius
|
val largeRadius = stepProperties.largeRadius
|
||||||
return when (i) {
|
val radii = FloatArray(8) { smallRadius }
|
||||||
0 -> // left radii bigger
|
if (i == 1) {
|
||||||
floatArrayOf(
|
radii.setLeftCorners(largeRadius)
|
||||||
largeRadius,
|
}
|
||||||
largeRadius,
|
// note "first" and "last" might be the same tile
|
||||||
smallRadius,
|
if (i == last) {
|
||||||
smallRadius,
|
radii.setRightCorners(largeRadius)
|
||||||
smallRadius,
|
}
|
||||||
smallRadius,
|
return radii
|
||||||
largeRadius,
|
}
|
||||||
largeRadius
|
|
||||||
)
|
private fun FloatArray.setLeftCorners(radius: Float) {
|
||||||
last -> // right radii bigger
|
LEFT_CORNERS_INDICES.forEach { this[it] = radius }
|
||||||
floatArrayOf(
|
}
|
||||||
smallRadius,
|
private fun FloatArray.setRightCorners(radius: Float) {
|
||||||
smallRadius,
|
RIGHT_CORNERS_INDICES.forEach { this[it] = radius }
|
||||||
largeRadius,
|
}
|
||||||
largeRadius,
|
|
||||||
largeRadius,
|
private companion object {
|
||||||
largeRadius,
|
@IdRes val BACKLIGHT_ICON_ID = R.id.backlight_icon
|
||||||
smallRadius,
|
|
||||||
smallRadius
|
// indices used to define corners radii in ShapeDrawable
|
||||||
)
|
val LEFT_CORNERS_INDICES: IntArray = intArrayOf(0, 1, 6, 7)
|
||||||
else -> FloatArray(8) { smallRadius } // all radii equal
|
val RIGHT_CORNERS_INDICES: IntArray = intArrayOf(2, 3, 4, 5)
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user