Search in sources :

Example 61 with FastBitmapDrawable

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

the class DrawableFactory method getBadgeForUser.

/**
 * Returns a drawable that can be used as a badge for the user or null.
 */
@UiThread
public Drawable getBadgeForUser(UserHandle user, Context context, int badgeSize) {
    if (mMyUser.equals(user)) {
        return null;
    }
    Bitmap badgeBitmap = getUserBadge(user, context, badgeSize);
    FastBitmapDrawable d = new FastBitmapDrawable(badgeBitmap);
    d.setFilterBitmap(true);
    d.setBounds(0, 0, badgeBitmap.getWidth(), badgeBitmap.getHeight());
    return d;
}
Also used : FastBitmapDrawable(com.android.launcher3.FastBitmapDrawable) Bitmap(android.graphics.Bitmap) UiThread(androidx.annotation.UiThread)

Example 62 with FastBitmapDrawable

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

the class DrawableFactory method newIcon.

/**
 * Returns a FastBitmapDrawable with the icon.
 */
public FastBitmapDrawable newIcon(ItemInfoWithIcon info) {
    FastBitmapDrawable drawable = new FastBitmapDrawable(info);
    drawable.setIsDisabled(info.isDisabled());
    return drawable;
}
Also used : FastBitmapDrawable(com.android.launcher3.FastBitmapDrawable)

Example 63 with FastBitmapDrawable

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

the class PendingAppWidgetHostView method reapplyItemInfo.

@Override
public void reapplyItemInfo(ItemInfoWithIcon info) {
    if (mCenterDrawable != null) {
        mCenterDrawable.setCallback(null);
        mCenterDrawable = null;
    }
    if (info.bitmap.icon != null) {
        // 3) Setup icon in the center and app icon in the top right corner.
        if (mDisabledForSafeMode) {
            FastBitmapDrawable disabledIcon = newIcon(getContext(), info);
            disabledIcon.setIsDisabled(true);
            mCenterDrawable = disabledIcon;
            mSettingIconDrawable = null;
        } else if (isReadyForClickSetup()) {
            mCenterDrawable = newIcon(getContext(), info);
            mSettingIconDrawable = getResources().getDrawable(R.drawable.ic_setting).mutate();
            updateSettingColor(info.bitmap.color);
        } else {
            mCenterDrawable = newPendingIcon(getContext(), info);
            mSettingIconDrawable = null;
            applyState();
        }
        mCenterDrawable.setCallback(this);
        mDrawableSizeChanged = true;
    }
    invalidate();
}
Also used : FastBitmapDrawable(com.android.launcher3.FastBitmapDrawable)

Example 64 with FastBitmapDrawable

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

the class QuickstepAppTransitionManagerImpl method getOpeningWindowAnimators.

/**
 * @return Animator that controls the window of the opening targets from app icons.
 */
