WearableButtons
public
final
class
WearableButtons
extends Object
java.lang.Object | |
↳ | androidx.wear.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
Drawable
|
getButtonIcon(Context context, int keycode)
Returns an icon that can be used to represent the location of a button. |
static
WearableButtons.ButtonInfo
|
getButtonInfo(Context context, int keycode)
Returns a |
static
CharSequence
|
getButtonLabel(Context context, int keycode)
Returns a CharSequence that describes the placement location of a button. |
static
void
|
setWearableButtonsProvider(WearableButtonsProvider provider)
Testing call to allow the underlying |
Inherited methods | |
---|---|
Public methods
getButtonCount
public static int getButtonCount (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 | |
---|---|
context |
Context : The context of the current activity |
Returns | |
---|---|
int |
The number of buttons available, or the information is not available. |
getButtonIcon
public static 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
public static 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 KeyEvent.KEYCODE_STEM_PRIMARY
, KeyEvent.KEYCODE_STEM_1
, KeyEvent.KEYCODE_STEM_2
, and
KeyEvent.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
public static 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, or null if no location is available for that button. |
setWearableButtonsProvider
public static void setWearableButtonsProvider (WearableButtonsProvider provider)
Testing call to allow the underlying WearableButtonsProvider
to be substituted in
test code.
Parameters | |
---|---|
provider |
WearableButtonsProvider : The new WearableButtonsProvider to use.
|
Content and code samples on this page are subject to the licenses described in the Content License. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2020-09-30 UTC.