Search in sources :

Example 71 with TaskStack

use of com.android.systemui.recents.model.TaskStack in project android_frameworks_base by DirtyUnicorns.

the class TaskStackAnimationHelper method startScrollToFocusedTaskAnimation.

/**
     * Starts the animation to focus the next {@link TaskView} when paging through recents.
     *
     * @return whether or not this will trigger a scroll in the stack
     */
public boolean startScrollToFocusedTaskAnimation(Task newFocusedTask, boolean requestViewFocus) {
    TaskStackLayoutAlgorithm stackLayout = mStackView.getStackAlgorithm();
    TaskStackViewScroller stackScroller = mStackView.getScroller();
    TaskStack stack = mStackView.getStack();
    final float curScroll = stackScroller.getStackScroll();
    final float newScroll = stackScroller.getBoundedStackScroll(stackLayout.getStackScrollForTask(newFocusedTask));
    boolean willScrollToFront = newScroll > curScroll;
    boolean willScroll = Float.compare(newScroll, curScroll) != 0;
    // Get the current set of task transforms
    int taskViewCount = mStackView.getTaskViews().size();
    ArrayList<Task> stackTasks = stack.getStackTasks();
    mStackView.getCurrentTaskTransforms(stackTasks, mTmpCurrentTaskTransforms);
    // Pick up the newly visible views after the scroll
    mStackView.bindVisibleTaskViews(newScroll);
    // Update the internal state
    stackLayout.setFocusState(TaskStackLayoutAlgorithm.STATE_FOCUSED);
    stackScroller.setStackScroll(newScroll, null);
    mStackView.cancelDeferredTaskViewLayoutAnimation();
    // Get the final set of task transforms
    mStackView.getLayoutTaskTransforms(newScroll, stackLayout.getFocusState(), stackTasks, true, /* ignoreTaskOverrides */
    mTmpFinalTaskTransforms);
    // Focus the task view
    TaskView newFocusedTaskView = mStackView.getChildViewForTask(newFocusedTask);
    if (newFocusedTaskView == null) {
        // Log the error if we have no task view, and skip the animation
        Log.e("TaskStackAnimationHelper", "b/27389156 null-task-view prebind:" + taskViewCount + " postbind:" + mStackView.getTaskViews().size() + " prescroll:" + curScroll + " postscroll: " + newScroll);
        return false;
    }
    newFocusedTaskView.setFocusedState(true, requestViewFocus);
    // Setup the end listener to return all the hidden views to the view pool after the
    // focus animation
    ReferenceCountedTrigger postAnimTrigger = new ReferenceCountedTrigger();
    postAnimTrigger.addLastDecrementRunnable(new Runnable() {

        @Override
        public void run() {
            mStackView.bindVisibleTaskViews(newScroll);
        }
    });
    List<TaskView> taskViews = mStackView.getTaskViews();
    taskViewCount = taskViews.size();
    int newFocusTaskViewIndex = taskViews.indexOf(newFocusedTaskView);
    for (int i = 0; i < taskViewCount; i++) {
        TaskView tv = taskViews.get(i);
        Task task = tv.getTask();
        if (mStackView.isIgnoredTask(task)) {
            continue;
        }
        int taskIndex = stackTasks.indexOf(task);
        TaskViewTransform fromTransform = mTmpCurrentTaskTransforms.get(taskIndex);
        TaskViewTransform toTransform = mTmpFinalTaskTransforms.get(taskIndex);
        // Update the task to the initial state (for the newly picked up tasks)
        mStackView.updateTaskViewToTransform(tv, fromTransform, AnimationProps.IMMEDIATE);
        int duration;
        Interpolator interpolator;
        if (willScrollToFront) {
            duration = calculateStaggeredAnimDuration(i);
            interpolator = FOCUS_BEHIND_NEXT_TASK_INTERPOLATOR;
        } else {
            if (i < newFocusTaskViewIndex) {
                duration = 150 + ((newFocusTaskViewIndex - i - 1) * 50);
                interpolator = FOCUS_BEHIND_NEXT_TASK_INTERPOLATOR;
            } else if (i > newFocusTaskViewIndex) {
                duration = Math.max(100, 150 - ((i - newFocusTaskViewIndex - 1) * 50));
                interpolator = FOCUS_IN_FRONT_NEXT_TASK_INTERPOLATOR;
            } else {
                duration = 200;
                interpolator = FOCUS_NEXT_TASK_INTERPOLATOR;
            }
        }
        AnimationProps anim = new AnimationProps().setDuration(AnimationProps.BOUNDS, duration).setInterpolator(AnimationProps.BOUNDS, interpolator).setListener(postAnimTrigger.decrementOnAnimationEnd());
        postAnimTrigger.increment();
        mStackView.updateTaskViewToTransform(tv, toTransform, anim);
    }
    return willScroll;
}
Also used : Task(com.android.systemui.recents.model.Task) TaskStack(com.android.systemui.recents.model.TaskStack) ReferenceCountedTrigger(com.android.systemui.recents.misc.ReferenceCountedTrigger) TimeInterpolator(android.animation.TimeInterpolator) PathInterpolator(android.view.animation.PathInterpolator) Interpolator(android.view.animation.Interpolator)

