summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorSunny Goyal <sunnygoyal@google.com>2016-09-09 12:42:10 -0700
committerSunny Goyal <sunnygoyal@google.com>2016-09-09 17:25:38 -0700
commite393d3af369c452f3b5f5d9c0a23a83aa3aa736b (patch)
tree8715db2ebb34874f5ded42e89f5e8f728be2b56d /src
parent40851b637ea8e460953c7f2ea448357a86456cb4 (diff)
downloadandroid_packages_apps_Trebuchet-e393d3af369c452f3b5f5d9c0a23a83aa3aa736b.tar.gz
android_packages_apps_Trebuchet-e393d3af369c452f3b5f5d9c0a23a83aa3aa736b.tar.bz2
android_packages_apps_Trebuchet-e393d3af369c452f3b5f5d9c0a23a83aa3aa736b.zip
Using DragObject for folder drop instead of maintaining states when
drag starts from inside a folder Change-Id: I073b59c194d0bd483d579bbcb638b116b09590a0
Diffstat (limited to 'src')
-rw-r--r--src/com/android/launcher3/Workspace.java2
-rw-r--r--src/com/android/launcher3/folder/Folder.java70
-rw-r--r--src/com/android/launcher3/folder/FolderIcon.java28
-rw-r--r--src/com/android/launcher3/folder/FolderPagedView.java2
4 files changed, 50 insertions, 52 deletions
diff --git a/src/com/android/launcher3/Workspace.java b/src/com/android/launcher3/Workspace.java
index d5f1363b4..cf4a43bcd 100644
--- a/src/com/android/launcher3/Workspace.java
+++ b/src/com/android/launcher3/Workspace.java
@@ -2907,7 +2907,7 @@ public class Workspace extends PagedView
private void cleanupAddToFolder() {
if (mDragOverFolderIcon != null) {
- mDragOverFolderIcon.onDragExit(null);
+ mDragOverFolderIcon.onDragExit();
mDragOverFolderIcon = null;
}
}
diff --git a/src/com/android/launcher3/folder/Folder.java b/src/com/android/launcher3/folder/Folder.java
index 19956a9c8..b64d12c1d 100644
--- a/src/com/android/launcher3/folder/Folder.java
+++ b/src/com/android/launcher3/folder/Folder.java
@@ -50,6 +50,7 @@ import android.widget.LinearLayout;
import android.widget.TextView;
import com.android.launcher3.Alarm;
+import com.android.launcher3.AppInfo;
import com.android.launcher3.CellLayout;
import com.android.launcher3.DeviceProfile;
import com.android.launcher3.DragSource;
@@ -163,10 +164,8 @@ public class Folder extends LinearLayout implements DragSource, View.OnClickList
@ViewDebug.ExportedProperty(category = "launcher")
private boolean mRearrangeOnClose = false;
boolean mItemsInvalidated = false;
- private ShortcutInfo mCurrentDragInfo;
private View mCurrentDragView;
private boolean mIsExternalDrag;
- boolean mSuppressOnAdd = false;
private boolean mDragInProgress = false;
private boolean mDeleteFolderOnDropCompleted = false;
private boolean mSuppressFolderDeletion = false;
@@ -291,7 +290,6 @@ public class Folder extends LinearLayout implements DragSource, View.OnClickList
return false;
}
- mCurrentDragInfo = item;
mEmptyCellRank = item.rank;
mCurrentDragView = v;
@@ -322,7 +320,15 @@ public class Folder extends LinearLayout implements DragSource, View.OnClickList
}
mContent.removeItem(mCurrentDragView);
- mInfo.remove(mCurrentDragInfo, true);
+ if (dragObject.dragInfo instanceof ShortcutInfo) {
+ mItemsInvalidated = true;
+
+ // We do not want to get events for the item being removed, as they will get handled
+ // when the drop completes
+ try (SuppressInfoChanges s = new SuppressInfoChanges()) {
+ mInfo.remove((ShortcutInfo) dragObject.dragInfo, true);
+ }
+ }
mDragInProgress = true;
mItemAddedBackToSelfViaIcon = false;
}
@@ -664,9 +670,8 @@ public class Folder extends LinearLayout implements DragSource, View.OnClickList
mContent.verifyVisibleHighResIcons(mContent.getNextPage());
}
- public void beginExternalDrag(ShortcutInfo item) {
- mCurrentDragInfo = item;
- mEmptyCellRank = mContent.allocateRankForNewItem(item);
+ public void beginExternalDrag() {
+ mEmptyCellRank = mContent.allocateRankForNewItem();
mIsExternalDrag = true;
mDragInProgress = true;
@@ -845,9 +850,7 @@ public class Folder extends LinearLayout implements DragSource, View.OnClickList
}
private void clearDragInfo() {
- mCurrentDragInfo = null;
mCurrentDragView = null;
- mSuppressOnAdd = false;
mIsExternalDrag = false;
}
@@ -911,9 +914,9 @@ public class Folder extends LinearLayout implements DragSource, View.OnClickList
mContent.arrangeChildren(views, views.size());
mItemsInvalidated = true;
- mSuppressOnAdd = true;
- mFolderIcon.onDrop(d);
- mSuppressOnAdd = false;
+ try (SuppressInfoChanges s = new SuppressInfoChanges()) {
+ mFolderIcon.onDrop(d);
+ }
}
if (target != this) {
@@ -930,9 +933,7 @@ public class Folder extends LinearLayout implements DragSource, View.OnClickList
mDeleteFolderOnDropCompleted = false;
mDragInProgress = false;
mItemAddedBackToSelfViaIcon = false;
- mCurrentDragInfo = null;
mCurrentDragView = null;
- mSuppressOnAdd = false;
// Reordering may have occured, and we need to save the new item locations. We do this once
// at the end to prevent unnecessary database operations.
@@ -1274,7 +1275,14 @@ public class Folder extends LinearLayout implements DragSource, View.OnClickList
mContent.completePendingPageChanges();
View currentDragView;
- ShortcutInfo si = mCurrentDragInfo;
+ final ShortcutInfo si;
+ if (d.dragInfo instanceof AppInfo) {
+ // Came from all apps -- make a copy.
+ si = ((AppInfo) d.dragInfo).makeShortcut();
+ } else {
+ // ShortcutInfo
+ si = (ShortcutInfo) d.dragInfo;
+ }
if (mIsExternalDrag) {
currentDragView = mContent.createAndAddViewForRank(si, mEmptyCellRank);
// Actually move the item in the database if it was an external drag. Call this
@@ -1311,11 +1319,11 @@ public class Folder extends LinearLayout implements DragSource, View.OnClickList
rearrangeChildren();
// Temporarily suppress the listener, as we did all the work already here.
- mSuppressOnAdd = true;
- mInfo.add(si, false);
- mSuppressOnAdd = false;
+ try (SuppressInfoChanges s = new SuppressInfoChanges()) {
+ mInfo.add(si, false);
+ }
+
// Clear the drag info, as it is no longer being dragged.
- mCurrentDragInfo = null;
mDragInProgress = false;
if (mContent.getPageCount() > 1) {
@@ -1338,10 +1346,7 @@ public class Folder extends LinearLayout implements DragSource, View.OnClickList
@Override
public void onAdd(ShortcutInfo item) {
- // 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.allocateRankForNewItem(item));
+ mContent.createAndAddViewForRank(item, mContent.allocateRankForNewItem());
mItemsInvalidated = true;
LauncherModel.addOrMoveItemInDatabase(
mLauncher, item, mInfo.id, 0, item.cellX, item.cellY);
@@ -1349,9 +1354,6 @@ public class Folder extends LinearLayout implements DragSource, View.OnClickList
public void onRemove(ShortcutInfo item) {
mItemsInvalidated = true;
- // If this item is being dragged from this open folder, we have already handled
- // the work associated with removing the item, so we don't have to do anything here.
- if (item == mCurrentDragInfo) return;
View v = getViewForInfo(item);
mContent.removeItem(v);
if (mState == STATE_ANIMATING) {
@@ -1490,4 +1492,20 @@ public class Folder extends LinearLayout implements DragSource, View.OnClickList
}
}
};
+
+ /**
+ * Temporary resource held while we don't want to handle info changes
+ */
+ private class SuppressInfoChanges implements AutoCloseable {
+
+ SuppressInfoChanges() {
+ mInfo.removeListener(Folder.this);
+ }
+
+ @Override
+ public void close() {
+ mInfo.addListener(Folder.this);
+ updateTextViewFocus();
+ }
+ }
}
diff --git a/src/com/android/launcher3/folder/FolderIcon.java b/src/com/android/launcher3/folder/FolderIcon.java
index eebbfe8b7..69c2b0fa3 100644
--- a/src/com/android/launcher3/folder/FolderIcon.java
+++ b/src/com/android/launcher3/folder/FolderIcon.java
@@ -125,8 +125,6 @@ public class FolderIcon extends FrameLayout implements FolderListener {
Paint mBgPaint = new Paint();
private Alarm mOpenAlarm = new Alarm();
- @Thunk
- ItemInfo mDragInfo;
public FolderIcon(Context context, AttributeSet attrs) {
super(context, attrs);
@@ -195,8 +193,6 @@ public class FolderIcon extends FrameLayout implements FolderListener {
return super.onSaveInstanceState();
}
-
-
public Folder getFolder() {
return mFolder;
}
@@ -242,22 +238,11 @@ public class FolderIcon extends FrameLayout implements FolderListener {
// Workspace#onDropExternal.
mOpenAlarm.setAlarm(ON_OPEN_DELAY);
}
- mDragInfo = dragInfo;
}
OnAlarmListener mOnOpenListener = new OnAlarmListener() {
public void onAlarm(Alarm alarm) {
- ShortcutInfo item;
- if (mDragInfo instanceof AppInfo) {
- // Came from all apps -- make a copy.
- item = ((AppInfo) mDragInfo).makeShortcut();
- item.spanX = 1;
- item.spanY = 1;
- } else {
- // ShortcutInfo
- item = (ShortcutInfo) mDragInfo;
- }
- mFolder.beginExternalDrag(item);
+ mFolder.beginExternalDrag();
mLauncher.openFolder(FolderIcon.this);
}
};
@@ -284,7 +269,7 @@ public class FolderIcon extends FrameLayout implements FolderListener {
animateFirstItem(animateDrawable, INITIAL_ITEM_ANIMATION_DURATION, false, null);
// This will animate the dragView (srcView) into the new folder
- onDrop(srcInfo, srcView, dstRect, scaleRelativeToDragLayer, 1, postAnimationRunnable, null);
+ onDrop(srcInfo, srcView, dstRect, scaleRelativeToDragLayer, 1, postAnimationRunnable);
}
public void performDestroyAnimation(final View finalView, Runnable onCompleteRunnable) {
@@ -298,18 +283,13 @@ public class FolderIcon extends FrameLayout implements FolderListener {
onCompleteRunnable);
}
- public void onDragExit(Object dragInfo) {
- onDragExit();
- }
-
public void onDragExit() {
mBackground.animateToRest();
mOpenAlarm.cancelAlarm();
}
private void onDrop(final ShortcutInfo item, DragView animateView, Rect finalRect,
- float scaleRelativeToDragLayer, int index, Runnable postAnimationRunnable,
- DragObject d) {
+ float scaleRelativeToDragLayer, int index, Runnable postAnimationRunnable) {
item.cellX = -1;
item.cellY = -1;
@@ -379,7 +359,7 @@ public class FolderIcon extends FrameLayout implements FolderListener {
item = (ShortcutInfo) d.dragInfo;
}
mFolder.notifyDrop();
- onDrop(item, d.dragView, null, 1.0f, mInfo.contents.size(), d.postAnimationRunnable, d);
+ onDrop(item, d.dragView, null, 1.0f, mInfo.contents.size(), d.postAnimationRunnable);
}
private void computePreviewDrawingParams(int drawableSize, int totalSize) {
diff --git a/src/com/android/launcher3/folder/FolderPagedView.java b/src/com/android/launcher3/folder/FolderPagedView.java
index 3df1d2438..1171d488d 100644
--- a/src/com/android/launcher3/folder/FolderPagedView.java
+++ b/src/com/android/launcher3/folder/FolderPagedView.java
@@ -195,7 +195,7 @@ public class FolderPagedView extends PagedView {
* Create space for a new item at the end, and returns the rank for that item.
* Also sets the current page to the last page.
*/
- public int allocateRankForNewItem(ShortcutInfo info) {
+ public int allocateRankForNewItem() {
int rank = getItemCount();
ArrayList<View> views = new ArrayList<>(mFolder.getItemsInReadingOrder());
views.add(rank, null);