Skip to content

Commit

Permalink
Replace usages of deprecated Resources.getColor() and getColorStateLi…
Browse files Browse the repository at this point in the history
…st()

Change-Id: I8f64fe6c4c44a92ff6d07250223ba590a1d691b0
  • Loading branch information
alanv committed Mar 19, 2015
1 parent f2560e6 commit 4a357cd
Show file tree
Hide file tree
Showing 52 changed files with 102 additions and 107 deletions.
10 changes: 5 additions & 5 deletions core/java/android/app/Notification.java
Original file line number Diff line number Diff line change
Expand Up @@ -2870,7 +2870,7 @@ private RemoteViews applyStandardTemplate(int resId, boolean hasProgress) {
contentView.setProgressBar(
R.id.progress, mProgressMax, mProgress, mProgressIndeterminate);
contentView.setProgressBackgroundTintList(
R.id.progress, ColorStateList.valueOf(mContext.getResources().getColor(
R.id.progress, ColorStateList.valueOf(mContext.getColor(
R.color.notification_progress_background_color)));
if (mColor != COLOR_DEFAULT) {
ColorStateList colorStateList = ColorStateList.valueOf(mColor);
Expand Down Expand Up @@ -3044,7 +3044,7 @@ private boolean isLegacy() {
private void processLegacyAction(Action action, RemoteViews button) {
if (!isLegacy() || mColorUtil.isGrayscaleIcon(mContext, action.icon)) {
button.setTextViewCompoundDrawablesRelativeColorFilter(R.id.action0, 0,
mContext.getResources().getColor(R.color.notification_action_color_filter),
mContext.getColor(R.color.notification_action_color_filter),
PorterDuff.Mode.MULTIPLY);
}
}
Expand Down Expand Up @@ -3142,7 +3142,7 @@ private int sanitizeColor() {

private int resolveColor() {
if (mColor == COLOR_DEFAULT) {
return mContext.getResources().getColor(R.color.notification_icon_bg_color);
return mContext.getColor(R.color.notification_icon_bg_color);
}
return mColor;
}
Expand Down Expand Up @@ -4321,9 +4321,9 @@ private void hideRightIcon(RemoteViews contentView) {
* Applies the special text colors for media notifications to all text views.
*/
private void styleText(RemoteViews contentView) {
int primaryColor = mBuilder.mContext.getResources().getColor(
int primaryColor = mBuilder.mContext.getColor(
R.color.notification_media_primary_color);
int secondaryColor = mBuilder.mContext.getResources().getColor(
int secondaryColor = mBuilder.mContext.getColor(
R.color.notification_media_secondary_color);
contentView.setTextColor(R.id.title, primaryColor);
if (mBuilder.showsTimeOrChronometer()) {
Expand Down
4 changes: 2 additions & 2 deletions core/java/android/content/res/Resources.java
Original file line number Diff line number Diff line change
Expand Up @@ -927,6 +927,7 @@ public Movie getMovie(@RawRes int id) throws NotFoundException {
* @deprecated Use {@link #getColor(int, Theme)} instead.
*/
@ColorInt
@Deprecated
public int getColor(@ColorRes int id) throws NotFoundException {
return getColor(id, null);
}
Expand Down Expand Up @@ -996,6 +997,7 @@ public int getColor(@ColorRes int id, @Nullable Theme theme) throws NotFoundExce
* @deprecated Use {@link #getColorStateList(int, Theme)} instead.
*/
@Nullable
@Deprecated
public ColorStateList getColorStateList(@ColorRes int id) throws NotFoundException {
final ColorStateList csl = getColorStateList(id, null);
if (csl != null && csl.canApplyTheme()) {
Expand Down Expand Up @@ -1049,8 +1051,6 @@ public ColorStateList getColorStateList(@ColorRes int id, @Nullable Theme theme)
return res;
}



/**
* Return a boolean associated with a particular resource ID. This can be
* used with any integral resource value, and will return true if it is
Expand Down
2 changes: 1 addition & 1 deletion core/java/android/content/res/StringBlock.java
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,7 @@ private static CharacterStyle getColor(String color, boolean foreground) {
String name = color.substring(1);
int colorRes = res.getIdentifier(name, "color", "android");
if (colorRes != 0) {
ColorStateList colors = res.getColorStateList(colorRes);
ColorStateList colors = res.getColorStateList(colorRes, null);
if (foreground) {
return new TextAppearanceSpan(null, 0, 0, colors, null);
} else {
Expand Down
2 changes: 1 addition & 1 deletion core/java/android/text/Html.java
Original file line number Diff line number Diff line change
Expand Up @@ -672,7 +672,7 @@ private static void endFont(SpannableStringBuilder text) {
String name = f.mColor.substring(1);
int colorRes = res.getIdentifier(name, "color", "android");
if (colorRes != 0) {
ColorStateList colors = res.getColorStateList(colorRes);
ColorStateList colors = res.getColorStateList(colorRes, null);
text.setSpan(new TextAppearanceSpan(null, 0, 0, colors, null),
where, len,
Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
Expand Down
8 changes: 4 additions & 4 deletions core/java/android/view/PhoneWindow.java
Original file line number Diff line number Diff line change
Expand Up @@ -2981,8 +2981,8 @@ private WindowInsets updateStatusGuard(WindowInsets insets) {

if (mStatusGuard == null) {
mStatusGuard = new View(mContext);
mStatusGuard.setBackgroundColor(mContext.getResources()
.getColor(R.color.input_method_navigation_guard));
mStatusGuard.setBackgroundColor(mContext.getColor(
R.color.input_method_navigation_guard));
addView(mStatusGuard, indexOfChild(mStatusColorViewState.view),
new LayoutParams(LayoutParams.MATCH_PARENT,
mlp.topMargin, Gravity.START | Gravity.TOP));
Expand Down Expand Up @@ -3041,8 +3041,8 @@ private void updateNavigationGuard(WindowInsets insets) {
// position the navigation guard view, creating it if necessary
if (mNavigationGuard == null) {
mNavigationGuard = new View(mContext);
mNavigationGuard.setBackgroundColor(mContext.getResources()
.getColor(R.color.input_method_navigation_guard));
mNavigationGuard.setBackgroundColor(mContext.getColor(
R.color.input_method_navigation_guard));
addView(mNavigationGuard, indexOfChild(mNavigationColorViewState.view),
new LayoutParams(LayoutParams.MATCH_PARENT,
insets.getSystemWindowInsetBottom(),
Expand Down
2 changes: 1 addition & 1 deletion core/java/android/widget/SuggestionsAdapter.java
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,7 @@ private CharSequence formatUrl(Context context, CharSequence url) {
// Lazily get the URL color from the current theme.
TypedValue colorValue = new TypedValue();
context.getTheme().resolveAttribute(R.attr.textColorSearchUrl, colorValue, true);
mUrlColor = context.getResources().getColorStateList(colorValue.resourceId);
mUrlColor = context.getColorStateList(colorValue.resourceId);
}

SpannableString text = new SpannableString(url);
Expand Down
4 changes: 2 additions & 2 deletions core/java/android/widget/TabHost.java
Original file line number Diff line number Diff line change
Expand Up @@ -603,7 +603,7 @@ public View createIndicatorView() {
if (context.getApplicationInfo().targetSdkVersion <= Build.VERSION_CODES.DONUT) {
// Donut apps get old color scheme
tabIndicator.setBackgroundResource(R.drawable.tab_indicator_v4);
tv.setTextColor(context.getResources().getColorStateList(R.color.tab_indicator_text_v4));
tv.setTextColor(context.getColorStateList(R.color.tab_indicator_text_v4));
}

return tabIndicator;
Expand Down Expand Up @@ -648,7 +648,7 @@ public View createIndicatorView() {
if (context.getApplicationInfo().targetSdkVersion <= Build.VERSION_CODES.DONUT) {
// Donut apps get old color scheme
tabIndicator.setBackgroundResource(R.drawable.tab_indicator_v4);
tv.setTextColor(context.getResources().getColorStateList(R.color.tab_indicator_text_v4));
tv.setTextColor(context.getColorStateList(R.color.tab_indicator_text_v4));
}

return tabIndicator;
Expand Down
4 changes: 2 additions & 2 deletions core/java/com/android/internal/util/UserIcons.java
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@ public static Drawable getDefaultUserIcon(int userId, boolean light) {
// Return colored icon instead
colorResId = USER_ICON_COLORS[userId % USER_ICON_COLORS.length];
}
Drawable icon = Resources.getSystem().getDrawable(R.drawable.ic_account_circle).mutate();
icon.setColorFilter(Resources.getSystem().getColor(colorResId), Mode.SRC_IN);
Drawable icon = Resources.getSystem().getDrawable(R.drawable.ic_account_circle, null).mutate();
icon.setColorFilter(Resources.getSystem().getColor(colorResId, null), Mode.SRC_IN);
icon.setBounds(0, 0, icon.getIntrinsicWidth(), icon.getIntrinsicHeight());
return icon;
}
Expand Down
6 changes: 3 additions & 3 deletions core/java/com/android/internal/widget/LockPatternView.java
Original file line number Diff line number Diff line change
Expand Up @@ -269,9 +269,9 @@ public LockPatternView(Context context, AttributeSet attrs) {
mPathPaint.setAntiAlias(true);
mPathPaint.setDither(true);

mRegularColor = getResources().getColor(R.color.lock_pattern_view_regular_color);
mErrorColor = getResources().getColor(R.color.lock_pattern_view_error_color);
mSuccessColor = getResources().getColor(R.color.lock_pattern_view_success_color);
mRegularColor = context.getColor(R.color.lock_pattern_view_regular_color);
mErrorColor = context.getColor(R.color.lock_pattern_view_error_color);
mSuccessColor = context.getColor(R.color.lock_pattern_view_success_color);
mRegularColor = a.getColor(R.styleable.LockPatternView_regularColor, mRegularColor);
mErrorColor = a.getColor(R.styleable.LockPatternView_errorColor, mErrorColor);
mSuccessColor = a.getColor(R.styleable.LockPatternView_successColor, mSuccessColor);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,7 @@ private synchronized void setNiNotification(GpsNiNotification notif) {
// if not to popup dialog immediately, pending intent will open the dialog
Intent intent = !mPopupImmediately ? getDlgIntent(notif) : new Intent();
PendingIntent pi = PendingIntent.getBroadcast(mContext, 0, intent, 0);
mNiNotification.color = mContext.getResources().getColor(
mNiNotification.color = mContext.getColor(
com.android.internal.R.color.system_notification_accent_color);
mNiNotification.setLatestEventInfo(mContext, title, message, pi);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ public static Drawable loadMimeIcon(Context context, String mimeType) {
public static Drawable applyTintColor(Context context, int drawableId, int tintColorId) {
final Drawable icon = context.getDrawable(drawableId);
icon.mutate();
icon.setTintList(context.getResources().getColorStateList(tintColorId));
icon.setTintList(context.getColorStateList(tintColorId));
return icon;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ private void createPrintingNotification(PrintJobInfo printJob) {
.setWhen(System.currentTimeMillis())
.setOngoing(true)
.setShowWhen(true)
.setColor(mContext.getResources().getColor(
.setColor(mContext.getColor(
com.android.internal.R.color.system_notification_accent_color));
mNotificationManager.notify(0, builder.build());
}
Expand All @@ -143,7 +143,7 @@ private void createFailedNotification(PrintJobInfo printJob) {
.setWhen(System.currentTimeMillis())
.setOngoing(true)
.setShowWhen(true)
.setColor(mContext.getResources().getColor(
.setColor(mContext.getColor(
com.android.internal.R.color.system_notification_accent_color));
mNotificationManager.notify(0, builder.build());
}
Expand All @@ -159,7 +159,7 @@ private void createBlockedNotification(PrintJobInfo printJob) {
.setWhen(System.currentTimeMillis())
.setOngoing(true)
.setShowWhen(true)
.setColor(mContext.getResources().getColor(
.setColor(mContext.getColor(
com.android.internal.R.color.system_notification_accent_color));
mNotificationManager.notify(0, builder.build());
}
Expand All @@ -173,7 +173,7 @@ private void createCancellingNotification(PrintJobInfo printJob) {
.setWhen(System.currentTimeMillis())
.setOngoing(true)
.setShowWhen(true)
.setColor(mContext.getResources().getColor(
.setColor(mContext.getColor(
com.android.internal.R.color.system_notification_accent_color));
mNotificationManager.notify(0, builder.build());
}
Expand Down Expand Up @@ -206,7 +206,7 @@ private void createStackedNotification(List<PrintJobInfo> printJobs) {

builder.setNumber(printJobCount);
builder.setStyle(inboxStyle);
builder.setColor(mContext.getResources().getColor(
builder.setColor(mContext.getColor(
com.android.internal.R.color.system_notification_accent_color));

mNotificationManager.notify(0, builder.build());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public PrintContentView(Context context, AttributeSet attrs) {
super(context, attrs);
mDragger = ViewDragHelper.create(this, new DragCallbacks());

mScrimColor = context.getResources().getColor(R.color.print_preview_scrim_color);
mScrimColor = context.getColor(R.color.print_preview_scrim_color);

// The options view is sliding under the static header but appears
// after it in the layout, so we will draw in opposite order.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ public void onReceive(Context context, Intent intent) {
context, 0, notifIntent, PendingIntent.FLAG_CANCEL_CURRENT))
.setAutoCancel(true)
.setLocalOnly(true)
.setColor(context.getResources().getColor(
.setColor(context.getColor(
com.android.internal.R.color.system_notification_accent_color));

NotificationManager.from(context).notify(TAG, 0, builder.build());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ public BatteryMeterView(Context context, AttributeSet attrs, int defStyle) {
TypedArray atts = context.obtainStyledAttributes(attrs, R.styleable.BatteryMeterView,
defStyle, 0);
final int frameColor = atts.getColor(R.styleable.BatteryMeterView_frameColor,
res.getColor(R.color.batterymeter_frame_color));
context.getColor(R.color.batterymeter_frame_color));
TypedArray levels = res.obtainTypedArray(R.array.batterymeter_color_levels);
TypedArray colors = res.obtainTypedArray(R.array.batterymeter_color_values);

Expand Down Expand Up @@ -240,10 +240,10 @@ public BatteryMeterView(Context context, AttributeSet attrs, int defStyle) {
mWarningTextPaint.setTypeface(font);
mWarningTextPaint.setTextAlign(Paint.Align.CENTER);

mChargeColor = getResources().getColor(R.color.batterymeter_charge_color);
mChargeColor = context.getColor(R.color.batterymeter_charge_color);

mBoltPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
mBoltPaint.setColor(res.getColor(R.color.batterymeter_bolt_color));
mBoltPaint.setColor(context.getColor(R.color.batterymeter_bolt_color));
mBoltPoints = loadBoltPoints(res);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,8 @@ public void getOutline(View view, Outline outline) {
mDisappearInterpolator = AnimationUtils.loadInterpolator(mContext,
android.R.interpolator.fast_out_linear_in);
mBackgroundPaint.setAntiAlias(true);
mBackgroundPaint.setColor(getResources().getColor(R.color.search_panel_circle_color));
mRipplePaint.setColor(getResources().getColor(R.color.search_panel_ripple_color));
mBackgroundPaint.setColor(context.getColor(R.color.search_panel_circle_color));
mRipplePaint.setColor(context.getColor(R.color.search_panel_ripple_color));
mRipplePaint.setAntiAlias(true);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ private void showInvalidChargerNotification() {
.setContentText(mContext.getString(R.string.invalid_charger_text))
.setPriority(Notification.PRIORITY_MAX)
.setVisibility(Notification.VISIBILITY_PUBLIC)
.setColor(mContext.getResources().getColor(
.setColor(mContext.getColor(
com.android.internal.R.color.system_notification_accent_color));
final Notification n = nb.build();
if (n.headsUpContentView != null) {
Expand All @@ -183,7 +183,7 @@ private void showWarningNotification() {
.setDeleteIntent(pendingBroadcast(ACTION_DISMISSED_WARNING))
.setPriority(Notification.PRIORITY_MAX)
.setVisibility(Notification.VISIBILITY_PUBLIC)
.setColor(mContext.getResources().getColor(
.setColor(mContext.getColor(
com.android.internal.R.color.battery_saver_mode_color));
if (hasBatterySettings()) {
nb.setContentIntent(pendingBroadcast(ACTION_SHOW_BATTERY_SETTINGS));
Expand Down Expand Up @@ -214,7 +214,7 @@ private void showSaverNotification() {
.setOngoing(true)
.setShowWhen(false)
.setVisibility(Notification.VISIBILITY_PUBLIC)
.setColor(mContext.getResources().getColor(
.setColor(mContext.getColor(
com.android.internal.R.color.battery_saver_mode_color));
addStopSaverAction(nb);
if (hasSaverSettings()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,10 @@ public class DataUsageGraph extends View {
public DataUsageGraph(Context context, AttributeSet attrs) {
super(context, attrs);
final Resources res = context.getResources();
mTrackColor = res.getColor(R.color.data_usage_graph_track);
mUsageColor = res.getColor(R.color.system_accent_color);
mOverlimitColor = res.getColor(R.color.system_warning_color);
mWarningColor = res.getColor(R.color.data_usage_graph_warning);
mTrackColor = context.getColor(R.color.data_usage_graph_track);
mUsageColor = context.getColor(R.color.system_accent_color);
mOverlimitColor = context.getColor(R.color.system_warning_color);
mWarningColor = context.getColor(R.color.data_usage_graph_warning);
mMarkerWidth = res.getDimensionPixelSize(R.dimen.data_usage_graph_marker_width);
}

Expand Down
8 changes: 4 additions & 4 deletions packages/SystemUI/src/com/android/systemui/qs/QSTileView.java
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ public QSTileView(Context context) {
addView(mIcon);

mDivider = new View(mContext);
mDivider.setBackgroundColor(res.getColor(R.color.qs_tile_divider));
mDivider.setBackgroundColor(context.getColor(R.color.qs_tile_divider));
final int dh = res.getDimensionPixelSize(R.dimen.qs_tile_divider_height);
mDivider.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, dh));
addView(mDivider);
Expand Down Expand Up @@ -138,8 +138,8 @@ private void recreateLabel() {
mDualLabel = new QSDualTileLabel(mContext);
mDualLabel.setId(android.R.id.title);
mDualLabel.setBackgroundResource(R.drawable.btn_borderless_rect);
mDualLabel.setFirstLineCaret(res.getDrawable(R.drawable.qs_dual_tile_caret));
mDualLabel.setTextColor(res.getColor(R.color.qs_tile_text));
mDualLabel.setFirstLineCaret(mContext.getDrawable(R.drawable.qs_dual_tile_caret));
mDualLabel.setTextColor(mContext.getColor(R.color.qs_tile_text));
mDualLabel.setPadding(0, mDualTileVerticalPaddingPx, 0, mDualTileVerticalPaddingPx);
mDualLabel.setTypeface(CONDENSED);
mDualLabel.setTextSize(TypedValue.COMPLEX_UNIT_PX,
Expand All @@ -157,7 +157,7 @@ private void recreateLabel() {
} else {
mLabel = new TextView(mContext);
mLabel.setId(android.R.id.title);
mLabel.setTextColor(res.getColor(R.color.qs_tile_text));
mLabel.setTextColor(mContext.getColor(R.color.qs_tile_text));
mLabel.setGravity(Gravity.CENTER_HORIZONTAL);
mLabel.setMinLines(2);
mLabel.setPadding(0, 0, 0, 0);
Expand Down
Loading

0 comments on commit 4a357cd

Please sign in to comment.