Example usage for android.util JsonReader nextLong

List of usage examples for android.util JsonReader nextLong

Introduction

In this page you can find the example usage for android.util JsonReader nextLong.

Prototype

public long nextLong() throws IOException 

Source Link

Document

Returns the JsonToken#NUMBER long value of the next token, consuming it.

Usage

From source file:com.fuzz.android.limelight.util.JSONTool.java

/**
 * @param reader/*from  w  ww.  ja va2 s . c o  m*/
 * @return the generated BaseChapter object from the JSON
 * @throws IOException
 */
public static Chapter readChapter(JsonReader reader) throws IOException {
    long time = -1;
    boolean hasActView = false;
    BaseChapter chapter = new BaseChapter();

    while (reader.hasNext()) {
        String name = reader.nextName();
        if (name.equals("duration"))
            time = reader.nextLong();
        else if (name.equals("has_act_view"))
            hasActView = reader.nextBoolean();
        else if (name.equals("act"))
            chapter.setAct(readAct(reader));
    }
    reader.endObject();

    chapter.setTime(time);
    chapter.setHasActView(hasActView);
    return chapter;
}

From source file:com.fuzz.android.limelight.util.JSONTool.java

/**
 * @param reader/*from   w  ww  .  j  av a 2  s.c  o m*/
 * @return the generated ChapterTransition object from JSON
 * @throws IOException
 */
public static ChapterTransition readTransition(JsonReader reader) throws IOException {
    long time = -1;
    int itemPosition = -1;
    int childId = -1;
    int anchorId = -1;
    String message = null;
    int messageResId = -1;
    int grapicResID = -1;
    boolean isActionBarItem = false;
    double xOffset = -1;
    double yOffset = -1;
    int textColor = -1;
    int textBackgroundColor = -1;
    float textSize = -1;
    boolean textBackgroundTransparent = false;
    String animation = null;

    while (reader.hasNext()) {
        try {
            String name = reader.nextName();
            if (name.equals("time"))
                time = reader.nextLong();
            else if (name.equals("item_position"))
                itemPosition = reader.nextInt();
            else if (name.equals("child_id"))
                childId = reader.nextInt();
            else if (name.equals("id"))
                anchorId = reader.nextInt();
            else if (name.equals("message"))
                message = reader.nextString();
            else if (name.equals("message_res_id"))
                messageResId = reader.nextInt();
            else if (name.equals("graphic_res_id"))
                grapicResID = reader.nextInt();
            else if (name.equals("is_action_bar_item"))
                isActionBarItem = reader.nextBoolean();
            else if (name.equals("x_offset"))
                xOffset = reader.nextDouble();
            else if (name.equals("y_offset"))
                yOffset = reader.nextDouble();
            else if (name.equals("text_color"))
                textColor = reader.nextInt();
            else if (name.equals("text_background_color"))
                textBackgroundColor = reader.nextInt();
            else if (name.equals("text_size"))
                textSize = reader.nextLong();
            else if (name.equals("text_background_transparent"))
                textBackgroundTransparent = reader.nextBoolean();
            else if (name.equals("animation"))
                animation = reader.nextString();
        } catch (IllegalStateException e) {
            reader.nextNull();
            e.printStackTrace();
        }
    }

    reader.endObject();

    ChapterTransition transition = new ChapterTransition();
    transition.setTime(time);
    transition.setItemPosition(itemPosition);
    transition.setChildID(childId);
    transition.setId(anchorId);
    transition.setMessage(message);
    transition.setMessageResID(messageResId);
    transition.setGraphicResID(grapicResID);
    transition.setIsActionBarItem(isActionBarItem);
    transition.setDisplacement(xOffset, yOffset);
    transition.setTextColor(textColor);
    transition.setTextBackgroundColor(textBackgroundColor);
    transition.setTextSize(textSize);
    transition.setTransparentBackground(textBackgroundTransparent);
    transition.setAnimation(animation);

    return transition;
}

From source file:com.tcity.android.ui.info.BuildArtifactsTask.java

private void handleFiles(@NotNull JsonReader reader) throws IOException {
    reader.beginArray();//from  w w  w .j av  a2  s  .  c  om

    List<BuildArtifact> result = new ArrayList<>();

    while (reader.hasNext()) {
        reader.beginObject();

        long size = -1;
        String name = null;
        String contentHref = null;
        String childrenHref = null;

        while (reader.hasNext()) {
            switch (reader.nextName()) {
            case "size":
                size = reader.nextLong();
                break;
            case "name":
                name = reader.nextString();
                break;
            case "children":
                childrenHref = getHref(reader);
                break;
            case "content":
                contentHref = getHref(reader);
                break;
            default:
                reader.skipValue();
            }
        }

        if (name == null) {
            throw new IllegalStateException("Invalid artifacts json: \"name\" is absent");
        }

        if (contentHref == null && childrenHref == null) {
            throw new IllegalStateException("Invalid artifacts json: \"content\" and \"children\" are absent");
        }

        result.add(new BuildArtifact(size, name, contentHref, childrenHref));

        reader.endObject();
    }

    reader.endArray();

    myResult = result;
}

