OSDN Git Service

Add ability to supply initial bounds when docking task
authorJorim Jaggi <jjaggi@google.com>
Tue, 24 Nov 2015 02:08:28 +0000 (18:08 -0800)
committerJorim Jaggi <jjaggi@google.com>
Tue, 24 Nov 2015 23:08:49 +0000 (15:08 -0800)
Add an optional parameter in moveTaskToDockedStack to supply an
initial rect to be used when creating the dockeds tack. Pass in
the adjusted rect when dragging up from the navbar so it doesn't
flicker anymore.

Change-Id: Ieb3c8c73b9e2a769a2ec6270bd76a713201a2aed

13 files changed:
core/java/android/app/ActivityManagerNative.java
core/java/android/app/IActivityManager.java
packages/SystemUI/src/com/android/systemui/RecentsComponent.java
packages/SystemUI/src/com/android/systemui/recents/Recents.java
packages/SystemUI/src/com/android/systemui/recents/RecentsImpl.java
packages/SystemUI/src/com/android/systemui/recents/misc/SystemServicesProxy.java
packages/SystemUI/src/com/android/systemui/stackdivider/DividerView.java
packages/SystemUI/src/com/android/systemui/statusbar/phone/NavigationBarGestureHelper.java
packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBar.java
services/core/java/com/android/server/am/ActivityManagerService.java
services/core/java/com/android/server/wm/TaskPositioner.java
services/core/java/com/android/server/wm/TaskStack.java
services/core/java/com/android/server/wm/WindowManagerService.java

index 303078b..19d9fc2 100644 (file)
@@ -752,7 +752,12 @@ public abstract class ActivityManagerNative extends Binder implements IActivityM
             int createMode = data.readInt();
             boolean toTop = data.readInt() != 0;
             boolean animate = data.readInt() != 0;
-            moveTaskToDockedStack(taskId, createMode, toTop, animate);
+            Rect bounds = null;
+            boolean hasBounds = data.readInt() != 0;
+            if (hasBounds) {
+                bounds = Rect.CREATOR.createFromParcel(data);
+            }
+            moveTaskToDockedStack(taskId, createMode, toTop, animate, bounds);
             reply.writeNoException();
             return true;
         }
@@ -3578,8 +3583,8 @@ class ActivityManagerProxy implements IActivityManager
         reply.recycle();
     }
     @Override
-    public void moveTaskToDockedStack(int taskId, int createMode, boolean toTop, boolean animate)
-            throws RemoteException
+    public void moveTaskToDockedStack(int taskId, int createMode, boolean toTop, boolean animate,
+            Rect initialBounds) throws RemoteException
     {
         Parcel data = Parcel.obtain();
         Parcel reply = Parcel.obtain();
@@ -3588,6 +3593,12 @@ class ActivityManagerProxy implements IActivityManager
         data.writeInt(createMode);
         data.writeInt(toTop ? 1 : 0);
         data.writeInt(animate ? 1 : 0);
+        if (initialBounds != null) {
+            data.writeInt(1);
+            initialBounds.writeToParcel(data, 0);
+        } else {
+            data.writeInt(0);
+        }
         mRemote.transact(MOVE_TASK_TO_DOCKED_STACK_TRANSACTION, data, reply, 0);
         reply.readException();
         data.recycle();
index 6594990..09c6c0b 100644 (file)
@@ -142,8 +142,8 @@ public interface IActivityManager extends IInterface {
     public boolean moveActivityTaskToBack(IBinder token, boolean nonRoot) throws RemoteException;
     public void moveTaskBackwards(int task) throws RemoteException;
     public void moveTaskToStack(int taskId, int stackId, boolean toTop) throws RemoteException;
-    public void moveTaskToDockedStack(int taskId, int createMode, boolean toTop, boolean animate)
-            throws RemoteException;
+    public void moveTaskToDockedStack(int taskId, int createMode, boolean toTop, boolean animate,
+            Rect initialBounds) throws RemoteException;
     public boolean moveTopActivityToPinnedStack(int stackId, Rect bounds) throws RemoteException;
     public void resizeStack(int stackId, Rect bounds, boolean allowResizeInDockedMode) throws RemoteException;
     public void positionTaskInStack(int taskId, int stackId, int position) throws RemoteException;
index f5f6acf..4cb8a3c 100644 (file)
@@ -16,6 +16,7 @@
 
 package com.android.systemui;
 
+import android.graphics.Rect;
 import android.view.Display;
 import android.view.View;
 
@@ -31,7 +32,7 @@ public interface RecentsComponent {
     /**
      * Docks the top-most task and opens recents.
      */
-    void dockTopTask(boolean draggingInRecents);
+    void dockTopTask(boolean draggingInRecents, Rect initialBounds);
 
     /**
      * Called during a drag-from-navbar-in gesture.
index 186cace..f5c6914 100644 (file)
@@ -21,6 +21,7 @@ import android.content.Context;
 import android.content.Intent;
 import android.content.ServiceConnection;
 import android.content.res.Configuration;
+import android.graphics.Rect;
 import android.os.Build;
 import android.os.Handler;
 import android.os.IBinder;
@@ -363,8 +364,8 @@ public class Recents extends SystemUI
     }
 
     @Override
-    public void dockTopTask(boolean draggingInRecents) {
-        mImpl.dockTopTask(draggingInRecents);
+    public void dockTopTask(boolean draggingInRecents, Rect initialBounds) {
+        mImpl.dockTopTask(draggingInRecents, initialBounds);
         if (draggingInRecents) {
             mDraggingInRecentsCurrentUser = sSystemServicesProxy.getCurrentUser();
         }
index e0ff4cc..4e08081 100644 (file)
@@ -537,12 +537,12 @@ public class RecentsImpl extends IRecentsNonSystemUserCallbacks.Stub implements
         showRelativeAffiliatedTask(false);
     }
 
-    public void dockTopTask(boolean draggingInRecents) {
+    public void dockTopTask(boolean draggingInRecents, Rect initialBounds) {
         SystemServicesProxy ssp = Recents.getSystemServices();
         ActivityManager.RunningTaskInfo topTask = ssp.getTopMostTask();
         if (topTask != null && !SystemServicesProxy.isHomeStack(topTask.stackId)) {
             ssp.moveTaskToDockedStack(topTask.id,
-                    ActivityManager.DOCKED_STACK_CREATE_MODE_TOP_OR_LEFT);
+                    ActivityManager.DOCKED_STACK_CREATE_MODE_TOP_OR_LEFT, initialBounds);
             showRecents(false /* triggeredFromAltTab */, draggingInRecents, false /* animate */);
         }
     }
