From 24cf70092b8b0281df071891573642f56e34f9e5 Mon Sep 17 00:00:00 2001 From: Winson Chung Date: Mon, 30 Mar 2015 14:25:04 -0700 Subject: [PATCH] Ensuring that we fast-scroll to the first section app. Bug: 19992026 Change-Id: Ia015b870f80fa598fa68087f90236c59b0ad7e6d --- .../launcher3/AppsContainerRecyclerView.java | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/com/android/launcher3/AppsContainerRecyclerView.java b/src/com/android/launcher3/AppsContainerRecyclerView.java index 0cc651417f..b942ea4516 100644 --- a/src/com/android/launcher3/AppsContainerRecyclerView.java +++ b/src/com/android/launcher3/AppsContainerRecyclerView.java @@ -23,6 +23,7 @@ import android.graphics.Color; import android.graphics.Paint; import android.graphics.Rect; import android.graphics.drawable.Drawable; +import android.support.v7.widget.LinearLayoutManager; import android.support.v7.widget.RecyclerView; import android.util.AttributeSet; import android.view.MotionEvent; @@ -290,14 +291,14 @@ public class AppsContainerRecyclerView extends RecyclerView // Get the total number of rows int rowCount = getNumRows(); - // Find the index of the first app in that row and scroll to that position + // Find the position of the first application in the section that contains the row at the + // current progress int rowAtProgress = (int) (progress * rowCount); int appIndex = 0; rowCount = 0; for (AlphabeticalAppsList.SectionInfo info : sections) { int numRowsInSection = (int) Math.ceil((float) info.numAppsInSection / mNumAppsPerRow); if (rowCount + numRowsInSection > rowAtProgress) { - appIndex += (rowAtProgress - rowCount) * mNumAppsPerRow; break; } rowCount += numRowsInSection; @@ -306,9 +307,14 @@ public class AppsContainerRecyclerView extends RecyclerView appIndex = Math.max(0, Math.min(mApps.getAppsWithoutSectionBreaks().size() - 1, appIndex)); AppInfo appInfo = mApps.getAppsWithoutSectionBreaks().get(appIndex); int sectionedAppIndex = mApps.getApps().indexOf(appInfo); - scrollToPosition(sectionedAppIndex); - // Returns the section name of the row + // Scroll the position into view, anchored at the top of the screen if possible. We call the + // scroll method on the LayoutManager directly since it is not exposed by RecyclerView. + LinearLayoutManager layoutManager = (LinearLayoutManager) getLayoutManager(); + stopScroll(); + layoutManager.scrollToPositionWithOffset(sectionedAppIndex, 0); + + // Return the section name of the row return mApps.getSectionNameForApp(appInfo); }