From source file:com.thingsee.tracker.REST.KiiBucketRequestAsyncTask.java

private JSONObject readSingleData(JsonReader jsonReader) throws IOException, JSONException {
    JSONObject jsonObject = new JSONObject();
    jsonReader.beginObject();/*from   w  w  w. jav  a  2  s .com*/
    JsonToken token;
    do {
        String name = jsonReader.nextName();
        if ("sId".equals(name)) {
            jsonObject.put("sId", jsonReader.nextString());
        } else if ("val".equals(name)) {
            jsonObject.put("val", jsonReader.nextDouble());
        } else if ("ts".equals(name)) {
            jsonObject.put("ts", jsonReader.nextLong());
        } else if ("_owner".equals(name)) {
            jsonObject.put("_owner", jsonReader.nextString());
        }

        token = jsonReader.peek();
    } while (token != null && !token.equals(JsonToken.END_OBJECT));
    jsonReader.endObject();
    return jsonObject;
}

From source file:com.fuzz.android.limelight.util.JSONTool.java

/**
 * @param reader/*from w ww  . jav  a  2 s.c  om*/
 * @return the generated Act object from the JSON
 * @throws IOException
 */
public static Act readAct(JsonReader reader) throws IOException {
    int id = -1;
    String message = null;
    int messageResId = -1;
    int graphResId = -1;
    boolean isActionBarItem = false;
    double xOffset = -1;
    double yOffset = -1;
    int textColor = -1;
    int textBackgroundColor = -1;
    float textSize = -1;
    boolean textBackgroundTransparent = false;
    String animation = null;
    String activityName = null;

    reader.beginObject();
    while (reader.hasNext()) {
        String name = reader.nextName();
        if (name.equals("id"))
            id = reader.nextInt();
        else if (name.equals("message"))
            message = reader.nextString();
        else if (name.equals("message_res_id"))
            messageResId = reader.nextInt();
        else if (name.equals("graphic_res_id"))
            graphResId = reader.nextInt();
        else if (name.equals("is_action_bar_item"))
            isActionBarItem = reader.nextBoolean();
        else if (name.equals("x_offset"))
            xOffset = reader.nextDouble();
        else if (name.equals("y_offset"))
            yOffset = reader.nextDouble();
        else if (name.equals("text_color"))
            textColor = reader.nextInt();
        else if (name.equals("text_background_color"))
            textBackgroundColor = reader.nextInt();
        else if (name.equals("text_size"))
            textSize = reader.nextLong();
        else if (name.equals("text_background_transparent"))
            textBackgroundTransparent = reader.nextBoolean();
        else if (name.equals("animation"))
            animation = reader.nextString();
        else if (name.equals("activity_name"))
            activityName = reader.nextString();
        else
            reader.skipValue();
    }
    reader.endObject();

    Act act = new Act();
    act.setId(id);
    act.setMessage(message);
    act.setMessageResID(messageResId);
    act.setGraphicResID(graphResId);
    act.setIsActionBarItem(isActionBarItem);
    act.setDisplacement(xOffset, yOffset);
    act.setTextColor(textColor);
    act.setTextBackgroundColor(textBackgroundColor);
    act.setTextSize(textSize);
    act.setTransparentBackground(textBackgroundTransparent);
    act.setAnimation(animation);
    act.setActivityName(activityName);
    act.getLayout();

    return act;
}

From source file:br.com.thinkti.android.filechooserfrag.fragFileChooserQuizlet.java

typVok parseSetDataJson(JsonReader reader) throws IOException {
    reader.beginObject();//from  w  w w.ja v  a2s.  c om
    typVok rowData = new typVok();

    while (reader.hasNext()) {
        String name = reader.nextName();
        if (name.equals("term")) {
            rowData.Wort = reader.nextString();
        } else if (name.equals("id")) {
            long id = reader.nextLong();
            rowData.z = 0;
        } else if (name.equals("definition")) {
            rowData.Bed1 = reader.nextString();
            rowData.Bed2 = "";
            rowData.Bed3 = "";
        } else if (name.equals("image")) {
            try {
                reader.beginObject();
                while (reader.hasNext()) {
                    String strName = reader.nextName();
                    if (strName.equals("url")) {
                        String value = "<link://" + reader.nextString() + " "
                                + _main.getString(R.string.picture) + "/>";
                        rowData.Kom = value;
                    } else {
                        reader.skipValue();
                    }
                }
                reader.endObject();
            } catch (Exception exception) {
                reader.skipValue();
                //String value = "<link://" + reader.nextString() + "/>";
                //rowData.Kom = value;
            }

        } else {
            reader.skipValue();
        }
    }
    reader.endObject();
    if (lib.libString.IsNullOrEmpty(rowData.Bed1)) {
        rowData.Bed1 = rowData.Kom;
        rowData.Bed2 = "";
        rowData.Bed3 = "";
    }
    return rowData;
}

