Search in sources :

Example 16 with FastBitmapDrawable

use of com.android.launcher3.FastBitmapDrawable in project android_packages_apps_Trebuchet by LineageOS.

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 (!Utilities.ATLEAST_OREO) {
        return;
    }
    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(new Runnable() {

        @Override
        public void run() {
            Object[] outObj = new Object[1];
            int w = mBitmap.getWidth();
            int h = mBitmap.getHeight();
            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
                mDrawBitmap = !(dr instanceof FolderAdaptiveIcon);
                try (LauncherIcons li = LauncherIcons.obtain(mLauncher)) {
                    // drawable to be normalized
                    Drawable nDr;
                    if (mDrawBitmap) {
                        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(new Runnable() {

                    @Override
                    public void run() {
                        // Assign the variable on the UI thread to avoid race conditions.
                        mScaledMaskPath = mask;
                        if (info.isDisabled()) {
                            FastBitmapDrawable d = new FastBitmapDrawable((Bitmap) null);
                            d.setIsDisabled(true);
                            mBaseFilter = (ColorMatrixColorFilter) d.getColorFilter();
                        }
                        updateColorFilter();
                    }
                });
            }
        }
    });
}
Also used : Path(android.graphics.Path) FastBitmapDrawable(com.android.launcher3.FastBitmapDrawable) Rect(android.graphics.Rect) ColorDrawable(android.graphics.drawable.ColorDrawable) LauncherIcons(com.android.launcher3.icons.LauncherIcons) AdaptiveIconDrawable(android.graphics.drawable.AdaptiveIconDrawable) ColorDrawable(android.graphics.drawable.ColorDrawable) Drawable(android.graphics.drawable.Drawable) FastBitmapDrawable(com.android.launcher3.FastBitmapDrawable) Handler(android.os.Handler) AdaptiveIconDrawable(android.graphics.drawable.AdaptiveIconDrawable) TargetApi(android.annotation.TargetApi)

Example 17 with FastBitmapDrawable

use of com.android.launcher3.FastBitmapDrawable in project android_packages_apps_Trebuchet by LineageOS.

the class TaskIconCache method getCacheEntry.

@WorkerThread
private TaskCacheEntry getCacheEntry(Task task) {
    TaskCacheEntry entry = mIconCache.getAndInvalidateIfModified(task.key);
    if (entry != null) {
        return entry;
    }
    TaskDescription desc = task.taskDescription;
    TaskKey key = task.key;
    ActivityInfo activityInfo = null;
    // Create new cache entry
    entry = new TaskCacheEntry();
    // Load icon
    // TODO: Load icon resource (b/143363444)
    Bitmap icon = TaskDescriptionCompat.getIcon(desc, key.userId);
    if (icon != null) {
        entry.icon = new FastBitmapDrawable(getBitmapInfo(new BitmapDrawable(mContext.getResources(), icon), key.userId, desc.getPrimaryColor(), false));
    } else {
        activityInfo = PackageManagerWrapper.getInstance().getActivityInfo(key.getComponent(), key.userId);
        if (activityInfo != null) {
            BitmapInfo bitmapInfo = getBitmapInfo(mIconProvider.getIcon(activityInfo, UserHandle.of(key.userId)), key.userId, desc.getPrimaryColor(), activityInfo.applicationInfo.isInstantApp());
            entry.icon = newIcon(mContext, bitmapInfo);
        } else {
            entry.icon = getDefaultIcon(key.userId);
        }
    }
    // Loading content descriptions if accessibility or low RAM recents is enabled.
    if (GO_LOW_RAM_RECENTS_ENABLED || mAccessibilityManager.isEnabled()) {
        // Skip loading the content description if the activity no longer exists
        if (activityInfo == null) {
            activityInfo = PackageManagerWrapper.getInstance().getActivityInfo(key.getComponent(), key.userId);
        }
        if (activityInfo != null) {
            entry.contentDescription = ActivityManagerWrapper.getInstance().getBadgedContentDescription(activityInfo, task.key.userId, task.taskDescription);
        }
    }
    mIconCache.put(task.key, entry);
    return entry;
}
Also used : FastBitmapDrawable(com.android.launcher3.FastBitmapDrawable) ActivityInfo(android.content.pm.ActivityInfo) Bitmap(android.graphics.Bitmap) TaskDescription(android.app.ActivityManager.TaskDescription) FastBitmapDrawable(com.android.launcher3.FastBitmapDrawable) BitmapDrawable(android.graphics.drawable.BitmapDrawable) TaskKey(com.android.systemui.shared.recents.model.Task.TaskKey) BitmapInfo(com.android.launcher3.icons.BitmapInfo) WorkerThread(androidx.annotation.WorkerThread)

