Adding sort switch in FolderPagedView
> Adding options column in DB to store generation purpose flags
> Storing isSorted flag in FolderInfo
> Adding a switch for A-Z sorting (only visible if pageCount > 1)
> When in sorted mode, spring-load snaps to the target location for 1.5 seconds
Change-Id: I8c7c778d2cc3ccbd35a2890a1a705e1c1a7e9a66
diff --git a/src/com/android/launcher3/Folder.java b/src/com/android/launcher3/Folder.java
index 7ff60de..deb94ca 100644
--- a/src/com/android/launcher3/Folder.java
+++ b/src/com/android/launcher3/Folder.java
@@ -86,6 +86,12 @@
public static final int SCROLL_HINT_DURATION = DragController.SCROLL_DELAY;
/**
+ * Time in milliseconds for which an icon sticks to the target position
+ * in case of a sorted folder.
+ */
+ private static final int SORTED_STICKY_REORDER_DELAY = 1500;
+
+ /**
* Fraction of icon width which behave as scroll region.
*/
private static final float ICON_OVERSCROLL_WIDTH_FACTOR = 0.45f;
@@ -423,8 +429,11 @@
if (!(getParent() instanceof DragLayer)) return;
if (ALLOW_FOLDER_SCROLL) {
- // Always open on the first page.
- mPagedView.snapToPageImmediately(0);
+ mPagedView.completePendingPageChanges();
+ if (!(mDragInProgress && mPagedView.mIsSorted)) {
+ // Open on the first page.
+ mPagedView.snapToPageImmediately(0);
+ }
}
Animator openFolderAnim = null;
@@ -531,9 +540,15 @@
public void beginExternalDrag(ShortcutInfo item) {
mCurrentDragInfo = item;
- mEmptyCellRank = mContent.allocateNewLastItemRank();
+ mEmptyCellRank = mContent.allocateRankForNewItem(item);
mIsExternalDrag = true;
mDragInProgress = true;
+ if (ALLOW_FOLDER_SCROLL && mPagedView.mIsSorted) {
+ mScrollPauseAlarm.setOnAlarmListener(null);
+ mScrollPauseAlarm.cancelAlarm();
+ mScrollPauseAlarm.setAlarm(SORTED_STICKY_REORDER_DELAY);
+ }
+
}
private void sendCustomAccessibilityEvent(int type, String text) {
@@ -747,6 +762,7 @@
if (!successfulDrop) {
mSuppressFolderDeletion = true;
}
+ mScrollPauseAlarm.cancelAlarm();
completeDragExit();
}
}
@@ -1155,7 +1171,7 @@
// If the item was dropped onto this open folder, we have done the work associated
// with adding the item to the folder, as indicated by mSuppressOnAdd being set
if (mSuppressOnAdd) return;
- mContent.createAndAddViewForRank(item, mContent.allocateNewLastItemRank());
+ mContent.createAndAddViewForRank(item, mContent.allocateRankForNewItem(item));
LauncherModel.addOrMoveItemInDatabase(
mLauncher, item, mInfo.id, 0, item.cellX, item.cellY);
}
@@ -1304,10 +1320,10 @@
ArrayList<ShortcutInfo> bindItems(ArrayList<ShortcutInfo> children);
/**
- * Create space for a new item at the end, and returns the rank for that item.
+ * Create space for a new item, and returns the rank for that item.
* Resizes the content if necessary.
*/
- int allocateNewLastItemRank();
+ int allocateRankForNewItem(ShortcutInfo info);
View createAndAddViewForRank(ShortcutInfo item, int rank);