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:com.fvd.nimbus.BrowseActivity.java

@Override
public void onTaskComplete(String result, String action) {
    /*if (progressDialog != null)
    progressDialog.dismiss();*//*ww  w  .j a  v  a 2  s .c  o  m*/
    try {
        JSONObject root = new JSONObject(result);
        int error = root.getInt("errorCode");
        if (error == 0) {
            if (action.equalsIgnoreCase("user:auth")) {
                sessionId = root.getJSONObject("body").getString("sessionid");
                Editor e = prefs.edit();
                e.putString("userMail", userMail);
                e.putString("userPass", userPass);
                e.putString("sessionId", sessionId);
                e.commit();

                appSettings.sessionId = sessionId;
                appSettings.userMail = userMail;
                appSettings.userPass = userPass;
                if (lastAction != "") {
                    serverHelper.getInstance().sendRequest(lastAction, "", "");
                } else if (clipData != null && clipData.getContent().length() > 0) {
                    /*sendNote(wv.getTitle(), clipData.getContent(),parent,tag);
                    clipData.setContent("");*/
                    if (prefs.getBoolean("check_fast", false)) {
                        sendNote(clipData.getTitle(), clipData.getContent(), parent, tag);
                        clipData.setContent("");
                    } else {
                        serverHelper.getInstance().setCallback(this, this);
                        if (appSettings.sessionId.length() > 0) {
                            serverHelper.getInstance().sendRequest("notes:getFolders", "", "");
                        }
                    }
                }
                /*else if(selBuff.length()>0){
                           
                if(prefs.getBoolean("check_fast", false)){
                   sendNote(wv.getTitle(), selBuff, parent, tag);
                    selBuff="";
                }
                else {
                serverHelper.getInstance().setCallback(this,this);
                if(appSettings.sessionId.length()>0) {
                   serverHelper.getInstance().sendRequest("notes:getFolders", "","");
                   }
                }
                  }*/

            } else if (action.equalsIgnoreCase("notes:getfolders")) {

                //ArrayList<FolderItem>items=new ArrayList<FolderItem>();
                //ArrayList<FolderListItem>items=new ArrayList<FolderListItem>();
                try {
                    result = URLDecoder.decode(result, "UTF-16");
                    clipData.setData(result);
                    String cr = prefs.getString("remFolderId", "default");
                    if (cr == null || cr == "")
                        cr = "default";
                    clipData.setId(cr);
                    clipData.setTitle(wv.getTitle());
                    clipData.setTags("androidclipper");
                    Intent intent = new Intent(getApplicationContext(), tagsActivity.class);
                    intent.putExtra("xdata", clipData);
                    /*intent.putExtra("current", cr);
                    intent.putExtra("title", wv.getTitle());
                    intent.putExtra("tags", "androidclipper");*/

                    startActivityForResult(intent, 7);
                    //overridePendingTransition( R.anim.slide_in_up, R.anim.slide_out_up );
                    overridePendingTransition(R.anim.carbon_slide_in, R.anim.carbon_slide_out);
                    clipData.setData("");
                } catch (Exception Ex) {
                    appSettings.appendLog("prefs:onTaskComplete " + Ex.getMessage());
                }
            } else if (action.equalsIgnoreCase("user:authstate")) {
                boolean auth = root.getJSONObject("body").getBoolean("authorized");
                Toast.makeText(getApplicationContext(), "User " + (auth ? "authorized" : "not authorized"),
                        Toast.LENGTH_LONG).show();
            } else if ("notes:update".equalsIgnoreCase(action)) {
                showArticleSuccess();
            } else if ("notes:share".equalsIgnoreCase(action)) {
                String url = root.getString("url");
                showArticleDlg(url);
                //Toast.makeText(getApplicationContext(), "The fragment was successfully saved to your Nimbus account", Toast.LENGTH_LONG).show();
            } else if ("user_register".equals(action)) {
                sendRequest("user:auth",
                        String.format("\"email\":\"%s\",\"password\":\"%s\"", userMail, userPass));
            }
        } else {
            if (action.equalsIgnoreCase("user:auth")) {
                lastAction = "";
                showSettings();
            } else if (error == -6) {
                if (action == "notes:getFolders")
                    lastAction = action;
                else
                    lastAction = "";
                showSettings();
            } else
                Toast.makeText(getApplicationContext(),
                        String.format("Error: %s", serverHelper.errorMsg(error)), Toast.LENGTH_LONG).show();
        }
    } catch (Exception Ex) {
    }
}

