Skip to content

Commit

Permalink
Closes #13 and v1.6.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Flavio De Stefano committed Oct 4, 2016
1 parent 7958425 commit ec5127a
Show file tree
Hide file tree
Showing 10 changed files with 90 additions and 74 deletions.
22 changes: 21 additions & 1 deletion android/LICENSE
@@ -1 +1,21 @@
TODO: place your license here and we'll include it in the module distribution
The MIT License (MIT)

Copyright (c) 2015 Caffeina

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
Binary file removed android/dist/map.jar
Binary file not shown.
Binary file not shown.
Binary file modified android/dist/ti.goosh.jar
Binary file not shown.
2 changes: 1 addition & 1 deletion android/manifest
Expand Up @@ -2,7 +2,7 @@
# this is your module manifest and used by Titanium
# during compilation, packaging, distribution, etc.
#
version: 1.5.0
version: 1.6.0
apiversion: 2
architectures: armeabi armeabi-v7a x86
description: ti.goosh
Expand Down
21 changes: 6 additions & 15 deletions android/src/ti/goosh/IntentService.java
Expand Up @@ -10,6 +10,7 @@
import java.util.concurrent.atomic.AtomicInteger;
import java.lang.reflect.Type;
import java.lang.Math;
import java.util.Random;

import android.app.Notification;
import android.app.NotificationManager;
Expand Down Expand Up @@ -77,7 +78,7 @@ private Bitmap getBitmapFromURL(String src) throws Exception {
}

