Search in sources :

Example 11 with Target

use of com.android.launcher3.userevent.nano.LauncherLogProto.Target in project android_packages_apps_Launcher3 by crdroidandroid.

the class NoButtonQuickSwitchTouchController method onDragEnd.

@Override
public void onDragEnd(PointF velocity) {
    boolean horizontalFling = mSwipeDetector.isFling(velocity.x);
    boolean verticalFling = mSwipeDetector.isFling(velocity.y);
    boolean noFling = !horizontalFling && !verticalFling;
    if (mMotionPauseDetector.isPaused() && noFling) {
        cancelAnimations();
        StateAnimationConfig config = new StateAnimationConfig();
        config.duration = ATOMIC_DURATION_FROM_PAUSED_TO_OVERVIEW;
        Animator overviewAnim = mLauncher.getStateManager().createAtomicAnimation(mStartState, OVERVIEW, config);
        overviewAnim.addListener(new AnimatorListenerAdapter() {

            @Override
            public void onAnimationEnd(Animator animation) {
                onAnimationToStateCompleted(OVERVIEW);
            }
        });
        overviewAnim.start();
        return;
    }
    final LauncherState targetState;
    if (horizontalFling && verticalFling) {
        if (velocity.x < 0) {
            // Flinging left and up or down both go back home.
            targetState = NORMAL;
        } else {
            if (velocity.y > 0) {
                // Flinging right and down goes to quick switch.
                targetState = QUICK_SWITCH;
            } else {
                // Flinging up and right could go either home or to quick switch.
                // Determine the target based on the higher velocity.
                targetState = Math.abs(velocity.x) > Math.abs(velocity.y) ? QUICK_SWITCH : NORMAL;
            }
        }
    } else if (horizontalFling) {
        targetState = velocity.x > 0 ? QUICK_SWITCH : NORMAL;
    } else if (verticalFling) {
        targetState = velocity.y > 0 ? QUICK_SWITCH : NORMAL;
    } else {
        // If user isn't flinging, just snap to the closest state.
        boolean passedHorizontalThreshold = mXOverviewAnim.getInterpolatedProgress() > 0.5f;
        boolean passedVerticalThreshold = mYOverviewAnim.value > 1f;
        targetState = passedHorizontalThreshold && !passedVerticalThreshold ? QUICK_SWITCH : NORMAL;
    }
    // Animate the various components to the target state.
    float xProgress = mXOverviewAnim.getProgressFraction();
    float startXProgress = Utilities.boundToRange(xProgress + velocity.x * getSingleFrameMs(mLauncher) / mXRange, 0f, 1f);
    final float endXProgress = targetState == NORMAL ? 0 : 1;
    long xDuration = BaseSwipeDetector.calculateDuration(velocity.x, Math.abs(endXProgress - startXProgress));
    ValueAnimator xOverviewAnim = mXOverviewAnim.getAnimationPlayer();
    xOverviewAnim.setFloatValues(startXProgress, endXProgress);
    xOverviewAnim.setDuration(xDuration).setInterpolator(scrollInterpolatorForVelocity(velocity.x));
    mXOverviewAnim.dispatchOnStart();
    boolean flingUpToNormal = verticalFling && velocity.y < 0 && targetState == NORMAL;
    float yProgress = mYOverviewAnim.value;
    float startYProgress = Utilities.boundToRange(yProgress - velocity.y * getSingleFrameMs(mLauncher) / mYRange, 0f, mMaxYProgress);
    final float endYProgress;
    if (flingUpToNormal) {
        endYProgress = 1;
    } else if (targetState == NORMAL) {
        // Keep overview at its current scale/translationY as it slides off the screen.
        endYProgress = startYProgress;
    } else {
        endYProgress = 0;
    }
    float yDistanceToCover = Math.abs(endYProgress - startYProgress) * mYRange;
    long yDuration = (long) (yDistanceToCover / Math.max(1f, Math.abs(velocity.y)));
    ValueAnimator yOverviewAnim = mYOverviewAnim.animateToValue(startYProgress, endYProgress);
    yOverviewAnim.setDuration(yDuration);
    mYOverviewAnim.updateValue(startYProgress);
    ValueAnimator nonOverviewAnim = mNonOverviewAnim.getAnimationPlayer();
    if (flingUpToNormal && !mIsHomeScreenVisible) {
        // We are flinging to home while workspace is invisible, run the same staggered
        // animation as from an app.
        StateAnimationConfig config = new StateAnimationConfig();
        // Update mNonOverviewAnim to do nothing so it doesn't interfere.
        config.animFlags = SKIP_ALL_ANIMATIONS;
        updateNonOverviewAnim(targetState, config);
        nonOverviewAnim = mNonOverviewAnim.getAnimationPlayer();
        new WorkspaceRevealAnim(mLauncher, false).start();
    } else {
        boolean canceled = targetState == NORMAL;
        if (canceled) {
            // Let the state manager know that the animation didn't go to the target state,
            // but don't clean up yet (we already clean up when the animation completes).
            mNonOverviewAnim.getTarget().removeListener(mClearStateOnCancelListener);
            mNonOverviewAnim.dispatchOnCancel();
        }
        float startProgress = mNonOverviewAnim.getProgressFraction();
        float endProgress = canceled ? 0 : 1;
        nonOverviewAnim.setFloatValues(startProgress, endProgress);
        mNonOverviewAnim.dispatchOnStart();
    }
    nonOverviewAnim.setDuration(Math.max(xDuration, yDuration));
    mNonOverviewAnim.setEndAction(() -> onAnimationToStateCompleted(targetState));
    cancelAnimations();
    xOverviewAnim.start();
    yOverviewAnim.start();
    nonOverviewAnim.start();
}
Also used : LauncherState(com.android.launcher3.LauncherState) Animator(android.animation.Animator) ValueAnimator(android.animation.ValueAnimator) StateAnimationConfig(com.android.launcher3.states.StateAnimationConfig) AnimatorListenerAdapter(android.animation.AnimatorListenerAdapter) ValueAnimator(android.animation.ValueAnimator) WorkspaceRevealAnim(com.android.quickstep.util.WorkspaceRevealAnim)

