use of org.json.JSONObject in project jpHolo by teusink.
the class Capture method createMediaFile.
/**
* Creates a JSONObject that represents a File from the Uri
*
* @param data the Uri of the audio/image/video
* @return a JSONObject that represents a File
* @throws IOException
*/
private JSONObject createMediaFile(Uri data) {
File fp = webView.getResourceApi().mapUriToFile(data);
JSONObject obj = new JSONObject();
Class webViewClass = webView.getClass();
PluginManager pm = null;
try {
Method gpm = webViewClass.getMethod("getPluginManager");
pm = (PluginManager) gpm.invoke(webView);
} catch (NoSuchMethodException e) {
} catch (IllegalAccessException e) {
} catch (InvocationTargetException e) {
}
if (pm == null) {
try {
Field pmf = webViewClass.getField("pluginManager");
pm = (PluginManager) pmf.get(webView);
} catch (NoSuchFieldException e) {
} catch (IllegalAccessException e) {
}
}
FileUtils filePlugin = (FileUtils) pm.getPlugin("File");
LocalFilesystemURL url = filePlugin.filesystemURLforLocalPath(fp.getAbsolutePath());
try {
// File properties
obj.put("name", fp.getName());
obj.put("fullPath", fp.toURI().toString());
if (url != null) {
obj.put("localURL", url.toString());
}
// is stored in the audio or video content store.
if (fp.getAbsoluteFile().toString().endsWith(".3gp") || fp.getAbsoluteFile().toString().endsWith(".3gpp")) {
if (data.toString().contains("/audio/")) {
obj.put("type", AUDIO_3GPP);
} else {
obj.put("type", VIDEO_3GPP);
}
} else {
obj.put("type", FileHelper.getMimeType(Uri.fromFile(fp), cordova));
}
obj.put("lastModifiedDate", fp.lastModified());
obj.put("size", fp.length());
} catch (JSONException e) {
// this will never happen
e.printStackTrace();
}
return obj;
}
use of org.json.JSONObject in project jpHolo by teusink.
the class Capture method createErrorObject.
private JSONObject createErrorObject(int code, String message) {
JSONObject obj = new JSONObject();
try {
obj.put("code", code);
obj.put("message", message);
} catch (JSONException e) {
// This will never happen
}
return obj;
}
use of org.json.JSONObject in project jpHolo by teusink.
the class Globalization method getStringtoDate.
/*
* @Description: Parses a date formatted as a string according to the client's user
* preferences and calendar using the time zone of the client and returns
* the corresponding date object
* @Return: JSONObject
* Object.year {Number}: The four digit year
* Object.month {Number}: The month from (0 - 11)
* Object.day {Number}: The day from (1 - 31)
* Object.hour {Number}: The hour from (0 - 23)
* Object.minute {Number}: The minute from (0 - 59)
* Object.second {Number}: The second from (0 - 59)
* Object.millisecond {Number}: The milliseconds (from 0 - 999), not available on all platforms
*
* @throws: GlobalizationError.PARSING_ERROR
*/
private JSONObject getStringtoDate(JSONArray options) throws GlobalizationError {
JSONObject obj = new JSONObject();
Date date;
try {
//get format pattern from android device (Will only have device specific formatting for short form of date) or options supplied
DateFormat fmt = new SimpleDateFormat(getDatePattern(options).getString("pattern"));
//attempt parsing string based on user preferences
date = fmt.parse(options.getJSONObject(0).get(DATESTRING).toString());
//set Android Time object
Time time = new Time();
time.set(date.getTime());
//return properties;
obj.put("year", time.year);
obj.put("month", time.month);
obj.put("day", time.monthDay);
obj.put("hour", time.hour);
obj.put("minute", time.minute);
obj.put("second", time.second);
obj.put("millisecond", Long.valueOf(0));
return obj;
} catch (Exception ge) {
throw new GlobalizationError(GlobalizationError.PARSING_ERROR);
}
}
use of org.json.JSONObject in project jpHolo by teusink.
the class Share method execute.
@Override
public boolean execute(final String action, final JSONArray args, final CallbackContext callbackContext) {
cordova.getThreadPool().execute(new Runnable() {
@Override
public void run() {
try {
final JSONObject jo = args.getJSONObject(0);
doSendIntent(jo.getString("subject"), jo.getString("text"));
callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK));
} catch (final JSONException e) {
Log.e(LOG_PROV, LOG_NAME + "Error: " + PluginResult.Status.JSON_EXCEPTION);
e.printStackTrace();
callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.JSON_EXCEPTION));
}
}
});
return true;
}
use of org.json.JSONObject in project glitch-hq-android by tinyspeck.
the class EncyclopediaLocationStreetFragment method onRequestBack.
@Override
public void onRequestBack(String method, JSONObject response) {
if (method == "locations.getStreets") {
m_streetsList.clear();
JSONObject streets = response.optJSONObject("streets");
if (streets != null && streets.length() > 0) {
Iterator<String> it = streets.keys();
while (it.hasNext()) {
String key = it.next();
JSONObject jobj = streets.optJSONObject(key);
if (jobj != null) {
glitchLocationStreet s = new glitchLocationStreet();
s.tsid = key;
s.name = jobj.optString("name");
m_streetsList.add(s);
}
}
Collections.sort(m_streetsList, new SortByName());
}
if (m_streetsList.size() > 0) {
((TextView) m_root.findViewById(R.id.encyclopedia_location_streets_list_message)).setText("");
}
showEncyclopediaLocationStreetsPage();
}
onRequestComplete();
}
Aggregations