Search in sources :

Example 6 with DepthController

use of com.android.launcher3.statehandlers.DepthController in project android_packages_apps_Launcher3 by crdroidandroid.

the class TaskViewUtils method createRecentsWindowAnimator.

/**
 * Creates an animation that controls the window of the opening targets for the recents launch
 * animation.
 */
public static void createRecentsWindowAnimator(TaskView v, boolean skipViewChanges, RemoteAnimationTargetCompat[] appTargets, RemoteAnimationTargetCompat[] wallpaperTargets, RemoteAnimationTargetCompat[] nonAppTargets, DepthController depthController, PendingAnimation out, @Nullable TransformParams params, @Nullable TaskViewSimulator tsv) {
    boolean isQuickSwitch = v.isEndQuickswitchCuj();
    v.setEndQuickswitchCuj(false);
    boolean inLiveTileMode = ENABLE_QUICKSTEP_LIVE_TILE.get() && v.getRecentsView().getRunningTaskIndex() != -1;
    final RemoteAnimationTargets targets = new RemoteAnimationTargets(appTargets, wallpaperTargets, nonAppTargets, inLiveTileMode ? MODE_CLOSING : MODE_OPENING);
    final RemoteAnimationTargetCompat navBarTarget = targets.getNavBarRemoteAnimationTarget();
    if (params == null) {
        SurfaceTransactionApplier applier = new SurfaceTransactionApplier(v);
        targets.addReleaseCheck(applier);
        params = new TransformParams().setSyncTransactionApplier(applier).setTargetSet(targets);
    }
    final RecentsView recentsView = v.getRecentsView();
    int taskIndex = recentsView.indexOfChild(v);
    Context context = v.getContext();
    DeviceProfile dp = BaseActivity.fromContext(context).getDeviceProfile();
    boolean showAsGrid = dp.isTablet && FeatureFlags.ENABLE_OVERVIEW_GRID.get();
    boolean parallaxCenterAndAdjacentTask = taskIndex != recentsView.getCurrentPage() && !showAsGrid;
    float gridTranslationSecondary = recentsView.getGridTranslationSecondary(taskIndex);
    int startScroll = recentsView.getScrollOffset(taskIndex);
    TaskViewSimulator topMostSimulator = null;
    if (tsv == null && targets.apps.length > 0) {
        tsv = new TaskViewSimulator(context, recentsView.getSizeStrategy());
        tsv.setDp(dp);
        // RecentsView never updates the display rotation until swipe-up so the value may
        // be stale. Use the display value instead.
        int displayRotation = DisplayController.INSTANCE.get(context).getInfo().rotation;
        tsv.getOrientationState().update(displayRotation, displayRotation);
        tsv.setPreview(targets.apps[targets.apps.length - 1]);
        tsv.fullScreenProgress.value = 0;
        tsv.recentsViewScale.value = 1;
        if (showAsGrid) {
            tsv.taskSecondaryTranslation.value = gridTranslationSecondary;
        }
        tsv.setScroll(startScroll);
        // Fade in the task during the initial 20% of the animation
        out.addFloat(params, TransformParams.TARGET_ALPHA, 0, 1, clampToProgress(LINEAR, 0, 0.2f));
    }
    if (tsv != null) {
        out.setFloat(tsv.fullScreenProgress, AnimatedFloat.VALUE, 1, TOUCH_RESPONSE_INTERPOLATOR);
        out.setFloat(tsv.recentsViewScale, AnimatedFloat.VALUE, tsv.getFullScreenScale(), TOUCH_RESPONSE_INTERPOLATOR);
        if (showAsGrid) {
            out.setFloat(tsv.taskSecondaryTranslation, AnimatedFloat.VALUE, 0, TOUCH_RESPONSE_INTERPOLATOR_ACCEL_DEACCEL);
        }
        out.setFloat(tsv.recentsViewScroll, AnimatedFloat.VALUE, 0, TOUCH_RESPONSE_INTERPOLATOR);
        TaskViewSimulator finalTsv = tsv;
        TransformParams finalParams = params;
        out.addOnFrameCallback(() -> finalTsv.apply(finalParams));
        if (navBarTarget != null) {
            final Rect cropRect = new Rect();
            out.addOnFrameListener(new MultiValueUpdateListener() {

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

                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) {
                    final SurfaceParams.Builder navBuilder = new SurfaceParams.Builder(navBarTarget.leash);
                    if (mNavFadeIn.value > mNavFadeIn.getStartValue()) {
                        finalTsv.getCurrentCropRect().round(cropRect);
                        navBuilder.withMatrix(finalTsv.getCurrentMatrix()).withWindowCrop(cropRect).withAlpha(mNavFadeIn.value);
                    } else {
                        navBuilder.withAlpha(mNavFadeOut.value);
                    }
                    finalParams.applySurfaceParams(navBuilder.build());
                }
            });
        } else if (inLiveTileMode) {
            // There is no transition animation for app launch from recent in live tile mode so
            // we have to trigger the navigation bar animation from system here.
            final RecentsAnimationController controller = recentsView.getRecentsAnimationController();
            if (controller != null) {
                controller.animateNavigationBarToApp(RECENTS_LAUNCH_DURATION);
            }
        }
        topMostSimulator = tsv;
    }
    if (!skipViewChanges && parallaxCenterAndAdjacentTask && topMostSimulator != null) {
        out.addFloat(v, VIEW_ALPHA, 1, 0, clampToProgress(LINEAR, 0.2f, 0.4f));
        TaskViewSimulator simulatorToCopy = topMostSimulator;
        simulatorToCopy.apply(params);
        // Mt represents the overall transformation on the thumbnailView relative to the
        // Launcher's rootView
        // K(t) represents transformation on the running window by the taskViewSimulator at
        // any time t.
        // at t = 0, we know that the simulator matches the thumbnailView. So if we apply K(0)`
        // on the Launcher's rootView, the thumbnailView would match the full running task
        // window. If we apply "K(0)` K(t)" thumbnailView will match the final transformed
        // window at any time t. This gives the overall matrix on thumbnailView to be:
        // Mt K(0)` K(t)
        // During animation we apply transformation on the thumbnailView (and not the rootView)
        // to follow the TaskViewSimulator. So the final matrix applied on the thumbnailView is:
        // Mt K(0)` K(t) Mt`
        TaskThumbnailView ttv = v.getThumbnail();
        RectF tvBounds = new RectF(0, 0, ttv.getWidth(), ttv.getHeight());
        float[] tvBoundsMapped = new float[] { 0, 0, ttv.getWidth(), ttv.getHeight() };
        getDescendantCoordRelativeToAncestor(ttv, ttv.getRootView(), tvBoundsMapped, false);
        RectF tvBoundsInRoot = new RectF(tvBoundsMapped[0], tvBoundsMapped[1], tvBoundsMapped[2], tvBoundsMapped[3]);
        Matrix mt = new Matrix();
        mt.setRectToRect(tvBounds, tvBoundsInRoot, ScaleToFit.FILL);
        Matrix mti = new Matrix();
        mt.invert(mti);
        Matrix k0i = new Matrix();
        simulatorToCopy.getCurrentMatrix().invert(k0i);
        Matrix animationMatrix = new Matrix();
        out.addOnFrameCallback(() -> {
            animationMatrix.set(mt);
            animationMatrix.postConcat(k0i);
            animationMatrix.postConcat(simulatorToCopy.getCurrentMatrix());
            animationMatrix.postConcat(mti);
            ttv.setAnimationMatrix(animationMatrix);
        });
        out.addListener(new AnimatorListenerAdapter() {

            @Override
            public void onAnimationEnd(Animator animation) {
                ttv.setAnimationMatrix(null);
            }
        });
    }
    out.addListener(new AnimationSuccessListener() {

        @Override
        public void onAnimationSuccess(Animator animator) {
            if (isQuickSwitch) {
                InteractionJankMonitorWrapper.end(InteractionJankMonitorWrapper.CUJ_QUICK_SWITCH);
            }
        }

        @Override
        public void onAnimationEnd(Animator animation) {
            targets.release();
            super.onAnimationEnd(animation);
        }
    });
    if (depthController != null) {
        out.setFloat(depthController, DEPTH, BACKGROUND_APP.getDepth(context), TOUCH_RESPONSE_INTERPOLATOR);
    }
}
Also used : DeviceProfile(com.android.launcher3.DeviceProfile) MultiValueUpdateListener(com.android.quickstep.util.MultiValueUpdateListener) SurfaceTransactionApplier(com.android.quickstep.util.SurfaceTransactionApplier) Matrix(android.graphics.Matrix) AnimatorListenerAdapter(android.animation.AnimatorListenerAdapter) SurfaceParams(com.android.systemui.shared.system.SyncRtSurfaceTransactionApplierCompat.SurfaceParams) AnimationSuccessListener(com.android.launcher3.anim.AnimationSuccessListener) Context(android.content.Context) Rect(android.graphics.Rect) TaskViewSimulator(com.android.quickstep.util.TaskViewSimulator) RemoteAnimationTargetCompat(com.android.systemui.shared.system.RemoteAnimationTargetCompat) RectF(android.graphics.RectF) Animator(android.animation.Animator) ObjectAnimator(android.animation.ObjectAnimator) TransformParams(com.android.quickstep.util.TransformParams) RecentsView(com.android.quickstep.views.RecentsView) TaskThumbnailView(com.android.quickstep.views.TaskThumbnailView)

