summaryrefslogtreecommitdiffstats
path: root/tutorials/NotepadCodeLab/Notepadv2Solution
diff options
context:
space:
mode:
Diffstat (limited to 'tutorials/NotepadCodeLab/Notepadv2Solution')
-rw-r--r--tutorials/NotepadCodeLab/Notepadv2Solution/Android.mk1
-rwxr-xr-xtutorials/NotepadCodeLab/Notepadv2Solution/AndroidManifest.xml2
-rwxr-xr-xtutorials/NotepadCodeLab/Notepadv2Solution/src/com/android/demo/notepad2/NoteEdit.java20
-rwxr-xr-xtutorials/NotepadCodeLab/Notepadv2Solution/src/com/android/demo/notepad2/Notepadv2.java99
-rwxr-xr-xtutorials/NotepadCodeLab/Notepadv2Solution/src/com/android/demo/notepad2/NotesDbAdapter.java14
5 files changed, 69 insertions, 67 deletions
diff --git a/tutorials/NotepadCodeLab/Notepadv2Solution/Android.mk b/tutorials/NotepadCodeLab/Notepadv2Solution/Android.mk
index 8e483519b..63961a32e 100644
--- a/tutorials/NotepadCodeLab/Notepadv2Solution/Android.mk
+++ b/tutorials/NotepadCodeLab/Notepadv2Solution/Android.mk
@@ -17,6 +17,7 @@
LOCAL_PATH:= $(call my-dir)
include $(CLEAR_VARS)
+# Only build apk if this package is added to CUSTOM_MODLUES in buildspec.mk
LOCAL_MODULE_TAGS := optional
# Only compile source java files in this apk.
diff --git a/tutorials/NotepadCodeLab/Notepadv2Solution/AndroidManifest.xml b/tutorials/NotepadCodeLab/Notepadv2Solution/AndroidManifest.xml
index dbfc9d0f7..b86a7419c 100755
--- a/tutorials/NotepadCodeLab/Notepadv2Solution/AndroidManifest.xml
+++ b/tutorials/NotepadCodeLab/Notepadv2Solution/AndroidManifest.xml
@@ -7,6 +7,6 @@
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
- <activity android:name=".NoteEdit"></activity>
+ <activity android:name=".NoteEdit" />
</application>
</manifest> \ No newline at end of file
diff --git a/tutorials/NotepadCodeLab/Notepadv2Solution/src/com/android/demo/notepad2/NoteEdit.java b/tutorials/NotepadCodeLab/Notepadv2Solution/src/com/android/demo/notepad2/NoteEdit.java
index 6c5e664b5..8c9dccc6b 100755
--- a/tutorials/NotepadCodeLab/Notepadv2Solution/src/com/android/demo/notepad2/NoteEdit.java
+++ b/tutorials/NotepadCodeLab/Notepadv2Solution/src/com/android/demo/notepad2/NoteEdit.java
@@ -9,7 +9,7 @@
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.savedInstanceState
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
@@ -25,7 +25,7 @@ import android.widget.EditText;
public class NoteEdit extends Activity {
- private EditText mTitleText;
+ private EditText mTitleText;
private EditText mBodyText;
private Long mRowId;
@@ -33,19 +33,19 @@ public class NoteEdit extends Activity {
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.note_edit);
-
+
mTitleText = (EditText) findViewById(R.id.title);
mBodyText = (EditText) findViewById(R.id.body);
-
+
Button confirmButton = (Button) findViewById(R.id.confirm);
-
+
mRowId = null;
Bundle extras = getIntent().getExtras();
if (extras != null) {
String title = extras.getString(NotesDbAdapter.KEY_TITLE);
String body = extras.getString(NotesDbAdapter.KEY_BODY);
mRowId = extras.getLong(NotesDbAdapter.KEY_ROWID);
-
+
if (title != null) {
mTitleText.setText(title);
}
@@ -53,24 +53,24 @@ public class NoteEdit extends Activity {
mBodyText.setText(body);
}
}
-
+
confirmButton.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
Bundle bundle = new Bundle();
-
+
bundle.putString(NotesDbAdapter.KEY_TITLE, mTitleText.getText().toString());
bundle.putString(NotesDbAdapter.KEY_BODY, mBodyText.getText().toString());
if (mRowId != null) {
bundle.putLong(NotesDbAdapter.KEY_ROWID, mRowId);
}
-
+
Intent mIntent = new Intent();
mIntent.putExtras(bundle);
setResult(RESULT_OK, mIntent);
finish();
}
-
+
});
}
}
diff --git a/tutorials/NotepadCodeLab/Notepadv2Solution/src/com/android/demo/notepad2/Notepadv2.java b/tutorials/NotepadCodeLab/Notepadv2Solution/src/com/android/demo/notepad2/Notepadv2.java
index 1b3398291..c65806be1 100755
--- a/tutorials/NotepadCodeLab/Notepadv2Solution/src/com/android/demo/notepad2/Notepadv2.java
+++ b/tutorials/NotepadCodeLab/Notepadv2Solution/src/com/android/demo/notepad2/Notepadv2.java
@@ -32,13 +32,13 @@ import android.widget.AdapterView.AdapterContextMenuInfo;
public class Notepadv2 extends ListActivity {
private static final int ACTIVITY_CREATE=0;
private static final int ACTIVITY_EDIT=1;
-
+
private static final int INSERT_ID = Menu.FIRST;
private static final int DELETE_ID = Menu.FIRST + 1;
private NotesDbAdapter mDbHelper;
private Cursor mNotesCursor;
-
+
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
@@ -49,68 +49,69 @@ public class Notepadv2 extends ListActivity {
fillData();
registerForContextMenu(getListView());
}
-
+
private void fillData() {
// Get all of the rows from the database and create the item list
mNotesCursor = mDbHelper.fetchAllNotes();
startManagingCursor(mNotesCursor);
-
+
// Create an array to specify the fields we want to display in the list (only TITLE)
String[] from = new String[]{NotesDbAdapter.KEY_TITLE};
-
+
// and an array of the fields we want to bind those fields to (in this case just text1)
int[] to = new int[]{R.id.text1};
-
+
// Now create a simple cursor adapter and set it to display
SimpleCursorAdapter notes =
- new SimpleCursorAdapter(this, R.layout.notes_row, mNotesCursor, from, to);
+ new SimpleCursorAdapter(this, R.layout.notes_row, mNotesCursor, from, to);
setListAdapter(notes);
}
-
+
@Override
public boolean onCreateOptionsMenu(Menu menu) {
super.onCreateOptionsMenu(menu);
- menu.add(0, INSERT_ID,0, R.string.menu_insert);
+ menu.add(0, INSERT_ID, 0, R.string.menu_insert);
return true;
}
-
+
@Override
public boolean onMenuItemSelected(int featureId, MenuItem item) {
switch(item.getItemId()) {
- case INSERT_ID:
- createNote();
- return true;
- }
+ case INSERT_ID:
+ createNote();
+ return true;
+ }
+
return super.onMenuItemSelected(featureId, item);
}
@Override
- public void onCreateContextMenu(ContextMenu menu, View v,
- ContextMenuInfo menuInfo) {
- super.onCreateContextMenu(menu, v, menuInfo);
+ public void onCreateContextMenu(ContextMenu menu, View v,
+ ContextMenuInfo menuInfo) {
+ super.onCreateContextMenu(menu, v, menuInfo);
menu.add(0, DELETE_ID, 0, R.string.menu_delete);
- }
+ }
@Override
- public boolean onContextItemSelected(MenuItem item) {
- switch(item.getItemId()) {
- case DELETE_ID:
- AdapterContextMenuInfo info = (AdapterContextMenuInfo) item.getMenuInfo();
- mDbHelper.deleteNote(info.id);
- fillData();
- return true;
- }
- return super.onContextItemSelected(item);
- }
-
- private void createNote() {
- Intent i = new Intent(this, NoteEdit.class);
- startActivityForResult(i, ACTIVITY_CREATE);
+ public boolean onContextItemSelected(MenuItem item) {
+ switch(item.getItemId()) {
+ case DELETE_ID:
+ AdapterContextMenuInfo info = (AdapterContextMenuInfo) item.getMenuInfo();
+ mDbHelper.deleteNote(info.id);
+ fillData();
+ return true;
+ }
+ return super.onContextItemSelected(item);
}
-
+
+ private void createNote() {
+ Intent i = new Intent(this, NoteEdit.class);
+ startActivityForResult(i, ACTIVITY_CREATE);
+ }
+
@Override
protected void onListItemClick(ListView l, View v, int position, long id) {
- super.onListItemClick(l, v, position, id);
+ super.onListItemClick(l, v, position, id);
Cursor c = mNotesCursor;
c.moveToPosition(position);
Intent i = new Intent(this, NoteEdit.class);
@@ -127,21 +128,21 @@ public class Notepadv2 extends ListActivity {
super.onActivityResult(requestCode, resultCode, intent);
Bundle extras = intent.getExtras();
switch(requestCode) {
- case ACTIVITY_CREATE:
- String title = extras.getString(NotesDbAdapter.KEY_TITLE);
- String body = extras.getString(NotesDbAdapter.KEY_BODY);
- mDbHelper.createNote(title, body);
- fillData();
- break;
- case ACTIVITY_EDIT:
- Long rowId = extras.getLong(NotesDbAdapter.KEY_ROWID);
- if (rowId != null) {
- String editTitle = extras.getString(NotesDbAdapter.KEY_TITLE);
- String editBody = extras.getString(NotesDbAdapter.KEY_BODY);
- mDbHelper.updateNote(rowId, editTitle, editBody);
- }
- fillData();
- break;
+ case ACTIVITY_CREATE:
+ String title = extras.getString(NotesDbAdapter.KEY_TITLE);
+ String body = extras.getString(NotesDbAdapter.KEY_BODY);
+ mDbHelper.createNote(title, body);
+ fillData();
+ break;
+ case ACTIVITY_EDIT:
+ Long rowId = extras.getLong(NotesDbAdapter.KEY_ROWID);
+ if (rowId != null) {
+ String editTitle = extras.getString(NotesDbAdapter.KEY_TITLE);
+ String editBody = extras.getString(NotesDbAdapter.KEY_BODY);
+ mDbHelper.updateNote(rowId, editTitle, editBody);
+ }
+ fillData();
+ break;
}
}
}
diff --git a/tutorials/NotepadCodeLab/Notepadv2Solution/src/com/android/demo/notepad2/NotesDbAdapter.java b/tutorials/NotepadCodeLab/Notepadv2Solution/src/com/android/demo/notepad2/NotesDbAdapter.java
index 5bf51b1e5..50994ae43 100755
--- a/tutorials/NotepadCodeLab/Notepadv2Solution/src/com/android/demo/notepad2/NotesDbAdapter.java
+++ b/tutorials/NotepadCodeLab/Notepadv2Solution/src/com/android/demo/notepad2/NotesDbAdapter.java
@@ -43,13 +43,13 @@ public class NotesDbAdapter {
private static final String TAG = "NotesDbAdapter";
private DatabaseHelper mDbHelper;
private SQLiteDatabase mDb;
-
+
/**
* Database creation sql statement
*/
private static final String DATABASE_CREATE =
- "create table notes (_id integer primary key autoincrement, "
- + "title text not null, body text not null);";
+ "create table notes (_id integer primary key autoincrement, "
+ + "title text not null, body text not null);";
private static final String DATABASE_NAME = "data";
private static final String DATABASE_TABLE = "notes";
@@ -102,7 +102,7 @@ public class NotesDbAdapter {
mDb = mDbHelper.getWritableDatabase();
return this;
}
-
+
public void close() {
mDbHelper.close();
}
@@ -158,9 +158,9 @@ public class NotesDbAdapter {
Cursor mCursor =
- mDb.query(true, DATABASE_TABLE, new String[] {KEY_ROWID,
- KEY_TITLE, KEY_BODY}, KEY_ROWID + "=" + rowId, null,
- null, null, null, null);
+ mDb.query(true, DATABASE_TABLE, new String[] {KEY_ROWID,
+ KEY_TITLE, KEY_BODY}, KEY_ROWID + "=" + rowId, null,
+ null, null, null, null);
if (mCursor != null) {
mCursor.moveToFirst();
}