Use ContextCompat getColor and getDrawable

pull/437/head
Alex Baker 8 years ago
parent 26275b8570
commit efe29333e5

@ -2,6 +2,7 @@ package org.tasks.locale.ui.activity;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.content.ContextCompat;
import android.support.v7.widget.Toolbar;
import android.view.MenuItem;
import android.widget.TextView;
@ -61,7 +62,7 @@ public final class TaskerSettingsActivity extends AbstractFragmentPluginAppCompa
}
updateView();
toolbar.setNavigationIcon(getResources().getDrawable(R.drawable.ic_close_24dp));
toolbar.setNavigationIcon(ContextCompat.getDrawable(this, R.drawable.ic_close_24dp));
toolbar.setOnMenuItemClickListener(this);
toolbar.setNavigationOnClickListener(view -> {
if (equalBundles(getResultBundle(), previousBundle)) {

@ -8,6 +8,7 @@ package com.todoroo.astrid.actfm;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.content.ContextCompat;
import android.support.v7.widget.Toolbar;
import android.view.MenuItem;
import android.view.inputmethod.InputMethodManager;
@ -55,7 +56,7 @@ public class FilterSettingsActivity extends ThemedInjectingAppCompatActivity imp
filter = getIntent().getParcelableExtra(TOKEN_FILTER);
final boolean backButtonSavesTask = preferences.backButtonSavesTask();
toolbar.setNavigationIcon(getResources().getDrawable(
toolbar.setNavigationIcon(ContextCompat.getDrawable(this,
backButtonSavesTask ? R.drawable.ic_close_24dp : R.drawable.ic_save_24dp));
toolbar.setTitle(filter.listingTitle);
toolbar.setNavigationOnClickListener(v -> {

@ -8,6 +8,7 @@ package com.todoroo.astrid.actfm;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.content.ContextCompat;
import android.support.v7.widget.Toolbar;
import android.view.MenuItem;
import android.view.View;
@ -97,7 +98,7 @@ public class TagSettingsActivity extends ThemedInjectingAppCompatActivity implem
final boolean backButtonSavesTask = preferences.backButtonSavesTask();
toolbar.setTitle(isNewTag ? getString(R.string.new_tag) : tagData.getName());
toolbar.setNavigationIcon(getResources().getDrawable(
toolbar.setNavigationIcon(ContextCompat.getDrawable(this,
backButtonSavesTask ? R.drawable.ic_close_24dp : R.drawable.ic_save_24dp));
toolbar.setNavigationOnClickListener(v -> {
if (backButtonSavesTask) {

@ -8,6 +8,7 @@ package com.todoroo.astrid.activity;
import android.content.Context;
import android.content.res.Resources;
import android.os.Bundle;
import android.support.v4.content.ContextCompat;
import android.support.v7.widget.Toolbar;
import android.view.MenuItem;
import android.view.View;
@ -57,7 +58,7 @@ public class BeastModePreferences extends ThemedInjectingAppCompatActivity imple
setContentView(R.layout.beast_mode_pref_activity);
ButterKnife.bind(this);
toolbar.setNavigationIcon(getResources().getDrawable(R.drawable.ic_arrow_back_24dp));
toolbar.setNavigationIcon(ContextCompat.getDrawable(this, R.drawable.ic_arrow_back_24dp));
toolbar.setNavigationOnClickListener(v -> finish());
toolbar.inflateMenu(R.menu.beast_mode);
toolbar.setOnMenuItemClickListener(this);

@ -10,6 +10,7 @@ import android.content.Context;
import android.os.Bundle;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.support.v4.content.ContextCompat;
import android.support.v7.widget.Toolbar;
import android.text.format.DateUtils;
import android.view.LayoutInflater;
@ -124,7 +125,7 @@ public final class TaskEditFragment extends InjectingFragment implements Toolbar
}
final boolean backButtonSavesTask = preferences.backButtonSavesTask();
toolbar.setNavigationIcon(getResources().getDrawable(
toolbar.setNavigationIcon(ContextCompat.getDrawable(context,
backButtonSavesTask ? R.drawable.ic_close_24dp : R.drawable.ic_save_24dp));
toolbar.setNavigationOnClickListener(v -> {
if (backButtonSavesTask) {

@ -88,6 +88,7 @@ import butterknife.ButterKnife;
import butterknife.OnClick;
import timber.log.Timber;
import static android.support.v4.content.ContextCompat.getColor;
import static com.todoroo.astrid.voice.VoiceInputAssistant.voiceInputAvailable;
/**
@ -458,8 +459,8 @@ public class TaskListFragment extends InjectingListFragment implements
public Snackbar makeSnackbar(String text) {
Snackbar snackbar = Snackbar.make(coordinatorLayout, text, 8000)
.setActionTextColor(getResources().getColor(R.color.snackbar_text_color));
snackbar.getView().setBackgroundColor(getResources().getColor(R.color.snackbar_background));
.setActionTextColor(getColor(context, R.color.snackbar_text_color));
snackbar.getView().setBackgroundColor(getColor(context, R.color.snackbar_background));
return snackbar;
}

@ -40,6 +40,8 @@ import org.tasks.ui.NavigationDrawerFragment;
import java.util.List;
import static android.support.v4.content.ContextCompat.getColor;
public class FilterAdapter extends ArrayAdapter<FilterListItem> {
private static final int VIEW_TYPE_COUNT = FilterListItem.Type.values().length;
@ -148,7 +150,7 @@ public class FilterAdapter extends ArrayAdapter<FilterListItem> {
Filter selected = ((TaskListActivity) activity).getCurrentFilter();
if (selected != null && selected.equals(viewHolder.item)) {
convertView.setBackgroundColor(activity.getResources().getColor(R.color.drawer_color_selected));
convertView.setBackgroundColor(getColor(activity, R.color.drawer_color_selected));
}
}
break;
@ -287,7 +289,7 @@ public class FilterAdapter extends ArrayAdapter<FilterListItem> {
viewHolder.icon.setImageResource(filter.icon);
viewHolder.icon.setColorFilter(filter.tint >= 0
? themeCache.getThemeColor(filter.tint).getPrimaryColor()
: getContext().getResources().getColor(R.color.text_primary));
: getColor(activity, R.color.text_primary));
String title = filter.listingTitle;
if(!title.equals(viewHolder.name.getText())) {
@ -302,7 +304,7 @@ public class FilterAdapter extends ArrayAdapter<FilterListItem> {
viewHolder.size.setVisibility(countInt > 0 ? View.VISIBLE : View.INVISIBLE);
if (selection == viewHolder.item) {
viewHolder.view.setBackgroundColor(activity.getResources().getColor(R.color.drawer_color_selected));
viewHolder.view.setBackgroundColor(getColor(activity, R.color.drawer_color_selected));
}
}

@ -67,6 +67,7 @@ import java.util.concurrent.atomic.AtomicReference;
import timber.log.Timber;
import static android.support.v4.content.ContextCompat.getColor;
import static com.google.common.collect.Iterables.filter;
import static com.google.common.collect.Lists.newArrayList;
import static com.google.common.collect.Lists.transform;
@ -172,7 +173,7 @@ public class TaskAdapter extends CursorAdapter implements Filterable {
textColorSecondary = getData(context, android.R.attr.textColorSecondary);
textColorHint = getData(context, android.R.attr.textColorTertiary);
textColorOverdue = resources.getColor(R.color.overdue);
textColorOverdue = getColor(context, R.color.overdue);
updateTagMap();
this.minRowHeight = computeMinRowHeight();

@ -10,6 +10,7 @@ import android.content.Context;
import android.content.Intent;
import android.database.Cursor;
import android.os.Bundle;
import android.support.v4.content.ContextCompat;
import android.support.v7.widget.Toolbar;
import android.view.ContextMenu;
import android.view.ContextMenu.ContextMenuInfo;
@ -147,7 +148,7 @@ public class CustomFilterActivity extends ThemedInjectingAppCompatActivity imple
setContentView(R.layout.custom_filter_activity);
ButterKnife.bind(this);
toolbar.setNavigationIcon(getResources().getDrawable(R.drawable.ic_close_24dp));
toolbar.setNavigationIcon(ContextCompat.getDrawable(this, R.drawable.ic_close_24dp));
toolbar.setTitle(R.string.FLA_new_filter);
toolbar.inflateMenu(R.menu.menu_custom_filter_activity);
toolbar.setOnMenuItemClickListener(this);

@ -14,6 +14,7 @@ import android.content.res.Resources;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.net.Uri;
import android.support.v4.content.ContextCompat;
import android.text.Spannable;
import android.text.style.URLSpan;
import android.text.util.Linkify;
@ -65,12 +66,12 @@ public class LinkActionExposer {
Resources r = context.getResources();
if (hasAttachments) {
BitmapDrawable icon = getBitmapDrawable(R.drawable.action_attachments, r);
BitmapDrawable icon = getBitmapDrawable(context, R.drawable.action_attachments, r);
return new FilesAction(icon);
}
if (hasNotes) {
BitmapDrawable icon = getBitmapDrawable(R.drawable.action_notes, r);
BitmapDrawable icon = getBitmapDrawable(context, R.drawable.action_notes, r);
return new NotesAction(icon);
}
@ -102,11 +103,11 @@ public class LinkActionExposer {
Resources r = context.getResources();
Drawable icon;
if (url.startsWith("mailto")) {
icon = getBitmapDrawable(R.drawable.action_mail, r);
icon = getBitmapDrawable(context, R.drawable.action_mail, r);
} else if (url.startsWith("tel")) {
icon = getBitmapDrawable(R.drawable.action_tel, r);
icon = getBitmapDrawable(context, R.drawable.action_tel, r);
} else {
icon = getBitmapDrawable(R.drawable.action_web, r);
icon = getBitmapDrawable(context, R.drawable.action_web, r);
}
return new TaskAction(PendingIntent.getActivity(context, (int)id, actionIntent, 0), (BitmapDrawable)icon);
@ -114,11 +115,11 @@ public class LinkActionExposer {
private static final HashMap<Integer, BitmapDrawable> IMAGE_CACHE = new HashMap<>();
private static BitmapDrawable getBitmapDrawable(int resId, Resources resources) {
private static BitmapDrawable getBitmapDrawable(Context context, int resId, Resources resources) {
if (IMAGE_CACHE.containsKey(resId)) {
return IMAGE_CACHE.get(resId);
} else {
BitmapDrawable b = (BitmapDrawable) resources.getDrawable(resId);
BitmapDrawable b = (BitmapDrawable) ContextCompat.getDrawable(context, resId);
IMAGE_CACHE.put(resId, b);
return b;
}

@ -34,6 +34,7 @@ import java.util.Collections;
import javax.inject.Inject;
import static android.support.v4.content.ContextCompat.getColor;
import static org.tasks.files.FileHelper.getPathFromUri;
import static org.tasks.files.ImageHelper.sampleBitmap;
@ -92,7 +93,7 @@ public class CommentsController {
if (items.size() > commentItems) {
Button loadMore = new Button(activity);
loadMore.setText(R.string.TEA_load_more);
loadMore.setTextColor(activity.getResources().getColor(R.color.task_edit_deadline_gray));
loadMore.setTextColor(getColor(activity, R.color.task_edit_deadline_gray));
loadMore.setBackgroundColor(Color.alpha(0));
loadMore.setOnClickListener(v -> {
// Perform action on click

@ -56,6 +56,7 @@ import butterknife.BindView;
import butterknife.OnClick;
import timber.log.Timber;
import static android.support.v4.content.ContextCompat.getColor;
import static org.tasks.date.DateTimeUtils.newDateTime;
/**
@ -445,11 +446,11 @@ public class RepeatControlSet extends TaskEditControlFragment {
protected void refreshDisplayView() {
if (doRepeat) {
displayView.setText(getRepeatString());
displayView.setTextColor(getResources().getColor(R.color.text_primary));
displayView.setTextColor(getColor(context, R.color.text_primary));
clear.setVisibility(View.VISIBLE);
} else {
displayView.setText(R.string.repeat_never);
displayView.setTextColor(getResources().getColor(R.color.text_tertiary));
displayView.setTextColor(getColor(context, R.color.text_tertiary));
clear.setVisibility(View.GONE);
}
}

@ -9,6 +9,7 @@ import android.annotation.SuppressLint;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.content.ContextCompat;
import android.support.v4.graphics.drawable.DrawableCompat;
import android.support.v7.app.AlertDialog;
import android.text.Editable;
@ -159,7 +160,7 @@ public final class TagsControlSet extends TaskEditControlFragment {
TagData tagData = allTags.get(position);
ThemeColor themeColor = themeCache.getThemeColor(tagData.getColor() >= 0 ? tagData.getColor() : 19);
view.setText(tagData.getName());
Drawable original = getResources().getDrawable(R.drawable.ic_label_24dp);
Drawable original = ContextCompat.getDrawable(getContext(), R.drawable.ic_label_24dp);
Drawable wrapped = DrawableCompat.wrap(original.mutate());
DrawableCompat.setTint(wrapped, themeColor.getPrimaryColor());
if (atLeastJellybeanMR1()) {

@ -37,6 +37,8 @@ import javax.inject.Inject;
import butterknife.BindView;
import butterknife.OnClick;
import static android.support.v4.content.ContextCompat.getColor;
/**
* Control Set for managing repeats
*
@ -210,10 +212,10 @@ public class TimerControlSet extends TaskEditControlFragment {
if (!TextUtils.isEmpty(toDisplay)) {
displayEdit.setText(toDisplay);
displayEdit.setTextColor(getResources().getColor(R.color.text_primary));
displayEdit.setTextColor(getColor(context, R.color.text_primary));
} else {
displayEdit.setText(R.string.TEA_timer_controls);
displayEdit.setTextColor(getResources().getColor(R.color.text_tertiary));
displayEdit.setTextColor(getColor(context, R.color.text_tertiary));
}
}

@ -41,6 +41,7 @@ import javax.inject.Inject;
import butterknife.BindView;
import butterknife.OnClick;
import static android.support.v4.content.ContextCompat.getColor;
import static java.util.Arrays.asList;
import static org.tasks.date.DateTimeUtils.newDateTime;
@ -102,14 +103,14 @@ public class HideUntilControlSet extends TaskEditControlFragment implements OnIt
if (value.setting == Task.HIDE_UNTIL_NONE) {
clearButton.setVisibility(View.GONE);
tv.setText(value.label);
tv.setTextColor(getContext().getResources().getColor(R.color.text_tertiary));
tv.setTextColor(getColor(context, R.color.text_tertiary));
} else {
String display = value.label;
if (value.setting != Task.HIDE_UNTIL_SPECIFIC_DAY && value.setting != Task.HIDE_UNTIL_SPECIFIC_DAY_TIME) {
display = display.toLowerCase();
}
tv.setText(getString(R.string.TEA_hideUntil_display, display));
tv.setTextColor(getContext().getResources().getColor(R.color.text_primary));
tv.setTextColor(getColor(context, R.color.text_primary));
}
return tv;
}

@ -7,6 +7,7 @@ import android.content.Context;
import android.content.DialogInterface;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.support.v4.content.ContextCompat;
import android.support.v4.graphics.drawable.DrawableCompat;
import android.view.LayoutInflater;
import android.view.View;
@ -75,7 +76,7 @@ public class ColorPickerDialog extends InjectingDialogFragment {
TextView textView = (TextView) (convertView == null
? inflater.inflate(R.layout.color_selection_row, parent, false)
: convertView);
Drawable original = context.getResources().getDrawable(preferences.hasPurchase(R.string.p_purchased_themes) || position < getNumFree()
Drawable original = ContextCompat.getDrawable(context, preferences.hasPurchase(R.string.p_purchased_themes) || position < getNumFree()
? R.drawable.ic_lens_black_24dp
: R.drawable.ic_vpn_key_black_24dp);
Drawable wrapped = DrawableCompat.wrap(original.mutate());

@ -8,6 +8,7 @@ import android.graphics.drawable.Drawable;
import android.net.Uri;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.content.ContextCompat;
import android.support.v4.graphics.drawable.DrawableCompat;
import android.text.TextUtils;
import android.util.TypedValue;
@ -238,7 +239,7 @@ public class CommentBarFragment extends TaskEditControlFragment {
private void resetPictureButton() {
TypedValue typedValue = new TypedValue();
getActivity().getTheme().resolveAttribute(R.attr.actionBarPrimaryText, typedValue, true);
Drawable drawable = DrawableCompat.wrap(getResources().getDrawable(R.drawable.ic_camera_alt_black_24dp));
Drawable drawable = DrawableCompat.wrap(ContextCompat.getDrawable(getContext(), R.drawable.ic_camera_alt_black_24dp));
drawable.mutate();
DrawableCompat.setTint(drawable, typedValue.data);
pictureButton.setImageDrawable(drawable);

@ -6,6 +6,7 @@ import android.os.Bundle;
import android.preference.Preference;
import android.preference.PreferenceCategory;
import android.preference.PreferenceGroup;
import android.support.v4.content.ContextCompat;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.view.ViewGroup;
@ -59,7 +60,7 @@ public abstract class InjectingPreferenceActivity extends AppCompatPreferenceAct
Timber.e(e, e.getMessage());
toolbar.setTitle(getTitle());
}
toolbar.setNavigationIcon(getResources().getDrawable(R.drawable.ic_arrow_back_24dp));
toolbar.setNavigationIcon(ContextCompat.getDrawable(this, R.drawable.ic_arrow_back_24dp));
toolbar.setNavigationOnClickListener(v -> finish());
MenuColorizer.colorToolbar(this, toolbar);
}

@ -11,6 +11,8 @@ import org.tasks.R;
import java.util.ArrayList;
import java.util.List;
import static android.support.v4.content.ContextCompat.getColor;
public class ThemeCache {
private final List<ThemeBase> themes = new ArrayList<>();
@ -23,11 +25,11 @@ public class ThemeCache {
public ThemeCache(Context context) {
Resources resources = context.getResources();
themes.add(new ThemeBase(context.getString(R.string.theme_light), 0, resources.getColor(R.color.md_background_light), AppCompatDelegate.MODE_NIGHT_NO));
themes.add(new ThemeBase(context.getString(R.string.theme_black), 1, resources.getColor(R.color.widget_background_black), AppCompatDelegate.MODE_NIGHT_YES));
themes.add(new ThemeBase(context.getString(R.string.theme_dark), 2, resources.getColor(R.color.md_background_dark), AppCompatDelegate.MODE_NIGHT_YES));
themes.add(new ThemeBase(context.getString(R.string.theme_wallpaper), 3, resources.getColor(R.color.black_38), AppCompatDelegate.MODE_NIGHT_YES));
themes.add(new ThemeBase(context.getString(R.string.theme_day_night), 4, resources.getColor(R.color.md_background_light), AppCompatDelegate.MODE_NIGHT_AUTO));
themes.add(new ThemeBase(context.getString(R.string.theme_light), 0, getColor(context, R.color.md_background_light), AppCompatDelegate.MODE_NIGHT_NO));
themes.add(new ThemeBase(context.getString(R.string.theme_black), 1, getColor(context, R.color.widget_background_black), AppCompatDelegate.MODE_NIGHT_YES));
themes.add(new ThemeBase(context.getString(R.string.theme_dark), 2, getColor(context, R.color.md_background_dark), AppCompatDelegate.MODE_NIGHT_YES));
themes.add(new ThemeBase(context.getString(R.string.theme_wallpaper), 3, getColor(context, R.color.black_38), AppCompatDelegate.MODE_NIGHT_YES));
themes.add(new ThemeBase(context.getString(R.string.theme_day_night), 4, getColor(context, R.color.md_background_light), AppCompatDelegate.MODE_NIGHT_AUTO));
String[] colorNames = resources.getStringArray(R.array.colors);
for (int i = 0 ; i < ThemeColor.COLORS.length ; i++) {
@ -52,16 +54,16 @@ public class ThemeCache {
for (int i = 0; i < WidgetTheme.BACKGROUNDS.length ; i++) {
widgetThemes.add(new WidgetTheme(
widgetBackgroundNames[i],
resources.getColor(WidgetTheme.BACKGROUNDS[i]),
resources.getColor(i == 0 ? R.color.black_87 : R.color.white_100)));
getColor(context, WidgetTheme.BACKGROUNDS[i]),
getColor(context, i == 0 ? R.color.black_87 : R.color.white_100)));
}
String []ledNames = resources.getStringArray(R.array.led);
for (int i = 0 ; i < LEDColor.LED_COLORS.length ; i++) {
led.add(new LEDColor(
ledNames[i],
resources.getColor(LEDColor.LED_COLORS[i])));
getColor(context, LEDColor.LED_COLORS[i])));
}
untaggedColor = new ThemeColor(null, 19, resources.getColor(R.color.tag_color_none_background), 0, resources.getColor(R.color.black_87), false);
untaggedColor = new ThemeColor(null, 19, getColor(context, R.color.tag_color_none_background), 0, getColor(context, R.color.black_87), false);
}
public WidgetTheme getWidgetTheme(int index) {

@ -19,12 +19,12 @@ import android.widget.Toast;
import com.google.common.base.Strings;
import com.todoroo.astrid.data.Task;
import org.tasks.calendars.AndroidCalendar;
import com.todoroo.astrid.gcal.GCalHelper;
import org.tasks.R;
import org.tasks.activities.CalendarSelectionActivity;
import org.tasks.analytics.Tracker;
import org.tasks.calendars.AndroidCalendar;
import org.tasks.calendars.CalendarProvider;
import org.tasks.dialogs.DialogBuilder;
import org.tasks.injection.ForActivity;
@ -40,6 +40,7 @@ import butterknife.BindView;
import butterknife.OnClick;
import timber.log.Timber;
import static android.support.v4.content.ContextCompat.getColor;
import static com.google.common.base.Strings.isNullOrEmpty;
public class CalendarControlSet extends TaskEditControlFragment {
@ -300,15 +301,15 @@ public class CalendarControlSet extends TaskEditControlFragment {
private void refreshDisplayView() {
if (!Strings.isNullOrEmpty(eventUri)) {
calendar.setText(R.string.gcal_TEA_showCalendar_label);
calendar.setTextColor(getResources().getColor(R.color.text_primary));
calendar.setTextColor(getColor(context, R.color.text_primary));
cancelButton.setVisibility(View.VISIBLE);
} else if (calendarName != null) {
calendar.setText(calendarName);
calendar.setTextColor(getResources().getColor(R.color.text_primary));
calendar.setTextColor(getColor(context, R.color.text_primary));
cancelButton.setVisibility(View.VISIBLE);
} else {
calendar.setText(R.string.gcal_TEA_addToCalendar_label);
calendar.setTextColor(getResources().getColor(R.color.text_tertiary));
calendar.setTextColor(getColor(context, R.color.text_tertiary));
cancelButton.setVisibility(View.GONE);
}
}

@ -1,8 +1,8 @@
package org.tasks.ui;
import android.content.Context;
import android.content.res.Resources;
import android.graphics.drawable.Drawable;
import android.support.v4.content.ContextCompat;
import android.support.v4.graphics.drawable.DrawableCompat;
import com.google.common.collect.ImmutableList;
@ -12,6 +12,8 @@ import org.tasks.R;
import java.util.List;
import static android.support.v4.content.ContextCompat.getColor;
public class CheckBoxes {
public static CheckBoxes newCheckBoxes(Context context) {
@ -31,10 +33,10 @@ public class CheckBoxes {
repeatingCheckboxes = wrapDrawable(context, R.drawable.ic_repeat_24dp);
completedCheckboxes = wrapDrawable(context, R.drawable.ic_check_box_24dp);
priorityColors = ImmutableList.of(
context.getResources().getColor(R.color.importance_1),
context.getResources().getColor(R.color.importance_2),
context.getResources().getColor(R.color.importance_3),
context.getResources().getColor(R.color.importance_4));
getColor(context, R.color.importance_1),
getColor(context, R.color.importance_2),
getColor(context, R.color.importance_3),
getColor(context, R.color.importance_4));
priorityColorsArray = Ints.toArray(priorityColors);
}
@ -79,10 +81,9 @@ public class CheckBoxes {
}
private static Drawable getDrawable(Context context, int resId, int importance) {
Resources resources = context.getResources();
Drawable original = resources.getDrawable(resId);
Drawable original = ContextCompat.getDrawable(context, resId);
Drawable wrapped = DrawableCompat.wrap(original.mutate());
DrawableCompat.setTint(wrapped, resources.getColor(getImportanceResId(importance)));
DrawableCompat.setTint(wrapped, getColor(context, getImportanceResId(importance)));
return wrapped;
}

@ -6,6 +6,7 @@ import android.content.Intent;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.content.ContextCompat;
import android.support.v4.graphics.drawable.DrawableCompat;
import android.view.LayoutInflater;
import android.view.View;
@ -36,6 +37,7 @@ import butterknife.BindView;
import butterknife.OnClick;
import butterknife.OnItemSelected;
import static android.support.v4.content.ContextCompat.getColor;
import static com.google.common.collect.Lists.newArrayList;
import static java.util.Arrays.asList;
import static org.tasks.date.DateTimeUtils.newDateTime;
@ -128,7 +130,7 @@ public class DeadlineControlSet extends TaskEditControlFragment {
date = savedInstanceState.getLong(EXTRA_DATE);
time = savedInstanceState.getInt(EXTRA_TIME);
}
final int overdueColor = context.getResources().getColor(R.color.overdue);
final int overdueColor = getColor(context, R.color.overdue);
dueDateAdapter = new HiddenTopArrayAdapter<String>(context, android.R.layout.simple_spinner_item, dueDateOptions) {
@Override
public View getView(final int position, final View convertView, final ViewGroup parent) {
@ -141,11 +143,11 @@ public class DeadlineControlSet extends TaskEditControlFragment {
tv.setText(dueDateOptions.get(selectedItemPosition));
int textColor;
if (date == 0) {
textColor = getResources().getColor(R.color.text_tertiary);
textColor = getColor(context, R.color.text_tertiary);
} else if (date < newDateTime().startOfDay().getMillis()) {
textColor = overdueColor;
} else {
textColor = getResources().getColor(R.color.text_primary);
textColor = getColor(context, R.color.text_primary);
}
dueDateSpinner.setBackgroundDrawable(getUnderline(textColor));
tv.setTextColor(textColor);
@ -166,11 +168,11 @@ public class DeadlineControlSet extends TaskEditControlFragment {
tv.setText(dueTimeOptions.get(selectedItemPosition));
int textColor;
if (time == -1) {
textColor = getResources().getColor(R.color.text_tertiary);
textColor = getColor(context, R.color.text_tertiary);
} else if (newDateTime(date).withMillisOfDay(time).isBeforeNow()) {
textColor = overdueColor;
} else {
textColor = getResources().getColor(R.color.text_primary);
textColor = getColor(context, R.color.text_primary);
}
tv.setTextColor(textColor);
dueTimeSpinner.setBackgroundDrawable(getUnderline(textColor));
@ -380,7 +382,7 @@ public class DeadlineControlSet extends TaskEditControlFragment {
}
private Drawable getUnderline(int color) {
Drawable drawable = DrawableCompat.wrap(context.getResources().getDrawable(R.drawable.textfield_underline_black));
Drawable drawable = DrawableCompat.wrap(ContextCompat.getDrawable(context, R.drawable.textfield_underline_black));
drawable.mutate();
DrawableCompat.setTint(drawable, color);
return drawable;

@ -31,6 +31,7 @@ import org.tasks.ui.WidgetCheckBoxes;
import timber.log.Timber;
import static android.support.v4.content.ContextCompat.getColor;
import static com.todoroo.andlib.utility.AndroidUtilities.atLeastJellybeanMR1;
public class ScrollableViewsFactory implements RemoteViewsService.RemoteViewsFactory {
@ -144,7 +145,6 @@ public class ScrollableViewsFactory implements RemoteViewsService.RemoteViewsFac
return null;
}
String textContent;
Resources r = context.getResources();
int textColor = themeTextColor;
textContent = task.getTitle();
@ -152,7 +152,7 @@ public class ScrollableViewsFactory implements RemoteViewsService.RemoteViewsFac
RemoteViews row = new RemoteViews(BuildConfig.APPLICATION_ID, R.layout.widget_row);
if (task.isCompleted()) {
textColor = r.getColor(R.color.task_list_done);
textColor = getColor(context, R.color.task_list_done);
row.setInt(R.id.widget_text, "setPaintFlags", Paint.STRIKE_THRU_TEXT_FLAG | Paint.ANTI_ALIAS_FLAG);
} else {
row.setInt(R.id.widget_text, "setPaintFlags", Paint.ANTI_ALIAS_FLAG);
@ -163,7 +163,7 @@ public class ScrollableViewsFactory implements RemoteViewsService.RemoteViewsFac
} else {
row.setViewVisibility(R.id.widget_due_date, View.GONE);
if (task.hasDueDate() && task.isOverdue()) {
textColor = r.getColor(R.color.overdue);
textColor = getColor(context, R.color.overdue);
}
}
@ -237,7 +237,8 @@ public class ScrollableViewsFactory implements RemoteViewsService.RemoteViewsFac
row.setTextViewText(R.id.widget_due_date, task.isCompleted()
? resources.getString(R.string.TAd_completed, DateUtilities.getRelativeDateStringWithTime(context, task.getCompletionDate()))
: DateUtilities.getRelativeDateStringWithTime(context, task.getDueDate()));
row.setTextColor(R.id.widget_due_date, task.isOverdue() ? resources.getColor(R.color.overdue) : textColor);
//noinspection ResourceAsColor
row.setTextColor(R.id.widget_due_date, task.isOverdue() ? getColor(context, R.color.overdue) : textColor);
row.setFloat(R.id.widget_due_date, "setTextSize", dueDateTextSize);
} else {
row.setViewVisibility(R.id.widget_due_date, View.GONE);

@ -5,6 +5,7 @@ import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.drawable.BitmapDrawable;
import android.os.Bundle;
import android.support.v4.content.ContextCompat;
import com.todoroo.astrid.api.Filter;
@ -43,7 +44,7 @@ public class ShortcutConfigActivity extends InjectingAppCompatActivity {
Filter filter = data.getParcelableExtra(FilterSelectionActivity.EXTRA_FILTER);
String filterId = defaultFilterProvider.getFilterPreferenceValue(filter);
Intent shortcutIntent = TaskIntents.getTaskListByIdIntent(this, filterId);
Bitmap bitmap = ((BitmapDrawable) getResources().getDrawable(R.mipmap.ic_launcher)).getBitmap();
Bitmap bitmap = ((BitmapDrawable) ContextCompat.getDrawable(this, R.mipmap.ic_launcher)).getBitmap();
Intent intent = new Intent();
intent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent);
intent.putExtra(Intent.EXTRA_SHORTCUT_NAME, filter.listingTitle);

Loading…
Cancel
Save