Merge "Fix battery color tint issue." into qt-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
f1cea95f3e
@@ -16,14 +16,13 @@
|
||||
|
||||
package com.android.settings.fuelgauge.batterytip.tips;
|
||||
|
||||
import android.annotation.Nullable;
|
||||
import android.content.Context;
|
||||
import android.content.res.ColorStateList;
|
||||
import android.os.Parcel;
|
||||
import android.os.Parcelable;
|
||||
import android.util.SparseIntArray;
|
||||
import android.view.View;
|
||||
|
||||
import androidx.annotation.ColorInt;
|
||||
import androidx.annotation.IdRes;
|
||||
import androidx.annotation.IntDef;
|
||||
import androidx.annotation.VisibleForTesting;
|
||||
@@ -154,15 +153,15 @@ public abstract class BatteryTip implements Comparable<BatteryTip>, Parcelable {
|
||||
preference.setTitle(getTitle(context));
|
||||
preference.setSummary(getSummary(context));
|
||||
preference.setIcon(getIconId());
|
||||
ColorStateList tint = getIconTint();
|
||||
if (tint != null) {
|
||||
preference.getIcon().setTintList(tint);
|
||||
@IdRes int iconTintColorId = getIconTintColorId();
|
||||
if (iconTintColorId != View.NO_ID) {
|
||||
preference.getIcon().setTint(context.getColor(iconTintColorId));
|
||||
}
|
||||
}
|
||||
|
||||
/** Returns the {@link ColorStateList} for tinting {@link #getIconId()} or null if none. */
|
||||
protected @Nullable ColorStateList getIconTint() {
|
||||
return null;
|
||||
/** Returns the color resid for tinting {@link #getIconId()} or {@link View#NO_ID} if none. */
|
||||
protected @IdRes int getIconTintColorId() {
|
||||
return View.NO_ID;
|
||||
}
|
||||
|
||||
public boolean shouldShowDialog() {
|
||||
|
@@ -64,10 +64,10 @@ public class EarlyWarningTip extends BatteryTip {
|
||||
}
|
||||
|
||||
@Override
|
||||
public ColorStateList getIconTint() {
|
||||
return ColorStateList.valueOf(mState == StateType.HANDLED
|
||||
public int getIconTintColorId() {
|
||||
return mState == StateType.HANDLED
|
||||
? R.color.battery_maybe_color_light
|
||||
: R.color.battery_bad_color_light);
|
||||
: R.color.battery_bad_color_light;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@@ -60,8 +60,8 @@ public class SummaryTip extends BatteryTip {
|
||||
}
|
||||
|
||||
@Override
|
||||
public ColorStateList getIconTint() {
|
||||
return ColorStateList.valueOf(R.color.battery_good_color_light);
|
||||
public int getIconTintColorId() {
|
||||
return R.color.battery_good_color_light;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@@ -70,6 +70,7 @@ public class EarlyWarningTipTest {
|
||||
assertThat(tip.getTitle(mContext)).isEqualTo("Turn on Battery Saver");
|
||||
assertThat(tip.getSummary(mContext)).isEqualTo("Battery may run out earlier than usual");
|
||||
assertThat(tip.getIconId()).isEqualTo(R.drawable.ic_battery_status_bad_24dp);
|
||||
assertThat(tip.getIconTintColorId()).isEqualTo(R.color.battery_bad_color_light);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -80,6 +81,7 @@ public class EarlyWarningTipTest {
|
||||
assertThat(tip.getTitle(mContext)).isEqualTo("Battery Saver is on");
|
||||
assertThat(tip.getSummary(mContext)).isEqualTo("Some features may be limited");
|
||||
assertThat(tip.getIconId()).isEqualTo(R.drawable.ic_battery_status_maybe_24dp);
|
||||
assertThat(tip.getIconTintColorId()).isEqualTo(R.color.battery_maybe_color_light);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
Reference in New Issue
Block a user