From source file:com.tapfortap.phonegap.TapForTapPhoneGapPlugin.java

private void setAdOptions(JSONObject options) throws JSONException {
    adView.setLayoutParams(getLayoutParamsForOptions(options));
    if (options.has("gender")) {
        String gender = options.getString("gender");
        if (gender.equals("male"))
            TapForTap.setGender(TapForTap.Gender.MALE);
        else if (gender.equals("female"))
            TapForTap.setGender(TapForTap.Gender.FEMALE);
        else/* ww  w .  j  ava2s. c  o m*/
            TapForTap.setGender(TapForTap.Gender.NONE);
    }
    if (options.has("age")) {
        TapForTap.setAge(options.getInt("age"));
    }
    if (options.has("location")) {
        JSONObject locationObject = options.getJSONObject("location");
        Location location = new Location("user");
        location.setLatitude(locationObject.getDouble("latitude"));
        location.setLongitude(locationObject.getDouble("longitude"));
        TapForTap.setLocation(location);
    }
}

From source file:org.chromium.ChromeSocket.java

private void sendTo(CordovaArgs args, final CallbackContext context) throws JSONException {
    JSONObject opts = args.getJSONObject(0);
    int socketId = opts.getInt("socketId");
    String address = opts.getString("address");
    int port = opts.getInt("port");
    byte[] data = args.getArrayBuffer(1);

    SocketData sd = sockets.get(Integer.valueOf(socketId));
    if (sd == null) {
        Log.e(LOG_TAG, "No socket with socketId " + socketId);
        return;/*from   w  w  w.  j av  a 2 s.  c  o m*/
    }

    new SendToTask().execute(sd, data, address, port, context);
}

From source file:iqq.im.util.DateUtils.java

public static Date parse(JSONObject jsonobj) throws ParseException, JSONException {
    DateFormat format = new SimpleDateFormat("yyyy-MM-dd");
    Date d = format.parse(jsonobj.getInt("year") + "-" + jsonobj.getInt("month") + "-" + jsonobj.getInt("day"));
    return d;//from   w w  w.jav  a  2s.  com
}

From source file:com.kwang.sunshine.FetchWeatherTask.java

/**
 * Take the String representing the complete forecast in JSON Format and
 * pull out the data we need to construct the Strings needed for the wireframes.
 *
 * Fortunately parsing is easy:  constructor takes the JSON string and converts it
 * into an Object hierarchy for us.//  w ww  .j a v  a  2 s  .  c o m
 */
