Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 package org.chromium.chrome.browser.notifications; | |
| 6 | |
| 7 import android.os.RemoteException; | |
| 8 | |
| 9 import org.chromium.base.Callback; | |
| 10 import org.chromium.base.Log; | |
| 11 import org.chromium.webapk.lib.client.WebApkServiceConnectionManager; | |
| 12 import org.chromium.webapk.lib.runtime_library.IWebApkApi; | |
| 13 | |
| 14 /** | |
| 15 * WebApkNotificationClient provides API to open/close notifications from WebAPK . | |
|
Peter Beverloo
2016/05/19 15:59:00
Comment suggestion:
* This class provides an API
pkotwicz
2016/05/20 00:45:19
Yes, we can modify this class as we please
| |
| 16 */ | |
| 17 public class WebApkNotificationClient { | |
| 18 private static final String TAG = "cr_WebApk"; | |
| 19 | |
| 20 // Callback which catches RemoteExceptions thrown due to IWebApkApi failure. | |
|
Peter Beverloo
2016/05/19 15:59:00
This seems like a very generic concept, is this th
pkotwicz
2016/05/20 00:45:19
I think of ApiUseCallback as a convenience class.
| |
| 21 private abstract static class ApiUseCallback implements Callback<IWebApkApi> { | |
| 22 public abstract void useApi(IWebApkApi api) throws RemoteException; | |
| 23 | |
| 24 @Override | |
| 25 public void onResult(IWebApkApi api) { | |
| 26 try { | |
| 27 useApi(api); | |
| 28 } catch (RemoteException e) { | |
| 29 Log.w(TAG, "WebApkAPI use failed.", e); | |
| 30 } | |
| 31 } | |
| 32 } | |
| 33 | |
| 34 /** | |
| 35 * Connect to a WebAPK's bound service, build a notification and hand it ove r to the WebAPK to | |
| 36 * display. Handing over the notification makes the notification look like i t originated from | |
| 37 * the WebAPK - not Chrome - in the Android UI. | |
| 38 * @param webApkPackage Package of the WebAPK to bind to. | |
| 39 * @param notificationBuilder | |
| 40 * @param platformTag | |
| 41 * @param platformID | |
|
Peter Beverloo
2016/05/19 15:59:00
nit: I think our style guide says that parameters
pkotwicz
2016/05/20 00:45:19
Removed the @params
| |
| 42 */ | |
| 43 public static void displayNotification(String webApkPackage, | |
| 44 final NotificationBuilderBase notificationBuilder, final String plat formTag, | |
| 45 final int platformID) { | |
| 46 final ApiUseCallback connectionCallback = new ApiUseCallback() { | |
| 47 @Override | |
| 48 public void useApi(IWebApkApi api) throws RemoteException { | |
| 49 notificationBuilder.setSmallIcon(api.getSmallIconId()); | |
|
Peter Beverloo
2016/05/19 15:59:00
Is a WebAPK guaranteed to have a small icon Id spe
pkotwicz
2016/05/20 00:45:19
I am unsure what we will do in the long term. Righ
Peter Beverloo
2016/05/20 14:12:15
These badges are Bitmaps, which indeed require M+.
| |
| 50 api.displayNotification(platformTag, platformID, notificationBui lder.build()); | |
| 51 } | |
| 52 }; | |
| 53 | |
| 54 WebApkServiceConnectionManager.getInstance().connect(webApkPackage, conn ectionCallback); | |
| 55 } | |
| 56 | |
| 57 /** | |
| 58 * Closes notification previously shown by WebAPK. | |
| 59 * @param webApkPackage Package of the WebAPK which displayed the notificati on. | |
| 60 * @param platformTag | |
| 61 * @param platformID | |
| 62 */ | |
| 63 public static void closeNotification( | |
| 64 String webApkPackage, final String platformTag, final int platformID ) { | |
| 65 final ApiUseCallback connectionCallback = new ApiUseCallback() { | |
| 66 @Override | |
| 67 public void useApi(IWebApkApi api) throws RemoteException { | |
| 68 api.closeNotification(platformTag, platformID); | |
| 69 } | |
| 70 }; | |
| 71 WebApkServiceConnectionManager.getInstance().connect(webApkPackage, conn ectionCallback); | |
| 72 } | |
| 73 } | |
| OLD | NEW |