Skip to content

Commit 7ccf350

Browse files
committed
Fix deprecated uses of getColor
1 parent ba354b6 commit 7ccf350

9 files changed

Lines changed: 49 additions & 31 deletions

File tree

app/src/main/java/org/gnucash/android/ui/account/AccountFormFragment.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
import android.support.design.widget.TextInputLayout;
3030
import android.support.v4.app.Fragment;
3131
import android.support.v4.app.FragmentManager;
32+
import android.support.v4.content.ContextCompat;
3233
import android.support.v4.widget.SimpleCursorAdapter;
3334
import android.support.v7.app.ActionBar;
3435
import android.support.v7.app.AppCompatActivity;
@@ -519,7 +520,8 @@ private int[] getAccountColorOptions(){
519520
TypedArray colorTypedArray = res.obtainTypedArray(R.array.account_colors);
520521
int[] colorOptions = new int[colorTypedArray.length()];
521522
for (int i = 0; i < colorTypedArray.length(); i++) {
522-
int color = colorTypedArray.getColor(i, getResources().getColor(R.color.title_green));
523+
int color = colorTypedArray.getColor(i, ContextCompat.getColor(getContext(),
524+
R.color.title_green));
523525
colorOptions[i] = color;
524526
}
525527
colorTypedArray.recycle();

app/src/main/java/org/gnucash/android/ui/export/ExportFormFragment.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import android.os.Bundle;
2424
import android.preference.PreferenceManager;
2525
import android.support.v4.app.Fragment;
26+
import android.support.v4.content.ContextCompat;
2627
import android.support.v7.app.ActionBar;
2728
import android.support.v7.app.AppCompatActivity;
2829
import android.support.v7.widget.SwitchCompat;
@@ -437,8 +438,8 @@ public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
437438
mExportStartDate.setEnabled(!isChecked);
438439
mExportStartTime.setEnabled(!isChecked);
439440
int color = isChecked ? android.R.color.darker_gray : android.R.color.black;
440-
mExportStartDate.setTextColor(getResources().getColor(color));
441-
mExportStartTime.setTextColor(getResources().getColor(color));
441+
mExportStartDate.setTextColor(ContextCompat.getColor(getContext(), color));
442+
mExportStartTime.setTextColor(ContextCompat.getColor(getContext(), color));
442443
}
443444
});
444445

app/src/main/java/org/gnucash/android/ui/homescreen/WidgetConfigurationActivity.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import android.database.Cursor;
2828
import android.database.sqlite.SQLiteDatabase;
2929
import android.os.Bundle;
30+
import android.support.v4.content.ContextCompat;
3031
import android.support.v4.widget.SimpleCursorAdapter;
3132
import android.support.v7.preference.PreferenceManager;
3233
import android.util.Log;
@@ -298,7 +299,7 @@ public static void updateWidget(final Context context, int appWidgetId) {
298299
views.setTextViewText(R.id.transactions_summary,
299300
accountBalance.formattedString(Locale.getDefault()));
300301
int color = accountBalance.isNegative() ? R.color.debit_red : R.color.credit_green;
301-
views.setTextColor(R.id.transactions_summary, context.getResources().getColor(color));
302+
views.setTextColor(R.id.transactions_summary, ContextCompat.getColor(context, color));
302303
}
303304

304305

