OSDN Git Service

Fixing page background not displayed when dragging from all apps
authorSunny Goyal <sunnygoyal@google.com>
Wed, 27 May 2015 01:56:52 +0000 (18:56 -0700)
committerSunny Goyal <sunnygoyal@google.com>
Thu, 28 May 2015 00:50:35 +0000 (17:50 -0700)
> Adding empty page synchronously, instead of waiting for a frame
> Changing launcher state from widgets screen in the same frame, similar to all apps
> Removing DragEnforcer, and moving that logic in side the workspace, disabled by a flag
> Using first page to get page bounds in drag layer, as last page may not have been measured

Change-Id: I172ba4e5ce44648ac55402d49994542c6e10f101

res/values/config.xml
src/com/android/launcher3/CellLayout.java
src/com/android/launcher3/DragLayer.java
src/com/android/launcher3/DropTarget.java
src/com/android/launcher3/Workspace.java
src/com/android/launcher3/allapps/AllAppsContainerView.java
src/com/android/launcher3/widget/WidgetsContainerView.java

index fbce3a4..73de794 100644 (file)
@@ -20,6 +20,7 @@
 
 <!-- DragController -->
     <integer name="config_flingToDeleteMinVelocity">-1500</integer>
+    <item type="id" name="drag_event_parity" />
 
 <!-- AllApps & Launcher transitions -->
     <!-- The alpha of the AppsCustomize bg in spring loaded mode -->