private String[] getWeatherDataFromJson(String forecastJsonStr, int numDays, String locationSetting)
        throws JSONException {

    // These are the names of the JSON objects that need to be extracted.

    // Location information
    final String OWM_CITY = "city";
    final String OWM_CITY_NAME = "name";
    final String OWM_COORD = "coord";
    final String OWM_COORD_LAT = "lat";
    final String OWM_COORD_LONG = "lon";

    // Weather information.  Each day's forecast info is an element of the "list" array.
    final String OWM_LIST = "list";

    final String OWM_DATETIME = "dt";
    final String OWM_PRESSURE = "pressure";
    final String OWM_HUMIDITY = "humidity";
    final String OWM_WINDSPEED = "speed";
    final String OWM_WIND_DIRECTION = "deg";

    // All temperatures are children of the "temp" object.
    final String OWM_TEMPERATURE = "temp";
    final String OWM_MAX = "max";
    final String OWM_MIN = "min";

    final String OWM_WEATHER = "weather";
    final String OWM_DESCRIPTION = "main";
    final String OWM_WEATHER_ID = "id";

    JSONObject forecastJson = new JSONObject(forecastJsonStr);
    JSONArray weatherArray = forecastJson.getJSONArray(OWM_LIST);

    JSONObject cityJson = forecastJson.getJSONObject(OWM_CITY);
    String cityName = cityJson.getString(OWM_CITY_NAME);
    JSONObject coordJSON = cityJson.getJSONObject(OWM_COORD);
    double cityLatitude = coordJSON.getLong(OWM_COORD_LAT);
    double cityLongitude = coordJSON.getLong(OWM_COORD_LONG);

    Log.v(LOG_TAG, cityName + ", with coord: " + cityLatitude + " " + cityLongitude);

    // Insert the location into the database.
    long locationID = addLocation(locationSetting, cityName, cityLatitude, cityLongitude);

    // Get and insert the new weather information into the database
    Vector<ContentValues> cVVector = new Vector<ContentValues>(weatherArray.length());

    String[] resultStrs = new String[numDays];

    for (int i = 0; i < weatherArray.length(); i++) {
        // These are the values that will be collected.

        long dateTime;
        double pressure;
        int humidity;
        double windSpeed;
        double windDirection;

        double high;
        double low;

        String description;
        int weatherId;

        // Get the JSON object representing the day
        JSONObject dayForecast = weatherArray.getJSONObject(i);

        // The date/time is returned as a long.  We need to convert that
        // into something human-readable, since most people won't read "1400356800" as
        // "this saturday".
        dateTime = dayForecast.getLong(OWM_DATETIME);

        pressure = dayForecast.getDouble(OWM_PRESSURE);
        humidity = dayForecast.getInt(OWM_HUMIDITY);
        windSpeed = dayForecast.getDouble(OWM_WINDSPEED);
        windDirection = dayForecast.getDouble(OWM_WIND_DIRECTION);

        // Description is in a child array called "weather", which is 1 element long.
        // That element also contains a weather code.
        JSONObject weatherObject = dayForecast.getJSONArray(OWM_WEATHER).getJSONObject(0);
        description = weatherObject.getString(OWM_DESCRIPTION);
        weatherId = weatherObject.getInt(OWM_WEATHER_ID);

        // Temperatures are in a child object called "temp".  Try not to name variables
        // "temp" when working with temperature.  It confuses everybody.
        JSONObject temperatureObject = dayForecast.getJSONObject(OWM_TEMPERATURE);
        high = temperatureObject.getDouble(OWM_MAX);
        low = temperatureObject.getDouble(OWM_MIN);

        ContentValues weatherValues = new ContentValues();

        weatherValues.put(WeatherEntry.COLUMN_LOC_KEY, locationID);
        weatherValues.put(WeatherEntry.COLUMN_DATETEXT,
                WeatherContract.getDbDateString(new Date(dateTime * 1000L)));
        weatherValues.put(WeatherEntry.COLUMN_HUMIDITY, humidity);
        weatherValues.put(WeatherEntry.COLUMN_PRESSURE, pressure);
        weatherValues.put(WeatherEntry.COLUMN_WIND_SPEED, windSpeed);
        weatherValues.put(WeatherEntry.COLUMN_DEGREES, windDirection);
        weatherValues.put(WeatherEntry.COLUMN_MAX_TEMP, high);
        weatherValues.put(WeatherEntry.COLUMN_MIN_TEMP, low);
        weatherValues.put(WeatherEntry.COLUMN_SHORT_DESC, description);
        weatherValues.put(WeatherEntry.COLUMN_WEATHER_ID, weatherId);

        cVVector.add(weatherValues);

        String highAndLow = formatHighLows(high, low);
        String day = getReadableDateString(dateTime);
        resultStrs[i] = day + " - " + description + " - " + highAndLow;
    }

    if (cVVector.size() > 0) {
        ContentValues[] cvArray = new ContentValues[cVVector.size()];
        cVVector.toArray(cvArray);
        int rowsInserted = mContext.getContentResolver().bulkInsert(WeatherEntry.CONTENT_URI, cvArray);
        Log.v(LOG_TAG, "inserted " + rowsInserted + " rows of weather data");
        // Use a DEBUG variable to gate whether or not you do this, so you can easily
        // turn it on and off, and so that it's easy to see what you can rip out if
        // you ever want to remove it.
        if (DEBUG) {
            Cursor weatherCursor = mContext.getContentResolver().query(WeatherEntry.CONTENT_URI, null, null,
                    null, null);

            if (weatherCursor.moveToFirst()) {
                ContentValues resultValues = new ContentValues();
                DatabaseUtils.cursorRowToContentValues(weatherCursor, resultValues);
                Log.v(LOG_TAG, "Query succeeded! **********");
                for (String key : resultValues.keySet()) {
                    Log.v(LOG_TAG, key + ": " + resultValues.getAsString(key));
                }
            } else {
                Log.v(LOG_TAG, "Query failed! :( **********");
            }
        }
    }

    return resultStrs;
}

From source file:com.neuron.trafikanten.dataProviders.trafikanten.TrafikantenDevi.java