Example 12 with Target

use of com.android.launcher3.userevent.nano.LauncherLogProto.Target in project android_packages_apps_Launcher3 by crdroidandroid.

the class TaskbarView method delegateTouchIfNecessary.

/**
 * User touched the Taskbar background. Determine whether the touch is close enough to a view
 * that we should forward the touches to it.
 * @return Whether a delegate view was chosen and it handled the touch event.
 */
private boolean delegateTouchIfNecessary(MotionEvent event) {
    final float x = event.getX();
    final float y = event.getY();
    if (mDelegateView == null && event.getAction() == MotionEvent.ACTION_DOWN) {
        View delegateView = findDelegateView(x, y);
        if (delegateView != null) {
            mDelegateTargeted = true;
            mDelegateView = delegateView;
            mDelegateSlopBounds.set(mTempDelegateBounds);
            mDelegateSlopBounds.inset(-mTouchSlop, -mTouchSlop);
        }
    }
    boolean sendToDelegate = mDelegateTargeted;
    boolean inBounds = true;
    switch(event.getAction()) {
        case MotionEvent.ACTION_MOVE:
            inBounds = mDelegateSlopBounds.contains(x, y);
            break;
        case MotionEvent.ACTION_UP:
        case MotionEvent.ACTION_CANCEL:
            mDelegateTargeted = false;
            break;
    }
    boolean handled = false;
    if (sendToDelegate) {
        if (inBounds) {
            // Offset event coordinates to be inside the target view
            event.setLocation(mDelegateView.getWidth() / 2f, mDelegateView.getHeight() / 2f);
        } else {
            // Offset event coordinates to be outside the target view (in case it does
            // something like tracking pressed state)
            event.setLocation(-mTouchSlop * 2, -mTouchSlop * 2);
        }
        handled = mDelegateView.dispatchTouchEvent(event);
        // Cleanup if this was the last event to send to the delegate.
        if (!mDelegateTargeted) {
            mDelegateView = null;
        }
    }
    return handled;
}
Also used : BubbleTextView(com.android.launcher3.BubbleTextView) View(android.view.View) AbstractFloatingView(com.android.launcher3.AbstractFloatingView)

Example 13 with Target

use of com.android.launcher3.userevent.nano.LauncherLogProto.Target in project android_packages_apps_Launcher3 by crdroidandroid.

