Java Code Examples for android.app.UiAutomation#ROTATION_FREEZE_180
The following examples show how to use
android.app.UiAutomation#ROTATION_FREEZE_180 .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: UiDevice.java From za-Farmer with MIT License | 5 votes |
/** * Check if the device is in its natural orientation. This is determined by checking if the * orientation is at 0 or 180 degrees. * @return true if it is in natural orientation * @since API Level 17 */ public boolean isNaturalOrientation() { Tracer.trace(); waitForIdle(); int ret = getAutomatorBridge().getRotation(); return ret == UiAutomation.ROTATION_FREEZE_0 || ret == UiAutomation.ROTATION_FREEZE_180; }
Example 2
Source File: UiDevice.java From JsDroidCmd with Mozilla Public License 2.0 | 5 votes |
public int getDisplayUnRotationWidth() { int rotation = getDisplayRotation(); if (rotation == UiAutomation.ROTATION_FREEZE_0 || rotation == UiAutomation.ROTATION_FREEZE_180) { return getDisplayWidth(); } else { return getDisplayHeight(); } }
Example 3
Source File: UiDevice.java From JsDroidCmd with Mozilla Public License 2.0 | 5 votes |
public int getDisplayUnRotationHeight() { int rotation = getDisplayRotation(); if (rotation == UiAutomation.ROTATION_FREEZE_0 || rotation == UiAutomation.ROTATION_FREEZE_180) { return getDisplayHeight(); } else { return getDisplayWidth(); } }
Example 4
Source File: UiDevice.java From JsDroidCmd with Mozilla Public License 2.0 | 5 votes |
/** * Check if the device is in its natural orientation. This is determined by * checking if the orientation is at 0 or 180 degrees. * * @return true if it is in natural orientation * @since API Level 17 */ public boolean isNaturalOrientation() { Tracer.trace(); waitForIdle(); int ret = getAutomatorBridge().getRotation(); return ret == UiAutomation.ROTATION_FREEZE_0 || ret == UiAutomation.ROTATION_FREEZE_180; }
Example 5
Source File: JsDroidEvent.java From JsDroidCmd with Mozilla Public License 2.0 | 4 votes |
public static Point toOriginPoint(int x, int y) { int rotation = UiDevice.getInstance().getRotation(); int width = UiDevice.getInstance().getDisplayWidth(); int height = UiDevice.getInstance().getDisplayHeight(); int rWidth = xmax() - xmin(); int rHeight = ymax() - ymin(); int tempx = 0; int tempy = 0; int tempWidth = 0; int tempHeight = 0; // 将xy旋转回来 switch (rotation) { case UiAutomation.ROTATION_FREEZE_0: break; case UiAutomation.ROTATION_FREEZE_90: // 原来的x = 现在的y,原来的y = 现在的宽度-现在的x tempx = y; tempy = width - x; x = tempx; y = tempy; tempWidth = height; tempHeight = width; break; case UiAutomation.ROTATION_FREEZE_180: // 原来的x = 现在的宽度-现在的x,原来的y=现在的高度-现在的y tempx = width - x; tempy = height - y; x = tempx; y = tempy; break; case UiAutomation.ROTATION_FREEZE_270: // 原来的x = 现在的高度-现在的y,原来的y=现在的x tempx = height - y; tempy = x; x = tempx; y = tempy; tempWidth = height; tempHeight = width; width = tempWidth; height = tempHeight; break; } // 缩放到驱动坐标 x = (x * rWidth / width); y = (y * rHeight / height); return new Point(x, y); }
Example 6
Source File: BitmapUtil.java From JsDroidCmd with Mozilla Public License 2.0 | 4 votes |
public static Bitmap takeScreenshot(int rotation, int screenWidth, int screenHeight) { Display display = DisplayManagerGlobal.getInstance().getRealDisplay( Display.DEFAULT_DISPLAY); Point displaySize = new Point(); display.getRealSize(displaySize); final int displayWidth = screenWidth; final int displayHeight = screenHeight; final float screenshotWidth; final float screenshotHeight; switch (rotation) { case UiAutomation.ROTATION_FREEZE_0: { screenshotWidth = displayWidth; screenshotHeight = displayHeight; } break; case UiAutomation.ROTATION_FREEZE_90: { screenshotWidth = displayHeight; screenshotHeight = displayWidth; } break; case UiAutomation.ROTATION_FREEZE_180: { screenshotWidth = displayWidth; screenshotHeight = displayHeight; } break; case UiAutomation.ROTATION_FREEZE_270: { screenshotWidth = displayHeight; screenshotHeight = displayWidth; } break; default: { return null; } } Bitmap screenShot = null; try { screenShot = SurfaceControl.screenshot((int) screenshotWidth, (int) screenshotHeight); if (screenShot == null) { return null; } } catch (Exception re) { return null; } if (rotation != UiAutomation.ROTATION_FREEZE_0) { Bitmap unrotatedScreenShot = Bitmap.createBitmap(displayWidth, displayHeight, Bitmap.Config.ARGB_8888); Canvas canvas = new Canvas(unrotatedScreenShot); canvas.translate(unrotatedScreenShot.getWidth() / 2, unrotatedScreenShot.getHeight() / 2); canvas.rotate(getDegreesForRotation(rotation)); canvas.translate(-screenshotWidth / 2, -screenshotHeight / 2); canvas.drawBitmap(screenShot, 0, 0, null); canvas.setBitmap(null); screenShot.recycle(); screenShot = unrotatedScreenShot; } // Optimization screenShot.setHasAlpha(false); return screenShot; }