Search in sources :

Example 56 with FastBitmapDrawable

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

the class TaskMenuView method addMenuOptions.

private void addMenuOptions(TaskView taskView) {
    Drawable icon = taskView.getTask().icon.getConstantState().newDrawable();
    mTaskIcon.setDrawable(icon);
    mTaskIcon.setOnClickListener(v -> close(true));
    mTaskName.setText(TaskUtils.getTitle(getContext(), taskView.getTask()));
    mTaskName.setOnClickListener(v -> close(true));
    // Set the icons to match scale by listening to each other's changes
    mMenuIconDrawable = icon instanceof FastBitmapDrawable ? (FastBitmapDrawable) icon : null;
    taskView.getIconView().addUpdateScaleListener(mTaskViewIconScaleListener);
    mTaskIcon.addUpdateScaleListener(mMenuIconScaleListener);
    // Move the icon and text up half an icon size to lay over the TaskView
    LinearLayout.LayoutParams params = (LinearLayout.LayoutParams) mTaskIcon.getLayoutParams();
    params.topMargin = (int) -mThumbnailTopMargin;
    mTaskIcon.setLayoutParams(params);
    final BaseDraggingActivity activity = BaseDraggingActivity.fromContext(getContext());
    final List<TaskSystemShortcut> shortcuts = TaskOverlayFactory.INSTANCE.get(getContext()).getEnabledShortcuts(taskView);
    final int count = shortcuts.size();
    for (int i = 0; i < count; ++i) {
        final TaskSystemShortcut menuOption = shortcuts.get(i);
        addMenuOption(menuOption, menuOption.getOnClickListener(activity, taskView));
    }
}
Also used : FastBitmapDrawable(com.android.launcher3.FastBitmapDrawable) BaseDraggingActivity(com.android.launcher3.BaseDraggingActivity) TaskSystemShortcut(com.android.quickstep.TaskSystemShortcut) Drawable(android.graphics.drawable.Drawable) FastBitmapDrawable(com.android.launcher3.FastBitmapDrawable) LinearLayout(android.widget.LinearLayout)

Example 57 with FastBitmapDrawable

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

the class QuickstepAppTransitionManagerImpl method getOpeningWindowAnimators.

/**
 * @return Animator that controls the window of the opening targets.
 */