private Animator getOpeningWindowAnimators(View v, RemoteAnimationTargetCompat[] appTargets, RemoteAnimationTargetCompat[] wallpaperTargets, 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();
    RemoteAnimationTargets openingTargets = new RemoteAnimationTargets(appTargets, wallpaperTargets, MODE_OPENING);
    SurfaceTransactionApplier surfaceApplier = new SurfaceTransactionApplier(floatingView);
    openingTargets.addReleaseCheck(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 iconBounds = new RectF();
    RectF temp = new RectF();
    Point tmpPos = new Point();
    AnimatorSet animatorSet = new AnimatorSet();
    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 mScale = 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 the size.
            float width = bounds.width() * mScale.value;
            float height = bounds.height() * mScale.value;
            // Animate the crop so that it starts off as a square.
            final int cropWidth;
            final int cropHeight;
            if (mDeviceProfile.isVerticalBarLayout()) {
                cropWidth = (int) mCroppedSize.value;
                cropHeight = windowTargetBounds.height();
            } else {
                cropWidth = windowTargetBounds.width();
                cropHeight = (int) mCroppedSize.value;
            }
            crop.set(0, 0, cropWidth, cropHeight);
            // Scale the size to match the crop.
            float scaleX = width / cropWidth;
            float scaleY = height / cropHeight;
            float scale = Math.min(1f, Math.max(scaleX, scaleY));
            float scaledCropWidth = cropWidth * scale;
            float scaledCropHeight = cropHeight * scale;
            float offsetX = (scaledCropWidth - width) / 2;
            float offsetY = (scaledCropHeight - height) / 2;
            // Calculate the window position.
            temp.set(bounds);
            temp.offset(dragLayerBounds[0], dragLayerBounds[1]);
            temp.offset(mDx.value, mDy.value);
            Utilities.scaleRectFAboutCenter(temp, mScale.value);
            float windowTransX0 = temp.left - offsetX;
            float windowTransY0 = temp.top - offsetY;
            // Calculate the icon position.
            iconBounds.set(bounds);
            iconBounds.offset(mDx.value, mDy.value);
            Utilities.scaleRectFAboutCenter(iconBounds, mScale.value);
            iconBounds.left -= offsetX;
            iconBounds.top -= offsetY;
            iconBounds.right += offsetX;
            iconBounds.bottom += offsetY;
            float croppedHeight = (windowTargetBounds.height() - crop.height()) * scale;
            float croppedWidth = (windowTargetBounds.width() - crop.width()) * scale;
            SurfaceParams[] params = new SurfaceParams[appTargets.length];
            for (int i = appTargets.length - 1; i >= 0; i--) {
                RemoteAnimationTargetCompat target = appTargets[i];
                SurfaceParams.Builder builder = new SurfaceParams.Builder(target.leash);
                if (target.mode == MODE_OPENING) {
                    matrix.setScale(scale, scale);
                    matrix.postTranslate(windowTransX0, windowTransY0);
                    floatingView.update(iconBounds, mIconAlpha.value, percent, 0f, mWindowRadius.value * scale, true);
                    builder.withMatrix(matrix).withWindowCrop(crop).withAlpha(1f - mIconAlpha.value).withCornerRadius(mWindowRadius.value);
                } else {
                    tmpPos.set(target.position.x, target.position.y);
                    if (target.localBounds != null) {
                        final Rect localBounds = target.localBounds;
                        tmpPos.set(target.localBounds.left, target.localBounds.top);
                    }
                    matrix.setTranslate(tmpPos.x, tmpPos.y);
                    final Rect crop = new Rect(target.screenSpaceBounds);
                    crop.offsetTo(0, 0);
                    builder.withMatrix(matrix).withWindowCrop(crop).withAlpha(1f);
                }
                params[i] = builder.build();
            }
            surfaceApplier.scheduleApply(params);
        }
    });
    // When launching an app from overview that doesn't map to a task, we still want to just
    // blur the wallpaper instead of the launcher surface as well
    boolean allowBlurringLauncher = mLauncher.getStateManager().getState() != OVERVIEW;
    DepthController depthController = mLauncher.getDepthController();
    ObjectAnimator backgroundRadiusAnim = ObjectAnimator.ofFloat(depthController, DEPTH, BACKGROUND_APP.getDepth(mLauncher)).setDuration(APP_LAUNCH_DURATION);
    if (allowBlurringLauncher) {
        depthController.setSurfaceToApp(RemoteAnimationProvider.findLowestOpaqueLayerTarget(appTargets, MODE_OPENING));
        backgroundRadiusAnim.addListener(new AnimatorListenerAdapter() {

            @Override
            public void onAnimationEnd(Animator animation) {
                depthController.setSurfaceToApp(null);
            }
        });
    }
    animatorSet.playTogether(appAnimator, backgroundRadiusAnim);
    return animatorSet;
}
Also used : FloatingIconView(com.android.launcher3.views.FloatingIconView) RemoteAnimationTargets(com.android.quickstep.RemoteAnimationTargets) AnimatorSet(android.animation.AnimatorSet) ValueAnimator(android.animation.ValueAnimator) DepthController(com.android.launcher3.statehandlers.DepthController) DeepShortcutView(com.android.launcher3.shortcuts.DeepShortcutView) MultiValueUpdateListener(com.android.quickstep.util.MultiValueUpdateListener) Matrix(android.graphics.Matrix) SurfaceTransactionApplier(com.android.quickstep.util.SurfaceTransactionApplier) AnimatorListenerAdapter(android.animation.AnimatorListenerAdapter) SurfaceParams(com.android.systemui.shared.system.SyncRtSurfaceTransactionApplierCompat.SurfaceParams) Rect(android.graphics.Rect) ObjectAnimator(android.animation.ObjectAnimator) RemoteAnimationTargetCompat(com.android.systemui.shared.system.RemoteAnimationTargetCompat) Drawable(android.graphics.drawable.Drawable) Point(android.graphics.Point) RectF(android.graphics.RectF) Animator(android.animation.Animator) ObjectAnimator(android.animation.ObjectAnimator) ValueAnimator(android.animation.ValueAnimator)

Example 65 with FastBitmapDrawable

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

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);
    TaskOverlayFactory.getEnabledShortcuts(taskView).forEach(this::addMenuOption);
}
Also used : FastBitmapDrawable(com.android.launcher3.FastBitmapDrawable) Drawable(android.graphics.drawable.Drawable) FastBitmapDrawable(com.android.launcher3.FastBitmapDrawable) LinearLayout(android.widget.LinearLayout)

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