AndroidUiTool.jar中UiTool包源码
来源:互联网 发布:linux常用命令mkdir 编辑:程序博客网 时间:2024/06/14 22:26
AndroidUiTool.jar中UiTool包源码
package com.androiduitool;import android.graphics.Point;import android.graphics.Rect;import android.os.RemoteException;import android.util.Log;import com.android.uiautomator.Configurator;import com.android.uiautomator.ShellUiAutomatorBridge;import com.android.uiautomator.UiAutomationShellWrapper;import com.android.uiautomator.UiDevice;import com.android.uiautomator.UiObject;import com.android.uiautomator.UiObjectNotFoundException;import com.android.uiautomator.UiScrollable;import com.android.uiautomator.UiSelector;import com.android.uiautomator.UiWatcher;import java.io.File;import java.io.IOException;import java.io.PrintStream;import java.net.HttpURLConnection;import java.net.URL;import java.net.UnknownHostException;import java.text.DecimalFormat;public class UiTool{ public static final String TAG = "AndroidUiTool"; private UiAutomationShellWrapper automationWrapper = new UiAutomationShellWrapper(); private UiDevice device = UiDevice.getInstance(); private UiObject obj; private boolean rlt = false; private String watcherAll = "WatchAll"; public UiTool() { this.automationWrapper.connect(); ShellUiAutomatorBridge localShellUiAutomatorBridge = new ShellUiAutomatorBridge(this.automationWrapper.getUiAutomation()); this.device.initialize(localShellUiAutomatorBridge); this.device.registerWatcher(this.watcherAll, new MyWatcher(null)); } @Description("Swipe 4/5 height to unlock screen") @MethodInfo("SwipeUnlock") public void SwipeUnlock() { int i = this.device.getDisplayWidth(); int j = this.device.getDisplayHeight(); System.out.println("width is: " + i + " height is: " + j); this.device.swipe(i / 2, j - j / 5, i / 2, 0, 10); } @Description("Perform a click at arbitrary coordinates specified by the user") @MethodInfo("click") public boolean click(@ParamInfo(Descript="x coordinate", Name="x") int paramInt1, @ParamInfo(Descript="y coordinate", Name="y") int paramInt2) { return this.device.click(paramInt1, paramInt2); } @Description("Click Object identified by class name and instance id") @MethodInfo("clickByClazzInstance") public boolean clickByClazzInstance(@ParamInfo(Descript="The class name of the ui objcet to be clicked", Name="clazz") String paramString1, @ParamInfo(Descript="The object instance id", Name="ins") String paramString2) { int i = Integer.parseInt(paramString2); this.obj = new UiObject(new UiSelector().className(paramString1).instance(i)); if (this.obj.exists()) { try { boolean bool = this.obj.click(); return bool; } catch (UiObjectNotFoundException localUiObjectNotFoundException) { Log.e("AndroidUiTool", "Clazz: " + paramString1 + ", Instance: " + paramString2 + " not found in clickByClazzInstance"); return false; } } Log.e("AndroidUiTool", "Clazz: " + paramString1 + ", Instance: " + paramString2 + " not found in clickByClazzInstance"); return false; } @Description("Click the object by description") @MethodInfo("clickByDesc") public boolean clickByDesc(@ParamInfo(Descript="The compare mode, value: e - exact Match, p - partial match", Name="mode") String paramString1, @ParamInfo(Descript="The description to be found", Name="desc") String paramString2) { if (paramString1.equals("e")) {} for (this.obj = new UiObject(new UiSelector().description(paramString2)); this.obj.exists(); this.obj = new UiObject(new UiSelector().descriptionContains(paramString2))) { try { boolean bool = this.obj.click(); return bool; } catch (UiObjectNotFoundException paramString1) { Log.e("AndroidUiTool", "Description: " + paramString2 + ", not found in clickByDesc"); return false; } } Log.e("AndroidUiTool", "Description: " + paramString2 + ", not found in clickByDesc"); return false; } @Description("Click the object by desc instance") @MethodInfo("clickByDescInstance") public boolean clickByDescInstance(@ParamInfo(Descript="The compare mode, value: e - exact Match, p - partial match", Name="mode") String paramString1, @ParamInfo(Descript="The text to be found", Name="desc") String paramString2, @ParamInfo(Descript="The object instance id", Name="ins") String paramString3) { int i = Integer.parseInt(paramString3); if (paramString1.equals("e")) {} for (this.obj = new UiObject(new UiSelector().description(paramString2).instance(i)); this.obj.exists(); this.obj = new UiObject(new UiSelector().descriptionContains(paramString2).instance(i))) { try { boolean bool = this.obj.click(); return bool; } catch (UiObjectNotFoundException paramString1) { Log.e("AndroidUiTool", "Text: " + paramString2 + ", Instance: " + paramString3 + ", not found in clickByDescInstance"); return false; } } Log.e("AndroidUiTool", "Text: " + paramString2 + ", Instance: " + paramString3 + ", not found in clickByDescInstance"); return false; } @Description("Click the object by resourceId") @MethodInfo("clickById") public boolean clickById(@ParamInfo(Descript="The compare mode, value: e - exact Match, p - partial match", Name="mode") String paramString1, @ParamInfo(Descript="The resourceId to be found", Name="id") String paramString2) { if (paramString1.equals("e")) {} for (this.obj = new UiObject(new UiSelector().resourceId(paramString2)); this.obj.exists(); this.obj = new UiObject(new UiSelector().resourceIdMatches(paramString2))) { try { boolean bool = this.obj.click(); return bool; } catch (UiObjectNotFoundException paramString1) { Log.e("AndroidUiTool", "Resource Id" + paramString2 + ", not found in clickById"); return false; } } Log.e("AndroidUiTool", "Resource Id" + paramString2 + ", not found in clickById"); return false; } @Description("Click the object by resourceId instance") @MethodInfo("clickByIdInstance") public boolean clickByIdInstance(@ParamInfo(Descript="The compare mode, value: e - exact Match, p - partial match", Name="mode") String paramString1, @ParamInfo(Descript="The resourceId to be found", Name="id") String paramString2, @ParamInfo(Descript="The object instance id", Name="ins") String paramString3) { int i = Integer.parseInt(paramString3); if (paramString1.equals("e")) {} for (this.obj = new UiObject(new UiSelector().resourceId(paramString2).instance(i)); this.obj.exists(); this.obj = new UiObject(new UiSelector().resourceIdMatches(paramString2).instance(i))) { try { boolean bool = this.obj.click(); return bool; } catch (UiObjectNotFoundException paramString1) { Log.e("AndroidUiTool", "Resource Id: " + paramString2 + ", Instance: " + paramString3 + ", not found in clickByIdInstance"); return false; } } Log.e("AndroidUiTool", "Resource Id: " + paramString2 + ", Instance: " + paramString3 + ", not found in clickByIdInstance"); return false; } @Description("Click the partial match text in scroll UI") @MethodInfo("clickByPartialTextScroll") public boolean clickByPartialTextScroll(@ParamInfo(Descript="The scroll direction: v - Vertical h - Horizontal", Name="direction") String paramString1, @ParamInfo(Descript="The text to be found", Name="text") String paramString2) { UiScrollable localUiScrollable = new UiScrollable(new UiSelector().scrollable(true)); if (paramString1.equals("v")) { localUiScrollable.setAsVerticalList(); } try { for (;;) { this.obj = localUiScrollable.getChildByPartialText(new UiSelector().textContains(paramString2), paramString2, true); if (!this.obj.exists()) { break; } boolean bool = this.obj.click(); return bool; localUiScrollable.setAsHorizontalList(); } Log.e("AndroidUiTool", "Text: " + paramString2 + ", not found in clickByPartialTextScroll"); return false; } catch (UiObjectNotFoundException paramString1) { Log.e("AndroidUiTool", "Text: " + paramString2 + ", not found in clickByPartialTextScroll"); } return false; } @Description("Click the object by text") @MethodInfo("clickByText") public boolean clickByText(@ParamInfo(Descript="The compare mode, value: e - exact Match, p - partial match", Name="mode") String paramString1, @ParamInfo(Descript="The text to be found", Name="text") String paramString2) { if (paramString1.equals("e")) {} for (this.obj = new UiObject(new UiSelector().text(paramString2)); this.obj.exists(); this.obj = new UiObject(new UiSelector().textContains(paramString2))) { try { boolean bool = this.obj.click(); return bool; } catch (UiObjectNotFoundException paramString1) { Log.e("AndroidUiTool", "Text: " + paramString2 + ", not found in clickByText"); return false; } } Log.e("AndroidUiTool", "Text: " + paramString2 + ", not found in clickByText"); return false; } @Description("Click the object by text instance") @MethodInfo("clickByTextInstance") public boolean clickByTextInstance(@ParamInfo(Descript="The compare mode, value: e - exact Match, p - partial match", Name="mode") String paramString1, @ParamInfo(Descript="The text to be found", Name="text") String paramString2, @ParamInfo(Descript="The object instance id", Name="ins") String paramString3) { int i = Integer.parseInt(paramString3); if (paramString1.equals("e")) {} for (this.obj = new UiObject(new UiSelector().text(paramString2).instance(i)); this.obj.exists(); this.obj = new UiObject(new UiSelector().textContains(paramString2).instance(i))) { try { boolean bool = this.obj.click(); return bool; } catch (UiObjectNotFoundException paramString1) { Log.e("AndroidUiTool", "Text: " + paramString2 + ", Instance: " + paramString3 + ", not found in clickByTextInstance"); return false; } } Log.e("AndroidUiTool", "Text: " + paramString2 + ", Instance: " + paramString3 + ", not found in clickByTextInstance"); return false; } @Description("Click the text in scroll UI") @MethodInfo("clickByTextScroll") public boolean clickByTextScroll(@ParamInfo(Descript="The scroll direction: v - Vertical h - Horizontal", Name="direction") String paramString1, @ParamInfo(Descript="The text to be found", Name="text") String paramString2) { UiScrollable localUiScrollable = new UiScrollable(new UiSelector().scrollable(true)); if (paramString1.equals("v")) { localUiScrollable.setAsVerticalList(); } try { for (;;) { this.obj = localUiScrollable.getChildByText(new UiSelector().text(paramString2), paramString2, true); if (!this.obj.exists()) { break; } boolean bool = this.obj.click(); return bool; localUiScrollable.setAsHorizontalList(); } Log.e("AndroidUiTool", "Text: " + paramString2 + ", not found in clickByTextScroll"); return false; } catch (UiObjectNotFoundException paramString1) { Log.e("AndroidUiTool", "Text: " + paramString2 + ", not found in clickByTextScroll"); } return false; } @Description("Click the text in scroll UI for XUI") @MethodInfo("clickScroll") public boolean clickScroll(@ParamInfo(Descript="The compare mode, value: e - exact Match, p - partial match", Name="mode") String paramString1, @ParamInfo(Descript="The text to be found", Name="text") String paramString2, @ParamInfo(Descript="The max swipe steps", Name="step") String paramString3) { UiScrollable localUiScrollable = new UiScrollable(new UiSelector().scrollable(true)); if (!localUiScrollable.exists()) {} for (;;) { return false; localUiScrollable.setAsHorizontalList(); try { localUiScrollable.flingBackward(); localUiScrollable.flingBackward(); int i = 0; while (i < Integer.parseInt(paramString3)) { if (paramString1.equals("e")) { this.obj = new UiObject(new UiSelector().text(paramString2)); } this.obj = new UiObject(new UiSelector().textContains(paramString2)); if (this.obj.exists()) { return this.obj.click(); } localUiScrollable.flingForward(); i += 1; } if (paramString1.equals("e")) { this.obj = new UiObject(new UiSelector().text(paramString2)); } this.obj = new UiObject(new UiSelector().textContains(paramString2)); if (this.obj.exists()) { boolean bool = this.obj.click(); return bool; } } catch (UiObjectNotFoundException paramString1) { paramString1.printStackTrace(); } } return false; } @Description("Clik the text in scroll along the vertical direction in XUI") @MethodInfo("clickScrollAlongVertical") public boolean clickScrollAlongVertical(@ParamInfo(Descript="The compare mode,value:e - exact match,p - partial match", Name="mode") String paramString1, @ParamInfo(Descript="The text to be found", Name="text") String paramString2, @ParamInfo(Descript="The max swipe steps", Name="step") String paramString3) { UiScrollable localUiScrollable = new UiScrollable(new UiSelector().scrollable(true)); if (!localUiScrollable.exists()) {} for (;;) { return false; localUiScrollable.setAsVerticalList(); for (;;) { int i; try { localUiScrollable.flingBackward(); localUiScrollable.flingBackward(); i = 0; if (i >= Integer.parseInt(paramString3)) { break; } if (paramString1.equals("e")) { this.obj = new UiObject(new UiSelector().text(paramString2)); if (this.obj.exists()) { return this.obj.click(); } } else { this.obj = new UiObject(new UiSelector().textContains(paramString2)); continue; } localUiScrollable.flingForward(); } catch (UiObjectNotFoundException paramString1) { paramString1.printStackTrace(); return false; } i += 1; } if (paramString1.equals("e")) {} for (this.obj = new UiObject(new UiSelector().text(paramString2)); this.obj.exists(); this.obj = new UiObject(new UiSelector().textContains(paramString2))) { return this.obj.click(); } } } @Description("Compare two input picture, return true if similarity is up to 90%") @MethodInfo("comparePic") public double comparePic(@ParamInfo(Descript="Picture 1 to be compared", Name="pic_1") String paramString1, @ParamInfo(Descript="Picture 2 to be compared", Name="pic_2") String paramString2) { if (!new File(paramString1).isFile()) { System.out.println("Picture 1 not exist!"); return 0.0D; } if (!new File(paramString2).isFile()) { System.out.println("Picture 2 not exist!"); return 0.0D; } double d = PictureContrast.similarity(paramString1, paramString2); System.out.println("The similarity is: " + d + "%"); return d; } public void disconnect() { this.device.removeWatcher(this.watcherAll); if (this.automationWrapper != null) { this.automationWrapper.disconnect(); } } @Description("Performs a drag from one coordinate to another using the number of steps.") @MethodInfo("drag") public boolean drag(@ParamInfo(Descript="start x coordinate", Name="startX") int paramInt1, @ParamInfo(Descript="start y coordinate", Name="startY") int paramInt2, @ParamInfo(Descript="end x coordinate", Name="endX") int paramInt3, @ParamInfo(Descript="end y coordinate", Name="endY") int paramInt4, @ParamInfo(Descript="steps swipe", Name="steps") int paramInt5) { return this.device.drag(paramInt1, paramInt2, paramInt3, paramInt4, paramInt5); } @Description("Drag an UiObject identified by resourceId to another coordinate using the number of steps.") @MethodInfo("dragObjById") public boolean dragObjById(@ParamInfo(Descript="The compare mode, value: e - exact Match, p - partial match", Name="mode") String paramString1, @ParamInfo(Descript="The resourceId to be found", Name="id") String paramString2, @ParamInfo(Descript="end x coordinate", Name="endX") int paramInt1, @ParamInfo(Descript="end y coordinate", Name="endY") int paramInt2, @ParamInfo(Descript="steps swipe", Name="steps") int paramInt3) { if (paramString1.equals("e")) { this.obj = new UiObject(new UiSelector().resourceId(paramString2)); } this.obj = new UiObject(new UiSelector().resourceIdMatches(paramString2)); try { if (this.obj.exists()) { return this.obj.dragTo(paramInt1, paramInt2, paramInt3); } Log.e("AndroidUiTool", "Resource Id: " + paramString2 + ", not found in dragObjById"); return false; } catch (UiObjectNotFoundException paramString1) { Log.e("AndroidUiTool", "Resource Id: " + paramString2 + ", not found in dragObjById"); } return false; } @Description("Drag an UiObject identified by text to another coordinate using the number of steps.") @MethodInfo("dragObjByText") public boolean dragObjByText(@ParamInfo(Descript="The compare mode, value: e - exact Match, p - partial match", Name="mode") String paramString1, @ParamInfo(Descript="The text to be found", Name="text") String paramString2, @ParamInfo(Descript="end x coordinate", Name="endX") int paramInt1, @ParamInfo(Descript="end y coordinate", Name="endY") int paramInt2, @ParamInfo(Descript="steps swipe", Name="steps") int paramInt3) throws UiObjectNotFoundException { if (paramString1.equals("e")) { this.obj = new UiObject(new UiSelector().text(paramString2)); } try { while (this.obj.exists()) { boolean bool = this.obj.dragTo(paramInt1, paramInt2, paramInt3); return bool; this.obj = new UiObject(new UiSelector().textContains(paramString2)); } Log.e("AndroidUiTool", "Text: " + paramString2 + ", not found in dragObjById"); return false; } catch (UiObjectNotFoundException paramString1) { Log.e("AndroidUiTool", "Text: " + paramString2 + ", not found in dragObjById"); } return false; } @Description("Dump the ui xml") @MethodInfo("dump") public void dump() { this.device.dumpWindowHierarchy("ui.uix"); } @Description("fling to the dirction: left - right - up -down") @MethodInfo("fling") public boolean fling(@ParamInfo(Descript="The direction flying to: left - right - up -down", Name="direction") String paramString) { UiScrollable localUiScrollable = new UiScrollable(new UiSelector().scrollable(true)); try { if (paramString.equals("left")) { localUiScrollable.setAsHorizontalList(); return localUiScrollable.flingForward(); } if (paramString.equals("right")) { localUiScrollable.setAsHorizontalList(); return localUiScrollable.flingBackward(); } if (paramString.equals("up")) { localUiScrollable.setAsVerticalList(); return localUiScrollable.flingForward(); } localUiScrollable.setAsVerticalList(); boolean bool = localUiScrollable.flingBackward(); return bool; } catch (UiObjectNotFoundException paramString) { Log.e("AndroidUiTool", "UiScrollable not found in fling"); } return false; } @Description("Take screenshot for an item by resourceId") @MethodInfo("getCameraScaleById") public String getCameraScaleById(@ParamInfo(Descript="The resourceId to be found", Name="id") String paramString) { Object localObject = new UiObject(new UiSelector().resourceId(paramString)); try { localObject = ((UiObject)localObject).getBounds(); float f = ((Rect)localObject).width() / ((Rect)localObject).height(); if (new DecimalFormat("0.00").format(f).equals("0.75")) { return "4:3"; } return "16:9"; } catch (UiObjectNotFoundException localUiObjectNotFoundException) { Log.e("AndroidUiTool", "Resource id: " + paramString + ", not found in takeItemshotById"); } return "ObjNotFound"; } @Description("get target obj package name, identified by resource id") @MethodInfo("getPkgByClazz") public String getPkgByClazz(@ParamInfo(Descript="The UiObject class name", Name="clazz") String paramString) { this.obj = new UiObject(new UiSelector().className(paramString)); try { String str = this.obj.getPackageName(); return str; } catch (UiObjectNotFoundException localUiObjectNotFoundException) { Log.e("AndroidUiTool", "Clazz: " + paramString + ", not found in getPkgByClazz"); } return "ObjNotFound"; } @Description("get target obj package name, identified by resource id") @MethodInfo("getPkgById") public String getPkgById(@ParamInfo(Descript="The UiObject resourceId", Name="id") String paramString) { this.obj = new UiObject(new UiSelector().resourceId(paramString)); try { String str = this.obj.getPackageName(); return str; } catch (UiObjectNotFoundException localUiObjectNotFoundException) { Log.e("AndroidUiTool", "Resource id: " + paramString + ", not found in getPkgById"); } return "ObjNotFound"; } @Description("get the device current rotation state") @MethodInfo("getRotation") public int getRotation() throws RemoteException { return this.device.getDisplayRotation(); } @Description("get target obj text value, identified by resource id") @MethodInfo("getTextById") public String getTextById(@ParamInfo(Descript="The UiObject resourceId", Name="id") String paramString) { this.obj = new UiObject(new UiSelector().resourceId(paramString)); try { String str = this.obj.getText(); return str; } catch (UiObjectNotFoundException localUiObjectNotFoundException) { Log.e("AndroidUiTool", "Resource id: " + paramString + ", not found in getTextById"); } return "ObjNotFound"; } @Description("get target obj text value, identified by resource id instance") @MethodInfo("getTextByIdInstance") public String getTextByIdInstance(@ParamInfo(Descript="The UiObject resourceId", Name="id") String paramString1, @ParamInfo(Descript="The object instance id", Name="ins") String paramString2) { this.obj = new UiObject(new UiSelector().resourceId(paramString1).instance(Integer.parseInt(paramString2))); try { paramString2 = this.obj.getText(); return paramString2; } catch (UiObjectNotFoundException paramString2) { Log.e("AndroidUiTool", "Resource id: " + paramString1 + ", not found in getTextByIdInstance"); } return "ObjNotFound"; } @Description("get the full text by partial text in scroll") @MethodInfo("getTextByPartialTextScroll") public String getTextByPartialTextScroll(@ParamInfo(Descript="The scroll direction: v - Vertical h - Horizontal", Name="direction") String paramString1, @ParamInfo(Descript="The text to be found", Name="text") String paramString2) throws UiObjectNotFoundException { UiScrollable localUiScrollable = new UiScrollable(new UiSelector().scrollable(true)); if (paramString1.equals("v")) { localUiScrollable.setAsVerticalList(); } for (;;) { try { this.obj = localUiScrollable.getChildByPartialText(new UiSelector().textContains(paramString2), paramString2, true); paramString1 = this.obj.getText(); return paramString1; } catch (UiObjectNotFoundException paramString1) { Log.e("AndroidUiTool", "Text: " + paramString2 + ", not found in getTextByPartialTextScroll"); throw paramString1; } localUiScrollable.setAsHorizontalList(); } } @Description("get device screen width and height") @MethodInfo("getWH") public String getWH() throws UiObjectNotFoundException { int i = this.device.getDisplayWidth(); int j = this.device.getDisplayHeight(); return "Device width is: " + String.valueOf(i) + " height is: " + String.valueOf(j); } @Description("Check Uiobject contains given description is checked or not") @MethodInfo("isCheckedByDesc") public boolean isCheckedByDesc(@ParamInfo(Descript="The compare mode, value: e - exact Match, p - partial match", Name="mode") String paramString1, @ParamInfo(Descript="The description to be found", Name="desc") String paramString2) { if (paramString1.equals("e")) {} for (this.obj = new UiObject(new UiSelector().description(paramString2));; this.obj = new UiObject(new UiSelector().descriptionContains(paramString2))) { try { boolean bool = this.obj.isChecked(); return bool; } catch (UiObjectNotFoundException paramString1) { Log.e("AndroidUiTool", "Description: " + paramString2 + ", not found in isCheckedByDesc"); } } return false; } @Description("Check Uiobject contains given resourceId is Checked or not") @MethodInfo("isCheckedById") public boolean isCheckedById(@ParamInfo(Descript="The compare mode, value: e - exact Match, p - partial match", Name="mode") String paramString1, @ParamInfo(Descript="The resourceId to be found", Name="id") String paramString2) { if (paramString1.equals("e")) {} for (this.obj = new UiObject(new UiSelector().resourceId(paramString2));; this.obj = new UiObject(new UiSelector().resourceIdMatches(paramString2))) { try { boolean bool = this.obj.isChecked(); return bool; } catch (UiObjectNotFoundException paramString1) { Log.e("AndroidUiTool", "Resource Id: " + paramString2 + ", not found in isCheckedById"); } } return false; } @Description("Check Uiobject contains given text is checked or not") @MethodInfo("isCheckedByText") public boolean isCheckedByText(@ParamInfo(Descript="The compare mode, value: e - exact Match, p - partial match", Name="mode") String paramString1, @ParamInfo(Descript="The text to be found", Name="text") String paramString2) { if (paramString1.equals("e")) {} for (this.obj = new UiObject(new UiSelector().text(paramString2));; this.obj = new UiObject(new UiSelector().textContains(paramString2))) { try { boolean bool = this.obj.isChecked(); return bool; } catch (UiObjectNotFoundException paramString1) { Log.e("AndroidUiTool", "Text: " + paramString2 + ", not found in isCheckedByText"); } } return false; } @Description("Check Uiobject contains given description exist or not") @MethodInfo("isEnabledByDesc") public boolean isEnabledByDesc(@ParamInfo(Descript="The compare mode, value: e - exact Match, p - partial match", Name="mode") String paramString1, @ParamInfo(Descript="The description to be found", Name="desc") String paramString2) { if (paramString1.equals("e")) {} for (this.obj = new UiObject(new UiSelector().description(paramString2));; this.obj = new UiObject(new UiSelector().descriptionContains(paramString2))) { try { boolean bool = this.obj.isEnabled(); return bool; } catch (UiObjectNotFoundException paramString1) { Log.e("AndroidUiTool", "Description: " + paramString2 + ", not found in isEnabledById"); } } return false; } @Description("Check Uiobject contains given resourceId exist or not") @MethodInfo("isEnabledById") public boolean isEnabledById(@ParamInfo(Descript="The compare mode, value: e - exact Match, p - partial match", Name="mode") String paramString1, @ParamInfo(Descript="The resourceId to be found", Name="id") String paramString2) { if (paramString1.equals("e")) {} for (this.obj = new UiObject(new UiSelector().resourceId(paramString2));; this.obj = new UiObject(new UiSelector().resourceIdMatches(paramString2))) { try { boolean bool = this.obj.isEnabled(); return bool; } catch (UiObjectNotFoundException paramString1) { Log.e("AndroidUiTool", "Resource Id: " + paramString2 + ", not found in isEnabledById"); } } return false; } @Description("Check Uiobject contains given text exist or not") @MethodInfo("isEnabledByText") public boolean isEnabledByText(@ParamInfo(Descript="The compare mode, value: e - exact Match, p - partial match", Name="mode") String paramString1, @ParamInfo(Descript="The text to be found", Name="text") String paramString2) { if (paramString1.equals("e")) {} for (this.obj = new UiObject(new UiSelector().text(paramString2));; this.obj = new UiObject(new UiSelector().textContains(paramString2))) { try { boolean bool = this.obj.isEnabled(); return bool; } catch (UiObjectNotFoundException paramString1) { Log.e("AndroidUiTool", "Text: " + paramString2 + ", not found in isEnabledByText"); } } return false; } @Description("Check Uiobject by class name exist or not") @MethodInfo("isExistByClazz") public boolean isExistByClazz(@ParamInfo(Descript="The compare mode, value: e - exact Match, p - partial match", Name="mode") String paramString1, @ParamInfo(Descript="The class name to be found", Name="clazz") String paramString2) { if (paramString1.equals("e")) {} for (this.obj = new UiObject(new UiSelector().className(paramString2)); !this.obj.exists(); this.obj = new UiObject(new UiSelector().classNameMatches(paramString2))) { this.device.removeWatcher(this.watcherAll); return false; } return true; } @Description("Check Uiobject contains given description exist or not") @MethodInfo("isExistByDesc") public boolean isExistByDesc(@ParamInfo(Descript="The compare mode, value: e - exact Match, p - partial match", Name="mode") String paramString1, @ParamInfo(Descript="The description to be found", Name="desc") String paramString2) { if (paramString1.equals("e")) {} for (this.obj = new UiObject(new UiSelector().description(paramString2)); !this.obj.exists(); this.obj = new UiObject(new UiSelector().descriptionContains(paramString2))) { this.device.removeWatcher(this.watcherAll); return false; } return true; } @Description("Check Uiobject contains given resourceId exist or not") @MethodInfo("isExistById") public boolean isExistById(@ParamInfo(Descript="The compare mode, value: e - exact Match, p - partial match", Name="mode") String paramString1, @ParamInfo(Descript="The resourceId to be found", Name="id") String paramString2) { if (paramString1.equals("e")) {} for (this.obj = new UiObject(new UiSelector().resourceId(paramString2)); !this.obj.exists(); this.obj = new UiObject(new UiSelector().resourceIdMatches(paramString2))) { this.device.removeWatcher(this.watcherAll); return false; } return true; } @Description("Check Uiobject contains given description exist or not") @MethodInfo("isExistByPkg") public boolean isExistByPkg(@ParamInfo(Descript="The package to be found", Name="pkg") String paramString) { this.obj = new UiObject(new UiSelector().packageName(paramString)); if (!this.obj.exists()) { this.device.removeWatcher(this.watcherAll); return false; } return true; } @Description("Check Uiobject contains given text exist or not") @MethodInfo("isExistByText") public boolean isExistByText(@ParamInfo(Descript="The compare mode, value: e - exact Match, p - partial match", Name="mode") String paramString1, @ParamInfo(Descript="The text to be found", Name="text") String paramString2) { if (paramString1.equals("e")) {} for (this.obj = new UiObject(new UiSelector().text(paramString2)); !this.obj.exists(); this.obj = new UiObject(new UiSelector().textContains(paramString2))) { this.device.removeWatcher(this.watcherAll); return false; } return true; } @Description("Check Uiobject contains given text exist or not in scroll") @MethodInfo("isExistByTextScroll") public boolean isExistByTextScroll(@ParamInfo(Descript="The scroll direction: v - Vertical h - Horizontal", Name="direction") String paramString1, @ParamInfo(Descript="The text to be found", Name="text") String paramString2) { UiScrollable localUiScrollable = new UiScrollable(new UiSelector().scrollable(true)); if (paramString1.equals("v")) { localUiScrollable.setAsVerticalList(); } for (;;) { try { this.obj = localUiScrollable.getChildByText(new UiSelector().text(paramString2), paramString2, true); boolean bool = this.obj.exists(); return bool; } catch (UiObjectNotFoundException paramString1) { paramString1.printStackTrace(); Log.e("AndroidUiTool", "Text: " + paramString2 + ", not found in isExistByTextScroll"); } localUiScrollable.setAsHorizontalList(); } return false; } @Description("Check the text exist or not in scroll UI for XUI") @MethodInfo("isExistScroll") public boolean isExistScroll(@ParamInfo(Descript="The compare mode, value: e - exact Match, p - partial match", Name="mode") String paramString1, @ParamInfo(Descript="The text to be found", Name="text") String paramString2, @ParamInfo(Descript="The max swipe steps", Name="step") String paramString3) { UiScrollable localUiScrollable = new UiScrollable(new UiSelector().scrollable(true)); if (!localUiScrollable.exists()) {} for (;;) { return false; localUiScrollable.setAsHorizontalList(); try { localUiScrollable.flingBackward(); localUiScrollable.flingBackward(); int i = 0; while (i < Integer.parseInt(paramString3)) { if (paramString1.equals("e")) { this.obj = new UiObject(new UiSelector().text(paramString2)); } this.obj = new UiObject(new UiSelector().textContains(paramString2)); if (this.obj.exists()) { return true; } localUiScrollable.flingForward(); i += 1; } if (paramString1.equals("e")) { this.obj = new UiObject(new UiSelector().text(paramString2)); } this.obj = new UiObject(new UiSelector().textContains(paramString2)); boolean bool = this.obj.exists(); if (bool) { return true; } } catch (UiObjectNotFoundException paramString1) { paramString1.printStackTrace(); } } return false; } @Description("Check the url is reachable") @MethodInfo("isReachable") public boolean isReachable(@ParamInfo(Descript="Url to be checked,like: http://www.baidu.com", Name="url") String paramString) { try { paramString = (HttpURLConnection)new URL(paramString).openConnection(); paramString.setConnectTimeout(5000); paramString.setReadTimeout(30000); paramString.getContent(); return true; } catch (UnknownHostException paramString) { System.out.println("UnknownHostException in isReachable"); return false; } catch (IOException paramString) { System.out.println("IOException in isReachable"); } return false; } @Description("Return if isScreenOn") @MethodInfo("isScreenOn") public boolean isScreenOn() throws RemoteException { return this.device.isScreenOn(); } @Description("Check Uiobject contains given description is selected or not") @MethodInfo("isSelectedByDesc") public boolean isSelectedByDesc(@ParamInfo(Descript="The compare mode, value: e - exact Match, p - partial match", Name="mode") String paramString1, @ParamInfo(Descript="The description to be found", Name="desc") String paramString2) { if (paramString1.equals("e")) {} for (this.obj = new UiObject(new UiSelector().description(paramString2));; this.obj = new UiObject(new UiSelector().descriptionContains(paramString2))) { try { boolean bool = this.obj.isSelected(); return bool; } catch (UiObjectNotFoundException paramString1) { Log.e("AndroidUiTool", "Description: " + paramString2 + ", not found in isSelectedByDesc"); } } return false; } @Description("Check Uiobject contains given resourceId is selected or not") @MethodInfo("isSelectedById") public boolean isSelectedById(@ParamInfo(Descript="The compare mode, value: e - exact Match, p - partial match", Name="mode") String paramString1, @ParamInfo(Descript="The resourceId to be found", Name="id") String paramString2) { if (paramString1.equals("e")) {} for (this.obj = new UiObject(new UiSelector().resourceId(paramString2));; this.obj = new UiObject(new UiSelector().resourceIdMatches(paramString2))) { try { boolean bool = this.obj.isSelected(); return bool; } catch (UiObjectNotFoundException paramString1) { Log.e("AndroidUiTool", "Resource Id: " + paramString2 + ", not found in isSelectedById"); } } return false; } @Description("Check Uiobject contains given text is selected or not") @MethodInfo("isSelectedByText") public boolean isSelectedByText(@ParamInfo(Descript="The compare mode, value: e - exact Match, p - partial match", Name="mode") String paramString1, @ParamInfo(Descript="The text to be found", Name="text") String paramString2) { if (paramString1.equals("e")) {} for (this.obj = new UiObject(new UiSelector().text(paramString2));; this.obj = new UiObject(new UiSelector().textContains(paramString2))) { try { boolean bool = this.obj.isSelected(); return bool; } catch (UiObjectNotFoundException paramString1) { Log.e("AndroidUiTool", "Text: " + paramString2 + ", not found in isSelectedByText"); } } return false; } @Description("Perform a long click at arbitrary coordinates specified by the user") @MethodInfo("longClick") public boolean longClick(@ParamInfo(Descript="x coordinate", Name="x") int paramInt1, @ParamInfo(Descript="y coordinate", Name="y") int paramInt2, @ParamInfo(Descript="Long click time, in milliseconds", Name="time") long paramLong) { return this.device.longClick(paramInt1, paramInt2, paramLong); } @Description("Long lick the object by resourceId") @MethodInfo("longClickById") public boolean longClickById(@ParamInfo(Descript="The compare mode, value: e - exact Match, p - partial match", Name="mode") String paramString1, @ParamInfo(Descript="Long click time, in milliseconds", Name="time") long paramLong, @ParamInfo(Descript="The resourceId to be found", Name="id") String paramString2) { if (paramString1.equals("e")) {} for (this.obj = new UiObject(new UiSelector().resourceId(paramString2));; this.obj = new UiObject(new UiSelector().resourceIdMatches(paramString2))) { try { boolean bool = this.obj.longClick(paramLong); return bool; } catch (UiObjectNotFoundException paramString1) { Log.e("AndroidUiTool", "Resource Id: " + paramString2 + ", not found in longClickById"); } } return false; } @Description("Long click the object by text") @MethodInfo("longClickByText") public boolean longClickByText(@ParamInfo(Descript="The compare mode, value: e - exact Match, p - partial match", Name="mode") String paramString1, @ParamInfo(Descript="Long click time, in milliseconds", Name="time") long paramLong, @ParamInfo(Descript="The text to be found", Name="text") String paramString2) { if (paramString1.equals("e")) { this.obj = new UiObject(new UiSelector().text(paramString2)); } this.obj = new UiObject(new UiSelector().textContains(paramString2)); try { boolean bool = this.obj.longClick(paramLong); return bool; } catch (UiObjectNotFoundException paramString1) { Log.e("AndroidUiTool", "Text: " + paramString2 + ", not found in longClickByText"); } return false; } @Description("Perform a click at arbitrary coordinates specified by the user") @MethodInfo("multiFastClick") public void multiFastClick(@ParamInfo(Descript="perform how many click", Name="num") int paramInt1, @ParamInfo(Descript="x coordinate", Name="x") int paramInt2, @ParamInfo(Descript="y coordinate", Name="y") int paramInt3) { long l = Configurator.getInstance().getActionAcknowledgmentTimeout(); Configurator.getInstance().setActionAcknowledgmentTimeout(0L); int i = 0; while (i < paramInt1) { this.device.click(paramInt2, paramInt3); i += 1; } Configurator.getInstance().setActionAcknowledgmentTimeout(l); } @Description("swipe object identified by resource id to the dirction: left - right - up -down") @MethodInfo("objSwipeById") public boolean objSwipeById(@ParamInfo(Descript="The compare mode, value: e - exact Match, p - partial match", Name="mode") String paramString1, @ParamInfo(Descript="The resourceId to be found", Name="id") String paramString2, @ParamInfo(Descript="The direction flying to: left - right - up -down", Name="direction") String paramString3) { if (paramString1.equals("e")) {} for (this.obj = new UiObject(new UiSelector().resourceId(paramString2)); !this.obj.exists(); this.obj = new UiObject(new UiSelector().resourceIdMatches(paramString2))) { Log.e("AndroidUiTool", "Resource Id: " + paramString2 + ", not found in objSwipeById"); return false; } try { if (paramString3.equals("left")) { return this.obj.swipeLeft(50); } if (paramString3.equals("right")) { return this.obj.swipeRight(50); } if (paramString3.equals("up")) { return this.obj.swipeUp(50); } boolean bool = this.obj.swipeDown(50); return bool; } catch (UiObjectNotFoundException paramString1) { Log.e("AndroidUiTool", "Resource Id: " + paramString2 + ", not found in objSwipeById"); } return false; } @Description("Opens the notification shade, return true if successful, else return false") @MethodInfo("openNotification") public boolean openNotification() { return this.device.openNotification(); } @Description("Simulate press Back button") @MethodInfo("pressBack") public boolean pressBack() { return this.device.pressBack(); } @Description("Simulate press Enter button") @MethodInfo("pressEnter") public boolean pressEnter() { return this.device.pressEnter(); } @Description("Simulate press Home button") @MethodInfo("pressHome") public boolean pressHome() { return this.device.pressHome(); } @Description("Simulate press Menu button") @MethodInfo("pressMenu") public boolean pressMenu() { return this.device.pressMenu(); } @Description("Simulate press Menu button") @MethodInfo("pressRecentApps") public boolean pressRecentApps() throws RemoteException { return this.device.pressRecentApps(); } @Description("Simulates orienting the device to the left.") @MethodInfo("setOrientationLeft") public void setOrientationLeft() throws RemoteException { this.device.setOrientationLeft(); } @Description("Simulates orienting the device into its natural orientation.") @MethodInfo("setOrientationNatural") public void setOrientationNatural() throws RemoteException { this.device.setOrientationNatural(); } @Description("Simulates orienting the device to the right.") @MethodInfo("setOrientationRight") public void setOrientationRight() throws RemoteException { this.device.setOrientationRight(); } @Description("Set value to the UiObject identified by resourceId") @MethodInfo("setValueById") public boolean setValueById(@ParamInfo(Descript="The compare mode, value: e - exact Match, p - partial match", Name="mode") String paramString1, @ParamInfo(Descript="The UiObject resourceId", Name="id") String paramString2, @ParamInfo(Descript="The value to be set", Name="value") String paramString3) { Configurator localConfigurator = Configurator.getInstance(); localConfigurator.setKeyInjectionDelay(100L); if (paramString1.equals("e")) { this.obj = new UiObject(new UiSelector().resourceId(paramString2)); } try { for (;;) { this.obj.exists(); this.device.removeWatcher(this.watcherAll); if (!this.obj.exists()) { break; } this.rlt = this.obj.setText(paramString3); localConfigurator.setKeyInjectionDelay(0L); boolean bool = this.rlt; return bool; this.obj = new UiObject(new UiSelector().resourceIdMatches(paramString2)); } Log.e("AndroidUiTool", "Resource Id: " + paramString2 + ", not found in setValueById"); localConfigurator.setKeyInjectionDelay(0L); return false; } catch (UiObjectNotFoundException paramString1) { Log.e("AndroidUiTool", "Resource Id: " + paramString2 + ", not found in setValueById"); localConfigurator.setKeyInjectionDelay(0L); } return false; } @Description("Set value to the UiObject identified by text") @MethodInfo("setValueByText") public boolean setValueByText(@ParamInfo(Descript="The compare mode, value: e - exact Match, p - partial match", Name="mode") String paramString1, @ParamInfo(Descript="The UiObject resourceId", Name="text") String paramString2, @ParamInfo(Descript="The value to be set", Name="value") String paramString3) throws UiObjectNotFoundException { Configurator localConfigurator = Configurator.getInstance(); localConfigurator.setKeyInjectionDelay(100L); if (paramString1.equals("e")) { this.obj = new UiObject(new UiSelector().text(paramString2)); } try { for (;;) { this.obj.exists(); this.device.removeWatcher(this.watcherAll); if (!this.obj.exists()) { break; } this.rlt = this.obj.setText(paramString3); localConfigurator.setKeyInjectionDelay(0L); boolean bool = this.rlt; return bool; this.obj = new UiObject(new UiSelector().textContains(paramString2)); } Log.e("AndroidUiTool", "Text: " + paramString2 + ", not found in setValueByText"); localConfigurator.setKeyInjectionDelay(0L); return false; } catch (UiObjectNotFoundException paramString1) { Log.e("AndroidUiTool", "Text: " + paramString2 + ", not found in setValueByText"); localConfigurator.setKeyInjectionDelay(0L); } return false; } @Description("Set value to the UiObject identified by text") @MethodInfo("setValueByTextInstance") public boolean setValueByTextInstance(@ParamInfo(Descript="The compare mode, value: e - exact Match, p - partial match", Name="mode") String paramString1, @ParamInfo(Descript="The UiObject resourceId", Name="text") String paramString2, @ParamInfo(Descript="The object instance id", Name="ins") String paramString3, @ParamInfo(Descript="The value to be set", Name="value") String paramString4) throws UiObjectNotFoundException { Configurator localConfigurator = Configurator.getInstance(); localConfigurator.setKeyInjectionDelay(100L); if (paramString1.equals("e")) { this.obj = new UiObject(new UiSelector().text(paramString2).instance(Integer.parseInt(paramString3))); } try { for (;;) { this.obj.exists(); this.device.removeWatcher(this.watcherAll); if (!this.obj.exists()) { break; } this.rlt = this.obj.setText(paramString4); localConfigurator.setKeyInjectionDelay(0L); boolean bool = this.rlt; return bool; this.obj = new UiObject(new UiSelector().textContains(paramString2).instance(Integer.parseInt(paramString3))); } Log.e("AndroidUiTool", "Text: " + paramString2 + ", not found in setValueByText"); localConfigurator.setKeyInjectionDelay(0L); return false; } catch (UiObjectNotFoundException paramString1) { Log.e("AndroidUiTool", "Text: " + paramString2 + ", not found in setValueByText"); localConfigurator.setKeyInjectionDelay(0L); } return false; } @Description("Simulate sleep devices") @MethodInfo("sleep") public void sleep() throws RemoteException { this.device.sleep(); } @Description("Performs a swipe from one coordinate to another using the number of steps.") @MethodInfo("swipe") public boolean swipe(@ParamInfo(Descript="start x coordinate", Name="startX") int paramInt1, @ParamInfo(Descript="start y coordinate", Name="startY") int paramInt2, @ParamInfo(Descript="end x coordinate", Name="endX") int paramInt3, @ParamInfo(Descript="end y coordinate", Name="endY") int paramInt4, @ParamInfo(Descript="steps swipe", Name="steps") int paramInt5) { return this.device.swipe(paramInt1, paramInt2, paramInt3, paramInt4, paramInt5); } @Description("Performs a swipe between points in the Point array.") @MethodInfo("swipeX") public boolean swipeX(@ParamInfo(Descript="swipe point array, x1-y1-x2-y2-x3-y3...", Name="points") String paramString, @ParamInfo(Descript="steps swipe", Name="steps") int paramInt) { paramString = paramString.split("-"); Point[] arrayOfPoint = new Point[paramString.length / 2]; int i = 0; while (i < arrayOfPoint.length) { arrayOfPoint[i] = new Point(); arrayOfPoint[i].x = Integer.valueOf(paramString[(i * 2)]).intValue(); arrayOfPoint[i].y = Integer.valueOf(paramString[(i * 2 + 1)]).intValue(); i += 1; } return this.device.swipe(arrayOfPoint, paramInt); } @Description("Take screenshot for an item by description") @MethodInfo("takeItemshotByDesc") public void takeItemshotByDesc(@ParamInfo(Descript="The description to be found", Name="desc") String paramString1, @ParamInfo(Descript="Screenshot file full path", Name="path") String paramString2) { this.obj = new UiObject(new UiSelector().description(paramString1)); try { Rect localRect = this.obj.getBounds(); File localFile = new File("/data/local/tmp/bitmapTemp.png"); this.device.takeScreenshot(localFile); PictureContrast.cutBitmap(localRect, paramString2); return; } catch (UiObjectNotFoundException paramString2) { Log.e("AndroidUiTool", "Description: " + paramString1 + ", not found in takeItemshotByDesc"); } } @Description("Take screenshot for an item by resourceId") @MethodInfo("takeItemshotById") public void takeItemshotById(@ParamInfo(Descript="The resourceId to be found", Name="id") String paramString1, @ParamInfo(Descript="Screenshot file full path", Name="path") String paramString2) { Object localObject = new UiObject(new UiSelector().resourceId(paramString1)); try { localObject = ((UiObject)localObject).getBounds(); File localFile = new File("/data/local/tmp/bitmapTemp.png"); this.device.takeScreenshot(localFile); PictureContrast.cutBitmap((Rect)localObject, paramString2); return; } catch (UiObjectNotFoundException paramString2) { Log.e("AndroidUiTool", "Resource id: " + paramString1 + ", not found in takeItemshotById"); } } @Description("Take screenshot for an item by Text") @MethodInfo("takeItemshotByText") public void takeItemshotByText(@ParamInfo(Descript="The compare mode, value: e - exact Match, p - partial match", Name="mode") String paramString1, @ParamInfo(Descript="The text to be found", Name="text") String paramString2, @ParamInfo(Descript="Screenshot file full path", Name="path") String paramString3) { if (paramString1.equals("e")) {} for (paramString1 = new UiObject(new UiSelector().text(paramString2));; paramString1 = new UiObject(new UiSelector().textContains(paramString2))) { try { paramString1 = paramString1.getBounds(); File localFile = new File("/data/local/tmp/bitmapTemp.png"); this.device.takeScreenshot(localFile); PictureContrast.cutBitmap(paramString1, paramString3); return; } catch (UiObjectNotFoundException paramString1) { Log.e("AndroidUiTool", "Text: " + paramString2 + ", not found in takeItemshotByText"); } } } @Description("Take a screenshot") @MethodInfo("takeScreenshot") public boolean takeScreenshot(@ParamInfo(Descript="Screenshot file full path", Name="path") String paramString) { paramString = new File(paramString); return this.device.takeScreenshot(paramString); } @Description("Simulate press wakeUp button") @MethodInfo("wakeUp") public void wakeUp() throws RemoteException { this.device.wakeUp(); } private class MyWatcher implements UiWatcher { private MyWatcher() {} public boolean checkForCondition() { System.out.println("In watcher now"); UiObject localUiObject = new UiObject(new UiSelector().text("Cancel")); if (new UiObject(new UiSelector().text("Turn on Super standby")).exists()) {} try { localUiObject.click(); return true; } catch (UiObjectNotFoundException localUiObjectNotFoundException) { Log.e("AndroidUiTool", "Not found Cancel in watcher for lowBattery_qiku"); } return false; } }}
阅读全文
0 0
- AndroidUiTool.jar中UiTool包源码
- Eclipse中查看jar包中的源码
- Eclipse中查看jar包中的源码
- Eclipse中查看jar包中的源码
- Eclipse中查看jar包中的源码
- Eclipse中导入jar包源码
- Eclipse中查看jar包中的源码
- Eclipse中查看jar包中的源码
- Eclipse中查看jar包中的源码
- Eclipse中查看jar包中的源码
- Eclipse中查看jar包中的源码
- eclipse中导入jar包的源码
- Eclipse中查看jar包中的源码
- eclipse中导入jar包的源码
- myeclipse 中查看jar包的源码
- eclipse中如何导入jar包源码
- Eclipse中查看jar包中的源码
- eclipse中导入jar包的源码
- 理解高并发(5).synchronized原理及用法
- JZOJ2017.07.08 C组
- ipython notebook 如何打开.ipynb文件?
- LeetCode Two sum c++
- 八大排序算法之选择排序
- AndroidUiTool.jar中UiTool包源码
- scikit-learn 实战之监督学习 1
- 为什么在cuda中调用__syncthreads()显示未定义标识符
- 理解高并发(6).jvm对内置锁的优化
- Linux常用命令
- scikit-learn 实战之监督学习 2
- 使用python爬取网页发送到邮箱
- jmap 查看内存使用直方图
- 理解高并发(7).编程过程中锁的优化技巧