Example usage for org.json JSONArray getBoolean

List of usage examples for org.json JSONArray getBoolean

Introduction

In this page you can find the example usage for org.json JSONArray getBoolean.

Prototype

public boolean getBoolean(int index) throws JSONException 

Source Link

Document

Get the boolean value associated with an index.

Usage

From source file:com.phonegap.GeoBroker.java

/**
 * Executes the request and returns PluginResult.
 * /*  w w  w .  ja  v  a  2 s  . co m*/
 * @param action       The action to execute.
 * @param args          JSONArry of arguments for the plugin.
 * @param callbackId   The callback id used when calling back into JavaScript.
 * @return             A PluginResult object with a status and message.
 */
public PluginResult execute(String action, JSONArray args, String callbackId) {
    PluginResult.Status status = PluginResult.Status.OK;
    String result = "";

    try {
        if (action.equals("getCurrentLocation")) {
            this.getCurrentLocation(args.getBoolean(0), args.getInt(1), args.getInt(2));
        } else if (action.equals("start")) {
            String s = this.start(args.getString(0), args.getBoolean(1), args.getInt(2), args.getInt(3));
            return new PluginResult(status, s);
        } else if (action.equals("stop")) {
            this.stop(args.getString(0));
        }
        return new PluginResult(status, result);
    } catch (JSONException e) {
        return new PluginResult(PluginResult.Status.JSON_EXCEPTION);
    }
}

From source file:com.Maestro.MidiOptions.java

