Search in sources :

Example 26 with FastBitmapDrawable

use of com.android.launcher3.FastBitmapDrawable in project android_packages_apps_Launcher3 by ArrowOS.

the class WidgetCell method applyPreview.

private void applyPreview(Bitmap bitmap) {
    if (bitmap != null) {
        Drawable drawable = new RoundDrawableWrapper(new FastBitmapDrawable(bitmap), mEnforcedCornerRadius);
        // Scale down the preview size if it's wider than the cell.
        float scale = 1f;
        if (mTargetPreviewWidth > 0) {
            float maxWidth = mTargetPreviewWidth;
            float previewWidth = drawable.getIntrinsicWidth() * mPreviewContainerScale;
            scale = Math.min(maxWidth / previewWidth, 1);
        }
        setContainerSize(Math.round(drawable.getIntrinsicWidth() * scale * mPreviewContainerScale), Math.round(drawable.getIntrinsicHeight() * scale * mPreviewContainerScale));
        mWidgetImage.setDrawable(drawable);
        mWidgetImage.setVisibility(View.VISIBLE);
        if (mAppWidgetHostViewPreview != null) {
            removeView(mAppWidgetHostViewPreview);
            mAppWidgetHostViewPreview = null;
        }
    }
    if (mAnimatePreview) {
        mWidgetImageContainer.setAlpha(0f);
        ViewPropertyAnimator anim = mWidgetImageContainer.animate();
        anim.alpha(1.0f).setDuration(FADE_IN_DURATION_MS);
    } else {
        mWidgetImageContainer.setAlpha(1f);
    }
    if (mActiveRequest != null) {
        mActiveRequest.cancel();
        mActiveRequest = null;
    }
}
Also used : FastBitmapDrawable(com.android.launcher3.icons.FastBitmapDrawable) Drawable(android.graphics.drawable.Drawable) FastBitmapDrawable(com.android.launcher3.icons.FastBitmapDrawable) RoundDrawableWrapper(com.android.launcher3.icons.RoundDrawableWrapper) ViewPropertyAnimator(android.view.ViewPropertyAnimator)

Example 27 with FastBitmapDrawable

use of com.android.launcher3.FastBitmapDrawable in project android_packages_apps_Launcher3 by ArrowOS.

the class BubbleTextView method applyIconAndLabel.

@UiThread
protected void applyIconAndLabel(ItemInfoWithIcon info) {
    if (mThemeAllAppsIcons) {
        boolean useTheme = mDisplay == DISPLAY_WORKSPACE || mDisplay == DISPLAY_FOLDER || mDisplay == DISPLAY_ALL_APPS || mDisplay == DISPLAY_TASKBAR;
        FastBitmapDrawable iconDrawable = info.newIcon(getContext(), useTheme);
        mDotParams.color = IconPalette.getMutedColor(iconDrawable.getIconColor(), 0.54f);
        setIcon(iconDrawable);
        applyLabel(info);
    } else {
        boolean useTheme = mDisplay == DISPLAY_WORKSPACE || mDisplay == DISPLAY_FOLDER || mDisplay == DISPLAY_TASKBAR;
        FastBitmapDrawable iconDrawable = info.newIcon(getContext(), useTheme);
        mDotParams.color = IconPalette.getMutedColor(iconDrawable.getIconColor(), 0.54f);
        setIcon(iconDrawable);
        applyLabel(info);
    }
}
Also used : FastBitmapDrawable(com.android.launcher3.icons.FastBitmapDrawable) UiThread(androidx.annotation.UiThread)

Example 28 with FastBitmapDrawable

use of com.android.launcher3.FastBitmapDrawable in project android_packages_apps_Launcher3 by ProtonAOSP.

the class ItemInfoWithIcon method newIcon.

/**
 * Returns a FastBitmapDrawable with the icon and context theme applied
 */
public FastBitmapDrawable newIcon(Context context, boolean applyTheme) {
    FastBitmapDrawable drawable = applyTheme ? bitmap.newThemedIcon(context) : bitmap.newIcon(context);
    drawable.setIsDisabled(isDisabled());
    return drawable;
}
Also used : FastBitmapDrawable(com.android.launcher3.icons.FastBitmapDrawable)

Example 29 with FastBitmapDrawable

use of com.android.launcher3.FastBitmapDrawable in project android_packages_apps_Launcher3 by ProtonAOSP.

the class Workspace method createWidgetDrawable.

private Drawable createWidgetDrawable(ItemInfo widgetInfo, View layout) {
    int[] unScaledSize = estimateItemSize(widgetInfo);
    int visibility = layout.getVisibility();
    layout.setVisibility(VISIBLE);
    int width = MeasureSpec.makeMeasureSpec(unScaledSize[0], MeasureSpec.EXACTLY);
    int height = MeasureSpec.makeMeasureSpec(unScaledSize[1], MeasureSpec.EXACTLY);
    layout.measure(width, height);
    layout.layout(0, 0, unScaledSize[0], unScaledSize[1]);
    Bitmap b = BitmapRenderer.createHardwareBitmap(unScaledSize[0], unScaledSize[1], layout::draw);
    layout.setVisibility(visibility);
    return new FastBitmapDrawable(b);
}
Also used : FastBitmapDrawable(com.android.launcher3.icons.FastBitmapDrawable) Bitmap(android.graphics.Bitmap) SuppressLint(android.annotation.SuppressLint) Point(android.graphics.Point)

Example 30 with FastBitmapDrawable

use of com.android.launcher3.FastBitmapDrawable in project android_packages_apps_Launcher3 by ProtonAOSP.

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_SEARCH_ACTION && 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(mActivity, info, w, h, outObj);
        if (dr instanceof AdaptiveIconDrawable) {
            int blurMargin = (int) mActivity.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(mActivity, 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(mActivity)) {
                // 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)

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