Skip to content

Commit

Permalink
Merge pull request #47 from gimdongwoo/master
Browse files Browse the repository at this point in the history
Support Parse Server, Add notification clear method, etc
  • Loading branch information
timanrebel committed Apr 28, 2016
2 parents 0bfa5f6 + 9cd4c91 commit 64378e8
Show file tree
Hide file tree
Showing 21 changed files with 125 additions and 25 deletions.
20 changes: 20 additions & 0 deletions .classpath
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="android/src"/>
<classpathentry kind="src" path="android/build/.apt_generated"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry kind="lib" path="/Users/InGrowth/Library/android-sdk-macosx/platforms/android-22/android.jar"/>
<classpathentry kind="lib" path="/Users/InGrowth/Library/android-sdk-macosx/add-ons/addon-google_apis-google-22/libs/maps.jar"/>
<classpathentry kind="lib" path="/Users/InGrowth/Library/Application Support/Titanium/mobilesdk/osx/4.1.0.GA/android/titanium.jar"/>
<classpathentry kind="lib" path="/Users/InGrowth/Library/Application Support/Titanium/mobilesdk/osx/4.1.0.GA/android/kroll-common.jar"/>
<classpathentry kind="lib" path="/Users/InGrowth/Library/Application Support/Titanium/mobilesdk/osx/4.1.0.GA/android/kroll-apt.jar"/>
<classpathentry kind="src" path=".apt_generated">
<attributes>
<attribute name="optional" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="lib" path="android/lib/bolts-tasks-1.4.0.jar"/>
<classpathentry kind="lib" path="android/lib/Parse-1.13.0.jar"/>
<classpathentry kind="lib" path="android/lib/ParseInterceptors-0.0.2.jar"/>
<classpathentry kind="output" path="bin"/>
</classpath>
3 changes: 1 addition & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
build/
build.log
.DS_Store
android/build.properties
parse.jar
cloudcode/config/local.json
cloudcode/config/local.json
29 changes: 29 additions & 0 deletions .project
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>Ti-Parse</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>com.appcelerator.titanium.core.builder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>com.aptana.ide.core.unifiedBuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
<nature>com.appcelerator.titanium.mobile.module.nature</nature>
<nature>com.aptana.projects.webnature</nature>
</natures>
</projectDescription>
17 changes: 15 additions & 2 deletions android/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ we need to put the application id and client key from Parse in your `tiapp.xml`
```xml
<property name="Parse_AppId" type="string">abcdefg</property>
<property name="Parse_ClientKey" type="string">hijklmnop</property>
<property name="Parse_ServerUrl" type="string">https://api.parse.com/1</property>
```

**Please note:** You should not add any other Parse tags to your `manifest` section in your `tiapp.xml` file, this module does this all for you. If you do, it will result in displaying Push Notifications multiple times.
Expand Down Expand Up @@ -50,6 +51,14 @@ To handle a click on a notification
});
```

To handle saved installation

```javascript
Parse.addEventListener('installationId', function(e) {
Ti.API.log("notification: ", JSON.stringify(e));
});
```

These events are only fired when the app is running. When the app is not running and a notification is clicked, the app is started and the notification data is added to the launching intent. It can be accessed with the following code:

```
Expand Down Expand Up @@ -131,10 +140,14 @@ If you want to change the background color of the notification circle, override
## Known Issues

