Example usage for org.json JSONArray getInt

List of usage examples for org.json JSONArray getInt

Introduction

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

Prototype

public int getInt(int index) throws JSONException 

Source Link

Document

Get the int value associated with an index.

Usage

From source file:com.transistorsoft.cordova.bggeo.CDVBackgroundGeolocation.java

public boolean execute(String action, JSONArray data, CallbackContext callbackContext) throws JSONException {
    Log.d(TAG, "$ " + action + "()");

    Boolean result = false;//from   www  . jav  a 2s. co  m

    if (BackgroundGeolocationService.ACTION_START.equalsIgnoreCase(action)) {
        result = true;
        if (!isStarting) {
            this.start(callbackContext);
        } else {
            callbackContext.error("- Waiting for previous start action to complete");
        }
    } else if (BackgroundGeolocationService.ACTION_STOP.equalsIgnoreCase(action)) {
        // No implementation to stop background-tasks with Android.  Just say "success"
        result = true;
        this.stop();
        callbackContext.success(0);
    } else if (ACTION_FINISH.equalsIgnoreCase(action)) {
        result = true;
        callbackContext.success();
    } else if (ACTION_ERROR.equalsIgnoreCase(action)) {
        result = true;
        this.onError(data.getString(1));
        callbackContext.success();
    } else if (ACTION_CONFIGURE.equalsIgnoreCase(action)) {
        result = true;
        configure(data.getJSONObject(0), callbackContext);
    } else if (ACTION_ADD_LOCATION_LISTENER.equalsIgnoreCase(action)) {
        result = true;
        addLocationListener(callbackContext);
    } else if (BackgroundGeolocationService.ACTION_CHANGE_PACE.equalsIgnoreCase(action)) {
        result = true;
        if (!isEnabled) {
            Log.w(TAG, "- Cannot change pace while disabled");
            callbackContext.error("Cannot #changePace while disabled");
        } else {
            changePace(callbackContext, data);
        }
    } else if (BackgroundGeolocationService.ACTION_SET_CONFIG.equalsIgnoreCase(action)) {
        result = true;
        JSONObject config = data.getJSONObject(0);
        setConfig(config);
        callbackContext.success();
    } else if (ACTION_GET_STATE.equalsIgnoreCase(action)) {
        result = true;
        JSONObject state = this.getState();
        PluginResult response = new PluginResult(PluginResult.Status.OK, state);
        response.setKeepCallback(false);
        callbackContext.sendPluginResult(response);
    } else if (ACTION_ADD_MOTION_CHANGE_LISTENER.equalsIgnoreCase(action)) {
        result = true;
        this.addMotionChangeListener(callbackContext);
    } else if (BackgroundGeolocationService.ACTION_GET_LOCATIONS.equalsIgnoreCase(action)) {
        result = true;
        getLocations(callbackContext);
    } else if (BackgroundGeolocationService.ACTION_SYNC.equalsIgnoreCase(action)) {
        result = true;
        sync(callbackContext);
    } else if (BackgroundGeolocationService.ACTION_GET_ODOMETER.equalsIgnoreCase(action)) {
        result = true;
        getOdometer(callbackContext);
    } else if (BackgroundGeolocationService.ACTION_RESET_ODOMETER.equalsIgnoreCase(action)) {
        result = true;
        resetOdometer(callbackContext);
    } else if (BackgroundGeolocationService.ACTION_ADD_GEOFENCE.equalsIgnoreCase(action)) {
        result = true;
        addGeofence(callbackContext, data.getJSONObject(0));
    } else if (BackgroundGeolocationService.ACTION_ADD_GEOFENCES.equalsIgnoreCase(action)) {
        result = true;
        addGeofences(callbackContext, data.getJSONArray(0));
    } else if (BackgroundGeolocationService.ACTION_REMOVE_GEOFENCE.equalsIgnoreCase(action)) {
        result = removeGeofence(data.getString(0));
        if (result) {
            callbackContext.success();
        } else {
            callbackContext.error("Failed to add geofence");
        }
    } else if (BackgroundGeolocationService.ACTION_REMOVE_GEOFENCES.equalsIgnoreCase(action)) {
        result = removeGeofences();
        if (result) {
            callbackContext.success();
        } else {
            callbackContext.error("Failed to add geofence");
        }
    } else if (BackgroundGeolocationService.ACTION_ON_GEOFENCE.equalsIgnoreCase(action)) {
        result = true;
        addGeofenceListener(callbackContext);
    } else if (BackgroundGeolocationService.ACTION_GET_GEOFENCES.equalsIgnoreCase(action)) {
        result = true;
        getGeofences(callbackContext);
    } else if (ACTION_PLAY_SOUND.equalsIgnoreCase(action)) {
        result = true;
        playSound(data.getInt(0));
        callbackContext.success();
    } else if (BackgroundGeolocationService.ACTION_GET_CURRENT_POSITION.equalsIgnoreCase(action)) {
        result = true;
        JSONObject options = data.getJSONObject(0);
        getCurrentPosition(callbackContext, options);
    } else if (BackgroundGeolocationService.ACTION_BEGIN_BACKGROUND_TASK.equalsIgnoreCase(action)) {
        // Android doesn't do background-tasks.  This is an iOS thing.  Just return a number.
        result = true;
        callbackContext.success(1);
    } else if (BackgroundGeolocationService.ACTION_CLEAR_DATABASE.equalsIgnoreCase(action)) {
        result = true;
        clearDatabase(callbackContext);
    } else if (ACTION_ADD_HTTP_LISTENER.equalsIgnoreCase(action)) {
        result = true;
        addHttpListener(callbackContext);
    } else if (ACTION_GET_LOG.equalsIgnoreCase(action)) {
        result = true;
        getLog(callbackContext);
    } else if (ACTION_EMAIL_LOG.equalsIgnoreCase(action)) {
        result = true;
        emailLog(callbackContext, data.getString(0));
    } else if (BackgroundGeolocationService.ACTION_INSERT_LOCATION.equalsIgnoreCase(action)) {
        result = true;
        insertLocation(data.getJSONObject(0), callbackContext);
    } else if (BackgroundGeolocationService.ACTION_GET_COUNT.equalsIgnoreCase(action)) {
        result = true;
        getCount(callbackContext);
    }
    return result;
}