private void parseNotification(Bundle bundle) {
Context context = TiApplication.getInstance().getApplicationContext();
Context context = getApplicationContext();
Boolean appInBackground = !TiApplication.isCurrentActivityInForeground();

Boolean showNotification = true;
Expand Down Expand Up @@ -110,21 +111,11 @@ private void parseNotification(Bundle bundle) {

if (showNotification) {

Intent notificationIntent = new Intent(this, PushHandlerActivity.class);
notificationIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
notificationIntent.putExtra(TiGooshModule.INTENT_EXTRA, jsonData);

// If the Application has a current activity, relaunch it
// otherwise, we need a LaunchIntent
Intent launcherIntent = null;
if (TiApplication.getAppRootOrCurrentActivity() == null) {
launcherIntent = context.getPackageManager().getLaunchIntentForPackage(context.getPackageName());
launcherIntent.setFlags(Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED | Intent.FLAG_ACTIVITY_SINGLE_TOP);
launcherIntent.addCategory(Intent.CATEGORY_LAUNCHER);
} else {
launcherIntent = TiApplication.getAppRootOrCurrentActivity().getIntent();
}

launcherIntent.putExtra("tigoosh.notification", jsonData);

PendingIntent contentIntent = PendingIntent.getActivity(this, 0, launcherIntent, PendingIntent.FLAG_ONE_SHOT);
PendingIntent contentIntent = PendingIntent.getActivity(this, new Random().nextInt(), notificationIntent, PendingIntent.FLAG_ONE_SHOT);

// Start building notification

Expand Down
42 changes: 42 additions & 0 deletions android/src/ti/goosh/PushHandlerActivity.java
@@ -0,0 +1,42 @@
package ti.goosh;

import android.app.Activity;
import android.app.NotificationManager;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.os.Bundle;
import android.util.Log;

import org.appcelerator.titanium.TiApplication;

public class PushHandlerActivity extends Activity {

private static String LCAT = "ti.goosh.TiGooshPushHandlerActivity";

@Override
public void onCreate(Bundle savedInstanceState) {
Log.d(LCAT, "started");
super.onCreate(savedInstanceState);

Context context = getApplicationContext();
String notification = getIntent().getStringExtra(TiGooshModule.INTENT_EXTRA);
TiGooshModule instance = TiGooshModule.getInstance();

Intent launcherIntent;

if (instance == null) {
launcherIntent = context.getPackageManager().getLaunchIntentForPackage(context.getPackageName());
launcherIntent.setFlags(Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
} else {
launcherIntent = TiApplication.getAppRootOrCurrentActivity().getIntent();
instance.sendMessage(notification, true);
}

launcherIntent.putExtra(TiGooshModule.INTENT_EXTRA, notification);
startActivity(launcherIntent);

finish();
}

}
38 changes: 0 additions & 38 deletions android/src/ti/goosh/TiGooshActivityLifecycleCallbacks.java

This file was deleted.

33 changes: 15 additions & 18 deletions android/src/ti/goosh/TiGooshModule.java
Expand Up @@ -46,6 +46,9 @@ public class TiGooshModule extends KrollModule {
private static final String LCAT = "ti.goosh.TiGooshModule";
private static final int PLAY_SERVICES_RESOLUTION_REQUEST = 9000;

public static final String INTENT_EXTRA = "tigoosh.notification";
public static final String TOKEN = "tigoosh.token";

private static TiGooshModule instance = null;

private KrollFunction successCallback = null;
Expand All @@ -63,22 +66,16 @@ public static TiGooshModule getInstance() {
return instance;
}

@Kroll.onAppCreate
public static void onAppCreate(TiApplication app) {
// Register the events to ensure the Intent parsing on resume
TiApplication.getInstance().registerActivityLifecycleCallbacks(new TiGooshActivityLifecycleCallbacks());
Log.d(LCAT, "onAppCreate " + app + " (" + (instance != null) + ")");
}

public void parseIncomingNotificationIntent() {
public void parseBootIntent() {
try {
Activity root = TiApplication.getAppRootOrCurrentActivity();
Intent intent = root.getIntent();
Intent intent = TiApplication.getAppRootOrCurrentActivity().getIntent();

if (intent.hasExtra("tigoosh.notification")) {
if (intent.hasExtra(INTENT_EXTRA)) {

TiGooshModule.getInstance().sendMessage(intent.getStringExtra("tigoosh.notification"), true);
intent.removeExtra("tigoosh.notification");
String notification = intent.getStringExtra(INTENT_EXTRA);

intent.removeExtra(INTENT_EXTRA);
instance.sendMessage(notification, true);

} else {
Log.d(LCAT, "No notification in Intent");
Expand Down Expand Up @@ -122,7 +119,7 @@ public void registerForPushNotifications(HashMap options) {
messageCallback = options.containsKey("callback") ? (KrollFunction)options.get("callback") : null;

registered = true;
parseIncomingNotificationIntent();
parseBootIntent();

if (checkPlayServices()) {
activity.startService( new Intent(activity, RegistrationIntentService.class) );
Expand Down Expand Up @@ -167,13 +164,13 @@ public void cancel(int id) {
@Kroll.method
@Kroll.getProperty
public Boolean isRemoteNotificationsEnabled() {
return getDefaultSharedPreferences().contains("tigoosh.token");
return getDefaultSharedPreferences().contains(TOKEN);
}

@Kroll.method
@Kroll.getProperty
public String getRemoteDeviceUUID() {
return getDefaultSharedPreferences().getString("tigoosh.token", "");
return getDefaultSharedPreferences().getString(TOKEN, "");
}

@Kroll.method
Expand All @@ -193,7 +190,7 @@ private SharedPreferences getDefaultSharedPreferences() {
}

private void saveToken(String token) {
getDefaultSharedPreferences().edit().putString("tigoosh.token", token).apply();
getDefaultSharedPreferences().edit().putString(TOKEN, token).apply();
}

// Public
Expand Down Expand Up @@ -230,7 +227,7 @@ public void sendMessage(String data, Boolean inBackground) {
}

try {

HashMap<String, Object> e = new HashMap<String, Object>();
e.put("data", data); // to parse on reverse on JS side
e.put("inBackground", inBackground);
Expand Down
6 changes: 5 additions & 1 deletion android/timodule.xml
Expand Up @@ -16,7 +16,6 @@
<uses-permission android:name="android.permission.GET_ACCOUNTS"/>
<uses-permission android:name="android.permission.USE_CREDENTIALS"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>

<!-- [END gcm_permission] -->

<application>
Expand Down Expand Up @@ -49,6 +48,11 @@
android:name="ti.goosh.RegistrationIntentService"
android:exported="false">
</service>

<activity
android:name="ti.goosh.PushHandlerActivity"
android:exported="true">
</activity>

</application>

Expand Down

0 comments on commit ec5127a

Please sign in to comment.