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;
}
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);
}
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);
}
}
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);
}
}
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;
}
Aggregations