FileDocCategorySizeDatePackage
TaskStackViewFilterAlgorithm.javaAPI DocAndroid 5.1 API8670Thu Mar 12 22:22:42 GMT 2015com.android.systemui.recents.views

TaskStackViewFilterAlgorithm

public class TaskStackViewFilterAlgorithm extends Object

Fields Summary
com.android.systemui.recents.RecentsConfiguration
mConfig
TaskStackView
mStackView
ViewPool
mViewPool
Constructors Summary
public TaskStackViewFilterAlgorithm(com.android.systemui.recents.RecentsConfiguration config, TaskStackView stackView, ViewPool viewPool)

        mConfig = config;
        mStackView = stackView;
        mViewPool = viewPool;
    
Methods Summary
intgetEnterTransformsForFilterAnimation(java.util.ArrayList tasks, java.util.ArrayList taskTransforms, java.util.HashMap childViewTransformsOut)
Creates the animations for all the children views that need to be animated in when we are un/filtering a stack, and returns the duration for these animations.

        int offset = 0;
        int movement = 0;
        int taskCount = tasks.size();
        for (int i = taskCount - 1; i >= 0; i--) {
            Task task = tasks.get(i);
            TaskViewTransform toTransform = taskTransforms.get(i);
            if (toTransform.visible) {
                TaskView tv = mStackView.getChildViewForTask(task);
                if (tv == null) {
                    // For views that are not already visible, animate them in
                    tv = mViewPool.pickUpViewFromPool(task, task);

                    // Compose a new transform to fade and slide the new task in
                    TaskViewTransform fromTransform = new TaskViewTransform(toTransform);
                    tv.prepareTaskTransformForFilterTaskHidden(fromTransform);
                    tv.updateViewPropertiesToTaskTransform(fromTransform, 0);

                    toTransform.startDelay = offset * Constants.Values.TaskStackView.FilterStartDelay;
                    childViewTransformsOut.put(tv, toTransform);

                    // Use the movement of the new views to calculate the duration of the animation
                    movement = Math.max(movement,
                            Math.abs(toTransform.translationY - fromTransform.translationY));
                    offset++;
                }
            }
        }
        return mConfig.filteringNewViewsAnimDuration;
    
intgetExitTransformsForFilterAnimation(java.util.ArrayList curTasks, java.util.ArrayList curTaskTransforms, java.util.ArrayList tasks, java.util.ArrayList taskTransforms, java.util.HashMap childViewTransformsOut, java.util.ArrayList childrenToRemoveOut)
Creates the animations for all the children views that need to be removed or to move views to their un/filtered position when we are un/filtering a stack, and returns the duration for these animations.

        // Animate all of the existing views out of view (if they are not in the visible range in
        // the new stack) or to their final positions in the new stack
        int offset = 0;
        int movement = 0;
        int childCount = mStackView.getChildCount();
        for (int i = 0; i < childCount; i++) {
            TaskView tv = (TaskView) mStackView.getChildAt(i);
            Task task = tv.getTask();
            int taskIndex = tasks.indexOf(task);
            TaskViewTransform toTransform;

            // If the view is no longer visible, then we should just animate it out
            boolean willBeInvisible = taskIndex < 0 || !taskTransforms.get(taskIndex).visible;
            if (willBeInvisible) {
                if (taskIndex < 0) {
                    toTransform = curTaskTransforms.get(curTasks.indexOf(task));
                } else {
                    toTransform = new TaskViewTransform(taskTransforms.get(taskIndex));
                }
                tv.prepareTaskTransformForFilterTaskVisible(toTransform);
                childrenToRemoveOut.add(tv);
            } else {
                toTransform = taskTransforms.get(taskIndex);
                // Use the movement of the visible views to calculate the duration of the animation
                movement = Math.max(movement, Math.abs(toTransform.translationY -
                        (int) tv.getTranslationY()));
            }

            toTransform.startDelay = offset * Constants.Values.TaskStackView.FilterStartDelay;
            childViewTransformsOut.put(tv, toTransform);
            offset++;
        }
        return mConfig.filteringCurrentViewsAnimDuration;
    
voidstartFilteringAnimation(java.util.ArrayList curTasks, java.util.ArrayList curTaskTransforms, java.util.ArrayList tasks, java.util.ArrayList taskTransforms)
Orchestrates the animations of the current child views and any new views.

        // Calculate the transforms to animate out all the existing views if they are not in the
        // new visible range (or to their final positions in the stack if they are)
        final ArrayList<TaskView> childrenToRemove = new ArrayList<TaskView>();
        final HashMap<TaskView, TaskViewTransform> childViewTransforms =
                new HashMap<TaskView, TaskViewTransform>();
        int duration = getExitTransformsForFilterAnimation(curTasks, curTaskTransforms, tasks,
                taskTransforms, childViewTransforms, childrenToRemove);

        // If all the current views are in the visible range of the new stack, then don't wait for
        // views to animate out and animate all the new views into their place
        final boolean unifyNewViewAnimation = childrenToRemove.isEmpty();
        if (unifyNewViewAnimation) {
            int inDuration = getEnterTransformsForFilterAnimation(tasks, taskTransforms,
                    childViewTransforms);
            duration = Math.max(duration, inDuration);
        }

        // Animate all the views to their final transforms
        for (final TaskView tv : childViewTransforms.keySet()) {
            TaskViewTransform t = childViewTransforms.get(tv);
            tv.animate().cancel();
            tv.animate()
                    .withEndAction(new Runnable() {
                        @Override
                        public void run() {
                            childViewTransforms.remove(tv);
                            if (childViewTransforms.isEmpty()) {
                                // Return all the removed children to the view pool
                                for (TaskView tv : childrenToRemove) {
                                    mViewPool.returnViewToPool(tv);
                                }

                                if (!unifyNewViewAnimation) {
                                    // For views that are not already visible, animate them in
                                    childViewTransforms.clear();
                                    int duration = getEnterTransformsForFilterAnimation(tasks,
                                            taskTransforms, childViewTransforms);
                                    for (final TaskView tv : childViewTransforms.keySet()) {
                                        TaskViewTransform t = childViewTransforms.get(tv);
                                        tv.updateViewPropertiesToTaskTransform(t, duration);
                                    }
                                }
                            }
                        }
                    });
            tv.updateViewPropertiesToTaskTransform(t, duration);
        }