From source file:br.com.thinkti.android.filechooserfrag.fragFileChooserQuizlet.java

private List<typVok> openSet(String id) throws Exception {
    this.errorDescription = null;
    this.errorTitle = null;
    InputStream inputStream = null;
    List<typVok> list = new ArrayList<typVok>();
    String Kom = "";
    _main.vok.title = "";
    try {/*from  w  ww  .j av a 2 s . c o  m*/
        URL url = new URL(getDeckUrl(id));
        /*
        HttpURLConnection connection = (HttpURLConnection) url.openConnection();
        if ( connection.getResponseCode() >= 400 ) {
           inputStream = connection.getErrorStream();
        }
        else {
           inputStream = connection.getInputStream();
        }
        */
        inputStream = org.liberty.android.fantastischmemo.downloader.quizlet.lib.makeApiCall(url,
                _main.QuizletAccessToken);
        JsonReader reader = new JsonReader(new InputStreamReader(inputStream, "UTF-8"));
        reader.beginArray();
        while (reader.hasNext()) {
            reader.beginObject();
            while (reader.hasNext()) {
                String name = reader.nextName();
                if ("id".equals(name)) {
                    long intId = reader.nextLong();
                    /*if (page > totalPages) {
                            
                    }*/
                } else if ("url".equals(name)) {
                    String strUrl = reader.nextString();
                } else if ("title".equals(name)) {
                    String title = reader.nextString();
                    _main.vok.title = title;
                } else if ("created_by".equals(name)) {
                    String created_by = reader.nextString();
                    Kom = _main.getString(R.string.created_by) + " " + created_by + " "
                            + _main.getString((R.string.at)) + " <link://https://quizlet.com/ Quizlet/>";
                } else if ("term_count".equals(name)) {
                    int term_count = reader.nextInt();
                } else if ("lang_terms".equals(name)) {
                    String lang_terms = reader.nextString();
                    try {
                        _LangWord = new Locale(lang_terms.replace("-", "_"));
                    } catch (Throwable ex) {

                    }
                } else if ("lang_definitions".equals(name)) {
                    String lang_definitions = reader.nextString();
                    try {
                        _LangMeaning = (new Locale(lang_definitions.replace("-", "_")));
                    } catch (Throwable ex) {

                    }
                } else if ("terms".equals(name)) {
                    reader.beginArray();
                    while (reader.hasNext()) {
                        typVok v = parseSetDataJson(reader);
                        String kom = v.Kom;
                        v.Kom = Kom;
                        if (!lib.libString.IsNullOrEmpty(kom)) {
                            v.Kom += " " + kom;
                        }
                        list.add(v);
                    }
                    reader.endArray();
                } else {
                    reader.skipValue();
                }
            }
            reader.endObject();
        }
        reader.endArray();
    } finally {
        if (inputStream != null) {
            inputStream.close();
        }
    }
    return list;
}

From source file:br.com.thinkti.android.filechooserfrag.fragFileChooserQuizlet.java

RowData parseSetJson(JsonReader reader) throws IOException {
    reader.beginObject();//  w  w  w.ja v  a  2 s  . c  om
    RowData rowData = new RowData();

    while (reader.hasNext()) {
        String name = reader.nextName();
        if (name.equals("title")) {
            rowData.name = reader.nextString();
        } else if (name.equals("description")) {
            rowData.description = reader.nextString();
            if (rowData.description.length() > 200)
                rowData.description = rowData.description.substring(0, 100);
        } else if (name.equals("id")) {
            rowData.id = reader.nextInt();
        } else if (name.equals("term_count")) {
            rowData.numCards = reader.nextInt();
        } else if (name.equals("modified_date")) {
            long value = reader.nextLong();
            rowData.lastModified = Data.SHORT_DATE_FORMAT.format(new Date(value * 1000));
            Log.d(Data.APP_ID, " modified_date   value=" + value + " formatted=" + rowData.lastModified
                    + " now=" + (new Date().getTime()));
        } else {
            reader.skipValue();
        }
    }
    reader.endObject();
    return rowData;
}