index 5026c79..de40a37 100644 (file)
@@ -312,11 +312,12 @@ public class SystemServicesProxy {
     }
 
     /** Docks an already resumed task to the side of the screen. */
-    public void moveTaskToDockedStack(int taskId, int createMode) {
+    public void moveTaskToDockedStack(int taskId, int createMode, Rect initialBounds) {
         if (mIam == null) return;
 
         try {
-            mIam.moveTaskToDockedStack(taskId, createMode, true /* onTop */, false /* animate */);
+            mIam.moveTaskToDockedStack(taskId, createMode, true /* onTop */, false /* animate */,
+                    initialBounds);
         } catch (RemoteException e) {
             e.printStackTrace();
         }
index 3e317ff..f045814 100644 (file)
@@ -301,22 +301,26 @@ public class DividerView extends FrameLayout implements OnTouchListener,
         return mStartPosition + touchY - mStartY;
     }
 
-    public void resizeStack(int position) {
-        mTmpRect.set(0, 0, mDisplayWidth, mDisplayHeight);
-        switch (mDockSide) {
+    public void calculateBoundsForPosition(int position, int dockSide, Rect outRect) {
+        outRect.set(0, 0, mDisplayWidth, mDisplayHeight);
+        switch (dockSide) {
             case WindowManager.DOCKED_LEFT:
-                mTmpRect.right = position;
+                outRect.right = position;
                 break;
             case WindowManager.DOCKED_TOP:
-                mTmpRect.bottom = position;
+                outRect.bottom = position;
                 break;
             case WindowManager.DOCKED_RIGHT:
-                mTmpRect.left = position + mDividerWindowWidth - 2 * mDividerInsets;
+                outRect.left = position + mDividerWindowWidth - 2 * mDividerInsets;
                 break;
             case WindowManager.DOCKED_BOTTOM:
-                mTmpRect.top = position + mDividerWindowWidth - 2 * mDividerInsets;
+                outRect.top = position + mDividerWindowWidth - 2 * mDividerInsets;
                 break;
         }
+    }
+
+    public void resizeStack(int position) {
+        calculateBoundsForPosition(position, mDockSide, mTmpRect);
         if (mTmpRect.equals(mLastResizeRect)) {
             return;
         }
index 742be02..d91bfb9 100644 (file)
@@ -19,6 +19,7 @@ package com.android.systemui.statusbar.phone;
 import android.content.Context;
 import android.content.res.Configuration;
 import android.content.res.Resources;
+import android.graphics.Rect;
 import android.os.SystemProperties;
 import android.view.GestureDetector;
 import android.view.MotionEvent;
@@ -170,7 +171,18 @@ public class NavigationBarGestureHelper extends GestureDetector.SimpleOnGestureL
             if (touchSlopExceeded && mDivider.getView().getWindowManagerProxy().getDockSide()
                     == DOCKED_INVALID) {
                 mDragMode = calculateDragMode();
-                mRecentsComponent.dockTopTask(mDragMode == DRAG_MODE_RECENTS);
+                Rect initialBounds = null;
+                if (mDragMode == DRAG_MODE_DIVIDER) {
+                    initialBounds = new Rect();
+                    mDivider.getView().calculateBoundsForPosition(mIsVertical
+                                    ? (int) event.getRawX()
+                                    : (int) event.getRawY(),
+                            mDivider.getView().isHorizontalDivision()
+                                    ? DOCKED_TOP
+                                    : DOCKED_LEFT,
+                            initialBounds);
+                }
+                mRecentsComponent.dockTopTask(mDragMode == DRAG_MODE_RECENTS, initialBounds);
                 if (mDragMode == DRAG_MODE_DIVIDER) {
                     mDivider.getView().startDragging();
                 }
@@ -193,12 +205,12 @@ public class NavigationBarGestureHelper extends GestureDetector.SimpleOnGestureL
         mVelocityTracker.computeCurrentVelocity(1000);
         if (mDockWindowTouchSlopExceeded) {
             if (mDragMode == DRAG_MODE_DIVIDER) {
-                mDivider.getView().stopDragging(!mIsVertical
-                                ? (int) event.getRawY()
-                                : (int) event.getRawX(),
-                        !mIsVertical
-                                ? mVelocityTracker.getYVelocity()
-                                : mVelocityTracker.getXVelocity());
+                mDivider.getView().stopDragging(mIsVertical
+                                ? (int) event.getRawX()
+                                : (int) event.getRawY(),
+                        mIsVertical
+                                ? mVelocityTracker.getXVelocity()
+                                : mVelocityTracker.getYVelocity());
             } else if (mDragMode == DRAG_MODE_RECENTS) {
                 mRecentsComponent.onDraggingInRecentsEnded(mVelocityTracker.getYVelocity());
             }
index 0f182ac..6d8e650 100644 (file)
@@ -1134,7 +1134,7 @@ public class PhoneStatusBar extends BaseStatusBar implements DemoMode,
         @Override
         public boolean onLongClick(View v) {
             if (mRecents != null) {
-                mRecents.dockTopTask(false /* draggingInRecents */);
+                mRecents.dockTopTask(false /* draggingInRecents */, null /* initialBounds */);
                 return true;
             }
             return false;
index 94a908c..9650088 100644 (file)
@@ -4317,7 +4317,8 @@ public final class ActivityManagerService extends ActivityManagerNative
             if (launchStackId != INVALID_STACK_ID) {
                 if (launchStackId == DOCKED_STACK_ID && bOptions != null) {
                     ActivityOptions activityOptions = new ActivityOptions(bOptions);
-                    mWindowManager.setDockedStackCreateMode(activityOptions.getDockCreateMode());
+                    mWindowManager.setDockedStackCreateState(activityOptions.getDockCreateMode(),
+                            null /* initialBounds */);
                 }
                 if (task.stack.mStackId != launchStackId) {
                     mStackSupervisor.moveTaskToStackLocked(
@@ -9280,9 +9281,12 @@ public final class ActivityManagerService extends ActivityManagerNative
      *                   {@link android.app.ActivityManager#DOCKED_STACK_CREATE_MODE_BOTTOM_OR_RIGHT}
      * @param toTop If the task and stack should be moved to the top.
      * @param animate Whether we should play an animation for the moving the task
+     * @param initialBounds If the docked stack gets created, it will use these bounds for the
+     *                      docked stack. Pass {@code null} to use default bounds.
      */
     @Override
-    public void moveTaskToDockedStack(int taskId, int createMode, boolean toTop, boolean animate) {
+    public void moveTaskToDockedStack(int taskId, int createMode, boolean toTop, boolean animate,
+            Rect initialBounds) {
         enforceCallingPermission(android.Manifest.permission.MANAGE_ACTIVITY_STACKS,
                 "moveTaskToDockedStack()");
         synchronized (this) {
@@ -9290,10 +9294,9 @@ public final class ActivityManagerService extends ActivityManagerNative
             try {
                 if (DEBUG_STACK) Slog.d(TAG_STACK, "moveTaskToDockedStack: moving task=" + taskId
                         + " to createMode=" + createMode + " toTop=" + toTop);
-                mWindowManager.setDockedStackCreateMode(createMode);
-                mStackSupervisor.moveTaskToStackLocked(
-                        taskId, DOCKED_STACK_ID, toTop, !FORCE_FOCUS, "moveTaskToDockedStack",
-                        animate);
+                mWindowManager.setDockedStackCreateState(createMode, initialBounds);
+                mStackSupervisor.moveTaskToStackLocked(taskId, DOCKED_STACK_ID, toTop, !FORCE_FOCUS,
+                        "moveTaskToDockedStack", animate);
             } finally {
                 Binder.restoreCallingIdentity(ident);
             }
index 804830e..09118c7 100644 (file)
@@ -196,7 +196,8 @@ class TaskPositioner implements DimLayer.DimLayerUser {
                                     ? DOCKED_STACK_CREATE_MODE_TOP_OR_LEFT
                                     : DOCKED_STACK_CREATE_MODE_BOTTOM_OR_RIGHT;
                             mService.mActivityManager.moveTaskToDockedStack(
-                                    mTask.mTaskId, createMode, true /*toTop*/, true /* animate */);
+                                    mTask.mTaskId, createMode, true /*toTop*/, true /* animate */,
+                                    null /* initialBounds */);
                         }
                     } catch(RemoteException e) {}
 
index 04ab544..9d07fb0 100644 (file)
@@ -387,7 +387,7 @@ public class TaskStack implements DimLayer.DimLayerUser {
             if (dockedStack != null) {
                 dockedStack.getRawBounds(mTmpRect2);
             }
-            final boolean dockedOnTopOrLeft = WindowManagerService.sDockedStackCreateMode
+            final boolean dockedOnTopOrLeft = mService.mDockedStackCreateMode
                     == DOCKED_STACK_CREATE_MODE_TOP_OR_LEFT;
             getStackDockedModeBounds(mTmpRect, bounds, mStackId, mTmpRect2,
                     mDisplayContent.mDividerControllerLocked.getContentWidth(),
@@ -451,7 +451,7 @@ public class TaskStack implements DimLayer.DimLayerUser {
      *                         close to the side of the dock.
      * @param dockOnTopOrLeft If the docked stack is on the top or left side of the screen.
      */
-    private static void getStackDockedModeBounds(
+    private void getStackDockedModeBounds(
             Rect displayRect, Rect outBounds, int stackId, Rect dockedBounds, int dockDividerWidth,
             boolean dockOnTopOrLeft) {
         final boolean dockedStack = stackId == DOCKED_STACK_ID;
@@ -459,6 +459,10 @@ public class TaskStack implements DimLayer.DimLayerUser {
 
         outBounds.set(displayRect);
         if (dockedStack) {
+            if (mService.mDockedStackCreateBounds != null) {
+                outBounds.set(mService.mDockedStackCreateBounds);
+                return;
+            }
             // The initial bounds of the docked stack when it is created half the screen space and
             // its bounds can be adjusted after that. The bounds of all other stacks are adjusted
             // to occupy whatever screen space the docked stack isn't occupying.
@@ -505,7 +509,7 @@ public class TaskStack implements DimLayer.DimLayerUser {
         final Rect bounds = new Rect();
         mDisplayContent.getLogicalDisplayRect(bounds);
         if (!fullscreen) {
-            final boolean dockedOnTopOrLeft = WindowManagerService.sDockedStackCreateMode
+            final boolean dockedOnTopOrLeft = mService.mDockedStackCreateMode
                     == DOCKED_STACK_CREATE_MODE_TOP_OR_LEFT;
             getStackDockedModeBounds(bounds, bounds, FULLSCREEN_WORKSPACE_STACK_ID, dockedBounds,
                     mDisplayContent.mDividerControllerLocked.getContentWidth(), dockedOnTopOrLeft);
index c7fccc3..d186e02 100644 (file)
@@ -482,7 +482,8 @@ public class WindowManagerService extends IWindowManager.Stub
 
     private boolean mKeyguardWaitingForActivityDrawn;
 
-    static int sDockedStackCreateMode = DOCKED_STACK_CREATE_MODE_TOP_OR_LEFT;
+    int mDockedStackCreateMode = DOCKED_STACK_CREATE_MODE_TOP_OR_LEFT;
+    Rect mDockedStackCreateBounds;
 
     private final SparseIntArray mTmpTaskIds = new SparseIntArray();
 
@@ -4631,9 +4632,10 @@ public class WindowManagerService extends IWindowManager.Stub
         return (stack != null && stack.isVisibleLocked());
     }
 
-    public void setDockedStackCreateMode(int mode) {
+    public void setDockedStackCreateState(int mode, Rect bounds) {
         synchronized (mWindowMap) {
-            sDockedStackCreateMode = mode;
+            mDockedStackCreateMode = mode;
+            mDockedStackCreateBounds = bounds;
         }
     }