@Override
public void run() {
    try {//from   w  w  w.j  a  v  a 2s.  c  o  m
        //String urlString = "http://devi.trafikanten.no/devirest.svc/json/linenames/";
        String urlString = "http://devi.trafikanten.no/devirest.svc/json/lineids/";
        if (lines.length() > 0) {
            urlString = urlString + URLEncoder.encode(lines, "UTF-8");
        } else {
            urlString = urlString + "null";
        }
        urlString = urlString + "/stopids/" + stationId + "/";
        urlString = urlString + "from/" + dateFormater.format(System.currentTimeMillis()) + "/to/2030-12-31";
        Log.i(TAG, "Loading devi data : " + urlString);

        final InputStream stream = HelperFunctions.executeHttpRequest(context, new HttpGet(urlString),
                false).stream;

        /*
         * Parse json
         */
        final JSONArray jsonArray = new JSONArray(HelperFunctions.InputStreamToString(stream));
        final int arraySize = jsonArray.length();
        for (int i = 0; i < arraySize; i++) {
            final JSONObject json = jsonArray.getJSONObject(i);
            DeviData deviData = new DeviData();

            {
                /*
                 * Grab validFrom and check if we should show it or not.
                 */
                deviData.validFrom = HelperFunctions.jsonToDate(json.getString("validFrom"));
                final long dateDiffHours = (deviData.validFrom - Calendar.getInstance().getTimeInMillis())
                        / HelperFunctions.HOUR;
                if (dateDiffHours > 3) {
                    /*
                     * This data starts more than 3 hours into the future, hide it.
                     */
                    continue;
                }
            }
            {
                /*
                 * Grab published, and see if this should be visible yet.
                 */
                final long publishDate = HelperFunctions.jsonToDate(json.getString("published"));
                if (System.currentTimeMillis() < publishDate) {
                    continue;
                }
            }
            {
                /*
                 * Check validto, and see if this should be visible yet.
                 */
                final long validToDate = HelperFunctions.jsonToDate(json.getString("validTo"));
                if (System.currentTimeMillis() > validToDate) {
                    continue;
                }
            }

            /*
             * Grab the easy data
             */
            deviData.title = json.getString("header");
            deviData.description = json.getString("lead");
            deviData.body = json.getString("body");
            deviData.validTo = HelperFunctions.jsonToDate(json.getString("validTo"));
            deviData.important = json.getBoolean("important");
            deviData.id = json.getInt("id");

            {
                /*
                 * Grab lines array
                 */
                final JSONArray jsonLines = json.getJSONArray("lines");
                final int jsonLinesSize = jsonLines.length();
                for (int j = 0; j < jsonLinesSize; j++) {
                    deviData.lines.add(jsonLines.getJSONObject(j).getInt("lineID"));
                }
            }

            {
                /*
                 * Grab stops array
                 */
                final JSONArray jsonLines = json.getJSONArray("stops");
                final int jsonLinesSize = jsonLines.length();
                for (int j = 0; j < jsonLinesSize; j++) {
                    deviData.stops.add(jsonLines.getJSONObject(j).getInt("stopID"));
                }
            }

            ThreadHandlePostData(deviData);
        }

    } catch (Exception e) {
        if (e.getClass() == InterruptedException.class) {
            ThreadHandlePostExecute(null);
            return;
        }
        ThreadHandlePostExecute(e);
        return;
    }
    ThreadHandlePostExecute(null);
}

From source file:com.funzio.pure2D.particles.nova.vo.NovaParticleVO.java

public NovaParticleVO(final JSONObject json) throws JSONException {
    super(json);// w w  w.  j  a v  a2 s . co  m

    name = json.optString("name");

    if (json.has("start_delay")) {
        start_delay = json.getInt("start_delay");
    }

    if (json.has("step_delay")) {
        step_delay = json.getInt("step_delay");
    }

    if (json.has("duration")) {
        duration = json.getInt("duration");
    }

    if (json.has("step_quantity")) {
        step_quantity = json.getInt("step_quantity");
    }

    if (json.has("layer")) {
        layer = json.getInt("layer");
    }

    if (json.has("origin_x")) {
        origin_x = json.getInt("origin_x");
    }

    if (json.has("origin_y")) {
        origin_y = json.getInt("origin_y");
    }

    // optional sprite or clip
    sprite = NovaVO.getListString(json, "sprite");
    start_frame = NovaVO.getListInt(json, "start_frame");
    loop_mode = NovaVO.getListString(json, "loop_mode");

    // basic DisplayObject's properties
    x = NovaVO.getListInt(json, "x");
    y = NovaVO.getListInt(json, "y");
    z = NovaVO.getListFloat(json, "z");
    animator = NovaVO.getListString(json, "animator");
    blend_mode = NovaVO.getListString(json, "blend_mode");
    alpha = NovaVO.getListFloat(json, "alpha");
    color = NovaVO.getListColor(json, "color");
    rotation = NovaVO.getListFloat(json, "rotation");
    scale_x = NovaVO.getListFloat(json, "scale_x");
    scale_y = NovaVO.getListFloat(json, "scale_y");
    skew_x = NovaVO.getListFloat(json, "skew_x");
    skew_y = NovaVO.getListFloat(json, "skew_y");
    motion_trail = NovaVO.getListString(json, "motion_trail");
}

