diff --git a/packages/SystemUI/res/drawable/brightness_progress_drawable_thick.xml b/packages/SystemUI/res/drawable/brightness_progress_drawable_thick.xml index 108591beb05a8..d097472471b0b 100644 --- a/packages/SystemUI/res/drawable/brightness_progress_drawable_thick.xml +++ b/packages/SystemUI/res/drawable/brightness_progress_drawable_thick.xml @@ -15,22 +15,24 @@ ~ limitations under the License. --> + android:paddingMode="stack" > - + - + - + + 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"> @@ -39,10 +41,8 @@ - + \ No newline at end of file diff --git a/packages/SystemUI/res/drawable/brightness_progress_full_drawable.xml b/packages/SystemUI/res/drawable/brightness_progress_full_drawable.xml index b5def5ebf5393..41140a7a8c853 100644 --- a/packages/SystemUI/res/drawable/brightness_progress_full_drawable.xml +++ b/packages/SystemUI/res/drawable/brightness_progress_full_drawable.xml @@ -15,18 +15,21 @@ ~ limitations under the License. --> - + - + - + + android:gravity="center_vertical|right" + android:height="@dimen/rounded_slider_icon_size" + android:width="@dimen/rounded_slider_icon_size" + android:right="@dimen/rounded_slider_icon_inset"> + + + + diff --git a/packages/SystemUI/res/values/dimens.xml b/packages/SystemUI/res/values/dimens.xml index 1fac96bb181dd..d92f4ea653904 100644 --- a/packages/SystemUI/res/values/dimens.xml +++ b/packages/SystemUI/res/values/dimens.xml @@ -1333,4 +1333,12 @@ 24dp 100dp 6dp + + 48dp + + 24dp + + 24dp + + 12dp diff --git a/packages/SystemUI/src/com/android/systemui/settings/brightness/BrightnessControllerSettings.java b/packages/SystemUI/src/com/android/systemui/settings/brightness/BrightnessControllerSettings.java index 8dcc8b46f0243..3c7d78c928fa2 100644 --- a/packages/SystemUI/src/com/android/systemui/settings/brightness/BrightnessControllerSettings.java +++ b/packages/SystemUI/src/com/android/systemui/settings/brightness/BrightnessControllerSettings.java @@ -18,7 +18,6 @@ package com.android.systemui.settings.brightness; import com.android.systemui.dagger.SysUISingleton; import com.android.systemui.statusbar.FeatureFlags; -import com.android.systemui.util.settings.SecureSettings; import javax.inject.Inject; @@ -30,25 +29,21 @@ public class BrightnessControllerSettings { private static final String THICK_BRIGHTNESS_SLIDER = "sysui_thick_brightness"; private final FeatureFlags mFeatureFlags; - private final boolean mUseThickSlider; - private final boolean mUseMirrorOnThickSlider; @Inject - public BrightnessControllerSettings(SecureSettings settings, FeatureFlags featureFlags) { + public BrightnessControllerSettings(FeatureFlags featureFlags) { mFeatureFlags = featureFlags; - mUseThickSlider = settings.getInt(THICK_BRIGHTNESS_SLIDER, 0) != 0; - mUseMirrorOnThickSlider = settings.getInt(THICK_BRIGHTNESS_SLIDER, 0) != 2; } // Changing this setting between zero and non-zero may crash systemui down the line. Better to // restart systemui after changing it. /** */ boolean useThickSlider() { - return mUseThickSlider && mFeatureFlags.useNewBrightnessSlider(); + return mFeatureFlags.useNewBrightnessSlider(); } /** */ boolean useMirrorOnThickSlider() { - return !useThickSlider() || (useThickSlider() && mUseMirrorOnThickSlider); + return !useThickSlider(); } } diff --git a/packages/SystemUI/src/com/android/systemui/settings/brightness/BrightnessSlider.java b/packages/SystemUI/src/com/android/systemui/settings/brightness/BrightnessSlider.java index 53ff1dfd277b2..a6aec3b7b1b73 100644 --- a/packages/SystemUI/src/com/android/systemui/settings/brightness/BrightnessSlider.java +++ b/packages/SystemUI/src/com/android/systemui/settings/brightness/BrightnessSlider.java @@ -17,7 +17,6 @@ package com.android.systemui.settings.brightness; import android.content.Context; -import android.graphics.drawable.ClipDrawable; import android.graphics.drawable.Drawable; import android.graphics.drawable.LayerDrawable; import android.view.LayoutInflater; @@ -33,6 +32,7 @@ import com.android.settingslib.RestrictedLockUtils; import com.android.settingslib.Utils; import com.android.systemui.R; import com.android.systemui.statusbar.policy.BrightnessMirrorController; +import com.android.systemui.util.RoundedCornerProgressDrawable; import com.android.systemui.util.ViewController; import javax.inject.Inject; @@ -292,8 +292,8 @@ public class BrightnessSlider if (b.getProgressDrawable() instanceof LayerDrawable) { Drawable progress = ((LayerDrawable) b.getProgressDrawable()) .findDrawableByLayerId(com.android.internal.R.id.progress); - if (progress instanceof ClipDrawable) { - Drawable inner = ((ClipDrawable) progress).getDrawable(); + if (progress instanceof RoundedCornerProgressDrawable) { + Drawable inner = ((RoundedCornerProgressDrawable) progress).getDrawable(); if (inner instanceof LayerDrawable) { return (LayerDrawable) inner; } diff --git a/packages/SystemUI/src/com/android/systemui/util/RoundedCornerProgressDrawable.kt b/packages/SystemUI/src/com/android/systemui/util/RoundedCornerProgressDrawable.kt new file mode 100644 index 0000000000000..1af2c9f463739 --- /dev/null +++ b/packages/SystemUI/src/com/android/systemui/util/RoundedCornerProgressDrawable.kt @@ -0,0 +1,118 @@ +/* + * Copyright (C) 2021 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.systemui.util + +import android.content.res.Resources +import android.content.res.TypedArray +import android.graphics.Canvas +import android.graphics.Path +import android.graphics.Rect +import android.graphics.drawable.Drawable +import android.graphics.drawable.DrawableWrapper +import android.util.AttributeSet +import com.android.systemui.R +import org.xmlpull.v1.XmlPullParser + +/** + * [DrawableWrapper] to use in the progress of a slider. + * + * This drawable is used to change the bounds of the enclosed drawable depending on the level to + * simulate a sliding progress, instead of using clipping or scaling. That way, the shape of the + * edges is maintained. + * + * 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. + */ +class RoundedCornerProgressDrawable(drawable: Drawable?) : DrawableWrapper(drawable) { + + constructor() : this(null) + + companion object { + private const val MAX_LEVEL = 10000 // Taken from Drawable + } + + private var clipPath: Path = Path() + + init { + setClipPath(Rect()) + } + + override fun inflate( + r: Resources, + parser: XmlPullParser, + attrs: AttributeSet, + theme: Resources.Theme? + ) { + val a = obtainAttributes(r, theme, attrs, R.styleable.RoundedCornerProgressDrawable) + + // Inflation will advance the XmlPullParser and AttributeSet. + super.inflate(r, parser, attrs, theme) + + updateStateFromTypedArray(a) + if (drawable == null) { + throw IllegalStateException("${this::class.java.simpleName} needs a drawable") + } + a.recycle() + } + + override fun onLayoutDirectionChanged(layoutDirection: Int): Boolean { + onLevelChange(level) + return super.onLayoutDirectionChanged(layoutDirection) + } + + private fun updateStateFromTypedArray(a: TypedArray) { + if (a.hasValue(R.styleable.RoundedCornerProgressDrawable_android_drawable)) { + setDrawable(a.getDrawable(R.styleable.RoundedCornerProgressDrawable_android_drawable)) + } + } + + 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) + return super.onLevelChange(level) + } + + override fun draw(canvas: Canvas) { + canvas.save() + canvas.clipPath(clipPath) + super.draw(canvas) + canvas.restore() + } +} \ No newline at end of file