Search in sources :

Example 1 with FloatingWidgetView

use of com.android.quickstep.views.FloatingWidgetView in project android_packages_apps_Launcher3 by crdroidandroid.

the class QuickstepTransitionManager method getOpeningWindowAnimatorsForWidget.

private Animator getOpeningWindowAnimatorsForWidget(LauncherAppWidgetHostView v, RemoteAnimationTargetCompat[] appTargets, RemoteAnimationTargetCompat[] wallpaperTargets, RemoteAnimationTargetCompat[] nonAppTargets, Rect windowTargetBounds, boolean appTargetsAreTranslucent) {
    final RectF widgetBackgroundBounds = new RectF();
    final Rect appWindowCrop = new Rect();
    final Matrix matrix = new Matrix();
    RemoteAnimationTargets openingTargets = new RemoteAnimationTargets(appTargets, wallpaperTargets, nonAppTargets, MODE_OPENING);
    RemoteAnimationTargetCompat openingTarget = openingTargets.getFirstAppTarget();
    int fallbackBackgroundColor = 0;
    if (openingTarget != null && supportsSSplashScreen()) {
        fallbackBackgroundColor = mTaskStartParams.containsKey(openingTarget.taskId) ? mTaskStartParams.get(openingTarget.taskId).second : 0;
        mTaskStartParams.remove(openingTarget.taskId);
    }
    if (fallbackBackgroundColor == 0) {
        fallbackBackgroundColor = FloatingWidgetView.getDefaultBackgroundColor(mLauncher, openingTarget);
    }
    final float finalWindowRadius = mDeviceProfile.isMultiWindowMode ? 0 : getWindowCornerRadius(mLauncher.getResources());
    final FloatingWidgetView floatingView = FloatingWidgetView.getFloatingWidgetView(mLauncher, v, widgetBackgroundBounds, new Size(windowTargetBounds.width(), windowTargetBounds.height()), finalWindowRadius, appTargetsAreTranslucent, fallbackBackgroundColor);
    final float initialWindowRadius = supportsRoundedCornersOnWindows(mLauncher.getResources()) ? floatingView.getInitialCornerRadius() : 0;
    SurfaceTransactionApplier surfaceApplier = new SurfaceTransactionApplier(floatingView);
    openingTargets.addReleaseCheck(surfaceApplier);
    RemoteAnimationTargetCompat navBarTarget = openingTargets.getNavBarRemoteAnimationTarget();
    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) {
            openingTargets.release();
        }
    });
    floatingView.setFastFinishRunnable(animatorSet::end);
    appAnimator.addUpdateListener(new MultiValueUpdateListener() {

        float mAppWindowScale = 1;

        final FloatProp mWidgetForegroundAlpha = new FloatProp(1, /* start */
        0, /* end */
        0, /* delay */
        WIDGET_CROSSFADE_DURATION_MILLIS / 2, /* duration */
        LINEAR);

        final FloatProp mWidgetFallbackBackgroundAlpha = new FloatProp(0, /* start */
        1, /* end */
        0, /* delay */
        75, /* duration */
        LINEAR);

        final FloatProp mPreviewAlpha = new FloatProp(0, /* start */
        1, /* end */
        WIDGET_CROSSFADE_DURATION_MILLIS / 2, /* delay */
        WIDGET_CROSSFADE_DURATION_MILLIS / 2, /* duration */
        LINEAR);

        final FloatProp mWindowRadius = new FloatProp(initialWindowRadius, finalWindowRadius, 0, /* start */
        APP_LAUNCH_DURATION, mOpeningInterpolator);

        final FloatProp mCornerRadiusProgress = new FloatProp(0, 1, 0, APP_LAUNCH_DURATION, mOpeningInterpolator);

        // Window & widget background positioning bounds
        final FloatProp mDx = new FloatProp(widgetBackgroundBounds.centerX(), windowTargetBounds.centerX(), 0, /* delay */
        APP_LAUNCH_DURATION, mOpeningXInterpolator);

        final FloatProp mDy = new FloatProp(widgetBackgroundBounds.centerY(), windowTargetBounds.centerY(), 0, /* delay */
        APP_LAUNCH_DURATION, mOpeningInterpolator);

        final FloatProp mWidth = new FloatProp(widgetBackgroundBounds.width(), windowTargetBounds.width(), 0, /* delay */
        APP_LAUNCH_DURATION, mOpeningInterpolator);

        final FloatProp mHeight = new FloatProp(widgetBackgroundBounds.height(), windowTargetBounds.height(), 0, /* delay */
        APP_LAUNCH_DURATION, mOpeningInterpolator);

        final FloatProp mNavFadeOut = new FloatProp(1f, 0f, 0, ANIMATION_NAV_FADE_OUT_DURATION, NAV_FADE_OUT_INTERPOLATOR);

        final FloatProp mNavFadeIn = new FloatProp(0f, 1f, ANIMATION_DELAY_NAV_FADE_IN, ANIMATION_NAV_FADE_IN_DURATION, NAV_FADE_IN_INTERPOLATOR);

        @Override
        public void onUpdate(float percent, boolean initOnly) {
            widgetBackgroundBounds.set(mDx.value - mWidth.value / 2f, mDy.value - mHeight.value / 2f, mDx.value + mWidth.value / 2f, mDy.value + mHeight.value / 2f);
            // Set app window scaling factor to match widget background width
            mAppWindowScale = widgetBackgroundBounds.width() / windowTargetBounds.width();
            // Crop scaled app window to match widget
            appWindowCrop.set(0, /* left */
            0, /* top */
            Math.round(windowTargetBounds.width()), /* right */
            Math.round(widgetBackgroundBounds.height() / mAppWindowScale));
            matrix.setTranslate(widgetBackgroundBounds.left, widgetBackgroundBounds.top);
            matrix.postScale(mAppWindowScale, mAppWindowScale, widgetBackgroundBounds.left, widgetBackgroundBounds.top);
            ArrayList<SurfaceParams> params = new ArrayList<>();
            float floatingViewAlpha = appTargetsAreTranslucent ? 1 - mPreviewAlpha.value : 1;
            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) {
                    floatingView.update(widgetBackgroundBounds, floatingViewAlpha, mWidgetForegroundAlpha.value, mWidgetFallbackBackgroundAlpha.value, mCornerRadiusProgress.value);
                    builder.withMatrix(matrix).withWindowCrop(appWindowCrop).withAlpha(mPreviewAlpha.value).withCornerRadius(mWindowRadius.value / mAppWindowScale);
                }
                params.add(builder.build());
            }
            if (navBarTarget != null) {
                final SurfaceParams.Builder navBuilder = new SurfaceParams.Builder(navBarTarget.leash);
                if (mNavFadeIn.value > mNavFadeIn.getStartValue()) {
                    navBuilder.withMatrix(matrix).withWindowCrop(appWindowCrop).withAlpha(mNavFadeIn.value);
                } else {
                    navBuilder.withAlpha(mNavFadeOut.value);
                }
                params.add(navBuilder.build());
            }
            surfaceApplier.scheduleApply(params.toArray(new SurfaceParams[params.size()]));
        }
    });
    animatorSet.playTogether(appAnimator, getBackgroundAnimator(appTargets));
    return animatorSet;
}
Also used : Rect(android.graphics.Rect) FloatingWidgetView(com.android.quickstep.views.FloatingWidgetView) Size(android.util.Size) RemoteAnimationTargetCompat(com.android.systemui.shared.system.RemoteAnimationTargetCompat) ArrayList(java.util.ArrayList) RemoteAnimationTargets(com.android.quickstep.RemoteAnimationTargets) AnimatorSet(android.animation.AnimatorSet) ValueAnimator(android.animation.ValueAnimator) Point(android.graphics.Point) RectF(android.graphics.RectF) MultiValueUpdateListener(com.android.quickstep.util.MultiValueUpdateListener) Matrix(android.graphics.Matrix) SurfaceTransactionApplier(com.android.quickstep.util.SurfaceTransactionApplier) ValueAnimator(android.animation.ValueAnimator) Animator(android.animation.Animator) ObjectAnimator(android.animation.ObjectAnimator) AnimatorListenerAdapter(android.animation.AnimatorListenerAdapter) SurfaceParams(com.android.systemui.shared.system.SyncRtSurfaceTransactionApplierCompat.SurfaceParams)

