From 431c14fa1828cbe410c74ee9548f2d7e90dedafd Mon Sep 17 00:00:00 2001 From: mxyyiyi Date: Tue, 21 May 2024 11:41:58 +0800 Subject: [PATCH] Update view alpha to improve text color constract in Battery usage - For light themes, first set the text color of title/summary/widget_summary to be consistent, then apply alpha = 0.65 [Before] https://screenshot.googleplex.com/4nVMMFBK7odhQju A11y Scanner result: https://screenshot.googleplex.com/4nVMMFBK7odhQju [After] https://screenshot.googleplex.com/B4r79v89HnWr4tw A11y Scanner result: https://screenshot.googleplex.com/3zQfRMe4HToc8Xm Dark mode: [before] https://screenshot.googleplex.com/BfLxR6tqQRgP4mQ [after] https://screenshot.googleplex.com/8KeG62i7R5hW8Ks Bug: 317139415 Bug: 265364351 Test: Accessibility Scanner Change-Id: I65a71525bbce41c37ee364f3f73c0d2d1d9ace38 --- .../fuelgauge/batteryusage/PowerGaugePreference.java | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/com/android/settings/fuelgauge/batteryusage/PowerGaugePreference.java b/src/com/android/settings/fuelgauge/batteryusage/PowerGaugePreference.java index ba2f89e3b48..1fc9abd4c5e 100644 --- a/src/com/android/settings/fuelgauge/batteryusage/PowerGaugePreference.java +++ b/src/com/android/settings/fuelgauge/batteryusage/PowerGaugePreference.java @@ -44,6 +44,8 @@ public class PowerGaugePreference extends AppPreference { private static final float UNSELECTABLE_ALPHA_LIGHT_MODE = 0.65f; private static final float UNSELECTABLE_ALPHA_DARK_MODE = 0.65f; + private final int mTitleColorNormal; + private BatteryEntry mInfo; private BatteryDiffEntry mBatteryDiffEntry; private CharSequence mContentDescription; @@ -78,6 +80,8 @@ public class PowerGaugePreference extends AppPreference { mInfo = info; mContentDescription = contentDescription; mShowAnomalyIcon = false; + mTitleColorNormal = + Utils.getColorAttrDefaultColor(context, android.R.attr.textColorPrimary); } /** Sets the content description. */ @@ -155,6 +159,13 @@ public class PowerGaugePreference extends AppPreference { final TextView titleView = (TextView) view.findViewById(android.R.id.title); titleView.setContentDescription(mContentDescription); } + + if (!isSelectable()) { + // Set colors consistently to meet contrast requirements for non-selectable items + ((TextView) view.findViewById(android.R.id.title)).setTextColor(mTitleColorNormal); + ((TextView) view.findViewById(android.R.id.summary)).setTextColor(mTitleColorNormal); + subtitle.setTextColor(mTitleColorNormal); + } } private static void setViewAlpha(View view, float alpha) {