Search in sources :

Example 1 with RemoteAnimationTargetCompat

use of com.android.systemui.shared.system.RemoteAnimationTargetCompat in project android_packages_apps_Launcher3 by crdroidandroid.

the class LauncherInitListener method handleInit.

@Override
public boolean handleInit(Launcher launcher, boolean alreadyOnHome) {
    if (mRemoteAnimationProvider != null) {
        QuickstepTransitionManager appTransitionManager = ((BaseQuickstepLauncher) launcher).getAppTransitionManager();
        // Set a one-time animation provider. After the first call, this will get cleared.
        // TODO: Probably also check the intended target id.
        CancellationSignal cancellationSignal = new CancellationSignal();
        appTransitionManager.setRemoteAnimationProvider(new RemoteAnimationProvider() {

            @Override
            public AnimatorSet createWindowAnimation(RemoteAnimationTargetCompat[] appTargets, RemoteAnimationTargetCompat[] wallpaperTargets) {
                // On the first call clear the reference.
                cancellationSignal.cancel();
                RemoteAnimationProvider provider = mRemoteAnimationProvider;
                mRemoteAnimationProvider = null;
                if (provider != null && launcher.getStateManager().getState().overviewUi) {
                    return provider.createWindowAnimation(appTargets, wallpaperTargets);
                }
                return null;
            }
        }, cancellationSignal);
    }
    launcher.deferOverlayCallbacksUntilNextResumeOrStop();
    return super.handleInit(launcher, alreadyOnHome);
}
Also used : RemoteAnimationTargetCompat(com.android.systemui.shared.system.RemoteAnimationTargetCompat) AnimatorSet(android.animation.AnimatorSet) CancellationSignal(android.os.CancellationSignal) RemoteAnimationProvider(com.android.quickstep.util.RemoteAnimationProvider)

Example 2 with RemoteAnimationTargetCompat

use of com.android.systemui.shared.system.RemoteAnimationTargetCompat in project android_packages_apps_Launcher3 by crdroidandroid.

the class QuickstepTransitionManager method getUnlockWindowAnimator.

/**
 * Animator that controls the transformations of the windows when unlocking the device.
 */
private Animator getUnlockWindowAnimator(RemoteAnimationTargetCompat[] appTargets, RemoteAnimationTargetCompat[] wallpaperTargets) {
    SurfaceTransactionApplier surfaceApplier = new SurfaceTransactionApplier(mDragLayer);
    ValueAnimator unlockAnimator = ValueAnimator.ofFloat(0, 1);
    unlockAnimator.setDuration(CLOSING_TRANSITION_DURATION_MS);
    float cornerRadius = mDeviceProfile.isMultiWindowMode ? 0 : QuickStepContract.getWindowCornerRadius(mLauncher.getResources());
    unlockAnimator.addListener(new AnimatorListenerAdapter() {

        @Override
        public void onAnimationStart(Animator animation) {
            SurfaceParams[] params = new SurfaceParams[appTargets.length];
            for (int i = appTargets.length - 1; i >= 0; i--) {
                RemoteAnimationTargetCompat target = appTargets[i];
                params[i] = new SurfaceParams.Builder(target.leash).withAlpha(1f).withWindowCrop(target.screenSpaceBounds).withCornerRadius(cornerRadius).build();
            }
            surfaceApplier.scheduleApply(params);
        }
    });
    return unlockAnimator;
}
Also used : SurfaceTransactionApplier(com.android.quickstep.util.SurfaceTransactionApplier) ValueAnimator(android.animation.ValueAnimator) Animator(android.animation.Animator) ObjectAnimator(android.animation.ObjectAnimator) AnimatorListenerAdapter(android.animation.AnimatorListenerAdapter) RemoteAnimationTargetCompat(com.android.systemui.shared.system.RemoteAnimationTargetCompat) ValueAnimator(android.animation.ValueAnimator)

Example 3 with RemoteAnimationTargetCompat

