summaryrefslogtreecommitdiffstats
path: root/src/com/android/launcher3/folder/Folder.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/com/android/launcher3/folder/Folder.java')
-rw-r--r--src/com/android/launcher3/folder/Folder.java114
1 files changed, 56 insertions, 58 deletions
diff --git a/src/com/android/launcher3/folder/Folder.java b/src/com/android/launcher3/folder/Folder.java
index f68b394c1..85792d4cc 100644
--- a/src/com/android/launcher3/folder/Folder.java
+++ b/src/com/android/launcher3/folder/Folder.java
@@ -133,7 +133,7 @@ public class Folder extends AbstractFloatingView implements DragSource, View.OnC
private final Alarm mOnScrollHintAlarm = new Alarm();
@Thunk final Alarm mScrollPauseAlarm = new Alarm();
- @Thunk final ArrayList<View> mItemsInRankOrder = new ArrayList<>();
+ @Thunk final ArrayList<View> mItemsInReadingOrder = new ArrayList<View>();
private AnimatorSet mCurrentAnimator;
@@ -284,7 +284,7 @@ public class Folder extends AbstractFloatingView implements DragSource, View.OnC
if (tag instanceof ShortcutInfo) {
ShortcutInfo item = (ShortcutInfo) tag;
- mEmptyCellRank = mContent.getReadingOrderPosForRank(item.rank);
+ mEmptyCellRank = item.rank;
mCurrentDragView = v;
mDragController.addDragListener(this);
@@ -705,7 +705,7 @@ public class Folder extends AbstractFloatingView implements DragSource, View.OnC
}
public void beginExternalDrag() {
- mEmptyCellRank = mContent.getReadingOrderPosForRank(mContent.allocateRankForNewItem());
+ mEmptyCellRank = mContent.allocateRankForNewItem();
mIsExternalDrag = true;
mDragInProgress = true;
@@ -791,12 +791,15 @@ public class Folder extends AbstractFloatingView implements DragSource, View.OnC
if (mFolderIcon != null) {
mFolderIcon.setVisibility(View.VISIBLE);
if (FeatureFlags.LAUNCHER3_NEW_FOLDER_ANIMATION) {
- mFolderIcon.mFolderName.setTextVisibility(true);
mFolderIcon.setBackgroundVisible(true);
- mFolderIcon.mBackground.fadeInBackgroundShadow();
+ mFolderIcon.mFolderName.setTextVisibility(true);
}
if (wasAnimated) {
- mFolderIcon.mBackground.animateBackgroundStroke();
+ if (FeatureFlags.LAUNCHER3_NEW_FOLDER_ANIMATION) {
+ mFolderIcon.mBackground.fadeInBackgroundShadow();
+ mFolderIcon.mBackground.animateBackgroundStroke();
+ mFolderIcon.onFolderClose(mContent.getCurrentPage());
+ }
if (mFolderIcon.hasBadge()) {
mFolderIcon.createBadgeScaleAnimator(0f, 1f).start();
}
@@ -818,6 +821,7 @@ public class Folder extends AbstractFloatingView implements DragSource, View.OnC
mSuppressFolderDeletion = false;
clearDragInfo();
mState = STATE_SMALL;
+ mContent.setCurrentPage(0);
}
public boolean acceptDrop(DragObject d) {
@@ -997,7 +1001,7 @@ public class Folder extends AbstractFloatingView implements DragSource, View.OnC
ShortcutInfo info = (ShortcutInfo) d.dragInfo;
View icon = (mCurrentDragView != null && mCurrentDragView.getTag() == info)
? mCurrentDragView : mContent.createNewView(info);
- ArrayList<View> views = getItemsInRankOrder();
+ ArrayList<View> views = getItemsInReadingOrder();
views.add(info.rank, icon);
mContent.arrangeChildren(views, views.size());
mItemsInvalidated = true;
@@ -1072,7 +1076,7 @@ public class Folder extends AbstractFloatingView implements DragSource, View.OnC
}
private void updateItemLocationsInDatabaseBatch() {
- ArrayList<View> list = getItemsInRankOrder();
+ ArrayList<View> list = getItemsInReadingOrder();
ArrayList<ItemInfo> items = new ArrayList<ItemInfo>();
for (int i = 0; i < list.size(); i++) {
View v = list.get(i);
@@ -1231,7 +1235,7 @@ public class Folder extends AbstractFloatingView implements DragSource, View.OnC
* otherwise it is ignored.
*/
public void rearrangeChildren(int itemCount) {
- ArrayList<View> views = getItemsInRankOrder();
+ ArrayList<View> views = getItemsInReadingOrder();
mContent.arrangeChildren(views, Math.max(itemCount, views.size()));
mItemsInvalidated = true;
}
@@ -1280,7 +1284,7 @@ public class Folder extends AbstractFloatingView implements DragSource, View.OnC
};
View finalChild = mContent.getLastItem();
if (finalChild != null) {
- mFolderIcon.performDestroyAnimation(finalChild, onCompleteRunnable);
+ mFolderIcon.performDestroyAnimation(onCompleteRunnable);
} else {
onCompleteRunnable.run();
}
@@ -1355,8 +1359,11 @@ public class Folder extends AbstractFloatingView implements DragSource, View.OnC
}
mContent.completePendingPageChanges();
- if (d.dragInfo instanceof PendingAddShortcutInfo) {
- PendingAddShortcutInfo pasi = (PendingAddShortcutInfo) d.dragInfo;
+ PendingAddShortcutInfo pasi = d.dragInfo instanceof PendingAddShortcutInfo
+ ? (PendingAddShortcutInfo) d.dragInfo : null;
+ ShortcutInfo pasiSi = pasi != null ? pasi.activityInfo.createShortcutInfo() : null;
+ if (pasi != null && pasiSi == null) {
+ // There is no ShortcutInfo, so we have to go through a configuration activity.
pasi.container = mInfo.id;
pasi.rank = mEmptyCellRank;
@@ -1366,7 +1373,9 @@ public class Folder extends AbstractFloatingView implements DragSource, View.OnC
mRearrangeOnClose = true;
} else {
final ShortcutInfo si;
- if (d.dragInfo instanceof AppInfo) {
+ if (pasiSi != null) {
+ si = pasiSi;
+ } else if (d.dragInfo instanceof AppInfo) {
// Came from all apps -- make a copy.
si = ((AppInfo) d.dragInfo).makeShortcut();
} else {
@@ -1376,19 +1385,23 @@ public class Folder extends AbstractFloatingView implements DragSource, View.OnC
View currentDragView;
if (mIsExternalDrag) {
+ currentDragView = mContent.createAndAddViewForRank(si, mEmptyCellRank);
+
// Actually move the item in the database if it was an external drag. Call this
// before creating the view, so that ShortcutInfo is updated appropriately.
- mLauncher.getModelWriter().addOrMoveItemInDatabase(si, mInfo.id, 0, si.cellX, si.cellY);
- }
+ mLauncher.getModelWriter().addOrMoveItemInDatabase(
+ si, mInfo.id, 0, si.cellX, si.cellY);
- currentDragView = mIsExternalDrag
- ? mContent.createNewView(si)
- : mCurrentDragView;
- mIsExternalDrag = false;
-
- // Note: addViewForRankDuringDragAndDrop handles rearranging the children.
- mContent.addViewForRankDuringDragAndDrop(currentDragView, si, mEmptyCellRank);
- mItemsInvalidated = true;
+ // We only need to update the locations if it doesn't get handled in
+ // #onDropCompleted.
+ if (d.dragSource != this) {
+ updateItemLocationsInDatabaseBatch();
+ }
+ mIsExternalDrag = false;
+ } else {
+ currentDragView = mCurrentDragView;
+ mContent.addViewForRank(currentDragView, si, mEmptyCellRank);
+ }
if (d.dragView.hasDrawn()) {
// Temporarily reset the scale such that the animation target gets calculated
@@ -1406,6 +1419,9 @@ public class Folder extends AbstractFloatingView implements DragSource, View.OnC
currentDragView.setVisibility(VISIBLE);
}
+ mItemsInvalidated = true;
+ rearrangeChildren();
+
// Temporarily suppress the listener, as we did all the work already here.
try (SuppressInfoChanges s = new SuppressInfoChanges()) {
mInfo.add(si, false);
@@ -1443,7 +1459,7 @@ public class Folder extends AbstractFloatingView implements DragSource, View.OnC
mLauncher.getModelWriter().addOrMoveItemInDatabase(item, mInfo.id, 0, item.cellX,
item.cellY);
- ArrayList<View> items = new ArrayList<>(getItemsInRankOrder());
+ ArrayList<View> items = new ArrayList<>(getItemsInReadingOrder());
items.add(rank, view);
mContent.arrangeChildren(items, items.size());
mItemsInvalidated = true;
@@ -1490,44 +1506,33 @@ public class Folder extends AbstractFloatingView implements DragSource, View.OnC
public void onTitleChanged(CharSequence title) {
}
- public ArrayList<View> getItemsInRankOrder() {
+ public ArrayList<View> getItemsInReadingOrder() {
if (mItemsInvalidated) {
- mItemsInRankOrder.clear();
- mItemsInRankOrder.addAll(getItemsInReadingOrder());
- mItemsInRankOrder.sort(VIEW_RANK_COMPARATOR);
+ mItemsInReadingOrder.clear();
+ mContent.iterateOverItems(new ItemOperator() {
+ @Override
+ public boolean evaluate(ItemInfo info, View view) {
+ mItemsInReadingOrder.add(view);
+ return false;
+ }
+ });
mItemsInvalidated = false;
}
- return mItemsInRankOrder;
- }
-
- /**
- * This is an expensive call. Consider using {@link #getItemsInRankOrder()} instead.
- */
- public ArrayList<View> getItemsInReadingOrder() {
- final ArrayList<View> itemsInReadingOrder = new ArrayList<>();
- mContent.iterateOverItems(new ItemOperator() {
- @Override
- public boolean evaluate(ItemInfo info, View view) {
- itemsInReadingOrder.add(view);
- return false;
- }
- });
- return itemsInReadingOrder;
+ return mItemsInReadingOrder;
}
- public List<BubbleTextView> getItemsOnCurrentPage() {
- ArrayList<View> allItems = getItemsInRankOrder();
- int currentPage = mContent.getCurrentPage();
+ public List<BubbleTextView> getItemsOnPage(int page) {
+ ArrayList<View> allItems = getItemsInReadingOrder();
int lastPage = mContent.getPageCount() - 1;
int totalItemsInFolder = allItems.size();
int itemsPerPage = mContent.itemsPerPage();
- int numItemsOnCurrentPage = currentPage == lastPage
- ? totalItemsInFolder - (itemsPerPage * currentPage)
+ int numItemsOnCurrentPage = page == lastPage
+ ? totalItemsInFolder - (itemsPerPage * page)
: itemsPerPage;
- int startIndex = currentPage * itemsPerPage;
- int endIndex = startIndex + numItemsOnCurrentPage;
+ int startIndex = page * itemsPerPage;
+ int endIndex = Math.min(startIndex + numItemsOnCurrentPage, allItems.size());
List<BubbleTextView> itemsOnCurrentPage = new ArrayList<>(numItemsOnCurrentPage);
for (int i = startIndex; i < endIndex; ++i) {
@@ -1625,13 +1630,6 @@ public class Folder extends AbstractFloatingView implements DragSource, View.OnC
}
};
- public static final Comparator<View> VIEW_RANK_COMPARATOR = new Comparator<View>() {
- @Override
- public int compare(View lhs, View rhs) {
- return ITEM_POS_COMPARATOR.compare((ItemInfo) lhs.getTag(), (ItemInfo) rhs.getTag());
- }
- };
-
/**
* Temporary resource held while we don't want to handle info changes
*/