Upstream version 11.40.271.0
[platform/framework/web/crosswalk.git] / src / xwalk / runtime / android / core_internal / src / org / xwalk / core / internal / XWalkNotificationServiceImpl.java
index 657c10b..0cc2ab2 100644 (file)
@@ -32,7 +32,6 @@ public class XWalkNotificationServiceImpl implements XWalkNotificationService {
     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 {
@@ -94,32 +93,25 @@ public class XWalkNotificationServiceImpl implements XWalkNotificationService {
     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(
@@ -135,17 +127,13 @@ public class XWalkNotificationServiceImpl implements XWalkNotificationService {
             }
         }
 
-        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)) {
@@ -176,6 +164,8 @@ public class XWalkNotificationServiceImpl implements XWalkNotificationService {
             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);
@@ -183,13 +173,11 @@ public class XWalkNotificationServiceImpl implements XWalkNotificationService {
         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(
@@ -200,31 +188,31 @@ public class XWalkNotificationServiceImpl implements XWalkNotificationService {
         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;
@@ -235,12 +223,12 @@ public class XWalkNotificationServiceImpl implements XWalkNotificationService {
 
         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;
@@ -251,7 +239,7 @@ public class XWalkNotificationServiceImpl implements XWalkNotificationService {
 
         notificationChanged();
         if (mBridge != null) {
-            mBridge.notificationClosed(notificationId, byUser, delegate);
+            mBridge.notificationClosed(notificationId, byUser);
         }
     }