Search in sources :

Example 11 with FolderAdaptiveIcon

use of com.android.launcher3.dragndrop.FolderAdaptiveIcon in project Neo-Launcher by NeoApplications.

the class Workspace method getFirstMatchForAppClose.

/**
 * Similar to {@link #getFirstMatch} but optimized to finding a suitable view for the app close
 * animation.
 *
 * @param packageName The package name of the app to match.
 * @param user The user of the app to match.
 */
public View getFirstMatchForAppClose(String packageName, UserHandle user) {
    final int curPage = getCurrentPage();
    final CellLayout currentPage = (CellLayout) getPageAt(curPage);
    final Workspace.ItemOperator packageAndUser = (ItemInfo info, View view) -> info != null && info.getTargetComponent() != null && TextUtils.equals(info.getTargetComponent().getPackageName(), packageName) && info.user.equals(user);
    final Workspace.ItemOperator packageAndUserAndApp = (ItemInfo info, View view) -> packageAndUser.evaluate(info, view) && info.itemType == ITEM_TYPE_APPLICATION;
    final Workspace.ItemOperator packageAndUserAndAppInFolder = (info, view) -> {
        if (info instanceof FolderInfo) {
            FolderInfo folderInfo = (FolderInfo) info;
            for (WorkspaceItemInfo shortcutInfo : folderInfo.contents) {
                if (packageAndUserAndApp.evaluate(shortcutInfo, view)) {
                    return true;
                }
            }
        }
        return false;
    };
    // Order: App icons, app in folder. Items in hotseat get returned first.
    if (ADAPTIVE_ICON_WINDOW_ANIM.get()) {
        return getFirstMatch(new CellLayout[] { getHotseat(), currentPage }, packageAndUserAndApp, packageAndUserAndAppInFolder);
    } else {
        // FolderAdaptiveIcon as the background.
        return getFirstMatch(new CellLayout[] { getHotseat(), currentPage }, packageAndUserAndApp);
    }
}
Also used : WorkspaceAccessibilityHelper(com.android.launcher3.accessibility.WorkspaceAccessibilityHelper) Rect(android.graphics.Rect) SPRING_LOADED_EXIT_DELAY(com.android.launcher3.LauncherAnimUtils.SPRING_LOADED_EXIT_DELAY) TestProtocol(com.android.launcher3.testing.TestProtocol) PendingAddWidgetInfo(com.android.launcher3.widget.PendingAddWidgetInfo) Animator(android.animation.Animator) AppWidgetProviderInfo(android.appwidget.AppWidgetProviderInfo) Drawable(android.graphics.drawable.Drawable) ProviderChangedListener(com.android.launcher3.LauncherAppWidgetHost.ProviderChangedListener) WallpaperManager(android.app.WallpaperManager) IBinder(android.os.IBinder) FolderDotInfo(com.android.launcher3.dot.FolderDotInfo) SPRING_LOADED(com.android.launcher3.LauncherState.SPRING_LOADED) LayoutTransition(android.animation.LayoutTransition) AttributeSet(android.util.AttributeSet) Interpolators(com.android.launcher3.anim.Interpolators) Handler(android.os.Handler) View(android.view.View) Target(com.android.launcher3.userevent.nano.LauncherLogProto.Target) Canvas(android.graphics.Canvas) PreloadIconDrawable(com.android.launcher3.graphics.PreloadIconDrawable) OmegaLauncher(com.saggitt.omega.OmegaLauncher) RotationMode(com.android.launcher3.graphics.RotationMode) Log(android.util.Log) ShortcutDragPreviewProvider(com.android.launcher3.shortcuts.ShortcutDragPreviewProvider) Predicate(java.util.function.Predicate) ObjectAnimator(android.animation.ObjectAnimator) WallpaperOffsetInterpolator(com.android.launcher3.util.WallpaperOffsetInterpolator) AnimatorListenerAdapter(android.animation.AnimatorListenerAdapter) PendingAppWidgetHostView(com.android.launcher3.widget.PendingAppWidgetHostView) ViewGroup(android.view.ViewGroup) DragOptions(com.android.launcher3.dragndrop.DragOptions) SPRING_LOADED_TRANSITION_MS(com.android.launcher3.LauncherAnimUtils.SPRING_LOADED_TRANSITION_MS) SparseArray(android.util.SparseArray) AnimatorSetBuilder(com.android.launcher3.anim.AnimatorSetBuilder) ALL_APPS(com.android.launcher3.LauncherState.ALL_APPS) Message(android.os.Message) LauncherAppWidgetHostView(com.android.launcher3.widget.LauncherAppWidgetHostView) ItemInfoMatcher(com.android.launcher3.util.ItemInfoMatcher) OVERVIEW_TRANSITION_MS(com.android.launcher3.LauncherAnimUtils.OVERVIEW_TRANSITION_MS) NORMAL(com.android.launcher3.LauncherState.NORMAL) ALPHA_INDEX_OVERLAY(com.android.launcher3.dragndrop.DragLayer.ALPHA_INDEX_OVERLAY) AccessibleDragListenerAdapter(com.android.launcher3.accessibility.AccessibleDragListenerAdapter) Folder(com.android.launcher3.folder.Folder) Context(android.content.Context) AccessibilityNodeInfo(android.view.accessibility.AccessibilityNodeInfo) AnimatorUpdateListener(android.animation.ValueAnimator.AnimatorUpdateListener) FolderIcon(com.android.launcher3.folder.FolderIcon) UserEventDispatcher(com.android.launcher3.logging.UserEventDispatcher) ITEM_TYPE_APPLICATION(com.android.launcher3.LauncherSettings.Favorites.ITEM_TYPE_APPLICATION) SpringLoadedDragController(com.android.launcher3.dragndrop.SpringLoadedDragController) ArrayList(java.util.ArrayList) PopupContainerWithArrow(com.android.launcher3.popup.PopupContainerWithArrow) HashSet(java.util.HashSet) SuppressLint(android.annotation.SuppressLint) PreviewBackground(com.android.launcher3.folder.PreviewBackground) AppWidgetHostView(android.appwidget.AppWidgetHostView) MotionEvent(android.view.MotionEvent) UserHandle(android.os.UserHandle) Toast(android.widget.Toast) DragLayer(com.android.launcher3.dragndrop.DragLayer) Executors(com.android.launcher3.util.Executors) IntArray(com.android.launcher3.util.IntArray) ADAPTIVE_ICON_WINDOW_ANIM(com.android.launcher3.config.FeatureFlags.ADAPTIVE_ICON_WINDOW_ANIM) Parcelable(android.os.Parcelable) Action(com.android.launcher3.userevent.nano.LauncherLogProto.Action) ContainerType(com.android.launcher3.userevent.nano.LauncherLogProto.ContainerType) LayoutInflater(android.view.LayoutInflater) AnimationConfig(com.android.launcher3.LauncherStateManager.AnimationConfig) DragController(com.android.launcher3.dragndrop.DragController) PackageUserKey(com.android.launcher3.util.PackageUserKey) Point(android.graphics.Point) TextUtils(android.text.TextUtils) FeatureFlags(com.android.launcher3.config.FeatureFlags) AppWidgetManagerCompat(com.android.launcher3.compat.AppWidgetManagerCompat) PendingAddShortcutInfo(com.android.launcher3.widget.PendingAddShortcutInfo) Bitmap(android.graphics.Bitmap) LauncherOverlay(com.android.launcher3.Launcher.LauncherOverlay) WorkspacePageIndicator(com.android.launcher3.pageindicators.WorkspacePageIndicator) ViewTreeObserver(android.view.ViewTreeObserver) WorkspaceTouchListener(com.android.launcher3.touch.WorkspaceTouchListener) IntSparseArrayMap(com.android.launcher3.util.IntSparseArrayMap) Thunk(com.android.launcher3.util.Thunk) DragPreviewProvider(com.android.launcher3.graphics.DragPreviewProvider) DragView(com.android.launcher3.dragndrop.DragView) OmegaBackgroundView(com.saggitt.omega.views.OmegaBackgroundView) ValueAnimator(android.animation.ValueAnimator) Resources(android.content.res.Resources) View(android.view.View) PendingAppWidgetHostView(com.android.launcher3.widget.PendingAppWidgetHostView) LauncherAppWidgetHostView(com.android.launcher3.widget.LauncherAppWidgetHostView) AppWidgetHostView(android.appwidget.AppWidgetHostView) DragView(com.android.launcher3.dragndrop.DragView) OmegaBackgroundView(com.saggitt.omega.views.OmegaBackgroundView) SuppressLint(android.annotation.SuppressLint) Point(android.graphics.Point)