private ValueAnimator getOpeningWindowAnimators(View v, RemoteAnimationTargetCompat[] targets, Rect windowTargetBounds, boolean toggleVisibility) {
    RectF bounds = new RectF();
    FloatingIconView floatingView = FloatingIconView.getFloatingIconView(mLauncher, v, toggleVisibility, bounds, true);
    Rect crop = new Rect();
    Matrix matrix = new Matrix();
    RemoteAnimationTargetSet openingTargets = new RemoteAnimationTargetSet(targets, MODE_OPENING);
    SyncRtSurfaceTransactionApplierCompat surfaceApplier = new SyncRtSurfaceTransactionApplierCompat(floatingView);
    openingTargets.addDependentTransactionApplier(surfaceApplier);
    // Scale the app icon to take up the entire screen. This simplifies the math when
    // animating the app window position / scale.
    float smallestSize = Math.min(windowTargetBounds.height(), windowTargetBounds.width());
    float maxScaleX = smallestSize / bounds.width();
    float maxScaleY = smallestSize / bounds.height();
    float scale = Math.max(maxScaleX, maxScaleY);
    float startScale = 1f;
    if (v instanceof BubbleTextView && !(v.getParent() instanceof DeepShortcutView)) {
        Drawable dr = ((BubbleTextView) v).getIcon();
        if (dr instanceof FastBitmapDrawable) {
            startScale = ((FastBitmapDrawable) dr).getAnimatedScale();
        }
    }
    final float initialStartScale = startScale;
    int[] dragLayerBounds = new int[2];
    mDragLayer.getLocationOnScreen(dragLayerBounds);
    // Animate the app icon to the center of the window bounds in screen coordinates.
    float centerX = windowTargetBounds.centerX() - dragLayerBounds[0];
    float centerY = windowTargetBounds.centerY() - dragLayerBounds[1];
    float dX = centerX - bounds.centerX();
    float dY = centerY - bounds.centerY();
    boolean useUpwardAnimation = bounds.top > centerY || Math.abs(dY) < mLauncher.getDeviceProfile().cellHeightPx;
    final long xDuration = useUpwardAnimation ? APP_LAUNCH_CURVED_DURATION : APP_LAUNCH_DOWN_DURATION;
    final long yDuration = useUpwardAnimation ? APP_LAUNCH_DURATION : APP_LAUNCH_DOWN_CURVED_DURATION;
    final long alphaDuration = useUpwardAnimation ? APP_LAUNCH_ALPHA_DURATION : APP_LAUNCH_ALPHA_DOWN_DURATION;
    RectF targetBounds = new RectF(windowTargetBounds);
    RectF currentBounds = new RectF();
    RectF temp = new RectF();
    ValueAnimator appAnimator = ValueAnimator.ofFloat(0, 1);
    appAnimator.setDuration(APP_LAUNCH_DURATION);
    appAnimator.setInterpolator(LINEAR);
    appAnimator.addListener(floatingView);
    appAnimator.addListener(new AnimatorListenerAdapter() {

        @Override
        public void onAnimationEnd(Animator animation) {
            if (v instanceof BubbleTextView) {
                ((BubbleTextView) v).setStayPressed(false);
            }
            openingTargets.release();
        }
    });
    float shapeRevealDuration = APP_LAUNCH_DURATION * SHAPE_PROGRESS_DURATION;
    final float startCrop;
    final float endCrop;
    if (mDeviceProfile.isVerticalBarLayout()) {
        startCrop = windowTargetBounds.height();
        endCrop = windowTargetBounds.width();
    } else {
        startCrop = windowTargetBounds.width();
        endCrop = windowTargetBounds.height();
    }
    final float initialWindowRadius = supportsRoundedCornersOnWindows(mLauncher.getResources()) ? startCrop / 2f : 0f;
    final float windowRadius = mDeviceProfile.isMultiWindowMode ? 0 : getWindowCornerRadius(mLauncher.getResources());
    appAnimator.addUpdateListener(new MultiValueUpdateListener() {

        FloatProp mDx = new FloatProp(0, dX, 0, xDuration, AGGRESSIVE_EASE);

        FloatProp mDy = new FloatProp(0, dY, 0, yDuration, AGGRESSIVE_EASE);

        FloatProp mIconScale = new FloatProp(initialStartScale, scale, 0, APP_LAUNCH_DURATION, EXAGGERATED_EASE);

        FloatProp mIconAlpha = new FloatProp(1f, 0f, APP_LAUNCH_ALPHA_START_DELAY, alphaDuration, LINEAR);

        FloatProp mCroppedSize = new FloatProp(startCrop, endCrop, 0, CROP_DURATION, EXAGGERATED_EASE);

        FloatProp mWindowRadius = new FloatProp(initialWindowRadius, windowRadius, 0, RADIUS_DURATION, EXAGGERATED_EASE);

        @Override
        public void onUpdate(float percent) {
            // Calculate app icon size.
            float iconWidth = bounds.width() * mIconScale.value;
            float iconHeight = bounds.height() * mIconScale.value;
            // Animate the window crop so that it starts off as a square.
            final int windowWidth;
            final int windowHeight;
            if (mDeviceProfile.isVerticalBarLayout()) {
                windowWidth = (int) mCroppedSize.value;
                windowHeight = windowTargetBounds.height();
            } else {
                windowWidth = windowTargetBounds.width();
                windowHeight = (int) mCroppedSize.value;
            }
            crop.set(0, 0, windowWidth, windowHeight);
            // Scale the app window to match the icon size.
            float scaleX = iconWidth / windowWidth;
            float scaleY = iconHeight / windowHeight;
            float scale = Math.min(1f, Math.max(scaleX, scaleY));
            float scaledWindowWidth = windowWidth * scale;
            float scaledWindowHeight = windowHeight * scale;
            float offsetX = (scaledWindowWidth - iconWidth) / 2;
            float offsetY = (scaledWindowHeight - iconHeight) / 2;
            // Calculate the window position
            temp.set(bounds);
            temp.offset(dragLayerBounds[0], dragLayerBounds[1]);
            temp.offset(mDx.value, mDy.value);
            Utilities.scaleRectFAboutCenter(temp, mIconScale.value);
            float transX0 = temp.left - offsetX;
            float transY0 = temp.top - offsetY;
            float croppedHeight = (windowTargetBounds.height() - crop.height()) * scale;
            float croppedWidth = (windowTargetBounds.width() - crop.width()) * scale;
            SurfaceParams[] params = new SurfaceParams[targets.length];
            for (int i = targets.length - 1; i >= 0; i--) {
                RemoteAnimationTargetCompat target = targets[i];
                Rect targetCrop;
                final float alpha;
                final float cornerRadius;
                if (target.mode == MODE_OPENING) {
                    matrix.setScale(scale, scale);
                    matrix.postTranslate(transX0, transY0);
                    targetCrop = crop;
                    alpha = 1f - mIconAlpha.value;
                    cornerRadius = mWindowRadius.value;
                    matrix.mapRect(currentBounds, targetBounds);
                    if (mDeviceProfile.isVerticalBarLayout()) {
                        currentBounds.right -= croppedWidth;
                    } else {
                        currentBounds.bottom -= croppedHeight;
                    }
                    floatingView.update(currentBounds, mIconAlpha.value, percent, 0f, cornerRadius * scale, true);
                } else {
                    matrix.setTranslate(target.position.x, target.position.y);
                    targetCrop = target.sourceContainerBounds;
                    alpha = 1f;
                    cornerRadius = 0;
                }
                params[i] = new SurfaceParams(target.leash, alpha, matrix, targetCrop, RemoteAnimationProvider.getLayer(target, MODE_OPENING), cornerRadius);
            }
            surfaceApplier.scheduleApply(params);
        }
    });
    return appAnimator;
}
Also used : SyncRtSurfaceTransactionApplierCompat(com.android.systemui.shared.system.SyncRtSurfaceTransactionApplierCompat) FloatingIconView(com.android.launcher3.views.FloatingIconView) Rect(android.graphics.Rect) RemoteAnimationTargetCompat(com.android.systemui.shared.system.RemoteAnimationTargetCompat) Drawable(android.graphics.drawable.Drawable) ValueAnimator(android.animation.ValueAnimator) DeepShortcutView(com.android.launcher3.shortcuts.DeepShortcutView) RemoteAnimationTargetSet(com.android.quickstep.util.RemoteAnimationTargetSet) RectF(android.graphics.RectF) MultiValueUpdateListener(com.android.quickstep.util.MultiValueUpdateListener) Matrix(android.graphics.Matrix) Animator(android.animation.Animator) ObjectAnimator(android.animation.ObjectAnimator) ValueAnimator(android.animation.ValueAnimator) AnimatorListenerAdapter(android.animation.AnimatorListenerAdapter) SurfaceParams(com.android.systemui.shared.system.SyncRtSurfaceTransactionApplierCompat.SurfaceParams)

