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.java158
1 files changed, 85 insertions, 73 deletions
diff --git a/src/com/android/launcher3/folder/Folder.java b/src/com/android/launcher3/folder/Folder.java
index 5450423a2..b64d12c1d 100644
--- a/src/com/android/launcher3/folder/Folder.java
+++ b/src/com/android/launcher3/folder/Folder.java
@@ -42,7 +42,6 @@ import android.view.MotionEvent;
import android.view.View;
import android.view.ViewDebug;
import android.view.accessibility.AccessibilityEvent;
-import android.view.accessibility.AccessibilityManager;
import android.view.animation.AccelerateInterpolator;
import android.view.animation.AnimationUtils;
import android.view.inputmethod.EditorInfo;
@@ -51,8 +50,8 @@ 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.CellLayout.CellInfo;
import com.android.launcher3.DeviceProfile;
import com.android.launcher3.DragSource;
import com.android.launcher3.DropTarget;
@@ -71,12 +70,12 @@ import com.android.launcher3.ShortcutInfo;
import com.android.launcher3.UninstallDropTarget.DropTargetSource;
import com.android.launcher3.Utilities;
import com.android.launcher3.Workspace.ItemOperator;
-import com.android.launcher3.accessibility.LauncherAccessibilityDelegate.AccessibilityDragSource;
+import com.android.launcher3.accessibility.AccessibileDragListenerAdapter;
import com.android.launcher3.config.FeatureFlags;
import com.android.launcher3.dragndrop.DragController;
import com.android.launcher3.dragndrop.DragController.DragListener;
import com.android.launcher3.dragndrop.DragLayer;
-import com.android.launcher3.logging.UserEventDispatcher.LaunchSourceProvider;
+import com.android.launcher3.dragndrop.DragOptions;
import com.android.launcher3.pageindicators.PageIndicatorDots;
import com.android.launcher3.userevent.nano.LauncherLogProto;
import com.android.launcher3.userevent.nano.LauncherLogProto.Target;
@@ -92,7 +91,7 @@ import java.util.Comparator;
*/
public class Folder extends LinearLayout implements DragSource, View.OnClickListener,
View.OnLongClickListener, DropTarget, FolderListener, TextView.OnEditorActionListener,
- View.OnFocusChangeListener, DragListener, DropTargetSource, AccessibilityDragSource {
+ View.OnFocusChangeListener, DragListener, DropTargetSource {
private static final String TAG = "Launcher.Folder";
/**
@@ -165,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;
@@ -282,10 +279,10 @@ public class Folder extends LinearLayout implements DragSource, View.OnClickList
public boolean onLongClick(View v) {
// Return if global dragging is not enabled
if (!mLauncher.isDraggingEnabled()) return true;
- return beginDrag(v, false);
+ return startDrag(v, new DragOptions());
}
- private boolean beginDrag(View v, boolean accessible) {
+ public boolean startDrag(View v, DragOptions options) {
Object tag = v.getTag();
if (tag instanceof ShortcutInfo) {
ShortcutInfo item = (ShortcutInfo) tag;
@@ -293,35 +290,55 @@ public class Folder extends LinearLayout implements DragSource, View.OnClickList
return false;
}
- mLauncher.getWorkspace().beginDragShared(v, this, accessible);
-
- mCurrentDragInfo = item;
mEmptyCellRank = item.rank;
mCurrentDragView = v;
- mContent.removeItem(mCurrentDragView);
- mInfo.remove(mCurrentDragInfo, true);
- mDragInProgress = true;
- mItemAddedBackToSelfViaIcon = false;
+ mDragController.addDragListener(this);
+ if (options.isAccessibleDrag) {
+ mDragController.addDragListener(new AccessibileDragListenerAdapter(
+ mContent, CellLayout.FOLDER_ACCESSIBILITY_DRAG) {
+
+ @Override
+ protected void enableAccessibleDrag(boolean enable) {
+ super.enableAccessibleDrag(enable);
+ mFooter.setImportantForAccessibility(enable
+ ? IMPORTANT_FOR_ACCESSIBILITY_NO_HIDE_DESCENDANTS
+ : IMPORTANT_FOR_ACCESSIBILITY_AUTO);
+ }
+ });
+ }
+
+ mLauncher.getWorkspace().beginDragShared(v, this, options);
}
return true;
}
@Override
- public void startDrag(CellInfo cellInfo, boolean accessible) {
- beginDrag(cellInfo.cell, accessible);
+ public void onDragStart(DropTarget.DragObject dragObject, DragOptions options) {
+ if (dragObject.dragSource != this) {
+ return;
+ }
+
+ mContent.removeItem(mCurrentDragView);
+ 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;
}
@Override
- public void enableAccessibleDrag(boolean enable) {
- mLauncher.getDropTargetBar().enableAccessibleDrag(enable);
- for (int i = 0; i < mContent.getChildCount(); i++) {
- mContent.getPageAt(i).enableAccessibleDrag(enable, CellLayout.FOLDER_ACCESSIBILITY_DRAG);
+ public void onDragEnd() {
+ if (mIsExternalDrag && mDragInProgress) {
+ completeDragExit();
}
-
- mFooter.setImportantForAccessibility(enable ? IMPORTANT_FOR_ACCESSIBILITY_NO_HIDE_DESCENDANTS :
- IMPORTANT_FOR_ACCESSIBILITY_AUTO);
- mLauncher.getWorkspace().setAddNewPageOnDrag(!enable);
+ mDragController.removeDragListener(this);
}
public boolean isEditingName() {
@@ -352,7 +369,8 @@ public class Folder extends LinearLayout implements DragSource, View.OnClickList
LauncherModel.updateItemInDatabase(mLauncher, mInfo);
if (commit) {
- sendCustomAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED,
+ Utilities.sendCustomAccessibilityEvent(
+ this, AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED,
getContext().getString(R.string.folder_renamed, newTitle));
}
@@ -591,7 +609,9 @@ public class Folder extends LinearLayout implements DragSource, View.OnClickList
openFolderAnim.addListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationStart(Animator animation) {
- sendCustomAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED,
+ Utilities.sendCustomAccessibilityEvent(
+ Folder.this,
+ AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED,
mContent.getAccessibilityDescription());
mState = STATE_ANIMATING;
}
@@ -650,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;
@@ -661,28 +680,6 @@ public class Folder extends LinearLayout implements DragSource, View.OnClickList
mDragController.addDragListener(this);
}
- @Override
- public void onDragStart(DragSource source, ItemInfo info, int dragAction) { }
-
- @Override
- public void onDragEnd() {
- if (mIsExternalDrag && mDragInProgress) {
- completeDragExit();
- }
- mDragController.removeDragListener(this);
- }
-
- @Thunk void sendCustomAccessibilityEvent(int type, String text) {
- AccessibilityManager accessibilityManager = (AccessibilityManager)
- getContext().getSystemService(Context.ACCESSIBILITY_SERVICE);
- if (accessibilityManager.isEnabled()) {
- AccessibilityEvent event = AccessibilityEvent.obtain(type);
- onInitializeAccessibilityEvent(event);
- event.getText().add(text);
- accessibilityManager.sendAccessibilityEvent(event);
- }
- }
-
public void animateClosed() {
if (!(getParent() instanceof DragLayer)) return;
final ObjectAnimator oa = LauncherAnimUtils.ofViewAlphaAndScale(this, 0, 0.9f, 0.9f);
@@ -694,7 +691,9 @@ public class Folder extends LinearLayout implements DragSource, View.OnClickList
}
@Override
public void onAnimationStart(Animator animation) {
- sendCustomAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED,
+ Utilities.sendCustomAccessibilityEvent(
+ Folder.this,
+ AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED,
getContext().getString(R.string.folder_closed));
mState = STATE_ANIMATING;
}
@@ -851,9 +850,7 @@ public class Folder extends LinearLayout implements DragSource, View.OnClickList
}
private void clearDragInfo() {
- mCurrentDragInfo = null;
mCurrentDragView = null;
- mSuppressOnAdd = false;
mIsExternalDrag = false;
}
@@ -917,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) {
@@ -936,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.
@@ -1280,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
@@ -1317,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) {
@@ -1344,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);
@@ -1355,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) {
@@ -1496,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();
+ }
+ }
}