use of org.json.JSONObject in project cordova-android-chromeview by thedracle.
the class CompassListener method getCompassHeading.
/**
* Create the CompassHeading JSON object to be returned to JavaScript
*
* @return a compass heading
*/
private JSONObject getCompassHeading() throws JSONException {
JSONObject obj = new JSONObject();
obj.put("magneticHeading", this.getHeading());
obj.put("trueHeading", this.getHeading());
// Since the magnetic and true heading are always the same our and accuracy
// is defined as the difference between true and magnetic always return zero
obj.put("headingAccuracy", 0);
obj.put("timestamp", this.timeStamp);
return obj;
}
use of org.json.JSONObject in project glitch-hq-android by tinyspeck.
the class MailboxFragment method addMailboxList.
private void addMailboxList(JSONObject response) {
JSONObject inbox = response.optJSONObject("inbox");
if (inbox != null) {
messageCount = inbox.optInt("message_count");
unreadCount = inbox.optInt("unread_count");
m_mailboxUnread.setText(String.valueOf(unreadCount));
m_mailboxUnread.setVisibility(unreadCount > 0 ? View.VISIBLE : View.GONE);
m_application.setMailUnreadCount(unreadCount);
currentPage = inbox.optInt("page");
JSONArray messages = inbox.optJSONArray("messages");
if (messages != null) {
for (int i = 0; i < messages.length(); i++) {
JSONObject message = messages.optJSONObject(i);
glitchMail mail = new glitchMail();
mail.id = message.optInt("message_id");
mail.currants = message.optInt("currants");
mail.text = message.optString("text");
if (mail.text.equalsIgnoreCase("null")) {
mail.text = "";
}
mail.received = message.optLong("received");
mail.replied = message.optInt("replied") == 1;
mail.is_expedited = message.optBoolean("is_expedited");
mail.is_read = message.optBoolean("is_read");
JSONObject sender = message.optJSONObject("sender");
if (sender != null) {
mail.sender_tsid = sender.optString("tsid");
mail.sender_label = sender.optString("label");
mail.sender_avatar = sender.optString("singles_url");
}
JSONObject item = message.optJSONObject("item");
if (item != null) {
mail.item = new glitchMailItem();
mail.item.tsid = item.optString("class_tsid");
mail.item.name = item.optString("name");
mail.item.count = item.optInt("count");
mail.item.desc = item.optString("desc");
mail.item.icon = item.optString("icon");
}
m_mailList.add(mail);
}
}
}
}
use of org.json.JSONObject in project glitch-hq-android by tinyspeck.
the class EncyclopediaSearchTextWatcher method onRequestBack.
private void onRequestBack(String method, JSONObject response) {
if (method == "encyclopedia.search") {
JSONObject jResults = response.optJSONObject("matches");
if (jResults != null && jResults.length() > 0) {
Iterator<String> types = jResults.keys();
while (types.hasNext()) {
String type = types.next();
if (!type.equalsIgnoreCase("Furniture") && !type.equalsIgnoreCase("Upgrade")) {
JSONArray typedResults = jResults.optJSONArray(type);
for (int i = 0; i < typedResults.length(); i++) {
JSONObject jResult = typedResults.optJSONObject(i);
if (jResult != null) {
searchResult result = m_bf.new searchResult();
result.type = type;
result.name = jResult.optString("name");
result.icon = jResult.optString("icon");
result.url = jResult.optString("url");
result.id = jResult.optString("class_tsid");
m_searchResultsList.add(result);
}
}
}
}
}
m_root.findViewById(R.id.encyclopedia_search_results_list_message).setVisibility(View.GONE);
((EncyclopediaSearchListViewAdapter) m_searchResultsListView.adapter).notifyDataSetChanged();
}
}
use of org.json.JSONObject in project glitch-hq-android by tinyspeck.
the class EncyclopediaSkillCategoriesFragment method onRequestBack.
@Override
public void onRequestBack(String method, JSONObject response) {
if (method == "skills.listAllCategories") {
JSONObject categories = response.optJSONObject("categories");
if (categories.length() > 0) {
m_categoriesList.clear();
Iterator<String> itr = categories.keys();
while (itr.hasNext()) {
String key = itr.next();
String category = categories.optString(key);
m_categoriesList.add(category);
}
Collections.sort(m_categoriesList);
}
if (m_categoriesList.size() == 0) {
((TextView) m_root.findViewById(R.id.encyclopedia_skill_categories_list_message)).setText("");
}
showEncyclopediaSkillCategoriesPage();
}
onRequestComplete();
}
use of org.json.JSONObject in project glitch-hq-android by tinyspeck.
the class EncyclopediaSkillsInCategoryFragment method onRequestBack.
@Override
public void onRequestBack(String method, JSONObject response) {
if (method == "skills.listAllInCategory") {
m_skillsList.clear();
JSONObject jSkills = response.optJSONObject("skills");
if (jSkills != null && jSkills.length() > 0) {
Iterator<String> it = jSkills.keys();
while (it.hasNext()) {
String key = it.next();
JSONObject jobj = jSkills.optJSONObject(key);
skillAvailable skill = new skillAvailable();
skill.id = jobj.optString("class_tsid");
skill.item = jobj.optString("name");
skill.icon = jobj.optString("icon_44");
skill.can_learn = (response.optInt("can_learn") == 1) ? true : false;
skill.got = (response.optInt("got") == 1) ? true : false;
skill.paused = (response.optInt("paused") == 1) ? true : false;
m_skillsList.add(skill);
}
Collections.sort(m_skillsList, new SortByName());
}
if (m_skillsList.size() > 0) {
((TextView) m_root.findViewById(R.id.encyclopedia_skills_in_category_list_message)).setText("");
}
showSkillsInCategoryPage();
}
onRequestComplete();
}
Aggregations