Merge "RESTRICT AUTOMERGE Implement latest design of brightness slider" into sc-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
cc2883bbad
@@ -18,33 +18,20 @@
|
||||
android:paddingMode="stack" >
|
||||
<item android:id="@android:id/background"
|
||||
android:gravity="center_vertical|fill_horizontal">
|
||||
<layer-list>
|
||||
<item>
|
||||
<shape
|
||||
android:tint="?android:attr/colorControlActivated"
|
||||
android:alpha="?android:attr/disabledAlpha">
|
||||
<size android:height="@dimen/rounded_slider_height" />
|
||||
<solid android:color="@color/white_disabled" />
|
||||
<corners android:radius="@dimen/rounded_slider_corner_radius" />
|
||||
</shape>
|
||||
</item>
|
||||
<item
|
||||
android:gravity="center_vertical|left"
|
||||
android:height="@dimen/rounded_slider_icon_size"
|
||||
android:width="@dimen/rounded_slider_icon_size"
|
||||
android:left="@dimen/rounded_slider_icon_inset">
|
||||
<com.android.systemui.util.AlphaTintDrawableWrapper
|
||||
android:drawable="@drawable/ic_brightness"
|
||||
android:tint="?android:attr/colorControlActivated" />
|
||||
</item>
|
||||
</layer-list>
|
||||
<inset
|
||||
android:insetLeft="@dimen/rounded_slider_track_inset"
|
||||
android:insetRight="@dimen/rounded_slider_track_inset" >
|
||||
<shape>
|
||||
<size android:height="@dimen/rounded_slider_track_width" />
|
||||
<corners android:radius="@dimen/rounded_slider_track_corner_radius" />
|
||||
<solid android:color="?android:attr/textColorPrimary" />
|
||||
</shape>
|
||||
</inset>
|
||||
</item>
|
||||
<item android:id="@android:id/progress"
|
||||
android:gravity="center_vertical|fill_horizontal">
|
||||
<clip
|
||||
<com.android.systemui.util.RoundedCornerProgressDrawable
|
||||
android:drawable="@drawable/brightness_progress_full_drawable"
|
||||
android:clipOrientation="horizontal"
|
||||
android:gravity="left"
|
||||
/>
|
||||
</item>
|
||||
</layer-list>
|
||||
@@ -26,10 +26,10 @@
|
||||
</item>
|
||||
<item
|
||||
android:id="@+id/slider_icon"
|
||||
android:gravity="center_vertical|left"
|
||||
android:gravity="center_vertical|right"
|
||||
android:height="@dimen/rounded_slider_icon_size"
|
||||
android:width="@dimen/rounded_slider_icon_size"
|
||||
android:left="@dimen/rounded_slider_icon_inset">
|
||||
android:right="@dimen/rounded_slider_icon_inset">
|
||||
<com.android.systemui.util.AlphaTintDrawableWrapper
|
||||
android:drawable="@drawable/ic_brightness"
|
||||
android:tint="?android:attr/colorBackground"
|
||||
|
||||
@@ -1356,11 +1356,15 @@
|
||||
<dimen name="people_space_image_radius">20dp</dimen>
|
||||
<dimen name="people_space_widget_background_padding">6dp</dimen>
|
||||
|
||||
<dimen name="rounded_slider_height">48dp</dimen>
|
||||
<dimen name="rounded_slider_height">44dp</dimen>
|
||||
<!-- rounded_slider_height / 2 -->
|
||||
<dimen name="rounded_slider_corner_radius">24dp</dimen>
|
||||
<!-- rounded_slider_height / 2 -->
|
||||
<dimen name="rounded_slider_icon_size">24dp</dimen>
|
||||
<!-- rounded_slider_icon_size / 2 -->
|
||||
<dimen name="rounded_slider_corner_radius">22dp</dimen>
|
||||
<dimen name="rounded_slider_icon_size">20dp</dimen>
|
||||
<!-- (rounded_slider_height - rounded_slider_icon_size) / 2 -->
|
||||
<dimen name="rounded_slider_icon_inset">12dp</dimen>
|
||||
<!-- rounded_slider_corner_radius - rounded_slider_track_corner_radius -->
|
||||
<dimen name="rounded_slider_track_inset">18dp</dimen>
|
||||
<dimen name="rounded_slider_track_width">8dp</dimen>
|
||||
<!-- rounded_slider_track_width / 2 -->
|
||||
<dimen name="rounded_slider_track_corner_radius">4dp</dimen>
|
||||
</resources>
|
||||
|
||||
@@ -17,8 +17,6 @@
|
||||
package com.android.systemui.util
|
||||
|
||||
import android.content.res.Resources
|
||||
import android.graphics.Canvas
|
||||
import android.graphics.Path
|
||||
import android.graphics.Rect
|
||||
import android.graphics.drawable.Drawable
|
||||
import android.graphics.drawable.DrawableWrapper
|
||||
@@ -43,53 +41,25 @@ class RoundedCornerProgressDrawable @JvmOverloads constructor(
|
||||
private const val MAX_LEVEL = 10000 // Taken from Drawable
|
||||
}
|
||||
|
||||
private var clipPath: Path = Path()
|
||||
|
||||
init {
|
||||
setClipPath(Rect())
|
||||
}
|
||||
|
||||
override fun onLayoutDirectionChanged(layoutDirection: Int): Boolean {
|
||||
onLevelChange(level)
|
||||
return super.onLayoutDirectionChanged(layoutDirection)
|
||||
}
|
||||
|
||||
override fun onBoundsChange(bounds: Rect) {
|
||||
setClipPath(bounds)
|
||||
super.onBoundsChange(bounds)
|
||||
onLevelChange(level)
|
||||
}
|
||||
|
||||
private fun setClipPath(bounds: Rect) {
|
||||
clipPath.reset()
|
||||
clipPath.addRoundRect(
|
||||
bounds.left.toFloat(),
|
||||
bounds.top.toFloat(),
|
||||
bounds.right.toFloat(),
|
||||
bounds.bottom.toFloat(),
|
||||
bounds.height().toFloat() / 2,
|
||||
bounds.height().toFloat() / 2,
|
||||
Path.Direction.CW
|
||||
)
|
||||
}
|
||||
|
||||
override fun onLevelChange(level: Int): Boolean {
|
||||
val db = drawable?.bounds!!
|
||||
val width = bounds.width() * level / MAX_LEVEL
|
||||
// Extra space on the left to keep the rounded shape on the right end
|
||||
val leftBound = bounds.left - bounds.height()
|
||||
drawable?.setBounds(leftBound, db.top, bounds.left + width, db.bottom)
|
||||
// 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)
|
||||
return super.onLevelChange(level)
|
||||
}
|
||||
|
||||
override fun draw(canvas: Canvas) {
|
||||
canvas.save()
|
||||
canvas.clipPath(clipPath)
|
||||
super.draw(canvas)
|
||||
canvas.restore()
|
||||
}
|
||||
|
||||
override fun getConstantState(): ConstantState? {
|
||||
override fun getConstantState(): ConstantState {
|
||||
// This should not be null as it was created with a state in the constructor.
|
||||
return RoundedCornerState(super.getConstantState()!!)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user