From source file:jfabrix101.billing.BillingSecurity.java

/**
 * Verifies that the data was signed with the given signature, and returns
 * the list of verified purchases. The data is in JSON format and contains
 * a nonce (number used once) that we generated and that was signed
 * (as part of the whole data string) with a private key. The data also
 * contains the {@link PurchaseState} and product ID of the purchase.
 * In the general case, there can be an array of purchase transactions
 * because there may be delays in processing the purchase on the backend
 * and then several purchases can be batched together.
 * @param signedData the signed JSON string (signed, not encrypted)
 * @param signature the signature for the data, signed with the private key
 *///w ww  .  j a  v a2 s .  co  m
public static ArrayList<VerifiedPurchase> verifyPurchase(Context context, String signedData, String signature) {
    if (signedData == null) {
        Log.e(TAG, "data is null");
        return null;
    }
    if (BillingConsts.DEBUG) {
        Log.i(TAG, "signedData: " + signedData);
    }
    boolean verified = false;
    if (!TextUtils.isEmpty(signature)) {
        /**
         * Compute your public key (that you got from the Android Market publisher site).
         *
         * Instead of just storing the entire literal string here embedded in the
         * program,  construct the key at runtime from pieces or
         * use bit manipulation (for example, XOR with some other string) to hide
         * the actual key.  The key itself is not secret information, but we don't
         * want to make it easy for an adversary to replace the public key with one
         * of their own and then fake messages from the server.
         *
         * Generally, encryption keys / passwords should only be kept in memory
         * long enough to perform the operation they need to perform.
         */

        SharedPreferences pref = context.getSharedPreferences("billingPK", 0);
        AESObfuscator obfuscator = AESObfuscator.getDefaultObfuscator(context);
        String publicKey = "";
        try {
            publicKey = obfuscator.unobfuscate(pref.getString("pk", ""));
        } catch (Exception e) {
            Log.e(TAG, "Error getting publicc key from repository");
            return null;
        }
        PublicKey key = BillingSecurity.generatePublicKey(publicKey);
        verified = BillingSecurity.verify(key, signedData, signature);
        if (!verified) {
            Log.w(TAG, "signature does not match data.");
            return null;
        }
    }

    JSONObject jObject;
    JSONArray jTransactionsArray = null;
    int numTransactions = 0;
    long nonce = 0L;
    try {
        jObject = new JSONObject(signedData);

        // The nonce might be null if the user backed out of the buy page.
        nonce = jObject.optLong("nonce");
        jTransactionsArray = jObject.optJSONArray("orders");
        if (jTransactionsArray != null) {
            numTransactions = jTransactionsArray.length();
        }
    } catch (JSONException e) {
        return null;
    }

    if (!BillingSecurity.isNonceKnown(nonce)) {
        Log.w(TAG, "Nonce not found: " + nonce);
        return null;
    }

    ArrayList<VerifiedPurchase> purchases = new ArrayList<VerifiedPurchase>();
    try {
        for (int i = 0; i < numTransactions; i++) {
            JSONObject jElement = jTransactionsArray.getJSONObject(i);
            int response = jElement.getInt("purchaseState");
            PurchaseState purchaseState = PurchaseState.valueOf(response);
            String productId = jElement.getString("productId");
            //String packageName = jElement.getString("packageName");
            long purchaseTime = jElement.getLong("purchaseTime");
            String orderId = jElement.optString("orderId", "");
            String notifyId = null;
            if (jElement.has("notificationId")) {
                notifyId = jElement.getString("notificationId");
            }
            String developerPayload = jElement.optString("developerPayload", null);

            // If the purchase state is PURCHASED, then we require a verified nonce.
            if (purchaseState == PurchaseState.PURCHASED && !verified) {
                continue;
            }
            purchases.add(new VerifiedPurchase(purchaseState, notifyId, productId, orderId, purchaseTime,
                    developerPayload));
        }
    } catch (JSONException e) {
        Log.e(TAG, "JSON exception: ", e);
        return null;
    }
    removeNonce(nonce);
    return purchases;
}

