diff --git a/packages/SystemUI/res/drawable/brightness_progress_drawable_thick.xml b/packages/SystemUI/res/drawable/brightness_progress_drawable_thick.xml index 9edf84ef70d19..108591beb05a8 100644 --- a/packages/SystemUI/res/drawable/brightness_progress_drawable_thick.xml +++ b/packages/SystemUI/res/drawable/brightness_progress_drawable_thick.xml @@ -20,9 +20,9 @@ android:gravity="center_vertical|fill_horizontal"> - + android:alpha="?android:attr/disabledAlpha"> @@ -31,21 +31,9 @@ - - - - - - - + diff --git a/packages/SystemUI/res/drawable/brightness_progress_full_drawable.xml b/packages/SystemUI/res/drawable/brightness_progress_full_drawable.xml index 2c7ff350381c5..b5def5ebf5393 100644 --- a/packages/SystemUI/res/drawable/brightness_progress_full_drawable.xml +++ b/packages/SystemUI/res/drawable/brightness_progress_full_drawable.xml @@ -16,7 +16,7 @@ --> - + @@ -24,23 +24,12 @@ - - - - - - - + \ No newline at end of file diff --git a/packages/SystemUI/res/values/attrs.xml b/packages/SystemUI/res/values/attrs.xml index 78d92c4b47e23..897e3902b55c6 100644 --- a/packages/SystemUI/res/values/attrs.xml +++ b/packages/SystemUI/res/values/attrs.xml @@ -161,5 +161,11 @@ + + + + + + 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 61a6ada3fc103..53ff1dfd277b2 100644 --- a/packages/SystemUI/src/com/android/systemui/settings/brightness/BrightnessSlider.java +++ b/packages/SystemUI/src/com/android/systemui/settings/brightness/BrightnessSlider.java @@ -17,6 +17,9 @@ 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; import android.view.MotionEvent; import android.view.View; @@ -27,6 +30,7 @@ import android.widget.SeekBar; import androidx.annotation.Nullable; 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.ViewController; @@ -269,6 +273,10 @@ public class BrightnessSlider private BrightnessSlider fromTree(ViewGroup root, boolean useMirror) { BrightnessSliderView v = root.requireViewById(R.id.brightness_slider); + + // TODO(175026098) Workaround. Remove when b/175026098 is fixed + applyTheme(v); + return new BrightnessSlider(root, v, useMirror); } @@ -278,5 +286,32 @@ public class BrightnessSlider ? R.layout.quick_settings_brightness_dialog_thick : R.layout.quick_settings_brightness_dialog; } + + private LayerDrawable findProgressClippableDrawable(BrightnessSliderView v) { + SeekBar b = v.requireViewById(R.id.slider); + 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 (inner instanceof LayerDrawable) { + return (LayerDrawable) inner; + } + } + } + return null; + } + + private void applyTheme(BrightnessSliderView v) { + LayerDrawable layer = findProgressClippableDrawable(v); + if (layer != null) { + layer.findDrawableByLayerId(R.id.slider_foreground).setTintList( + Utils.getColorAttr(v.getContext(), + com.android.internal.R.attr.colorControlActivated)); + layer.findDrawableByLayerId(R.id.slider_icon).setTintList( + Utils.getColorAttr(v.getContext(), + com.android.internal.R.attr.colorBackground)); + } + } } } diff --git a/packages/SystemUI/src/com/android/systemui/util/AlphaTintDrawableWrapper.java b/packages/SystemUI/src/com/android/systemui/util/AlphaTintDrawableWrapper.java new file mode 100644 index 0000000000000..79a197d9d4097 --- /dev/null +++ b/packages/SystemUI/src/com/android/systemui/util/AlphaTintDrawableWrapper.java @@ -0,0 +1,112 @@ +/* + * Copyright (C) 2020 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.annotation.NonNull; +import android.annotation.Nullable; +import android.content.res.ColorStateList; +import android.content.res.Resources; +import android.content.res.Resources.Theme; +import android.content.res.TypedArray; +import android.graphics.drawable.DrawableWrapper; +import android.util.AttributeSet; + +import com.android.systemui.R; + +import org.xmlpull.v1.XmlPullParser; +import org.xmlpull.v1.XmlPullParserException; + +import java.io.IOException; + +/** + * An extension of {@link DrawableWrapper} that supports alpha and tint XML properties. + * + * {@link DrawableWrapper} supports setting these properties programmatically, but doesn't expose + * corresponding XML properties for some reason. This class allows to set these values in the XML, + * supporting theming. + * + * This class should only be used in XML. + * + * @attr ref android.R.styleable#DrawableWrapper_drawable + * @attr ref R.styleable#AlphaTintDrawableWrapper_tint + * @attr ref R.styleable#AlphaTintDrawableWrapper_alpha + */ +public class AlphaTintDrawableWrapper extends DrawableWrapper { + private ColorStateList mTint; + private int[] mThemeAttrs; + + /** No-arg constructor used by drawable inflation. */ + public AlphaTintDrawableWrapper() { + super(null); + } + + @Override + public void inflate(@NonNull Resources r, @NonNull XmlPullParser parser, + @NonNull AttributeSet attrs, @Nullable Theme theme) + throws XmlPullParserException, IOException { + final TypedArray a = obtainAttributes(r, theme, attrs, + R.styleable.AlphaTintDrawableWrapper); + + super.inflate(r, parser, attrs, theme); + + mThemeAttrs = a.extractThemeAttrs(); + updateStateFromTypedArray(a); + a.recycle(); + + applyTint(); + } + + @Override + public void applyTheme(Theme t) { + super.applyTheme(t); + + if (mThemeAttrs != null) { + final TypedArray a = t.resolveAttributes(mThemeAttrs, + R.styleable.AlphaTintDrawableWrapper); + updateStateFromTypedArray(a); + a.recycle(); + } + + // Ensure tint is reapplied after applying the theme to ensure this drawables' + // tint overrides the underlying drawables' tint. + applyTint(); + } + + @Override + public boolean canApplyTheme() { + return (mThemeAttrs != null && mThemeAttrs.length > 0) || super.canApplyTheme(); + } + + private void updateStateFromTypedArray(@NonNull TypedArray a) { + if (a.hasValue(R.styleable.AlphaTintDrawableWrapper_android_drawable)) { + setDrawable(a.getDrawable(R.styleable.AlphaTintDrawableWrapper_android_drawable)); + } + if (a.hasValue(R.styleable.AlphaTintDrawableWrapper_android_tint)) { + mTint = a.getColorStateList(R.styleable.AlphaTintDrawableWrapper_android_tint); + } + if (a.hasValue(R.styleable.AlphaTintDrawableWrapper_android_alpha)) { + float alpha = a.getFloat(R.styleable.AlphaTintDrawableWrapper_android_alpha, 1); + setAlpha(Math.round(alpha * 255)); + } + } + + private void applyTint() { + if (getDrawable() != null && mTint != null) { + getDrawable().mutate().setTintList(mTint); + } + } +}