diff options
author | Tony Wickham <twickham@google.com> | 2019-04-24 11:32:59 -0700 |
---|---|---|
committer | Tony Wickham <twickham@google.com> | 2019-04-24 17:09:34 -0700 |
commit | 66d1c2fada7f2c9bb4bd25dd55b1584d2270c020 (patch) | |
tree | 358fa0e02f8b3cd844c9bfe126740b236b3775ec /src | |
parent | b0c81fc031162d163922f7cdcbf2cbcf3de958b5 (diff) | |
download | android_packages_apps_Trebuchet-66d1c2fada7f2c9bb4bd25dd55b1584d2270c020.tar.gz android_packages_apps_Trebuchet-66d1c2fada7f2c9bb4bd25dd55b1584d2270c020.tar.bz2 android_packages_apps_Trebuchet-66d1c2fada7f2c9bb4bd25dd55b1584d2270c020.zip |
Hide Clear all button during quick switch
- Add support for mMinScrollX to PagedView
- Add RECENTS_CLEAR_ALL_BUTTON as a state-specified visible element
- In BackgroundAppState, set Clear all invisible and bound RecentsView
scroll to the last task
Test:
- Open an app, quick switch until reaching the end, ensure Clear all
does not show up and an overscroll effect is performed
- Enter overview, scroll to the end and ensure Clear all shows up
- Same tests in RTL and 3rd party launcher
Bug: 130160876
Change-Id: I5fb958744d0055b83ced1f8b0d7face0e06a0cc5
Diffstat (limited to 'src')
-rw-r--r-- | src/com/android/launcher3/LauncherState.java | 3 | ||||
-rw-r--r-- | src/com/android/launcher3/PagedView.java | 76 | ||||
-rw-r--r-- | src/com/android/launcher3/Workspace.java | 3 |
3 files changed, 56 insertions, 26 deletions
diff --git a/src/com/android/launcher3/LauncherState.java b/src/com/android/launcher3/LauncherState.java index 124574cc0..51079b0e6 100644 --- a/src/com/android/launcher3/LauncherState.java +++ b/src/com/android/launcher3/LauncherState.java @@ -18,6 +18,7 @@ package com.android.launcher3; import static android.view.View.IMPORTANT_FOR_ACCESSIBILITY_AUTO; import static android.view.View.IMPORTANT_FOR_ACCESSIBILITY_NO_HIDE_DESCENDANTS; import static android.view.accessibility.AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED; + import static com.android.launcher3.TestProtocol.ALL_APPS_STATE_ORDINAL; import static com.android.launcher3.TestProtocol.BACKGROUND_APP_STATE_ORDINAL; import static com.android.launcher3.TestProtocol.NORMAL_STATE_ORDINAL; @@ -30,7 +31,6 @@ import static com.android.launcher3.states.RotationHelper.REQUEST_NONE; import android.view.animation.Interpolator; -import com.android.launcher3.config.FeatureFlags; import com.android.launcher3.states.SpringLoadedState; import com.android.launcher3.uioverrides.UiFactory; import com.android.launcher3.uioverrides.states.AllAppsState; @@ -58,6 +58,7 @@ public class LauncherState { public static final int ALL_APPS_HEADER_EXTRA = 1 << 3; // e.g. app predictions public static final int ALL_APPS_CONTENT = 1 << 4; public static final int VERTICAL_SWIPE_INDICATOR = 1 << 5; + public static final int RECENTS_CLEAR_ALL_BUTTON = 1 << 6; protected static final int FLAG_MULTI_PAGE = 1 << 0; protected static final int FLAG_DISABLE_ACCESSIBILITY = 1 << 1; diff --git a/src/com/android/launcher3/PagedView.java b/src/com/android/launcher3/PagedView.java index ed7778612..abb45e51d 100644 --- a/src/com/android/launcher3/PagedView.java +++ b/src/com/android/launcher3/PagedView.java @@ -98,6 +98,7 @@ public abstract class PagedView<T extends View & PageIndicator> extends ViewGrou @ViewDebug.ExportedProperty(category = "launcher") protected int mNextPage = INVALID_PAGE; + protected int mMinScrollX; protected int mMaxScrollX; protected OverScroller mScroller; private Interpolator mDefaultInterpolator; @@ -266,11 +267,40 @@ public abstract class PagedView<T extends View & PageIndicator> extends ViewGrou } private int validateNewPage(int newPage) { + newPage = ensureWithinScrollBounds(newPage); // Ensure that it is clamped by the actual set of children in all cases return Utilities.boundToRange(newPage, 0, getPageCount() - 1); } /** + * @return The closest page to the provided page that is within mMinScrollX and mMaxScrollX. + */ + private int ensureWithinScrollBounds(int page) { + int dir = !mIsRtl ? 1 : - 1; + int currScroll = getScrollForPage(page); + int prevScroll; + while (currScroll < mMinScrollX) { + page += dir; + prevScroll = currScroll; + currScroll = getScrollForPage(page); + if (currScroll <= prevScroll) { + Log.e(TAG, "validateNewPage: failed to find a page > mMinScrollX"); + break; + } + } + while (currScroll > mMaxScrollX) { + page -= dir; + prevScroll = currScroll; + currScroll = getScrollForPage(page); + if (currScroll >= prevScroll) { + Log.e(TAG, "validateNewPage: failed to find a page < mMaxScrollX"); + break; + } + } + return page; + } + + /** * Sets the current page. */ public void setCurrentPage(int currentPage) { @@ -348,29 +378,29 @@ public abstract class PagedView<T extends View & PageIndicator> extends ViewGrou public void scrollTo(int x, int y) { mUnboundedScrollX = x; - boolean isXBeforeFirstPage = mIsRtl ? (x > mMaxScrollX) : (x < 0); - boolean isXAfterLastPage = mIsRtl ? (x < 0) : (x > mMaxScrollX); + boolean isXBeforeFirstPage = mIsRtl ? (x > mMaxScrollX) : (x < mMinScrollX); + boolean isXAfterLastPage = mIsRtl ? (x < mMinScrollX) : (x > mMaxScrollX); if (!isXBeforeFirstPage && !isXAfterLastPage) { mSpringOverScrollX = 0; } if (isXBeforeFirstPage) { - super.scrollTo(mIsRtl ? mMaxScrollX : 0, y); + super.scrollTo(mIsRtl ? mMaxScrollX : mMinScrollX, y); if (mAllowOverScroll) { mWasInOverscroll = true; if (mIsRtl) { overScroll(x - mMaxScrollX); } else { - overScroll(x); + overScroll(x - mMinScrollX); } } } else if (isXAfterLastPage) { - super.scrollTo(mIsRtl ? 0 : mMaxScrollX, y); + super.scrollTo(mIsRtl ? mMinScrollX : mMaxScrollX, y); if (mAllowOverScroll) { mWasInOverscroll = true; if (mIsRtl) { - overScroll(x); + overScroll(x - mMinScrollX); } else { overScroll(x - mMaxScrollX); } @@ -557,12 +587,12 @@ public abstract class PagedView<T extends View & PageIndicator> extends ViewGrou // Wait until all transitions are complete. if (!transition.isRunning()) { transition.removeTransitionListener(this); - updateMaxScrollX(); + updateMinAndMaxScrollX(); } } }); } else { - updateMaxScrollX(); + updateMinAndMaxScrollX(); } if (mFirstLayout && mCurrentPage >= 0 && mCurrentPage < childCount) { @@ -627,12 +657,13 @@ public abstract class PagedView<T extends View & PageIndicator> extends ViewGrou return 0; } - private void updateMaxScrollX() { + protected void updateMinAndMaxScrollX() { + mMinScrollX = computeMinScrollX(); mMaxScrollX = computeMaxScrollX(); } - public int getMaxScrollX() { - return mMaxScrollX; + protected int computeMinScrollX() { + return 0; } protected int computeMaxScrollX() { @@ -1010,12 +1041,8 @@ public abstract class PagedView<T extends View & PageIndicator> extends ViewGrou return; } - if (overScrollAmount < 0) { - super.scrollTo(overScrollAmount, getScrollY()); - } else { - int x = Math.max(0, Math.min(getScrollX(), mMaxScrollX)); - super.scrollTo(x + overScrollAmount, getScrollY()); - } + int x = Utilities.boundToRange(getScrollX(), mMinScrollX, mMaxScrollX); + super.scrollTo(x + overScrollAmount, getScrollY()); invalidate(); } @@ -1030,7 +1057,7 @@ public abstract class PagedView<T extends View & PageIndicator> extends ViewGrou if (mFreeScroll && !mScroller.isFinished()) { if (amount < 0) { - super.scrollTo(amount, getScrollY()); + super.scrollTo(mMinScrollX + amount, getScrollY()); } else { super.scrollTo(mMaxScrollX + amount, getScrollY()); } @@ -1169,12 +1196,12 @@ public abstract class PagedView<T extends View & PageIndicator> extends ViewGrou int initialScrollX = getScrollX(); if (((initialScrollX >= mMaxScrollX) && (isVelocityXLeft || !isFling)) || - ((initialScrollX <= 0) && (!isVelocityXLeft || !isFling))) { - mScroller.springBack(getScrollX(), 0, mMaxScrollX); + ((initialScrollX <= mMinScrollX) && (!isVelocityXLeft || !isFling))) { + mScroller.springBack(getScrollX(), mMinScrollX, mMaxScrollX); } else { mScroller.setInterpolator(mDefaultInterpolator); mScroller.fling(initialScrollX, -velocityX, - 0, mMaxScrollX, + mMinScrollX, mMaxScrollX, Math.round(getWidth() * 0.5f * OVERSCROLL_DAMP_FACTOR)); int finalX = mScroller.getFinalPos(); @@ -1182,12 +1209,13 @@ public abstract class PagedView<T extends View & PageIndicator> extends ViewGrou int firstPageScroll = getScrollForPage(!mIsRtl ? 0 : getPageCount() - 1); int lastPageScroll = getScrollForPage(!mIsRtl ? getPageCount() - 1 : 0); - if (finalX > 0 && finalX < mMaxScrollX) { + if (finalX > mMinScrollX && finalX < mMaxScrollX) { // If scrolling ends in the half of the added space that is closer to // the end, settle to the end. Otherwise snap to the nearest page. // If flinging past one of the ends, don't change the velocity as it // will get stopped at the end anyway. - int pageSnappedX = finalX < firstPageScroll / 2 ? 0 + int pageSnappedX = finalX < (firstPageScroll + mMinScrollX) / 2 + ? mMinScrollX : finalX > (lastPageScroll + mMaxScrollX) / 2 ? mMaxScrollX : getScrollForPage(mNextPage); @@ -1347,7 +1375,7 @@ public abstract class PagedView<T extends View & PageIndicator> extends ViewGrou } protected boolean isInOverScroll() { - return (getScrollX() > mMaxScrollX || getScrollX() < 0); + return (getScrollX() > mMaxScrollX || getScrollX() < mMinScrollX); } protected int getPageSnapDuration() { diff --git a/src/com/android/launcher3/Workspace.java b/src/com/android/launcher3/Workspace.java index efb50f0dd..8849768f8 100644 --- a/src/com/android/launcher3/Workspace.java +++ b/src/com/android/launcher3/Workspace.java @@ -956,7 +956,8 @@ public class Workspace extends PagedView<WorkspacePageIndicator> private boolean isScrollingOverlay() { return mLauncherOverlay != null && - ((mIsRtl && getUnboundedScrollX() > mMaxScrollX) || (!mIsRtl && getUnboundedScrollX() < 0)); + ((mIsRtl && getUnboundedScrollX() > mMaxScrollX) + || (!mIsRtl && getUnboundedScrollX() < mMinScrollX)); } @Override |