Example 2 with FloatingWidgetView

use of com.android.quickstep.views.FloatingWidgetView in project android_packages_apps_Launcher3 by crdroidandroid.

the class LauncherSwipeHandlerV2 method createWidgetHomeAnimationFactory.

private HomeAnimationFactory createWidgetHomeAnimationFactory(LauncherAppWidgetHostView hostView, boolean isTargetTranslucent, RemoteAnimationTargetCompat runningTaskTarget) {
    final float floatingWidgetAlpha = isTargetTranslucent ? 0 : 1;
    RectF backgroundLocation = new RectF();
    Rect crop = new Rect();
    mTaskViewSimulator.getCurrentCropRect().roundOut(crop);
    Size windowSize = new Size(crop.width(), crop.height());
    int fallbackBackgroundColor = FloatingWidgetView.getDefaultBackgroundColor(mContext, runningTaskTarget);
    FloatingWidgetView floatingWidgetView = FloatingWidgetView.getFloatingWidgetView(mActivity, hostView, backgroundLocation, windowSize, mTaskViewSimulator.getCurrentCornerRadius(), isTargetTranslucent, fallbackBackgroundColor);
    return new FloatingViewHomeAnimationFactory(floatingWidgetView) {

        @Override
        @Nullable
        protected View getViewIgnoredInWorkspaceRevealAnimation() {
            return hostView;
        }

        @Override
        public RectF getWindowTargetRect() {
            super.getWindowTargetRect();
            return backgroundLocation;
        }

        @Override
        public float getEndRadius(RectF cropRectF) {
            return floatingWidgetView.getInitialCornerRadius();
        }

        @Override
        public void setAnimation(RectFSpringAnim anim) {
            super.setAnimation(anim);
            anim.addAnimatorListener(floatingWidgetView);
            floatingWidgetView.setOnTargetChangeListener(anim::onTargetPositionChanged);
            floatingWidgetView.setFastFinishRunnable(anim::end);
        }

        @Override
        public boolean keepWindowOpaque() {
            return false;
        }

        @Override
        public void update(@Nullable AppCloseConfig config, RectF currentRect, float progress, float radius) {
            super.update(config, currentRect, progress, radius);
            final float fallbackBackgroundAlpha = 1 - mapBoundToRange(progress, 0.8f, 1, 0, 1, EXAGGERATED_EASE);
            final float foregroundAlpha = mapBoundToRange(progress, 0.5f, 1, 0, 1, EXAGGERATED_EASE);
            floatingWidgetView.update(currentRect, floatingWidgetAlpha, foregroundAlpha, fallbackBackgroundAlpha, 1 - progress);
        }

        @Override
        protected float getWindowAlpha(float progress) {
            return 1 - mapBoundToRange(progress, 0, 0.5f, 0, 1, LINEAR);
        }
    };
}
Also used : RectF(android.graphics.RectF) RectFSpringAnim(com.android.quickstep.util.RectFSpringAnim) Rect(android.graphics.Rect) Size(android.util.Size) FloatingWidgetView(com.android.quickstep.views.FloatingWidgetView) AppCloseConfig(com.android.quickstep.util.AppCloseConfig) Nullable(androidx.annotation.Nullable)

