Merge "Adding enabled state for remote actions."

This commit is contained in:
TreeHugger Robot
2017-03-17 17:51:40 +00:00
committed by Android (Google) Code Review
7 changed files with 47 additions and 13 deletions

View File

@@ -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<android.app.RemoteAction> CREATOR;
}

View File

@@ -5920,6 +5920,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<android.app.RemoteAction> CREATOR;
}

View File

@@ -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<android.app.RemoteAction> CREATOR;
}

View File

@@ -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());

View File

@@ -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" />
android:background="?android:selectableItemBackgroundBorderless"
android:forceHasOverlappingRendering="false" />

View File

@@ -23,7 +23,8 @@
<FrameLayout
android:id="@+id/menu_container"
android:layout_width="match_parent"
android:layout_height="match_parent">
android:layout_height="match_parent"
android:forceHasOverlappingRendering="false">
<ImageView
android:id="@+id/dismiss"

View File

@@ -19,8 +19,8 @@ package com.android.systemui.pip.phone;
import static com.android.systemui.pip.phone.PipMenuActivityController.EXTRA_ACTIONS;
import static com.android.systemui.pip.phone.PipMenuActivityController.EXTRA_CONTROLLER_MESSENGER;
import static com.android.systemui.pip.phone.PipMenuActivityController.EXTRA_MOVEMENT_BOUNDS;
import static com.android.systemui.pip.phone.PipMenuActivityController.EXTRA_STACK_BOUNDS;
import static com.android.systemui.pip.phone.PipMenuActivityController.EXTRA_SHOW_MENU;
import static com.android.systemui.pip.phone.PipMenuActivityController.EXTRA_STACK_BOUNDS;
import android.animation.Animator;
import android.animation.AnimatorListenerAdapter;
@@ -33,13 +33,11 @@ import android.app.PendingIntent.CanceledException;
import android.app.RemoteAction;
import android.content.Intent;
import android.content.pm.ParceledListSlice;
import android.content.res.Resources;
import android.graphics.Color;
import android.graphics.PointF;
import android.graphics.Rect;
import android.graphics.drawable.ColorDrawable;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.Icon;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
@@ -84,6 +82,8 @@ public class PipMenuActivity extends Activity {
private static final float MENU_BACKGROUND_ALPHA = 0.3f;
private static final float DISMISS_BACKGROUND_ALPHA = 0.8f;
private static final float DISABLED_ACTION_ALPHA = 0.54f;
private boolean mMenuVisible;
private final List<RemoteAction> mActions = new ArrayList<>();
private View mViewRoot;
@@ -371,13 +371,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();