Back to project page note-pad.
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.
package in.anandm.apps.notepad.interfaces; //from w ww.j ava2 s .co 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.annotation.TargetApi; import android.app.ActionBar; import android.app.ActionBar.LayoutParams; import android.app.ListActivity; import android.content.Context; import android.content.Intent; import android.database.Cursor; import android.os.Build; import android.os.Bundle; import android.provider.BaseColumns; import android.view.Gravity; import android.view.Menu; import android.view.MenuItem; import android.view.View; import android.widget.AdapterView; import android.widget.FilterQueryProvider; import android.widget.ListView; import android.widget.ProgressBar; import android.widget.SearchView; import android.widget.SimpleCursorAdapter; import android.widget.Toast; public class NotePadMainActivity extends ListActivity { /** * The serialization (saved instance state) Bundle key representing the * current dropdown position. */ private static final String STATE_SELECTED_NAVIGATION_ITEM = "selected_navigation_item"; private static INoteRepository noteRepository = null; private SimpleCursorAdapter adapter; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_note_pad_main); noteRepository = new NoteRepository(getApplicationContext()); //progress bar ProgressBar progressBar = new ProgressBar(this); progressBar.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT, Gravity.CENTER)); progressBar.setIndeterminate(true); getListView().setEmptyView(progressBar); //adaptor adapter = new SimpleCursorAdapter(getApplicationContext(),R.layout.notes_list_row, noteRepository.getCursor(), new String[] { "title" }, new int[] {R.id.noteTitle }); adapter.setFilterQueryProvider(new FilterQueryProvider() { @Override public Cursor runQuery(CharSequence constraint) { return noteRepository.getWhereTitleContains(constraint); } }); getListView().setChoiceMode(ListView.CHOICE_MODE_MULTIPLE); setListAdapter(adapter); //search view SearchView searchView = (SearchView) findViewById(R.id.searchView1); searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() { @Override public boolean onQueryTextSubmit(String query) { adapter.getFilter().filter(query); return true; } @Override public boolean onQueryTextChange(String newText) { adapter.getFilter().filter(newText); return true; } }); //item click listener getListView().setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { Cursor cursor = (Cursor) adapter.getItem(position); int indexOfIdColumn = cursor.getColumnIndex(BaseColumns._ID); Note note = noteRepository.getNoteById(cursor.getLong(indexOfIdColumn)); Intent intent = new Intent(getApplicationContext(), NoteActivity.class); intent.putExtra("noteObject", note); startActivity(intent); } }); } /** * Backward-compatible version of {@link ActionBar#getThemedContext()} that * simply returns the {@link android.app.Activity} if * <code>getThemedContext</code> is unavailable. */ @TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH) private Context getActionBarThemedContextCompat() { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) { return getActionBar().getThemedContext(); } else { return this; } } @Override public void onRestoreInstanceState(Bundle savedInstanceState) { // Restore the previously serialized current dropdown position. if (savedInstanceState.containsKey(STATE_SELECTED_NAVIGATION_ITEM)) { getActionBar().setSelectedNavigationItem( savedInstanceState.getInt(STATE_SELECTED_NAVIGATION_ITEM)); } } @Override public void onSaveInstanceState(Bundle outState) { // Serialize the current dropdown position. outState.putInt(STATE_SELECTED_NAVIGATION_ITEM, getActionBar() .getSelectedNavigationIndex()); } @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_pad_main, menu); return true; } //action bar menus @Override public boolean onMenuItemSelected(int featureId, MenuItem item) { Toast msg = null; switch (item.getItemId()) { case R.id.action_new: //msg = Toast.makeText(getApplicationContext(), "Add Option Selected", Toast.LENGTH_SHORT); Intent intent = new Intent(getApplicationContext(), NoteActivity.class); startActivity(intent); break; case R.id.action_remove: msg = Toast.makeText(getApplicationContext(), "Remove Option Selected", Toast.LENGTH_SHORT); break; case R.id.action_sort: msg = Toast.makeText(getApplicationContext(), "Sort Option Selected", Toast.LENGTH_SHORT); break; default: msg = Toast.makeText(getApplicationContext(), "Unknown Option Selected", Toast.LENGTH_SHORT); break; } msg.show(); return true; } }