[SettingsLib] Update Utils APIs usage

Update Utils.getColorAttr and similar methods in Utils to return a ColorStateList instead of a color

Bug: 74872054
Test: Force to display different color items then manually test
Change-Id: If002f9a578558e6254220c36ef556e8378d4522a
This commit is contained in:
Jason Chang
2018-04-10 21:09:39 +08:00
parent d1a6a71567
commit c44097d345
8 changed files with 17 additions and 14 deletions

View File

@@ -50,8 +50,8 @@ public class ChartDataUsagePreference extends Preference {
public ChartDataUsagePreference(Context context, AttributeSet attrs) { public ChartDataUsagePreference(Context context, AttributeSet attrs) {
super(context, attrs); super(context, attrs);
setSelectable(false); setSelectable(false);
mLimitColor = Utils.getColorAttr(context, android.R.attr.colorError); mLimitColor = Utils.getColorAttrDefaultColor(context, android.R.attr.colorError);
mWarningColor = Utils.getColorAttr(context, android.R.attr.textColorSecondary); mWarningColor = Utils.getColorAttrDefaultColor(context, android.R.attr.textColorSecondary);
setLayoutResource(R.layout.data_usage_graph); setLayoutResource(R.layout.data_usage_graph);
} }

View File

@@ -106,7 +106,7 @@ public class StorageVolumePreference extends Preference {
} }
if (freeBytes < mStorageManager.getStorageLowBytes(path)) { if (freeBytes < mStorageManager.getStorageLowBytes(path)) {
mColor = Utils.getColorAttr(context, android.R.attr.colorError); mColor = Utils.getColorAttrDefaultColor(context, android.R.attr.colorError);
icon = context.getDrawable(R.drawable.ic_warning_24dp); icon = context.getDrawable(R.drawable.ic_warning_24dp);
} }

View File

@@ -130,7 +130,7 @@ public class UserProfileController extends AbstractPreferenceController implemen
private static Drawable applyTint(Context context, Drawable icon) { private static Drawable applyTint(Context context, Drawable icon) {
icon = icon.mutate(); icon = icon.mutate();
icon.setTint(Utils.getColorAttr(context, android.R.attr.colorControlNormal)); icon.setTintList(Utils.getColorAttr(context, android.R.attr.colorControlNormal));
return icon; return icon;
} }

View File

@@ -51,7 +51,8 @@ public class BatteryMeterView extends ImageView {
final int frameColor = context.getColor(R.color.meter_background_color); final int frameColor = context.getColor(R.color.meter_background_color);
mAccentColorFilter = new PorterDuffColorFilter( mAccentColorFilter = new PorterDuffColorFilter(
Utils.getColorAttr(context, android.R.attr.colorAccent), PorterDuff.Mode.SRC_IN); Utils.getColorAttrDefaultColor(context, android.R.attr.colorAccent),
PorterDuff.Mode.SRC_IN);
mErrorColorFilter = new PorterDuffColorFilter( mErrorColorFilter = new PorterDuffColorFilter(
context.getColor(R.color.battery_icon_color_error), PorterDuff.Mode.SRC_IN); context.getColor(R.color.battery_icon_color_error), PorterDuff.Mode.SRC_IN);

View File

@@ -37,7 +37,7 @@ public class BatterySaverDrawable extends BatteryMeterDrawableBase {
setPowerSave(true); setPowerSave(true);
setCharging(false); setCharging(false);
setPowerSaveAsColorError(false); setPowerSaveAsColorError(false);
final int tintColor = Utils.getColorAttr(context, android.R.attr.colorAccent); final int tintColor = Utils.getColorAttrDefaultColor(context, android.R.attr.colorAccent);
setColorFilter(new PorterDuffColorFilter(tintColor, PorterDuff.Mode.SRC_IN)); setColorFilter(new PorterDuffColorFilter(tintColor, PorterDuff.Mode.SRC_IN));
} }
} }

View File