Example 18 with FastBitmapDrawable

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

the class Workspace method beginDragShared.

public DragView beginDragShared(View child, DragSource source, ItemInfo dragObject, DragPreviewProvider previewProvider, DragOptions dragOptions) {
    if (TestProtocol.sDebugTracing) {
        Log.d(TestProtocol.NO_CONTEXT_MENU, "beginDragShared");
    }
    float iconScale = 1f;
    if (child instanceof BubbleTextView) {
        Drawable icon = ((BubbleTextView) child).getIcon();
        if (icon instanceof FastBitmapDrawable) {
            iconScale = ((FastBitmapDrawable) icon).getAnimatedScale();
        }
    }
    child.clearFocus();
    child.setPressed(false);
    mOutlineProvider = previewProvider;
    // The drag bitmap follows the touch point around on the screen
    final Bitmap b = previewProvider.createDragBitmap();
    int halfPadding = previewProvider.previewPadding / 2;
    float scale = previewProvider.getScaleAndPosition(b, mTempXY);
    int dragLayerX = mTempXY[0];
    int dragLayerY = mTempXY[1];
    DeviceProfile grid = mLauncher.getDeviceProfile();
    Point dragVisualizeOffset = null;
    Rect dragRect = null;
    if (child instanceof BubbleTextView) {
        dragRect = new Rect();
        BubbleTextView.getIconBounds(child, dragRect, grid.iconSizePx);
        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);
    } else if (child instanceof FolderIcon) {
        int previewSize = grid.folderIconSizePx;
        dragVisualizeOffset = new Point(-halfPadding, halfPadding - child.getPaddingTop());
        dragRect = new Rect(0, child.getPaddingTop(), child.getWidth(), previewSize);
    } else if (previewProvider instanceof ShortcutDragPreviewProvider) {
        dragVisualizeOffset = new Point(-halfPadding, halfPadding);
    }
    // Clear the pressed state if necessary
    if (child instanceof BubbleTextView) {
        BubbleTextView icon = (BubbleTextView) child;
        icon.clearPressedBackground();
    }
    if (child.getParent() instanceof ShortcutAndWidgetContainer) {
        mDragSourceInternal = (ShortcutAndWidgetContainer) child.getParent();
    }
    if (child instanceof BubbleTextView && !dragOptions.isAccessibleDrag) {
        PopupContainerWithArrow popupContainer = PopupContainerWithArrow.showForIcon((BubbleTextView) child);
        if (popupContainer != null) {
            dragOptions.preDragCondition = popupContainer.createPreDragCondition();
            mLauncher.getUserEventDispatcher().resetElapsedContainerMillis("dragging started");
        }
    }
    DragView dv = mDragController.startDrag(b, dragLayerX, dragLayerY, source, dragObject, dragVisualizeOffset, dragRect, scale * iconScale, scale, dragOptions);
    dv.setIntrinsicIconScaleFactor(dragOptions.intrinsicIconScaleFactor);
    return dv;
}
Also used : Rect(android.graphics.Rect) Drawable(android.graphics.drawable.Drawable) PreloadIconDrawable(com.android.launcher3.graphics.PreloadIconDrawable) DragView(com.android.launcher3.dragndrop.DragView) Point(android.graphics.Point) SuppressLint(android.annotation.SuppressLint) Point(android.graphics.Point) Bitmap(android.graphics.Bitmap) FolderIcon(com.android.launcher3.folder.FolderIcon) ShortcutDragPreviewProvider(com.android.launcher3.shortcuts.ShortcutDragPreviewProvider) PopupContainerWithArrow(com.android.launcher3.popup.PopupContainerWithArrow)

