Search in sources :

Example 71 with JSONObject

use of org.json.JSONObject in project baker-android by bakerframework.

the class BasicResult method errorJson.

public JSONObject errorJson(final String value) throws JSONException {
    JSONObject json = new JSONObject();
    json.put("type", "error");
    json.put("value", value);
    return json;
}
Also used : JSONObject(org.json.JSONObject)

Example 72 with JSONObject

use of org.json.JSONObject in project baker-android by bakerframework.

the class BasicResult method toJson.

public JSONObject toJson() throws JSONException {
    JSONObject json = new JSONObject();
    json.put("type", this.type);
    json.put("value", this.value);
    return json;
}
Also used : JSONObject(org.json.JSONObject)

Example 73 with JSONObject

use of org.json.JSONObject in project baker-android by bakerframework.

the class BookJson method fromJson.

public void fromJson(final String jsonString) throws JSONException, ParseException {
    JSONObject json = new JSONObject(jsonString);
    if (json.has("liveUrl")) {
        this.liveUrl = json.getString("liveUrl");
    }
    //		SimpleDateFormat sdfInput = new SimpleDateFormat("yyyy-MM-dd",
    //				Locale.US);
    // The other properties are commented by now, as we are not gonna use them yet.
    this.hpub = json.optString("hpub", "1");
    this.title = json.optString("title", "");
    //		this.date = sdfInput.parse(json.getString("date"));
    this.url = json.optString("url", "");
    this.cover = json.optString("cover", "");
    this.orientation = json.optString("orientation", "PORTRAIT");
    //		this.zoomable = json.getBoolean("zoomable");
    //		JSONArray authors = new JSONArray(json.getString("author"));
    //		JSONArray creators = new JSONArray(json.getString("creator"));
    JSONArray contents = new JSONArray(json.getString("contents"));
    //		this.authors = new ArrayList<String>();
    //		this.creators = new ArrayList<String>();
    this.contents = new ArrayList<String>();
    for (int i = 0; i < contents.length(); i++) {
        this.contents.add(contents.getString(i));
    }
}
Also used : JSONObject(org.json.JSONObject) JSONArray(org.json.JSONArray)

Example 74 with JSONObject

use of org.json.JSONObject in project cordova-android-chromeview by thedracle.

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 = new File(FileHelper.getRealPath(data, this.cordova));
    JSONObject obj = new JSONObject();
    try {
        // File properties
        obj.put("name", fp.getName());
        obj.put("fullPath", "file://" + fp.getAbsolutePath());
        // 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(fp.getAbsolutePath(), cordova));
        }
        obj.put("lastModifiedDate", fp.lastModified());
        obj.put("size", fp.length());
    } catch (JSONException e) {
        // this will never happen
        e.printStackTrace();
    }
    return obj;
}
Also used : JSONObject(org.json.JSONObject) JSONException(org.json.JSONException) File(java.io.File)

Example 75 with JSONObject

use of org.json.JSONObject in project cordova-android-chromeview by thedracle.

the class Capture method getFormatData.

/**
     * Provides the media data file data depending on it's mime type
     *
     * @param filePath path to the file
     * @param mimeType of the file
     * @return a MediaFileData object
     */
private JSONObject getFormatData(String filePath, String mimeType) throws JSONException {
    JSONObject obj = new JSONObject();
    // setup defaults
    obj.put("height", 0);
    obj.put("width", 0);
    obj.put("bitrate", 0);
    obj.put("duration", 0);
    obj.put("codecs", "");
    // so let's see if we can determine it.
    if (mimeType == null || mimeType.equals("") || "null".equals(mimeType)) {
        mimeType = FileHelper.getMimeType(filePath, cordova);
    }
    Log.d(LOG_TAG, "Mime type = " + mimeType);
    if (mimeType.equals(IMAGE_JPEG) || filePath.endsWith(".jpg")) {
        obj = getImageData(filePath, obj);
    } else if (mimeType.endsWith(AUDIO_3GPP)) {
        obj = getAudioVideoData(filePath, obj, false);
    } else if (mimeType.equals(VIDEO_3GPP) || mimeType.equals(VIDEO_MP4)) {
        obj = getAudioVideoData(filePath, obj, true);
    }
    return obj;
}
Also used : JSONObject(org.json.JSONObject)

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