summaryrefslogtreecommitdiffstats
path: root/src/com/android/launcher3/widget/WidgetsRecyclerView.java
diff options
context:
space:
mode:
authorcretin45 <cretin45@gmail.com>2015-12-10 15:39:19 -0800
committercretin45 <cretin45@gmail.com>2015-12-10 16:19:01 -0800
commitd8e89b7851586a46f67837e289f51d63a32b68a8 (patch)
treebf359b7542f3b4a88759eeb3bc63e4add7831aa7 /src/com/android/launcher3/widget/WidgetsRecyclerView.java
parent7600c7f3125a845ce6d4add4ceff90b884e1c033 (diff)
downloadandroid_packages_apps_Trebuchet-d8e89b7851586a46f67837e289f51d63a32b68a8.tar.gz
android_packages_apps_Trebuchet-d8e89b7851586a46f67837e289f51d63a32b68a8.tar.bz2
android_packages_apps_Trebuchet-d8e89b7851586a46f67837e289f51d63a32b68a8.zip
Trebuchet: Add scrubber to widget viewstaging/cm-13.0
Change-Id: I68711e95ed31a962b47e995e979e32de37570b44
Diffstat (limited to 'src/com/android/launcher3/widget/WidgetsRecyclerView.java')
-rw-r--r--src/com/android/launcher3/widget/WidgetsRecyclerView.java44
1 files changed, 42 insertions, 2 deletions
diff --git a/src/com/android/launcher3/widget/WidgetsRecyclerView.java b/src/com/android/launcher3/widget/WidgetsRecyclerView.java
index ac32f154e..6818f3f71 100644
--- a/src/com/android/launcher3/widget/WidgetsRecyclerView.java
+++ b/src/com/android/launcher3/widget/WidgetsRecyclerView.java
@@ -20,13 +20,17 @@ import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.support.v7.widget.LinearLayoutManager;
+import android.text.TextUtils;
import android.util.AttributeSet;
+import android.util.Log;
import android.view.View;
import com.android.launcher3.BaseRecyclerView;
import com.android.launcher3.R;
import com.android.launcher3.model.PackageItemInfo;
import com.android.launcher3.model.WidgetsModel;
+import java.util.ArrayList;
+
/**
* The widgets recycler view.
*/
@@ -70,7 +74,11 @@ public class WidgetsRecyclerView extends BaseRecyclerView {
public void setWidgets(WidgetsModel widgets) {
mWidgets = widgets;
}
-
+
+ public WidgetsModel getWidgets() {
+ return mWidgets;
+ }
+
/**
* We need to override the draw to ensure that we don't draw the overscroll effect beyond the
* background bounds.
@@ -146,12 +154,44 @@ public class WidgetsRecyclerView extends BaseRecyclerView {
@Override
public String scrollToSection(String sectionName) {
+ // Skip early if widgets are not bound.
+ if (mWidgets == null) {
+ return "";
+ }
+
+ // Skip early if there are no widgets.
+ int rowCount = mWidgets.getPackageSize();
+ if (rowCount == 0) {
+ return "";
+ }
+ for (int i = 0; i < rowCount; i++) {
+ PackageItemInfo packageItemInfo = mWidgets.getPackageItemInfo(i);
+ if (packageItemInfo != null && !TextUtils.isEmpty(packageItemInfo.titleSectionName) &&
+ packageItemInfo.titleSectionName.equals(sectionName)) {
+ LinearLayoutManager layoutManager = ((LinearLayoutManager) getLayoutManager());
+ layoutManager.smoothScrollToPosition(this, null, i);
+ return packageItemInfo.titleSectionName;
+ }
+ }
return null;
}
@Override
public String[] getSectionNames() {
- return new String[0];
+ if (mWidgets == null) {
+ return new String[0];
+ }
+ final int N = mWidgets.getPackageSize();
+ ArrayList<String> sections = new ArrayList<>();
+ String lastLetter = null;
+ for (int i = 0; i < N; i++) {
+ final String titleSectionName = mWidgets.getPackageItemInfo(i).titleSectionName;
+ if (!TextUtils.isEmpty(titleSectionName) && !titleSectionName.equals(lastLetter)) {
+ lastLetter = titleSectionName;
+ sections.add(titleSectionName);
+ }
+ }
+ return sections.toArray(new String[sections.size()]);
}
/**