From source file:com.mparticle.internal.ConfigManager.java

public boolean shouldTrigger(MPMessage message) {
    JSONArray messageMatches = getTriggerMessageMatches();
    JSONArray triggerHashes = getTriggerMessageHashes();

    //always trigger for PUSH_RECEIVED
    boolean shouldTrigger = message.getMessageType().equals(Constants.MessageType.PUSH_RECEIVED)
            || message.getMessageType().equals(Constants.MessageType.COMMERCE_EVENT);

    if (!shouldTrigger && messageMatches != null && messageMatches.length() > 0) {
        shouldTrigger = true;//  w w w.j  a  v a2s  .  c o m
        int i = 0;
        while (shouldTrigger && i < messageMatches.length()) {
            try {
                JSONObject messageMatch = messageMatches.getJSONObject(i);
                Iterator<?> keys = messageMatch.keys();
                while (shouldTrigger && keys.hasNext()) {
                    String key = (String) keys.next();
                    shouldTrigger = message.has(key);
                    if (shouldTrigger) {
                        try {
                            shouldTrigger = messageMatch.getString(key)
                                    .equalsIgnoreCase(message.getString(key));
                        } catch (JSONException stringex) {
                            try {
                                shouldTrigger = message.getBoolean(key) == messageMatch.getBoolean(key);
                            } catch (JSONException boolex) {
                                try {
                                    shouldTrigger = message.getDouble(key) == messageMatch.getDouble(key);
                                } catch (JSONException doubleex) {
                                    shouldTrigger = false;
                                }
                            }
                        }
                    }
                }
            } catch (Exception e) {

            }
            i++;
        }
    }
    if (!shouldTrigger && triggerHashes != null) {
        for (int i = 0; i < triggerHashes.length(); i++) {
            try {
                if (triggerHashes.getInt(i) == message.getTypeNameHash()) {
                    shouldTrigger = true;
                    break;
                }
            } catch (JSONException jse) {

            }
        }
    }
    return shouldTrigger;
}

