From 2c5763ae5d04ebd67eae2f86f840e6e68304e821 Mon Sep 17 00:00:00 2001 From: Wale Ogunwale Date: Wed, 11 Feb 2015 10:26:44 -0800 Subject: Am command to split a stack. Change-Id: Idf3a364fc3826f6fe92f55b5c83b16b380d62ff4 --- cmds/am/src/com/android/commands/am/Am.java | 68 ++++++++++++++++++++++++++++- 1 file changed, 67 insertions(+), 1 deletion(-) (limited to 'cmds/am') diff --git a/cmds/am/src/com/android/commands/am/Am.java b/cmds/am/src/com/android/commands/am/Am.java index cf608a8..8997671 100644 --- a/cmds/am/src/com/android/commands/am/Am.java +++ b/cmds/am/src/com/android/commands/am/Am.java @@ -132,6 +132,7 @@ public class Am extends BaseCommand { " am stack start \n" + " am stack movetask [true|false]\n" + " am stack resize \n" + + " am stack split [INTENT]\n" + " am stack list\n" + " am stack info \n" + " am task lock \n" + @@ -245,7 +246,14 @@ public class Am extends BaseCommand { "am stack movetask: move from its current stack to the top (true) or" + " bottom (false) of .\n" + "\n" + - "am stack resize: change size and position to .\n" + + "am stack resize: change size and position to " + + ".\n" + + "\n" + + "am stack split: split into 2 stacks ertically or orizontally" + + " starting the new stack with [INTENT] if specified. If [INTENT] isn't" + + " specified and the current stack has more than one task, then the top task" + + " of the current task will be moved to the new stack. Command will also force" + + " all current tasks in both stacks to be resizeable." + "\n" + "am stack list: list all of the activity stacks and their sizes.\n" + "\n" + @@ -1687,6 +1695,8 @@ public class Am extends BaseCommand { runStackList(); } else if (op.equals("info")) { runStackInfo(); + } else if (op.equals("split")) { + runStackSplit(); } else { showError("Error: unknown command '" + op + "'"); return; @@ -1783,6 +1793,62 @@ public class Am extends BaseCommand { } } + private void runStackSplit() throws Exception { + final int stackId = Integer.valueOf(nextArgRequired()); + final String splitDirection = nextArgRequired(); + Intent intent = null; + try { + intent = makeIntent(UserHandle.USER_CURRENT); + } catch (IllegalArgumentException e) { + // no intent supplied. + } + + try { + final StackInfo currentStackInfo = mAm.getStackInfo(stackId); + // Calculate bounds for new and current stack. + final Rect currentStackBounds = new Rect(currentStackInfo.bounds); + final Rect newStackBounds = new Rect(currentStackInfo.bounds); + if ("v".equals(splitDirection)) { + currentStackBounds.right = newStackBounds.left = currentStackInfo.bounds.centerX(); + } else if ("h".equals(splitDirection)) { + currentStackBounds.bottom = newStackBounds.top = currentStackInfo.bounds.centerY(); + } else { + showError("Error: unknown split direction '" + splitDirection + "'"); + return; + } + + // Create new stack + IActivityContainer container = mAm.createStackOnDisplay(currentStackInfo.displayId); + if (container == null) { + showError("Error: Unable to create new stack..."); + } + + final StackInfo newStackInfo = mAm.getStackInfo(container.getStackId()); + + if (intent != null) { + container.startActivity(intent); + } else if (currentStackInfo.taskIds != null && currentStackInfo.taskIds.length > 1) { + // Move top task over to new stack + mAm.moveTaskToStack(currentStackInfo.taskIds[currentStackInfo.taskIds.length - 1], + newStackInfo.stackId, true); + } + + // Make all tasks in the stacks resizeable. + for (int taskId : currentStackInfo.taskIds) { + mAm.setTaskResizeable(taskId, true); + } + + for (int taskId : newStackInfo.taskIds) { + mAm.setTaskResizeable(taskId, true); + } + + // Resize stacks + mAm.resizeStack(currentStackInfo.stackId, currentStackBounds); + mAm.resizeStack(newStackInfo.stackId, newStackBounds); + } catch (RemoteException e) { + } + } + private void runTask() throws Exception { String op = nextArgRequired(); if (op.equals("lock")) { -- cgit v1.1