index 2b1cfe0..61567ac 100644 (file)
@@ -168,7 +168,6 @@ public class CellLayout extends ViewGroup implements BubbleTextShadowHandler {
     private int[] mDirectionVector = new int[2];
     int[] mPreviousReorderDirection = new int[2];
     private static final int INVALID_DIRECTION = -100;
-    private DropTarget.DragEnforcer mDragEnforcer;
 
     private final Rect mTempRect = new Rect();
 
@@ -188,7 +187,6 @@ public class CellLayout extends ViewGroup implements BubbleTextShadowHandler {
 
     public CellLayout(Context context, AttributeSet attrs, int defStyle) {
         super(context, attrs, defStyle);
-        mDragEnforcer = new DropTarget.DragEnforcer(context);
 
         // A ViewGroup usually does not draw, but CellLayout needs to draw a rectangle to show
         // the user where a dragged item will land when dropped.
@@ -2637,7 +2635,6 @@ public class CellLayout extends ViewGroup implements BubbleTextShadowHandler {
      * or it may have begun on another layout.
      */
     void onDragEnter() {
-        mDragEnforcer.onDragEnter();
         mDragging = true;
     }
 
@@ -2645,7 +2642,6 @@ public class CellLayout extends ViewGroup implements BubbleTextShadowHandler {
      * Called when drag has left this CellLayout or has been completed (successfully or not)
      */
     void onDragExit() {
-        mDragEnforcer.onDragExit();
         // This can actually be called when we aren't in a drag, e.g. when adding a new
         // item to this layout via the customize drawer.
         // Guard against that case.
index 423a9a3..41e053e 100644 (file)
@@ -918,7 +918,7 @@ public class DragLayer extends InsettableFrameLayout {
     void showPageHints() {
         mShowPageHints = true;
         Workspace workspace = mLauncher.getWorkspace();
-        getDescendantRectRelativeToSelf(workspace.getChildAt(workspace.getChildCount() - 1),
+        getDescendantRectRelativeToSelf(workspace.getChildAt(workspace.numCustomPages()),
                 mScrollChildPosition);
         invalidate();
     }
index a3828c1..c8fac54 100644 (file)
 
 package com.android.launcher3;
 
-import android.content.Context;
 import android.graphics.PointF;
 import android.graphics.Rect;
-import android.util.Log;
 
 /**
  * Interface defining an object that can receive a drag.
@@ -93,43 +91,6 @@ public interface DropTarget {
         }
     }
 
-    public static class DragEnforcer implements DragController.DragListener {
-        int dragParity = 0;
-
-        public DragEnforcer(Context context) {
-            Launcher launcher = (Launcher) context;
-            launcher.getDragController().addDragListener(this);
-        }
-
-        void onDragEnter() {
-            dragParity++;
-            if (dragParity != 1) {
-                Log.e(TAG, "onDragEnter: Drag contract violated: " + dragParity);
-            }
-        }
-
-        void onDragExit() {
-            dragParity--;
-            if (dragParity != 0) {
-                Log.e(TAG, "onDragExit: Drag contract violated: " + dragParity);
-            }
-        }
-
-        @Override
-        public void onDragStart(DragSource source, Object info, int dragAction) {
-            if (dragParity != 0) {
-                Log.e(TAG, "onDragEnter: Drag contract violated: " + dragParity);
-            }
-        }
-
-        @Override
-        public void onDragEnd() {
-            if (dragParity != 0) {
-                Log.e(TAG, "onDragExit: Drag contract violated: " + dragParity);
-            }
-        }
-    }
-
     /**
      * Used to temporarily disable certain drop targets
      *
index c0a1cfc..2eb1879 100644 (file)
@@ -64,8 +64,8 @@ import com.android.launcher3.Launcher.LauncherOverlay;
 import com.android.launcher3.LauncherSettings.Favorites;
 import com.android.launcher3.UninstallDropTarget.UninstallSource;
 import com.android.launcher3.accessibility.LauncherAccessibilityDelegate;
-import com.android.launcher3.accessibility.OverviewScreenAccessibilityDelegate;
 import com.android.launcher3.accessibility.LauncherAccessibilityDelegate.AccessibilityDragSource;
+import com.android.launcher3.accessibility.OverviewScreenAccessibilityDelegate;
 import com.android.launcher3.compat.UserHandleCompat;
 import com.android.launcher3.util.LongArrayMap;
 import com.android.launcher3.util.Thunk;
@@ -89,6 +89,8 @@ public class Workspace extends PagedView
         Insettable, UninstallSource, AccessibilityDragSource {
     private static final String TAG = "Launcher.Workspace";
 
+    private static boolean ENFORCE_DRAG_EVENT_ORDER = false;
+
     protected static final int SNAP_OFF_EMPTY_SCREEN_DURATION = 400;
     protected static final int FADE_EMPTY_SCREEN_DURATION = 150;
 
@@ -215,7 +217,6 @@ public class Workspace extends PagedView
     private FolderIcon mDragOverFolderIcon = null;
     private boolean mCreateUserFolderOnDrop = false;
     private boolean mAddToExistingFolderOnDrop = false;
-    private DropTarget.DragEnforcer mDragEnforcer;
     private float mMaxDistanceForFolderCreation;
 
     private final Canvas mCanvas = new Canvas();
@@ -301,9 +302,6 @@ public class Workspace extends PagedView
 
         mOutlineHelper = HolographicOutlineHelper.obtain(context);
 
-        mDragEnforcer = new DropTarget.DragEnforcer(context);
-        // With workspace, data is available straight from the get-go
-
         mLauncher = (Launcher) context;
         mStateTransitionAnimation = new WorkspaceStateTransitionAnimation(mLauncher, this);
         final Resources res = getResources();
@@ -372,22 +370,23 @@ public class Workspace extends PagedView
         return r;
     }
 
+    @Override
     public void onDragStart(final DragSource source, Object info, int dragAction) {
+        if (ENFORCE_DRAG_EVENT_ORDER) {
+            enfoceDragParity("onDragStart", 0, 0);
+        }
+
         mIsDragOccuring = true;
         updateChildrenLayersEnabled(false);
         mLauncher.lockScreenOrientation();
         mLauncher.onInteractionBegin();
         // Prevent any Un/InstallShortcutReceivers from updating the db while we are dragging
         InstallShortcutReceiver.enableInstallQueue();
-        post(new Runnable() {
-            @Override
-            public void run() {
-                if (mIsDragOccuring && mAddNewPageOnDrag) {
-                    mDeferRemoveExtraEmptyScreen = false;
-                    addExtraEmptyScreenOnDrag();
-                }
-            }
-        });
+
+        if (mAddNewPageOnDrag) {
+            mDeferRemoveExtraEmptyScreen = false;
+            addExtraEmptyScreenOnDrag();
+        }
     }
 
     public void setAddNewPageOnDrag(boolean addPage) {
@@ -398,7 +397,12 @@ public class Workspace extends PagedView
         mDeferRemoveExtraEmptyScreen = true;
     }
 
+    @Override
     public void onDragEnd() {
+        if (ENFORCE_DRAG_EVENT_ORDER) {
+            enfoceDragParity("onDragEnd", 0, 0);
+        }
+
         if (!mDeferRemoveExtraEmptyScreen) {
             removeExtraEmptyScreen(true, mDragSourceInternal != null);
         }
@@ -2822,8 +2826,12 @@ public class Workspace extends PagedView
         location[1] = vY - y;
     }
 
+    @Override
     public void onDragEnter(DragObject d) {
-        mDragEnforcer.onDragEnter();
+        if (ENFORCE_DRAG_EVENT_ORDER) {
+            enfoceDragParity("onDragEnter", 1, 1);
+        }
+
         mCreateUserFolderOnDrop = false;
         mAddToExistingFolderOnDrop = false;
 
@@ -2876,8 +2884,11 @@ public class Workspace extends PagedView
         return null;
     }
 
+    @Override
     public void onDragExit(DragObject d) {
-        mDragEnforcer.onDragExit();
+        if (ENFORCE_DRAG_EVENT_ORDER) {
+            enfoceDragParity("onDragExit", -1, 0);
+        }
 
         // Here we store the final page that will be dropped to, if the workspace in fact
         // receives the drop
@@ -2909,6 +2920,24 @@ public class Workspace extends PagedView
         mLauncher.getDragLayer().hidePageHints();
     }
 
+    private void enfoceDragParity(String event, int update, int expectedValue) {
+        enfoceDragParity(this, event, update, expectedValue);
+        for (int i = 0; i < getChildCount(); i++) {
+            enfoceDragParity(getChildAt(i), event, update, expectedValue);
+        }
+    }
+
+    private void enfoceDragParity(View v, String event, int update, int expectedValue) {
+        Object tag = v.getTag(R.id.drag_event_parity);
+        int value = tag == null ? 0 : (Integer) tag;
+        value += update;
+        v.setTag(R.id.drag_event_parity, value);
+
+        if (value != expectedValue) {
+            Log.e(TAG, event + ": Drag contract violated: " + value);
+        }
+    }
+
     void setCurrentDropLayout(CellLayout layout) {
         if (mDragTargetLayout != null) {
             mDragTargetLayout.revertTempState();
index 60f9ab3..d81f97f 100644 (file)
@@ -447,7 +447,6 @@ public class AllAppsContainerView extends BaseContainerView implements DragSourc
     @Override
     protected void onFixedBoundsUpdated() {
         // Update the number of items in the grid
-        LauncherAppState app = LauncherAppState.getInstance();
         DeviceProfile grid = mLauncher.getDeviceProfile();
         if (grid.updateAppsViewNumCols(getContext().getResources(), mFixedBounds.width())) {
             mNumAppsPerRow = grid.allAppsNumCols;
index 05e842e..778cf9e 100644 (file)
@@ -35,7 +35,6 @@ import com.android.launcher3.DeviceProfile;
 import com.android.launcher3.DragController;
 import com.android.launcher3.DragSource;
 import com.android.launcher3.DropTarget.DragObject;
-import com.android.launcher3.model.WidgetsModel;
 import com.android.launcher3.Folder;
 import com.android.launcher3.IconCache;
 import com.android.launcher3.ItemInfo;
@@ -46,6 +45,7 @@ import com.android.launcher3.R;
 import com.android.launcher3.Utilities;
 import com.android.launcher3.WidgetPreviewLoader;
 import com.android.launcher3.Workspace;
+import com.android.launcher3.model.WidgetsModel;
 
 /**
  * The widgets list view container.
@@ -56,8 +56,6 @@ public class WidgetsContainerView extends BaseContainerView
     private static final String TAG = "WidgetsContainerView";
     private static final boolean DEBUG = false;
 
-    private static final int SPRING_MODE_DELAY_MS = 150;
-
     /* Coefficient multiplied to the screen height for preloading widgets. */
     private static final int PRELOAD_SCREEN_HEIGHT_MULTIPLE = 1;
 
@@ -186,18 +184,11 @@ public class WidgetsContainerView extends BaseContainerView
             Log.e(TAG, "Unexpected dragging view: " + v);
         }
 
-        // We delay entering spring-loaded mode slightly to make sure the UI
-        // thread is free of any work.
-        postDelayed(new Runnable() {
-            @Override
-            public void run() {
-                // We don't enter spring-loaded mode if the drag has been cancelled
-                if (mLauncher.getDragController().isDragging()) {
-                    // Go into spring loaded mode (must happen before we startDrag())
-                    mLauncher.enterSpringLoadedDragMode();
-                }
-            }
-        }, SPRING_MODE_DELAY_MS);
+        // We don't enter spring-loaded mode if the drag has been cancelled
+        if (mLauncher.getDragController().isDragging()) {
+            // Go into spring loaded mode (must happen before we startDrag())
+            mLauncher.enterSpringLoadedDragMode();
+        }
 
         return true;
     }