/** * Get extra long value. * @param key The key of the stored value. * @param defaultValue The value to return if the key does not exist or the value cannot be * coerced into the necessary type. * @return The stored value or the provided default if it doesn't exist in specified form. */ public long optExtraLong(String key, long defaultValue) { return mExtraData.optLong(key, defaultValue); }
/** * Get extra long value. * @param key The key of the stored value. * @return The stored value or 0 if it doesn't exist in specified form. */ public long optExtraLong(String key) { return mExtraData.optLong(key); }
/** * Get extra long value. * @param key The key of the stored value. * @return The stored value or 0 if it doesn't exist in specified form. */ public long optExtraLong(String key) { return mExtraData.optLong(key); }
/** * Get extra long value. * @param key The key of the stored value. * @param defaultValue The value to return if the key does not exist or the value cannot be * coerced into the necessary type. * @return The stored value or the provided default if it doesn't exist in specified form. */ public long optExtraLong(String key, long defaultValue) { return mExtraData.optLong(key, defaultValue); }
/** * Get an optional long value associated with a key, or zero if there is no * such key or if the value is not a number. If the value is a string, an * attempt will be made to evaluate it as a number. * * @param key * A key string. * @return An object which is the value. */ public long optLong(String key) { return this.optLong(key, 0); }
/** * Returns the value mapped by {@code name} if it exists and is a long or * can be coerced to a long. Returns 0 otherwise. Note that JSON represents numbers as doubles, * so this is <a href="#lossy">lossy</a>; use strings to transfer numbers via JSON. */ public long optLong(String name) { return optLong(name, 0L); }
/** * Returns the value mapped by {@code name} if it exists and is a long or can be coerced to a * long, or 0 otherwise. Note that JSON represents numbers as doubles, so this is * <a href="#lossy">lossy</a>; use strings to transfer numbers via JSON. * * @param name The name of the field we want. * @return The selected value. */ public long optLong(String name) { return optLong(name, 0L); }
/** * Get an optional long value associated with a key, or zero if there is no * such key or if the value is not a number. If the value is a string, an * attempt will be made to evaluate it as a number. * * @param key * A key string. * @return An object which is the value. */ public long optLong(String key) { return this.optLong(key, 0); }
public long getLong(String key) { return jsonObject.optLong(key); }
@Override public void onCompleted(GraphResponse response) { JSONObject data = response.getJSONObject(); if (data == null) { return; } refreshResult.accessToken = data.optString("access_token"); refreshResult.expiresAt = data.optInt("expires_at"); refreshResult.dataAccessExpirationTime = data.optLong("data_access_expiration_time"); } })
public SkuDetails(JSONObject source) throws JSONException { String responseType = source.optString(Constants.RESPONSE_TYPE); if (responseType == null) { responseType = Constants.PRODUCT_TYPE_MANAGED; } productId = source.optString(Constants.RESPONSE_PRODUCT_ID); title = source.optString(Constants.RESPONSE_TITLE); description = source.optString(Constants.RESPONSE_DESCRIPTION); isSubscription = responseType.equalsIgnoreCase(Constants.PRODUCT_TYPE_SUBSCRIPTION); currency = source.optString(Constants.RESPONSE_PRICE_CURRENCY); priceLong = source.optLong(Constants.RESPONSE_PRICE_MICROS); priceValue = priceLong / 1000000d; priceText = source.optString(Constants.RESPONSE_PRICE); subscriptionPeriod = source.optString(Constants.RESPONSE_SUBSCRIPTION_PERIOD); subscriptionFreeTrialPeriod = source.optString(Constants.RESPONSE_FREE_TRIAL_PERIOD); haveTrialPeriod = !TextUtils.isEmpty(subscriptionFreeTrialPeriod); introductoryPriceLong = source.optLong(Constants.RESPONSE_INTRODUCTORY_PRICE_MICROS); introductoryPriceValue = introductoryPriceLong / 1000000d; introductoryPriceText = source.optString(Constants.RESPONSE_INTRODUCTORY_PRICE); introductoryPricePeriod = source.optString(Constants.RESPONSE_INTRODUCTORY_PRICE_PERIOD); haveIntroductoryPeriod = !TextUtils.isEmpty(introductoryPricePeriod); introductoryPriceCycles = source.optInt(Constants.RESPONSE_INTRODUCTORY_PRICE_CYCLES); }
private static UpdateInfo parse(JSONObject o) { UpdateInfo info = new UpdateInfo(); if (o == null) { return info; } info.hasUpdate = o.optBoolean("hasUpdate", false); if (!info.hasUpdate) { return info; } info.isSilent = o.optBoolean("isSilent", false); info.isForce = o.optBoolean("isForce", false); info.isAutoInstall = o.optBoolean("isAutoInstall", !info.isSilent); info.isIgnorable = o.optBoolean("isIgnorable", true); info.versionCode = o.optInt("versionCode", 0); info.versionName = o.optString("versionName"); info.updateContent = o.optString("updateContent"); info.url = o.optString("url"); info.md5 = o.optString("md5"); info.size = o.optLong("size", 0); return info; } }
PurchaseData parseResponseDataImpl() { try { JSONObject json = new JSONObject(responseData); PurchaseData data = new PurchaseData(); data.orderId = json.optString(Constants.RESPONSE_ORDER_ID); data.packageName = json.optString(Constants.RESPONSE_PACKAGE_NAME); data.productId = json.optString(Constants.RESPONSE_PRODUCT_ID); long purchaseTimeMillis = json.optLong(Constants.RESPONSE_PURCHASE_TIME, 0); data.purchaseTime = purchaseTimeMillis != 0 ? new Date(purchaseTimeMillis) : null; data.purchaseState = PurchaseState.values()[json.optInt(Constants.RESPONSE_PURCHASE_STATE, 1)]; data.developerPayload = json.optString(Constants.RESPONSE_DEVELOPER_PAYLOAD); data.purchaseToken = json.getString(Constants.RESPONSE_PURCHASE_TOKEN); data.autoRenewing = json.optBoolean(Constants.RESPONSE_AUTO_RENEWING); return data; } catch (JSONException e) { Log.e(LOG_TAG, "Failed to parse response data", e); return null; } }
private long getModelIdFromUri(Uri uri, Collection col) { String modelIdSegment = uri.getPathSegments().get(1); long id; if (modelIdSegment.equals(FlashCardsContract.Model.CURRENT_MODEL_ID)) { id = col.getModels().current().optLong("id", -1); } else { try { id = Long.parseLong(uri.getPathSegments().get(1)); } catch (NumberFormatException e) { throw new IllegalArgumentException("Model ID must be either numeric or the String CURRENT_MODEL_ID"); } } return id; }
static AccessToken createFromJSONObject(JSONObject jsonObject) throws JSONException { int version = jsonObject.getInt(VERSION_KEY); if (version > CURRENT_JSON_FORMAT) { throw new FacebookException("Unknown AccessToken serialization format."); } String token = jsonObject.getString(TOKEN_KEY); Date expiresAt = new Date(jsonObject.getLong(EXPIRES_AT_KEY)); JSONArray permissionsArray = jsonObject.getJSONArray(PERMISSIONS_KEY); JSONArray declinedPermissionsArray = jsonObject.getJSONArray(DECLINED_PERMISSIONS_KEY); Date lastRefresh = new Date(jsonObject.getLong(LAST_REFRESH_KEY)); AccessTokenSource source = AccessTokenSource.valueOf(jsonObject.getString(SOURCE_KEY)); String applicationId = jsonObject.getString(APPLICATION_ID_KEY); String userId = jsonObject.getString(USER_ID_KEY); Date dataAccessExpirationTime = new Date( jsonObject.optLong(DATA_ACCESS_EXPIRATION_TIME, 0)); return new AccessToken( token, applicationId, userId, Utility.jsonArrayToStringList(permissionsArray), Utility.jsonArrayToStringList(declinedPermissionsArray), source, expiresAt, lastRefresh, dataAccessExpirationTime); }
/** * Return the position of the deck in the deck list. If the deck is a child of a collapsed deck * (i.e., not visible in the deck list), then the position of the parent deck is returned instead. * * An invalid deck ID will return position 0. */ public int findDeckPosition(long did) { for (int i = 0; i < mDeckList.size(); i++) { if (mDeckList.get(i).did == did) { return i; } } // If the deck is not in our list, we search again using the immediate parent List<JSONObject> parents = mCol.getDecks().parents(did); if (parents.size() == 0) { return 0; } else { return findDeckPosition(parents.get(parents.size() - 1).optLong("id", 0)); } }
/** * Get current model. * @param forDeck If true, it tries to get the deck specified in deck by mid, otherwise or if the former is not * found, it uses the configuration`s field curModel. * @return The JSONObject of the model, or null if not found in the deck and in the configuration. */ public JSONObject current(boolean forDeck) { JSONObject m = null; if (forDeck) { m = get(mCol.getDecks().current().optLong("mid", -1)); } if (m == null) { m = get(mCol.getConf().optLong("curModel", -1)); } if (m == null) { if (!mModels.isEmpty()) { m = mModels.values().iterator().next(); } } return m; }
@Override public void onPreExecute() { mProgressDialog = StyledProgressDialog.show(DeckPicker.this, "", getResources().getString(R.string.delete_deck), false); if (did == getCol().getDecks().current().optLong("id")) { removingCurrent = true; } }