Search in sources :

Example 21 with Task

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

the class RecentsImpl method getThumbnailTransitionTransform.

/**
     * Returns the transition rect for the given task id.
     */
private TaskViewTransform getThumbnailTransitionTransform(TaskStackView stackView, Task runningTaskOut, Rect windowOverrideRect) {
    // Find the running task in the TaskStack
    TaskStack stack = stackView.getStack();
    Task launchTask = stack.getLaunchTarget();
    if (launchTask != null) {
        runningTaskOut.copyFrom(launchTask);
    } else {
        // If no task is specified or we can not find the task just use the front most one
        launchTask = stack.getStackFrontMostTask(true);
        runningTaskOut.copyFrom(launchTask);
    }
    // Get the transform for the running task
    stackView.updateLayoutAlgorithm(true);
    stackView.updateToInitialState();
    stackView.getStackAlgorithm().getStackTransformScreenCoordinates(launchTask, stackView.getScroller().getStackScroll(), mTmpTransform, null, windowOverrideRect);
    return mTmpTransform;
}
Also used : TaskStack(com.android.systemui.recents.model.TaskStack) Task(com.android.systemui.recents.model.Task)

Example 22 with Task

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

the class RecentsImpl method showNextTask.

/**
     * Transitions to the next recent task in the stack.
     */
public void showNextTask() {
    SystemServicesProxy ssp = Recents.getSystemServices();
    RecentsTaskLoader loader = Recents.getTaskLoader();
    RecentsTaskLoadPlan plan = loader.createLoadPlan(mContext);
    loader.preloadTasks(plan, -1, false);
    TaskStack focusedStack = plan.getTaskStack();
    // Return early if there are no tasks in the focused stack
    if (focusedStack == null || focusedStack.getTaskCount() == 0)
        return;
    // Return early if there is no running task
    ActivityManager.RunningTaskInfo runningTask = ssp.getRunningTask();
    if (runningTask == null)
        return;
    // Find the task in the recents list
    boolean isRunningTaskInHomeStack = SystemServicesProxy.isHomeStack(runningTask.stackId);
    ArrayList<Task> tasks = focusedStack.getStackTasks();
    Task toTask = null;
    ActivityOptions launchOpts = null;
    int taskCount = tasks.size();
    for (int i = taskCount - 1; i >= 1; i--) {
        Task task = tasks.get(i);
        if (isRunningTaskInHomeStack) {
            toTask = tasks.get(i - 1);
            launchOpts = ActivityOptions.makeCustomAnimation(mContext, R.anim.recents_launch_next_affiliated_task_target, R.anim.recents_fast_toggle_app_home_exit);
            break;
        } else if (task.key.id == runningTask.id) {
            toTask = tasks.get(i - 1);
            launchOpts = ActivityOptions.makeCustomAnimation(mContext, R.anim.recents_launch_prev_affiliated_task_target, R.anim.recents_launch_prev_affiliated_task_source);
            break;
        }
    }
    // Return early if there is no next task
    if (toTask == null) {
        ssp.startInPlaceAnimationOnFrontMostApplication(ActivityOptions.makeCustomInPlaceAnimation(mContext, R.anim.recents_launch_prev_affiliated_task_bounce));
        return;
    }
    // Launch the task
    ssp.startActivityFromRecents(mContext, toTask.key, toTask.title, launchOpts);
}
Also used : SystemServicesProxy(com.android.systemui.recents.misc.SystemServicesProxy) TaskStack(com.android.systemui.recents.model.TaskStack) Task(com.android.systemui.recents.model.Task) RecentsTaskLoadPlan(com.android.systemui.recents.model.RecentsTaskLoadPlan) RecentsTaskLoader(com.android.systemui.recents.model.RecentsTaskLoader) ActivityManager(android.app.ActivityManager) ActivityOptions(android.app.ActivityOptions)

Example 23 with Task

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

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 24 with Task

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

the class RecentsImpl method getThumbnailTransitionActivityOptions.

/**
     * Creates the activity options for an app->recents transition.
     */
