Merge "Fixing folder order persistence (issue 6176721)" into jb-dev
This commit is contained in:
commit
d1710fbb40
1 file changed
+44
-3
@@ -29,6 +29,7 @@ import android.text.InputType;
|
|||||||
import android.text.Selection;
|
import android.text.Selection;
|
||||||
import android.text.Spannable;
|
import android.text.Spannable;
|
||||||
import android.util.AttributeSet;
|
import android.util.AttributeSet;
|
||||||
|
import android.util.Log;
|
||||||
import android.view.ActionMode;
|
import android.view.ActionMode;
|
||||||
import android.view.KeyEvent;
|
import android.view.KeyEvent;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
@@ -47,6 +48,8 @@ import com.android.launcher.R;
|
|||||||
import com.android.launcher2.FolderInfo.FolderListener;
|
import com.android.launcher2.FolderInfo.FolderListener;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
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.
|
* 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;
|
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) {
|
void bind(FolderInfo info) {
|
||||||
mInfo = info;
|
mInfo = info;
|
||||||
ArrayList<ShortcutInfo> children = info.contents;
|
ArrayList<ShortcutInfo> children = info.contents;
|
||||||
ArrayList<ShortcutInfo> overflow = new ArrayList<ShortcutInfo>();
|
ArrayList<ShortcutInfo> overflow = new ArrayList<ShortcutInfo>();
|
||||||
setupContentForNumItems(children.size());
|
setupContentForNumItems(children.size());
|
||||||
|
placeInReadingOrder(children);
|
||||||
int count = 0;
|
int count = 0;
|
||||||
for (int i = 0; i < children.size(); i++) {
|
for (int i = 0; i < children.size(); i++) {
|
||||||
ShortcutInfo child = (ShortcutInfo) children.get(i);
|
ShortcutInfo child = (ShortcutInfo) children.get(i);
|
||||||
@@ -481,11 +521,11 @@ public class Folder extends LinearLayout implements DragSource, View.OnClickList
|
|||||||
textView.setOnLongClickListener(this);
|
textView.setOnLongClickListener(this);
|
||||||
|
|
||||||
// We need to check here to verify that the given item's location isn't already occupied
|
// 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
|
// by another item.
|
||||||
// it that position. This is an issue when upgrading from the old Folders implementation
|
|
||||||
// which could contain an unlimited number of items.
|
|
||||||
if (mContent.getChildAt(item.cellX, item.cellY) != null || item.cellX < 0 || item.cellY < 0
|
if (mContent.getChildAt(item.cellX, item.cellY) != null || item.cellX < 0 || item.cellY < 0
|
||||||
|| item.cellX >= mContent.getCountX() || item.cellY >= mContent.getCountY()) {
|
|| 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)) {
|
if (!findAndSetEmptyCells(item)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -780,6 +820,7 @@ public class Folder extends LinearLayout implements DragSource, View.OnClickList
|
|||||||
(1.0f * folderPivotX / width));
|
(1.0f * folderPivotX / width));
|
||||||
int folderIconPivotY = (int) (mFolderIcon.getMeasuredHeight() *
|
int folderIconPivotY = (int) (mFolderIcon.getMeasuredHeight() *
|
||||||
(1.0f * folderPivotY / height));
|
(1.0f * folderPivotY / height));
|
||||||
|
|
||||||
mFolderIcon.setPivotX(folderIconPivotX);
|
mFolderIcon.setPivotX(folderIconPivotX);
|
||||||
mFolderIcon.setPivotY(folderIconPivotY);
|
mFolderIcon.setPivotY(folderIconPivotY);
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user