Finish adding Makefiles for the Notepad tutorial.
Add the missing makefiles for the non-solution versions of the tutorial code. Required providing missing imports in Notepadv2. Also standardized white spaces using Source > Correct Indentation in Eclipse and a few manual changes. This was done to minimize differences such as: diff -r Notepadv1 Notepadv1Solution diff -r Notepadv1Solution/src/com/android/demo/notepad1/ Notepadv2/src/com/android/demo/notepad2/ Change-Id: Ie8b10efd61f2200b3c741ea500a6924710ab54ed
This commit is contained in:
31
tutorials/NotepadCodeLab/Notepadv1/Android.mk
Normal file
31
tutorials/NotepadCodeLab/Notepadv1/Android.mk
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
#
|
||||||
|
# Copyright (C) 2009 The Android Open Source Project
|
||||||
|
#
|
||||||
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
# you may not use this file except in compliance with the License.
|
||||||
|
# You may obtain a copy of the License at
|
||||||
|
#
|
||||||
|
# http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
#
|
||||||
|
# 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.
|
||||||
|
# See the License for the specific language governing permissions and
|
||||||
|
# limitations under the License.
|
||||||
|
#
|
||||||
|
|
||||||
|
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.
|
||||||
|
LOCAL_SRC_FILES := $(call all-java-files-under, src)
|
||||||
|
|
||||||
|
LOCAL_PACKAGE_NAME := Notepadv1
|
||||||
|
|
||||||
|
# Make the app build against the current SDK
|
||||||
|
LOCAL_SDK_VERSION := current
|
||||||
|
|
||||||
|
include $(BUILD_PACKAGE)
|
||||||
@@ -1,5 +1,6 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.android.demo.notepad1">
|
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
package="com.android.demo.notepad1">
|
||||||
<application android:icon="@drawable/icon">
|
<application android:icon="@drawable/icon">
|
||||||
<activity android:name=".Notepadv1" android:label="@string/app_name">
|
<activity android:name=".Notepadv1" android:label="@string/app_name">
|
||||||
<intent-filter>
|
<intent-filter>
|
||||||
|
|||||||
@@ -22,8 +22,8 @@ import android.view.Menu;
|
|||||||
import android.view.MenuItem;
|
import android.view.MenuItem;
|
||||||
|
|
||||||
public class Notepadv1 extends Activity {
|
public class Notepadv1 extends Activity {
|
||||||
private int mNoteNumber = 1;
|
private int mNoteNumber = 1;
|
||||||
|
|
||||||
/** Called when the activity is first created. */
|
/** Called when the activity is first created. */
|
||||||
@Override
|
@Override
|
||||||
public void onCreate(Bundle savedInstanceState) {
|
public void onCreate(Bundle savedInstanceState) {
|
||||||
|
|||||||
@@ -43,13 +43,13 @@ public class NotesDbAdapter {
|
|||||||
private static final String TAG = "NotesDbAdapter";
|
private static final String TAG = "NotesDbAdapter";
|
||||||
private DatabaseHelper mDbHelper;
|
private DatabaseHelper mDbHelper;
|
||||||
private SQLiteDatabase mDb;
|
private SQLiteDatabase mDb;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Database creation sql statement
|
* Database creation sql statement
|
||||||
*/
|
*/
|
||||||
private static final String DATABASE_CREATE =
|
private static final String DATABASE_CREATE =
|
||||||
"create table notes (_id integer primary key autoincrement, "
|
"create table notes (_id integer primary key autoincrement, "
|
||||||
+ "title text not null, body text not null);";
|
+ "title text not null, body text not null);";
|
||||||
|
|
||||||
private static final String DATABASE_NAME = "data";
|
private static final String DATABASE_NAME = "data";
|
||||||
private static final String DATABASE_TABLE = "notes";
|
private static final String DATABASE_TABLE = "notes";
|
||||||
@@ -102,7 +102,7 @@ public class NotesDbAdapter {
|
|||||||
mDb = mDbHelper.getWritableDatabase();
|
mDb = mDbHelper.getWritableDatabase();
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void close() {
|
public void close() {
|
||||||
mDbHelper.close();
|
mDbHelper.close();
|
||||||
}
|
}
|
||||||
@@ -158,9 +158,9 @@ public class NotesDbAdapter {
|
|||||||
|
|
||||||
Cursor mCursor =
|
Cursor mCursor =
|
||||||
|
|
||||||
mDb.query(true, DATABASE_TABLE, new String[] {KEY_ROWID,
|
mDb.query(true, DATABASE_TABLE, new String[] {KEY_ROWID,
|
||||||
KEY_TITLE, KEY_BODY}, KEY_ROWID + "=" + rowId, null,
|
KEY_TITLE, KEY_BODY}, KEY_ROWID + "=" + rowId, null,
|
||||||
null, null, null, null);
|
null, null, null, null);
|
||||||
if (mCursor != null) {
|
if (mCursor != null) {
|
||||||
mCursor.moveToFirst();
|
mCursor.moveToFirst();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,6 +17,7 @@
|
|||||||
LOCAL_PATH:= $(call my-dir)
|
LOCAL_PATH:= $(call my-dir)
|
||||||
include $(CLEAR_VARS)
|
include $(CLEAR_VARS)
|
||||||
|
|
||||||
|
# Only build apk if this package is added to CUSTOM_MODLUES in buildspec.mk
|
||||||
LOCAL_MODULE_TAGS := optional
|
LOCAL_MODULE_TAGS := optional
|
||||||
|
|
||||||
# Only compile source java files in this apk.
|
# Only compile source java files in this apk.
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<TextView android:id="@+id/text1"
|
<TextView android:id="@+id/text1" xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"/>
|
android:layout_height="wrap_content"/>
|
||||||
|
|||||||
@@ -43,13 +43,13 @@ public class NotesDbAdapter {
|
|||||||
private static final String TAG = "NotesDbAdapter";
|
private static final String TAG = "NotesDbAdapter";
|
||||||
private DatabaseHelper mDbHelper;
|
private DatabaseHelper mDbHelper;
|
||||||
private SQLiteDatabase mDb;
|
private SQLiteDatabase mDb;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Database creation sql statement
|
* Database creation sql statement
|
||||||
*/
|
*/
|
||||||
private static final String DATABASE_CREATE =
|
private static final String DATABASE_CREATE =
|
||||||
"create table notes (_id integer primary key autoincrement, "
|
"create table notes (_id integer primary key autoincrement, "
|
||||||
+ "title text not null, body text not null);";
|
+ "title text not null, body text not null);";
|
||||||
|
|
||||||
private static final String DATABASE_NAME = "data";
|
private static final String DATABASE_NAME = "data";
|
||||||
private static final String DATABASE_TABLE = "notes";
|
private static final String DATABASE_TABLE = "notes";
|
||||||
@@ -102,7 +102,7 @@ public class NotesDbAdapter {
|
|||||||
mDb = mDbHelper.getWritableDatabase();
|
mDb = mDbHelper.getWritableDatabase();
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void close() {
|
public void close() {
|
||||||
mDbHelper.close();
|
mDbHelper.close();
|
||||||
}
|
}
|
||||||
@@ -158,9 +158,9 @@ public class NotesDbAdapter {
|
|||||||
|
|
||||||
Cursor mCursor =
|
Cursor mCursor =
|
||||||
|
|
||||||
mDb.query(true, DATABASE_TABLE, new String[] {KEY_ROWID,
|
mDb.query(true, DATABASE_TABLE, new String[] {KEY_ROWID,
|
||||||
KEY_TITLE, KEY_BODY}, KEY_ROWID + "=" + rowId, null,
|
KEY_TITLE, KEY_BODY}, KEY_ROWID + "=" + rowId, null,
|
||||||
null, null, null, null);
|
null, null, null, null);
|
||||||
if (mCursor != null) {
|
if (mCursor != null) {
|
||||||
mCursor.moveToFirst();
|
mCursor.moveToFirst();
|
||||||
}
|
}
|
||||||
|
|||||||
31
tutorials/NotepadCodeLab/Notepadv2/Android.mk
Normal file
31
tutorials/NotepadCodeLab/Notepadv2/Android.mk
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
#
|
||||||
|
# Copyright (C) 2009 The Android Open Source Project
|
||||||
|
#
|
||||||
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
# you may not use this file except in compliance with the License.
|
||||||
|
# You may obtain a copy of the License at
|
||||||
|
#
|
||||||
|
# http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
#
|
||||||
|
# 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.
|
||||||
|
# See the License for the specific language governing permissions and
|
||||||
|
# limitations under the License.
|
||||||
|
#
|
||||||
|
|
||||||
|
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.
|
||||||
|
LOCAL_SRC_FILES := $(call all-java-files-under, src)
|
||||||
|
|
||||||
|
LOCAL_PACKAGE_NAME := Notepadv2
|
||||||
|
|
||||||
|
# Make the app build against the current SDK
|
||||||
|
LOCAL_SDK_VERSION := current
|
||||||
|
|
||||||
|
include $(BUILD_PACKAGE)
|
||||||
@@ -20,9 +20,11 @@ import android.app.ListActivity;
|
|||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.database.Cursor;
|
import android.database.Cursor;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
import android.view.ContextMenu;
|
||||||
import android.view.Menu;
|
import android.view.Menu;
|
||||||
import android.view.MenuItem;
|
import android.view.MenuItem;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
|
import android.view.ContextMenu.ContextMenuInfo;
|
||||||
import android.widget.ListView;
|
import android.widget.ListView;
|
||||||
import android.widget.SimpleCursorAdapter;
|
import android.widget.SimpleCursorAdapter;
|
||||||
|
|
||||||
|
|||||||
@@ -43,13 +43,13 @@ public class NotesDbAdapter {
|
|||||||
private static final String TAG = "NotesDbAdapter";
|
private static final String TAG = "NotesDbAdapter";
|
||||||
private DatabaseHelper mDbHelper;
|
private DatabaseHelper mDbHelper;
|
||||||
private SQLiteDatabase mDb;
|
private SQLiteDatabase mDb;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Database creation sql statement
|
* Database creation sql statement
|
||||||
*/
|
*/
|
||||||
private static final String DATABASE_CREATE =
|
private static final String DATABASE_CREATE =
|
||||||
"create table notes (_id integer primary key autoincrement, "
|
"create table notes (_id integer primary key autoincrement, "
|
||||||
+ "title text not null, body text not null);";
|
+ "title text not null, body text not null);";
|
||||||
|
|
||||||
private static final String DATABASE_NAME = "data";
|
private static final String DATABASE_NAME = "data";
|
||||||
private static final String DATABASE_TABLE = "notes";
|
private static final String DATABASE_TABLE = "notes";
|
||||||
@@ -102,7 +102,7 @@ public class NotesDbAdapter {
|
|||||||
mDb = mDbHelper.getWritableDatabase();
|
mDb = mDbHelper.getWritableDatabase();
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void close() {
|
public void close() {
|
||||||
mDbHelper.close();
|
mDbHelper.close();
|
||||||
}
|
}
|
||||||
@@ -158,9 +158,9 @@ public class NotesDbAdapter {
|
|||||||
|
|
||||||
Cursor mCursor =
|
Cursor mCursor =
|
||||||
|
|
||||||
mDb.query(true, DATABASE_TABLE, new String[] {KEY_ROWID,
|
mDb.query(true, DATABASE_TABLE, new String[] {KEY_ROWID,
|
||||||
KEY_TITLE, KEY_BODY}, KEY_ROWID + "=" + rowId, null,
|
KEY_TITLE, KEY_BODY}, KEY_ROWID + "=" + rowId, null,
|
||||||
null, null, null, null);
|
null, null, null, null);
|
||||||
if (mCursor != null) {
|
if (mCursor != null) {
|
||||||
mCursor.moveToFirst();
|
mCursor.moveToFirst();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,6 +17,7 @@
|
|||||||
LOCAL_PATH:= $(call my-dir)
|
LOCAL_PATH:= $(call my-dir)
|
||||||
include $(CLEAR_VARS)
|
include $(CLEAR_VARS)
|
||||||
|
|
||||||
|
# Only build apk if this package is added to CUSTOM_MODLUES in buildspec.mk
|
||||||
LOCAL_MODULE_TAGS := optional
|
LOCAL_MODULE_TAGS := optional
|
||||||
|
|
||||||
# Only compile source java files in this apk.
|
# Only compile source java files in this apk.
|
||||||
|
|||||||
@@ -7,6 +7,6 @@
|
|||||||
<category android:name="android.intent.category.LAUNCHER" />
|
<category android:name="android.intent.category.LAUNCHER" />
|
||||||
</intent-filter>
|
</intent-filter>
|
||||||
</activity>
|
</activity>
|
||||||
<activity android:name=".NoteEdit"></activity>
|
<activity android:name=".NoteEdit" />
|
||||||
</application>
|
</application>
|
||||||
</manifest>
|
</manifest>
|
||||||
@@ -9,7 +9,7 @@
|
|||||||
*
|
*
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
* 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
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
@@ -25,7 +25,7 @@ import android.widget.EditText;
|
|||||||
|
|
||||||
public class NoteEdit extends Activity {
|
public class NoteEdit extends Activity {
|
||||||
|
|
||||||
private EditText mTitleText;
|
private EditText mTitleText;
|
||||||
private EditText mBodyText;
|
private EditText mBodyText;
|
||||||
private Long mRowId;
|
private Long mRowId;
|
||||||
|
|
||||||
@@ -33,19 +33,19 @@ public class NoteEdit extends Activity {
|
|||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
setContentView(R.layout.note_edit);
|
setContentView(R.layout.note_edit);
|
||||||
|
|
||||||
mTitleText = (EditText) findViewById(R.id.title);
|
mTitleText = (EditText) findViewById(R.id.title);
|
||||||
mBodyText = (EditText) findViewById(R.id.body);
|
mBodyText = (EditText) findViewById(R.id.body);
|
||||||
|
|
||||||
Button confirmButton = (Button) findViewById(R.id.confirm);
|
Button confirmButton = (Button) findViewById(R.id.confirm);
|
||||||
|
|
||||||
mRowId = null;
|
mRowId = null;
|
||||||
Bundle extras = getIntent().getExtras();
|
Bundle extras = getIntent().getExtras();
|
||||||
if (extras != null) {
|
if (extras != null) {
|
||||||
String title = extras.getString(NotesDbAdapter.KEY_TITLE);
|
String title = extras.getString(NotesDbAdapter.KEY_TITLE);
|
||||||
String body = extras.getString(NotesDbAdapter.KEY_BODY);
|
String body = extras.getString(NotesDbAdapter.KEY_BODY);
|
||||||
mRowId = extras.getLong(NotesDbAdapter.KEY_ROWID);
|
mRowId = extras.getLong(NotesDbAdapter.KEY_ROWID);
|
||||||
|
|
||||||
if (title != null) {
|
if (title != null) {
|
||||||
mTitleText.setText(title);
|
mTitleText.setText(title);
|
||||||
}
|
}
|
||||||
@@ -53,24 +53,24 @@ public class NoteEdit extends Activity {
|
|||||||
mBodyText.setText(body);
|
mBodyText.setText(body);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
confirmButton.setOnClickListener(new View.OnClickListener() {
|
confirmButton.setOnClickListener(new View.OnClickListener() {
|
||||||
|
|
||||||
public void onClick(View view) {
|
public void onClick(View view) {
|
||||||
Bundle bundle = new Bundle();
|
Bundle bundle = new Bundle();
|
||||||
|
|
||||||
bundle.putString(NotesDbAdapter.KEY_TITLE, mTitleText.getText().toString());
|
bundle.putString(NotesDbAdapter.KEY_TITLE, mTitleText.getText().toString());
|
||||||
bundle.putString(NotesDbAdapter.KEY_BODY, mBodyText.getText().toString());
|
bundle.putString(NotesDbAdapter.KEY_BODY, mBodyText.getText().toString());
|
||||||
if (mRowId != null) {
|
if (mRowId != null) {
|
||||||
bundle.putLong(NotesDbAdapter.KEY_ROWID, mRowId);
|
bundle.putLong(NotesDbAdapter.KEY_ROWID, mRowId);
|
||||||
}
|
}
|
||||||
|
|
||||||
Intent mIntent = new Intent();
|
Intent mIntent = new Intent();
|
||||||
mIntent.putExtras(bundle);
|
mIntent.putExtras(bundle);
|
||||||
setResult(RESULT_OK, mIntent);
|
setResult(RESULT_OK, mIntent);
|
||||||
finish();
|
finish();
|
||||||
}
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -32,13 +32,13 @@ import android.widget.AdapterView.AdapterContextMenuInfo;
|
|||||||
public class Notepadv2 extends ListActivity {
|
public class Notepadv2 extends ListActivity {
|
||||||
private static final int ACTIVITY_CREATE=0;
|
private static final int ACTIVITY_CREATE=0;
|
||||||
private static final int ACTIVITY_EDIT=1;
|
private static final int ACTIVITY_EDIT=1;
|
||||||
|
|
||||||
private static final int INSERT_ID = Menu.FIRST;
|
private static final int INSERT_ID = Menu.FIRST;
|
||||||
private static final int DELETE_ID = Menu.FIRST + 1;
|
private static final int DELETE_ID = Menu.FIRST + 1;
|
||||||
|
|
||||||
private NotesDbAdapter mDbHelper;
|
private NotesDbAdapter mDbHelper;
|
||||||
private Cursor mNotesCursor;
|
private Cursor mNotesCursor;
|
||||||
|
|
||||||
/** Called when the activity is first created. */
|
/** Called when the activity is first created. */
|
||||||
@Override
|
@Override
|
||||||
public void onCreate(Bundle savedInstanceState) {
|
public void onCreate(Bundle savedInstanceState) {
|
||||||
@@ -49,68 +49,69 @@ public class Notepadv2 extends ListActivity {
|
|||||||
fillData();
|
fillData();
|
||||||
registerForContextMenu(getListView());
|
registerForContextMenu(getListView());
|
||||||
}
|
}
|
||||||
|
|
||||||
private void fillData() {
|
private void fillData() {
|
||||||
// Get all of the rows from the database and create the item list
|
// Get all of the rows from the database and create the item list
|
||||||
mNotesCursor = mDbHelper.fetchAllNotes();
|
mNotesCursor = mDbHelper.fetchAllNotes();
|
||||||
startManagingCursor(mNotesCursor);
|
startManagingCursor(mNotesCursor);
|
||||||
|
|
||||||
// Create an array to specify the fields we want to display in the list (only TITLE)
|
// Create an array to specify the fields we want to display in the list (only TITLE)
|
||||||
String[] from = new String[]{NotesDbAdapter.KEY_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)
|
// 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};
|
int[] to = new int[]{R.id.text1};
|
||||||
|
|
||||||
// Now create a simple cursor adapter and set it to display
|
// Now create a simple cursor adapter and set it to display
|
||||||
SimpleCursorAdapter notes =
|
SimpleCursorAdapter notes =
|
||||||
new SimpleCursorAdapter(this, R.layout.notes_row, mNotesCursor, from, to);
|
new SimpleCursorAdapter(this, R.layout.notes_row, mNotesCursor, from, to);
|
||||||
setListAdapter(notes);
|
setListAdapter(notes);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onCreateOptionsMenu(Menu menu) {
|
public boolean onCreateOptionsMenu(Menu menu) {
|
||||||
super.onCreateOptionsMenu(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;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onMenuItemSelected(int featureId, MenuItem item) {
|
public boolean onMenuItemSelected(int featureId, MenuItem item) {
|
||||||
switch(item.getItemId()) {
|
switch(item.getItemId()) {
|
||||||
case INSERT_ID:
|
case INSERT_ID:
|
||||||
createNote();
|
createNote();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
return super.onMenuItemSelected(featureId, item);
|
return super.onMenuItemSelected(featureId, item);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCreateContextMenu(ContextMenu menu, View v,
|
public void onCreateContextMenu(ContextMenu menu, View v,
|
||||||
ContextMenuInfo menuInfo) {
|
ContextMenuInfo menuInfo) {
|
||||||
super.onCreateContextMenu(menu, v, menuInfo);
|
super.onCreateContextMenu(menu, v, menuInfo);
|
||||||
menu.add(0, DELETE_ID, 0, R.string.menu_delete);
|
menu.add(0, DELETE_ID, 0, R.string.menu_delete);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onContextItemSelected(MenuItem item) {
|
public boolean onContextItemSelected(MenuItem item) {
|
||||||
switch(item.getItemId()) {
|
switch(item.getItemId()) {
|
||||||
case DELETE_ID:
|
case DELETE_ID:
|
||||||
AdapterContextMenuInfo info = (AdapterContextMenuInfo) item.getMenuInfo();
|
AdapterContextMenuInfo info = (AdapterContextMenuInfo) item.getMenuInfo();
|
||||||
mDbHelper.deleteNote(info.id);
|
mDbHelper.deleteNote(info.id);
|
||||||
fillData();
|
fillData();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return super.onContextItemSelected(item);
|
return super.onContextItemSelected(item);
|
||||||
}
|
|
||||||
|
|
||||||
private void createNote() {
|
|
||||||
Intent i = new Intent(this, NoteEdit.class);
|
|
||||||
startActivityForResult(i, ACTIVITY_CREATE);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void createNote() {
|
||||||
|
Intent i = new Intent(this, NoteEdit.class);
|
||||||
|
startActivityForResult(i, ACTIVITY_CREATE);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onListItemClick(ListView l, View v, int position, long id) {
|
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;
|
Cursor c = mNotesCursor;
|
||||||
c.moveToPosition(position);
|
c.moveToPosition(position);
|
||||||
Intent i = new Intent(this, NoteEdit.class);
|
Intent i = new Intent(this, NoteEdit.class);
|
||||||
@@ -127,21 +128,21 @@ public class Notepadv2 extends ListActivity {
|
|||||||
super.onActivityResult(requestCode, resultCode, intent);
|
super.onActivityResult(requestCode, resultCode, intent);
|
||||||
Bundle extras = intent.getExtras();
|
Bundle extras = intent.getExtras();
|
||||||
switch(requestCode) {
|
switch(requestCode) {
|
||||||
case ACTIVITY_CREATE:
|
case ACTIVITY_CREATE:
|
||||||
String title = extras.getString(NotesDbAdapter.KEY_TITLE);
|
String title = extras.getString(NotesDbAdapter.KEY_TITLE);
|
||||||
String body = extras.getString(NotesDbAdapter.KEY_BODY);
|
String body = extras.getString(NotesDbAdapter.KEY_BODY);
|
||||||
mDbHelper.createNote(title, body);
|
mDbHelper.createNote(title, body);
|
||||||
fillData();
|
fillData();
|
||||||
break;
|
break;
|
||||||
case ACTIVITY_EDIT:
|
case ACTIVITY_EDIT:
|
||||||
Long rowId = extras.getLong(NotesDbAdapter.KEY_ROWID);
|
Long rowId = extras.getLong(NotesDbAdapter.KEY_ROWID);
|
||||||
if (rowId != null) {
|
if (rowId != null) {
|
||||||
String editTitle = extras.getString(NotesDbAdapter.KEY_TITLE);
|
String editTitle = extras.getString(NotesDbAdapter.KEY_TITLE);
|
||||||
String editBody = extras.getString(NotesDbAdapter.KEY_BODY);
|
String editBody = extras.getString(NotesDbAdapter.KEY_BODY);
|
||||||
mDbHelper.updateNote(rowId, editTitle, editBody);
|
mDbHelper.updateNote(rowId, editTitle, editBody);
|
||||||
}
|
}
|
||||||
fillData();
|
fillData();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -43,13 +43,13 @@ public class NotesDbAdapter {
|
|||||||
private static final String TAG = "NotesDbAdapter";
|
private static final String TAG = "NotesDbAdapter";
|
||||||
private DatabaseHelper mDbHelper;
|
private DatabaseHelper mDbHelper;
|
||||||
private SQLiteDatabase mDb;
|
private SQLiteDatabase mDb;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Database creation sql statement
|
* Database creation sql statement
|
||||||
*/
|
*/
|
||||||
private static final String DATABASE_CREATE =
|
private static final String DATABASE_CREATE =
|
||||||
"create table notes (_id integer primary key autoincrement, "
|
"create table notes (_id integer primary key autoincrement, "
|
||||||
+ "title text not null, body text not null);";
|
+ "title text not null, body text not null);";
|
||||||
|
|
||||||
private static final String DATABASE_NAME = "data";
|
private static final String DATABASE_NAME = "data";
|
||||||
private static final String DATABASE_TABLE = "notes";
|
private static final String DATABASE_TABLE = "notes";
|
||||||
@@ -102,7 +102,7 @@ public class NotesDbAdapter {
|
|||||||
mDb = mDbHelper.getWritableDatabase();
|
mDb = mDbHelper.getWritableDatabase();
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void close() {
|
public void close() {
|
||||||
mDbHelper.close();
|
mDbHelper.close();
|
||||||
}
|
}
|
||||||
@@ -158,9 +158,9 @@ public class NotesDbAdapter {
|
|||||||
|
|
||||||
Cursor mCursor =
|
Cursor mCursor =
|
||||||
|
|
||||||
mDb.query(true, DATABASE_TABLE, new String[] {KEY_ROWID,
|
mDb.query(true, DATABASE_TABLE, new String[] {KEY_ROWID,
|
||||||
KEY_TITLE, KEY_BODY}, KEY_ROWID + "=" + rowId, null,
|
KEY_TITLE, KEY_BODY}, KEY_ROWID + "=" + rowId, null,
|
||||||
null, null, null, null);
|
null, null, null, null);
|
||||||
if (mCursor != null) {
|
if (mCursor != null) {
|
||||||
mCursor.moveToFirst();
|
mCursor.moveToFirst();
|
||||||
}
|
}
|
||||||
|
|||||||
31
tutorials/NotepadCodeLab/Notepadv3/Android.mk
Normal file
31
tutorials/NotepadCodeLab/Notepadv3/Android.mk
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
#
|
||||||
|
# Copyright (C) 2009 The Android Open Source Project
|
||||||
|
#
|
||||||
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
# you may not use this file except in compliance with the License.
|
||||||
|
# You may obtain a copy of the License at
|
||||||
|
#
|
||||||
|
# http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
#
|
||||||
|
# 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.
|
||||||
|
# See the License for the specific language governing permissions and
|
||||||
|
# limitations under the License.
|
||||||
|
#
|
||||||
|
|
||||||
|
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.
|
||||||
|
LOCAL_SRC_FILES := $(call all-java-files-under, src)
|
||||||
|
|
||||||
|
LOCAL_PACKAGE_NAME := Notepadv3
|
||||||
|
|
||||||
|
# Make the app build against the current SDK
|
||||||
|
LOCAL_SDK_VERSION := current
|
||||||
|
|
||||||
|
include $(BUILD_PACKAGE)
|
||||||
@@ -7,6 +7,6 @@
|
|||||||
<category android:name="android.intent.category.LAUNCHER" />
|
<category android:name="android.intent.category.LAUNCHER" />
|
||||||
</intent-filter>
|
</intent-filter>
|
||||||
</activity>
|
</activity>
|
||||||
<activity android:name=".NoteEdit"/>
|
<activity android:name=".NoteEdit" />
|
||||||
</application>
|
</application>
|
||||||
</manifest>
|
</manifest>
|
||||||
@@ -25,7 +25,7 @@ import android.widget.EditText;
|
|||||||
|
|
||||||
public class NoteEdit extends Activity {
|
public class NoteEdit extends Activity {
|
||||||
|
|
||||||
private EditText mTitleText;
|
private EditText mTitleText;
|
||||||
private EditText mBodyText;
|
private EditText mBodyText;
|
||||||
private Long mRowId;
|
private Long mRowId;
|
||||||
|
|
||||||
@@ -33,19 +33,19 @@ public class NoteEdit extends Activity {
|
|||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
setContentView(R.layout.note_edit);
|
setContentView(R.layout.note_edit);
|
||||||
|
|
||||||
mTitleText = (EditText) findViewById(R.id.title);
|
mTitleText = (EditText) findViewById(R.id.title);
|
||||||
mBodyText = (EditText) findViewById(R.id.body);
|
mBodyText = (EditText) findViewById(R.id.body);
|
||||||
|
|
||||||
Button confirmButton = (Button) findViewById(R.id.confirm);
|
Button confirmButton = (Button) findViewById(R.id.confirm);
|
||||||
|
|
||||||
mRowId = null;
|
mRowId = null;
|
||||||
Bundle extras = getIntent().getExtras();
|
Bundle extras = getIntent().getExtras();
|
||||||
if (extras != null) {
|
if (extras != null) {
|
||||||
String title = extras.getString(NotesDbAdapter.KEY_TITLE);
|
String title = extras.getString(NotesDbAdapter.KEY_TITLE);
|
||||||
String body = extras.getString(NotesDbAdapter.KEY_BODY);
|
String body = extras.getString(NotesDbAdapter.KEY_BODY);
|
||||||
mRowId = extras.getLong(NotesDbAdapter.KEY_ROWID);
|
mRowId = extras.getLong(NotesDbAdapter.KEY_ROWID);
|
||||||
|
|
||||||
if (title != null) {
|
if (title != null) {
|
||||||
mTitleText.setText(title);
|
mTitleText.setText(title);
|
||||||
}
|
}
|
||||||
@@ -53,24 +53,24 @@ public class NoteEdit extends Activity {
|
|||||||
mBodyText.setText(body);
|
mBodyText.setText(body);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
confirmButton.setOnClickListener(new View.OnClickListener() {
|
confirmButton.setOnClickListener(new View.OnClickListener() {
|
||||||
|
|
||||||
public void onClick(View view) {
|
public void onClick(View view) {
|
||||||
Bundle bundle = new Bundle();
|
Bundle bundle = new Bundle();
|
||||||
|
|
||||||
bundle.putString(NotesDbAdapter.KEY_TITLE, mTitleText.getText().toString());
|
bundle.putString(NotesDbAdapter.KEY_TITLE, mTitleText.getText().toString());
|
||||||
bundle.putString(NotesDbAdapter.KEY_BODY, mBodyText.getText().toString());
|
bundle.putString(NotesDbAdapter.KEY_BODY, mBodyText.getText().toString());
|
||||||
if (mRowId != null) {
|
if (mRowId != null) {
|
||||||
bundle.putLong(NotesDbAdapter.KEY_ROWID, mRowId);
|
bundle.putLong(NotesDbAdapter.KEY_ROWID, mRowId);
|
||||||
}
|
}
|
||||||
|
|
||||||
Intent mIntent = new Intent();
|
Intent mIntent = new Intent();
|
||||||
mIntent.putExtras(bundle);
|
mIntent.putExtras(bundle);
|
||||||
setResult(RESULT_OK, mIntent);
|
setResult(RESULT_OK, mIntent);
|
||||||
finish();
|
finish();
|
||||||
}
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (C) 2008 Google Inc.
|
* Copyright (C) 2008 Google Inc.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License")savedInstanceState;
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
* You may obtain a copy of the License at
|
* You may obtain a copy of the License at
|
||||||
*
|
*
|
||||||
@@ -32,13 +32,13 @@ import android.widget.AdapterView.AdapterContextMenuInfo;
|
|||||||
public class Notepadv3 extends ListActivity {
|
public class Notepadv3 extends ListActivity {
|
||||||
private static final int ACTIVITY_CREATE=0;
|
private static final int ACTIVITY_CREATE=0;
|
||||||
private static final int ACTIVITY_EDIT=1;
|
private static final int ACTIVITY_EDIT=1;
|
||||||
|
|
||||||
private static final int INSERT_ID = Menu.FIRST;
|
private static final int INSERT_ID = Menu.FIRST;
|
||||||
private static final int DELETE_ID = Menu.FIRST + 1;
|
private static final int DELETE_ID = Menu.FIRST + 1;
|
||||||
|
|
||||||
private NotesDbAdapter mDbHelper;
|
private NotesDbAdapter mDbHelper;
|
||||||
private Cursor mNotesCursor;
|
private Cursor mNotesCursor;
|
||||||
|
|
||||||
/** Called when the activity is first created. */
|
/** Called when the activity is first created. */
|
||||||
@Override
|
@Override
|
||||||
public void onCreate(Bundle savedInstanceState) {
|
public void onCreate(Bundle savedInstanceState) {
|
||||||
@@ -49,24 +49,24 @@ public class Notepadv3 extends ListActivity {
|
|||||||
fillData();
|
fillData();
|
||||||
registerForContextMenu(getListView());
|
registerForContextMenu(getListView());
|
||||||
}
|
}
|
||||||
|
|
||||||
private void fillData() {
|
private void fillData() {
|
||||||
// Get all of the rows from the database and create the item list
|
// Get all of the rows from the database and create the item list
|
||||||
mNotesCursor = mDbHelper.fetchAllNotes();
|
mNotesCursor = mDbHelper.fetchAllNotes();
|
||||||
startManagingCursor(mNotesCursor);
|
startManagingCursor(mNotesCursor);
|
||||||
|
|
||||||
// Create an array to specify the fields we want to display in the list (only TITLE)
|
// Create an array to specify the fields we want to display in the list (only TITLE)
|
||||||
String[] from = new String[]{NotesDbAdapter.KEY_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)
|
// 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};
|
int[] to = new int[]{R.id.text1};
|
||||||
|
|
||||||
// Now create a simple cursor adapter and set it to display
|
// Now create a simple cursor adapter and set it to display
|
||||||
SimpleCursorAdapter notes =
|
SimpleCursorAdapter notes =
|
||||||
new SimpleCursorAdapter(this, R.layout.notes_row, mNotesCursor, from, to);
|
new SimpleCursorAdapter(this, R.layout.notes_row, mNotesCursor, from, to);
|
||||||
setListAdapter(notes);
|
setListAdapter(notes);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onCreateOptionsMenu(Menu menu) {
|
public boolean onCreateOptionsMenu(Menu menu) {
|
||||||
super.onCreateOptionsMenu(menu);
|
super.onCreateOptionsMenu(menu);
|
||||||
@@ -77,38 +77,38 @@ public class Notepadv3 extends ListActivity {
|
|||||||
@Override
|
@Override
|
||||||
public boolean onMenuItemSelected(int featureId, MenuItem item) {
|
public boolean onMenuItemSelected(int featureId, MenuItem item) {
|
||||||
switch(item.getItemId()) {
|
switch(item.getItemId()) {
|
||||||
case INSERT_ID:
|
case INSERT_ID:
|
||||||
createNote();
|
createNote();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
return super.onMenuItemSelected(featureId, item);
|
return super.onMenuItemSelected(featureId, item);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
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
|
@Override
|
||||||
public boolean onContextItemSelected(MenuItem item) {
|
public void onCreateContextMenu(ContextMenu menu, View v,
|
||||||
switch(item.getItemId()) {
|
ContextMenuInfo menuInfo) {
|
||||||
case DELETE_ID:
|
super.onCreateContextMenu(menu, v, menuInfo);
|
||||||
AdapterContextMenuInfo info = (AdapterContextMenuInfo) item.getMenuInfo();
|
menu.add(0, DELETE_ID, 0, R.string.menu_delete);
|
||||||
mDbHelper.deleteNote(info.id);
|
}
|
||||||
fillData();
|
|
||||||
return true;
|
@Override
|
||||||
}
|
public boolean onContextItemSelected(MenuItem item) {
|
||||||
return super.onContextItemSelected(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() {
|
private void createNote() {
|
||||||
Intent i = new Intent(this, NoteEdit.class);
|
Intent i = new Intent(this, NoteEdit.class);
|
||||||
startActivityForResult(i, ACTIVITY_CREATE);
|
startActivityForResult(i, ACTIVITY_CREATE);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onListItemClick(ListView l, View v, int position, long id) {
|
protected void onListItemClick(ListView l, View v, int position, long id) {
|
||||||
super.onListItemClick(l, v, position, id);
|
super.onListItemClick(l, v, position, id);
|
||||||
@@ -117,9 +117,9 @@ public class Notepadv3 extends ListActivity {
|
|||||||
Intent i = new Intent(this, NoteEdit.class);
|
Intent i = new Intent(this, NoteEdit.class);
|
||||||
i.putExtra(NotesDbAdapter.KEY_ROWID, id);
|
i.putExtra(NotesDbAdapter.KEY_ROWID, id);
|
||||||
i.putExtra(NotesDbAdapter.KEY_TITLE, c.getString(
|
i.putExtra(NotesDbAdapter.KEY_TITLE, c.getString(
|
||||||
c.getColumnIndexOrThrow(NotesDbAdapter.KEY_TITLE)));
|
c.getColumnIndexOrThrow(NotesDbAdapter.KEY_TITLE)));
|
||||||
i.putExtra(NotesDbAdapter.KEY_BODY, c.getString(
|
i.putExtra(NotesDbAdapter.KEY_BODY, c.getString(
|
||||||
c.getColumnIndexOrThrow(NotesDbAdapter.KEY_BODY)));
|
c.getColumnIndexOrThrow(NotesDbAdapter.KEY_BODY)));
|
||||||
startActivityForResult(i, ACTIVITY_EDIT);
|
startActivityForResult(i, ACTIVITY_EDIT);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -128,21 +128,21 @@ public class Notepadv3 extends ListActivity {
|
|||||||
super.onActivityResult(requestCode, resultCode, intent);
|
super.onActivityResult(requestCode, resultCode, intent);
|
||||||
Bundle extras = intent.getExtras();
|
Bundle extras = intent.getExtras();
|
||||||
switch(requestCode) {
|
switch(requestCode) {
|
||||||
case ACTIVITY_CREATE:
|
case ACTIVITY_CREATE:
|
||||||
String title = extras.getString(NotesDbAdapter.KEY_TITLE);
|
String title = extras.getString(NotesDbAdapter.KEY_TITLE);
|
||||||
String body = extras.getString(NotesDbAdapter.KEY_BODY);
|
String body = extras.getString(NotesDbAdapter.KEY_BODY);
|
||||||
mDbHelper.createNote(title, body);
|
mDbHelper.createNote(title, body);
|
||||||
fillData();
|
fillData();
|
||||||
break;
|
break;
|
||||||
case ACTIVITY_EDIT:
|
case ACTIVITY_EDIT:
|
||||||
Long rowId = extras.getLong(NotesDbAdapter.KEY_ROWID);
|
Long rowId = extras.getLong(NotesDbAdapter.KEY_ROWID);
|
||||||
if (rowId != null) {
|
if (rowId != null) {
|
||||||
String editTitle = extras.getString(NotesDbAdapter.KEY_TITLE);
|
String editTitle = extras.getString(NotesDbAdapter.KEY_TITLE);
|
||||||
String editBody = extras.getString(NotesDbAdapter.KEY_BODY);
|
String editBody = extras.getString(NotesDbAdapter.KEY_BODY);
|
||||||
mDbHelper.updateNote(rowId, editTitle, editBody);
|
mDbHelper.updateNote(rowId, editTitle, editBody);
|
||||||
}
|
}
|
||||||
fillData();
|
fillData();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -43,13 +43,13 @@ public class NotesDbAdapter {
|
|||||||
private static final String TAG = "NotesDbAdapter";
|
private static final String TAG = "NotesDbAdapter";
|
||||||
private DatabaseHelper mDbHelper;
|
private DatabaseHelper mDbHelper;
|
||||||
private SQLiteDatabase mDb;
|
private SQLiteDatabase mDb;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Database creation sql statement
|
* Database creation sql statement
|
||||||
*/
|
*/
|
||||||
private static final String DATABASE_CREATE =
|
private static final String DATABASE_CREATE =
|
||||||
"create table notes (_id integer primary key autoincrement, "
|
"create table notes (_id integer primary key autoincrement, "
|
||||||
+ "title text not null, body text not null);";
|
+ "title text not null, body text not null);";
|
||||||
|
|
||||||
private static final String DATABASE_NAME = "data";
|
private static final String DATABASE_NAME = "data";
|
||||||
private static final String DATABASE_TABLE = "notes";
|
private static final String DATABASE_TABLE = "notes";
|
||||||
@@ -102,7 +102,7 @@ public class NotesDbAdapter {
|
|||||||
mDb = mDbHelper.getWritableDatabase();
|
mDb = mDbHelper.getWritableDatabase();
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void close() {
|
public void close() {
|
||||||
mDbHelper.close();
|
mDbHelper.close();
|
||||||
}
|
}
|
||||||
@@ -158,9 +158,9 @@ public class NotesDbAdapter {
|
|||||||
|
|
||||||
Cursor mCursor =
|
Cursor mCursor =
|
||||||
|
|
||||||
mDb.query(true, DATABASE_TABLE, new String[] {KEY_ROWID,
|
mDb.query(true, DATABASE_TABLE, new String[] {KEY_ROWID,
|
||||||
KEY_TITLE, KEY_BODY}, KEY_ROWID + "=" + rowId, null,
|
KEY_TITLE, KEY_BODY}, KEY_ROWID + "=" + rowId, null,
|
||||||
null, null, null, null);
|
null, null, null, null);
|
||||||
if (mCursor != null) {
|
if (mCursor != null) {
|
||||||
mCursor.moveToFirst();
|
mCursor.moveToFirst();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,6 +17,7 @@
|
|||||||
LOCAL_PATH:= $(call my-dir)
|
LOCAL_PATH:= $(call my-dir)
|
||||||
include $(CLEAR_VARS)
|
include $(CLEAR_VARS)
|
||||||
|
|
||||||
|
# Only build apk if this package is added to CUSTOM_MODLUES in buildspec.mk
|
||||||
LOCAL_MODULE_TAGS := optional
|
LOCAL_MODULE_TAGS := optional
|
||||||
|
|
||||||
# Only compile source java files in this apk.
|
# Only compile source java files in this apk.
|
||||||
|
|||||||
@@ -7,6 +7,6 @@
|
|||||||
<category android:name="android.intent.category.LAUNCHER" />
|
<category android:name="android.intent.category.LAUNCHER" />
|
||||||
</intent-filter>
|
</intent-filter>
|
||||||
</activity>
|
</activity>
|
||||||
<activity android:name=".NoteEdit"/>
|
<activity android:name=".NoteEdit" />
|
||||||
</application>
|
</application>
|
||||||
</manifest>
|
</manifest>
|
||||||
@@ -25,7 +25,7 @@ import android.widget.EditText;
|
|||||||
|
|
||||||
public class NoteEdit extends Activity {
|
public class NoteEdit extends Activity {
|
||||||
|
|
||||||
private EditText mTitleText;
|
private EditText mTitleText;
|
||||||
private EditText mBodyText;
|
private EditText mBodyText;
|
||||||
private Long mRowId;
|
private Long mRowId;
|
||||||
private NotesDbAdapter mDbHelper;
|
private NotesDbAdapter mDbHelper;
|
||||||
@@ -36,63 +36,62 @@ public class NoteEdit extends Activity {
|
|||||||
mDbHelper = new NotesDbAdapter(this);
|
mDbHelper = new NotesDbAdapter(this);
|
||||||
mDbHelper.open();
|
mDbHelper.open();
|
||||||
setContentView(R.layout.note_edit);
|
setContentView(R.layout.note_edit);
|
||||||
|
|
||||||
|
|
||||||
mTitleText = (EditText) findViewById(R.id.title);
|
mTitleText = (EditText) findViewById(R.id.title);
|
||||||
mBodyText = (EditText) findViewById(R.id.body);
|
mBodyText = (EditText) findViewById(R.id.body);
|
||||||
|
|
||||||
Button confirmButton = (Button) findViewById(R.id.confirm);
|
Button confirmButton = (Button) findViewById(R.id.confirm);
|
||||||
|
|
||||||
mRowId = (savedInstanceState == null) ? null :
|
mRowId = (savedInstanceState == null) ? null :
|
||||||
(Long) savedInstanceState.getSerializable(NotesDbAdapter.KEY_ROWID);
|
(Long) savedInstanceState.getSerializable(NotesDbAdapter.KEY_ROWID);
|
||||||
if (mRowId == null) {
|
if (mRowId == null) {
|
||||||
Bundle extras = getIntent().getExtras();
|
Bundle extras = getIntent().getExtras();
|
||||||
mRowId = extras != null ? extras.getLong(NotesDbAdapter.KEY_ROWID)
|
mRowId = extras != null ? extras.getLong(NotesDbAdapter.KEY_ROWID)
|
||||||
: null;
|
: null;
|
||||||
}
|
}
|
||||||
|
|
||||||
populateFields();
|
populateFields();
|
||||||
|
|
||||||
confirmButton.setOnClickListener(new View.OnClickListener() {
|
confirmButton.setOnClickListener(new View.OnClickListener() {
|
||||||
|
|
||||||
public void onClick(View view) {
|
public void onClick(View view) {
|
||||||
setResult(RESULT_OK);
|
setResult(RESULT_OK);
|
||||||
finish();
|
finish();
|
||||||
}
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private void populateFields() {
|
private void populateFields() {
|
||||||
if (mRowId != null) {
|
if (mRowId != null) {
|
||||||
Cursor note = mDbHelper.fetchNote(mRowId);
|
Cursor note = mDbHelper.fetchNote(mRowId);
|
||||||
startManagingCursor(note);
|
startManagingCursor(note);
|
||||||
mTitleText.setText(note.getString(
|
mTitleText.setText(note.getString(
|
||||||
note.getColumnIndexOrThrow(NotesDbAdapter.KEY_TITLE)));
|
note.getColumnIndexOrThrow(NotesDbAdapter.KEY_TITLE)));
|
||||||
mBodyText.setText(note.getString(
|
mBodyText.setText(note.getString(
|
||||||
note.getColumnIndexOrThrow(NotesDbAdapter.KEY_BODY)));
|
note.getColumnIndexOrThrow(NotesDbAdapter.KEY_BODY)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onSaveInstanceState(Bundle outState) {
|
protected void onSaveInstanceState(Bundle outState) {
|
||||||
super.onSaveInstanceState(outState);
|
super.onSaveInstanceState(outState);
|
||||||
saveState();
|
saveState();
|
||||||
outState.putSerializable(NotesDbAdapter.KEY_ROWID, mRowId);
|
outState.putSerializable(NotesDbAdapter.KEY_ROWID, mRowId);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onPause() {
|
protected void onPause() {
|
||||||
super.onPause();
|
super.onPause();
|
||||||
saveState();
|
saveState();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onResume() {
|
protected void onResume() {
|
||||||
super.onResume();
|
super.onResume();
|
||||||
populateFields();
|
populateFields();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void saveState() {
|
private void saveState() {
|
||||||
String title = mTitleText.getText().toString();
|
String title = mTitleText.getText().toString();
|
||||||
String body = mBodyText.getText().toString();
|
String body = mBodyText.getText().toString();
|
||||||
@@ -106,5 +105,5 @@ public class NoteEdit extends Activity {
|
|||||||
mDbHelper.updateNote(mRowId, title, body);
|
mDbHelper.updateNote(mRowId, title, body);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (C) 2008 Google Inc.
|
* Copyright (C) 2008 Google Inc.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License")savedInstanceState;
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
* You may obtain a copy of the License at
|
* You may obtain a copy of the License at
|
||||||
*
|
*
|
||||||
@@ -32,12 +32,12 @@ import android.widget.AdapterView.AdapterContextMenuInfo;
|
|||||||
public class Notepadv3 extends ListActivity {
|
public class Notepadv3 extends ListActivity {
|
||||||
private static final int ACTIVITY_CREATE=0;
|
private static final int ACTIVITY_CREATE=0;
|
||||||
private static final int ACTIVITY_EDIT=1;
|
private static final int ACTIVITY_EDIT=1;
|
||||||
|
|
||||||
private static final int INSERT_ID = Menu.FIRST;
|
private static final int INSERT_ID = Menu.FIRST;
|
||||||
private static final int DELETE_ID = Menu.FIRST + 1;
|
private static final int DELETE_ID = Menu.FIRST + 1;
|
||||||
|
|
||||||
private NotesDbAdapter mDbHelper;
|
private NotesDbAdapter mDbHelper;
|
||||||
|
|
||||||
/** Called when the activity is first created. */
|
/** Called when the activity is first created. */
|
||||||
@Override
|
@Override
|
||||||
public void onCreate(Bundle savedInstanceState) {
|
public void onCreate(Bundle savedInstanceState) {
|
||||||
@@ -48,23 +48,23 @@ public class Notepadv3 extends ListActivity {
|
|||||||
fillData();
|
fillData();
|
||||||
registerForContextMenu(getListView());
|
registerForContextMenu(getListView());
|
||||||
}
|
}
|
||||||
|
|
||||||
private void fillData() {
|
private void fillData() {
|
||||||
Cursor notesCursor = mDbHelper.fetchAllNotes();
|
Cursor notesCursor = mDbHelper.fetchAllNotes();
|
||||||
startManagingCursor(notesCursor);
|
startManagingCursor(notesCursor);
|
||||||
|
|
||||||
// Create an array to specify the fields we want to display in the list (only TITLE)
|
// Create an array to specify the fields we want to display in the list (only TITLE)
|
||||||
String[] from = new String[]{NotesDbAdapter.KEY_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)
|
// 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};
|
int[] to = new int[]{R.id.text1};
|
||||||
|
|
||||||
// Now create a simple cursor adapter and set it to display
|
// Now create a simple cursor adapter and set it to display
|
||||||
SimpleCursorAdapter notes =
|
SimpleCursorAdapter notes =
|
||||||
new SimpleCursorAdapter(this, R.layout.notes_row, notesCursor, from, to);
|
new SimpleCursorAdapter(this, R.layout.notes_row, notesCursor, from, to);
|
||||||
setListAdapter(notes);
|
setListAdapter(notes);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onCreateOptionsMenu(Menu menu) {
|
public boolean onCreateOptionsMenu(Menu menu) {
|
||||||
super.onCreateOptionsMenu(menu);
|
super.onCreateOptionsMenu(menu);
|
||||||
@@ -75,38 +75,38 @@ public class Notepadv3 extends ListActivity {
|
|||||||
@Override
|
@Override
|
||||||
public boolean onMenuItemSelected(int featureId, MenuItem item) {
|
public boolean onMenuItemSelected(int featureId, MenuItem item) {
|
||||||
switch(item.getItemId()) {
|
switch(item.getItemId()) {
|
||||||
case INSERT_ID:
|
case INSERT_ID:
|
||||||
createNote();
|
createNote();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
return super.onMenuItemSelected(featureId, item);
|
return super.onMenuItemSelected(featureId, item);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
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
|
@Override
|
||||||
public boolean onContextItemSelected(MenuItem item) {
|
public void onCreateContextMenu(ContextMenu menu, View v,
|
||||||
switch(item.getItemId()) {
|
ContextMenuInfo menuInfo) {
|
||||||
case DELETE_ID:
|
super.onCreateContextMenu(menu, v, menuInfo);
|
||||||
AdapterContextMenuInfo info = (AdapterContextMenuInfo) item.getMenuInfo();
|
menu.add(0, DELETE_ID, 0, R.string.menu_delete);
|
||||||
mDbHelper.deleteNote(info.id);
|
}
|
||||||
fillData();
|
|
||||||
return true;
|
@Override
|
||||||
}
|
public boolean onContextItemSelected(MenuItem item) {
|
||||||
return super.onContextItemSelected(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() {
|
private void createNote() {
|
||||||
Intent i = new Intent(this, NoteEdit.class);
|
Intent i = new Intent(this, NoteEdit.class);
|
||||||
startActivityForResult(i, ACTIVITY_CREATE);
|
startActivityForResult(i, ACTIVITY_CREATE);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onListItemClick(ListView l, View v, int position, long id) {
|
protected void onListItemClick(ListView l, View v, int position, long id) {
|
||||||
super.onListItemClick(l, v, position, id);
|
super.onListItemClick(l, v, position, id);
|
||||||
@@ -116,8 +116,7 @@ public class Notepadv3 extends ListActivity {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onActivityResult(int requestCode, int resultCode,
|
protected void onActivityResult(int requestCode, int resultCode, Intent intent) {
|
||||||
Intent intent) {
|
|
||||||
super.onActivityResult(requestCode, resultCode, intent);
|
super.onActivityResult(requestCode, resultCode, intent);
|
||||||
fillData();
|
fillData();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -43,13 +43,13 @@ public class NotesDbAdapter {
|
|||||||
private static final String TAG = "NotesDbAdapter";
|
private static final String TAG = "NotesDbAdapter";
|
||||||
private DatabaseHelper mDbHelper;
|
private DatabaseHelper mDbHelper;
|
||||||
private SQLiteDatabase mDb;
|
private SQLiteDatabase mDb;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Database creation sql statement
|
* Database creation sql statement
|
||||||
*/
|
*/
|
||||||
private static final String DATABASE_CREATE =
|
private static final String DATABASE_CREATE =
|
||||||
"create table notes (_id integer primary key autoincrement, "
|
"create table notes (_id integer primary key autoincrement, "
|
||||||
+ "title text not null, body text not null);";
|
+ "title text not null, body text not null);";
|
||||||
|
|
||||||
private static final String DATABASE_NAME = "data";
|
private static final String DATABASE_NAME = "data";
|
||||||
private static final String DATABASE_TABLE = "notes";
|
private static final String DATABASE_TABLE = "notes";
|
||||||
@@ -102,7 +102,7 @@ public class NotesDbAdapter {
|
|||||||
mDb = mDbHelper.getWritableDatabase();
|
mDb = mDbHelper.getWritableDatabase();
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void close() {
|
public void close() {
|
||||||
mDbHelper.close();
|
mDbHelper.close();
|
||||||
}
|
}
|
||||||
@@ -158,9 +158,9 @@ public class NotesDbAdapter {
|
|||||||
|
|
||||||
Cursor mCursor =
|
Cursor mCursor =
|
||||||
|
|
||||||
mDb.query(true, DATABASE_TABLE, new String[] {KEY_ROWID,
|
mDb.query(true, DATABASE_TABLE, new String[] {KEY_ROWID,
|
||||||
KEY_TITLE, KEY_BODY}, KEY_ROWID + "=" + rowId, null,
|
KEY_TITLE, KEY_BODY}, KEY_ROWID + "=" + rowId, null,
|
||||||
null, null, null, null);
|
null, null, null, null);
|
||||||
if (mCursor != null) {
|
if (mCursor != null) {
|
||||||
mCursor.moveToFirst();
|
mCursor.moveToFirst();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user