private ActivityOptions getThumbnailTransitionActivityOptions(ActivityManager.RunningTaskInfo runningTask, TaskStackView stackView, Rect windowOverrideRect) {
    if (runningTask != null && runningTask.stackId == FREEFORM_WORKSPACE_STACK_ID) {
        ArrayList<AppTransitionAnimationSpec> specs = new ArrayList<>();
        ArrayList<Task> tasks = stackView.getStack().getStackTasks();
        TaskStackLayoutAlgorithm stackLayout = stackView.getStackAlgorithm();
        TaskStackViewScroller stackScroller = stackView.getScroller();
        stackView.updateLayoutAlgorithm(true);
        stackView.updateToInitialState();
        for (int i = tasks.size() - 1; i >= 0; i--) {
            Task task = tasks.get(i);
            if (task.isFreeformTask()) {
                mTmpTransform = stackLayout.getStackTransformScreenCoordinates(task, stackScroller.getStackScroll(), mTmpTransform, null, windowOverrideRect);
                Bitmap thumbnail = drawThumbnailTransitionBitmap(task, mTmpTransform, mThumbTransitionBitmapCache);
                Rect toTaskRect = new Rect();
                mTmpTransform.rect.round(toTaskRect);
                specs.add(new AppTransitionAnimationSpec(task.key.id, thumbnail, toTaskRect));
            }
        }
        AppTransitionAnimationSpec[] specsArray = new AppTransitionAnimationSpec[specs.size()];
        specs.toArray(specsArray);
        return ActivityOptions.makeThumbnailAspectScaleDownAnimation(mDummyStackView, specsArray, mHandler, null, this);
    } else {
        // Update the destination rect
        Task toTask = new Task();
        TaskViewTransform toTransform = getThumbnailTransitionTransform(stackView, toTask, windowOverrideRect);
        Bitmap thumbnail = drawThumbnailTransitionBitmap(toTask, toTransform, mThumbTransitionBitmapCache);
        if (thumbnail != null) {
            RectF toTaskRect = toTransform.rect;
            return ActivityOptions.makeThumbnailAspectScaleDownAnimation(mDummyStackView, thumbnail, (int) toTaskRect.left, (int) toTaskRect.top, (int) toTaskRect.width(), (int) toTaskRect.height(), mHandler, null);
        }
        // If both the screenshot and thumbnail fails, then just fall back to the default transition
        return getUnknownTransitionActivityOptions();
    }
}
Also used : TaskStackViewScroller(com.android.systemui.recents.views.TaskStackViewScroller) Task(com.android.systemui.recents.model.Task) Rect(android.graphics.Rect) ArrayList(java.util.ArrayList) RectF(android.graphics.RectF) Bitmap(android.graphics.Bitmap) AppTransitionAnimationSpec(android.view.AppTransitionAnimationSpec) TaskViewTransform(com.android.systemui.recents.views.TaskViewTransform) TaskStackLayoutAlgorithm(com.android.systemui.recents.views.TaskStackLayoutAlgorithm)

Example 25 with Task

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

the class FreeformWorkspaceLayoutAlgorithm method update.

/**
     * Updates the layout for each of the freeform workspace tasks.  This is called after the stack
     * layout is updated.
     */