Example 72 with TaskStack

use of com.android.systemui.recents.model.TaskStack in project android_frameworks_base by DirtyUnicorns.

the class TaskStackAnimationHelper method startExitToHomeAnimation.

/**
     * Starts an in-app animation to hide all the task views so that we can transition back home.
     */
public void startExitToHomeAnimation(boolean animated, ReferenceCountedTrigger postAnimationTrigger) {
    TaskStackLayoutAlgorithm stackLayout = mStackView.getStackAlgorithm();
    TaskStack stack = mStackView.getStack();
    // Break early if there are no tasks
    if (stack.getTaskCount() == 0) {
        return;
    }
    int offscreenYOffset = stackLayout.mStackRect.height();
    // Create the animations for each of the tasks
    List<TaskView> taskViews = mStackView.getTaskViews();
    int taskViewCount = taskViews.size();
    for (int i = 0; i < taskViewCount; i++) {
        int taskIndexFromFront = taskViewCount - i - 1;
        TaskView tv = taskViews.get(i);
        Task task = tv.getTask();
        if (mStackView.isIgnoredTask(task)) {
            continue;
        }
        // Animate the tasks down
        AnimationProps taskAnimation;
        if (animated) {
            int delay = Math.min(ENTER_EXIT_NUM_ANIMATING_TASKS, taskIndexFromFront) * mEnterAndExitFromHomeTranslationOffset;
            taskAnimation = new AnimationProps().setStartDelay(AnimationProps.BOUNDS, delay).setDuration(AnimationProps.BOUNDS, EXIT_TO_HOME_TRANSLATION_DURATION).setInterpolator(AnimationProps.BOUNDS, EXIT_TO_HOME_TRANSLATION_INTERPOLATOR).setListener(postAnimationTrigger.decrementOnAnimationEnd());
            postAnimationTrigger.increment();
        } else {
            taskAnimation = AnimationProps.IMMEDIATE;
        }
        mTmpTransform.fillIn(tv);
        mTmpTransform.rect.offset(0, offscreenYOffset);
        mStackView.updateTaskViewToTransform(tv, mTmpTransform, taskAnimation);
    }
}
Also used : TaskStack(com.android.systemui.recents.model.TaskStack) Task(com.android.systemui.recents.model.Task)

Example 73 with TaskStack

use of com.android.systemui.recents.model.TaskStack in project android_frameworks_base by DirtyUnicorns.

the class TaskStackAnimationHelper method prepareForEnterAnimation.

/**
     * Prepares the stack views and puts them in their initial animation state while visible, before
     * the in-app enter animations start (after the window-transition completes).
     */