Example 7 with DepthController

use of com.android.launcher3.statehandlers.DepthController in project android_packages_apps_Launcher3 by crdroidandroid.

the class RecentsActivity method composeRecentsLaunchAnimator.

/**
 * Composes the animations for a launch from the recents list if possible.
 */
private AnimatorSet composeRecentsLaunchAnimator(TaskView taskView, RemoteAnimationTargetCompat[] appTargets, RemoteAnimationTargetCompat[] wallpaperTargets, RemoteAnimationTargetCompat[] nonAppTargets) {
    AnimatorSet target = new AnimatorSet();
    boolean activityClosing = taskIsATargetWithMode(appTargets, getTaskId(), MODE_CLOSING);
    PendingAnimation pa = new PendingAnimation(RECENTS_LAUNCH_DURATION);
    createRecentsWindowAnimator(taskView, !activityClosing, appTargets, wallpaperTargets, nonAppTargets, null, /* depthController */
    pa);
    target.play(pa.buildAnim());
    // Found a visible recents task that matches the opening app, lets launch the app from there
    if (activityClosing) {
        Animator adjacentAnimation = mFallbackRecentsView.createAdjacentPageAnimForTaskLaunch(taskView);
        adjacentAnimation.setInterpolator(Interpolators.TOUCH_RESPONSE_INTERPOLATOR);
        adjacentAnimation.setDuration(RECENTS_LAUNCH_DURATION);
        adjacentAnimation.addListener(resetStateListener());
        target.play(adjacentAnimation);
    }
    return target;
}
Also used : PendingAnimation(com.android.launcher3.anim.PendingAnimation) Animator(android.animation.Animator) TaskViewUtils.createRecentsWindowAnimator(com.android.quickstep.TaskViewUtils.createRecentsWindowAnimator) AnimatorSet(android.animation.AnimatorSet)

Aggregations

PendingAnimation (com.android.launcher3.anim.PendingAnimation)5 Animator (android.animation.Animator)4 ObjectAnimator (android.animation.ObjectAnimator)4 AnimatorListenerAdapter (android.animation.AnimatorListenerAdapter)3 Context (android.content.Context)3 DeviceProfile (com.android.launcher3.DeviceProfile)3 DepthController (com.android.launcher3.statehandlers.DepthController)3 AnimatorSet (android.animation.AnimatorSet)2 ValueAnimator (android.animation.ValueAnimator)2 Rect (android.graphics.Rect)2 SurfaceTransactionApplier (com.android.quickstep.util.SurfaceTransactionApplier)2 TaskViewSimulator (com.android.quickstep.util.TaskViewSimulator)2 TransformParams (com.android.quickstep.util.TransformParams)2 RecentsView (com.android.quickstep.views.RecentsView)2 Matrix (android.graphics.Matrix)1 Point (android.graphics.Point)1 RectF (android.graphics.RectF)1 TextPaint (android.text.TextPaint)1 SurfaceControl (android.view.SurfaceControl)1 ViewRootImpl (android.view.ViewRootImpl)1