use of com.android.systemui.shared.system.RemoteAnimationTargetCompat in project android_packages_apps_Launcher3 by crdroidandroid.

the class QuickstepTransitionManager method getOpeningWindowAnimators.

/**
 * @return Animator that controls the window of the opening targets from app icons.
 */
private Animator getOpeningWindowAnimators(View v, RemoteAnimationTargetCompat[] appTargets, RemoteAnimationTargetCompat[] wallpaperTargets, RemoteAnimationTargetCompat[] nonAppTargets, Rect windowTargetBounds, boolean appTargetsAreTranslucent, int rotationChange) {
    RectF launcherIconBounds = new RectF();
    FloatingIconView floatingView = FloatingIconView.getFloatingIconView(mLauncher, v, !appTargetsAreTranslucent, launcherIconBounds, true);
    Rect crop = new Rect();
    Matrix matrix = new Matrix();
    RemoteAnimationTargets openingTargets = new RemoteAnimationTargets(appTargets, wallpaperTargets, nonAppTargets, MODE_OPENING);
    SurfaceTransactionApplier surfaceApplier = new SurfaceTransactionApplier(floatingView);
    openingTargets.addReleaseCheck(surfaceApplier);
    RemoteAnimationTargetCompat navBarTarget = openingTargets.getNavBarRemoteAnimationTarget();
    int[] dragLayerBounds = new int[2];
    mDragLayer.getLocationOnScreen(dragLayerBounds);
    final boolean hasSplashScreen;
    if (supportsSSplashScreen()) {
        int taskId = openingTargets.getFirstAppTargetTaskId();
        Pair<Integer, Integer> defaultParams = Pair.create(STARTING_WINDOW_TYPE_NONE, 0);
        Pair<Integer, Integer> taskParams = mTaskStartParams.getOrDefault(taskId, defaultParams);
        mTaskStartParams.remove(taskId);
        hasSplashScreen = taskParams.first == STARTING_WINDOW_TYPE_SPLASH_SCREEN;
    } else {
        hasSplashScreen = false;
    }
    AnimOpenProperties prop = new AnimOpenProperties(mLauncher.getResources(), mDeviceProfile, windowTargetBounds, launcherIconBounds, v, dragLayerBounds[0], dragLayerBounds[1], hasSplashScreen, floatingView.isDifferentFromAppIcon());
    int left = (int) (prop.cropCenterXStart - prop.cropWidthStart / 2);
    int top = (int) (prop.cropCenterYStart - prop.cropHeightStart / 2);
    int right = (int) (left + prop.cropWidthStart);
    int bottom = (int) (top + prop.cropHeightStart);
    // Set the crop here so we can calculate the corner radius below.
    crop.set(left, top, right, bottom);
    RectF floatingIconBounds = new RectF();
    RectF tmpRectF = 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();
        }
    });
    final float initialWindowRadius = supportsRoundedCornersOnWindows(mLauncher.getResources()) ? Math.max(crop.width(), crop.height()) / 2f : 0f;
    final float finalWindowRadius = mDeviceProfile.isMultiWindowMode ? 0 : getWindowCornerRadius(mLauncher.getResources());
    final float finalShadowRadius = appTargetsAreTranslucent ? 0 : mMaxShadowRadius;
    MultiValueUpdateListener listener = new MultiValueUpdateListener() {

        FloatProp mDx = new FloatProp(0, prop.dX, 0, APP_LAUNCH_DURATION, mOpeningXInterpolator);

        FloatProp mDy = new FloatProp(0, prop.dY, 0, APP_LAUNCH_DURATION, mOpeningInterpolator);

        FloatProp mIconScaleToFitScreen = new FloatProp(prop.initialAppIconScale, prop.finalAppIconScale, 0, APP_LAUNCH_DURATION, mOpeningInterpolator);

        FloatProp mIconAlpha = new FloatProp(prop.iconAlphaStart, 0f, APP_LAUNCH_ALPHA_START_DELAY, APP_LAUNCH_ALPHA_DURATION, LINEAR);

        FloatProp mWindowRadius = new FloatProp(initialWindowRadius, finalWindowRadius, 0, APP_LAUNCH_DURATION, mOpeningInterpolator);

        FloatProp mShadowRadius = new FloatProp(0, finalShadowRadius, 0, APP_LAUNCH_DURATION, mOpeningInterpolator);

        FloatProp mCropRectCenterX = new FloatProp(prop.cropCenterXStart, prop.cropCenterXEnd, 0, APP_LAUNCH_DURATION, mOpeningInterpolator);

        FloatProp mCropRectCenterY = new FloatProp(prop.cropCenterYStart, prop.cropCenterYEnd, 0, APP_LAUNCH_DURATION, mOpeningInterpolator);

        FloatProp mCropRectWidth = new FloatProp(prop.cropWidthStart, prop.cropWidthEnd, 0, APP_LAUNCH_DURATION, mOpeningInterpolator);

        FloatProp mCropRectHeight = new FloatProp(prop.cropHeightStart, prop.cropHeightEnd, 0, APP_LAUNCH_DURATION, mOpeningInterpolator);

        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) {
            // Calculate the size of the scaled icon.
            float iconWidth = launcherIconBounds.width() * mIconScaleToFitScreen.value;
            float iconHeight = launcherIconBounds.height() * mIconScaleToFitScreen.value;
            int left = (int) (mCropRectCenterX.value - mCropRectWidth.value / 2);
            int top = (int) (mCropRectCenterY.value - mCropRectHeight.value / 2);
            int right = (int) (left + mCropRectWidth.value);
            int bottom = (int) (top + mCropRectHeight.value);
            crop.set(left, top, right, bottom);
            final int windowCropWidth = crop.width();
            final int windowCropHeight = crop.height();
            if (rotationChange != 0) {
                Utilities.rotateBounds(crop, mDeviceProfile.widthPx, mDeviceProfile.heightPx, rotationChange);
            }
            // Scale the size of the icon to match the size of the window crop.
            float scaleX = iconWidth / windowCropWidth;
            float scaleY = iconHeight / windowCropHeight;
            float scale = Math.min(1f, Math.max(scaleX, scaleY));
            float scaledCropWidth = windowCropWidth * scale;
            float scaledCropHeight = windowCropHeight * scale;
            float offsetX = (scaledCropWidth - iconWidth) / 2;
            float offsetY = (scaledCropHeight - iconHeight) / 2;
            // Calculate the window position to match the icon position.
            tmpRectF.set(launcherIconBounds);
            tmpRectF.offset(dragLayerBounds[0], dragLayerBounds[1]);
            tmpRectF.offset(mDx.value, mDy.value);
            Utilities.scaleRectFAboutCenter(tmpRectF, mIconScaleToFitScreen.value);
            float windowTransX0 = tmpRectF.left - offsetX - crop.left * scale;
            float windowTransY0 = tmpRectF.top - offsetY - crop.top * scale;
            // Calculate the icon position.
            floatingIconBounds.set(launcherIconBounds);
            floatingIconBounds.offset(mDx.value, mDy.value);
            Utilities.scaleRectFAboutCenter(floatingIconBounds, mIconScaleToFitScreen.value);
            floatingIconBounds.left -= offsetX;
            floatingIconBounds.top -= offsetY;
            floatingIconBounds.right += offsetX;
            floatingIconBounds.bottom += offsetY;
            if (initOnly) {
                // For the init pass, we want full alpha since the window is not yet ready.
                floatingView.update(1f, 255, floatingIconBounds, percent, 0f, mWindowRadius.value * scale, true);
                return;
            }
            ArrayList<SurfaceParams> params = new ArrayList<>();
            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);
                    if (rotationChange == 1) {
                        matrix.postTranslate(windowTransY0, mDeviceProfile.widthPx - (windowTransX0 + scaledCropWidth));
                    } else if (rotationChange == 2) {
                        matrix.postTranslate(mDeviceProfile.widthPx - (windowTransX0 + scaledCropWidth), mDeviceProfile.heightPx - (windowTransY0 + scaledCropHeight));
                    } else if (rotationChange == 3) {
                        matrix.postTranslate(mDeviceProfile.heightPx - (windowTransY0 + scaledCropHeight), windowTransX0);
                    } else {
                        matrix.postTranslate(windowTransX0, windowTransY0);
                    }
                    floatingView.update(mIconAlpha.value, 255, floatingIconBounds, percent, 0f, mWindowRadius.value * scale, true);
                    builder.withMatrix(matrix).withWindowCrop(crop).withAlpha(1f - mIconAlpha.value).withCornerRadius(mWindowRadius.value).withShadowRadius(mShadowRadius.value);
                } else if (target.mode == MODE_CLOSING) {
                    if (target.localBounds != null) {
                        final Rect localBounds = target.localBounds;
                        tmpPos.set(target.localBounds.left, target.localBounds.top);
                    } else {
                        tmpPos.set(target.position.x, target.position.y);
                    }
                    final Rect crop = new Rect(target.screenSpaceBounds);
                    crop.offsetTo(0, 0);
                    if ((rotationChange % 2) == 1) {
                        int tmp = crop.right;
                        crop.right = crop.bottom;
                        crop.bottom = tmp;
                        tmp = tmpPos.x;
                        tmpPos.x = tmpPos.y;
                        tmpPos.y = tmp;
                    }
                    matrix.setTranslate(tmpPos.x, tmpPos.y);
                    builder.withMatrix(matrix).withWindowCrop(crop).withAlpha(1f);
                }
                params.add(builder.build());
            }
            if (navBarTarget != null) {
                final SurfaceParams.Builder navBuilder = new SurfaceParams.Builder(navBarTarget.leash);
                if (mNavFadeIn.value > mNavFadeIn.getStartValue()) {
                    matrix.setScale(scale, scale);
                    matrix.postTranslate(windowTransX0, windowTransY0);
                    navBuilder.withMatrix(matrix).withWindowCrop(crop).withAlpha(mNavFadeIn.value);
                } else {
                    navBuilder.withAlpha(mNavFadeOut.value);
                }
                params.add(navBuilder.build());
            }
            surfaceApplier.scheduleApply(params.toArray(new SurfaceParams[params.size()]));
        }
    };
    appAnimator.addUpdateListener(listener);
    // Since we added a start delay, call update here to init the FloatingIconView properly.
    listener.onUpdate(0, true);
    animatorSet.playTogether(appAnimator, getBackgroundAnimator(appTargets));
    return animatorSet;
}
Also used : FloatingIconView(com.android.launcher3.views.FloatingIconView) ArrayList(java.util.ArrayList) RemoteAnimationTargets(com.android.quickstep.RemoteAnimationTargets) AnimatorSet(android.animation.AnimatorSet) ValueAnimator(android.animation.ValueAnimator) 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) RemoteAnimationTargetCompat(com.android.systemui.shared.system.RemoteAnimationTargetCompat) Point(android.graphics.Point) Point(android.graphics.Point) RectF(android.graphics.RectF) ValueAnimator(android.animation.ValueAnimator) Animator(android.animation.Animator) ObjectAnimator(android.animation.ObjectAnimator)

