WearableButtons
class WearableButtons
Class containing helpers for managing wearable buttons.
Summary
Nested types |
|---|
|
Metadata for a specific button. |
Constants |
|
|---|---|
const Int |
LOCATION_BOTTOM_CENTER = 107Represents the center third of the bottom side on a square device. |
const Int |
LOCATION_BOTTOM_LEFT = 106Represents the left third of the bottom side on a square device. |
const Int |
LOCATION_BOTTOM_RIGHT = 108Represents the right third of the bottom side on a square device. |
const Int |
LOCATION_EAST = 0Represents the east position on a round device. |
const Int |
LOCATION_ENE = 1Represents the east-northeast position on a round device. |
const Int |
LOCATION_ESE = 15Represents the east-southeast position on a round device. |
const Int |
LOCATION_LEFT_BOTTOM = 105Represents the bottom third of the left side on a square device. |
const Int |
LOCATION_LEFT_CENTER = 104Represents the center third of the left side on a square device. |
const Int |
LOCATION_LEFT_TOP = 103Represents the top third of the left side on a square device. |
const Int |
LOCATION_NE = 2Represents the northeast position on a round device. |
const Int |
LOCATION_NNE = 3Represents the north-northeast position on a round device. |
const Int |
LOCATION_NNW = 5Represents the north-northwest position on a round device. |
const Int |
LOCATION_NORTH = 4Represents the north position on a round device. |
const Int |
LOCATION_NW = 6Represents the northwest position on a round device. |
const Int |
LOCATION_RIGHT_BOTTOM = 109Represents the bottom third of the right side on a square device. |
const Int |
LOCATION_RIGHT_CENTER = 110Represents the center third of the right side on a square device. |
const Int |
LOCATION_RIGHT_TOP = 111Represents the top third of the right side on a square device. |
const Int |
LOCATION_SE = 14Represents the southeast position on a round device. |
const Int |
LOCATION_SOUTH = 12Represents the south position on a round device. |
const Int |
LOCATION_SSE = 13Represents the south-southeast position on a round device. |
const Int |
LOCATION_SSW = 11Represents the south-southwest position on a round device. |
const Int |
LOCATION_SW = 10Represents the southwest position on a round device. |
const Int |
LOCATION_TOP_CENTER = 101Represents the center third of the top side on a square device. |
const Int |
LOCATION_TOP_LEFT = 102Represents the left third of the top side on a square device. |
const Int |
LOCATION_TOP_RIGHT = 100Represents the right third of the top side on a square device. |
const Int |
LOCATION_UNKNOWN = -1Represents that the location zone is unknown. |
const Int |
LOCATION_WEST = 8Represents the west position on a round device. |
const Int |
LOCATION_WNW = 7Represents the west-northwest position on a round device. |
const Int |
LOCATION_WSW = 9Represents the west-southwest position on a round device. |
Public functions |
|
|---|---|
java-static Int |
getButtonCount(context: Context)Get the number of hardware buttons available. |
java-static Drawable? |
getButtonIcon(context: Context, keycode: Int)Returns an icon that can be used to represent the location of a button. |
java-static WearableButtons.ButtonInfo? |
getButtonInfo(context: Context, keycode: Int)Returns a |
java-static CharSequence? |
getButtonLabel(context: Context, keycode: Int)Returns a CharSequence that describes the placement location of a button. |
java-static Unit |
Testing call to allow the underlying |
Constants
LOCATION_BOTTOM_CENTER
const val LOCATION_BOTTOM_CENTER = 107: Int
Represents the center third of the bottom side on a square device.
LOCATION_BOTTOM_LEFT
const val LOCATION_BOTTOM_LEFT = 106: Int
Represents the left third of the bottom side on a square device.
LOCATION_BOTTOM_RIGHT
const val LOCATION_BOTTOM_RIGHT = 108: Int
Represents the right third of the bottom side on a square device.
LOCATION_EAST
const val LOCATION_EAST = 0: Int
Represents the east position on a round device.
LOCATION_ENE
const val LOCATION_ENE = 1: Int
Represents the east-northeast position on a round device.
LOCATION_ESE
const val LOCATION_ESE = 15: Int
Represents the east-southeast position on a round device.
LOCATION_LEFT_BOTTOM
const val LOCATION_LEFT_BOTTOM = 105: Int
Represents the bottom third of the left side on a square device.
LOCATION_LEFT_CENTER
const val LOCATION_LEFT_CENTER = 104: Int
Represents the center third of the left side on a square device.
LOCATION_LEFT_TOP
const val LOCATION_LEFT_TOP = 103: Int
Represents the top third of the left side on a square device.
LOCATION_NE
const val LOCATION_NE = 2: Int
Represents the northeast position on a round device.
LOCATION_NNE
const val LOCATION_NNE = 3: Int
Represents the north-northeast position on a round device.
LOCATION_NNW
const val LOCATION_NNW = 5: Int
Represents the north-northwest position on a round device.
LOCATION_NORTH
const val LOCATION_NORTH = 4: Int
Represents the north position on a round device.
LOCATION_NW
const val LOCATION_NW = 6: Int
Represents the northwest position on a round device.
LOCATION_RIGHT_BOTTOM
const val LOCATION_RIGHT_BOTTOM = 109: Int
Represents the bottom third of the right side on a square device.
LOCATION_RIGHT_CENTER
const val LOCATION_RIGHT_CENTER = 110: Int
Represents the center third of the right side on a square device.
LOCATION_RIGHT_TOP
const val LOCATION_RIGHT_TOP = 111: Int
Represents the top third of the right side on a square device.
LOCATION_SE
const val LOCATION_SE = 14: Int
Represents the southeast position on a round device.
LOCATION_SOUTH
const val LOCATION_SOUTH = 12: Int
Represents the south position on a round device.
LOCATION_SSE
const val LOCATION_SSE = 13: Int
Represents the south-southeast position on a round device.
LOCATION_SSW
const val LOCATION_SSW = 11: Int
Represents the south-southwest position on a round device.
LOCATION_SW
const val LOCATION_SW = 10: Int
Represents the southwest position on a round device.
LOCATION_TOP_CENTER
const val LOCATION_TOP_CENTER = 101: Int
Represents the center third of the top side on a square device.
LOCATION_TOP_LEFT
const val LOCATION_TOP_LEFT = 102: Int
Represents the left third of the top side on a square device.
LOCATION_TOP_RIGHT
const val LOCATION_TOP_RIGHT = 100: Int
Represents the right third of the top side on a square device.
LOCATION_UNKNOWN
const val LOCATION_UNKNOWN = -1: Int
Represents that the location zone is unknown.
LOCATION_WEST
const val LOCATION_WEST = 8: Int
Represents the west position on a round device.
LOCATION_WNW
const val LOCATION_WNW = 7: Int
Represents the west-northwest position on a round device.
LOCATION_WSW
const val LOCATION_WSW = 9: Int
Represents the west-southwest position on a round device.
Public functions
getButtonCount
java-static fun getButtonCount(context: Context): Int
Get the number of hardware buttons available. 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 the information is not available. |
getButtonIcon
java-static fun getButtonIcon(context: Context, keycode: Int): Drawable?
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
java-static fun getButtonInfo(context: Context, keycode: Int): WearableButtons.ButtonInfo?
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.
Additionally, a location zone will be provided for the button, which will be one of the LOCATION_* constants. This defines the general area of the button on the device, and can be passed to getButtonLabel to provide a human-understandable name for the location. There are two sets of locations for a device, depending on whether it is a circular or rectilinear device.
The "compass" locations (e.g. LOCATION_ENE) are used on a circular device. The locations for each are shown in the following image: 
The other locations (e.g. LOCATION_BOTTOM_CENTER) are used on a rectilinear device. The locations for each are shown in the following image: 
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 |
getButtonLabel
java-static fun getButtonLabel(context: Context, keycode: Int): CharSequence?
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, or null if no location is available for that button. |
setWearableButtonsProvider
@VisibleForTesting
java-static fun setWearableButtonsProvider(provider: WearableButtonsProvider): Unit
Testing call to allow the underlying WearableButtonsProvider to be substituted in test code.
| Parameters | |
|---|---|
provider: WearableButtonsProvider |
The new |