diff options
author | Tony Wickham <twickham@google.com> | 2017-04-25 23:59:41 +0000 |
---|---|---|
committer | android-build-merger <android-build-merger@google.com> | 2017-04-25 23:59:41 +0000 |
commit | 0e96f3fea90ffaf2da20a9c5476e342c8f866d76 (patch) | |
tree | 88582bce023a0919dc8539ac094e2b5c71f38601 /src/com | |
parent | 03a222ee866a64ed8da855f0a06c5549dcc18a26 (diff) | |
parent | 0fa96ea2f6c8a48917e619b3120beaa90698cb43 (diff) | |
download | android_packages_apps_Trebuchet-0e96f3fea90ffaf2da20a9c5476e342c8f866d76.tar.gz android_packages_apps_Trebuchet-0e96f3fea90ffaf2da20a9c5476e342c8f866d76.tar.bz2 android_packages_apps_Trebuchet-0e96f3fea90ffaf2da20a9c5476e342c8f866d76.zip |
Merge "Update icon badges to match spec" into ub-launcher3-dorval
am: 0fa96ea2f6
Change-Id: I5f8e6bdbca13435d54e3b636564f7d3eef58ca5c
Diffstat (limited to 'src/com')
-rw-r--r-- | src/com/android/launcher3/BubbleTextView.java | 90 | ||||
-rw-r--r-- | src/com/android/launcher3/DeviceProfile.java | 5 | ||||
-rw-r--r-- | src/com/android/launcher3/FastBitmapDrawable.java | 50 | ||||
-rw-r--r-- | src/com/android/launcher3/Workspace.java | 12 | ||||
-rw-r--r-- | src/com/android/launcher3/badge/BadgeRenderer.java | 62 | ||||
-rw-r--r-- | src/com/android/launcher3/folder/FolderIcon.java | 16 | ||||
-rw-r--r-- | src/com/android/launcher3/graphics/IconPalette.java | 6 | ||||
-rw-r--r-- | src/com/android/launcher3/graphics/ShadowGenerator.java | 32 | ||||
-rw-r--r-- | src/com/android/launcher3/popup/PopupContainerWithArrow.java | 4 |
9 files changed, 177 insertions, 100 deletions
diff --git a/src/com/android/launcher3/BubbleTextView.java b/src/com/android/launcher3/BubbleTextView.java index add0185ba..45dabe9aa 100644 --- a/src/com/android/launcher3/BubbleTextView.java +++ b/src/com/android/launcher3/BubbleTextView.java @@ -16,6 +16,7 @@ package com.android.launcher3; +import android.animation.ObjectAnimator; import android.content.Context; import android.content.res.ColorStateList; import android.content.res.Resources; @@ -23,9 +24,12 @@ import android.content.res.TypedArray; import android.graphics.Bitmap; import android.graphics.Canvas; import android.graphics.Paint; +import android.graphics.Point; +import android.graphics.Rect; import android.graphics.Region; import android.graphics.drawable.Drawable; import android.util.AttributeSet; +import android.util.Property; import android.util.TypedValue; import android.view.KeyEvent; import android.view.MotionEvent; @@ -42,6 +46,7 @@ import com.android.launcher3.badge.BadgeRenderer; import com.android.launcher3.folder.FolderIconPreviewVerifier; import com.android.launcher3.graphics.DrawableFactory; import com.android.launcher3.graphics.HolographicOutlineHelper; +import com.android.launcher3.graphics.IconPalette; import com.android.launcher3.graphics.PreloadIconDrawable; import com.android.launcher3.model.PackageItemInfo; import com.android.launcher3.popup.PopupContainerWithArrow; @@ -90,6 +95,28 @@ public class BubbleTextView extends TextView implements ItemInfoUpdateReceiver { @ViewDebug.ExportedProperty(category = "launcher") private int mTextColor; + private BadgeInfo mBadgeInfo; + private BadgeRenderer mBadgeRenderer; + private IconPalette mIconPalette; + private float mBadgeScale; + private boolean mForceHideBadge; + private Point mTempSpaceForBadgeOffset = new Point(); + private Rect mTempIconBounds = new Rect(); + + private static final Property<BubbleTextView, Float> BADGE_SCALE_PROPERTY + = new Property<BubbleTextView, Float>(Float.TYPE, "badgeScale") { + @Override + public Float get(BubbleTextView bubbleTextView) { + return bubbleTextView.mBadgeScale; + } + + @Override + public void set(BubbleTextView bubbleTextView, Float value) { + bubbleTextView.mBadgeScale = value; + bubbleTextView.invalidate(); + } + }; + @ViewDebug.ExportedProperty(category = "launcher") private boolean mStayPressed; @ViewDebug.ExportedProperty(category = "launcher") @@ -373,6 +400,7 @@ public class BubbleTextView extends TextView implements ItemInfoUpdateReceiver { public void draw(Canvas canvas) { if (!mCustomShadowsEnabled) { super.draw(canvas); + drawBadgeIfNecessary(canvas); return; } @@ -399,6 +427,7 @@ public class BubbleTextView extends TextView implements ItemInfoUpdateReceiver { if ((getCurrentTextColor() >> 24) == 0) { getPaint().clearShadowLayer(); super.draw(canvas); + drawBadgeIfNecessary(canvas); return; } @@ -414,6 +443,50 @@ public class BubbleTextView extends TextView implements ItemInfoUpdateReceiver { density * KEY_SHADOW_RADIUS, 0.0f, density * KEY_SHADOW_OFFSET, KEY_SHADOW_COLOR); super.draw(canvas); canvas.restore(); + + drawBadgeIfNecessary(canvas); + } + + /** + * Draws the icon badge in the top right corner of the icon bounds. + * @param canvas The canvas to draw to. + */ + private void drawBadgeIfNecessary(Canvas canvas) { + if (!mForceHideBadge && (hasBadge() || mBadgeScale > 0)) { + getIconBounds(mTempIconBounds); + mTempSpaceForBadgeOffset.set((getWidth() - mIconSize) / 2, getPaddingTop()); + final int scrollX = getScrollX(); + final int scrollY = getScrollY(); + canvas.translate(scrollX, scrollY); + mBadgeRenderer.draw(canvas, mIconPalette, mBadgeInfo, mTempIconBounds, mBadgeScale, + mTempSpaceForBadgeOffset); + canvas.translate(-scrollX, -scrollY); + } + } + + public void forceHideBadge(boolean forceHideBadge) { + if (mForceHideBadge == forceHideBadge) { + return; + } + mForceHideBadge = forceHideBadge; + + if (forceHideBadge) { + invalidate(); + } else if (hasBadge()) { + ObjectAnimator.ofFloat(this, BADGE_SCALE_PROPERTY, 0, 1).start(); + } + } + + private boolean hasBadge() { + return (mBadgeInfo != null && mBadgeInfo.getNotificationCount() > 0); + } + + public void getIconBounds(Rect outBounds) { + int top = getPaddingTop(); + int left = (getWidth() - mIconSize) / 2; + int right = left + mIconSize; + int bottom = top + mIconSize; + outBounds.set(left, top, right, bottom); } @Override @@ -519,7 +592,22 @@ public class BubbleTextView extends TextView implements ItemInfoUpdateReceiver { if (popup != null) { popup.updateNotificationHeader(badgeInfo, itemInfo); } - ((FastBitmapDrawable) mIcon).applyIconBadge(badgeInfo, badgeRenderer, animate); + + boolean wasBadged = mBadgeInfo != null; + boolean isBadged = badgeInfo != null; + float newBadgeScale = isBadged ? 1f : 0; + mBadgeInfo = badgeInfo; + mBadgeRenderer = badgeRenderer; + if (wasBadged || isBadged) { + mIconPalette = ((FastBitmapDrawable) mIcon).getIconPalette(); + // Animate when a badge is first added or when it is removed. + if (animate && (wasBadged ^ isBadged) && isShown()) { + ObjectAnimator.ofFloat(this, BADGE_SCALE_PROPERTY, newBadgeScale).start(); + } else { + mBadgeScale = newBadgeScale; + invalidate(); + } + } } } diff --git a/src/com/android/launcher3/DeviceProfile.java b/src/com/android/launcher3/DeviceProfile.java index 43f7d2317..e47031ae8 100644 --- a/src/com/android/launcher3/DeviceProfile.java +++ b/src/com/android/launcher3/DeviceProfile.java @@ -197,8 +197,6 @@ public class DeviceProfile { hotseatBarBottomPaddingPx = 0; hotseatLandGutterPx = res.getDimensionPixelSize(R.dimen.dynamic_grid_hotseat_gutter_width); - mBadgeRenderer = new BadgeRenderer(context); - // Determine sizes. widthPx = width; heightPx = height; @@ -213,6 +211,9 @@ public class DeviceProfile { // Calculate the remaining vars updateAvailableDimensions(dm, res); computeAllAppsButtonSize(context); + + // This is done last, after iconSizePx is calculated above. + mBadgeRenderer = new BadgeRenderer(context, iconSizePx); } DeviceProfile getMultiWindowProfile(Context context, Point mwSize) { diff --git a/src/com/android/launcher3/FastBitmapDrawable.java b/src/com/android/launcher3/FastBitmapDrawable.java index be3ba9014..a096a1ddf 100644 --- a/src/com/android/launcher3/FastBitmapDrawable.java +++ b/src/com/android/launcher3/FastBitmapDrawable.java @@ -32,8 +32,6 @@ import android.graphics.drawable.Drawable; import android.util.Property; import android.util.SparseArray; -import com.android.launcher3.badge.BadgeInfo; -import com.android.launcher3.badge.BadgeRenderer; import com.android.launcher3.graphics.IconPalette; public class FastBitmapDrawable extends Drawable { @@ -77,24 +75,7 @@ public class FastBitmapDrawable extends Drawable { private boolean mIsPressed; private boolean mIsDisabled; - private BadgeInfo mBadgeInfo; - private BadgeRenderer mBadgeRenderer; private IconPalette mIconPalette; - private float mBadgeScale; - - private static final Property<FastBitmapDrawable, Float> BADGE_SCALE_PROPERTY - = new Property<FastBitmapDrawable, Float>(Float.TYPE, "badgeScale") { - @Override - public Float get(FastBitmapDrawable fastBitmapDrawable) { - return fastBitmapDrawable.mBadgeScale; - } - - @Override - public void set(FastBitmapDrawable fastBitmapDrawable, Float value) { - fastBitmapDrawable.mBadgeScale = value; - fastBitmapDrawable.invalidateSelf(); - } - }; private static final Property<FastBitmapDrawable, Float> BRIGHTNESS = new Property<FastBitmapDrawable, Float>(Float.TYPE, "brightness") { @@ -124,30 +105,9 @@ public class FastBitmapDrawable extends Drawable { setFilterBitmap(true); } - public void applyIconBadge(final BadgeInfo badgeInfo, BadgeRenderer badgeRenderer, - boolean animate) { - boolean wasBadged = mBadgeInfo != null; - boolean isBadged = badgeInfo != null; - float newBadgeScale = isBadged ? 1f : 0; - mBadgeInfo = badgeInfo; - mBadgeRenderer = badgeRenderer; - if (wasBadged || isBadged) { - mIconPalette = getIconPalette(); - // Animate when a badge is first added or when it is removed. - if (animate && (wasBadged ^ isBadged) && isVisible()) { - ObjectAnimator.ofFloat(this, BADGE_SCALE_PROPERTY, newBadgeScale).start(); - } else { - mBadgeScale = newBadgeScale; - invalidateSelf(); - } - } - } - @Override public void draw(Canvas canvas) { drawInternal(canvas); - // Draw the icon badge in the top right corner. - drawBadgeIfNecessary(canvas); } public void drawWithBrightness(Canvas canvas, float brightness) { @@ -161,12 +121,6 @@ public class FastBitmapDrawable extends Drawable { canvas.drawBitmap(mBitmap, null, getBounds(), mPaint); } - protected void drawBadgeIfNecessary(Canvas canvas) { - if (hasBadge()) { - mBadgeRenderer.draw(canvas, mIconPalette, mBadgeInfo, getBounds(), mBadgeScale); - } - } - public IconPalette getIconPalette() { if (mIconPalette == null) { mIconPalette = IconPalette.fromDominantColor(Utilities @@ -175,10 +129,6 @@ public class FastBitmapDrawable extends Drawable { return mIconPalette; } - private boolean hasBadge() { - return (mBadgeInfo != null && mBadgeInfo.getNotificationCount() > 0) || mBadgeScale > 0; - } - @Override public void setColorFilter(ColorFilter cf) { // No op diff --git a/src/com/android/launcher3/Workspace.java b/src/com/android/launcher3/Workspace.java index 8f8d32ccc..dd2daca57 100644 --- a/src/com/android/launcher3/Workspace.java +++ b/src/com/android/launcher3/Workspace.java @@ -2245,16 +2245,12 @@ public class Workspace extends PagedView Point dragVisualizeOffset = null; Rect dragRect = null; if (child instanceof BubbleTextView) { - int iconSize = grid.iconSizePx; - int top = child.getPaddingTop(); - int left = (b.getWidth() - iconSize) / 2; - int right = left + iconSize; - int bottom = top + iconSize; - dragLayerY += top; - // Note: The drag region is used to calculate drag layer offsets, but the + dragRect = new Rect(); + ((BubbleTextView) child).getIconBounds(dragRect); + dragLayerY += dragRect.top; + // Note: The dragRect is used to calculate drag layer offsets, but the // dragVisualizeOffset in addition to the dragRect (the size) to position the outline. dragVisualizeOffset = new Point(- halfPadding, halfPadding); - dragRect = new Rect(left, top, right, bottom); } else if (child instanceof FolderIcon) { int previewSize = grid.folderIconSizePx; dragVisualizeOffset = new Point(- halfPadding, halfPadding - child.getPaddingTop()); diff --git a/src/com/android/launcher3/badge/BadgeRenderer.java b/src/com/android/launcher3/badge/BadgeRenderer.java index 58969289e..a1ef22f4e 100644 --- a/src/com/android/launcher3/badge/BadgeRenderer.java +++ b/src/com/android/launcher3/badge/BadgeRenderer.java @@ -22,9 +22,11 @@ import android.graphics.Bitmap; import android.graphics.Canvas; import android.graphics.Color; import android.graphics.Paint; +import android.graphics.Point; import android.graphics.Rect; import android.graphics.Shader; import android.support.annotation.Nullable; +import android.util.SparseArray; import com.android.launcher3.R; import com.android.launcher3.graphics.IconPalette; @@ -36,31 +38,41 @@ import com.android.launcher3.graphics.ShadowGenerator; */ public class BadgeRenderer { + // The badge sizes are defined as percentages of the app icon size. + private static final float SIZE_PERCENTAGE = 0.38f; + // Used to expand the width of the badge for each additional digit. + private static final float CHAR_SIZE_PERCENTAGE = 0.12f; + private static final float TEXT_SIZE_PERCENTAGE = 0.26f; + private static final float OFFSET_PERCENTAGE = 0.02f; + private final Context mContext; private final int mSize; + private final int mCharSize; private final int mTextHeight; + private final int mOffset; private final IconDrawer mLargeIconDrawer; private final IconDrawer mSmallIconDrawer; private final Paint mTextPaint = new Paint(Paint.ANTI_ALIAS_FLAG); private final Paint mBackgroundPaint = new Paint(Paint.ANTI_ALIAS_FLAG | Paint.FILTER_BITMAP_FLAG); - private final Bitmap mBackgroundWithShadow; + private final SparseArray<Bitmap> mBackgroundsWithShadow; - public BadgeRenderer(final Context context) { + public BadgeRenderer(Context context, int iconSizePx) { mContext = context; Resources res = context.getResources(); - mSize = res.getDimensionPixelSize(R.dimen.badge_size); + mSize = (int) (SIZE_PERCENTAGE * iconSizePx); + mCharSize = (int) (CHAR_SIZE_PERCENTAGE * iconSizePx); + mOffset = (int) (OFFSET_PERCENTAGE * iconSizePx); + mTextPaint.setTextSize(iconSizePx * TEXT_SIZE_PERCENTAGE); + mTextPaint.setTextAlign(Paint.Align.CENTER); mLargeIconDrawer = new IconDrawer(res.getDimensionPixelSize(R.dimen.badge_small_padding)); mSmallIconDrawer = new IconDrawer(res.getDimensionPixelSize(R.dimen.badge_large_padding)); - mTextPaint.setTextAlign(Paint.Align.CENTER); - mTextPaint.setTextSize(res.getDimensionPixelSize(R.dimen.badge_text_size)); - mTextPaint.setFakeBoldText(true); // Measure the text height. Rect tempTextHeight = new Rect(); mTextPaint.getTextBounds("0", 0, 1, tempTextHeight); mTextHeight = tempTextHeight.height(); - mBackgroundWithShadow = ShadowGenerator.createCircleWithShadow(Color.WHITE, mSize); + mBackgroundsWithShadow = new SparseArray<>(3); } /** @@ -70,29 +82,43 @@ public class BadgeRenderer { * @param badgeInfo Contains data to draw on the badge. Could be null if we are animating out. * @param iconBounds The bounds of the icon being badged. * @param badgeScale The progress of the animation, from 0 to 1. + * @param spaceForOffset How much space is available to offset the badge up and to the right. */ public void draw(Canvas canvas, IconPalette palette, @Nullable BadgeInfo badgeInfo, - Rect iconBounds, float badgeScale) { + Rect iconBounds, float badgeScale, Point spaceForOffset) { mTextPaint.setColor(palette.textColor); - canvas.save(Canvas.MATRIX_SAVE_FLAG); - // We draw the badge relative to its center. - canvas.translate(iconBounds.right - mSize / 2, iconBounds.top + mSize / 2); - canvas.scale(badgeScale, badgeScale); - mBackgroundPaint.setColorFilter(palette.backgroundColorMatrixFilter); - int backgroundSize = mBackgroundWithShadow.getHeight(); // Same as width. - canvas.drawBitmap(mBackgroundWithShadow, -backgroundSize / 2, -backgroundSize / 2, - mBackgroundPaint); IconDrawer iconDrawer = badgeInfo != null && badgeInfo.isIconLarge() ? mLargeIconDrawer : mSmallIconDrawer; Shader icon = badgeInfo == null ? null : badgeInfo.getNotificationIconForBadge( mContext, palette.backgroundColor, mSize, iconDrawer.mPadding); + String notificationCount = icon != null || badgeInfo == null ? "0" + : String.valueOf(badgeInfo.getNotificationCount()); + int numChars = notificationCount.length(); + int width = mSize + mCharSize * (numChars - 1); + // Lazily load the background with shadow. + Bitmap backgroundWithShadow = mBackgroundsWithShadow.get(numChars); + if (backgroundWithShadow == null) { + backgroundWithShadow = ShadowGenerator.createPillWithShadow(Color.WHITE, width, mSize); + mBackgroundsWithShadow.put(numChars, backgroundWithShadow); + } + canvas.save(Canvas.MATRIX_SAVE_FLAG); + // We draw the badge relative to its center. + int badgeCenterX = iconBounds.right - width / 2; + int badgeCenterY = iconBounds.top + mSize / 2; + int offsetX = Math.min(mOffset, spaceForOffset.x); + int offsetY = Math.min(mOffset, spaceForOffset.y); + canvas.translate(badgeCenterX + offsetX, badgeCenterY - offsetY); + canvas.scale(badgeScale, badgeScale); + // Draw the background and shadow. + mBackgroundPaint.setColorFilter(palette.backgroundColorMatrixFilter); + int backgroundWithShadowSize = backgroundWithShadow.getHeight(); // Same as width. + canvas.drawBitmap(backgroundWithShadow, -backgroundWithShadowSize / 2, + -backgroundWithShadowSize / 2, mBackgroundPaint); if (icon != null) { // Draw the notification icon with padding. iconDrawer.drawIcon(icon, canvas); } else { // Draw the notification count. - String notificationCount = badgeInfo == null ? "0" - : String.valueOf(badgeInfo.getNotificationCount()); canvas.drawText(notificationCount, 0, mTextHeight / 2, mTextPaint); } canvas.restore(); diff --git a/src/com/android/launcher3/folder/FolderIcon.java b/src/com/android/launcher3/folder/FolderIcon.java index ced9c9e8d..6f10d8419 100644 --- a/src/com/android/launcher3/folder/FolderIcon.java +++ b/src/com/android/launcher3/folder/FolderIcon.java @@ -27,6 +27,7 @@ import android.graphics.Color; import android.graphics.Matrix; import android.graphics.Paint; import android.graphics.Path; +import android.graphics.Point; import android.graphics.PorterDuff; import android.graphics.PorterDuffXfermode; import android.graphics.RadialGradient; @@ -121,7 +122,7 @@ public class FolderIcon extends FrameLayout implements FolderListener { private PreviewLayoutRule mPreviewLayoutRule; boolean mAnimating = false; - private Rect mOldBounds = new Rect(); + private Rect mTempBounds = new Rect(); private float mSlop; @@ -135,6 +136,7 @@ public class FolderIcon extends FrameLayout implements FolderListener { private FolderBadgeInfo mBadgeInfo = new FolderBadgeInfo(); private BadgeRenderer mBadgeRenderer; private float mBadgeScale; + private Point mTempSpaceForBadgeOffset = new Point(); private static final Property<FolderIcon, Float> BADGE_SCALE_PROPERTY = new Property<FolderIcon, Float>(Float.TYPE, "badgeScale") { @@ -503,7 +505,7 @@ public class FolderIcon extends FrameLayout implements FolderListener { Drawable d = params.drawable; if (d != null) { - mOldBounds.set(d.getBounds()); + mTempBounds.set(d.getBounds()); d.setBounds(0, 0, mIntrinsicIconSize, mIntrinsicIconSize); if (d instanceof FastBitmapDrawable) { FastBitmapDrawable fd = (FastBitmapDrawable) d; @@ -514,7 +516,7 @@ public class FolderIcon extends FrameLayout implements FolderListener { d.draw(canvas); d.clearColorFilter(); } - d.setBounds(mOldBounds); + d.setBounds(mTempBounds); } canvas.restore(); } @@ -893,14 +895,16 @@ public class FolderIcon extends FrameLayout implements FolderListener { } if ((mBadgeInfo != null && mBadgeInfo.getNotificationCount() > 0) || mBadgeScale > 0) { - // If we are animating to the accepting state, animate the badge out. int offsetX = mBackground.getOffsetX(); int offsetY = mBackground.getOffsetY(); int previewSize = (int) (mBackground.previewSize * mBackground.mScale); - Rect bounds = new Rect(offsetX, offsetY, offsetX + previewSize, offsetY + previewSize); + mTempBounds.set(offsetX, offsetY, offsetX + previewSize, offsetY + previewSize); + // If we are animating to the accepting state, animate the badge out. float badgeScale = Math.max(0, mBadgeScale - mBackground.getScaleProgress()); - mBadgeRenderer.draw(canvas, IconPalette.FOLDER_ICON_PALETTE, mBadgeInfo, bounds, badgeScale); + mTempSpaceForBadgeOffset.set(getWidth() - mTempBounds.right, mTempBounds.top); + mBadgeRenderer.draw(canvas, IconPalette.FOLDER_ICON_PALETTE, mBadgeInfo, mTempBounds, + badgeScale, mTempSpaceForBadgeOffset); } } diff --git a/src/com/android/launcher3/graphics/IconPalette.java b/src/com/android/launcher3/graphics/IconPalette.java index cd7cf702e..c45f48190 100644 --- a/src/com/android/launcher3/graphics/IconPalette.java +++ b/src/com/android/launcher3/graphics/IconPalette.java @@ -173,12 +173,12 @@ public class IconPalette { } private static int getMutedColor(int color) { - int alpha = (int) (255 * 0.15f); - return ColorUtils.compositeColors(ColorUtils.setAlphaComponent(color, alpha), Color.WHITE); + int whiteScrim = ColorUtils.setAlphaComponent(Color.WHITE, (int) (255 * 0.87f)); + return ColorUtils.compositeColors(whiteScrim, color); } private static int getTextColorForBackground(int backgroundColor) { - return getLighterOrDarkerVersionOfColor(backgroundColor, 3f); + return getLighterOrDarkerVersionOfColor(backgroundColor, 4.5f); } private static int getLowContrastColor(int color) { diff --git a/src/com/android/launcher3/graphics/ShadowGenerator.java b/src/com/android/launcher3/graphics/ShadowGenerator.java index 6c603c971..5dd8d200b 100644 --- a/src/com/android/launcher3/graphics/ShadowGenerator.java +++ b/src/com/android/launcher3/graphics/ShadowGenerator.java @@ -83,34 +83,44 @@ public class ShadowGenerator { return result; } - public static Bitmap createCircleWithShadow(int circleColor, int diameter) { + public static Bitmap createPillWithShadow(int rectColor, int width, int height) { - float shadowRadius = diameter * 1f / 32; - float shadowYOffset = diameter * 1f / 16; + float shadowRadius = height * 1f / 32; + float shadowYOffset = height * 1f / 16; + int ambientShadowAlpha = AMBIENT_SHADOW_ALPHA / 2; + int keyShadowAlpha = KEY_SHADOW_ALPHA / 2; - int radius = diameter / 2; + int radius = height / 2; Canvas canvas = new Canvas(); Paint blurPaint = new Paint(Paint.ANTI_ALIAS_FLAG | Paint.FILTER_BITMAP_FLAG); blurPaint.setMaskFilter(new BlurMaskFilter(shadowRadius, Blur.NORMAL)); - int center = Math.round(radius + shadowRadius + shadowYOffset); + int centerX = Math.round(width / 2 + shadowRadius); + int centerY = Math.round(radius + shadowRadius + shadowYOffset); + int center = Math.max(centerX, centerY); int size = center * 2; Bitmap result = Bitmap.createBitmap(size, size, Config.ARGB_8888); canvas.setBitmap(result); + int left = center - width / 2; + int top = center - height / 2; + int right = center + width / 2; + int bottom = center + height / 2; + // Draw ambient shadow, center aligned within size - blurPaint.setAlpha(AMBIENT_SHADOW_ALPHA); - canvas.drawCircle(center, center, radius, blurPaint); + blurPaint.setAlpha(ambientShadowAlpha); + canvas.drawRoundRect(left, top, right, bottom, radius, radius, blurPaint); // Draw key shadow, bottom aligned within size - blurPaint.setAlpha(KEY_SHADOW_ALPHA); - canvas.drawCircle(center, center + shadowYOffset, radius, blurPaint); + blurPaint.setAlpha(keyShadowAlpha); + canvas.drawRoundRect(left, top + shadowYOffset, right, bottom + shadowYOffset, + radius, radius, blurPaint); // Draw the circle Paint drawPaint = new Paint(Paint.ANTI_ALIAS_FLAG | Paint.FILTER_BITMAP_FLAG); - drawPaint.setColor(circleColor); - canvas.drawCircle(center, center, radius, drawPaint); + drawPaint.setColor(rectColor); + canvas.drawRoundRect(left, top, right, bottom, radius, radius, drawPaint); return result; } diff --git a/src/com/android/launcher3/popup/PopupContainerWithArrow.java b/src/com/android/launcher3/popup/PopupContainerWithArrow.java index a4823ae3e..ee64ef9e1 100644 --- a/src/com/android/launcher3/popup/PopupContainerWithArrow.java +++ b/src/com/android/launcher3/popup/PopupContainerWithArrow.java @@ -213,8 +213,8 @@ public class PopupContainerWithArrow extends AbstractFloatingView implements Dra animateOpen(); mOriginalIcon = originalIcon; - mLauncher.getDragController().addDragListener(this); + mOriginalIcon.forceHideBadge(true); // Load the shortcuts on a background thread and update the container as it animates. final Looper workerLooper = LauncherModel.getWorkerLooper(); @@ -799,6 +799,7 @@ public class PopupContainerWithArrow extends AbstractFloatingView implements Dra }); mOpenCloseAnimator = shortcutAnims; shortcutAnims.start(); + mOriginalIcon.forceHideBadge(false); } /** @@ -814,6 +815,7 @@ public class PopupContainerWithArrow extends AbstractFloatingView implements Dra boolean isInHotseat = ((ItemInfo) mOriginalIcon.getTag()).container == LauncherSettings.Favorites.CONTAINER_HOTSEAT; mOriginalIcon.setTextVisibility(!isInHotseat); + mOriginalIcon.forceHideBadge(false); mLauncher.getDragController().removeDragListener(this); mLauncher.getDragLayer().removeView(this); } |