TestWearableButtonsProvider

public class TestWearableButtonsProvider implements WearableButtonsProvider


A WearableButtonsProvider suitable for use in tests.

This allows for explicitly specifying which buttons are available for testing, and their coordinates. It is intended to be used by passing in a map, mapping between the button keycode (typically in the set KEYCODE_STEM_PRIMARY, , KEYCODE_STEM_2, or ) and the location of the button. Take the following example:

    Mapbuttons = new HashMap<>();
    buttons.put(KEYCODE_STEM_1, new TestWearableButtonLocation(100, 100);

    TestWearableButtonsProvider provider = new TestWearableButtonsProvider(buttons);

    WearableButtons.setWearableButtonsProvider(provider);

Summary

Nested types

TestWearableButtonsProvider.TestWearableButtonLocation

Class describing the location of a button on a wearable device.

Public constructors

Build a button provider, which will respond with the provided set of buttons.

Public methods

@Nullable @Override Array<@NonNull int>

Get the keycodes of available hardware buttons on device.

@NonNull @Override Bundle
getButtonInfo(@NonNull Context context, @NonNull int keycode)

Returns a bundle containing the metadata of a specific button.

Public constructors

TestWearableButtonsProvider

public TestWearableButtonsProvider(
    @NonNull Map<@NonNull Integer, @NonNull TestWearableButtonsProvider.TestWearableButtonLocation> buttons
)

Build a button provider, which will respond with the provided set of buttons.

Parameters
@NonNull Map<@NonNull Integer, @NonNull TestWearableButtonsProvider.TestWearableButtonLocation> buttons

The buttons returned by this provider.

Public methods

getAvailableButtonKeyCodes

@Nullable
@Override
@NonNull
public @Override Array<@NonNull int> getAvailableButtonKeyCodes(@NonNull Context context)

Get the keycodes of available hardware buttons on device. This function based on key's locations from system property. 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
@Override Array<@NonNull int>

An int array of available button keycodes, or null if no keycodes could be read.

getButtonInfo

@NonNull
@Override
public @Override Bundle getButtonInfo(@NonNull Context context, @NonNull int keycode)

Returns a bundle containing the metadata of a specific button. Currently, only location is supported. Use with X_KEY and Y_KEY. The key will not be present if the information is not available for the requested keycode.

The location returned is a Cartesian coordinate where the bottom left corner of the screen is the origin. 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.

Parameters
@NonNull Context context

The context of the current activity

@NonNull int keycode

The keycode associated with the hardware button of interest

Returns
@Override Bundle

A Bundle containing the metadata for the given keycode