Android Open Source - note-pad Note Activity






From Project

Back to project page note-pad.

License

The source code is released under:

GNU General Public License

If you think the Android project note-pad 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 in.anandm.apps.notepad.interfaces;
/* w w  w .j  ava  2  s.  c  o m*/
import in.anandm.apps.notepad.R;
import in.anandm.apps.notepad.domain.model.note.INoteRepository;
import in.anandm.apps.notepad.domain.model.note.Note;
import in.anandm.apps.notepad.infrastructure.persistence.sqlite.NoteRepository;
import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

public class NoteActivity extends Activity {



  boolean initialized = false;
  EditText noteId;
  EditText noteTitleText;
  EditText noteText;
  INoteRepository noteRepository ;

  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_note);
    noteRepository = new NoteRepository(getApplicationContext());
    Note note = (Note) getIntent().getExtras().get("noteObject");

    if(!initialized){
      noteId = (EditText) findViewById(R.id.noteId);
      noteTitleText = (EditText) findViewById(R.id.noteTitleText);
      noteText = (EditText) findViewById(R.id.noteText);
    }

    if(note != null){
      noteId.setText(String.valueOf(note.getId()));
      noteTitleText.setText(note.getTitle());
      noteText.setText(note.getNote());
    }

  }

  @Override
  public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.note, menu);
    return true;
  }

  @Override
  public boolean onOptionsItemSelected(MenuItem item) {

    Toast msg = null;
    switch (item.getItemId()) {

    case R.id.action_edit:
      msg = Toast.makeText(getApplicationContext(), "Edit Option Selected", Toast.LENGTH_SHORT);
      break;
    case R.id.action_save:
      String id = noteId.getText().toString();
      String noteTitle = noteTitleText.getText().toString();
      String noteContent = noteText.getText().toString();
      if(id != null && !"".equals(id)){
        Note note = noteRepository.getNoteById(Long.valueOf(id));
        note.setTitle(noteTitle);
        note.setNote(noteContent);
        noteRepository.saveNote(note);
      }else{
        Note note = new Note(noteTitle, noteContent);
        noteRepository.saveNote(note);
      }
      //msg = Toast.makeText(getApplicationContext(), "Save Option Selected", Toast.LENGTH_SHORT);
      break;

    default:
      msg = Toast.makeText(getApplicationContext(), "Unknown Option Selected", Toast.LENGTH_SHORT);
      msg.show();
      break;
    }

    
    return true;
  }
}




Java Source Code List

in.anandm.apps.notepad.domain.model.note.INoteRepository.java
in.anandm.apps.notepad.domain.model.note.Note.java
in.anandm.apps.notepad.infrastructure.persistence.inmemory.NoteRepository.java
in.anandm.apps.notepad.infrastructure.persistence.sqlite.NoteRepository.java
in.anandm.apps.notepad.interfaces.NoteActivity.java
in.anandm.apps.notepad.interfaces.NoteAdapter.java
in.anandm.apps.notepad.interfaces.NotePadMainActivity.java