From source file:samurai.geeft.android.geeft.utilities.GCM.MyGcmListenerService.java

private void parseCostum(String custom) {
    try {//from w  ww  . jav a2s. c o m
        JSONObject obj = new JSONObject(custom);
        JSONArray array = obj.getJSONArray("custom");
        key = array.getInt(0);
        geeftId = array.getString(1);
        docUserId = array.getString(2);

        Log.d(TAG, "key: " + key);
        Log.d(TAG, "geeftId:" + geeftId);
        Log.d(TAG, "doc_id: " + docUserId);
        if (docUserId.equals(""))
            docUserId = null;
        //} catch (org.json.JSONException t) {
    } catch (Exception t) {
        Log.e(TAG, "Could not parse malformed JSON: \"" + custom + "\"");
        //startMainActivity();
    }
}

From source file:com.liferay.mobile.android.v7.organization.OrganizationService.java

public Integer getOrganizationsCount(long companyId, long parentOrganizationId) throws Exception {
    JSONObject _command = new JSONObject();

    try {// ww w .j  ava 2  s  .c om
        JSONObject _params = new JSONObject();

        _params.put("companyId", companyId);
        _params.put("parentOrganizationId", parentOrganizationId);

        _command.put("/organization/get-organizations-count", _params);
    } catch (JSONException _je) {
        throw new Exception(_je);
    }

    JSONArray _result = session.invoke(_command);

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

    return _result.getInt(0);
}

From source file:org.akvo.caddisfly.sensor.colorimetry.strip.detect.DetectStripTask.java

