Android Open Source - commande-godo Todo Json Reader






From Project

Back to project page commande-godo.

License

The source code is released under:

MIT License

If you think the Android project commande-godo listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

// http://developer.android.com/reference/android/util/JsonReader.html, Sept 14, 2014
// w  w  w .  j a va2s  .  c o m
package ca.ualberta.commande.android.commande_godo.data;

import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;

import android.util.JsonReader;

public class TodoJsonReader {
  public static List<TodoItem> readJsonStream(InputStream in) throws IOException {
    JsonReader reader = new JsonReader(new InputStreamReader(in, "UTF-8"));
    try {
      return readTodosArray(reader);
    } finally {
      reader.close();
    }
  }

  public static List<TodoItem> readTodosArray(JsonReader reader) throws IOException {
    List<TodoItem> todos = new ArrayList<TodoItem>();

    reader.beginArray();
    while (reader.hasNext()) {
      todos.add(readTodo(reader));
    }
    reader.endArray();
    return todos;
  }

  public static TodoItem readTodo(JsonReader reader) throws IOException {
    String key = null;
    String title = null;
    boolean completed = false;
    boolean archived = false;

    reader.beginObject();
    while (reader.hasNext()) {
      String name = reader.nextName();
      if (name.equals("key")) {
        key = reader.nextString();
      } else if (name.equals("title")) {
        title = reader.nextString();
      } else if (name.equals("completed")) {
        completed = reader.nextBoolean();
      } else if (name.equals("archived")) {
        archived = reader.nextBoolean();
      } else {
        reader.skipValue();
      }
    }
    reader.endObject();
    return TodoItem.getNew(key, title, completed, archived);
  }
}




Java Source Code List

ca.ualberta.commande.android.commande_godo.MainActivity.java
ca.ualberta.commande.android.commande_godo.NewTodoActivity.java
ca.ualberta.commande.android.commande_godo.SummaryActivity.java
ca.ualberta.commande.android.commande_godo.TodoAdapter.java
ca.ualberta.commande.android.commande_godo.TodoEmailer.java
ca.ualberta.commande.android.commande_godo.data.TodoItem.java
ca.ualberta.commande.android.commande_godo.data.TodoJsonReader.java
ca.ualberta.commande.android.commande_godo.data.TodoJsonWriter.java
ca.ualberta.commande.android.commande_godo.data.TodosDataSource.java