From af760cfc4038d3512deac2b8515f80ad30fa002d Mon Sep 17 00:00:00 2001 From: Winson Chung Date: Fri, 16 Apr 2021 16:55:38 -0700 Subject: [PATCH] Alternative workaround for using private attribute - SysUI studio has trouble referencing this private attribute directly, so move the resolving of the color to the code instead Bug: 152086714 Test: Studio builds, numpad colors still reflect the colorSurface color when changing dark/light & wallpapers Change-Id: I9a96c89010c41eaf6d14d5e1cfe86777cc30c8be --- .../SystemUI/res-keyguard/values/styles.xml | 6 ++++-- .../com/android/keyguard/NumPadAnimator.java | 4 +++- .../src/com/android/systemui/util/Utils.java | 21 +++++++++++++++++++ 3 files changed, 28 insertions(+), 3 deletions(-) diff --git a/packages/SystemUI/res-keyguard/values/styles.xml b/packages/SystemUI/res-keyguard/values/styles.xml index 0fef9f15c3738..72b027af1bf68 100644 --- a/packages/SystemUI/res-keyguard/values/styles.xml +++ b/packages/SystemUI/res-keyguard/values/styles.xml @@ -17,7 +17,7 @@ */ --> - + diff --git a/packages/SystemUI/src/com/android/keyguard/NumPadAnimator.java b/packages/SystemUI/src/com/android/keyguard/NumPadAnimator.java index 570854ecaa364..abdd770c37d4a 100644 --- a/packages/SystemUI/src/com/android/keyguard/NumPadAnimator.java +++ b/packages/SystemUI/src/com/android/keyguard/NumPadAnimator.java @@ -29,6 +29,7 @@ import androidx.annotation.StyleRes; import com.android.systemui.R; import com.android.systemui.animation.Interpolators; +import com.android.systemui.util.Utils; /** * Provides background color and radius animations for key pad buttons. @@ -100,7 +101,8 @@ class NumPadAnimator { ContextThemeWrapper ctw = new ContextThemeWrapper(context, mStyle); TypedArray a = ctw.obtainStyledAttributes(customAttrs); - mNormalColor = a.getColor(0, 0); + mNormalColor = Utils.getPrivateAttrColorIfUnset(ctw, a, 0, 0, + com.android.internal.R.attr.colorSurface); mHighlightColor = a.getColor(1, 0); a.recycle(); diff --git a/packages/SystemUI/src/com/android/systemui/util/Utils.java b/packages/SystemUI/src/com/android/systemui/util/Utils.java index fd3641cfdaa0b..f3a95f711b7c7 100644 --- a/packages/SystemUI/src/com/android/systemui/util/Utils.java +++ b/packages/SystemUI/src/com/android/systemui/util/Utils.java @@ -21,8 +21,10 @@ import android.content.Context; import android.content.Intent; import android.content.pm.PackageManager; import android.content.res.Resources; +import android.content.res.TypedArray; import android.provider.Settings; import android.text.TextUtils; +import android.view.ContextThemeWrapper; import android.view.View; import com.android.systemui.R; @@ -177,4 +179,23 @@ public class Utils { && resources.getBoolean(R.bool.config_use_split_notification_shade); } + /** + * Returns the color provided at the specified {@param attrIndex} in {@param a} if it exists, + * otherwise, returns the color from the private attribute {@param privAttrId}. + */ + public static int getPrivateAttrColorIfUnset(ContextThemeWrapper ctw, TypedArray a, + int attrIndex, int defColor, int privAttrId) { + // If the index is specified, use that value + if (a.hasValue(attrIndex)) { + return a.getColor(attrIndex, defColor); + } + + // Otherwise fallback to the value of the private attribute + int[] customAttrs = { privAttrId }; + a = ctw.obtainStyledAttributes(customAttrs); + int color = a.getColor(0, defColor); + a.recycle(); + return color; + } + }