Merge "2D Recents: Show / hide / layout the Clear all button as needed"

This commit is contained in:
TreeHugger Robot
2016-12-20 02:30:52 +00:00
committed by Android (Google) Code Review
4 changed files with 37 additions and 14 deletions

View File

@@ -337,7 +337,8 @@ public class RecentsView extends FrameLayout {
if (RecentsDebugFlags.Static.EnableStackActionButton) {
// Measure the stack action button within the constraints of the space above the stack
Rect buttonBounds = mTaskStackView.mLayoutAlgorithm.mStackActionButtonRect;
Rect buttonBounds = mTaskStackView.mLayoutAlgorithm.getStackActionButtonRect(
mTaskStackView.useGridLayout());
measureChild(mStackActionButton,
MeasureSpec.makeMeasureSpec(buttonBounds.width(), MeasureSpec.AT_MOST),
MeasureSpec.makeMeasureSpec(buttonBounds.height(), MeasureSpec.AT_MOST));
@@ -772,7 +773,8 @@ public class RecentsView extends FrameLayout {
* @return the bounds of the stack action button.
*/
private Rect getStackActionButtonBoundsFromStackLayout() {
Rect actionButtonRect = new Rect(mTaskStackView.mLayoutAlgorithm.mStackActionButtonRect);
Rect actionButtonRect = new Rect(mTaskStackView.mLayoutAlgorithm.getStackActionButtonRect(
mTaskStackView.useGridLayout()));
int left = isLayoutRtl()
? actionButtonRect.left - mStackActionButton.getPaddingLeft()
: actionButtonRect.right + mStackActionButton.getPaddingRight()

View File

@@ -240,14 +240,14 @@ public class TaskStackLayoutAlgorithm {
// This is the current system insets
@ViewDebug.ExportedProperty(category="recents")
public Rect mSystemInsets = new Rect();
// This is the bounds of the stack action above the stack rect
@ViewDebug.ExportedProperty(category="recents")
public Rect mStackActionButtonRect = new Rect();
// The visible ranges when the stack is focused and unfocused
private Range mUnfocusedRange;
private Range mFocusedRange;
// This is the bounds of the stack action above the stack rect
@ViewDebug.ExportedProperty(category="recents")
private Rect mStackActionButtonRect = new Rect();
// The base top margin for the stack from the system insets
@ViewDebug.ExportedProperty(category="recents")
private int mBaseTopMargin;
@@ -732,6 +732,11 @@ public class TaskStackLayoutAlgorithm {
}
}
public Rect getStackActionButtonRect(boolean useGridLayout) {
return useGridLayout
? mTaskGridLayoutAlgorithm.getStackActionButtonRect() : mStackActionButtonRect;
}
/**
* Returns the TaskViewTransform that would put the task just off the back of the stack.
*/

View File

@@ -1345,14 +1345,7 @@ public class TaskStackView extends FrameLayout implements TaskStack.TaskStackCal
setFocusedTask(focusedTaskIndex, false /* scrollToTask */,
false /* requestViewFocus */);
}
// Update the stack action button visibility
if (mStackScroller.getStackScroll() < SHOW_STACK_ACTION_BUTTON_SCROLL_THRESHOLD &&
mStack.getTaskCount() > 0) {
EventBus.getDefault().send(new ShowStackActionButtonEvent(false /* translate */));
} else {
EventBus.getDefault().send(new HideStackActionButtonEvent());
}
updateStackActionButtonVisibility();
}
public boolean isTouchPointInView(float x, float y, TaskView tv) {
@@ -1647,7 +1640,8 @@ public class TaskStackView extends FrameLayout implements TaskStack.TaskStackCal
relayoutTaskViewsOnNextFrame(animation);
}
if (mEnterAnimationComplete) {
// In grid layout, the stack action button always remains visible.
if (mEnterAnimationComplete && !useGridLayout()) {
if (prevScroll > SHOW_STACK_ACTION_BUTTON_SCROLL_THRESHOLD &&
curScroll <= SHOW_STACK_ACTION_BUTTON_SCROLL_THRESHOLD &&
mStack.getTaskCount() > 0) {
@@ -2063,6 +2057,9 @@ public class TaskStackView extends FrameLayout implements TaskStack.TaskStackCal
}
}
// Update the Clear All button in case we're switching in or out of grid layout.
updateStackActionButtonVisibility();
// Trigger a new layout and update to the initial state if necessary
if (event.fromMultiWindow) {
mInitialState = INITIAL_STATE_UPDATE_LAYOUT_ONLY;
@@ -2156,6 +2153,17 @@ public class TaskStackView extends FrameLayout implements TaskStack.TaskStackCal
Settings.System.LOCK_TO_APP_ENABLED) != 0;
}
private void updateStackActionButtonVisibility() {
// Always show the button in grid layout.
if (useGridLayout() ||
(mStackScroller.getStackScroll() < SHOW_STACK_ACTION_BUTTON_SCROLL_THRESHOLD &&
mStack.getTaskCount() > 0)) {
EventBus.getDefault().send(new ShowStackActionButtonEvent(false /* translate */));
} else {
EventBus.getDefault().send(new HideStackActionButtonEvent());
}
}
public void dump(String prefix, PrintWriter writer) {
String innerPrefix = prefix + " ";
String id = Integer.toHexString(System.identityHashCode(this));

View File

@@ -146,4 +146,12 @@ public class TaskGridLayoutAlgorithm {
int usableHeight = mScreenSize.y - mSystemInsets.top - mSystemInsets.bottom;
mAppAspectRatio = (float) usableWidth / (float) usableHeight;
}
public Rect getStackActionButtonRect() {
Rect buttonRect = new Rect(mDisplayRect);
buttonRect.right -= mPaddingLeftRight;
buttonRect.left += mPaddingLeftRight;
buttonRect.bottom = buttonRect.top + mPaddingTopBottom;
return buttonRect;
}
}