Example 4 with RemoteAnimationTargetCompat

use of com.android.systemui.shared.system.RemoteAnimationTargetCompat in project android_packages_apps_Launcher3 by crdroidandroid.

the class QuickstepTransitionManager method getWindowTargetBounds.

/**
 * Return the window bounds of the opening target.
 * In multiwindow mode, we need to get the final size of the opening app window target to help
 * figure out where the floating view should animate to.
 */
private Rect getWindowTargetBounds(@NonNull RemoteAnimationTargetCompat[] appTargets, int rotationChange) {
    RemoteAnimationTargetCompat target = null;
    for (RemoteAnimationTargetCompat t : appTargets) {
        if (t.mode != MODE_OPENING)
            continue;
        target = t;
        break;
    }
    if (target == null)
        return new Rect(0, 0, mDeviceProfile.widthPx, mDeviceProfile.heightPx);
    final Rect bounds = new Rect(target.screenSpaceBounds);
    if (target.localBounds != null) {
        bounds.set(target.localBounds);
    } else {
        bounds.offsetTo(target.position.x, target.position.y);
    }
    if (rotationChange != 0) {
        if ((rotationChange % 2) == 1) {
            // undoing rotation, so our "original" parent size is actually flipped
            Utilities.rotateBounds(bounds, mDeviceProfile.heightPx, mDeviceProfile.widthPx, 4 - rotationChange);
        } else {
            Utilities.rotateBounds(bounds, mDeviceProfile.widthPx, mDeviceProfile.heightPx, 4 - rotationChange);
        }
    }
    return bounds;
}
Also used : Rect(android.graphics.Rect) RemoteAnimationTargetCompat(com.android.systemui.shared.system.RemoteAnimationTargetCompat)

