Google TV

UI Controls

  1. Input events
  2. Navigation and focus
  3. Media Keys

Focus

The standard input hardware for a Google TV device includes a mouse or equivalent, an alphanumeric keyboard, a directional pad (D-Pad), and media transport controls keys such as play, pause, and rewind (see the following section "Media Keys"). In addition, you should expect that the device does not have a full touch screen interface. Some devices may emulate a subset of touchscreen features using the mouse or D-Pad.

To respond to input devices, your Android application UI contains several View objects that trigger actions or provide input to the application. These are your UI controls.

Your users interact with your UI controls by using the D-Pad keys either to navigate to a control or to trigger an input. To navigate between controls, the user presses the up, down, left, and right arrow keys on the D-Pad. These may be labeled with text or icons or both, or may simply have the appropriate shape. In response, Google TV moves the input focus to the nearest control in the appropriate direction, as determined by an internal algorithm.

To trigger the action of a control, the user presses the center key of the D-Pad, which sends KeyEvent.KEYCODE_DPAD_CENTER. The keyboard ENTER key sends KeyEvent.KEYCODE_ENTER.

In some cases, the navigation task is not over, because the control has its own internal navigation; for example, the user may also need to navigate among the cells in a GridView control. In this case, you may need to provide the user with one or more sub-controls for saving and canceling the work down within the control.

Navigating with a D-Pad is not as straightforward as using a touch screen, so you should take extra steps to provide a good user experience. Test your application with the D-Pad to ensure that your users can easily navigate to all the controls in each Activity. Ensure that movement between controls is straightforward and predictable. Android usually handles this automatically, so you don't need to do anything extra.

If the screen layout makes navigation difficult, or if you want users to move through the layout in a specific way, you can set up explicit navigation for your controls. To set up explicit navigation, use the android:nextFocusUp, android:nextFocusDown, android:nextFocusLeft, and android:nextFocusRight attributes for the control View objects in your layout. These specify the next View that should get focus when the next focus is "up", "down", "left", and "right". The next focus is triggered by a D-Pad key; for example, android:nextFocusUp is triggered by KeyEvent.KEYCODE_DPAD_UP.

You can also use android:nextFocusForward, which specifies the next View that should receive focus when the next focus is FOCUS_FORWARD. This is usually generated by KeyEvent.KEYCODE_TAB.

To use an explicit navigation attribute, you set it to the android:id value for another control in the Layout. Because of this, you have to set android:id values for any control that's the target of an explicit navigation attribute. You should set up the focus order as a loop, so that the last control directs focus back to the first one.

If necessary, you can allow a View object to receive focus, even if it normally doesn't. To do this, you use the android:focusable attribute.

To learn more about designing UIs for non-touchscreen devices, you should also read the topic Designing for Accessibility in the Android Developers Guide.

Media keys

Google TV keyboards have seven media-control keys that are mapped to KeyEvent constants. These are listed in Table 1. If your application plays music, displays video or or runs a slide show, you can handle these control keys in the android.view.View.onKeyDown() callback for the View that controls the media.

Note: The media-control keys for Android versions prior to 2.3 (Gingerbread) are not supported.

Table 1. Google TV Media Keys, KeyEvent Mappings, and Symbols
1The symbol usually associated with the key. Some keyboards may have two symbols on the same key; in this case, the scan code sent out by the key is controlled by a separate modifier key.
Action KeyEvent keycode constant Keyboard Symbol1
Start playback KeyEvent.KEYCODE_MEDIA_PLAY illustration of a play button
Pause playback KeyEvent.KEYCODE_MEDIA_PAUSE illustration of a pause button
Stop playback KeyEvent.KEYCODE_MEDIA_STOP illustration of a stop button
Next KeyEvent.KEYCODE_MEDIA_NEXT illustration of a next button
Fast-forward KeyEvent.KEYCODE_MEDIA_FAST_FORWARD illustration of a fast-forward button
Previous KeyEvent.KEYCODE_MEDIA_PREVIOUS illustration of a previous selection button
Rewind KeyEvent.KEYCODE_MEDIA_REWIND illustration of a rewind button

This code snippet demonstrates how to handle media key events:

@Override
/**
 * Overrides the callback method for a UI control handling a slideshow
 **/
public boolean onKeyDown(int keyCode, KeyEvent event) {

  /*
   * Chooses the action to take, based on the incoming keycode
   */
  switch (keyCode) {
    case KeyEvent.KEYCODE_PAUSE:
         
      Log.d("MediaPlayer", "Pausing the slideshow");

      if (slideshow.pause()) {
        showStatusToast(R.string.slideshow_paused);
      }

      return true;

    case KeyEvent.KEYCODE_MEDIA_PLAY:
         
      Log.d(TAG, "Resuming the slideshow");
         
      if (slideshow.resume()) {
        showStatusToast(R.string.slideshow_resumed);
      }

      return true;

    /*
     * Keycodes should always be passed upwards in the chain for handling.
     */
    default:
      return super.onKeyDown(keyCode, event);
  }
}

Authentication required

You need to be signed in with Google+ to do that.

Signing you in...

Google Developers needs your permission to do that.