@@ -70,7 +70,8 @@ public class DonutView extends View {
public DonutView(Context context, AttributeSet attrs) { public DonutView(Context context, AttributeSet attrs) {
super(context, attrs); super(context, attrs);
mMeterBackgroundColor = context.getColor(R.color.meter_background_color); mMeterBackgroundColor = context.getColor(R.color.meter_background_color);
mMeterConsumedColor = Utils.getDefaultColor(mContext, R.color.meter_consumed_color); mMeterConsumedColor = Utils.getColorStateListDefaultColor(mContext,
R.color.meter_consumed_color);
boolean applyColorAccent = true; boolean applyColorAccent = true;
Resources resources = context.getResources(); Resources resources = context.getResources();
mStrokeWidth = resources.getDimension(R.dimen.storage_donut_thickness); mStrokeWidth = resources.getDimension(R.dimen.storage_donut_thickness);
@@ -107,7 +108,7 @@ public class DonutView extends View {
if (applyColorAccent) { if (applyColorAccent) {
final ColorFilter mAccentColorFilter = final ColorFilter mAccentColorFilter =
new PorterDuffColorFilter( new PorterDuffColorFilter(
Utils.getColorAttr(context, android.R.attr.colorAccent), Utils.getColorAttrDefaultColor(context, android.R.attr.colorAccent),
PorterDuff.Mode.SRC_IN); PorterDuff.Mode.SRC_IN);
mBackgroundCircle.setColorFilter(mAccentColorFilter); mBackgroundCircle.setColorFilter(mAccentColorFilter);
mFilledArc.setColorFilter(mAccentColorFilter); mFilledArc.setColorFilter(mAccentColorFilter);

View File

@@ -307,7 +307,8 @@ public class EntityHeaderController {
return this; return this;
} }
actionBar.setBackgroundDrawable( actionBar.setBackgroundDrawable(
new ColorDrawable(Utils.getColorAttr(activity, android.R.attr.colorPrimary))); new ColorDrawable(
Utils.getColorAttrDefaultColor(activity, android.R.attr.colorPrimary)));
actionBar.setElevation(0); actionBar.setElevation(0);
if (mRecyclerView != null && mLifecycle != null) { if (mRecyclerView != null && mLifecycle != null) {
ActionBarShadowController.attachToRecyclerView(mActivity, mLifecycle, mRecyclerView); ActionBarShadowController.attachToRecyclerView(mActivity, mLifecycle, mRecyclerView);

View File

@@ -225,7 +225,7 @@ public class DataUsageSummaryPreferenceTest {
bindViewHolder(); bindViewHolder();
assertThat(mCarrierInfo.getVisibility()).isEqualTo(View.VISIBLE); assertThat(mCarrierInfo.getVisibility()).isEqualTo(View.VISIBLE);
assertThat(mCarrierInfo.getCurrentTextColor()).isEqualTo( assertThat(mCarrierInfo.getCurrentTextColor()).isEqualTo(
Utils.getColorAttr(mContext, android.R.attr.textColorSecondary)); Utils.getColorAttrDefaultColor(mContext, android.R.attr.textColorSecondary));
assertThat(mCarrierInfo.getTypeface()).isEqualTo(Typeface.SANS_SERIF); assertThat(mCarrierInfo.getTypeface()).isEqualTo(Typeface.SANS_SERIF);
} }
@@ -238,7 +238,7 @@ public class DataUsageSummaryPreferenceTest {
bindViewHolder(); bindViewHolder();
assertThat(mCarrierInfo.getVisibility()).isEqualTo(View.VISIBLE); assertThat(mCarrierInfo.getVisibility()).isEqualTo(View.VISIBLE);
assertThat(mCarrierInfo.getCurrentTextColor()).isEqualTo( assertThat(mCarrierInfo.getCurrentTextColor()).isEqualTo(
Utils.getColorAttr(mContext, android.R.attr.colorError)); Utils.getColorAttrDefaultColor(mContext, android.R.attr.colorError));
assertThat(mCarrierInfo.getTypeface()).isEqualTo( assertThat(mCarrierInfo.getTypeface()).isEqualTo(
DataUsageSummaryPreference.SANS_SERIF_MEDIUM); DataUsageSummaryPreference.SANS_SERIF_MEDIUM);
} }
@@ -378,7 +378,7 @@ public class DataUsageSummaryPreferenceTest {
bindViewHolder(); bindViewHolder();
assertThat(mDataUsed.getText().toString()).isEqualTo("1.00 MB used"); assertThat(mDataUsed.getText().toString()).isEqualTo("1.00 MB used");
assertThat(mDataRemaining.getText().toString()).isEqualTo("9.00 MB left"); assertThat(mDataRemaining.getText().toString()).isEqualTo("9.00 MB left");
final int colorId = Utils.getColorAttr(mContext, android.R.attr.colorAccent); final int colorId = Utils.getColorAttrDefaultColor(mContext, android.R.attr.colorAccent);
assertThat(mDataRemaining.getCurrentTextColor()).isEqualTo(colorId); assertThat(mDataRemaining.getCurrentTextColor()).isEqualTo(colorId);
} }
@@ -391,7 +391,7 @@ public class DataUsageSummaryPreferenceTest {
bindViewHolder(); bindViewHolder();
assertThat(mDataUsed.getText().toString()).isEqualTo("11.00 MB used"); assertThat(mDataUsed.getText().toString()).isEqualTo("11.00 MB used");
assertThat(mDataRemaining.getText().toString()).isEqualTo("1.00 MB over"); assertThat(mDataRemaining.getText().toString()).isEqualTo("1.00 MB over");
final int colorId = Utils.getColorAttr(mContext, android.R.attr.colorError); final int colorId = Utils.getColorAttrDefaultColor(mContext, android.R.attr.colorError);
assertThat(mDataRemaining.getCurrentTextColor()).isEqualTo(colorId); assertThat(mDataRemaining.getCurrentTextColor()).isEqualTo(colorId);
} }