List of usage examples for org.json JSONException toString
public String toString()
From source file:com.krayzk9s.imgurholo.ui.SingleImageFragment.java
void getComments() { if (!((ImgurHoloActivity) getActivity()).getApiCall().settings.getBoolean("ShowComments", true)) return;/*from ww w .j a v a 2 s .com*/ try { Fetcher fetcher = new Fetcher(this, "3/gallery/image/" + imageData.getJSONObject().getString("id") + "/comments", ApiCall.GET, null, ((ImgurHoloActivity) getActivity()).getApiCall(), COMMENTS); fetcher.execute(); } catch (JSONException e) { Log.e("Error!", e.toString()); } }
From source file:com.krayzk9s.imgurholo.ui.SingleImageFragment.java
private void addComments() { try {//from ww w . j a v a2 s . co m if (getActivity() == null) return; JSONArray commentJSONArray = commentData.getJSONObject().getJSONArray("data"); if (commentJSONArray.length() > 0) { imageUpvote.setVisibility(View.VISIBLE); imageDownvote.setVisibility(View.VISIBLE); imageComment.setVisibility(View.VISIBLE); } commentArray = new ArrayList<JSONParcelable>(); Log.d("calling indent function", commentJSONArray.toString()); ArrayList<JSONObject> childrenArray = new ArrayList<JSONObject>(); for (int i = 0; i < commentJSONArray.length(); i++) { childrenArray.add(commentJSONArray.getJSONObject(i)); } if (sort.equals("New")) Collections.sort(childrenArray, new JSONNewestComparator()); else if (sort.equals("Top")) Collections.sort(childrenArray, new JSONTopComparator()); for (JSONObject aChildrenArray : childrenArray) { getIndents(aChildrenArray, 0); } commentAdapter.addAll(commentArray); } catch (JSONException e) { Log.e("Error1!", e.toString()); } }
From source file:com.krayzk9s.imgurholo.ui.SingleImageFragment.java
private void getIndents(JSONObject comment, int currentIndent) { JSONArray children;//from w w w . j a v a2 s . c o m try { comment.put("indent", currentIndent); ArrayList<JSONObject> childrenArray = null; if (comment.has("children")) { children = comment.getJSONArray("children"); childrenArray = new ArrayList<JSONObject>(); for (int i = 0; i < children.length(); i++) childrenArray.add(children.getJSONObject(i)); if (sort.equals(getString(R.string.newComment))) Collections.sort(childrenArray, new JSONNewestComparator()); else if (sort.equals(getString(R.string.topComment))) Collections.sort(childrenArray, new JSONTopComparator()); comment.remove("children"); } JSONParcelable commentParse = new JSONParcelable(); commentParse.setJSONObject(comment); commentArray.add(commentParse); if (childrenArray != null) { for (JSONObject child : childrenArray) { getIndents(child, currentIndent + 1); } } } catch (JSONException e) { Log.e("Error5!", e.toString()); } }
From source file:com.krayzk9s.imgurholo.ui.SingleImageFragment.java
private void setDescendantsHidden(View view) { LinearLayout convertView = (LinearLayout) view; ViewHolder holder = (ViewHolder) convertView.getTag(); int position = holder.position; JSONObject viewData = commentAdapter.getItem(position).getJSONObject(); try {//from w w w .jav a 2 s. c om if (!viewData.has("hidden")) viewData.put("hidden", ViewHolder.VIEW_VISIBLE); boolean hiding; int indentLevel = viewData.getInt("indent"); if (viewData.getInt("hidden") != ViewHolder.VIEW_HIDDEN) { viewData.put("hidden", ViewHolder.VIEW_HIDDEN); hiding = true; } else { viewData.put("hidden", ViewHolder.VIEW_VISIBLE); hiding = false; } for (int i = position + 1; i < commentAdapter.getCount(); i++) { JSONObject childViewData = commentAdapter.getItem(i).getJSONObject(); if (childViewData.getInt("indent") > indentLevel) { if (hiding) { childViewData.put("hidden", ViewHolder.VIEW_DESCENDANT); commentAdapter.addHiddenItem(i); } else { childViewData.put("hidden", ViewHolder.VIEW_VISIBLE); commentAdapter.removeHiddenItem(i); } } else break; } } catch (JSONException e) { Log.e("Converting to Hidden Error!", e.toString()); } commentAdapter.notifyDataSetChanged(); }
From source file:org.godotengine.godot.AdMob.java
public void createRewardedVideo() { mrv = MobileAds.getRewardedVideoAdInstance(activity); mrv.setRewardedVideoAdListener(new RewardedVideoAdListener() { @Override/* w w w . j a v a 2s . c o m*/ public void onRewardedVideoAdLoaded() { Utils.d("AdMob:Video:Loaded"); emitRewardedVideoStatus(); } @Override public void onRewarded(RewardItem rewardItem) { Utils.d("AdMob:Rewarded"); //rewardItem.getType() //rewardItem.getAmount() JSONObject ret = new JSONObject(); try { ret.put("RewardType", rewardItem.getType()); ret.put("RewardAmount", rewardItem.getAmount()); } catch (JSONException e) { Utils.d("AdMob:Reward:Error:" + e.toString()); } Utils.callScriptFunc("AdMobReward", ret.toString()); } @Override public void onRewardedVideoAdFailedToLoad(int errorCode) { Utils.d("AdMob:VideoLoad:Failed"); Utils.callScriptFunc("AdMob_Video", "load_failed"); } @Override public void onRewardedVideoAdClosed() { Utils.d("AdMob:VideoAd:Closed"); } @Override public void onRewardedVideoAdLeftApplication() { Utils.d("AdMob:VideoAd:LeftApp"); } @Override public void onRewardedVideoAdOpened() { Utils.d("AdMon:VideoAd:Opended"); } @Override public void onRewardedVideoStarted() { Utils.d("Reward:VideoAd:Started"); } }); requestNewRewardedVideo(); }
From source file:com.intellisol.plugin.Ringer.java
@Override public boolean execute(String action, JSONArray args, CallbackContext callbackContext) throws JSONException { if (NATIVE_ACTION_STRING.equals(action)) { int mode; try {/* ww w. j a v a 2 s. c om*/ // get mode from argument mode = args.getInt(0); // get context (Android) Context ctxt = cordova.getActivity().getBaseContext(); if (mode == NORMAL) { // set ringer mode AudioManager audioManager = (AudioManager) ctxt.getSystemService(Context.AUDIO_SERVICE); audioManager.setRingerMode(AudioManager.RINGER_MODE_NORMAL); } else if (mode == VIBRATE) { AudioManager audioManager = (AudioManager) ctxt.getSystemService(Context.AUDIO_SERVICE); audioManager.setRingerMode(AudioManager.RINGER_MODE_VIBRATE); } else if (mode == SILENT) { AudioManager audioManager = (AudioManager) ctxt.getSystemService(Context.AUDIO_SERVICE); audioManager.setRingerMode(AudioManager.RINGER_MODE_SILENT); } } catch (JSONException e) { // log error Log.d("Ringer", e.toString()); return false; } catch (Exception e) { // log error Log.d("Ringer", e.toString()); return false; } } return true; }
From source file:pl.poznan.put.cs.ify.api.group.YCommData.java
public String toJson() { try {//from ww w. j a v a2 s. c om return toJsonObject().toString(); } catch (JSONException e) { YLog.w("YCommData", e.toString()); return "{}"; } }
From source file:com.dragondevs.pubnubexample.DrawingActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); Intent intent = getIntent();// w w w. j ava2 s. co m channelName = intent.getStringExtra("CHANNEL"); //Create Handler to update screen from PubnubClient mHandler = new Handler(Looper.getMainLooper()) { @Override public void handleMessage(Message inputMessage) { if (inputMessage.obj instanceof JSONObject) { JSONObject json = (JSONObject) inputMessage.obj; int x = -1; int y = -1; int state = -1; try { x = json.getInt("X"); y = json.getInt("Y"); state = json.getInt("STATE"); } catch (JSONException e) { Log.d(TAG, "Error: " + e.toString()); } Log.d(TAG, "Drawing coord at x, y, state: " + x + " " + y + " " + state); if (x >= 0 && y >= 0 && state >= 0) myView.drawLine(x, y, state); else Log.d(TAG, "Json values read was not valid"); } } }; myView = new MyView(this, mHandler); setContentView(myView); mPaint = new Paint(); mPaint.setAntiAlias(true); mPaint.setDither(true); mPaint.setColor(0xFFFF0000); mPaint.setStyle(Paint.Style.STROKE); mPaint.setStrokeJoin(Paint.Join.ROUND); mPaint.setStrokeCap(Paint.Cap.ROUND); mPaint.setStrokeWidth(12); }
From source file:com.projectgoth.mywebrtcdemo.ConnectActivity.java
@Override public void onResume() { super.onResume(); String room = sharedPref.getString(keyprefRoom, ""); roomEditText.setText(room);// www.ja v a 2 s .co m roomList = new ArrayList<String>(); String roomListJson = sharedPref.getString(keyprefRoomList, null); if (roomListJson != null) { try { JSONArray jsonArray = new JSONArray(roomListJson); for (int i = 0; i < jsonArray.length(); i++) { roomList.add(jsonArray.get(i).toString()); } } catch (JSONException e) { Log.e(TAG, "Failed to load room list: " + e.toString()); } } adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, roomList); roomListView.setAdapter(adapter); if (adapter.getCount() > 0) { roomListView.requestFocus(); roomListView.setItemChecked(0, true); } }
From source file:org.transdroid.daemon.DLinkRouterBT.DLinkRouterBTAdapter.java
@Override public DaemonTaskResult executeTask(Log log, DaemonTask task) { try {/*from w w w . j a v a2 s .c om*/ switch (task.getMethod()) { case Retrieve: // Request all torrents from server JSONObject result = makeRequest(log, API_GET); return new RetrieveTaskSuccessResult((RetrieveTask) task, parseJsonRetrieveTorrents(result), null); case GetFileList: // Request all details for a specific torrent JSONObject result2 = makeRequest(log, API_GET_FILES + task.getTargetTorrent().getUniqueID()); return new GetFileListTaskSuccessResult((GetFileListTask) task, parseJsonFileList(result2, task.getTargetTorrent().getUniqueID())); case AddByFile: // Add a torrent to the server by sending the contents of a local .torrent file String file = ((AddByFileTask) task).getFile(); // put .torrent file's data into the request makeRequest(log, API_ADD_BY_FILE, new File(URI.create(file))); return new DaemonTaskSuccessResult(task); case AddByUrl: // Request to add a torrent by URL String url = ((AddByUrlTask) task).getUrl(); makeRequest(log, API_ADD + url); return new DaemonTaskSuccessResult(task); case Remove: // Remove a torrent RemoveTask removeTask = (RemoveTask) task; makeRequest(log, API_REMOVE + removeTask.getTargetTorrent().getUniqueID() + (removeTask.includingData() ? API_DEL_DATA + "yes" : ""), false); return new DaemonTaskSuccessResult(task); // case Stop: case Pause: // Pause a torrent PauseTask pauseTask = (PauseTask) task; makeRequest(log, API_STOP + pauseTask.getTargetTorrent().getUniqueID(), false); return new DaemonTaskSuccessResult(task); // case PauseAll: // Resume all torrents // makeRequest(buildRequestObject(RPC_METHOD_PAUSE, buildTorrentRequestObject(FOR_ALL, null, // false))); // return new DaemonTaskSuccessResult(task); // case Start: case Resume: // Resume a torrent ResumeTask resumeTask = (ResumeTask) task; makeRequest(log, API_START + resumeTask.getTargetTorrent().getUniqueID(), false); return new DaemonTaskSuccessResult(task); // case ResumeAll: // Resume all torrents // makeRequest(buildRequestObject(RPC_METHOD_RESUME, buildTorrentRequestObject(FOR_ALL, null, // false))); // return new DaemonTaskSuccessResult(task); // case SetTransferRates: // Request to set the maximum transfer rates // SetTransferRatesTask ratesTask = (SetTransferRatesTask) task; // if (ratesTask.getUploadRate() == null) { // request.put(RPC_SESSION_LIMITUPE, false); // } else { // request.put(RPC_SESSION_LIMITUPE, true); // request.put(RPC_SESSION_LIMITUP, ratesTask.getUploadRate().intValue()); // } // if (ratesTask.getDownloadRate() == null) { // request.put(RPC_SESSION_LIMITDOWNE, false); // } else { // request.put(RPC_SESSION_LIMITDOWNE, true); // request.put(RPC_SESSION_LIMITDOWN, ratesTask.getDownloadRate().intValue()); // } // makeRequest( RPC_METHOD_SESSIONSET ); // return new DaemonTaskSuccessResult(task); default: return new DaemonTaskFailureResult(task, new DaemonException(ExceptionType.MethodUnsupported, task.getMethod() + " is not supported by " + getType())); } } catch (JSONException e) { return new DaemonTaskFailureResult(task, new DaemonException(ExceptionType.ParsingFailed, e.toString())); } catch (DaemonException e) { return new DaemonTaskFailureResult(task, e); } }