the class AnimatorControllerWithResistance method createForRecents.

/**
 * Applies resistance to recents when swiping up past its target position.
 * @param normalController The controller to run from 0 to 1 before this resistance applies.
 * @param context Used to compute start and end values.
 * @param recentsOrientedState Used to compute start and end values.
 * @param dp Used to compute start and end values.
 * @param scaleTarget The target for the scaleProperty.
 * @param scaleProperty Animate the value to change the scale of the window/recents view.
 * @param translationTarget The target for the translationProperty.
 * @param translationProperty Animate the value to change the translation of the recents view.
 */
public static <SCALE, TRANSLATION> AnimatorControllerWithResistance createForRecents(AnimatorPlaybackController normalController, Context context, RecentsOrientedState recentsOrientedState, DeviceProfile dp, SCALE scaleTarget, FloatProperty<SCALE> scaleProperty, TRANSLATION translationTarget, FloatProperty<TRANSLATION> translationProperty) {
    RecentsParams params = new RecentsParams(context, recentsOrientedState, dp, scaleTarget, scaleProperty, translationTarget, translationProperty);
    PendingAnimation resistAnim = createRecentsResistanceAnim(params);
    AnimatorPlaybackController resistanceController = resistAnim.createPlaybackController();
    return new AnimatorControllerWithResistance(normalController, resistanceController);
}
Also used : PendingAnimation(com.android.launcher3.anim.PendingAnimation) AnimatorPlaybackController(com.android.launcher3.anim.AnimatorPlaybackController)

Example 14 with Target

use of com.android.launcher3.userevent.nano.LauncherLogProto.Target in project android_packages_apps_Launcher3 by AOSPA.

the class AbsSwipeUpHandler method onRecentsAnimationStart.

@Override
public void onRecentsAnimationStart(RecentsAnimationController controller, RecentsAnimationTargets targets) {
    super.onRecentsAnimationStart(controller, targets);
    ActiveGestureLog.INSTANCE.addLog("startRecentsAnimationCallback", targets.apps.length);
    mRemoteTargetHandles = mTargetGluer.assignTargetsForSplitScreen(targets);
    mRecentsAnimationController = controller;
    mRecentsAnimationTargets = targets;
    // configurations targets.homeContentInsets may not be correct.
    if (mActivity == null) {
        RemoteAnimationTargetCompat primaryTaskTarget = targets.apps[0];
        // orientation state is independent of which remote target handle we use since both
        // should be pointing to the same one. Just choose index 0 for now since that works for
        // both split and non-split
        RecentsOrientedState orientationState = mRemoteTargetHandles[0].getTaskViewSimulator().getOrientationState();
        DeviceProfile dp = orientationState.getLauncherDeviceProfile();
        if (targets.minimizedHomeBounds != null && primaryTaskTarget != null) {
            Rect overviewStackBounds = mActivityInterface.getOverviewWindowBounds(targets.minimizedHomeBounds, primaryTaskTarget);
            dp = dp.getMultiWindowProfile(mContext, new WindowBounds(overviewStackBounds, targets.homeContentInsets));
        } else {
            // If we are not in multi-window mode, home insets should be same as system insets.
            dp = dp.copy(mContext);
        }
        dp.updateInsets(targets.homeContentInsets);
        dp.updateIsSeascape(mContext);
        initTransitionEndpoints(dp);
        orientationState.setMultiWindowMode(dp.isMultiWindowMode);
    }
    // Notify when the animation starts
    flushOnRecentsAnimationAndLauncherBound();
    TaskViewUtils.setSplitAuxiliarySurfacesShown(mRecentsAnimationTargets.nonApps, false, /*shown*/
    true);
    // Only add the callback to enable the input consumer after we actually have the controller
    mStateCallback.runOnceAtState(STATE_APP_CONTROLLER_RECEIVED | STATE_GESTURE_STARTED, mRecentsAnimationController::enableInputConsumer);
    mStateCallback.setStateOnUiThread(STATE_APP_CONTROLLER_RECEIVED);
    mPassedOverviewThreshold = false;
}
Also used : DeviceProfile(com.android.launcher3.DeviceProfile) Rect(android.graphics.Rect) WindowBounds(com.android.launcher3.util.WindowBounds) RemoteAnimationTargetCompat(com.android.systemui.shared.system.RemoteAnimationTargetCompat) RecentsOrientedState(com.android.quickstep.util.RecentsOrientedState)

