List of usage examples for org.json JSONObject getBoolean
public boolean getBoolean(String key) throws JSONException
From source file:com.sabdroidex.controllers.couchpotato.CouchPotatoController.java
/** * Retrieve possible download profiles from CouchPotato *///from w w w.java 2 s .c o m public synchronized static void getStatusList() { if ("".equals(Preferences.get(Preferences.COUCHPOTATO_URL))) { return; } Thread thread = new Thread() { @Override public void run() { try { String result = makeApiCall(MESSAGE.STATUS_LIST.toString().toLowerCase()); JSONObject jsonObject = new JSONObject(result); if (jsonObject.getBoolean("success")) { JSONArray profileList = jsonObject.getJSONArray("list"); status = new HashMap<Integer, String>(); for (int i = 0; i < profileList.length(); i++) { status.put(profileList.getJSONObject(i).getInt("id"), profileList.getJSONObject(i).getString("label")); } } } catch (IOException e) { Log.w(TAG, " " + e.getLocalizedMessage()); } catch (Throwable e) { Log.w(TAG, " " + e.getLocalizedMessage()); } finally { executingCommand = false; } } }; executingCommand = true; thread.start(); }
From source file:com.sabdroidex.controllers.couchpotato.CouchPotatoController.java
/** * Retrieve possible download profiles from CouchPotato * /* ww w.j a v a 2s . c om*/ * @param messageHandler Handler */ public synchronized static void getStatusList(final Handler messageHandler) { if (executingCommand || "".equals(Preferences.get(Preferences.COUCHPOTATO_URL))) { return; } Thread thread = new Thread() { @Override public void run() { try { String result = makeApiCall(MESSAGE.STATUS_LIST.toString().toLowerCase()); JSONObject jsonObject = new JSONObject(result); if (jsonObject.getBoolean("success")) { JSONArray profileList = jsonObject.getJSONArray("list"); status = new HashMap<Integer, String>(); for (int i = 0; i < profileList.length(); i++) { status.put(profileList.getJSONObject(i).getInt("id"), profileList.getJSONObject(i).getString("label")); } Message message = new Message(); message.setTarget(messageHandler); message.what = MESSAGE.PROFILE_LIST.hashCode(); message.obj = status; message.sendToTarget(); } } catch (IOException e) { Log.w(TAG, " " + e.getLocalizedMessage()); } catch (Throwable e) { Log.w(TAG, " " + e.getLocalizedMessage()); } finally { executingCommand = false; } } }; executingCommand = true; thread.start(); }
From source file:com.sabdroidex.controllers.couchpotato.CouchPotatoController.java
/** * Retrieve possible download profiles from CouchPotato *///from w ww . j a v a2 s .c om public synchronized static void getProfiles() { if ("".equals(Preferences.get(Preferences.COUCHPOTATO_URL))) { return; } Thread thread = new Thread() { @Override public void run() { try { String result = makeApiCall(MESSAGE.PROFILE_LIST.toString().toLowerCase()); JSONObject jsonObject = new JSONObject(result); if (jsonObject.getBoolean("success")) { profiles = new HashMap<Integer, String>(); JSONArray profileList = jsonObject.getJSONArray("list"); for (int i = 0; i < profileList.length(); i++) { profiles.put(profileList.getJSONObject(i).getInt("id"), profileList.getJSONObject(i).getString("label")); } } } catch (IOException e) { Log.w(TAG, " " + e.getLocalizedMessage()); } catch (Throwable e) { Log.w(TAG, " " + e.getLocalizedMessage()); } finally { executingCommand = false; } } }; executingCommand = true; thread.start(); }
From source file:com.sabdroidex.controllers.couchpotato.CouchPotatoController.java
/** * Retrieve possible download profiles from CouchPotat * //from w ww. jav a 2 s . c om * @param messageHandler Handler */ public synchronized static void getProfiles(final Handler messageHandler) { if (executingCommand || !Preferences.isSet(Preferences.COUCHPOTATO_URL)) { return; } Thread thread = new Thread() { @Override public void run() { try { String result = makeApiCall(MESSAGE.PROFILE_LIST.toString().toLowerCase()); JSONObject jsonObject = new JSONObject(result); if (jsonObject.getBoolean("success") && profiles == null) { profiles = new HashMap<Integer, String>(); JSONArray profileList = jsonObject.getJSONArray("list"); for (int i = 0; i < profileList.length(); i++) { profiles.put(profileList.getJSONObject(i).getInt("id"), profileList.getJSONObject(i).getString("label")); } } Message message = new Message(); message.setTarget(messageHandler); message.what = MESSAGE.PROFILE_LIST.hashCode(); message.obj = profiles; message.sendToTarget(); } catch (IOException e) { Log.w(TAG, " " + e.getLocalizedMessage()); } catch (Throwable e) { Log.w(TAG, " " + e.getLocalizedMessage()); } finally { executingCommand = false; } } }; executingCommand = true; sendUpdateMessageStatus(messageHandler, MESSAGE.MOVIE_DELETE.toString()); thread.start(); }
From source file:com.sabdroidex.controllers.couchpotato.CouchPotatoController.java
/** * Delete a move Based on ID//from www . j av a2 s. com * * @param messageHandler Handler * @param ids ID's of movies to delete */ public static void deleteMovie(final Handler messageHandler, final int... ids) { if (!Preferences.isSet(Preferences.COUCHPOTATO_URL)) { return; } Thread thread = new Thread() { @Override public void run() { String movieIds = ""; for (int i = 0; i < ids.length; i++) { if (i == 0) movieIds += Integer.toString(ids[i]); else movieIds += "," + Integer.toString(ids[i]); } try { String result = makeApiCall(MESSAGE.MOVIE_DELETE.toString().toLowerCase(), "id=" + movieIds); JSONObject jsonObject = new JSONObject(result); if (jsonObject.getBoolean("success") && ids.length != 1) { // TODO: Resource bundle sendUpdateMessageStatus(messageHandler, "Deleted movies"); } else if (jsonObject.getBoolean("success") && ids.length == 1) { // TODO: Resource bundle sendUpdateMessageStatus(messageHandler, "Deleted movie"); } else { // TODO: Resource bundle sendUpdateMessageStatus(messageHandler, "Failed"); } Thread.sleep(100); CouchPotatoController.refreshMovies(messageHandler, ""); } catch (IOException e) { Log.w(TAG, " " + e.getLocalizedMessage()); } catch (Throwable e) { Log.w(TAG, " " + e.getLocalizedMessage()); } finally { executingCommand = false; sendUpdateMessageStatus(messageHandler, ""); } } }; executingCommand = true; sendUpdateMessageStatus(messageHandler, MESSAGE.MOVIE_DELETE.toString()); thread.start(); }
From source file:com.sabdroidex.controllers.couchpotato.CouchPotatoController.java
/** * Edit a move Based on ID and Profile_ID * //from w w w .ja v a 2s .c o m * @param messageHandler Handler * @param ids ID's of movies to edit * @param profile_id Profile ID of profile to edit the movies in */ public static void editMovie(final Handler messageHandler, final int profile_id, final int... ids) { if (!Preferences.isSet(Preferences.COUCHPOTATO_URL)) { return; } Thread thread = new Thread() { @Override public void run() { String movieIds = ""; for (int i = 0; i < ids.length; i++) { if (i == 0) movieIds += Integer.toString(ids[i]); else movieIds += "," + Integer.toString(ids[i]); } try { String result = makeApiCall(MESSAGE.MOVIE_EDIT.toString().toLowerCase(), "profile_id=" + profile_id, "id=" + movieIds); JSONObject jsonObject = new JSONObject(result); if (jsonObject.getBoolean("success")) { // TODO: Resource bundle sendUpdateMessageStatus(messageHandler, "Edited"); } else { // TODO: Resource bundle sendUpdateMessageStatus(messageHandler, "Failed"); } Thread.sleep(100); CouchPotatoController.refreshMovies(messageHandler, "active,done"); } catch (IOException e) { Log.w(TAG, " " + e.getLocalizedMessage()); } catch (Throwable e) { Log.w(TAG, " " + e.getLocalizedMessage()); } finally { executingCommand = false; sendUpdateMessageStatus(messageHandler, ""); } } }; executingCommand = true; sendUpdateMessageStatus(messageHandler, MESSAGE.MOVIE_EDIT.toString()); thread.start(); }
From source file:com.sabdroidex.controllers.couchpotato.CouchPotatoController.java
/** * Download a release of a movie//from w ww .j a v a2s . c om * * @param messageHandler Handler * @param releaseId ID of release to download */ public static void downloadRelease(final Handler messageHandler, final int releaseId) { if (!Preferences.isSet(Preferences.COUCHPOTATO_URL)) { return; } Thread thread = new Thread() { @Override public void run() { try { String result = makeApiCall(MESSAGE.RELEASE_DOWNLOAD.toString().toLowerCase(), "id=" + releaseId); JSONObject jsonObject = new JSONObject(result); Message message = new Message(); message.setTarget(messageHandler); message.what = MESSAGE.RELEASE_DOWNLOAD.hashCode(); message.obj = jsonObject.getBoolean("success"); message.sendToTarget(); } catch (IOException e) { Log.w(TAG, " " + e.getLocalizedMessage()); } catch (Throwable e) { Log.w(TAG, " " + e.getLocalizedMessage()); } } }; thread.start(); }
From source file:com.sakisds.icymonitor.activities.AddServerActivity.java
@SuppressWarnings("ConstantConditions") @Override//from ww w.j a va2 s. c o m public void onClick(View view) { // Check if name is empty if (mEditText_name.getText().toString().equals("")) { mEditText_name.setError(getResources().getString(R.string.error_empty_name)); mEditText_name.requestFocus(); } else if (mEditText_port.getText().toString().equals("")) { mEditText_port.setError(getString(R.string.error_empty_port)); mEditText_port.requestFocus(); } else if (mEditText_address.getText().toString().equals("")) { mEditText_address.setError(getString(R.string.error_empty_address)); mEditText_address.requestFocus(); } else { // If it's not // Validate URL String url = mEditText_address.getText().toString(); // Add http:// if needed if (!url.substring(0, 7).equals("http://")) { url = "http://" + url; } url += ":" + mEditText_port.getText().toString(); url = url.replace(" ", ""); if (!URLUtil.isValidUrl(url)) { // If invalid mEditText_address.setError(getResources().getString(R.string.error_invalid_address)); mEditText_address.requestFocus(); } else { // If URL is valid // Create a dialog final ProgressDialog progress = ProgressDialog.show(this, "", getResources().getString(R.string.connecting), false); // Store actual URL final String actualURL = url; // Check if auth is enabled mClient.get(url + "/authEnabled", null, new JsonHttpResponseHandler() { @Override public void onSuccess(JSONObject response) { try { if (response.getBoolean("AuthEnabled")) { progress.setMessage(getString(R.string.check_computer)); } } catch (JSONException ignored) { } // If there are issues they will be dealt with later } }); // Register RequestParams params = new RequestParams(); params.put("name", android.os.Build.MODEL); params.put("id", String.valueOf(mSettings.getLong("device_id", -2))); params.put("gcm", mGCMID); params.put("ask", "true"); JsonHttpResponseHandler handler = new JsonHttpResponseHandler() { @Override public void onSuccess(JSONObject response) { try { // Get string String version = response.getString("Version"); // Parse response if (version.equals(ConnectionActivity.ACCEPTED_SERVER_VERSION)) { String regStatus = response.getString("Status"); if (regStatus.equals("ALLOWED")) { saveServer(actualURL); progress.dismiss(); mResponseReady = true; } else if (regStatus.equals("DENIED")) { mEditText_address.setError(getResources().getString(R.string.error_rejected)); mEditText_address.requestFocus(); progress.dismiss(); mResponseReady = true; } } else { mEditText_address .setError(getResources().getString(R.string.error_outdated_server)); mEditText_address.requestFocus(); progress.dismiss(); mResponseReady = true; } } catch (JSONException e) { mEditText_address.setError(getResources().getString(R.string.error_invalid_response)); mEditText_address.requestFocus(); progress.dismiss(); mResponseReady = true; } } @Override public void onFailure(Throwable e, JSONObject errorResponse) { progress.dismiss(); mEditText_address.setError(getResources().getString(R.string.error_could_not_reach_host)); mEditText_address.requestFocus(); mResponseReady = true; } }; mClient.get(url + "/register", params, handler); params.remove("ask"); WaitingTask task = new WaitingTask(); task.mUrl = url + "/register"; task.mParams = params; task.mHandler = handler; task.execute(); } } }
From source file:fr.haploid.webservices.WebServicesTask.java
@Override protected void onPostExecute(JSONObject response) { super.onPostExecute(response); if (response != null) { try {//from w w w .jav a 2s. co m JSONObject message = new JSONObject(); message.put(Cobalt.kJSType, Cobalt.JSTypePlugin); message.put(Cobalt.kJSPluginName, JSPluginNameWebservices); if (response.getBoolean(kJSSuccess)) message.put(Cobalt.kJSAction, JSOnWSResult); else message.put(Cobalt.kJSAction, JSOnWSError); JSONObject data = new JSONObject(); data.put(kJSCallId, mCallId); int statusCode = response.optInt(kJSStatusCode, -1); if (statusCode != -1) data.put(kJSStatusCode, statusCode); String text = response.optString(kJSText, null); if (text != null) { try { JSONObject responseData = new JSONObject(text); responseData = WebServicesPlugin.treatData(responseData, mProcessData, mFragment); data.put(Cobalt.kJSData, responseData); } catch (JSONException exception) { Log.w(Cobalt.TAG, TAG + " - onPostExecute: response could not be parsed as JSON. Response: " + text); exception.printStackTrace(); data.put(kJSText, text); } } message.put(Cobalt.kJSData, data); if (response.getBoolean(kJSSuccess) || WebServicesPlugin.handleError(mCall, message, mFragment)) mFragment.sendMessage(message); if (mSaveToStorage && mStorageKey != null) { WebServicesPlugin.storeValue(text, mStorageKey, mFragment); } else if (Cobalt.DEBUG) { Log.w(Cobalt.TAG, TAG + " - onPostExecute: missing storageKey field \n" + "Web service response will not be stored in cache."); } } catch (JSONException exception) { exception.printStackTrace(); } } else if (Cobalt.DEBUG) { Log.d(Cobalt.TAG, TAG + " - onPostExecute: url and/or type fields were empty, Webservice has not been called."); } }
From source file:com.domuslink.elements.Module.java
public Module(JSONObject jsonElement) throws Exception { super();/*from www. j a v a2 s . co m*/ try { setModuleType(jsonElement.getString("moduleType")); setModuleImage(jsonElement.getString("moduleImage")); setElementType(jsonElement.getString("elementType")); setElementLine(jsonElement.getString("elementLine")); setLineNum(jsonElement.getInt("lineNum")); setArrayNum(jsonElement.getInt("arrayNum")); setEnabled(jsonElement.getBoolean("enabled")); } catch (Exception e) { Log.e(TAG, "Error getting alias from JSONObject", e); throw e; } }