Java Code Examples for android.support.test.uiautomator.UiDevice.pressKeyCode()

The following are Jave code examples for showing how to use pressKeyCode() of the android.support.test.uiautomator.UiDevice class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: UIAutomatorWD   File: KeysController.java   View Source Code Vote up 6 votes
@Override
public NanoHTTPD.Response get(RouterNanoHTTPD.UriResource uriResource, Map<String, String> urlParams, NanoHTTPD.IHTTPSession session) {
    String sessionId = urlParams.get("sessionId");
    Map<String, String> body = new HashMap<String, String>();
    UiDevice mDevice = Elements.getGlobal().getmDevice();
    JSONObject result = null;
    try {
        session.parseBody(body);
        String postData = body.get("postData");
        JSONObject jsonObj = JSON.parseObject(postData);
        JSONArray keycodes = (JSONArray)jsonObj.get("value");
        for (Iterator iterator = keycodes.iterator(); iterator.hasNext();) {
            int keycode = (int) iterator.next();
            mDevice.pressKeyCode(keycode);
        }
        return NanoHTTPD.newFixedLengthResponse(getStatus(), getMimeType(), new Response(result, sessionId).toString());
    } catch (Exception e) {
        return NanoHTTPD.newFixedLengthResponse(getStatus(), getMimeType(), new Response(Status.UnknownError, sessionId).toString());
    }
}
 
Example 2
Project: android_packages_apps_tv   File: UiDeviceUtils.java   View Source Code Vote up 5 votes
/**
 * Parses the string and sends the corresponding individual key preses.
 * <p>
 * <b>Note:</b> only handles 0-9, '.', and '-'.
 */
public static void pressKeys(UiDevice uiDevice, String keys) {
    for (char c : keys.toCharArray()) {
        if (c >= '0' && c <= '9') {
            uiDevice.pressKeyCode(KeyEvent.KEYCODE_0 + c - '0');
        } else if (c == '-') {
            uiDevice.pressKeyCode(KeyEvent.KEYCODE_MINUS);
        } else if (c == '.') {
            uiDevice.pressKeyCode(KeyEvent.KEYCODE_PERIOD);
        } else {
            throw new IllegalArgumentException(c + " is not supported");
        }
    }
}
 
Example 3
Project: android_packages_apps_tv   File: UiDeviceUtils.java   View Source Code Vote up 4 votes
public static void pressKeys(UiDevice uiDevice, int... keyCodes) {
    for (int k : keyCodes) {
        uiDevice.pressKeyCode(k);
    }
}