* The current implementation only works in combination with [Facebook module](https://github.com/appcelerator-modules/ti.facebook) version 5.0.0 provided by [Appcelerator](https://github.com/appcelerator). That Facebook module also has a dependency onto the Boltz framework. Both modules should depend on the same version!
* Somehow the Parse module enables the use of [OkHttp](http://square.github.io/okhttp/) internally when running on Android 4.4 and up. This is a side effect that only has benefits. Titanium internally still uses the Apache HTTP client, but the OkHttp client is more up-to-date and faster. Android 6.0 completely removes the [Apache HTTP client](http://developer.android.com/about/versions/marshmallow/android-6.0-changes.html#behavior-apache-http-client) support.


## Changelog
**[v0.13.1](https://github.com/timanrebel/Parse/releases/tag/0.13.1)**
- Add silent push notification (when exist 'content-available' or omitted 'title'&'alert')
- Add notification clear method : notificationClear()
- Fire `installationId` event when new installation is saved.
- Support Parse server : Parse_ServerUrl

**[v0.12.0](https://github.com/timanrebel/Parse/releases/tag/0.12.0)**
- Resolve ti.facebook incompatibility [#19](https://github.com/timanrebel/Parse/issues/19)
- Resolve SSL / SNI problems by adding OkHttp [#35](https://github.com/timanrebel/Parse/issues/35)
Expand Down
3 changes: 3 additions & 0 deletions android/build.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
titanium.platform=/Users/InGrowth/Library/Application Support/Titanium/mobilesdk/osx/4.1.0.GA/android
android.platform=/Users/InGrowth/Library/android-sdk-macosx/platforms/android-22
google.apis=/Users/InGrowth/Library/android-sdk-macosx/add-ons/addon-google_apis-google-22
Binary file removed android/dist/eu.rebelcorp.parse-android-0.12.0.zip
Binary file not shown.
Binary file not shown.
Binary file removed android/lib/Parse-1.10.3.jar
Binary file not shown.
Binary file added android/lib/Parse-1.13.0.jar
Binary file not shown.
Binary file added android/lib/ParseInterceptors-0.0.2.jar
Binary file not shown.
Binary file removed android/lib/bolts-android-1.2.1.jar
Binary file not shown.
Binary file added android/lib/bolts-tasks-1.4.0.jar
Binary file not shown.
Binary file removed android/lib/okhttp-2.5.0.jar
Binary file not shown.
Binary file removed android/lib/okio-1.6.0.jar
Binary file not shown.
Binary file modified android/libs/armeabi-v7a/libeu.rebelcorp.parse.so
Binary file not shown.
Binary file modified android/libs/armeabi/libeu.rebelcorp.parse.so
Binary file not shown.
Binary file modified android/libs/x86/libeu.rebelcorp.parse.so
Binary file not shown.
4 changes: 2 additions & 2 deletions android/manifest
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# this is your module manifest and used by Titanium
# during compilation, packaging, distribution, etc.
#
version: 0.12.0
version: 0.13.1
apiversion: 2
description: Titanium module wrapping the Parse Android SDK.
author: Timan Rebel
Expand All @@ -16,4 +16,4 @@ moduleid: eu.rebelcorp.parse
guid: 39f0181f-c7e5-4665-a87f-4a06e4f41f9f
platform: android
architectures: armeabi armeabi-v7a x86
minsdk: 4.1.1.GA
minsdk: 4.1.0.GA
35 changes: 31 additions & 4 deletions android/src/eu/rebelcorp/parse/ParseModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,15 @@
*/
package eu.rebelcorp.parse;

import org.appcelerator.kroll.KrollDict;
import org.appcelerator.kroll.KrollModule;
import org.appcelerator.kroll.annotations.Kroll;

import org.appcelerator.titanium.TiApplication;
import org.appcelerator.kroll.common.Log;
import org.json.JSONException;
import org.json.JSONObject;

import android.app.NotificationManager;
import android.content.Context;
import android.app.Activity;
import android.provider.Settings.Secure;
Expand Down Expand Up @@ -41,6 +44,7 @@ public class ParseModule extends KrollModule
// tiapp.xml properties containing Parse's app id and client key
public static String PROPERTY_APP_ID = "Parse_AppId";
public static String PROPERTY_CLIENT_KEY = "Parse_ClientKey";
public static String PROPERTY_SERVER_URL = "Parse_ServerUrl";

public static final int STATE_RUNNING = 1;
public static final int STATE_STOPPED = 2;
Expand All @@ -63,9 +67,15 @@ public static void onAppCreate(TiApplication app)
{
String appId = TiApplication.getInstance().getAppProperties().getString(ParseModule.PROPERTY_APP_ID, "");
String clientKey = TiApplication.getInstance().getAppProperties().getString(ParseModule.PROPERTY_CLIENT_KEY, "");
String serverUrl = TiApplication.getInstance().getAppProperties().getString(ParseModule.PROPERTY_SERVER_URL, "");

Log.d(TAG, "Initializing with: " + appId + ", " + clientKey + ";");
Parse.initialize(TiApplication.getInstance(), appId, clientKey);
Log.d(TAG, "Initializing with: " + appId + ", " + clientKey + ", " + serverUrl);
Parse.initialize(new Parse.Configuration.Builder(TiApplication.getInstance())
.applicationId(appId)
.clientKey(clientKey)
.server(serverUrl + "/") // The trailing slash is important.
.build()
);
}

/* Get control over the module's state */
Expand Down Expand Up @@ -121,13 +131,23 @@ public void start()
{
setState(STATE_RUNNING);
// Track Push opens
ParseAnalytics.trackAppOpened(TiApplication.getAppRootOrCurrentActivity().getIntent());
ParseAnalytics.trackAppOpenedInBackground(TiApplication.getAppRootOrCurrentActivity().getIntent());
ParseInstallation.getCurrentInstallation().put("androidId", getAndroidId());
ParseInstallation.getCurrentInstallation().saveInBackground(new SaveCallback() {
public void done(ParseException e) {
if (e != null) {
Log.e(TAG, "Installation initialization failed: " + e.getMessage());
}
// fire event
try {
JSONObject pnData = new JSONObject();
pnData.put("objectId", getObjectId());
pnData.put("installationId", getCurrentInstallationId());
KrollDict data = new KrollDict(pnData);
module.fireEvent("installationId", data);
} catch (JSONException e1) {
Log.e(TAG, "InstallationId event failed: " + e1.getMessage());
}
}
});
}
Expand Down Expand Up @@ -175,6 +195,13 @@ public String getCurrentInstallationId() {
public String getObjectId() {
return ParseInstallation.getCurrentInstallation().getObjectId();
}

@Kroll.method
public void notificationClear() {
TiApplication context = TiApplication.getInstance();
NotificationManager notifiyMgr = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
notifiyMgr.cancelAll();
}

protected String getAndroidId() {
Context context = TiApplication.getInstance().getApplicationContext();
Expand Down
33 changes: 21 additions & 12 deletions android/src/eu/rebelcorp/parse/ParseModuleBroadcastReceiver.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import org.json.JSONObject;

import android.os.Bundle;

import org.appcelerator.kroll.KrollDict;
import org.appcelerator.titanium.TiApplication;
import org.appcelerator.titanium.util.TiRHelper;
Expand All @@ -20,14 +21,15 @@
import android.content.Context;
import android.content.Intent;
import android.util.Log;

import eu.rebelcorp.parse.ParseModule;
import com.parse.ParsePushBroadcastReceiver;

import com.parse.ParseAnalytics;
import android.R;
import android.os.Build;
import android.app.Notification;

import com.parse.ParsePushBroadcastReceiver;
import com.parse.ParseAnalytics;

public class ParseModuleBroadcastReceiver extends ParsePushBroadcastReceiver {

@Override
Expand Down Expand Up @@ -64,33 +66,40 @@ public void onPushOpen(Context context, Intent intent) {
@Override
public void onPushReceive(Context context, Intent intent) {
try {
if (intent == null) {
if (intent == null) {
Log.d("onPushReceive", "Receiver intent null");
super.onPushReceive(context, intent);
return;
}

JSONObject pnData = new JSONObject(intent.getExtras().getString("com.parse.Data"));
KrollDict data = new KrollDict(pnData);

if (ParseModule.getInstance() == null) {
Log.d("onPushReceive", "No instance of ParseModule found");
super.onPushReceive(context, intent);
// silent push
if (pnData.has("content-available") == false) {
super.onPushReceive(context, intent);
}
return;
}

/* The notification is received by the device */

if (ParseModule.getInstance().getState() != ParseModule.STATE_DESTROYED) {
Log.d("onPushReceive", "App is in foreground; trigger event 'notificationreceive'");

try {
KrollDict data = new KrollDict(new JSONObject(intent.getExtras().getString("com.parse.Data")));
ParseModule.getInstance().fireEvent("notificationreceive", data);
try {
ParseModule.getInstance().fireEvent("notificationreceive", data);
} catch (Exception e) {
Log.d("onPushReceive", e.getMessage());
}
} else {
Log.d("onPushReceive", "App is not alive; 'notificationreceive' won't be triggered");
}

super.onPushReceive(context, intent);

// silent push
if (pnData.has("content-available") == false) {
super.onPushReceive(context, intent);
}
} catch (Exception e) {
Log.e("Push", "Exception: " + e.toString());
}
Expand Down
6 changes: 3 additions & 3 deletions android/timodule.xml
Original file line number Diff line number Diff line change
Expand Up @@ -29,23 +29,23 @@
<intent-filter>
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
<action android:name="com.google.android.c2dm.intent.REGISTRATION" />

<!--
IMPORTANT: Change "com.parse.starter" to match your app's package name.
-->
<category android:name="${tiapp.properties['id']}" />
</intent-filter>
</receiver>
</application>

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />

<permission android:name="${tiapp.properties['id']}.permission.C2D_MESSAGE" android:protectionLevel="signature" />
<uses-permission android:name="${tiapp.properties['id']}.permission.C2D_MESSAGE" />
</manifest>
Expand Down

0 comments on commit 64378e8

Please sign in to comment.