app/src/main/java/org/gnucash/android/ui/report/ReportsActivity.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import android.support.v4.app.Fragment;
2727
import android.support.v4.app.FragmentManager;
2828
import android.support.v4.app.FragmentTransaction;
29+
import android.support.v4.content.ContextCompat;
2930
import android.support.v7.app.ActionBar;
3031
import android.view.KeyEvent;
3132
import android.view.Menu;
@@ -230,7 +231,7 @@ public void toggleToolbarTitleVisibility() {
230231
* Sets the color Action Bar and Status bar (where applicable)
231232
*/
232233
public void setAppBarColor(int color) {
233-
int resolvedColor = getResources().getColor(color);
234+
int resolvedColor = ContextCompat.getColor(this, color);
234235
if (getSupportActionBar() != null)
235236
getSupportActionBar().setBackgroundDrawable(new ColorDrawable(resolvedColor));
236237

app/src/main/java/org/gnucash/android/ui/report/ReportsOverviewFragment.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import android.os.Bundle;
2121
import android.support.annotation.Nullable;
2222
import android.support.v4.app.FragmentManager;
23+
import android.support.v4.content.ContextCompat;
2324
import android.support.v4.view.ViewCompat;
2425
import android.support.v7.widget.AppCompatButton;
2526
import android.view.Menu;
@@ -126,13 +127,13 @@ public void onActivityCreated(@Nullable Bundle savedInstanceState) {
126127
legend.setPosition(LegendPosition.RIGHT_OF_CHART_CENTER);
127128
legend.setTextSize(LEGEND_TEXT_SIZE);
128129

129-
ColorStateList csl = new ColorStateList(new int[][]{new int[0]}, new int[]{getResources().getColor(R.color.account_green)});
130+
ColorStateList csl = new ColorStateList(new int[][]{new int[0]}, new int[]{ContextCompat.getColor(getContext(), R.color.account_green)});
130131
setButtonTint(mPieChartButton, csl);
131-
csl = new ColorStateList(new int[][]{new int[0]}, new int[]{getResources().getColor(R.color.account_red)});
132+
csl = new ColorStateList(new int[][]{new int[0]}, new int[]{ContextCompat.getColor(getContext(), R.color.account_red)});
132133
setButtonTint(mBarChartButton, csl);
133-
csl = new ColorStateList(new int[][]{new int[0]}, new int[]{getResources().getColor(R.color.account_blue)});
134+
csl = new ColorStateList(new int[][]{new int[0]}, new int[]{ContextCompat.getColor(getContext(), R.color.account_blue)});
134135
setButtonTint(mLineChartButton, csl);
135-
csl = new ColorStateList(new int[][]{new int[0]}, new int[]{getResources().getColor(R.color.account_purple)});
136+
csl = new ColorStateList(new int[][]{new int[0]}, new int[]{ContextCompat.getColor(getContext(), R.color.account_purple)});
136137
setButtonTint(mBalanceSheetButton, csl);
137138
}
138139

@@ -261,7 +262,7 @@ public void setButtonTint(Button button, ColorStateList tint) {
261262
} else {
262263
ViewCompat.setBackgroundTintList(button, tint);
263264
}
264-
button.setTextColor(getResources().getColor(android.R.color.white));
265+
button.setTextColor(ContextCompat.getColor(getContext(), android.R.color.white));
265266
}
266267

267268
}

app/src/main/java/org/gnucash/android/ui/settings/BookManagerFragment.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,8 @@ private void setStatisticsText(View view, String bookUID) {
298298
statsText.setText(stats);
299299

300300
if (bookUID.equals(BooksDbAdapter.getInstance().getActiveBookUID())){
301-
((TextView)view.findViewById(R.id.primary_text)).setTextColor(getResources().getColor(R.color.theme_primary));
301+
((TextView)view.findViewById(R.id.primary_text))
302+
.setTextColor(ContextCompat.getColor(getContext(), R.color.theme_primary));
302303
}
303304
}
304305
}

app/src/main/java/org/gnucash/android/ui/transaction/ScheduledActionsListFragment.java

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import android.support.v4.app.Fragment;
2929
import android.support.v4.app.ListFragment;
3030
import android.support.v4.app.LoaderManager;
31+
import android.support.v4.content.ContextCompat;
3132
import android.support.v4.content.Loader;
3233
import android.support.v4.widget.SimpleCursorAdapter;
3334
import android.support.v7.app.ActionBar;
@@ -151,7 +152,8 @@ public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
151152

152153
private void setDefaultStatusBarColor() {
153154
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
154-
getActivity().getWindow().setStatusBarColor(getResources().getColor(R.color.theme_primary_dark));
155+
getActivity().getWindow().setStatusBarColor(
156+
ContextCompat.getColor(getContext(), R.color.theme_primary_dark));
155157
}
156158
}
157159

