mirror of https://github.com/tasks/tasks
parent
99303b9e56
commit
74cf0fc378
@ -1,68 +1,51 @@
|
|||||||
package org.tasks.ui;
|
package org.tasks.ui;
|
||||||
|
|
||||||
import static com.google.common.collect.Lists.newArrayList;
|
|
||||||
import static com.google.common.collect.Lists.transform;
|
|
||||||
|
|
||||||
import android.graphics.Bitmap;
|
import android.graphics.Bitmap;
|
||||||
import android.graphics.Canvas;
|
import android.graphics.Canvas;
|
||||||
import android.graphics.drawable.BitmapDrawable;
|
|
||||||
import android.graphics.drawable.Drawable;
|
import android.graphics.drawable.Drawable;
|
||||||
import java.util.List;
|
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
import org.tasks.injection.ApplicationScope;
|
import org.tasks.injection.ApplicationScope;
|
||||||
import timber.log.Timber;
|
|
||||||
|
|
||||||
@ApplicationScope
|
@ApplicationScope
|
||||||
public class WidgetCheckBoxes {
|
public class WidgetCheckBoxes {
|
||||||
|
|
||||||
private final List<Bitmap> checkboxes;
|
private final CheckBoxes checkBoxes;
|
||||||
private final List<Bitmap> repeatingCheckboxes;
|
private final Bitmap[] incomplete = new Bitmap[4];
|
||||||
private final List<Bitmap> completedCheckboxes;
|
private final Bitmap[] repeating = new Bitmap[4];
|
||||||
|
private final Bitmap[] completed = new Bitmap[4];
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
public WidgetCheckBoxes(CheckBoxes checkBoxes) {
|
public WidgetCheckBoxes(CheckBoxes checkBoxes) {
|
||||||
Timber.d("Initializing widget checkboxes");
|
this.checkBoxes = checkBoxes;
|
||||||
checkboxes = convertToBitmap(checkBoxes.getCheckBoxes());
|
|
||||||
repeatingCheckboxes = convertToBitmap(checkBoxes.getRepeatingCheckBoxes());
|
|
||||||
completedCheckboxes = convertToBitmap(checkBoxes.getCompletedCheckBoxes());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static List<Bitmap> convertToBitmap(final List<Drawable> drawables) {
|
private static Bitmap convertToBitmap(Drawable d) {
|
||||||
return newArrayList(
|
Bitmap bitmap =
|
||||||
transform(
|
Bitmap.createBitmap(d.getIntrinsicWidth(), d.getIntrinsicHeight(), Bitmap.Config.ARGB_8888);
|
||||||
drawables,
|
Canvas canvas = new Canvas(bitmap);
|
||||||
drawable -> {
|
d.setBounds(0, 0, canvas.getWidth(), canvas.getHeight());
|
||||||
if (drawable instanceof BitmapDrawable) {
|
d.draw(canvas);
|
||||||
BitmapDrawable bitmapDrawable = (BitmapDrawable) drawable;
|
return bitmap;
|
||||||
if (bitmapDrawable.getBitmap() != null) {
|
|
||||||
return bitmapDrawable.getBitmap();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Bitmap bitmap =
|
|
||||||
drawable.getIntrinsicWidth() <= 0 || drawable.getIntrinsicHeight() <= 0
|
|
||||||
? Bitmap.createBitmap(1, 1, Bitmap.Config.ARGB_8888)
|
|
||||||
: Bitmap.createBitmap(
|
|
||||||
drawable.getIntrinsicWidth(),
|
|
||||||
drawable.getIntrinsicHeight(),
|
|
||||||
Bitmap.Config.ARGB_8888);
|
|
||||||
|
|
||||||
Canvas canvas = new Canvas(bitmap);
|
|
||||||
drawable.setBounds(0, 0, canvas.getWidth(), canvas.getHeight());
|
|
||||||
drawable.draw(canvas);
|
|
||||||
return bitmap;
|
|
||||||
}));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public Bitmap getCompletedCheckbox(int importance) {
|
public Bitmap getCompletedCheckbox(int importance) {
|
||||||
return completedCheckboxes.get(importance);
|
if (completed[importance] == null) {
|
||||||
|
completed[importance] = convertToBitmap(checkBoxes.getCompletedCheckbox(importance));
|
||||||
|
}
|
||||||
|
return completed[importance];
|
||||||
}
|
}
|
||||||
|
|
||||||
public Bitmap getRepeatingCheckBox(int importance) {
|
public Bitmap getRepeatingCheckBox(int importance) {
|
||||||
return repeatingCheckboxes.get(importance);
|
if (repeating[importance] == null) {
|
||||||
|
repeating[importance] = convertToBitmap(checkBoxes.getRepeatingCheckBox(importance));
|
||||||
|
}
|
||||||
|
return repeating[importance];
|
||||||
}
|
}
|
||||||
|
|
||||||
public Bitmap getCheckBox(int importance) {
|
public Bitmap getCheckBox(int importance) {
|
||||||
return checkboxes.get(importance);
|
if (incomplete[importance] == null) {
|
||||||
|
incomplete[importance] = convertToBitmap(checkBoxes.getCheckBox(importance));
|
||||||
|
}
|
||||||
|
return incomplete[importance];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue