Example usage for org.json JSONObject getInt

List of usage examples for org.json JSONObject getInt

Introduction

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

Prototype

public int getInt(String key) throws JSONException 

Source Link

Document

Get the int value associated with a key.

Usage

From source file:fr.immotronic.ubikit.pems.enocean.impl.item.data.EEP07201011DataImpl.java

public static EEP07201011DataImpl constructDataFromRecord(JSONObject lastKnownData) {
    if (lastKnownData == null)
        return new EEP07201011DataImpl(Mode.NO_ACTION, VanePosition.NO_ACTION, FanSpeed.NO_ACTION,
                RoomOccupancy.OCCUPIED, OnOffStatus.ON, 0, Disablement.NOT_DISABLED, Disablement.NOT_DISABLED,
                Disablement.NOT_DISABLED, Disablement.NOT_DISABLED, WindowsStatus.WINDOWS_CLOSED, AlarmState.OK,
                null);//w ww.  j av  a 2  s  .  c  o m

    try {
        Mode mode = Mode.valueOf(lastKnownData.getString("mode"));
        VanePosition vanePosition = VanePosition.valueOf(lastKnownData.getString("vanePosition"));
        FanSpeed fanSpeed = FanSpeed.valueOf(lastKnownData.getString("fanSpeed"));
        RoomOccupancy roomOccupancy = RoomOccupancy.valueOf(lastKnownData.getString("roomOccupancy"));
        OnOffStatus onOffStatus = OnOffStatus.valueOf(lastKnownData.getString("onOffStatus"));

        int errorCode = lastKnownData.getInt("errorCode");
        Disablement windowContactDisablement = Disablement.valueOf(lastKnownData.getString("windowContactD"));
        Disablement keyCardDisablement = Disablement.valueOf(lastKnownData.getString("keyCardD"));
        Disablement externalDisablement = Disablement.valueOf(lastKnownData.getString("externalD"));
        Disablement remoteControllerDisablement = Disablement
                .valueOf(lastKnownData.getString("remoteControllerD"));
        WindowsStatus windowContact = WindowsStatus.valueOf(lastKnownData.getString("windowContact"));
        AlarmState alarmState = AlarmState.valueOf(lastKnownData.getString("alarmState"));

        Date date = new Date(lastKnownData.getLong("date"));

        return new EEP07201011DataImpl(mode, vanePosition, fanSpeed, roomOccupancy, onOffStatus, errorCode,
                windowContactDisablement, keyCardDisablement, externalDisablement, remoteControllerDisablement,
                windowContact, alarmState, date);
    } catch (JSONException e) {
        Logger.error(LC.gi(), null,
                "constructDataFromRecord(): An exception while building a sensorData from a JSONObject SHOULD never happen. Check the code !",
                e);
        return new EEP07201011DataImpl(Mode.NO_ACTION, VanePosition.NO_ACTION, FanSpeed.NO_ACTION,
                RoomOccupancy.OCCUPIED, OnOffStatus.ON, 0, Disablement.NOT_DISABLED, Disablement.NOT_DISABLED,
                Disablement.NOT_DISABLED, Disablement.NOT_DISABLED, WindowsStatus.WINDOWS_CLOSED, AlarmState.OK,
                null);
    }
}

From source file:fr.bde_eseo.eseomega.lacommande.model.LacmdElement.java

public LacmdElement(JSONObject obj) throws JSONException {
    super(obj.getString("name"), obj.getString("idstr"), obj.getInt("hasingredients"), 0,
            obj.getDouble("priceuni"), ID_CAT_ELEMENT);
    this.pricemore = obj.getDouble("pricemore");
    this.stock = obj.getInt("stock");
    this.outofmenu = obj.getInt("outofmenu");
    this.idcat = obj.getString("idcat");
}

From source file:com.appdynamics.monitors.nginx.statsExtractor.UpstreamsStatsExtractor.java

@Override
public Map<String, String> extractStats(JSONObject respJson) {

    JSONObject upstreams = respJson.getJSONObject("upstreams");

    int version = respJson.getInt("version");

    Map<String, String> upstreamsStats = new HashMap<String, String>();
    if (version == 6) {
        upstreamsStats = getUpstreamsStatsV6(upstreams);
    } else if (version == 5) {
        upstreamsStats = getUpstreamsStatsV5(upstreams);
    }//from   w ww  . j  av  a 2 s . c  o m
    return upstreamsStats;
}

From source file:in.neoandroid.neoupdate.neoUpdate.java

private Boolean parseMetafile(JSONObject metafile) {
    double version;
    boolean forceVersion;
    boolean allowed = false;
    try {// w w  w  .ja v a 2 s  .  com
        version = metafile.getDouble("version");
        forceVersion = metafile.getBoolean("forceVersion");
        JSONObject appDetails = metafile.getJSONObject("app");
        JSONArray assets = metafile.getJSONArray("assets");
        JSONArray devices = metafile.getJSONArray("allowedDevices");

        int nAssets = assets.length();
        String packageName = appDetails.getString("packageName");
        int versionCode = appDetails.getInt("versionCode");
        String apkPath = appDetails.getString("APK");
        boolean offlineSupport = appDetails.getBoolean("offlineSupport");

        if (enableDebug) {
            Log.d(TAG, "Version: " + version + ":" + neoUpdateVersion);
            Log.d(TAG, "Package Name: " + packageName + ":" + packageInfo.packageName);
            Log.d(TAG, "APK Path: " + apkPath);
        }

        // Check if it is being updated using offline storage
        if (!offlineSupport && fromOfflineStorage) {
            Log.e(TAG, "Updating from offline storage is disabled for this app?");
            return false;
        }

        db.clearDevicesList();
        for (int i = 0; i < devices.length(); i++) {
            String device = devices.getString(i);
            if (device.length() > 0 && deviceID.compareToIgnoreCase(device) == 0)
                allowed = true;
            db.insertDevice(device);
            if (enableDebug)
                Log.d(TAG, "Device Allowed: " + device);
        }

        // DeviceID or signature error
        if (!allowed)
            return false;

        apkUpdatePath = null;
        if (version > neoUpdateVersion && forceVersion) {
            Log.e(TAG, "neoUpdate seems to be of older version! Required: " + version + " Current: "
                    + neoUpdateVersion);
            return false;
        }

        if (packageInfo.packageName.compareTo(packageName) != 0) {
            Log.e(TAG, "PackageNames don't seem to match - url for some other app? Provided: " + packageName);
            return false;
        }

        if (packageInfo.versionCode < versionCode) {
            // APK Update Required - Lets first do that
            apkUpdatePath = new NewAsset();
            apkUpdatePath.path = apkPath;
            apkUpdatePath.md5 = appDetails.getString("md5");
            return true;
        }

        // Parse the assets
        for (int i = 0; i < nAssets; i++) {
            JSONObject obj = assets.getJSONObject(i);
            NewAsset asset = new NewAsset();
            asset.path = obj.getString("path");
            asset.md5 = obj.getString("md5");

            // Ignore already downloaded files
            if (db.updateAndGetStatus(asset.path, asset.md5) == neoUpdateDB.UPDATE_STATUS.UPDATE_COMPLETE)
                continue;
            filesToDownload.add(asset);
            if (enableDebug) {
                Log.d(TAG, "Enqueued: " + asset.path + " With MD5: " + asset.md5);
            }
        }
        totalFilesToDownload = filesToDownload.size();
    } catch (Exception e) {
        if (enableDebug)
            e.printStackTrace();
        return false;
    }
    return true;
}

From source file:edu.cwru.apo.Login.java

public void onRestRequestComplete(Methods method, JSONObject result) {
    if (method == Methods.login) {
        if (result != null) {
            try {
                String requestStatus = result.getString("requestStatus");
                if (requestStatus.compareTo("valid login") == 0) {
                    Auth.loggedIn = true;
                    Auth.Hmac.setCounter(result.getInt("counter"));
                    Auth.Hmac.setIncrement(result.getInt("increment"));
                    PhoneOpenHelper db = new PhoneOpenHelper(this);
                    if (database == null)
                        database = db.getWritableDatabase();
                    API api = new API(this);
                    if (!api.callMethod(Methods.phone, this, (String[]) null)) {
                        Toast msg = Toast.makeText(this, "Error: Calling phone", Toast.LENGTH_LONG);
                        msg.show();//from w ww.ja  v a  2 s  .co  m
                    }

                } else if (requestStatus.compareTo("invalid username") == 0) {
                    Toast msg = Toast.makeText(getApplicationContext(), "Invalid username", Toast.LENGTH_LONG);
                    msg.show();
                } else if (requestStatus.compareTo("invalid login") == 0) {
                    Toast msg = Toast.makeText(getApplicationContext(), "Invalid username and/or password",
                            Toast.LENGTH_LONG);
                    msg.show();
                } else if (requestStatus.compareTo("no user") == 0) {
                    Toast msg = Toast.makeText(getApplicationContext(), "No username was provided",
                            Toast.LENGTH_LONG);
                    msg.show();
                } else {
                    Toast msg = Toast.makeText(getApplicationContext(), "Invalid requestStatus",
                            Toast.LENGTH_LONG);
                    msg.show();
                }
            } catch (JSONException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        } else {
            Toast msg = Toast.makeText(getApplicationContext(),
                    "Could not contact web server.  Please check your connection", Toast.LENGTH_LONG);
            msg.show();
        }
    } else if (method == Methods.phone) {
        if (result != null) {
            try {
                String requestStatus = result.getString("requestStatus");
                if (requestStatus.compareTo("success") == 0) {
                    SharedPreferences.Editor editor = getSharedPreferences(APO.PREF_FILE_NAME, MODE_PRIVATE)
                            .edit();
                    editor.putLong("updateTime", result.getLong("updateTime"));
                    editor.commit();
                    int numbros = result.getInt("numBros");

                    if (numbros > 0) {
                        JSONArray caseID = result.getJSONArray("caseID");
                        JSONArray first = result.getJSONArray("first");
                        JSONArray last = result.getJSONArray("last");
                        JSONArray phone = result.getJSONArray("phone");
                        JSONArray family = result.getJSONArray("family");
                        ContentValues values;
                        for (int i = 0; i < numbros; i++) {
                            values = new ContentValues();
                            values.put("_id", caseID.getString(i));
                            values.put("first", first.getString(i));
                            values.put("last", last.getString(i));
                            values.put("phone", phone.getString(i));
                            values.put("family", family.getString(i));
                            database.replace("phoneDB", null, values);
                        }
                    }
                    Intent homeIntent = new Intent(Login.this, Home.class);
                    Login.this.startActivity(homeIntent);
                    finish();
                } else if (requestStatus.compareTo("timestamp invalid") == 0) {
                    Toast msg = Toast.makeText(this, "Invalid timestamp.  Please try again.",
                            Toast.LENGTH_LONG);
                    msg.show();
                } else if (requestStatus.compareTo("HMAC invalid") == 0) {
                    Toast msg = Toast.makeText(this,
                            "You have been logged out by the server.  Please log in again.", Toast.LENGTH_LONG);
                    msg.show();
                } else {
                    Toast msg = Toast.makeText(this, "Invalid requestStatus", Toast.LENGTH_LONG);
                    msg.show();
                }
            } catch (JSONException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }
    } else {
        Toast msg = Toast.makeText(getApplicationContext(), "Invalid method callback", Toast.LENGTH_LONG);
        msg.show();
    }
}

From source file:fr.pasteque.pos.sales.restaurant.Place.java

public Place(JSONObject o) {
    this.m_sId = o.getString("id");
    this.m_sName = o.getString("label");
    this.m_ix = o.getInt("x");
    this.m_iy = o.getInt("y");
    this.m_sfloor = o.getString("floorId");

    m_bPeople = false;/* w  ww.  j ava 2 s .c o  m*/
    m_btn = new JButton();

    m_btn.setFocusPainted(false);
    m_btn.setFocusable(false);
    m_btn.setRequestFocusEnabled(false);
    m_btn.setHorizontalTextPosition(SwingConstants.CENTER);
    m_btn.setVerticalTextPosition(SwingConstants.BOTTOM);
    m_btn.setIcon(ICO_FRE);
    m_btn.setText(m_sName);
}

From source file:org.uiautomation.ios.wkrdp.internal.WebKitRemoteDebugProtocol.java

public synchronized JSONObject sendWebkitCommand(JSONObject command, int pageId) {
    String sender = generateSenderString(pageId);
    try {//w  ww  .  j  a  v  a 2  s.c o  m
        commandId++;
        command.put("id", commandId);

        long start = System.currentTimeMillis();

        String xml = plist.JSONCommand(command);
        Map<String, String> var = ImmutableMap.of("$WIRConnectionIdentifierKey", connectionId, "$bundleId",
                bundleId, "$WIRSenderKey", sender, "$WIRPageIdentifierKey", "" + pageId);
        for (String key : var.keySet()) {
            xml = xml.replace(key, var.get(key));
        }
        sendMessage(xml);
        JSONObject response = handler.getResponse(command.getInt("id"));
        JSONObject error = response.optJSONObject("error");
        if (error != null) {
            throw new RemoteExceptionException(error, command);
        } else if (response.optBoolean("wasThrown", false)) {
            throw new WebDriverException("remote JS exception " + response.toString(2));
        } else {
            log.fine(System.currentTimeMillis() + "\t\t" + (System.currentTimeMillis() - start) + "ms\t"
                    + command.getString("method") + " " + command);
            JSONObject res = response.getJSONObject("result");
            if (res == null) {
                System.err.println("GOT a null result from " + response.toString(2));
            }
            return res;
        }
    } catch (JSONException e) {
        throw new WebDriverException(e);
    }
}

From source file:com.breadwallet.tools.security.RequestHandler.java

public static boolean tryBitIdUri(final Activity app, String uri, JSONObject jsonBody) {
    if (uri == null)
        return false;
    boolean isBitUri = false;

    URI bitIdUri = null;//w  ww  .ja v  a  2 s . c  o  m
    try {
        bitIdUri = new URI(uri);
        if ("bitid".equals(bitIdUri.getScheme()))
            isBitUri = true;
    } catch (URISyntaxException e) {
        e.printStackTrace();
    }

    _bitUri = uri;

    if (jsonBody != null) {
        try {
            _authString = jsonBody.getString("prompt_string");
            _bitCallback = jsonBody.getString("bitid_url");
            _index = jsonBody.getInt("bitid_index");
            _strToSign = jsonBody.getString("string_to_sign");
        } catch (JSONException e) {
            e.printStackTrace();
        }
    } else if (bitIdUri != null && "bitid".equals(bitIdUri.getScheme())) {
        if (app == null) {
            Log.e(TAG, "tryBitIdUri: app is null, returning true still");
            return isBitUri;
        }

        //ask for phrase, will system auth if needed

        _authString = "BitID Authentication Request";
    }

    //        Log.e(TAG, "tryBitIdUri: _bitUri: " + _bitUri);
    //        Log.e(TAG, "tryBitIdUri: _strToSign: " + _strToSign);
    //        Log.e(TAG, "tryBitIdUri: _index: " + _index);

    new Thread(new Runnable() {
        @Override
        public void run() {
            byte[] phrase = null;
            try {
                Thread.sleep(500);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            Uri tmpUri = Uri.parse(_bitUri);
            try {
                phrase = KeyStoreManager.getKeyStorePhrase(app, REQUEST_PHRASE_BITID);
                ((BreadWalletApp) app.getApplicationContext()).promptForAuthentication(app, AUTH_FOR_BIT_ID,
                        null, tmpUri.getHost(), _authString, null, false);
            } catch (BRKeystoreErrorException e) {
                //asked the system, no need for local auth
                e.printStackTrace();
            } finally {
                //free the phrase
                if (phrase != null)
                    Arrays.fill(phrase, (byte) 0);
            }
        }
    }).start();
    return isBitUri;

}

From source file:edu.mit.scratch.ScratchCloudSession.java

public void handleLine(final String line) {
    final JSONObject object = new JSONObject(line);

    final String method = object.getString("method");
    if ("set".equals(method)) { // inverted the .equals to prevent NullPointerExceptions
        final int projectID = object.getInt("project_id");
        final String name = object.getString("name");
        final String value = object.getString("value");

        for (final ScratchCloudListener listener : this.listeners)
            listener.onSet(projectID, name, value);
    } else { // TODO: Add `end`.
        System.out.println("Unknown method: " + method + "\nfor line: " + line);
    }//from   www . j  a  va  2 s.c o  m
}

From source file:robots.ScrapBot.java

public void scrapWeapons(boolean verbose, boolean pretend) throws Exception {
    // TODO: Pretty sure I'll need to ensure that it's scrapping scrappable weapons.  eg. pull out genuines, etc.
    getSchema();//from   w  ww. ja  v a 2 s. co m
    getBackpack();

    final Point smeltWeapons = pointProvider.getPoint(PointPlace.smeltWeapons);

    outputter.output("Scrapping Weapons...");
    leftClick(smeltWeapons.x, smeltWeapons.y);

    // Populate the array with all items and the information we care about.
    int bitmask = 0xFFFF;
    for (int i = 0; i < backpackItems.length(); i++) {
        JSONObject item = backpackItems.getJSONObject(i);
        int inventoryValue = backpackItems.getJSONObject(i).getInt("inventory");
        Weapon currentItem = new Weapon();
        currentItem.setDefindex(item.getInt("defindex"));
        currentItem.setInventorySlot(inventoryValue & bitmask);
        items.add(currentItem);
    }

    // Fill in remaining information and remove non-weapons
    ArrayList<Weapon> newList = new ArrayList<Weapon>();
    for (Weapon item : items) {
        for (int i = 0; i < schemaItems.length(); i++) {
            JSONObject schemaItem = schemaItems.getJSONObject(i);
            if (item.getDefindex().equals(schemaItem.getInt("defindex")) && item.getInventorySlot() > 0) {
                if (schemaItem.has("craft_material_type")) {
                    if (schemaItem.getString("craft_material_type").equals("weapon")) {
                        item.setName(schemaItem.getString("item_name"));
                        JSONArray classesJson = schemaItem.getJSONObject("used_by_classes")
                                .getJSONArray("class");
                        ArrayList<TF2Class> classes = new ArrayList<TF2Class>();
                        for (int j = 0; j < classesJson.length(); j++) {
                            String tf2Class = classesJson.getString(j);
                            TF2Class currentClass = TF2Class.SCOUT;
                            if (tf2Class.equals("Scout"))
                                currentClass = TF2Class.SCOUT;
                            else if (tf2Class.equals("Soldier"))
                                currentClass = TF2Class.SOLIDER;
                            else if (tf2Class.equals("Pyro"))
                                currentClass = TF2Class.PYRO;
                            else if (tf2Class.equals("Demoman"))
                                currentClass = TF2Class.DEMOMAN;
                            else if (tf2Class.equals("Heavy"))
                                currentClass = TF2Class.HEAVY;
                            else if (tf2Class.equals("Engineer"))
                                currentClass = TF2Class.ENGINEER;
                            else if (tf2Class.equals("Medic"))
                                currentClass = TF2Class.MEDIC;
                            else if (tf2Class.equals("Sniper"))
                                currentClass = TF2Class.SNIPER;
                            else if (tf2Class.equals("Spy"))
                                currentClass = TF2Class.SPY;
                            classes.add(currentClass);
                        }
                        item.setClasses(classes);
                        newList.add(item);
                    }
                }
            }
        }
    }
    items = newList;

    // Now, compare and determine two items to scrap
    ArrayList<Weapon> itemsToIgnore = new ArrayList<Weapon>();
    for (Weapon item : items) {
        // If the item is still there, it hasn't been used in crafting OR it hasn't been iterated to yet.
        if (!itemsToIgnore.contains(item)) {
            Weapon match = null;
            for (Weapon hopefulMatch : items) {
                if (!hopefulMatch.equals(item) && !itemsToIgnore.contains(hopefulMatch)) {
                    for (TF2Class tf2Class : item.getClasses()) {
                        for (TF2Class hopefulClass : hopefulMatch.getClasses()) {
                            if (tf2Class.equals(hopefulClass)) {
                                // These two weapons are compatible.  Scrap 'em!
                                match = hopefulMatch;
                                break;
                            }
                        }
                        if (match != null)
                            break;
                    }
                }
                if (match != null)
                    break;
            }
            // Come out here
            if (match != null) {
                // Scrap
                if (verbose)
                    outputter.output("Scrapping a " + item.getName() + " and a " + match.getName() + ".");
                if (!pretend) {
                    scrapWeapons(item, match);
                    Point mouseLoc = MouseInfo.getPointerInfo().getLocation();
                    Point ok2 = pointProvider.getPoint(PointPlace.ok2);
                    if (mouseLoc.getX() != ok2.x || mouseLoc.getY() != ok2.getY())
                        break;
                }
                itemsToIgnore.add(match);
            }
            itemsToIgnore.add(item);
        }
    }
    outputter.output("Weapons Scrapped.");
}