Search in sources :

Example 61 with JSONArray

use of org.json.JSONArray in project androidquery by androidquery.

the class AbstractAjaxCallback method transform.

@SuppressWarnings("unchecked")
protected T transform(String url, byte[] data, AjaxStatus status) {
    if (type == null) {
        return null;
    }
    File file = status.getFile();
    if (data != null) {
        if (type.equals(Bitmap.class)) {
            return (T) BitmapFactory.decodeByteArray(data, 0, data.length);
        }
        if (type.equals(JSONObject.class)) {
            JSONObject result = null;
            String str = null;
            try {
                str = new String(data, encoding);
                result = (JSONObject) new JSONTokener(str).nextValue();
            } catch (Exception e) {
                AQUtility.debug(e);
                AQUtility.debug(str);
            }
            return (T) result;
        }
        if (type.equals(JSONArray.class)) {
            JSONArray result = null;
            try {
                String str = new String(data, encoding);
                result = (JSONArray) new JSONTokener(str).nextValue();
            } catch (Exception e) {
                AQUtility.debug(e);
            }
            return (T) result;
        }
        if (type.equals(String.class)) {
            String result = null;
            if (status.getSource() == AjaxStatus.NETWORK) {
                AQUtility.debug("network");
                result = correctEncoding(data, encoding, status);
            } else {
                AQUtility.debug("file");
                try {
                    result = new String(data, encoding);
                } catch (Exception e) {
                    AQUtility.debug(e);
                }
            }
            return (T) result;
        }
        if (type.equals(byte[].class)) {
            return (T) data;
        }
        if (transformer != null) {
            return transformer.transform(url, type, encoding, data, status);
        }
        if (st != null) {
            return st.transform(url, type, encoding, data, status);
        }
    } else if (file != null) {
        if (type.equals(File.class)) {
            return (T) file;
        }
        if (type.equals(XmlDom.class)) {
            XmlDom result = null;
            try {
                FileInputStream fis = new FileInputStream(file);
                result = new XmlDom(fis);
                status.closeLater(fis);
            } catch (Exception e) {
                AQUtility.report(e);
                return null;
            }
            return (T) result;
        }
        if (type.equals(XmlPullParser.class)) {
            XmlPullParser parser = Xml.newPullParser();
            try {
                FileInputStream fis = new FileInputStream(file);
                parser.setInput(fis, encoding);
                status.closeLater(fis);
            } catch (Exception e) {
                AQUtility.report(e);
                return null;
            }
            return (T) parser;
        }
        if (type.equals(InputStream.class)) {
            try {
                FileInputStream fis = new FileInputStream(file);
                status.closeLater(fis);
                return (T) fis;
            } catch (Exception e) {
                AQUtility.report(e);
                return null;
            }
        }
    }
    return null;
}
Also used : JSONTokener(org.json.JSONTokener) JSONObject(org.json.JSONObject) GZIPInputStream(java.util.zip.GZIPInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) XmlDom(com.androidquery.util.XmlDom) JSONArray(org.json.JSONArray) XmlPullParser(org.xmlpull.v1.XmlPullParser) File(java.io.File) HttpHostConnectException(org.apache.http.conn.HttpHostConnectException) ClientProtocolException(org.apache.http.client.ClientProtocolException) IOException(java.io.IOException) FileInputStream(java.io.FileInputStream)

Example 62 with JSONArray

use of org.json.JSONArray in project androidquery by androidquery.

the class ImageLoadingList3Activity method renderNews.

public void renderNews(String url, JSONObject json, AjaxStatus status) {
    if (json == null)
        return;
    JSONArray ja = json.optJSONObject("responseData").optJSONArray("results");
    if (ja == null)
        return;
    List<JSONObject> items = new ArrayList<JSONObject>();
    for (int i = 0; i < 10; i++) {
        addItems(ja, items);
    }
    listAq = new AQuery(this);
    ArrayAdapter<JSONObject> aa = new ArrayAdapter<JSONObject>(this, R.layout.content_item_s, items) {

        @Override
        public View getView(int position, View convertView, ViewGroup parent) {
            ViewHolder holder;
            if (convertView == null) {
                holder = new ViewHolder();
                convertView = getLayoutInflater().inflate(R.layout.content_item_s, parent, false);
                holder.imageview = (ImageView) convertView.findViewById(R.id.tb);
                holder.progress = (ProgressBar) convertView.findViewById(R.id.progress);
                holder.name = (TextView) convertView.findViewById(R.id.name);
                holder.meta = (TextView) convertView.findViewById(R.id.meta);
                convertView.setTag(holder);
            } else {
                holder = (ViewHolder) convertView.getTag();
            }
            JSONObject jo = getItem(position);
            String tb = jo.optJSONObject("image").optString("tbUrl");
            AQuery aq = listAq.recycle(convertView);
            aq.id(holder.name).text(jo.optString("titleNoFormatting", "No Title"));
            aq.id(holder.meta).text(jo.optString("publisher", ""));
            aq.id(holder.imageview).progress(holder.progress).image(tb, true, true, 0, 0, null, 0, 1.0f);
            return convertView;
        }
    };
    aq.id(R.id.list).adapter(aa);
}
Also used : AQuery(com.androidquery.AQuery) JSONObject(org.json.JSONObject) ViewGroup(android.view.ViewGroup) JSONArray(org.json.JSONArray) ArrayList(java.util.ArrayList) ImageView(android.widget.ImageView) TextView(android.widget.TextView) View(android.view.View) ArrayAdapter(android.widget.ArrayAdapter)