public static MidiOptions fromJson(String jsonString) {
    if (jsonString == null) {
        return null;
    }/*from  w  ww. java 2  s  . c o  m*/
    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.showLyrics = json.getBoolean("showLyrics");
        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:com.suarez.cordova.mapsforge.MapsforgePlugin.java

@Override
public boolean execute(String action, JSONArray args, CallbackContext callbackContext) throws JSONException {
    if ("global-status".equals(action)) {
        this.status();
        callbackContext.success();//  w  w  w  . ja  v a 2  s .  c om
        return true;
    } else if (action.contains("native-")) {
        if ("native-set-center".equals(action)) {
            try {
                MapsforgeNative.INSTANCE.setCenter(args.getDouble(0), args.getDouble(1));
                callbackContext.success();
            } catch (JSONException je) {
                callbackContext.error(je.getMessage());
            } catch (Exception e) {
                callbackContext.error(e.getMessage());
            }

            return true;
        } else if ("native-set-zoom".equals(action)) {
            try {
                MapsforgeNative.INSTANCE.setZoom(Byte.parseByte(args.getString(0)));
                callbackContext.success();
            } catch (NumberFormatException nfe) {
                callbackContext.error("Incorrect argument format. Should be: (byte zoom)");
            } catch (JSONException je) {
                callbackContext.error(je.getMessage());
            } catch (Exception e) {
                callbackContext.error(e.getMessage());
            }

            return true;
        } else if ("native-show".equals(action)) {
            try {
                MapsforgeNative.INSTANCE.show();
                callbackContext.success();
            } catch (Exception e) {
                callbackContext.error(e.getMessage());
            }
            return true;
        } else if ("native-hide".equals(action)) {
            MapsforgeNative.INSTANCE.hide();
            return true;
        } else if ("native-marker".equals(action)) {
            try {
                Activity context = this.cordova.getActivity();

                int markerId = context.getResources().getIdentifier(args.getString(0), "drawable",
                        context.getPackageName());
                if (markerId == 0) {
                    Log.i(MapsforgePlugin.TAG, "Marker not found...using default marker: marker_green");
                    markerId = context.getResources().getIdentifier("marker_green", "drawable",
                            context.getPackageName());
                }

                int markerKey = MapsforgeNative.INSTANCE.addMarker(markerId, args.getDouble(1),
                        args.getDouble(2));
                callbackContext.success(markerKey);
            } catch (JSONException je) {
                callbackContext.error(je.getMessage());
            } catch (Exception e) {
                callbackContext.error(e.getMessage());
            }

            return true;
        } else if ("native-polyline".equals(action)) {

            try {
                JSONArray points = args.getJSONArray(2);

                if (points.length() % 2 != 0)
                    throw new JSONException("Invalid array of coordinates. Length should be multiple of 2");

                int polylineKey = MapsforgeNative.INSTANCE.addPolyline(args.getInt(0), args.getInt(1), points);

                callbackContext.success(polylineKey);
            } catch (JSONException je) {
                callbackContext.error(je.getMessage());
            } catch (Exception e) {
                callbackContext.error(e.getMessage());
            }

            return true;
        } else if ("native-delete-layer".equals(action)) {

            try {
                MapsforgeNative.INSTANCE.deleteLayer(args.getInt(0));
                callbackContext.success();
            } catch (JSONException je) {
                callbackContext.error(je.getMessage());
            } catch (Exception e) {
                callbackContext.error(e.getMessage());
            }

            return true;
        } else if ("native-initialize".equals(action)) {

            try {

                MapsforgeNative.createInstance(this.cordova.getActivity(), args.getString(0), args.getInt(1),
                        args.getInt(2));
                callbackContext.success();
            } catch (JSONException je) {
                callbackContext.error(je.getMessage());
            } catch (IllegalArgumentException e) {
                callbackContext.error(e.getMessage());
            } catch (IOException e) {
                callbackContext.error(e.getMessage());
            } catch (Exception e) {
                callbackContext.error(e.getMessage());
            }

            return true;
        } else if ("native-set-max-zoom".equals(action)) {

            try {
                MapsforgeNative.INSTANCE.setMaxZoom(Byte.parseByte(args.getString(0)));
                callbackContext.success();
            } catch (NumberFormatException nfe) {
                callbackContext.error("Incorrect argument format. Should be: (byte zoom)");
            } catch (JSONException je) {
                callbackContext.error(je.getMessage());
            } catch (Exception e) {
                callbackContext.error(e.getMessage());
            }

            return true;
        } else if ("native-set-min-zoom".equals(action)) {

            try {
                MapsforgeNative.INSTANCE.setMinZoom(Byte.parseByte(args.getString(0)));
                callbackContext.success();
            } catch (NumberFormatException nfe) {
                callbackContext.error("Incorrect argument format. Should be: (byte zoom)");
            } catch (JSONException je) {
                callbackContext.error(je.getMessage());
            } catch (Exception e) {
                callbackContext.error(e.getMessage());
            }

            return true;
        } else if ("native-show-controls".equals(action)) {

            try {
                MapsforgeNative.INSTANCE.setBuiltInZoomControls(args.getBoolean(0));
                callbackContext.success();
            } catch (JSONException je) {
                callbackContext.error(je.getMessage());
            } catch (Exception e) {
                callbackContext.error(e.getMessage());
            }

            return true;
        } else if ("native-clickable".equals(action)) {

            try {
                MapsforgeNative.INSTANCE.setClickable(args.getBoolean(0));
                callbackContext.success();
            } catch (JSONException je) {
                callbackContext.error(je.getMessage());
            } catch (Exception e) {
                callbackContext.error(e.getMessage());
            }

            return true;
        } else if ("native-show-scale".equals(action)) {

            try {
                MapsforgeNative.INSTANCE.showScaleBar(args.getBoolean(0));
                callbackContext.success();
            } catch (JSONException je) {
                callbackContext.error(je.getMessage());
            } catch (Exception e) {
                callbackContext.error(e.getMessage());
            }

            return true;
        } else if ("native-destroy-cache".equals(action)) {

            try {
                MapsforgeNative.INSTANCE.destroyCache(args.getBoolean(0));
                callbackContext.success();
            } catch (JSONException je) {
                callbackContext.error(je.getMessage());
            }

            return true;
        } else if ("native-map-path".equals(action)) {

            try {
                MapsforgeNative.INSTANCE.setMapFilePath(args.getString(0));
                callbackContext.success();
            } catch (JSONException je) {
                callbackContext.error(je.getMessage());
            } catch (IllegalArgumentException iae) {
                callbackContext.error(iae.getMessage());
            } catch (Exception e) {
                callbackContext.error(e.getMessage());
            }

            return true;
        } else if ("native-cache-name".equals(action)) {

            try {
                MapsforgeNative.INSTANCE.setCacheName(args.getString(0));
                callbackContext.success();
            } catch (JSONException je) {
                callbackContext.error(je.getMessage());
            } catch (Exception e) {
                callbackContext.error(e.getMessage());
            }

            return true;
        } else if ("native-theme-path".equals(action)) {

            try {
                MapsforgeNative.INSTANCE.setRenderThemePath(args.getString(0));
                callbackContext.success();
            } catch (JSONException je) {
                callbackContext.error(je.getMessage());
            } catch (IllegalArgumentException e) {
                callbackContext.error(e.getMessage());
            } catch (IOException e) {
                callbackContext.error(e.getMessage());
            } catch (Exception e) {
                callbackContext.error(e.getMessage());
            }

            return true;
        } else if ("native-stop".equals(action)) {
            try {
                MapsforgeNative.INSTANCE.onStop();
                callbackContext.success();
            } catch (Exception e) {
                callbackContext.error(e.getMessage());
            }

            return true;
        } else if ("native-start".equals(action)) {
            try {
                MapsforgeNative.INSTANCE.onStart();
                callbackContext.success();
            } catch (Exception e) {
                callbackContext.error(e.getMessage());
            }

            return true;
        } else if ("native-destroy".equals(action)) {
            try {
                MapsforgeNative.INSTANCE.onDestroy();
                callbackContext.success();
            } catch (Exception e) {
                callbackContext.error(e.getMessage());
            }

            return true;
        } else if ("native-online".equals(action)) {

            try {
                MapsforgeNative.INSTANCE.setOnline(args.getString(0), args.getString(1), args.getString(2),
                        args.getString(3), args.getInt(4));
                callbackContext.success();
            } catch (JSONException je) {
                callbackContext.error(je.getMessage());
            } catch (Exception e) {
                callbackContext.error(e.getMessage());
            }

            return true;
        } else if ("native-offline".equals(action)) {

            try {
                MapsforgeNative.INSTANCE.setOffline(args.getString(0), args.getString(1));
                callbackContext.success();
            } catch (JSONException je) {
                callbackContext.error(je.getMessage());
            } catch (IllegalArgumentException e) {
                callbackContext.error(e.getMessage());
            } catch (IOException e) {
                callbackContext.error(e.getMessage());
            } catch (Exception e) {
                callbackContext.error(e.getMessage());
            }

            return true;
        }
    } else if (action.contains("cache-")) {
        if ("cache-get-tile".equals(action)) {

            try {
                final long x = args.getLong(0);
                final long y = args.getLong(1);
                final byte z = Byte.parseByte(args.getString(2));
                final CallbackContext callbacks = callbackContext;

                cordova.getThreadPool().execute(new Runnable() {
                    public void run() {
                        try {
                            String path = MapsforgeCache.INSTANCE.getTilePath(x, y, z);
                            callbacks.success(path);
                        } catch (IOException e) {
                            callbacks.error(e.getMessage());
                        } catch (Exception e) {
                            callbacks.error(e.getMessage());
                        }
                    }
                });
            } catch (JSONException je) {
                callbackContext.error(je.getMessage());
            } catch (NumberFormatException nfe) {
                callbackContext.error(nfe.getMessage());
            } catch (Exception e) {
                callbackContext.error(e.getMessage());
            }

            return true;
        } else if ("cache-initialize".equals(action)) {

            try {
                MapsforgeCache.createInstance(cordova.getActivity(), args.getString(0));
                callbackContext.success();
            } catch (JSONException je) {
                callbackContext.error(je.getMessage());
            } catch (IllegalArgumentException e) {
                callbackContext.error(e.getMessage());
            } catch (IOException e) {
                callbackContext.error(e.getMessage());
            } catch (Exception e) {
                callbackContext.error(e.getMessage());
            }

            return true;
        } else if ("cache-map-path".equals(action)) {

            try {
                final String mapFile = args.getString(0);
                final CallbackContext callbacks = callbackContext;

                cordova.getThreadPool().execute(new Runnable() {

                    @Override
                    public void run() {
                        try {
                            MapsforgeCache.INSTANCE.setMapFilePath(mapFile);
                            callbacks.success();
                        } catch (IllegalArgumentException e) {
                            callbacks.error(e.getMessage());
                        } catch (FileNotFoundException e) {
                            callbacks.error(e.getMessage());
                        } catch (Exception e) {
                            callbacks.error(e.getMessage());
                        }
                    }
                });
            } catch (JSONException je) {
                callbackContext.error(je.getMessage());
            } catch (Exception e) {
                callbackContext.error(e.getMessage());
            }

            return true;
        } else if ("cache-max-size".equals(action)) {

            try {
                MapsforgeCache.INSTANCE.setMaxCacheSize(args.getInt(0));
                callbackContext.success();
            } catch (JSONException je) {
                callbackContext.error(je.getMessage());
            } catch (Exception e) {
                callbackContext.error(e.getMessage());
            }

            return true;
        } else if ("cache-max-age".equals(action)) {

            try {
                MapsforgeCache.INSTANCE.setMaxCacheAge(args.getLong(0));
                callbackContext.success();
            } catch (JSONException je) {
                callbackContext.error(je.getMessage());
            } catch (Exception e) {
                callbackContext.error(e.getMessage());
            }

            return true;
        } else if ("cache-cleaning-trigger".equals(action)) {

            try {
                MapsforgeCache.INSTANCE.setCleanCacheTrigger(args.getInt(0));
                callbackContext.success();
            } catch (JSONException je) {
                callbackContext.error(je.getMessage());
            } catch (Exception e) {
                callbackContext.error(e.getMessage());
            }

            return true;
        } else if ("cache-enabled".equals(action)) {

            try {
                MapsforgeCache.INSTANCE.setCacheEnabled(args.getBoolean(0));
                callbackContext.success();
            } catch (JSONException je) {
                callbackContext.error(je.getMessage());
            } catch (Exception e) {
                callbackContext.error(e.getMessage());
            }

            return true;
        } else if ("cache-external".equals(action)) {

            try {
                MapsforgeCache.INSTANCE.setExternalCache(args.getBoolean(0));
                callbackContext.success();
            } catch (JSONException je) {
                callbackContext.error(je.getMessage());
            } catch (Exception e) {
                callbackContext.error(e.getMessage());
            }

            return true;
        } else if ("cache-name".equals(action)) {

            try {
                MapsforgeCache.INSTANCE.setCacheName(args.getString(0));
                callbackContext.success();
            } catch (JSONException je) {
                callbackContext.error(je.getMessage());
            } catch (Exception e) {
                callbackContext.error(e.getMessage());
            }

            return true;
        } else if ("cache-tile-size".equals(action)) {

            try {
                MapsforgeCache.INSTANCE.setTileSize(args.getInt(0));
                callbackContext.success();
            } catch (JSONException je) {
                callbackContext.error(je.getMessage());
            } catch (Exception e) {
                callbackContext.error(e.getMessage());
            }

            return true;
        } else if ("cache-clean-destroy".equals(action)) {

            try {
                MapsforgeCache.INSTANCE.setCleanOnDestroy(args.getBoolean(0));
                callbackContext.success();
            } catch (JSONException je) {
                callbackContext.error(je.getMessage());
            } catch (Exception e) {
                callbackContext.error(e.getMessage());
            }

            return true;
        } else if ("cache-theme-path".equals(action)) {

            try {
                final CallbackContext callbacks = callbackContext;
                final String themePath = args.getString(0);

                cordova.getThreadPool().execute(new Runnable() {

                    @Override
                    public void run() {
                        try {
                            MapsforgeCache.INSTANCE.setRenderTheme(themePath);
                            callbacks.success();
                        } catch (IllegalArgumentException e) {
                            callbacks.error(e.getMessage());
                        } catch (FileNotFoundException e) {
                            callbacks.error(e.getMessage());
                        } catch (Exception e) {
                            callbacks.error(e.getMessage());
                        }
                    }
                });
            } catch (JSONException je) {
                callbackContext.error(je.getMessage());
            } catch (Exception e) {
                callbackContext.error(e.getMessage());
            }

            return true;
        } else if ("cache-screen-ratio".equals(action)) {

            try {
                MapsforgeCache.INSTANCE.setScreenRatio(Float.parseFloat(args.getString(0)));
                callbackContext.success();
            } catch (JSONException je) {
                callbackContext.error(je.getMessage());
            } catch (NumberFormatException nfe) {
                callbackContext.error(nfe.getMessage());
            } catch (Exception e) {
                callbackContext.error(e.getMessage());
            }

            return true;
        } else if ("cache-overdraw".equals(action)) {

            try {
                MapsforgeCache.INSTANCE.setOverdrawFactor(Float.parseFloat(args.getString(0)));
                callbackContext.success();
            } catch (JSONException je) {
                callbackContext.error(je.getMessage());
            } catch (NumberFormatException nfe) {
                callbackContext.error(nfe.getMessage());
            } catch (Exception e) {
                callbackContext.error(e.getMessage());
            }

            return true;
        } else if ("cache-destroy".equals(action)) {
            try {
                MapsforgeCache.INSTANCE.onDestroy();
                callbackContext.success();
            } catch (Exception e) {
                callbackContext.error(e.getMessage());
            }

            return true;
        }
    }
    return false; // Returning false results in a "MethodNotFound" error.
}

From source file:com.liferay.mobile.android.v62.team.TeamService.java

public Boolean hasUserTeam(long userId, long teamId) throws Exception {
    JSONObject _command = new JSONObject();

    try {//from   w  w  w.j  a  v a2s  .c om
        JSONObject _params = new JSONObject();

        _params.put("userId", userId);
        _params.put("teamId", teamId);

        _command.put("/team/has-user-team", _params);
    } catch (JSONException _je) {
        throw new Exception(_je);
    }

    JSONArray _result = session.invoke(_command);

    if (_result == null) {
        return null;
    }

    return _result.getBoolean(0);
}

From source file:com.rasrin.locale.formatter.plugin.LocaleFormatter.java

@Override
public boolean execute(String action, JSONArray args, CallbackContext callbackContext) throws JSONException {

    try {//from  w  ww .  j a  v  a2  s .  c o m

        if (action.equals("formatCurrency")) {

            if (args.length() < 3) {
                callbackContext.error("Expected 3 arguments.");
                return false;
            }

            String ilocale = args.getString(0);
            long amount = args.getLong(1);
            boolean debug = args.getBoolean(2);
            Locale locale = new Locale("en", "US");
            if (ilocale != null && ilocale.length() <= 5) {
                if (ilocale.indexOf('-') > 0) {
                    String[] parts = ilocale.split("-");
                    locale = new Locale(parts[0], parts[1]);
                }
            }

            NumberFormat formatter = NumberFormat.getCurrencyInstance(locale);
            String moneyString = formatter.format(amount);

            if (debug) {
                System.out.println("Called with locale: " + ilocale + " & amount: " + amount
                        + ". Formatted string is: " + moneyString);
            }

            callbackContext.success(moneyString);

            return true;

        } else {
            callbackContext.error("Unsupported operation");
            return false;
        }

    } catch (Exception ex) {
        callbackContext.error("Something went wrong: " + ex.getMessage());
        return false;
    }

}

From source file:plugin.geolocation.GeoBroker.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          True if the action was valid, or false if not.
 *//*www.  j  a v a  2  s  .  c om*/
public boolean execute(String action, JSONArray args, CallbackContext callbackContext) throws JSONException {
    if (locationManager == null) {
        locationManager = (LocationManager) this.cordova.getActivity()
                .getSystemService(Context.LOCATION_SERVICE);
    }
    if (locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER)
            || locationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER)) {
        if (networkListener == null) {
            networkListener = new NetworkListener(locationManager, this);
        }
        if (gpsListener == null) {
            gpsListener = new GPSListener(locationManager, this);
        }

        if (action.equals("getLocation")) {
            boolean enableHighAccuracy = args.getBoolean(0);
            int maximumAge = args.getInt(1);
            String provider = (enableHighAccuracy
                    && locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER))
                            ? LocationManager.GPS_PROVIDER
                            : LocationManager.NETWORK_PROVIDER;
            Location last = this.locationManager.getLastKnownLocation(provider);
            // Check if we can use lastKnownLocation to get a quick reading and use less battery
            if (last != null && (System.currentTimeMillis() - last.getTime()) <= maximumAge) {
                PluginResult result = new PluginResult(PluginResult.Status.OK, this.returnLocationJSON(last));
                callbackContext.sendPluginResult(result);
            } else {
                this.getCurrentLocation(callbackContext, enableHighAccuracy, args.optInt(2, 60000));
            }
        } else if (action.equals("addWatch")) {
            String id = args.getString(0);
            boolean enableHighAccuracy = args.getBoolean(1);
            this.addWatch(id, callbackContext, enableHighAccuracy);
        } else if (action.equals("clearWatch")) {
            String id = args.getString(0);
            this.clearWatch(id);
        } else {
            return false;
        }
    } else {
        PluginResult.Status status = PluginResult.Status.NO_RESULT;
        String message = "Location API is not available for this device.";
        PluginResult result = new PluginResult(status, message);
        callbackContext.sendPluginResult(result);
    }
    return true;
}

