List of usage examples for org.json JSONArray getString
public String getString(int index) throws JSONException
From source file:io.winch.phonegap.plugin.WinchPlugin.java
private void get(CallbackContext callbackContext, JSONArray args) { try {/*from w w w. j a va 2s.c o m*/ String namespace = args.getString(0); String key = args.getString(1); byte[] value = mWinch.getNamespace(namespace).get(key); PluginResult pr = new PluginResult(PluginResult.Status.OK, value, true); callbackContext.sendPluginResult(pr); } catch (WinchError e) { e.printStackTrace(); PluginResult r = buildErrorResult(e.getErrorCode(), e.getMessage()); callbackContext.sendPluginResult(r); } catch (JSONException e1) { e1.printStackTrace(); } }
From source file:io.winch.phonegap.plugin.WinchPlugin.java
private void getString(CallbackContext callbackContext, JSONArray args) { try {/*from w w w . j a va 2 s . com*/ String namespace = args.getString(0); String key = args.getString(1); String value = mWinch.getNamespace(namespace).getString(key); PluginResult pr = new PluginResult(PluginResult.Status.OK, value); callbackContext.sendPluginResult(pr); } catch (WinchError e) { e.printStackTrace(); PluginResult r = buildErrorResult(e.getErrorCode(), e.getMessage()); callbackContext.sendPluginResult(r); } catch (JSONException e1) { e1.printStackTrace(); } }
From source file:io.winch.phonegap.plugin.WinchPlugin.java
private void getBase64(CallbackContext callbackContext, JSONArray args) { try {//from w w w . j a va2 s.co m String namespace = args.getString(0); String key = args.getString(1); byte[] value = mWinch.getNamespace(namespace).get(key); String base64 = Base64.encodeToString(value, Base64.NO_WRAP); PluginResult pr = new PluginResult(PluginResult.Status.OK, base64); callbackContext.sendPluginResult(pr); } catch (WinchError e) { e.printStackTrace(); PluginResult r = buildErrorResult(e.getErrorCode(), e.getMessage()); callbackContext.sendPluginResult(r); } catch (JSONException e1) { e1.printStackTrace(); } }
From source file:io.winch.phonegap.plugin.WinchPlugin.java
private void putString(CallbackContext callbackContext, JSONArray args) { try {/*from w w w .j a v a 2s.c om*/ String namespace = args.getString(0); String key = args.getString(1); String data = args.getString(2); mWinch.getNamespace(namespace).putString(key, data); callbackContext.success(); } catch (WinchError e) { e.printStackTrace(); PluginResult r = buildErrorResult(e.getErrorCode(), e.getMessage()); callbackContext.sendPluginResult(r); } catch (JSONException e) { e.printStackTrace(); } }
From source file:io.winch.phonegap.plugin.WinchPlugin.java
private void putBase64(CallbackContext callbackContext, JSONArray args) { try {//w w w . j a va 2s . c om String namespace = args.getString(0); String key = args.getString(1); String base64 = args.getString(2); byte[] data = Base64.decode(base64, Base64.NO_WRAP); mWinch.getNamespace(namespace).put(key, data); callbackContext.success(); } catch (WinchError e) { e.printStackTrace(); PluginResult r = buildErrorResult(e.getErrorCode(), e.getMessage()); callbackContext.sendPluginResult(r); } catch (JSONException e) { e.printStackTrace(); } }
From source file:io.winch.phonegap.plugin.WinchPlugin.java
private void iterateAsString(final CallbackContext callbackContext, JSONArray args) { try {/*from w w w. j a va 2 s . c o m*/ String namespace = args.getString(0); Enumerator it1 = new Enumerator() { public int next() { JSONObject obj = new JSONObject(); try { obj.put(KEY, key); obj.put(DATA, new String(data)); } catch (JSONException e) { e.printStackTrace(); } PluginResult r = new PluginResult(PluginResult.Status.OK, obj); r.setKeepCallback(true); callbackContext.sendPluginResult(r); return Enumerator.Code.NONE; } }; mWinch.getNamespace(namespace).enumerate(it1); } catch (JSONException e1) { e1.printStackTrace(); } catch (WinchError e) { e.log(); PluginResult r = buildErrorResult(e.getErrorCode(), e.getMessage()); callbackContext.sendPluginResult(r); } PluginResult r = new PluginResult(PluginResult.Status.OK, false); r.setKeepCallback(false); callbackContext.sendPluginResult(r); }
From source file:io.winch.phonegap.plugin.WinchPlugin.java
private void iterateAsBase64(final CallbackContext callbackContext, JSONArray args) { try {//from w w w. j a v a 2 s. c om String namespace = args.getString(0); Enumerator it1 = new Enumerator() { public int next() { JSONObject obj = new JSONObject(); try { obj.put(KEY, key); String base64 = Base64.encodeToString(data, Base64.NO_WRAP); obj.put(DATA, base64); } catch (JSONException e) { e.printStackTrace(); } PluginResult r = new PluginResult(PluginResult.Status.OK, obj); r.setKeepCallback(true); callbackContext.sendPluginResult(r); return Enumerator.Code.NONE; } }; mWinch.getNamespace(namespace).enumerate(it1); } catch (JSONException e1) { e1.printStackTrace(); } catch (WinchError e) { e.log(); PluginResult r = buildErrorResult(e.getErrorCode(), e.getMessage()); callbackContext.sendPluginResult(r); } PluginResult r = new PluginResult(PluginResult.Status.OK, false); r.setKeepCallback(false); callbackContext.sendPluginResult(r); }
From source file:io.winch.phonegap.plugin.WinchPlugin.java
private void remove(CallbackContext callbackContext, JSONArray args) { try {//from ww w .j a va2 s . co m String namespace = args.getString(0); String key = args.getString(1); mWinch.getNamespace(namespace).remove(key); callbackContext.success(); } catch (WinchError e) { e.printStackTrace(); PluginResult r = this.buildErrorResult(e.getErrorCode(), e.getMessage()); callbackContext.sendPluginResult(r); } catch (JSONException e) { e.printStackTrace(); } }
From source file:io.winch.phonegap.plugin.WinchPlugin.java
private void drop(CallbackContext callbackContext, JSONArray args) { try {// w ww. ja v a 2 s . co m mWinch.drop(args.getString(0)); callbackContext.success(); } catch (JSONException e) { e.printStackTrace(); } catch (WinchError e) { e.printStackTrace(); callbackContext.error(e.getErrorCode()); } }
From source file:com.ct.speech.TTS.java
@Override public PluginResult execute(String action, JSONArray args, String callbackId) { PluginResult.Status status = PluginResult.Status.OK; String result = ""; try {/*from www. j a v a 2 s . c om*/ if (action.equals("speak")) { String text = args.getString(0); if (isReady()) { mTts.speak(text, TextToSpeech.QUEUE_ADD, null); return new PluginResult(status, result); } else { JSONObject error = new JSONObject(); error.put("message", "TTS service is still initialzing."); error.put("code", TTS.INITIALIZING); return new PluginResult(PluginResult.Status.ERROR, error); } } else if (action.equals("silence")) { if (isReady()) { mTts.playSilence(args.getLong(0), TextToSpeech.QUEUE_ADD, null); return new PluginResult(status, result); } else { JSONObject error = new JSONObject(); error.put("message", "TTS service is still initialzing."); error.put("code", TTS.INITIALIZING); return new PluginResult(PluginResult.Status.ERROR, error); } } else if (action.equals("startup")) { if (mTts == null) { this.startupCallbackId = callbackId; state = TTS.INITIALIZING; mTts = new TextToSpeech((Context) ctx, this); //mTts.setLanguage(Locale.US); } PluginResult pluginResult = new PluginResult(status, TTS.INITIALIZING); pluginResult.setKeepCallback(true); return pluginResult; } else if (action.equals("shutdown")) { if (mTts != null) { mTts.shutdown(); } return new PluginResult(status, result); } else if (action.equals("stop")) { if (mTts != null) { mTts.stop(); } return new PluginResult(status, result); } else if (action.equals("getLanguage")) { if (mTts != null) { result = mTts.getLanguage().toString(); return new PluginResult(status, result); } } else if (action.equals("isLanguageAvailable")) { if (mTts != null) { Locale loc = new Locale(args.getString(0)); int available = mTts.isLanguageAvailable(loc); result = (available < 0) ? "false" : "true"; return new PluginResult(status, result); } } else if (action.equals("setLanguage")) { if (mTts != null) { Locale loc = new Locale(args.getString(0)); int available = mTts.setLanguage(loc); result = (available < 0) ? "false" : "true"; return new PluginResult(status, result); } } return new PluginResult(status, result); } catch (JSONException e) { e.printStackTrace(); return new PluginResult(PluginResult.Status.JSON_EXCEPTION); } }