use of com.android.systemui.recents.model.Task in project android_frameworks_base by ResurrectionRemix.
the class TaskStackView method bindVisibleTaskViews.
/**
* Synchronizes the set of children {@link TaskView}s to match the visible set of tasks in the
* current {@link TaskStack}. This call does not continue on to update their position to the
* computed {@link TaskViewTransform}s of the visible range, but only ensures that they will
* be added/removed from the view hierarchy and placed in the correct Z order and initial
* position (if not currently on screen).
*
* @param targetStackScroll If provided, will ensure that the set of visible {@link TaskView}s
* includes those visible at the current stack scroll, and all at the
* target stack scroll.
* @param ignoreTaskOverrides If set, the visible task computation will get the transforms for
* tasks at their non-overridden task progress
*/
void bindVisibleTaskViews(float targetStackScroll, boolean ignoreTaskOverrides) {
// Get all the task transforms
ArrayList<Task> tasks = mStack.getStackTasks();
int[] visibleTaskRange = computeVisibleTaskTransforms(mCurrentTaskTransforms, tasks, mStackScroller.getStackScroll(), targetStackScroll, mIgnoreTasks, ignoreTaskOverrides);
// Return all the invisible children to the pool
mTmpTaskViewMap.clear();
List<TaskView> taskViews = getTaskViews();
int lastFocusedTaskIndex = -1;
int taskViewCount = taskViews.size();
for (int i = taskViewCount - 1; i >= 0; i--) {
TaskView tv = taskViews.get(i);
Task task = tv.getTask();
// Skip ignored tasks
if (mIgnoreTasks.contains(task.key)) {
continue;
}
// It is possible for the set of lingering TaskViews to differ from the stack if the
// stack was updated before the relayout. If the task view is no longer in the stack,
// then just return it back to the view pool.
int taskIndex = mStack.indexOfStackTask(task);
TaskViewTransform transform = null;
if (taskIndex != -1) {
transform = mCurrentTaskTransforms.get(taskIndex);
}
if (task.isFreeformTask() || (transform != null && transform.visible)) {
mTmpTaskViewMap.put(task.key, tv);
} else {
if (mTouchExplorationEnabled && Utilities.isDescendentAccessibilityFocused(tv)) {
lastFocusedTaskIndex = taskIndex;
resetFocusedTask(task);
}
mViewPool.returnViewToPool(tv);
}
}
// Pick up all the newly visible children
for (int i = tasks.size() - 1; i >= 0; i--) {
Task task = tasks.get(i);
TaskViewTransform transform = mCurrentTaskTransforms.get(i);
// Skip ignored tasks
if (mIgnoreTasks.contains(task.key)) {
continue;
}
// Skip the invisible non-freeform stack tasks
if (!task.isFreeformTask() && !transform.visible) {
continue;
}
TaskView tv = mTmpTaskViewMap.get(task.key);
if (tv == null) {
tv = mViewPool.pickUpViewFromPool(task, task);
if (task.isFreeformTask()) {
updateTaskViewToTransform(tv, transform, AnimationProps.IMMEDIATE);
} else {
if (transform.rect.top <= mLayoutAlgorithm.mStackRect.top) {
updateTaskViewToTransform(tv, mLayoutAlgorithm.getBackOfStackTransform(), AnimationProps.IMMEDIATE);
} else {
updateTaskViewToTransform(tv, mLayoutAlgorithm.getFrontOfStackTransform(), AnimationProps.IMMEDIATE);
}
}
} else {
// Reattach it in the right z order
final int taskIndex = mStack.indexOfStackTask(task);
final int insertIndex = findTaskViewInsertIndex(task, taskIndex);
if (insertIndex != getTaskViews().indexOf(tv)) {
detachViewFromParent(tv);
attachViewToParent(tv, insertIndex, tv.getLayoutParams());
updateTaskViewsList();
}
}
}
// Update the focus if the previous focused task was returned to the view pool
if (lastFocusedTaskIndex != -1) {
int newFocusedTaskIndex = (lastFocusedTaskIndex < visibleTaskRange[1]) ? visibleTaskRange[1] : visibleTaskRange[0];
setFocusedTask(newFocusedTaskIndex, false, /* scrollToTask */
true);
TaskView focusedTaskView = getChildViewForTask(mFocusedTask);
if (focusedTaskView != null) {
focusedTaskView.requestAccessibilityFocus();
}
}
}
use of com.android.systemui.recents.model.Task in project android_frameworks_base by ResurrectionRemix.
the class TaskStackView method computeVisibleTaskTransforms.
/**
* Computes the task transforms at the current stack scroll for all visible tasks. If a valid
* target stack scroll is provided (ie. is different than {@param curStackScroll}), then the
* visible range includes all tasks at the target stack scroll. This is useful for ensure that
* all views necessary for a transition or animation will be visible at the start.
*
* This call ignores freeform tasks.
*
* @param taskTransforms The set of task view transforms to reuse, this list will be sized to
* match the size of {@param tasks}
* @param tasks The set of tasks for which to generate transforms
* @param curStackScroll The current stack scroll
* @param targetStackScroll The stack scroll that we anticipate we are going to be scrolling to.
* The range of the union of the visible views at the current and
* target stack scrolls will be returned.
* @param ignoreTasksSet The set of tasks to skip for purposes of calculaing the visible range.
* Transforms will still be calculated for the ignore tasks.
* @return the front and back most visible task indices (there may be non visible tasks in
* between this range)
*/
int[] computeVisibleTaskTransforms(ArrayList<TaskViewTransform> taskTransforms, ArrayList<Task> tasks, float curStackScroll, float targetStackScroll, ArraySet<Task.TaskKey> ignoreTasksSet, boolean ignoreTaskOverrides) {
int taskCount = tasks.size();
int[] visibleTaskRange = mTmpIntPair;
visibleTaskRange[0] = -1;
visibleTaskRange[1] = -1;
boolean useTargetStackScroll = Float.compare(curStackScroll, targetStackScroll) != 0;
// We can reuse the task transforms where possible to reduce object allocation
Utilities.matchTaskListSize(tasks, taskTransforms);
// Update the stack transforms
TaskViewTransform frontTransform = null;
TaskViewTransform frontTransformAtTarget = null;
TaskViewTransform transform = null;
TaskViewTransform transformAtTarget = null;
for (int i = taskCount - 1; i >= 0; i--) {
Task task = tasks.get(i);
// Calculate the current and (if necessary) the target transform for the task
transform = mLayoutAlgorithm.getStackTransform(task, curStackScroll, taskTransforms.get(i), frontTransform, ignoreTaskOverrides);
if (useTargetStackScroll && !transform.visible) {
// If we have a target stack scroll and the task is not currently visible, then we
// just update the transform at the new scroll
// TODO: Optimize this
transformAtTarget = mLayoutAlgorithm.getStackTransform(task, targetStackScroll, new TaskViewTransform(), frontTransformAtTarget);
if (transformAtTarget.visible) {
transform.copyFrom(transformAtTarget);
}
}
// visible stack indices
if (ignoreTasksSet.contains(task.key)) {
continue;
}
// the visible stack indices
if (task.isFreeformTask()) {
continue;
}
frontTransform = transform;
frontTransformAtTarget = transformAtTarget;
if (transform.visible) {
if (visibleTaskRange[0] < 0) {
visibleTaskRange[0] = i;
}
visibleTaskRange[1] = i;
}
}
return visibleTaskRange;
}
use of com.android.systemui.recents.model.Task in project android_frameworks_base by ResurrectionRemix.
the class TaskStackView method getLayoutTaskTransforms.
/**
* Returns the task transforms for all the tasks in the stack if the stack was at the given
* {@param stackScroll} and {@param focusState}.
*/
public void getLayoutTaskTransforms(float stackScroll, int focusState, ArrayList<Task> tasks, boolean ignoreTaskOverrides, ArrayList<TaskViewTransform> transformsOut) {
Utilities.matchTaskListSize(tasks, transformsOut);
for (int i = tasks.size() - 1; i >= 0; i--) {
Task task = tasks.get(i);
TaskViewTransform transform = transformsOut.get(i);
mLayoutAlgorithm.getStackTransform(task, stackScroll, focusState, transform, null, true, /* forceUpdate */
ignoreTaskOverrides);
transform.visible = true;
}
}
use of com.android.systemui.recents.model.Task in project android_frameworks_base by ResurrectionRemix.
the class RecentsTvActivity method onResume.
@Override
public void onResume() {
super.onResume();
mPipRecentsOverlayManager.onRecentsResumed();
// Update the recent tasks
updateRecentsTasks();
// If this is a new instance from a configuration change, then we have to manually trigger
// the enter animation state, or if recents was relaunched by AM, without going through
// the normal mechanisms
RecentsConfiguration config = Recents.getConfiguration();
RecentsActivityLaunchState launchState = config.getLaunchState();
boolean wasLaunchedByAm = !launchState.launchedFromHome && !launchState.launchedFromApp;
if (wasLaunchedByAm) {
EventBus.getDefault().send(new EnterRecentsWindowAnimationCompletedEvent());
}
// Notify that recents is now visible
SystemServicesProxy ssp = Recents.getSystemServices();
EventBus.getDefault().send(new RecentsVisibilityChangedEvent(this, true));
if (mTaskStackHorizontalGridView.getStack().getTaskCount() > 1 && !mLaunchedFromHome) {
// If there are 2 or more tasks, and we are not launching from home
// set the selected position to the 2nd task to allow for faster app switching
mTaskStackHorizontalGridView.setSelectedPosition(1);
} else {
mTaskStackHorizontalGridView.setSelectedPosition(0);
}
mRecentsView.getViewTreeObserver().addOnPreDrawListener(this);
View dismissPlaceholder = findViewById(R.id.dismiss_placeholder);
mTalkBackEnabled = ssp.isTouchExplorationEnabled();
if (mTalkBackEnabled) {
dismissPlaceholder.setAccessibilityTraversalBefore(R.id.task_list);
dismissPlaceholder.setAccessibilityTraversalAfter(R.id.dismiss_placeholder);
mTaskStackHorizontalGridView.setAccessibilityTraversalAfter(R.id.dismiss_placeholder);
mTaskStackHorizontalGridView.setAccessibilityTraversalBefore(R.id.pip);
dismissPlaceholder.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
mTaskStackHorizontalGridView.requestFocus();
mTaskStackHorizontalGridView.sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_FOCUSED);
Task focusedTask = mTaskStackHorizontalGridView.getFocusedTask();
if (focusedTask != null) {
mTaskStackViewAdapter.removeTask(focusedTask);
EventBus.getDefault().send(new DeleteTaskDataEvent(focusedTask));
}
}
});
}
// Initialize PIP UI
if (mPipManager.isPipShown()) {
if (mTalkBackEnabled) {
// If talkback is on, use the mPipView to handle focus changes
// between recents row and PIP controls.
mPipView.setVisibility(View.VISIBLE);
} else {
mPipView.setVisibility(View.GONE);
}
// When PIP view has focus, recents overlay view will takes the focus
// as if it's the part of the Recents UI.
mPipRecentsOverlayManager.requestFocus(mTaskStackViewAdapter.getItemCount() > 0);
} else {
mPipView.setVisibility(View.GONE);
mPipRecentsOverlayManager.removePipRecentsOverlayView();
}
}
use of com.android.systemui.recents.model.Task in project android_frameworks_base by ResurrectionRemix.
the class RecentsTvView method launchTaskFomRecents.
/**
* Launch the given task from recents with animation. If the task is not focused, this will
* attempt to scroll to focus the task before launching.
* @param task
*/
private void launchTaskFomRecents(final Task task, boolean animate) {
if (!animate) {
SystemServicesProxy ssp = Recents.getSystemServices();
ssp.startActivityFromRecents(getContext(), task.key, task.title, null);
return;
}
mTaskStackHorizontalView.requestFocus();
Task focusedTask = mTaskStackHorizontalView.getFocusedTask();
if (focusedTask != null && task != focusedTask) {
if (mScrollListener != null) {
mTaskStackHorizontalView.removeOnScrollListener(mScrollListener);
}
mScrollListener = new OnScrollListener() {
@Override
public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
super.onScrollStateChanged(recyclerView, newState);
if (newState == RecyclerView.SCROLL_STATE_IDLE) {
TaskCardView cardView = mTaskStackHorizontalView.getChildViewForTask(task);
if (cardView != null) {
mTransitionHelper.launchTaskFromRecents(mStack, task, mTaskStackHorizontalView, cardView, null, INVALID_STACK_ID);
} else {
// This should not happen normally. If this happens then the data in
// the grid view was altered during the scroll. Log error and launch
// task with no animation.
Log.e(TAG, "Card view for task : " + task + ", returned null.");
SystemServicesProxy ssp = Recents.getSystemServices();
ssp.startActivityFromRecents(getContext(), task.key, task.title, null);
}
mTaskStackHorizontalView.removeOnScrollListener(mScrollListener);
}
}
};
mTaskStackHorizontalView.addOnScrollListener(mScrollListener);
mTaskStackHorizontalView.setSelectedPositionSmooth(((TaskStackHorizontalViewAdapter) mTaskStackHorizontalView.getAdapter()).getPositionOfTask(task));
} else {
mTransitionHelper.launchTaskFromRecents(mStack, task, mTaskStackHorizontalView, mTaskStackHorizontalView.getChildViewForTask(task), null, INVALID_STACK_ID);
}
}
Aggregations