Example 12 with FolderAdaptiveIcon

use of com.android.launcher3.dragndrop.FolderAdaptiveIcon in project Neo-Launcher by NeoApplications.

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;
        LauncherIcons li = LauncherIcons.obtain(appState.getContext());
        Bitmap badge = li.getShortcutInfoBadge(si, appState.getIconCache()).iconBitmap;
        li.recycle();
        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);
    }
}
Also used : Bitmap(android.graphics.Bitmap) ShortcutInfo(android.content.pm.ShortcutInfo) PendingAddShortcutInfo(com.android.launcher3.widget.PendingAddShortcutInfo) LauncherIcons(com.android.launcher3.icons.LauncherIcons) InsetDrawable(android.graphics.drawable.InsetDrawable) Paint(android.graphics.Paint) Point(android.graphics.Point) TargetApi(android.annotation.TargetApi)

Example 13 with FolderAdaptiveIcon

use of com.android.launcher3.dragndrop.FolderAdaptiveIcon in project Neo-Launcher by NeoApplications.

the class Utilities method getFullDrawable.

/**
 * Returns the full drawable for {@param info}.
 * @param outObj this is set to the internal data associated with {@param info},
 *               eg {@link LauncherActivityInfo} or {@link ShortcutInfo}.
 */
public static Drawable getFullDrawable(Launcher launcher, ItemInfo info, int width, int height, boolean flattenDrawable, Object[] outObj) {
    LauncherAppState appState = LauncherAppState.getInstance(launcher);
    IconPackManager.CustomIconEntry customIconEntry = (info instanceof WorkspaceItemInfo) ? ((WorkspaceItemInfo) info).customIconEntry : null;
    if (info.itemType == LauncherSettings.Favorites.ITEM_TYPE_APPLICATION || customIconEntry != null) {
        LauncherActivityInfo activityInfo = LauncherAppsCompat.getInstance(launcher).resolveActivity(info.getIntent(), info.user);
        outObj[0] = activityInfo;
        return (activityInfo != null) ? appState.getIconCache().getFullResIcon(activityInfo, flattenDrawable) : null;
    } else if (info.itemType == LauncherSettings.Favorites.ITEM_TYPE_DEEP_SHORTCUT) {
        if (info instanceof PendingAddShortcutInfo) {
            ShortcutConfigActivityInfo activityInfo = ((PendingAddShortcutInfo) info).activityInfo;
            outObj[0] = activityInfo;
            return activityInfo.getFullResIcon(appState.getIconCache());
        }
        ShortcutKey key = ShortcutKey.fromItemInfo(info);
        DeepShortcutManager sm = DeepShortcutManager.getInstance(launcher);
        List<ShortcutInfo> si = sm.queryForFullDetails(key.componentName.getPackageName(), Arrays.asList(key.getId()), key.user);
        if (si.isEmpty()) {
            return null;
        } else {
            outObj[0] = si.get(0);
            return sm.getShortcutIconDrawable(si.get(0), appState.getInvariantDeviceProfile().fillResIconDpi);
        }
    } else if (info.itemType == LauncherSettings.Favorites.ITEM_TYPE_FOLDER) {
        FolderAdaptiveIcon icon = FolderAdaptiveIcon.createFolderAdaptiveIcon(launcher, info.id, new Point(width, height));
        if (icon == null) {
            return null;
        }
        outObj[0] = icon;
        return icon;
    } else {
        return null;
    }
}
Also used : FolderAdaptiveIcon(com.android.launcher3.dragndrop.FolderAdaptiveIcon) IconPackManager(com.saggitt.omega.iconpack.IconPackManager) LauncherActivityInfo(android.content.pm.LauncherActivityInfo) PendingAddShortcutInfo(com.android.launcher3.widget.PendingAddShortcutInfo) ShortcutConfigActivityInfo(com.android.launcher3.compat.ShortcutConfigActivityInfo) List(java.util.List) ArrayList(java.util.ArrayList) Point(android.graphics.Point) DeepShortcutManager(com.android.launcher3.shortcuts.DeepShortcutManager) ShortcutKey(com.android.launcher3.shortcuts.ShortcutKey)

