List of usage examples for org.json JSONArray getString
public String getString(int index) throws JSONException
From source file:com.phonegap.App.java
/** * Executes the request and returns PluginResult. * * @param action The action to execute. * @param args JSONArry of arguments for the plugin. * @param callbackId The callback id used when calling back into JavaScript. * @return A PluginResult object with a status and message. *//*from w ww .ja va 2 s . c om*/ public PluginResult execute(String action, JSONArray args, String callbackId) { PluginResult.Status status = PluginResult.Status.OK; String result = ""; try { if (action.equals("clearCache")) { this.clearCache(); } else if (action.equals("loadUrl")) { this.loadUrl(args.getString(0), args.optJSONObject(1)); } else if (action.equals("cancelLoadUrl")) { this.cancelLoadUrl(); } else if (action.equals("clearHistory")) { this.clearHistory(); } else if (action.equals("addService")) { this.addService(args.getString(0), args.getString(1)); } return new PluginResult(status, result); } catch (JSONException e) { return new PluginResult(PluginResult.Status.JSON_EXCEPTION); } }
From source file:com.phonegap.App.java
/** * Load the url into the webview./*from w ww. ja va 2 s. c om*/ * * @param url * @param props Properties that can be passed in to the DroidGap activity (i.e. loadingDialog, wait, ...) * @throws JSONException */ public void loadUrl(String url, JSONObject props) throws JSONException { System.out.println("App.loadUrl(" + url + "," + props + ")"); int wait = 0; // If there are properties, then set them on the Activity if (props != null) { JSONArray keys = props.names(); for (int i = 0; i < keys.length(); i++) { String key = keys.getString(i); if (key.equals("wait")) { wait = props.getInt(key); } else { Object value = props.get(key); if (value == null) { } else if (value.getClass().equals(String.class)) { this.ctx.getIntent().putExtra(key, (String) value); } else if (value.getClass().equals(Boolean.class)) { this.ctx.getIntent().putExtra(key, (Boolean) value); } else if (value.getClass().equals(Integer.class)) { this.ctx.getIntent().putExtra(key, (Integer) value); } } } } // If wait property, then delay loading if (wait > 0) { ((DroidGap) this.ctx).loadUrl(url, wait); } else { ((DroidGap) this.ctx).loadUrl(url); } }
From source file:com.phonegap.plugins.ExternalAppLauncher.ExternalAppLauncher.java
@Override public boolean execute(String action, JSONArray data, CallbackContext callbackContext) { Context context = cordova.getActivity().getApplicationContext(); PackageManager pm = cordova.getActivity().getPackageManager(); String packageName;//from w w w . java 2s.c o m Boolean result = true; try { packageName = data.getString(0); } catch (JSONException e) { return false; } if (LAUNCH_APP.equals(action)) { result = launchApp(context, pm, packageName); } else if (LAUNCH_MARKET.equals(action)) { result = launchMarket(context, packageName); } if (result == true) { callbackContext.success(0); return true; } else { callbackContext.error(0); return false; } }
From source file:org.indigo.cdmi.backend.radosgw.JsonResponseTranlator.java
/** * Maps names of profiles from prifilesNames JSON array to comma separated sequence of * associated URIs.//from w w w . ja va2 s . com * @param profilesNames JSON array of profiles' names */ private String profilesToUris(JSONArray profilesNames, String cdmiObjectType) { StringBuffer rv = new StringBuffer(); log.debug("In profilesToURIs(): {}", profilesNames); for (int index = 0; index < profilesNames.length(); index++) { String profileName = profilesNames.getString(index); log.debug("Processed profile name: {}", profileName); String capabilityUri = profileToUri(profileName, cdmiObjectType); if (index > 0) { rv.append(", "); } rv.append(capabilityUri); } // for() return rv.toString(); }
From source file:com.intel.xdk.device.Device.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 context used when calling back into JavaScript. * @return True when the action was valid, false otherwise. *//*w ww.j a va2 s. c o m*/ public boolean execute(String action, JSONArray args, CallbackContext callbackContext) throws JSONException { if (action.equals("openWebPage")) { this.openWebPage(args.getString(0)); } else if (action.equals("getRemoteData")) { //String success = args.getString(3); //String error = args.getString(4); if (args.length() <= 3) { getRemoteData(args.getString(0), args.getString(1), args.getString(2), callbackContext); } else { getRemoteData(args.getString(0), args.getString(1), args.getString(2), args.getString(3), args.getString(4)); } } else if (action.equals("getRemoteDataExt")) { final JSONObject json = args.getJSONObject(0); cordova.getThreadPool().execute(new Runnable() { @Override public void run() { Device.this.getRemoteDataExt(json); } }); } else if (action.equals("getRemoteDataWithID")) { String success = args.getString(4); String error = args.getString(5); if (success == "null" && error == "null") { this.getRemoteDataWithID(args.getString(0), args.getString(1), args.getString(2), args.getInt(3), callbackContext); } else { this.getRemoteDataWithID(args.getString(0), args.getString(1), args.getString(2), args.getInt(3), args.getString(4), args.getString(5)); } } else if (action.equals("hideStatusBar")) { this.hideStatusBar(); } else if (action.equals("launchExternal")) { this.launchExternal(args.getString(0)); } else if (action.equals("managePower")) { this.managePower(args.getBoolean(0), args.getBoolean(1)); } else if (action.equals("runInstallNativeApp")) { this.runInstallNativeApp(args.getString(0), args.getString(1), args.getString(2), args.getString(3)); } else if (action.equals("sendEmail")) { this.sendEmail(args.getString(0), args.getString(1), args.getString(2), args.getBoolean(3), args.getString(4), args.getString(5)); } else if (action.equals("sendSMS")) { this.sendSMS(args.getString(0), args.getString(1)); } else if (action.equals("setAutoRotate")) { this.setAutoRotate(args.getBoolean(0)); } else if (action.equals("setRotateOrientation")) { this.setRotateOrientation(args.getString(0)); } else if (action.equals("setBasicAuthentication")) { this.setBasicAuthentication(args.getString(0), args.getString(1), args.getString(2)); } else if (action.equals("showRemoteSite")) { this.showRemoteSite(args.getString(0), args.getInt(1), args.getInt(2), args.getInt(3), args.getInt(4)); } else if (action.equals("showRemoteSiteExt")) { this.showRemoteSite(args.getString(0), args.getInt(1), args.getInt(2), args.getInt(3), args.getInt(4), args.getInt(5), args.getInt(6)); } else if (action.equals("closeRemoteSite")) { this.closeRemoteSite(); } else if (action.equals("updateConnection")) { this.updateConnection(); } else if (action.equals("mainViewExecute")) { this.mainViewExecute(args.getString(0)); } else if (action.equals("copyToClipboard")) { this.copyToClipboard(args.getString(0)); } else if (action.equals("initialize")) { this.initialize(); } else { return false; } // All actions are async. //callbackContext.success(); return true; }
From source file:com.github.secondsun.catfactsdemo.networking.CatFactFetcherService.java
protected void onHandleIntent(Intent intent) { if (intent.getBooleanExtra(LOAD, false)) { CharSequence contentText; if (data.size() > 0) { contentText = "Data Loaded"; } else {//from w w w . j ava 2 s . com contentText = "Awaiting Data Load"; } Intent notificationIntent = new Intent(this, CatFacts.class); PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0); Notification notification = new Notification.Builder(this).setSmallIcon(R.mipmap.ic_launcher) .setContentTitle("CatFact Fetcher").setContentText(contentText).setContentIntent(pendingIntent) .build(); startForeground(ONGOING_NOTIFICATION_ID, notification); } else if (intent.getBooleanExtra(UNLOAD, false)) { stopForeground(true); } else { if (intent.getBooleanExtra(RESET, false)) { data.clear(); Intent notificationIntent = new Intent(this, CatFacts.class); PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0); Notification notification = new Notification.Builder(this).setSmallIcon(R.mipmap.ic_launcher) .setContentTitle("CatFact Fetcher").setContentText("Awaiting Data Load") .setContentIntent(pendingIntent).build(); startForeground(ONGOING_NOTIFICATION_ID, notification); } if (data.size() == 0) { try { Thread.sleep(Constants.DELAY); OkHttpClient client = new OkHttpClient(); Request request = new Request.Builder().url(Constants.CAT_FACTS_URL).build(); Response response = client.newCall(request).execute(); JSONObject responseJson = new JSONObject(response.body().string()); JSONArray facts = responseJson.getJSONArray("facts"); ArrayList<String> toReturn = new ArrayList<>(facts.length()); for (int i = 0; i < facts.length(); i++) { toReturn.add(facts.getString(i)); } data = toReturn; } catch (InterruptedException | IOException | JSONException e) { ArrayList<String> toReturn = new ArrayList<>(); toReturn.add("Error:" + e.getMessage()); data = toReturn; } } Intent notificationIntent = new Intent(this, CatFacts.class); PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0); Notification notification = new Notification.Builder(this).setSmallIcon(R.mipmap.ic_launcher) .setContentTitle("CatFact Fetcher").setContentText("Data Available") .setContentIntent(pendingIntent).build(); startForeground(ONGOING_NOTIFICATION_ID, notification); sendData(); } }
From source file:com.jennifer.ui.util.DomUtil.java
public String collapseStyle() { StringBuilder str = new StringBuilder(); JSONArray names = styles.names(); if (names != null) { for (int i = 0, len = names.length(); i < len; i++) { String key = names.getString(i); String value = styles.getString(key); str.append("" + key + ":" + value + ";"); }/* www . j a v a 2 s . c om*/ } return str.toString(); }
From source file:com.jennifer.ui.util.DomUtil.java
public String collapseAttr() { StringBuilder str = new StringBuilder(); String style = collapseStyle(); if (!style.equals("")) { if (attrs.has("style")) { style = getString("style") + ";" + style; }//from www.j a v a 2 s.co m put("style", style); } JSONArray names = attrs.names(); if (names != null) { for (int i = 0, len = names.length(); i < len; i++) { String key = names.getString(i); String value = get(key).toString(); str.append(" " + key + "=\"" + value + "\""); } } return str.toString(); }
From source file:com.jennifer.ui.util.DomUtil.java
public static String join(JSONArray list, String separator) { int len = list.length(); StringBuilder sb = new StringBuilder(); for (int i = 0; i < len; i += 1) { if (i > 0) { sb.append(separator);/*from w w w .j a v a 2s . c o m*/ } sb.append(list.getString(i)); } return sb.toString(); }
From source file:com.jennifer.ui.util.DomUtil.java
public DomUtil attr(JSONObject JSONObject) { JSONArray list = JSONObject.names(); for (int i = 0, len = list.length(); i < len; i++) { String key = list.getString(i); put(key, JSONObject.get(key));//from w w w . j a v a 2s . c o m } return this; }