Example 15 with Target

use of com.android.launcher3.userevent.nano.LauncherLogProto.Target in project android_packages_apps_Launcher3 by AOSPA.

the class AbsSwipeUpHandler method animateToProgressInternal.

@UiThread
private void animateToProgressInternal(float start, float end, long duration, Interpolator interpolator, GestureEndTarget target, PointF velocityPxPerMs) {
    maybeUpdateRecentsAttachedState();
    // the transition is in progress
    if (mGestureState.getEndTarget().isLauncher) {
        TaskStackChangeListeners.getInstance().registerTaskStackListener(mActivityRestartListener);
        mParallelRunningAnim = mActivityInterface.getParallelAnimationToLauncher(mGestureState.getEndTarget(), duration, mTaskAnimationManager.getCurrentCallbacks());
        if (mParallelRunningAnim != null) {
            mParallelRunningAnim.addListener(new AnimatorListenerAdapter() {

                @Override
                public void onAnimationEnd(Animator animation) {
                    mParallelRunningAnim = null;
                }
            });
            mParallelRunningAnim.start();
        }
    }
    if (mGestureState.getEndTarget() == HOME) {
        getOrientationHandler().adjustFloatingIconStartVelocity(velocityPxPerMs);
        final RemoteAnimationTargetCompat runningTaskTarget = mRecentsAnimationTargets != null ? mRecentsAnimationTargets.findTask(mGestureState.getRunningTaskId()) : null;
        final ArrayList<IBinder> cookies = runningTaskTarget != null ? runningTaskTarget.taskInfo.launchCookies : new ArrayList<>();
        boolean isTranslucent = runningTaskTarget != null && runningTaskTarget.isTranslucent;
        boolean appCanEnterPip = !mDeviceState.isPipActive() && runningTaskTarget != null && runningTaskTarget.allowEnterPip && runningTaskTarget.taskInfo.pictureInPictureParams != null && runningTaskTarget.taskInfo.pictureInPictureParams.isAutoEnterEnabled();
        HomeAnimationFactory homeAnimFactory = createHomeAnimationFactory(cookies, duration, isTranslucent, appCanEnterPip, runningTaskTarget);
        mIsSwipingPipToHome = !mIsSwipeForStagedSplit && homeAnimFactory.supportSwipePipToHome() && appCanEnterPip;
        final RectFSpringAnim[] windowAnim;
        if (mIsSwipingPipToHome) {
            mSwipePipToHomeAnimator = createWindowAnimationToPip(homeAnimFactory, runningTaskTarget, start);
            mSwipePipToHomeAnimators[0] = mSwipePipToHomeAnimator;
            windowAnim = mSwipePipToHomeAnimators;
        } else {
            mSwipePipToHomeAnimator = null;
            windowAnim = createWindowAnimationToHome(start, homeAnimFactory);
            windowAnim[0].addAnimatorListener(new AnimationSuccessListener() {

                @Override
                public void onAnimationSuccess(Animator animator) {
                    if (mRecentsAnimationController == null) {
                        // we can skip doing any future work here for the current gesture.
                        return;
                    }
                    // Finalize the state and notify of the change
                    mGestureState.setState(STATE_END_TARGET_ANIMATION_FINISHED);
                }
            });
        }
        mRunningWindowAnim = new RunningWindowAnim[windowAnim.length];
        for (int i = 0, windowAnimLength = windowAnim.length; i < windowAnimLength; i++) {
            RectFSpringAnim windowAnimation = windowAnim[i];
            if (windowAnimation == null) {
                continue;
            }
            windowAnimation.start(mContext, velocityPxPerMs);
            mRunningWindowAnim[i] = RunningWindowAnim.wrap(windowAnimation);
        }
        homeAnimFactory.setSwipeVelocity(velocityPxPerMs.y);
        homeAnimFactory.playAtomicAnimation(velocityPxPerMs.y);
        mLauncherTransitionController = null;
        if (mRecentsView != null) {
            mRecentsView.onPrepareGestureEndAnimation(null, mGestureState.getEndTarget(), getRemoteTaskViewSimulators());
        }
    } else {
        AnimatorSet animatorSet = new AnimatorSet();
        ValueAnimator windowAnim = mCurrentShift.animateToValue(start, end);
        windowAnim.addUpdateListener(valueAnimator -> {
            computeRecentsScrollIfInvisible();
        });
        windowAnim.addListener(new AnimationSuccessListener() {

            @Override
            public void onAnimationSuccess(Animator animator) {
                if (mRecentsAnimationController == null) {
                    // skip doing any future work here for the current gesture.
                    return;
                }
                if (mRecentsView != null) {
                    int taskToLaunch = mRecentsView.getNextPage();
                    int runningTask = getLastAppearedTaskIndex();
                    boolean hasStartedNewTask = hasStartedNewTask();
                    if (target == NEW_TASK && taskToLaunch == runningTask && !hasStartedNewTask) {
                        // We are about to launch the current running task, so use LAST_TASK
                        // state instead of NEW_TASK. This could happen, for example, if our
                        // scroll is aborted after we determined the target to be NEW_TASK.
                        mGestureState.setEndTarget(LAST_TASK);
                    } else if (target == LAST_TASK && hasStartedNewTask) {
                        // We are about to re-launch the previously running task, but we can't
                        // just finish the controller like we normally would because that would
                        // instead resume the last task that appeared, and not ensure that this
                        // task is restored to the top. To address this, re-launch the task as
                        // if it were a new task.
                        mGestureState.setEndTarget(NEW_TASK);
                    }
                }
                mGestureState.setState(STATE_END_TARGET_ANIMATION_FINISHED);
            }
        });
        animatorSet.play(windowAnim);
        if (mRecentsView != null) {
            mRecentsView.onPrepareGestureEndAnimation(animatorSet, mGestureState.getEndTarget(), getRemoteTaskViewSimulators());
        }
        animatorSet.setDuration(duration).setInterpolator(interpolator);
        animatorSet.start();
        mRunningWindowAnim = new RunningWindowAnim[] { RunningWindowAnim.wrap(animatorSet) };
    }
}
Also used : RemoteAnimationTargetCompat(com.android.systemui.shared.system.RemoteAnimationTargetCompat) AnimatorSet(android.animation.AnimatorSet) ValueAnimator(android.animation.ValueAnimator) RectFSpringAnim(com.android.quickstep.util.RectFSpringAnim) IBinder(android.os.IBinder) SwipePipToHomeAnimator(com.android.quickstep.util.SwipePipToHomeAnimator) ValueAnimator(android.animation.ValueAnimator) Animator(android.animation.Animator) AnimatorListenerAdapter(android.animation.AnimatorListenerAdapter) AnimationSuccessListener(com.android.launcher3.anim.AnimationSuccessListener) UiThread(androidx.annotation.UiThread)

