Fix b/265364351: Light theme icons opacity is too light

https://screenshot.googleplex.com/Avqsw3gb2tjKqrK.png
https://screenshot.googleplex.com/46AZuJMjp2HMyqd.png
https://screenshot.googleplex.com/9mE3XutRUNaGckg.png
https://screenshot.googleplex.com/5rNUKMJjhNBNShZ.png

Bug: 265364351
Fix: 265364351
Test: manual
Change-Id: I7521030f1a5d84cd88027fb84a465623610707fb
This commit is contained in:
Zaiyue Xue
2023-02-21 14:39:17 +08:00
parent da1f2578a0
commit ea5b49f799
4 changed files with 42 additions and 17 deletions

View File

@@ -19,6 +19,8 @@ package com.android.settings.fuelgauge.batteryusage;
import android.content.Context;
import android.graphics.drawable.Drawable;
import android.util.AttributeSet;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import androidx.preference.PreferenceViewHolder;
@@ -37,6 +39,10 @@ import com.android.settingslib.widget.AppPreference;
public class PowerGaugePreference extends AppPreference {
private static final double PERCENTAGE_TO_SHOW_THRESHOLD = 1f;
// Please see go/battery-usage-app-list-alpha
private static final float SELECTABLE_ALPHA = 1f;
private static final float UNSELECTABLE_ALPHA_LIGHT_MODE = 0.65f;
private static final float UNSELECTABLE_ALPHA_DARK_MODE = 0.5f;
private BatteryEntry mInfo;
private BatteryDiffEntry mBatteryDiffEntry;
@@ -125,6 +131,11 @@ public class PowerGaugePreference extends AppPreference {
public void onBindViewHolder(PreferenceViewHolder view) {
super.onBindViewHolder(view);
final boolean isNightMode = Utils.isNightMode(getContext());
final float alpha = isSelectable() ? SELECTABLE_ALPHA
: (isNightMode ? UNSELECTABLE_ALPHA_DARK_MODE : UNSELECTABLE_ALPHA_LIGHT_MODE);
setViewAlpha(view.itemView, alpha);
final TextView subtitle = (TextView) view.findViewById(R.id.widget_summary);
subtitle.setText(mProgress);
if (mShowAnomalyIcon) {
@@ -138,4 +149,15 @@ public class PowerGaugePreference extends AppPreference {
titleView.setContentDescription(mContentDescription);
}
}
private static void setViewAlpha(View view, float alpha) {
if (view instanceof ViewGroup) {
final ViewGroup viewGroup = (ViewGroup) view;
for (int i = viewGroup.getChildCount() - 1; i >= 0; i--) {
setViewAlpha(viewGroup.getChildAt(i), alpha);
}
} else {
view.setAlpha(alpha);
}
}
}