Updating widget preview generation to not embed any badge.
Instead drawing badge in the view directly. This will allow us to reuse the same preview when we do not want to draw badges. This also simplified badging of shortcut config activities. Change-Id: I9c07c33bf9c2b8ef81a00026b1d42587868c906f
This commit is contained in:
1 parent
278359539c
commit
a2441e88ff
8 files changed
+105
-72
No files matched your search
@@ -22,9 +22,13 @@ import android.graphics.Canvas;
|
||||
import android.graphics.Paint;
|
||||
import android.graphics.Rect;
|
||||
import android.graphics.RectF;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.util.AttributeSet;
|
||||
import android.view.View;
|
||||
|
||||
import com.android.launcher3.R;
|
||||
import com.android.launcher3.Utilities;
|
||||
|
||||
/**
|
||||
* View that draws a bitmap horizontally centered. If the image width is greater than the view
|
||||
* width, the image is scaled down appropriately.
|
||||
@@ -33,22 +37,29 @@ public class WidgetImageView extends View {
|
||||
|
||||
private final Paint mPaint = new Paint(Paint.ANTI_ALIAS_FLAG | Paint.FILTER_BITMAP_FLAG);
|
||||
private final RectF mDstRectF = new RectF();
|
||||
private final int mBadgeMargin;
|
||||
|
||||
private Bitmap mBitmap;
|
||||
private Drawable mBadge;
|
||||
|
||||
public WidgetImageView(Context context) {
|
||||
super(context);
|
||||
this(context, null);
|
||||
}
|
||||
|
||||
public WidgetImageView(Context context, AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
this(context, attrs, 0);
|
||||
}
|
||||
|
||||
public WidgetImageView(Context context, AttributeSet attrs, int defStyle) {
|
||||
super(context, attrs, defStyle);
|
||||
|
||||
mBadgeMargin = context.getResources()
|
||||
.getDimensionPixelSize(R.dimen.profile_badge_margin);
|
||||
}
|
||||
|
||||
public void setBitmap(Bitmap bitmap) {
|
||||
public void setBitmap(Bitmap bitmap, Drawable badge) {
|
||||
mBitmap = bitmap;
|
||||
mBadge = badge;
|
||||
invalidate();
|
||||
}
|
||||
|
||||
@@ -61,6 +72,11 @@ public class WidgetImageView extends View {
|
||||
if (mBitmap != null) {
|
||||
updateDstRectF();
|
||||
canvas.drawBitmap(mBitmap, null, mDstRectF, mPaint);
|
||||
|
||||
// Only draw the badge if a preview was drawn.
|
||||
if (mBadge != null) {
|
||||
mBadge.draw(canvas);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -83,6 +99,16 @@ public class WidgetImageView extends View {
|
||||
(getWidth() + mBitmap.getWidth()) * 0.5f,
|
||||
mBitmap.getHeight());
|
||||
}
|
||||
if (mBadge != null) {
|
||||
Rect bounds = mBadge.getBounds();
|
||||
int left = Utilities.boundToRange(
|
||||
(int) (mDstRectF.right + mBadgeMargin - bounds.width()),
|
||||
mBadgeMargin, getWidth() - bounds.width());
|
||||
int top = Utilities.boundToRange(
|
||||
(int) (mDstRectF.bottom + mBadgeMargin - bounds.height()),
|
||||
mBadgeMargin, getHeight() - bounds.height());
|
||||
mBadge.setBounds(left, top, bounds.width() + left, bounds.height() + top);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in new issue
Block a user