From 6b88baf1e8cf85f0e44054464824c3af76b2b6ce Mon Sep 17 00:00:00 2001 From: Winson Chung Date: Thu, 16 Mar 2017 17:10:21 -0700 Subject: [PATCH] Adding enabled state for remote actions. - Actions can specify whether they are enabled (default) or disabled, and SystemUI will reflect the state in the PiP actions. Bug: 36363677 Test: Expand pip with dismissed action Change-Id: I36994868f82d8ba0fc87947a722d9f20b39425a1 --- api/current.txt | 4 ++- api/system-current.txt | 4 ++- api/test-current.txt | 4 ++- core/java/android/app/RemoteAction.java | 23 ++++++++++++++++- .../SystemUI/res/layout/pip_menu_action.xml | 3 ++- .../SystemUI/res/layout/pip_menu_activity.xml | 3 ++- .../systemui/pip/phone/PipMenuActivity.java | 25 +++++++++++-------- 7 files changed, 50 insertions(+), 16 deletions(-) diff --git a/api/current.txt b/api/current.txt index 77cb9e490b04e..8908ccda61cb5 100644 --- a/api/current.txt +++ b/api/current.txt @@ -5717,6 +5717,8 @@ package android.app { method public java.lang.CharSequence getContentDescription(); method public android.graphics.drawable.Icon getIcon(); method public java.lang.CharSequence getTitle(); + method public boolean isEnabled(); + method public void setEnabled(boolean); method public void writeToParcel(android.os.Parcel, int); field public static final android.os.Parcelable.Creator CREATOR; } @@ -45423,7 +45425,7 @@ package android.view { method public void setActivated(boolean); method public void setAlpha(float); method public void setAnimation(android.view.animation.Animation); - method public void setAutofillHint(java.lang.String[]); + method public void setAutofillHint(java.lang.String...); method public void setAutofillMode(int); method public void setBackground(android.graphics.drawable.Drawable); method public void setBackgroundColor(int); diff --git a/api/system-current.txt b/api/system-current.txt index 827b46ce77463..b59df7bff072f 100644 --- a/api/system-current.txt +++ b/api/system-current.txt @@ -5924,6 +5924,8 @@ package android.app { method public java.lang.CharSequence getContentDescription(); method public android.graphics.drawable.Icon getIcon(); method public java.lang.CharSequence getTitle(); + method public boolean isEnabled(); + method public void setEnabled(boolean); method public void writeToParcel(android.os.Parcel, int); field public static final android.os.Parcelable.Creator CREATOR; } @@ -48889,7 +48891,7 @@ package android.view { method public void setActivated(boolean); method public void setAlpha(float); method public void setAnimation(android.view.animation.Animation); - method public void setAutofillHint(java.lang.String[]); + method public void setAutofillHint(java.lang.String...); method public void setAutofillMode(int); method public void setBackground(android.graphics.drawable.Drawable); method public void setBackgroundColor(int); diff --git a/api/test-current.txt b/api/test-current.txt index 04f4f21e095fd..042c9212fdc7c 100644 --- a/api/test-current.txt +++ b/api/test-current.txt @@ -5728,6 +5728,8 @@ package android.app { method public java.lang.CharSequence getContentDescription(); method public android.graphics.drawable.Icon getIcon(); method public java.lang.CharSequence getTitle(); + method public boolean isEnabled(); + method public void setEnabled(boolean); method public void writeToParcel(android.os.Parcel, int); field public static final android.os.Parcelable.Creator CREATOR; } @@ -45786,7 +45788,7 @@ package android.view { method public void setActivated(boolean); method public void setAlpha(float); method public void setAnimation(android.view.animation.Animation); - method public void setAutofillHint(java.lang.String[]); + method public void setAutofillHint(java.lang.String...); method public void setAutofillMode(int); method public void setBackground(android.graphics.drawable.Drawable); method public void setBackgroundColor(int); diff --git a/core/java/android/app/RemoteAction.java b/core/java/android/app/RemoteAction.java index 5958bc14d4746..e7fe407b29b33 100644 --- a/core/java/android/app/RemoteAction.java +++ b/core/java/android/app/RemoteAction.java @@ -41,12 +41,14 @@ public final class RemoteAction implements Parcelable { private final CharSequence mTitle; private final CharSequence mContentDescription; private final PendingIntent mActionIntent; + private boolean mEnabled; RemoteAction(Parcel in) { mIcon = Icon.CREATOR.createFromParcel(in); mTitle = TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(in); mContentDescription = TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(in); mActionIntent = PendingIntent.CREATOR.createFromParcel(in); + mEnabled = in.readBoolean(); } public RemoteAction(@NonNull Icon icon, @NonNull CharSequence title, @@ -59,6 +61,21 @@ public final class RemoteAction implements Parcelable { mTitle = title; mContentDescription = contentDescription; mActionIntent = intent; + mEnabled = true; + } + + /** + * Sets whether this action is enabled. + */ + public void setEnabled(boolean enabled) { + mEnabled = enabled; + } + + /** + * Return whether this action is enabled. + */ + public boolean isEnabled() { + return mEnabled; } /** @@ -91,7 +108,9 @@ public final class RemoteAction implements Parcelable { @Override public RemoteAction clone() { - return new RemoteAction(mIcon, mTitle, mContentDescription, mActionIntent); + RemoteAction action = new RemoteAction(mIcon, mTitle, mContentDescription, mActionIntent); + action.setEnabled(mEnabled); + return action; } @Override @@ -105,11 +124,13 @@ public final class RemoteAction implements Parcelable { TextUtils.writeToParcel(mTitle, out, flags); TextUtils.writeToParcel(mContentDescription, out, flags); mActionIntent.writeToParcel(out, flags); + out.writeBoolean(mEnabled); } public void dump(String prefix, PrintWriter pw) { pw.print(prefix); pw.print("title=" + mTitle); + pw.print(" enabled=" + mEnabled); pw.print(" contentDescription=" + mContentDescription); pw.print(" icon=" + mIcon); pw.print(" action=" + mActionIntent.getIntent()); diff --git a/packages/SystemUI/res/layout/pip_menu_action.xml b/packages/SystemUI/res/layout/pip_menu_action.xml index 77efc9be5bc82..9150a000de004 100644 --- a/packages/SystemUI/res/layout/pip_menu_action.xml +++ b/packages/SystemUI/res/layout/pip_menu_action.xml @@ -18,4 +18,5 @@ android:layout_width="@dimen/pip_action_size" android:layout_height="@dimen/pip_action_size" android:padding="@dimen/pip_action_padding" - android:background="?android:selectableItemBackgroundBorderless" /> \ No newline at end of file + android:background="?android:selectableItemBackgroundBorderless" + android:forceHasOverlappingRendering="false" /> \ No newline at end of file diff --git a/packages/SystemUI/res/layout/pip_menu_activity.xml b/packages/SystemUI/res/layout/pip_menu_activity.xml index c6837fa30925f..44ced1736f658 100644 --- a/packages/SystemUI/res/layout/pip_menu_activity.xml +++ b/packages/SystemUI/res/layout/pip_menu_activity.xml @@ -23,7 +23,8 @@ + android:layout_height="match_parent" + android:forceHasOverlappingRendering="false"> mActions = new ArrayList<>(); private View mViewRoot; @@ -369,13 +369,18 @@ public class PipMenuActivity extends Activity { actionView.setImageDrawable(d); }, mHandler); actionView.setContentDescription(action.getContentDescription()); - actionView.setOnClickListener(v -> { - try { - action.getActionIntent().send(); - } catch (CanceledException e) { - Log.w(TAG, "Failed to send action", e); - } - }); + if (action.isEnabled()) { + actionView.setOnClickListener(v -> { + try { + action.getActionIntent().send(); + } catch (CanceledException e) { + Log.w(TAG, "Failed to send action", e); + } + }); + } else { + actionView.setAlpha(DISABLED_ACTION_ALPHA); + actionView.setEnabled(false); + } if (isLandscapePip && i > 0) { LinearLayout.LayoutParams lp = (LinearLayout.LayoutParams) actionView.getLayoutParams();