Action button improvements:
- Horizontal layout
- At most 2 are shown
- Tombstones are now shown (if the intent is null, the
button is disabled; use it for quick feedback of an
action's effect)
Bug: 6418617 (tombstones)
Bug: 6482237 (action separators)
Change-Id: Ie0c613006227bbfe1c0ec6eab1cda4f3782a05f2
diff --git a/core/java/android/app/Notification.java b/core/java/android/app/Notification.java
index 0c47069..6d3aa98 100644
--- a/core/java/android/app/Notification.java
+++ b/core/java/android/app/Notification.java
@@ -907,6 +907,8 @@
* </pre>
*/
public static class Builder {
+ private static final int MAX_ACTION_BUTTONS = 2;
+
private Context mContext;
private long mWhen;
@@ -938,7 +940,7 @@
private ArrayList<String> mKindList = new ArrayList<String>(1);
private Bundle mExtras;
private int mPriority;
- private ArrayList<Action> mActions = new ArrayList<Action>(3);
+ private ArrayList<Action> mActions = new ArrayList<Action>(MAX_ACTION_BUTTONS);
private boolean mUseChronometer;
private Style mStyle;
@@ -1460,7 +1462,7 @@
if (N > 0) {
// Log.d("Notification", "has actions: " + mContentText);
big.setViewVisibility(R.id.actions, View.VISIBLE);
- if (N>3) N=3;
+ if (N>MAX_ACTION_BUTTONS) N=MAX_ACTION_BUTTONS;
big.removeAllViews(R.id.actions);
for (int i=0; i<N; i++) {
final RemoteViews button = generateActionButton(mActions.get(i));
@@ -1500,18 +1502,14 @@
}
private RemoteViews generateActionButton(Action action) {
- RemoteViews button = new RemoteViews(mContext.getPackageName(), R.layout.notification_action);
+ final boolean tombstone = (action.actionIntent == null);
+ RemoteViews button = new RemoteViews(mContext.getPackageName(),
+ tombstone ? R.layout.notification_action_tombstone
+ : R.layout.notification_action);
button.setTextViewCompoundDrawables(R.id.action0, action.icon, 0, 0, 0);
button.setTextViewText(R.id.action0, action.title);
- if (action.actionIntent != null) {
+ if (!tombstone) {
button.setOnClickPendingIntent(R.id.action0, action.actionIntent);
- //button.setBoolean(R.id.action0, "setEnabled", true);
- button.setFloat(R.id.button0, "setAlpha", 1.0f);
- button.setBoolean(R.id.button0, "setClickable", true);
- } else {
- //button.setBoolean(R.id.action0, "setEnabled", false);
- button.setFloat(R.id.button0, "setAlpha", 0.5f);
- button.setBoolean(R.id.button0, "setClickable", false);
}
button.setContentDescription(R.id.action0, action.title);
return button;