Example 58 with FastBitmapDrawable

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

the class NormalizedIconLoader method getDefaultIcon.

@Override
public Drawable getDefaultIcon(int userId) {
    synchronized (mDefaultIcons) {
        BitmapInfo info = mDefaultIcons.get(userId);
        if (info == null) {
            info = getBitmapInfo(Resources.getSystem().getDrawable(android.R.drawable.sym_def_app_icon), userId, 0, false);
            mDefaultIcons.put(userId, info);
        }
        return new FastBitmapDrawable(info);
    }
}
Also used : FastBitmapDrawable(com.android.launcher3.FastBitmapDrawable) BitmapInfo(com.android.launcher3.icons.BitmapInfo)

Example 59 with FastBitmapDrawable

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

the class PendingAppWidgetHostView method reapplyItemInfo.

@Override
public void reapplyItemInfo(ItemInfoWithIcon info) {
    if (mCenterDrawable != null) {
        mCenterDrawable.setCallback(null);
        mCenterDrawable = null;
    }
    if (info.iconBitmap != null) {
        // The view displays three modes,
        // 1) App icon in the center
        // 2) Preload icon in the center
        // 3) Setup icon in the center and app icon in the top right corner.
        DrawableFactory drawableFactory = DrawableFactory.INSTANCE.get(getContext());
        if (mDisabledForSafeMode) {
            FastBitmapDrawable disabledIcon = drawableFactory.newIcon(getContext(), info);
            disabledIcon.setIsDisabled(true);
            mCenterDrawable = disabledIcon;
            mSettingIconDrawable = null;
        } else if (isReadyForClickSetup()) {
            mCenterDrawable = drawableFactory.newIcon(getContext(), info);
            mSettingIconDrawable = getResources().getDrawable(R.drawable.ic_setting).mutate();
            updateSettingColor(info.iconColor);
        } else {
            mCenterDrawable = DrawableFactory.INSTANCE.get(getContext()).newPendingIcon(getContext(), info);
            mSettingIconDrawable = null;
            applyState();
        }
        mCenterDrawable.setCallback(this);
        mDrawableSizeChanged = true;
    }
    invalidate();
}
Also used : FastBitmapDrawable(com.android.launcher3.FastBitmapDrawable) DrawableFactory(com.android.launcher3.graphics.DrawableFactory)

Example 60 with FastBitmapDrawable

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

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, false, /* flattenDrawable */
            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)

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