Skip to content

Commit

Permalink
Merge pull request crosswalk-project#1960 from darktears/android-noti…
Browse files Browse the repository at this point in the history
…fications

[Next][Android] Notifications refactor due to upstream changes.
  • Loading branch information
darktears committed May 20, 2014
2 parents 827572d + ffa2a6b commit deffd9a
Show file tree
Hide file tree
Showing 8 changed files with 136 additions and 150 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -552,16 +552,16 @@ private void updateNotificationIcon(int notificationId, Bitmap icon) {

@CalledByNative
private void showNotification(String title, String message, String replaceId,
int notificationId, int processId, int routeId) {
int notificationId, long delegate) {
// FIXME(wang16): use replaceId to replace exist notification. It happens when
// a notification with same name and tag fires.
mNotificationService.showNotification(
title, message, notificationId, processId, routeId);
title, message, notificationId, delegate);
}

@CalledByNative
private void cancelNotification(int notificationId, int processId, int routeId) {
mNotificationService.cancelNotification(notificationId, processId, routeId);
private void cancelNotification(int notificationId, long delegate) {
mNotificationService.cancelNotification(notificationId, delegate);
}

void confirmJsResult(int id, String prompt) {
Expand All @@ -579,24 +579,24 @@ void exitFullscreen(long nativeWebContents) {
nativeExitFullscreen(mNativeContentsClientBridge, nativeWebContents);
}

public void notificationDisplayed(int id, int processId, int routeId) {
public void notificationDisplayed(long delegate) {
if (mNativeContentsClientBridge == 0) return;
nativeNotificationDisplayed(mNativeContentsClientBridge, id, processId, routeId);
nativeNotificationDisplayed(mNativeContentsClientBridge, delegate);
}

public void notificationError(int id, String error, int processId, int routeId) {
public void notificationError(long delegate) {
if (mNativeContentsClientBridge == 0) return;
nativeNotificationError(mNativeContentsClientBridge, id, error, processId, routeId);
nativeNotificationError(mNativeContentsClientBridge, delegate);
}

public void notificationClicked(int id, int processId, int routeId) {
public void notificationClicked(int id, long delegate) {
if (mNativeContentsClientBridge == 0) return;
nativeNotificationClicked(mNativeContentsClientBridge, id, processId, routeId);
nativeNotificationClicked(mNativeContentsClientBridge, id, delegate);
}

public void notificationClosed(int id, boolean byUser, int processId, int routeId) {
public void notificationClosed(int id, boolean byUser, long delegate) {
if (mNativeContentsClientBridge == 0) return;
nativeNotificationClosed(mNativeContentsClientBridge, id, byUser, processId, routeId);
nativeNotificationClosed(mNativeContentsClientBridge, id, byUser, delegate);
}

void setDownloadListener(DownloadListener listener) {
Expand Down Expand Up @@ -627,14 +627,10 @@ private native void nativeConfirmJsResult(long nativeXWalkContentsClientBridge,
String prompt);
private native void nativeCancelJsResult(long nativeXWalkContentsClientBridge, int id);
private native void nativeExitFullscreen(long nativeXWalkContentsClientBridge, long nativeWebContents);
private native void nativeNotificationDisplayed(long nativeXWalkContentsClientBridge, int id,
int processId, int routeId);
private native void nativeNotificationError(long nativeXWalkContentsClientBridge, int id,
String error, int processId, int routeId);
private native void nativeNotificationClicked(long nativeXWalkContentsClientBridge, int id,
int processId, int routeId);
private native void nativeNotificationClosed(long nativeXWalkContentsClientBridge, int id,
boolean byUser, int processId, int routeId);
private native void nativeNotificationDisplayed(long nativeXWalkContentsClientBridge, long delegate);
private native void nativeNotificationError(long nativeXWalkContentsClientBridge, long delegate);
private native void nativeNotificationClicked(long nativeXWalkContentsClientBridge, int id, long delegate);
private native void nativeNotificationClosed(long nativeXWalkContentsClientBridge, int id, boolean byUser, long delegate);
private native void nativeOnFilesSelected(long nativeXWalkContentsClientBridge,
int processId, int renderId, int mode_flags, String filepath, String displayName);
private native void nativeOnFilesNotSelected(long nativeXWalkContentsClientBridge,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@
interface XWalkNotificationService {
public void setBridge(XWalkContentsClientBridge bridge);
public void showNotification(
String title, String message, int notificationId, int processId, int routeId);
String title, String message, int notificationId, long delegate);
public void updateNotificationIcon(int notificationId, Bitmap icon);
public void cancelNotification(int notificationId, int processId, int routeId);
public void cancelNotification(int notificationId, long delegate);
public void shutdown();
public boolean maybeHandleIntent(Intent intent);
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,7 @@ 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_PROCESS_ID = "xwalk.PROCESS_ID";
private static final String XWALK_INTENT_EXTRA_KEY_ROUTE_ID = "xwalk.ROUTE_ID";
private static final String XWALK_INTENT_EXTRA_KEY_DELEGATE = "xwalk.DELEGATE";
private static final String XWALK_INTENT_CATEGORY_NOTIFICATION_PREFIX = "notification_";

private Context mContext;
Expand Down Expand Up @@ -112,16 +111,15 @@ public void shutdown() {
public boolean maybeHandleIntent(Intent intent) {
if (intent.getAction() == null) return false;
int notificationId = intent.getIntExtra(XWALK_INTENT_EXTRA_KEY_NOTIFICATION_ID, -1);
int processId = intent.getIntExtra(XWALK_INTENT_EXTRA_KEY_PROCESS_ID, -1);
int routeId = intent.getIntExtra(XWALK_INTENT_EXTRA_KEY_ROUTE_ID, -1);
if (notificationId < 0) return false;
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, processId, routeId);
onNotificationClose(notificationId, true, delegate);
return true;
} else if (intent.getAction().equals(
mView.getActivity().getPackageName() + XWALK_ACTION_CLICK_NOTIFICATION_SUFFIX)) {
onNotificationClick(notificationId, processId, routeId);
onNotificationClick(notificationId, delegate);
return true;
}
return false;
Expand Down Expand Up @@ -163,14 +161,13 @@ public void updateNotificationIcon(int notificationId, Bitmap icon) {
@Override
@SuppressWarnings("deprecation")
public void showNotification(String title, String message,
int notificationId, int processId, int routeId) {
int notificationId, long delegate) {
Context activity = mView.getActivity();
String category = getCategoryFromNotificationId(notificationId);
Intent clickIntent = new Intent(activity, activity.getClass());
clickIntent.setAction(activity.getPackageName() + XWALK_ACTION_CLICK_NOTIFICATION_SUFFIX);
clickIntent.putExtra(XWALK_INTENT_EXTRA_KEY_NOTIFICATION_ID, notificationId);
clickIntent.putExtra(XWALK_INTENT_EXTRA_KEY_PROCESS_ID, processId);
clickIntent.putExtra(XWALK_INTENT_EXTRA_KEY_ROUTE_ID, routeId);
clickIntent.putExtra(XWALK_INTENT_EXTRA_KEY_DELEGATE, delegate);
clickIntent.setFlags(
Intent.FLAG_ACTIVITY_LAUNCHED_FROM_HISTORY | Intent.FLAG_ACTIVITY_SINGLE_TOP);
clickIntent.addCategory(category);
Expand All @@ -179,8 +176,7 @@ public void showNotification(String title, String message,
Intent closeIntent =
new Intent(activity.getPackageName() + XWALK_ACTION_CLOSE_NOTIFICATION_SUFFIX);
closeIntent.putExtra(XWALK_INTENT_EXTRA_KEY_NOTIFICATION_ID, notificationId);
closeIntent.putExtra(XWALK_INTENT_EXTRA_KEY_PROCESS_ID, processId);
closeIntent.putExtra(XWALK_INTENT_EXTRA_KEY_ROUTE_ID, routeId);
closeIntent.putExtra(XWALK_INTENT_EXTRA_KEY_DELEGATE, delegate);
closeIntent.addCategory(category);
PendingIntent pendingCloseIntent = PendingIntent.getBroadcast(activity,
0, closeIntent, PendingIntent.FLAG_UPDATE_CURRENT);
Expand All @@ -202,42 +198,42 @@ public void showNotification(String title, String message,
doShowNotification(notificationId, notification);
mExistNotificationIds.put(notificationId, builder);
notificationChanged();
onNotificationShown(notificationId, processId, routeId);
onNotificationShown(notificationId, delegate);
}

@Override
public void cancelNotification(int notificationId, int processId, int routeId) {
public void cancelNotification(int notificationId, long delegate) {
mNotificationManager.cancel(notificationId);
onNotificationClose(notificationId, false, processId, routeId);
onNotificationClose(notificationId, false, delegate);
}

public void doShowNotification(int id, Notification notification) {
mNotificationManager.notify(id, notification);
}

public void onNotificationShown(int notificationId, int processId, int routeId) {
public void onNotificationShown(int notificationId, long delegate) {
if (mExistNotificationIds.containsKey(notificationId) && mBridge != null) {
mBridge.notificationDisplayed(notificationId, processId, routeId);
mBridge.notificationDisplayed(delegate);
}
}

public void onNotificationClick(int notificationId, int processId, int routeId) {
public void onNotificationClick(int notificationId, long delegate) {
if (mExistNotificationIds.containsKey(notificationId)) {
mExistNotificationIds.remove(notificationId);
notificationChanged();
if (mBridge != null) {
mBridge.notificationClicked(notificationId, processId, routeId);
mBridge.notificationClicked(notificationId, delegate);
}
}
}

public void onNotificationClose(
int notificationId, boolean byUser, int processId, int routeId) {
int notificationId, boolean byUser, long delegate) {
if (mExistNotificationIds.containsKey(notificationId)) {
mExistNotificationIds.remove(notificationId);
notificationChanged();
if (mBridge != null) {
mBridge.notificationClosed(notificationId, byUser, processId, routeId);
mBridge.notificationClosed(notificationId, byUser, delegate);
}
}
}
Expand Down
Loading

0 comments on commit deffd9a

Please sign in to comment.