Merge "Don't notifyPageSwitchListener until page settles (issue 12069757)" into jb-ub-now-kermit
diff --git a/src/com/android/launcher3/PagedView.java b/src/com/android/launcher3/PagedView.java
index 196913e..8d5d8dd 100644
--- a/src/com/android/launcher3/PagedView.java
+++ b/src/com/android/launcher3/PagedView.java
@@ -449,6 +449,10 @@
return new PageIndicator.PageMarkerResources();
}
+ /**
+ * Add a page change listener which will be called when a page is _finished_ listening.
+ *
+ */
public void setPageSwitchListener(PageSwitchListener pageSwitchListener) {
mPageSwitchListener = pageSwitchListener;
if (mPageSwitchListener != null) {
@@ -523,6 +527,7 @@
*/
void stopScrolling() {
mCurrentPage = getNextPage();
+ notifyPageSwitchListener();
forceFinishScroller();
}
@@ -572,11 +577,19 @@
return mRestorePage;
}
+ /**
+ * Should be called whenever the page changes. In the case of a scroll, we wait until the page
+ * has settled.
+ */
protected void notifyPageSwitchListener() {
if (mPageSwitchListener != null) {
- mPageSwitchListener.onPageSwitch(getPageAt(mCurrentPage), mCurrentPage);
+ mPageSwitchListener.onPageSwitch(getPageAt(getNextPage()), getNextPage());
}
+ updatePageIndicator();
+ }
+
+ private void updatePageIndicator() {
// Update the page indicator (when we aren't reordering)
if (mPageIndicator != null && !isReordering(false)) {
mPageIndicator.setActiveMarker(getNextPage());
@@ -2230,7 +2243,7 @@
mScroller.startScroll(mUnboundedScrollX, 0, delta, 0, duration);
- notifyPageSwitchListener();
+ updatePageIndicator();
// Trigger a compute() to finish switching pages if necessary
if (immediate) {
diff --git a/src/com/android/launcher3/Workspace.java b/src/com/android/launcher3/Workspace.java
index e6550bc..b6276c0 100644
--- a/src/com/android/launcher3/Workspace.java
+++ b/src/com/android/launcher3/Workspace.java
@@ -1200,7 +1200,7 @@
@Override
protected void notifyPageSwitchListener() {
super.notifyPageSwitchListener();
- Launcher.setScreen(mCurrentPage);
+ Launcher.setScreen(getNextPage());
if (hasCustomContent() && getNextPage() == 0 && !mCustomContentShowing) {
mCustomContentShowing = true;