Skip to content

Most visited

Recently visited

navigation

WearableButtons

public final class WearableButtons
extends Object

java.lang.Object
   ↳ android.support.wearable.input.WearableButtons


Class containing helpers for managing wearable buttons.

Summary

Nested classes

class WearableButtons.ButtonInfo

Metadata for a specific button. 

Public methods

static int getButtonCount(Context context)

Get the number of hardware buttons available.

static final Drawable getButtonIcon(Context context, int keycode)

Returns an icon that can be used to represent the location of a button.

static final WearableButtons.ButtonInfo getButtonInfo(Context context, int keycode)

Returns a WearableButtons.ButtonInfo containing the metadata for a specific button.

static final CharSequence getButtonLabel(Context context, int keycode)

Returns a CharSequence that describes the placement location of a button.

Inherited methods

From class java.lang.Object

Public methods

getButtonCount

int getButtonCount (Context context)

Get the number of hardware buttons available. This function only works on API level 24 or higher (Wear 2.0). This count includes the primary stem key as well as any secondary stem keys available.

Parameters
context Context: The context of the current activity

Returns
int The number of buttons available or -1 if not a Wear 2.0 device.

getButtonIcon

Drawable getButtonIcon (Context context, 
                int keycode)

Returns an icon that can be used to represent the location of a button.

Parameters
context Context: The context of the current activity

keycode int: The keycode associated with the hardware button of interest

Returns
Drawable A drawable representing the location of a button, or null if unavailable

getButtonInfo

WearableButtons.ButtonInfo getButtonInfo (Context context, 
                int keycode)

Returns a WearableButtons.ButtonInfo containing the metadata for a specific button.

The location will be populated in the following manner:

  • The provided point will be on the screen, or more typically, on the edge of the screen.
  • The point won't be off the edge of the screen.
  • The location returned is a screen coordinate. The unit of measurement is in pixels. The coordinates do not take rotation into account and assume that the device is in the standard upright position.

Common keycodes to use are KEYCODE_STEM_PRIMARY, KEYCODE_STEM_1, KEYCODE_STEM_2, and KEYCODE_STEM_3.

Parameters
context Context: The context of the current activity

keycode int: The keycode associated with the hardware button of interest

Returns
WearableButtons.ButtonInfo A WearableButtons.ButtonInfo containing the metadata for the given keycode or null if the information is not available

getButtonLabel

CharSequence getButtonLabel (Context context, 
                int keycode)

Returns a CharSequence that describes the placement location of a button. An example might be "Top right" or "Bottom".

Parameters
context Context: The context of the current activity

keycode int: The keycode associated with the hardware button of interest

Returns
CharSequence A CharSequence describing the placement location of the button

This site uses cookies to store your preferences for site-specific language and display options.

Get the latest Android developer news and tips that will help you find success on Google Play.

* Required Fields

Hooray!

Follow Google Developers on WeChat

Browse this site in ?

You requested a page in , but your language preference for this site is .

Would you like to change your language preference and browse this site in ? If you want to change your language preference later, use the language menu at the bottom of each page.

This class requires API level or higher

This doc is hidden because your selected API level for the documentation is . You can change the documentation API level with the selector above the left navigation.

For more information about specifying the API level your app requires, read Supporting Different Platform Versions.

Take a short survey?
Help us improve the Android developer experience. (Dec 2017 Android Platform & Tools Survey)