Merge "Create TintDrawable in Settings." into qt-dev

This commit is contained in:
TreeHugger Robot
2019-04-16 15:16:26 +00:00
committed by Android (Google) Code Review
10 changed files with 138 additions and 97 deletions

View File

@@ -13,17 +13,7 @@
See the License for the specific language governing permissions and
limitations under the License.
-->
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24.0"
android:viewportHeight="24.0"
android:tint="?android:attr/colorAccent">
<path
android:fillColor="#FF000000"
android:pathData="M16.67,4H14.5V2h-5v2H7.33C6.6,4 6,4.6 6,5.33V15v5.67C6,21.4 6.6,22 7.33,22h9.33C17.4,22 18,21.4 18,20.67V15V5.33C18,4.6 17.4,4 16.67,4zM16,15v5H8v-5V6h8V15z"/>
<path
android:fillColor="#FF000000"
android:pathData="M15,12l-2,0l0,-2l-2,0l0,2l-2,0l0,2l2,0l0,2l2,0l0,-2l2,0z"/>
</vector>
<com.android.settings.widget.TintDrawable
xmlns:android="http://schemas.android.com/apk/res/android"
android:drawable="@drawable/ic_battery_status_bad_24dp"
android:tint="?android:attr/colorAccent" />

View File

@@ -13,19 +13,7 @@
See the License for the specific language governing permissions and
limitations under the License.
-->
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24.0dp"
android:height="24.0dp"
android:viewportWidth="24.0"
android:viewportHeight="24.0"
android:tint="?android:attr/colorAccent">
<path
android:fillColor="#FF000000"
android:pathData="M15,4V3H9v1H4v2h1v13c0,1.1 0.9,2 2,2h10c1.1,0 2,-0.9 2,-2V6h1V4H15zM17,19H7V6h10V19z"/>
<path
android:fillColor="#FF000000"
android:pathData="M9,8h2v9h-2z"/>
<path
android:fillColor="#FF000000"
android:pathData="M13,8h2v9h-2z"/>
</vector>
<com.android.settings.widget.TintDrawable
xmlns:android="http://schemas.android.com/apk/res/android"
android:drawable="@drawable/ic_delete"
android:tint="?android:attr/colorAccent" />

View File

@@ -13,12 +13,7 @@
See the License for the specific language governing permissions and
limitations under the License.
-->
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24.0dp"
android:height="24.0dp"
android:viewportWidth="24.0"
android:viewportHeight="24.0">
<path
android:fillColor="#FFFFFFFF"
android:pathData="M1,9l2,2c4.97,-4.97 13.03,-4.97 18,0l2,-2C16.93,2.93 7.08,2.93 1,9zM9,17l3,3l3,-3C13.35,15.34 10.66,15.34 9,17zM5,13l2,2c2.76,-2.76 7.24,-2.76 10,0l2,-2C15.14,9.14 8.87,9.14 5,13z"/>
</vector>
<com.android.settings.widget.TintDrawable
xmlns:android="http://schemas.android.com/apk/res/android"
android:drawable="@drawable/ic_settings_wireless"
android:tint="@android:color/white" />

View File

@@ -14,13 +14,7 @@
See the License for the specific language governing permissions and
limitations under the License.
-->
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="26dp"
android:height="24dp"
android:viewportWidth="26"
android:viewportHeight="24">
<path
android:fillAlpha="0.3"
android:fillColor="?attr/wifi_signal_color"
android:pathData="M13.0,22.0L25.6,6.5C25.1,6.1 20.3,2.1 13.0,2.1S0.9,6.1 0.4,6.5L13.0,22.0L13.0,22.0L13.0,22.0L13.0,22.0L13.0,22.0z"/>
</vector>
<com.android.settings.widget.TintDrawable
xmlns:android="http://schemas.android.com/apk/res/android"
android:drawable="@*android:drawable/ic_wifi_signal_0"
android:tint="?attr/wifi_signal_color" />

View File

@@ -14,16 +14,7 @@
See the License for the specific language governing permissions and
limitations under the License.
-->
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="26dp"
android:height="24dp"
android:viewportWidth="26"
android:viewportHeight="24">
<path
android:fillAlpha="0.3"
android:fillColor="?attr/wifi_signal_color"
android:pathData="M13.1,22.0L25.6,6.5C25.1,6.1 20.3,2.1 13.0,2.1S0.9,6.1 0.5,6.5L13.1,22.0L13.1,22.0L13.1,22.0L13.1,22.0L13.1,22.0z"/>
<path
android:fillColor="?attr/wifi_signal_color"
android:pathData="M13.1,22.0l5.5,-6.8c-0.2,-0.2 -2.3,-1.9 -5.5,-1.9s-5.3,1.8 -5.5,1.9L13.1,22.0L13.1,22.0L13.1,22.0L13.1,22.0L13.1,22.0z"/>
</vector>
<com.android.settings.widget.TintDrawable
xmlns:android="http://schemas.android.com/apk/res/android"
android:drawable="@*android:drawable/ic_wifi_signal_1"
android:tint="?attr/wifi_signal_color" />

