Keep clear-all button revealed after dismiss

If it was visible before the dismiss, it will be visible after that.
As a nice side effect, it will preserve visibility on any layout, say,
after a rotation.

Bug: 79117932
Test: Manual
Change-Id: Ia8a544af1326458d4e2d7a07ae2b668f604bc0b3
This commit is contained in:
Vadim Tryshev 2018-05-10 15:42:42 -07:00
parent c14adabe99
commit 3154cd16b0
2 changed files with 31 additions and 7 deletions

View File

@ -121,6 +121,8 @@ public abstract class RecentsView<T extends BaseActivity> extends PagedView impl
// Keeps track of the previously known visible tasks for purposes of loading/unloading task data // Keeps track of the previously known visible tasks for purposes of loading/unloading task data
private final SparseBooleanArray mHasVisibleTaskData = new SparseBooleanArray(); private final SparseBooleanArray mHasVisibleTaskData = new SparseBooleanArray();
private boolean mIsClearAllButtonFullyRevealed;
/** /**
* TODO: Call reloadIdNeeded in onTaskStackChanged. * TODO: Call reloadIdNeeded in onTaskStackChanged.
*/ */
@ -337,11 +339,15 @@ public abstract class RecentsView<T extends BaseActivity> extends PagedView impl
} }
} }
private int getScrollEnd() {
return mIsRtl ? 0 : mMaxScrollX;
}
private float calculateClearAllButtonAlpha() { private float calculateClearAllButtonAlpha() {
final int childCount = getChildCount(); final int childCount = getChildCount();
if (mShowEmptyMessage || childCount == 0) return 0; if (mShowEmptyMessage || childCount == 0) return 0;
final int scrollEnd = mIsRtl ? 0 : mMaxScrollX; final int scrollEnd = getScrollEnd();
final int oldestChildScroll = getScrollForPage(childCount - 1); final int oldestChildScroll = getScrollForPage(childCount - 1);
return Utilities.boundToRange( return Utilities.boundToRange(
@ -352,6 +358,7 @@ public abstract class RecentsView<T extends BaseActivity> extends PagedView impl
private void updateClearAllButtonAlpha() { private void updateClearAllButtonAlpha() {
if (mClearAllButton != null) { if (mClearAllButton != null) {
final float alpha = calculateClearAllButtonAlpha(); final float alpha = calculateClearAllButtonAlpha();
mIsClearAllButtonFullyRevealed = alpha == 1;
mClearAllButton.setAlpha(alpha * mContentAlpha); mClearAllButton.setAlpha(alpha * mContentAlpha);
} }
} }
@ -362,10 +369,19 @@ public abstract class RecentsView<T extends BaseActivity> extends PagedView impl
updateClearAllButtonAlpha(); updateClearAllButtonAlpha();
} }
@Override
protected void restoreScrollOnLayout() {
if (mIsClearAllButtonFullyRevealed) {
scrollAndForceFinish(getScrollEnd());
} else {
super.restoreScrollOnLayout();
}
}
@Override @Override
public boolean onTouchEvent(MotionEvent ev) { public boolean onTouchEvent(MotionEvent ev) {
if (ev.getAction() == MotionEvent.ACTION_DOWN && mTouchState == TOUCH_STATE_REST if (ev.getAction() == MotionEvent.ACTION_DOWN && mTouchState == TOUCH_STATE_REST
&& mScroller.isFinished() && mClearAllButton.getAlpha() > 0) { && mScroller.isFinished() && mIsClearAllButtonFullyRevealed) {
mClearAllButton.getHitRect(mTempRect); mClearAllButton.getHitRect(mTempRect);
mTempRect.offset(-getLeft(), -getTop()); mTempRect.offset(-getLeft(), -getTop());
if (mTempRect.contains((int) ev.getX(), (int) ev.getY())) { if (mTempRect.contains((int) ev.getX(), (int) ev.getY())) {
@ -829,7 +845,7 @@ public abstract class RecentsView<T extends BaseActivity> extends PagedView impl
removeView(taskView); removeView(taskView);
if (getChildCount() == 0) { if (getChildCount() == 0) {
onAllTasksRemoved(); onAllTasksRemoved();
} else { } else if (!mIsClearAllButtonFullyRevealed) {
snapToPageImmediately(pageToSnapTo); snapToPageImmediately(pageToSnapTo);
} }
} }

View File

@ -238,6 +238,12 @@ public abstract class PagedView<T extends View & PageIndicator> extends ViewGrou
return index; return index;
} }
protected void scrollAndForceFinish(int scrollX) {
scrollTo(scrollX, 0);
mScroller.setFinalX(scrollX);
forceFinishScroller(true);
}
/** /**
* Updates the scroll of the current page immediately to its final scroll position. We use this * Updates the scroll of the current page immediately to its final scroll position. We use this
* in CustomizePagedView to allow tabs to share the same PagedView while resetting the scroll of * in CustomizePagedView to allow tabs to share the same PagedView while resetting the scroll of
@ -249,9 +255,7 @@ public abstract class PagedView<T extends View & PageIndicator> extends ViewGrou
if (0 <= mCurrentPage && mCurrentPage < getPageCount()) { if (0 <= mCurrentPage && mCurrentPage < getPageCount()) {
newX = getScrollForPage(mCurrentPage); newX = getScrollForPage(mCurrentPage);
} }
scrollTo(newX, 0); scrollAndForceFinish(newX);
mScroller.setFinalX(newX);
forceFinishScroller(true);
} }
private void abortScrollerAnimation(boolean resetNextPage) { private void abortScrollerAnimation(boolean resetNextPage) {
@ -538,6 +542,10 @@ public abstract class PagedView<T extends View & PageIndicator> extends ViewGrou
setMeasuredDimension(widthSize, heightSize); setMeasuredDimension(widthSize, heightSize);
} }
protected void restoreScrollOnLayout() {
setCurrentPage(getNextPage());
}
@SuppressLint("DrawAllocation") @SuppressLint("DrawAllocation")
@Override @Override
protected void onLayout(boolean changed, int left, int top, int right, int bottom) { protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
@ -589,7 +597,7 @@ public abstract class PagedView<T extends View & PageIndicator> extends ViewGrou
} }
if (mScroller.isFinished() && pageScrollChanged) { if (mScroller.isFinished() && pageScrollChanged) {
setCurrentPage(getNextPage()); restoreScrollOnLayout();
} }
} }