@Nullable
@Override/*w w w .  j  a  v a  2  s . c om*/
protected Void doInBackground(Intent... params) {
    Intent intent = params[0];

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

    String uuid = intent.getStringExtra(Constant.UUID);

    StripTest stripTest = new StripTest();
    int numPatches = stripTest.getPatchCount(uuid);

    format = intent.getIntExtra(Constant.FORMAT, ImageFormat.NV21);
    width = intent.getIntExtra(Constant.WIDTH, 0);
    height = intent.getIntExtra(Constant.HEIGHT, 0);

    if (width == 0 || height == 0) {
        return null;
    }

    JSONArray imagePatchArray = null;
    int imageCount = -1;
    Mat labImg; // Mat for image from NV21 data
    Mat labStrip; // Mat for detected strip

    try {
        String json = FileUtil.readFromInternalStorage(context, Constant.IMAGE_PATCH);
        imagePatchArray = new JSONArray(json);
    } catch (Exception e) {
        Timber.e(e);
    }

    for (int i = 0; i < numPatches; i++) {
        try {
            if (imagePatchArray != null) {
                // sub-array for each patch
                JSONArray array = imagePatchArray.getJSONArray(i);

                // get the image number from the json array
                int imageNo = array.getInt(0);

                if (imageNo > imageCount) {

                    // Set imageCount to current number
                    imageCount = imageNo;

                    byte[] data = FileUtil.readByteArray(context, Constant.DATA + imageNo);
                    if (data == null) {
                        throw new IOException();
                    }

                    //make a L,A,B Mat object from data
                    try {
                        labImg = makeLab(data);
                    } catch (Exception e) {
                        if (context != null) {
                            Timber.e(e);
                        }
                        continue;
                    }

                    //perspectiveTransform
                    try {
                        if (labImg != null) {
                            warp(labImg, imageNo);
                        }
                    } catch (Exception e) {
                        if (context != null) {
                            Timber.e(e);
                        }
                        continue;
                    }

                    //divide into calibration and strip areas
                    try {
                        if (context != null) {
                            divideIntoCalibrationAndStripArea();
                        }
                    } catch (Exception e) {
                        Timber.e(e);
                        continue;
                    }

                    //save warped image to external storage
                    //                        if (DEVELOP_MODE) {
                    //                        Mat rgb = new Mat();
                    //                        Imgproc.cvtColor(warpMat, rgb, Imgproc.COLOR_Lab2RGB);
                    //                        Bitmap bitmap = Bitmap.createBitmap(rgb.width(), rgb.height(), Bitmap.Config.ARGB_8888);
                    //                        Utils.matToBitmap(rgb, bitmap);
                    //
                    //                        //if (FileUtil.isExternalStorageWritable()) {
                    //                        FileUtil.writeBitmapToExternalStorage(bitmap, "/warp", UUID.randomUUID().toString() + ".png");
                    //}
                    //                            //Bitmap.createScaledBitmap(bitmap, BITMAP_SCALED_WIDTH, BITMAP_SCALED_HEIGHT, false);
                    //                        }

                    //calibrate
                    Mat calibrationMat;
                    try {
                        CalibrationResultData calResult = getCalibratedImage(warpMat);
                        if (calResult == null) {
                            return null;
                        } else {
                            calibrationMat = calResult.getCalibratedImage();
                        }

                        //                            Log.d(this.getClass().getSimpleName(), "E94 error mean: " + String.format(Locale.US, "%.2f", calResult.meanE94)
                        //                                    + ", max: " + String.format(Locale.US, "%.2f", calResult.maxE94)
                        //                                    + ", total: " + String.format(Locale.US, "%.2f", calResult.totalE94));

                        //                            if (AppPreferences.isDiagnosticMode()) {
                        //                                listener.showError("E94 mean: " + String.format(Locale.US, "%.2f", calResult.meanE94)
                        //                                        + ", max: " + String.format(Locale.US, "%.2f", calResult.maxE94)
                        //                                        + ", total: " + String.format(Locale.US, "%.2f", calResult.totalE94));
                        //                            }
                    } catch (Exception e) {
                        Timber.e(e);
                        return null;
                    }

                    //show calibrated image
                    //                        if (DEVELOP_MODE) {
                    //                            Mat rgb = new Mat();
                    //                            Imgproc.cvtColor(calibrationMat, rgb, Imgproc.COLOR_Lab2RGB);
                    //                            Bitmap bitmap = Bitmap.createBitmap(rgb.width(), rgb.height(), Bitmap.Config.ARGB_8888);
                    //                            Utils.matToBitmap(rgb, bitmap);
                    //                            if (FileUtil.isExternalStorageWritable()) {
                    //                                FileUtil.writeBitmapToExternalStorage(bitmap, "/warp", UUID.randomUUID().toString() + "_cal.png");
                    //                            }
                    //                            //Bitmap.createScaledBitmap(bitmap, BITMAP_SCALED_WIDTH, BITMAP_SCALED_HEIGHT, false);
                    //                        }

                    // cut out black area that contains the strip
                    Mat stripArea = null;
                    if (roiStripArea != null) {
                        stripArea = calibrationMat.submat(roiStripArea);
                    }

                    if (stripArea != null) {
                        Mat strip = null;
                        try {
                            StripTest.Brand brand = stripTest.getBrand(uuid);
                            strip = OpenCVUtil.detectStrip(stripArea, brand, ratioW, ratioH);
                        } catch (Exception e) {
                            Timber.e(e);
                        }

                        String error = "";
                        if (strip != null) {
                            labStrip = strip.clone();
                        } else {
                            if (context != null) {
                                Timber.e(context.getString(R.string.error_calibrating));
                            }
                            labStrip = stripArea.clone();

                            error = Constant.ERROR;

                            //draw a red cross over the image
                            Scalar red = RED_LAB_COLOR; // Lab color
                            Imgproc.line(labStrip, new Point(0, 0), new Point(labStrip.cols(), labStrip.rows()),
                                    red, 2);
                            Imgproc.line(labStrip, new Point(0, labStrip.rows()), new Point(labStrip.cols(), 0),
                                    red, 2);
                        }

                        try {
                            // create byte[] from Mat and store it in internal storage
                            // In order to restore the byte array, we also need the rows and columns dimensions
                            // these are stored in the last 8 bytes
                            int dataSize = labStrip.cols() * labStrip.rows() * 3;
                            byte[] payload = new byte[dataSize + 8];
                            byte[] matByteArray = new byte[dataSize];

                            labStrip.get(0, 0, matByteArray);

                            // pack cols and rows into byte arrays
                            byte[] rows = FileUtil.leIntToByteArray(labStrip.rows());
                            byte[] cols = FileUtil.leIntToByteArray(labStrip.cols());

                            // append them to the end of the array, in order rows, cols
                            System.arraycopy(matByteArray, 0, payload, 0, dataSize);
                            System.arraycopy(rows, 0, payload, dataSize, 4);
                            System.arraycopy(cols, 0, payload, dataSize + 4, 4);
                            FileUtil.writeByteArray(context, payload, Constant.STRIP + imageNo + error);
                        } catch (Exception e) {
                            Timber.e(e);
                        }
                    }
                }
            }
        } catch (@NonNull JSONException | IOException e) {

            if (context != null) {
                Timber.e(context.getString(R.string.error_cut_out_strip));
            }
        }
    }
    return null;
}

