diff --git a/.gitignore b/.gitignore index b555fa9..5ee0542 100644 --- a/.gitignore +++ b/.gitignore @@ -133,7 +133,6 @@ inspector/ios-inspector/.DS_Store #FORGE module/manifest.json module/.DS_Store -module/android module/docs/* module/identity.json module/inspector_config.json @@ -146,9 +145,9 @@ module/tests* .DS_Store .trigger +.hash .lib -inspector/ios-inspector/.hash inspector/ios-inspector/.DS_Store inspector/ios-inspector/ForgeCore.bundle inspector/ios-inspector/ForgeCore.framework @@ -157,8 +156,6 @@ inspector/ios-inspector/build inspector/ios-inspector/ForgeInspector.xcodeproj/project.pbxproj inspector/ios-inspector/ForgeInspector.xcodeproj/project.xcworkspace/xcshareddata/ForgeInspector.xccheckout inspector/ios-inspector.* -inspector/*an -inspector/an-inspector.* inspector/ios-inspector/ForgeModule/ForgeModule-Prefix.pch inspector/ios-inspector/ForgeModule/ForgeModule.xcodeproj/project.pbxproj inspector/ios-inspector/ForgeModule/ForgeModule.xcodeproj/xcshareddata/xcschemes/ForgeModule.xcscheme @@ -168,3 +165,16 @@ ForgeInspector.xcodeproj/project.xcworkspace/xcuserdata/horak.xcuserdatad/UserIn inspector/ios-inspector/ForgeInspector.xcodeproj/project.xcworkspace/* inspector/ios-inspector/ForgeInspector.xcodeproj/xcuserdata/* + +inspector/an-inspector.* +inspector/an-inspector/ForgeInspector +inspector/an-inspector/ForgeModule/.settings +inspector/an-inspector/ForgeModule/libs +inspector/an-inspector/ForgeModule/res +inspector/an-inspector/ForgeModule/gen +inspector/an-inspector/ForgeModule/bin +inspector/an-inspector/ForgeModule/trigger-gen +inspector/an-inspector/ForgeModule/.classpath +inspector/an-inspector/ForgeModule/.project +inspector/an-inspector/ForgeModule/AndroidManifest.xml +inspector/an-inspector/ForgeModule/project.properties diff --git a/inspector/an-inspector/ForgeModule/src/io/trigger/forge/android/modules/push/API.java b/inspector/an-inspector/ForgeModule/src/io/trigger/forge/android/modules/push/API.java new file mode 100644 index 0000000..fc45136 --- /dev/null +++ b/inspector/an-inspector/ForgeModule/src/io/trigger/forge/android/modules/push/API.java @@ -0,0 +1,31 @@ +package io.trigger.forge.android.modules.push; + +import java.io.IOException; + +import com.google.android.gms.gcm.GoogleCloudMessaging; +import com.google.gson.JsonPrimitive; + +import io.trigger.forge.android.core.ForgeApp; +import io.trigger.forge.android.core.ForgeTask; + +public class API { + + private static boolean isRegistered = false; + + public static void registerWithAPNS(final ForgeTask task){ + final GoogleCloudMessaging gcm = GoogleCloudMessaging.getInstance(ForgeApp.getApp()); + try { + String senderID = ForgeApp.configForPlugin("push").get("gcm-sender-id").getAsString(); + //TODO: the register method is deprecated + String regid = gcm.register(senderID); + isRegistered = true; + task.success(regid); + ForgeApp.event("onDidRegisterWithAPNS", new JsonPrimitive(regid)); + } catch (IOException e) { + task.error(e.getMessage()); + } + } + public static void checkIfRegisteredWithAPNS(final ForgeTask task){ + task.success(isRegistered); + } +} diff --git a/inspector/an-inspector/ForgeModule/src/io/trigger/forge/android/modules/push/EventListener.java b/inspector/an-inspector/ForgeModule/src/io/trigger/forge/android/modules/push/EventListener.java new file mode 100644 index 0000000..2751d10 --- /dev/null +++ b/inspector/an-inspector/ForgeModule/src/io/trigger/forge/android/modules/push/EventListener.java @@ -0,0 +1,12 @@ +package io.trigger.forge.android.modules.push; + +import io.trigger.forge.android.core.ForgeApp; +import io.trigger.forge.android.core.ForgeEventListener; + +public class EventListener extends ForgeEventListener { + + @Override + public void onRestart() { + ForgeApp.event("push.resume", null); + } +} diff --git a/inspector/an-inspector/ForgeModule/src/io/trigger/forge/android/modules/push/GCMReceiver.java b/inspector/an-inspector/ForgeModule/src/io/trigger/forge/android/modules/push/GCMReceiver.java new file mode 100644 index 0000000..3e9fb71 --- /dev/null +++ b/inspector/an-inspector/ForgeModule/src/io/trigger/forge/android/modules/push/GCMReceiver.java @@ -0,0 +1,18 @@ +package io.trigger.forge.android.modules.push; + +import android.app.Activity; +import android.content.BroadcastReceiver; +import android.content.ComponentName; +import android.content.Context; +import android.content.Intent; + +public class GCMReceiver extends BroadcastReceiver { + + @Override + public void onReceive(Context context, Intent intent) { + ComponentName comp = new ComponentName(context.getPackageName(), GCMService.class.getName()); + context.startService(intent.setComponent(comp)); + setResultCode(Activity.RESULT_OK); + } + +} diff --git a/inspector/an-inspector/ForgeModule/src/io/trigger/forge/android/modules/push/GCMService.java b/inspector/an-inspector/ForgeModule/src/io/trigger/forge/android/modules/push/GCMService.java new file mode 100644 index 0000000..086d6f8 --- /dev/null +++ b/inspector/an-inspector/ForgeModule/src/io/trigger/forge/android/modules/push/GCMService.java @@ -0,0 +1,55 @@ +package io.trigger.forge.android.modules.push; + +import io.trigger.forge.android.core.ForgeApp; + +import android.util.Log; + +import com.google.gson.Gson; +import com.google.gson.JsonPrimitive; +import com.google.gson.JsonSyntaxException; +import com.kinvey.android.push.KinveyGCMService; + +public class GCMService extends KinveyGCMService { + + private static final Gson gson = new Gson(); + + @Override + public Class getReceiver() { + return GCMReceiver.class; + } + + @Override + public void onDelete(String arg0) { + Log.i(TAG, arg0); + } + + @Override + public void onError(String arg0) { + Log.e(TAG, arg0); + } + + @Override + public void onMessage(String message) { + PushMessage notification; + try { + notification = gson.fromJson(message, PushMessage.class); + } catch (JsonSyntaxException e) { + notification = new PushMessage(message); + } + notification.show(); + ForgeApp.event("push.message", new JsonPrimitive(message)); + } + + @Override + public void onRegistered(String arg0) { + Log.i(TAG, arg0); + + } + + @Override + public void onUnregistered(String arg0) { + Log.i(TAG, arg0); + + } + +} diff --git a/inspector/an-inspector/ForgeModule/src/io/trigger/forge/android/modules/push/PushMessage.java b/inspector/an-inspector/ForgeModule/src/io/trigger/forge/android/modules/push/PushMessage.java new file mode 100644 index 0000000..b55a387 --- /dev/null +++ b/inspector/an-inspector/ForgeModule/src/io/trigger/forge/android/modules/push/PushMessage.java @@ -0,0 +1,60 @@ +package io.trigger.forge.android.modules.push; + +import io.trigger.forge.android.core.ForgeApp; +import android.app.Notification; +import android.app.NotificationManager; +import android.app.PendingIntent; +import android.content.Context; +import android.content.Intent; +import android.support.v4.app.NotificationCompat; + +public class PushMessage { + + private String message; + private String from; + private String subject; + + + public PushMessage(String message) { + this(message, "Fetchnotes", ""); + } + public PushMessage(String message, String from, String subject) { + this.message = message; + this.from = from; + this.subject = subject; + } + + public String getMessage() { + return message; + } + public void setMessage(String message) { + this.message = message; + } + public String getFrom() { + return from; + } + public void setFrom(String from) { + this.from = from; + } + public String getSubject() { + return subject; + } + public void setSubject(String subject) { + this.subject = subject; + } + public void show() { + Context context = ForgeApp.getApp(); + Intent intent = new Intent(context, ForgeApp.getActivity().getClass()); + PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent, 0); + NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context) + .setSmallIcon(ForgeApp.getResourceId("icons", "drawable")) + .setDefaults(Notification.DEFAULT_VIBRATE) + .setContentIntent(pendingIntent) + .setAutoCancel(true) + .setContentTitle(from) + .setContentText(message); + NotificationManager mNotificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); + mNotificationManager.notify(1, mBuilder.getNotification()); + } + +} diff --git a/module/android/build_steps.json b/module/android/build_steps.json new file mode 100644 index 0000000..77589b5 --- /dev/null +++ b/module/android/build_steps.json @@ -0,0 +1,157 @@ +[ + { + "do": { + "android_add_permission": { + "permission": "android.permission.INTERNET" + } + } + }, + { + "do": { + "android_add_permission": { + "permission": "android.permission.ACCESS_NETWORK_STATE" + } + } + }, + { + "do": { + "android_add_permission": { + "permission": "android.permission.VIBRATE" + } + } + }, + { + "do": { + "android_add_permission": { + "permission": "android.permission.WAKE_LOCK" + } + } + }, + { + "do": { + "android_add_permission": { + "permission": "com.google.android.c2dm.permission.RECEIVE" + } + } + }, + { + "do": { + "android_add_permission": { + "permission": "android.permission.BROADCAST_STICKY" + } + } + }, + { + "do": { + "android_add_to_application_manifest": { + "element": { + "tag": "permission", + "attributes": { + "android:name": "io.trigger.forge.android.modules.push.permission.C2D_MESSAGE", + "android:protectionLevel": "signature" + } + } + } + } + }, + { + "do": { + "android_add_permission": { + "permission": "io.trigger.forge.android.modules.push.permission.C2D_MESSAGE" + } + } + }, + { + "do": { + "android_add_to_application_manifest": { + "element": { + "tag": "receiver", + "attributes": { + "android:name": "io.trigger.forge.android.modules.push.GCMReceiver", + "android:permission": "com.google.android.c2dm.permission.SEND" + }, + "children": [{ + "tag": "intent-filter", + "children": [{ + "tag": "action", + "attributes": { + "android:name": "com.google.android.c2dm.intent.RECEIVE" + } + }, { + "tag": "action", + "attributes": { + "android:name": "com.google.android.c2dm.intent.REGISTRATION" + } + }, { + "tag": "category", + "attributes": { + "android:name": "io.trigger.forge.android.modules.push" + } + }] + }] + } + } + } + }, + { + "do": { + "android_add_to_application_manifest": { + "element": { + "tag": "service", + "attributes": { + "android:name": "io.trigger.forge.android.modules.push.GCMService", + "android:label": "Push Notification Service" + } + } + } + } + }, + { + "do": { + "android_add_to_application_manifest": { + "element": { + "tag": "meta-data", + "attributes": { + "android:name": "com.google.android.gms.version", + "android:value": "@integer/google_play_services_version" + } + } + } + } + }, + { + "do": { + "android_add_proguard_rule": { + "rule": "-keep class * extends java.util.ListResourceBundle { protected Object[][] getContents(); }" + } + } + }, + { + "do": { + "android_add_proguard_rule": { + "rule": "-keep public class com.google.android.gms.common.internal.safeparcel.SafeParcelable { public static final *** NULL; }" + } + } + }, + { + "do": { + "android_add_proguard_rule": { + "rule": "-keepnames @com.google.android.gms.common.annotation.KeepName class *" + } + } + }, + { + "do": { + "android_add_proguard_rule": { + "rule": "-keepclassmembernames class * { @com.google.android.gms.common.annotation.KeepName *; }" + } + } + }, + { + "do": { + "android_add_proguard_rule": { + "rule": "-keepnames class * implements android.os.Parcelable { public static final ** CREATOR; }" + } + } + } +] diff --git a/module/android/libs/gcm.jar b/module/android/libs/gcm.jar new file mode 100644 index 0000000..d6a3fa9 Binary files /dev/null and b/module/android/libs/gcm.jar differ diff --git a/module/android/libs/google-http-client-1.19.0.jar b/module/android/libs/google-http-client-1.19.0.jar new file mode 100644 index 0000000..3204499 Binary files /dev/null and b/module/android/libs/google-http-client-1.19.0.jar differ diff --git a/module/android/libs/google-http-client-android-1.19.0.jar b/module/android/libs/google-http-client-android-1.19.0.jar new file mode 100644 index 0000000..409ec5b Binary files /dev/null and b/module/android/libs/google-http-client-android-1.19.0.jar differ diff --git a/module/android/libs/google-http-client-gson-1.19.0.jar b/module/android/libs/google-http-client-gson-1.19.0.jar new file mode 100644 index 0000000..78575bc Binary files /dev/null and b/module/android/libs/google-http-client-gson-1.19.0.jar differ diff --git a/module/android/libs/google-http-client-jackson2-1.19.0.jar b/module/android/libs/google-http-client-jackson2-1.19.0.jar new file mode 100644 index 0000000..f60d097 Binary files /dev/null and b/module/android/libs/google-http-client-jackson2-1.19.0.jar differ diff --git a/module/android/libs/kinvey-android-lib-2.9.5.jar b/module/android/libs/kinvey-android-lib-2.9.5.jar new file mode 100644 index 0000000..5a886f2 Binary files /dev/null and b/module/android/libs/kinvey-android-lib-2.9.5.jar differ diff --git a/module/android/libs/kinvey-java-2.9.5.jar b/module/android/libs/kinvey-java-2.9.5.jar new file mode 100644 index 0000000..4ec5f99 Binary files /dev/null and b/module/android/libs/kinvey-java-2.9.5.jar differ diff --git a/module/android/res/drawable-hdpi-v11/icons.png b/module/android/res/drawable-hdpi-v11/icons.png new file mode 100644 index 0000000..56afede Binary files /dev/null and b/module/android/res/drawable-hdpi-v11/icons.png differ diff --git a/module/android/res/drawable-hdpi-v9/icons.png b/module/android/res/drawable-hdpi-v9/icons.png new file mode 100644 index 0000000..7cfb266 Binary files /dev/null and b/module/android/res/drawable-hdpi-v9/icons.png differ diff --git a/module/android/res/drawable-hdpi/icons.png b/module/android/res/drawable-hdpi/icons.png new file mode 100644 index 0000000..ee5f0b4 Binary files /dev/null and b/module/android/res/drawable-hdpi/icons.png differ diff --git a/module/android/res/drawable-mdpi-v11/icons.png b/module/android/res/drawable-mdpi-v11/icons.png new file mode 100644 index 0000000..ef7a98c Binary files /dev/null and b/module/android/res/drawable-mdpi-v11/icons.png differ diff --git a/module/android/res/drawable-mdpi-v9/icons.png b/module/android/res/drawable-mdpi-v9/icons.png new file mode 100644 index 0000000..f389fdc Binary files /dev/null and b/module/android/res/drawable-mdpi-v9/icons.png differ diff --git a/module/android/res/drawable-mdpi/icons.png b/module/android/res/drawable-mdpi/icons.png new file mode 100644 index 0000000..c0e8264 Binary files /dev/null and b/module/android/res/drawable-mdpi/icons.png differ diff --git a/module/android/res/drawable-xhdpi-v11/icons.png b/module/android/res/drawable-xhdpi-v11/icons.png new file mode 100644 index 0000000..79685aa Binary files /dev/null and b/module/android/res/drawable-xhdpi-v11/icons.png differ diff --git a/module/android/res/drawable-xhdpi-v9/icons.png b/module/android/res/drawable-xhdpi-v9/icons.png new file mode 100644 index 0000000..490367d Binary files /dev/null and b/module/android/res/drawable-xhdpi-v9/icons.png differ diff --git a/module/android/res/drawable-xhdpi/icons.png b/module/android/res/drawable-xhdpi/icons.png new file mode 100644 index 0000000..7c395f4 Binary files /dev/null and b/module/android/res/drawable-xhdpi/icons.png differ diff --git a/module/android/res/drawable-xxhdpi-v11/icons.png b/module/android/res/drawable-xxhdpi-v11/icons.png new file mode 100644 index 0000000..290ea97 Binary files /dev/null and b/module/android/res/drawable-xxhdpi-v11/icons.png differ diff --git a/module/android/res/drawable-xxhdpi-v9/icons.png b/module/android/res/drawable-xxhdpi-v9/icons.png new file mode 100644 index 0000000..33748e9 Binary files /dev/null and b/module/android/res/drawable-xxhdpi-v9/icons.png differ diff --git a/module/android/res/drawable-xxhdpi/icons.png b/module/android/res/drawable-xxhdpi/icons.png new file mode 100644 index 0000000..b201164 Binary files /dev/null and b/module/android/res/drawable-xxhdpi/icons.png differ diff --git a/module/android/res/values/version.xml b/module/android/res/values/version.xml new file mode 100644 index 0000000..d8a0e1f --- /dev/null +++ b/module/android/res/values/version.xml @@ -0,0 +1,4 @@ + + + 7571000 + \ No newline at end of file diff --git a/module/config_schema.json b/module/config_schema.json new file mode 100644 index 0000000..d623831 --- /dev/null +++ b/module/config_schema.json @@ -0,0 +1,12 @@ +{ + "type": "object", + "additionalProperties": false, + "properties": { + "gcm-sender-id": { + "type": "string", + "required": true, + "description": "Sender ID for Google Cloud Messaging (GCM)", + "pattern": "^\\d{12}$" + } + } +} diff --git a/module/inspector_config.json b/module/inspector_config.json deleted file mode 100644 index 969feaf..0000000 --- a/module/inspector_config.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "this_module": { - "config": {} - }, - "modules": {} -} \ No newline at end of file diff --git a/module/manifest.json b/module/manifest.json index 41ac3a5..cd48650 100644 --- a/module/manifest.json +++ b/module/manifest.json @@ -1,8 +1,8 @@ { - "description": "ios 8 compatibility", - "min_platform_version": "v2.2.2", - "namespace": "push", - "platform_version": "v2.2.2", - "changes": "iOS 8 compatibility", - "version": "0.9" -} + "description": "Enable push notifications", + "min_platform_version": "v2.2.2", + "namespace": "push", + "platform_version": "v2.2.2", + "changes": "Remove iOS, add partial Android support", + "version": "1.0.9" +} \ No newline at end of file