diff options
| author | 2022-08-18 17:35:48 +0000 | |
|---|---|---|
| committer | 2022-08-26 15:08:26 +0000 | |
| commit | bd45429b18389e4da4fb34233f740a5e1ee074fe (patch) | |
| tree | 35a20e3e9394b2ae1b430876344d78b8ae045a92 | |
| parent | 2cd24931e31b4051c30f0524522ea9ebdced4b23 (diff) | |
Fixed inaccurate brightness slider UI
The brightness slider's sun icon now corresponds directly with where the
user taps. The user can tap both edges of the slider to easily get the
maximum and minimum brightness levels.
Fixes: 205967506
Test: Manually tested, tapped both edges of the slider and was able to easily get the max and min widths
Change-Id: I7611946edd39adb75bfbc7b990c7d9dafa105e9f
| -rw-r--r-- | packages/SystemUI/src/com/android/systemui/util/RoundedCornerProgressDrawable.kt | 18 |
1 files changed, 15 insertions, 3 deletions
diff --git a/packages/SystemUI/src/com/android/systemui/util/RoundedCornerProgressDrawable.kt b/packages/SystemUI/src/com/android/systemui/util/RoundedCornerProgressDrawable.kt index 1059d6c61287..99eb03b44276 100644 --- a/packages/SystemUI/src/com/android/systemui/util/RoundedCornerProgressDrawable.kt +++ b/packages/SystemUI/src/com/android/systemui/util/RoundedCornerProgressDrawable.kt @@ -33,6 +33,11 @@ import android.graphics.drawable.InsetDrawable * Meant to be used with a rounded ends background, it will also prevent deformation when the slider * is meant to be smaller than the rounded corner. The background should have rounded corners that * are half of the height. + * + * This class also assumes that a "thumb" icon exists within the end's edge of the progress + * drawable, and the slider's width, when interacted on, if offset by half the size of the thumb + * icon which puts the icon directly underneath the user's finger. + * */ class RoundedCornerProgressDrawable @JvmOverloads constructor( drawable: Drawable? = null @@ -54,9 +59,16 @@ class RoundedCornerProgressDrawable @JvmOverloads constructor( override fun onLevelChange(level: Int): Boolean { val db = drawable?.bounds!! + + // The thumb offset shifts the sun icon directly under the user's thumb + val thumbOffset = bounds.height() / 2 + val width = bounds.width() * level / MAX_LEVEL + thumbOffset + // On 0, the width is bounds.height (a circle), and on MAX_LEVEL, the width is bounds.width - val width = bounds.height() + (bounds.width() - bounds.height()) * level / MAX_LEVEL - drawable?.setBounds(bounds.left, db.top, bounds.left + width, db.bottom) + drawable?.setBounds( + bounds.left, db.top, + width.coerceAtMost(bounds.width()).coerceAtLeast(bounds.height()), db.bottom + ) return super.onLevelChange(level) } @@ -91,4 +103,4 @@ class RoundedCornerProgressDrawable @JvmOverloads constructor( return true } } -}
\ No newline at end of file +} |