WearableButtons

public final class WearableButtons


Class containing helpers for managing wearable buttons.

Summary

Nested types

public final class WearableButtons.ButtonInfo

Metadata for a specific button.

Constants

static final int

Represents the center third of the bottom side on a square device.

static final int

Represents the left third of the bottom side on a square device.

static final int

Represents the right third of the bottom side on a square device.

static final int

Represents the east position on a round device.

static final int

Represents the east-northeast position on a round device.

static final int
LOC_ESE = 15

Represents the east-southeast position on a round device.

static final int

Represents the bottom third of the left side on a square device.

static final int

Represents the center third of the left side on a square device.

static final int

Represents the top third of the left side on a square device.

static final int
LOC_NE = 2

Represents the northeast position on a round device.

static final int

Represents the north-northeast position on a round device.

static final int

Represents the north-northwest position on a round device.

static final int

Represents the north position on a round device.

static final int
LOC_NW = 6

Represents the northwest position on a round device.

static final int

Represents the bottom third of the right side on a square device.

static final int

Represents the center third of the right side on a square device.

static final int

Represents the top third of the right side on a square device.

static final int
LOC_SE = 14

Represents the southeast position on a round device.

static final int

Represents the south position on a round device.

static final int
LOC_SSE = 13

Represents the south-southeast position on a round device.

static final int
LOC_SSW = 11

Represents the south-southwest position on a round device.

static final int
LOC_SW = 10

Represents the southwest position on a round device.

static final int

Represents the center third of the top side on a square device.

static final int

Represents the left third of the top side on a square device.

static final int

Represents the right third of the top side on a square device.

static final int

Represents that the location zone is unknown.

static final int

Represents the west position on a round device.

static final int

Represents the west-northwest position on a round device.

static final int

Represents the west-southwest position on a round device.

Public methods

static int

Get the number of hardware buttons available.

static @Nullable Drawable
getButtonIcon(@NonNull Context context, int keycode)

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

static @Nullable WearableButtons.ButtonInfo
getButtonInfo(@NonNull Context context, int keycode)

Returns a ButtonInfo containing the metadata for a specific button.

static @Nullable CharSequence
getButtonLabel(@NonNull Context context, int keycode)

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

static void
@VisibleForTesting(otherwise = VisibleForTesting.NONE)
setWearableButtonsProvider(@NonNull WearableButtonsProvider provider)

Testing call to allow the underlying WearableButtonsProvider to be substituted in test code.

Constants

LOC_BOTTOM_CENTER

public static final int LOC_BOTTOM_CENTER = 107

Represents the center third of the bottom side on a square device.

LOC_BOTTOM_LEFT

public static final int LOC_BOTTOM_LEFT = 106

Represents the left third of the bottom side on a square device.

LOC_BOTTOM_RIGHT

public static final int LOC_BOTTOM_RIGHT = 108

Represents the right third of the bottom side on a square device.

LOC_EAST

public static final int LOC_EAST = 0

Represents the east position on a round device.

LOC_ENE

public static final int LOC_ENE = 1

Represents the east-northeast position on a round device.

LOC_ESE

public static final int LOC_ESE = 15

Represents the east-southeast position on a round device.

LOC_LEFT_BOTTOM

public static final int LOC_LEFT_BOTTOM = 105

Represents the bottom third of the left side on a square device.

LOC_LEFT_CENTER

public static final int LOC_LEFT_CENTER = 104

Represents the center third of the left side on a square device.

LOC_LEFT_TOP

public static final int LOC_LEFT_TOP = 103

Represents the top third of the left side on a square device.

LOC_NE

public static final int LOC_NE = 2

Represents the northeast position on a round device.

LOC_NNE

public static final int LOC_NNE = 3

Represents the north-northeast position on a round device.

LOC_NNW

public static final int LOC_NNW = 5

Represents the north-northwest position on a round device.

LOC_NORTH

public static final int LOC_NORTH = 4

Represents the north position on a round device.

LOC_NW

public static final int LOC_NW = 6

Represents the northwest position on a round device.

LOC_RIGHT_BOTTOM

public static final int LOC_RIGHT_BOTTOM = 109

Represents the bottom third of the right side on a square device.

LOC_RIGHT_CENTER

public static final int LOC_RIGHT_CENTER = 110

Represents the center third of the right side on a square device.

LOC_RIGHT_TOP

public static final int LOC_RIGHT_TOP = 111

Represents the top third of the right side on a square device.

LOC_SE

public static final int LOC_SE = 14

Represents the southeast position on a round device.

LOC_SOUTH

public static final int LOC_SOUTH = 12

Represents the south position on a round device.

LOC_SSE

public static final int LOC_SSE = 13

Represents the south-southeast position on a round device.

LOC_SSW

public static final int LOC_SSW = 11

Represents the south-southwest position on a round device.

LOC_SW

public static final int LOC_SW = 10

Represents the southwest position on a round device.

LOC_TOP_CENTER

public static final int LOC_TOP_CENTER = 101

Represents the center third of the top side on a square device.

LOC_TOP_LEFT

public static final int LOC_TOP_LEFT = 102

Represents the left third of the top side on a square device.

LOC_TOP_RIGHT

public static final int LOC_TOP_RIGHT = 100

Represents the right third of the top side on a square device.

LOC_UNKNOWN

public static final int LOC_UNKNOWN = -1

Represents that the location zone is unknown.

LOC_WEST

public static final int LOC_WEST = 8

Represents the west position on a round device.

LOC_WNW

public static final int LOC_WNW = 7

Represents the west-northwest position on a round device.

LOC_WSW

public static final int LOC_WSW = 9

Represents the west-southwest position on a round device.

Public methods

getButtonCount

Added in 1.0.0
public static int getButtonCount(@NonNull Context context)

Get the number of hardware buttons available. This count includes the primary stem key as well as any secondary stem keys available.

Parameters
@NonNull Context context

The context of the current activity

Returns
int

The number of buttons available, or the information is not available.

getButtonIcon

Added in 1.0.0
public static @Nullable Drawable getButtonIcon(@NonNull Context context, int keycode)

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

Parameters
@NonNull Context context

The context of the current activity

int keycode

The keycode associated with the hardware button of interest

Returns
@Nullable Drawable

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

getButtonInfo

Added in 1.0.0
public static @Nullable WearableButtons.ButtonInfo getButtonInfo(@NonNull Context context, int keycode)

Returns a 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
@NonNull Context context

The context of the current activity

int keycode

The keycode associated with the hardware button of interest

Returns
@Nullable WearableButtons.ButtonInfo

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

getButtonLabel

Added in 1.0.0
public static @Nullable CharSequence getButtonLabel(@NonNull Context context, int keycode)

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

Parameters
@NonNull Context context

The context of the current activity

int keycode

The keycode associated with the hardware button of interest

Returns
@Nullable CharSequence

A CharSequence describing the placement location of the button, or null if no location is available for that button.

setWearableButtonsProvider

Added in 1.2.0-alpha03
@VisibleForTesting(otherwise = VisibleForTesting.NONE)
public static void setWearableButtonsProvider(@NonNull WearableButtonsProvider provider)

Testing call to allow the underlying WearableButtonsProvider to be substituted in test code.

Parameters
@NonNull WearableButtonsProvider provider

The new WearableButtonsProvider to use.