Merge "Fixed inaccurate brightness slider UI" into tm-qpr-dev am: 4f33cbd64f am: 7954582e7c

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/19669170

Change-Id: I9c39a763dc6294b0526c66aca81a328a87b4ad71
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
Rasheed Lewis
2022-08-26 16:52:15 +00:00
committed by Automerger Merge Worker

View File

@@ -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
}
}
}
}