public void prepareForEnterAnimation() {
    RecentsConfiguration config = Recents.getConfiguration();
    RecentsActivityLaunchState launchState = config.getLaunchState();
    Resources res = mStackView.getResources();
    Resources appResources = mStackView.getContext().getApplicationContext().getResources();
    TaskStackLayoutAlgorithm stackLayout = mStackView.getStackAlgorithm();
    TaskStackViewScroller stackScroller = mStackView.getScroller();
    TaskStack stack = mStackView.getStack();
    Task launchTargetTask = stack.getLaunchTarget();
    // Break early if there are no tasks
    if (stack.getTaskCount() == 0) {
        return;
    }
    int offscreenYOffset = stackLayout.mStackRect.height();
    int taskViewAffiliateGroupEnterOffset = res.getDimensionPixelSize(R.dimen.recents_task_stack_animation_affiliate_enter_offset);
    int launchedWhileDockingOffset = res.getDimensionPixelSize(R.dimen.recents_task_stack_animation_launched_while_docking_offset);
    boolean isLandscape = appResources.getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE;
    // Prepare each of the task views for their enter animation from front to back
    List<TaskView> taskViews = mStackView.getTaskViews();
    for (int i = taskViews.size() - 1; i >= 0; i--) {
        TaskView tv = taskViews.get(i);
        Task task = tv.getTask();
        boolean currentTaskOccludesLaunchTarget = launchTargetTask != null && launchTargetTask.group != null && launchTargetTask.group.isTaskAboveTask(task, launchTargetTask);
        boolean hideTask = launchTargetTask != null && launchTargetTask.isFreeformTask() && task.isFreeformTask();
        // Get the current transform for the task, which will be used to position it offscreen
        stackLayout.getStackTransform(task, stackScroller.getStackScroll(), mTmpTransform, null);
        if (hideTask) {
            tv.setVisibility(View.INVISIBLE);
        } else if (launchState.launchedFromApp && !launchState.launchedViaDockGesture) {
            if (task.isLaunchTarget) {
                tv.onPrepareLaunchTargetForEnterAnimation();
            } else if (currentTaskOccludesLaunchTarget) {
                // Move the task view slightly lower so we can animate it in
                mTmpTransform.rect.offset(0, taskViewAffiliateGroupEnterOffset);
                mTmpTransform.alpha = 0f;
                mStackView.updateTaskViewToTransform(tv, mTmpTransform, AnimationProps.IMMEDIATE);
                tv.setClipViewInStack(false);
            }
        } else if (launchState.launchedFromHome) {
            // Move the task view off screen (below) so we can animate it in
            mTmpTransform.rect.offset(0, offscreenYOffset);
            mTmpTransform.alpha = 0f;
            mStackView.updateTaskViewToTransform(tv, mTmpTransform, AnimationProps.IMMEDIATE);
        } else if (launchState.launchedViaDockGesture) {
            int offset = isLandscape ? launchedWhileDockingOffset : (int) (offscreenYOffset * 0.9f);
            mTmpTransform.rect.offset(0, offset);
            mTmpTransform.alpha = 0f;
            mStackView.updateTaskViewToTransform(tv, mTmpTransform, AnimationProps.IMMEDIATE);
        }
    }
}
Also used : TaskStack(com.android.systemui.recents.model.TaskStack) Task(com.android.systemui.recents.model.Task) RecentsActivityLaunchState(com.android.systemui.recents.RecentsActivityLaunchState) RecentsConfiguration(com.android.systemui.recents.RecentsConfiguration) Resources(android.content.res.Resources)

Example 74 with TaskStack

use of com.android.systemui.recents.model.TaskStack in project android_frameworks_base by crdroidandroid.

the class RecentsTvActivity method updateRecentsTasks.

