use of com.android.launcher3.dragndrop.FolderAdaptiveIcon in project android_packages_apps_Launcher3 by crdroidandroid.
the class DragView method setItemInfo.
/**
* Initialize {@code #mIconDrawable} if the item can be represented using
* an {@link AdaptiveIconDrawable} or {@link FolderAdaptiveIcon}.
*/
@TargetApi(Build.VERSION_CODES.O)
public void setItemInfo(final ItemInfo info) {
if (info.itemType != LauncherSettings.Favorites.ITEM_TYPE_APPLICATION && info.itemType != LauncherSettings.Favorites.ITEM_TYPE_DEEP_SHORTCUT && info.itemType != LauncherSettings.Favorites.ITEM_TYPE_FOLDER) {
return;
}
// Load the adaptive icon on a background thread and add the view in ui thread.
MODEL_EXECUTOR.getHandler().postAtFrontOfQueue(() -> {
Object[] outObj = new Object[1];
int w = mWidth;
int h = mHeight;
Drawable dr = Utilities.getFullDrawable(mLauncher, info, w, h, outObj);
if (dr instanceof AdaptiveIconDrawable) {
int blurMargin = (int) mLauncher.getResources().getDimension(R.dimen.blur_size_medium_outline) / 2;
Rect bounds = new Rect(0, 0, w, h);
bounds.inset(blurMargin, blurMargin);
// 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(mLauncher, info, outObj[0]);
mBadge.setBounds(badgeBounds);
// Do not draw the background in case of folder as its translucent
final boolean shouldDrawBackground = !(dr instanceof FolderAdaptiveIcon);
try (LauncherIcons li = LauncherIcons.obtain(mLauncher)) {
// drawable to be normalized
Drawable nDr;
if (shouldDrawBackground) {
nDr = dr;
} else {
// Since we just want the scale, avoid heavy drawing operations
nDr = new AdaptiveIconDrawable(new ColorDrawable(Color.BLACK), null);
}
Utilities.scaleRectAboutCenter(bounds, li.getNormalizer().getScale(nDr, null, null, null));
}
AdaptiveIconDrawable adaptiveIcon = (AdaptiveIconDrawable) dr;
// Shrink very tiny bit so that the clip path is smaller than the original bitmap
// that has anti aliased edges and shadows.
Rect shrunkBounds = new Rect(bounds);
Utilities.scaleRectAboutCenter(shrunkBounds, 0.98f);
adaptiveIcon.setBounds(shrunkBounds);
final Path mask = adaptiveIcon.getIconMask();
mTranslateX = new SpringFloatValue(DragView.this, w * AdaptiveIconDrawable.getExtraInsetFraction());
mTranslateY = new SpringFloatValue(DragView.this, h * AdaptiveIconDrawable.getExtraInsetFraction());
bounds.inset((int) (-bounds.width() * AdaptiveIconDrawable.getExtraInsetFraction()), (int) (-bounds.height() * AdaptiveIconDrawable.getExtraInsetFraction()));
mBgSpringDrawable = adaptiveIcon.getBackground();
if (mBgSpringDrawable == null) {
mBgSpringDrawable = new ColorDrawable(Color.TRANSPARENT);
}
mBgSpringDrawable.setBounds(bounds);
mFgSpringDrawable = adaptiveIcon.getForeground();
if (mFgSpringDrawable == null) {
mFgSpringDrawable = new ColorDrawable(Color.TRANSPARENT);
}
mFgSpringDrawable.setBounds(bounds);
new Handler(Looper.getMainLooper()).post(() -> mOnDragStartCallback.add(() -> {
// TODO: Consider fade-in animation
// Assign the variable on the UI thread to avoid race conditions.
mScaledMaskPath = mask;
// Avoid relayout as we do not care about children affecting layout
removeAllViewsInLayout();
if (info.isDisabled()) {
FastBitmapDrawable d = new FastBitmapDrawable((Bitmap) null);
d.setIsDisabled(true);
mBgSpringDrawable.setColorFilter(d.getColorFilter());
mFgSpringDrawable.setColorFilter(d.getColorFilter());
mBadge.setColorFilter(d.getColorFilter());
}
invalidate();
}));
}
});
}
use of com.android.launcher3.dragndrop.FolderAdaptiveIcon in project android_packages_apps_Launcher3 by crdroidandroid.
the class Utilities method getBadge.
/**
* 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;
Bitmap badge = LauncherAppState.getInstance(appState.getContext()).getIconCache().getShortcutInfoBadge(si).icon;
float badgeSize = LauncherIcons.getBadgeSizeForIconSize(iconSize);
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);
}
}
use of com.android.launcher3.dragndrop.FolderAdaptiveIcon in project android_packages_apps_Launcher3 by crdroidandroid.
the class ClipIconView method setIcon.
/**
* Sets the icon for this view as part of initial setup
*/
public void setIcon(@Nullable Drawable drawable, int iconOffset, MarginLayoutParams lp, boolean isOpening, boolean isVerticalBarLayout, DeviceProfile dp) {
mIsAdaptiveIcon = drawable instanceof AdaptiveIconDrawable;
if (mIsAdaptiveIcon) {
boolean isFolderIcon = drawable instanceof FolderAdaptiveIcon;
AdaptiveIconDrawable adaptiveIcon = (AdaptiveIconDrawable) drawable;
Drawable background = adaptiveIcon.getBackground();
if (background == null) {
background = new ColorDrawable(Color.TRANSPARENT);
}
mBackground = background;
Drawable foreground = adaptiveIcon.getForeground();
if (foreground == null) {
foreground = new ColorDrawable(Color.TRANSPARENT);
}
mForeground = foreground;
final int originalHeight = lp.height;
final int originalWidth = lp.width;
int blurMargin = mBlurSizeOutline / 2;
mFinalDrawableBounds.set(0, 0, originalWidth, originalHeight);
if (!isFolderIcon) {
mFinalDrawableBounds.inset(iconOffset - blurMargin, iconOffset - blurMargin);
}
mForeground.setBounds(mFinalDrawableBounds);
mBackground.setBounds(mFinalDrawableBounds);
mStartRevealRect.set(0, 0, originalWidth, originalHeight);
if (!isFolderIcon) {
Utilities.scaleRectAboutCenter(mStartRevealRect, IconShape.getNormalizationScale());
}
if (isVerticalBarLayout) {
lp.width = (int) Math.max(lp.width, lp.height * dp.aspectRatio);
} else {
lp.height = (int) Math.max(lp.height, lp.width * dp.aspectRatio);
}
int left = mIsRtl ? dp.widthPx - lp.getMarginStart() - lp.width : lp.leftMargin;
layout(left, lp.topMargin, left + lp.width, lp.topMargin + lp.height);
float scale = Math.max((float) lp.height / originalHeight, (float) lp.width / originalWidth);
float bgDrawableStartScale;
if (isOpening) {
bgDrawableStartScale = 1f;
mOutline.set(0, 0, originalWidth, originalHeight);
} else {
bgDrawableStartScale = scale;
mOutline.set(0, 0, lp.width, lp.height);
}
setBackgroundDrawableBounds(bgDrawableStartScale, isVerticalBarLayout);
mEndRevealRect.set(0, 0, lp.width, lp.height);
setOutlineProvider(new ViewOutlineProvider() {
@Override
public void getOutline(View view, Outline outline) {
outline.setRoundRect(mOutline, mTaskCornerRadius);
}
});
setClipToOutline(true);
} else {
setBackground(drawable);
setClipToOutline(false);
}
invalidate();
invalidateOutline();
}
use of com.android.launcher3.dragndrop.FolderAdaptiveIcon in project android_packages_apps_Launcher3 by AOSPA.
the class Launcher method getFirstMatchForAppClose.
/**
* Similar to {@link #getFirstMatch} but optimized to finding a suitable view for the app close
* animation.
*
* @param preferredItemId The id of the preferred item to match to if it exists.
* @param packageName The package name of the app to match.
* @param user The user of the app to match.
*/
public View getFirstMatchForAppClose(int preferredItemId, String packageName, UserHandle user) {
final ItemInfoMatcher preferredItem = (info, cn) -> info != null && info.id == preferredItemId;
final ItemInfoMatcher packageAndUserAndApp = (info, cn) -> info != null && info.itemType == ITEM_TYPE_APPLICATION && info.user.equals(user) && info.getTargetComponent() != null && TextUtils.equals(info.getTargetComponent().getPackageName(), packageName);
if (isInState(LauncherState.ALL_APPS)) {
return getFirstMatch(Collections.singletonList(mAppsView.getActiveRecyclerView()), preferredItem, packageAndUserAndApp);
} else {
List<ViewGroup> containers = new ArrayList<>(mWorkspace.getPanelCount() + 1);
containers.add(mWorkspace.getHotseat().getShortcutsAndWidgets());
mWorkspace.forEachVisiblePage(page -> containers.add(((CellLayout) page).getShortcutsAndWidgets()));
// Order: Preferred item by itself or in folder, then by matching package/user
if (ADAPTIVE_ICON_WINDOW_ANIM.get()) {
return getFirstMatch(containers, preferredItem, forFolderMatch(preferredItem), packageAndUserAndApp, forFolderMatch(packageAndUserAndApp));
} else {
// FolderAdaptiveIcon as the background.
return getFirstMatch(containers, preferredItem, packageAndUserAndApp);
}
}
}
use of com.android.launcher3.dragndrop.FolderAdaptiveIcon in project android_packages_apps_Launcher3 by AOSPA.
the class FloatingIconView method getOffsetForIconBounds.
@WorkerThread
@SuppressWarnings("WrongThread")
private static int getOffsetForIconBounds(Launcher l, Drawable drawable, RectF position) {
if (!(drawable instanceof AdaptiveIconDrawable) || (drawable instanceof FolderAdaptiveIcon)) {
return 0;
}
int blurSizeOutline = l.getResources().getDimensionPixelSize(R.dimen.blur_size_medium_outline);
Rect bounds = new Rect(0, 0, (int) position.width() + blurSizeOutline, (int) position.height() + blurSizeOutline);
bounds.inset(blurSizeOutline / 2, blurSizeOutline / 2);
try (LauncherIcons li = LauncherIcons.obtain(l)) {
Utilities.scaleRectAboutCenter(bounds, li.getNormalizer().getScale(drawable, null, null, null));
}
bounds.inset((int) (-bounds.width() * AdaptiveIconDrawable.getExtraInsetFraction()), (int) (-bounds.height() * AdaptiveIconDrawable.getExtraInsetFraction()));
return bounds.left;
}
Aggregations