v0.6.1: added support for bundling and unbundling float arrays
This commit is contained in:
parent
096d453cbb
commit
113ac2daa1
|
@ -21,6 +21,11 @@
|
|||
|
||||
package com.watabou.utils;
|
||||
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
import org.json.JSONTokener;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.BufferedWriter;
|
||||
import java.io.IOException;
|
||||
|
@ -36,11 +41,6 @@ import java.util.HashMap;
|
|||
import java.util.zip.GZIPInputStream;
|
||||
import java.util.zip.GZIPOutputStream;
|
||||
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
import org.json.JSONTokener;
|
||||
|
||||
public class Bundle {
|
||||
|
||||
private static final String CLASS_NAME = "__className";
|
||||
|
@ -166,6 +166,21 @@ public class Bundle {
|
|||
}
|
||||
}
|
||||
|
||||
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) {
|
||||
reportException(e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean[] getBooleanArray( String key ) {
|
||||
try {
|
||||
JSONArray array = data.getJSONArray( key );
|
||||
|
@ -329,6 +344,18 @@ public class Bundle {
|
|||
}
|
||||
}
|
||||
|
||||
public void put( String key, float[] array ) {
|
||||
try {
|
||||
JSONArray jsonArray = new JSONArray();
|
||||
for (int i=0; i < array.length; i++) {
|
||||
jsonArray.put( i, array[i] );
|
||||
}
|
||||
data.put( key, jsonArray );
|
||||
} catch (JSONException e) {
|
||||
reportException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public void put( String key, boolean[] array ) {
|
||||
try {
|
||||
JSONArray jsonArray = new JSONArray();
|
||||
|
|
Loading…
Reference in New Issue
Block a user