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;
}
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);
}
}
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);
}
}
}
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;
}
}
}
}
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();
}
Aggregations