summaryrefslogtreecommitdiffstats
path: root/src/com/android/launcher3/accessibility
diff options
context:
space:
mode:
authorSunny Goyal <sunnygoyal@google.com>2016-08-16 15:36:48 -0700
committerSunny Goyal <sunnygoyal@google.com>2016-09-01 15:55:13 -0700
commit94b510cc683a6436ae82c6d323cbd8b429561b06 (patch)
tree7f5c31eed6030bea083d1b77396478bbe5f35e7c /src/com/android/launcher3/accessibility
parent61bcfba33598ddd0bc59910ab758fcd51d770502 (diff)
downloadandroid_packages_apps_Trebuchet-94b510cc683a6436ae82c6d323cbd8b429561b06.tar.gz
android_packages_apps_Trebuchet-94b510cc683a6436ae82c6d323cbd8b429561b06.tar.bz2
android_packages_apps_Trebuchet-94b510cc683a6436ae82c6d323cbd8b429561b06.zip
Some drag and drop code refactor:
1) Adding DragOptions to easily extend drap functionality 2) Changing onDragStarted signature to send more information 3) Updating states for dropTargetButton based on drag event directly 4) Removing folder item based on onDragStarted and not startDrag Change-Id: I65b684e092ddc081d086bfe2c8c1973ed170eaeb
Diffstat (limited to 'src/com/android/launcher3/accessibility')
-rw-r--r--src/com/android/launcher3/accessibility/AccessibileDragListenerAdapter.java66
-rw-r--r--src/com/android/launcher3/accessibility/LauncherAccessibilityDelegate.java36
2 files changed, 79 insertions, 23 deletions
diff --git a/src/com/android/launcher3/accessibility/AccessibileDragListenerAdapter.java b/src/com/android/launcher3/accessibility/AccessibileDragListenerAdapter.java
new file mode 100644
index 000000000..62a9a6d19
--- /dev/null
+++ b/src/com/android/launcher3/accessibility/AccessibileDragListenerAdapter.java
@@ -0,0 +1,66 @@
+/*
+ * Copyright (C) 2016 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.launcher3.accessibility;
+
+import android.view.ViewGroup;
+
+import com.android.launcher3.CellLayout;
+import com.android.launcher3.DropTarget.DragObject;
+import com.android.launcher3.Launcher;
+import com.android.launcher3.dragndrop.DragController.DragListener;
+import com.android.launcher3.dragndrop.DragOptions;
+
+/**
+ * Utility listener to enable/disable accessibility drag flags for a ViewGroup
+ * containing CellLayouts
+ */
+public class AccessibileDragListenerAdapter implements DragListener {
+
+ private final ViewGroup mViewGroup;
+ private final int mDragType;
+
+ /**
+ * @param parent
+ * @param dragType either {@link CellLayout#WORKSPACE_ACCESSIBILITY_DRAG} or
+ * {@link CellLayout#FOLDER_ACCESSIBILITY_DRAG}
+ */
+ public AccessibileDragListenerAdapter(ViewGroup parent, int dragType) {
+ mViewGroup = parent;
+ mDragType = dragType;
+ }
+
+ @Override
+ public void onDragStart(DragObject dragObject, DragOptions options) {
+ enableAccessibleDrag(true);
+ }
+
+ @Override
+ public void onDragEnd() {
+ enableAccessibleDrag(false);
+ Launcher.getLauncher(mViewGroup.getContext()).getDragController().removeDragListener(this);
+ }
+
+ protected void enableAccessibleDrag(boolean enable) {
+ for (int i = 0; i < mViewGroup.getChildCount(); i++) {
+ setEnableForLayout((CellLayout) mViewGroup.getChildAt(i), enable);
+ }
+ }
+
+ protected final void setEnableForLayout(CellLayout layout, boolean enable) {
+ layout.enableAccessibleDrag(enable, mDragType);
+ }
+}
diff --git a/src/com/android/launcher3/accessibility/LauncherAccessibilityDelegate.java b/src/com/android/launcher3/accessibility/LauncherAccessibilityDelegate.java
index 0562cf54b..173aad044 100644
--- a/src/com/android/launcher3/accessibility/LauncherAccessibilityDelegate.java
+++ b/src/com/android/launcher3/accessibility/LauncherAccessibilityDelegate.java
@@ -22,6 +22,8 @@ import com.android.launcher3.BubbleTextView;
import com.android.launcher3.CellLayout;
import com.android.launcher3.DeleteDropTarget;
import com.android.launcher3.DragSource;
+import com.android.launcher3.DropTarget.DragObject;
+import com.android.launcher3.dragndrop.DragOptions;
import com.android.launcher3.folder.Folder;
import com.android.launcher3.FolderInfo;
import com.android.launcher3.InfoDropTarget;
@@ -73,7 +75,6 @@ public class LauncherAccessibilityDelegate extends AccessibilityDelegate impleme
@Thunk final Launcher mLauncher;
private DragInfo mDragInfo = null;
- private AccessibilityDragSource mDragSource = null;
public LauncherAccessibilityDelegate(Launcher launcher) {
mLauncher = launcher;
@@ -372,26 +373,25 @@ public class LauncherAccessibilityDelegate extends AccessibilityDelegate impleme
Folder folder = workspace.getOpenFolder();
if (folder != null) {
- if (folder.getItemsInReadingOrder().contains(item)) {
- mDragSource = folder;
- } else {
+ if (!folder.getItemsInReadingOrder().contains(item)) {
mLauncher.closeFolder();
+ folder = null;
}
}
- if (mDragSource == null) {
- mDragSource = workspace;
- }
- mDragSource.enableAccessibleDrag(true);
- mDragSource.startDrag(cellInfo, true);
- if (mLauncher.getDragController().isDragging()) {
- mLauncher.getDragController().addDragListener(this);
+ mLauncher.getDragController().addDragListener(this);
+
+ DragOptions options = new DragOptions();
+ options.isAccessibleDrag = true;
+ if (folder != null) {
+ folder.startDrag(cellInfo.cell, options);
+ } else {
+ workspace.startDrag(cellInfo, options);
}
}
-
@Override
- public void onDragStart(DragSource source, ItemInfo info, int dragAction) {
+ public void onDragStart(DragObject dragObject, DragOptions options) {
// No-op
}
@@ -399,16 +399,6 @@ public class LauncherAccessibilityDelegate extends AccessibilityDelegate impleme
public void onDragEnd() {
mLauncher.getDragController().removeDragListener(this);
mDragInfo = null;
- if (mDragSource != null) {
- mDragSource.enableAccessibleDrag(false);
- mDragSource = null;
- }
- }
-
- public static interface AccessibilityDragSource {
- void startDrag(CellLayout.CellInfo cellInfo, boolean accessible);
-
- void enableAccessibleDrag(boolean enable);
}
/**