private void updateRecentsTasks() {
    RecentsTaskLoader loader = Recents.getTaskLoader();
    RecentsTaskLoadPlan plan = RecentsImpl.consumeInstanceLoadPlan();
    if (plan == null) {
        plan = loader.createLoadPlan(this);
    }
    RecentsConfiguration config = Recents.getConfiguration();
    RecentsActivityLaunchState launchState = config.getLaunchState();
    if (!plan.hasTasks()) {
        loader.preloadTasks(plan, -1, !launchState.launchedFromHome);
    }
    int numVisibleTasks = TaskCardView.getNumberOfVisibleTasks(getApplicationContext());
    mLaunchedFromHome = launchState.launchedFromHome;
    TaskStack stack = plan.getTaskStack();
    RecentsTaskLoadPlan.Options loadOpts = new RecentsTaskLoadPlan.Options();
    loadOpts.runningTaskId = launchState.launchedToTaskId;
    loadOpts.numVisibleTasks = numVisibleTasks;
    loadOpts.numVisibleTaskThumbnails = numVisibleTasks;
    loader.loadTasks(this, plan, loadOpts);
    List stackTasks = stack.getStackTasks();
    Collections.reverse(stackTasks);
    if (mTaskStackViewAdapter == null) {
        mTaskStackViewAdapter = new TaskStackHorizontalViewAdapter(stackTasks);
        mTaskStackHorizontalGridView = mRecentsView.setTaskStackViewAdapter(mTaskStackViewAdapter);
        mHomeRecentsEnterExitAnimationHolder = new HomeRecentsEnterExitAnimationHolder(getApplicationContext(), mTaskStackHorizontalGridView);
    } else {
        mTaskStackViewAdapter.setNewStackTasks(stackTasks);
    }
    mRecentsView.init(stack);
    if (launchState.launchedToTaskId != -1) {
        ArrayList<Task> tasks = stack.getStackTasks();
        int taskCount = tasks.size();
        for (int i = 0; i < taskCount; i++) {
            Task t = tasks.get(i);
            if (t.key.id == launchState.launchedToTaskId) {
                t.isLaunchTarget = true;
                break;
            }
        }
    }
}
Also used : ActivityOptions(android.app.ActivityOptions) Task(com.android.systemui.recents.model.Task) RecentsTaskLoadPlan(com.android.systemui.recents.model.RecentsTaskLoadPlan) RecentsTaskLoader(com.android.systemui.recents.model.RecentsTaskLoader) HomeRecentsEnterExitAnimationHolder(com.android.systemui.recents.tv.animations.HomeRecentsEnterExitAnimationHolder) TaskStack(com.android.systemui.recents.model.TaskStack) RecentsActivityLaunchState(com.android.systemui.recents.RecentsActivityLaunchState) RecentsConfiguration(com.android.systemui.recents.RecentsConfiguration) TaskStackHorizontalViewAdapter(com.android.systemui.recents.tv.views.TaskStackHorizontalViewAdapter) ArrayList(java.util.ArrayList) List(java.util.List)

Example 75 with TaskStack

use of com.android.systemui.recents.model.TaskStack in project android_frameworks_base by crdroidandroid.

the class RecentsImpl method startRecentsActivity.

/**
     * Shows the recents activity
     */