public void update(List<Task> freeformTasks, TaskStackLayoutAlgorithm stackLayout) {
    Collections.reverse(freeformTasks);
    mTaskRectMap.clear();
    int numFreeformTasks = stackLayout.mNumFreeformTasks;
    if (!freeformTasks.isEmpty()) {
        // Normalize the widths so that we can calculate the best layout below
        int workspaceWidth = stackLayout.mFreeformRect.width();
        int workspaceHeight = stackLayout.mFreeformRect.height();
        float normalizedWorkspaceWidth = (float) workspaceWidth / workspaceHeight;
        float normalizedWorkspaceHeight = 1f;
        float[] normalizedTaskWidths = new float[numFreeformTasks];
        for (int i = 0; i < numFreeformTasks; i++) {
            Task task = freeformTasks.get(i);
            float rowTaskWidth;
            if (task.bounds != null) {
                rowTaskWidth = (float) task.bounds.width() / task.bounds.height();
            } else {
                // If this is a stack task that was dragged into the freeform workspace, then
                // the task will not yet have an associated bounds, so assume the full workspace
                // width for the time being
                rowTaskWidth = normalizedWorkspaceWidth;
            }
            // Bound the task width to the workspace width so that at the worst case, it will
            // fit its own row
            normalizedTaskWidths[i] = Math.min(rowTaskWidth, normalizedWorkspaceWidth);
        }
        // Determine the scale to best fit each of the tasks in the workspace
        float rowScale = 0.85f;
        float rowWidth = 0f;
        float maxRowWidth = 0f;
        int rowCount = 1;
        for (int i = 0; i < numFreeformTasks; ) {
            float width = normalizedTaskWidths[i] * rowScale;
            if (rowWidth + width > normalizedWorkspaceWidth) {
                // That is too long for this row, create new row
                if ((rowCount + 1) * rowScale > normalizedWorkspaceHeight) {
                    // The new row is too high, so we need to try fitting again.  Update the
                    // scale to be the smaller of the scale needed to fit the task in the
                    // previous row, or the scale needed to fit the new row
                    rowScale = Math.min(normalizedWorkspaceWidth / (rowWidth + width), normalizedWorkspaceHeight / (rowCount + 1));
                    rowCount = 1;
                    rowWidth = 0;
                    i = 0;
                } else {
                    // The new row fits, so continue
                    rowWidth = width;
                    rowCount++;
                    i++;
                }
            } else {
                // Task is OK in this row
                rowWidth += width;
                i++;
            }
            maxRowWidth = Math.max(rowWidth, maxRowWidth);
        }
        // Normalize each of the actual rects to that scale
        float defaultRowLeft = ((1f - (maxRowWidth / normalizedWorkspaceWidth)) * workspaceWidth) / 2f;
        float rowLeft = defaultRowLeft;
        float rowTop = ((1f - (rowScale * rowCount)) * workspaceHeight) / 2f;
        float rowHeight = rowScale * workspaceHeight;
        for (int i = 0; i < numFreeformTasks; i++) {
            Task task = freeformTasks.get(i);
            float width = rowHeight * normalizedTaskWidths[i];
            if (rowLeft + width > workspaceWidth) {
                // This goes on the next line
                rowTop += rowHeight;
                rowLeft = defaultRowLeft;
            }
            RectF rect = new RectF(rowLeft, rowTop, rowLeft + width, rowTop + rowHeight);
            rect.inset(mTaskPadding, mTaskPadding);
            rowLeft += width;
            mTaskRectMap.put(task.key, rect);
        }
    }
}
Also used : RectF(android.graphics.RectF) Task(com.android.systemui.recents.model.Task)

Aggregations

Task (com.android.systemui.recents.model.Task)225 TaskStack (com.android.systemui.recents.model.TaskStack)56 GridTaskView (com.android.systemui.recents.views.grid.GridTaskView)43 RecentsActivityLaunchState (com.android.systemui.recents.RecentsActivityLaunchState)30 SystemServicesProxy (com.android.systemui.recents.misc.SystemServicesProxy)25 ArrayList (java.util.ArrayList)23 ActivityOptions (android.app.ActivityOptions)20 RecentsConfiguration (com.android.systemui.recents.RecentsConfiguration)20 RecentsTaskLoadPlan (com.android.systemui.recents.model.RecentsTaskLoadPlan)20 RecentsTaskLoader (com.android.systemui.recents.model.RecentsTaskLoader)20 Resources (android.content.res.Resources)15 AppTransitionAnimationSpec (android.view.AppTransitionAnimationSpec)15 LaunchTaskEvent (com.android.systemui.recents.events.activity.LaunchTaskEvent)11 TimeInterpolator (android.animation.TimeInterpolator)10 ActivityManager (android.app.ActivityManager)10 Bitmap (android.graphics.Bitmap)10 Rect (android.graphics.Rect)10 RectF (android.graphics.RectF)10 Interpolator (android.view.animation.Interpolator)10 PathInterpolator (android.view.animation.PathInterpolator)10