Android Open Source - notes Notebook






From Project

Back to project page notes.

License

The source code is released under:

Apache License

If you think the Android project notes 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

package com.donnemartin.android.notes.notes;
//  w ww  .  j  a v a 2s  .  c o m
import android.content.Context;
import android.util.Log;

import java.util.ArrayList;
import java.util.UUID;

public class Notebook {

    private ArrayList<Note> mNotes;
    private static Notebook sNotebook;
    private Context mAppContext;
    private NoteIntentJSONSerializer mSerializer;


    private static final String TAG = "Notebook";
    private static final String FILENAME = "notes.json";

    private Notebook(Context appContext) {
        mAppContext = appContext;
        mSerializer = new NoteIntentJSONSerializer(mAppContext, FILENAME);

        try {
            mNotes = mSerializer.loadNotes();
        } catch (Exception e) {
            mNotes = new ArrayList<Note>();
            Log.e(TAG, "Error loading notes: ", e);
        }
    }

    public static Notebook getInstance(Context context) {
        if (sNotebook == null) {
            // Ensure the singleton has a long-term Context to work with
            // Application context is global to the application
            // Application-wide singleton should always use the
            // application context
            sNotebook = new Notebook(context.getApplicationContext());
        }

        return sNotebook;
    }

    public boolean saveNotes() {
        boolean success = false;

        try {
            mSerializer.saveNotes(mNotes);
            Log.d(TAG, "Notes saved to file");
            success = true;
        } catch (Exception e) {
            Log.e(TAG, "Error saving notes: ", e);
        }

        return success;
    }

    public ArrayList<Note> getNotes() {
        return mNotes;
    }

    public void addNote(Note note) {
        mNotes.add(note);
    }

    public void deleteNote(Note note) {
        mNotes.remove(note);
    }

    public Note getNote(UUID id) {
        Note matchNote = null;

        for (Note note : mNotes) {
            if (note.getId().equals(id)) {
                matchNote = note;
                break;
            }
        }

        return matchNote;
    }
}




Java Source Code List

com.donnemartin.android.notes.notes.AudioPlayer.java
com.donnemartin.android.notes.notes.AudioRecorder.java
com.donnemartin.android.notes.notes.DatePickerFragment.java
com.donnemartin.android.notes.notes.ImageFragment.java
com.donnemartin.android.notes.notes.NoteCameraActivity.java
com.donnemartin.android.notes.notes.NoteCameraFragment.java
com.donnemartin.android.notes.notes.NoteFragment.java
com.donnemartin.android.notes.notes.NoteIntentJSONSerializer.java
com.donnemartin.android.notes.notes.NoteListActivity.java
com.donnemartin.android.notes.notes.NoteListFragment.java
com.donnemartin.android.notes.notes.NotePagerActivity.java
com.donnemartin.android.notes.notes.Note.java
com.donnemartin.android.notes.notes.Notebook.java
com.donnemartin.android.notes.notes.Photo.java
com.donnemartin.android.notes.notes.PictureUtils.java
com.donnemartin.android.notes.notes.SingleFragmentActivity.java