1/*
2 * Copyright (C) 2008 Google Inc.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *      http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.android.demo.notepad2;
18
19import android.app.ListActivity;
20import android.content.Intent;
21import android.database.Cursor;
22import android.os.Bundle;
23import android.view.ContextMenu;
24import android.view.Menu;
25import android.view.MenuItem;
26import android.view.View;
27import android.view.ContextMenu.ContextMenuInfo;
28import android.widget.ListView;
29import android.widget.SimpleCursorAdapter;
30
31public class Notepadv2 extends ListActivity {
32    private static final int ACTIVITY_CREATE=0;
33    private static final int ACTIVITY_EDIT=1;
34
35    private static final int INSERT_ID = Menu.FIRST;
36    private static final int DELETE_ID = Menu.FIRST + 1;
37
38    private NotesDbAdapter mDbHelper;
39    private Cursor mNotesCursor;
40
41    /** Called when the activity is first created. */
42    @Override
43    public void onCreate(Bundle savedInstanceState) {
44        super.onCreate(savedInstanceState);
45        setContentView(R.layout.notes_list);
46        mDbHelper = new NotesDbAdapter(this);
47        mDbHelper.open();
48        fillData();
49    }
50
51    private void fillData() {
52        // Get all of the rows from the database and create the item list
53        mNotesCursor = mDbHelper.fetchAllNotes();
54        startManagingCursor(mNotesCursor);
55
56        // Create an array to specify the fields we want to display in the list (only TITLE)
57        String[] from = new String[]{NotesDbAdapter.KEY_TITLE};
58
59        // and an array of the fields we want to bind those fields to (in this case just text1)
60        int[] to = new int[]{R.id.text1};
61
62        // Now create a simple cursor adapter and set it to display
63        SimpleCursorAdapter notes =
64        	    new SimpleCursorAdapter(this, R.layout.notes_row, mNotesCursor, from, to);
65        setListAdapter(notes);
66    }
67
68    @Override
69    public boolean onCreateOptionsMenu(Menu menu) {
70        super.onCreateOptionsMenu(menu);
71        menu.add(0, INSERT_ID,0, R.string.menu_insert);
72        return true;
73    }
74
75    @Override
76    public boolean onMenuItemSelected(int featureId, MenuItem item) {
77        switch(item.getItemId()) {
78        case INSERT_ID:
79            createNote();
80            return true;
81        }
82
83        return super.onMenuItemSelected(featureId, item);
84    }
85
86    @Override
87	public void onCreateContextMenu(ContextMenu menu, View v,
88			ContextMenuInfo menuInfo) {
89		super.onCreateContextMenu(menu, v, menuInfo);
90
91        // TODO: fill in rest of method
92	}
93
94    @Override
95	public boolean onContextItemSelected(MenuItem item) {
96		return super.onContextItemSelected(item);
97
98        // TODO: fill in rest of method
99	}
100
101    private void createNote() {
102        // TODO: fill in implementation
103
104    }
105
106    @Override
107    protected void onListItemClick(ListView l, View v, int position, long id) {
108        super.onListItemClick(l, v, position, id);
109
110        // TODO: fill in rest of method
111
112    }
113
114    @Override
115    protected void onActivityResult(int requestCode, int resultCode, Intent intent) {
116        super.onActivityResult(requestCode, resultCode, intent);
117
118        // TODO: fill in rest of method
119
120    }
121
122}
123