Android Open Source - commande-godo Todo Json Writer






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

// This file referenced from
// http://developer.android.com/reference/android/util/JsonWriter.html Sept 14, 2014
//from  www .  j a v a 2 s. c  o  m
package ca.ualberta.commande.android.commande_godo.data;

import java.io.IOException;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.util.List;

import android.util.JsonWriter;

public class TodoJsonWriter {
  public static void writeJsonStream(OutputStream out, List<TodoItem> todos) throws IOException {
       JsonWriter writer = new JsonWriter(new OutputStreamWriter(out, "UTF-8"));
       writer.setIndent("  ");
       writeTodosArray(writer, todos);
       writer.close();
  }
  
  public static void writeTodosArray(JsonWriter writer, List<TodoItem> todos) throws IOException {
    writer.beginArray();
    for (TodoItem todo : todos) {
      writeTodo(writer, todo);
    }
    writer.endArray();
  }

  public static void writeTodo(JsonWriter writer, TodoItem todo) throws IOException {
    writer.beginObject();
    writer.name("key").value(todo.getKey());
    writer.name("title").value(todo.getTitle());
    writer.name("completed").value(todo.isCompleted());
    writer.name("archived").value(todo.isArchived());
    writer.endObject();
  }
}




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