Search in sources :

Example 1 with FastBitmapDrawable

use of com.android.launcher3.icons.FastBitmapDrawable in project Launcher3 by chislon.

the class AppsCustomizePagedView method onSyncWidgetPageItems.

private void onSyncWidgetPageItems(AsyncTaskPageData data) {
    if (mInTransition) {
        mDeferredSyncWidgetPageItems.add(data);
        return;
    }
    try {
        int page = data.page;
        PagedViewGridLayout layout = (PagedViewGridLayout) getPageAt(page);
        ArrayList<Object> items = data.items;
        int count = items.size();
        for (int i = 0; i < count; ++i) {
            PagedViewWidget widget = (PagedViewWidget) layout.getChildAt(i);
            if (widget != null) {
                Bitmap preview = data.generatedImages.get(i);
                widget.applyPreview(new FastBitmapDrawable(preview), i);
            }
        }
        enableHwLayersOnVisiblePages();
        // Update all thread priorities
        Iterator<AppsCustomizeAsyncTask> iter = mRunningTasks.iterator();
        while (iter.hasNext()) {
            AppsCustomizeAsyncTask task = (AppsCustomizeAsyncTask) iter.next();
            int pageIndex = task.page;
            task.setThreadPriority(getThreadPriorityForPage(pageIndex));
        }
    } finally {
        data.cleanup(false);
    }
}
Also used : Bitmap(android.graphics.Bitmap) DragObject(com.android.launcher3.DropTarget.DragObject) Point(android.graphics.Point)

Example 2 with FastBitmapDrawable

use of com.android.launcher3.icons.FastBitmapDrawable 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();
            }));
        }
    });
}
Also used : Path(android.graphics.Path) Rect(android.graphics.Rect) AdaptiveIconDrawable(android.graphics.drawable.AdaptiveIconDrawable) ColorDrawable(android.graphics.drawable.ColorDrawable) Drawable(android.graphics.drawable.Drawable) FastBitmapDrawable(com.android.launcher3.icons.FastBitmapDrawable) PictureDrawable(android.graphics.drawable.PictureDrawable) Handler(android.os.Handler) Point(android.graphics.Point) FastBitmapDrawable(com.android.launcher3.icons.FastBitmapDrawable) Bitmap(android.graphics.Bitmap) ColorDrawable(android.graphics.drawable.ColorDrawable) LauncherIcons(com.android.launcher3.icons.LauncherIcons) AdaptiveIconDrawable(android.graphics.drawable.AdaptiveIconDrawable) TargetApi(android.annotation.TargetApi)

Example 3 with FastBitmapDrawable

use of com.android.launcher3.icons.FastBitmapDrawable in project android_packages_apps_Launcher3 by crdroidandroid.

the class DragPreviewProvider method createDrawable.

/**
 * Returns a new drawable to show when the {@link #mView} is being dragged around.
 * Responsibility for the drawable is transferred to the caller.
 */
public Drawable createDrawable() {
    if (mView instanceof LauncherAppWidgetHostView) {
        return null;
    }
    int width = 0;
    int height = 0;
    // Assume scaleX == scaleY, which is always the case for workspace items.
    float scale = mView.getScaleX();
    if (mView instanceof DraggableView) {
        ((DraggableView) mView).getSourceVisualDragBounds(mTempRect);
        width = mTempRect.width();
        height = mTempRect.height();
    } else {
        width = mView.getWidth();
        height = mView.getHeight();
    }
    return new FastBitmapDrawable(BitmapRenderer.createHardwareBitmap(width + blurSizeOutline, height + blurSizeOutline, (c) -> drawDragView(c, scale)));
}
Also used : FastBitmapDrawable(com.android.launcher3.icons.FastBitmapDrawable) Context(android.content.Context) Rect(android.graphics.Rect) Launcher(com.android.launcher3.Launcher) BitmapRenderer(com.android.launcher3.icons.BitmapRenderer) UI_HELPER_EXECUTOR(com.android.launcher3.util.Executors.UI_HELPER_EXECUTOR) FastBitmapDrawable(com.android.launcher3.icons.FastBitmapDrawable) BlurMaskFilter(android.graphics.BlurMaskFilter) FeatureFlags(com.android.launcher3.config.FeatureFlags) PorterDuff(android.graphics.PorterDuff) SafeCloseable(com.android.launcher3.util.SafeCloseable) Drawable(android.graphics.drawable.Drawable) DraggableView(com.android.launcher3.dragndrop.DraggableView) BubbleTextView(com.android.launcher3.BubbleTextView) ByteBuffer(java.nio.ByteBuffer) PorterDuffXfermode(android.graphics.PorterDuffXfermode) Nullable(androidx.annotation.Nullable) R(com.android.launcher3.R) Bitmap(android.graphics.Bitmap) View(android.view.View) LauncherAppWidgetHostView(com.android.launcher3.widget.LauncherAppWidgetHostView) Canvas(android.graphics.Canvas) Paint(android.graphics.Paint) LauncherAppWidgetHostView(com.android.launcher3.widget.LauncherAppWidgetHostView) DraggableView(com.android.launcher3.dragndrop.DraggableView) Paint(android.graphics.Paint)

