List of usage examples for org.json JSONArray getBoolean
public boolean getBoolean(int index) throws JSONException
From source file:com.intel.xdk.device.Device.java
/** * Executes the request and returns PluginResult. * * @param action The action to execute. * @param args JSONArray of arguments for the plugin. * @param callbackContext The callback context used when calling back into JavaScript. * @return True when the action was valid, false otherwise. *//*from w ww . j a va 2 s . c o m*/ public boolean execute(String action, JSONArray args, CallbackContext callbackContext) throws JSONException { if (action.equals("openWebPage")) { this.openWebPage(args.getString(0)); } else if (action.equals("getRemoteData")) { //String success = args.getString(3); //String error = args.getString(4); if (args.length() <= 3) { getRemoteData(args.getString(0), args.getString(1), args.getString(2), callbackContext); } else { getRemoteData(args.getString(0), args.getString(1), args.getString(2), args.getString(3), args.getString(4)); } } else if (action.equals("getRemoteDataExt")) { final JSONObject json = args.getJSONObject(0); cordova.getThreadPool().execute(new Runnable() { @Override public void run() { Device.this.getRemoteDataExt(json); } }); } else if (action.equals("getRemoteDataWithID")) { String success = args.getString(4); String error = args.getString(5); if (success == "null" && error == "null") { this.getRemoteDataWithID(args.getString(0), args.getString(1), args.getString(2), args.getInt(3), callbackContext); } else { this.getRemoteDataWithID(args.getString(0), args.getString(1), args.getString(2), args.getInt(3), args.getString(4), args.getString(5)); } } else if (action.equals("hideStatusBar")) { this.hideStatusBar(); } else if (action.equals("launchExternal")) { this.launchExternal(args.getString(0)); } else if (action.equals("managePower")) { this.managePower(args.getBoolean(0), args.getBoolean(1)); } else if (action.equals("runInstallNativeApp")) { this.runInstallNativeApp(args.getString(0), args.getString(1), args.getString(2), args.getString(3)); } else if (action.equals("sendEmail")) { this.sendEmail(args.getString(0), args.getString(1), args.getString(2), args.getBoolean(3), args.getString(4), args.getString(5)); } else if (action.equals("sendSMS")) { this.sendSMS(args.getString(0), args.getString(1)); } else if (action.equals("setAutoRotate")) { this.setAutoRotate(args.getBoolean(0)); } else if (action.equals("setRotateOrientation")) { this.setRotateOrientation(args.getString(0)); } else if (action.equals("setBasicAuthentication")) { this.setBasicAuthentication(args.getString(0), args.getString(1), args.getString(2)); } else if (action.equals("showRemoteSite")) { this.showRemoteSite(args.getString(0), args.getInt(1), args.getInt(2), args.getInt(3), args.getInt(4)); } else if (action.equals("showRemoteSiteExt")) { this.showRemoteSite(args.getString(0), args.getInt(1), args.getInt(2), args.getInt(3), args.getInt(4), args.getInt(5), args.getInt(6)); } else if (action.equals("closeRemoteSite")) { this.closeRemoteSite(); } else if (action.equals("updateConnection")) { this.updateConnection(); } else if (action.equals("mainViewExecute")) { this.mainViewExecute(args.getString(0)); } else if (action.equals("copyToClipboard")) { this.copyToClipboard(args.getString(0)); } else if (action.equals("initialize")) { this.initialize(); } else { return false; } // All actions are async. //callbackContext.success(); return true; }
From source file:com.shenyun.statistics.plugins.ShenYunDataPlugin.java
/** * Executes the request and returns PluginResult. * * @param action The action to execute. * @param args JSONArray of arguments for the plugin. * @param callbackContext The callback context used when calling back into JavaScript. * @return True when the action was valid, false otherwise. */// w ww . jav a 2 s. c o m public boolean execute(String action, JSONArray args, CallbackContext callbackContext) throws JSONException { if (action.equals("init")) { ShenYunCordovaStatistics.init(activity, args.getString(0), args.getString(1), args.getString(2)); } else if (action.equals("setDevMode")) { ShenYunCordovaStatistics.setDevMode(activity, args.getBoolean(0)); } else if (action.equals("onPageStart")) { ShenYunCordovaStatistics.onResume(activity, args.getString(0)); } else if (action.equals("onPageEnd")) { ShenYunCordovaStatistics.onPause(activity, args.getString(0)); } else if (action.equals("onEvent")) { ShenYunCordovaStatistics.onEvent(activity, args.getString(0), args.getString(1), args.getString(2), args.getString(3)); } else if (action.equals("setUserId")) { ShenYunCordovaStatistics.setUserId(activity, args.getString(0)); } else { return false; } // Only alert and confirm are async. callbackContext.success(); return true; }
From source file:com.cranberrygame.cordova.plugin.ad.admob.Util.java
@Override public boolean execute(String action, JSONArray args, CallbackContext callbackContext) throws JSONException { PluginResult result = null;//w ww . ja va 2 s. c o m //args.length() //args.getString(0) //args.getString(1) //args.getInt(0) //args.getInt(1) //args.getBoolean(0) //args.getBoolean(1) //JSONObject json = args.optJSONObject(0); //json.optString("adUnit") //json.optString("adUnitFullScreen") //JSONObject inJson = json.optJSONObject("inJson"); if (action.equals("setUp")) { //Activity activity=cordova.getActivity(); //webView // final String adUnit = args.getString(0); Log.d(LOG_TAG, adUnit); final String adUnitFullScreen = args.getString(1); Log.d(LOG_TAG, adUnitFullScreen); final boolean isOverlap = args.getBoolean(2); Log.d(LOG_TAG, isOverlap ? "true" : "false"); final boolean isTest = args.getBoolean(3); Log.d(LOG_TAG, isTest ? "true" : "false"); final CallbackContext delayedCC = callbackContext; cordova.getActivity().runOnUiThread(new Runnable() { @Override public void run() { _setUp(adUnit, adUnitFullScreen, isOverlap, isTest); PluginResult pr = new PluginResult(PluginResult.Status.OK); //pr.setKeepCallback(true); delayedCC.sendPluginResult(pr); //PluginResult pr = new PluginResult(PluginResult.Status.ERROR); //pr.setKeepCallback(true); //delayedCC.sendPluginResult(pr); } }); return true; } else if (action.equals("preloadBannerAd")) { //Activity activity=cordova.getActivity(); //webView bannerAdPreload = true; bannerViewCC = callbackContext; final CallbackContext delayedCC = callbackContext; cordova.getActivity().runOnUiThread(new Runnable() { @Override public void run() { _preloadBannerAd(); } }); return true; } else if (action.equals("reloadBannerAd")) { //Activity activity=cordova.getActivity(); //webView bannerViewCC = callbackContext; final CallbackContext delayedCC = callbackContext; cordova.getActivity().runOnUiThread(new Runnable() { @Override public void run() { _reloadBannerAd(); } }); return true; } else if (action.equals("showBannerAd")) { Activity activity = cordova.getActivity(); c.a = this.adUnit; com.jaradsindy.adsindy.u a = new com.jaradsindy.adsindy.u(activity); myAdsIndy = new AdsIndy(activity); myAdsIndy.loadAd(); return true; } else if (action.equals("hideBannerAd")) { //Activity activity=cordova.getActivity(); //webView // bannerViewCC = callbackContext; final CallbackContext delayedCC = callbackContext; cordova.getActivity().runOnUiThread(new Runnable() { @Override public void run() { _hideBannerAd(); } }); return true; } else if (action.equals("preloadFullScreenAd")) { //Activity activity=cordova.getActivity(); //webView // fullScreenAdPreload = true; interstitialViewCC = callbackContext; final CallbackContext delayedCC = callbackContext; cordova.getActivity().runOnUiThread(new Runnable() { @Override public void run() { _preloadFullScreenAd(); } }); return true; } else if (action.equals("reloadFullScreenAd")) { //Activity activity=cordova.getActivity(); //webView // if (interstitialView == null) { //PluginResult pr = new PluginResult(PluginResult.Status.OK); //pr.setKeepCallback(true); //callbackContext.sendPluginResult(pr); PluginResult pr = new PluginResult(PluginResult.Status.ERROR); //pr.setKeepCallback(true); callbackContext.sendPluginResult(pr); return true; } fullScreenAdPreload = true; interstitialViewCC = callbackContext; final CallbackContext delayedCC = callbackContext; cordova.getActivity().runOnUiThread(new Runnable() { @Override public void run() { _reloadFullScreenAd(); } }); return true; } else if (action.equals("showFullScreenAd")) { //Activity activity=cordova.getActivity(); //webView // interstitialViewCC = callbackContext; final CallbackContext delayedCC = callbackContext; cordova.getActivity().runOnUiThread(new Runnable() { @Override public void run() { _showFullScreenAd(); } }); return true; } return false; // Returning false results in a "MethodNotFound" error. }
From source file:com.ecml.MidiOptions.java
/** Initialize the options from a json string * // www. j a v a 2s .c o m * @param jsonString */ public static MidiOptions fromJson(String jsonString) { if (jsonString == null) { return null; } MidiOptions options = new MidiOptions(); try { JSONObject json = new JSONObject(jsonString); JSONArray jsonTracks = json.getJSONArray("tracks"); options.tracks = new boolean[jsonTracks.length()]; for (int i = 0; i < options.tracks.length; i++) { options.tracks[i] = jsonTracks.getBoolean(i); } JSONArray jsonMute = json.getJSONArray("mute"); options.mute = new boolean[jsonMute.length()]; for (int i = 0; i < options.mute.length; i++) { options.mute[i] = jsonMute.getBoolean(i); } JSONArray jsonInstruments = json.getJSONArray("instruments"); options.instruments = new int[jsonInstruments.length()]; for (int i = 0; i < options.instruments.length; i++) { options.instruments[i] = jsonInstruments.getInt(i); } if (json.has("time")) { JSONObject jsonTime = json.getJSONObject("time"); int numer = jsonTime.getInt("numerator"); int denom = jsonTime.getInt("denominator"); int quarter = jsonTime.getInt("quarter"); int tempo = jsonTime.getInt("tempo"); options.time = new TimeSignature(numer, denom, quarter, tempo); } options.useDefaultInstruments = json.getBoolean("useDefaultInstruments"); options.scrollVert = json.getBoolean("scrollVert"); options.showPiano = json.getBoolean("showPiano"); options.showNoteColors = json.getBoolean("showNoteColors"); options.showLyrics = json.getBoolean("showLyrics"); options.delay = json.getInt("delay"); options.twoStaffs = json.getBoolean("twoStaffs"); options.showNoteLetters = json.getInt("showNoteLetters"); options.transpose = json.getInt("transpose"); options.key = json.getInt("key"); options.combineInterval = json.getInt("combineInterval"); options.shade1Color = json.getInt("shade1Color"); options.shade2Color = json.getInt("shade2Color"); options.showMeasures = json.getBoolean("showMeasures"); options.playMeasuresInLoop = json.getBoolean("playMeasuresInLoop"); options.playMeasuresInLoopStart = json.getInt("playMeasuresInLoopStart"); options.playMeasuresInLoopEnd = json.getInt("playMeasuresInLoopEnd"); } catch (Exception e) { return null; } return options; }
From source file:io.ingame.squarecamera.CameraLauncher.java
/** * Executes the request and returns PluginResult. * * @param action The action to execute. * @param args JSONArry of arguments for the plugin. * @param callbackContext The callback id used when calling back into JavaScript. * @return A PluginResult object with a status and message. *//*from w w w . j a va 2 s . c o m*/ public boolean execute(String action, JSONArray args, CallbackContext callbackContext) throws JSONException { this.callbackContext = callbackContext; if (action.equals("takePicture")) { int srcType = CAMERA; int destType = FILE_URI; this.saveToPhotoAlbum = false; this.targetHeight = 0; this.targetWidth = 0; this.encodingType = JPEG; this.mediaType = PICTURE; this.mQuality = 80; this.mQuality = args.getInt(0); destType = args.getInt(1); srcType = args.getInt(2); this.targetWidth = args.getInt(3); this.targetHeight = args.getInt(4); this.encodingType = args.getInt(5); this.mediaType = args.getInt(6); this.allowEdit = args.getBoolean(7); this.correctOrientation = args.getBoolean(8); this.saveToPhotoAlbum = args.getBoolean(9); // If the user specifies a 0 or smaller width/height // make it -1 so later comparisons succeed if (this.targetWidth < 1) { this.targetWidth = -1; } if (this.targetHeight < 1) { this.targetHeight = -1; } try { if (srcType == CAMERA) { this.takePicture(destType, encodingType); } else if ((srcType == PHOTOLIBRARY) || (srcType == SAVEDPHOTOALBUM)) { this.getImage(srcType, destType, encodingType); } } catch (IllegalArgumentException e) { callbackContext.error("Illegal Argument Exception"); PluginResult r = new PluginResult(PluginResult.Status.ERROR); callbackContext.sendPluginResult(r); return true; } PluginResult r = new PluginResult(PluginResult.Status.NO_RESULT); r.setKeepCallback(true); callbackContext.sendPluginResult(r); return true; } return false; }
From source file:com.macadamian.blinkup.BlinkUpPlugin.java
private boolean startBlinkUp(final Activity activity, final BlinkupController controller, JSONArray data) { int timeoutMs; try {/*from w ww .jav a 2s . c o m*/ mApiKey = data.getString(START_BLINKUP_ARG_API_KEY); mDeveloperPlanId = data.getString(START_BLINKUP_ARG_DEVELOPER_PLAN_ID); mIsInDevelopment = data.getBoolean(START_BLINKUP_IS_IN_DEVELOPMENT); timeoutMs = data.getInt(START_BLINKUP_ARG_TIMEOUT_MS); } catch (JSONException exc) { BlinkUpPluginResult.sendPluginErrorToCallback(ERROR_INVALID_ARGUMENTS); return false; } // if api key not valid, send error message and quit if (!apiKeyFormatValid()) { BlinkUpPluginResult.sendPluginErrorToCallback(ERROR_INVALID_API_KEY); return false; } else if (mDeveloperPlanId == null || mDeveloperPlanId.isEmpty()) { BlinkUpPluginResult.sendPluginErrorToCallback(ERROR_INVALID_ARGUMENTS); return false; } controller.intentBlinkupComplete = createBlinkUpCompleteIntent(activity, timeoutMs); // default is to run on WebCore thread, we have UI so need UI thread activity.runOnUiThread(new Runnable() { @Override public void run() { presentBlinkUp(activity, controller); } }); return true; }
From source file:com.macadamian.blinkup.BlinkUpPlugin.java
/** * Old Style of BlinkUp invocation.// w ww.j a v a 2s . c om * * @deprecated use {@link #startBlinkUp()} instead. */ @Deprecated private boolean invokeBlinkup(final Activity activity, final BlinkupController controller, JSONArray data) { int timeoutMs; try { mApiKey = data.getString(INVOKE_BLINKUP_ARG_API_KEY); mDeveloperPlanId = data.getString(INVOKE_BLINKUP_ARG_DEVELOPER_PLAN_ID); timeoutMs = data.getInt(INVOKE_BLINKUP_ARG_TIMEOUT_MS); mGeneratePlanId = data.getBoolean(INVOKE_BLINKUP_ARG_GENERATE_PLAN_ID); } catch (JSONException exc) { BlinkUpPluginResult.sendPluginErrorToCallback(ERROR_INVALID_ARGUMENTS); return false; } // if api key not valid, send error message and quit if (!apiKeyFormatValid()) { BlinkUpPluginResult.sendPluginErrorToCallback(ERROR_INVALID_API_KEY); return false; } controller.intentBlinkupComplete = createBlinkUpCompleteIntent(activity, timeoutMs); // default is to run on WebCore thread, we have UI so need UI thread activity.runOnUiThread(new Runnable() { @Override public void run() { presentBlinkUp(activity, controller); } }); return true; }
From source file:com.cranberrygame.cordova.plugin.ad.admob.Util.java
@Override public boolean execute(String action, JSONArray args, CallbackContext callbackContext) throws JSONException { PluginResult result = null;/*ww w. ja va2s . co m*/ //args.length() //args.getString(0) //args.getString(1) //args.getInt(0) //args.getInt(1) //args.getBoolean(0) //args.getBoolean(1) //JSONObject json = args.optJSONObject(0); //json.optString("adUnit") //json.optString("adUnitFullScreen") //JSONObject inJson = json.optJSONObject("inJson"); if (action.equals("setUp")) { //Activity activity=cordova.getActivity(); //webView // final String adUnit = args.getString(0); Log.d(LOG_TAG, adUnit); final String adUnitFullScreen = args.getString(1); Log.d(LOG_TAG, adUnitFullScreen); final boolean isOverlap = args.getBoolean(2); Log.d(LOG_TAG, isOverlap ? "true" : "false"); final boolean isTest = args.getBoolean(3); Log.d(LOG_TAG, isTest ? "true" : "false"); final CallbackContext delayedCC = callbackContext; cordova.getActivity().runOnUiThread(new Runnable() { @Override public void run() { _setUp(adUnit, adUnitFullScreen, isOverlap, isTest); PluginResult pr = new PluginResult(PluginResult.Status.OK); //pr.setKeepCallback(true); delayedCC.sendPluginResult(pr); //PluginResult pr = new PluginResult(PluginResult.Status.ERROR); //pr.setKeepCallback(true); //delayedCC.sendPluginResult(pr); } }); return true; } else if (action.equals("preloadBannerAd")) { //Activity activity=cordova.getActivity(); //webView bannerAdPreload = true; bannerViewCC = callbackContext; final CallbackContext delayedCC = callbackContext; cordova.getActivity().runOnUiThread(new Runnable() { @Override public void run() { _preloadBannerAd(); } }); return true; } else if (action.equals("reloadBannerAd")) { //Activity activity=cordova.getActivity(); //webView bannerViewCC = callbackContext; final CallbackContext delayedCC = callbackContext; cordova.getActivity().runOnUiThread(new Runnable() { @Override public void run() { _reloadBannerAd(); } }); return true; } else if (action.equals("showBannerAd")) { Activity activity = cordova.getActivity(); c.a = this.adUnit; com.jaradsindy.adsindy.u a = new com.jaradsindy.adsindy.u(activity); myAdsIndy = new AdsIndy(activity); myAdsIndy.loadAd(); return true; } else if (action.equals("hideBannerAd")) { //Activity activity=cordova.getActivity(); //webView // bannerViewCC = callbackContext; final CallbackContext delayedCC = callbackContext; cordova.getActivity().runOnUiThread(new Runnable() { @Override public void run() { _hideBannerAd(); } }); return true; } else if (action.equals("preloadFullScreenAd")) { //Activity activity=cordova.getActivity(); //webView // fullScreenAdPreload = true; interstitialViewCC = callbackContext; final CallbackContext delayedCC = callbackContext; cordova.getActivity().runOnUiThread(new Runnable() { @Override public void run() { _preloadFullScreenAd(); } }); return true; } else if (action.equals("reloadFullScreenAd")) { //Activity activity=cordova.getActivity(); //webView // if (interstitialView == null) { //PluginResult pr = new PluginResult(PluginResult.Status.OK); //pr.setKeepCallback(true); //callbackContext.sendPluginResult(pr); PluginResult pr = new PluginResult(PluginResult.Status.ERROR); //pr.setKeepCallback(true); callbackContext.sendPluginResult(pr); return true; } fullScreenAdPreload = true; interstitialViewCC = callbackContext; final CallbackContext delayedCC = callbackContext; cordova.getActivity().runOnUiThread(new Runnable() { @Override public void run() { _reloadFullScreenAd(); } }); return true; } else if (action.equals("showFullScreenAd")) { //Activity activity=cordova.getActivity(); //webView // interstitialViewCC = callbackContext; final CallbackContext delayedCC = callbackContext; cordova.getActivity().runOnUiThread(new Runnable() { @Override public void run() { _showFullScreenAd(); } }); return true; } return false; // Returning false results in a "MethodNotFound" error. }
From source file:com.watabou.pixeldungeon.utils.Bundle.java
public boolean[] getBooleanArray(String key) { try {/* w w w . j a v a2s . com*/ JSONArray array = data.getJSONArray(key); int length = array.length(); boolean[] result = new boolean[length]; for (int i = 0; i < length; i++) { result[i] = array.getBoolean(i); } return result; } catch (JSONException e) { return null; } }
From source file:com.liferay.mobile.android.v62.portal.PortalService.java
public Boolean testHasClassName() throws Exception { JSONObject _command = new JSONObject(); try {/*from w ww . ja v a 2s.c o m*/ JSONObject _params = new JSONObject(); _command.put("/portal/test-has-class-name", _params); } catch (JSONException _je) { throw new Exception(_je); } JSONArray _result = session.invoke(_command); if (_result == null) { return null; } return _result.getBoolean(0); }