From source file:com.baroq.pico.google.PlayServices.java

@Override
public boolean execute(String action, JSONArray data, CallbackContext callbackContext) {

    try {//from   w w  w  .ja  va 2 s .com
        if (!ACTION_SETUP.equals(action) && !ACTION_SIGNIN.equals(action)
                && (null == mHelper || !mHelper.isConnected())) {
            callbackContext.error("Please setup and signin to use PlayServices plugin");
            return false;
        }
        if (ACTION_SETUP.equals(action)) {
            int l = data.length();
            if (0 == l) {
                callbackContext.error("Expecting at least 1 parameter for action: " + action);
                return false;
            }
            clientTypes = data.getInt(0);
            String[] extraScopes = new String[l - 1];
            for (int i = 1; i < l; i++) {
                extraScopes[i - 1] = data.getString(i);
            }
            setup(clientTypes, extraScopes, callbackContext);
            PluginResult pluginResult = new PluginResult(PluginResult.Status.NO_RESULT);
            pluginResult.setKeepCallback(true);
            callbackContext.sendPluginResult(pluginResult);
        } else if (ACTION_SIGNIN.equals(action)) {
            mHelper.beginUserInitiatedSignIn();
            callbackContext.success();
        } else if (ACTION_SIGNOUT.equals(action)) {
            signout();
            callbackContext.success();
        } else if (ACTION_AS_MAX_KEYS.equals(action)) {
            PluginResult pluginResult = new PluginResult(PluginResult.Status.OK,
                    mHelper.getAppStateClient().getMaxNumKeys());
            pluginResult.setKeepCallback(false);
            callbackContext.sendPluginResult(pluginResult);
        } else if (ACTION_AS_MAX_SIZE.equals(action)) {
            PluginResult pluginResult = new PluginResult(PluginResult.Status.OK,
                    mHelper.getAppStateClient().getMaxStateSize());
            pluginResult.setKeepCallback(false);
            callbackContext.sendPluginResult(pluginResult);
        } else if (ACTION_AS_DEL.equals(action)) {
            int key = data.getInt(0);
            mHelper.getAppStateClient().deleteState(this, key);
            callbackContext.success();
        } else if (ACTION_AS_LIST.equals(action)) {
            mHelper.getAppStateClient().listStates(this);
            callbackContext.success();
        } else if (ACTION_AS_LOAD.equals(action)) {
            int key = data.getInt(0);
            mHelper.getAppStateClient().loadState(this, key);
            callbackContext.success();
        } else if (ACTION_AS_RESOLVE.equals(action)) {
            int key = data.getInt(0);
            String resolvedVersion = data.getString(1);
            String value = data.getString(2);
            mHelper.getAppStateClient().resolveState(this, key, resolvedVersion, value.getBytes());
            callbackContext.success();
        } else if (ACTION_AS_UPDATE.equals(action)) {
            int key = data.getInt(0);
            String value = data.getString(1);
            mHelper.getAppStateClient().updateState(key, value.getBytes());
            callbackContext.success();
        } else if (ACTION_AS_UPDATE_NOW.equals(action)) {
            int key = data.getInt(0);
            String value = data.getString(1);
            mHelper.getAppStateClient().updateStateImmediate(this, key, value.getBytes());
            callbackContext.success();
        } else if (ACTION_GAME_SHOW_ACHIEVEMENTS.equals(action)) {
            cordova.startActivityForResult((CordovaPlugin) this,
                    mHelper.getGamesClient().getAchievementsIntent(), RC_UNUSED);
            callbackContext.success();
        } else if (ACTION_GAME_SHOW_LEADERBOARDS.equals(action)) {
            cordova.startActivityForResult((CordovaPlugin) this,
                    mHelper.getGamesClient().getAllLeaderboardsIntent(), RC_UNUSED);
            callbackContext.success();
        } else if (ACTION_GAME_SHOW_LEADERBOARD.equals(action)) {
            String id = data.getString(0);
            cordova.startActivityForResult((CordovaPlugin) this,
                    mHelper.getGamesClient().getLeaderboardIntent(id), RC_UNUSED);
            callbackContext.success();
        } else if (ACTION_GAME_INCR_ACHIEVEMENT.equals(action)) {
            String id = data.getString(0);
            int numSteps = data.getInt(1);
            mHelper.getGamesClient().incrementAchievement(id, numSteps);
            callbackContext.success();
        } else if (ACTION_GAME_INCR_ACHIEVEMENT_NOW.equals(action)) {
            String id = data.getString(0);
            int numSteps = data.getInt(1);
            mHelper.getGamesClient().incrementAchievementImmediate(this, id, numSteps);
            callbackContext.success();
        } else if (ACTION_GAME_LOAD_ACHIEVEMENTS.equals(action)) {
            boolean forceReload = data.getBoolean(0);
            mHelper.getGamesClient().loadAchievements(this, forceReload);
            callbackContext.success();
        } else if (ACTION_GAME_LOAD_GAME.equals(action)) {
            mHelper.getGamesClient().loadGame(this);
            callbackContext.success();
        } else if (ACTION_GAME_LOAD_LEADERBOARD_METADATA.equals(action)) {
            if (1 == data.length()) {
                mHelper.getGamesClient().loadLeaderboardMetadata(this, data.getBoolean(0));
            } else {
                mHelper.getGamesClient().loadLeaderboardMetadata(this, data.getString(0), data.getBoolean(1));
            }
            callbackContext.success();
        } else if (ACTION_GAME_LOAD_MORE_SCORES.equals(action)) {
            if (null == scoreBuffer) {
                callbackContext.error("Get a leaderboard fist before calling: " + action);
                return false;
            }
            int maxResults = data.getInt(0);
            int pageDirection = data.getInt(0);
            mHelper.getGamesClient().loadMoreScores(this, scoreBuffer, maxResults, pageDirection);
            callbackContext.success();
        } else if (ACTION_GAME_LOAD_PLAYER.equals(action)) {
            String playerId = data.getString(0);
            mHelper.getGamesClient().loadPlayer(this, playerId);
            callbackContext.success();
        } else if (ACTION_GAME_LOAD_PLAYER_CENTERED_SCORES.equals(action)) {
            String leaderboardId = data.getString(0);
            int span = data.getInt(1);
            int leaderboardCollection = data.getInt(2);
            int maxResults = data.getInt(3);
            if (data.isNull(4)) {
                mHelper.getGamesClient().loadPlayerCenteredScores(this, leaderboardId, span,
                        leaderboardCollection, maxResults);
            } else {
                boolean forceReload = data.getBoolean(4);
                mHelper.getGamesClient().loadPlayerCenteredScores(this, leaderboardId, span,
                        leaderboardCollection, maxResults, forceReload);
            }
            callbackContext.success();
        } else if (ACTION_GAME_LOAD_TOP_SCORES.equals(action)) {
            String leaderboardId = data.getString(0);
            int span = data.getInt(1);
            int leaderboardCollection = data.getInt(2);
            int maxResults = data.getInt(3);
            if (data.isNull(4)) {
                mHelper.getGamesClient().loadTopScores(this, leaderboardId, span, leaderboardCollection,
                        maxResults);
            } else {
                boolean forceReload = data.getBoolean(4);
                mHelper.getGamesClient().loadTopScores(this, leaderboardId, span, leaderboardCollection,
                        maxResults, forceReload);
            }
            callbackContext.success();
        } else if (ACTION_GAME_REVEAL_ACHIEVEMENT.equals(action)) {
            String id = data.getString(0);
            mHelper.getGamesClient().revealAchievement(id);
            callbackContext.success();
        } else if (ACTION_GAME_REVEAL_ACHIEVEMENT_NOW.equals(action)) {
            String id = data.getString(0);
            mHelper.getGamesClient().revealAchievementImmediate(this, id);
            callbackContext.success();
        } else if (ACTION_GAME_SUBMIT_SCORE.equals(action)) {
            String leaderboardId = data.getString(0);
            int score = data.getInt(1);
            mHelper.getGamesClient().submitScore(leaderboardId, score);
            callbackContext.success();
        } else if (ACTION_GAME_SUBMIT_SCORE_NOW.equals(action)) {
            String leaderboardId = data.getString(0);
            int score = data.getInt(1);
            mHelper.getGamesClient().submitScoreImmediate(this, leaderboardId, score);
            callbackContext.success();
        } else if (ACTION_GAME_UNLOCK_ACHIEVEMENT.equals(action)) {
            String id = data.getString(0);
            mHelper.getGamesClient().unlockAchievement(id);
            callbackContext.success();
        } else if (ACTION_GAME_UNLOCK_ACHIEVEMENT_NOW.equals(action)) {
            String id = data.getString(0);
            mHelper.getGamesClient().unlockAchievementImmediate(this, id);
            callbackContext.success();
        } else {
            callbackContext.error("Unknown action: " + action);
            return false;
        }
    } catch (JSONException ex) {
        callbackContext.error(ex.getMessage());
        return false;
    }

    return true;
}

