private static final String XWALK_ACTION_CLICK_NOTIFICATION_SUFFIX = ".notification.click";
private static final String XWALK_ACTION_CLOSE_NOTIFICATION_SUFFIX = ".notification.close";
private static final String XWALK_INTENT_EXTRA_KEY_NOTIFICATION_ID = "xwalk.NOTIFICATION_ID";
- private static final String XWALK_INTENT_EXTRA_KEY_DELEGATE = "xwalk.DELEGATE";
private static final String XWALK_INTENT_CATEGORY_NOTIFICATION_PREFIX = "notification_";
private class WebNotification {
public boolean maybeHandleIntent(Intent intent) {
if (intent.getAction() == null) return false;
int notificationId = intent.getIntExtra(XWALK_INTENT_EXTRA_KEY_NOTIFICATION_ID, -1);
- long delegate = intent.getLongExtra(XWALK_INTENT_EXTRA_KEY_DELEGATE, -1);
if (notificationId <= 0) return false;
if (intent.getAction().equals(
mView.getActivity().getPackageName() + XWALK_ACTION_CLOSE_NOTIFICATION_SUFFIX)) {
- onNotificationClose(notificationId, true, delegate);
+ onNotificationClose(notificationId, true);
return true;
} else if (intent.getAction().equals(
mView.getActivity().getPackageName() + XWALK_ACTION_CLICK_NOTIFICATION_SUFFIX)) {
- onNotificationClick(notificationId, delegate);
+ onNotificationClick(notificationId);
return true;
}
return false;
}
- @Override
- @SuppressWarnings("deprecation")
- public void updateNotificationIcon(int notificationId, Bitmap icon) {
- WebNotification webNotification = mExistNotificationIds.get(notificationId);
- if (webNotification == null) {
- return;
- }
-
+ public Bitmap getNotificationIcon(Bitmap icon) {
+ if (icon == null) return null;
int originalWidth = icon.getWidth();
int originalHeight = icon.getHeight();
if (originalWidth == 0 || originalHeight == 0) {
- return;
+ return icon;
}
int targetWidth = mContext.getResources().getDimensionPixelSize(
}
}
- Notification.Builder builder = webNotification.mBuilder;
- builder.setLargeIcon(Bitmap.createScaledBitmap(icon, targetWidth, targetHeight, true));
-
- doShowNotification(notificationId,
- VERSION.SDK_INT >= VERSION_CODES.JELLY_BEAN ? builder.build() : builder.getNotification());
+ return Bitmap.createScaledBitmap(icon, targetWidth, targetHeight, true);
}
@Override
@SuppressWarnings("deprecation")
public void showNotification(String title, String message, String replaceId,
- int notificationId, long delegate) {
+ Bitmap icon, int notificationId) {
Notification.Builder builder;
if (!replaceId.isEmpty() && mExistReplaceIds.containsKey(replaceId)) {
iconRes = android.R.drawable.sym_def_app_icon;
}
builder.setSmallIcon(iconRes);
+ Bitmap bigIcon = getNotificationIcon(icon);
+ if (bigIcon != null) builder.setLargeIcon(bigIcon);
Context activity = mView.getActivity();
String category = getCategoryFromNotificationId(notificationId);
Intent clickIntent = new Intent(activity, activity.getClass())
.setAction(activity.getPackageName() + XWALK_ACTION_CLICK_NOTIFICATION_SUFFIX)
.putExtra(XWALK_INTENT_EXTRA_KEY_NOTIFICATION_ID, notificationId)
- .putExtra(XWALK_INTENT_EXTRA_KEY_DELEGATE, delegate)
.setFlags(Intent.FLAG_ACTIVITY_LAUNCHED_FROM_HISTORY | Intent.FLAG_ACTIVITY_SINGLE_TOP)
.addCategory(category);
Intent closeIntent = new Intent(activity.getPackageName() + XWALK_ACTION_CLOSE_NOTIFICATION_SUFFIX)
.putExtra(XWALK_INTENT_EXTRA_KEY_NOTIFICATION_ID, notificationId)
- .putExtra(XWALK_INTENT_EXTRA_KEY_DELEGATE, delegate)
.addCategory(category);
builder.setContentIntent(PendingIntent.getActivity(
doShowNotification(notificationId,
VERSION.SDK_INT >= VERSION_CODES.JELLY_BEAN ? builder.build() : builder.getNotification());
notificationChanged();
- onNotificationShown(notificationId, delegate);
+ onNotificationShown(notificationId);
}
@Override
- public void cancelNotification(int notificationId, long delegate) {
+ public void cancelNotification(int notificationId) {
mNotificationManager.cancel(notificationId);
- onNotificationClose(notificationId, false, delegate);
+ onNotificationClose(notificationId, false);
}
public void doShowNotification(int notificationId, Notification notification) {
mNotificationManager.notify(notificationId, notification);
}
- public void onNotificationShown(int notificationId, long delegate) {
+ public void onNotificationShown(int notificationId) {
WebNotification webNotification = mExistNotificationIds.get(notificationId);
if (webNotification == null) {
return;
}
if (mBridge != null) {
- mBridge.notificationDisplayed(delegate);
+ mBridge.notificationDisplayed(notificationId);
}
}
- public void onNotificationClick(int notificationId, long delegate) {
+ public void onNotificationClick(int notificationId) {
WebNotification webNotification = mExistNotificationIds.get(notificationId);
if (webNotification == null) {
return;
notificationChanged();
if (mBridge != null) {
- mBridge.notificationClicked(notificationId, delegate);
+ mBridge.notificationClicked(notificationId);
}
}
public void onNotificationClose(
- int notificationId, boolean byUser, long delegate) {
+ int notificationId, boolean byUser) {
WebNotification webNotification = mExistNotificationIds.get(notificationId);
if (webNotification == null) {
return;
notificationChanged();
if (mBridge != null) {
- mBridge.notificationClosed(notificationId, byUser, delegate);
+ mBridge.notificationClosed(notificationId, byUser);
}
}