Example 4 with FastBitmapDrawable

use of com.android.launcher3.icons.FastBitmapDrawable 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);
    }
}
Also used : FastBitmapDrawable(com.android.launcher3.icons.FastBitmapDrawable) Bitmap(android.graphics.Bitmap) ShortcutInfo(android.content.pm.ShortcutInfo) PendingAddShortcutInfo(com.android.launcher3.widget.PendingAddShortcutInfo) InsetDrawable(android.graphics.drawable.InsetDrawable) ItemInfoWithIcon(com.android.launcher3.model.data.ItemInfoWithIcon) Paint(android.graphics.Paint) Point(android.graphics.Point) TargetApi(android.annotation.TargetApi)

Example 5 with FastBitmapDrawable

use of com.android.launcher3.icons.FastBitmapDrawable in project android_packages_apps_Launcher3 by crdroidandroid.

the class PendingAppWidgetHostView method reapplyItemInfo.

@Override
public void reapplyItemInfo(ItemInfoWithIcon info) {
    if (mCenterDrawable != null) {
        mCenterDrawable.setCallback(null);
        mCenterDrawable = null;
    }
    if (info.bitmap.icon != null) {
        Drawable widgetCategoryIcon = getWidgetCategoryIcon();
        // 3) App icon in the center with a setup icon on the top left corner.
        if (mDisabledForSafeMode) {
            if (widgetCategoryIcon == null) {
                FastBitmapDrawable disabledIcon = info.newIcon(getContext());
                disabledIcon.setIsDisabled(true);
                mCenterDrawable = disabledIcon;
            } else {
                widgetCategoryIcon.setColorFilter(FastBitmapDrawable.getDisabledFColorFilter(/* disabledAlpha= */
                1f));
                mCenterDrawable = widgetCategoryIcon;
            }
            mSettingIconDrawable = null;
        } else if (isReadyForClickSetup()) {
            mCenterDrawable = widgetCategoryIcon == null ? info.newIcon(getContext()) : widgetCategoryIcon;
            mSettingIconDrawable = getResources().getDrawable(R.drawable.ic_setting).mutate();
            updateSettingColor(info.bitmap.color);
        } else {
            mCenterDrawable = widgetCategoryIcon == null ? newPendingIcon(getContext(), info) : widgetCategoryIcon;
            mSettingIconDrawable = null;
            applyState();
        }
        mCenterDrawable.setCallback(this);
        mDrawableSizeChanged = true;
    }
    invalidate();
}
Also used : FastBitmapDrawable(com.android.launcher3.icons.FastBitmapDrawable) Drawable(android.graphics.drawable.Drawable) FastBitmapDrawable(com.android.launcher3.icons.FastBitmapDrawable)

Aggregations

FastBitmapDrawable (com.android.launcher3.icons.FastBitmapDrawable)11 Point (android.graphics.Point)6 Bitmap (android.graphics.Bitmap)5 Drawable (android.graphics.drawable.Drawable)5 Rect (android.graphics.Rect)4 Paint (android.graphics.Paint)3 DraggableView (com.android.launcher3.dragndrop.DraggableView)3 SuppressLint (android.annotation.SuppressLint)2 TargetApi (android.annotation.TargetApi)2 View (android.view.View)2 UiThread (androidx.annotation.UiThread)2 BubbleTextView (com.android.launcher3.BubbleTextView)2 Launcher (com.android.launcher3.Launcher)2 LauncherIcons (com.android.launcher3.icons.LauncherIcons)2 RoundDrawableWrapper (com.android.launcher3.icons.RoundDrawableWrapper)2 ItemInfoWithIcon (com.android.launcher3.model.data.ItemInfoWithIcon)2 LauncherAppWidgetHostView (com.android.launcher3.widget.LauncherAppWidgetHostView)2 AppWidgetHostViewDragListener (com.android.launcher3.widget.dragndrop.AppWidgetHostViewDragListener)2 AppWidgetHostView (android.appwidget.AppWidgetHostView)1 Context (android.content.Context)1