From source file:com.aokyu.dev.pocket.ModifyResponse.java

public boolean[] getActionResults() throws JSONException {
    JSONArray jsonArray = (JSONArray) get(Parameter.ACTION_RESULTS);
    int size = jsonArray.length();
    boolean[] results = new boolean[size];
    for (int i = 0; i < size; i++) {
        results[i] = jsonArray.getBoolean(i);
    }/*from w w  w  .j  a v a  2s.  com*/
    return results;
}

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 w  w. ja  v a 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();
        //webView
        //
        final String position = args.getString(0);
        Log.d(LOG_TAG, position);
        final String size = args.getString(1);
        Log.d(LOG_TAG, size);

        //
        boolean bannerIsShowing = false;
        if (isOverlap) {
            if (bannerView != null) {
                //if banner is showing
                RelativeLayout bannerViewLayout = (RelativeLayout) bannerView.getParent();
                if (bannerViewLayout != null) {
                    bannerIsShowing = true;
                }
            }
        } else {
            if (bannerView != null) {
                //if banner is showing
                ViewGroup parentView = (ViewGroup) bannerView.getParent();
                if (parentView != null) {
                    bannerIsShowing = true;
                }
            }
        }
        if (bannerIsShowing && position.equals(this.position) && size.equals(this.size)) {
            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;
        }

        bannerViewCC = callbackContext;

        final CallbackContext delayedCC = callbackContext;
        cordova.getActivity().runOnUiThread(new Runnable() {
            @Override
            public void run() {
                _showBannerAd(position, size);
            }
        });

        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:run.ace.NativeHost.java

