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

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

Issue 2396063002: Add Notification images (Android pre-N standard layout) (Closed)
Patch Set: Add test and move comment Created 4 years, 2 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
« no previous file with comments | « no previous file | chrome/android/junit/src/org/chromium/chrome/browser/notifications/NotificationPlatformBridgeUnitTest.java » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/android/java/src/org/chromium/chrome/browser/notifications/NotificationPlatformBridge.java
diff --git a/chrome/android/java/src/org/chromium/chrome/browser/notifications/NotificationPlatformBridge.java b/chrome/android/java/src/org/chromium/chrome/browser/notifications/NotificationPlatformBridge.java
index 0381041ed47919404f9b5b459e301c26898cef95..55e1de2fb8a0d5797e8da478da2fb256cc48a0f7 100644
--- a/chrome/android/java/src/org/chromium/chrome/browser/notifications/NotificationPlatformBridge.java
+++ b/chrome/android/java/src/org/chromium/chrome/browser/notifications/NotificationPlatformBridge.java
@@ -506,8 +506,10 @@ public class NotificationPlatformBridge {
makePendingIntent(NotificationConstants.ACTION_CLOSE_NOTIFICATION, notificationId,
origin, profileId, incognito, tag, webApkPackage, -1 /* actionIndex */);
+ boolean hasImage = image != null;
+
NotificationBuilderBase notificationBuilder =
- createNotificationBuilder()
+ createNotificationBuilder(hasImage)
.setTitle(title)
.setBody(body)
.setImage(image)
@@ -526,13 +528,15 @@ public class NotificationPlatformBridge {
PendingIntent intent = makePendingIntent(
NotificationConstants.ACTION_CLICK_NOTIFICATION, notificationId, origin,
profileId, incognito, tag, webApkPackage, actionIndex);
+ // Don't show action button icons when there's an image, as then action buttons go on
+ // the same row as the Site Settings button, so icons wouldn't leave room for text.
+ Bitmap actionIcon = hasImage ? null : actionIcons[actionIndex];
// TODO(crbug.com/650302): Encode actionTypes with an enum, not a magic string!
if (actionTypes[actionIndex].equals("text")) {
- notificationBuilder.addTextAction(actionIcons[actionIndex],
- actionTitles[actionIndex], intent, actionPlaceholders[actionIndex]);
+ notificationBuilder.addTextAction(actionIcon, actionTitles[actionIndex], intent,
+ actionPlaceholders[actionIndex]);
} else {
- notificationBuilder.addButtonAction(
- actionIcons[actionIndex], actionTitles[actionIndex], intent);
+ notificationBuilder.addButtonAction(actionIcon, actionTitles[actionIndex], intent);
}
}
@@ -540,7 +544,7 @@ public class NotificationPlatformBridge {
// label and icon, so abbreviate it. This has the unfortunate side-effect of unnecessarily
// abbreviating it on Android Wear also (crbug.com/576656). If custom layouts are enabled,
// the label and icon provided here only affect Android Wear, so don't abbreviate them.
- boolean abbreviateSiteSettings = actionTitles.length > 0 && !useCustomLayouts();
+ boolean abbreviateSiteSettings = actionTitles.length > 0 && !useCustomLayouts(hasImage);
int settingsIconId = abbreviateSiteSettings ? 0 : R.drawable.settings_cog;
CharSequence settingsTitle = abbreviateSiteSettings
? res.getString(R.string.notification_site_settings_button)
@@ -569,8 +573,8 @@ public class NotificationPlatformBridge {
}
}
- private NotificationBuilderBase createNotificationBuilder() {
- if (useCustomLayouts()) {
+ private NotificationBuilderBase createNotificationBuilder(boolean hasImage) {
+ if (useCustomLayouts(hasImage)) {
return new CustomNotificationBuilder(mAppContext);
}
return new StandardNotificationBuilder(mAppContext);
@@ -604,10 +608,16 @@ public class NotificationPlatformBridge {
*
* The --{enable,disable}-web-notification-custom-layouts command line flags take precedence.
*
+ * Normally a standard layout is used on Android N+, and a custom layout is used on older
+ * versions of Android. But if the notification has a content image, there isn't enough room for
+ * the Site Settings button to go on its own line when showing an image, nor is there enough
+ * room for action button icons, so a standard layout will be used here even on old versions.
+ *
+ * @param hasImage Whether the notification has a content image.
* @return Whether custom layouts should be used.
*/
@VisibleForTesting
- static boolean useCustomLayouts() {
+ static boolean useCustomLayouts(boolean hasImage) {
CommandLine commandLine = CommandLine.getInstance();
if (commandLine.hasSwitch(ChromeSwitches.ENABLE_WEB_NOTIFICATION_CUSTOM_LAYOUTS)) {
return true;
@@ -618,6 +628,9 @@ public class NotificationPlatformBridge {
if (Build.VERSION.CODENAME.equals("N") || Build.VERSION.SDK_INT > Build.VERSION_CODES.M) {
return false;
}
+ if (hasImage) {
+ return false;
+ }
return true;
}
« no previous file with comments | « no previous file | chrome/android/junit/src/org/chromium/chrome/browser/notifications/NotificationPlatformBridgeUnitTest.java » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698