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

The following are Jave code examples for showing how to use getDisplayWidth() 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.
Example 1
Project: UIAutomatorWD   File: WindowController.java   Source Code and License Vote up 6 votes
@Override
public NanoHTTPD.Response get(RouterNanoHTTPD.UriResource uriResource, Map<String, String> urlParams, NanoHTTPD.IHTTPSession session) {
    String sessionId = urlParams.get("sessionId");
    try {
        UiDevice mDevice = Elements.getGlobal().getmDevice();
        Integer width = mDevice.getDisplayWidth();
        Integer height = mDevice.getDisplayHeight();
        JSONObject size = new JSONObject();
        size.put("width", width);
        size.put("height", height);
        return NanoHTTPD.newFixedLengthResponse(getStatus(), getMimeType(), new Response(size, sessionId).toString());
    } catch(Exception e) {
        return NanoHTTPD.newFixedLengthResponse(getStatus(), getMimeType(), new Response(Status.UnknownError, sessionId).toString());
    }
}
 
Example 2
Project: appium-uiautomator2-server   File: PositionHelper.java   Source Code and License Vote up 5 votes
public static Point getDeviceAbsPos(final Point point)
        throws UiObjectNotFoundException, InvalidCoordinatesException {
    final UiDevice d = UiDevice.getInstance();
    final Rect displayRect = new Rect(0, 0, d.getDisplayWidth(), d.getDisplayHeight());

    Logger.debug("Display bounds: " + displayRect.toShortString());

    return getAbsolutePosition(point, displayRect, new Point(), true);
}