Java Code Examples for org.json.JSONArray#optDouble()
The following examples show how to use
org.json.JSONArray#optDouble() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: GeoJsonExtent.java From ground-android with Apache License 2.0 | 6 votes |
private ImmutableList<LatLng> ringCoordinatesToLatLngs(JSONArray exteriorRing) { if (exteriorRing == null) { return ImmutableList.of(); } List<LatLng> coordinates = new ArrayList<>(); for (int i = 0; i < exteriorRing.length(); i++) { JSONArray point = exteriorRing.optJSONArray(i); double lat = point.optDouble(1, 0.0); double lng = point.optDouble(0, 0.0); // PMD complains about instantiating objects in loops, but here, we retain a reference to the // object after the loop exits--the PMD recommendation here makes little sense, and is // presumably intended to prevent short-lived allocations. coordinates.add(new LatLng(lat, lng)); // NOPMD } return stream(coordinates).collect(toImmutableList()); }
Example 2
Source File: ColumnStyle.java From Tangram-Android with MIT License | 6 votes |
@Override public void parseWith(JSONObject data) { super.parseWith(data); if (data != null) { JSONArray jsonCols = data.optJSONArray(KEY_COLS); if (jsonCols != null) { cols = new float[jsonCols.length()]; for (int i = 0; i < cols.length; i++) { cols[i] = (float) jsonCols.optDouble(i, 0); } } else { cols = new float[0]; } JSONArray jsonRows = data.optJSONArray(KEY_ROWS); if (jsonRows != null) { rows = new float[jsonRows.length()]; for (int i = 0; i < rows.length; i++) { rows[i] = (float) jsonRows.optDouble(i, 0); } } else { rows = new float[0]; } } }
Example 3
Source File: GridCard.java From Tangram-Android with MIT License | 6 votes |
@Override public void parseWith(JSONObject data) { super.parseWith(data); if (data != null) { column = data.optInt(KEY_COLUMN, 0); autoExpand = data.optBoolean(KEY_AUTO_EXPAND, false); JSONArray jsonCols = data.optJSONArray(KEY_COLS); if (jsonCols != null) { cols = new float[jsonCols.length()]; for (int i = 0; i < cols.length; i++) { cols[i] = (float) jsonCols.optDouble(i, 0); } } else { cols = new float[0]; } hGap = Style.parseSize(data.optString(KEY_H_GAP), 0); vGap = Style.parseSize(data.optString(KEY_V_GAP), 0); } }
Example 4
Source File: ColorFactory.java From atlas with Apache License 2.0 | 6 votes |
@Override public Integer valueFromObject(Object object, float scale) { JSONArray colorArray = (JSONArray) object; if (colorArray.length() == 4) { boolean shouldUse255 = true; for (int i = 0; i < colorArray.length(); i++) { double colorChannel = colorArray.optDouble(i); if (colorChannel > 1f) { shouldUse255 = false; } } float multiplier = shouldUse255 ? 255f : 1f; return Color.argb( (int) (colorArray.optDouble(3) * multiplier), (int) (colorArray.optDouble(0) * multiplier), (int) (colorArray.optDouble(1) * multiplier), (int) (colorArray.optDouble(2) * multiplier)); } return Color.BLACK; }
Example 5
Source File: FURenderer.java From PLDroidShortVideo with Apache License 2.0 | 6 votes |
/** * 从 assets 中读取颜色数据 * * @param colorAssetPath * @return rgba 数组 * @throws Exception */ private double[] readMakeupLipColors(String colorAssetPath) throws IOException, JSONException { if (TextUtils.isEmpty(colorAssetPath)) { return null; } InputStream is = null; try { is = mContext.getAssets().open(colorAssetPath); byte[] bytes = new byte[is.available()]; is.read(bytes); String s = new String(bytes); JSONObject jsonObject = new JSONObject(s); JSONArray jsonArray = jsonObject.optJSONArray("rgba"); double[] colors = new double[4]; for (int i = 0, length = jsonArray.length(); i < length; i++) { colors[i] = jsonArray.optDouble(i); } return colors; } finally { if (is != null) { is.close(); } } }
Example 6
Source File: MagicPhotoEntity.java From PLDroidShortVideo with Apache License 2.0 | 6 votes |
public double[] getGroupType() { if (groupType == null) { if (groupTypeStr != null) { try { JSONArray jsonArray = new JSONArray(groupTypeStr); int size = jsonArray.length(); groupType = new double[size]; for (int i = 0; i < size; i++) { groupType[i] = jsonArray.optDouble(i); } } catch (JSONException e) { e.printStackTrace(); } } } return groupType; }
Example 7
Source File: MagicPhotoEntity.java From PLDroidShortVideo with Apache License 2.0 | 6 votes |
public double[] getGroupPoints() { if (groupPoints == null) { if (groupPointsStr != null) { try { JSONArray jsonArray = new JSONArray(groupPointsStr); int size = jsonArray.length(); groupPoints = new double[size]; for (int i = 0; i < size; i++) { groupPoints[i] = jsonArray.optDouble(i); } } catch (JSONException e) { e.printStackTrace(); } } } return groupPoints; }
Example 8
Source File: LivePhoto.java From sealrtc-android with MIT License | 6 votes |
public float[] getAdjustPointsF() { if (this.adjustedPointsStr != null) { try { JSONArray jsonArray = new JSONArray(this.adjustedPointsStr); int length = jsonArray.length(); float[] adjustPoints = new float[length]; for (int i = 0; i < length; i++) { adjustPoints[i] = (float) jsonArray.optDouble(i); } return adjustPoints; } catch (JSONException e) { e.printStackTrace(); } } return null; }
Example 9
Source File: LivePhoto.java From sealrtc-android with MIT License | 6 votes |
public float[] getMatrixF() { if (this.transformMatrixStr != null) { try { JSONArray jsonArray = new JSONArray(this.transformMatrixStr); int length = jsonArray.length(); float[] matrix = new float[length]; for (int i = 0; i < length; i++) { matrix[i] = (float) jsonArray.optDouble(i); } return matrix; } catch (JSONException e) { e.printStackTrace(); } } return null; }
Example 10
Source File: LivePhoto.java From sealrtc-android with MIT License | 6 votes |
public double[] getGroupType() { if (this.groupType == null) { if (this.groupTypeStr != null) { try { JSONArray jsonArray = new JSONArray(this.groupTypeStr); int size = jsonArray.length(); this.groupType = new double[size]; for (int i = 0; i < size; i++) { this.groupType[i] = jsonArray.optDouble(i); } } catch (JSONException e) { e.printStackTrace(); } } } return this.groupType; }
Example 11
Source File: LivePhoto.java From sealrtc-android with MIT License | 6 votes |
public double[] getGroupPoints() { if (groupPoints == null) { if (groupPointsStr != null) { try { JSONArray jsonArray = new JSONArray(groupPointsStr); int size = jsonArray.length(); groupPoints = new double[size]; for (int i = 0; i < size; i++) { groupPoints[i] = jsonArray.optDouble(i); } } catch (JSONException e) { e.printStackTrace(); } } } return groupPoints; }
Example 12
Source File: AvatarFaceHelper.java From PLDroidShortVideo with Apache License 2.0 | 5 votes |
public static List<AvatarFaceAspect> config2List(String config) { try { JSONArray jsonArray = new JSONArray(config); int length = jsonArray.length(); List<AvatarFaceAspect> avatarFaceAspects = new ArrayList<>(length); AvatarFaceAspect avatarFaceAspect; for (int i = 0; i < length; i++) { avatarFaceAspect = new AvatarFaceAspect(); JSONObject jsonObject = jsonArray.optJSONObject(i); String name = jsonObject.optString("name"); if (jsonObject.has("level")) { double level = jsonObject.optDouble("level"); avatarFaceAspect.setLevel((float) level); avatarFaceAspect.setName(name); } else if (jsonObject.has("color")) { JSONArray color = jsonObject.optJSONArray("color"); if (color != null) { int cLen = color.length(); double[] col = new double[cLen]; for (int j = 0; j < cLen; j++) { col[j] = color.optDouble(j); } avatarFaceAspect.setColor(col); } avatarFaceAspect.setName(name); } else if (jsonObject.has("path")) { String path = jsonObject.optString("path"); avatarFaceAspect.setBundlePath(path); } avatarFaceAspects.add(avatarFaceAspect); } return avatarFaceAspects; } catch (JSONException e) { e.printStackTrace(); } return null; }
Example 13
Source File: JsonUtils.java From atlas with Apache License 2.0 | 5 votes |
static PointF pointFromJsonArray(JSONArray values, float scale) { if (values.length() < 2) { throw new IllegalArgumentException("Unable to parse point for " + values); } return new PointF( (float) values.optDouble(0, 1) * scale, (float) values.optDouble(1, 1) * scale); }
Example 14
Source File: InputConverter.java From react-native-image-filter-kit with MIT License | 5 votes |
private float[] convertScalarVector(@Nullable JSONObject scalarVector, float[] defaultValue) { if (scalarVector != null && scalarVector.has("scalarVector")) { JSONArray sv = scalarVector.optJSONArray("scalarVector"); float[] vector = new float[sv != null ? sv.length() : 0]; for (int i = 0; i < vector.length; i++) { vector[i] = (float) sv.optDouble(i); } return vector; } return defaultValue; }
Example 15
Source File: GeoOri.java From Simpler with Apache License 2.0 | 5 votes |
public static GeoOri parse(JSONObject object) { GeoOri geoOri = null; if (object != null) { geoOri = new GeoOri(); geoOri.type = object.optString("type"); JSONArray array = object.optJSONArray("coordinates"); geoOri.latitude = array.optDouble(0); geoOri.longitude = array.optDouble(1); } return geoOri; }
Example 16
Source File: Bundle.java From shattered-pixel-dungeon-gdx with GNU General Public License v3.0 | 5 votes |
public float[] getFloatArray( String key ) { try { JSONArray array = data.getJSONArray( key ); int length = array.length(); float[] result = new float[length]; for (int i=0; i < length; i++) { result[i] = (float)array.optDouble( i, 0.0 ); } return result; } catch (JSONException e) { Game.reportException(e); return null; } }
Example 17
Source File: DbOpenHelper.java From PLDroidShortVideo with Apache License 2.0 | 4 votes |
public static List<MagicPhotoEntity> getDefaultMagicPhotos(Context context) { List<MagicPhotoEntity> magicPhotoEntities = new ArrayList<>(); File magicPhotoDir = FileUtils.getMagicPhotoDir(context); File[] files = magicPhotoDir.listFiles(); MagicPhotoEntity magicPhotoEntity; Arrays.sort(files); for (File file : files) { File[] mf = file.listFiles(); Arrays.sort(mf); magicPhotoEntity = new MagicPhotoEntity(); for (File f : mf) { String name = f.getName(); if (name.endsWith(".json")) { try { String s = FileUtils.readStringFromFile(f); JSONObject jsonObject = new JSONObject(s); int width = jsonObject.optInt("width"); int height = jsonObject.optInt("height"); JSONArray pointsArray = jsonObject.optJSONArray("group_points"); int len = pointsArray.length(); double[] groupPoints = new double[len]; for (int i = 0; i < len; i++) { groupPoints[i] = pointsArray.optDouble(i); } JSONArray typeArray = jsonObject.optJSONArray("group_type"); len = typeArray.length(); double[] groupType = new double[len]; for (int i = 0; i < len; i++) { groupType[i] = typeArray.optDouble(i); } magicPhotoEntity.setWidth(width); magicPhotoEntity.setHeight(height); magicPhotoEntity.setGroupPoints(groupPoints); magicPhotoEntity.setGroupType(groupType); } catch (Exception e) { Log.e(TAG, "getDefaultMagicPhotos: ", e); } } else if (name.endsWith(".jpg") || name.endsWith(".png")) { magicPhotoEntity.setImagePath(f.getAbsolutePath()); } } magicPhotoEntities.add(magicPhotoEntity); } return magicPhotoEntities; }
Example 18
Source File: ScaleXY.java From atlas with Apache License 2.0 | 4 votes |
@Override public ScaleXY valueFromObject(Object object, float scale) { JSONArray array = (JSONArray) object; return new ScaleXY( (float) array.optDouble(0, 1) / 100f * scale, (float) array.optDouble(1, 1) / 100f * scale); }
Example 19
Source File: LivePhoto.java From sealrtc-android with MIT License | 4 votes |
public static List<LivePhoto> getDefaultLivePhotos(Context context) { List<LivePhoto> livePhotos = new ArrayList<>(4); File livePhotoDir = FileUtils.getLivePhotoDir(context); File[] files = livePhotoDir.listFiles(); if (files != null) { LivePhoto livePhoto; for (File file : files) { File[] mf = file.listFiles(); if (mf != null) { livePhoto = new LivePhoto(); for (File f : mf) { String name = f.getName(); if (name.endsWith(".json")) { try { String s = FileUtils.readStringFromFile(f); JSONObject jsonObject = new JSONObject(s); int width = jsonObject.optInt("width"); int height = jsonObject.optInt("height"); JSONArray pointsArray = jsonObject.optJSONArray("group_points"); int len = pointsArray.length(); double[] groupPoints = new double[len]; for (int i = 0; i < len; i++) { groupPoints[i] = pointsArray.optDouble(i); } JSONArray typeArray = jsonObject.optJSONArray("group_type"); len = typeArray.length(); double[] groupType = new double[len]; for (int i = 0; i < len; i++) { groupType[i] = typeArray.optDouble(i); } livePhoto.setWidth(width); livePhoto.setHeight(height); livePhoto.setGroupPoints(groupPoints); livePhoto.setGroupType(groupType); } catch (Exception e) { e.printStackTrace(); } } else if (name.endsWith(MiscUtil.IMAGE_FORMAT_JPG) || name.endsWith(MiscUtil.IMAGE_FORMAT_JPEG) || name.endsWith(MiscUtil.IMAGE_FORMAT_PNG)) { livePhoto.setTemplateImagePath(f.getAbsolutePath()); } } livePhotos.add(livePhoto); } } } return livePhotos; }
Example 20
Source File: Position.java From OpenMapKitAndroid with BSD 3-Clause "New" or "Revised" License | 4 votes |
public Position(JSONArray array) { this.mStorage[LON_IDX] = array.optDouble(LON_IDX, 0); this.mStorage[LAT_IDX] = array.optDouble(LAT_IDX, 0); this.mStorage[ALT_IDX] = array.optDouble(ALT_IDX, 0); }