@@ -211,7 +213,8 @@ public void onActivityCreated(Bundle savedInstanceState) {
211213

212214
setHasOptionsMenu(true);
213215
getListView().setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);
214-
((TextView)getListView().getEmptyView()).setTextColor(getResources().getColor(R.color.theme_accent));
216+
((TextView)getListView().getEmptyView())
217+
.setTextColor(ContextCompat.getColor(getContext(), R.color.theme_accent));
215218
if (mActionType == ScheduledAction.ActionType.TRANSACTION){
216219
((TextView)getListView().getEmptyView()).setText(R.string.label_no_recurring_transactions);
217220
} else if (mActionType == ScheduledAction.ActionType.BACKUP){
@@ -363,7 +366,8 @@ private void startActionMode(){
363366
mActionMode = ((AppCompatActivity) getActivity())
364367
.startSupportActionMode(mActionModeCallbacks);
365368
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP){
366-
getActivity().getWindow().setStatusBarColor(getResources().getColor(android.R.color.darker_gray));
369+
getActivity().getWindow().setStatusBarColor(
370+
ContextCompat.getColor(getContext(), android.R.color.darker_gray));
367371
}
368372
}
369373

@@ -426,11 +430,12 @@ public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
426430

427431
ListView listView = (ListView) parent;
428432
if (mInEditMode && listView.isItemChecked(position)){
429-
view.setBackgroundColor(getResources().getColor(R.color.abs__holo_blue_light));
430-
secondaryText.setTextColor(getResources().getColor(android.R.color.white));
433+
view.setBackgroundColor(ContextCompat.getColor(getContext(), R.color.abs__holo_blue_light));
434+
secondaryText.setTextColor(ContextCompat.getColor(getContext(), android.R.color.white));
431435
} else {
432-
view.setBackgroundColor(getResources().getColor(android.R.color.transparent));
433-
secondaryText.setTextColor(getResources().getColor(android.R.color.secondary_text_light_nodisable));
436+
view.setBackgroundColor(ContextCompat.getColor(getContext(), android.R.color.transparent));
437+
secondaryText.setTextColor(ContextCompat.getColor(getContext(),
438+
android.R.color.secondary_text_light_nodisable));
434439
checkbox.setChecked(false);
435440
}
436441