From source file:com.polychrom.cordova.ActionBarPlugin.java

@Override
public boolean execute(final String action, final JSONArray args, final CallbackContext callbackContext)
        throws JSONException {
    if (!plugin_actions.contains(action)) {
        return false;
    }//from   w  w  w .  ja  va  2  s  .c o  m

    final Activity ctx = (Activity) cordova;

    if ("isAvailable".equals(action)) {
        JSONObject result = new JSONObject();
        result.put("value", ctx.getWindow().hasFeature(Window.FEATURE_ACTION_BAR));
        callbackContext.success(result);
        return true;
    }

    final ActionBar bar = ctx.getActionBar();
    if (bar == null) {
        Window window = ctx.getWindow();
        if (!window.hasFeature(Window.FEATURE_ACTION_BAR)) {
            callbackContext
                    .error("ActionBar feature not available, Window.FEATURE_ACTION_BAR must be enabled!");
        } else {
            callbackContext.error("Failed to get ActionBar");
        }

        return true;
    }

    if (menu == null) {
        callbackContext.error("Options menu not initialised");
        return true;
    }

    final StringBuffer error = new StringBuffer();
    JSONObject result = new JSONObject();

    if ("isShowing".equals(action)) {
        result.put("value", bar.isShowing());
    } else if ("getHeight".equals(action)) {
        result.put("value", bar.getHeight());
    } else if ("getDisplayOptions".equals(action)) {
        result.put("value", bar.getDisplayOptions());
    } else if ("getNavigationMode".equals(action)) {
        result.put("value", bar.getNavigationMode());
    } else if ("getSelectedNavigationItem".equals(action)) {
        result.put("value", bar.getSelectedNavigationIndex());
    } else if ("getSubtitle".equals(action)) {
        result.put("value", bar.getSubtitle());
    } else if ("getTitle".equals(action)) {
        result.put("value", bar.getTitle());
    } else {
        try {
            JSONException exception = new Runnable() {
                public JSONException exception = null;

                public void run() {
                    try {
                        // This is a bit of a hack (should be specific to the request, not global)
                        bases = new String[] { removeFilename(webView.getOriginalUrl()),
                                removeFilename(webView.getUrl()) };

                        if ("show".equals(action)) {
                            bar.show();
                        } else if ("hide".equals(action)) {
                            bar.hide();
                        } else if ("setMenu".equals(action)) {
                            if (args.isNull(0)) {
                                error.append("menu can not be null");
                                return;
                            }

                            menu_definition = args.getJSONArray(0);

                            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
                                ctx.invalidateOptionsMenu();
                            }
                        } else if ("setTabs".equals(action)) {
                            if (args.isNull(0)) {
                                error.append("menu can not be null");
                                return;
                            }

                            bar.removeAllTabs();
                            tab_callbacks.clear();

                            if (!buildTabs(bar, args.getJSONArray(0))) {
                                error.append("Invalid tab bar definition");
                            }
                        } else if ("setDisplayHomeAsUpEnabled".equals(action)) {
                            if (args.isNull(0)) {
                                error.append("showHomeAsUp can not be null");
                                return;
                            }

                            bar.setDisplayHomeAsUpEnabled(args.getBoolean(0));
                        } else if ("setDisplayOptions".equals(action)) {
                            if (args.isNull(0)) {
                                error.append("options can not be null");
                                return;
                            }

                            final int options = args.getInt(0);
                            bar.setDisplayOptions(options);
                        } else if ("setDisplayShowHomeEnabled".equals(action)) {
                            if (args.isNull(0)) {
                                error.append("showHome can not be null");
                                return;
                            }

                            bar.setDisplayShowHomeEnabled(args.getBoolean(0));
                        } else if ("setDisplayShowTitleEnabled".equals(action)) {
                            if (args.isNull(0)) {
                                error.append("showTitle can not be null");
                                return;
                            }

                            bar.setDisplayShowTitleEnabled(args.getBoolean(0));
                        } else if ("setDisplayUseLogoEnabled".equals(action)) {
                            if (args.isNull(0)) {
                                error.append("useLogo can not be null");
                                return;
                            }

                            bar.setDisplayUseLogoEnabled(args.getBoolean(0));
                        } else if ("setHomeButtonEnabled".equals(action)) {
                            if (args.isNull(0)) {
                                error.append("enabled can not be null");
                                return;
                            }

                            bar.setHomeButtonEnabled(args.getBoolean(0));
                        } else if ("setIcon".equals(action)) {
                            if (args.isNull(0)) {
                                error.append("icon can not be null");
                                return;
                            }

                            Drawable drawable = getDrawableForURI(args.getString(0));
                            bar.setIcon(drawable);
                        } else if ("setListNavigation".equals(action)) {
                            JSONArray items = null;
                            if (args.isNull(0) == false) {
                                items = args.getJSONArray(0);
                            }

                            navigation_adapter.setItems(items);
                            bar.setListNavigationCallbacks(navigation_adapter, navigation_listener);
                        } else if ("setLogo".equals(action)) {
                            if (args.isNull(0)) {
                                error.append("logo can not be null");
                                return;
                            }

                            Drawable drawable = getDrawableForURI(args.getString(0));
                            bar.setLogo(drawable);
                        } else if ("setNavigationMode".equals(action)) {
                            if (args.isNull(0)) {
                                error.append("mode can not be null");
                                return;
                            }

                            final int mode = args.getInt(0);
                            bar.setNavigationMode(mode);
                        } else if ("setSelectedNavigationItem".equals(action)) {
                            if (args.isNull(0)) {
                                error.append("position can not be null");
                                return;
                            }

                            bar.setSelectedNavigationItem(args.getInt(0));
                        } else if ("setSubtitle".equals(action)) {
                            if (args.isNull(0)) {
                                error.append("subtitle can not be null");
                                return;
                            }

                            bar.setSubtitle(args.getString(0));
                        } else if ("setTitle".equals(action)) {
                            if (args.isNull(0)) {
                                error.append("title can not be null");
                                return;
                            }

                            bar.setTitle(args.getString(0));
                        }
                    } catch (JSONException e) {
                        exception = e;
                    } finally {
                        synchronized (this) {
                            this.notify();
                        }
                    }
                }

                // Run task synchronously
                {
                    synchronized (this) {
                        ctx.runOnUiThread(this);
                        this.wait();
                    }
                }
            }.exception;

            if (exception != null) {
                throw exception;
            }
        } catch (InterruptedException e) {
            error.append("Function interrupted on UI thread");
        }
    }

    if (error.length() == 0) {
        if (result.length() > 0) {
            callbackContext.success(result);
        } else {
            callbackContext.success();
        }
    } else {
        callbackContext.error(error.toString());
    }

    return true;
}

