Use saturated checkbox colors in dark mode

pull/935/head
Alex Baker 4 years ago
parent 9c2f1b449b
commit f4561121b6

@ -6,24 +6,19 @@ import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.drawable.Drawable;
import androidx.annotation.ColorRes;
import androidx.annotation.DrawableRes;
import androidx.core.content.ContextCompat;
import androidx.core.graphics.drawable.DrawableCompat;
import com.todoroo.astrid.data.Task;
import org.tasks.R;
import org.tasks.themes.DrawableUtil;
public class CheckBoxes {
private CheckBoxes() {}
private static Drawable getDrawable(Context context, @DrawableRes int resId, int priority) {
Drawable original = ContextCompat.getDrawable(context, resId);
Drawable wrapped = DrawableCompat.wrap(original.mutate());
DrawableCompat.setTint(wrapped, getColor(context, getPriorityResId(priority)));
return wrapped;
}
private static int getPriorityResId(int priority) {
private @ColorRes static int getPriorityResId(int priority) {
if (priority <= 0) {
return R.color.priority_1;
} else if (priority == 1) {
@ -35,6 +30,18 @@ public class CheckBoxes {
}
}
private @ColorRes static int getWidgetPriorityResId(int priority) {
if (priority <= 0) {
return R.color.widget_priority_1;
} else if (priority == 1) {
return R.color.widget_priority_2;
} else if (priority == 2) {
return R.color.widget_priority_3;
} else {
return R.color.priority_4;
}
}
private static Bitmap convertToBitmap(Drawable d) {
Bitmap bitmap =
Bitmap.createBitmap(d.getIntrinsicWidth(), d.getIntrinsicHeight(), Bitmap.Config.ARGB_8888);
@ -44,8 +51,21 @@ public class CheckBoxes {
return bitmap;
}
public static Bitmap getCheckBoxBitmap(Context context, Task task) {
return convertToBitmap(getCheckBox(context, task));
private static @DrawableRes int getDrawable(Task task) {
if (task.isCompleted()) {
return R.drawable.ic_outline_check_box_24px;
} else if (task.isRecurring()) {
return R.drawable.ic_outline_repeat_24px;
} else {
return R.drawable.ic_outline_check_box_outline_blank_24px;
}
}
public static Bitmap getWidgetCheckBox(Context context, Task task) {
Drawable wrapped = DrawableUtil.getWrapped(context, getDrawable(task));
int color = getWidgetPriorityResId(task.getPriority());
DrawableUtil.setTint(wrapped, ContextCompat.getColor(context, color));
return convertToBitmap(wrapped);
}
public static Drawable getCheckBox(Context context, Task task) {
@ -63,6 +83,13 @@ public class CheckBoxes {
}
}
private static Drawable getDrawable(Context context, @DrawableRes int resId, int priority) {
Drawable original = ContextCompat.getDrawable(context, resId);
Drawable wrapped = DrawableCompat.wrap(original.mutate());
DrawableCompat.setTint(wrapped, getColor(context, getPriorityResId(priority)));
return wrapped;
}
public static int getPriorityColor(Context context, int priority) {
return getColor(context, getPriorityResId(priority));
}

@ -124,7 +124,7 @@ class ScrollableViewsFactory implements RemoteViewsService.RemoteViewsFactory {
}
private Bitmap getCheckbox(Task task) {
return CheckBoxes.getCheckBoxBitmap(context, task);
return CheckBoxes.getWidgetCheckBox(context, task);
}
private RemoteViews buildUpdate(int position) {

@ -10,4 +10,9 @@
<color name="text_secondary">@color/white_60</color>
<color name="text_tertiary">@color/white_38</color>
<color name="overdue">@color/error_color_material_dark</color>
<color name="priority_1">@color/red_200</color>
<color name="priority_2">@color/amber_200</color>
<color name="priority_3">@color/blue_200</color>
</resources>

@ -5,7 +5,7 @@
** See the file "LICENSE" for the full license governing this code.
-->
<resources>
<color name="red_200">#EF9A9A</color>
<color name="red_500">#f44336</color>
<color name="red_a400">#ff1744</color>
<color name="red_a100">#FF8A80</color>
@ -26,6 +26,7 @@
<color name="indigo_a400">#3d5afe</color>
<color name="indigo_a100">#8C9EFF</color>
<color name="blue_200">#90CAF9</color>
<color name="blue_500">#2196f3</color>
<color name="blue_a400">#2979ff</color>
<color name="blue_a100">#82B1FF</color>
@ -58,6 +59,7 @@
<color name="yellow_a400">#ffea00</color>
<color name="yellow_a100">#FFFF8D</color>
<color name="amber_200">#FFE082</color>
<color name="amber_500">#ffc107</color>
<color name="amber_a400">#ffc400</color>
<color name="amber_a100">#FFE57F</color>
@ -110,6 +112,10 @@
<color name="priority_3">@color/blue_500</color>
<color name="priority_4">@color/grey_500</color>
<color name="widget_priority_1">@color/red_500</color>
<color name="widget_priority_2">@color/amber_500</color>
<color name="widget_priority_3">@color/blue_500</color>
<color name="snackbar_text_color">@color/white_87</color>
<color name="snackbar_action_color">#f4b400</color>
<color name="snackbar_background">@color/grey_800</color>

Loading…
Cancel
Save