Example 14 with FolderAdaptiveIcon

use of com.android.launcher3.dragndrop.FolderAdaptiveIcon in project Neo-Launcher by NeoApplications.

the class FloatingIconView method setIcon.

/**
 * Sets the drawables of the {@param originalView} onto this view.
 *
 * @param originalView The View that the FloatingIconView will replace.
 * @param drawable The drawable of the original view.
 * @param badge The badge of the original view.
 * @param iconOffset The amount of offset needed to match this view with the original view.
 */
@UiThread
private void setIcon(View originalView, @Nullable Drawable drawable, @Nullable Drawable badge, int iconOffset) {
    mBadge = badge;
    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 LayoutParams lp = (LayoutParams) getLayoutParams();
        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 (mBadge != null) {
            mBadge.setBounds(mStartRevealRect);
            if (!mIsOpening && !isFolderIcon) {
                DRAWABLE_ALPHA.set(mBadge, 0);
            }
        }
        if (isFolderIcon) {
            ((FolderIcon) originalView).getPreviewBounds(sTmpRect);
            float bgStroke = ((FolderIcon) originalView).getBackgroundStrokeWidth();
            if (mForeground instanceof ShiftedBitmapDrawable) {
                ShiftedBitmapDrawable sbd = (ShiftedBitmapDrawable) mForeground;
                sbd.setShiftX(sbd.getShiftX() - sTmpRect.left - bgStroke);
                sbd.setShiftY(sbd.getShiftY() - sTmpRect.top - bgStroke);
            }
            if (mBadge instanceof ShiftedBitmapDrawable) {
                ShiftedBitmapDrawable sbd = (ShiftedBitmapDrawable) mBadge;
                sbd.setShiftX(sbd.getShiftX() - sTmpRect.left - bgStroke);
                sbd.setShiftY(sbd.getShiftY() - sTmpRect.top - bgStroke);
            }
        } else {
            Utilities.scaleRectAboutCenter(mStartRevealRect, IconShape.getNormalizationScale());
        }
        float aspectRatio = mLauncher.getDeviceProfile().aspectRatio;
        if (mIsVerticalBarLayout) {
            lp.width = (int) Math.max(lp.width, lp.height * aspectRatio);
        } else {
            lp.height = (int) Math.max(lp.height, lp.width * aspectRatio);
        }
        int left = mIsRtl ? mLauncher.getDeviceProfile().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 (mIsOpening) {
            bgDrawableStartScale = 1f;
            mOutline.set(0, 0, originalWidth, originalHeight);
        } else {
            bgDrawableStartScale = scale;
            mOutline.set(0, 0, lp.width, lp.height);
        }
        setBackgroundDrawableBounds(bgDrawableStartScale);
        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();
}
Also used : FolderAdaptiveIcon(com.android.launcher3.dragndrop.FolderAdaptiveIcon) LayoutParams(com.android.launcher3.InsettableFrameLayout.LayoutParams) AdaptiveIconDrawable(android.graphics.drawable.AdaptiveIconDrawable) ColorDrawable(android.graphics.drawable.ColorDrawable) Drawable(android.graphics.drawable.Drawable) ShiftedBitmapDrawable(com.android.launcher3.graphics.ShiftedBitmapDrawable) Utilities.getFullDrawable(com.android.launcher3.Utilities.getFullDrawable) Outline(android.graphics.Outline) ViewOutlineProvider(android.view.ViewOutlineProvider) ImageView(android.widget.ImageView) BubbleTextView(com.android.launcher3.BubbleTextView) View(android.view.View) DeepShortcutView(com.android.launcher3.shortcuts.DeepShortcutView) ColorDrawable(android.graphics.drawable.ColorDrawable) FolderIcon(com.android.launcher3.folder.FolderIcon) ShiftedBitmapDrawable(com.android.launcher3.graphics.ShiftedBitmapDrawable) AdaptiveIconDrawable(android.graphics.drawable.AdaptiveIconDrawable) UiThread(androidx.annotation.UiThread)

