Skip to content
This repository has been archived by the owner on Sep 4, 2020. It is now read-only.

Commit

Permalink
Merge branch 'GreyDekart-master'
Browse files Browse the repository at this point in the history
  • Loading branch information
macdonst committed Sep 11, 2015
2 parents ff236ff + 9f95a63 commit 1690257
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 52 deletions.
46 changes: 27 additions & 19 deletions src/android/com/adobe/phonegap/push/GCMIntentService.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import com.google.android.gcm.GCMBaseIntentService;

import java.util.ArrayList;
import java.util.HashMap;

@SuppressLint("NewApi")
public class GCMIntentService extends GCMBaseIntentService {
Expand All @@ -41,11 +42,17 @@ public class GCMIntentService extends GCMBaseIntentService {
private static final String STYLE_INBOX = "inbox";
private static final String STYLE_PICTURE = "picture";
private static final String STYLE_TEXT = "text";
private static ArrayList<String> messageList = new ArrayList();
private static HashMap<Integer, ArrayList<String>> messageMap = new HashMap<Integer, ArrayList<String>>();

public void setNotification(String message){

if(message == ""){
public void setNotification(int notId, String message){
ArrayList<String> messageList = messageMap.get(notId);
if(messageList == null) {
messageList = new ArrayList<String>();
messageMap.put(notId, messageList);
}

if(message.isEmpty()){
messageList.clear();
}else{
messageList.add(message);
Expand Down Expand Up @@ -109,20 +116,22 @@ public void createNotification(Context context, Bundle extras) {
String packageName = context.getPackageName();
Resources resources = context.getResources();

int notId = parseInt("notId", extras);
Intent notificationIntent = new Intent(this, PushHandlerActivity.class);
notificationIntent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_CLEAR_TOP);
notificationIntent.putExtra("pushBundle", extras);
notificationIntent.putExtra("notId", notId);

int requestCode = new Random().nextInt();
PendingIntent contentIntent = PendingIntent.getActivity(this, requestCode, notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT);

NotificationCompat.Builder mBuilder =
new NotificationCompat.Builder(context)
.setWhen(System.currentTimeMillis())
.setContentTitle(getString(extras, "title"))
.setTicker(getString(extras, "title"))
.setContentIntent(contentIntent)
.setAutoCancel(true);
new NotificationCompat.Builder(context)
.setWhen(System.currentTimeMillis())
.setContentTitle(getString(extras, "title"))
.setTicker(getString(extras, "title"))
.setContentIntent(contentIntent)
.setAutoCancel(true);

SharedPreferences prefs = context.getSharedPreferences(PushPlugin.COM_ADOBE_PHONEGAP_PUSH, Context.MODE_PRIVATE);
String localIcon = prefs.getString("icon", null);
Expand Down Expand Up @@ -197,7 +206,7 @@ public void createNotification(Context context, Bundle extras) {
/*
* Notification message
*/
setNotificationMessage(extras, mBuilder);
setNotificationMessage(notId, extras, mBuilder);

/*
* Notification count
Expand All @@ -209,8 +218,6 @@ public void createNotification(Context context, Bundle extras) {
*/
createActions(extras, mBuilder, resources, packageName);

int notId = parseInt("notId", extras);

mNotificationManager.notify((String) appName, notId, mBuilder.build());
}

Expand Down Expand Up @@ -266,15 +273,16 @@ private void setNotificationVibration(Bundle extras, Boolean vibrateOption, Noti
}
}

private void setNotificationMessage(Bundle extras, NotificationCompat.Builder mBuilder) {
private void setNotificationMessage(int notId, Bundle extras, NotificationCompat.Builder mBuilder) {
String message = getMessageText(extras);

String style = getString(extras, "style", STYLE_TEXT);
if(STYLE_INBOX.equals(style)) {
setNotification(message);
setNotification(notId, message);

mBuilder.setContentText(message);

ArrayList<String> messageList = messageMap.get(notId);
Integer sizeList = messageList.size();
if (sizeList > 1) {
String sizeListMessage = sizeList.toString();
Expand All @@ -294,7 +302,7 @@ private void setNotificationMessage(Bundle extras, NotificationCompat.Builder mB
mBuilder.setStyle(notificationInbox);
}
} else if (STYLE_PICTURE.equals(style)) {
setNotification("");
setNotification(notId, "");

NotificationCompat.BigPictureStyle bigPicture = new NotificationCompat.BigPictureStyle();
bigPicture.bigPicture(getBitmapFromURL(getString(extras, "picture")));
Expand All @@ -306,7 +314,7 @@ private void setNotificationMessage(Bundle extras, NotificationCompat.Builder mB

mBuilder.setStyle(bigPicture);
} else {
setNotification("");
setNotification(notId, "");

NotificationCompat.BigTextStyle bigText = new NotificationCompat.BigTextStyle();

Expand All @@ -327,7 +335,7 @@ private void setNotificationMessage(Bundle extras, NotificationCompat.Builder mB
}
}
}

private String getString(Bundle extras,String key) {
String message = extras.getString(key);
if (message == null) {
Expand All @@ -337,7 +345,7 @@ private String getString(Bundle extras,String key) {
}

private String getString(Bundle extras,String key, String defaultString) {
String message = extras.getString(key, defaultString);
String message = extras.getString(key);
if (message == null) {
message = extras.getString("gcm.notification."+key, defaultString);
}
Expand All @@ -359,7 +367,7 @@ private void setNotificationSound(Context context, Bundle extras, NotificationCo
}
if (soundname != null) {
Uri sound = Uri.parse(ContentResolver.SCHEME_ANDROID_RESOURCE
+ "://" + context.getPackageName() + "/raw/" + soundname);
+ "://" + context.getPackageName() + "/raw/" + soundname);
Log.d(LOG_TAG, sound.toString());
mBuilder.setSound(sound);
} else {
Expand Down
66 changes: 33 additions & 33 deletions src/android/com/adobe/phonegap/push/PushHandlerActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,20 @@

public class PushHandlerActivity extends Activity
{
private static String LOG_TAG = "PushPlugin_PushHandlerActivity";
private static String LOG_TAG = "PushPlugin_PushHandlerActivity";

/*
* this activity will be started if the user touches a notification that we own.
* We send it's data off to the push plugin for processing.
* If needed, we boot up the main activity to kickstart the application.
* @see android.app.Activity#onCreate(android.os.Bundle)
*/
@Override
public void onCreate(Bundle savedInstanceState) {
GCMIntentService gcm = new GCMIntentService();
gcm.setNotification("");
super.onCreate(savedInstanceState);
Log.v(LOG_TAG, "onCreate");
/*
* this activity will be started if the user touches a notification that we own.
* We send it's data off to the push plugin for processing.
* If needed, we boot up the main activity to kickstart the application.
* @see android.app.Activity#onCreate(android.os.Bundle)
*/
@Override
public void onCreate(Bundle savedInstanceState) {
GCMIntentService gcm = new GCMIntentService();
gcm.setNotification(getIntent().getIntExtra("notId", 0), "");
super.onCreate(savedInstanceState);
Log.v(LOG_TAG, "onCreate");

boolean isPushPluginActive = PushPlugin.isActive();
processPushBundle(isPushPluginActive);
Expand All @@ -33,34 +33,34 @@ public void onCreate(Bundle savedInstanceState) {
if (!isPushPluginActive) {
forceMainActivityReload();
}
}
}

/**
* Takes the pushBundle extras from the intent,
* and sends it through to the PushPlugin for processing.
*/
private void processPushBundle(boolean isPushPluginActive) {
Bundle extras = getIntent().getExtras();
/**
* Takes the pushBundle extras from the intent,
* and sends it through to the PushPlugin for processing.
*/
private void processPushBundle(boolean isPushPluginActive) {
Bundle extras = getIntent().getExtras();

if (extras != null) {
Bundle originalExtras = extras.getBundle("pushBundle");
if (extras != null) {
Bundle originalExtras = extras.getBundle("pushBundle");

originalExtras.putBoolean("foreground", false);
originalExtras.putBoolean("coldstart", !isPushPluginActive);
originalExtras.putString("callback", getIntent().getExtras().getString("callback"));

PushPlugin.sendExtras(originalExtras);
}
}
PushPlugin.sendExtras(originalExtras);
}
}

/**
* Forces the main activity to re-launch if it's unloaded.
*/
private void forceMainActivityReload() {
PackageManager pm = getPackageManager();
Intent launchIntent = pm.getLaunchIntentForPackage(getApplicationContext().getPackageName());
startActivity(launchIntent);
}
/**
* Forces the main activity to re-launch if it's unloaded.
*/
private void forceMainActivityReload() {
PackageManager pm = getPackageManager();
Intent launchIntent = pm.getLaunchIntentForPackage(getApplicationContext().getPackageName());
startActivity(launchIntent);
}

@Override
protected void onResume() {
Expand Down

0 comments on commit 1690257

Please sign in to comment.