From source file:com.liferay.mobile.android.v62.user.UserService.java

public Integer getCompanyUsersCount(long companyId) throws Exception {
    JSONObject _command = new JSONObject();

    try {/* w  w w  . j  a v a 2s  . co  m*/
        JSONObject _params = new JSONObject();

        _params.put("companyId", companyId);

        _command.put("/user/get-company-users-count", _params);
    } catch (JSONException _je) {
        throw new Exception(_je);
    }

    JSONArray _result = session.invoke(_command);

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

    return _result.getInt(0);
}

From source file:com.hichinaschool.flashcards.libanki.Sched.java

public void extendLimits(int newc, int rev) {
    JSONObject cur = mCol.getDecks().current();
    ArrayList<JSONObject> decks = new ArrayList<JSONObject>();
    decks.add(cur);//from  w w w  .j av a2 s.com
    try {
        decks.addAll(mCol.getDecks().parents(cur.getLong("id")));
        for (long did : mCol.getDecks().children(cur.getLong("id")).values()) {
            decks.add(mCol.getDecks().get(did));
        }
        for (JSONObject g : decks) {
            // add
            JSONArray ja = g.getJSONArray("newToday");
            ja.put(1, ja.getInt(1) - newc);
            g.put("newToday", ja);
            ja = g.getJSONArray("revToday");
            ja.put(1, ja.getInt(1) - rev);
            g.put("revToday", ja);
            mCol.getDecks().save(g);
        }
    } catch (JSONException e) {
        throw new RuntimeException(e);
    }
}