Example 5 with RemoteAnimationTargetCompat

use of com.android.systemui.shared.system.RemoteAnimationTargetCompat in project android_packages_apps_Launcher3 by crdroidandroid.

the class BaseQuickstepLauncher method useFadeOutAnimationForLauncherStart.

@Override
public void useFadeOutAnimationForLauncherStart(CancellationSignal signal) {
    QuickstepTransitionManager appTransitionManager = getAppTransitionManager();
    appTransitionManager.setRemoteAnimationProvider(new RemoteAnimationProvider() {

        @Override
        public AnimatorSet createWindowAnimation(RemoteAnimationTargetCompat[] appTargets, RemoteAnimationTargetCompat[] wallpaperTargets) {
            // On the first call clear the reference.
            signal.cancel();
            ValueAnimator fadeAnimation = ValueAnimator.ofFloat(1, 0);
            fadeAnimation.addUpdateListener(new RemoteFadeOutAnimationListener(appTargets, wallpaperTargets));
            AnimatorSet anim = new AnimatorSet();
            anim.play(fadeAnimation);
            return anim;
        }
    }, signal);
}
Also used : RemoteFadeOutAnimationListener(com.android.quickstep.util.RemoteFadeOutAnimationListener) RemoteAnimationTargetCompat(com.android.systemui.shared.system.RemoteAnimationTargetCompat) AnimatorSet(android.animation.AnimatorSet) ValueAnimator(android.animation.ValueAnimator) RemoteAnimationProvider(com.android.quickstep.util.RemoteAnimationProvider)

