am 606726ba: Merge "Preventing null pointer crash when opening a folder" into ub-launcher3-burnaby
* commit '606726ba289583a67188d9448b220c2e3fae87d7':
Preventing null pointer crash when opening a folder
diff --git a/src/com/android/launcher3/BaseRecyclerView.java b/src/com/android/launcher3/BaseRecyclerView.java
index f0d8b3b..9d713e3 100644
--- a/src/com/android/launcher3/BaseRecyclerView.java
+++ b/src/com/android/launcher3/BaseRecyclerView.java
@@ -268,6 +268,13 @@
}
/**
+ * Returns whether fast scrolling is supported in the current state.
+ */
+ protected boolean supportsFastScrolling() {
+ return true;
+ }
+
+ /**
* Maps the touch (from 0..1) to the adapter position that should be visible.
* <p>Override in each subclass of this base class.
*/
diff --git a/src/com/android/launcher3/BaseRecyclerViewFastScrollBar.java b/src/com/android/launcher3/BaseRecyclerViewFastScrollBar.java
index fcee7e8..32ea576 100644
--- a/src/com/android/launcher3/BaseRecyclerViewFastScrollBar.java
+++ b/src/com/android/launcher3/BaseRecyclerViewFastScrollBar.java
@@ -189,7 +189,8 @@
// Check if we should start scrolling, but ignore this fastscroll gesture if we have
// exceeded some fixed movement
mIgnoreDragGesture |= Math.abs(y - downY) > config.getScaledPagingTouchSlop();
- if (!mIsDragging && !mIgnoreDragGesture && isNearThumb(downX, lastY) &&
+ if (!mIsDragging && !mIgnoreDragGesture && mRv.supportsFastScrolling() &&
+ isNearThumb(downX, lastY) &&
Math.abs(y - downY) > config.getScaledTouchSlop()) {
mRv.getParent().requestDisallowInterceptTouchEvent(true);
mIsDragging = true;
diff --git a/src/com/android/launcher3/Launcher.java b/src/com/android/launcher3/Launcher.java
index 1f843cb..8bfc841 100644
--- a/src/com/android/launcher3/Launcher.java
+++ b/src/com/android/launcher3/Launcher.java
@@ -1614,7 +1614,10 @@
// processing a multi-step drop
if (mAppsView != null && mWidgetsView != null &&
mPendingAddInfo.container == ItemInfo.NO_ID) {
- showWorkspace(false);
+ if (!showWorkspace(false)) {
+ // If we are already on the workspace, then manually reset all apps
+ mAppsView.reset();
+ }
}
} else if (Intent.ACTION_USER_PRESENT.equals(action)) {
mUserPresent = true;
@@ -3259,20 +3262,32 @@
}
}
- public void showWorkspace(boolean animated) {
- showWorkspace(WorkspaceStateTransitionAnimation.SCROLL_TO_CURRENT_PAGE, animated, null);
+ /**
+ * @return whether or not the Launcher state changed.
+ */
+ public boolean showWorkspace(boolean animated) {
+ return showWorkspace(WorkspaceStateTransitionAnimation.SCROLL_TO_CURRENT_PAGE, animated, null);
}
- public void showWorkspace(boolean animated, Runnable onCompleteRunnable) {
- showWorkspace(WorkspaceStateTransitionAnimation.SCROLL_TO_CURRENT_PAGE, animated,
+ /**
+ * @return whether or not the Launcher state changed.
+ */
+ public boolean showWorkspace(boolean animated, Runnable onCompleteRunnable) {
+ return showWorkspace(WorkspaceStateTransitionAnimation.SCROLL_TO_CURRENT_PAGE, animated,
onCompleteRunnable);
}
- protected void showWorkspace(int snapToPage, boolean animated) {
- showWorkspace(snapToPage, animated, null);
+ /**
+ * @return whether or not the Launcher state changed.
+ */
+ protected boolean showWorkspace(int snapToPage, boolean animated) {
+ return showWorkspace(snapToPage, animated, null);
}
- void showWorkspace(int snapToPage, boolean animated, Runnable onCompleteRunnable) {
+ /**
+ * @return whether or not the Launcher state changed.
+ */
+ boolean showWorkspace(int snapToPage, boolean animated, Runnable onCompleteRunnable) {
boolean changed = mState != State.WORKSPACE ||
mWorkspace.getState() != Workspace.State.NORMAL;
if (changed) {
@@ -3298,6 +3313,7 @@
getWindow().getDecorView()
.sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED);
}
+ return changed;
}
void showOverviewMode(boolean animated) {
diff --git a/src/com/android/launcher3/allapps/AllAppsContainerView.java b/src/com/android/launcher3/allapps/AllAppsContainerView.java
index 88c6aca..564527e 100644
--- a/src/com/android/launcher3/allapps/AllAppsContainerView.java
+++ b/src/com/android/launcher3/allapps/AllAppsContainerView.java
@@ -290,6 +290,15 @@
}
}
+ /**
+ * Resets the state of AllApps.
+ */
+ public void reset() {
+ // Reset the search bar and base recycler view after transitioning home
+ mSearchBarController.reset();
+ mAppsRecyclerView.reset();
+ }
+
@Override
protected void onFinishInflate() {
super.onFinishInflate();
@@ -555,9 +564,7 @@
@Override
public void onLauncherTransitionEnd(Launcher l, boolean animated, boolean toWorkspace) {
if (toWorkspace) {
- // Reset the search bar and base recycler view after transitioning home
- mSearchBarController.reset();
- mAppsRecyclerView.reset();
+ reset();
}
}
diff --git a/src/com/android/launcher3/allapps/AllAppsRecyclerView.java b/src/com/android/launcher3/allapps/AllAppsRecyclerView.java
index 2f66e2c..10d10f1 100644
--- a/src/com/android/launcher3/allapps/AllAppsRecyclerView.java
+++ b/src/com/android/launcher3/allapps/AllAppsRecyclerView.java
@@ -431,6 +431,13 @@
}
}
+ @Override
+ protected boolean supportsFastScrolling() {
+ // Only allow fast scrolling when the user is not searching, since the results are not
+ // grouped in a meaningful order
+ return !mApps.hasFilter();
+ }
+
/**
* Returns the scrollY for the given position in the adapter.
*/