Example 15 with FolderAdaptiveIcon

use of com.android.launcher3.dragndrop.FolderAdaptiveIcon in project android_packages_apps_Launcher3 by ArrowOS.

the class Utilities method loadFullDrawableWithoutTheme.

private static Drawable loadFullDrawableWithoutTheme(Context context, ItemInfo info, int width, int height, Object[] outObj) {
    ActivityContext activity = ActivityContext.lookupContext(context);
    LauncherAppState appState = LauncherAppState.getInstance(context);
    if (info.itemType == LauncherSettings.Favorites.ITEM_TYPE_APPLICATION) {
        LauncherActivityInfo activityInfo = context.getSystemService(LauncherApps.class).resolveActivity(info.getIntent(), info.user);
        outObj[0] = activityInfo;
        return activityInfo == null ? null : LauncherAppState.getInstance(context).getIconProvider().getIcon(activityInfo, activity.getDeviceProfile().inv.fillResIconDpi);
    } else if (info.itemType == LauncherSettings.Favorites.ITEM_TYPE_DEEP_SHORTCUT) {
        if (info instanceof PendingAddShortcutInfo) {
            ShortcutConfigActivityInfo activityInfo = ((PendingAddShortcutInfo) info).activityInfo;
            outObj[0] = activityInfo;
            return activityInfo.getFullResIcon(appState.getIconCache());
        }
        List<ShortcutInfo> si = ShortcutKey.fromItemInfo(info).buildRequest(context).query(ShortcutRequest.ALL);
        if (si.isEmpty()) {
            return null;
        } else {
            outObj[0] = si.get(0);
            return ShortcutCachingLogic.getIcon(context, si.get(0), appState.getInvariantDeviceProfile().fillResIconDpi);
        }
    } else if (info.itemType == LauncherSettings.Favorites.ITEM_TYPE_FOLDER) {
        FolderAdaptiveIcon icon = FolderAdaptiveIcon.createFolderAdaptiveIcon(activity, info.id, new Point(width, height));
        if (icon == null) {
            return null;
        }
        outObj[0] = icon;
        return icon;
    } else if (info.itemType == LauncherSettings.Favorites.ITEM_TYPE_SEARCH_ACTION && info instanceof SearchActionItemInfo) {
        return new AdaptiveIconDrawable(new FastBitmapDrawable(((SearchActionItemInfo) info).bitmap), null);
    } else {
        return null;
    }
}
Also used : ActivityContext(com.android.launcher3.views.ActivityContext) FolderAdaptiveIcon(com.android.launcher3.dragndrop.FolderAdaptiveIcon) FastBitmapDrawable(com.android.launcher3.icons.FastBitmapDrawable) LauncherActivityInfo(android.content.pm.LauncherActivityInfo) PendingAddShortcutInfo(com.android.launcher3.widget.PendingAddShortcutInfo) ShortcutConfigActivityInfo(com.android.launcher3.pm.ShortcutConfigActivityInfo) LauncherApps(android.content.pm.LauncherApps) List(java.util.List) SearchActionItemInfo(com.android.launcher3.model.data.SearchActionItemInfo) Point(android.graphics.Point) AdaptiveIconDrawable(android.graphics.drawable.AdaptiveIconDrawable)

Aggregations

Point (android.graphics.Point)29 Bitmap (android.graphics.Bitmap)26 AdaptiveIconDrawable (android.graphics.drawable.AdaptiveIconDrawable)24 FolderAdaptiveIcon (com.android.launcher3.dragndrop.FolderAdaptiveIcon)20 PendingAddShortcutInfo (com.android.launcher3.widget.PendingAddShortcutInfo)20 Rect (android.graphics.Rect)19 TargetApi (android.annotation.TargetApi)18 ColorDrawable (android.graphics.drawable.ColorDrawable)16 Drawable (android.graphics.drawable.Drawable)16 Path (android.graphics.Path)14 FastBitmapDrawable (com.android.launcher3.icons.FastBitmapDrawable)14 LauncherIcons (com.android.launcher3.icons.LauncherIcons)14 View (android.view.View)13 Paint (android.graphics.Paint)12 List (java.util.List)11 Handler (android.os.Handler)9 PreviewBackground (com.android.launcher3.folder.PreviewBackground)9 FolderIcon (com.android.launcher3.folder.FolderIcon)8 ShortcutInfo (android.content.pm.ShortcutInfo)7 Matrix (android.graphics.Matrix)7