Package totalcross.unit
Class UIRobot
- java.lang.Object
-
- totalcross.unit.UIRobot
-
public class UIRobot extends java.lang.ObjectThis class permits the control of the User Interface, playing back events recorded by the user. The robot is comprised of some dialogs that are invoked using a special key defined by the application. The special key running in Java SE (eclipse, netbeans) is control+1. The code below defines the Find special key to be used at the device (you can choose any special key you want):Vm.interceptSpecialKeys(new int[]{SpecialKeys.FIND}); Settings.deviceRobotSpecialKey = SpecialKeys.FIND;You should set it at the application's constructor. When this key is pressed, it opens a window with three options: record, playback and cancel. Clicking on the "record" button opens another window asking for the robot's name. Type the name and press "Start record" to start recording. Do the events smoothly and slowly. When done, press the special key again. Clicking in the playback button opens a screen with a list of recorded robots. After selecting the robots, press one of these buttons:- Play selected: plays the robots in the same order you selected (the order is recorded as you select).
- Play all: plays all robots in the list, in the order they appear.
- Play random: randomizes the selected robots order and reproduce that. A new window is opened asking you to enter the number of times that exact sequence will be run.
- Dump contents: dumps the contents of the selected robots, so you can see the events that are played back.
- Delete selected: delete the selected robots.
- Android: adb shell am start -a android.intent.action.MAIN -n totalcross.app.uigadgets/.UIGadgets -e cmdline test1.robot
- Windows 32: UIGadgets.exe /cmdline test1.robot
- J2SE: /cmdline flick.robot tc.samples.ui.gadgets.UIGadgets
if (event.type == UIRobotEvent.ROBOT_FAILED || event.type == UIRobotEvent.ROBOT_SUCCEED) { try { File f = new File(Settings.appPath+"/robot.log",File.CREATE_EMPTY); String s = event.type == UIRobotEvent.ROBOT_FAILED ? "FAILED" : "SUCCEED"; f.writeBytes("Robot "+UIRobot.robotFileName+" "+s+". Running time: "+UIRobot.totalTime); f.close(); } catch (Exception e) {e.printStackTrace();} }- See Also:
SpecialKeys,UIRobotEvent
-
-
Field Summary
Fields Modifier and Type Field Description static booleanabortSet to true to abort the run of the current UIRobot.static intIDLEstatic intPLAYBACKstatic intRECORDINGstatic java.lang.StringrobotFileNameThe filename of the running robot.static intstatusstatic inttotalTimeThe amount of time since the robot started.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddUIRobotListener(UIRobotListener listener)Adds a listener for UIRobot events.voidonEvent(int type, int key, int x, int y, int modifiers)voidremoveUIRobotListener(UIRobotListener listener)Removes a listener for UIRobot events.voidstop()
-
-
-
Field Detail
-
IDLE
public static final int IDLE
- See Also:
- Constant Field Values
-
RECORDING
public static final int RECORDING
- See Also:
- Constant Field Values
-
PLAYBACK
public static final int PLAYBACK
- See Also:
- Constant Field Values
-
status
public static int status
-
abort
public static boolean abort
Set to true to abort the run of the current UIRobot. Useful if you set a breakpoint at a code and want to abort the run. You can also abort the UIRobot by pressing the shift key during execution and at the starting message box.
-
robotFileName
public static java.lang.String robotFileName
The filename of the running robot.
-
totalTime
public static int totalTime
The amount of time since the robot started.
-
-
Constructor Detail
-
UIRobot
public UIRobot() throws java.lang.ExceptionConstructs a new UIRobot and opens the user interface.- Throws:
java.lang.Exception
-
UIRobot
public UIRobot(java.lang.String robotFileName) throws java.lang.ExceptionConstructs a new UIRobot and starts the playback of the given file.- Throws:
java.lang.Exception
-
-
Method Detail
-
onEvent
public void onEvent(int type, int key, int x, int y, int modifiers)
-
stop
public void stop() throws java.lang.Exception- Throws:
java.lang.Exception
-
addUIRobotListener
public void addUIRobotListener(UIRobotListener listener)
Adds a listener for UIRobot events.- See Also:
UIRobotListener
-
removeUIRobotListener
public void removeUIRobotListener(UIRobotListener listener)
Removes a listener for UIRobot events.- See Also:
UIRobotListener
-
-