List of usage examples for org.json JSONException printStackTrace
public void printStackTrace()
From source file:net.idlesoft.android.apps.github.activities.SingleActivityItem.java
private void loadActivityItemBox() { final TextView date = (TextView) findViewById(R.id.tv_activity_item_date); final ImageView gravatar = (ImageView) findViewById(R.id.iv_activity_item_gravatar); final ImageView icon = (ImageView) findViewById(R.id.iv_activity_item_icon); final TextView title_tv = (TextView) findViewById(R.id.tv_activity_item_title); try {//from w w w . j a v a2s . co m final JSONObject entry = mJson; final JSONObject payload = entry.getJSONObject("payload"); String end; final SimpleDateFormat dateFormat = new SimpleDateFormat(Hubroid.GITHUB_ISSUES_TIME_FORMAT); final Date item_time = dateFormat.parse(entry.getString("created_at")); final Date current_time = dateFormat.parse(dateFormat.format(new Date())); final long ms = current_time.getTime() - item_time.getTime(); final long sec = ms / 1000; final long min = sec / 60; final long hour = min / 60; final long day = hour / 24; if (day > 0) { if (day == 1) { end = " day ago"; } else { end = " days ago"; } date.setText(day + end); } else if (hour > 0) { if (hour == 1) { end = " hour ago"; } else { end = " hours ago"; } date.setText(hour + end); } else if (min > 0) { if (min == 1) { end = " minute ago"; } else { end = " minutes ago"; } date.setText(min + end); } else { if (sec == 1) { end = " second ago"; } else { end = " seconds ago"; } date.setText(sec + end); } final String actor = entry.getString("actor"); final String eventType = entry.getString("type"); String title = actor + " did something..."; gravatar.setImageBitmap(GravatarCache.getDipGravatar(GravatarCache.getGravatarID(actor), 30.0f, getResources().getDisplayMetrics().density)); if (eventType.contains("PushEvent")) { icon.setImageResource(R.drawable.push); title = actor + " pushed to " + payload.getString("ref").split("/")[2] + " at " + entry.getJSONObject("repository").getString("owner") + "/" + entry.getJSONObject("repository").getString("name"); } else if (eventType.contains("WatchEvent")) { final String action = payload.getString("action"); if (action.equalsIgnoreCase("started")) { icon.setImageResource(R.drawable.watch_started); } else { icon.setImageResource(R.drawable.watch_stopped); } title = actor + " " + action + " watching " + entry.getJSONObject("repository").getString("owner") + "/" + entry.getJSONObject("repository").getString("name"); } else if (eventType.contains("GistEvent")) { final String action = payload.getString("action"); icon.setImageResource(R.drawable.gist); title = actor + " " + action + "d " + payload.getString("name"); } else if (eventType.contains("ForkEvent")) { icon.setImageResource(R.drawable.fork); title = actor + " forked " + entry.getJSONObject("repository").getString("name") + "/" + entry.getJSONObject("repository").getString("owner"); } else if (eventType.contains("CommitCommentEvent")) { icon.setImageResource(R.drawable.comment); title = actor + " commented on " + entry.getJSONObject("repository").getString("owner") + "/" + entry.getJSONObject("repository").getString("name"); } else if (eventType.contains("ForkApplyEvent")) { icon.setImageResource(R.drawable.merge); title = actor + " applied fork commits to " + entry.getJSONObject("repository").getString("owner") + "/" + entry.getJSONObject("repository").getString("name"); } else if (eventType.contains("FollowEvent")) { icon.setImageResource(R.drawable.follow); title = actor + " started following " + payload.getJSONObject("target").getString("login"); } else if (eventType.contains("CreateEvent")) { icon.setImageResource(R.drawable.create); if (payload.getString("object").contains("repository")) { title = actor + " created repository " + payload.getString("name"); } else if (payload.getString("object").contains("branch")) { title = actor + " created branch " + payload.getString("object_name") + " at " + entry.getJSONObject("repository").getString("owner") + "/" + entry.getJSONObject("repository").getString("name"); } else if (payload.getString("object").contains("tag")) { title = actor + " created tag " + payload.getString("object_name") + " at " + entry.getJSONObject("repository").getString("owner") + "/" + entry.getJSONObject("repository").getString("name"); } } else if (eventType.contains("IssuesEvent")) { if (payload.getString("action").equalsIgnoreCase("opened")) { icon.setImageResource(R.drawable.issues_open); } else { icon.setImageResource(R.drawable.issues_closed); } title = actor + " " + payload.getString("action") + " issue " + payload.getInt("number") + " on " + entry.getJSONObject("repository").getString("owner") + "/" + entry.getJSONObject("repository").getString("name"); } else if (eventType.contains("DeleteEvent")) { icon.setImageResource(R.drawable.delete); if (payload.getString("object").contains("repository")) { title = actor + " deleted repository " + payload.getString("name"); } else if (payload.getString("object").contains("branch")) { title = actor + " deleted branch " + payload.getString("object_name") + " at " + entry.getJSONObject("repository").getString("owner") + "/" + entry.getJSONObject("repository").getString("name"); } else if (payload.getString("object").contains("tag")) { title = actor + " deleted tag " + payload.getString("object_name") + " at " + entry.getJSONObject("repository").getString("owner") + "/" + entry.getJSONObject("repository").getString("name"); } } else if (eventType.contains("WikiEvent")) { icon.setImageResource(R.drawable.wiki); title = actor + " " + payload.getString("action") + " a page in the " + entry.getJSONObject("repository").getString("owner") + "/" + entry.getJSONObject("repository").getString("name") + " wiki"; } else if (eventType.contains("DownloadEvent")) { icon.setImageResource(R.drawable.download); title = actor + " uploaded a file to " + entry.getJSONObject("repository").getString("owner") + "/" + entry.getJSONObject("repository").getString("name"); } else if (eventType.contains("PublicEvent")) { icon.setImageResource(R.drawable.opensource); title = actor + " open sourced " + entry.getJSONObject("repository").getString("name"); } else if (eventType.contains("PullRequestEvent")) { final int number = (payload.get("pull_request") instanceof JSONObject) ? payload.getJSONObject("pull_request").getInt("number") : payload.getInt("number"); if (payload.getString("action").equalsIgnoreCase("opened")) { icon.setImageResource(R.drawable.issues_open); title = actor + " opened pull request " + number + " on " + entry.getJSONObject("repository").getString("owner") + "/" + entry.getJSONObject("repository").getString("name"); } else if (payload.getString("action").equalsIgnoreCase("closed")) { icon.setImageResource(R.drawable.issues_closed); title = actor + " closed pull request " + number + " on " + entry.getJSONObject("repository").getString("owner") + "/" + entry.getJSONObject("repository").getString("name"); } } else if (eventType.contains("MemberEvent")) { icon.setImageResource(R.drawable.follow); title = actor + " added " + payload.getString("member") + " to " + entry.getJSONObject("repository").getString("owner") + "/" + entry.getJSONObject("repository").getString("name"); } title_tv.setText(title); gravatar.setOnClickListener(new OnClickListener() { public void onClick(final View v) { final Intent i = new Intent(SingleActivityItem.this, Profile.class); i.putExtra("username", actor); startActivity(i); } }); } catch (final JSONException e) { e.printStackTrace(); } catch (final ParseException e) { e.printStackTrace(); } }
From source file:net.idlesoft.android.apps.github.activities.SingleActivityItem.java
@Override public void onCreate(final Bundle icicle) { super.onCreate(icicle); setContentView(R.layout.single_activity_item); mPrefs = getSharedPreferences(Hubroid.PREFS_NAME, 0); mEditor = mPrefs.edit();//w ww . ja v a2 s . c o m ((ImageButton) findViewById(R.id.btn_search)).setOnClickListener(new OnClickListener() { public void onClick(final View v) { startActivity(new Intent(SingleActivityItem.this, Search.class)); } }); final Bundle extras = getIntent().getExtras(); if (extras != null) { try { mJson = new JSONObject(extras.getString("item_json")); loadActivityItemBox(); final WebView content = (WebView) findViewById(R.id.wv_single_activity_item_content); content.setWebViewClient(new WebViewClient() { public boolean shouldOverrideUrlLoading(final WebView view, final String url) { if (url.startsWith("hubroid://")) { final String parts[] = url.substring(10).split("/"); if (parts[0].equals("showCommit")) { final Intent intent = new Intent(SingleActivityItem.this, Commit.class); intent.putExtra("repo_owner", parts[1]); intent.putExtra("repo_name", parts[2]); intent.putExtra("commit_sha", parts[3]); startActivity(intent); } else if (parts[0].equals("showRepo")) { final Intent intent = new Intent(SingleActivityItem.this, Repository.class); intent.putExtra("repo_owner", parts[1]); intent.putExtra("repo_name", parts[2]); startActivity(intent); } else if (parts[0].equals("showUser")) { final Intent intent = new Intent(SingleActivityItem.this, Profile.class); intent.putExtra("username", parts[1]); startActivity(intent); } else if (parts[0].equals("showIssues")) { final Intent intent = new Intent(SingleActivityItem.this, Issues.class); intent.putExtra("repo_owner", parts[1]); intent.putExtra("repo_name", parts[2]); startActivity(intent); } return true; } return false; } }); String html = ""; final String eventType = mJson.getString("type"); if (eventType.equals("PushEvent")) { html = NewsFeedHelpers.linkifyPushItem(mJson); } else if (eventType.equals("CreateEvent")) { final String object = mJson.getJSONObject("payload").getString("object"); if (object.equals("branch")) { html = NewsFeedHelpers.linkifyCreateBranchItem(mJson); } else if (object.equals("repository")) { html = NewsFeedHelpers.linkifyCreateRepoItem(mJson); } } else if (eventType.equals("CommitCommentEvent")) { html = NewsFeedHelpers.linkifyCommitCommentItem(mJson); } else if (eventType.equals("FollowEvent")) { html = NewsFeedHelpers.linkifyFollowItem(mJson); } else if (eventType.equals("ForkEvent")) { html = NewsFeedHelpers.linkifyForkItem(mJson); } else if (eventType.equals("IssuesEvent")) { html = NewsFeedHelpers.linkifyIssueItem(mJson); } else if (eventType.equals("WatchEvent")) { html = NewsFeedHelpers.linkifyWatchItem(mJson); } final String out = CSS + html; content.loadData(out, "text/html", "UTF-8"); } catch (final JSONException e) { e.printStackTrace(); } } }
From source file:io.winch.phonegap.plugin.WinchPlugin.java
private void sync(JSONArray args) { try {/*from www .j av a 2 s . co m*/ List<SyncElement> syncElements = new ArrayList<SyncElement>(); JSONObject params = args.getJSONObject(0); Iterator<?> iter = params.keys(); // iterate to retrieve sync pairs while (iter.hasNext()) { String namespace = (String) iter.next(); String syncOption = params.getString(namespace); SyncElement se = new SyncElement(namespace, syncOption); syncElements.add(se); } mWinch.sync(this, syncElements); } catch (JSONException e1) { e1.printStackTrace(); } catch (WinchError e) { e.printStackTrace(); PluginResult r = buildErrorResult(e.getErrorCode(), e.getMessage()); this.syncCallback.sendPluginResult(r); } }
From source file:io.winch.phonegap.plugin.WinchPlugin.java
private void load(JSONArray args) { try {/* w w w . jav a2 s. co m*/ List<LoadElement> loadElements = new ArrayList<LoadElement>(); JSONObject params = args.getJSONObject(0); Iterator<?> iter = params.keys(); // iterate to retrieve load pairs while (iter.hasNext()) { String namespace = (String) iter.next(); String key = params.getString(namespace); LoadElement le = new LoadElement(namespace, key); loadElements.add(le); } mWinch.load(this, loadElements); } catch (JSONException e) { e.printStackTrace(); } catch (WinchError e) { e.printStackTrace(); PluginResult r = buildErrorResult(e.getErrorCode(), e.getMessage()); this.loadCallback.sendPluginResult(r); } }
From source file:io.winch.phonegap.plugin.WinchPlugin.java
private void count(CallbackContext callbackContext, JSONArray args) { try {/*from w w w . j a v a 2 s.co m*/ String namespace = args.getString(0); int count = mWinch.getNamespace(namespace).count(); PluginResult r = new PluginResult(PluginResult.Status.OK, count); callbackContext.sendPluginResult(r); } catch (JSONException e) { e.printStackTrace(); } catch (WinchError e) { e.printStackTrace(); PluginResult r = buildErrorResult(e.getErrorCode(), e.getMessage()); callbackContext.sendPluginResult(r); } }
From source file:io.winch.phonegap.plugin.WinchPlugin.java
private void get(CallbackContext callbackContext, JSONArray args) { try {// ww w .j a va 2s . co m String namespace = args.getString(0); String key = args.getString(1); byte[] value = mWinch.getNamespace(namespace).get(key); PluginResult pr = new PluginResult(PluginResult.Status.OK, value, true); callbackContext.sendPluginResult(pr); } catch (WinchError e) { e.printStackTrace(); PluginResult r = buildErrorResult(e.getErrorCode(), e.getMessage()); callbackContext.sendPluginResult(r); } catch (JSONException e1) { e1.printStackTrace(); } }
From source file:io.winch.phonegap.plugin.WinchPlugin.java
private void getString(CallbackContext callbackContext, JSONArray args) { try {//from www .j a va 2 s . co m String namespace = args.getString(0); String key = args.getString(1); String value = mWinch.getNamespace(namespace).getString(key); PluginResult pr = new PluginResult(PluginResult.Status.OK, value); callbackContext.sendPluginResult(pr); } catch (WinchError e) { e.printStackTrace(); PluginResult r = buildErrorResult(e.getErrorCode(), e.getMessage()); callbackContext.sendPluginResult(r); } catch (JSONException e1) { e1.printStackTrace(); } }
From source file:io.winch.phonegap.plugin.WinchPlugin.java
private void getBase64(CallbackContext callbackContext, JSONArray args) { try {/*from w w w. j a v a 2 s .c o m*/ String namespace = args.getString(0); String key = args.getString(1); byte[] value = mWinch.getNamespace(namespace).get(key); String base64 = Base64.encodeToString(value, Base64.NO_WRAP); PluginResult pr = new PluginResult(PluginResult.Status.OK, base64); callbackContext.sendPluginResult(pr); } catch (WinchError e) { e.printStackTrace(); PluginResult r = buildErrorResult(e.getErrorCode(), e.getMessage()); callbackContext.sendPluginResult(r); } catch (JSONException e1) { e1.printStackTrace(); } }
From source file:io.winch.phonegap.plugin.WinchPlugin.java
private void put(CallbackContext callbackContext, CordovaArgs args) { try {/*from w ww . j a v a 2 s . c om*/ String namespace = args.getString(0); String key = args.getString(1); byte[] data = args.getArrayBuffer(2); mWinch.getNamespace(namespace).put(key, data); callbackContext.success(); } catch (JSONException e) { e.printStackTrace(); } catch (WinchError e) { e.printStackTrace(); PluginResult r = buildErrorResult(e.getErrorCode(), e.getMessage()); callbackContext.sendPluginResult(r); } }
From source file:io.winch.phonegap.plugin.WinchPlugin.java
private void iterateAsString(final CallbackContext callbackContext, JSONArray args) { try {//from w ww . j a v a2 s. co m String namespace = args.getString(0); Enumerator it1 = new Enumerator() { public int next() { JSONObject obj = new JSONObject(); try { obj.put(KEY, key); obj.put(DATA, new String(data)); } catch (JSONException e) { e.printStackTrace(); } PluginResult r = new PluginResult(PluginResult.Status.OK, obj); r.setKeepCallback(true); callbackContext.sendPluginResult(r); return Enumerator.Code.NONE; } }; mWinch.getNamespace(namespace).enumerate(it1); } catch (JSONException e1) { e1.printStackTrace(); } catch (WinchError e) { e.log(); PluginResult r = buildErrorResult(e.getErrorCode(), e.getMessage()); callbackContext.sendPluginResult(r); } PluginResult r = new PluginResult(PluginResult.Status.OK, false); r.setKeepCallback(false); callbackContext.sendPluginResult(r); }