@@ -477,7 +482,8 @@ public void bindView(View view, Context context, Cursor cursor) {
477482
ScheduledAction scheduledAction = scheduledActionDbAdapter.getRecord(scheduledActionUID);
478483
long endTime = scheduledAction.getEndTime();
479484
if (endTime > 0 && endTime < System.currentTimeMillis()){
480-
((TextView)view.findViewById(R.id.primary_text)).setTextColor(getResources().getColor(android.R.color.darker_gray));
485+
((TextView)view.findViewById(R.id.primary_text)).setTextColor(
486+
ContextCompat.getColor(getContext(), android.R.color.darker_gray));
481487
descriptionTextView.setText(getString(R.string.label_scheduled_action_ended,
482488
DateFormat.getInstance().format(new Date(scheduledAction.getLastRunTime()))));
483489
} else {
@@ -525,11 +531,12 @@ public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
525531

526532
ListView listView = (ListView) parent;
527533
if (mInEditMode && listView.isItemChecked(position)){
528-
view.setBackgroundColor(getResources().getColor(R.color.abs__holo_blue_light));
529-
secondaryText.setTextColor(getResources().getColor(android.R.color.white));
534+
view.setBackgroundColor(ContextCompat.getColor(getContext(), R.color.abs__holo_blue_light));
535+
secondaryText.setTextColor(ContextCompat.getColor(getContext(), android.R.color.white));
530536
} else {
531-
view.setBackgroundColor(getResources().getColor(android.R.color.transparent));
532-
secondaryText.setTextColor(getResources().getColor(android.R.color.secondary_text_light_nodisable));
537+
view.setBackgroundColor(ContextCompat.getColor(getContext(), android.R.color.transparent));
538+
secondaryText.setTextColor(
539+
ContextCompat.getColor(getContext(), android.R.color.secondary_text_light_nodisable));
533540
checkbox.setChecked(false);
534541
}
535542

@@ -576,7 +583,8 @@ public void bindView(View view, Context context, Cursor cursor) {
576583
descriptionTextView.setText(scheduledAction.getRepeatString());
577584
long endTime = scheduledAction.getEndTime();
578585
if (endTime > 0 && endTime < System.currentTimeMillis()){
579-
((TextView)view.findViewById(R.id.primary_text)).setTextColor(getResources().getColor(android.R.color.darker_gray));
586+
((TextView)view.findViewById(R.id.primary_text))
587+
.setTextColor(ContextCompat.getColor(getContext(), android.R.color.darker_gray));
580588
descriptionTextView.setText(getString(R.string.label_scheduled_action_ended,
581589
DateFormat.getInstance().format(new Date(scheduledAction.getLastRunTime()))));
582590
} else {

app/src/main/java/org/gnucash/android/ui/util/widget/TransactionTypeSwitch.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
package org.gnucash.android.ui.util.widget;
1818

1919
import android.content.Context;
20+
import android.support.v4.content.ContextCompat;
2021
import android.support.v7.widget.SwitchCompat;
2122
import android.util.AttributeSet;
2223
import android.widget.CompoundButton;
@@ -165,13 +166,13 @@ public OnTypeChangedListener(CalculatorEditText amountEditText, TextView currenc
165166
public void onCheckedChanged(CompoundButton compoundButton, boolean isChecked) {
166167
setText(isChecked ? getTextOn() : getTextOff());
167168
if (isChecked){
168-
int red = getResources().getColor(R.color.debit_red);
169+
int red = ContextCompat.getColor(getContext(), R.color.debit_red);
169170
TransactionTypeSwitch.this.setTextColor(red);
170171
mAmountEditText.setTextColor(red);
171172
mCurrencyTextView.setTextColor(red);
172173
}
173174
else {
174-
int green = getResources().getColor(R.color.credit_green);
175+
int green = ContextCompat.getColor(getContext(), R.color.credit_green);
175176
TransactionTypeSwitch.this.setTextColor(green);
176177
mAmountEditText.setTextColor(green);
177178
mCurrencyTextView.setTextColor(green);

app/src/main/java/org/gnucash/android/ui/wizard/FirstRunWizardActivity.java

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
import android.support.v4.app.Fragment;
3131
import android.support.v4.app.FragmentManager;
3232
import android.support.v4.app.FragmentStatePagerAdapter;
33+
import android.support.v4.content.ContextCompat;
3334
import android.support.v4.view.ViewPager;
3435
import android.support.v7.app.AppCompatActivity;
3536
import android.support.v7.widget.AppCompatButton;
@@ -245,14 +246,15 @@ private void updateBottomBar() {
245246
if (position == mCurrentPageSequence.size()) {
246247
mNextButton.setText(R.string.btn_wizard_finish);
247248

248-
mNextButton.setBackgroundDrawable(new ColorDrawable(res.getColor(R.color.theme_accent)));
249-
mNextButton.setTextColor(res.getColor(android.R.color.white));
249+
mNextButton.setBackgroundDrawable(
250+
new ColorDrawable(ContextCompat.getColor(this, R.color.theme_accent)));
251+
mNextButton.setTextColor(ContextCompat.getColor(this, android.R.color.white));
250252
} else {
251253
mNextButton.setText(mEditingAfterReview ? R.string.review
252254
: R.string.btn_wizard_next);
253-
mNextButton
254-
.setBackgroundDrawable(new ColorDrawable(res.getColor(android.R.color.transparent)));
255-
mNextButton.setTextColor(res.getColor(R.color.theme_accent));
255+
mNextButton.setBackgroundDrawable(
256+
new ColorDrawable(ContextCompat.getColor(this, android.R.color.transparent)));
257+
mNextButton.setTextColor(ContextCompat.getColor(this, R.color.theme_accent));
256258
mNextButton.setEnabled(position != mPagerAdapter.getCutOffPage());
257259
}
258260

0 commit comments

Comments
 (0)