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:
@@ -20,7 +20,6 @@ import android.animation.Animator;
|
||||
import android.animation.AnimatorListenerAdapter;
|
||||
import android.app.settings.SettingsEnums;
|
||||
import android.content.Context;
|
||||
import android.content.res.Configuration;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.os.Looper;
|
||||
@@ -68,8 +67,6 @@ public class BatteryChartPreferenceController extends AbstractPreferenceControll
|
||||
private static final String KEY_DAILY_CHART_INDEX = "daily_chart_index";
|
||||
private static final String KEY_HOURLY_CHART_INDEX = "hourly_chart_index";
|
||||
|
||||
private static int sUiMode = Configuration.UI_MODE_NIGHT_UNDEFINED;
|
||||
|
||||
/**
|
||||
* A callback listener for battery usage is updated.
|
||||
* This happens when battery usage data is ready or the selected index is changed.
|
||||
@@ -167,14 +164,6 @@ public class BatteryChartPreferenceController extends AbstractPreferenceControll
|
||||
|
||||
@Override
|
||||
public void onResume() {
|
||||
final int currentUiMode =
|
||||
mContext.getResources().getConfiguration().uiMode
|
||||
& Configuration.UI_MODE_NIGHT_MASK;
|
||||
if (sUiMode != currentUiMode) {
|
||||
sUiMode = currentUiMode;
|
||||
BatteryDiffEntry.clearCache();
|
||||
Log.d(TAG, "clear icon and label cache since uiMode is changed");
|
||||
}
|
||||
mIs24HourFormat = DateFormat.is24HourFormat(mContext);
|
||||
mMetricsFeatureProvider.action(mPrefContext, SettingsEnums.OPEN_BATTERY_USAGE);
|
||||
}
|
||||
|
@@ -18,6 +18,7 @@ package com.android.settings.fuelgauge.batteryusage;
|
||||
|
||||
import android.app.settings.SettingsEnums;
|
||||
import android.content.Context;
|
||||
import android.content.res.Configuration;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.os.Handler;
|
||||
import android.os.Looper;
|
||||
@@ -43,6 +44,7 @@ import com.android.settingslib.core.instrumentation.MetricsFeatureProvider;
|
||||
import com.android.settingslib.core.lifecycle.Lifecycle;
|
||||
import com.android.settingslib.core.lifecycle.LifecycleObserver;
|
||||
import com.android.settingslib.core.lifecycle.events.OnDestroy;
|
||||
import com.android.settingslib.core.lifecycle.events.OnResume;
|
||||
import com.android.settingslib.widget.FooterPreference;
|
||||
|
||||
import java.util.HashMap;
|
||||
@@ -51,15 +53,15 @@ import java.util.Map;
|
||||
|
||||
/** Controller for battery usage breakdown preference group. */
|
||||
public class BatteryUsageBreakdownController extends BasePreferenceController
|
||||
implements LifecycleObserver, OnDestroy {
|
||||
implements LifecycleObserver, OnResume, OnDestroy {
|
||||
private static final String TAG = "BatteryUsageBreakdownController";
|
||||
private static final String ROOT_PREFERENCE_KEY = "battery_usage_breakdown";
|
||||
private static final String FOOTER_PREFERENCE_KEY = "battery_usage_footer";
|
||||
private static final String SPINNER_PREFERENCE_KEY = "battery_usage_spinner";
|
||||
private static final String APP_LIST_PREFERENCE_KEY = "app_list";
|
||||
private static final String PACKAGE_NAME_NONE = "none";
|
||||
private static final int ENABLED_ICON_ALPHA = 255;
|
||||
private static final int DISABLED_ICON_ALPHA = 255 / 3;
|
||||
|
||||
private static int sUiMode = Configuration.UI_MODE_NIGHT_UNDEFINED;
|
||||
|
||||
private final SettingsActivity mActivity;
|
||||
private final InstrumentedPreferenceFragment mFragment;
|
||||
@@ -98,6 +100,19 @@ public class BatteryUsageBreakdownController extends BasePreferenceController
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResume() {
|
||||
final int currentUiMode =
|
||||
mContext.getResources().getConfiguration().uiMode
|
||||
& Configuration.UI_MODE_NIGHT_MASK;
|
||||
if (sUiMode != currentUiMode) {
|
||||
sUiMode = currentUiMode;
|
||||
BatteryDiffEntry.clearCache();
|
||||
mPreferenceCache.clear();
|
||||
Log.d(TAG, "clear icon and label cache since uiMode is changed");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroy() {
|
||||
mHandler.removeCallbacksAndMessages(/*token=*/ null);
|
||||
@@ -273,12 +288,11 @@ public class BatteryUsageBreakdownController extends BasePreferenceController
|
||||
pref.setSingleLineTitle(true);
|
||||
// Sets the BatteryDiffEntry to preference for launching detailed page.
|
||||
pref.setBatteryDiffEntry(entry);
|
||||
pref.setEnabled(entry.validForRestriction());
|
||||
pref.setSelectable(entry.validForRestriction());
|
||||
setPreferenceSummary(pref, entry);
|
||||
if (!isAdded) {
|
||||
mAppListPreferenceGroup.addPreference(pref);
|
||||
}
|
||||
appIcon.setAlpha(pref.isEnabled() ? ENABLED_ICON_ALPHA : DISABLED_ICON_ALPHA);
|
||||
prefIndex++;
|
||||
}
|
||||
Log.d(TAG, String.format("addAllPreferences() is finished in %d/ms",
|
||||
|
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -157,7 +157,7 @@ public final class BatteryUsageBreakdownControllerTest {
|
||||
assertThat(pref.getOrder()).isEqualTo(1);
|
||||
assertThat(pref.getBatteryDiffEntry()).isSameInstanceAs(mBatteryDiffEntry);
|
||||
assertThat(pref.isSingleLineTitle()).isTrue();
|
||||
assertThat(pref.isEnabled()).isFalse();
|
||||
assertThat(pref.isSelectable()).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
|
Reference in New Issue
Block a user