Example 63 with JSONArray

use of org.json.JSONArray in project androidquery by androidquery.

the class AjaxAuthActivity method picasaCb.

public void picasaCb(String url, JSONObject jo, AjaxStatus status) {
    showResult(jo);
    if (jo != null) {
        JSONArray entries = jo.optJSONObject("feed").optJSONArray("entry");
        AQUtility.debug(entries.toString());
        for (int i = 0; i < entries.length(); i++) {
            JSONObject entry = entries.optJSONObject(i);
            JSONObject co = entry.optJSONObject("gphoto$numphotos");
            int count = co.optInt("$t", 0);
            if (count > 0) {
                String tb = entry.optJSONObject("media$group").optJSONArray("media$content").optJSONObject(0).optString("url");
                AQUtility.debug("tb", tb);
                aq.id(R.id.image).image(tb);
                break;
            }
        }
    } else {
        showError(status);
    }
}
Also used : JSONObject(org.json.JSONObject) JSONArray(org.json.JSONArray)

Example 64 with JSONArray

use of org.json.JSONArray in project androidquery by androidquery.

the class AjaxAuthActivity method youtubeCb.

public void youtubeCb(String url, JSONObject jo, AjaxStatus status) {
    if (jo != null) {
        JSONArray entries = jo.optJSONObject("feed").optJSONArray("entry");
        //if(entries.length() > 0){	
        //String src = entries.optJSONObject(0).optJSONObject("content").optString("src");			
        //auth_youtube2(src + "&alt=json");
        //}else{
        showResult(jo);
    //}
    } else {
        showError(status);
    }
}
Also used : JSONArray(org.json.JSONArray)

Example 65 with JSONArray

use of org.json.JSONArray in project platform_frameworks_base by android.

the class RankingHelper method dumpJson.

public JSONObject dumpJson(NotificationManagerService.DumpFilter filter) {
    JSONObject ranking = new JSONObject();
    JSONArray records = new JSONArray();
    try {
        ranking.put("noUid", mRestoredWithoutUids.size());
    } catch (JSONException e) {
    // pass
    }
    final int N = mRecords.size();
    for (int i = 0; i < N; i++) {
        final Record r = mRecords.valueAt(i);
        if (filter == null || filter.matches(r.pkg)) {
            JSONObject record = new JSONObject();
            try {
                record.put("userId", UserHandle.getUserId(r.uid));
                record.put("packageName", r.pkg);
                if (r.importance != DEFAULT_IMPORTANCE) {
                    record.put("importance", Ranking.importanceToString(r.importance));
                }
                if (r.priority != DEFAULT_PRIORITY) {
                    record.put("priority", Notification.priorityToString(r.priority));
                }
                if (r.visibility != DEFAULT_VISIBILITY) {
                    record.put("visibility", Notification.visibilityToString(r.visibility));
                }
            } catch (JSONException e) {
            // pass
            }
            records.put(record);
        }
    }
    try {
        ranking.put("records", records);
    } catch (JSONException e) {
    // pass
    }
    return ranking;
}
Also used : JSONObject(org.json.JSONObject) JSONArray(org.json.JSONArray) JSONException(org.json.JSONException)

Aggregations

JSONArray (org.json.JSONArray)1710 JSONObject (org.json.JSONObject)1191 JSONException (org.json.JSONException)738 ArrayList (java.util.ArrayList)323 IOException (java.io.IOException)243 Test (org.junit.Test)207 HashMap (java.util.HashMap)108 ClientException (edu.umass.cs.gnscommon.exceptions.client.ClientException)96 List (java.util.List)63 DefaultGNSTest (edu.umass.cs.gnsserver.utils.DefaultGNSTest)61 File (java.io.File)54 HashSet (java.util.HashSet)54 Date (java.util.Date)47 Query (org.b3log.latke.repository.Query)47 RandomString (edu.umass.cs.gnscommon.utils.RandomString)44 GraphObject (com.abewy.android.apps.klyph.core.graph.GraphObject)43 FileNotFoundException (java.io.FileNotFoundException)40 Map (java.util.Map)40 GuidEntry (edu.umass.cs.gnsclient.client.util.GuidEntry)36 VolleyError (com.android.volley.VolleyError)35