Aggregations

View (android.view.View)85 WorkspaceItemInfo (com.android.launcher3.model.data.WorkspaceItemInfo)59 Point (android.graphics.Point)42 Rect (android.graphics.Rect)41 AppWidgetHostView (android.appwidget.AppWidgetHostView)40 AbstractFloatingView (com.android.launcher3.AbstractFloatingView)38 ItemInfo (com.android.launcher3.model.data.ItemInfo)37 Animator (android.animation.Animator)35 ValueAnimator (android.animation.ValueAnimator)35 Target (com.android.launcher3.userevent.nano.LauncherLogProto.Target)35 BubbleTextView (com.android.launcher3.BubbleTextView)34 DropTarget (com.android.launcher3.DropTarget)32 DragView (com.android.launcher3.dragndrop.DragView)30 LauncherAppWidgetHostView (com.android.launcher3.widget.LauncherAppWidgetHostView)30 AnimatorSet (android.animation.AnimatorSet)29 RemoteAnimationTargetCompat (com.android.systemui.shared.system.RemoteAnimationTargetCompat)29 ComponentName (android.content.ComponentName)28 ObjectAnimator (android.animation.ObjectAnimator)27 DraggableView (com.android.launcher3.dragndrop.DraggableView)26 AppInfo (com.android.launcher3.model.data.AppInfo)26