Adding menu to arrange one or two tasks and arrange them accordingly
Added dialog with buttons for task arrangement upon click on decorator
icon.
BUG: 19492945,19868830,19656507
Change-Id: Ie31e2788efb097db1c1f54f0ef1b2fda1ccc71ec
diff --git a/packages/SystemUI/src/com/android/systemui/recents/RecentsActivity.java b/packages/SystemUI/src/com/android/systemui/recents/RecentsActivity.java
index c259c9d..f014f09 100644
--- a/packages/SystemUI/src/com/android/systemui/recents/RecentsActivity.java
+++ b/packages/SystemUI/src/com/android/systemui/recents/RecentsActivity.java
@@ -592,14 +592,14 @@
private RecentsResizeTaskDialog getResizeTaskDebugDialog() {
if (mResizeTaskDebugDialog == null) {
- mResizeTaskDebugDialog = new RecentsResizeTaskDialog(getFragmentManager());
+ mResizeTaskDebugDialog = new RecentsResizeTaskDialog(getFragmentManager(), this);
}
return mResizeTaskDebugDialog;
}
@Override
public void onTaskResize(Task t) {
- getResizeTaskDebugDialog().showResizeTaskDialog(t);
+ getResizeTaskDebugDialog().showResizeTaskDialog(t, mRecentsView);
}
/**** RecentsView.RecentsViewCallbacks Implementation ****/
diff --git a/packages/SystemUI/src/com/android/systemui/recents/RecentsResizeTaskDialog.java b/packages/SystemUI/src/com/android/systemui/recents/RecentsResizeTaskDialog.java
index d67eceb..7c11894 100644
--- a/packages/SystemUI/src/com/android/systemui/recents/RecentsResizeTaskDialog.java
+++ b/packages/SystemUI/src/com/android/systemui/recents/RecentsResizeTaskDialog.java
@@ -16,31 +16,23 @@
package com.android.systemui.recents;
-import android.app.ActivityManager;
import android.app.AlertDialog;
import android.app.Dialog;
import android.app.DialogFragment;
import android.app.FragmentManager;
-import android.content.ComponentName;
import android.content.Context;
import android.content.DialogInterface;
-import android.content.Intent;
-import android.content.pm.ActivityInfo;
-import android.content.pm.ResolveInfo;
import android.graphics.Rect;
import android.os.Bundle;
-import android.util.MutableInt;
-import android.util.SparseArray;
import android.view.LayoutInflater;
import android.view.View;
-import android.widget.EditText;
-import android.widget.Toast;
+import android.widget.Button;
import com.android.systemui.R;
import com.android.systemui.recents.misc.SystemServicesProxy;
import com.android.systemui.recents.model.RecentsTaskLoader;
import com.android.systemui.recents.model.Task;
-
-import java.util.List;
+import com.android.systemui.recents.RecentsActivity;
+import com.android.systemui.recents.views.RecentsView;
/**
* A helper for the dialogs that show when task debugging is on.
@@ -49,80 +41,137 @@
static final String TAG = "RecentsResizeTaskDialog";
+ // The various window arrangements we can handle.
+ private static final int PLACE_LEFT = 1;
+ private static final int PLACE_RIGHT = 2;
+ private static final int PLACE_TOP = 3;
+ private static final int PLACE_BOTTOM = 4;
+ private static final int PLACE_FULL = 5;
+
// The task we want to resize.
- Task mTaskToResize;
- FragmentManager mFragmentManager;
- View mResizeTaskDialogContent;
+ private Task mTaskToResize;
+ private Task mNextTaskToResize;
+ private FragmentManager mFragmentManager;
+ private View mResizeTaskDialogContent;
+ private RecentsActivity mRecentsActivity;
+ private RecentsView mRecentsView;
+ private SystemServicesProxy mSsp;
- public RecentsResizeTaskDialog() {}
-
- public RecentsResizeTaskDialog(FragmentManager mgr) {
+ public RecentsResizeTaskDialog(FragmentManager mgr, RecentsActivity activity) {
mFragmentManager = mgr;
+ mRecentsActivity = activity;
+ mSsp = RecentsTaskLoader.getInstance().getSystemServicesProxy();
}
/** Shows the resize-task dialog. */
- void showResizeTaskDialog(Task t) {
- mTaskToResize = t;
+ void showResizeTaskDialog(Task mainTask, RecentsView rv) {
+ mTaskToResize = mainTask;
+ mRecentsView = rv;
+ mNextTaskToResize = mRecentsView.getNextTaskOrTopTask(mainTask);
+
show(mFragmentManager, TAG);
}
/** Creates a new resize-task dialog. */
private void createResizeTaskDialog(final Context context, LayoutInflater inflater,
- AlertDialog.Builder builder, final SystemServicesProxy ssp) {
- builder.setTitle("Resize Task - Enter new dimensions");
+ AlertDialog.Builder builder) {
+ builder.setTitle(R.string.recents_caption_resize);
mResizeTaskDialogContent =
- inflater.inflate(R.layout.recents_multistack_stack_size_dialog, null, false);
- Rect bounds = ssp.getTaskBounds(mTaskToResize.key.stackId);
- setDimensionInEditText(mResizeTaskDialogContent, R.id.inset_left, bounds.left);
- setDimensionInEditText(mResizeTaskDialogContent, R.id.inset_top, bounds.top);
- setDimensionInEditText(mResizeTaskDialogContent, R.id.inset_right, bounds.right);
- setDimensionInEditText(mResizeTaskDialogContent, R.id.inset_bottom, bounds.bottom);
+ inflater.inflate(R.layout.recents_task_resize_dialog, null, false);
+
+ ((Button)mResizeTaskDialogContent.findViewById(R.id.place_left)).setOnClickListener(
+ new View.OnClickListener() {
+ public void onClick(View v) {
+ placeTasks(PLACE_LEFT);
+ }
+ });
+ ((Button)mResizeTaskDialogContent.findViewById(R.id.place_right)).setOnClickListener(
+ new View.OnClickListener() {
+ public void onClick(View v) {
+ placeTasks(PLACE_RIGHT);
+ }
+ });
+ ((Button)mResizeTaskDialogContent.findViewById(R.id.place_top)).setOnClickListener(
+ new View.OnClickListener() {
+ public void onClick(View v) {
+ placeTasks(PLACE_TOP);
+ }
+ });
+ ((Button)mResizeTaskDialogContent.findViewById(R.id.place_bottom)).setOnClickListener(
+ new View.OnClickListener() {
+ public void onClick(View v) {
+ placeTasks(PLACE_BOTTOM);
+ }
+ });
+ ((Button)mResizeTaskDialogContent.findViewById(R.id.place_full)).setOnClickListener(
+ new View.OnClickListener() {
+ public void onClick(View v) {
+ placeTasks(PLACE_FULL);
+ }
+ });
+
+ builder.setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
+ @Override
+ public void onClick(DialogInterface dialog, int which) {
+ dismiss();
+ }
+ });
+
builder.setView(mResizeTaskDialogContent);
- builder.setPositiveButton("Resize Task", new DialogInterface.OnClickListener() {
- @Override
- public void onClick(DialogInterface dialog, int which) {
- int left = getDimensionFromEditText(mResizeTaskDialogContent, R.id.inset_left);
- int top = getDimensionFromEditText(mResizeTaskDialogContent, R.id.inset_top);
- int right = getDimensionFromEditText(mResizeTaskDialogContent, R.id.inset_right);
- int bottom = getDimensionFromEditText(mResizeTaskDialogContent, R.id.inset_bottom);
- if (bottom <= top || right <= left) {
- Toast.makeText(context, "Invalid dimensions", Toast.LENGTH_SHORT).show();
- dismiss();
- return;
- }
- ssp.resizeTask(mTaskToResize.key.id, new Rect(left, top, right, bottom));
- dismiss();
- }
- });
- builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
- @Override
- public void onClick(DialogInterface dialog, int which) {
- dismiss();
- }
- });
}
- /** Helper to get an integer value from an edit text. */
- private int getDimensionFromEditText(View container, int id) {
- String text = ((EditText) container.findViewById(id)).getText().toString();
- if (text.trim().length() != 0) {
- return Integer.parseInt(text.trim());
+ /** Helper function to place window(s) on the display according to an arrangement request. */
+ private void placeTasks(int arrangement) {
+ Rect focusedBounds = mSsp.getWindowRect();
+ Rect otherBounds = new Rect(focusedBounds);
+
+ switch (arrangement) {
+ case PLACE_LEFT:
+ focusedBounds.right = focusedBounds.centerX();
+ otherBounds.left = focusedBounds.right;
+ break;
+ case PLACE_RIGHT:
+ otherBounds.right = otherBounds.centerX();
+ focusedBounds.left = otherBounds.right;
+ break;
+ case PLACE_TOP:
+ focusedBounds.bottom = focusedBounds.centerY();
+ otherBounds.top = focusedBounds.bottom;
+ break;
+ case PLACE_BOTTOM:
+ otherBounds.bottom = otherBounds.centerY();
+ focusedBounds.top = otherBounds.bottom;
+ break;
+ case PLACE_FULL:
+ // Null the rectangle to avoid the other task to show up.
+ otherBounds = new Rect();
+ break;
}
- return 0;
- }
- /** Helper to set an integer value to an edit text. */
- private void setDimensionInEditText(View container, int id, int value) {
- ((EditText) container.findViewById(id)).setText("" + value);
+ // Resize all other tasks to go to the other side.
+ if (mNextTaskToResize != null && !otherBounds.isEmpty()) {
+ mSsp.resizeTask(mNextTaskToResize.key.id, otherBounds);
+ }
+ mSsp.resizeTask(mTaskToResize.key.id, focusedBounds);
+
+ // Get rid of the dialog.
+ dismiss();
+ mRecentsActivity.dismissRecentsToHomeRaw(false);
+
+ // Show tasks - beginning with the other first so that the focus ends on the selected one.
+ // TODO: Remove this once issue b/19893373 is resolved.
+ if (mNextTaskToResize != null && !otherBounds.isEmpty()) {
+ mRecentsView.launchTask(mNextTaskToResize);
+ }
+ mRecentsView.launchTask(mTaskToResize);
}
@Override
public Dialog onCreateDialog(Bundle args) {
final Context context = this.getActivity();
- final SystemServicesProxy ssp = RecentsTaskLoader.getInstance().getSystemServicesProxy();
LayoutInflater inflater = getActivity().getLayoutInflater();
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
- createResizeTaskDialog(context, inflater, builder, ssp);
+ createResizeTaskDialog(context, inflater, builder);
return builder.create();
}
}
diff --git a/packages/SystemUI/src/com/android/systemui/recents/misc/SystemServicesProxy.java b/packages/SystemUI/src/com/android/systemui/recents/misc/SystemServicesProxy.java
index a473a29..d60df9c 100644
--- a/packages/SystemUI/src/com/android/systemui/recents/misc/SystemServicesProxy.java
+++ b/packages/SystemUI/src/com/android/systemui/recents/misc/SystemServicesProxy.java
@@ -259,7 +259,7 @@
public Rect getTaskBounds(int stackId) {
ActivityManager.StackInfo info = getAllStackInfos().get(stackId);
if (info != null)
- return getAllStackInfos().get(stackId).bounds;
+ return info.bounds;
return new Rect();
}
diff --git a/packages/SystemUI/src/com/android/systemui/recents/views/RecentsView.java b/packages/SystemUI/src/com/android/systemui/recents/views/RecentsView.java
index 448a7a9..abed7a5 100644
--- a/packages/SystemUI/src/com/android/systemui/recents/views/RecentsView.java
+++ b/packages/SystemUI/src/com/android/systemui/recents/views/RecentsView.java
@@ -149,6 +149,31 @@
return mTaskStackViews;
}
+ /** Gets the next task in the stack - or if the last - the top task */
+ public Task getNextTaskOrTopTask(Task taskToSearch) {
+ Task returnTask = null;
+ boolean found = false;
+ List<TaskStackView> stackViews = getTaskStackViews();
+ int stackCount = stackViews.size();
+ for (int i = stackCount - 1; i >= 0; --i) {
+ TaskStack stack = stackViews.get(i).getStack();
+ ArrayList<Task> taskList = stack.getTasks();
+ // Iterate the stack views and try and find the focused task
+ for (int j = taskList.size() - 1; j >= 0; --j) {
+ Task task = taskList.get(j);
+ // Return the next task in the line.
+ if (found)
+ return task;
+ // Remember the first possible task as the top task.
+ if (returnTask == null)
+ returnTask = task;
+ if (task == taskToSearch)
+ found = true;
+ }
+ }
+ return returnTask;
+ }
+
/** Launches the focused task from the first stack if possible */
public boolean launchFocusedTask() {
// Get the first stack view
@@ -172,6 +197,28 @@
return false;
}
+ /** Launches a given task. */
+ public boolean launchTask(Task task) {
+ // Get the first stack view
+ List<TaskStackView> stackViews = getTaskStackViews();
+ int stackCount = stackViews.size();
+ for (int i = 0; i < stackCount; i++) {
+ TaskStackView stackView = stackViews.get(i);
+ TaskStack stack = stackView.getStack();
+ // Iterate the stack views and try and find the given task.
+ List<TaskView> taskViews = stackView.getTaskViews();
+ int taskViewCount = taskViews.size();
+ for (int j = 0; j < taskViewCount; j++) {
+ TaskView tv = taskViews.get(j);
+ if (tv.getTask() == task) {
+ onTaskViewClicked(stackView, tv, stack, task, false);
+ return true;
+ }
+ }
+ }
+ return false;
+ }
+
/** Launches the task that Recents was launched from, if possible */
public boolean launchPreviousTask() {
// Get the first stack view
diff --git a/packages/SystemUI/src/com/android/systemui/recents/views/TaskViewHeader.java b/packages/SystemUI/src/com/android/systemui/recents/views/TaskViewHeader.java
index 56801e5..42399a3 100644
--- a/packages/SystemUI/src/com/android/systemui/recents/views/TaskViewHeader.java
+++ b/packages/SystemUI/src/com/android/systemui/recents/views/TaskViewHeader.java
@@ -26,14 +26,15 @@
import android.content.res.ColorStateList;
import android.graphics.Canvas;
import android.graphics.Color;
+import android.graphics.drawable.Drawable;
+import android.graphics.drawable.GradientDrawable;
+import android.graphics.drawable.RippleDrawable;
import android.graphics.Outline;
import android.graphics.Paint;
import android.graphics.PorterDuff;
import android.graphics.PorterDuffColorFilter;
import android.graphics.PorterDuffXfermode;
-import android.graphics.drawable.Drawable;
-import android.graphics.drawable.GradientDrawable;
-import android.graphics.drawable.RippleDrawable;
+import android.graphics.Rect;
import android.util.AttributeSet;
import android.view.View;
import android.view.ViewOutlineProvider;
@@ -43,7 +44,9 @@
import com.android.systemui.R;
import com.android.systemui.recents.Constants;
import com.android.systemui.recents.RecentsConfiguration;
+import com.android.systemui.recents.misc.SystemServicesProxy;
import com.android.systemui.recents.misc.Utilities;
+import com.android.systemui.recents.model.RecentsTaskLoader;
import com.android.systemui.recents.model.Task;
@@ -51,6 +54,7 @@
public class TaskViewHeader extends FrameLayout {
RecentsConfiguration mConfig;
+ private SystemServicesProxy mSsp;
// Header views
ImageView mMoveTaskButton;
@@ -91,6 +95,7 @@
public TaskViewHeader(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
super(context, attrs, defStyleAttr, defStyleRes);
mConfig = RecentsConfiguration.getInstance();
+ mSsp = RecentsTaskLoader.getInstance().getSystemServicesProxy();
setWillNotDraw(false);
setClipToOutline(true);
setOutlineProvider(new ViewOutlineProvider() {
@@ -209,6 +214,31 @@
mMoveTaskButton.setVisibility((mConfig.multiStackEnabled) ? View.VISIBLE : View.INVISIBLE);
}
+ /** Updates the resize task bar button. */
+ void updateResizeTaskBarIcon(Task t) {
+ Rect display = mSsp.getWindowRect();
+ Rect taskRect = mSsp.getTaskBounds(t.key.stackId);
+ int resId = R.drawable.star;
+ if (display.equals(taskRect)) {
+ resId = R.drawable.vector_drawable_place_fullscreen;
+ } else {
+ boolean top = display.top == taskRect.top;
+ boolean bottom = display.bottom == taskRect.bottom;
+ boolean left = display.left == taskRect.left;
+ boolean right = display.right == taskRect.right;
+ if (top && bottom && left) {
+ resId = R.drawable.vector_drawable_place_left;
+ } else if (top && bottom && right) {
+ resId = R.drawable.vector_drawable_place_right;
+ } else if (top && left && right) {
+ resId = R.drawable.vector_drawable_place_top;
+ } else if (bottom && left && right) {
+ resId = R.drawable.vector_drawable_place_bottom;
+ }
+ }
+ mMoveTaskButton.setImageResource(resId);
+ }
+
/** Unbinds the bar view from the task */
void unbindFromTask() {
mApplicationIcon.setImageDrawable(null);