List of usage examples for org.json JSONObject optBoolean
public boolean optBoolean(String key)
From source file:g7.bluesky.launcher3.InstallShortcutReceiver.java
private static PendingInstallShortcutInfo decode(String encoded, Context context) { try {// ww w.ja v a2 s . c om JSONObject object = (JSONObject) new JSONTokener(encoded).nextValue(); Intent launcherIntent = Intent.parseUri(object.getString(LAUNCH_INTENT_KEY), 0); if (object.optBoolean(APP_SHORTCUT_TYPE_KEY)) { // The is an internal launcher target shortcut. UserHandleCompat user = UserManagerCompat.getInstance(context) .getUserForSerialNumber(object.getLong(USER_HANDLE_KEY)); if (user == null) { return null; } LauncherActivityInfoCompat info = LauncherAppsCompat.getInstance(context) .resolveActivity(launcherIntent, user); return info == null ? null : new PendingInstallShortcutInfo(info, context); } Intent data = new Intent(); data.putExtra(Intent.EXTRA_SHORTCUT_INTENT, launcherIntent); data.putExtra(Intent.EXTRA_SHORTCUT_NAME, object.getString(NAME_KEY)); String iconBase64 = object.optString(ICON_KEY); String iconResourceName = object.optString(ICON_RESOURCE_NAME_KEY); String iconResourcePackageName = object.optString(ICON_RESOURCE_PACKAGE_NAME_KEY); if (iconBase64 != null && !iconBase64.isEmpty()) { byte[] iconArray = Base64.decode(iconBase64, Base64.DEFAULT); Bitmap b = BitmapFactory.decodeByteArray(iconArray, 0, iconArray.length); data.putExtra(Intent.EXTRA_SHORTCUT_ICON, b); } else if (iconResourceName != null && !iconResourceName.isEmpty()) { Intent.ShortcutIconResource iconResource = new Intent.ShortcutIconResource(); iconResource.resourceName = iconResourceName; iconResource.packageName = iconResourcePackageName; data.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, iconResource); } return new PendingInstallShortcutInfo(data, context); } catch (JSONException e) { Log.d(TAG, "Exception reading shortcut to add: " + e); } catch (URISyntaxException e) { Log.d(TAG, "Exception reading shortcut to add: " + e); } return null; }
From source file:com.zotoh.core.util.JSONUte.java
/** * @param obj//w w w.j ava 2s . c o m * @param key * @return */ public static boolean getBoolean(JSONObject obj, String key) { return obj == null ? false : obj.optBoolean(key); }
From source file:com.rapid.actions.Database.java
public Database(RapidHttpServlet rapidServlet, JSONObject jsonAction) throws Exception { // call the super parameterless constructor which sets the xml version super();//from ww w .j av a2s.c om // save all key/values from the json into the properties for (String key : JSONObject.getNames(jsonAction)) { // add all json properties to our properties, except for query if (!"query".equals(key) && !"showLoading".equals(key) && !"childDatabaseActions".equals(key) && !"successActions".equals(key) && !"errorActions".equals(key) && !"childActions".equals(key)) addProperty(key, jsonAction.get(key).toString()); } // try and build the query object JSONObject jsonQuery = jsonAction.optJSONObject("query"); // check we got one if (jsonQuery != null) { // get the parameters ArrayList<Parameter> inputs = getParameters(jsonQuery.optJSONArray("inputs")); ArrayList<Parameter> outputs = getParameters(jsonQuery.optJSONArray("outputs")); String sql = jsonQuery.optString("SQL"); boolean multiRow = jsonQuery.optBoolean("multiRow"); int databaseConnectionIndex = jsonQuery.optInt("databaseConnectionIndex"); // make the object _query = new Query(inputs, outputs, sql, multiRow, databaseConnectionIndex); } // look for showLoading _showLoading = jsonAction.optBoolean("showLoading"); // grab any successActions JSONArray jsonChildDatabaseActions = jsonAction.optJSONArray("childDatabaseActions"); // if we had some if (jsonChildDatabaseActions != null) { // instantiate collection _childDatabaseActions = new ArrayList<Database>(); // loop them for (int i = 0; i < jsonChildDatabaseActions.length(); i++) { // get one JSONObject jsonChildDatabaseAction = jsonChildDatabaseActions.getJSONObject(i); // instantiate and add to collection _childDatabaseActions.add(new Database(rapidServlet, jsonChildDatabaseAction)); } } // grab any successActions JSONArray jsonSuccessActions = jsonAction.optJSONArray("successActions"); // if we had some instantiate our collection if (jsonSuccessActions != null) _successActions = Control.getActions(rapidServlet, jsonSuccessActions); // grab any errorActions JSONArray jsonErrorActions = jsonAction.optJSONArray("errorActions"); // if we had some instantiate our collection if (jsonErrorActions != null) _errorActions = Control.getActions(rapidServlet, jsonErrorActions); }