protected void startRecentsActivity(ActivityManager.RunningTaskInfo runningTask, boolean isHomeStackVisible, boolean animate, int growTarget) {
    RecentsTaskLoader loader = Recents.getTaskLoader();
    RecentsActivityLaunchState launchState = Recents.getConfiguration().getLaunchState();
    SystemServicesProxy ssp = Recents.getSystemServices();
    boolean isBlacklisted = (runningTask != null) ? ssp.isBlackListedActivity(runningTask.baseActivity.getClassName()) : false;
    int runningTaskId = !mLaunchedWhileDocking && !isBlacklisted && (runningTask != null) ? runningTask.id : -1;
    // the stacks might have changed.
    if (mLaunchedWhileDocking || mTriggeredFromAltTab || sInstanceLoadPlan == null) {
        // Create a new load plan if preloadRecents() was never triggered
        sInstanceLoadPlan = loader.createLoadPlan(mContext);
    }
    if (mLaunchedWhileDocking || mTriggeredFromAltTab || !sInstanceLoadPlan.hasTasks()) {
        loader.preloadTasks(sInstanceLoadPlan, runningTaskId, !isHomeStackVisible);
    }
    TaskStack stack = sInstanceLoadPlan.getTaskStack();
    boolean hasRecentTasks = stack.getTaskCount() > 0;
    boolean useThumbnailTransition = (runningTask != null) && !isHomeStackVisible && hasRecentTasks;
    // Update the launch state that we need in updateHeaderBarLayout()
    launchState.launchedFromHome = !useThumbnailTransition && !mLaunchedWhileDocking;
    launchState.launchedFromApp = useThumbnailTransition || mLaunchedWhileDocking;
    launchState.launchedFromBlacklistedApp = launchState.launchedFromApp && isBlacklisted;
    launchState.launchedViaDockGesture = mLaunchedWhileDocking;
    launchState.launchedViaDragGesture = mDraggingInRecents;
    launchState.launchedToTaskId = runningTaskId;
    launchState.launchedWithAltTab = mTriggeredFromAltTab;
    // Preload the icon (this will be a null-op if we have preloaded the icon already in
    // preloadRecents())
    preloadIcon(runningTaskId);
    // Update the header bar if necessary
    Rect windowOverrideRect = getWindowRectOverride(growTarget);
    updateHeaderBarLayout(stack, windowOverrideRect);
    // Prepare the dummy stack for the transition
    TaskStackLayoutAlgorithm.VisibilityReport stackVr = mDummyStackView.computeStackVisibilityReport();
    // Update the remaining launch state
    launchState.launchedNumVisibleTasks = stackVr.numVisibleTasks;
    launchState.launchedNumVisibleThumbnails = stackVr.numVisibleThumbnails;
    if (!animate) {
        startRecentsActivity(ActivityOptions.makeCustomAnimation(mContext, -1, -1));
        return;
    }
    ActivityOptions opts;
    if (isBlacklisted) {
        opts = getUnknownTransitionActivityOptions();
    } else if (useThumbnailTransition) {
        // Try starting with a thumbnail transition
        opts = getThumbnailTransitionActivityOptions(runningTask, mDummyStackView, windowOverrideRect);
    } else {
        // If there is no thumbnail transition, but is launching from home into recents, then
        // use a quick home transition
        opts = hasRecentTasks ? getHomeTransitionActivityOptions() : getUnknownTransitionActivityOptions();
    }
    startRecentsActivity(opts);
    mLastToggleTime = SystemClock.elapsedRealtime();
}
Also used : SystemServicesProxy(com.android.systemui.recents.misc.SystemServicesProxy) TaskStack(com.android.systemui.recents.model.TaskStack) Rect(android.graphics.Rect) RecentsTaskLoader(com.android.systemui.recents.model.RecentsTaskLoader) TaskStackLayoutAlgorithm(com.android.systemui.recents.views.TaskStackLayoutAlgorithm) ActivityOptions(android.app.ActivityOptions)

Aggregations

TaskStack (com.android.systemui.recents.model.TaskStack)80 Task (com.android.systemui.recents.model.Task)56 RecentsTaskLoader (com.android.systemui.recents.model.RecentsTaskLoader)40 ActivityOptions (android.app.ActivityOptions)35 RecentsTaskLoadPlan (com.android.systemui.recents.model.RecentsTaskLoadPlan)25 SystemServicesProxy (com.android.systemui.recents.misc.SystemServicesProxy)20 ActivityManager (android.app.ActivityManager)15 RecentsActivityLaunchState (com.android.systemui.recents.RecentsActivityLaunchState)15 RecentsConfiguration (com.android.systemui.recents.RecentsConfiguration)15 Resources (android.content.res.Resources)10 Rect (android.graphics.Rect)10 ArrayList (java.util.ArrayList)10 Animator (android.animation.Animator)5 AnimatorListenerAdapter (android.animation.AnimatorListenerAdapter)5 TimeInterpolator (android.animation.TimeInterpolator)5 ValueAnimator (android.animation.ValueAnimator)5 MutableBoolean (android.util.MutableBoolean)5 AppTransitionAnimationSpec (android.view.AppTransitionAnimationSpec)5 Interpolator (android.view.animation.Interpolator)5 PathInterpolator (android.view.animation.PathInterpolator)5