Merge "Fade in badges on top of icons after swipe up animation." into ub-launcher3-qt-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
746aefe4fb
@@ -17,6 +17,7 @@
|
||||
package com.android.launcher3;
|
||||
|
||||
import android.animation.ValueAnimator;
|
||||
import android.annotation.TargetApi;
|
||||
import android.app.ActivityManager;
|
||||
import android.app.WallpaperManager;
|
||||
import android.content.BroadcastReceiver;
|
||||
@@ -32,12 +33,16 @@ import android.content.pm.PackageManager.NameNotFoundException;
|
||||
import android.content.pm.ResolveInfo;
|
||||
import android.content.pm.ShortcutInfo;
|
||||
import android.content.res.Resources;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.Color;
|
||||
import android.graphics.Matrix;
|
||||
import android.graphics.Paint;
|
||||
import android.graphics.Point;
|
||||
import android.graphics.Rect;
|
||||
import android.graphics.RectF;
|
||||
import android.graphics.drawable.ColorDrawable;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.graphics.drawable.InsetDrawable;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.os.DeadObjectException;
|
||||
@@ -62,6 +67,7 @@ import com.android.launcher3.compat.ShortcutConfigActivityInfo;
|
||||
import com.android.launcher3.config.FeatureFlags;
|
||||
import com.android.launcher3.dragndrop.FolderAdaptiveIcon;
|
||||
import com.android.launcher3.graphics.RotationMode;
|
||||
import com.android.launcher3.icons.LauncherIcons;
|
||||
import com.android.launcher3.shortcuts.DeepShortcutManager;
|
||||
import com.android.launcher3.shortcuts.ShortcutKey;
|
||||
import com.android.launcher3.util.IntArray;
|
||||
@@ -82,6 +88,8 @@ import java.util.concurrent.TimeUnit;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import static com.android.launcher3.ItemInfoWithIcon.FLAG_ICON_BADGED;
|
||||
|
||||
/**
|
||||
* Various utilities shared amongst the Launcher's classes.
|
||||
*/
|
||||
@@ -654,6 +662,40 @@ public final class Utilities {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* For apps icons and shortcut icons that have badges, this method creates a drawable that can
|
||||
* later on be rendered on top of the layers for the badges. For app icons, work profile badges
|
||||
* can only be applied. For deep shortcuts, when dragged from the pop up container, there's no
|
||||
* badge. When dragged from workspace or folder, it may contain app AND/OR work profile badge
|
||||
**/
|
||||
@TargetApi(Build.VERSION_CODES.O)
|
||||
public static Drawable getBadge(Launcher launcher, ItemInfo info, Object obj) {
|
||||
LauncherAppState appState = LauncherAppState.getInstance(launcher);
|
||||
int iconSize = appState.getInvariantDeviceProfile().iconBitmapSize;
|
||||
if (info.itemType == LauncherSettings.Favorites.ITEM_TYPE_DEEP_SHORTCUT) {
|
||||
boolean iconBadged = (info instanceof ItemInfoWithIcon)
|
||||
&& (((ItemInfoWithIcon) info).runtimeStatusFlags & FLAG_ICON_BADGED) > 0;
|
||||
if ((info.id == ItemInfo.NO_ID && !iconBadged)
|
||||
|| !(obj instanceof ShortcutInfo)) {
|
||||
// The item is not yet added on home screen.
|
||||
return new FixedSizeEmptyDrawable(iconSize);
|
||||
}
|
||||
ShortcutInfo si = (ShortcutInfo) obj;
|
||||
LauncherIcons li = LauncherIcons.obtain(appState.getContext());
|
||||
Bitmap badge = li.getShortcutInfoBadge(si, appState.getIconCache()).iconBitmap;
|
||||
li.recycle();
|
||||
float badgeSize = launcher.getResources().getDimension(R.dimen.profile_badge_size);
|
||||
float insetFraction = (iconSize - badgeSize) / iconSize;
|
||||
return new InsetDrawable(new FastBitmapDrawable(badge),
|
||||
insetFraction, insetFraction, 0, 0);
|
||||
} else if (info.itemType == LauncherSettings.Favorites.ITEM_TYPE_FOLDER) {
|
||||
return ((FolderAdaptiveIcon) obj).getBadge();
|
||||
} else {
|
||||
return launcher.getPackageManager()
|
||||
.getUserBadgedIcon(new FixedSizeEmptyDrawable(iconSize), info.user);
|
||||
}
|
||||
}
|
||||
|
||||
public static int[] getIntArrayFromString(String tokenized) {
|
||||
StringTokenizer tokenizer = new StringTokenizer(tokenized, ",");
|
||||
int[] array = new int[tokenizer.countTokens()];
|
||||
@@ -672,4 +714,24 @@ public final class Utilities {
|
||||
}
|
||||
return str.toString();
|
||||
}
|
||||
|
||||
private static class FixedSizeEmptyDrawable extends ColorDrawable {
|
||||
|
||||
private final int mSize;
|
||||
|
||||
public FixedSizeEmptyDrawable(int size) {
|
||||
super(Color.TRANSPARENT);
|
||||
mSize = size;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getIntrinsicHeight() {
|
||||
return mSize;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getIntrinsicWidth() {
|
||||
return mSize;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
|
||||
package com.android.launcher3.dragndrop;
|
||||
|
||||
import static com.android.launcher3.ItemInfoWithIcon.FLAG_ICON_BADGED;
|
||||
import static com.android.launcher3.Utilities.getBadge;
|
||||
|
||||
import android.animation.Animator;
|
||||
import android.animation.AnimatorListenerAdapter;
|
||||
@@ -24,7 +24,6 @@ import android.animation.FloatArrayEvaluator;
|
||||
import android.animation.ValueAnimator;
|
||||
import android.animation.ValueAnimator.AnimatorUpdateListener;
|
||||
import android.annotation.TargetApi;
|
||||
import android.content.pm.ShortcutInfo;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.Canvas;
|
||||
import android.graphics.Color;
|
||||
@@ -37,7 +36,6 @@ import android.graphics.Rect;
|
||||
import android.graphics.drawable.AdaptiveIconDrawable;
|
||||
import android.graphics.drawable.ColorDrawable;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.graphics.drawable.InsetDrawable;
|
||||
import android.os.Build;
|
||||
import android.os.Handler;
|
||||
import android.os.Looper;
|
||||
@@ -45,9 +43,7 @@ import android.view.View;
|
||||
|
||||
import com.android.launcher3.FastBitmapDrawable;
|
||||
import com.android.launcher3.ItemInfo;
|
||||
import com.android.launcher3.ItemInfoWithIcon;
|
||||
import com.android.launcher3.Launcher;
|
||||
import com.android.launcher3.LauncherAppState;
|
||||
import com.android.launcher3.LauncherModel;
|
||||
import com.android.launcher3.LauncherSettings;
|
||||
import com.android.launcher3.R;
|
||||
@@ -195,7 +191,6 @@ public class DragView extends View {
|
||||
new Handler(workerLooper).postAtFrontOfQueue(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
LauncherAppState appState = LauncherAppState.getInstance(mLauncher);
|
||||
Object[] outObj = new Object[1];
|
||||
int w = mBitmap.getWidth();
|
||||
int h = mBitmap.getHeight();
|
||||
@@ -211,7 +206,7 @@ public class DragView extends View {
|
||||
// Badge is applied after icon normalization so the bounds for badge should not
|
||||
// be scaled down due to icon normalization.
|
||||
Rect badgeBounds = new Rect(bounds);
|
||||
mBadge = getBadge(info, appState, outObj[0]);
|
||||
mBadge = getBadge(mLauncher, info, outObj[0]);
|
||||
mBadge.setBounds(badgeBounds);
|
||||
|
||||
// Do not draw the background in case of folder as its translucent
|
||||
@@ -307,40 +302,6 @@ public class DragView extends View {
|
||||
invalidate();
|
||||
}
|
||||
|
||||
/**
|
||||
* For apps icons and shortcut icons that have badges, this method creates a drawable that can
|
||||
* later on be rendered on top of the layers for the badges. For app icons, work profile badges
|
||||
* can only be applied. For deep shortcuts, when dragged from the pop up container, there's no
|
||||
* badge. When dragged from workspace or folder, it may contain app AND/OR work profile badge
|
||||
**/
|
||||
|
||||
@TargetApi(Build.VERSION_CODES.O)
|
||||
private Drawable getBadge(ItemInfo info, LauncherAppState appState, Object obj) {
|
||||
int iconSize = appState.getInvariantDeviceProfile().iconBitmapSize;
|
||||
if (info.itemType == LauncherSettings.Favorites.ITEM_TYPE_DEEP_SHORTCUT) {
|
||||
boolean iconBadged = (info instanceof ItemInfoWithIcon)
|
||||
&& (((ItemInfoWithIcon) info).runtimeStatusFlags & FLAG_ICON_BADGED) > 0;
|
||||
if ((info.id == ItemInfo.NO_ID && !iconBadged)
|
||||
|| !(obj instanceof ShortcutInfo)) {
|
||||
// The item is not yet added on home screen.
|
||||
return new FixedSizeEmptyDrawable(iconSize);
|
||||
}
|
||||
ShortcutInfo si = (ShortcutInfo) obj;
|
||||
LauncherIcons li = LauncherIcons.obtain(appState.getContext());
|
||||
Bitmap badge = li.getShortcutInfoBadge(si, appState.getIconCache()).iconBitmap;
|
||||
li.recycle();
|
||||
float badgeSize = mLauncher.getResources().getDimension(R.dimen.profile_badge_size);
|
||||
float insetFraction = (iconSize - badgeSize) / iconSize;
|
||||
return new InsetDrawable(new FastBitmapDrawable(badge),
|
||||
insetFraction, insetFraction, 0, 0);
|
||||
} else if (info.itemType == LauncherSettings.Favorites.ITEM_TYPE_FOLDER) {
|
||||
return ((FolderAdaptiveIcon) obj).getBadge();
|
||||
} else {
|
||||
return mLauncher.getPackageManager()
|
||||
.getUserBadgedIcon(new FixedSizeEmptyDrawable(iconSize), info.user);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
|
||||
setMeasuredDimension(mBitmap.getWidth(), mBitmap.getHeight());
|
||||
@@ -626,24 +587,4 @@ public class DragView extends View {
|
||||
mSpring.animateToFinalPosition(Utilities.boundToRange(value, -mDelta, mDelta));
|
||||
}
|
||||
}
|
||||
|
||||
private static class FixedSizeEmptyDrawable extends ColorDrawable {
|
||||
|
||||
private final int mSize;
|
||||
|
||||
public FixedSizeEmptyDrawable(int size) {
|
||||
super(Color.TRANSPARENT);
|
||||
mSize = size;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getIntrinsicHeight() {
|
||||
return mSize;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getIntrinsicWidth() {
|
||||
return mSize;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,6 +15,8 @@
|
||||
*/
|
||||
package com.android.launcher3.views;
|
||||
|
||||
import static com.android.launcher3.LauncherAnimUtils.DRAWABLE_ALPHA;
|
||||
import static com.android.launcher3.Utilities.getBadge;
|
||||
import static com.android.launcher3.Utilities.mapToRange;
|
||||
import static com.android.launcher3.anim.Interpolators.LINEAR;
|
||||
import static com.android.launcher3.config.FeatureFlags.ADAPTIVE_ICON_WINDOW_ANIM;
|
||||
@@ -121,6 +123,7 @@ public class FloatingIconView extends View implements
|
||||
private boolean mIsVerticalBarLayout = false;
|
||||
private boolean mIsAdaptiveIcon = false;
|
||||
|
||||
private @Nullable Drawable mBadge;
|
||||
private @Nullable Drawable mForeground;
|
||||
private @Nullable Drawable mBackground;
|
||||
private float mRotation;
|
||||
@@ -362,7 +365,9 @@ public class FloatingIconView extends View implements
|
||||
if (supportsAdaptiveIcons) {
|
||||
drawable = Utilities.getFullDrawable(mLauncher, info, lp.width, lp.height,
|
||||
false, sTmpObjArray);
|
||||
if (!(drawable instanceof AdaptiveIconDrawable)) {
|
||||
if ((drawable instanceof AdaptiveIconDrawable)) {
|
||||
mBadge = getBadge(mLauncher, info, sTmpObjArray[0]);
|
||||
} else {
|
||||
// The drawable we get back is not an adaptive icon, so we need to use the
|
||||
// BubbleTextView icon that is already legacy treated.
|
||||
drawable = btvIcon;
|
||||
@@ -421,6 +426,14 @@ public class FloatingIconView extends View implements
|
||||
|
||||
mStartRevealRect.set(0, 0, originalWidth, originalHeight);
|
||||
|
||||
if (mBadge != null) {
|
||||
mBadge.setBounds(mStartRevealRect);
|
||||
if (!isOpening) {
|
||||
DRAWABLE_ALPHA.set(mBadge, 0);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (!isFolderIcon) {
|
||||
mStartRevealRect.inset(mBlurSizeOutline, mBlurSizeOutline);
|
||||
}
|
||||
@@ -524,6 +537,9 @@ public class FloatingIconView extends View implements
|
||||
mForeground.draw(canvas);
|
||||
canvas.restoreToCount(count2);
|
||||
}
|
||||
if (mBadge != null) {
|
||||
mBadge.draw(canvas);
|
||||
}
|
||||
canvas.restoreToCount(count);
|
||||
}
|
||||
|
||||
@@ -642,6 +658,12 @@ public class FloatingIconView extends View implements
|
||||
}
|
||||
});
|
||||
|
||||
if (mBadge != null) {
|
||||
ObjectAnimator badgeFade = ObjectAnimator.ofInt(mBadge, DRAWABLE_ALPHA, 255);
|
||||
badgeFade.addUpdateListener(valueAnimator -> invalidate());
|
||||
fade.play(badgeFade);
|
||||
}
|
||||
|
||||
if (originalView instanceof BubbleTextView) {
|
||||
BubbleTextView btv = (BubbleTextView) originalView;
|
||||
btv.forceHideDot(true);
|
||||
@@ -716,5 +738,6 @@ public class FloatingIconView extends View implements
|
||||
mFgSpringX.cancel();
|
||||
mFgTransX = 0;
|
||||
mFgSpringY.cancel();
|
||||
mBadge = null;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user