View File

@@ -14,16 +14,7 @@
See the License for the specific language governing permissions and
limitations under the License.
-->
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="26dp"
android:height="24dp"
android:viewportWidth="26"
android:viewportHeight="24">
<path
android:fillAlpha="0.3"
android:fillColor="?attr/wifi_signal_color"
android:pathData="M13.0,22.0L25.6,6.5C25.1,6.1 20.3,2.1 13.0,2.1S0.9,6.1 0.4,6.5L13.0,22.0L13.0,22.0L13.0,22.0L13.0,22.0L13.0,22.0z"/>
<path
android:fillColor="?attr/wifi_signal_color"
android:pathData="M13.0,22.0l7.6,-9.4C20.3,12.4 17.4,10.0 13.0,10.0s-7.3,2.4 -7.6,2.7L13.0,22.0L13.0,22.0L13.0,22.0L13.0,22.0L13.0,22.0z"/>
</vector>
<com.android.settings.widget.TintDrawable
xmlns:android="http://schemas.android.com/apk/res/android"
android:drawable="@*android:drawable/ic_wifi_signal_2"
android:tint="?attr/wifi_signal_color" />

View File

@@ -14,16 +14,7 @@
See the License for the specific language governing permissions and
limitations under the License.
-->
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="26dp"
android:height="24dp"
android:viewportWidth="26"
android:viewportHeight="24">
<path
android:fillAlpha="0.3"
android:fillColor="?attr/wifi_signal_color"
android:pathData="M13.0,22.0L25.6,6.5C25.1,6.1 20.3,2.1 13.0,2.1S0.9,6.1 0.4,6.5L13.0,22.0L13.0,22.0L13.0,22.0L13.0,22.0L13.0,22.0z"/>
<path
android:fillColor="?attr/wifi_signal_color"
android:pathData="M13.0,22.0l9.2,-11.4c-0.4,-0.3 -3.9,-3.2 -9.2,-3.2s-8.9,3.0 -9.2,3.2L13.0,22.0L13.0,22.0L13.0,22.0L13.0,22.0L13.0,22.0z"/>
</vector>
<com.android.settings.widget.TintDrawable
xmlns:android="http://schemas.android.com/apk/res/android"
android:drawable="@*android:drawable/ic_wifi_signal_3"
android:tint="?attr/wifi_signal_color" />

View File

@@ -14,12 +14,7 @@
See the License for the specific language governing permissions and
limitations under the License.
-->
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="26dp"
android:height="24dp"
android:viewportWidth="26"
android:viewportHeight="24">
<path
android:fillColor="?attr/wifi_signal_color"
android:pathData="M13.0,22.0L25.6,6.5C25.1,6.1 20.3,2.1 13.0,2.1S0.9,6.1 0.4,6.5L13.0,22.0L13.0,22.0L13.0,22.0L13.0,22.0L13.0,22.0z"/>
</vector>
<com.android.settings.widget.TintDrawable
xmlns:android="http://schemas.android.com/apk/res/android"
android:drawable="@*android:drawable/ic_wifi_signal_4"
android:tint="?attr/wifi_signal_color" />

View File

@@ -164,6 +164,11 @@
<attr name="textOff" format="reference" />
</declare-styleable>
<declare-styleable name="TintDrawable">
<attr name="android:tint" />
<attr name="android:drawable" />
</declare-styleable>
<attr name="twoStateButtonPreferenceStyle" format="reference" />
<attr name="fingerprint_layout_theme" format="reference" />

View File

@@ -0,0 +1,101 @@
/*
* Copyright (C) 2019 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.settings.widget;
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 android.util.Log;
import com.android.settings.R;
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
import java.io.IOException;
/**
* A Drawable that tints a contained Drawable, overriding the existing tint specified in the
* underlying drawable. This class should only be used in XML.
*
* @attr ref android.R.styleable#DrawableWrapper_drawable
* @attr ref R.styleable#TintDrawable_tint
*/
public class TintDrawable extends DrawableWrapper {
private ColorStateList mTint;
private int[] mThemeAttrs;
/** No-arg constructor used by drawable inflation. */
public TintDrawable() {
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.TintDrawable);
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.TintDrawable);
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.TintDrawable_android_drawable)) {
setDrawable(a.getDrawable(R.styleable.TintDrawable_android_drawable));
}
if (a.hasValue(R.styleable.TintDrawable_android_tint)) {
mTint = a.getColorStateList(R.styleable.TintDrawable_android_tint);
}
}
private void applyTint() {
if (getDrawable() != null && mTint != null) {
getDrawable().mutate().setTintList(mTint);
}
}
}