Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(12)

Unified Diff: chrome/android/java/src/org/chromium/chrome/browser/notifications/NotificationBuilderBase.java

Issue 1864053002: Implement Android UI of web notification inline replies Base URL: https://chromium.googlesource.com/chromium/src.git@inline_replies_ps1
Patch Set: Fix filename? Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/android/java/src/org/chromium/chrome/browser/notifications/NotificationBuilderBase.java
diff --git a/chrome/android/java/src/org/chromium/chrome/browser/notifications/NotificationBuilderBase.java b/chrome/android/java/src/org/chromium/chrome/browser/notifications/NotificationBuilderBase.java
index ffb3136b989940c66705fdf6111be7510e2e6963..61b9359ccd393382084587813f5bece875c39de2 100644
--- a/chrome/android/java/src/org/chromium/chrome/browser/notifications/NotificationBuilderBase.java
+++ b/chrome/android/java/src/org/chromium/chrome/browser/notifications/NotificationBuilderBase.java
@@ -7,6 +7,7 @@ package org.chromium.chrome.browser.notifications;
import android.annotation.TargetApi;
import android.app.Notification;
import android.app.PendingIntent;
+import android.app.RemoteInput;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Color;
@@ -29,10 +30,12 @@ import javax.annotation.Nullable;
*/
public abstract class NotificationBuilderBase {
protected static class Action {
+ public int type;
public int iconId;
public Bitmap iconBitmap;
public CharSequence title;
public PendingIntent intent;
+ public String placeholder;
Action(int iconId, CharSequence title, PendingIntent intent) {
this.iconId = iconId;
@@ -40,10 +43,13 @@ public abstract class NotificationBuilderBase {
this.intent = intent;
}
- Action(Bitmap iconBitmap, CharSequence title, PendingIntent intent) {
+ Action(int type, Bitmap iconBitmap, CharSequence title, PendingIntent intent,
+ String placeholder) {
+ this.type = type;
this.iconBitmap = iconBitmap;
this.title = title;
this.intent = intent;
+ this.placeholder = placeholder;
}
}
@@ -61,6 +67,8 @@ public abstract class NotificationBuilderBase {
*/
private static final int MAX_AUTHOR_PROVIDED_ACTION_BUTTONS = 2;
+ private static final String REMOTE_INPUT_KEY = "remote-input-key";
+
protected CharSequence mTitle;
protected CharSequence mBody;
protected CharSequence mOrigin;
@@ -76,6 +84,7 @@ public abstract class NotificationBuilderBase {
protected long[] mVibratePattern;
protected long mTimestamp;
protected boolean mRenotify;
+ protected String mDefaultPlaceholder;
/**
* Combines all of the options that have been set and returns a new Notification object.
@@ -166,8 +175,9 @@ public abstract class NotificationBuilderBase {
* Adds an action to the notification. Actions are typically displayed as a button adjacent to
* the notification content.
*/
- public NotificationBuilderBase addAction(@Nullable Bitmap iconBitmap,
- @Nullable CharSequence title, @Nullable PendingIntent intent) {
+ public NotificationBuilderBase addAction(int type, @Nullable Bitmap iconBitmap,
+ @Nullable CharSequence title, @Nullable String placeholder,
+ @Nullable PendingIntent intent) {
if (mActions.size() == MAX_AUTHOR_PROVIDED_ACTION_BUTTONS) {
throw new IllegalStateException(
"Cannot add more than " + MAX_AUTHOR_PROVIDED_ACTION_BUTTONS + " actions.");
@@ -175,7 +185,7 @@ public abstract class NotificationBuilderBase {
if (iconBitmap != null) {
applyWhiteOverlayToBitmap(iconBitmap);
}
- mActions.add(new Action(iconBitmap, limitLength(title), intent));
+ mActions.add(new Action(type, iconBitmap, limitLength(title), intent, placeholder));
return this;
}
@@ -227,6 +237,15 @@ public abstract class NotificationBuilderBase {
return this;
}
+ /**
+ * Sets the placeholder to show for text actions if the developer does not specify one.
+ */
+ public NotificationBuilderBase setDefaultActionPlaceholder(
+ @Nullable String defaultPlaceholder) {
+ this.mDefaultPlaceholder = defaultPlaceholder;
+ return this;
+ }
+
@Nullable
private static CharSequence limitLength(@Nullable CharSequence input) {
if (input == null) {
@@ -258,11 +277,26 @@ public abstract class NotificationBuilderBase {
*/
@SuppressWarnings("deprecation") // For addAction(int, CharSequence, PendingIntent)
@TargetApi(Build.VERSION_CODES.M) // For the Icon class.
- protected static void addActionToBuilder(Notification.Builder builder, Action action) {
- if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && action.iconBitmap != null) {
- Icon icon = Icon.createWithBitmap(action.iconBitmap);
- builder.addAction(
- new Notification.Action.Builder(icon, action.title, action.intent).build());
+ protected static void addActionToBuilder(
+ Notification.Builder builder, Action action, @Nullable String defaultPlaceholder) {
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
Michael van Ouwerkerk 2016/04/07 14:19:20 As discussed offline, I understand this should be
+ Notification.Action.Builder actionBuilder;
+ if (action.iconBitmap != null) {
+ Icon icon = Icon.createWithBitmap(action.iconBitmap);
+ actionBuilder = new Notification.Action.Builder(icon, action.title, action.intent);
+ } else {
+ actionBuilder =
+ new Notification.Action.Builder(action.iconId, action.title, action.intent);
+ }
+ if (action.type == ButtonInfoType.TEXT) {
+ RemoteInput remoteInput =
+ new RemoteInput.Builder(REMOTE_INPUT_KEY)
+ .setLabel(action.placeholder == null ? defaultPlaceholder
+ : action.placeholder)
+ .build();
+ actionBuilder.addRemoteInput(remoteInput);
+ }
+ builder.addAction(actionBuilder.build());
} else {
builder.addAction(action.iconId, action.title, action.intent);
}

Powered by Google App Engine
This is Rietveld 408576698