Aggregations

Rect (android.graphics.Rect)2 RectF (android.graphics.RectF)2 Size (android.util.Size)2 FloatingWidgetView (com.android.quickstep.views.FloatingWidgetView)2 Animator (android.animation.Animator)1 AnimatorListenerAdapter (android.animation.AnimatorListenerAdapter)1 AnimatorSet (android.animation.AnimatorSet)1 ObjectAnimator (android.animation.ObjectAnimator)1 ValueAnimator (android.animation.ValueAnimator)1 Matrix (android.graphics.Matrix)1 Point (android.graphics.Point)1 Nullable (androidx.annotation.Nullable)1 RemoteAnimationTargets (com.android.quickstep.RemoteAnimationTargets)1 AppCloseConfig (com.android.quickstep.util.AppCloseConfig)1 MultiValueUpdateListener (com.android.quickstep.util.MultiValueUpdateListener)1 RectFSpringAnim (com.android.quickstep.util.RectFSpringAnim)1 SurfaceTransactionApplier (com.android.quickstep.util.SurfaceTransactionApplier)1 RemoteAnimationTargetCompat (com.android.systemui.shared.system.RemoteAnimationTargetCompat)1 SurfaceParams (com.android.systemui.shared.system.SyncRtSurfaceTransactionApplierCompat.SurfaceParams)1 ArrayList (java.util.ArrayList)1