List of usage examples for org.json JSONArray getString
public String getString(int index) throws JSONException
From source file:com.angrystone.JpegCompressor.java
@Override public PluginResult execute(String action, JSONArray args, String callbackId) { PluginResult.Status status = PluginResult.Status.OK; String filename = "/mnt/sdcard/DCIM/Camera/Convert_"; String orifilename = "/mnt/sdcard/DCIM/Camera/"; if (action.equals("compress")) { Integer quality = 100;//ww w . ja v a2 s. c o m try { orifilename = orifilename.concat(args.getString(0)); filename = filename.concat(args.getString(0)); quality = args.getInt(1); } catch (JSONException e) { // TODO Auto-generated catch block e.printStackTrace(); } OutputStream outputStream = null; File file = new File(filename); Bitmap bitmap = BitmapFactory.decodeFile(orifilename); try { outputStream = new FileOutputStream(file); bitmap.compress(Bitmap.CompressFormat.JPEG, quality, outputStream); try { outputStream.flush(); outputStream.close(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } } else { status = PluginResult.Status.INVALID_ACTION; } return new PluginResult(status, filename); }
From source file:com.polyvi.xface.extension.messaging.XMessagingExt.java
@Override public boolean execute(String action, JSONArray args, CallbackContext callbackContext) throws JSONException { mCallbackContext = callbackContext;/*from w w w . j a v a 2 s. c o m*/ try { if (action.equals(COMMAND_SENDMESSAGE)) { sendMessage(args.getString(0), args.getString(1), args.getString(2), args.getString(3)); } else if (action.equals(COMMAND_GETQUANTITIES)) { int numbers = getQuantities(args.getString(0), args.getString(1)); callbackContext.success(numbers); } else if (action.equals(COMMAND_GETALLMESSAGES)) { JSONArray messages = getAllMessages(args.getString(0), args.getString(1)); callbackContext.success(messages); } else if (action.equals(COMMAND_GETMESSAGE)) { JSONObject message = getMessage(args.getString(0), args.getString(1), args.getInt(2)); callbackContext.success(message); } else if (action.equals(COMMAND_FINDMESSAGES)) { JSONArray messages = findMessages(args.getJSONObject(0), args.getString(1), args.getInt(2), args.getInt(3)); callbackContext.success(messages); } return true; } catch (IllegalArgumentException e) { } catch (Exception e) { } return false; }
From source file:com.keylesspalace.tusky.util.NotificationManager.java
/** * Takes a given Mastodon notification and either creates a new Android notification or updates * the state of the existing notification to reflect the new interaction. * * @param context to access application preferences and services * @param notifyId an arbitrary number to reference this notification for any future action * @param body a new Mastodon notification *///w w w . j a va 2 s . co m public static void make(final Context context, final int notifyId, Notification body) { final SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context); final SharedPreferences notificationPreferences = context.getSharedPreferences("Notifications", Context.MODE_PRIVATE); if (!filterNotification(preferences, body)) { return; } createNotificationChannels(context); String rawCurrentNotifications = notificationPreferences.getString("current", "[]"); JSONArray currentNotifications; try { currentNotifications = new JSONArray(rawCurrentNotifications); } catch (JSONException e) { currentNotifications = new JSONArray(); } boolean alreadyContains = false; for (int i = 0; i < currentNotifications.length(); i++) { try { if (currentNotifications.getString(i).equals(body.account.getDisplayName())) { alreadyContains = true; } } catch (JSONException e) { Log.d(TAG, Log.getStackTraceString(e)); } } if (!alreadyContains) { currentNotifications.put(body.account.getDisplayName()); } notificationPreferences.edit().putString("current", currentNotifications.toString()).apply(); Intent resultIntent = new Intent(context, MainActivity.class); resultIntent.putExtra("tab_position", 1); TaskStackBuilder stackBuilder = TaskStackBuilder.create(context); stackBuilder.addParentStack(MainActivity.class); stackBuilder.addNextIntent(resultIntent); PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT); Intent deleteIntent = new Intent(context, NotificationClearBroadcastReceiver.class); PendingIntent deletePendingIntent = PendingIntent.getBroadcast(context, 0, deleteIntent, PendingIntent.FLAG_CANCEL_CURRENT); final NotificationCompat.Builder builder = new NotificationCompat.Builder(context, getChannelId(body)) .setSmallIcon(R.drawable.ic_notify).setContentIntent(resultPendingIntent) .setDeleteIntent(deletePendingIntent).setColor(ContextCompat.getColor(context, (R.color.primary))) .setDefaults(0); // So it doesn't ring twice, notify only in Target callback setupPreferences(preferences, builder); if (currentNotifications.length() == 1) { builder.setContentTitle(titleForType(context, body)) .setContentText(truncateWithEllipses(bodyForType(body), 40)); //load the avatar synchronously Bitmap accountAvatar; try { accountAvatar = Picasso.with(context).load(body.account.avatar) .transform(new RoundedTransformation(7, 0)).get(); } catch (IOException e) { Log.d(TAG, "error loading account avatar", e); accountAvatar = BitmapFactory.decodeResource(context.getResources(), R.drawable.avatar_default); } builder.setLargeIcon(accountAvatar); } else { try { String format = context.getString(R.string.notification_title_summary); String title = String.format(format, currentNotifications.length()); String text = truncateWithEllipses(joinNames(context, currentNotifications), 40); builder.setContentTitle(title).setContentText(text); } catch (JSONException e) { Log.d(TAG, Log.getStackTraceString(e)); } } if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { builder.setVisibility(android.app.Notification.VISIBILITY_PRIVATE); builder.setCategory(android.app.Notification.CATEGORY_SOCIAL); } android.app.NotificationManager notificationManager = (android.app.NotificationManager) context .getSystemService(Context.NOTIFICATION_SERVICE); //noinspection ConstantConditions notificationManager.notify(notifyId, builder.build()); }
From source file:mai.whack.StickyNotesActivity.java
public void handleData(String data) { JSONObject jsonObject;//w w w . j a v a 2 s .c o m JSONArray jsonTabs = null; try { mHttpGetThread = null; jsonObject = new JSONObject(data); if (jsonObject.getString("type").equals("tabs")) { jsonTabs = jsonObject.getJSONArray("tabs"); for (int i = 0; i < jsonTabs.length(); i++) { openBrowser(jsonTabs.getString(i)); } } else if (jsonObject.getString("type").equals("files")) { jsonTabs = jsonObject.getJSONArray("files"); String[] files = new String[jsonTabs.length()]; for (int i = 0; i < jsonTabs.length(); i++) { files[i] = jsonTabs.getString(i); } onFileList(files); } } catch (JSONException e) { e.printStackTrace(); } }
From source file:com.fanfou.app.opensource.api.ApiParser.java
public static ArrayList<String> ids(final JSONArray a) throws IOException { final ArrayList<String> ids = new ArrayList<String>(); if (a == null) { return ids; }/* ww w.j av a2 s . c o m*/ try { for (int i = 0; i < a.length(); i++) { ids.add(a.getString(i)); } return ids; } catch (final JSONException e) { if (AppContext.DEBUG) { e.printStackTrace(); } } return ids; }
From source file:com.yoncabt.ebr.util.ResultSetDeserializer.java
public List<Object[]> getData() { List<Object[]> ret = new ArrayList<>(); JSONArray arr = jo.getJSONArray("values"); for (int i = 0; i < arr.length(); i++) { List<Object> column = new ArrayList<>(); JSONArray row = arr.getJSONArray(i); for (int j = 0; j < types.size(); j++) { if (row.isNull(j)) { column.add(null);/*from w ww .j a v a2 s. c o m*/ } else { switch (types.get(j)) { case DATE: column.add(new Date(row.getLong(j))); break; case STRING: column.add(row.getString(j)); break; case INTEGER: column.add(row.getInt(j)); break; case LONG: column.add(row.getLong(j)); break; case DOUBLE: column.add(row.getDouble(j)); break; default: throw new AssertionError(); } } } ret.add(column.toArray()); } return ret; }
From source file:com.yoncabt.ebr.util.ResultSetDeserializer.java
private void readTypes() { JSONArray arr = jo.getJSONArray("types"); for (int i = 0; i < arr.length(); i++) { String type = arr.getString(i); types.add(FieldType.valueOf(type)); }/*from w w w . j av a 2s.c o m*/ arr = jo.getJSONArray("names"); for (int i = 0; i < arr.length(); i++) { String name = arr.getString(i); names.add(name); } }
From source file:com.fluidinfo.utils.StringUtil.java
/** * Given a JSONArray (of strings) will return the String[] array representation * @param input The JSONArray to process * @return The resulting String[]/*from w w w .ja v a2 s. co m*/ * @throws JSONException */ public static String[] getStringArrayFromJSONArray(JSONArray input) throws JSONException { String[] result = new String[input.length()]; for (int i = 0; i < input.length(); i++) { result[i] = input.getString(i); } return result; }
From source file:com.dubsar_dictionary.Dubsar.model.Synset.java
@Override public void parseData(Object jsonResponse) throws JSONException { JSONArray response = (JSONArray) jsonResponse; setPos(response.getString(1)); setLexname(response.getString(2));/* w ww. j a v a 2s .c o m*/ mGloss = response.getString(3); JSONArray samples = response.getJSONArray(4); mSamples = new ArrayList<String>(samples.length()); int j; for (j = 0; j < samples.length(); ++j) { mSamples.add(samples.getString(j)); } JSONArray senses = response.getJSONArray(5); mSenses = new ArrayList<Sense>(senses.length()); for (j = 0; j < senses.length(); ++j) { JSONArray _sense = senses.getJSONArray(j); int senseId = _sense.getInt(0); String senseName = _sense.getString(1); Sense sense = new Sense(senseId, senseName, this); sense.setLexname(getLexname()); if (!_sense.isNull(2)) { sense.setMarker(_sense.getString(2)); } sense.setFreqCnt(_sense.getInt(3)); mSenses.add(sense); } mFreqCnt = response.getInt(6); parsePointers(response.getJSONArray(7)); }
From source file:com.richardradics.commons.helper.SimpleSharedPreferences.java
@Override public Set<String> getStringSet(String key, Set<String> defValues) throws ClassCastException { initiateSharedPreferences();/* w w w . ja v a 2 s . c om*/ final String jsonPref = getString(key, null); if (jsonPref == null) { return defValues; } final List<String> prefValues = new ArrayList<String>(); try { final JSONArray mJsonArray = new JSONObject(jsonPref).getJSONArray(key); for (int i = 0; i < mJsonArray.length(); i++) { prefValues.add(mJsonArray.getString(i)); } } catch (final JSONException e) { e.printStackTrace(); } try { return new HashSet<String>(prefValues); } catch (final ClassCastException e) { final String returnType = new Object() { }.getClass().getEnclosingMethod().getReturnType().toString(); throw new ClassCastException("\n ======================================== \nClassCastException : " + key + "'s value is not a " + returnType + " \n ======================================== \n"); } catch (final Exception e) { return defValues; } }