summaryrefslogtreecommitdiff
path: root/StoneIsland/platforms/android/src/com
diff options
context:
space:
mode:
Diffstat (limited to 'StoneIsland/platforms/android/src/com')
-rw-r--r--StoneIsland/platforms/android/src/com/adobe/phonegap/push/BackgroundActionButtonHandler.java41
-rw-r--r--StoneIsland/platforms/android/src/com/adobe/phonegap/push/GCMIntentService.java802
-rw-r--r--StoneIsland/platforms/android/src/com/adobe/phonegap/push/PermissionUtils.java55
-rw-r--r--StoneIsland/platforms/android/src/com/adobe/phonegap/push/PushConstants.java72
-rw-r--r--StoneIsland/platforms/android/src/com/adobe/phonegap/push/PushHandlerActivity.java120
-rw-r--r--StoneIsland/platforms/android/src/com/adobe/phonegap/push/PushInstanceIDListenerService.java27
-rw-r--r--StoneIsland/platforms/android/src/com/adobe/phonegap/push/PushPlugin.java458
-rw-r--r--StoneIsland/platforms/android/src/com/adobe/phonegap/push/RegistrationIntentService.java38
-rw-r--r--StoneIsland/platforms/android/src/com/pbakondy/Sim.java264
-rw-r--r--StoneIsland/platforms/android/src/com/phonegap/plugin/mobileaccessibility/AbstractMobileAccessibilityHelper.java41
-rw-r--r--StoneIsland/platforms/android/src/com/phonegap/plugin/mobileaccessibility/DonutMobileAccessibilityHelper.java187
-rw-r--r--StoneIsland/platforms/android/src/com/phonegap/plugin/mobileaccessibility/IceCreamSandwichMobileAccessibilityHelper.java104
-rw-r--r--StoneIsland/platforms/android/src/com/phonegap/plugin/mobileaccessibility/JellyBeanMobileAccessibilityHelper.java52
-rw-r--r--StoneIsland/platforms/android/src/com/phonegap/plugin/mobileaccessibility/KitKatMobileAccessibilityHelper.java99
-rw-r--r--StoneIsland/platforms/android/src/com/phonegap/plugin/mobileaccessibility/MobileAccessibility.java330
15 files changed, 0 insertions, 2690 deletions
diff --git a/StoneIsland/platforms/android/src/com/adobe/phonegap/push/BackgroundActionButtonHandler.java b/StoneIsland/platforms/android/src/com/adobe/phonegap/push/BackgroundActionButtonHandler.java
deleted file mode 100644
index 3ccea6cb..00000000
--- a/StoneIsland/platforms/android/src/com/adobe/phonegap/push/BackgroundActionButtonHandler.java
+++ /dev/null
@@ -1,41 +0,0 @@
-package com.adobe.phonegap.push;
-
-import android.app.NotificationManager;
-import android.content.BroadcastReceiver;
-import android.content.Context;
-import android.content.Intent;
-import android.os.Bundle;
-import android.util.Log;
-import android.support.v4.app.RemoteInput;
-
-public class BackgroundActionButtonHandler extends BroadcastReceiver implements PushConstants {
- private static String LOG_TAG = "PushPlugin_BackgroundActionButtonHandler";
-
- @Override
- public void onReceive(Context context, Intent intent) {
- Bundle extras = intent.getExtras();
- Log.d(LOG_TAG, "BackgroundActionButtonHandler = " + extras);
-
- int notId = intent.getIntExtra(NOT_ID, 0);
- Log.d(LOG_TAG, "not id = " + notId);
- NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
- notificationManager.cancel(GCMIntentService.getAppName(context), notId);
-
- if (extras != null) {
- Bundle originalExtras = extras.getBundle(PUSH_BUNDLE);
-
- originalExtras.putBoolean(FOREGROUND, false);
- originalExtras.putBoolean(COLDSTART, false);
- originalExtras.putString(ACTION_CALLBACK, extras.getString(CALLBACK));
-
- Bundle remoteInput = RemoteInput.getResultsFromIntent(intent);
- if (remoteInput != null) {
- String inputString = remoteInput.getCharSequence(INLINE_REPLY).toString();
- Log.d(LOG_TAG, "response: " + inputString);
- originalExtras.putString(INLINE_REPLY, inputString);
- }
-
- PushPlugin.sendExtras(originalExtras);
- }
- }
-}
diff --git a/StoneIsland/platforms/android/src/com/adobe/phonegap/push/GCMIntentService.java b/StoneIsland/platforms/android/src/com/adobe/phonegap/push/GCMIntentService.java
deleted file mode 100644
index e1a2b75c..00000000
--- a/StoneIsland/platforms/android/src/com/adobe/phonegap/push/GCMIntentService.java
+++ /dev/null
@@ -1,802 +0,0 @@
-package com.adobe.phonegap.push;
-
-import android.annotation.SuppressLint;
-import android.app.Notification;
-import android.app.NotificationManager;
-import android.app.PendingIntent;
-import android.content.ContentResolver;
-import android.content.Context;
-import android.content.Intent;
-import android.content.SharedPreferences;
-import android.content.res.AssetManager;
-import android.content.res.Resources;
-import android.graphics.Bitmap;
-import android.graphics.BitmapFactory;
-import android.graphics.Color;
-import android.net.Uri;
-import android.os.Bundle;
-import android.support.v4.app.NotificationCompat;
-import android.support.v4.app.NotificationManagerCompat;
-import android.support.v4.app.NotificationCompat.WearableExtender;
-import android.support.v4.app.RemoteInput;
-import android.text.Html;
-import android.text.Spanned;
-import android.util.Log;
-
-import com.google.android.gms.gcm.GcmListenerService;
-
-import org.json.JSONArray;
-import org.json.JSONException;
-import org.json.JSONObject;
-
-import java.io.IOException;
-import java.io.InputStream;
-import java.net.HttpURLConnection;
-import java.net.URL;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.Random;
-
-@SuppressLint("NewApi")
-public class GCMIntentService extends GcmListenerService implements PushConstants {
-
- private static final String LOG_TAG = "PushPlugin_GCMIntentService";
- private static HashMap<Integer, ArrayList<String>> messageMap = new HashMap<Integer, ArrayList<String>>();
-
- public void setNotification(int notId, String message){
- ArrayList<String> messageList = messageMap.get(notId);
- if(messageList == null) {
- messageList = new ArrayList<String>();
- messageMap.put(notId, messageList);
- }
-
- if(message.isEmpty()){
- messageList.clear();
- }else{
- messageList.add(message);
- }
- }
-
- @Override
- public void onMessageReceived(String from, Bundle extras) {
- Log.d(LOG_TAG, "onMessage - from: " + from);
-
- if (extras != null) {
- Context applicationContext = getApplicationContext();
-
- SharedPreferences prefs = applicationContext.getSharedPreferences(PushPlugin.COM_ADOBE_PHONEGAP_PUSH, Context.MODE_PRIVATE);
- boolean forceShow = prefs.getBoolean(FORCE_SHOW, false);
- boolean clearBadge = prefs.getBoolean(CLEAR_BADGE, false);
-
- extras = normalizeExtras(applicationContext, extras);
-
- if (clearBadge) {
- PushPlugin.setApplicationIconBadgeNumber(getApplicationContext(), 0);
- }
-
- // if we are in the foreground and forceShow is `false` only send data
- if (!forceShow && PushPlugin.isInForeground()) {
- Log.d(LOG_TAG, "foreground");
- extras.putBoolean(FOREGROUND, true);
- extras.putBoolean(COLDSTART, false);
- PushPlugin.sendExtras(extras);
- }
- // if we are in the foreground and forceShow is `true`, force show the notification if the data has at least a message or title
- else if (forceShow && PushPlugin.isInForeground()) {
- Log.d(LOG_TAG, "foreground force");
- extras.putBoolean(FOREGROUND, true);
- extras.putBoolean(COLDSTART, false);
-
- showNotificationIfPossible(applicationContext, extras);
- }
- // if we are not in the foreground always send notification if the data has at least a message or title
- else {
- Log.d(LOG_TAG, "background");
- extras.putBoolean(FOREGROUND, false);
- extras.putBoolean(COLDSTART, PushPlugin.isActive());
-
- showNotificationIfPossible(applicationContext, extras);
- }
- }
- }
-
- /*
- * Change a values key in the extras bundle
- */
- private void replaceKey(Context context, String oldKey, String newKey, Bundle extras, Bundle newExtras) {
- Object value = extras.get(oldKey);
- if ( value != null ) {
- if (value instanceof String) {
- value = localizeKey(context, newKey, (String) value);
-
- newExtras.putString(newKey, (String) value);
- } else if (value instanceof Boolean) {
- newExtras.putBoolean(newKey, (Boolean) value);
- } else if (value instanceof Number) {
- newExtras.putDouble(newKey, ((Number) value).doubleValue());
- } else {
- newExtras.putString(newKey, String.valueOf(value));
- }
- }
- }
-
- /*
- * Normalize localization for key
- */
- private String localizeKey(Context context, String key, String value) {
- if (key.equals(TITLE) || key.equals(MESSAGE) || key.equals(SUMMARY_TEXT)) {
- try {
- JSONObject localeObject = new JSONObject(value);
-
- String localeKey = localeObject.getString(LOC_KEY);
-
- ArrayList<String> localeFormatData = new ArrayList<String>();
- if (!localeObject.isNull(LOC_DATA)) {
- String localeData = localeObject.getString(LOC_DATA);
- JSONArray localeDataArray = new JSONArray(localeData);
- for (int i = 0 ; i < localeDataArray.length(); i++) {
- localeFormatData.add(localeDataArray.getString(i));
- }
- }
-
- String packageName = context.getPackageName();
- Resources resources = context.getResources();
-
- int resourceId = resources.getIdentifier(localeKey, "string", packageName);
-
- if (resourceId != 0) {
- return resources.getString(resourceId, localeFormatData.toArray());
- }
- else {
- Log.d(LOG_TAG, "can't find resource for locale key = " + localeKey);
-
- return value;
- }
- }
- catch(JSONException e) {
- Log.d(LOG_TAG, "no locale found for key = " + key + ", error " + e.getMessage());
-
- return value;
- }
- }
-
- return value;
- }
-
- /*
- * Replace alternate keys with our canonical value
- */
- private String normalizeKey(String key) {
- if (key.equals(BODY) || key.equals(ALERT) || key.equals(GCM_NOTIFICATION_BODY) || key.equals(TWILIO_BODY)) {
- return MESSAGE;
- } else if (key.equals(TWILIO_TITLE)) {
- return TITLE;
- }else if (key.equals(MSGCNT) || key.equals(BADGE)) {
- return COUNT;
- } else if (key.equals(SOUNDNAME) || key.equals(TWILIO_SOUND)) {
- return SOUND;
- } else if (key.startsWith(GCM_NOTIFICATION)) {
- return key.substring(GCM_NOTIFICATION.length()+1, key.length());
- } else if (key.startsWith(GCM_N)) {
- return key.substring(GCM_N.length()+1, key.length());
- } else if (key.startsWith(UA_PREFIX)) {
- key = key.substring(UA_PREFIX.length()+1, key.length());
- return key.toLowerCase();
- } else {
- return key;
- }
- }
-
- /*
- * Parse bundle into normalized keys.
- */
- private Bundle normalizeExtras(Context context, Bundle extras) {
- Log.d(LOG_TAG, "normalize extras");
- Iterator<String> it = extras.keySet().iterator();
- Bundle newExtras = new Bundle();
-
- while (it.hasNext()) {
- String key = it.next();
-
- Log.d(LOG_TAG, "key = " + key);
-
- // If normalizeKeythe key is "data" or "message" and the value is a json object extract
- // This is to support parse.com and other services. Issue #147 and pull #218
- if (key.equals(PARSE_COM_DATA) || key.equals(MESSAGE)) {
- Object json = extras.get(key);
- // Make sure data is json object stringified
- if ( json instanceof String && ((String) json).startsWith("{") ) {
- Log.d(LOG_TAG, "extracting nested message data from key = " + key);
- try {
- // If object contains message keys promote each value to the root of the bundle
- JSONObject data = new JSONObject((String) json);
- if ( data.has(ALERT) || data.has(MESSAGE) || data.has(BODY) || data.has(TITLE) ) {
- Iterator<String> jsonIter = data.keys();
- while (jsonIter.hasNext()) {
- String jsonKey = jsonIter.next();
-
- Log.d(LOG_TAG, "key = data/" + jsonKey);
-
- String value = data.getString(jsonKey);
- jsonKey = normalizeKey(jsonKey);
- value = localizeKey(context, jsonKey, value);
-
- newExtras.putString(jsonKey, value);
- }
- }
- } catch( JSONException e) {
- Log.e(LOG_TAG, "normalizeExtras: JSON exception");
- }
- }
- } else if (key.equals(("notification"))) {
- Bundle value = extras.getBundle(key);
- Iterator<String> iterator = value.keySet().iterator();
- while (iterator.hasNext()) {
- String notifkey = iterator.next();
-
- Log.d(LOG_TAG, "notifkey = " + notifkey);
- String newKey = normalizeKey(notifkey);
- Log.d(LOG_TAG, "replace key " + notifkey + " with " + newKey);
-
- String valueData = value.getString(notifkey);
- valueData = localizeKey(context, newKey, valueData);
-
- newExtras.putString(newKey, valueData);
- }
- continue;
- }
-
- String newKey = normalizeKey(key);
- Log.d(LOG_TAG, "replace key " + key + " with " + newKey);
- replaceKey(context, key, newKey, extras, newExtras);
-
- } // while
-
- return newExtras;
- }
-
- private int extractBadgeCount(Bundle extras) {
- int count = -1;
- String msgcnt = extras.getString(COUNT);
-
- try {
- if (msgcnt != null) {
- count = Integer.parseInt(msgcnt);
- }
- } catch (NumberFormatException e) {
- Log.e(LOG_TAG, e.getLocalizedMessage(), e);
- }
-
- return count;
- }
-
- private void showNotificationIfPossible (Context context, Bundle extras) {
-
- // Send a notification if there is a message or title, otherwise just send data
- String message = extras.getString(MESSAGE);
- String title = extras.getString(TITLE);
- String contentAvailable = extras.getString(CONTENT_AVAILABLE);
- String forceStart = extras.getString(FORCE_START);
- int badgeCount = extractBadgeCount(extras);
- if (badgeCount >= 0) {
- Log.d(LOG_TAG, "count =[" + badgeCount + "]");
- PushPlugin.setApplicationIconBadgeNumber(context, badgeCount);
- }
-
- Log.d(LOG_TAG, "message =[" + message + "]");
- Log.d(LOG_TAG, "title =[" + title + "]");
- Log.d(LOG_TAG, "contentAvailable =[" + contentAvailable + "]");
- Log.d(LOG_TAG, "forceStart =[" + forceStart + "]");
-
- if ((message != null && message.length() != 0) ||
- (title != null && title.length() != 0)) {
-
- Log.d(LOG_TAG, "create notification");
-
- if(title == null || title.isEmpty()){
- extras.putString(TITLE, getAppName(this));
- }
-
- createNotification(context, extras);
- }
-
- if(!PushPlugin.isActive() && "1".equals(forceStart)){
- Log.d(LOG_TAG, "app is not running but we should start it and put in background");
- Intent intent = new Intent(this, PushHandlerActivity.class);
- intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
- intent.putExtra(PUSH_BUNDLE, extras);
- intent.putExtra(START_IN_BACKGROUND, true);
- intent.putExtra(FOREGROUND, false);
- startActivity(intent);
- } else if ("1".equals(contentAvailable)) {
- Log.d(LOG_TAG, "app is not running and content available true");
- Log.d(LOG_TAG, "send notification event");
- PushPlugin.sendExtras(extras);
- }
- }
-
- public void createNotification(Context context, Bundle extras) {
- NotificationManager mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
- String appName = getAppName(this);
- String packageName = context.getPackageName();
- Resources resources = context.getResources();
-
- int notId = parseInt(NOT_ID, extras);
- Intent notificationIntent = new Intent(this, PushHandlerActivity.class);
- notificationIntent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_CLEAR_TOP);
- notificationIntent.putExtra(PUSH_BUNDLE, extras);
- notificationIntent.putExtra(NOT_ID, notId);
-
- int requestCode = new Random().nextInt();
- PendingIntent contentIntent = PendingIntent.getActivity(this, requestCode, notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT);
-
- NotificationCompat.Builder mBuilder =
- new NotificationCompat.Builder(context)
- .setWhen(System.currentTimeMillis())
- .setContentTitle(fromHtml(extras.getString(TITLE)))
- .setTicker(fromHtml(extras.getString(TITLE)))
- .setContentIntent(contentIntent)
- .setAutoCancel(true);
-
- SharedPreferences prefs = context.getSharedPreferences(PushPlugin.COM_ADOBE_PHONEGAP_PUSH, Context.MODE_PRIVATE);
- String localIcon = prefs.getString(ICON, null);
- String localIconColor = prefs.getString(ICON_COLOR, null);
- boolean soundOption = prefs.getBoolean(SOUND, true);
- boolean vibrateOption = prefs.getBoolean(VIBRATE, true);
- Log.d(LOG_TAG, "stored icon=" + localIcon);
- Log.d(LOG_TAG, "stored iconColor=" + localIconColor);
- Log.d(LOG_TAG, "stored sound=" + soundOption);
- Log.d(LOG_TAG, "stored vibrate=" + vibrateOption);
-
- /*
- * Notification Vibration
- */
-
- setNotificationVibration(extras, vibrateOption, mBuilder);
-
- /*
- * Notification Icon Color
- *
- * Sets the small-icon background color of the notification.
- * To use, add the `iconColor` key to plugin android options
- *
- */
- setNotificationIconColor(extras.getString("color"), mBuilder, localIconColor);
-
- /*
- * Notification Icon
- *
- * Sets the small-icon of the notification.
- *
- * - checks the plugin options for `icon` key
- * - if none, uses the application icon
- *
- * The icon value must be a string that maps to a drawable resource.
- * If no resource is found, falls
- *
- */
- setNotificationSmallIcon(context, extras, packageName, resources, mBuilder, localIcon);
-
- /*
- * Notification Large-Icon
- *
- * Sets the large-icon of the notification
- *
- * - checks the gcm data for the `image` key
- * - checks to see if remote image, loads it.
- * - checks to see if assets image, Loads It.
- * - checks to see if resource image, LOADS IT!
- * - if none, we don't set the large icon
- *
- */
- setNotificationLargeIcon(extras, packageName, resources, mBuilder);
-
- /*
- * Notification Sound
- */
- if (soundOption) {
- setNotificationSound(context, extras, mBuilder);
- }
-
- /*
- * LED Notification
- */
- setNotificationLedColor(extras, mBuilder);
-
- /*
- * Priority Notification
- */
- setNotificationPriority(extras, mBuilder);
-
- /*
- * Notification message
- */
- setNotificationMessage(notId, extras, mBuilder);
-
- /*
- * Notification count
- */
- setNotificationCount(context, extras, mBuilder);
-
- /*
- * Notification count
- */
- setVisibility(context, extras, mBuilder);
-
- /*
- * Notification add actions
- */
- createActions(extras, mBuilder, resources, packageName, notId);
-
- mNotificationManager.notify(appName, notId, mBuilder.build());
- }
-
- private void updateIntent(Intent intent, String callback, Bundle extras, boolean foreground, int notId) {
- intent.putExtra(CALLBACK, callback);
- intent.putExtra(PUSH_BUNDLE, extras);
- intent.putExtra(FOREGROUND, foreground);
- intent.putExtra(NOT_ID, notId);
- }
-
- private void createActions(Bundle extras, NotificationCompat.Builder mBuilder, Resources resources, String packageName, int notId) {
- Log.d(LOG_TAG, "create actions: with in-line");
- String actions = extras.getString(ACTIONS);
- if (actions != null) {
- try {
- JSONArray actionsArray = new JSONArray(actions);
- ArrayList<NotificationCompat.Action> wActions = new ArrayList<NotificationCompat.Action>();
- for (int i=0; i < actionsArray.length(); i++) {
- int min = 1;
- int max = 2000000000;
- Random random = new Random();
- int uniquePendingIntentRequestCode = random.nextInt((max - min) + 1) + min;
- Log.d(LOG_TAG, "adding action");
- JSONObject action = actionsArray.getJSONObject(i);
- Log.d(LOG_TAG, "adding callback = " + action.getString(CALLBACK));
- boolean foreground = action.optBoolean(FOREGROUND, true);
- boolean inline = action.optBoolean("inline", false);
- Intent intent = null;
- PendingIntent pIntent = null;
- if (inline) {
- Log.d(LOG_TAG, "Version: " + android.os.Build.VERSION.SDK_INT + " = " + android.os.Build.VERSION_CODES.M);
- if (android.os.Build.VERSION.SDK_INT <= android.os.Build.VERSION_CODES.M) {
- Log.d(LOG_TAG, "push activity");
- intent = new Intent(this, PushHandlerActivity.class);
- } else {
- Log.d(LOG_TAG, "push receiver");
- intent = new Intent(this, BackgroundActionButtonHandler.class);
- }
-
- updateIntent(intent, action.getString(CALLBACK), extras, foreground, notId);
-
- if (android.os.Build.VERSION.SDK_INT <= android.os.Build.VERSION_CODES.M) {
- Log.d(LOG_TAG, "push activity for notId " + notId);
- pIntent = PendingIntent.getActivity(this, uniquePendingIntentRequestCode, intent, PendingIntent.FLAG_ONE_SHOT);
- } else {
- Log.d(LOG_TAG, "push receiver for notId " + notId);
- pIntent = PendingIntent.getBroadcast(this, uniquePendingIntentRequestCode, intent, PendingIntent.FLAG_ONE_SHOT);
- }
- } else if (foreground) {
- intent = new Intent(this, PushHandlerActivity.class);
- updateIntent(intent, action.getString(CALLBACK), extras, foreground, notId);
- pIntent = PendingIntent.getActivity(this, uniquePendingIntentRequestCode, intent, PendingIntent.FLAG_UPDATE_CURRENT);
- } else {
- intent = new Intent(this, BackgroundActionButtonHandler.class);
- updateIntent(intent, action.getString(CALLBACK), extras, foreground, notId);
- pIntent = PendingIntent.getBroadcast(this, uniquePendingIntentRequestCode, intent, PendingIntent.FLAG_UPDATE_CURRENT);
- }
-
- NotificationCompat.Action.Builder actionBuilder =
- new NotificationCompat.Action.Builder(resources.getIdentifier(action.optString(ICON, ""), DRAWABLE, packageName),
- action.getString(TITLE), pIntent);
-
- RemoteInput remoteInput = null;
- if (inline) {
- Log.d(LOG_TAG, "create remote input");
- String replyLabel = "Enter your reply here";
- remoteInput =
- new RemoteInput.Builder(INLINE_REPLY)
- .setLabel(replyLabel)
- .build();
- actionBuilder.addRemoteInput(remoteInput);
- }
-
- NotificationCompat.Action wAction = actionBuilder.build();
- wActions.add(actionBuilder.build());
-
- if (inline) {
- mBuilder.addAction(wAction);
- } else {
- mBuilder.addAction(resources.getIdentifier(action.optString(ICON, ""), DRAWABLE, packageName),
- action.getString(TITLE), pIntent);
- }
- wAction = null;
- pIntent = null;
- }
- mBuilder.extend(new WearableExtender().addActions(wActions));
- wActions.clear();
- } catch(JSONException e) {
- // nope
- }
- }
- }
-
- private void setNotificationCount(Context context, Bundle extras, NotificationCompat.Builder mBuilder) {
- int count = extractBadgeCount(extras);
- if (count >= 0) {
- Log.d(LOG_TAG, "count =[" + count + "]");
- mBuilder.setNumber(count);
- }
- }
-
-
- private void setVisibility(Context context, Bundle extras, NotificationCompat.Builder mBuilder) {
- String visibilityStr = extras.getString(VISIBILITY);
- if (visibilityStr != null) {
- try {
- Integer visibility = Integer.parseInt(visibilityStr);
- if (visibility >= NotificationCompat.VISIBILITY_SECRET && visibility <= NotificationCompat.VISIBILITY_PUBLIC) {
- mBuilder.setVisibility(visibility);
- } else {
- Log.e(LOG_TAG, "Visibility parameter must be between -1 and 1");
- }
- } catch (NumberFormatException e) {
- e.printStackTrace();
- }
- }
- }
-
- private void setNotificationVibration(Bundle extras, Boolean vibrateOption, NotificationCompat.Builder mBuilder) {
- String vibrationPattern = extras.getString(VIBRATION_PATTERN);
- if (vibrationPattern != null) {
- String[] items = vibrationPattern.replaceAll("\\[", "").replaceAll("\\]", "").split(",");
- long[] results = new long[items.length];
- for (int i = 0; i < items.length; i++) {
- try {
- results[i] = Long.parseLong(items[i].trim());
- } catch (NumberFormatException nfe) {}
- }
- mBuilder.setVibrate(results);
- } else {
- if (vibrateOption) {
- mBuilder.setDefaults(Notification.DEFAULT_VIBRATE);
- }
- }
- }
-
- private void setNotificationMessage(int notId, Bundle extras, NotificationCompat.Builder mBuilder) {
- String message = extras.getString(MESSAGE);
-
- String style = extras.getString(STYLE, STYLE_TEXT);
- if(STYLE_INBOX.equals(style)) {
- setNotification(notId, message);
-
- mBuilder.setContentText(fromHtml(message));
-
- ArrayList<String> messageList = messageMap.get(notId);
- Integer sizeList = messageList.size();
- if (sizeList > 1) {
- String sizeListMessage = sizeList.toString();
- String stacking = sizeList + " more";
- if (extras.getString(SUMMARY_TEXT) != null) {
- stacking = extras.getString(SUMMARY_TEXT);
- stacking = stacking.replace("%n%", sizeListMessage);
- }
- NotificationCompat.InboxStyle notificationInbox = new NotificationCompat.InboxStyle()
- .setBigContentTitle(fromHtml(extras.getString(TITLE)))
- .setSummaryText(fromHtml(stacking));
-
- for (int i = messageList.size() - 1; i >= 0; i--) {
- notificationInbox.addLine(fromHtml(messageList.get(i)));
- }
-
- mBuilder.setStyle(notificationInbox);
- } else {
- NotificationCompat.BigTextStyle bigText = new NotificationCompat.BigTextStyle();
- if (message != null) {
- bigText.bigText(fromHtml(message));
- bigText.setBigContentTitle(fromHtml(extras.getString(TITLE)));
- mBuilder.setStyle(bigText);
- }
- }
- } else if (STYLE_PICTURE.equals(style)) {
- setNotification(notId, "");
-
- NotificationCompat.BigPictureStyle bigPicture = new NotificationCompat.BigPictureStyle();
- bigPicture.bigPicture(getBitmapFromURL(extras.getString(PICTURE)));
- bigPicture.setBigContentTitle(fromHtml(extras.getString(TITLE)));
- bigPicture.setSummaryText(fromHtml(extras.getString(SUMMARY_TEXT)));
-
- mBuilder.setContentTitle(fromHtml(extras.getString(TITLE)));
- mBuilder.setContentText(fromHtml(message));
-
- mBuilder.setStyle(bigPicture);
- } else {
- setNotification(notId, "");
-
- NotificationCompat.BigTextStyle bigText = new NotificationCompat.BigTextStyle();
-
- if (message != null) {
- mBuilder.setContentText(fromHtml(message));
-
- bigText.bigText(fromHtml(message));
- bigText.setBigContentTitle(fromHtml(extras.getString(TITLE)));
-
- String summaryText = extras.getString(SUMMARY_TEXT);
- if (summaryText != null) {
- bigText.setSummaryText(fromHtml(summaryText));
- }
-
- mBuilder.setStyle(bigText);
- }
- /*
- else {
- mBuilder.setContentText("<missing message content>");
- }
- */
- }
- }
-
- private void setNotificationSound(Context context, Bundle extras, NotificationCompat.Builder mBuilder) {
- String soundname = extras.getString(SOUNDNAME);
- if (soundname == null) {
- soundname = extras.getString(SOUND);
- }
- if (SOUND_RINGTONE.equals(soundname)) {
- mBuilder.setSound(android.provider.Settings.System.DEFAULT_RINGTONE_URI);
- } else if (soundname != null && !soundname.contentEquals(SOUND_DEFAULT)) {
- Uri sound = Uri.parse(ContentResolver.SCHEME_ANDROID_RESOURCE
- + "://" + context.getPackageName() + "/raw/" + soundname);
- Log.d(LOG_TAG, sound.toString());
- mBuilder.setSound(sound);
- } else {
- mBuilder.setSound(android.provider.Settings.System.DEFAULT_NOTIFICATION_URI);
- }
- }
-
- private void setNotificationLedColor(Bundle extras, NotificationCompat.Builder mBuilder) {
- String ledColor = extras.getString(LED_COLOR);
- if (ledColor != null) {
- // Converts parse Int Array from ledColor
- String[] items = ledColor.replaceAll("\\[", "").replaceAll("\\]", "").split(",");
- int[] results = new int[items.length];
- for (int i = 0; i < items.length; i++) {
- try {
- results[i] = Integer.parseInt(items[i].trim());
- } catch (NumberFormatException nfe) {}
- }
- if (results.length == 4) {
- mBuilder.setLights(Color.argb(results[0], results[1], results[2], results[3]), 500, 500);
- } else {
- Log.e(LOG_TAG, "ledColor parameter must be an array of length == 4 (ARGB)");
- }
- }
- }
-
- private void setNotificationPriority(Bundle extras, NotificationCompat.Builder mBuilder) {
- String priorityStr = extras.getString(PRIORITY);
- if (priorityStr != null) {
- try {
- Integer priority = Integer.parseInt(priorityStr);
- if (priority >= NotificationCompat.PRIORITY_MIN && priority <= NotificationCompat.PRIORITY_MAX) {
- mBuilder.setPriority(priority);
- } else {
- Log.e(LOG_TAG, "Priority parameter must be between -2 and 2");
- }
- } catch (NumberFormatException e) {
- e.printStackTrace();
- }
- }
- }
-
- private void setNotificationLargeIcon(Bundle extras, String packageName, Resources resources, NotificationCompat.Builder mBuilder) {
- String gcmLargeIcon = extras.getString(IMAGE); // from gcm
- if (gcmLargeIcon != null && !"".equals(gcmLargeIcon)) {
- if (gcmLargeIcon.startsWith("http://") || gcmLargeIcon.startsWith("https://")) {
- mBuilder.setLargeIcon(getBitmapFromURL(gcmLargeIcon));
- Log.d(LOG_TAG, "using remote large-icon from gcm");
- } else {
- AssetManager assetManager = getAssets();
- InputStream istr;
- try {
- istr = assetManager.open(gcmLargeIcon);
- Bitmap bitmap = BitmapFactory.decodeStream(istr);
- mBuilder.setLargeIcon(bitmap);
- Log.d(LOG_TAG, "using assets large-icon from gcm");
- } catch (IOException e) {
- int largeIconId = 0;
- largeIconId = resources.getIdentifier(gcmLargeIcon, DRAWABLE, packageName);
- if (largeIconId != 0) {
- Bitmap largeIconBitmap = BitmapFactory.decodeResource(resources, largeIconId);
- mBuilder.setLargeIcon(largeIconBitmap);
- Log.d(LOG_TAG, "using resources large-icon from gcm");
- } else {
- Log.d(LOG_TAG, "Not setting large icon");
- }
- }
- }
- }
- }
-
- private void setNotificationSmallIcon(Context context, Bundle extras, String packageName, Resources resources, NotificationCompat.Builder mBuilder, String localIcon) {
- int iconId = 0;
- String icon = extras.getString(ICON);
- if (icon != null && !"".equals(icon)) {
- iconId = resources.getIdentifier(icon, DRAWABLE, packageName);
- Log.d(LOG_TAG, "using icon from plugin options");
- }
- else if (localIcon != null && !"".equals(localIcon)) {
- iconId = resources.getIdentifier(localIcon, DRAWABLE, packageName);
- Log.d(LOG_TAG, "using icon from plugin options");
- }
- if (iconId == 0) {
- Log.d(LOG_TAG, "no icon resource found - using application icon");
- iconId = context.getApplicationInfo().icon;
- }
- mBuilder.setSmallIcon(iconId);
- }
-
- private void setNotificationIconColor(String color, NotificationCompat.Builder mBuilder, String localIconColor) {
- int iconColor = 0;
- if (color != null && !"".equals(color)) {
- try {
- iconColor = Color.parseColor(color);
- } catch (IllegalArgumentException e) {
- Log.e(LOG_TAG, "couldn't parse color from android options");
- }
- }
- else if (localIconColor != null && !"".equals(localIconColor)) {
- try {
- iconColor = Color.parseColor(localIconColor);
- } catch (IllegalArgumentException e) {
- Log.e(LOG_TAG, "couldn't parse color from android options");
- }
- }
- if (iconColor != 0) {
- mBuilder.setColor(iconColor);
- }
- }
-
- public Bitmap getBitmapFromURL(String strURL) {
- try {
- URL url = new URL(strURL);
- HttpURLConnection connection = (HttpURLConnection) url.openConnection();
- connection.setDoInput(true);
- connection.connect();
- InputStream input = connection.getInputStream();
- return BitmapFactory.decodeStream(input);
- } catch (IOException e) {
- e.printStackTrace();
- return null;
- }
- }
-
- public static String getAppName(Context context) {
- CharSequence appName = context.getPackageManager().getApplicationLabel(context.getApplicationInfo());
- return (String)appName;
- }
-
- private int parseInt(String value, Bundle extras) {
- int retval = 0;
-
- try {
- retval = Integer.parseInt(extras.getString(value));
- }
- catch(NumberFormatException e) {
- Log.e(LOG_TAG, "Number format exception - Error parsing " + value + ": " + e.getMessage());
- }
- catch(Exception e) {
- Log.e(LOG_TAG, "Number format exception - Error parsing " + value + ": " + e.getMessage());
- }
-
- return retval;
- }
-
- private Spanned fromHtml(String source) {
- if (source != null)
- return Html.fromHtml(source);
- else
- return null;
- }
-}
diff --git a/StoneIsland/platforms/android/src/com/adobe/phonegap/push/PermissionUtils.java b/StoneIsland/platforms/android/src/com/adobe/phonegap/push/PermissionUtils.java
deleted file mode 100644
index 6aa5c9bf..00000000
--- a/StoneIsland/platforms/android/src/com/adobe/phonegap/push/PermissionUtils.java
+++ /dev/null
@@ -1,55 +0,0 @@
-package com.adobe.phonegap.push;
-
-import android.content.Context;
-import android.content.pm.ApplicationInfo;
-
-import java.lang.reflect.Field;
-import java.lang.reflect.InvocationTargetException;
-import java.lang.reflect.Method;
-
-public class PermissionUtils {
-
- private static final String CHECK_OP_NO_THROW = "checkOpNoThrow";
-
- public static boolean hasPermission(Context appContext, String appOpsServiceId) throws UnknownError {
-
- ApplicationInfo appInfo = appContext.getApplicationInfo();
-
- String pkg = appContext.getPackageName();
- int uid = appInfo.uid;
- Class appOpsClass = null;
- Object appOps = appContext.getSystemService("appops");
-
- try {
-
- appOpsClass = Class.forName("android.app.AppOpsManager");
-
- Method checkOpNoThrowMethod = appOpsClass.getMethod(
- CHECK_OP_NO_THROW,
- Integer.TYPE,
- Integer.TYPE,
- String.class
- );
-
- Field opValue = appOpsClass.getDeclaredField(appOpsServiceId);
-
- int value = (int) opValue.getInt(Integer.class);
- Object result = checkOpNoThrowMethod.invoke(appOps, value, uid, pkg);
-
- return Integer.parseInt(result.toString()) == 0; // AppOpsManager.MODE_ALLOWED
-
- } catch (ClassNotFoundException e) {
- throw new UnknownError("class not found");
- } catch (NoSuchMethodException e) {
- throw new UnknownError("no such method");
- } catch (NoSuchFieldException e) {
- throw new UnknownError("no such field");
- } catch (InvocationTargetException e) {
- throw new UnknownError("invocation target");
- } catch (IllegalAccessException e) {
- throw new UnknownError("illegal access");
- }
-
- }
-
-}
diff --git a/StoneIsland/platforms/android/src/com/adobe/phonegap/push/PushConstants.java b/StoneIsland/platforms/android/src/com/adobe/phonegap/push/PushConstants.java
deleted file mode 100644
index 37874e04..00000000
--- a/StoneIsland/platforms/android/src/com/adobe/phonegap/push/PushConstants.java
+++ /dev/null
@@ -1,72 +0,0 @@
-package com.adobe.phonegap.push;
-
-public interface PushConstants {
- public static final String COM_ADOBE_PHONEGAP_PUSH = "com.adobe.phonegap.push";
- public static final String REGISTRATION_ID = "registrationId";
- public static final String FOREGROUND = "foreground";
- public static final String TITLE = "title";
- public static final String NOT_ID = "notId";
- public static final String PUSH_BUNDLE = "pushBundle";
- public static final String ICON = "icon";
- public static final String ICON_COLOR = "iconColor";
- public static final String SOUND = "sound";
- public static final String SOUND_DEFAULT = "default";
- public static final String SOUND_RINGTONE = "ringtone";
- public static final String VIBRATE = "vibrate";
- public static final String ACTIONS = "actions";
- public static final String CALLBACK = "callback";
- public static final String ACTION_CALLBACK = "actionCallback";
- public static final String DRAWABLE = "drawable";
- public static final String MSGCNT = "msgcnt";
- public static final String VIBRATION_PATTERN = "vibrationPattern";
- public static final String STYLE = "style";
- public static final String SUMMARY_TEXT = "summaryText";
- public static final String PICTURE = "picture";
- public static final String GCM_N = "gcm.n.";
- public static final String GCM_NOTIFICATION = "gcm.notification";
- public static final String GCM_NOTIFICATION_BODY = "gcm.notification.body";
- public static final String UA_PREFIX = "com.urbanairship.push";
- public static final String PARSE_COM_DATA = "data";
- public static final String ALERT = "alert";
- public static final String MESSAGE = "message";
- public static final String BODY = "body";
- public static final String SOUNDNAME = "soundname";
- public static final String LED_COLOR = "ledColor";
- public static final String PRIORITY = "priority";
- public static final String IMAGE = "image";
- public static final String STYLE_INBOX = "inbox";
- public static final String STYLE_PICTURE = "picture";
- public static final String STYLE_TEXT = "text";
- public static final String BADGE = "badge";
- public static final String INITIALIZE = "init";
- public static final String SUBSCRIBE = "subscribe";
- public static final String UNSUBSCRIBE = "unsubscribe";
- public static final String UNREGISTER = "unregister";
- public static final String EXIT = "exit";
- public static final String FINISH = "finish";
- public static final String HAS_PERMISSION = "hasPermission";
- public static final String ANDROID = "android";
- public static final String SENDER_ID = "senderID";
- public static final String CLEAR_BADGE = "clearBadge";
- public static final String CLEAR_NOTIFICATIONS = "clearNotifications";
- public static final String COLDSTART = "coldstart";
- public static final String ADDITIONAL_DATA = "additionalData";
- public static final String COUNT = "count";
- public static final String FROM = "from";
- public static final String COLLAPSE_KEY = "collapse_key";
- public static final String FORCE_SHOW = "forceShow";
- public static final String GCM = "GCM";
- public static final String CONTENT_AVAILABLE = "content-available";
- public static final String TOPICS = "topics";
- public static final String SET_APPLICATION_ICON_BADGE_NUMBER = "setApplicationIconBadgeNumber";
- public static final String CLEAR_ALL_NOTIFICATIONS = "clearAllNotifications";
- public static final String VISIBILITY = "visibility";
- public static final String INLINE_REPLY = "inlineReply";
- public static final String LOC_KEY = "locKey";
- public static final String LOC_DATA = "locData";
- public static final String TWILIO_BODY = "twi_body";
- public static final String TWILIO_TITLE = "twi_title";
- public static final String TWILIO_SOUND = "twi_sound";
- public static final String START_IN_BACKGROUND = "cdvStartInBackground";
- public static final String FORCE_START = "force-start";
-}
diff --git a/StoneIsland/platforms/android/src/com/adobe/phonegap/push/PushHandlerActivity.java b/StoneIsland/platforms/android/src/com/adobe/phonegap/push/PushHandlerActivity.java
deleted file mode 100644
index 23682ac8..00000000
--- a/StoneIsland/platforms/android/src/com/adobe/phonegap/push/PushHandlerActivity.java
+++ /dev/null
@@ -1,120 +0,0 @@
-package com.adobe.phonegap.push;
-
-import android.app.Activity;
-import android.app.NotificationManager;
-import android.content.Context;
-import android.content.Intent;
-import android.content.pm.PackageManager;
-import android.os.Bundle;
-import android.util.Log;
-import android.support.v4.app.RemoteInput;
-
-
-public class PushHandlerActivity extends Activity implements PushConstants {
- private static String LOG_TAG = "PushPlugin_PushHandlerActivity";
-
- /*
- * this activity will be started if the user touches a notification that we own.
- * We send it's data off to the push plugin for processing.
- * If needed, we boot up the main activity to kickstart the application.
- * @see android.app.Activity#onCreate(android.os.Bundle)
- */
- @Override
- public void onCreate(Bundle savedInstanceState) {
- GCMIntentService gcm = new GCMIntentService();
-
- Intent intent = getIntent();
-
- int notId = intent.getExtras().getInt(NOT_ID, 0);
- Log.d(LOG_TAG, "not id = " + notId);
- gcm.setNotification(notId, "");
- super.onCreate(savedInstanceState);
- Log.v(LOG_TAG, "onCreate");
- String callback = getIntent().getExtras().getString("callback");
- Log.d(LOG_TAG, "callback = " + callback);
- boolean foreground = getIntent().getExtras().getBoolean("foreground", true);
- boolean startOnBackground = getIntent().getExtras().getBoolean(START_IN_BACKGROUND, false);
-
- if(!startOnBackground){
- NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
- notificationManager.cancel(GCMIntentService.getAppName(this), notId);
- }
-
- boolean isPushPluginActive = PushPlugin.isActive();
- boolean inline = processPushBundle(isPushPluginActive, intent);
-
- if(inline && android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.N){
- foreground = true;
- }
-
- Log.d(LOG_TAG, "bringToForeground = " + foreground);
-
- finish();
-
- Log.d(LOG_TAG, "isPushPluginActive = " + isPushPluginActive);
- if (!isPushPluginActive && foreground && inline) {
- Log.d(LOG_TAG, "forceMainActivityReload");
- forceMainActivityReload(false);
- } else if(startOnBackground) {
- Log.d(LOG_TAG, "startOnBackgroundTrue");
- forceMainActivityReload(true);
- } else {
- Log.d(LOG_TAG, "don't want main activity");
- }
- }
-
- /**
- * Takes the pushBundle extras from the intent,
- * and sends it through to the PushPlugin for processing.
- */
- private boolean processPushBundle(boolean isPushPluginActive, Intent intent) {
- Bundle extras = getIntent().getExtras();
- Bundle remoteInput = null;
-
- if (extras != null) {
- Bundle originalExtras = extras.getBundle(PUSH_BUNDLE);
-
- originalExtras.putBoolean(FOREGROUND, false);
- originalExtras.putBoolean(COLDSTART, !isPushPluginActive);
- originalExtras.putString(ACTION_CALLBACK, extras.getString(CALLBACK));
-
- remoteInput = RemoteInput.getResultsFromIntent(intent);
- if (remoteInput != null) {
- String inputString = remoteInput.getCharSequence(INLINE_REPLY).toString();
- Log.d(LOG_TAG, "response: " + inputString);
- originalExtras.putString(INLINE_REPLY, inputString);
- }
-
- PushPlugin.sendExtras(originalExtras);
- }
- return remoteInput == null;
- }
-
- /**
- * Forces the main activity to re-launch if it's unloaded.
- */
- private void forceMainActivityReload(boolean startOnBackground) {
- PackageManager pm = getPackageManager();
- Intent launchIntent = pm.getLaunchIntentForPackage(getApplicationContext().getPackageName());
-
- Bundle extras = getIntent().getExtras();
- if (extras != null) {
- Bundle originalExtras = extras.getBundle(PUSH_BUNDLE);
- if (originalExtras != null) {
- launchIntent.putExtras(originalExtras);
- }
- launchIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
- launchIntent.addFlags(Intent.FLAG_FROM_BACKGROUND);
- launchIntent.putExtra(START_IN_BACKGROUND, startOnBackground);
- }
-
- startActivity(launchIntent);
- }
-
- @Override
- protected void onResume() {
- super.onResume();
- final NotificationManager notificationManager = (NotificationManager) this.getSystemService(Context.NOTIFICATION_SERVICE);
- notificationManager.cancelAll();
- }
-}
diff --git a/StoneIsland/platforms/android/src/com/adobe/phonegap/push/PushInstanceIDListenerService.java b/StoneIsland/platforms/android/src/com/adobe/phonegap/push/PushInstanceIDListenerService.java
deleted file mode 100644
index eaa39a48..00000000
--- a/StoneIsland/platforms/android/src/com/adobe/phonegap/push/PushInstanceIDListenerService.java
+++ /dev/null
@@ -1,27 +0,0 @@
-package com.adobe.phonegap.push;
-
-import android.content.Intent;
-import android.content.Context;
-import android.content.SharedPreferences;
-import android.util.Log;
-
-import com.google.android.gms.iid.InstanceID;
-import com.google.android.gms.iid.InstanceIDListenerService;
-
-import org.json.JSONException;
-
-import java.io.IOException;
-
-public class PushInstanceIDListenerService extends InstanceIDListenerService implements PushConstants {
- public static final String LOG_TAG = "PushPlugin_PushInstanceIDListenerService";
-
- @Override
- public void onTokenRefresh() {
- SharedPreferences sharedPref = getApplicationContext().getSharedPreferences(COM_ADOBE_PHONEGAP_PUSH, Context.MODE_PRIVATE);
- String senderID = sharedPref.getString(SENDER_ID, "");
- if (!"".equals(senderID)) {
- Intent intent = new Intent(this, RegistrationIntentService.class);
- startService(intent);
- }
- }
-}
diff --git a/StoneIsland/platforms/android/src/com/adobe/phonegap/push/PushPlugin.java b/StoneIsland/platforms/android/src/com/adobe/phonegap/push/PushPlugin.java
deleted file mode 100644
index f6faaa2b..00000000
--- a/StoneIsland/platforms/android/src/com/adobe/phonegap/push/PushPlugin.java
+++ /dev/null
@@ -1,458 +0,0 @@
-package com.adobe.phonegap.push;
-
-import android.app.NotificationManager;
-import android.content.Context;
-import android.content.SharedPreferences;
-import android.os.Bundle;
-import android.util.Log;
-
-import com.google.android.gms.gcm.GcmPubSub;
-import com.google.android.gms.iid.InstanceID;
-
-import org.apache.cordova.CallbackContext;
-import org.apache.cordova.CordovaInterface;
-import org.apache.cordova.CordovaPlugin;
-import org.apache.cordova.CordovaWebView;
-import org.apache.cordova.PluginResult;
-import org.json.JSONArray;
-import org.json.JSONException;
-import org.json.JSONObject;
-
-import java.io.IOException;
-import java.util.Collections;
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.ArrayList;
-import java.util.List;
-
-import me.leolin.shortcutbadger.ShortcutBadger;
-
-public class PushPlugin extends CordovaPlugin implements PushConstants {
-
- public static final String LOG_TAG = "PushPlugin";
-
- private static CallbackContext pushContext;
- private static CordovaWebView gWebView;
- private static List<Bundle> gCachedExtras = Collections.synchronizedList(new ArrayList<Bundle>());
- private static boolean gForeground = false;
-
- private static String registration_id = "";
-
- /**
- * Gets the application context from cordova's main activity.
- * @return the application context
- */
- private Context getApplicationContext() {
- return this.cordova.getActivity().getApplicationContext();
- }
-
- @Override
- public boolean execute(final String action, final JSONArray data, final CallbackContext callbackContext) {
- Log.v(LOG_TAG, "execute: action=" + action);
- gWebView = this.webView;
-
- if (INITIALIZE.equals(action)) {
- cordova.getThreadPool().execute(new Runnable() {
- public void run() {
- pushContext = callbackContext;
- JSONObject jo = null;
-
- Log.v(LOG_TAG, "execute: data=" + data.toString());
- SharedPreferences sharedPref = getApplicationContext().getSharedPreferences(COM_ADOBE_PHONEGAP_PUSH, Context.MODE_PRIVATE);
- String senderID = null;
-
- try {
- jo = data.getJSONObject(0).getJSONObject(ANDROID);
-
- Log.v(LOG_TAG, "execute: jo=" + jo.toString());
-
- senderID = jo.getString(SENDER_ID);
-
- Log.v(LOG_TAG, "execute: senderID=" + senderID);
-
- String savedSenderID = sharedPref.getString(SENDER_ID, "");
- registration_id = InstanceID.getInstance(getApplicationContext()).getToken(senderID, GCM);
-
- if (!"".equals(registration_id)) {
- JSONObject json = new JSONObject().put(REGISTRATION_ID, registration_id);
-
- Log.v(LOG_TAG, "onRegistered: " + json.toString());
-
- JSONArray topics = jo.optJSONArray(TOPICS);
- subscribeToTopics(topics, registration_id);
-
- PushPlugin.sendEvent( json );
- } else {
- callbackContext.error("Empty registration ID received from GCM");
- return;
- }
- } catch (JSONException e) {
- Log.e(LOG_TAG, "execute: Got JSON Exception " + e.getMessage());
- callbackContext.error(e.getMessage());
- } catch (IOException e) {
- Log.e(LOG_TAG, "execute: Got JSON Exception " + e.getMessage());
- callbackContext.error(e.getMessage());
- }
-
- if (jo != null) {
- SharedPreferences.Editor editor = sharedPref.edit();
- try {
- editor.putString(ICON, jo.getString(ICON));
- } catch (JSONException e) {
- Log.d(LOG_TAG, "no icon option");
- }
- try {
- editor.putString(ICON_COLOR, jo.getString(ICON_COLOR));
- } catch (JSONException e) {
- Log.d(LOG_TAG, "no iconColor option");
- }
-
- boolean clearBadge = jo.optBoolean(CLEAR_BADGE, false);
- if (clearBadge) {
- setApplicationIconBadgeNumber(getApplicationContext(), 0);
- }
-
- editor.putBoolean(SOUND, jo.optBoolean(SOUND, true));
- editor.putBoolean(VIBRATE, jo.optBoolean(VIBRATE, true));
- editor.putBoolean(CLEAR_BADGE, clearBadge);
- editor.putBoolean(CLEAR_NOTIFICATIONS, jo.optBoolean(CLEAR_NOTIFICATIONS, true));
- editor.putBoolean(FORCE_SHOW, jo.optBoolean(FORCE_SHOW, false));
- editor.putString(SENDER_ID, senderID);
- editor.commit();
-
- }
-
- if (!gCachedExtras.isEmpty()) {
- Log.v(LOG_TAG, "sending cached extras");
- synchronized(gCachedExtras) {
- Iterator<Bundle> gCachedExtrasIterator = gCachedExtras.iterator();
- while (gCachedExtrasIterator.hasNext()) {
- sendExtras(gCachedExtrasIterator.next());
- }
- }
- gCachedExtras.clear();
- }
- }
- });
- } else if (UNREGISTER.equals(action)) {
- cordova.getThreadPool().execute(new Runnable() {
- public void run() {
- try {
- SharedPreferences sharedPref = getApplicationContext().getSharedPreferences(COM_ADOBE_PHONEGAP_PUSH, Context.MODE_PRIVATE);
- JSONArray topics = data.optJSONArray(0);
- if (topics != null && !"".equals(registration_id)) {
- unsubscribeFromTopics(topics, registration_id);
- } else {
- InstanceID.getInstance(getApplicationContext()).deleteInstanceID();
- Log.v(LOG_TAG, "UNREGISTER");
-
- // Remove shared prefs
- SharedPreferences.Editor editor = sharedPref.edit();
- editor.remove(SOUND);
- editor.remove(VIBRATE);
- editor.remove(CLEAR_BADGE);
- editor.remove(CLEAR_NOTIFICATIONS);
- editor.remove(FORCE_SHOW);
- editor.remove(SENDER_ID);
- editor.commit();
- }
-
- callbackContext.success();
- } catch (IOException e) {
- Log.e(LOG_TAG, "execute: Got JSON Exception " + e.getMessage());
- callbackContext.error(e.getMessage());
- }
- }
- });
- } else if (FINISH.equals(action)) {
- callbackContext.success();
- } else if (HAS_PERMISSION.equals(action)) {
- cordova.getThreadPool().execute(new Runnable() {
- public void run() {
- JSONObject jo = new JSONObject();
- try {
- jo.put("isEnabled", PermissionUtils.hasPermission(getApplicationContext(), "OP_POST_NOTIFICATION"));
- PluginResult pluginResult = new PluginResult(PluginResult.Status.OK, jo);
- pluginResult.setKeepCallback(true);
- callbackContext.sendPluginResult(pluginResult);
- } catch (UnknownError e) {
- callbackContext.error(e.getMessage());
- } catch (JSONException e) {
- callbackContext.error(e.getMessage());
- }
- }
- });
- } else if (SET_APPLICATION_ICON_BADGE_NUMBER.equals(action)) {
- cordova.getThreadPool().execute(new Runnable() {
- public void run() {
- Log.v(LOG_TAG, "setApplicationIconBadgeNumber: data=" + data.toString());
- try {
- setApplicationIconBadgeNumber(getApplicationContext(), data.getJSONObject(0).getInt(BADGE));
- } catch (JSONException e) {
- callbackContext.error(e.getMessage());
- }
- callbackContext.success();
- }
- });
- } else if (CLEAR_ALL_NOTIFICATIONS.equals(action)) {
- cordova.getThreadPool().execute(new Runnable() {
- public void run() {
- Log.v(LOG_TAG, "clearAllNotifications");
- clearAllNotifications();
- callbackContext.success();
- }
- });
- } else if (SUBSCRIBE.equals(action)){
- // Subscribing for a topic
- cordova.getThreadPool().execute(new Runnable() {
- public void run() {
- try {
- String topic = data.getString(0);
- subscribeToTopic(topic, registration_id);
- callbackContext.success();
- } catch (JSONException e) {
- callbackContext.error(e.getMessage());
- } catch (IOException e) {
- callbackContext.error(e.getMessage());
- }
- }
- });
- } else if (UNSUBSCRIBE.equals(action)){
- // un-subscribing for a topic
- cordova.getThreadPool().execute(new Runnable(){
- public void run() {
- try {
- String topic = data.getString(0);
- unsubscribeFromTopic(topic, registration_id);
- callbackContext.success();
- } catch (JSONException e) {
- callbackContext.error(e.getMessage());
- } catch (IOException e) {
- callbackContext.error(e.getMessage());
- }
- }
- });
- } else {
- Log.e(LOG_TAG, "Invalid action : " + action);
- callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.INVALID_ACTION));
- return false;
- }
-
- return true;
- }
-
- public static void sendEvent(JSONObject _json) {
- PluginResult pluginResult = new PluginResult(PluginResult.Status.OK, _json);
- pluginResult.setKeepCallback(true);
- if (pushContext != null) {
- pushContext.sendPluginResult(pluginResult);
- }
- }
-
- public static void sendError(String message) {
- PluginResult pluginResult = new PluginResult(PluginResult.Status.ERROR, message);
- pluginResult.setKeepCallback(true);
- if (pushContext != null) {
- pushContext.sendPluginResult(pluginResult);
- }
- }
-
- /*
- * Sends the pushbundle extras to the client application.
- * If the client application isn't currently active, it is cached for later processing.
- */
- public static void sendExtras(Bundle extras) {
- if (extras != null) {
- if (gWebView != null) {
- sendEvent(convertBundleToJson(extras));
- } else {
- Log.v(LOG_TAG, "sendExtras: caching extras to send at a later time.");
- gCachedExtras.add(extras);
- }
- }
- }
-
- public static void setApplicationIconBadgeNumber(Context context, int badgeCount) {
- if (badgeCount > 0) {
- ShortcutBadger.applyCount(context, badgeCount);
- } else {
- ShortcutBadger.removeCount(context);
- }
- }
-
- @Override
- public void initialize(CordovaInterface cordova, CordovaWebView webView) {
- super.initialize(cordova, webView);
- gForeground = true;
- }
-
- @Override
- public void onPause(boolean multitasking) {
- super.onPause(multitasking);
- gForeground = false;
-
- SharedPreferences prefs = getApplicationContext().getSharedPreferences(COM_ADOBE_PHONEGAP_PUSH, Context.MODE_PRIVATE);
- if (prefs.getBoolean(CLEAR_NOTIFICATIONS, true)) {
- clearAllNotifications();
- }
- }
-
- @Override
- public void onResume(boolean multitasking) {
- super.onResume(multitasking);
- gForeground = true;
- }
-
- @Override
- public void onDestroy() {
- super.onDestroy();
- gForeground = false;
- gWebView = null;
- }
-
- private void clearAllNotifications() {
- final NotificationManager notificationManager = (NotificationManager) cordova.getActivity().getSystemService(Context.NOTIFICATION_SERVICE);
- notificationManager.cancelAll();
- }
-
- /**
- * Transform `topic name` to `topic path`
- * Normally, the `topic` inputed from end-user is `topic name` only.
- * We should convert them to GCM `topic path`
- * Example:
- * when topic name = 'my-topic'
- * then topic path = '/topics/my-topic'
- *
- * @param String topic The topic name
- * @return The topic path
- */
- private String getTopicPath(String topic)
- {
- return "/topics/" + topic;
- }
-
- private void subscribeToTopics(JSONArray topics, String registrationToken) throws IOException {
- if (topics != null) {
- String topic = null;
- for (int i=0; i<topics.length(); i++) {
- topic = topics.optString(i, null);
- subscribeToTopic(topic, registrationToken);
- }
- }
- }
-
- private void subscribeToTopic(String topic, String registrationToken) throws IOException
- {
- try {
- if (topic != null) {
- Log.d(LOG_TAG, "Subscribing to topic: " + topic);
- GcmPubSub.getInstance(getApplicationContext()).subscribe(registrationToken, getTopicPath(topic), null);
- }
- } catch (IOException e) {
- Log.e(LOG_TAG, "Failed to subscribe to topic: " + topic, e);
- throw e;
- }
- }
-
- private void unsubscribeFromTopics(JSONArray topics, String registrationToken) {
- if (topics != null) {
- String topic = null;
- for (int i=0; i<topics.length(); i++) {
- try {
- topic = topics.optString(i, null);
- if (topic != null) {
- Log.d(LOG_TAG, "Unsubscribing to topic: " + topic);
- GcmPubSub.getInstance(getApplicationContext()).unsubscribe(registrationToken, getTopicPath(topic));
- }
- } catch (IOException e) {
- Log.e(LOG_TAG, "Failed to unsubscribe to topic: " + topic, e);
- }
- }
- }
- }
-
- private void unsubscribeFromTopic(String topic, String registrationToken) throws IOException
- {
- try {
- if (topic != null) {
- Log.d(LOG_TAG, "Unsubscribing to topic: " + topic);
- GcmPubSub.getInstance(getApplicationContext()).unsubscribe(registrationToken, getTopicPath(topic));
- }
- } catch (IOException e) {
- Log.e(LOG_TAG, "Failed to unsubscribe to topic: " + topic, e);
- throw e;
- }
- }
-
- /*
- * serializes a bundle to JSON.
- */
- private static JSONObject convertBundleToJson(Bundle extras) {
- Log.d(LOG_TAG, "convert extras to json");
- try {
- JSONObject json = new JSONObject();
- JSONObject additionalData = new JSONObject();
-
- // Add any keys that need to be in top level json to this set
- HashSet<String> jsonKeySet = new HashSet();
- Collections.addAll(jsonKeySet, TITLE,MESSAGE,COUNT,SOUND,IMAGE);
-
- Iterator<String> it = extras.keySet().iterator();
- while (it.hasNext()) {
- String key = it.next();
- Object value = extras.get(key);
-
- Log.d(LOG_TAG, "key = " + key);
-
- if (jsonKeySet.contains(key)) {
- json.put(key, value);
- }
- else if (key.equals(COLDSTART)) {
- additionalData.put(key, extras.getBoolean(COLDSTART));
- }
- else if (key.equals(FOREGROUND)) {
- additionalData.put(key, extras.getBoolean(FOREGROUND));
- }
- else if ( value instanceof String ) {
- String strValue = (String)value;
- try {
- // Try to figure out if the value is another JSON object
- if (strValue.startsWith("{")) {
- additionalData.put(key, new JSONObject(strValue));
- }
- // Try to figure out if the value is another JSON array
- else if (strValue.startsWith("[")) {
- additionalData.put(key, new JSONArray(strValue));
- }
- else {
- additionalData.put(key, value);
- }
- } catch (Exception e) {
- additionalData.put(key, value);
- }
- }
- } // while
-
- json.put(ADDITIONAL_DATA, additionalData);
- Log.v(LOG_TAG, "extrasToJSON: " + json.toString());
-
- return json;
- }
- catch( JSONException e) {
- Log.e(LOG_TAG, "extrasToJSON: JSON exception");
- }
- return null;
- }
-
- public static boolean isInForeground() {
- return gForeground;
- }
-
- public static boolean isActive() {
- return gWebView != null;
- }
-
- protected static void setRegistrationID(String token) {
- registration_id = token;
- }
-}
diff --git a/StoneIsland/platforms/android/src/com/adobe/phonegap/push/RegistrationIntentService.java b/StoneIsland/platforms/android/src/com/adobe/phonegap/push/RegistrationIntentService.java
deleted file mode 100644
index b181e88e..00000000
--- a/StoneIsland/platforms/android/src/com/adobe/phonegap/push/RegistrationIntentService.java
+++ /dev/null
@@ -1,38 +0,0 @@
-package com.adobe.phonegap.push;
-
-import android.content.Context;
-
-import android.app.IntentService;
-import android.content.Intent;
-import android.content.SharedPreferences;
-import android.util.Log;
-
-import com.google.android.gms.gcm.GoogleCloudMessaging;
-import com.google.android.gms.iid.InstanceID;
-
-import java.io.IOException;
-
-public class RegistrationIntentService extends IntentService implements PushConstants {
- public static final String LOG_TAG = "PushPlugin_RegistrationIntentService";
-
- public RegistrationIntentService() {
- super(LOG_TAG);
- }
-
- @Override
- protected void onHandleIntent(Intent intent) {
- SharedPreferences sharedPreferences = getApplicationContext().getSharedPreferences(COM_ADOBE_PHONEGAP_PUSH, Context.MODE_PRIVATE);
-
- try {
- InstanceID instanceID = InstanceID.getInstance(this);
- String senderID = sharedPreferences.getString(SENDER_ID, "");
- String token = instanceID.getToken(senderID,
- GoogleCloudMessaging.INSTANCE_ID_SCOPE, null);
- PushPlugin.setRegistrationID(token);
- Log.i(LOG_TAG, "new GCM Registration Token: " + token);
-
- } catch (Exception e) {
- Log.d(LOG_TAG, "Failed to complete token refresh", e);
- }
- }
-}
diff --git a/StoneIsland/platforms/android/src/com/pbakondy/Sim.java b/StoneIsland/platforms/android/src/com/pbakondy/Sim.java
deleted file mode 100644
index df3542f7..00000000
--- a/StoneIsland/platforms/android/src/com/pbakondy/Sim.java
+++ /dev/null
@@ -1,264 +0,0 @@
-// MCC and MNC codes on Wikipedia
-// http://en.wikipedia.org/wiki/Mobile_country_code
-
-// Mobile Network Codes (MNC) for the international identification plan for public networks and subscriptions
-// http://www.itu.int/pub/T-SP-E.212B-2014
-
-// class TelephonyManager
-// http://developer.android.com/reference/android/telephony/TelephonyManager.html
-// https://github.com/android/platform_frameworks_base/blob/master/telephony/java/android/telephony/TelephonyManager.java
-
-// permissions
-// http://developer.android.com/training/permissions/requesting.html
-
-// Multiple SIM Card Support
-// https://developer.android.com/about/versions/android-5.1.html
-
-// class SubscriptionManager
-// https://developer.android.com/reference/android/telephony/SubscriptionManager.html
-// https://github.com/android/platform_frameworks_base/blob/master/telephony/java/android/telephony/SubscriptionManager.java
-
-// class SubscriptionInfo
-// https://developer.android.com/reference/android/telephony/SubscriptionInfo.html
-// https://github.com/android/platform_frameworks_base/blob/master/telephony/java/android/telephony/SubscriptionInfo.java
-
-// Cordova Permissions API
-// https://cordova.apache.org/docs/en/latest/guide/platforms/android/plugin.html#android-permissions
-
-package com.pbakondy;
-
-import org.apache.cordova.CallbackContext;
-import org.apache.cordova.CordovaPlugin;
-import org.apache.cordova.PluginResult;
-import org.apache.cordova.LOG;
-
-import org.json.JSONObject;
-import org.json.JSONArray;
-import org.json.JSONException;
-
-import android.annotation.SuppressLint;
-import android.content.Context;
-import android.content.pm.PackageManager;
-import android.os.Build;
-import android.Manifest;
-
-import android.telephony.SubscriptionInfo;
-import android.telephony.SubscriptionManager;
-import android.telephony.TelephonyManager;
-
-import java.util.List;
-
-public class Sim extends CordovaPlugin {
- private static final String LOG_TAG = "CordovaPluginSim";
-
-
- private static final String GET_SIM_INFO = "getSimInfo";
- private static final String HAS_READ_PERMISSION = "hasReadPermission";
- private static final String REQUEST_READ_PERMISSION = "requestReadPermission";
-
- private CallbackContext callback;
-
- @SuppressLint("HardwareIds")
- @Override
- public boolean execute(String action, JSONArray args, CallbackContext callbackContext) throws JSONException {
- callback = callbackContext;
-
- if (GET_SIM_INFO.equals(action)) {
- Context context = this.cordova.getActivity().getApplicationContext();
-
- TelephonyManager manager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
-
- // dual SIM detection with SubscriptionManager API
- // requires API 22
- // requires permission READ_PHONE_STATE
- JSONArray sims = null;
- Integer phoneCount = null;
- Integer activeSubscriptionInfoCount = null;
- Integer activeSubscriptionInfoCountMax = null;
-
- try {
- // TelephonyManager.getPhoneCount() requires API 23
- if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.M) {
- phoneCount = manager.getPhoneCount();
- }
-
- if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.LOLLIPOP_MR1) {
-
- if (simPermissionGranted(Manifest.permission.READ_PHONE_STATE)) {
-
- SubscriptionManager subscriptionManager = (SubscriptionManager) context.getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
- activeSubscriptionInfoCount = subscriptionManager.getActiveSubscriptionInfoCount();
- activeSubscriptionInfoCountMax = subscriptionManager.getActiveSubscriptionInfoCountMax();
-
- sims = new JSONArray();
-
- List<SubscriptionInfo> subscriptionInfos = subscriptionManager.getActiveSubscriptionInfoList();
- for (SubscriptionInfo subscriptionInfo : subscriptionInfos) {
-
- CharSequence carrierName = subscriptionInfo.getCarrierName();
- String countryIso = subscriptionInfo.getCountryIso();
- int dataRoaming = subscriptionInfo.getDataRoaming(); // 1 is enabled ; 0 is disabled
- CharSequence displayName = subscriptionInfo.getDisplayName();
- String iccId = subscriptionInfo.getIccId();
- int mcc = subscriptionInfo.getMcc();
- int mnc = subscriptionInfo.getMnc();
- String number = subscriptionInfo.getNumber();
- int simSlotIndex = subscriptionInfo.getSimSlotIndex();
- int subscriptionId = subscriptionInfo.getSubscriptionId();
-
- boolean networkRoaming = subscriptionManager.isNetworkRoaming(simSlotIndex);
-
- String deviceId = null;
- // TelephonyManager.getDeviceId(slotId) requires API 23
- if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.M) {
- deviceId = manager.getDeviceId(simSlotIndex);
- }
-
- JSONObject simData = new JSONObject();
-
- simData.put("carrierName", carrierName.toString());
- simData.put("displayName", displayName.toString());
- simData.put("countryCode", countryIso);
- simData.put("mcc", mcc);
- simData.put("mnc", mnc);
- simData.put("isNetworkRoaming", networkRoaming);
- simData.put("isDataRoaming", (dataRoaming == 1));
- simData.put("simSlotIndex", simSlotIndex);
- simData.put("phoneNumber", number);
- if (deviceId != null) {
- simData.put("deviceId", deviceId);
- }
- simData.put("simSerialNumber", iccId);
- simData.put("subscriptionId", subscriptionId);
-
- sims.put(simData);
-
- }
- }
- }
- } catch (JSONException e) {
- e.printStackTrace();
- } catch (Exception e) {
- e.printStackTrace();
- }
-
- String phoneNumber = null;
- String countryCode = manager.getSimCountryIso();
- String simOperator = manager.getSimOperator();
- String carrierName = manager.getSimOperatorName();
-
- String deviceId = null;
- String deviceSoftwareVersion = null;
- String simSerialNumber = null;
- String subscriberId = null;
-
- int callState = manager.getCallState();
- int dataActivity = manager.getDataActivity();
- int networkType = manager.getNetworkType();
- int phoneType = manager.getPhoneType();
- int simState = manager.getSimState();
-
- boolean isNetworkRoaming = manager.isNetworkRoaming();
-
- if (simPermissionGranted(Manifest.permission.READ_PHONE_STATE)) {
- phoneNumber = manager.getLine1Number();
- deviceId = manager.getDeviceId();
- deviceSoftwareVersion = manager.getDeviceSoftwareVersion();
- simSerialNumber = manager.getSimSerialNumber();
- subscriberId = manager.getSubscriberId();
- }
-
- String mcc = "";
- String mnc = "";
-
- if (simOperator.length() >= 3) {
- mcc = simOperator.substring(0, 3);
- mnc = simOperator.substring(3);
- }
-
- JSONObject result = new JSONObject();
-
- result.put("carrierName", carrierName);
- result.put("countryCode", countryCode);
- result.put("mcc", mcc);
- result.put("mnc", mnc);
-
- result.put("callState", callState);
- result.put("dataActivity", dataActivity);
- result.put("networkType", networkType);
- result.put("phoneType", phoneType);
- result.put("simState", simState);
-
- result.put("isNetworkRoaming", isNetworkRoaming);
-
- if (phoneCount != null) {
- result.put("phoneCount", (int)phoneCount);
- }
- if (activeSubscriptionInfoCount != null) {
- result.put("activeSubscriptionInfoCount", (int)activeSubscriptionInfoCount);
- }
- if (activeSubscriptionInfoCountMax != null) {
- result.put("activeSubscriptionInfoCountMax", (int)activeSubscriptionInfoCountMax);
- }
-
- if (simPermissionGranted(Manifest.permission.READ_PHONE_STATE)) {
- result.put("phoneNumber", phoneNumber);
- result.put("deviceId", deviceId);
- result.put("deviceSoftwareVersion", deviceSoftwareVersion);
- result.put("simSerialNumber", simSerialNumber);
- result.put("subscriberId", subscriberId);
- }
-
- if (sims != null && sims.length() != 0) {
- result.put("cards", sims);
- }
-
- callbackContext.success(result);
-
- return true;
- } else if (HAS_READ_PERMISSION.equals(action)) {
- hasReadPermission();
- return true;
- } else if (REQUEST_READ_PERMISSION.equals(action)) {
- requestReadPermission();
- return true;
- } else {
- return false;
- }
- }
-
- private void hasReadPermission() {
- this.callback.sendPluginResult(new PluginResult(PluginResult.Status.OK,
- simPermissionGranted(Manifest.permission.READ_PHONE_STATE)));
- }
-
- private void requestReadPermission() {
- requestPermission(Manifest.permission.READ_PHONE_STATE);
- }
-
- private boolean simPermissionGranted(String type) {
- if (Build.VERSION.SDK_INT < 23) {
- return true;
- }
- return cordova.hasPermission(type);
- }
-
- private void requestPermission(String type) {
- LOG.i(LOG_TAG, "requestPermission");
- if (!simPermissionGranted(type)) {
- cordova.requestPermission(this, 12345, type);
- } else {
- this.callback.success();
- }
- }
-
- @Override
- public void onRequestPermissionResult(int requestCode, String[] permissions, int[] grantResults) throws JSONException
- {
- if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
- this.callback.success();
- } else {
- this.callback.error("Permission denied");
- }
- }
-}
diff --git a/StoneIsland/platforms/android/src/com/phonegap/plugin/mobileaccessibility/AbstractMobileAccessibilityHelper.java b/StoneIsland/platforms/android/src/com/phonegap/plugin/mobileaccessibility/AbstractMobileAccessibilityHelper.java
deleted file mode 100644
index d76a951f..00000000
--- a/StoneIsland/platforms/android/src/com/phonegap/plugin/mobileaccessibility/AbstractMobileAccessibilityHelper.java
+++ /dev/null
@@ -1,41 +0,0 @@
-/**
- *
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- *
-*/
-
-package com.phonegap.plugin.mobileaccessibility;
-
-import android.view.ViewParent;
-
-abstract class AbstractMobileAccessibilityHelper {
- MobileAccessibility mMobileAccessibility;
- ViewParent mParent;
- public abstract void initialize(MobileAccessibility mobileAccessibility);
- public abstract boolean isClosedCaptioningEnabled();
- public abstract boolean isScreenReaderRunning();
- public abstract boolean isTouchExplorationEnabled();
- public abstract void onAccessibilityStateChanged(boolean enabled);
- public abstract void onCaptioningEnabledChanged(boolean enabled);
- public abstract void onTouchExplorationStateChanged(boolean enabled);
- public abstract void addStateChangeListeners();
- public abstract void removeStateChangeListeners();
- public abstract void announceForAccessibility(CharSequence text);
- public abstract double getTextZoom();
- public abstract void setTextZoom(double textZoom);
-}
diff --git a/StoneIsland/platforms/android/src/com/phonegap/plugin/mobileaccessibility/DonutMobileAccessibilityHelper.java b/StoneIsland/platforms/android/src/com/phonegap/plugin/mobileaccessibility/DonutMobileAccessibilityHelper.java
deleted file mode 100644
index e6972719..00000000
--- a/StoneIsland/platforms/android/src/com/phonegap/plugin/mobileaccessibility/DonutMobileAccessibilityHelper.java
+++ /dev/null
@@ -1,187 +0,0 @@
-/**
- *
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- *
-*/
-
-package com.phonegap.plugin.mobileaccessibility;
-
-import android.annotation.TargetApi;
-import android.content.Context;
-import android.os.Build;
-import android.view.accessibility.AccessibilityEvent;
-import android.view.accessibility.AccessibilityManager;
-import android.view.View;
-import android.webkit.WebSettings;
-import android.webkit.WebView;
-
-import java.lang.IllegalAccessException;
-import java.lang.reflect.InvocationTargetException;
-import java.lang.reflect.Method;
-
-@TargetApi(Build.VERSION_CODES.DONUT)
-public class DonutMobileAccessibilityHelper extends
- AbstractMobileAccessibilityHelper {
- AccessibilityManager mAccessibilityManager;
- View mView;
-
- @Override
- public void initialize(MobileAccessibility mobileAccessibility) {
- mMobileAccessibility = mobileAccessibility;
- WebView view;
- try {
- view = (WebView) mobileAccessibility.webView;
- mView = view;
- } catch(ClassCastException ce) { // cordova-android 4.0+
- try {
- Method getView = mobileAccessibility.webView.getClass().getMethod("getView");
- mView = (View) getView.invoke(mobileAccessibility.webView);
- } catch (NoSuchMethodException e) {
- e.printStackTrace();
- } catch (InvocationTargetException e) {
- e.printStackTrace();
- } catch (IllegalAccessException e) {
- e.printStackTrace();
- }
- }
-
- mAccessibilityManager = (AccessibilityManager) mMobileAccessibility.cordova.getActivity().getSystemService(Context.ACCESSIBILITY_SERVICE);
- }
-
- @Override
- public boolean isClosedCaptioningEnabled() {
- return false;
- }
-
- @Override
- public boolean isScreenReaderRunning() {
- return mAccessibilityManager.isEnabled();
- }
-
- @Override
- public boolean isTouchExplorationEnabled() {
- return false;
- }
-
- @Override
- public void onAccessibilityStateChanged(boolean enabled) {
- mMobileAccessibility.onAccessibilityStateChanged(enabled);
- }
-
- @Override
- public void onCaptioningEnabledChanged(boolean enabled) {
- mMobileAccessibility.onCaptioningEnabledChanged(enabled);
- }
-
- @Override
- public void onTouchExplorationStateChanged(boolean enabled) {
- mMobileAccessibility.onTouchExplorationStateChanged(enabled);
- }
-
- @Override
- public void addStateChangeListeners() {
- }
-
- @Override
- public void removeStateChangeListeners() {
- }
-
- @Override
- public void announceForAccessibility(CharSequence text) {
- if (!mAccessibilityManager.isEnabled()) {
- return;
- }
-
- final int eventType = AccessibilityEvent.TYPE_VIEW_FOCUSED;
- final AccessibilityEvent event = AccessibilityEvent.obtain(eventType);
- event.getText().add(text);
- event.setEnabled(mView.isEnabled());
- event.setClassName(mView.getClass().getName());
- event.setPackageName(mView.getContext().getPackageName());
- event.setContentDescription(null);
-
- mAccessibilityManager.sendAccessibilityEvent(event);
- }
-
- @SuppressWarnings("deprecation")
- @Override
- public double getTextZoom() {
- double zoom = 100;
- WebSettings.TextSize wTextSize = WebSettings.TextSize.NORMAL;
-
- try {
- Method getSettings = mView.getClass().getMethod("getSettings");
- Object wSettings = getSettings.invoke(mView);
- Method getTextSize = wSettings.getClass().getMethod("getTextSize");
- wTextSize = (WebSettings.TextSize) getTextSize.invoke(wSettings);
- } catch(ClassCastException ce) {
- ce.printStackTrace();
- } catch (NoSuchMethodException e) {
- e.printStackTrace();
- } catch (InvocationTargetException e) {
- e.printStackTrace();
- } catch (IllegalAccessException e) {
- e.printStackTrace();
- }
-
- switch (wTextSize) {
- case LARGEST:
- zoom = 200;
- break;
- case LARGER:
- zoom = 150;
- break;
- case SMALLER:
- zoom = 75;
- break;
- case SMALLEST:
- zoom = 50;
- break;
- }
-
- return zoom;
- }
-
- @SuppressWarnings("deprecation")
- @Override
- public void setTextZoom(double textZoom) {
- WebSettings.TextSize wTextSize = WebSettings.TextSize.SMALLEST;
- if (textZoom > 115) {
- wTextSize = WebSettings.TextSize.LARGEST;
- } else if (textZoom > 100) {
- wTextSize = WebSettings.TextSize.LARGER;
- } else if (textZoom == 100) {
- wTextSize = WebSettings.TextSize.NORMAL;
- } else if (textZoom > 50) {
- wTextSize = WebSettings.TextSize.SMALLER;
- }
- //Log.i("MobileAccessibility", "fontScale = " + zoom + ", WebSettings.TextSize = " + wTextSize.toString());
- try {
- Method getSettings = mView.getClass().getMethod("getSettings");
- Object wSettings = getSettings.invoke(mView);
- Method setTextSize = wSettings.getClass().getMethod("setTextSize", WebSettings.TextSize.class);
- setTextSize.invoke(wSettings, wTextSize);
- } catch (NoSuchMethodException e) {
- e.printStackTrace();
- } catch (InvocationTargetException e) {
- e.printStackTrace();
- } catch (IllegalAccessException e) {
- e.printStackTrace();
- }
- }
-}
diff --git a/StoneIsland/platforms/android/src/com/phonegap/plugin/mobileaccessibility/IceCreamSandwichMobileAccessibilityHelper.java b/StoneIsland/platforms/android/src/com/phonegap/plugin/mobileaccessibility/IceCreamSandwichMobileAccessibilityHelper.java
deleted file mode 100644
index f0cd252e..00000000
--- a/StoneIsland/platforms/android/src/com/phonegap/plugin/mobileaccessibility/IceCreamSandwichMobileAccessibilityHelper.java
+++ /dev/null
@@ -1,104 +0,0 @@
-/**
- *
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- *
-*/
-
-package com.phonegap.plugin.mobileaccessibility;
-
-import android.accessibilityservice.AccessibilityServiceInfo;
-import android.annotation.TargetApi;
-import android.os.Build;
-import android.view.accessibility.AccessibilityManager.AccessibilityStateChangeListener;
-
-import java.lang.IllegalAccessException;
-import java.lang.reflect.InvocationTargetException;
-import java.lang.reflect.Method;
-
-@TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH)
-public class IceCreamSandwichMobileAccessibilityHelper extends
- DonutMobileAccessibilityHelper {
- private AccessibilityStateChangeListener mAccessibilityStateChangeListener;
-
- @Override
- public boolean isScreenReaderRunning() {
- return mAccessibilityManager.getEnabledAccessibilityServiceList(AccessibilityServiceInfo.FEEDBACK_SPOKEN).size() > 0;
- }
-
- @Override
- public void addStateChangeListeners() {
- if (mAccessibilityStateChangeListener == null) {
- mAccessibilityStateChangeListener = new InternalAccessibilityStateChangeListener();
- }
- mAccessibilityManager.addAccessibilityStateChangeListener(mAccessibilityStateChangeListener);
- }
-
- @Override
- public void removeStateChangeListeners() {
- mAccessibilityManager.removeAccessibilityStateChangeListener(mAccessibilityStateChangeListener);
- mAccessibilityStateChangeListener = null;
- }
-
- @Override
- public double getTextZoom() {
- double zoom = 100;
- try {
- Method getSettings = mView.getClass().getMethod("getSettings");
- Object wSettings = getSettings.invoke(mView);
- Method getTextZoom = wSettings.getClass().getMethod("getTextZoom");
- zoom = Double.valueOf(getTextZoom.invoke(wSettings).toString());
- } catch (ClassCastException ce) {
- ce.printStackTrace();
- } catch (NoSuchMethodException e) {
- e.printStackTrace();
- } catch (InvocationTargetException e) {
- e.printStackTrace();
- } catch (IllegalAccessException e) {
- e.printStackTrace();
- }
- return zoom;
- }
-
- @Override
- public void setTextZoom(double textZoom) {
- //Log.i("MobileAccessibility", "setTextZoom(" + zoom + ")");
- try {
- Method getSettings = mView.getClass().getMethod("getSettings");
- Object wSettings = getSettings.invoke(mView);
- Method setTextZoom = wSettings.getClass().getMethod("setTextZoom", Integer.TYPE);
- setTextZoom.invoke(wSettings, (int) textZoom);
- } catch (ClassCastException ce) {
- ce.printStackTrace();
- } catch (NoSuchMethodException e) {
- e.printStackTrace();
- } catch (InvocationTargetException e) {
- e.printStackTrace();
- } catch (IllegalAccessException e) {
- e.printStackTrace();
- }
- }
-
- private class InternalAccessibilityStateChangeListener
- implements AccessibilityStateChangeListener {
-
- @Override
- public void onAccessibilityStateChanged(boolean enabled) {
- mMobileAccessibility.onAccessibilityStateChanged(enabled);
- }
- }
-}
diff --git a/StoneIsland/platforms/android/src/com/phonegap/plugin/mobileaccessibility/JellyBeanMobileAccessibilityHelper.java b/StoneIsland/platforms/android/src/com/phonegap/plugin/mobileaccessibility/JellyBeanMobileAccessibilityHelper.java
deleted file mode 100644
index 7c97d247..00000000
--- a/StoneIsland/platforms/android/src/com/phonegap/plugin/mobileaccessibility/JellyBeanMobileAccessibilityHelper.java
+++ /dev/null
@@ -1,52 +0,0 @@
-/**
- *
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- *
-*/
-
-package com.phonegap.plugin.mobileaccessibility;
-
-import com.phonegap.plugin.mobileaccessibility.MobileAccessibility;
-
-import android.annotation.TargetApi;
-import android.os.Build;
-import android.view.accessibility.AccessibilityEvent;
-
-@TargetApi(Build.VERSION_CODES.JELLY_BEAN)
-public class JellyBeanMobileAccessibilityHelper extends
- IceCreamSandwichMobileAccessibilityHelper {
-
- @Override
- public void initialize(MobileAccessibility mobileAccessibility) {
- super.initialize(mobileAccessibility);
- mParent = mView.getParentForAccessibility();
- }
-
- @Override
- public void announceForAccessibility(CharSequence text) {
- if (mAccessibilityManager.isEnabled() && mParent != null) {
- mAccessibilityManager.interrupt();
- AccessibilityEvent event = AccessibilityEvent.obtain(
- AccessibilityEvent.TYPE_ANNOUNCEMENT);
- mView.onInitializeAccessibilityEvent(event);
- event.getText().add(text);
- event.setContentDescription(null);
- mParent.requestSendAccessibilityEvent(mView, event);
- }
- }
-}
diff --git a/StoneIsland/platforms/android/src/com/phonegap/plugin/mobileaccessibility/KitKatMobileAccessibilityHelper.java b/StoneIsland/platforms/android/src/com/phonegap/plugin/mobileaccessibility/KitKatMobileAccessibilityHelper.java
deleted file mode 100644
index 11d342cb..00000000
--- a/StoneIsland/platforms/android/src/com/phonegap/plugin/mobileaccessibility/KitKatMobileAccessibilityHelper.java
+++ /dev/null
@@ -1,99 +0,0 @@
-/**
- *
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- *
-*/
-
-package com.phonegap.plugin.mobileaccessibility;
-
-import android.accessibilityservice.AccessibilityServiceInfo;
-import android.annotation.TargetApi;
-import android.content.Context;
-import android.view.accessibility.AccessibilityManager.TouchExplorationStateChangeListener;
-import android.view.accessibility.CaptioningManager;
-import android.view.accessibility.CaptioningManager.CaptioningChangeListener;
-
-@TargetApi(19)
-public class KitKatMobileAccessibilityHelper extends
- JellyBeanMobileAccessibilityHelper {
- private CaptioningManager mCaptioningManager;
- private CaptioningChangeListener mCaptioningChangeListener;
- private TouchExplorationStateChangeListener mTouchExplorationStateChangeListener;
-
- @Override
- public void initialize(MobileAccessibility mobileAccessibility) {
- super.initialize(mobileAccessibility);
- mCaptioningManager = (CaptioningManager) mobileAccessibility.cordova.getActivity().getSystemService(Context.CAPTIONING_SERVICE);
- }
-
- @Override
- public boolean isScreenReaderRunning() {
- return mAccessibilityManager.getEnabledAccessibilityServiceList(AccessibilityServiceInfo.FEEDBACK_BRAILLE | AccessibilityServiceInfo.FEEDBACK_SPOKEN).size() > 0;
- }
-
- @Override
- public boolean isClosedCaptioningEnabled() {
- return mCaptioningManager.isEnabled();
- }
-
- @Override
- public boolean isTouchExplorationEnabled() {
- return mAccessibilityManager.isTouchExplorationEnabled();
- }
-
- @Override
- public void addStateChangeListeners() {
- super.addStateChangeListeners();
- if (mCaptioningChangeListener == null) {
- mCaptioningChangeListener = new CaptioningChangeListener() {
- @Override
- public void onEnabledChanged(boolean enabled) {
- onCaptioningEnabledChanged(enabled);
- }
- };
- }
- mCaptioningManager.addCaptioningChangeListener(mCaptioningChangeListener);
-
- if (mTouchExplorationStateChangeListener == null) {
- mTouchExplorationStateChangeListener = new InternalTouchExplorationStateChangeListener();
- }
- mAccessibilityManager.addTouchExplorationStateChangeListener(mTouchExplorationStateChangeListener);
- }
-
- @Override
- public void removeStateChangeListeners() {
- super.removeStateChangeListeners();
- if (mCaptioningChangeListener != null) {
- mCaptioningManager.removeCaptioningChangeListener(mCaptioningChangeListener);
- mCaptioningChangeListener = null;
- }
- if (mTouchExplorationStateChangeListener != null) {
- mAccessibilityManager.removeTouchExplorationStateChangeListener(mTouchExplorationStateChangeListener);
- mTouchExplorationStateChangeListener = null;
- }
- }
-
- private class InternalTouchExplorationStateChangeListener
- implements TouchExplorationStateChangeListener {
-
- @Override
- public void onTouchExplorationStateChanged(boolean enabled) {
- mMobileAccessibility.onTouchExplorationStateChanged(enabled);
- }
- }
-}
diff --git a/StoneIsland/platforms/android/src/com/phonegap/plugin/mobileaccessibility/MobileAccessibility.java b/StoneIsland/platforms/android/src/com/phonegap/plugin/mobileaccessibility/MobileAccessibility.java
deleted file mode 100644
index a979420e..00000000
--- a/StoneIsland/platforms/android/src/com/phonegap/plugin/mobileaccessibility/MobileAccessibility.java
+++ /dev/null
@@ -1,330 +0,0 @@
-/**
- *
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- *
-*/
-
-package com.phonegap.plugin.mobileaccessibility;
-
-import org.apache.cordova.CallbackContext;
-import org.apache.cordova.CordovaInterface;
-import org.apache.cordova.CordovaPlugin;
-import org.apache.cordova.CordovaWebView;
-import org.apache.cordova.PluginResult;
-import org.json.JSONArray;
-import org.json.JSONException;
-import org.json.JSONObject;
-
-import android.os.Build;
-import android.webkit.WebView;
-
-import java.lang.IllegalAccessException;
-import java.lang.reflect.InvocationTargetException;
-import java.lang.reflect.Method;
-
-/**
- * This class provides information on the status of native accessibility services to JavaScript.
- */
-public class MobileAccessibility extends CordovaPlugin {
- private AbstractMobileAccessibilityHelper mMobileAccessibilityHelper;
- private CallbackContext mCallbackContext = null;
- private boolean mIsScreenReaderRunning = false;
- private boolean mClosedCaptioningEnabled = false;
- private boolean mTouchExplorationEnabled = false;
- private boolean mCachedIsScreenReaderRunning = false;
- private float mFontScale = 1;
-
- @Override
- public void initialize(CordovaInterface cordova, CordovaWebView webView) {
- super.initialize(cordova, webView);
- if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
- mMobileAccessibilityHelper = new KitKatMobileAccessibilityHelper();
- } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
- mMobileAccessibilityHelper = new JellyBeanMobileAccessibilityHelper();
- } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
- mMobileAccessibilityHelper = new IceCreamSandwichMobileAccessibilityHelper();
- } else {
- mMobileAccessibilityHelper = new DonutMobileAccessibilityHelper();
- }
- mMobileAccessibilityHelper.initialize(this);
- }
-
- @Override
- public boolean execute(String action, JSONArray args, CallbackContext callbackContext) throws JSONException {
- try {
- if (action.equals("isScreenReaderRunning")) {
- isScreenReaderRunning(callbackContext);
- return true;
- } else if (action.equals("isClosedCaptioningEnabled")) {
- isClosedCaptioningEnabled(callbackContext);
- return true;
- } else if (action.equals("isTouchExplorationEnabled")) {
- isTouchExplorationEnabled(callbackContext);
- return true;
- } else if (action.equals("postNotification")) {
- if (args.length() > 1) {
- String string = args.getString(1);
- if (!string.isEmpty()) {
- announceForAccessibility(string, callbackContext);
- }
- }
- return true;
- } else if(action.equals("getTextZoom")) {
- getTextZoom(callbackContext);
- return true;
- } else if(action.equals("setTextZoom")) {
- if (args.length() > 0) {
- double textZoom = args.getDouble(0);
- if (textZoom > 0) {
- setTextZoom(textZoom, callbackContext);
- }
- }
- return true;
- } else if(action.equals("updateTextZoom")) {
- updateTextZoom(callbackContext);
- return true;
- } else if (action.equals("start")) {
- start(callbackContext);
- return true;
- } else if (action.equals("stop")) {
- stop();
- return true;
- }
- } catch (JSONException e) {
- e.printStackTrace();
- callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.JSON_EXCEPTION));
- }
- return false;
- }
-
- /**
- * Called when the system is about to pause the current activity
- *
- * @param multitasking Flag indicating if multitasking is turned on for app
- */
- @Override
- public void onPause(boolean multitasking) {
- //Log.i("MobileAccessibility", "onPause");
- mCachedIsScreenReaderRunning = mIsScreenReaderRunning;
- }
-
- /**
- * Called when the activity will start interacting with the user.
- *
- * @param multitasking Flag indicating if multitasking is turned on for app
- */
- @Override
- public void onResume(boolean multitasking) {
- //Log.i("MobileAccessibility", "onResume");
- if (mIsScreenReaderRunning && !mCachedIsScreenReaderRunning) {
- //Log.i("MobileAccessibility", "Reloading page on reload because the Accessibility State has changed.");
- mCachedIsScreenReaderRunning = mIsScreenReaderRunning;
- stop();
- cordova.getActivity().runOnUiThread(new Runnable() {
- public void run() {
- WebView view;
- try {
- view = (WebView) webView;
- view.reload();
- } catch(ClassCastException ce) { // cordova-android 4.0+
- try { // cordova-android 4.0+
- Method getView = webView.getClass().getMethod("getView");
- Method reload = getView.invoke(webView).getClass().getMethod("reload");
- reload.invoke(webView);
- } catch (NoSuchMethodException e) {
- e.printStackTrace();
- } catch (InvocationTargetException e) {
- e.printStackTrace();
- } catch (IllegalAccessException e) {
- e.printStackTrace();
- }
- }
- }
- });
- }
- }
-
- /**
- * The final call you receive before your activity is destroyed.
- */
- public void onDestroy() {
- stop();
- }
-
- private void isScreenReaderRunning(final CallbackContext callbackContext) {
- mIsScreenReaderRunning = mMobileAccessibilityHelper.isScreenReaderRunning();
- cordova.getThreadPool().execute(new Runnable() {
- public void run() {
- callbackContext.success(mIsScreenReaderRunning ? 1 : 0);
- }
- });
- }
-
- protected boolean isScreenReaderRunning() {
- mIsScreenReaderRunning = mMobileAccessibilityHelper.isScreenReaderRunning();
- return mIsScreenReaderRunning;
- }
-
- private void isClosedCaptioningEnabled(final CallbackContext callbackContext) {
- mClosedCaptioningEnabled = mMobileAccessibilityHelper.isClosedCaptioningEnabled();
- cordova.getThreadPool().execute(new Runnable() {
- public void run() {
- callbackContext.success(mClosedCaptioningEnabled ? 1 : 0);
- }
- });
- }
-
- protected boolean isClosedCaptioningEnabled() {
- mClosedCaptioningEnabled = mMobileAccessibilityHelper.isClosedCaptioningEnabled();
- return mClosedCaptioningEnabled;
- }
-
- private void isTouchExplorationEnabled(final CallbackContext callbackContext) {
- mTouchExplorationEnabled= mMobileAccessibilityHelper.isTouchExplorationEnabled();
- cordova.getThreadPool().execute(new Runnable() {
- public void run() {
- callbackContext.success(mTouchExplorationEnabled ? 1 : 0);
- }
- });
- }
-
- protected boolean isTouchExplorationEnabled() {
- mTouchExplorationEnabled = mMobileAccessibilityHelper.isTouchExplorationEnabled();
- return mTouchExplorationEnabled;
- }
-
- private void announceForAccessibility(CharSequence text, final CallbackContext callbackContext) {
- mMobileAccessibilityHelper.announceForAccessibility(text);
- if (callbackContext != null) {
- JSONObject info = new JSONObject();
- try {
- info.put("stringValue", text);
- info.put("wasSuccessful", mIsScreenReaderRunning);
- } catch (JSONException e) {
- e.printStackTrace();
- }
- callbackContext.success(info);
- }
- }
-
- public void onAccessibilityStateChanged(boolean enabled) {
- mIsScreenReaderRunning = enabled;
- cordova.getActivity().runOnUiThread(new Runnable() {
- public void run() {
- sendMobileAccessibilityStatusChangedCallback();
- }
- });
- }
-
- public void onCaptioningEnabledChanged(boolean enabled) {
- mClosedCaptioningEnabled = enabled;
- cordova.getActivity().runOnUiThread(new Runnable() {
- public void run() {
- sendMobileAccessibilityStatusChangedCallback();
- }
- });
- }
-
- public void onTouchExplorationStateChanged(boolean enabled) {
- mTouchExplorationEnabled = enabled;
- cordova.getActivity().runOnUiThread(new Runnable() {
- public void run() {
- sendMobileAccessibilityStatusChangedCallback();
- }
- });
- }
-
- private void getTextZoom(final CallbackContext callbackContext) {
- cordova.getActivity().runOnUiThread(new Runnable() {
- public void run() {
- final double textZoom = mMobileAccessibilityHelper.getTextZoom();
- if (callbackContext != null) {
- callbackContext.success((int) textZoom);
- }
- }
- });
- }
-
- private void setTextZoom(final double textZoom, final CallbackContext callbackContext) {
- cordova.getActivity().runOnUiThread(new Runnable() {
- public void run() {
- mMobileAccessibilityHelper.setTextZoom(textZoom);
- if (callbackContext != null) {
- callbackContext.success((int) mMobileAccessibilityHelper.getTextZoom());
- }
- }
- });
- }
-
- public void setTextZoom(final double textZoom) {
- cordova.getActivity().runOnUiThread(new Runnable() {
- public void run() {
- mMobileAccessibilityHelper.setTextZoom(textZoom);
- }
- });
- }
-
- private void updateTextZoom(final CallbackContext callbackContext) {
- float fontScale = cordova.getActivity().getResources().getConfiguration().fontScale;
- if (fontScale != mFontScale) {
- mFontScale = fontScale;
- }
- final double textZoom = Math.round(mFontScale * 100);
- setTextZoom(textZoom, callbackContext);
- }
-
- private void sendMobileAccessibilityStatusChangedCallback() {
- if (this.mCallbackContext != null) {
- PluginResult result = new PluginResult(PluginResult.Status.OK, getMobileAccessibilityStatus());
- result.setKeepCallback(true);
- this.mCallbackContext.sendPluginResult(result);
- }
- }
-
- /* Get the current mobile accessibility status. */
- private JSONObject getMobileAccessibilityStatus() {
- JSONObject status = new JSONObject();
- try {
- status.put("isScreenReaderRunning", mIsScreenReaderRunning);
- status.put("isClosedCaptioningEnabled", mClosedCaptioningEnabled);
- status.put("isTouchExplorationEnabled", mTouchExplorationEnabled);
- //Log.i("MobileAccessibility", "MobileAccessibility.isScreenReaderRunning == " + status.getString("isScreenReaderRunning") +
- // "\nMobileAccessibility.isClosedCaptioningEnabled == " + status.getString("isClosedCaptioningEnabled") +
- // "\nMobileAccessibility.isTouchExplorationEnabled == " + status.getString("isTouchExplorationEnabled") );
- } catch (JSONException e) {
- e.printStackTrace();
- }
- return status;
- }
-
- private void start(CallbackContext callbackContext) {
- //Log.i("MobileAccessibility", "MobileAccessibility.start");
- mCallbackContext = callbackContext;
- mMobileAccessibilityHelper.addStateChangeListeners();
- sendMobileAccessibilityStatusChangedCallback();
- }
-
- private void stop() {
- //Log.i("MobileAccessibility", "MobileAccessibility.stop");
- if (mCallbackContext != null) {
- sendMobileAccessibilityStatusChangedCallback();
- mMobileAccessibilityHelper.removeStateChangeListeners();
- mCallbackContext = null;
- }
- }
-}