Android Open Source - EasyNote Main Activity

From Project

Back to project page EasyNote.


The source code is released under:

This is free and unencumbered software released into the public domain. Anyone is free to copy, modify, publish, use, compile, sell, or distribute this software, either in source code form or as a co...

If you think the Android project EasyNote 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.manustudios.easynote;
/*w w w.j av a2  s. c o  m*/
import java.util.List;

import com.manustudios.supernotes.R;

import android.os.Bundle;
import android.content.Intent;
import android.view.ContextMenu;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ContextMenu.ContextMenuInfo;
import android.widget.ListView;
import android.widget.AdapterView.AdapterContextMenuInfo;

public class MainActivity extends ListActivity {

  private static final int EDITOR_ACTIVITY_REQUEST = 10;
  private static final int MENU_DELETE_ID = 12;
  private int currentNoteId;
  private NoteDataSource dataSource;
  private List<NoteItem> notes;
  protected void onCreate(Bundle savedInstanceState) {
    dataSource = new NoteDataSource(this);

  private void refreshScreen() {
    notes = dataSource.findAll();
    //ArrayAdapter<NoteItem> adapter = new ArrayAdapter<NoteItem>(this, R.layout.list_item_layout, notes);
    NoteItemAdapter adapter = new NoteItemAdapter(this, R.layout.list_item_layout, notes);   //THE ADAPTER FOR THE NOTES
    setListAdapter(adapter);  //SETTING THE ADAPTER

  public boolean onCreateOptionsMenu(Menu menu) {  //INFLATE THE ACTION BAR
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(, menu);
    return true;
  public boolean onOptionsItemSelected(MenuItem item) {  //PRESS THHE ACTION BAR
    return super.onOptionsItemSelected(item);

  private void createNote() {  //CREATE A NEW NOTE
    NoteItem note = NoteItem.getNew();
    Intent intent = new Intent(this, NoteEditorActivity.class);
    intent.putExtra("key", note.getKey());
    intent.putExtra("title", "");
    intent.putExtra("text", note.getText());
    intent.putExtra("selfTitle", false);
    startActivityForResult(intent, EDITOR_ACTIVITY_REQUEST);

  protected void onListItemClick(ListView l, View v, int position, long id) {
    NoteItem note = notes.get(position);
    Intent intent = new Intent(this, NoteEditorActivity.class);
    intent.putExtra("key", note.getKey());
    intent.putExtra("title", note.getTitle());
    intent.putExtra("text", note.getText());
    intent.putExtra("selfTitle", true);
    startActivityForResult(intent, EDITOR_ACTIVITY_REQUEST);
  protected void onActivityResult(int requestCode, int resultCode, Intent data) {  //COMING BACK FROM ANY OTHER ACTIVITY
    if (requestCode == EDITOR_ACTIVITY_REQUEST && resultCode == RESULT_OK) {
      NoteItem note = new NoteItem();
      note.setSelfTitle(data.getBooleanExtra("selfTitle", false));
      note.setText(data.getStringExtra("text"));  //NEVERMIND THE DATE IT IS UPDATED INSIDE dataSource Object
  public void onCreateContextMenu(ContextMenu menu, View v,
      ContextMenuInfo menuInfo) {
      AdapterContextMenuInfo info = (AdapterContextMenuInfo) menuInfo;
      currentNoteId = (int);
      menu.add(0, MENU_DELETE_ID, 0, "Delete");
  public boolean onContextItemSelected(MenuItem item) {
    if (item.getItemId() == MENU_DELETE_ID) {
      NoteItem note = notes.get(currentNoteId);
    return super.onContextItemSelected(item);

Java Source Code List