Creating menu and string resources

Our app's menus and localizable text are described in XML files. Identifiers in these resource files are referenced by Java code, as we will see later.

First, let's edit res/menu/activity_camera.xml so that it has the following implementation, describing the menu items for CameraActivity:

<menu xmlns:android="http://schemas.android.com/apk/res/android" >
  <item
    android:id="@+id/menu_next_camera"
    android:orderInCategory="100"
    android:showAsAction="ifRoom|withText"
    android:title="@string/menu_next_camera"/>
  <item
    android:id="@+id/menu_take_photo"
    android:orderInCategory="100"
    android:showAsAction="always|withText"
    android:title="@string/menu_take_photo"/>
</menu>

Note that we use the android:showAsAction attribute to make menu items appear in the app's top bar, as seen in the earlier screenshots.

Similarly, the menu items for LabActivity are described in res/menu/activity_lab.xml, as follows:

<menu xmlns:android="http://schemas.android.com/apk/res/android" >
  <item
    android:id="@+id/menu_delete"
    android:orderInCategory="100"
    android:showAsAction="ifRoom|withText"
    android:title="@string/delete" />
  <item
    android:id="@+id/menu_edit"
    android:orderInCategory="100"
    android:showAsAction="ifRoom|withText"
    android:title="@string/edit" />
  <item
    android:id="@+id/menu_share"
    android:orderInCategory="100"
    android:showAsAction="ifRoom|withText"
    android:title="@string/share" />
</menu>

Strings of user-readable text, used in various places in the app, are described in res/values/strings.xml as follows:

<?xml version="1.0" encoding="utf-8"?>
<resources>
  <string name="app_name">Second Sight</string>
  <string name="delete">Delete</string>
  <string name="edit">Edit</string>
  <string name="menu_next_camera">Next Cam</string>
  <string name="menu_take_photo">Take Photo</string>
  <string name="photo_delete_prompt_message">This photo is saved
    in your Gallery. Do you want to delete it?</string>
  <string name="photo_delete_prompt_title">Delete photo?</string>
  <string name="photo_error_message">Failed to save photo</string>
  <string name="photo_edit_chooser_title">Edit photo
    with…</string>
  <string name="photo_send_chooser_title">Share photo
    with…</string>
  <string name="photo_send_extra_subject">My photo from Second
    Sight</string>
  <string name="photo_send_extra_text">Check out my photo from the
    Second Sight app! http://nummist.com/opencv/</string>
  <string name="share">Share</string>
</resources>

Having defined these boilerplate resources, we can proceed to implementing our app's functionality in Java.