List of usage examples for org.json JSONArray optString
public String optString(int index)
From source file:com.commontime.plugin.LocationManager.java
/** * Executes the request and returns PluginResult. * * @param action The action to execute. * @param args JSONArray 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. *///from w w w .j a va2 s. c o m public boolean execute(String action, JSONArray args, CallbackContext callbackContext) { if (action.equals("onDomDelegateReady")) { onDomDelegateReady(callbackContext); } else if (action.equals("disableDebugNotifications")) { disableDebugNotifications(callbackContext); } else if (action.equals("enableDebugNotifications")) { enableDebugNotifications(callbackContext); } else if (action.equals("disableDebugLogs")) { disableDebugLogs(callbackContext); } else if (action.equals("enableDebugLogs")) { enableDebugLogs(callbackContext); } else if (action.equals("appendToDeviceLog")) { appendToDeviceLog(args.optString(0), callbackContext); } else if (action.equals("startMonitoringForRegion")) { startMonitoringForRegion(args.optJSONObject(0), callbackContext); } else if (action.equals("stopMonitoringForRegion")) { stopMonitoringForRegion(args.optJSONObject(0), callbackContext); } else if (action.equals("startRangingBeaconsInRegion")) { startRangingBeaconsInRegion(args.optJSONObject(0), callbackContext); } else if (action.equals("stopRangingBeaconsInRegion")) { stopRangingBeaconsInRegion(args.optJSONObject(0), callbackContext); } else if (action.equals("isRangingAvailable")) { isRangingAvailable(callbackContext); } else if (action.equals("getAuthorizationStatus")) { getAuthorizationStatus(callbackContext); } else if (action.equals("requestWhenInUseAuthorization")) { requestWhenInUseAuthorization(callbackContext); } else if (action.equals("requestAlwaysAuthorization")) { requestAlwaysAuthorization(callbackContext); } else if (action.equals("getMonitoredRegions")) { getMonitoredRegions(callbackContext); } else if (action.equals("getRangedRegions")) { getRangedRegions(callbackContext); } else if (action.equals("requestStateForRegion")) { requestStateForRegion(args.optJSONObject(0), callbackContext); } else if (action.equals("registerDelegateCallbackId")) { registerDelegateCallbackId(args.optJSONObject(0), callbackContext); } else if (action.equals("isMonitoringAvailableForClass")) { isMonitoringAvailableForClass(args.optJSONObject(0), callbackContext); } else if (action.equals("isAdvertisingAvailable")) { isAdvertisingAvailable(callbackContext); } else if (action.equals("isAdvertising")) { isAdvertising(callbackContext); } else if (action.equals("startAdvertising")) { startAdvertising(args.optJSONObject(0), callbackContext); } else if (action.equals("stopAdvertising")) { stopAdvertising(callbackContext); } else if (action.equals("isBluetoothEnabled")) { isBluetoothEnabled(callbackContext); } else if (action.equals("enableBluetooth")) { enableBluetooth(callbackContext); } else if (action.equals("disableBluetooth")) { disableBluetooth(callbackContext); } else { return false; } return true; }
From source file:com.samsung.richnotification.RichNotificationOptions.java
RichNotificationOptions(JSONArray data) throws JSONException { // Fetch options from the data object this.uuid = data.optString(0); this.readoutTitle = data.optString(1); this.readout = data.optString(2); this.notificationTitle = data.optString(3); this.headerSizeType = data.optString(4); this.primarySubHeader = data.optString(5); this.primaryBody = data.optString(6); this.qrImage = data.optString(7); this.primaryBackgroundColor = data.optString(8); this.primaryBackgroundImage = data.optString(9); this.secondaryType = data.optString(10); this.secondarySubHeader = data.optString(11); this.secondaryContent = data.optJSONArray(12); this.secondaryBackgroundColor = data.optString(13); this.secondaryImage = data.optString(14); this.secondaryIcon1Path = data.optString(15); this.secondaryIcon1Text = data.optString(16); this.secondaryIcon2Path = data.optString(17); this.secondaryIcon2Text = data.optString(18); this.notificationIcon = data.optString(19); int alert = data.optInt(20); int popup = data.optInt(21); this.actions = data.optJSONArray(22); switch (alert) { case RichNotificationHelper.ALERT_TYPE_SILENCE: this.alertType = AlertType.SILENCE; break;//from w ww . j a v a2s. c om case RichNotificationHelper.ALERT_TYPE_SOUND: this.alertType = AlertType.SOUND; break; case RichNotificationHelper.ALERT_TYPE_SOUND_AND_VIBR: this.alertType = AlertType.SOUND_AND_VIBRATION; break; case RichNotificationHelper.ALERT_TYPE_VIBR: this.alertType = AlertType.VIBRATION; break; default: this.alertType = AlertType.SOUND_AND_VIBRATION; } if (popup == RichNotificationHelper.POPUP_TYPE_NONE) this.popupType = PopupType.NONE; else this.popupType = PopupType.NORMAL; }
From source file:re.notifica.cordova.NotificarePlugin.java
/** * Create a new user account/* w w w. j a va2 s . co m*/ * @param args * @param callbackContext */ protected void createAccount(JSONArray args, final CallbackContext callbackContext) { Log.d(TAG, "CREATEACCOUNT"); try { String email = args.getString(0); String password = args.getString(1); String userName = null; if (args.length() == 3) { userName = args.optString(2); } Notificare.shared().createAccount(email, password, userName, new NotificareCallback<Boolean>() { @Override public void onSuccess(Boolean result) { if (callbackContext == null) { return; } callbackContext.success(); } @Override public void onError(NotificareError error) { if (callbackContext == null) { return; } callbackContext.error(error.getLocalizedMessage()); } }); } catch (JSONException e) { callbackContext.error("JSON parse error"); } }
From source file:com.openquartz.glassmemo.Utils.java
/** * Gets the arraylist from shared preferences * @param context// ww w .ja v a2s. c o m * @param key * @return */ public static ArrayList<String> getStringArrayPref(final Context context, String key) { SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(context); String json = sharedPref.getString(key, null); ArrayList<String> memoList = new ArrayList<String>(); if (json != null) { try { JSONArray a = new JSONArray(json); for (int i = 0; i < a.length(); i++) { memoList.add(a.optString(i)); } } catch (JSONException e) { } } return memoList; }
From source file:org.privatenotes.Note.java
public Note(JSONObject json) { // These methods return an empty string if the key is not found setTitle(XmlUtils.unescape(json.optString("title"))); setGuid(json.optString("guid")); setLastChangeDate(json.optString("last-change-date")); lastSyncRevision = json.optInt("last-sync-revision", -1); setXmlContent(json.optString("note-content")); JSONArray jtags = json.optJSONArray("tags"); String tag;/*from w w w . j a v a 2 s .com*/ tags = new String(); if (jtags != null) { for (int i = 0; i < jtags.length(); i++) { tag = jtags.optString(i); tags += tag + ","; } } // encryption/decryption if (json.optString("encrypted") != null) { //<encrypted> setEncrypted(json.optString("encrypted").toLowerCase().trim().equals("true")); } //<encryptedAlgorithm> setEncryptedAlgorithm(json.optString("encryptedAlgorithm")); }
From source file:com.percolatestudio.cordova.fileupload.PSFileUpload.java
/** * Convenience method to read a parameter from the list of JSON args. * @param args the args passed to the Plugin * @param position the position to retrieve the arg from * @param defaultString the default to be used if the arg does not exist * @return String with the retrieved value */// w w w. j a va 2s . com private static String getArgument(JSONArray args, int position, String defaultString) { String arg = defaultString; if (args.length() > position) { arg = args.optString(position); if (arg == null || "null".equals(arg)) { arg = defaultString; } } return arg; }
From source file:com.ca.mas.cordova.storage.MASStoragePlugin.java
private void saveToLocal(final JSONArray args, final CallbackContext callbackContext) { try {/* www. j a v a2 s. c om*/ MASStorage storage = new MASSecureLocalStorage(); String key = args.optString(1); Object data = args.opt(2); int segment_0 = args.getInt(3); int segment = fetchSegmentLocal(segment_0); storage.save(key, data, segment, new MASCallback<Void>() { @Override public void onSuccess(Void result) { success(callbackContext, true, false); } @Override public void onError(Throwable e) { callbackContext.error(getError(e)); } }); } catch (Exception e) { Log.e(TAG, e.getMessage(), e); callbackContext.error(getError(e)); } }
From source file:com.ca.mas.cordova.storage.MASStoragePlugin.java
private void findByUsingKeyAndModeLocal(final JSONArray args, final CallbackContext callbackContext) { try {//from www. j a va 2 s. co m MASStorage storage = new MASSecureLocalStorage(); String key = args.optString(0); int segment_0 = args.getInt(1); int segment = fetchSegmentLocal(segment_0); storage.findByKey(key, segment, new MASCallback() { @Override public void onSuccess(Object result) { JSONObject response = null; try { response = getResultJson(result); success(callbackContext, response, false); } catch (Exception ex) { Log.e(TAG, ex.getMessage()); callbackContext.error(getError(ex)); } } @Override public void onError(Throwable e) { callbackContext.error(getError(e)); } }); } catch (Exception e) { Log.e(TAG, e.getMessage(), e); callbackContext.error(getError(e)); } }
From source file:com.ca.mas.cordova.storage.MASStoragePlugin.java
private void deleteByUsingKeyAndModeLocal(final JSONArray args, final CallbackContext callbackContext) { try {//from ww w. jav a 2 s . c om MASStorage storage = new MASSecureLocalStorage(); String key = args.optString(0); int segment_0 = args.getInt(1); int segment = fetchSegmentLocal(segment_0); storage.delete(key, segment, new MASCallback<Void>() { @Override public void onSuccess(Void result) { success(callbackContext, true, false); } @Override public void onError(Throwable e) { LOG.e(TAG, e.getMessage()); callbackContext.error(getError(e)); } }); } catch (Exception e) { Log.e(TAG, e.getMessage(), e); callbackContext.error(getError(e)); } }
From source file:com.ca.mas.cordova.storage.MASStoragePlugin.java
private void saveToCloud(final JSONArray args, final CallbackContext callbackContext) { try {//from w w w . j av a2 s . co m MASStorage storage = new MASSecureStorage(); String key = args.optString(1); Object data = args.opt(2); int segment_0 = args.getInt(3); int segment = fetchSegmentCloud(segment_0); storage.save(key, data, segment, new MASCallback<Void>() { @Override public void onSuccess(Void result) { success(callbackContext, true, false); } @Override public void onError(Throwable e) { Log.e(TAG, e.getMessage()); callbackContext.error(getError(e)); } }); } catch (Exception e) { Log.e(TAG, e.getMessage(), e); callbackContext.error(getError(e)); } }