Example 19 with FastBitmapDrawable

use of com.android.launcher3.FastBitmapDrawable 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 20 with FastBitmapDrawable

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

the class DragPreviewProvider method drawDragView.

/**
 * Draws the {@link #mView} into the given {@param destCanvas}.
 */
protected void drawDragView(Canvas destCanvas, float scale) {
    destCanvas.save();
    destCanvas.scale(scale, scale);
    if (mView instanceof BubbleTextView) {
        Drawable d = ((BubbleTextView) mView).getIcon();
        Rect bounds = getDrawableBounds(d);
        destCanvas.translate(blurSizeOutline / 2 - bounds.left, blurSizeOutline / 2 - bounds.top);
        if (d instanceof FastBitmapDrawable) {
            ((FastBitmapDrawable) d).setScale(1);
        }
        d.draw(destCanvas);
    } else {
        final Rect clipRect = mTempRect;
        mView.getDrawingRect(clipRect);
        boolean textVisible = false;
        if (mView instanceof FolderIcon) {
            // hide the text completely (which can't be achieved by clipping).
            if (((FolderIcon) mView).getTextVisible()) {
                ((FolderIcon) mView).setTextVisible(false);
                textVisible = true;
            }
        }
        destCanvas.translate(-mView.getScrollX() + blurSizeOutline / 2, -mView.getScrollY() + blurSizeOutline / 2);
        destCanvas.clipRect(clipRect);
        mView.draw(destCanvas);
        // Restore text visibility of FolderIcon if necessary
        if (textVisible) {
            ((FolderIcon) mView).setTextVisible(true);
        }
    }
    destCanvas.restore();
}
Also used : FastBitmapDrawable(com.android.launcher3.FastBitmapDrawable) Rect(android.graphics.Rect) FolderIcon(com.android.launcher3.folder.FolderIcon) Drawable(android.graphics.drawable.Drawable) FastBitmapDrawable(com.android.launcher3.FastBitmapDrawable) BubbleTextView(com.android.launcher3.BubbleTextView)

Aggregations

FastBitmapDrawable (com.android.launcher3.icons.FastBitmapDrawable)66 Drawable (android.graphics.drawable.Drawable)40 Point (android.graphics.Point)35 Bitmap (android.graphics.Bitmap)33 Rect (android.graphics.Rect)27 Paint (android.graphics.Paint)17 DraggableView (com.android.launcher3.dragndrop.DraggableView)16 TargetApi (android.annotation.TargetApi)14 FastBitmapDrawable (com.android.launcher3.FastBitmapDrawable)13 LauncherIcons (com.android.launcher3.icons.LauncherIcons)13 SuppressLint (android.annotation.SuppressLint)12 UiThread (androidx.annotation.UiThread)12 AdaptiveIconDrawable (android.graphics.drawable.AdaptiveIconDrawable)11 BubbleTextView (com.android.launcher3.BubbleTextView)11 ItemInfoWithIcon (com.android.launcher3.model.data.ItemInfoWithIcon)11 PendingAddShortcutInfo (com.android.launcher3.widget.PendingAddShortcutInfo)11 View (android.view.View)10 RoundDrawableWrapper (com.android.launcher3.icons.RoundDrawableWrapper)10 LauncherAppWidgetHostView (com.android.launcher3.widget.LauncherAppWidgetHostView)10 ShortcutInfo (android.content.pm.ShortcutInfo)8