Merge changes I73bb98a0,Ie545c3b6

* changes:
  Extend DrawableWrapper to set tint and alpha
  Fix colors of thick brightness slider
This commit is contained in:
Fabian Kozynski
2020-12-10 15:39:34 +00:00
committed by Android (Google) Code Review
6 changed files with 197 additions and 32 deletions

View File

@@ -16,6 +16,27 @@
-->
<layer-list xmlns:android="http://schemas.android.com/apk/res/android"
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="48dp" />
<solid android:color="@color/white_disabled" />
<corners android:radius="24dp" />
</shape>
</item>
<item
android:gravity="center_vertical|start"
android:start="32dp">
<com.android.systemui.util.AlphaTintDrawableWrapper
android:drawable="@drawable/ic_brightness"
android:tint="?android:attr/colorControlActivated" />
</item>
</layer-list>
</item>
<item android:id="@android:id/progress"
android:gravity="center_vertical|fill_horizontal">
<clip
@@ -24,13 +45,4 @@
android:gravity="left"
/>
</item>
<item android:id="@android:id/background"
android:gravity="center_vertical|fill_horizontal">
<shape android:shape="rectangle"
android:tint="?android:attr/colorControlNormal">
<size android:height="48dp" />
<solid android:color="@color/white_disabled" />
<corners android:radius="24dp" />
</shape>
</item>
</layer-list>

View File

@@ -15,10 +15,21 @@
~ limitations under the License.
-->
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle"
android:tint="?android:attr/colorControlActivated">
<size android:height="48dp" />
<solid android:color="@android:color/white" />
<corners android:radius="24dp"/>
</shape>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="@+id/slider_foreground">
<shape>
<size android:height="48dp" />
<solid android:color="?android:attr/colorControlActivated" />
<corners android:radius="24dp"/>
</shape>
</item>
<item
android:id="@+id/slider_icon"
android:gravity="center_vertical|start"
android:start="32dp">
<com.android.systemui.util.AlphaTintDrawableWrapper
android:drawable="@drawable/ic_brightness"
android:tint="?android:attr/colorBackground"
android:alpha="0.8"/>
</item>
</layer-list>

View File

@@ -14,10 +14,10 @@
limitations under the License.
-->
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:layout_gravity="center"
style="@style/BrightnessDialogContainer">
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:layout_gravity="center"
style="@style/BrightnessDialogContainer">
<com.android.systemui.settings.brightness.BrightnessSliderView
android:id="@+id/brightness_slider"
@@ -38,16 +38,5 @@
android:progressDrawable="@drawable/brightness_progress_drawable_thick"
android:splitTrack="false"
/>
<ImageView
android:id="@+id/image"
android:layout_width="24dp"
android:layout_height="24dp"
android:layout_marginLeft="48dp"
android:layout_gravity="center_vertical"
android:src="@drawable/ic_brightness"
android:tint="?android:attr/textColorTertiary"
android:visibility="visible"
/>
</com.android.systemui.settings.brightness.BrightnessSliderView>
</FrameLayout>

View File

@@ -161,5 +161,11 @@
<attr name="sensorPressureCoefficient" format="float"/>
<attr name="sensorTouchAreaCoefficient" format="float"/>
</declare-styleable>
<declare-styleable name="AlphaTintDrawableWrapper">
<attr name="android:tint" />
<attr name="android:drawable" />
<attr name="android:alpha" />
</declare-styleable>
</resources>

View File

@@ -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,14 +273,45 @@ 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);
}
/** Get the layout to inflate based on what slider to use */
public int getLayout() {
private int getLayout() {
return mSettings.useThickSlider()
? 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));
}
}
}
}

View File

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