Home | History | Annotate | Download | only in watch-faces
      1 page.title=Providing Configuration Activities
      2 
      3 @jd:body
      4 
      5 <div id="tb-wrapper">
      6 <div id="tb">
      7 <h2>This lesson teaches you to</h2>
      8 <ol>
      9   <li><a href="#Intent">Specify an Intent for Configuration Activities</a></li>
     10   <li><a href="#WearableActivity">Create a Wearable Configuration Activity</a></li>
     11   <li><a href="#CompanionActivity">Create a Companion Configuration Activity</a></li>
     12 </ol>
     13 <h2>You should also read</h2>
     14 <ul>
     15   <li><a href="{@docRoot}design/wear/watchfaces.html">Watch Faces for Android Wear</a></li>
     16 </ul>
     17 </div>
     18 </div>
     19 
     20 <p>When users install a handheld app that contains a <a
     21 href="{@docRoot}training/wearables/apps/index.html">wearable app</a> with watch faces, these
     22 watch faces become available in the Android Wear companion app on the companion device and in
     23 the watch face picker on the wearable. Users can choose the active watch face for their wearable
     24 device by selecting it on the companion app or using the watch face picker on the wearable
     25 device.</p>
     26 
     27 <p>Some watch faces support configuration parameters to let users customize how the watch face
     28 looks and behaves. For example, some watch faces let users pick a custom background color, and
     29 watch faces that tell time for two different time zones can let users select which time zones
     30 they are interested in.</p>
     31 
     32 <p>Watch faces that support configuration parameters can let users customize a watch face using
     33 an activity in the wearable app, an activity on the handheld app, or both. Users can start the
     34 wearable configuration activity on the wearable device, and they can start the companion
     35 configuration activity from the Android Wear companion app.</p>
     36 
     37 <p>The digital watch face from the <em>WatchFace</em> sample in the Android SDK demonstrates how to
     38 implement handheld and wearable configuration activities and how to update a watch face in
     39 response to configuration changes. This sample is located in the
     40 <code>android-sdk/samples/android-21/wearable/WatchFace</code> directory.</p>
     41 
     42 
     43 
     44 <h2 id="Intent">Specify an Intent for Configuration Activities</h2>
     45 
     46 <p>If your watch face includes configuration activities, add the following metadata entries to
     47 the service declaration in the manifest file of the wearable app:</p>
     48 
     49 <pre>
     50 &lt;service
     51     android:name=".DigitalWatchFaceService" ... />
     52     &lt;!-- companion configuration activity -->
     53     &lt;meta-data
     54         android:name=
     55            "com.google.android.wearable.watchface.companionConfigurationAction"
     56         android:value=
     57            "com.example.android.wearable.watchface.CONFIG_DIGITAL" />
     58     &lt;!-- wearable configuration activity -->
     59     &lt;meta-data
     60         android:name=
     61            "com.google.android.wearable.watchface.wearableConfigurationAction"
     62         android:value=
     63            "com.example.android.wearable.watchface.CONFIG_DIGITAL" />
     64     ...
     65 &lt;/service>
     66 </pre>
     67 
     68 <p>Provide values for these entries that are preceded by the package name of your app.
     69 Configuration activities register intent filters for this intent, and the system fires this
     70 intent when users want to configure your watch face.</p>
     71 
     72 <p>If your watch face only includes a companion or a wearable configuration activity, you only
     73 need to include the corresponding metadata entry from the example above.</p>
     74 
     75 
     76 
     77 <h2 id="WearableActivity">Create a Wearable Configuration Activity</h2>
     78 
     79 <p>Wearable configuration activities provide a limited set of customization choices for a
     80 watch face, because complex menus are hard to navigate on smaller screens. Your wearable
     81 configuration activity should provide binary choices and just a few selections to customize
     82 the main aspects of your watch face.</p>
     83 
     84 <p>To create a wearable configuration activity, add a new activity to your wearable app module
     85 and declare the following intent filter in the manifest file of the wearable app:</p>
     86 
     87 <pre>
     88 &lt;activity
     89     android:name=".DigitalWatchFaceWearableConfigActivity"
     90     android:label="@string/digital_config_name">
     91     &lt;intent-filter>
     92         &lt;action android:name=
     93             "com.example.android.wearable.watchface.CONFIG_DIGITAL" />
     94         &lt;category android:name=
     95         <strong>"com.google.android.wearable.watchface.category.WEARABLE_CONFIGURATION"</strong> />
     96         &lt;category android:name="android.intent.category.DEFAULT" />
     97     &lt;/intent-filter>
     98 &lt;/activity>
     99 </pre>
    100 
    101 <p>The name of the action in this intent filter must match the intent name you defined in
    102 <a href="#Intent">Specify an Intent for Configuration Activities</a>.</p>
    103 
    104 <p>In your configuration activity, build a simple UI that provides selections for users to
    105 customize your watch face. When users make a selection, use the <a
    106 href="{@docRoot}training/wearables/data-layer/index.html">Wearable Data Layer API</a> to
    107 communicate the configuration change to the watch face activity.</p>
    108 
    109 <p>For more details, see the <code>DigitalWatchFaceWearableConfigActivity</code> and
    110 <code>DigitalWatchFaceUtil</code> classes in the <em>WatchFace</em> sample.</p>
    111 
    112 
    113 
    114 <h2 id="CompanionActivity">Create a Companion Configuration Activity</h2>
    115 
    116 <p>Companion configuration activities give users access to the full set of configuration choices
    117 for a watch face, because it is easier to interact with complex menus on the larger screen of
    118 a handheld device. For example, a configuration activity on a handheld device enables you to
    119 present users with elaborate color pickers to select the background color of a watch face.</p>
    120 
    121 <p>To create a companion configuration activity, add a new activity to your handheld app module and
    122 declare the following intent filter in the manifest file of the handheld app:</p>
    123 
    124 <pre>
    125 &lt;activity
    126     android:name=".DigitalWatchFaceCompanionConfigActivity"
    127     android:label="@string/app_name">
    128     &lt;intent-filter>
    129         &lt;action android:name=
    130             "com.example.android.wearable.watchface.CONFIG_DIGITAL" />
    131         &lt;category android:name=
    132         <strong>"com.google.android.wearable.watchface.category.COMPANION_CONFIGURATION"</strong> />
    133         &lt;category android:name="android.intent.category.DEFAULT" />
    134     &lt;/intent-filter>
    135 &lt;/activity>
    136 </pre>
    137 
    138 <p>In your configuration activity, build a UI that provides options to customize all the
    139 configurable elements of your watch face. When users make a selection, use the <a
    140 href="{@docRoot}training/wearables/data-layer/index.html">Wearable Data Layer API</a> to
    141 communicate the configuration change to the watch face activity.</p>
    142 
    143 <p>For more details, see the <code>DigitalWatchFaceCompanionConfigActivity</code> class in the
    144 <em>WatchFace</em> sample.</p>
    145 
    146 
    147 
    148 <h2 id="Listener">Create a Listener Service in the Wearable App</h2>
    149 
    150 <p>To receive updated configuration parameters from the configuration activities, create a
    151 service that implements the <code>WearableListenerService</code> interface from the <a
    152 href="{@docRoot}training/wearables/data-layer/index.html">Wearable Data Layer API</a> in your
    153 wearable app. Your watch face implementation can redraw the watch face when the configuration
    154 parameters change.</p>
    155 
    156 <p>For more details, see the <code>DigitalWatchFaceConfigListenerService</code> and
    157 <code>DigitalWatchFaceService</code> classes in the <em>WatchFace</em> sample.</p>
    158