Updating the shortcut preview generation logic

Drawing a shortcut icon on a white round-rect with shadow
Also center aligning the preview

Bug: 34819119
Change-Id: Ic25be6bf301aeb11315a5050f009259b26c6134a
This commit is contained in:
Sunny Goyal
2017-02-13 10:44:43 -08:00
parent eb04b84153
commit 7d87cb1a6e
4 changed files with 77 additions and 61 deletions

View File

@@ -89,16 +89,25 @@ public class WidgetImageView extends View {
}
private void updateDstRectF() {
if (mBitmap.getWidth() > getWidth()) {
float scale = ((float) getWidth()) / mBitmap.getWidth();
mDstRectF.set(0, 0, getWidth(), scale * mBitmap.getHeight());
float myWidth = getWidth();
float myHeight = getHeight();
float bitmapWidth = mBitmap.getWidth();
final float scale = bitmapWidth > myWidth ? myWidth / bitmapWidth : 1;
float scaledWidth = bitmapWidth * scale;
float scaledHeight = mBitmap.getHeight() * scale;
mDstRectF.left = (myWidth - scaledWidth) / 2;
mDstRectF.right = (myWidth + scaledWidth) / 2;
if (scaledHeight > myHeight) {
mDstRectF.top = 0;
mDstRectF.bottom = scaledHeight;
} else {
mDstRectF.set(
(getWidth() - mBitmap.getWidth()) * 0.5f,
0,
(getWidth() + mBitmap.getWidth()) * 0.5f,
mBitmap.getHeight());
mDstRectF.top = (myHeight - scaledHeight) / 2;
mDstRectF.bottom = (myHeight + scaledHeight) / 2;
}
if (mBadge != null) {
Rect bounds = mBadge.getBounds();
int left = Utilities.boundToRange(