diff options
Diffstat (limited to 'StoneIsland/platforms/android')
20 files changed, 1124 insertions, 788 deletions
diff --git a/StoneIsland/platforms/android/AndroidManifest.xml b/StoneIsland/platforms/android/AndroidManifest.xml index 25ce62dd..dbd8afc1 100755 --- a/StoneIsland/platforms/android/AndroidManifest.xml +++ b/StoneIsland/platforms/android/AndroidManifest.xml @@ -1,7 +1,6 @@ <?xml version='1.0' encoding='utf-8'?> <manifest android:hardwareAccelerated="true" android:versionCode="6000" android:versionName="0.8.4" package="us.okfoc.stoneisland" xmlns:android="http://schemas.android.com/apk/res/android"> <supports-screens android:anyDensity="true" android:largeScreens="true" android:normalScreens="true" android:resizeable="true" android:smallScreens="true" android:xlargeScreens="true" /> - <uses-permission android:name="android.permission.INTERNET" /> <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" /> <application android:hardwareAccelerated="true" android:icon="@drawable/icon" android:label="@string/app_name" android:supportsRtl="true"> <activity android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale" android:label="@string/activity_name" android:launchMode="singleTop" android:name="MainActivity" android:screenOrientation="portrait" android:theme="@android:style/Theme.Black.NoTitleBar" android:windowSoftInputMode="adjustResize"> @@ -41,18 +40,18 @@ </intent-filter> </service> <service android:exported="false" android:name="com.adobe.phonegap.push.RegistrationIntentService" /> - <receiver android:enabled="true" android:name="com.google.android.gms.analytics.AnalyticsReceiver"> + <service android:enabled="true" android:exported="false" android:name="com.google.android.gms.measurement.AppMeasurementService" /> + <service android:name="org.apache.cordova.firebase.FirebasePluginMessagingService"> <intent-filter> - <action android:name="com.google.android.gms.analytics.ANALYTICS_DISPATCH" /> + <action android:name="com.google.firebase.MESSAGING_EVENT" /> </intent-filter> - </receiver> - <service android:enabled="true" android:exported="false" android:name="com.google.android.gms.analytics.AnalyticsService" /> - <receiver android:enabled="true" android:exported="true" android:name="com.google.android.gms.analytics.CampaignTrackingReceiver"> + </service> + <service android:name="org.apache.cordova.firebase.FirebasePluginInstanceIDService"> <intent-filter> - <action android:name="com.android.vending.INSTALL_REFERRER" /> + <action android:name="com.google.firebase.INSTANCE_ID_EVENT" /> </intent-filter> - </receiver> - <service android:enabled="true" android:exported="false" android:name="com.google.android.gms.analytics.CampaignTrackingService" /> + </service> + <receiver android:name="org.apache.cordova.firebase.OnNotificationOpenReceiver" /> </application> <uses-sdk android:minSdkVersion="21" android:targetSdkVersion="22" /> <uses-permission android:name="android.permission.WAKE_LOCK" /> @@ -67,4 +66,5 @@ <uses-permission android:name="${applicationId}.permission.PushHandlerActivity" /> <permission android:name="${applicationId}.permission.C2D_MESSAGE" android:protectionLevel="signature" /> <permission android:name="${applicationId}.permission.PushHandlerActivity" android:protectionLevel="signature" /> + <uses-permission android:name="android.permission.INTERNET" /> </manifest> diff --git a/StoneIsland/platforms/android/android.json b/StoneIsland/platforms/android/android.json index df55a288..c87b55d4 100755 --- a/StoneIsland/platforms/android/android.json +++ b/StoneIsland/platforms/android/android.json @@ -53,11 +53,11 @@ "count": 1 }, { - "xml": "<feature name=\"UniversalAnalytics\"><param name=\"android-package\" value=\"com.danielcwilson.plugins.analytics.UniversalAnalyticsPlugin\" /></feature>", + "xml": "<feature name=\"StatusBar\"><param name=\"android-package\" value=\"org.apache.cordova.statusbar.StatusBar\" /><param name=\"onload\" value=\"true\" /></feature>", "count": 1 }, { - "xml": "<feature name=\"StatusBar\"><param name=\"android-package\" value=\"org.apache.cordova.statusbar.StatusBar\" /><param name=\"onload\" value=\"true\" /></feature>", + "xml": "<feature name=\"FirebasePlugin\"><param name=\"android-package\" value=\"org.apache.cordova.firebase.FirebasePlugin\" /><param name=\"onload\" value=\"true\" /></feature>", "count": 1 } ] @@ -91,19 +91,19 @@ "count": 1 }, { - "xml": "<receiver android:enabled=\"true\" android:name=\"com.google.android.gms.analytics.AnalyticsReceiver\"><intent-filter><action android:name=\"com.google.android.gms.analytics.ANALYTICS_DISPATCH\" /></intent-filter></receiver>", + "xml": "<service android:enabled=\"true\" android:exported=\"false\" android:name=\"com.google.android.gms.measurement.AppMeasurementService\" />", "count": 1 }, { - "xml": "<service android:enabled=\"true\" android:exported=\"false\" android:name=\"com.google.android.gms.analytics.AnalyticsService\" />", + "xml": "<service android:name=\"org.apache.cordova.firebase.FirebasePluginMessagingService\"><intent-filter><action android:name=\"com.google.firebase.MESSAGING_EVENT\" /></intent-filter></service>", "count": 1 }, { - "xml": "<receiver android:enabled=\"true\" android:exported=\"true\" android:name=\"com.google.android.gms.analytics.CampaignTrackingReceiver\"><intent-filter><action android:name=\"com.android.vending.INSTALL_REFERRER\" /></intent-filter></receiver>", + "xml": "<service android:name=\"org.apache.cordova.firebase.FirebasePluginInstanceIDService\"><intent-filter><action android:name=\"com.google.firebase.INSTANCE_ID_EVENT\" /></intent-filter></service>", "count": 1 }, { - "xml": "<service android:enabled=\"true\" android:exported=\"false\" android:name=\"com.google.android.gms.analytics.CampaignTrackingService\" />", + "xml": "<receiver android:name=\"org.apache.cordova.firebase.OnNotificationOpenReceiver\" />", "count": 1 } ], @@ -170,6 +170,10 @@ { "xml": "<uses-permission android:name=\"android.permission.INTERNET\" />", "count": 1 + }, + { + "xml": "<uses-permission android:name=\"android.permission.WAKE_LOCK\" />", + "count": 1 } ], "/manifest/application/activity": [ @@ -195,6 +199,14 @@ { "xml": "<string name=\"google_app_id\">XXXXXXX</string>", "count": 1 + }, + { + "xml": "<string name=\"google_app_id\">@string/google_app_id</string>", + "count": 1 + }, + { + "xml": "<string name=\"google_api_key\">@string/google_api_key</string>", + "count": 1 } ] } @@ -246,10 +258,10 @@ "SENDER_ID": "XXXXXXX", "PACKAGE_NAME": "us.okfoc.stoneisland" }, - "cordova-plugin-google-analytics": { + "cordova-plugin-statusbar": { "PACKAGE_NAME": "us.okfoc.stoneisland" }, - "cordova-plugin-statusbar": { + "cordova-plugin-firebase": { "PACKAGE_NAME": "us.okfoc.stoneisland" } }, @@ -361,21 +373,20 @@ ] }, { - "id": "cordova-plugin-google-analytics.UniversalAnalytics", - "file": "plugins/cordova-plugin-google-analytics/www/analytics.js", - "pluginId": "cordova-plugin-google-analytics", - "clobbers": [ - "analytics", - "ga" - ] - }, - { "id": "cordova-plugin-statusbar.statusbar", "file": "plugins/cordova-plugin-statusbar/www/statusbar.js", "pluginId": "cordova-plugin-statusbar", "clobbers": [ "window.StatusBar" ] + }, + { + "id": "cordova-plugin-firebase.FirebasePlugin", + "file": "plugins/cordova-plugin-firebase/www/firebase.js", + "pluginId": "cordova-plugin-firebase", + "clobbers": [ + "FirebasePlugin" + ] } ], "plugin_metadata": { @@ -392,7 +403,7 @@ "cordova-plugin-geolocation": "2.4.0", "ionic-plugin-keyboard": "2.2.1", "phonegap-plugin-push": "1.9.2", - "cordova-plugin-google-analytics": "1.8.3", - "cordova-plugin-statusbar": "2.2.3" + "cordova-plugin-statusbar": "2.2.3", + "cordova-plugin-firebase": "0.1.24" } }
\ No newline at end of file diff --git a/StoneIsland/platforms/android/assets/www/cordova_plugins.js b/StoneIsland/platforms/android/assets/www/cordova_plugins.js index be2a17ab..f462f716 100755 --- a/StoneIsland/platforms/android/assets/www/cordova_plugins.js +++ b/StoneIsland/platforms/android/assets/www/cordova_plugins.js @@ -106,21 +106,20 @@ module.exports = [ ] }, { - "id": "cordova-plugin-google-analytics.UniversalAnalytics", - "file": "plugins/cordova-plugin-google-analytics/www/analytics.js", - "pluginId": "cordova-plugin-google-analytics", - "clobbers": [ - "analytics", - "ga" - ] - }, - { "id": "cordova-plugin-statusbar.statusbar", "file": "plugins/cordova-plugin-statusbar/www/statusbar.js", "pluginId": "cordova-plugin-statusbar", "clobbers": [ "window.StatusBar" ] + }, + { + "id": "cordova-plugin-firebase.FirebasePlugin", + "file": "plugins/cordova-plugin-firebase/www/firebase.js", + "pluginId": "cordova-plugin-firebase", + "clobbers": [ + "FirebasePlugin" + ] } ]; module.exports.metadata = @@ -139,8 +138,8 @@ module.exports.metadata = "cordova-plugin-geolocation": "2.4.0", "ionic-plugin-keyboard": "2.2.1", "phonegap-plugin-push": "1.9.2", - "cordova-plugin-google-analytics": "1.8.3", - "cordova-plugin-statusbar": "2.2.3" + "cordova-plugin-statusbar": "2.2.3", + "cordova-plugin-firebase": "0.1.24" }; // BOTTOM OF METADATA });
\ No newline at end of file diff --git a/StoneIsland/platforms/android/assets/www/plugins/cordova-plugin-firebase/www/firebase.js b/StoneIsland/platforms/android/assets/www/plugins/cordova-plugin-firebase/www/firebase.js new file mode 100644 index 00000000..e1e423d1 --- /dev/null +++ b/StoneIsland/platforms/android/assets/www/plugins/cordova-plugin-firebase/www/firebase.js @@ -0,0 +1,124 @@ +cordova.define("cordova-plugin-firebase.FirebasePlugin", function(require, exports, module) { +var exec = require('cordova/exec'); + +exports.getInstanceId = function(success, error) { + exec(success, error, "FirebasePlugin", "getInstanceId", []); +}; + +exports.getToken = function(success, error) { + exec(success, error, "FirebasePlugin", "getToken", []); +}; + +exports.onNotificationOpen = function(success, error) { + exec(success, error, "FirebasePlugin", "onNotificationOpen", []); +}; + +exports.onTokenRefresh = function(success, error) { + exec(success, error, "FirebasePlugin", "onTokenRefresh", []); +}; + +exports.grantPermission = function(success, error) { + exec(success, error, "FirebasePlugin", "grantPermission", []); +}; + +exports.hasPermission = function(success, error) { + exec(success, error, "FirebasePlugin", "hasPermission", []); +}; + +exports.setBadgeNumber = function(number, success, error) { + exec(success, error, "FirebasePlugin", "setBadgeNumber", [number]); +}; + +exports.getBadgeNumber = function(success, error) { + exec(success, error, "FirebasePlugin", "getBadgeNumber", []); +}; + +exports.subscribe = function(topic, success, error) { + exec(success, error, "FirebasePlugin", "subscribe", [topic]); +}; + +exports.unsubscribe = function(topic, success, error) { + exec(success, error, "FirebasePlugin", "unsubscribe", [topic]); +}; + +exports.unregister = function(success, error) { + exec(success, error, "FirebasePlugin", "unregister", []); +}; + +exports.logEvent = function(name, params, success, error) { + exec(success, error, "FirebasePlugin", "logEvent", [name, params]); +}; + +exports.logError = function(message, success, error) { + exec(success, error, "FirebasePlugin", "logError", [message]); +}; + +exports.setScreenName = function(name, success, error) { + exec(success, error, "FirebasePlugin", "setScreenName", [name]); +}; + +exports.setUserId = function(id, success, error) { + exec(success, error, "FirebasePlugin", "setUserId", [id]); +}; + +exports.setUserProperty = function(name, value, success, error) { + exec(success, error, "FirebasePlugin", "setUserProperty", [name, value]); +}; + +exports.activateFetched = function (success, error) { + exec(success, error, "FirebasePlugin", "activateFetched", []); +}; + +exports.fetch = function (cacheExpirationSeconds, success, error) { + var args = []; + if (typeof cacheExpirationSeconds === 'number') { + args.push(cacheExpirationSeconds); + } else { + error = success; + success = cacheExpirationSeconds; + } + exec(success, error, "FirebasePlugin", "fetch", args); +}; + +exports.getByteArray = function (key, namespace, success, error) { + var args = [key]; + if (typeof namespace === 'string') { + args.push(namespace); + } else { + error = success; + success = namespace; + } + exec(success, error, "FirebasePlugin", "getByteArray", args); +}; + +exports.getValue = function (key, namespace, success, error) { + var args = [key]; + if (typeof namespace === 'string') { + args.push(namespace); + } else { + error = success; + success = namespace; + } + exec(success, error, "FirebasePlugin", "getValue", args); +}; + +exports.getInfo = function (success, error) { + exec(success, error, "FirebasePlugin", "getInfo", []); +}; + +exports.setConfigSettings = function (settings, success, error) { + exec(success, error, "FirebasePlugin", "setConfigSettings", [settings]); +}; + +exports.setDefaults = function (defaults, namespace, success, error) { + var args = [defaults]; + if (typeof namespace === 'string') { + args.push(namespace); + } else { + error = success; + success = namespace; + } + exec(success, error, "FirebasePlugin", "setDefaults", args); +}; + +}); diff --git a/StoneIsland/platforms/android/assets/www/plugins/cordova-plugin-google-analytics/www/analytics.js b/StoneIsland/platforms/android/assets/www/plugins/cordova-plugin-google-analytics/www/analytics.js deleted file mode 100644 index b46b19ea..00000000 --- a/StoneIsland/platforms/android/assets/www/plugins/cordova-plugin-google-analytics/www/analytics.js +++ /dev/null @@ -1,130 +0,0 @@ -cordova.define("cordova-plugin-google-analytics.UniversalAnalytics", function(require, exports, module) { -function UniversalAnalyticsPlugin() {} - -UniversalAnalyticsPlugin.prototype.startTrackerWithId = function(id, dispatchPeriod, success, error) { - if (typeof dispatchPeriod === 'undefined' || dispatchPeriod === null) { - dispatchPeriod = 30; - } else if (typeof dispatchPeriod === 'function' && typeof error === 'undefined') { - // Called without dispatchPeriod but with a callback. - // Looks like the original API was used so shift parameters over to remain compatible. - error = success; - success = dispatchPeriod; - dispatchPeriod = 30; - } - cordova.exec(success, error, 'UniversalAnalytics', 'startTrackerWithId', [id, dispatchPeriod]); -}; - -UniversalAnalyticsPlugin.prototype.setAllowIDFACollection = function(enable, success, error) { - cordova.exec(success, error, 'UniversalAnalytics', 'setAllowIDFACollection', [enable]); -}; - -UniversalAnalyticsPlugin.prototype.setUserId = function(id, success, error) { - cordova.exec(success, error, 'UniversalAnalytics', 'setUserId', [id]); -}; - -UniversalAnalyticsPlugin.prototype.setAnonymizeIp = function(anonymize, success, error) { - cordova.exec(success, error, 'UniversalAnalytics', 'setAnonymizeIp', [anonymize]); -}; - -UniversalAnalyticsPlugin.prototype.setOptOut = function(optout, success, error) { - cordova.exec(success, error, 'UniversalAnalytics', 'setOptOut', [optout]); -}; - -UniversalAnalyticsPlugin.prototype.setAppVersion = function(version, success, error) { - cordova.exec(success, error, 'UniversalAnalytics', 'setAppVersion', [version]); -}; - -UniversalAnalyticsPlugin.prototype.getVar = function(variable, success, error) { - cordova.exec(success, error, 'UniversalAnalytics', 'getVar', [variable]); -}; - -UniversalAnalyticsPlugin.prototype.setVar = function(variable, value, success, error) { - cordova.exec(success, error, 'UniversalAnalytics', 'setVar', [variable, value]); -}; - -UniversalAnalyticsPlugin.prototype.dispatch = function(success, error) { - cordova.exec(success, error, 'UniversalAnalytics', 'dispatch', []); -}; - -/* enables verbose logging */ -UniversalAnalyticsPlugin.prototype.debugMode = function(success, error) { - cordova.exec(success, error, 'UniversalAnalytics', 'debugMode', []); -}; - -UniversalAnalyticsPlugin.prototype.trackMetric = function(key, value, success, error) { - cordova.exec(success, error, 'UniversalAnalytics', 'trackMetric', [key, value]); -}; - -UniversalAnalyticsPlugin.prototype.trackView = function(screen, campaignUrl, newSession, success, error) { - if (typeof campaignUrl === 'undefined' || campaignUrl === null) { - campaignUrl = ''; - } - - if (typeof newSession === 'undefined' || newSession === null) { - newSession = false; - } - - cordova.exec(success, error, 'UniversalAnalytics', 'trackView', [screen, campaignUrl, newSession]); -}; - -UniversalAnalyticsPlugin.prototype.addCustomDimension = function(key, value, success, error) { - if (typeof key !== "number") { - throw Error("key must be a valid integer not '" + typeof key + "'"); - } - cordova.exec(success, error, 'UniversalAnalytics', 'addCustomDimension', [key, value]); -}; - -UniversalAnalyticsPlugin.prototype.trackEvent = function(category, action, label, value, newSession, success, error) { - if (typeof label === 'undefined' || label === null) { - label = ''; - } - if (typeof value === 'undefined' || value === null) { - value = 0; - } - - if (typeof newSession === 'undefined' || newSession === null) { - newSession = false; - } - - cordova.exec(success, error, 'UniversalAnalytics', 'trackEvent', [category, action, label, value, newSession]); -}; - -/** - * https://developers.google.com/analytics/devguides/collection/android/v3/exceptions - */ -UniversalAnalyticsPlugin.prototype.trackException = function(description, fatal, success, error) { - cordova.exec(success, error, 'UniversalAnalytics', 'trackException', [description, fatal]); -}; - -UniversalAnalyticsPlugin.prototype.trackTiming = function(category, intervalInMilliseconds, name, label, success, error) { - if (typeof intervalInMilliseconds === 'undefined' || intervalInMilliseconds === null) { - intervalInMilliseconds = 0; - } - if (typeof name === 'undefined' || name === null) { - name = ''; - } - if (typeof label === 'undefined' || label === null) { - label = ''; - } - - cordova.exec(success, error, 'UniversalAnalytics', 'trackTiming', [category, intervalInMilliseconds, name, label]); -}; - -/* Google Analytics e-Commerce Tracking */ -/* https://developers.google.com/analytics/devguides/collection/analyticsjs/ecommerce */ -UniversalAnalyticsPlugin.prototype.addTransaction = function(transactionId, affiliation, revenue, tax, shipping, currencyCode, success, error) { - cordova.exec(success, error, 'UniversalAnalytics', 'addTransaction', [transactionId, affiliation, revenue, tax, shipping, currencyCode]); -}; - -UniversalAnalyticsPlugin.prototype.addTransactionItem = function(transactionId, name ,sku, category, price, quantity, currencyCode, success, error) { - cordova.exec(success, error, 'UniversalAnalytics', 'addTransactionItem', [transactionId, name ,sku, category, price, quantity, currencyCode]); -}; - -/* automatic uncaught exception tracking */ -UniversalAnalyticsPlugin.prototype.enableUncaughtExceptionReporting = function (enable, success, error) { - cordova.exec(success, error, 'UniversalAnalytics', 'enableUncaughtExceptionReporting', [enable]); -}; - -module.exports = new UniversalAnalyticsPlugin(); - -}); diff --git a/StoneIsland/platforms/android/build.gradle b/StoneIsland/platforms/android/build.gradle index a6e144c5..c4752d60 100644 --- a/StoneIsland/platforms/android/build.gradle +++ b/StoneIsland/platforms/android/build.gradle @@ -91,6 +91,7 @@ ext { // PLUGIN GRADLE EXTENSIONS START apply from: "phonegap-plugin-push/stoneisland-push.gradle" +apply from: "cordova-plugin-firebase/stoneisland-build.gradle" // PLUGIN GRADLE EXTENSIONS END def hasBuildExtras = file('build-extras.gradle').exists() @@ -255,7 +256,11 @@ dependencies { compile "com.android.support:support-v13:23+" compile "com.google.android.gms:play-services-gcm:9.8+" compile "me.leolin:ShortcutBadger:1.1.11@aar" - compile "com.google.android.gms:play-services-analytics:+" + compile "com.google.gms:google-services:+" + compile "com.google.firebase:firebase-core:+" + compile "com.google.firebase:firebase-messaging:+" + compile "com.google.firebase:firebase-crash:+" + compile "com.google.firebase:firebase-config:+" // SUB-PROJECT DEPENDENCIES END } diff --git a/StoneIsland/platforms/android/cordova-plugin-firebase/stoneisland-build.gradle b/StoneIsland/platforms/android/cordova-plugin-firebase/stoneisland-build.gradle new file mode 100755 index 00000000..d5cb4edd --- /dev/null +++ b/StoneIsland/platforms/android/cordova-plugin-firebase/stoneisland-build.gradle @@ -0,0 +1,15 @@ +buildscript {
+ repositories {
+ mavenCentral()
+ }
+ dependencies {
+ classpath 'com.google.gms:google-services:3.0.0'
+ }
+}
+repositories {
+ mavenCentral()
+}
+dependencies {
+ compile 'me.leolin:ShortcutBadger:1.1.4@aar'
+ compile 'com.google.firebase:firebase-crash:+'
+}
diff --git a/StoneIsland/platforms/android/google-services.json b/StoneIsland/platforms/android/google-services.json index 57497bf5..e69de29b 100644 --- a/StoneIsland/platforms/android/google-services.json +++ b/StoneIsland/platforms/android/google-services.json @@ -1,4 +0,0 @@ -{ - "project_info": {}, - "client": [] -} diff --git a/StoneIsland/platforms/android/platform_www/cordova_plugins.js b/StoneIsland/platforms/android/platform_www/cordova_plugins.js index be2a17ab..f462f716 100755 --- a/StoneIsland/platforms/android/platform_www/cordova_plugins.js +++ b/StoneIsland/platforms/android/platform_www/cordova_plugins.js @@ -106,21 +106,20 @@ module.exports = [ ] }, { - "id": "cordova-plugin-google-analytics.UniversalAnalytics", - "file": "plugins/cordova-plugin-google-analytics/www/analytics.js", - "pluginId": "cordova-plugin-google-analytics", - "clobbers": [ - "analytics", - "ga" - ] - }, - { "id": "cordova-plugin-statusbar.statusbar", "file": "plugins/cordova-plugin-statusbar/www/statusbar.js", "pluginId": "cordova-plugin-statusbar", "clobbers": [ "window.StatusBar" ] + }, + { + "id": "cordova-plugin-firebase.FirebasePlugin", + "file": "plugins/cordova-plugin-firebase/www/firebase.js", + "pluginId": "cordova-plugin-firebase", + "clobbers": [ + "FirebasePlugin" + ] } ]; module.exports.metadata = @@ -139,8 +138,8 @@ module.exports.metadata = "cordova-plugin-geolocation": "2.4.0", "ionic-plugin-keyboard": "2.2.1", "phonegap-plugin-push": "1.9.2", - "cordova-plugin-google-analytics": "1.8.3", - "cordova-plugin-statusbar": "2.2.3" + "cordova-plugin-statusbar": "2.2.3", + "cordova-plugin-firebase": "0.1.24" }; // BOTTOM OF METADATA });
\ No newline at end of file diff --git a/StoneIsland/platforms/android/platform_www/plugins/cordova-plugin-firebase/www/firebase.js b/StoneIsland/platforms/android/platform_www/plugins/cordova-plugin-firebase/www/firebase.js new file mode 100644 index 00000000..e1e423d1 --- /dev/null +++ b/StoneIsland/platforms/android/platform_www/plugins/cordova-plugin-firebase/www/firebase.js @@ -0,0 +1,124 @@ +cordova.define("cordova-plugin-firebase.FirebasePlugin", function(require, exports, module) { +var exec = require('cordova/exec'); + +exports.getInstanceId = function(success, error) { + exec(success, error, "FirebasePlugin", "getInstanceId", []); +}; + +exports.getToken = function(success, error) { + exec(success, error, "FirebasePlugin", "getToken", []); +}; + +exports.onNotificationOpen = function(success, error) { + exec(success, error, "FirebasePlugin", "onNotificationOpen", []); +}; + +exports.onTokenRefresh = function(success, error) { + exec(success, error, "FirebasePlugin", "onTokenRefresh", []); +}; + +exports.grantPermission = function(success, error) { + exec(success, error, "FirebasePlugin", "grantPermission", []); +}; + +exports.hasPermission = function(success, error) { + exec(success, error, "FirebasePlugin", "hasPermission", []); +}; + +exports.setBadgeNumber = function(number, success, error) { + exec(success, error, "FirebasePlugin", "setBadgeNumber", [number]); +}; + +exports.getBadgeNumber = function(success, error) { + exec(success, error, "FirebasePlugin", "getBadgeNumber", []); +}; + +exports.subscribe = function(topic, success, error) { + exec(success, error, "FirebasePlugin", "subscribe", [topic]); +}; + +exports.unsubscribe = function(topic, success, error) { + exec(success, error, "FirebasePlugin", "unsubscribe", [topic]); +}; + +exports.unregister = function(success, error) { + exec(success, error, "FirebasePlugin", "unregister", []); +}; + +exports.logEvent = function(name, params, success, error) { + exec(success, error, "FirebasePlugin", "logEvent", [name, params]); +}; + +exports.logError = function(message, success, error) { + exec(success, error, "FirebasePlugin", "logError", [message]); +}; + +exports.setScreenName = function(name, success, error) { + exec(success, error, "FirebasePlugin", "setScreenName", [name]); +}; + +exports.setUserId = function(id, success, error) { + exec(success, error, "FirebasePlugin", "setUserId", [id]); +}; + +exports.setUserProperty = function(name, value, success, error) { + exec(success, error, "FirebasePlugin", "setUserProperty", [name, value]); +}; + +exports.activateFetched = function (success, error) { + exec(success, error, "FirebasePlugin", "activateFetched", []); +}; + +exports.fetch = function (cacheExpirationSeconds, success, error) { + var args = []; + if (typeof cacheExpirationSeconds === 'number') { + args.push(cacheExpirationSeconds); + } else { + error = success; + success = cacheExpirationSeconds; + } + exec(success, error, "FirebasePlugin", "fetch", args); +}; + +exports.getByteArray = function (key, namespace, success, error) { + var args = [key]; + if (typeof namespace === 'string') { + args.push(namespace); + } else { + error = success; + success = namespace; + } + exec(success, error, "FirebasePlugin", "getByteArray", args); +}; + +exports.getValue = function (key, namespace, success, error) { + var args = [key]; + if (typeof namespace === 'string') { + args.push(namespace); + } else { + error = success; + success = namespace; + } + exec(success, error, "FirebasePlugin", "getValue", args); +}; + +exports.getInfo = function (success, error) { + exec(success, error, "FirebasePlugin", "getInfo", []); +}; + +exports.setConfigSettings = function (settings, success, error) { + exec(success, error, "FirebasePlugin", "setConfigSettings", [settings]); +}; + +exports.setDefaults = function (defaults, namespace, success, error) { + var args = [defaults]; + if (typeof namespace === 'string') { + args.push(namespace); + } else { + error = success; + success = namespace; + } + exec(success, error, "FirebasePlugin", "setDefaults", args); +}; + +}); diff --git a/StoneIsland/platforms/android/platform_www/plugins/cordova-plugin-google-analytics/www/analytics.js b/StoneIsland/platforms/android/platform_www/plugins/cordova-plugin-google-analytics/www/analytics.js deleted file mode 100644 index b46b19ea..00000000 --- a/StoneIsland/platforms/android/platform_www/plugins/cordova-plugin-google-analytics/www/analytics.js +++ /dev/null @@ -1,130 +0,0 @@ -cordova.define("cordova-plugin-google-analytics.UniversalAnalytics", function(require, exports, module) { -function UniversalAnalyticsPlugin() {} - -UniversalAnalyticsPlugin.prototype.startTrackerWithId = function(id, dispatchPeriod, success, error) { - if (typeof dispatchPeriod === 'undefined' || dispatchPeriod === null) { - dispatchPeriod = 30; - } else if (typeof dispatchPeriod === 'function' && typeof error === 'undefined') { - // Called without dispatchPeriod but with a callback. - // Looks like the original API was used so shift parameters over to remain compatible. - error = success; - success = dispatchPeriod; - dispatchPeriod = 30; - } - cordova.exec(success, error, 'UniversalAnalytics', 'startTrackerWithId', [id, dispatchPeriod]); -}; - -UniversalAnalyticsPlugin.prototype.setAllowIDFACollection = function(enable, success, error) { - cordova.exec(success, error, 'UniversalAnalytics', 'setAllowIDFACollection', [enable]); -}; - -UniversalAnalyticsPlugin.prototype.setUserId = function(id, success, error) { - cordova.exec(success, error, 'UniversalAnalytics', 'setUserId', [id]); -}; - -UniversalAnalyticsPlugin.prototype.setAnonymizeIp = function(anonymize, success, error) { - cordova.exec(success, error, 'UniversalAnalytics', 'setAnonymizeIp', [anonymize]); -}; - -UniversalAnalyticsPlugin.prototype.setOptOut = function(optout, success, error) { - cordova.exec(success, error, 'UniversalAnalytics', 'setOptOut', [optout]); -}; - -UniversalAnalyticsPlugin.prototype.setAppVersion = function(version, success, error) { - cordova.exec(success, error, 'UniversalAnalytics', 'setAppVersion', [version]); -}; - -UniversalAnalyticsPlugin.prototype.getVar = function(variable, success, error) { - cordova.exec(success, error, 'UniversalAnalytics', 'getVar', [variable]); -}; - -UniversalAnalyticsPlugin.prototype.setVar = function(variable, value, success, error) { - cordova.exec(success, error, 'UniversalAnalytics', 'setVar', [variable, value]); -}; - -UniversalAnalyticsPlugin.prototype.dispatch = function(success, error) { - cordova.exec(success, error, 'UniversalAnalytics', 'dispatch', []); -}; - -/* enables verbose logging */ -UniversalAnalyticsPlugin.prototype.debugMode = function(success, error) { - cordova.exec(success, error, 'UniversalAnalytics', 'debugMode', []); -}; - -UniversalAnalyticsPlugin.prototype.trackMetric = function(key, value, success, error) { - cordova.exec(success, error, 'UniversalAnalytics', 'trackMetric', [key, value]); -}; - -UniversalAnalyticsPlugin.prototype.trackView = function(screen, campaignUrl, newSession, success, error) { - if (typeof campaignUrl === 'undefined' || campaignUrl === null) { - campaignUrl = ''; - } - - if (typeof newSession === 'undefined' || newSession === null) { - newSession = false; - } - - cordova.exec(success, error, 'UniversalAnalytics', 'trackView', [screen, campaignUrl, newSession]); -}; - -UniversalAnalyticsPlugin.prototype.addCustomDimension = function(key, value, success, error) { - if (typeof key !== "number") { - throw Error("key must be a valid integer not '" + typeof key + "'"); - } - cordova.exec(success, error, 'UniversalAnalytics', 'addCustomDimension', [key, value]); -}; - -UniversalAnalyticsPlugin.prototype.trackEvent = function(category, action, label, value, newSession, success, error) { - if (typeof label === 'undefined' || label === null) { - label = ''; - } - if (typeof value === 'undefined' || value === null) { - value = 0; - } - - if (typeof newSession === 'undefined' || newSession === null) { - newSession = false; - } - - cordova.exec(success, error, 'UniversalAnalytics', 'trackEvent', [category, action, label, value, newSession]); -}; - -/** - * https://developers.google.com/analytics/devguides/collection/android/v3/exceptions - */ -UniversalAnalyticsPlugin.prototype.trackException = function(description, fatal, success, error) { - cordova.exec(success, error, 'UniversalAnalytics', 'trackException', [description, fatal]); -}; - -UniversalAnalyticsPlugin.prototype.trackTiming = function(category, intervalInMilliseconds, name, label, success, error) { - if (typeof intervalInMilliseconds === 'undefined' || intervalInMilliseconds === null) { - intervalInMilliseconds = 0; - } - if (typeof name === 'undefined' || name === null) { - name = ''; - } - if (typeof label === 'undefined' || label === null) { - label = ''; - } - - cordova.exec(success, error, 'UniversalAnalytics', 'trackTiming', [category, intervalInMilliseconds, name, label]); -}; - -/* Google Analytics e-Commerce Tracking */ -/* https://developers.google.com/analytics/devguides/collection/analyticsjs/ecommerce */ -UniversalAnalyticsPlugin.prototype.addTransaction = function(transactionId, affiliation, revenue, tax, shipping, currencyCode, success, error) { - cordova.exec(success, error, 'UniversalAnalytics', 'addTransaction', [transactionId, affiliation, revenue, tax, shipping, currencyCode]); -}; - -UniversalAnalyticsPlugin.prototype.addTransactionItem = function(transactionId, name ,sku, category, price, quantity, currencyCode, success, error) { - cordova.exec(success, error, 'UniversalAnalytics', 'addTransactionItem', [transactionId, name ,sku, category, price, quantity, currencyCode]); -}; - -/* automatic uncaught exception tracking */ -UniversalAnalyticsPlugin.prototype.enableUncaughtExceptionReporting = function (enable, success, error) { - cordova.exec(success, error, 'UniversalAnalytics', 'enableUncaughtExceptionReporting', [enable]); -}; - -module.exports = new UniversalAnalyticsPlugin(); - -}); diff --git a/StoneIsland/platforms/android/project.properties b/StoneIsland/platforms/android/project.properties index edb81941..c708ff82 100755 --- a/StoneIsland/platforms/android/project.properties +++ b/StoneIsland/platforms/android/project.properties @@ -16,4 +16,9 @@ cordova.gradle.include.1=phonegap-plugin-push/stoneisland-push.gradle cordova.system.library.1=com.android.support:support-v13:23+ cordova.system.library.2=com.google.android.gms:play-services-gcm:9.8+ cordova.system.library.3=me.leolin:ShortcutBadger:1.1.11@aar -cordova.system.library.4=com.google.android.gms:play-services-analytics:+
\ No newline at end of file +cordova.gradle.include.2=cordova-plugin-firebase/stoneisland-build.gradle +cordova.system.library.4=com.google.gms:google-services:+ +cordova.system.library.5=com.google.firebase:firebase-core:+ +cordova.system.library.6=com.google.firebase:firebase-messaging:+ +cordova.system.library.7=com.google.firebase:firebase-crash:+ +cordova.system.library.8=com.google.firebase:firebase-config:+
\ No newline at end of file diff --git a/StoneIsland/platforms/android/res/values/colors.xml b/StoneIsland/platforms/android/res/values/colors.xml new file mode 100644 index 00000000..6f1665a5 --- /dev/null +++ b/StoneIsland/platforms/android/res/values/colors.xml @@ -0,0 +1,6 @@ +<?xml version="1.0" encoding="utf-8"?> +<resources> + <color name="primary">#FFFFFF00</color> + <color name="primary_dark">#FF220022</color> + <color name="accent">#FF00FFFF</color> +</resources>
\ No newline at end of file diff --git a/StoneIsland/platforms/android/res/values/strings.xml b/StoneIsland/platforms/android/res/values/strings.xml index 60540e70..84421037 100755 --- a/StoneIsland/platforms/android/res/values/strings.xml +++ b/StoneIsland/platforms/android/res/values/strings.xml @@ -4,4 +4,6 @@ <string name="launcher_name">@string/app_name</string> <string name="activity_name">@string/launcher_name</string> <string name="google_app_id">XXXXXXX</string> + <string name="google_app_id">@string/google_app_id</string> + <string name="google_api_key">@string/google_api_key</string> </resources> diff --git a/StoneIsland/platforms/android/res/xml/config.xml b/StoneIsland/platforms/android/res/xml/config.xml index 49590cc4..57fa94d1 100644 --- a/StoneIsland/platforms/android/res/xml/config.xml +++ b/StoneIsland/platforms/android/res/xml/config.xml @@ -69,11 +69,12 @@ <preference name="AllowInlineMediaPlayback" value="true" /> <preference name="AndroidLaunchMode" value="singleTop" /> <preference name="android-minSdkVersion" value="21" /> - <feature name="UniversalAnalytics"> - <param name="android-package" value="com.danielcwilson.plugins.analytics.UniversalAnalyticsPlugin" /> - </feature> <feature name="StatusBar"> <param name="android-package" value="org.apache.cordova.statusbar.StatusBar" /> <param name="onload" value="true" /> </feature> + <feature name="FirebasePlugin"> + <param name="android-package" value="org.apache.cordova.firebase.FirebasePlugin" /> + <param name="onload" value="true" /> + </feature> </widget> diff --git a/StoneIsland/platforms/android/src/com/danielcwilson/plugins/analytics/UniversalAnalyticsPlugin.java b/StoneIsland/platforms/android/src/com/danielcwilson/plugins/analytics/UniversalAnalyticsPlugin.java deleted file mode 100644 index 23c20023..00000000 --- a/StoneIsland/platforms/android/src/com/danielcwilson/plugins/analytics/UniversalAnalyticsPlugin.java +++ /dev/null @@ -1,469 +0,0 @@ -package com.danielcwilson.plugins.analytics; - -import com.google.android.gms.analytics.GoogleAnalytics; -import com.google.android.gms.analytics.Logger.LogLevel; -import com.google.android.gms.analytics.HitBuilders; -import com.google.android.gms.analytics.Tracker; - -import org.apache.cordova.CordovaPlugin; -import org.apache.cordova.CallbackContext; - -import org.json.JSONArray; -import org.json.JSONException; - -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; -import java.util.HashMap; -import java.util.Map.Entry; - -public class UniversalAnalyticsPlugin extends CordovaPlugin { - public static final String START_TRACKER = "startTrackerWithId"; - public static final String TRACK_VIEW = "trackView"; - public static final String TRACK_EVENT = "trackEvent"; - public static final String TRACK_EXCEPTION = "trackException"; - public static final String TRACK_TIMING = "trackTiming"; - public static final String TRACK_METRIC = "trackMetric"; - public static final String ADD_DIMENSION = "addCustomDimension"; - public static final String ADD_TRANSACTION = "addTransaction"; - public static final String ADD_TRANSACTION_ITEM = "addTransactionItem"; - - public static final String SET_ALLOW_IDFA_COLLECTION = "setAllowIDFACollection"; - public static final String SET_USER_ID = "setUserId"; - public static final String SET_ANONYMIZE_IP = "setAnonymizeIp"; - public static final String SET_OPT_OUT = "setOptOut"; - public static final String SET_APP_VERSION = "setAppVersion"; - public static final String GET_VAR = "getVar"; - public static final String SET_VAR = "setVar"; - public static final String DISPATCH = "dispatch"; - public static final String DEBUG_MODE = "debugMode"; - public static final String ENABLE_UNCAUGHT_EXCEPTION_REPORTING = "enableUncaughtExceptionReporting"; - - public Boolean trackerStarted = false; - public Boolean debugModeEnabled = false; - public HashMap<Integer, String> customDimensions = new HashMap<Integer, String>(); - - public Tracker tracker; - - @Override - public boolean execute(String action, JSONArray args, CallbackContext callbackContext) throws JSONException { - if (START_TRACKER.equals(action)) { - String id = args.getString(0); - int dispatchPeriod = args.length() > 1 ? args.getInt(1) : 30; - this.startTracker(id, dispatchPeriod, callbackContext); - return true; - } else if (TRACK_VIEW.equals(action)) { - int length = args.length(); - String screen = args.getString(0); - this.trackView(screen, length > 1 && !args.isNull(1) ? args.getString(1) : "", length > 2 && !args.isNull(2) ? args.getBoolean(2) : false, callbackContext); - return true; - } else if (TRACK_EVENT.equals(action)) { - int length = args.length(); - if (length > 0) { - this.trackEvent( - args.getString(0), - length > 1 ? args.getString(1) : "", - length > 2 ? args.getString(2) : "", - length > 3 ? args.getLong(3) : 0, - length > 4 ? args.getBoolean(4) : false, - callbackContext); - } - return true; - } else if (TRACK_EXCEPTION.equals(action)) { - String description = args.getString(0); - Boolean fatal = args.getBoolean(1); - this.trackException(description, fatal, callbackContext); - return true; - } else if (TRACK_TIMING.equals(action)) { - int length = args.length(); - if (length > 0) { - this.trackTiming(args.getString(0), length > 1 ? args.getLong(1) : 0, length > 2 ? args.getString(2) : "", length > 3 ? args.getString(3) : "", callbackContext); - } - return true; - } else if (TRACK_METRIC.equals(action)) { - int length = args.length(); - if (length > 0) { - this.trackMetric(args.getInt(0), length > 1 ? args.getString(1) : "", callbackContext); - } - return true; - } else if (ADD_DIMENSION.equals(action)) { - Integer key = args.getInt(0); - String value = args.getString(1); - this.addCustomDimension(key, value, callbackContext); - return true; - } else if (ADD_TRANSACTION.equals(action)) { - int length = args.length(); - if (length > 0) { - this.addTransaction( - args.getString(0), - length > 1 ? args.getString(1) : "", - length > 2 ? args.getDouble(2) : 0, - length > 3 ? args.getDouble(3) : 0, - length > 4 ? args.getDouble(4) : 0, - length > 5 ? args.getString(5) : null, - callbackContext); - } - return true; - } else if (ADD_TRANSACTION_ITEM.equals(action)) { - int length = args.length(); - if (length > 0) { - this.addTransactionItem( - args.getString(0), - length > 1 ? args.getString(1) : "", - length > 2 ? args.getString(2) : "", - length > 3 ? args.getString(3) : "", - length > 4 ? args.getDouble(4) : 0, - length > 5 ? args.getLong(5) : 0, - length > 6 ? args.getString(6) : null, - callbackContext); - } - return true; - } else if (SET_ALLOW_IDFA_COLLECTION.equals(action)) { - this.setAllowIDFACollection(args.getBoolean(0), callbackContext); - } else if (SET_USER_ID.equals(action)) { - String userId = args.getString(0); - this.setUserId(userId, callbackContext); - } else if (SET_ANONYMIZE_IP.equals(action)) { - boolean anonymize = args.getBoolean(0); - this.setAnonymizeIp(anonymize, callbackContext); - } else if (SET_OPT_OUT.equals(action)) { - boolean optout = args.getBoolean(0); - this.setOptOut(optout, callbackContext); - } else if (SET_APP_VERSION.equals(action)) { - String version = args.getString(0); - this.setAppVersion(version, callbackContext); - } else if (GET_VAR.equals(action)) { - String variable = args.getString(0); - this.getVar(variable, callbackContext); - } else if (SET_VAR.equals(action)) { - String variable = args.getString(0); - String value = args.getString(1); - this.setVar(variable, value, callbackContext); - return true; - } else if (DISPATCH.equals(action)) { - this.dispatch(callbackContext); - return true; - } else if (DEBUG_MODE.equals(action)) { - this.debugMode(callbackContext); - } else if (ENABLE_UNCAUGHT_EXCEPTION_REPORTING.equals(action)) { - Boolean enable = args.getBoolean(0); - this.enableUncaughtExceptionReporting(enable, callbackContext); - } - return false; - } - - private void startTracker(String id, int dispatchPeriod, CallbackContext callbackContext) { - if (null != id && id.length() > 0) { - tracker = GoogleAnalytics.getInstance(this.cordova.getActivity()).newTracker(id); - callbackContext.success("tracker started"); - trackerStarted = true; - GoogleAnalytics.getInstance(this.cordova.getActivity()).setLocalDispatchPeriod(dispatchPeriod); - } else { - callbackContext.error("tracker id is not valid"); - } - } - - private void addCustomDimension(Integer key, String value, CallbackContext callbackContext) { - if (key <= 0) { - callbackContext.error("Expected positive integer argument for key."); - return; - } - - if (null == value || value.length() == 0) { - callbackContext.error("Expected non-empty string argument for value."); - return; - } - - customDimensions.put(key, value); - callbackContext.success("custom dimension started"); - } - - private <T> void addCustomDimensionsToHitBuilder(T builder) { - //unfortunately the base HitBuilders.HitBuilder class is not public, therefore have to use reflection to use - //the common setCustomDimension (int index, String dimension) method - try { - Method builderMethod = builder.getClass().getMethod("setCustomDimension", Integer.TYPE, String.class); - - for (Entry<Integer, String> entry : customDimensions.entrySet()) { - Integer key = entry.getKey(); - String value = entry.getValue(); - try { - builderMethod.invoke(builder, (key), value); - } catch (IllegalArgumentException e) { - } catch (IllegalAccessException e) { - } catch (InvocationTargetException e) { - } - } - } catch (SecurityException e) { - } catch (NoSuchMethodException e) { - } - } - - private void trackView(String screenname, String campaignUrl, boolean newSession, CallbackContext callbackContext) { - if (! trackerStarted ) { - callbackContext.error("Tracker not started"); - return; - } - - if (null != screenname && screenname.length() > 0) { - tracker.setScreenName(screenname); - - HitBuilders.ScreenViewBuilder hitBuilder = new HitBuilders.ScreenViewBuilder(); - addCustomDimensionsToHitBuilder(hitBuilder); - - if(!campaignUrl.equals("")){ - hitBuilder.setCampaignParamsFromUrl(campaignUrl); - } - - if(!newSession) { - tracker.send(hitBuilder.build()); - } else { - tracker.send(hitBuilder.setNewSession().build()); - } - - callbackContext.success("Track Screen: " + screenname); - } else { - callbackContext.error("Expected one non-empty string argument."); - } - } - - private void trackEvent(String category, String action, String label, long value, boolean newSession, CallbackContext callbackContext) { - if (!trackerStarted) { - callbackContext.error("Tracker not started"); - return; - } - - if (null != category && category.length() > 0) { - HitBuilders.EventBuilder hitBuilder = new HitBuilders.EventBuilder(); - addCustomDimensionsToHitBuilder(hitBuilder); - - if(!newSession){ - tracker.send(hitBuilder - .setCategory(category) - .setAction(action) - .setLabel(label) - .setValue(value) - .build()); - } else { - tracker.send(hitBuilder - .setCategory(category) - .setAction(action) - .setLabel(label) - .setValue(value) - .setNewSession() - .build()); - } - - callbackContext.success("Track Event: " + category); - } else { - callbackContext.error("Expected non-empty string arguments."); - } - } - - private void trackMetric(Integer key, String value, CallbackContext callbackContext) { - if (!trackerStarted) { - callbackContext.error("Tracker not started"); - return; - } - - if (key >= 0) { - HitBuilders.ScreenViewBuilder hitBuilder = new HitBuilders.ScreenViewBuilder(); - tracker.send(hitBuilder - .setCustomMetric(key, Float.parseFloat(value)) - .build() - ); - callbackContext.success("Track Metric: " + key + ", value: " + value); - } else { - callbackContext.error("Expected integer key: " + key + ", and string value: " + value); - } - } - - private void trackException(String description, Boolean fatal, CallbackContext callbackContext) { - if (!trackerStarted) { - callbackContext.error("Tracker not started"); - return; - } - - if (null != description && description.length() > 0) { - HitBuilders.ExceptionBuilder hitBuilder = new HitBuilders.ExceptionBuilder(); - addCustomDimensionsToHitBuilder(hitBuilder); - - tracker.send(hitBuilder - .setDescription(description) - .setFatal(fatal) - .build() - ); - callbackContext.success("Track Exception: " + description); - } else { - callbackContext.error("Expected non-empty string arguments."); - } - } - - private void trackTiming(String category, long intervalInMilliseconds, String name, String label, CallbackContext callbackContext) { - if (!trackerStarted) { - callbackContext.error("Tracker not started"); - return; - } - - if (null != category && category.length() > 0) { - HitBuilders.TimingBuilder hitBuilder = new HitBuilders.TimingBuilder(); - addCustomDimensionsToHitBuilder(hitBuilder); - - tracker.send(hitBuilder - .setCategory(category) - .setValue(intervalInMilliseconds) - .setVariable(name) - .setLabel(label) - .build() - ); - callbackContext.success("Track Timing: " + category); - } else { - callbackContext.error("Expected non-empty string arguments."); - } - } - - private void addTransaction(String id, String affiliation, double revenue, double tax, double shipping, String currencyCode, CallbackContext callbackContext) { - if (!trackerStarted) { - callbackContext.error("Tracker not started"); - return; - } - - if (null != id && id.length() > 0) { - HitBuilders.TransactionBuilder hitBuilder = new HitBuilders.TransactionBuilder(); - addCustomDimensionsToHitBuilder(hitBuilder); - - tracker.send(hitBuilder - .setTransactionId(id) - .setAffiliation(affiliation) - .setRevenue(revenue).setTax(tax) - .setShipping(shipping) - .setCurrencyCode(currencyCode) - .build() - ); //Deprecated - callbackContext.success("Add Transaction: " + id); - } else { - callbackContext.error("Expected non-empty ID."); - } - } - - private void addTransactionItem(String id, String name, String sku, String category, double price, long quantity, String currencyCode, CallbackContext callbackContext) { - if (!trackerStarted) { - callbackContext.error("Tracker not started"); - return; - } - - if (null != id && id.length() > 0) { - HitBuilders.ItemBuilder hitBuilder = new HitBuilders.ItemBuilder(); - addCustomDimensionsToHitBuilder(hitBuilder); - - tracker.send(hitBuilder - .setTransactionId(id) - .setName(name) - .setSku(sku) - .setCategory(category) - .setPrice(price) - .setQuantity(quantity) - .setCurrencyCode(currencyCode) - .build() - ); //Deprecated - callbackContext.success("Add Transaction Item: " + id); - } else { - callbackContext.error("Expected non-empty ID."); - } - } - - private void setAllowIDFACollection(Boolean enable, CallbackContext callbackContext) { - if (!trackerStarted) { - callbackContext.error("Tracker not started"); - return; - } - - tracker.enableAdvertisingIdCollection(enable); - callbackContext.success("Enable Advertising Id Collection: " + enable); - } - - private void setVar(String variable, String value, CallbackContext callbackContext) { - if (!trackerStarted) { - callbackContext.error("Tracker not started"); - return; - } - - tracker.set(variable, value); - callbackContext.success("Set variable " + variable + "to " + value); - } - private void dispatch(CallbackContext callbackContext) { - if (!trackerStarted) { - callbackContext.error("Tracker not started"); - return; - } - - GoogleAnalytics.getInstance(this.cordova.getActivity()).dispatchLocalHits(); - callbackContext.success("dispatch sent"); - } - - private void getVar(String variable, CallbackContext callbackContext) { - if (!trackerStarted) { - callbackContext.error("Tracker not started"); - return; - } - - String result = tracker.get(variable); - callbackContext.success(result); - } - - private void debugMode(CallbackContext callbackContext) { - GoogleAnalytics.getInstance(this.cordova.getActivity()).getLogger().setLogLevel(LogLevel.VERBOSE); - - this.debugModeEnabled = true; - callbackContext.success("debugMode enabled"); - } - - private void setAnonymizeIp(boolean anonymize, CallbackContext callbackContext) { - if (!trackerStarted) { - callbackContext.error("Tracker not started"); - return; - } - - tracker.setAnonymizeIp(anonymize); - callbackContext.success("Set AnonymizeIp " + anonymize); - } - - private void setOptOut(boolean optout, CallbackContext callbackContext) { - if (!trackerStarted) { - callbackContext.error("Tracker not started"); - return; - } - - GoogleAnalytics.getInstance(this.cordova.getActivity()).setAppOptOut(optout); - callbackContext.success("Set Opt-Out " + optout); - } - - private void setUserId(String userId, CallbackContext callbackContext) { - if (!trackerStarted) { - callbackContext.error("Tracker not started"); - return; - } - - tracker.set("&uid", userId); - callbackContext.success("Set user id" + userId); - } - - private void setAppVersion(String version, CallbackContext callbackContext) { - if (!trackerStarted) { - callbackContext.error("Tracker not started"); - return; - } - - tracker.set("&av", version); - callbackContext.success("Set app version: " + version); - } - - private void enableUncaughtExceptionReporting(Boolean enable, CallbackContext callbackContext) { - if (!trackerStarted) { - callbackContext.error("Tracker not started"); - return; - } - - tracker.enableExceptionReporting(enable); - callbackContext.success((enable ? "Enabled" : "Disabled") + " uncaught exception reporting"); - } -} diff --git a/StoneIsland/platforms/android/src/org/apache/cordova/firebase/FirebasePlugin.java b/StoneIsland/platforms/android/src/org/apache/cordova/firebase/FirebasePlugin.java new file mode 100755 index 00000000..7e4431df --- /dev/null +++ b/StoneIsland/platforms/android/src/org/apache/cordova/firebase/FirebasePlugin.java @@ -0,0 +1,601 @@ +package org.apache.cordova.firebase; + +import android.content.Context; +import android.content.Intent; +import android.content.SharedPreferences; +import android.os.Bundle; +import android.support.v4.app.NotificationManagerCompat; +import android.util.Base64; +import android.util.Log; +import com.google.android.gms.tasks.OnCompleteListener; +import com.google.android.gms.tasks.OnFailureListener; +import com.google.android.gms.tasks.Task; +import com.google.firebase.analytics.FirebaseAnalytics; +import com.google.firebase.iid.FirebaseInstanceId; +import com.google.firebase.messaging.FirebaseMessaging; +import com.google.firebase.remoteconfig.FirebaseRemoteConfig; +import com.google.firebase.remoteconfig.FirebaseRemoteConfigInfo; +import com.google.firebase.remoteconfig.FirebaseRemoteConfigSettings; +import com.google.firebase.remoteconfig.FirebaseRemoteConfigValue; +import com.google.firebase.crash.FirebaseCrash; +import me.leolin.shortcutbadger.ShortcutBadger; +import org.apache.cordova.CallbackContext; +import org.apache.cordova.CordovaPlugin; +import org.apache.cordova.PluginResult; +import org.json.JSONArray; +import org.json.JSONException; +import org.json.JSONObject; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Iterator; +import java.util.Map; +import java.util.Set; + +public class FirebasePlugin extends CordovaPlugin { + + private FirebaseAnalytics mFirebaseAnalytics; + private final String TAG = "FirebasePlugin"; + protected static final String KEY = "badge"; + + private static boolean inBackground = true; + private static ArrayList<Bundle> notificationStack = null; + private static CallbackContext notificationCallbackContext; + private static CallbackContext tokenRefreshCallbackContext; + + @Override + protected void pluginInitialize() { + final Context context = this.cordova.getActivity().getApplicationContext(); + final Bundle extras = this.cordova.getActivity().getIntent().getExtras(); + this.cordova.getThreadPool().execute(new Runnable() { + public void run() { + Log.d(TAG, "Starting Firebase plugin"); + mFirebaseAnalytics = FirebaseAnalytics.getInstance(context); + mFirebaseAnalytics.setAnalyticsCollectionEnabled(true); + if (extras != null && extras.size() > 1) { + if (FirebasePlugin.notificationStack == null) { + FirebasePlugin.notificationStack = new ArrayList<Bundle>(); + } + if (extras.containsKey("google.message_id")) { + extras.putBoolean("tap", true); + notificationStack.add(extras); + } + } + } + }); + } + + @Override + public boolean execute(String action, JSONArray args, CallbackContext callbackContext) throws JSONException { + if (action.equals("getInstanceId")) { + this.getInstanceId(callbackContext); + return true; + } else if (action.equals("getToken")) { + this.getToken(callbackContext); + return true; + } else if (action.equals("hasPermission")) { + this.hasPermission(callbackContext); + return true; + } else if (action.equals("setBadgeNumber")) { + this.setBadgeNumber(callbackContext, args.getInt(0)); + return true; + } else if (action.equals("getBadgeNumber")) { + this.getBadgeNumber(callbackContext); + return true; + } else if (action.equals("subscribe")) { + this.subscribe(callbackContext, args.getString(0)); + return true; + } else if (action.equals("unsubscribe")) { + this.unsubscribe(callbackContext, args.getString(0)); + return true; + } else if (action.equals("unregister")) { + this.unregister(callbackContext); + return true; + } else if (action.equals("onNotificationOpen")) { + this.onNotificationOpen(callbackContext); + return true; + } else if (action.equals("onTokenRefresh")) { + this.onTokenRefresh(callbackContext); + return true; + } else if (action.equals("logEvent")) { + this.logEvent(callbackContext, args.getString(0), args.getJSONObject(1)); + return true; + } else if (action.equals("logError")) { + this.logError(callbackContext, args.getString(0)); + return true; + } else if (action.equals("setScreenName")) { + this.setScreenName(callbackContext, args.getString(0)); + return true; + } else if (action.equals("setUserId")) { + this.setUserId(callbackContext, args.getString(0)); + return true; + } else if (action.equals("setUserProperty")) { + this.setUserProperty(callbackContext, args.getString(0), args.getString(1)); + return true; + } else if (action.equals("activateFetched")) { + this.activateFetched(callbackContext); + return true; + } else if (action.equals("fetch")) { + if (args.length() > 0) this.fetch(callbackContext, args.getLong(0)); + else this.fetch(callbackContext); + return true; + } else if (action.equals("getByteArray")) { + if (args.length() > 1) this.getByteArray(callbackContext, args.getString(0), args.getString(1)); + else this.getByteArray(callbackContext, args.getString(0), null); + return true; + } else if (action.equals("getValue")) { + if (args.length() > 1) this.getValue(callbackContext, args.getString(0), args.getString(1)); + else this.getValue(callbackContext, args.getString(0), null); + return true; + } else if (action.equals("getInfo")) { + this.getInfo(callbackContext); + return true; + } else if (action.equals("setConfigSettings")) { + this.setConfigSettings(callbackContext, args.getJSONObject(0)); + return true; + } else if (action.equals("setDefaults")) { + if (args.length() > 1) this.setDefaults(callbackContext, args.getJSONObject(0), args.getString(1)); + else this.setDefaults(callbackContext, args.getJSONObject(0), null); + return true; + } + return false; + } + + @Override + public void onPause(boolean multitasking) { + FirebasePlugin.inBackground = true; + } + + @Override + public void onResume(boolean multitasking) { + FirebasePlugin.inBackground = false; + } + + @Override + public void onReset() { + FirebasePlugin.notificationCallbackContext = null; + FirebasePlugin.tokenRefreshCallbackContext = null; + } + + private void onNotificationOpen(final CallbackContext callbackContext) { + FirebasePlugin.notificationCallbackContext = callbackContext; + if (FirebasePlugin.notificationStack != null) { + for (Bundle bundle : FirebasePlugin.notificationStack) { + FirebasePlugin.sendNotification(bundle); + } + FirebasePlugin.notificationStack.clear(); + } + } + + private void onTokenRefresh(final CallbackContext callbackContext) { + FirebasePlugin.tokenRefreshCallbackContext = callbackContext; + + cordova.getThreadPool().execute(new Runnable() { + public void run() { + try { + String currentToken = FirebaseInstanceId.getInstance().getToken(); + + if (currentToken != null) { + FirebasePlugin.sendToken(currentToken); + } + } catch (Exception e) { + callbackContext.error(e.getMessage()); + } + } + }); + } + + public static void sendNotification(Bundle bundle) { + if (!FirebasePlugin.hasNotificationsCallback()) { + if (FirebasePlugin.notificationStack == null) { + FirebasePlugin.notificationStack = new ArrayList<Bundle>(); + } + notificationStack.add(bundle); + return; + } + final CallbackContext callbackContext = FirebasePlugin.notificationCallbackContext; + if (callbackContext != null && bundle != null) { + JSONObject json = new JSONObject(); + Set<String> keys = bundle.keySet(); + for (String key : keys) { + try { + json.put(key, bundle.get(key)); + } catch (JSONException e) { + callbackContext.error(e.getMessage()); + return; + } + } + + PluginResult pluginresult = new PluginResult(PluginResult.Status.OK, json); + pluginresult.setKeepCallback(true); + callbackContext.sendPluginResult(pluginresult); + } + } + + public static void sendToken(String token) { + if (FirebasePlugin.tokenRefreshCallbackContext == null) { + return; + } + final CallbackContext callbackContext = FirebasePlugin.tokenRefreshCallbackContext; + if (callbackContext != null && token != null) { + PluginResult pluginresult = new PluginResult(PluginResult.Status.OK, token); + pluginresult.setKeepCallback(true); + callbackContext.sendPluginResult(pluginresult); + } + } + + public static boolean inBackground() { + return FirebasePlugin.inBackground; + } + + public static boolean hasNotificationsCallback() { + return FirebasePlugin.notificationCallbackContext != null; + } + + @Override + public void onNewIntent(Intent intent) { + super.onNewIntent(intent); + final Bundle data = intent.getExtras(); + if (data != null && data.containsKey("google.message_id")) { + data.putBoolean("tap", true); + FirebasePlugin.sendNotification(data); + } + } + + // DEPRECTED - alias of getToken + private void getInstanceId(final CallbackContext callbackContext) { + cordova.getThreadPool().execute(new Runnable() { + public void run() { + try { + String token = FirebaseInstanceId.getInstance().getToken(); + callbackContext.success(token); + } catch (Exception e) { + callbackContext.error(e.getMessage()); + } + } + }); + } + + private void getToken(final CallbackContext callbackContext) { + cordova.getThreadPool().execute(new Runnable() { + public void run() { + try { + String token = FirebaseInstanceId.getInstance().getToken(); + callbackContext.success(token); + } catch (Exception e) { + callbackContext.error(e.getMessage()); + } + } + }); + } + + private void hasPermission(final CallbackContext callbackContext) { + cordova.getThreadPool().execute(new Runnable() { + public void run() { + try { + Context context = cordova.getActivity(); + NotificationManagerCompat notificationManagerCompat = NotificationManagerCompat.from(context); + boolean areNotificationsEnabled = notificationManagerCompat.areNotificationsEnabled(); + JSONObject object = new JSONObject(); + object.put("isEnabled", areNotificationsEnabled); + callbackContext.success(object); + } catch (Exception e) { + callbackContext.error(e.getMessage()); + } + } + }); + } + + private void setBadgeNumber(final CallbackContext callbackContext, final int number) { + cordova.getThreadPool().execute(new Runnable() { + public void run() { + try { + Context context = cordova.getActivity(); + SharedPreferences.Editor editor = context.getSharedPreferences(KEY, Context.MODE_PRIVATE).edit(); + editor.putInt(KEY, number); + editor.apply(); + ShortcutBadger.applyCount(context, number); + callbackContext.success(); + } catch (Exception e) { + callbackContext.error(e.getMessage()); + } + } + }); + } + + private void getBadgeNumber(final CallbackContext callbackContext) { + cordova.getThreadPool().execute(new Runnable() { + public void run() { + try { + Context context = cordova.getActivity(); + SharedPreferences settings = context.getSharedPreferences(KEY, Context.MODE_PRIVATE); + int number = settings.getInt(KEY, 0); + callbackContext.success(number); + } catch (Exception e) { + callbackContext.error(e.getMessage()); + } + } + }); + } + + private void subscribe(final CallbackContext callbackContext, final String topic) { + cordova.getThreadPool().execute(new Runnable() { + public void run() { + try { + FirebaseMessaging.getInstance().subscribeToTopic(topic); + callbackContext.success(); + } catch (Exception e) { + callbackContext.error(e.getMessage()); + } + } + }); + } + + private void unsubscribe(final CallbackContext callbackContext, final String topic) { + cordova.getThreadPool().execute(new Runnable() { + public void run() { + try { + FirebaseMessaging.getInstance().unsubscribeFromTopic(topic); + callbackContext.success(); + } catch (Exception e) { + callbackContext.error(e.getMessage()); + } + } + }); + } + + private void unregister(final CallbackContext callbackContext) { + cordova.getThreadPool().execute(new Runnable() { + public void run() { + try { + FirebaseInstanceId.getInstance().deleteInstanceId(); + String currentToken = FirebaseInstanceId.getInstance().getToken(); + if (currentToken != null) { + FirebasePlugin.sendToken(currentToken); + } + callbackContext.success(); + } catch (Exception e) { + callbackContext.error(e.getMessage()); + } + } + }); + } + + private void logEvent(final CallbackContext callbackContext, final String name, final JSONObject params) throws JSONException { + final Bundle bundle = new Bundle(); + Iterator iter = params.keys(); + while (iter.hasNext()) { + String key = (String) iter.next(); + Object value = params.get(key); + + if (value instanceof Integer || value instanceof Double) { + bundle.putFloat(key, ((Number) value).floatValue()); + } else { + bundle.putString(key, value.toString()); + } + } + + cordova.getThreadPool().execute(new Runnable() { + public void run() { + try { + mFirebaseAnalytics.logEvent(name, bundle); + callbackContext.success(); + } catch (Exception e) { + callbackContext.error(e.getMessage()); + } + } + }); + } + + private void logError(final CallbackContext callbackContext, final String message) throws JSONException { + cordova.getThreadPool().execute(new Runnable() { + public void run() { + try { + FirebaseCrash.report(new Exception(message)); + callbackContext.success(1); + } catch (Exception e) { + FirebaseCrash.log(e.getMessage()); + e.printStackTrace(); + callbackContext.error(e.getMessage()); + } + } + }); + } + + private void setScreenName(final CallbackContext callbackContext, final String name) { + // This must be called on the main thread + cordova.getActivity().runOnUiThread(new Runnable() { + public void run() { + try { + mFirebaseAnalytics.setCurrentScreen(cordova.getActivity(), name, null); + callbackContext.success(); + } catch (Exception e) { + callbackContext.error(e.getMessage()); + } + } + }); + } + + private void setUserId(final CallbackContext callbackContext, final String id) { + cordova.getThreadPool().execute(new Runnable() { + public void run() { + try { + mFirebaseAnalytics.setUserId(id); + callbackContext.success(); + } catch (Exception e) { + callbackContext.error(e.getMessage()); + } + } + }); + } + + private void setUserProperty(final CallbackContext callbackContext, final String name, final String value) { + cordova.getThreadPool().execute(new Runnable() { + public void run() { + try { + mFirebaseAnalytics.setUserProperty(name, value); + callbackContext.success(); + } catch (Exception e) { + callbackContext.error(e.getMessage()); + } + } + }); + } + + private void activateFetched(final CallbackContext callbackContext) { + cordova.getThreadPool().execute(new Runnable() { + public void run() { + try { + final boolean activated = FirebaseRemoteConfig.getInstance().activateFetched(); + callbackContext.success(String.valueOf(activated)); + } catch (Exception e) { + callbackContext.error(e.getMessage()); + } + } + }); + } + + private void fetch(CallbackContext callbackContext) { + fetch(callbackContext, FirebaseRemoteConfig.getInstance().fetch()); + } + + private void fetch(CallbackContext callbackContext, long cacheExpirationSeconds) { + fetch(callbackContext, FirebaseRemoteConfig.getInstance().fetch(cacheExpirationSeconds)); + } + + private void fetch(final CallbackContext callbackContext, final Task<Void> task) { + cordova.getThreadPool().execute(new Runnable() { + public void run() { + try { + task.addOnCompleteListener(new OnCompleteListener<Void>() { + @Override + public void onComplete(Task<Void> task) { + callbackContext.success(); + } + }).addOnFailureListener(new OnFailureListener() { + @Override + public void onFailure(Exception e) { + callbackContext.error(e.getMessage()); + } + }); + } catch (Exception e) { + callbackContext.error(e.getMessage()); + } + } + }); + } + + private void getByteArray(final CallbackContext callbackContext, final String key, final String namespace) { + cordova.getThreadPool().execute(new Runnable() { + public void run() { + try { + byte[] bytes = namespace == null ? FirebaseRemoteConfig.getInstance().getByteArray(key) + : FirebaseRemoteConfig.getInstance().getByteArray(key, namespace); + JSONObject object = new JSONObject(); + object.put("base64", Base64.encodeToString(bytes, Base64.DEFAULT)); + object.put("array", new JSONArray(bytes)); + callbackContext.success(object); + } catch (Exception e) { + callbackContext.error(e.getMessage()); + } + } + }); + } + + private void getValue(final CallbackContext callbackContext, final String key, final String namespace) { + cordova.getThreadPool().execute(new Runnable() { + public void run() { + try { + FirebaseRemoteConfigValue value = namespace == null ? FirebaseRemoteConfig.getInstance().getValue(key) + : FirebaseRemoteConfig.getInstance().getValue(key, namespace); + callbackContext.success(value.asString()); + } catch (Exception e) { + callbackContext.error(e.getMessage()); + } + } + }); + } + + private void getInfo(final CallbackContext callbackContext) { + cordova.getThreadPool().execute(new Runnable() { + public void run() { + try { + FirebaseRemoteConfigInfo remoteConfigInfo = FirebaseRemoteConfig.getInstance().getInfo(); + JSONObject info = new JSONObject(); + + JSONObject settings = new JSONObject(); + settings.put("developerModeEnabled", remoteConfigInfo.getConfigSettings().isDeveloperModeEnabled()); + info.put("configSettings", settings); + + info.put("fetchTimeMillis", remoteConfigInfo.getFetchTimeMillis()); + info.put("lastFetchStatus", remoteConfigInfo.getLastFetchStatus()); + + callbackContext.success(info); + } catch (Exception e) { + callbackContext.error(e.getMessage()); + } + } + }); + } + + private void setConfigSettings(final CallbackContext callbackContext, final JSONObject config) { + cordova.getThreadPool().execute(new Runnable() { + public void run() { + try { + boolean devMode = config.getBoolean("developerModeEnabled"); + FirebaseRemoteConfigSettings.Builder settings = new FirebaseRemoteConfigSettings.Builder() + .setDeveloperModeEnabled(devMode); + FirebaseRemoteConfig.getInstance().setConfigSettings(settings.build()); + callbackContext.success(); + } catch (Exception e) { + callbackContext.error(e.getMessage()); + } + } + }); + } + + private void setDefaults(final CallbackContext callbackContext, final JSONObject defaults, final String namespace) { + cordova.getThreadPool().execute(new Runnable() { + public void run() { + try { + if (namespace == null) + FirebaseRemoteConfig.getInstance().setDefaults(defaultsToMap(defaults)); + else + FirebaseRemoteConfig.getInstance().setDefaults(defaultsToMap(defaults), namespace); + callbackContext.success(); + } catch (Exception e) { + callbackContext.error(e.getMessage()); + } + } + }); + } + + private static Map<String, Object> defaultsToMap(JSONObject object) throws JSONException { + final Map<String, Object> map = new HashMap<String, Object>(); + + for (Iterator<String> keys = object.keys(); keys.hasNext(); ) { + String key = keys.next(); + Object value = object.get(key); + + if (value instanceof Integer) { + //setDefaults() should take Longs + value = new Long((Integer) value); + } else if (value instanceof JSONArray) { + JSONArray array = (JSONArray) value; + if (array.length() == 1 && array.get(0) instanceof String) { + //parse byte[] as Base64 String + value = Base64.decode(array.getString(0), Base64.DEFAULT); + } else { + //parse byte[] as numeric array + byte[] bytes = new byte[array.length()]; + for (int i = 0; i < array.length(); i++) + bytes[i] = (byte) array.getInt(i); + value = bytes; + } + } + + map.put(key, value); + } + return map; + } +} diff --git a/StoneIsland/platforms/android/src/org/apache/cordova/firebase/FirebasePluginInstanceIDService.java b/StoneIsland/platforms/android/src/org/apache/cordova/firebase/FirebasePluginInstanceIDService.java new file mode 100755 index 00000000..96140f02 --- /dev/null +++ b/StoneIsland/platforms/android/src/org/apache/cordova/firebase/FirebasePluginInstanceIDService.java @@ -0,0 +1,26 @@ +package org.apache.cordova.firebase; + +import android.util.Log; + +import com.google.firebase.iid.FirebaseInstanceId; +import com.google.firebase.iid.FirebaseInstanceIdService; + + +public class FirebasePluginInstanceIDService extends FirebaseInstanceIdService { + + private static final String TAG = "FirebasePlugin"; + + /** + * Called if InstanceID token is updated. This may occur if the security of + * the previous token had been compromised. Note that this is called when the InstanceID token + * is initially generated so this is where you would retrieve the token. + */ + @Override + public void onTokenRefresh() { + // Get updated InstanceID token. + String refreshedToken = FirebaseInstanceId.getInstance().getToken(); + Log.d(TAG, "Refreshed token: " + refreshedToken); + + FirebasePlugin.sendToken(refreshedToken); + } +} diff --git a/StoneIsland/platforms/android/src/org/apache/cordova/firebase/FirebasePluginMessagingService.java b/StoneIsland/platforms/android/src/org/apache/cordova/firebase/FirebasePluginMessagingService.java new file mode 100755 index 00000000..a42ce60e --- /dev/null +++ b/StoneIsland/platforms/android/src/org/apache/cordova/firebase/FirebasePluginMessagingService.java @@ -0,0 +1,127 @@ +package org.apache.cordova.firebase; + +import android.app.NotificationManager; +import android.app.PendingIntent; +import android.content.Context; +import android.content.Intent; +import android.media.RingtoneManager; +import android.net.Uri; +import android.os.Bundle; +import android.support.v4.app.NotificationCompat; +import android.util.Log; +import android.app.Notification; +import android.text.TextUtils; + +import com.google.firebase.messaging.FirebaseMessagingService; +import com.google.firebase.messaging.RemoteMessage; + +import java.util.Map; +import java.util.Random; + +public class FirebasePluginMessagingService extends FirebaseMessagingService { + + private static final String TAG = "FirebasePlugin"; + + /** + * Called when message is received. + * + * @param remoteMessage Object representing the message received from Firebase Cloud Messaging. + */ + @Override + public void onMessageReceived(RemoteMessage remoteMessage) { + // [START_EXCLUDE] + // There are two types of messages data messages and notification messages. Data messages are handled + // here in onMessageReceived whether the app is in the foreground or background. Data messages are the type + // traditionally used with GCM. Notification messages are only received here in onMessageReceived when the app + // is in the foreground. When the app is in the background an automatically generated notification is displayed. + // When the user taps on the notification they are returned to the app. Messages containing both notification + // and data payloads are treated as notification messages. The Firebase console always sends notification + // messages. For more see: https://firebase.google.com/docs/cloud-messaging/concept-options + // [END_EXCLUDE] + + // TODO(developer): Handle FCM messages here. + // Not getting messages here? See why this may be: https://goo.gl/39bRNJ + String title; + String text; + String id; + if (remoteMessage.getNotification() != null) { + title = remoteMessage.getNotification().getTitle(); + text = remoteMessage.getNotification().getBody(); + id = remoteMessage.getMessageId(); + } else { + title = remoteMessage.getData().get("title"); + text = remoteMessage.getData().get("text"); + id = remoteMessage.getData().get("id"); + } + + if(TextUtils.isEmpty(id)){ + Random rand = new Random(); + int n = rand.nextInt(50) + 1; + id = Integer.toString(n); + } + + Log.d(TAG, "From: " + remoteMessage.getFrom()); + Log.d(TAG, "Notification Message id: " + id); + Log.d(TAG, "Notification Message Title: " + title); + Log.d(TAG, "Notification Message Body/Text: " + text); + + // TODO: Add option to developer to configure if show notification when app on foreground + if (!TextUtils.isEmpty(text) || !TextUtils.isEmpty(title) || (!remoteMessage.getData().isEmpty())) { + boolean showNotification = (FirebasePlugin.inBackground() || !FirebasePlugin.hasNotificationsCallback()) && (!TextUtils.isEmpty(text) || !TextUtils.isEmpty(title)); + sendNotification(id, title, text, remoteMessage.getData(), showNotification); + } + } + + private void sendNotification(String id, String title, String messageBody, Map<String, String> data, boolean showNotification) { + Bundle bundle = new Bundle(); + for (String key : data.keySet()) { + bundle.putString(key, data.get(key)); + } + if (showNotification) { + Intent intent = new Intent(this, OnNotificationOpenReceiver.class); + intent.putExtras(bundle); + PendingIntent pendingIntent = PendingIntent.getBroadcast(this, id.hashCode(), intent, + PendingIntent.FLAG_UPDATE_CURRENT); + + Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); + NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this) + .setContentTitle(title) + .setContentText(messageBody) + .setVisibility(NotificationCompat.VISIBILITY_PUBLIC) + .setStyle(new NotificationCompat.BigTextStyle().bigText(messageBody)) + .setAutoCancel(true) + .setSound(defaultSoundUri) + .setContentIntent(pendingIntent); + + int resID = getResources().getIdentifier("notification_icon", "drawable", getPackageName()); + if (resID != 0) { + notificationBuilder.setSmallIcon(resID); + } else { + notificationBuilder.setSmallIcon(getApplicationInfo().icon); + } + + if(android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.M) + { + int accentID = getResources().getIdentifier("accent", "color", getPackageName()); + notificationBuilder.setColor(getResources().getColor(accentID, null)); + } + + Notification notification = notificationBuilder.build(); + if(android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.LOLLIPOP){ + int iconID = android.R.id.icon; + int notiID = getResources().getIdentifier("notification_big", "drawable", getPackageName()); + if (notification.contentView != null) { + notification.contentView.setImageViewResource(iconID, notiID); + } + } + NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); + + notificationManager.notify(id.hashCode(), notification); + } else { + bundle.putBoolean("tap", false); + bundle.putString("title", title); + bundle.putString("body", messageBody); + FirebasePlugin.sendNotification(bundle); + } + } +} diff --git a/StoneIsland/platforms/android/src/org/apache/cordova/firebase/OnNotificationOpenReceiver.java b/StoneIsland/platforms/android/src/org/apache/cordova/firebase/OnNotificationOpenReceiver.java new file mode 100644 index 00000000..a7f63757 --- /dev/null +++ b/StoneIsland/platforms/android/src/org/apache/cordova/firebase/OnNotificationOpenReceiver.java @@ -0,0 +1,24 @@ +package org.apache.cordova.firebase; + +import android.app.PendingIntent; +import android.content.BroadcastReceiver; +import android.content.Context; +import android.content.Intent; +import android.content.pm.PackageManager; +import android.os.Bundle; + +public class OnNotificationOpenReceiver extends BroadcastReceiver { + + @Override + public void onReceive(Context context, Intent intent) { + PackageManager pm = context.getPackageManager(); + Intent launchIntent = pm.getLaunchIntentForPackage(context.getPackageName()); + + launchIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK); + Bundle data = intent.getExtras(); + data.putBoolean("tap", true); + FirebasePlugin.sendNotification(data); + launchIntent.putExtras(data); + context.startActivity(launchIntent); + } +} |
