Adding actions to non client decor buttons
This patch requires CL 744205 to be landed first.
Bug: 22881983
Change-Id: I1bbce52e18719adcd09c7e70e09c37ec33387b04
diff --git a/core/java/android/view/Window.java b/core/java/android/view/Window.java
index 4fc2ad3..78e2788 100644
--- a/core/java/android/view/Window.java
+++ b/core/java/android/view/Window.java
@@ -674,9 +674,9 @@
}
/** @hide */
- public final void dispatchOnWindowDismissed() {
+ public final void dispatchOnWindowDismissed(boolean finishTask) {
if (mOnWindowDismissedCallback != null) {
- mOnWindowDismissedCallback.onWindowDismissed(false);
+ mOnWindowDismissedCallback.onWindowDismissed(finishTask);
}
}
diff --git a/core/java/com/android/internal/policy/PhoneWindow.java b/core/java/com/android/internal/policy/PhoneWindow.java
index 0bd8d85..807f082 100644
--- a/core/java/com/android/internal/policy/PhoneWindow.java
+++ b/core/java/com/android/internal/policy/PhoneWindow.java
@@ -4403,7 +4403,7 @@
swipeDismiss.setOnDismissedListener(new SwipeDismissLayout.OnDismissedListener() {
@Override
public void onDismissed(SwipeDismissLayout layout) {
- dispatchOnWindowDismissed();
+ dispatchOnWindowDismissed(false /*finishTask*/);
}
});
swipeDismiss.setOnSwipeProgressChangedListener(
diff --git a/core/java/com/android/internal/widget/NonClientDecorView.java b/core/java/com/android/internal/widget/NonClientDecorView.java
index 57039b7..d343783 100644
--- a/core/java/com/android/internal/widget/NonClientDecorView.java
+++ b/core/java/com/android/internal/widget/NonClientDecorView.java
@@ -16,9 +16,6 @@
package com.android.internal.widget;
-import android.app.ActivityManager;
-import android.app.ActivityManager.RunningTaskInfo;
-import android.app.ActivityManagerNative;
import android.content.Context;
import android.os.RemoteException;
import android.util.AttributeSet;
@@ -29,11 +26,10 @@
import android.view.ViewOutlineProvider;
import android.view.WindowInsets;
+import android.view.Window;
import com.android.internal.R;
import com.android.internal.policy.PhoneWindow;
-import java.util.List;
-
/**
* This class represents the special screen elements to control a window on free form
* environment. All thse screen elements are added in the "non client area" which is the area of
@@ -106,20 +102,9 @@
@Override
public void onClick(View view) {
if (view.getId() == R.id.maximize_window) {
- // TODO(skuhne): Add code to maximize window.
+ maximizeWindow();
} else if (view.getId() == R.id.close_window) {
- // TODO(skuhne): This is not the right way to kill an app and we should add a high level
- // function for it.
- final ActivityManager m =
- (ActivityManager) getContext().getSystemService(Context.ACTIVITY_SERVICE);
- List<RunningTaskInfo> runningTaskInfoList = m.getRunningTasks(1);
- if (!runningTaskInfoList.isEmpty()) {
- try {
- ActivityManagerNative.getDefault().removeTask(runningTaskInfoList.get(0).id);
- } catch (RemoteException ex) {
- Log.e(TAG, "Couldn't close task with the close button.");
- }
- }
+ mOwner.dispatchOnWindowDismissed(true /*finishTask*/);
}
}
@@ -216,4 +201,17 @@
return TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dip,
getResources().getDisplayMetrics());
}
+
+ // Maximize the window by moving it to the maximize stack.
+ private void maximizeWindow() {
+ Window.WindowStackCallback callback = mOwner.getWindowStackCallback();
+ if (callback != null) {
+ try {
+ callback.changeWindowStack(
+ android.app.ActivityManager.FULLSCREEN_WORKSPACE_STACK_ID);
+ } catch (RemoteException ex) {
+ Log.e(TAG, "Cannot change task workspace.");
+ }
+ }
+ }
}