⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 automatedeventhandler.java

📁 用于移动设备上的java虚拟机源代码
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
		    break;		default : 		    // unknown error.		    playbackDone = true;		}	    } 	    synchronized (thisReference) {		thisReference.notify();	    }	}	    }    /**     * Replay a given event sequence. This will replay a sequence of     * events represented in the given EventSequence object. It will     * then capture the contents of the screen at the end of the event     * sequence and compare it to the screen capture that is included     * in the EventSequence object.     *     * @param sequence The EventSequence object to replay and test     * @param speed The factor by which to modify the replay speed of     *              the event sequence. This is on a scale of 100,     *              meaning a value of 100 would be normal speed,     *              50 would be half speed, and 200 would be double     *              speed.     *     * @return True if the screen capture at the end of replaying     *         the given event sequence matches that which is stored     *         in the given EventSequence object.     */    public boolean replayEventSequence(EventSequence sequence,                                                int speed) {	// NOTE: Do we check if an event sequence is currently being recorded/	// replayed, before starting replay?	sequence.initializeReplay();	EventPlaybackThread eventPlaybackThread 	    = new EventPlaybackThread(sequence, speed);	eventPlaybackThread.start();	// hang around until replay is finished.	synchronized (thisReference) {            try {		thisReference.wait();            } catch (InterruptedException e) {		// ERROR!                e.printStackTrace();            }	} 	return lastScreenCaptureComparisonTrue;    }    /**     * Update the screen capture for this event sequence. Over time, the     * screen captures in a stored event sequence may become out of date.     * Calling this method will run the given event sequence, capture     * the resulting screen, and return the same EventSequence object     * with the updated screen value.     *     * @param sequence The EventSequence to run and update the screen for     * @return The updated EventSequence with the new captured screen value     */    public EventSequence updateScreenForSequence(                                  EventSequence sequence) {	return eventSequence;    }    /**     * Capture the current contents of the physical display in the form of a     * byte array. The byte array may be some reduced form of the display, such     * as a checksum or hash, but must be guaranteed unique for the display     * such that no two differing displays will have the same return value     *     * @return The byte[] of the captured screen contents     */    public byte[] captureScreen() {	byte x[] = (ScreenGrabber.getInstance()).getData();	return x;    }    // method to get this AutomatedEventHandler's reference    public static AutomationHandler getAutomationHandler() {	return thisReference;    }        // override DefaultEventHandler's implementation    // these methods do what is needed by AutomatedEventHandler    // and then call super's method.    /**     * Process a key event     *     * @param type The type of key event     * @param str The String associated with an input method event     * @param code The keycode of the key event     */    void keyEvent(int type, String str, int code) {	// we have a key event	// do we need to take a hot key action on this?	if (type == 1 && // key press            (code == hotKey_StartRecording ||            code == hotKey_StopRecording   ||	    code == hotKey_CaptureScreen)) {		// process the hot key		if (code == hotKey_StartRecording) {		    startEventSequence();		}		if (code == hotKey_StopRecording) {		    stopEventSequence();		    // note : this method also performs a screen capture		    // does this have any implications?		    if (sequenceHandler != null) {			sequenceHandler.handleEventSequence(eventSequence);		    }		}		if (code == hotKey_CaptureScreen) {		    byte s_cap[] = captureScreen();		    if (sequenceHandler != null) {			sequenceHandler.handleScreenCapture(s_cap);		    }		}	} else {	    if (recordingInProgress) {		if (type == IME) {		    int time = (int)(System.currentTimeMillis() - this.millis);		    // this is an input method event		    RecordedEvent event = new RecordedEvent(time, str);		    eventSequence.appendEvent(event);		    // set the clock		    this.millis = System.currentTimeMillis();		} else {		    int time = (int)(System.currentTimeMillis() - this.millis);		    // this is a KEY_EVENT		    RecordedEvent event = new RecordedEvent(time, type, code);		    eventSequence.appendEvent(event);		    // set the clock		    this.millis = System.currentTimeMillis();		}	    }	}	super.keyEvent(type, str, code);    }    /**     * Process a pointer event     *     * @param type The type of pointer event     * @param x The x coordinate location of the event     * @param y The y coordinate location of the event     */    void pointerEvent(int type, int x, int y) {	if (recordingInProgress) {	    int time = (int)(System.currentTimeMillis() - this.millis);	    RecordedEvent event = new RecordedEvent(time, type, x, y);	    eventSequence.appendEvent(event);	    // set the clock	    this.millis = System.currentTimeMillis();	}	super.pointerEvent(type, x, y);    }    /**     * Process a command event     *     * @param type The type of Command event to process     */    void commandEvent(int type) {	if (recordingInProgress) {	    int time = (int)(System.currentTimeMillis() - this.millis);	    RecordedEvent event = new RecordedEvent(time, type);	    eventSequence.appendEvent(event);	    // set the clock	    this.millis = System.currentTimeMillis();	}	super.commandEvent(type);    }    // -- private ---    /**     * Initialize the event sequence for recording.     * Currently, this allocates a new EventSequence     *      */    private void initializeEventSequence() {	eventSequence = new EventSequence();    }    /**     * Checks if two byte arrays match.     * <P />     * @param a first byte array     * @param b second byte array     * @return true if the sequence of bytes in a matches those in b,     *         false otherwise     */     private static boolean byteMatch(byte[] a, byte[] b) {        if (a.length != b.length)	    return false;        int len = a.length;        for (int i = 0; i < len; i++) {            if (a[i] != b[i])                return false;        }        return true;    }    // reference to ourself    static AutomationHandler thisReference;    EventSequence eventSequence;    SequenceHandler sequenceHandler;    int hotKey_StartRecording;    int hotKey_StopRecording;    int hotKey_CaptureScreen;    // was the last screen capture a true match?    boolean lastScreenCaptureComparisonTrue;    // are we recording?    boolean recordingInProgress;    // time    long millis;}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -