Merge "Added shortcut key to dock windows" into nyc-dev
This commit is contained in:
@@ -278,6 +278,26 @@ public class DividerSnapAlgorithm {
|
|||||||
return snapTarget;
|
return snapTarget;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Cycles through all non-dismiss targets with a stepping of {@param increment}. It moves left
|
||||||
|
* if {@param increment} is negative and moves right otherwise.
|
||||||
|
*/
|
||||||
|
public SnapTarget cycleNonDismissTarget(SnapTarget snapTarget, int increment) {
|
||||||
|
int index = mTargets.indexOf(snapTarget);
|
||||||
|
if (index != -1) {
|
||||||
|
SnapTarget newTarget = mTargets.get((index + mTargets.size() + increment)
|
||||||
|
% mTargets.size());
|
||||||
|
if (newTarget == mDismissStartTarget) {
|
||||||
|
return mLastSplitTarget;
|
||||||
|
} else if (newTarget == mDismissEndTarget) {
|
||||||
|
return mFirstSplitTarget;
|
||||||
|
} else {
|
||||||
|
return newTarget;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return snapTarget;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents a snap target for the divider.
|
* Represents a snap target for the divider.
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -23,7 +23,9 @@ import android.content.Context;
|
|||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.ServiceConnection;
|
import android.content.ServiceConnection;
|
||||||
import android.content.res.Configuration;
|
import android.content.res.Configuration;
|
||||||
|
import android.graphics.Point;
|
||||||
import android.graphics.Rect;
|
import android.graphics.Rect;
|
||||||
|
import android.hardware.display.DisplayManager;
|
||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
import android.os.Handler;
|
import android.os.Handler;
|
||||||
import android.os.IBinder;
|
import android.os.IBinder;
|
||||||
@@ -389,6 +391,13 @@ public class Recents extends SystemUI
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Point realSize = new Point();
|
||||||
|
if (initialBounds == null) {
|
||||||
|
mContext.getSystemService(DisplayManager.class).getDisplay(Display.DEFAULT_DISPLAY)
|
||||||
|
.getRealSize(realSize);
|
||||||
|
initialBounds = new Rect(0, 0, realSize.x, realSize.y);
|
||||||
|
}
|
||||||
|
|
||||||
int currentUser = sSystemServicesProxy.getCurrentUser();
|
int currentUser = sSystemServicesProxy.getCurrentUser();
|
||||||
SystemServicesProxy ssp = Recents.getSystemServices();
|
SystemServicesProxy ssp = Recents.getSystemServices();
|
||||||
ActivityManager.RunningTaskInfo topTask = ssp.getTopMostTask();
|
ActivityManager.RunningTaskInfo topTask = ssp.getTopMostTask();
|
||||||
|
|||||||
@@ -17,18 +17,31 @@
|
|||||||
package com.android.systemui.shortcut;
|
package com.android.systemui.shortcut;
|
||||||
|
|
||||||
import android.accessibilityservice.AccessibilityServiceInfo;
|
import android.accessibilityservice.AccessibilityServiceInfo;
|
||||||
|
import android.app.ActivityManager;
|
||||||
|
import android.app.ActivityManagerNative;
|
||||||
|
import android.app.IActivityManager;
|
||||||
import android.content.ComponentName;
|
import android.content.ComponentName;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.pm.ServiceInfo;
|
import android.content.pm.ServiceInfo;
|
||||||
|
import android.content.res.Configuration;
|
||||||
import android.os.RemoteException;
|
import android.os.RemoteException;
|
||||||
|
import android.util.DisplayMetrics;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.view.IWindowManager;
|
import android.view.IWindowManager;
|
||||||
import android.view.KeyEvent;
|
import android.view.KeyEvent;
|
||||||
|
import android.view.WindowManager;
|
||||||
import android.view.WindowManagerGlobal;
|
import android.view.WindowManagerGlobal;
|
||||||
import android.view.accessibility.AccessibilityManager;
|
import android.view.accessibility.AccessibilityManager;
|
||||||
|
import com.android.internal.logging.MetricsLogger;
|
||||||
|
import com.android.internal.logging.MetricsProto.MetricsEvent;
|
||||||
|
import com.android.internal.policy.DividerSnapAlgorithm;
|
||||||
import com.android.settingslib.accessibility.AccessibilityUtils;
|
import com.android.settingslib.accessibility.AccessibilityUtils;
|
||||||
import com.android.systemui.R;
|
import com.android.systemui.R;
|
||||||
import com.android.systemui.SystemUI;
|
import com.android.systemui.SystemUI;
|
||||||
|
import com.android.systemui.recents.Recents;
|
||||||
|
import com.android.systemui.stackdivider.Divider;
|
||||||
|
import com.android.systemui.stackdivider.DividerView;
|
||||||
|
import com.android.systemui.statusbar.phone.NavigationBarGestureHelper;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
@@ -42,28 +55,70 @@ public class ShortcutKeyDispatcher extends SystemUI
|
|||||||
private static final String TAG = "ShortcutKeyDispatcher";
|
private static final String TAG = "ShortcutKeyDispatcher";
|
||||||
|
|
||||||
private ShortcutKeyServiceProxy mShortcutKeyServiceProxy = new ShortcutKeyServiceProxy(this);
|
private ShortcutKeyServiceProxy mShortcutKeyServiceProxy = new ShortcutKeyServiceProxy(this);
|
||||||
private IWindowManager windowManagerService = WindowManagerGlobal.getWindowManagerService();
|
private IWindowManager mWindowManagerService = WindowManagerGlobal.getWindowManagerService();
|
||||||
|
private IActivityManager mActivityManager = ActivityManagerNative.getDefault();
|
||||||
|
|
||||||
protected final long META_MASK = ((long) KeyEvent.META_META_ON) << Integer.SIZE;
|
protected final long META_MASK = ((long) KeyEvent.META_META_ON) << Integer.SIZE;
|
||||||
protected final long ALT_MASK = ((long) KeyEvent.META_ALT_ON) << Integer.SIZE;
|
protected final long ALT_MASK = ((long) KeyEvent.META_ALT_ON) << Integer.SIZE;
|
||||||
protected final long CTRL_MASK = ((long) KeyEvent.META_CTRL_ON) << Integer.SIZE;
|
protected final long CTRL_MASK = ((long) KeyEvent.META_CTRL_ON) << Integer.SIZE;
|
||||||
protected final long SHIFT_MASK = ((long) KeyEvent.META_SHIFT_ON) << Integer.SIZE;
|
protected final long SHIFT_MASK = ((long) KeyEvent.META_SHIFT_ON) << Integer.SIZE;
|
||||||
|
|
||||||
|
protected final long SC_DOCK_LEFT = META_MASK | KeyEvent.KEYCODE_LEFT_BRACKET;
|
||||||
|
protected final long SC_DOCK_RIGHT = META_MASK | KeyEvent.KEYCODE_RIGHT_BRACKET;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Registers a shortcut key to window manager.
|
* Registers a shortcut key to window manager.
|
||||||
* @param shortcutCode packed representation of shortcut key code and meta information
|
* @param shortcutCode packed representation of shortcut key code and meta information
|
||||||
*/
|
*/
|
||||||
public void registerShortcutKey(long shortcutCode) {
|
public void registerShortcutKey(long shortcutCode) {
|
||||||
try {
|
try {
|
||||||
windowManagerService.registerShortcutKey(shortcutCode, mShortcutKeyServiceProxy);
|
mWindowManagerService.registerShortcutKey(shortcutCode, mShortcutKeyServiceProxy);
|
||||||
} catch (RemoteException e) {
|
} catch (RemoteException e) {
|
||||||
// Do nothing
|
// Do nothing
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onShortcutKeyPressed(long shortcutCode) {}
|
public void onShortcutKeyPressed(long shortcutCode) {
|
||||||
|
int orientation = mContext.getResources().getConfiguration().orientation;
|
||||||
|
if ((shortcutCode == SC_DOCK_LEFT || shortcutCode == SC_DOCK_RIGHT)
|
||||||
|
&& orientation == Configuration.ORIENTATION_LANDSCAPE) {
|
||||||
|
handleDockKey(shortcutCode);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void start() {}
|
public void start() {
|
||||||
|
registerShortcutKey(SC_DOCK_LEFT);
|
||||||
|
registerShortcutKey(SC_DOCK_RIGHT);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void handleDockKey(long shortcutCode) {
|
||||||
|
try {
|
||||||
|
int dockSide = mWindowManagerService.getDockedStackSide();
|
||||||
|
if (dockSide == WindowManager.DOCKED_INVALID) {
|
||||||
|
// If there is no window docked, we dock the top-most window.
|
||||||
|
Recents recents = getComponent(Recents.class);
|
||||||
|
int dockMode = (shortcutCode == SC_DOCK_LEFT)
|
||||||
|
? ActivityManager.DOCKED_STACK_CREATE_MODE_TOP_OR_LEFT
|
||||||
|
: ActivityManager.DOCKED_STACK_CREATE_MODE_BOTTOM_OR_RIGHT;
|
||||||
|
recents.dockTopTask(NavigationBarGestureHelper.DRAG_MODE_NONE, dockMode, null);
|
||||||
|
MetricsLogger.action(mContext, MetricsEvent.WINDOW_DOCK_SHORTCUTS);
|
||||||
|
} else {
|
||||||
|
// If there is already a docked window, we respond by resizing the docking pane.
|
||||||
|
DividerView dividerView = getComponent(Divider.class).getView();
|
||||||
|
DividerSnapAlgorithm snapAlgorithm = dividerView.getSnapAlgorithm();
|
||||||
|
int dividerPosition = dividerView.getCurrentPosition();
|
||||||
|
DividerSnapAlgorithm.SnapTarget currentTarget =
|
||||||
|
snapAlgorithm.calculateNonDismissingSnapTarget(dividerPosition);
|
||||||
|
int increment = (shortcutCode == SC_DOCK_LEFT) ? -1 : 1;
|
||||||
|
DividerSnapAlgorithm.SnapTarget target = snapAlgorithm.cycleNonDismissTarget(
|
||||||
|
currentTarget, increment);
|
||||||
|
dividerView.startDragging(true /* animate */, false /* touching */);
|
||||||
|
dividerView.stopDragging(target.position, 0f, true /* avoidDismissStart */);
|
||||||
|
}
|
||||||
|
} catch (RemoteException e) {
|
||||||
|
Log.e(TAG, "handleDockKey() failed.");
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1172,13 +1172,8 @@ public class PhoneStatusBar extends BaseStatusBar implements DemoMode,
|
|||||||
}
|
}
|
||||||
int dockSide = WindowManagerProxy.getInstance().getDockSide();
|
int dockSide = WindowManagerProxy.getInstance().getDockSide();
|
||||||
if (dockSide == WindowManager.DOCKED_INVALID) {
|
if (dockSide == WindowManager.DOCKED_INVALID) {
|
||||||
Point realSize = new Point();
|
|
||||||
mContext.getSystemService(DisplayManager.class).getDisplay(Display.DEFAULT_DISPLAY)
|
|
||||||
.getRealSize(realSize);
|
|
||||||
Rect initialBounds= new Rect(0, 0, realSize.x, realSize.y);
|
|
||||||
return mRecents.dockTopTask(NavigationBarGestureHelper.DRAG_MODE_NONE,
|
return mRecents.dockTopTask(NavigationBarGestureHelper.DRAG_MODE_NONE,
|
||||||
ActivityManager.DOCKED_STACK_CREATE_MODE_TOP_OR_LEFT,
|
ActivityManager.DOCKED_STACK_CREATE_MODE_TOP_OR_LEFT, null);
|
||||||
initialBounds);
|
|
||||||
} else {
|
} else {
|
||||||
EventBus.getDefault().send(new UndockingTaskEvent());
|
EventBus.getDefault().send(new UndockingTaskEvent());
|
||||||
return false;
|
return false;
|
||||||
|
|||||||
@@ -1993,6 +1993,9 @@ message MetricsEvent {
|
|||||||
// Settings -> Apps -> Gear -> Special access
|
// Settings -> Apps -> Gear -> Special access
|
||||||
SPECIAL_ACCESS = 351;
|
SPECIAL_ACCESS = 351;
|
||||||
|
|
||||||
|
// Logs that the user docks window via shortcut key.
|
||||||
|
WINDOW_DOCK_SHORTCUTS = 352;
|
||||||
|
|
||||||
// Add new aosp constants above this line.
|
// Add new aosp constants above this line.
|
||||||
// END OF AOSP CONSTANTS
|
// END OF AOSP CONSTANTS
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user