summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorAdam Cohen <adamcohen@google.com>2012-05-08 13:12:26 -0700
committerAndroid (Google) Code Review <android-gerrit@google.com>2012-05-08 13:12:26 -0700
commitd1710fbb4053f80103b740c8b393b6cb4a480d6f (patch)
treebd1343d21091e4a56ffaa4f3fd1a5ba6cc27796b /src
parent33a0ad56c0970b5c60b6e4e207f24dcefd1fd3e8 (diff)
parent3bf84d3250bf45f2a5b041245e9bd327e03e22c0 (diff)
downloadandroid_packages_apps_Trebuchet-d1710fbb4053f80103b740c8b393b6cb4a480d6f.tar.gz
android_packages_apps_Trebuchet-d1710fbb4053f80103b740c8b393b6cb4a480d6f.tar.bz2
android_packages_apps_Trebuchet-d1710fbb4053f80103b740c8b393b6cb4a480d6f.zip
Merge "Fixing folder order persistence (issue 6176721)" into jb-dev
Diffstat (limited to 'src')
-rw-r--r--src/com/android/launcher2/Folder.java47
1 files changed, 44 insertions, 3 deletions
diff --git a/src/com/android/launcher2/Folder.java b/src/com/android/launcher2/Folder.java
index f63e9bc3e..36913ca6a 100644
--- a/src/com/android/launcher2/Folder.java
+++ b/src/com/android/launcher2/Folder.java
@@ -29,6 +29,7 @@ import android.text.InputType;
import android.text.Selection;
import android.text.Spannable;
import android.util.AttributeSet;
+import android.util.Log;
import android.view.ActionMode;
import android.view.KeyEvent;
import android.view.LayoutInflater;
@@ -47,6 +48,8 @@ import com.android.launcher.R;
import com.android.launcher2.FolderInfo.FolderListener;
import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Comparator;
/**
* Represents a set of icons chosen by the user or generated by the system.
@@ -308,11 +311,48 @@ public class Folder extends LinearLayout implements DragSource, View.OnClickList
return mInfo;
}
+ private class GridComparator implements Comparator<ShortcutInfo> {
+ int mNumCols;
+ public GridComparator(int numCols) {
+ mNumCols = numCols;
+ }
+
+ @Override
+ public int compare(ShortcutInfo lhs, ShortcutInfo rhs) {
+ int lhIndex = lhs.cellY * mNumCols + lhs.cellX;
+ int rhIndex = rhs.cellY * mNumCols + rhs.cellX;
+ return (lhIndex - rhIndex);
+ }
+
+ }
+
+ private void placeInReadingOrder(ArrayList<ShortcutInfo> items) {
+ int maxX = 0;
+ int count = items.size();
+ for (int i = 0; i < count; i++) {
+ ShortcutInfo item = items.get(i);
+ if (item.cellX > maxX) {
+ maxX = item.cellX;
+ }
+ }
+ GridComparator gridComparator = new GridComparator(maxX);
+ Collections.sort(items, gridComparator);
+ final int countX = mContent.getCountX();
+ for (int i = 0; i < count; i++) {
+ int x = i % countX;
+ int y = i / countX;
+ ShortcutInfo item = items.get(i);
+ item.cellX = x;
+ item.cellY = y;
+ }
+ }
+
void bind(FolderInfo info) {
mInfo = info;
ArrayList<ShortcutInfo> children = info.contents;
ArrayList<ShortcutInfo> overflow = new ArrayList<ShortcutInfo>();
setupContentForNumItems(children.size());
+ placeInReadingOrder(children);
int count = 0;
for (int i = 0; i < children.size(); i++) {
ShortcutInfo child = (ShortcutInfo) children.get(i);
@@ -481,11 +521,11 @@ public class Folder extends LinearLayout implements DragSource, View.OnClickList
textView.setOnLongClickListener(this);
// We need to check here to verify that the given item's location isn't already occupied
- // by another item. If it is, we need to find the next available slot and assign
- // it that position. This is an issue when upgrading from the old Folders implementation
- // which could contain an unlimited number of items.
+ // by another item.
if (mContent.getChildAt(item.cellX, item.cellY) != null || item.cellX < 0 || item.cellY < 0
|| item.cellX >= mContent.getCountX() || item.cellY >= mContent.getCountY()) {
+ // This shouldn't happen, log it.
+ Log.e(TAG, "Folder order not properly persisted during bind");
if (!findAndSetEmptyCells(item)) {
return false;
}
@@ -780,6 +820,7 @@ public class Folder extends LinearLayout implements DragSource, View.OnClickList
(1.0f * folderPivotX / width));
int folderIconPivotY = (int) (mFolderIcon.getMeasuredHeight() *
(1.0f * folderPivotY / height));
+
mFolderIcon.setPivotX(folderIconPivotX);
mFolderIcon.setPivotY(folderIconPivotY);