public boolean execute(String action, JSONArray args, CallbackContext callbackContext) throws JSONException {
    // Don't run any of these if the current activity is finishing.
    if (_activity.isFinishing())
        return true;

    if (action.equals("send")) {
        this.send(args, callbackContext);
    } else if (action.equals("loadXbf")) {
        this.loadXbf(args.getString(0), callbackContext);
    } else if (action.equals("initialize")) {
        ///*w w w.  j  av  a 2s. com*/
        // Do not initialize unsupported android versions
        //
        if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.KITKAT) {
            return true;
        }

        OutgoingMessages.setCallbackContext(callbackContext);
        /* TODO: No startup markup
        if (_startupMarkup != null) {
        // Send the bytes back to the managed side.
        // Do it directly instead of using OutgoingMessages.raiseEvent
        // Because otherwise it gets marshaled as an array instead of an ArrayBuffer
          PluginResult r = new PluginResult(PluginResult.Status.OK, _startupMarkup);
          r.setKeepCallback(true);
        callbackContext.sendPluginResult(r);
        _startupMarkup = null;
        }
        */
    } else if (action.equals("loadPlatformSpecificMarkup")) {
        this.loadPlatformSpecificMarkup(args.getString(0), callbackContext);
    } else if (action.equals("getAndroidId")) {
        this.getAndroidId(args.getString(0), callbackContext);
    } else if (action.equals("startAndroidActivity")) {
        this.startAndroidActivity(args.getString(0), callbackContext);
    } else if (action.equals("setPopupsCloseOnHtmlNavigation")) {
        this.setPopupsCloseOnHtmlNavigation(args.getBoolean(0), callbackContext);
    } else if (action.equals("isSupported")) {
        boolean supported = android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.KITKAT;
        callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK, supported));
    } else {
        return false;
    }

    return true;
}