Skip to content

Commit 05523fb

Browse files
committed
Do not merge.
Revise NotePad application to use better practices such as - inflating menus from XML and supporting API Level 3 without the need for version qualifiers on resource directories. - to NOT include items in the options menu based on the 'selected' item (that's what a context menu is for). - include all drawables in the app, instead of using system resources. Add features: - the ability to edit the note title through the context menu - disable menu items in the editor based on menu groups - add a "save" button to the editor instead of assuming BACK functionality - and show the title of the current note in the activity title. - and probably others Change-Id: Ib7ea41079f3b268f3be1f86febdb1caed98bdd8e
1 parent 42d3a4a commit 05523fb

34 files changed

+274
-307
lines changed

samples/NotePad/AndroidManifest.xml

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,15 @@
2020
own application, the package name must be changed from "com.example.*"
2121
to come from a domain that you own or have control over. -->
2222
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
23-
package="com.example.android.notepad"
24-
>
23+
package="com.example.android.notepad" >
24+
2525
<application android:icon="@drawable/app_notes"
26-
android:label="@string/app_name"
27-
>
26+
android:label="@string/app_name" >
2827
<provider android:name="NotePadProvider"
29-
android:authorities="com.google.provider.NotePad"
30-
/>
28+
android:authorities="com.example.notepad.provider.NotePad" />
3129

32-
<activity android:name="NotesList" android:label="@string/title_notes_list">
30+
<activity android:name="NotesList"
31+
android:label="@string/title_notes_list">
3332
<intent-filter>
3433
<action android:name="android.intent.action.MAIN" />
3534
<category android:name="android.intent.category.LAUNCHER" />
@@ -50,16 +49,13 @@
5049

5150
<activity android:name="NoteEditor"
5251
android:theme="@android:style/Theme.Light"
53-
android:label="@string/title_note"
54-
android:screenOrientation="sensor"
55-
android:configChanges="keyboardHidden|orientation"
56-
>
52+
android:configChanges="keyboardHidden|orientation">
5753
<!-- This filter says that we can view or edit the data of
5854
a single note -->
5955
<intent-filter android:label="@string/resolve_edit">
6056
<action android:name="android.intent.action.VIEW" />
6157
<action android:name="android.intent.action.EDIT" />
62-
<action android:name="com.android.notepad.action.EDIT_NOTE" />
58+
<action android:name="com.android.notes.action.EDIT_NOTE" />
6359
<category android:name="android.intent.category.DEFAULT" />
6460
<data android:mimeType="vnd.android.cursor.item/vnd.google.note" />
6561
</intent-filter>
@@ -77,6 +73,7 @@
7773
<activity android:name="TitleEditor"
7874
android:label="@string/title_edit_title"
7975
android:theme="@android:style/Theme.Dialog"
76+
android:icon="@drawable/ic_menu_edit"
8077
android:windowSoftInputMode="stateVisible">
8178
<!-- This activity implements an alternative action that can be
8279
performed on notes: editing their title. It can be used as
@@ -110,6 +107,6 @@
110107

111108
</application>
112109

113-
<uses-sdk android:targetSdkVersion="4" android:minSdkVersion="3"/>
110+
<uses-sdk android:minSdkVersion="3" android:targetSdkVersion="4"/>
114111
</manifest>
115112

Binary file not shown.

samples/NotePad/res/drawable-hdpi/app_notes.png

100755100644
-940 Bytes
Loading
Loading
Loading
Loading
Loading
Loading
Loading
-2.81 KB
Binary file not shown.
Binary file not shown.
1.97 KB
Loading
1.71 KB
Loading
5.18 KB
Loading
1.62 KB
Loading
1.69 KB
Loading
1.61 KB
Loading

samples/NotePad/res/layout/note_editor.xml

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,15 @@
1313
See the License for the specific language governing permissions and
1414
limitations under the License.
1515
-->
16-
1716
<view xmlns:android="http://schemas.android.com/apk/res/android"
1817
class="com.example.android.notepad.NoteEditor$LinedEditText"
1918
android:id="@+id/note"
20-
android:layout_width="match_parent"
21-
android:layout_height="match_parent"
19+
android:layout_width="fill_parent"
20+
android:layout_height="fill_parent"
2221
android:background="@android:color/transparent"
23-
android:padding="5dip"
22+
android:padding="5dp"
2423
android:scrollbars="vertical"
2524
android:fadingEdge="vertical"
2625
android:gravity="top"
2726
android:textSize="22sp"
28-
android:capitalize="sentences"
29-
/>
27+
android:capitalize="sentences" />

samples/NotePad/res/layout/noteslist_item.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
1818
android:id="@android:id/text1"
19-
android:layout_width="match_parent"
19+
android:layout_width="fill_parent"
2020
android:layout_height="?android:attr/listPreferredItemHeight"
2121
android:textAppearance="?android:attr/textAppearanceLarge"
2222
android:gravity="center_vertical"
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<menu xmlns:android="http://schemas.android.com/apk/res/android">
3+
<item android:id="@+id/menu_save"
4+
android:icon="@drawable/ic_menu_save"
5+
android:alphabeticShortcut='s'
6+
android:title="@string/menu_save" />
7+
<group android:id="@+id/menu_group_edit">
8+
<item android:id="@+id/menu_revert"
9+
android:icon="@drawable/ic_menu_revert"
10+
android:title="@string/menu_revert" />
11+
<item android:id="@+id/menu_delete"
12+
android:icon="@drawable/ic_menu_delete"
13+
android:title="@string/menu_delete" />
14+
</group>
15+
<group android:id="@+id/menu_group_insert">
16+
<item android:id="@+id/menu_discard"
17+
android:icon="@drawable/ic_menu_discard"
18+
android:title="@string/menu_discard" />
19+
</group>
20+
</menu>
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<menu xmlns:android="http://schemas.android.com/apk/res/android">
3+
<item android:id="@+id/context_open"
4+
android:title="@string/menu_open" />
5+
<item android:id="@+id/context_delete"
6+
android:title="@string/menu_delete" />
7+
</menu>
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<menu xmlns:android="http://schemas.android.com/apk/res/android">
3+
<!-- This is our one standard application action (creating a new note). -->
4+
<item android:id="@+id/menu_add"
5+
android:icon="@drawable/ic_menu_compose"
6+
android:alphabeticShortcut='a'
7+
android:title="@string/menu_add" />
8+
</menu>

samples/NotePad/res/values/strings.xml

Lines changed: 22 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -15,25 +15,28 @@
1515
-->
1616

1717
<resources>
18+
<string name="app_name">NotePad</string>
19+
<string name="live_folder_name">Notes</string>
20+
21+
<string name="title_edit_title">Note title:</string>
22+
<string name="title_create">Create note</string>
23+
<string name="title_edit">Edit: \"%1$s\"</string>
24+
<string name="title_notes_list">Notes</string>
25+
26+
<string name="menu_add">Add note</string>
27+
<string name="menu_save">Save</string>
1828
<string name="menu_delete">Delete</string>
19-
<string name="menu_insert">Add note</string>
20-
<string name="menu_revert">Revert</string>
29+
<string name="menu_open">Open</string>
30+
<string name="menu_revert">Revert changes</string>
2131
<string name="menu_discard">Discard</string>
22-
32+
33+
<string name="button_ok">OK</string>
34+
<string name="text_title">Title:</string>
35+
2336
<string name="resolve_edit">Edit note</string>
24-
<string name="resolve_title">Edit title</string>
25-
26-
<string name="title_create">Create note</string>
27-
<string name="title_edit">Edit note</string>
28-
<string name="title_notes_list">Note pad</string>
29-
<string name="title_note">Note</string>
30-
<string name="title_edit_title">Note title:</string>
31-
32-
<string name="app_name">Note Pad</string>
33-
<string name="live_folder_name">Notes</string>
34-
35-
<string name="button_ok">OK</string>
36-
37-
<string name="error_title">Error</string>
38-
<string name="error_message">Error loading note</string>
39-
</resources>
37+
<string name="resolve_title">Edit title</string>
38+
39+
<string name="error_title">Error</string>
40+
<string name="error_message">Error loading note</string>
41+
<string name="nothing_to_save">There is nothing to save</string>
42+
</resources>

0 commit comments

Comments
 (0)