From source file:com.krayzk9s.imgurholo.ui.AccountFragment.java

public void onGetObject(Object data, String tag) {
    refreshedCount++;/*w w w  .jav a 2  s.co  m*/
    if (refreshedCount == 5) {
        mPullToRefreshLayout.setRefreshComplete();
    }
    try {
        if (data == null) {
            return;
        }
        JSONObject jsonData;

        /*int duration = Toast.LENGTH_SHORT;
            Toast toast;
        MainActivity activity = (MainActivity) getActivity();
        toast = Toast.makeText(activity, "User not found", duration);
        toast.show();
        activity.getFragmentManager().popBackStack();*/

        if (tag.equals(ACCOUNTDATA)) {
            jsonData = ((JSONObject) data).getJSONObject("data");
            if (jsonData.has("error"))
                return;
            Calendar accountCreationDate = Calendar.getInstance();
            accountCreationDate.setTimeInMillis((long) jsonData.getInt("created") * 1000);
            SimpleDateFormat sdf = new SimpleDateFormat("MM/dd/yyyy");
            String accountcreated = sdf.format(accountCreationDate.getTime());
            created.setText(accountcreated);
            reputation.setText(Integer.toString(jsonData.getInt("reputation")));
            if (jsonData.getString("bio") != null && !jsonData.getString("bio").equals("null")
                    && !jsonData.getString("bio").equals(""))
                biography.setText(jsonData.getString("bio"));
            else
                biography.setText("No Biography");
        } else if (tag.equals(COUNTDATA)) {
            jsonData = ((JSONObject) data);
            if (jsonData.has("error"))
                return;
            if (jsonData.getInt("status") == 200)
                mMenuList[1] = mMenuList[1] + " (" + Integer.toString(jsonData.getInt("data")) + ")";
            else
                mMenuList[1] = mMenuList[1] + " (0)";
        } else if (tag.equals(ALBUMDATA)) {
            jsonData = ((JSONObject) data);
            if (jsonData.has("error"))
                return;
            if (jsonData.getInt("status") == 200)
                mMenuList[0] = mMenuList[0] + " (" + Integer.toString(jsonData.getJSONArray("data").length())
                        + ")";
            else
                mMenuList[0] = mMenuList[0] + " (0)";
        } else if (tag.equals(LIKEDATA)) {
            JSONArray jsonArray = ((JSONObject) data).getJSONArray("data");
            mMenuList[2] = mMenuList[2] + " (" + String.valueOf(jsonArray.length()) + ")";
        } else if (tag.equals(COMMENTDATA)) {
            jsonData = ((JSONObject) data);
            mMenuList[3] = mMenuList[3] + " (" + String.valueOf(jsonData.getInt("data")) + ")";
        }
        adapter.notifyDataSetChanged();
    } catch (JSONException e) {
        Log.e("Error!", e.toString());
    }
}

From source file:cn.code.notes.gtask.data.TaskList.java

public void setContentByLocalJSON(JSONObject js) {
    if (js == null || !js.has(GTaskStringUtils.META_HEAD_NOTE)) {
        Log.w(TAG, "setContentByLocalJSON: nothing is avaiable");
    }//from w w  w . j a  v a  2s  .  c o m

    try {
        JSONObject folder = js.getJSONObject(GTaskStringUtils.META_HEAD_NOTE);

        if (folder.getInt(NoteColumns.TYPE) == Notes.TYPE_FOLDER) {
            String name = folder.getString(NoteColumns.SNIPPET);
            setName(GTaskStringUtils.MIUI_FOLDER_PREFFIX + name);
        } else if (folder.getInt(NoteColumns.TYPE) == Notes.TYPE_SYSTEM) {
            if (folder.getLong(NoteColumns.ID) == Notes.ID_ROOT_FOLDER)
                setName(GTaskStringUtils.MIUI_FOLDER_PREFFIX + GTaskStringUtils.FOLDER_DEFAULT);
            else if (folder.getLong(NoteColumns.ID) == Notes.ID_CALL_RECORD_FOLDER)
                setName(GTaskStringUtils.MIUI_FOLDER_PREFFIX + GTaskStringUtils.FOLDER_CALL_NOTE);
            else
                Log.e(TAG, "invalid system folder");
        } else {
            Log.e(TAG, "error type");
        }
    } catch (JSONException e) {
        Log.e(TAG, e.toString());
        e.printStackTrace();
    }
}