Aggregations

RemoteAnimationTargetCompat (com.android.systemui.shared.system.RemoteAnimationTargetCompat)18 ValueAnimator (android.animation.ValueAnimator)7 AnimatorSet (android.animation.AnimatorSet)6 Rect (android.graphics.Rect)6 Animator (android.animation.Animator)5 SurfaceTransactionApplier (com.android.quickstep.util.SurfaceTransactionApplier)5 SurfaceParams (com.android.systemui.shared.system.SyncRtSurfaceTransactionApplierCompat.SurfaceParams)5 AnimatorListenerAdapter (android.animation.AnimatorListenerAdapter)4 ObjectAnimator (android.animation.ObjectAnimator)4 Matrix (android.graphics.Matrix)4 MultiValueUpdateListener (com.android.quickstep.util.MultiValueUpdateListener)4 Point (android.graphics.Point)3 RectF (android.graphics.RectF)3 RemoteAnimationTargets (com.android.quickstep.RemoteAnimationTargets)3 ArrayList (java.util.ArrayList)3 UiThread (androidx.annotation.UiThread)2 DeviceProfile (com.android.launcher3.DeviceProfile)2 AnimationSuccessListener (com.android.launcher3.anim.AnimationSuccessListener)2 RemoteAnimationProvider (com.android.quickstep.util.RemoteAnimationProvider)2 RecentsView (com.android.quickstep.views.RecentsView)2