Search in sources :

Example 91 with JSONObject

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;
}
Also used : FileUtils(org.apache.cordova.file.FileUtils) JSONException(org.json.JSONException) Method(java.lang.reflect.Method) InvocationTargetException(java.lang.reflect.InvocationTargetException) PluginManager(org.apache.cordova.PluginManager) Field(java.lang.reflect.Field) JSONObject(org.json.JSONObject) File(java.io.File) LocalFilesystemURL(org.apache.cordova.file.LocalFilesystemURL)

Example 92 with JSONObject

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;
}
Also used : JSONObject(org.json.JSONObject) JSONException(org.json.JSONException)

Example 93 with JSONObject

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);
    }
}
Also used : JSONObject(org.json.JSONObject) SimpleDateFormat(java.text.SimpleDateFormat) DateFormat(java.text.DateFormat) Time(android.text.format.Time) SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date) JSONException(org.json.JSONException)

Example 94 with JSONObject

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;
}
Also used : JSONObject(org.json.JSONObject) PluginResult(org.apache.cordova.PluginResult) JSONException(org.json.JSONException)

Example 95 with JSONObject

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();
}
Also used : JSONObject(org.json.JSONObject) TextView(android.widget.TextView)

Aggregations

JSONObject (org.json.JSONObject)4075 JSONException (org.json.JSONException)1601 JSONArray (org.json.JSONArray)1156 Test (org.junit.Test)526 IOException (java.io.IOException)456 ArrayList (java.util.ArrayList)402 HashMap (java.util.HashMap)290 Test (org.testng.annotations.Test)175 File (java.io.File)145 Date (java.util.Date)144 ServiceException (org.b3log.latke.service.ServiceException)125 Bundle (android.os.Bundle)109 VolleyError (com.android.volley.VolleyError)104 Map (java.util.Map)96 BufferedReader (java.io.BufferedReader)93 RequestProcessing (org.b3log.latke.servlet.annotation.RequestProcessing)92 InputStreamReader (java.io.InputStreamReader)90 List (java.util.List)85 Response (com.android.volley.Response)84 InputStream (java.io.InputStream)73