diff options
author | Adam Cohen <adamcohen@google.com> | 2011-06-28 14:41:44 -0700 |
---|---|---|
committer | Adam Cohen <adamcohen@google.com> | 2011-06-28 14:41:44 -0700 |
commit | c508b2d701ef980875f7ebc71bf2d87781159478 (patch) | |
tree | 4bc1131ff3e93cb64f6a8408c5ed555e413d1615 /src/com/android/launcher2/Folder.java | |
parent | a65beeea13c18c443f15f8d51c4c6e153a6c4ef9 (diff) | |
download | android_packages_apps_Trebuchet-c508b2d701ef980875f7ebc71bf2d87781159478.tar.gz android_packages_apps_Trebuchet-c508b2d701ef980875f7ebc71bf2d87781159478.tar.bz2 android_packages_apps_Trebuchet-c508b2d701ef980875f7ebc71bf2d87781159478.zip |
Dealing with upgrade from previous Folder implementation
-> We need to truncate the old folder if it had more items
than are currently supported
-> We need to automatically place the items, since their folder
location is not stored in the LauncherModel
Change-Id: I4a5955adf2fed4d9b96a1cbd145dd69bbffc1cc7
Diffstat (limited to 'src/com/android/launcher2/Folder.java')
-rw-r--r-- | src/com/android/launcher2/Folder.java | 27 |
1 files changed, 25 insertions, 2 deletions
diff --git a/src/com/android/launcher2/Folder.java b/src/com/android/launcher2/Folder.java index c1580b168..80428fa5a 100644 --- a/src/com/android/launcher2/Folder.java +++ b/src/com/android/launcher2/Folder.java @@ -328,11 +328,23 @@ public class Folder extends LinearLayout implements DragSource, OnItemLongClickL void bind(FolderInfo info) { mInfo = info; ArrayList<ShortcutInfo> children = info.contents; + ArrayList<ShortcutInfo> overflow = new ArrayList<ShortcutInfo>(); setupContentForNumItems(children.size()); for (int i = 0; i < children.size(); i++) { ShortcutInfo child = (ShortcutInfo) children.get(i); - createAndAddShortcut(child); + if (!createAndAddShortcut(child)) { + overflow.add(child); + } } + + // If our folder has too many items we prune them from the list. This is an issue + // when upgrading from the old Folders implementation which could contain an unlimited + // number of items. + for (ShortcutInfo item: overflow) { + mInfo.remove(item); + LauncherModel.deleteItemFromDatabase(mLauncher, item); + } + mItemsInvalidated = true; mInfo.addListener(this); @@ -499,7 +511,7 @@ public class Folder extends LinearLayout implements DragSource, OnItemLongClickL } } - protected void createAndAddShortcut(ShortcutInfo item) { + protected boolean createAndAddShortcut(ShortcutInfo item) { final TextView textView = (TextView) mInflater.inflate(R.layout.application_boxed, this, false); textView.setCompoundDrawablesWithIntrinsicBounds(null, @@ -510,10 +522,21 @@ public class Folder extends LinearLayout implements DragSource, OnItemLongClickL textView.setOnClickListener(this); 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. + if (mContent.getChildAt(item.cellX, item.cellY) != null) { + if (!findAndSetEmptyCells(item)) { + return false; + } + } + CellLayout.LayoutParams lp = new CellLayout.LayoutParams(item.cellX, item.cellY, item.spanX, item.spanY); boolean insert = false; mContent.addViewToCellLayout(textView, insert ? 0 : -1, (int)item.id, lp, true); + return true; } public void onDragEnter(DragObject d) { |