Merge "Implement latest design on thick brightness slider" into sc-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
707e17ba50
@@ -15,22 +15,24 @@
|
||||
~ limitations under the License.
|
||||
-->
|
||||
<layer-list xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:paddingMode="stack">
|
||||
android:paddingMode="stack" >
|
||||
<item android:id="@android:id/background"
|
||||
android:gravity="center_vertical|fill_horizontal">
|
||||
<layer-list >
|
||||
<layer-list>
|
||||
<item>
|
||||
<shape
|
||||
android:tint="?android:attr/colorControlActivated"
|
||||
android:alpha="?android:attr/disabledAlpha">
|
||||
<size android:height="48dp" />
|
||||
<size android:height="@dimen/rounded_slider_height" />
|
||||
<solid android:color="@color/white_disabled" />
|
||||
<corners android:radius="24dp" />
|
||||
<corners android:radius="@dimen/rounded_slider_corner_radius" />
|
||||
</shape>
|
||||
</item>
|
||||
<item
|
||||
android:gravity="center_vertical|start"
|
||||
android:start="32dp">
|
||||
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" />
|
||||
@@ -39,10 +41,8 @@
|
||||
</item>
|
||||
<item android:id="@android:id/progress"
|
||||
android:gravity="center_vertical|fill_horizontal">
|
||||
<clip
|
||||
android:drawable="@drawable/brightness_progress_full_drawable"
|
||||
android:clipOrientation="horizontal"
|
||||
android:gravity="left"
|
||||
/>
|
||||
<com.android.systemui.util.RoundedCornerProgressDrawable
|
||||
android:drawable="@drawable/brightness_progress_full_drawable"
|
||||
/>
|
||||
</item>
|
||||
</layer-list>
|
||||
@@ -15,18 +15,21 @@
|
||||
~ limitations under the License.
|
||||
-->
|
||||
|
||||
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<layer-list xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:autoMirrored="true">
|
||||
<item android:id="@+id/slider_foreground">
|
||||
<shape>
|
||||
<size android:height="48dp" />
|
||||
<size android:height="@dimen/rounded_slider_height" />
|
||||
<solid android:color="?android:attr/colorControlActivated" />
|
||||
<corners android:radius="24dp"/>
|
||||
<corners android:radius="@dimen/rounded_slider_corner_radius"/>
|
||||
</shape>
|
||||
</item>
|
||||
<item
|
||||
android:id="@+id/slider_icon"
|
||||
android:gravity="center_vertical|start"
|
||||
android:start="32dp">
|
||||
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">
|
||||
<com.android.systemui.util.AlphaTintDrawableWrapper
|
||||
android:drawable="@drawable/ic_brightness"
|
||||
android:tint="?android:attr/colorBackground"
|
||||
|
||||
@@ -177,5 +177,9 @@
|
||||
<attr name="handleColor" format="color" />
|
||||
<attr name="scrimColor" format="color" />
|
||||
</declare-styleable>
|
||||
|
||||
<declare-styleable name="RoundedCornerProgressDrawable">
|
||||
<attr name="android:drawable" />
|
||||
</declare-styleable>
|
||||
</resources>
|
||||
|
||||
|
||||
@@ -1333,4 +1333,12 @@
|
||||
<dimen name="people_space_widget_radius">24dp</dimen>
|
||||
<dimen name="people_space_widget_round_radius">100dp</dimen>
|
||||
<dimen name="people_space_widget_background_padding">6dp</dimen>
|
||||
|
||||
<dimen name="rounded_slider_height">48dp</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_icon_inset">12dp</dimen>
|
||||
</resources>
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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()
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user