diff options
| author | Jules Laplace <julescarbon@gmail.com> | 2020-08-31 22:37:03 +0200 |
|---|---|---|
| committer | Jules Laplace <julescarbon@gmail.com> | 2020-08-31 22:37:03 +0200 |
| commit | d22d51a1ae49680015326857360eb699f31efced (patch) | |
| tree | 43ac5007de26848f516b37b863daeb77f86d97d2 /StoneIsland/platforms/android/src | |
| parent | a81d20bc18d002623fc24cdcea8df7eed6d85bc9 (diff) | |
NO MORE ANDROID BUILD
Diffstat (limited to 'StoneIsland/platforms/android/src')
31 files changed, 0 insertions, 7033 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; - } - } -} diff --git a/StoneIsland/platforms/android/src/io/ionic/keyboard/IonicKeyboard.java b/StoneIsland/platforms/android/src/io/ionic/keyboard/IonicKeyboard.java deleted file mode 100644 index 128063b9..00000000 --- a/StoneIsland/platforms/android/src/io/ionic/keyboard/IonicKeyboard.java +++ /dev/null @@ -1,130 +0,0 @@ -package io.ionic.keyboard; - -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.apache.cordova.PluginResult.Status; -import org.json.JSONArray; -import org.json.JSONException; - -import android.content.Context; -import android.graphics.Rect; -import android.util.DisplayMetrics; -import android.view.View; -import android.view.ViewTreeObserver.OnGlobalLayoutListener; -import android.view.inputmethod.InputMethodManager; - -// import additionally required classes for calculating screen height -import android.view.Display; -import android.graphics.Point; -import android.os.Build; - -public class IonicKeyboard extends CordovaPlugin { - - public void initialize(CordovaInterface cordova, CordovaWebView webView) { - super.initialize(cordova, webView); - } - - public boolean execute(String action, JSONArray args, final CallbackContext callbackContext) throws JSONException { - if ("close".equals(action)) { - cordova.getThreadPool().execute(new Runnable() { - public void run() { - //http://stackoverflow.com/a/7696791/1091751 - InputMethodManager inputManager = (InputMethodManager) cordova.getActivity().getSystemService(Context.INPUT_METHOD_SERVICE); - View v = cordova.getActivity().getCurrentFocus(); - - if (v == null) { - callbackContext.error("No current focus"); - } else { - inputManager.hideSoftInputFromWindow(v.getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS); - callbackContext.success(); // Thread-safe. - } - } - }); - return true; - } - if ("show".equals(action)) { - cordova.getThreadPool().execute(new Runnable() { - public void run() { - ((InputMethodManager) cordova.getActivity().getSystemService(Context.INPUT_METHOD_SERVICE)).toggleSoftInput(0, InputMethodManager.HIDE_IMPLICIT_ONLY); - callbackContext.success(); // Thread-safe. - } - }); - return true; - } - if ("init".equals(action)) { - cordova.getThreadPool().execute(new Runnable() { - public void run() { - //calculate density-independent pixels (dp) - //http://developer.android.com/guide/practices/screens_support.html - DisplayMetrics dm = new DisplayMetrics(); - cordova.getActivity().getWindowManager().getDefaultDisplay().getMetrics(dm); - final float density = dm.density; - - //http://stackoverflow.com/a/4737265/1091751 detect if keyboard is showing - final View rootView = cordova.getActivity().getWindow().getDecorView().findViewById(android.R.id.content).getRootView(); - OnGlobalLayoutListener list = new OnGlobalLayoutListener() { - int previousHeightDiff = 0; - @Override - public void onGlobalLayout() { - Rect r = new Rect(); - //r will be populated with the coordinates of your view that area still visible. - rootView.getWindowVisibleDisplayFrame(r); - - PluginResult result; - - // cache properties for later use - int rootViewHeight = rootView.getRootView().getHeight(); - int resultBottom = r.bottom; - - // calculate screen height differently for android versions >= 21: Lollipop 5.x, Marshmallow 6.x - //http://stackoverflow.com/a/29257533/3642890 beware of nexus 5 - int screenHeight; - - if (Build.VERSION.SDK_INT >= 21) { - Display display = cordova.getActivity().getWindowManager().getDefaultDisplay(); - Point size = new Point(); - display.getSize(size); - screenHeight = size.y; - } else { - screenHeight = rootViewHeight; - } - - int heightDiff = screenHeight - resultBottom; - - int pixelHeightDiff = (int)(heightDiff / density); - if (pixelHeightDiff > 100 && pixelHeightDiff != previousHeightDiff) { // if more than 100 pixels, its probably a keyboard... - String msg = "S" + Integer.toString(pixelHeightDiff); - result = new PluginResult(PluginResult.Status.OK, msg); - result.setKeepCallback(true); - callbackContext.sendPluginResult(result); - } - else if ( pixelHeightDiff != previousHeightDiff && ( previousHeightDiff - pixelHeightDiff ) > 100 ){ - String msg = "H"; - result = new PluginResult(PluginResult.Status.OK, msg); - result.setKeepCallback(true); - callbackContext.sendPluginResult(result); - } - previousHeightDiff = pixelHeightDiff; - } - }; - - rootView.getViewTreeObserver().addOnGlobalLayoutListener(list); - - - PluginResult dataResult = new PluginResult(PluginResult.Status.OK); - dataResult.setKeepCallback(true); - callbackContext.sendPluginResult(dataResult); - } - }); - return true; - } - return false; // Returning false results in a "MethodNotFound" error. - } - - -} - - diff --git a/StoneIsland/platforms/android/src/nl/xservices/plugins/LaunchMyApp.java b/StoneIsland/platforms/android/src/nl/xservices/plugins/LaunchMyApp.java deleted file mode 100644 index 3a52d287..00000000 --- a/StoneIsland/platforms/android/src/nl/xservices/plugins/LaunchMyApp.java +++ /dev/null @@ -1,173 +0,0 @@ -package nl.xservices.plugins; - -import android.content.Intent; -import org.apache.cordova.CallbackContext; -import org.apache.cordova.CordovaActivity; -import org.apache.cordova.CordovaPlugin; -import org.apache.cordova.CordovaInterface; -import org.apache.cordova.CordovaWebView; -import org.apache.cordova.PluginResult; -import org.json.JSONArray; -import org.json.JSONException; - -import java.io.IOException; -import java.io.StringWriter; -import java.io.Writer; -import java.util.Locale; - -public class LaunchMyApp extends CordovaPlugin { - - private static final String ACTION_CHECKINTENT = "checkIntent"; - private static final String ACTION_CLEARINTENT = "clearIntent"; - private static final String ACTION_GETLASTINTENT = "getLastIntent"; - - private String lastIntentString = null; - - /** - * We don't want to interfere with other plugins requiring the intent data, - * but in case of a multi-page app your app may receive the same intent data - * multiple times, that's why you'll get an option to reset it (null it). - * - * Add this to config.xml to enable that behaviour (default false): - * <preference name="CustomURLSchemePluginClearsAndroidIntent" value="true"/> - */ - private boolean resetIntent; - - @Override - public void initialize(final CordovaInterface cordova, CordovaWebView webView){ - this.resetIntent = preferences.getBoolean("resetIntent", false) || - preferences.getBoolean("CustomURLSchemePluginClearsAndroidIntent", false); - } - - @Override - public boolean execute(String action, JSONArray args, CallbackContext callbackContext) throws JSONException { - if (ACTION_CLEARINTENT.equalsIgnoreCase(action)) { - final Intent intent = ((CordovaActivity) this.webView.getContext()).getIntent(); - if (resetIntent){ - intent.setData(null); - } - return true; - } else if (ACTION_CHECKINTENT.equalsIgnoreCase(action)) { - final Intent intent = ((CordovaActivity) this.webView.getContext()).getIntent(); - final String intentString = intent.getDataString(); - if (intentString != null && intent.getScheme() != null) { - lastIntentString = intentString; - callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK, intent.getDataString())); - } else { - callbackContext.error("App was not started via the launchmyapp URL scheme. Ignoring this errorcallback is the best approach."); - } - return true; - } else if (ACTION_GETLASTINTENT.equalsIgnoreCase(action)) { - if(lastIntentString != null) { - callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK, lastIntentString)); - } else { - callbackContext.error("No intent received so far."); - } - return true; - } else { - callbackContext.error("This plugin only responds to the " + ACTION_CHECKINTENT + " action."); - return false; - } - } - - @Override - public void onNewIntent(Intent intent) { - final String intentString = intent.getDataString(); - if (intentString != null && intent.getScheme() != null) { - if (resetIntent){ - intent.setData(null); - } - try { - StringWriter writer = new StringWriter(intentString.length() * 2); - escapeJavaStyleString(writer, intentString, true, false); - webView.loadUrl("javascript:handleOpenURL('" + writer.toString() + "');"); - } catch (IOException ignore) { - } - } - } - - // Taken from commons StringEscapeUtils - private static void escapeJavaStyleString(Writer out, String str, boolean escapeSingleQuote, - boolean escapeForwardSlash) throws IOException { - if (out == null) { - throw new IllegalArgumentException("The Writer must not be null"); - } - if (str == null) { - return; - } - int sz; - sz = str.length(); - for (int i = 0; i < sz; i++) { - char ch = str.charAt(i); - - // handle unicode - if (ch > 0xfff) { - out.write("\\u" + hex(ch)); - } else if (ch > 0xff) { - out.write("\\u0" + hex(ch)); - } else if (ch > 0x7f) { - out.write("\\u00" + hex(ch)); - } else if (ch < 32) { - switch (ch) { - case '\b': - out.write('\\'); - out.write('b'); - break; - case '\n': - out.write('\\'); - out.write('n'); - break; - case '\t': - out.write('\\'); - out.write('t'); - break; - case '\f': - out.write('\\'); - out.write('f'); - break; - case '\r': - out.write('\\'); - out.write('r'); - break; - default: - if (ch > 0xf) { - out.write("\\u00" + hex(ch)); - } else { - out.write("\\u000" + hex(ch)); - } - break; - } - } else { - switch (ch) { - case '\'': - if (escapeSingleQuote) { - out.write('\\'); - } - out.write('\''); - break; - case '"': - out.write('\\'); - out.write('"'); - break; - case '\\': - out.write('\\'); - out.write('\\'); - break; - case '/': - if (escapeForwardSlash) { - out.write('\\'); - } - out.write('/'); - break; - default: - out.write(ch); - break; - } - } - } - } - - private static String hex(char ch) { - return Integer.toHexString(ch).toUpperCase(Locale.ENGLISH); - } -} diff --git a/StoneIsland/platforms/android/src/nl/xservices/plugins/SocialSharing.java b/StoneIsland/platforms/android/src/nl/xservices/plugins/SocialSharing.java deleted file mode 100644 index 8de31da8..00000000 --- a/StoneIsland/platforms/android/src/nl/xservices/plugins/SocialSharing.java +++ /dev/null @@ -1,775 +0,0 @@ -package nl.xservices.plugins; - -import android.annotation.SuppressLint; -import android.app.Activity; -import android.content.*; -import android.content.pm.ActivityInfo; -import android.content.pm.PackageManager; -import android.content.pm.ResolveInfo; -import android.net.Uri; -import android.os.Build; -import android.os.Environment; -import android.text.Html; -import android.util.Base64; -import android.view.Gravity; -import android.widget.Toast; - -import org.apache.cordova.CallbackContext; -import org.apache.cordova.CordovaInterface; -import org.apache.cordova.CordovaPlugin; -import org.apache.cordova.PluginResult; -import org.json.JSONArray; -import org.json.JSONException; -import org.json.JSONObject; - -import java.io.*; -import java.net.URL; -import java.net.URLConnection; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Timer; -import java.util.TimerTask; -import java.util.regex.Matcher; -import java.util.regex.Pattern; - -public class SocialSharing extends CordovaPlugin { - - private static final String ACTION_AVAILABLE_EVENT = "available"; - private static final String ACTION_SHARE_EVENT = "share"; - private static final String ACTION_SHARE_WITH_OPTIONS_EVENT = "shareWithOptions"; - private static final String ACTION_CAN_SHARE_VIA = "canShareVia"; - private static final String ACTION_CAN_SHARE_VIA_EMAIL = "canShareViaEmail"; - private static final String ACTION_SHARE_VIA = "shareVia"; - private static final String ACTION_SHARE_VIA_TWITTER_EVENT = "shareViaTwitter"; - private static final String ACTION_SHARE_VIA_FACEBOOK_EVENT = "shareViaFacebook"; - private static final String ACTION_SHARE_VIA_FACEBOOK_WITH_PASTEMESSAGEHINT = "shareViaFacebookWithPasteMessageHint"; - private static final String ACTION_SHARE_VIA_WHATSAPP_EVENT = "shareViaWhatsApp"; - private static final String ACTION_SHARE_VIA_INSTAGRAM_EVENT = "shareViaInstagram"; - private static final String ACTION_SHARE_VIA_SMS_EVENT = "shareViaSMS"; - private static final String ACTION_SHARE_VIA_EMAIL_EVENT = "shareViaEmail"; - - private static final int ACTIVITY_CODE_SEND__BOOLRESULT = 1; - private static final int ACTIVITY_CODE_SEND__OBJECT = 2; - private static final int ACTIVITY_CODE_SENDVIAEMAIL = 3; - private static final int ACTIVITY_CODE_SENDVIAWHATSAPP = 4; - - private CallbackContext _callbackContext; - - private String pasteMessage; - - private abstract class SocialSharingRunnable implements Runnable { - public CallbackContext callbackContext; - - SocialSharingRunnable(CallbackContext cb) { - this.callbackContext = cb; - } - } - - @Override - public boolean execute(String action, JSONArray args, CallbackContext callbackContext) throws JSONException { - this._callbackContext = callbackContext; // only used for onActivityResult - this.pasteMessage = null; - if (ACTION_AVAILABLE_EVENT.equals(action)) { - callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK)); - return true; - } else if (ACTION_SHARE_EVENT.equals(action)) { - return doSendIntent(callbackContext, args.getString(0), args.getString(1), args.getJSONArray(2), args.getString(3), null, null, false, true); - } else if (ACTION_SHARE_WITH_OPTIONS_EVENT.equals(action)) { - return shareWithOptions(callbackContext, args.getJSONObject(0)); - } else if (ACTION_SHARE_VIA_TWITTER_EVENT.equals(action)) { - return doSendIntent(callbackContext, args.getString(0), args.getString(1), args.getJSONArray(2), args.getString(3), "twitter", null, false, true); - } else if (ACTION_SHARE_VIA_FACEBOOK_EVENT.equals(action)) { - return doSendIntent(callbackContext, args.getString(0), args.getString(1), args.getJSONArray(2), args.getString(3), "com.facebook.katana", null, false, true); - } else if (ACTION_SHARE_VIA_FACEBOOK_WITH_PASTEMESSAGEHINT.equals(action)) { - this.pasteMessage = args.getString(4); - return doSendIntent(callbackContext, args.getString(0), args.getString(1), args.getJSONArray(2), args.getString(3), "com.facebook.katana", null, false, true); - } else if (ACTION_SHARE_VIA_WHATSAPP_EVENT.equals(action)) { - if (notEmpty(args.getString(4))) { - return shareViaWhatsAppDirectly(callbackContext, args.getString(0), args.getString(1), args.getJSONArray(2), args.getString(3), args.getString(4)); - } else { - return doSendIntent(callbackContext, args.getString(0), args.getString(1), args.getJSONArray(2), args.getString(3), "whatsapp", null, false, true); - } - } else if (ACTION_SHARE_VIA_INSTAGRAM_EVENT.equals(action)) { - if (notEmpty(args.getString(0))) { - copyHintToClipboard(args.getString(0), "Instagram paste message"); - } - return doSendIntent(callbackContext, args.getString(0), args.getString(1), args.getJSONArray(2), args.getString(3), "instagram", null, false, true); - } else if (ACTION_CAN_SHARE_VIA.equals(action)) { - return doSendIntent(callbackContext, args.getString(0), args.getString(1), args.getJSONArray(2), args.getString(3), args.getString(4), null, true, true); - } else if (ACTION_CAN_SHARE_VIA_EMAIL.equals(action)) { - if (isEmailAvailable()) { - callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK)); - return true; - } else { - callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.ERROR, "not available")); - return false; - } - } else if (ACTION_SHARE_VIA.equals(action)) { - return doSendIntent(callbackContext, args.getString(0), args.getString(1), args.getJSONArray(2), args.getString(3), args.getString(4), null, false, true); - } else if (ACTION_SHARE_VIA_SMS_EVENT.equals(action)) { - return invokeSMSIntent(callbackContext, args.getJSONObject(0), args.getString(1)); - } else if (ACTION_SHARE_VIA_EMAIL_EVENT.equals(action)) { - return invokeEmailIntent(callbackContext, args.getString(0), args.getString(1), args.getJSONArray(2), args.isNull(3) ? null : args.getJSONArray(3), args.isNull(4) ? null : args.getJSONArray(4), args.isNull(5) ? null : args.getJSONArray(5)); - } else { - callbackContext.error("socialSharing." + action + " is not a supported function. Did you mean '" + ACTION_SHARE_EVENT + "'?"); - return false; - } - } - - private boolean isEmailAvailable() { - final Intent intent = new Intent(Intent.ACTION_SENDTO, Uri.fromParts("mailto", "someone@domain.com", null)); - return cordova.getActivity().getPackageManager().queryIntentActivities(intent, 0).size() > 0; - } - - private boolean invokeEmailIntent(final CallbackContext callbackContext, final String message, final String subject, final JSONArray to, final JSONArray cc, final JSONArray bcc, final JSONArray files) throws JSONException { - - final SocialSharing plugin = this; - cordova.getThreadPool().execute(new SocialSharingRunnable(callbackContext) { - public void run() { - final Intent draft = new Intent(Intent.ACTION_SEND_MULTIPLE); - if (notEmpty(message)) { - Pattern htmlPattern = Pattern.compile(".*\\<[^>]+>.*", Pattern.DOTALL); - if (htmlPattern.matcher(message).matches()) { - draft.putExtra(android.content.Intent.EXTRA_TEXT, Html.fromHtml(message)); - draft.setType("text/html"); - } else { - draft.putExtra(android.content.Intent.EXTRA_TEXT, message); - draft.setType("text/plain"); - } - } - if (notEmpty(subject)) { - draft.putExtra(android.content.Intent.EXTRA_SUBJECT, subject); - } - try { - if (to != null && to.length() > 0) { - draft.putExtra(android.content.Intent.EXTRA_EMAIL, toStringArray(to)); - } - if (cc != null && cc.length() > 0) { - draft.putExtra(android.content.Intent.EXTRA_CC, toStringArray(cc)); - } - if (bcc != null && bcc.length() > 0) { - draft.putExtra(android.content.Intent.EXTRA_BCC, toStringArray(bcc)); - } - if (files.length() > 0) { - final String dir = getDownloadDir(); - if (dir != null) { - ArrayList<Uri> fileUris = new ArrayList<Uri>(); - for (int i = 0; i < files.length(); i++) { - final Uri fileUri = getFileUriAndSetType(draft, dir, files.getString(i), subject, i); - if (fileUri != null) { - fileUris.add(fileUri); - } - } - if (!fileUris.isEmpty()) { - draft.putExtra(Intent.EXTRA_STREAM, fileUris); - } - } - } - } catch (Exception e) { - callbackContext.error(e.getMessage()); - } - - // this was added to start the intent in a new window as suggested in #300 to prevent crashes upon return - draft.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); - - draft.setType("application/octet-stream"); - - // as an experiment for #300 we're explicitly running it on the ui thread here - cordova.getActivity().runOnUiThread(new Runnable() { - public void run() { - cordova.startActivityForResult(plugin, Intent.createChooser(draft, "Choose Email App"), ACTIVITY_CODE_SENDVIAEMAIL); - } - }); - } - }); - - return true; - } - - private String getDownloadDir() throws IOException { - // better check, otherwise it may crash the app - if (Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState())) { - // we need to use external storage since we need to share to another app - final String dir = webView.getContext().getExternalFilesDir(null) + "/socialsharing-downloads"; - createOrCleanDir(dir); - return dir; - } else { - return null; - } - } - - private boolean shareWithOptions(CallbackContext callbackContext, JSONObject jsonObject) { - return doSendIntent( - callbackContext, - jsonObject.optString("message", null), - jsonObject.optString("subject", null), - jsonObject.optJSONArray("files") == null ? new JSONArray() : jsonObject.optJSONArray("files"), - jsonObject.optString("url", null), - null, - jsonObject.optString("chooserTitle", null), - false, - false - ); - } - - private boolean doSendIntent( - final CallbackContext callbackContext, - final String msg, - final String subject, - final JSONArray files, - final String url, - final String appPackageName, - final String chooserTitle, - final boolean peek, - final boolean boolResult) { - - final CordovaInterface mycordova = cordova; - final CordovaPlugin plugin = this; - - cordova.getThreadPool().execute(new SocialSharingRunnable(callbackContext) { - public void run() { - String message = msg; - final boolean hasMultipleAttachments = files.length() > 1; - final Intent sendIntent = new Intent(hasMultipleAttachments ? Intent.ACTION_SEND_MULTIPLE : Intent.ACTION_SEND); - sendIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET); - - try { - if (files.length() > 0 && !"".equals(files.getString(0))) { - final String dir = getDownloadDir(); - if (dir != null) { - ArrayList<Uri> fileUris = new ArrayList<Uri>(); - Uri fileUri = null; - for (int i = 0; i < files.length(); i++) { - fileUri = getFileUriAndSetType(sendIntent, dir, files.getString(i), subject, i); - if (fileUri != null) { - fileUris.add(fileUri); - } - } - if (!fileUris.isEmpty()) { - if (hasMultipleAttachments) { - sendIntent.putExtra(Intent.EXTRA_STREAM, fileUris); - } else { - sendIntent.putExtra(Intent.EXTRA_STREAM, fileUri); - } - } - } else { - sendIntent.setType("text/plain"); - } - } else { - sendIntent.setType("text/plain"); - } - } catch (Exception e) { - callbackContext.error(e.getMessage()); - } - - if (notEmpty(subject)) { - sendIntent.putExtra(Intent.EXTRA_SUBJECT, subject); - } - - // add the URL to the message, as there seems to be no separate field - if (notEmpty(url)) { - if (notEmpty(message)) { - message += " " + url; - } else { - message = url; - } - } - if (notEmpty(message)) { - sendIntent.putExtra(android.content.Intent.EXTRA_TEXT, message); - // sometimes required when the user picks share via sms - if (Build.VERSION.SDK_INT < 21) { // LOLLIPOP - sendIntent.putExtra("sms_body", message); - } - } - - // this was added to start the intent in a new window as suggested in #300 to prevent crashes upon return - sendIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); - - if (appPackageName != null) { - String packageName = appPackageName; - String passedActivityName = null; - if (packageName.contains("/")) { - String[] items = appPackageName.split("/"); - packageName = items[0]; - passedActivityName = items[1]; - } - final ActivityInfo activity = getActivity(callbackContext, sendIntent, packageName); - if (activity != null) { - if (peek) { - callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK)); - } else { - sendIntent.addCategory(Intent.CATEGORY_LAUNCHER); - sendIntent.setComponent(new ComponentName(activity.applicationInfo.packageName, - passedActivityName != null ? passedActivityName : activity.name)); - - // as an experiment for #300 we're explicitly running it on the ui thread here - cordova.getActivity().runOnUiThread(new Runnable() { - public void run() { - mycordova.startActivityForResult(plugin, sendIntent, 0); - } - }); - - if (pasteMessage != null) { - // add a little delay because target app (facebook only atm) needs to be started first - new Timer().schedule(new TimerTask() { - public void run() { - cordova.getActivity().runOnUiThread(new Runnable() { - public void run() { - copyHintToClipboard(msg, pasteMessage); - showPasteMessage(pasteMessage); - } - }); - } - }, 2000); - } - } - } - } else { - if (peek) { - callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK)); - } else { - // experimenting a bit - // as an experiment for #300 we're explicitly running it on the ui thread here - cordova.getActivity().runOnUiThread(new Runnable() { - public void run() { - mycordova.startActivityForResult(plugin, Intent.createChooser(sendIntent, chooserTitle), boolResult ? ACTIVITY_CODE_SEND__BOOLRESULT : ACTIVITY_CODE_SEND__OBJECT); - } - }); - } - } - } - }); - return true; - } - - @SuppressLint("NewApi") - private void copyHintToClipboard(String msg, String label) { - if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB) { - return; - } - final ClipboardManager clipboard = (android.content.ClipboardManager) cordova.getActivity().getSystemService(Context.CLIPBOARD_SERVICE); - final ClipData clip = android.content.ClipData.newPlainText(label, msg); - clipboard.setPrimaryClip(clip); - } - - @SuppressLint("NewApi") - private void showPasteMessage(String label) { - if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB) { - return; - } - final Toast toast = Toast.makeText(webView.getContext(), label, Toast.LENGTH_LONG); - toast.setGravity(Gravity.CENTER_VERTICAL | Gravity.CENTER_HORIZONTAL, 0, 0); - toast.show(); - } - - private Uri getFileUriAndSetType(Intent sendIntent, String dir, String image, String subject, int nthFile) throws IOException { - // we're assuming an image, but this can be any filetype you like - String localImage = image; - if (image.endsWith("mp4") || image.endsWith("mov") || image.endsWith("3gp")){ - sendIntent.setType("video/*"); - } else { - sendIntent.setType("image/*"); - } - - if (image.startsWith("http") || image.startsWith("www/")) { - String filename = getFileName(image); - localImage = "file://" + dir + "/" + filename; - if (image.startsWith("http")) { - // filename optimisation taken from https://github.com/EddyVerbruggen/SocialSharing-PhoneGap-Plugin/pull/56 - URLConnection connection = new URL(image).openConnection(); - String disposition = connection.getHeaderField("Content-Disposition"); - if (disposition != null) { - final Pattern dispositionPattern = Pattern.compile("filename=([^;]+)"); - Matcher matcher = dispositionPattern.matcher(disposition); - if (matcher.find()) { - filename = matcher.group(1).replaceAll("[^a-zA-Z0-9._-]", ""); - if (filename.length() == 0) { - // in this case we can't determine a filetype so some targets (gmail) may not render it correctly - filename = "file"; - } - localImage = "file://" + dir + "/" + filename; - } - } - saveFile(getBytes(connection.getInputStream()), dir, filename); - } else { - saveFile(getBytes(webView.getContext().getAssets().open(image)), dir, filename); - } - } else if (image.startsWith("data:")) { - // safeguard for https://code.google.com/p/android/issues/detail?id=7901#c43 - if (!image.contains(";base64,")) { - sendIntent.setType("text/plain"); - return null; - } - // image looks like this: data:image/png;base64,R0lGODlhDAA... - final String encodedImg = image.substring(image.indexOf(";base64,") + 8); - // correct the intent type if anything else was passed, like a pdf: data:application/pdf;base64,.. - if (!image.contains("data:image/")) { - sendIntent.setType(image.substring(image.indexOf("data:") + 5, image.indexOf(";base64"))); - } - // the filename needs a valid extension, so it renders correctly in target apps - final String imgExtension = image.substring(image.indexOf("/") + 1, image.indexOf(";base64")); - String fileName; - // if a subject was passed, use it as the filename - // filenames must be unique when passing in multiple files [#158] - if (notEmpty(subject)) { - fileName = sanitizeFilename(subject) + (nthFile == 0 ? "" : "_" + nthFile) + "." + imgExtension; - } else { - fileName = "file" + (nthFile == 0 ? "" : "_" + nthFile) + "." + imgExtension; - } - saveFile(Base64.decode(encodedImg, Base64.DEFAULT), dir, fileName); - localImage = "file://" + dir + "/" + fileName; - } else if (image.startsWith("df:")) { - // safeguard for https://code.google.com/p/android/issues/detail?id=7901#c43 - if (!image.contains(";base64,")) { - sendIntent.setType("text/plain"); - return null; - } - // format looks like this : df:filename.txt;data:image/png;base64,R0lGODlhDAA... - final String fileName = image.substring(image.indexOf("df:") + 3, image.indexOf(";data:")); - final String fileType = image.substring(image.indexOf(";data:") + 6, image.indexOf(";base64,")); - final String encodedImg = image.substring(image.indexOf(";base64,") + 8); - sendIntent.setType(fileType); - saveFile(Base64.decode(encodedImg, Base64.DEFAULT), dir, sanitizeFilename(fileName)); - localImage = "file://" + dir + "/" + fileName; - } else if (!image.startsWith("file://")) { - throw new IllegalArgumentException("URL_NOT_SUPPORTED"); - } else { - //get file MIME type - String type = getMIMEType(image); - //set intent data and Type - sendIntent.setType(type); - } - return Uri.parse(localImage); - } - - private String getMIMEType(String fileName) { - String type = "*/*"; - int dotIndex = fileName.lastIndexOf("."); - if (dotIndex == -1) { - return type; - } - final String end = fileName.substring(dotIndex+1, fileName.length()).toLowerCase(); - String fromMap = MIME_Map.get(end); - return fromMap == null ? type : fromMap; - } - - private static final Map<String, String> MIME_Map = new HashMap<String, String>(); - static { - MIME_Map.put("3gp", "video/3gpp"); - MIME_Map.put("apk", "application/vnd.android.package-archive"); - MIME_Map.put("asf", "video/x-ms-asf"); - MIME_Map.put("avi", "video/x-msvideo"); - MIME_Map.put("bin", "application/octet-stream"); - MIME_Map.put("bmp", "image/bmp"); - MIME_Map.put("c", "text/plain"); - MIME_Map.put("class", "application/octet-stream"); - MIME_Map.put("conf", "text/plain"); - MIME_Map.put("cpp", "text/plain"); - MIME_Map.put("doc", "application/msword"); - MIME_Map.put("docx", "application/vnd.openxmlformats-officedocument.wordprocessingml.document"); - MIME_Map.put("xls", "application/vnd.ms-excel"); - MIME_Map.put("xlsx", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"); - MIME_Map.put("exe", "application/octet-stream"); - MIME_Map.put("gif", "image/gif"); - MIME_Map.put("gtar", "application/x-gtar"); - MIME_Map.put("gz", "application/x-gzip"); - MIME_Map.put("h", "text/plain"); - MIME_Map.put("htm", "text/html"); - MIME_Map.put("html", "text/html"); - MIME_Map.put("jar", "application/java-archive"); - MIME_Map.put("java", "text/plain"); - MIME_Map.put("jpeg", "image/jpeg"); - MIME_Map.put("jpg", "image/*"); - MIME_Map.put("js", "application/x-javascript"); - MIME_Map.put("log", "text/plain"); - MIME_Map.put("m3u", "audio/x-mpegurl"); - MIME_Map.put("m4a", "audio/mp4a-latm"); - MIME_Map.put("m4b", "audio/mp4a-latm"); - MIME_Map.put("m4p", "audio/mp4a-latm"); - MIME_Map.put("m4u", "video/vnd.mpegurl"); - MIME_Map.put("m4v", "video/x-m4v"); - MIME_Map.put("mov", "video/quicktime"); - MIME_Map.put("mp2", "audio/x-mpeg"); - MIME_Map.put("mp3", "audio/x-mpeg"); - MIME_Map.put("mp4", "video/mp4"); - MIME_Map.put("mpc", "application/vnd.mpohun.certificate"); - MIME_Map.put("mpe", "video/mpeg"); - MIME_Map.put("mpeg", "video/mpeg"); - MIME_Map.put("mpg", "video/mpeg"); - MIME_Map.put("mpg4", "video/mp4"); - MIME_Map.put("mpga", "audio/mpeg"); - MIME_Map.put("msg", "application/vnd.ms-outlook"); - MIME_Map.put("ogg", "audio/ogg"); - MIME_Map.put("pdf", "application/pdf"); - MIME_Map.put("png", "image/png"); - MIME_Map.put("pps", "application/vnd.ms-powerpoint"); - MIME_Map.put("ppt", "application/vnd.ms-powerpoint"); - MIME_Map.put("pptx", "application/vnd.openxmlformats-officedocument.presentationml.presentation"); - MIME_Map.put("prop", "text/plain"); - MIME_Map.put("rc", "text/plain"); - MIME_Map.put("rmvb", "audio/x-pn-realaudio"); - MIME_Map.put("rtf", "application/rtf"); - MIME_Map.put("sh", "text/plain"); - MIME_Map.put("tar", "application/x-tar"); - MIME_Map.put("tgz", "application/x-compressed"); - MIME_Map.put("txt", "text/plain"); - MIME_Map.put("wav", "audio/x-wav"); - MIME_Map.put("wma", "audio/x-ms-wma"); - MIME_Map.put("wmv", "audio/x-ms-wmv"); - MIME_Map.put("wps", "application/vnd.ms-works"); - MIME_Map.put("xml", "text/plain"); - MIME_Map.put("z", "application/x-compress"); - MIME_Map.put("zip", "application/x-zip-compressed"); - MIME_Map.put("", "*/*"); - } - - private boolean shareViaWhatsAppDirectly(final CallbackContext callbackContext, String message, final String subject, final JSONArray files, final String url, final String number) { - // add the URL to the message, as there seems to be no separate field - if (notEmpty(url)) { - if (notEmpty(message)) { - message += " " + url; - } else { - message = url; - } - } - final String shareMessage = message; - final SocialSharing plugin = this; - cordova.getThreadPool().execute(new SocialSharingRunnable(callbackContext) { - public void run() { - final Intent intent = new Intent(Intent.ACTION_SENDTO); - intent.setData(Uri.parse("smsto:" + number)); - - intent.putExtra("sms_body", shareMessage); - intent.putExtra("sms_subject", subject); - intent.setPackage("com.whatsapp"); - - try { - if (files.length() > 0 && !"".equals(files.getString(0))) { - final boolean hasMultipleAttachments = files.length() > 1; - final String dir = getDownloadDir(); - if (dir != null) { - ArrayList<Uri> fileUris = new ArrayList<Uri>(); - Uri fileUri = null; - for (int i = 0; i < files.length(); i++) { - fileUri = getFileUriAndSetType(intent, dir, files.getString(i), subject, i); - if (fileUri != null) { - fileUris.add(fileUri); - } - } - if (!fileUris.isEmpty()) { - if (hasMultipleAttachments) { - intent.putExtra(Intent.EXTRA_STREAM, fileUris); - } else { - intent.putExtra(Intent.EXTRA_STREAM, fileUri); - } - } - } - } - } catch (Exception e) { - callbackContext.error(e.getMessage()); - } - try { - // this was added to start the intent in a new window as suggested in #300 to prevent crashes upon return - // update: didn't help (doesn't seem to hurt either though) - intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); - - // as an experiment for #300 we're explicitly running it on the ui thread here - cordova.getActivity().runOnUiThread(new Runnable() { - public void run() { - cordova.startActivityForResult(plugin, intent, ACTIVITY_CODE_SENDVIAWHATSAPP); - } - }); - } catch (Exception e) { - callbackContext.error(e.getMessage()); - } - } - }); - return true; - } - - private boolean invokeSMSIntent(final CallbackContext callbackContext, JSONObject options, String p_phonenumbers) { - final String message = options.optString("message"); - // TODO test this on a real SMS enabled device before releasing it -// final String subject = options.optString("subject"); -// final String image = options.optString("image"); - final String subject = null; //options.optString("subject"); - final String image = null; // options.optString("image"); - final String phonenumbers = getPhoneNumbersWithManufacturerSpecificSeparators(p_phonenumbers); - final SocialSharing plugin = this; - cordova.getThreadPool().execute(new SocialSharingRunnable(callbackContext) { - public void run() { - Intent intent; - - if (Build.VERSION.SDK_INT >= 19) { // Build.VERSION_CODES.KITKAT) { - // passing in no phonenumbers for kitkat may result in an error, - // but it may also work for some devices, so documentation will need to cover this case - intent = new Intent(Intent.ACTION_SENDTO); - intent.setData(Uri.parse("smsto:" + (notEmpty(phonenumbers) ? phonenumbers : ""))); - } else { - intent = new Intent(Intent.ACTION_VIEW); - intent.setType("vnd.android-dir/mms-sms"); - if (phonenumbers != null) { - intent.putExtra("address", phonenumbers); - } - } - intent.putExtra("sms_body", message); - intent.putExtra("sms_subject", subject); - - try { - if (image != null && !"".equals(image)) { - final Uri fileUri = getFileUriAndSetType(intent, getDownloadDir(), image, subject, 0); - if (fileUri != null) { - intent.putExtra(Intent.EXTRA_STREAM, fileUri); - } - } - // this was added to start the intent in a new window as suggested in #300 to prevent crashes upon return - intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); - - cordova.startActivityForResult(plugin, intent, 0); - } catch (Exception e) { - callbackContext.error(e.getMessage()); - } - } - }); - return true; - } - - private static String getPhoneNumbersWithManufacturerSpecificSeparators(String phonenumbers) { - if (notEmpty(phonenumbers)) { - char separator; - if (android.os.Build.MANUFACTURER.equalsIgnoreCase("samsung")) { - separator = ','; - } else { - separator = ';'; - } - return phonenumbers.replace(';', separator).replace(',', separator); - } - return null; - } - - private ActivityInfo getActivity(final CallbackContext callbackContext, final Intent shareIntent, final String appPackageName) { - final PackageManager pm = webView.getContext().getPackageManager(); - List<ResolveInfo> activityList = pm.queryIntentActivities(shareIntent, 0); - for (final ResolveInfo app : activityList) { - if ((app.activityInfo.packageName).contains(appPackageName)) { - return app.activityInfo; - } - } - // no matching app found - callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.ERROR, getShareActivities(activityList))); - return null; - } - - private JSONArray getShareActivities(List<ResolveInfo> activityList) { - List<String> packages = new ArrayList<String>(); - for (final ResolveInfo app : activityList) { - packages.add(app.activityInfo.packageName); - } - return new JSONArray(packages); - } - - @Override - public void onActivityResult(int requestCode, int resultCode, Intent intent) { - super.onActivityResult(requestCode, resultCode, intent); - if (_callbackContext != null) { - switch (requestCode) { - case ACTIVITY_CODE_SEND__BOOLRESULT: - _callbackContext.sendPluginResult(new PluginResult( - PluginResult.Status.OK, - resultCode == Activity.RESULT_OK)); - break; - case ACTIVITY_CODE_SEND__OBJECT: - JSONObject json = new JSONObject(); - try { - json.put("completed", resultCode == Activity.RESULT_OK); - json.put("app", ""); // we need a completely different approach if we want to support this on Android. Idea: https://clickclickclack.wordpress.com/2012/01/03/intercepting-androids-action_send-intents/ - _callbackContext.sendPluginResult(new PluginResult( - PluginResult.Status.OK, - json)); - } catch (JSONException e) { - _callbackContext.error(e.getMessage()); - } - break; - default: - _callbackContext.success(); - } - } - } - - private void createOrCleanDir(final String downloadDir) throws IOException { - final File dir = new File(downloadDir); - if (!dir.exists()) { - if (!dir.mkdirs()) { - throw new IOException("CREATE_DIRS_FAILED"); - } - } else { - cleanupOldFiles(dir); - } - } - - private static String getFileName(String url) { - if (url.endsWith("/")) { - url = url.substring(0, url.length()-1); - } - final String pattern = ".*/([^?#]+)?"; - Pattern r = Pattern.compile(pattern); - Matcher m = r.matcher(url); - if (m.find()) { - return m.group(1); - } else { - return "file"; - } - } - - private byte[] getBytes(InputStream is) throws IOException { - ByteArrayOutputStream buffer = new ByteArrayOutputStream(); - int nRead; - byte[] data = new byte[16384]; - while ((nRead = is.read(data, 0, data.length)) != -1) { - buffer.write(data, 0, nRead); - } - buffer.flush(); - return buffer.toByteArray(); - } - - private void saveFile(byte[] bytes, String dirName, String fileName) throws IOException { - final File dir = new File(dirName); - final FileOutputStream fos = new FileOutputStream(new File(dir, fileName)); - fos.write(bytes); - fos.flush(); - fos.close(); - } - - /** - * As file.deleteOnExit does not work on Android, we need to delete files manually. - * Deleting them in onActivityResult is not a good idea, because for example a base64 encoded file - * will not be available for upload to Facebook (it's deleted before it's uploaded). - * So the best approach is deleting old files when saving (sharing) a new one. - */ - private void cleanupOldFiles(File dir) { - for (File f : dir.listFiles()) { - //noinspection ResultOfMethodCallIgnored - f.delete(); - } - } - - private static boolean notEmpty(String what) { - return what != null && - !"".equals(what) && - !"null".equalsIgnoreCase(what); - } - - private static String[] toStringArray(JSONArray jsonArray) throws JSONException { - String[] result = new String[jsonArray.length()]; - for (int i = 0; i < jsonArray.length(); i++) { - result[i] = jsonArray.getString(i); - } - return result; - } - - public static String sanitizeFilename(String name) { - return name.replaceAll("[:\\\\/*?|<> ]", "_"); - } -} diff --git a/StoneIsland/platforms/android/src/org/apache/cordova/BuildHelper.java b/StoneIsland/platforms/android/src/org/apache/cordova/BuildHelper.java deleted file mode 100644 index d9b18aa2..00000000 --- a/StoneIsland/platforms/android/src/org/apache/cordova/BuildHelper.java +++ /dev/null @@ -1,70 +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 org.apache.cordova; - -/* - * This is a utility class that allows us to get the BuildConfig variable, which is required - * for the use of different providers. This is not guaranteed to work, and it's better for this - * to be set in the build step in config.xml - * - */ - -import android.app.Activity; -import android.content.Context; - -import java.lang.reflect.Field; - - -public class BuildHelper { - - - private static String TAG="BuildHelper"; - - /* - * This needs to be implemented if you wish to use the Camera Plugin or other plugins - * that read the Build Configuration. - * - * Thanks to Phil@Medtronic and Graham Borland for finding the answer and posting it to - * StackOverflow. This is annoying as hell! However, this method does not work with - * ProGuard, and you should use the config.xml to define the application_id - * - */ - - public static Object getBuildConfigValue(Context ctx, String key) - { - try - { - Class<?> clazz = Class.forName(ctx.getPackageName() + ".BuildConfig"); - Field field = clazz.getField(key); - return field.get(null); - } catch (ClassNotFoundException e) { - LOG.d(TAG, "Unable to get the BuildConfig, is this built with ANT?"); - e.printStackTrace(); - } catch (NoSuchFieldException e) { - LOG.d(TAG, key + " is not a valid field. Check your build.gradle"); - } catch (IllegalAccessException e) { - LOG.d(TAG, "Illegal Access Exception: Let's print a stack trace."); - e.printStackTrace(); - } - - return null; - } - -} diff --git a/StoneIsland/platforms/android/src/org/apache/cordova/PermissionHelper.java b/StoneIsland/platforms/android/src/org/apache/cordova/PermissionHelper.java deleted file mode 100644 index bbd79112..00000000 --- a/StoneIsland/platforms/android/src/org/apache/cordova/PermissionHelper.java +++ /dev/null @@ -1,138 +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 org.apache.cordova; - -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; -import java.util.Arrays; - -import org.apache.cordova.CordovaInterface; -import org.apache.cordova.CordovaPlugin; -import org.apache.cordova.LOG; - -import android.content.pm.PackageManager; - -/** - * This class provides reflective methods for permission requesting and checking so that plugins - * written for cordova-android 5.0.0+ can still compile with earlier cordova-android versions. - */ -public class PermissionHelper { - private static final String LOG_TAG = "CordovaPermissionHelper"; - - /** - * Requests a "dangerous" permission for the application at runtime. This is a helper method - * alternative to cordovaInterface.requestPermission() that does not require the project to be - * built with cordova-android 5.0.0+ - * - * @param plugin The plugin the permission is being requested for - * @param requestCode A requestCode to be passed to the plugin's onRequestPermissionResult() - * along with the result of the permission request - * @param permission The permission to be requested - */ - public static void requestPermission(CordovaPlugin plugin, int requestCode, String permission) { - PermissionHelper.requestPermissions(plugin, requestCode, new String[] {permission}); - } - - /** - * Requests "dangerous" permissions for the application at runtime. This is a helper method - * alternative to cordovaInterface.requestPermissions() that does not require the project to be - * built with cordova-android 5.0.0+ - * - * @param plugin The plugin the permissions are being requested for - * @param requestCode A requestCode to be passed to the plugin's onRequestPermissionResult() - * along with the result of the permissions request - * @param permissions The permissions to be requested - */ - public static void requestPermissions(CordovaPlugin plugin, int requestCode, String[] permissions) { - try { - Method requestPermission = CordovaInterface.class.getDeclaredMethod( - "requestPermissions", CordovaPlugin.class, int.class, String[].class); - - // If there is no exception, then this is cordova-android 5.0.0+ - requestPermission.invoke(plugin.cordova, plugin, requestCode, permissions); - } catch (NoSuchMethodException noSuchMethodException) { - // cordova-android version is less than 5.0.0, so permission is implicitly granted - LOG.d(LOG_TAG, "No need to request permissions " + Arrays.toString(permissions)); - - // Notify the plugin that all were granted by using more reflection - deliverPermissionResult(plugin, requestCode, permissions); - } catch (IllegalAccessException illegalAccessException) { - // Should never be caught; this is a public method - LOG.e(LOG_TAG, "IllegalAccessException when requesting permissions " + Arrays.toString(permissions), illegalAccessException); - } catch(InvocationTargetException invocationTargetException) { - // This method does not throw any exceptions, so this should never be caught - LOG.e(LOG_TAG, "invocationTargetException when requesting permissions " + Arrays.toString(permissions), invocationTargetException); - } - } - - /** - * Checks at runtime to see if the application has been granted a permission. This is a helper - * method alternative to cordovaInterface.hasPermission() that does not require the project to - * be built with cordova-android 5.0.0+ - * - * @param plugin The plugin the permission is being checked against - * @param permission The permission to be checked - * - * @return True if the permission has already been granted and false otherwise - */ - public static boolean hasPermission(CordovaPlugin plugin, String permission) { - try { - Method hasPermission = CordovaInterface.class.getDeclaredMethod("hasPermission", String.class); - - // If there is no exception, then this is cordova-android 5.0.0+ - return (Boolean) hasPermission.invoke(plugin.cordova, permission); - } catch (NoSuchMethodException noSuchMethodException) { - // cordova-android version is less than 5.0.0, so permission is implicitly granted - LOG.d(LOG_TAG, "No need to check for permission " + permission); - return true; - } catch (IllegalAccessException illegalAccessException) { - // Should never be caught; this is a public method - LOG.e(LOG_TAG, "IllegalAccessException when checking permission " + permission, illegalAccessException); - } catch(InvocationTargetException invocationTargetException) { - // This method does not throw any exceptions, so this should never be caught - LOG.e(LOG_TAG, "invocationTargetException when checking permission " + permission, invocationTargetException); - } - return false; - } - - private static void deliverPermissionResult(CordovaPlugin plugin, int requestCode, String[] permissions) { - // Generate the request results - int[] requestResults = new int[permissions.length]; - Arrays.fill(requestResults, PackageManager.PERMISSION_GRANTED); - - try { - Method onRequestPermissionResult = CordovaPlugin.class.getDeclaredMethod( - "onRequestPermissionResult", int.class, String[].class, int[].class); - - onRequestPermissionResult.invoke(plugin, requestCode, permissions, requestResults); - } catch (NoSuchMethodException noSuchMethodException) { - // Should never be caught since the plugin must be written for cordova-android 5.0.0+ if it - // made it to this point - LOG.e(LOG_TAG, "NoSuchMethodException when delivering permissions results", noSuchMethodException); - } catch (IllegalAccessException illegalAccessException) { - // Should never be caught; this is a public method - LOG.e(LOG_TAG, "IllegalAccessException when delivering permissions results", illegalAccessException); - } catch(InvocationTargetException invocationTargetException) { - // This method may throw a JSONException. We are just duplicating cordova-android's - // exception handling behavior here; all it does is log the exception in CordovaActivity, - // print the stacktrace, and ignore it - LOG.e(LOG_TAG, "InvocationTargetException when delivering permissions results", invocationTargetException); - } - } -} diff --git a/StoneIsland/platforms/android/src/org/apache/cordova/device/Device.java b/StoneIsland/platforms/android/src/org/apache/cordova/device/Device.java deleted file mode 100644 index e9efcb49..00000000 --- a/StoneIsland/platforms/android/src/org/apache/cordova/device/Device.java +++ /dev/null @@ -1,174 +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 org.apache.cordova.device; - -import java.util.TimeZone; - -import org.apache.cordova.CordovaWebView; -import org.apache.cordova.CallbackContext; -import org.apache.cordova.CordovaPlugin; -import org.apache.cordova.CordovaInterface; -import org.json.JSONArray; -import org.json.JSONException; -import org.json.JSONObject; - -import android.provider.Settings; - -public class Device extends CordovaPlugin { - public static final String TAG = "Device"; - - public static String platform; // Device OS - public static String uuid; // Device UUID - - private static final String ANDROID_PLATFORM = "Android"; - private static final String AMAZON_PLATFORM = "amazon-fireos"; - private static final String AMAZON_DEVICE = "Amazon"; - - /** - * Constructor. - */ - public Device() { - } - - /** - * Sets the context of the Command. This can then be used to do things like - * get file paths associated with the Activity. - * - * @param cordova The context of the main Activity. - * @param webView The CordovaWebView Cordova is running in. - */ - public void initialize(CordovaInterface cordova, CordovaWebView webView) { - super.initialize(cordova, webView); - Device.uuid = getUuid(); - } - - /** - * Executes the request and returns PluginResult. - * - * @param action The action to execute. - * @param args JSONArry of arguments for the plugin. - * @param callbackContext The callback id used when calling back into JavaScript. - * @return True if the action was valid, false if not. - */ - public boolean execute(String action, JSONArray args, CallbackContext callbackContext) throws JSONException { - if ("getDeviceInfo".equals(action)) { - JSONObject r = new JSONObject(); - r.put("uuid", Device.uuid); - r.put("version", this.getOSVersion()); - r.put("platform", this.getPlatform()); - r.put("model", this.getModel()); - r.put("manufacturer", this.getManufacturer()); - r.put("isVirtual", this.isVirtual()); - r.put("serial", this.getSerialNumber()); - callbackContext.success(r); - } - else { - return false; - } - return true; - } - - //-------------------------------------------------------------------------- - // LOCAL METHODS - //-------------------------------------------------------------------------- - - /** - * Get the OS name. - * - * @return - */ - public String getPlatform() { - String platform; - if (isAmazonDevice()) { - platform = AMAZON_PLATFORM; - } else { - platform = ANDROID_PLATFORM; - } - return platform; - } - - /** - * Get the device's Universally Unique Identifier (UUID). - * - * @return - */ - public String getUuid() { - String uuid = Settings.Secure.getString(this.cordova.getActivity().getContentResolver(), android.provider.Settings.Secure.ANDROID_ID); - return uuid; - } - - public String getModel() { - String model = android.os.Build.MODEL; - return model; - } - - public String getProductName() { - String productname = android.os.Build.PRODUCT; - return productname; - } - - public String getManufacturer() { - String manufacturer = android.os.Build.MANUFACTURER; - return manufacturer; - } - - public String getSerialNumber() { - String serial = android.os.Build.SERIAL; - return serial; - } - - /** - * Get the OS version. - * - * @return - */ - public String getOSVersion() { - String osversion = android.os.Build.VERSION.RELEASE; - return osversion; - } - - public String getSDKVersion() { - @SuppressWarnings("deprecation") - String sdkversion = android.os.Build.VERSION.SDK; - return sdkversion; - } - - public String getTimeZoneID() { - TimeZone tz = TimeZone.getDefault(); - return (tz.getID()); - } - - /** - * Function to check if the device is manufactured by Amazon - * - * @return - */ - public boolean isAmazonDevice() { - if (android.os.Build.MANUFACTURER.equals(AMAZON_DEVICE)) { - return true; - } - return false; - } - - public boolean isVirtual() { - return android.os.Build.FINGERPRINT.contains("generic") || - android.os.Build.PRODUCT.contains("sdk"); - } - -} diff --git a/StoneIsland/platforms/android/src/org/apache/cordova/dialogs/Notification.java b/StoneIsland/platforms/android/src/org/apache/cordova/dialogs/Notification.java deleted file mode 100644 index f19bc888..00000000 --- a/StoneIsland/platforms/android/src/org/apache/cordova/dialogs/Notification.java +++ /dev/null @@ -1,513 +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 org.apache.cordova.dialogs; - -import org.apache.cordova.CallbackContext; -import org.apache.cordova.CordovaInterface; -import org.apache.cordova.CordovaPlugin; -import org.apache.cordova.LOG; -import org.apache.cordova.PluginResult; -import org.json.JSONArray; -import org.json.JSONException; -import org.json.JSONObject; - -import android.annotation.SuppressLint; -import android.app.AlertDialog; -import android.app.AlertDialog.Builder; -import android.app.ProgressDialog; -import android.content.DialogInterface; -import android.content.res.Resources; -import android.media.Ringtone; -import android.media.RingtoneManager; -import android.net.Uri; -import android.widget.EditText; -import android.widget.TextView; - - -/** - * This class provides access to notifications on the device. - * - * Be aware that this implementation gets called on - * navigator.notification.{alert|confirm|prompt}, and that there is a separate - * implementation in org.apache.cordova.CordovaChromeClient that gets - * called on a simple window.{alert|confirm|prompt}. - */ -public class Notification extends CordovaPlugin { - - private static final String LOG_TAG = "Notification"; - - public int confirmResult = -1; - public ProgressDialog spinnerDialog = null; - public ProgressDialog progressDialog = null; - - /** - * Constructor. - */ - public Notification() { - } - - /** - * Executes the request and returns PluginResult. - * - * @param action The action to execute. - * @param args JSONArray of arguments for the plugin. - * @param callbackContext The callback context used when calling back into JavaScript. - * @return True when the action was valid, false otherwise. - */ - public boolean execute(String action, JSONArray args, CallbackContext callbackContext) throws JSONException { - /* - * Don't run any of these if the current activity is finishing - * in order to avoid android.view.WindowManager$BadTokenException - * crashing the app. Just return true here since false should only - * be returned in the event of an invalid action. - */ - if(this.cordova.getActivity().isFinishing()) return true; - - if (action.equals("beep")) { - this.beep(args.getLong(0)); - } - else if (action.equals("alert")) { - this.alert(args.getString(0), args.getString(1), args.getString(2), callbackContext); - return true; - } - else if (action.equals("confirm")) { - this.confirm(args.getString(0), args.getString(1), args.getJSONArray(2), callbackContext); - return true; - } - else if (action.equals("prompt")) { - this.prompt(args.getString(0), args.getString(1), args.getJSONArray(2), args.getString(3), callbackContext); - return true; - } - else if (action.equals("activityStart")) { - this.activityStart(args.getString(0), args.getString(1)); - } - else if (action.equals("activityStop")) { - this.activityStop(); - } - else if (action.equals("progressStart")) { - this.progressStart(args.getString(0), args.getString(1)); - } - else if (action.equals("progressValue")) { - this.progressValue(args.getInt(0)); - } - else if (action.equals("progressStop")) { - this.progressStop(); - } - else { - return false; - } - - // Only alert and confirm are async. - callbackContext.success(); - return true; - } - - //-------------------------------------------------------------------------- - // LOCAL METHODS - //-------------------------------------------------------------------------- - - /** - * Beep plays the default notification ringtone. - * - * @param count Number of times to play notification - */ - public void beep(final long count) { - cordova.getThreadPool().execute(new Runnable() { - public void run() { - Uri ringtone = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); - Ringtone notification = RingtoneManager.getRingtone(cordova.getActivity().getBaseContext(), ringtone); - - // If phone is not set to silent mode - if (notification != null) { - for (long i = 0; i < count; ++i) { - notification.play(); - long timeout = 5000; - while (notification.isPlaying() && (timeout > 0)) { - timeout = timeout - 100; - try { - Thread.sleep(100); - } catch (InterruptedException e) { - Thread.currentThread().interrupt(); - } - } - } - } - } - }); - } - - /** - * Builds and shows a native Android alert with given Strings - * @param message The message the alert should display - * @param title The title of the alert - * @param buttonLabel The label of the button - * @param callbackContext The callback context - */ - public synchronized void alert(final String message, final String title, final String buttonLabel, final CallbackContext callbackContext) { - final CordovaInterface cordova = this.cordova; - - Runnable runnable = new Runnable() { - public void run() { - - AlertDialog.Builder dlg = createDialog(cordova); // new AlertDialog.Builder(cordova.getActivity(), AlertDialog.THEME_DEVICE_DEFAULT_LIGHT); - dlg.setMessage(message); - dlg.setTitle(title); - dlg.setCancelable(true); - dlg.setPositiveButton(buttonLabel, - new AlertDialog.OnClickListener() { - public void onClick(DialogInterface dialog, int which) { - dialog.dismiss(); - callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK, 0)); - } - }); - dlg.setOnCancelListener(new AlertDialog.OnCancelListener() { - public void onCancel(DialogInterface dialog) - { - dialog.dismiss(); - callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK, 0)); - } - }); - - changeTextDirection(dlg); - }; - }; - this.cordova.getActivity().runOnUiThread(runnable); - } - - /** - * Builds and shows a native Android confirm dialog with given title, message, buttons. - * This dialog only shows up to 3 buttons. Any labels after that will be ignored. - * The index of the button pressed will be returned to the JavaScript callback identified by callbackId. - * - * @param message The message the dialog should display - * @param title The title of the dialog - * @param buttonLabels A comma separated list of button labels (Up to 3 buttons) - * @param callbackContext The callback context. - */ - public synchronized void confirm(final String message, final String title, final JSONArray buttonLabels, final CallbackContext callbackContext) { - final CordovaInterface cordova = this.cordova; - - Runnable runnable = new Runnable() { - public void run() { - AlertDialog.Builder dlg = createDialog(cordova); // new AlertDialog.Builder(cordova.getActivity(), AlertDialog.THEME_DEVICE_DEFAULT_LIGHT); - dlg.setMessage(message); - dlg.setTitle(title); - dlg.setCancelable(true); - - // First button - if (buttonLabels.length() > 0) { - try { - dlg.setNegativeButton(buttonLabels.getString(0), - new AlertDialog.OnClickListener() { - public void onClick(DialogInterface dialog, int which) { - dialog.dismiss(); - callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK, 1)); - } - }); - } catch (JSONException e) { - LOG.d(LOG_TAG,"JSONException on first button."); - } - } - - // Second button - if (buttonLabels.length() > 1) { - try { - dlg.setNeutralButton(buttonLabels.getString(1), - new AlertDialog.OnClickListener() { - public void onClick(DialogInterface dialog, int which) { - dialog.dismiss(); - callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK, 2)); - } - }); - } catch (JSONException e) { - LOG.d(LOG_TAG,"JSONException on second button."); - } - } - - // Third button - if (buttonLabels.length() > 2) { - try { - dlg.setPositiveButton(buttonLabels.getString(2), - new AlertDialog.OnClickListener() { - public void onClick(DialogInterface dialog, int which) { - dialog.dismiss(); - callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK, 3)); - } - }); - } catch (JSONException e) { - LOG.d(LOG_TAG,"JSONException on third button."); - } - } - dlg.setOnCancelListener(new AlertDialog.OnCancelListener() { - public void onCancel(DialogInterface dialog) - { - dialog.dismiss(); - callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK, 0)); - } - }); - - changeTextDirection(dlg); - }; - }; - this.cordova.getActivity().runOnUiThread(runnable); - } - - /** - * Builds and shows a native Android prompt dialog with given title, message, buttons. - * This dialog only shows up to 3 buttons. Any labels after that will be ignored. - * The following results are returned to the JavaScript callback identified by callbackId: - * buttonIndex Index number of the button selected - * input1 The text entered in the prompt dialog box - * - * @param message The message the dialog should display - * @param title The title of the dialog - * @param buttonLabels A comma separated list of button labels (Up to 3 buttons) - * @param callbackContext The callback context. - */ - public synchronized void prompt(final String message, final String title, final JSONArray buttonLabels, final String defaultText, final CallbackContext callbackContext) { - - final CordovaInterface cordova = this.cordova; - - Runnable runnable = new Runnable() { - public void run() { - final EditText promptInput = new EditText(cordova.getActivity()); - - /* CB-11677 - By default, prompt input text color is set according current theme. - But for some android versions is not visible (for example 5.1.1). - android.R.color.primary_text_light will make text visible on all versions. */ - Resources resources = cordova.getActivity().getResources(); - int promptInputTextColor = resources.getColor(android.R.color.primary_text_light); - promptInput.setTextColor(promptInputTextColor); - promptInput.setText(defaultText); - AlertDialog.Builder dlg = createDialog(cordova); // new AlertDialog.Builder(cordova.getActivity(), AlertDialog.THEME_DEVICE_DEFAULT_LIGHT); - dlg.setMessage(message); - dlg.setTitle(title); - dlg.setCancelable(true); - - dlg.setView(promptInput); - - final JSONObject result = new JSONObject(); - - // First button - if (buttonLabels.length() > 0) { - try { - dlg.setNegativeButton(buttonLabels.getString(0), - new AlertDialog.OnClickListener() { - public void onClick(DialogInterface dialog, int which) { - dialog.dismiss(); - try { - result.put("buttonIndex",1); - result.put("input1", promptInput.getText().toString().trim().length()==0 ? defaultText : promptInput.getText()); - } catch (JSONException e) { - LOG.d(LOG_TAG,"JSONException on first button.", e); - } - callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK, result)); - } - }); - } catch (JSONException e) { - LOG.d(LOG_TAG,"JSONException on first button."); - } - } - - // Second button - if (buttonLabels.length() > 1) { - try { - dlg.setNeutralButton(buttonLabels.getString(1), - new AlertDialog.OnClickListener() { - public void onClick(DialogInterface dialog, int which) { - dialog.dismiss(); - try { - result.put("buttonIndex",2); - result.put("input1", promptInput.getText().toString().trim().length()==0 ? defaultText : promptInput.getText()); - } catch (JSONException e) { - LOG.d(LOG_TAG,"JSONException on second button.", e); - } - callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK, result)); - } - }); - } catch (JSONException e) { - LOG.d(LOG_TAG,"JSONException on second button."); - } - } - - // Third button - if (buttonLabels.length() > 2) { - try { - dlg.setPositiveButton(buttonLabels.getString(2), - new AlertDialog.OnClickListener() { - public void onClick(DialogInterface dialog, int which) { - dialog.dismiss(); - try { - result.put("buttonIndex",3); - result.put("input1", promptInput.getText().toString().trim().length()==0 ? defaultText : promptInput.getText()); - } catch (JSONException e) { - LOG.d(LOG_TAG,"JSONException on third button.", e); - } - callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK, result)); - } - }); - } catch (JSONException e) { - LOG.d(LOG_TAG,"JSONException on third button."); - } - } - dlg.setOnCancelListener(new AlertDialog.OnCancelListener() { - public void onCancel(DialogInterface dialog){ - dialog.dismiss(); - try { - result.put("buttonIndex",0); - result.put("input1", promptInput.getText().toString().trim().length()==0 ? defaultText : promptInput.getText()); - } catch (JSONException e) { e.printStackTrace(); } - callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK, result)); - } - }); - - changeTextDirection(dlg); - }; - }; - this.cordova.getActivity().runOnUiThread(runnable); - } - - /** - * Show the spinner. - * - * @param title Title of the dialog - * @param message The message of the dialog - */ - public synchronized void activityStart(final String title, final String message) { - if (this.spinnerDialog != null) { - this.spinnerDialog.dismiss(); - this.spinnerDialog = null; - } - final Notification notification = this; - final CordovaInterface cordova = this.cordova; - Runnable runnable = new Runnable() { - public void run() { - notification.spinnerDialog = createProgressDialog(cordova); // new ProgressDialog(cordova.getActivity(), AlertDialog.THEME_DEVICE_DEFAULT_LIGHT); - notification.spinnerDialog.setTitle(title); - notification.spinnerDialog.setMessage(message); - notification.spinnerDialog.setCancelable(true); - notification.spinnerDialog.setIndeterminate(true); - notification.spinnerDialog.setOnCancelListener( - new DialogInterface.OnCancelListener() { - public void onCancel(DialogInterface dialog) { - notification.spinnerDialog = null; - } - }); - notification.spinnerDialog.show(); - } - }; - this.cordova.getActivity().runOnUiThread(runnable); - } - - /** - * Stop spinner. - */ - public synchronized void activityStop() { - if (this.spinnerDialog != null) { - this.spinnerDialog.dismiss(); - this.spinnerDialog = null; - } - } - - /** - * Show the progress dialog. - * - * @param title Title of the dialog - * @param message The message of the dialog - */ - public synchronized void progressStart(final String title, final String message) { - if (this.progressDialog != null) { - this.progressDialog.dismiss(); - this.progressDialog = null; - } - final Notification notification = this; - final CordovaInterface cordova = this.cordova; - Runnable runnable = new Runnable() { - public void run() { - notification.progressDialog = createProgressDialog(cordova); // new ProgressDialog(cordova.getActivity(), AlertDialog.THEME_DEVICE_DEFAULT_LIGHT); - notification.progressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL); - notification.progressDialog.setTitle(title); - notification.progressDialog.setMessage(message); - notification.progressDialog.setCancelable(true); - notification.progressDialog.setMax(100); - notification.progressDialog.setProgress(0); - notification.progressDialog.setOnCancelListener( - new DialogInterface.OnCancelListener() { - public void onCancel(DialogInterface dialog) { - notification.progressDialog = null; - } - }); - notification.progressDialog.show(); - } - }; - this.cordova.getActivity().runOnUiThread(runnable); - } - - /** - * Set value of progress bar. - * - * @param value 0-100 - */ - public synchronized void progressValue(int value) { - if (this.progressDialog != null) { - this.progressDialog.setProgress(value); - } - } - - /** - * Stop progress dialog. - */ - public synchronized void progressStop() { - if (this.progressDialog != null) { - this.progressDialog.dismiss(); - this.progressDialog = null; - } - } - - @SuppressLint("NewApi") - private AlertDialog.Builder createDialog(CordovaInterface cordova) { - int currentapiVersion = android.os.Build.VERSION.SDK_INT; - if (currentapiVersion >= android.os.Build.VERSION_CODES.HONEYCOMB) { - return new AlertDialog.Builder(cordova.getActivity(), AlertDialog.THEME_DEVICE_DEFAULT_LIGHT); - } else { - return new AlertDialog.Builder(cordova.getActivity()); - } - } - - @SuppressLint("InlinedApi") - private ProgressDialog createProgressDialog(CordovaInterface cordova) { - int currentapiVersion = android.os.Build.VERSION.SDK_INT; - if (currentapiVersion >= android.os.Build.VERSION_CODES.ICE_CREAM_SANDWICH) { - return new ProgressDialog(cordova.getActivity(), AlertDialog.THEME_DEVICE_DEFAULT_LIGHT); - } else { - return new ProgressDialog(cordova.getActivity()); - } - } - - @SuppressLint("NewApi") - private void changeTextDirection(Builder dlg){ - int currentapiVersion = android.os.Build.VERSION.SDK_INT; - dlg.create(); - AlertDialog dialog = dlg.show(); - if (currentapiVersion >= android.os.Build.VERSION_CODES.JELLY_BEAN_MR1) { - TextView messageview = (TextView)dialog.findViewById(android.R.id.message); - messageview.setTextDirection(android.view.View.TEXT_DIRECTION_LOCALE); - } - } -} diff --git a/StoneIsland/platforms/android/src/org/apache/cordova/geolocation/Geolocation.java b/StoneIsland/platforms/android/src/org/apache/cordova/geolocation/Geolocation.java deleted file mode 100644 index 6452170a..00000000 --- a/StoneIsland/platforms/android/src/org/apache/cordova/geolocation/Geolocation.java +++ /dev/null @@ -1,107 +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 org.apache.cordova.geolocation; - -import android.content.pm.PackageManager; -import android.Manifest; -import android.os.Build; - -import org.apache.cordova.CallbackContext; -import org.apache.cordova.CordovaArgs; -import org.apache.cordova.CordovaPlugin; -import org.apache.cordova.PermissionHelper; -import org.apache.cordova.PluginResult; -import org.apache.cordova.LOG; -import org.json.JSONArray; -import org.json.JSONException; - -import javax.security.auth.callback.Callback; - -public class Geolocation extends CordovaPlugin { - - String TAG = "GeolocationPlugin"; - CallbackContext context; - - String [] permissions = { Manifest.permission.ACCESS_COARSE_LOCATION, Manifest.permission.ACCESS_FINE_LOCATION }; - - - public boolean execute(String action, JSONArray args, CallbackContext callbackContext) throws JSONException { - LOG.d(TAG, "We are entering execute"); - context = callbackContext; - if(action.equals("getPermission")) - { - if(hasPermisssion()) - { - PluginResult r = new PluginResult(PluginResult.Status.OK); - context.sendPluginResult(r); - return true; - } - else { - PermissionHelper.requestPermissions(this, 0, permissions); - } - return true; - } - return false; - } - - - public void onRequestPermissionResult(int requestCode, String[] permissions, - int[] grantResults) throws JSONException - { - PluginResult result; - //This is important if we're using Cordova without using Cordova, but we have the geolocation plugin installed - if(context != null) { - for (int r : grantResults) { - if (r == PackageManager.PERMISSION_DENIED) { - LOG.d(TAG, "Permission Denied!"); - result = new PluginResult(PluginResult.Status.ILLEGAL_ACCESS_EXCEPTION); - context.sendPluginResult(result); - return; - } - - } - result = new PluginResult(PluginResult.Status.OK); - context.sendPluginResult(result); - } - } - - public boolean hasPermisssion() { - for(String p : permissions) - { - if(!PermissionHelper.hasPermission(this, p)) - { - return false; - } - } - return true; - } - - /* - * We override this so that we can access the permissions variable, which no longer exists in - * the parent class, since we can't initialize it reliably in the constructor! - */ - - public void requestPermissions(int requestCode) - { - PermissionHelper.requestPermissions(this, requestCode, permissions); - } - - - -} diff --git a/StoneIsland/platforms/android/src/org/apache/cordova/inappbrowser/InAppBrowser.java b/StoneIsland/platforms/android/src/org/apache/cordova/inappbrowser/InAppBrowser.java deleted file mode 100644 index 8f4f3d97..00000000 --- a/StoneIsland/platforms/android/src/org/apache/cordova/inappbrowser/InAppBrowser.java +++ /dev/null @@ -1,1005 +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 org.apache.cordova.inappbrowser; - -import android.annotation.SuppressLint; -import android.content.Context; -import android.content.Intent; -import android.provider.Browser; -import android.content.res.Resources; -import android.graphics.Bitmap; -import android.graphics.drawable.Drawable; -import android.net.Uri; -import android.os.Build; -import android.os.Bundle; -import android.text.InputType; -import android.util.TypedValue; -import android.view.Gravity; -import android.view.KeyEvent; -import android.view.View; -import android.view.Window; -import android.view.WindowManager; -import android.view.WindowManager.LayoutParams; -import android.view.inputmethod.EditorInfo; -import android.view.inputmethod.InputMethodManager; -import android.webkit.CookieManager; -import android.webkit.CookieSyncManager; -import android.webkit.HttpAuthHandler; -import android.webkit.WebSettings; -import android.webkit.WebView; -import android.webkit.WebViewClient; -import android.widget.EditText; -import android.widget.ImageButton; -import android.widget.ImageView; -import android.widget.LinearLayout; -import android.widget.RelativeLayout; - -import org.apache.cordova.CallbackContext; -import org.apache.cordova.Config; -import org.apache.cordova.CordovaArgs; -import org.apache.cordova.CordovaHttpAuthHandler; -import org.apache.cordova.CordovaPlugin; -import org.apache.cordova.CordovaWebView; -import org.apache.cordova.LOG; -import org.apache.cordova.PluginManager; -import org.apache.cordova.PluginResult; -import org.json.JSONException; -import org.json.JSONObject; - -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Field; -import java.lang.reflect.Method; -import java.util.HashMap; -import java.util.StringTokenizer; - -@SuppressLint("SetJavaScriptEnabled") -public class InAppBrowser extends CordovaPlugin { - - private static final String NULL = "null"; - protected static final String LOG_TAG = "InAppBrowser"; - private static final String SELF = "_self"; - private static final String SYSTEM = "_system"; - private static final String EXIT_EVENT = "exit"; - private static final String LOCATION = "location"; - private static final String ZOOM = "zoom"; - private static final String HIDDEN = "hidden"; - private static final String LOAD_START_EVENT = "loadstart"; - private static final String LOAD_STOP_EVENT = "loadstop"; - private static final String LOAD_ERROR_EVENT = "loaderror"; - private static final String CLEAR_ALL_CACHE = "clearcache"; - private static final String CLEAR_SESSION_CACHE = "clearsessioncache"; - private static final String HARDWARE_BACK_BUTTON = "hardwareback"; - private static final String MEDIA_PLAYBACK_REQUIRES_USER_ACTION = "mediaPlaybackRequiresUserAction"; - private static final String SHOULD_PAUSE = "shouldPauseOnSuspend"; - - private InAppBrowserDialog dialog; - private WebView inAppWebView; - private EditText edittext; - private CallbackContext callbackContext; - private boolean showLocationBar = true; - private boolean showZoomControls = true; - private boolean openWindowHidden = false; - private boolean clearAllCache = false; - private boolean clearSessionCache = false; - private boolean hadwareBackButton = true; - private boolean mediaPlaybackRequiresUserGesture = false; - private boolean shouldPauseInAppBrowser = false; - - /** - * Executes the request and returns PluginResult. - * - * @param action the action to execute. - * @param args JSONArry of arguments for the plugin. - * @param callbackContext the callbackContext used when calling back into JavaScript. - * @return A PluginResult object with a status and message. - */ - public boolean execute(String action, CordovaArgs args, final CallbackContext callbackContext) throws JSONException { - if (action.equals("open")) { - this.callbackContext = callbackContext; - final String url = args.getString(0); - String t = args.optString(1); - if (t == null || t.equals("") || t.equals(NULL)) { - t = SELF; - } - final String target = t; - final HashMap<String, Boolean> features = parseFeature(args.optString(2)); - - LOG.d(LOG_TAG, "target = " + target); - - this.cordova.getActivity().runOnUiThread(new Runnable() { - @Override - public void run() { - String result = ""; - // SELF - if (SELF.equals(target)) { - LOG.d(LOG_TAG, "in self"); - /* This code exists for compatibility between 3.x and 4.x versions of Cordova. - * Previously the Config class had a static method, isUrlWhitelisted(). That - * responsibility has been moved to the plugins, with an aggregating method in - * PluginManager. - */ - Boolean shouldAllowNavigation = null; - if (url.startsWith("javascript:")) { - shouldAllowNavigation = true; - } - if (shouldAllowNavigation == null) { - try { - Method iuw = Config.class.getMethod("isUrlWhiteListed", String.class); - shouldAllowNavigation = (Boolean)iuw.invoke(null, url); - } catch (NoSuchMethodException e) { - LOG.d(LOG_TAG, e.getLocalizedMessage()); - } catch (IllegalAccessException e) { - LOG.d(LOG_TAG, e.getLocalizedMessage()); - } catch (InvocationTargetException e) { - LOG.d(LOG_TAG, e.getLocalizedMessage()); - } - } - if (shouldAllowNavigation == null) { - try { - Method gpm = webView.getClass().getMethod("getPluginManager"); - PluginManager pm = (PluginManager)gpm.invoke(webView); - Method san = pm.getClass().getMethod("shouldAllowNavigation", String.class); - shouldAllowNavigation = (Boolean)san.invoke(pm, url); - } catch (NoSuchMethodException e) { - LOG.d(LOG_TAG, e.getLocalizedMessage()); - } catch (IllegalAccessException e) { - LOG.d(LOG_TAG, e.getLocalizedMessage()); - } catch (InvocationTargetException e) { - LOG.d(LOG_TAG, e.getLocalizedMessage()); - } - } - // load in webview - if (Boolean.TRUE.equals(shouldAllowNavigation)) { - LOG.d(LOG_TAG, "loading in webview"); - webView.loadUrl(url); - } - //Load the dialer - else if (url.startsWith(WebView.SCHEME_TEL)) - { - try { - LOG.d(LOG_TAG, "loading in dialer"); - Intent intent = new Intent(Intent.ACTION_DIAL); - intent.setData(Uri.parse(url)); - cordova.getActivity().startActivity(intent); - } catch (android.content.ActivityNotFoundException e) { - LOG.e(LOG_TAG, "Error dialing " + url + ": " + e.toString()); - } - } - // load in InAppBrowser - else { - LOG.d(LOG_TAG, "loading in InAppBrowser"); - result = showWebPage(url, features); - } - } - // SYSTEM - else if (SYSTEM.equals(target)) { - LOG.d(LOG_TAG, "in system"); - result = openExternal(url); - } - // BLANK - or anything else - else { - LOG.d(LOG_TAG, "in blank"); - result = showWebPage(url, features); - } - - PluginResult pluginResult = new PluginResult(PluginResult.Status.OK, result); - pluginResult.setKeepCallback(true); - callbackContext.sendPluginResult(pluginResult); - } - }); - } - else if (action.equals("close")) { - closeDialog(); - } - else if (action.equals("injectScriptCode")) { - String jsWrapper = null; - if (args.getBoolean(1)) { - jsWrapper = String.format("(function(){prompt(JSON.stringify([eval(%%s)]), 'gap-iab://%s')})()", callbackContext.getCallbackId()); - } - injectDeferredObject(args.getString(0), jsWrapper); - } - else if (action.equals("injectScriptFile")) { - String jsWrapper; - if (args.getBoolean(1)) { - jsWrapper = String.format("(function(d) { var c = d.createElement('script'); c.src = %%s; c.onload = function() { prompt('', 'gap-iab://%s'); }; d.body.appendChild(c); })(document)", callbackContext.getCallbackId()); - } else { - jsWrapper = "(function(d) { var c = d.createElement('script'); c.src = %s; d.body.appendChild(c); })(document)"; - } - injectDeferredObject(args.getString(0), jsWrapper); - } - else if (action.equals("injectStyleCode")) { - String jsWrapper; - if (args.getBoolean(1)) { - jsWrapper = String.format("(function(d) { var c = d.createElement('style'); c.innerHTML = %%s; d.body.appendChild(c); prompt('', 'gap-iab://%s');})(document)", callbackContext.getCallbackId()); - } else { - jsWrapper = "(function(d) { var c = d.createElement('style'); c.innerHTML = %s; d.body.appendChild(c); })(document)"; - } - injectDeferredObject(args.getString(0), jsWrapper); - } - else if (action.equals("injectStyleFile")) { - String jsWrapper; - if (args.getBoolean(1)) { - jsWrapper = String.format("(function(d) { var c = d.createElement('link'); c.rel='stylesheet'; c.type='text/css'; c.href = %%s; d.head.appendChild(c); prompt('', 'gap-iab://%s');})(document)", callbackContext.getCallbackId()); - } else { - jsWrapper = "(function(d) { var c = d.createElement('link'); c.rel='stylesheet'; c.type='text/css'; c.href = %s; d.head.appendChild(c); })(document)"; - } - injectDeferredObject(args.getString(0), jsWrapper); - } - else if (action.equals("show")) { - this.cordova.getActivity().runOnUiThread(new Runnable() { - @Override - public void run() { - dialog.show(); - } - }); - PluginResult pluginResult = new PluginResult(PluginResult.Status.OK); - pluginResult.setKeepCallback(true); - this.callbackContext.sendPluginResult(pluginResult); - } - else { - return false; - } - return true; - } - - /** - * Called when the view navigates. - */ - @Override - public void onReset() { - closeDialog(); - } - - /** - * Called when the system is about to start resuming a previous activity. - */ - @Override - public void onPause(boolean multitasking) { - if (shouldPauseInAppBrowser) { - inAppWebView.onPause(); - } - } - - /** - * Called when the activity will start interacting with the user. - */ - @Override - public void onResume(boolean multitasking) { - if (shouldPauseInAppBrowser) { - inAppWebView.onResume(); - } - } - - /** - * Called by AccelBroker when listener is to be shut down. - * Stop listener. - */ - public void onDestroy() { - closeDialog(); - } - - /** - * Inject an object (script or style) into the InAppBrowser WebView. - * - * This is a helper method for the inject{Script|Style}{Code|File} API calls, which - * provides a consistent method for injecting JavaScript code into the document. - * - * If a wrapper string is supplied, then the source string will be JSON-encoded (adding - * quotes) and wrapped using string formatting. (The wrapper string should have a single - * '%s' marker) - * - * @param source The source object (filename or script/style text) to inject into - * the document. - * @param jsWrapper A JavaScript string to wrap the source string in, so that the object - * is properly injected, or null if the source string is JavaScript text - * which should be executed directly. - */ - private void injectDeferredObject(String source, String jsWrapper) { - String scriptToInject; - if (jsWrapper != null) { - org.json.JSONArray jsonEsc = new org.json.JSONArray(); - jsonEsc.put(source); - String jsonRepr = jsonEsc.toString(); - String jsonSourceString = jsonRepr.substring(1, jsonRepr.length()-1); - scriptToInject = String.format(jsWrapper, jsonSourceString); - } else { - scriptToInject = source; - } - final String finalScriptToInject = scriptToInject; - this.cordova.getActivity().runOnUiThread(new Runnable() { - @SuppressLint("NewApi") - @Override - public void run() { - if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) { - // This action will have the side-effect of blurring the currently focused element - inAppWebView.loadUrl("javascript:" + finalScriptToInject); - } else { - inAppWebView.evaluateJavascript(finalScriptToInject, null); - } - } - }); - } - - /** - * Put the list of features into a hash map - * - * @param optString - * @return - */ - private HashMap<String, Boolean> parseFeature(String optString) { - if (optString.equals(NULL)) { - return null; - } else { - HashMap<String, Boolean> map = new HashMap<String, Boolean>(); - StringTokenizer features = new StringTokenizer(optString, ","); - StringTokenizer option; - while(features.hasMoreElements()) { - option = new StringTokenizer(features.nextToken(), "="); - if (option.hasMoreElements()) { - String key = option.nextToken(); - Boolean value = option.nextToken().equals("no") ? Boolean.FALSE : Boolean.TRUE; - map.put(key, value); - } - } - return map; - } - } - - /** - * Display a new browser with the specified URL. - * - * @param url the url to load. - * @return "" if ok, or error message. - */ - public String openExternal(String url) { - try { - Intent intent = null; - intent = new Intent(Intent.ACTION_VIEW); - // Omitting the MIME type for file: URLs causes "No Activity found to handle Intent". - // Adding the MIME type to http: URLs causes them to not be handled by the downloader. - Uri uri = Uri.parse(url); - if ("file".equals(uri.getScheme())) { - intent.setDataAndType(uri, webView.getResourceApi().getMimeType(uri)); - } else { - intent.setData(uri); - } - intent.putExtra(Browser.EXTRA_APPLICATION_ID, cordova.getActivity().getPackageName()); - this.cordova.getActivity().startActivity(intent); - return ""; - } catch (android.content.ActivityNotFoundException e) { - LOG.d(LOG_TAG, "InAppBrowser: Error loading url "+url+":"+ e.toString()); - return e.toString(); - } - } - - /** - * Closes the dialog - */ - public void closeDialog() { - this.cordova.getActivity().runOnUiThread(new Runnable() { - @Override - public void run() { - final WebView childView = inAppWebView; - // The JS protects against multiple calls, so this should happen only when - // closeDialog() is called by other native code. - if (childView == null) { - return; - } - - childView.setWebViewClient(new WebViewClient() { - // NB: wait for about:blank before dismissing - public void onPageFinished(WebView view, String url) { - if (dialog != null) { - dialog.dismiss(); - dialog = null; - } - } - }); - // NB: From SDK 19: "If you call methods on WebView from any thread - // other than your app's UI thread, it can cause unexpected results." - // http://developer.android.com/guide/webapps/migrating.html#Threads - childView.loadUrl("about:blank"); - - try { - JSONObject obj = new JSONObject(); - obj.put("type", EXIT_EVENT); - sendUpdate(obj, false); - } catch (JSONException ex) { - LOG.d(LOG_TAG, "Should never happen"); - } - } - }); - } - - /** - * Checks to see if it is possible to go back one page in history, then does so. - */ - public void goBack() { - if (this.inAppWebView.canGoBack()) { - this.inAppWebView.goBack(); - } - } - - /** - * Can the web browser go back? - * @return boolean - */ - public boolean canGoBack() { - return this.inAppWebView.canGoBack(); - } - - /** - * Has the user set the hardware back button to go back - * @return boolean - */ - public boolean hardwareBack() { - return hadwareBackButton; - } - - /** - * Checks to see if it is possible to go forward one page in history, then does so. - */ - private void goForward() { - if (this.inAppWebView.canGoForward()) { - this.inAppWebView.goForward(); - } - } - - /** - * Navigate to the new page - * - * @param url to load - */ - private void navigate(String url) { - InputMethodManager imm = (InputMethodManager)this.cordova.getActivity().getSystemService(Context.INPUT_METHOD_SERVICE); - imm.hideSoftInputFromWindow(edittext.getWindowToken(), 0); - - if (!url.startsWith("http") && !url.startsWith("file:")) { - this.inAppWebView.loadUrl("http://" + url); - } else { - this.inAppWebView.loadUrl(url); - } - this.inAppWebView.requestFocus(); - } - - - /** - * Should we show the location bar? - * - * @return boolean - */ - private boolean getShowLocationBar() { - return this.showLocationBar; - } - - private InAppBrowser getInAppBrowser(){ - return this; - } - - /** - * Display a new browser with the specified URL. - * - * @param url the url to load. - * @param features jsonObject - */ - public String showWebPage(final String url, HashMap<String, Boolean> features) { - // Determine if we should hide the location bar. - showLocationBar = true; - showZoomControls = true; - openWindowHidden = false; - mediaPlaybackRequiresUserGesture = false; - - if (features != null) { - Boolean show = features.get(LOCATION); - if (show != null) { - showLocationBar = show.booleanValue(); - } - Boolean zoom = features.get(ZOOM); - if (zoom != null) { - showZoomControls = zoom.booleanValue(); - } - Boolean hidden = features.get(HIDDEN); - if (hidden != null) { - openWindowHidden = hidden.booleanValue(); - } - Boolean hardwareBack = features.get(HARDWARE_BACK_BUTTON); - if (hardwareBack != null) { - hadwareBackButton = hardwareBack.booleanValue(); - } - Boolean mediaPlayback = features.get(MEDIA_PLAYBACK_REQUIRES_USER_ACTION); - if (mediaPlayback != null) { - mediaPlaybackRequiresUserGesture = mediaPlayback.booleanValue(); - } - Boolean cache = features.get(CLEAR_ALL_CACHE); - if (cache != null) { - clearAllCache = cache.booleanValue(); - } else { - cache = features.get(CLEAR_SESSION_CACHE); - if (cache != null) { - clearSessionCache = cache.booleanValue(); - } - } - Boolean shouldPause = features.get(SHOULD_PAUSE); - if (shouldPause != null) { - shouldPauseInAppBrowser = shouldPause.booleanValue(); - } - } - - final CordovaWebView thatWebView = this.webView; - - // Create dialog in new thread - Runnable runnable = new Runnable() { - /** - * Convert our DIP units to Pixels - * - * @return int - */ - private int dpToPixels(int dipValue) { - int value = (int) TypedValue.applyDimension( TypedValue.COMPLEX_UNIT_DIP, - (float) dipValue, - cordova.getActivity().getResources().getDisplayMetrics() - ); - - return value; - } - - @SuppressLint("NewApi") - public void run() { - - // CB-6702 InAppBrowser hangs when opening more than one instance - if (dialog != null) { - dialog.dismiss(); - }; - - // Let's create the main dialog - dialog = new InAppBrowserDialog(cordova.getActivity(), android.R.style.Theme_NoTitleBar); - dialog.getWindow().getAttributes().windowAnimations = android.R.style.Animation_Dialog; - dialog.requestWindowFeature(Window.FEATURE_NO_TITLE); - dialog.setCancelable(true); - dialog.setInAppBroswer(getInAppBrowser()); - - // Main container layout - LinearLayout main = new LinearLayout(cordova.getActivity()); - main.setOrientation(LinearLayout.VERTICAL); - - // Toolbar layout - RelativeLayout toolbar = new RelativeLayout(cordova.getActivity()); - //Please, no more black! - toolbar.setBackgroundColor(android.graphics.Color.LTGRAY); - toolbar.setLayoutParams(new RelativeLayout.LayoutParams(LayoutParams.MATCH_PARENT, this.dpToPixels(44))); - toolbar.setPadding(this.dpToPixels(2), this.dpToPixels(2), this.dpToPixels(2), this.dpToPixels(2)); - toolbar.setHorizontalGravity(Gravity.LEFT); - toolbar.setVerticalGravity(Gravity.TOP); - - // Action Button Container layout - RelativeLayout actionButtonContainer = new RelativeLayout(cordova.getActivity()); - actionButtonContainer.setLayoutParams(new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT)); - actionButtonContainer.setHorizontalGravity(Gravity.LEFT); - actionButtonContainer.setVerticalGravity(Gravity.CENTER_VERTICAL); - actionButtonContainer.setId(Integer.valueOf(1)); - - // Back button - ImageButton back = new ImageButton(cordova.getActivity()); - RelativeLayout.LayoutParams backLayoutParams = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT); - backLayoutParams.addRule(RelativeLayout.ALIGN_LEFT); - back.setLayoutParams(backLayoutParams); - back.setContentDescription("Back Button"); - back.setId(Integer.valueOf(2)); - Resources activityRes = cordova.getActivity().getResources(); - int backResId = activityRes.getIdentifier("ic_action_previous_item", "drawable", cordova.getActivity().getPackageName()); - Drawable backIcon = activityRes.getDrawable(backResId); - if (Build.VERSION.SDK_INT >= 16) - back.setBackground(null); - else - back.setBackgroundDrawable(null); - back.setImageDrawable(backIcon); - back.setScaleType(ImageView.ScaleType.FIT_CENTER); - back.setPadding(0, this.dpToPixels(10), 0, this.dpToPixels(10)); - if (Build.VERSION.SDK_INT >= 16) - back.getAdjustViewBounds(); - - back.setOnClickListener(new View.OnClickListener() { - public void onClick(View v) { - goBack(); - } - }); - - // Forward button - ImageButton forward = new ImageButton(cordova.getActivity()); - RelativeLayout.LayoutParams forwardLayoutParams = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT); - forwardLayoutParams.addRule(RelativeLayout.RIGHT_OF, 2); - forward.setLayoutParams(forwardLayoutParams); - forward.setContentDescription("Forward Button"); - forward.setId(Integer.valueOf(3)); - int fwdResId = activityRes.getIdentifier("ic_action_next_item", "drawable", cordova.getActivity().getPackageName()); - Drawable fwdIcon = activityRes.getDrawable(fwdResId); - if (Build.VERSION.SDK_INT >= 16) - forward.setBackground(null); - else - forward.setBackgroundDrawable(null); - forward.setImageDrawable(fwdIcon); - forward.setScaleType(ImageView.ScaleType.FIT_CENTER); - forward.setPadding(0, this.dpToPixels(10), 0, this.dpToPixels(10)); - if (Build.VERSION.SDK_INT >= 16) - forward.getAdjustViewBounds(); - - forward.setOnClickListener(new View.OnClickListener() { - public void onClick(View v) { - goForward(); - } - }); - - // Edit Text Box - edittext = new EditText(cordova.getActivity()); - RelativeLayout.LayoutParams textLayoutParams = new RelativeLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT); - textLayoutParams.addRule(RelativeLayout.RIGHT_OF, 1); - textLayoutParams.addRule(RelativeLayout.LEFT_OF, 5); - edittext.setLayoutParams(textLayoutParams); - edittext.setId(Integer.valueOf(4)); - edittext.setSingleLine(true); - edittext.setText(url); - edittext.setInputType(InputType.TYPE_TEXT_VARIATION_URI); - edittext.setImeOptions(EditorInfo.IME_ACTION_GO); - edittext.setInputType(InputType.TYPE_NULL); // Will not except input... Makes the text NON-EDITABLE - edittext.setOnKeyListener(new View.OnKeyListener() { - public boolean onKey(View v, int keyCode, KeyEvent event) { - // If the event is a key-down event on the "enter" button - if ((event.getAction() == KeyEvent.ACTION_DOWN) && (keyCode == KeyEvent.KEYCODE_ENTER)) { - navigate(edittext.getText().toString()); - return true; - } - return false; - } - }); - - // Close/Done button - ImageButton close = new ImageButton(cordova.getActivity()); - RelativeLayout.LayoutParams closeLayoutParams = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT); - closeLayoutParams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT); - close.setLayoutParams(closeLayoutParams); - forward.setContentDescription("Close Button"); - close.setId(Integer.valueOf(5)); - int closeResId = activityRes.getIdentifier("ic_action_remove", "drawable", cordova.getActivity().getPackageName()); - Drawable closeIcon = activityRes.getDrawable(closeResId); - if (Build.VERSION.SDK_INT >= 16) - close.setBackground(null); - else - close.setBackgroundDrawable(null); - close.setImageDrawable(closeIcon); - close.setScaleType(ImageView.ScaleType.FIT_CENTER); - back.setPadding(0, this.dpToPixels(10), 0, this.dpToPixels(10)); - if (Build.VERSION.SDK_INT >= 16) - close.getAdjustViewBounds(); - - close.setOnClickListener(new View.OnClickListener() { - public void onClick(View v) { - closeDialog(); - } - }); - - // WebView - inAppWebView = new WebView(cordova.getActivity()); - inAppWebView.setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT)); - inAppWebView.setId(Integer.valueOf(6)); - inAppWebView.setWebChromeClient(new InAppChromeClient(thatWebView)); - WebViewClient client = new InAppBrowserClient(thatWebView, edittext); - inAppWebView.setWebViewClient(client); - WebSettings settings = inAppWebView.getSettings(); - settings.setJavaScriptEnabled(true); - settings.setJavaScriptCanOpenWindowsAutomatically(true); - settings.setBuiltInZoomControls(showZoomControls); - settings.setPluginState(android.webkit.WebSettings.PluginState.ON); - - if(android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.JELLY_BEAN_MR1) { - settings.setMediaPlaybackRequiresUserGesture(mediaPlaybackRequiresUserGesture); - } - - String overrideUserAgent = preferences.getString("OverrideUserAgent", null); - String appendUserAgent = preferences.getString("AppendUserAgent", null); - - if (overrideUserAgent != null) { - settings.setUserAgentString(overrideUserAgent); - } - if (appendUserAgent != null) { - settings.setUserAgentString(settings.getUserAgentString() + appendUserAgent); - } - - //Toggle whether this is enabled or not! - Bundle appSettings = cordova.getActivity().getIntent().getExtras(); - boolean enableDatabase = appSettings == null ? true : appSettings.getBoolean("InAppBrowserStorageEnabled", true); - if (enableDatabase) { - String databasePath = cordova.getActivity().getApplicationContext().getDir("inAppBrowserDB", Context.MODE_PRIVATE).getPath(); - settings.setDatabasePath(databasePath); - settings.setDatabaseEnabled(true); - } - settings.setDomStorageEnabled(true); - - if (clearAllCache) { - CookieManager.getInstance().removeAllCookie(); - } else if (clearSessionCache) { - CookieManager.getInstance().removeSessionCookie(); - } - - inAppWebView.loadUrl(url); - inAppWebView.setId(Integer.valueOf(6)); - inAppWebView.getSettings().setLoadWithOverviewMode(true); - inAppWebView.getSettings().setUseWideViewPort(true); - inAppWebView.requestFocus(); - inAppWebView.requestFocusFromTouch(); - - // Add the back and forward buttons to our action button container layout - actionButtonContainer.addView(back); - actionButtonContainer.addView(forward); - - // Add the views to our toolbar - toolbar.addView(actionButtonContainer); - toolbar.addView(edittext); - toolbar.addView(close); - - // Don't add the toolbar if its been disabled - if (getShowLocationBar()) { - // Add our toolbar to our main view/layout - main.addView(toolbar); - } - - // Add our webview to our main view/layout - main.addView(inAppWebView); - - WindowManager.LayoutParams lp = new WindowManager.LayoutParams(); - lp.copyFrom(dialog.getWindow().getAttributes()); - lp.width = WindowManager.LayoutParams.MATCH_PARENT; - lp.height = WindowManager.LayoutParams.MATCH_PARENT; - - dialog.setContentView(main); - dialog.show(); - dialog.getWindow().setAttributes(lp); - // the goal of openhidden is to load the url and not display it - // Show() needs to be called to cause the URL to be loaded - if(openWindowHidden) { - dialog.hide(); - } - } - }; - this.cordova.getActivity().runOnUiThread(runnable); - return ""; - } - - /** - * Create a new plugin success result and send it back to JavaScript - * - * @param obj a JSONObject contain event payload information - */ - private void sendUpdate(JSONObject obj, boolean keepCallback) { - sendUpdate(obj, keepCallback, PluginResult.Status.OK); - } - - /** - * Create a new plugin result and send it back to JavaScript - * - * @param obj a JSONObject contain event payload information - * @param status the status code to return to the JavaScript environment - */ - private void sendUpdate(JSONObject obj, boolean keepCallback, PluginResult.Status status) { - if (callbackContext != null) { - PluginResult result = new PluginResult(status, obj); - result.setKeepCallback(keepCallback); - callbackContext.sendPluginResult(result); - if (!keepCallback) { - callbackContext = null; - } - } - } - - /** - * The webview client receives notifications about appView - */ - public class InAppBrowserClient extends WebViewClient { - EditText edittext; - CordovaWebView webView; - - /** - * Constructor. - * - * @param webView - * @param mEditText - */ - public InAppBrowserClient(CordovaWebView webView, EditText mEditText) { - this.webView = webView; - this.edittext = mEditText; - } - - /** - * Override the URL that should be loaded - * - * This handles a small subset of all the URIs that would be encountered. - * - * @param webView - * @param url - */ - @Override - public boolean shouldOverrideUrlLoading(WebView webView, String url) { - if (url.startsWith(WebView.SCHEME_TEL)) { - try { - Intent intent = new Intent(Intent.ACTION_DIAL); - intent.setData(Uri.parse(url)); - cordova.getActivity().startActivity(intent); - return true; - } catch (android.content.ActivityNotFoundException e) { - LOG.e(LOG_TAG, "Error dialing " + url + ": " + e.toString()); - } - } else if (url.startsWith("geo:") || url.startsWith(WebView.SCHEME_MAILTO) || url.startsWith("market:") || url.startsWith("intent:")) { - try { - Intent intent = new Intent(Intent.ACTION_VIEW); - intent.setData(Uri.parse(url)); - cordova.getActivity().startActivity(intent); - return true; - } catch (android.content.ActivityNotFoundException e) { - LOG.e(LOG_TAG, "Error with " + url + ": " + e.toString()); - } - } - // If sms:5551212?body=This is the message - else if (url.startsWith("sms:")) { - try { - Intent intent = new Intent(Intent.ACTION_VIEW); - - // Get address - String address = null; - int parmIndex = url.indexOf('?'); - if (parmIndex == -1) { - address = url.substring(4); - } else { - address = url.substring(4, parmIndex); - - // If body, then set sms body - Uri uri = Uri.parse(url); - String query = uri.getQuery(); - if (query != null) { - if (query.startsWith("body=")) { - intent.putExtra("sms_body", query.substring(5)); - } - } - } - intent.setData(Uri.parse("sms:" + address)); - intent.putExtra("address", address); - intent.setType("vnd.android-dir/mms-sms"); - cordova.getActivity().startActivity(intent); - return true; - } catch (android.content.ActivityNotFoundException e) { - LOG.e(LOG_TAG, "Error sending sms " + url + ":" + e.toString()); - } - } - return false; - } - - - /* - * onPageStarted fires the LOAD_START_EVENT - * - * @param view - * @param url - * @param favicon - */ - @Override - public void onPageStarted(WebView view, String url, Bitmap favicon) { - super.onPageStarted(view, url, favicon); - String newloc = ""; - if (url.startsWith("http:") || url.startsWith("https:") || url.startsWith("file:")) { - newloc = url; - } - else - { - // Assume that everything is HTTP at this point, because if we don't specify, - // it really should be. Complain loudly about this!!! - LOG.e(LOG_TAG, "Possible Uncaught/Unknown URI"); - newloc = "http://" + url; - } - - // Update the UI if we haven't already - if (!newloc.equals(edittext.getText().toString())) { - edittext.setText(newloc); - } - - try { - JSONObject obj = new JSONObject(); - obj.put("type", LOAD_START_EVENT); - obj.put("url", newloc); - sendUpdate(obj, true); - } catch (JSONException ex) { - LOG.e(LOG_TAG, "URI passed in has caused a JSON error."); - } - } - - - - public void onPageFinished(WebView view, String url) { - super.onPageFinished(view, url); - - // CB-10395 InAppBrowser's WebView not storing cookies reliable to local device storage - if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.LOLLIPOP) { - CookieManager.getInstance().flush(); - } else { - CookieSyncManager.getInstance().sync(); - } - - try { - JSONObject obj = new JSONObject(); - obj.put("type", LOAD_STOP_EVENT); - obj.put("url", url); - - sendUpdate(obj, true); - } catch (JSONException ex) { - LOG.d(LOG_TAG, "Should never happen"); - } - } - - public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) { - super.onReceivedError(view, errorCode, description, failingUrl); - - try { - JSONObject obj = new JSONObject(); - obj.put("type", LOAD_ERROR_EVENT); - obj.put("url", failingUrl); - obj.put("code", errorCode); - obj.put("message", description); - - sendUpdate(obj, true, PluginResult.Status.ERROR); - } catch (JSONException ex) { - LOG.d(LOG_TAG, "Should never happen"); - } - } - - /** - * On received http auth request. - */ - @Override - public void onReceivedHttpAuthRequest(WebView view, HttpAuthHandler handler, String host, String realm) { - - // Check if there is some plugin which can resolve this auth challenge - PluginManager pluginManager = null; - try { - Method gpm = webView.getClass().getMethod("getPluginManager"); - pluginManager = (PluginManager)gpm.invoke(webView); - } catch (NoSuchMethodException e) { - LOG.d(LOG_TAG, e.getLocalizedMessage()); - } catch (IllegalAccessException e) { - LOG.d(LOG_TAG, e.getLocalizedMessage()); - } catch (InvocationTargetException e) { - LOG.d(LOG_TAG, e.getLocalizedMessage()); - } - - if (pluginManager == null) { - try { - Field pmf = webView.getClass().getField("pluginManager"); - pluginManager = (PluginManager)pmf.get(webView); - } catch (NoSuchFieldException e) { - LOG.d(LOG_TAG, e.getLocalizedMessage()); - } catch (IllegalAccessException e) { - LOG.d(LOG_TAG, e.getLocalizedMessage()); - } - } - - if (pluginManager != null && pluginManager.onReceivedHttpAuthRequest(webView, new CordovaHttpAuthHandler(handler), host, realm)) { - return; - } - - // By default handle 401 like we'd normally do! - super.onReceivedHttpAuthRequest(view, handler, host, realm); - } - } -} diff --git a/StoneIsland/platforms/android/src/org/apache/cordova/inappbrowser/InAppBrowserDialog.java b/StoneIsland/platforms/android/src/org/apache/cordova/inappbrowser/InAppBrowserDialog.java deleted file mode 100644 index e7b212f2..00000000 --- a/StoneIsland/platforms/android/src/org/apache/cordova/inappbrowser/InAppBrowserDialog.java +++ /dev/null @@ -1,57 +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 org.apache.cordova.inappbrowser; - -import android.app.AlertDialog; -import android.app.Dialog; -import android.content.Context; - -import org.json.JSONException; -import org.json.JSONObject; - -/** - * Created by Oliver on 22/11/2013. - */ -public class InAppBrowserDialog extends Dialog { - Context context; - InAppBrowser inAppBrowser = null; - - public InAppBrowserDialog(Context context, int theme) { - super(context, theme); - this.context = context; - } - - public void setInAppBroswer(InAppBrowser browser) { - this.inAppBrowser = browser; - } - - public void onBackPressed () { - if (this.inAppBrowser == null) { - this.dismiss(); - } else { - // better to go through the in inAppBrowser - // because it does a clean up - if (this.inAppBrowser.hardwareBack() && this.inAppBrowser.canGoBack()) { - this.inAppBrowser.goBack(); - } else { - this.inAppBrowser.closeDialog(); - } - } - } -} diff --git a/StoneIsland/platforms/android/src/org/apache/cordova/inappbrowser/InAppChromeClient.java b/StoneIsland/platforms/android/src/org/apache/cordova/inappbrowser/InAppChromeClient.java deleted file mode 100644 index a2145e6a..00000000 --- a/StoneIsland/platforms/android/src/org/apache/cordova/inappbrowser/InAppChromeClient.java +++ /dev/null @@ -1,133 +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 org.apache.cordova.inappbrowser; - -import org.apache.cordova.CordovaWebView; -import org.apache.cordova.LOG; -import org.apache.cordova.PluginResult; -import org.json.JSONArray; -import org.json.JSONException; - -import android.webkit.JsPromptResult; -import android.webkit.WebChromeClient; -import android.webkit.WebStorage; -import android.webkit.WebView; -import android.webkit.WebViewClient; -import android.webkit.GeolocationPermissions.Callback; - -public class InAppChromeClient extends WebChromeClient { - - private CordovaWebView webView; - private String LOG_TAG = "InAppChromeClient"; - private long MAX_QUOTA = 100 * 1024 * 1024; - - public InAppChromeClient(CordovaWebView webView) { - super(); - this.webView = webView; - } - /** - * Handle database quota exceeded notification. - * - * @param url - * @param databaseIdentifier - * @param currentQuota - * @param estimatedSize - * @param totalUsedQuota - * @param quotaUpdater - */ - @Override - public void onExceededDatabaseQuota(String url, String databaseIdentifier, long currentQuota, long estimatedSize, - long totalUsedQuota, WebStorage.QuotaUpdater quotaUpdater) - { - LOG.d(LOG_TAG, "onExceededDatabaseQuota estimatedSize: %d currentQuota: %d totalUsedQuota: %d", estimatedSize, currentQuota, totalUsedQuota); - quotaUpdater.updateQuota(MAX_QUOTA); - } - - /** - * Instructs the client to show a prompt to ask the user to set the Geolocation permission state for the specified origin. - * - * @param origin - * @param callback - */ - @Override - public void onGeolocationPermissionsShowPrompt(String origin, Callback callback) { - super.onGeolocationPermissionsShowPrompt(origin, callback); - callback.invoke(origin, true, false); - } - - /** - * Tell the client to display a prompt dialog to the user. - * If the client returns true, WebView will assume that the client will - * handle the prompt dialog and call the appropriate JsPromptResult method. - * - * The prompt bridge provided for the InAppBrowser is capable of executing any - * oustanding callback belonging to the InAppBrowser plugin. Care has been - * taken that other callbacks cannot be triggered, and that no other code - * execution is possible. - * - * To trigger the bridge, the prompt default value should be of the form: - * - * gap-iab://<callbackId> - * - * where <callbackId> is the string id of the callback to trigger (something - * like "InAppBrowser0123456789") - * - * If present, the prompt message is expected to be a JSON-encoded value to - * pass to the callback. A JSON_EXCEPTION is returned if the JSON is invalid. - * - * @param view - * @param url - * @param message - * @param defaultValue - * @param result - */ - @Override - public boolean onJsPrompt(WebView view, String url, String message, String defaultValue, JsPromptResult result) { - // See if the prompt string uses the 'gap-iab' protocol. If so, the remainder should be the id of a callback to execute. - if (defaultValue != null && defaultValue.startsWith("gap")) { - if(defaultValue.startsWith("gap-iab://")) { - PluginResult scriptResult; - String scriptCallbackId = defaultValue.substring(10); - if (scriptCallbackId.startsWith("InAppBrowser")) { - if(message == null || message.length() == 0) { - scriptResult = new PluginResult(PluginResult.Status.OK, new JSONArray()); - } else { - try { - scriptResult = new PluginResult(PluginResult.Status.OK, new JSONArray(message)); - } catch(JSONException e) { - scriptResult = new PluginResult(PluginResult.Status.JSON_EXCEPTION, e.getMessage()); - } - } - this.webView.sendPluginResult(scriptResult, scriptCallbackId); - result.confirm(""); - return true; - } - } - else - { - // Anything else with a gap: prefix should get this message - LOG.w(LOG_TAG, "InAppBrowser does not support Cordova API calls: " + url + " " + defaultValue); - result.cancel(); - return true; - } - } - return false; - } - -} diff --git a/StoneIsland/platforms/android/src/org/apache/cordova/networkinformation/NetworkManager.java b/StoneIsland/platforms/android/src/org/apache/cordova/networkinformation/NetworkManager.java deleted file mode 100755 index 614b6e7b..00000000 --- a/StoneIsland/platforms/android/src/org/apache/cordova/networkinformation/NetworkManager.java +++ /dev/null @@ -1,287 +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 org.apache.cordova.networkinformation; - -import org.apache.cordova.CallbackContext; -import org.apache.cordova.CordovaInterface; -import org.apache.cordova.CordovaPlugin; -import org.apache.cordova.LOG; -import org.apache.cordova.PluginResult; -import org.apache.cordova.CordovaWebView; -import org.json.JSONArray; -import org.json.JSONException; -import org.json.JSONObject; - -import android.content.BroadcastReceiver; -import android.content.Context; -import android.content.Intent; -import android.content.IntentFilter; -import android.net.ConnectivityManager; -import android.net.NetworkInfo; - -import java.util.Locale; - -public class NetworkManager extends CordovaPlugin { - - public static int NOT_REACHABLE = 0; - public static int REACHABLE_VIA_CARRIER_DATA_NETWORK = 1; - public static int REACHABLE_VIA_WIFI_NETWORK = 2; - - public static final String WIFI = "wifi"; - public static final String WIMAX = "wimax"; - // mobile - public static final String MOBILE = "mobile"; - - // Android L calls this Cellular, because I have no idea! - public static final String CELLULAR = "cellular"; - // 2G network types - public static final String TWO_G = "2g"; - public static final String GSM = "gsm"; - public static final String GPRS = "gprs"; - public static final String EDGE = "edge"; - // 3G network types - public static final String THREE_G = "3g"; - public static final String CDMA = "cdma"; - public static final String UMTS = "umts"; - public static final String HSPA = "hspa"; - public static final String HSUPA = "hsupa"; - public static final String HSDPA = "hsdpa"; - public static final String ONEXRTT = "1xrtt"; - public static final String EHRPD = "ehrpd"; - // 4G network types - public static final String FOUR_G = "4g"; - public static final String LTE = "lte"; - public static final String UMB = "umb"; - public static final String HSPA_PLUS = "hspa+"; - // return type - public static final String TYPE_UNKNOWN = "unknown"; - public static final String TYPE_ETHERNET = "ethernet"; - public static final String TYPE_ETHERNET_SHORT = "eth"; - public static final String TYPE_WIFI = "wifi"; - public static final String TYPE_2G = "2g"; - public static final String TYPE_3G = "3g"; - public static final String TYPE_4G = "4g"; - public static final String TYPE_NONE = "none"; - - private static final String LOG_TAG = "NetworkManager"; - - private CallbackContext connectionCallbackContext; - - ConnectivityManager sockMan; - BroadcastReceiver receiver; - private JSONObject lastInfo = null; - - /** - * Sets the context of the Command. This can then be used to do things like - * get file paths associated with the Activity. - * - * @param cordova The context of the main Activity. - * @param webView The CordovaWebView Cordova is running in. - */ - public void initialize(CordovaInterface cordova, CordovaWebView webView) { - super.initialize(cordova, webView); - this.sockMan = (ConnectivityManager) cordova.getActivity().getSystemService(Context.CONNECTIVITY_SERVICE); - this.connectionCallbackContext = null; - - // We need to listen to connectivity events to update navigator.connection - IntentFilter intentFilter = new IntentFilter(); - intentFilter.addAction(ConnectivityManager.CONNECTIVITY_ACTION); - if (this.receiver == null) { - this.receiver = new BroadcastReceiver() { - @Override - public void onReceive(Context context, Intent intent) { - // (The null check is for the ARM Emulator, please use Intel Emulator for better results) - if(NetworkManager.this.webView != null) - updateConnectionInfo(sockMan.getActiveNetworkInfo()); - } - }; - webView.getContext().registerReceiver(this.receiver, intentFilter); - } - - } - - /** - * Executes the request and returns PluginResult. - * - * @param action The action to execute. - * @param args JSONArry of arguments for the plugin. - * @param callbackContext The callback id used when calling back into JavaScript. - * @return True if the action was valid, false otherwise. - */ - public boolean execute(String action, JSONArray args, CallbackContext callbackContext) { - if (action.equals("getConnectionInfo")) { - this.connectionCallbackContext = callbackContext; - NetworkInfo info = sockMan.getActiveNetworkInfo(); - String connectionType = ""; - try { - connectionType = this.getConnectionInfo(info).get("type").toString(); - } catch (JSONException e) { - LOG.d(LOG_TAG, e.getLocalizedMessage()); - } - - PluginResult pluginResult = new PluginResult(PluginResult.Status.OK, connectionType); - pluginResult.setKeepCallback(true); - callbackContext.sendPluginResult(pluginResult); - return true; - } - return false; - } - - /** - * Stop network receiver. - */ - public void onDestroy() { - if (this.receiver != null) { - try { - webView.getContext().unregisterReceiver(this.receiver); - } catch (Exception e) { - LOG.e(LOG_TAG, "Error unregistering network receiver: " + e.getMessage(), e); - } finally { - receiver = null; - } - } - } - - //-------------------------------------------------------------------------- - // LOCAL METHODS - //-------------------------------------------------------------------------- - - /** - * Updates the JavaScript side whenever the connection changes - * - * @param info the current active network info - * @return - */ - private void updateConnectionInfo(NetworkInfo info) { - // send update to javascript "navigator.network.connection" - // Jellybean sends its own info - JSONObject thisInfo = this.getConnectionInfo(info); - if(!thisInfo.equals(lastInfo)) - { - String connectionType = ""; - try { - connectionType = thisInfo.get("type").toString(); - } catch (JSONException e) { - LOG.d(LOG_TAG, e.getLocalizedMessage()); - } - - sendUpdate(connectionType); - lastInfo = thisInfo; - } - } - - /** - * Get the latest network connection information - * - * @param info the current active network info - * @return a JSONObject that represents the network info - */ - private JSONObject getConnectionInfo(NetworkInfo info) { - String type = TYPE_NONE; - String extraInfo = ""; - if (info != null) { - // If we are not connected to any network set type to none - if (!info.isConnected()) { - type = TYPE_NONE; - } - else { - type = getType(info); - } - extraInfo = info.getExtraInfo(); - } - - LOG.d(LOG_TAG, "Connection Type: " + type); - LOG.d(LOG_TAG, "Connection Extra Info: " + extraInfo); - - JSONObject connectionInfo = new JSONObject(); - - try { - connectionInfo.put("type", type); - connectionInfo.put("extraInfo", extraInfo); - } catch (JSONException e) { - LOG.d(LOG_TAG, e.getLocalizedMessage()); - } - - return connectionInfo; - } - - /** - * Create a new plugin result and send it back to JavaScript - * - * @param connection the network info to set as navigator.connection - */ - private void sendUpdate(String type) { - if (connectionCallbackContext != null) { - PluginResult result = new PluginResult(PluginResult.Status.OK, type); - result.setKeepCallback(true); - connectionCallbackContext.sendPluginResult(result); - } - webView.postMessage("networkconnection", type); - } - - /** - * Determine the type of connection - * - * @param info the network info so we can determine connection type. - * @return the type of mobile network we are on - */ - private String getType(NetworkInfo info) { - if (info != null) { - String type = info.getTypeName().toLowerCase(Locale.US); - - LOG.d(LOG_TAG, "toLower : " + type.toLowerCase()); - LOG.d(LOG_TAG, "wifi : " + WIFI); - if (type.equals(WIFI)) { - return TYPE_WIFI; - } - else if (type.toLowerCase().equals(TYPE_ETHERNET) || type.toLowerCase().startsWith(TYPE_ETHERNET_SHORT)) { - return TYPE_ETHERNET; - } - else if (type.equals(MOBILE) || type.equals(CELLULAR)) { - type = info.getSubtypeName().toLowerCase(Locale.US); - if (type.equals(GSM) || - type.equals(GPRS) || - type.equals(EDGE) || - type.equals(TWO_G)) { - return TYPE_2G; - } - else if (type.startsWith(CDMA) || - type.equals(UMTS) || - type.equals(ONEXRTT) || - type.equals(EHRPD) || - type.equals(HSUPA) || - type.equals(HSDPA) || - type.equals(HSPA) || - type.equals(THREE_G)) { - return TYPE_3G; - } - else if (type.equals(LTE) || - type.equals(UMB) || - type.equals(HSPA_PLUS) || - type.equals(FOUR_G)) { - return TYPE_4G; - } - } - } - else { - return TYPE_NONE; - } - return TYPE_UNKNOWN; - } -} diff --git a/StoneIsland/platforms/android/src/org/apache/cordova/splashscreen/SplashScreen.java b/StoneIsland/platforms/android/src/org/apache/cordova/splashscreen/SplashScreen.java deleted file mode 100644 index 14b63790..00000000 --- a/StoneIsland/platforms/android/src/org/apache/cordova/splashscreen/SplashScreen.java +++ /dev/null @@ -1,385 +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 org.apache.cordova.splashscreen; - -import android.app.Dialog; -import android.app.ProgressDialog; -import android.content.Context; -import android.content.DialogInterface; -import android.content.res.Configuration; -import android.graphics.Color; -import android.graphics.drawable.ColorDrawable; -import android.os.Handler; -import android.view.Display; -import android.view.Gravity; -import android.view.View; -import android.view.ViewGroup.LayoutParams; -import android.view.WindowManager; -import android.view.animation.Animation; -import android.view.animation.AlphaAnimation; -import android.view.animation.DecelerateInterpolator; -import android.widget.ImageView; -import android.widget.LinearLayout; -import android.widget.ProgressBar; -import android.widget.RelativeLayout; - -import org.apache.cordova.CallbackContext; -import org.apache.cordova.CordovaPlugin; -import org.apache.cordova.CordovaWebView; -import org.json.JSONArray; -import org.json.JSONException; - -public class SplashScreen extends CordovaPlugin { - private static final String LOG_TAG = "SplashScreen"; - // Cordova 3.x.x has a copy of this plugin bundled with it (SplashScreenInternal.java). - // Enable functionality only if running on 4.x.x. - private static final boolean HAS_BUILT_IN_SPLASH_SCREEN = Integer.valueOf(CordovaWebView.CORDOVA_VERSION.split("\\.")[0]) < 4; - private static final int DEFAULT_SPLASHSCREEN_DURATION = 3000; - private static final int DEFAULT_FADE_DURATION = 500; - private static Dialog splashDialog; - private static ProgressDialog spinnerDialog; - private static boolean firstShow = true; - private static boolean lastHideAfterDelay; // https://issues.apache.org/jira/browse/CB-9094 - - /** - * Displays the splash drawable. - */ - private ImageView splashImageView; - - /** - * Remember last device orientation to detect orientation changes. - */ - private int orientation; - - // Helper to be compile-time compatible with both Cordova 3.x and 4.x. - private View getView() { - try { - return (View)webView.getClass().getMethod("getView").invoke(webView); - } catch (Exception e) { - return (View)webView; - } - } - - @Override - protected void pluginInitialize() { - if (HAS_BUILT_IN_SPLASH_SCREEN) { - return; - } - // Make WebView invisible while loading URL - // CB-11326 Ensure we're calling this on UI thread - cordova.getActivity().runOnUiThread(new Runnable() { - @Override - public void run() { - getView().setVisibility(View.INVISIBLE); - } - }); - int drawableId = preferences.getInteger("SplashDrawableId", 0); - if (drawableId == 0) { - String splashResource = preferences.getString("SplashScreen", "screen"); - if (splashResource != null) { - drawableId = cordova.getActivity().getResources().getIdentifier(splashResource, "drawable", cordova.getActivity().getClass().getPackage().getName()); - if (drawableId == 0) { - drawableId = cordova.getActivity().getResources().getIdentifier(splashResource, "drawable", cordova.getActivity().getPackageName()); - } - preferences.set("SplashDrawableId", drawableId); - } - } - - // Save initial orientation. - orientation = cordova.getActivity().getResources().getConfiguration().orientation; - - if (firstShow) { - boolean autoHide = preferences.getBoolean("AutoHideSplashScreen", true); - showSplashScreen(autoHide); - } - - if (preferences.getBoolean("SplashShowOnlyFirstTime", true)) { - firstShow = false; - } - } - - /** - * Shorter way to check value of "SplashMaintainAspectRatio" preference. - */ - private boolean isMaintainAspectRatio () { - return preferences.getBoolean("SplashMaintainAspectRatio", false); - } - - private int getFadeDuration () { - int fadeSplashScreenDuration = preferences.getBoolean("FadeSplashScreen", true) ? - preferences.getInteger("FadeSplashScreenDuration", DEFAULT_FADE_DURATION) : 0; - - if (fadeSplashScreenDuration < 30) { - // [CB-9750] This value used to be in decimal seconds, so we will assume that if someone specifies 10 - // they mean 10 seconds, and not the meaningless 10ms - fadeSplashScreenDuration *= 1000; - } - - return fadeSplashScreenDuration; - } - - @Override - public void onPause(boolean multitasking) { - if (HAS_BUILT_IN_SPLASH_SCREEN) { - return; - } - // hide the splash screen to avoid leaking a window - this.removeSplashScreen(true); - } - - @Override - public void onDestroy() { - if (HAS_BUILT_IN_SPLASH_SCREEN) { - return; - } - // hide the splash screen to avoid leaking a window - this.removeSplashScreen(true); - // If we set this to true onDestroy, we lose track when we go from page to page! - //firstShow = true; - } - - @Override - public boolean execute(String action, JSONArray args, CallbackContext callbackContext) throws JSONException { - if (action.equals("hide")) { - cordova.getActivity().runOnUiThread(new Runnable() { - public void run() { - webView.postMessage("splashscreen", "hide"); - } - }); - } else if (action.equals("show")) { - cordova.getActivity().runOnUiThread(new Runnable() { - public void run() { - webView.postMessage("splashscreen", "show"); - } - }); - } else { - return false; - } - - callbackContext.success(); - return true; - } - - @Override - public Object onMessage(String id, Object data) { - if (HAS_BUILT_IN_SPLASH_SCREEN) { - return null; - } - if ("splashscreen".equals(id)) { - if ("hide".equals(data.toString())) { - this.removeSplashScreen(false); - } else { - this.showSplashScreen(false); - } - } else if ("spinner".equals(id)) { - if ("stop".equals(data.toString())) { - getView().setVisibility(View.VISIBLE); - } - } else if ("onReceivedError".equals(id)) { - this.spinnerStop(); - } - return null; - } - - // Don't add @Override so that plugin still compiles on 3.x.x for a while - public void onConfigurationChanged(Configuration newConfig) { - if (newConfig.orientation != orientation) { - orientation = newConfig.orientation; - - // Splash drawable may change with orientation, so reload it. - if (splashImageView != null) { - int drawableId = preferences.getInteger("SplashDrawableId", 0); - if (drawableId != 0) { - splashImageView.setImageDrawable(cordova.getActivity().getResources().getDrawable(drawableId)); - } - } - } - } - - private void removeSplashScreen(final boolean forceHideImmediately) { - cordova.getActivity().runOnUiThread(new Runnable() { - public void run() { - if (splashDialog != null && splashDialog.isShowing()) { - final int fadeSplashScreenDuration = getFadeDuration(); - // CB-10692 If the plugin is being paused/destroyed, skip the fading and hide it immediately - if (fadeSplashScreenDuration > 0 && forceHideImmediately == false) { - AlphaAnimation fadeOut = new AlphaAnimation(1, 0); - fadeOut.setInterpolator(new DecelerateInterpolator()); - fadeOut.setDuration(fadeSplashScreenDuration); - - splashImageView.setAnimation(fadeOut); - splashImageView.startAnimation(fadeOut); - - fadeOut.setAnimationListener(new Animation.AnimationListener() { - @Override - public void onAnimationStart(Animation animation) { - spinnerStop(); - } - - @Override - public void onAnimationEnd(Animation animation) { - if (splashDialog != null && splashDialog.isShowing()) { - splashDialog.dismiss(); - splashDialog = null; - splashImageView = null; - } - } - - @Override - public void onAnimationRepeat(Animation animation) { - } - }); - } else { - spinnerStop(); - splashDialog.dismiss(); - splashDialog = null; - splashImageView = null; - } - } - } - }); - } - - /** - * Shows the splash screen over the full Activity - */ - @SuppressWarnings("deprecation") - private void showSplashScreen(final boolean hideAfterDelay) { - final int splashscreenTime = preferences.getInteger("SplashScreenDelay", DEFAULT_SPLASHSCREEN_DURATION); - final int drawableId = preferences.getInteger("SplashDrawableId", 0); - - final int fadeSplashScreenDuration = getFadeDuration(); - final int effectiveSplashDuration = Math.max(0, splashscreenTime - fadeSplashScreenDuration); - - lastHideAfterDelay = hideAfterDelay; - - // If the splash dialog is showing don't try to show it again - if (splashDialog != null && splashDialog.isShowing()) { - return; - } - if (drawableId == 0 || (splashscreenTime <= 0 && hideAfterDelay)) { - return; - } - - cordova.getActivity().runOnUiThread(new Runnable() { - public void run() { - // Get reference to display - Display display = cordova.getActivity().getWindowManager().getDefaultDisplay(); - Context context = webView.getContext(); - - // Use an ImageView to render the image because of its flexible scaling options. - splashImageView = new ImageView(context); - splashImageView.setImageResource(drawableId); - LayoutParams layoutParams = new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT); - splashImageView.setLayoutParams(layoutParams); - - splashImageView.setMinimumHeight(display.getHeight()); - splashImageView.setMinimumWidth(display.getWidth()); - - // TODO: Use the background color of the webView's parent instead of using the preference. - splashImageView.setBackgroundColor(preferences.getInteger("backgroundColor", Color.BLACK)); - - if (isMaintainAspectRatio()) { - // CENTER_CROP scale mode is equivalent to CSS "background-size:cover" - splashImageView.setScaleType(ImageView.ScaleType.CENTER_CROP); - } - else { - // FIT_XY scales image non-uniformly to fit into image view. - splashImageView.setScaleType(ImageView.ScaleType.FIT_XY); - } - - // Create and show the dialog - splashDialog = new Dialog(context, android.R.style.Theme_Translucent_NoTitleBar); - // check to see if the splash screen should be full screen - if ((cordova.getActivity().getWindow().getAttributes().flags & WindowManager.LayoutParams.FLAG_FULLSCREEN) - == WindowManager.LayoutParams.FLAG_FULLSCREEN) { - splashDialog.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, - WindowManager.LayoutParams.FLAG_FULLSCREEN); - } - splashDialog.setContentView(splashImageView); - splashDialog.setCancelable(false); - splashDialog.show(); - - if (preferences.getBoolean("ShowSplashScreenSpinner", true)) { - spinnerStart(); - } - - // Set Runnable to remove splash screen just in case - if (hideAfterDelay) { - final Handler handler = new Handler(); - handler.postDelayed(new Runnable() { - public void run() { - if (lastHideAfterDelay) { - removeSplashScreen(false); - } - } - }, effectiveSplashDuration); - } - } - }); - } - - // Show only spinner in the center of the screen - private void spinnerStart() { - cordova.getActivity().runOnUiThread(new Runnable() { - public void run() { - spinnerStop(); - - spinnerDialog = new ProgressDialog(webView.getContext()); - spinnerDialog.setOnCancelListener(new DialogInterface.OnCancelListener() { - public void onCancel(DialogInterface dialog) { - spinnerDialog = null; - } - }); - - spinnerDialog.setCancelable(false); - spinnerDialog.setIndeterminate(true); - - RelativeLayout centeredLayout = new RelativeLayout(cordova.getActivity()); - centeredLayout.setGravity(Gravity.CENTER); - centeredLayout.setLayoutParams(new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT)); - - ProgressBar progressBar = new ProgressBar(webView.getContext()); - RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); - layoutParams.addRule(RelativeLayout.CENTER_IN_PARENT, RelativeLayout.TRUE); - progressBar.setLayoutParams(layoutParams); - - centeredLayout.addView(progressBar); - - spinnerDialog.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND); - spinnerDialog.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT)); - - spinnerDialog.show(); - spinnerDialog.setContentView(centeredLayout); - } - }); - } - - private void spinnerStop() { - cordova.getActivity().runOnUiThread(new Runnable() { - public void run() { - if (spinnerDialog != null && spinnerDialog.isShowing()) { - spinnerDialog.dismiss(); - spinnerDialog = null; - } - } - }); - } -} diff --git a/StoneIsland/platforms/android/src/org/apache/cordova/statusbar/StatusBar.java b/StoneIsland/platforms/android/src/org/apache/cordova/statusbar/StatusBar.java deleted file mode 100644 index 7b4d946a..00000000 --- a/StoneIsland/platforms/android/src/org/apache/cordova/statusbar/StatusBar.java +++ /dev/null @@ -1,201 +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 org.apache.cordova.statusbar; - -import android.app.Activity; -import android.graphics.Color; -import android.os.Build; -import android.view.View; -import android.view.Window; -import android.view.WindowManager; - -import org.apache.cordova.CallbackContext; -import org.apache.cordova.CordovaArgs; -import org.apache.cordova.CordovaInterface; -import org.apache.cordova.CordovaPlugin; -import org.apache.cordova.CordovaWebView; -import org.apache.cordova.LOG; -import org.apache.cordova.PluginResult; -import org.json.JSONException; - -public class StatusBar extends CordovaPlugin { - private static final String TAG = "StatusBar"; - - /** - * Sets the context of the Command. This can then be used to do things like - * get file paths associated with the Activity. - * - * @param cordova The context of the main Activity. - * @param webView The CordovaWebView Cordova is running in. - */ - @Override - public void initialize(final CordovaInterface cordova, CordovaWebView webView) { - LOG.v(TAG, "StatusBar: initialization"); - super.initialize(cordova, webView); - - this.cordova.getActivity().runOnUiThread(new Runnable() { - @Override - public void run() { - // Clear flag FLAG_FORCE_NOT_FULLSCREEN which is set initially - // by the Cordova. - Window window = cordova.getActivity().getWindow(); - window.clearFlags(WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN); - - // Read 'StatusBarBackgroundColor' from config.xml, default is #000000. - setStatusBarBackgroundColor(preferences.getString("StatusBarBackgroundColor", "#000000")); - } - }); - } - - /** - * Executes the request and returns PluginResult. - * - * @param action The action to execute. - * @param args JSONArry of arguments for the plugin. - * @param callbackContext The callback id used when calling back into JavaScript. - * @return True if the action was valid, false otherwise. - */ - @Override - public boolean execute(final String action, final CordovaArgs args, final CallbackContext callbackContext) throws JSONException { - LOG.v(TAG, "Executing action: " + action); - final Activity activity = this.cordova.getActivity(); - final Window window = activity.getWindow(); - - if ("_ready".equals(action)) { - boolean statusBarVisible = (window.getAttributes().flags & WindowManager.LayoutParams.FLAG_FULLSCREEN) == 0; - callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK, statusBarVisible)); - return true; - } - - if ("show".equals(action)) { - this.cordova.getActivity().runOnUiThread(new Runnable() { - @Override - public void run() { - // SYSTEM_UI_FLAG_FULLSCREEN is available since JellyBean, but we - // use KitKat here to be aligned with "Fullscreen" preference - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { - int uiOptions = window.getDecorView().getSystemUiVisibility(); - uiOptions &= ~View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN; - uiOptions &= ~View.SYSTEM_UI_FLAG_FULLSCREEN; - - window.getDecorView().setSystemUiVisibility(uiOptions); - } - - // CB-11197 We still need to update LayoutParams to force status bar - // to be hidden when entering e.g. text fields - window.clearFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN); - } - }); - return true; - } - - if ("hide".equals(action)) { - this.cordova.getActivity().runOnUiThread(new Runnable() { - @Override - public void run() { - // SYSTEM_UI_FLAG_FULLSCREEN is available since JellyBean, but we - // use KitKat here to be aligned with "Fullscreen" preference - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { - int uiOptions = window.getDecorView().getSystemUiVisibility() - | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN - | View.SYSTEM_UI_FLAG_FULLSCREEN; - - window.getDecorView().setSystemUiVisibility(uiOptions); - } - - // CB-11197 We still need to update LayoutParams to force status bar - // to be hidden when entering e.g. text fields - window.addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN); - } - }); - return true; - } - - if ("backgroundColorByHexString".equals(action)) { - this.cordova.getActivity().runOnUiThread(new Runnable() { - @Override - public void run() { - try { - setStatusBarBackgroundColor(args.getString(0)); - } catch (JSONException ignore) { - LOG.e(TAG, "Invalid hexString argument, use f.i. '#777777'"); - } - } - }); - return true; - } - - if ("overlaysWebView".equals(action)) { - if (Build.VERSION.SDK_INT >= 21) { - this.cordova.getActivity().runOnUiThread(new Runnable() { - @Override - public void run() { - try { - setStatusBarTransparent(args.getBoolean(0)); - } catch (JSONException ignore) { - LOG.e(TAG, "Invalid boolean argument"); - } - } - }); - return true; - } - else return args.getBoolean(0) == false; - } - - return false; - } - - private void setStatusBarBackgroundColor(final String colorPref) { - if (Build.VERSION.SDK_INT >= 21) { - if (colorPref != null && !colorPref.isEmpty()) { - final Window window = cordova.getActivity().getWindow(); - // Method and constants not available on all SDKs but we want to be able to compile this code with any SDK - window.clearFlags(0x04000000); // SDK 19: WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS); - window.addFlags(0x80000000); // SDK 21: WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS); - try { - // Using reflection makes sure any 5.0+ device will work without having to compile with SDK level 21 - window.getClass().getMethod("setStatusBarColor", int.class).invoke(window, Color.parseColor(colorPref)); - } catch (IllegalArgumentException ignore) { - LOG.e(TAG, "Invalid hexString argument, use f.i. '#999999'"); - } catch (Exception ignore) { - // this should not happen, only in case Android removes this method in a version > 21 - LOG.w(TAG, "Method window.setStatusBarColor not found for SDK level " + Build.VERSION.SDK_INT); - } - } - } - } - - private void setStatusBarTransparent(final boolean transparent) { - if (Build.VERSION.SDK_INT >= 21) { - final Window window = cordova.getActivity().getWindow(); - if (transparent) { - window.getDecorView().setSystemUiVisibility( - View.SYSTEM_UI_FLAG_LAYOUT_STABLE - | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN); - window.setStatusBarColor(Color.TRANSPARENT); - } - else { - window.getDecorView().setSystemUiVisibility( - View.SYSTEM_UI_FLAG_LAYOUT_STABLE - | View.SYSTEM_UI_FLAG_VISIBLE); - } - } - } -} diff --git a/StoneIsland/platforms/android/src/org/apache/cordova/whitelist/WhitelistPlugin.java b/StoneIsland/platforms/android/src/org/apache/cordova/whitelist/WhitelistPlugin.java deleted file mode 100644 index 36567886..00000000 --- a/StoneIsland/platforms/android/src/org/apache/cordova/whitelist/WhitelistPlugin.java +++ /dev/null @@ -1,161 +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 org.apache.cordova.whitelist; - -import org.apache.cordova.CordovaPlugin; -import org.apache.cordova.ConfigXmlParser; -import org.apache.cordova.LOG; -import org.apache.cordova.Whitelist; -import org.xmlpull.v1.XmlPullParser; - -import android.content.Context; - -public class WhitelistPlugin extends CordovaPlugin { - private static final String LOG_TAG = "WhitelistPlugin"; - private Whitelist allowedNavigations; - private Whitelist allowedIntents; - private Whitelist allowedRequests; - - // Used when instantiated via reflection by PluginManager - public WhitelistPlugin() { - } - // These can be used by embedders to allow Java-configuration of whitelists. - public WhitelistPlugin(Context context) { - this(new Whitelist(), new Whitelist(), null); - new CustomConfigXmlParser().parse(context); - } - public WhitelistPlugin(XmlPullParser xmlParser) { - this(new Whitelist(), new Whitelist(), null); - new CustomConfigXmlParser().parse(xmlParser); - } - public WhitelistPlugin(Whitelist allowedNavigations, Whitelist allowedIntents, Whitelist allowedRequests) { - if (allowedRequests == null) { - allowedRequests = new Whitelist(); - allowedRequests.addWhiteListEntry("file:///*", false); - allowedRequests.addWhiteListEntry("data:*", false); - } - this.allowedNavigations = allowedNavigations; - this.allowedIntents = allowedIntents; - this.allowedRequests = allowedRequests; - } - @Override - public void pluginInitialize() { - if (allowedNavigations == null) { - allowedNavigations = new Whitelist(); - allowedIntents = new Whitelist(); - allowedRequests = new Whitelist(); - new CustomConfigXmlParser().parse(webView.getContext()); - } - } - - private class CustomConfigXmlParser extends ConfigXmlParser { - @Override - public void handleStartTag(XmlPullParser xml) { - String strNode = xml.getName(); - if (strNode.equals("content")) { - String startPage = xml.getAttributeValue(null, "src"); - allowedNavigations.addWhiteListEntry(startPage, false); - } else if (strNode.equals("allow-navigation")) { - String origin = xml.getAttributeValue(null, "href"); - if ("*".equals(origin)) { - allowedNavigations.addWhiteListEntry("http://*/*", false); - allowedNavigations.addWhiteListEntry("https://*/*", false); - allowedNavigations.addWhiteListEntry("data:*", false); - } else { - allowedNavigations.addWhiteListEntry(origin, false); - } - } else if (strNode.equals("allow-intent")) { - String origin = xml.getAttributeValue(null, "href"); - allowedIntents.addWhiteListEntry(origin, false); - } else if (strNode.equals("access")) { - String origin = xml.getAttributeValue(null, "origin"); - String subdomains = xml.getAttributeValue(null, "subdomains"); - boolean external = (xml.getAttributeValue(null, "launch-external") != null); - if (origin != null) { - if (external) { - LOG.w(LOG_TAG, "Found <access launch-external> within config.xml. Please use <allow-intent> instead."); - allowedIntents.addWhiteListEntry(origin, (subdomains != null) && (subdomains.compareToIgnoreCase("true") == 0)); - } else { - if ("*".equals(origin)) { - allowedRequests.addWhiteListEntry("http://*/*", false); - allowedRequests.addWhiteListEntry("https://*/*", false); - } else { - allowedRequests.addWhiteListEntry(origin, (subdomains != null) && (subdomains.compareToIgnoreCase("true") == 0)); - } - } - } - } - } - @Override - public void handleEndTag(XmlPullParser xml) { - } - } - - @Override - public Boolean shouldAllowNavigation(String url) { - if (allowedNavigations.isUrlWhiteListed(url)) { - return true; - } - return null; // Default policy - } - - @Override - public Boolean shouldAllowRequest(String url) { - if (Boolean.TRUE == shouldAllowNavigation(url)) { - return true; - } - if (allowedRequests.isUrlWhiteListed(url)) { - return true; - } - return null; // Default policy - } - - @Override - public Boolean shouldOpenExternalUrl(String url) { - if (allowedIntents.isUrlWhiteListed(url)) { - return true; - } - return null; // Default policy - } - - public Whitelist getAllowedNavigations() { - return allowedNavigations; - } - - public void setAllowedNavigations(Whitelist allowedNavigations) { - this.allowedNavigations = allowedNavigations; - } - - public Whitelist getAllowedIntents() { - return allowedIntents; - } - - public void setAllowedIntents(Whitelist allowedIntents) { - this.allowedIntents = allowedIntents; - } - - public Whitelist getAllowedRequests() { - return allowedRequests; - } - - public void setAllowedRequests(Whitelist allowedRequests) { - this.allowedRequests = allowedRequests; - } -} diff --git a/StoneIsland/platforms/android/src/us/okfoc/stoneisland/MainActivity.java b/StoneIsland/platforms/android/src/us/okfoc/stoneisland/MainActivity.java deleted file mode 100755 index f7a7bc56..00000000 --- a/StoneIsland/platforms/android/src/us/okfoc/stoneisland/MainActivity.java +++ /dev/null @@ -1,34 +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 us.okfoc.stoneisland; - -import android.os.Bundle; -import org.apache.cordova.*; - -public class MainActivity extends CordovaActivity -{ - @Override - public void onCreate(Bundle savedInstanceState) - { - super.onCreate(savedInstanceState); - // Set by <content src="index.html" /> in config.xml - loadUrl(launchUrl); - } -} |