From source file:com.hichinaschool.flashcards.libanki.Sched.java

private int _graduatingIvl(Card card, JSONObject conf, boolean early, boolean adj) {
    if (card.getType() == 2) {
        // lapsed card being relearnt
        if (card.getODid() != 0) {
            try {
                if (conf.getBoolean("resched")) {
                    return _dynIvlBoost(card);
                }//from  w  w w  .j a v a2  s .com
            } catch (JSONException e) {
                throw new RuntimeException(e);
            }
        }
        return card.getIvl();
    }
    int ideal;
    JSONArray ja;
    try {
        ja = conf.getJSONArray("ints");
        if (!early) {
            // graduate
            ideal = ja.getInt(0);
        } else {
            ideal = ja.getInt(1);
        }
        if (adj) {
            return _adjRevIvl(card, ideal);
        } else {
            return ideal;
        }
    } catch (JSONException e) {
        throw new RuntimeException(e);
    }
}

From source file:com.hichinaschool.flashcards.libanki.Sched.java

private List<Long> _fillDyn(JSONObject deck) {
    JSONArray terms;
    List<Long> ids;/*from w  ww. j  a  v a2 s  . com*/
    try {
        terms = deck.getJSONArray("terms").getJSONArray(0);
        String search = terms.getString(0);
        int limit = terms.getInt(1);
        int order = terms.getInt(2);
        String orderlimit = _dynOrder(order, limit);
        search += " -is:suspended -is:buried -deck:filtered";
        ids = mCol.findCards(search, orderlimit);
        if (ids.isEmpty()) {
            return ids;
        }
        // move the cards over
        _moveToDyn(deck.getLong("id"), ids);
    } catch (JSONException e) {
        throw new RuntimeException(e);
    }
    return ids;
}