/*
* Copyright (C) 2010 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.android.monkeyrunner.recorder;
import com.android.monkeyrunner.MonkeyDevice;
import com.android.monkeyrunner.core.IMonkeyImage;
import com.android.monkeyrunner.core.IMonkeyDevice;
import com.android.monkeyrunner.recorder.actions.Action;
import com.android.monkeyrunner.recorder.actions.DragAction;
import com.android.monkeyrunner.recorder.actions.DragAction.Direction;
import com.android.monkeyrunner.recorder.actions.PressAction;
import com.android.monkeyrunner.recorder.actions.TouchAction;
import com.android.monkeyrunner.recorder.actions.TypeAction;
import com.android.monkeyrunner.recorder.actions.WaitAction;
import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.Graphics2D;
import java.awt.Point;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.MouseMotionAdapter;
import java.awt.geom.GeneralPath;
import java.awt.image.BufferedImage;
import java.io.FileNotFoundException;
import java.text.SimpleDateFormat;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.BoxLayout;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFileChooser;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.SwingUtilities;
import javax.swing.Timer;
/**
* MainFrame for MonkeyRecorder.
*/
public class MonkeyRecorderFrame extends JFrame {
private static final Logger LOG = Logger
.getLogger(MonkeyRecorderFrame.class.getName());
private final IMonkeyDevice device;
public int startxx = 0;
public int startyy = 0;
public int endxx = 0;
public int endyy = 0;
public String stime,etime;
GeneralPath gPath= new GeneralPath(); //GeneralPath对象实例
Point aPoint;
private static final long serialVersionUID = 1L;
private JPanel jContentPane = null;
private JLabel display = null;
private JScrollPane historyPanel = null;
private JPanel actionPanel = null;
//private JButton waitButton = null;
private JButton menuButton = null;
private JButton homeButton = null;
private JButton backButton = null;
//private JButton pressButton = null;
private JButton typeButton = null;
//private JButton flingButton = null;
private JButton westButton = null;
private JButton eastButton = null;
private JButton northButton = null;
private JButton southButton = null;
private JButton barButton = null;
private JButton exportActionButton = null;
private JButton refreshButton = null;
private BufferedImage currentImage; // @jve:decl-index=0:
private BufferedImage scaledImage = new BufferedImage(320, 480,
BufferedImage.TYPE_INT_ARGB); // @jve:decl-index=0:
private JList historyList;
private ActionListModel actionListModel;
private final Timer refreshTimer = new Timer(1000, new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
refreshDisplay(); // @jve:decl-index=0:
}
});
/**
* This is the default constructor
*/
public MonkeyRecorderFrame(IMonkeyDevice device) {
this.device = device;
initialize();
}
private void initialize() {
this.setSize(800, 1200);
this.setContentPane(getJContentPane());
this.setTitle("MonkeyRecorder");
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
refreshDisplay();
}
});
refreshTimer.start();
}
private void refreshDisplay() {
IMonkeyImage snapshot = device.takeSnapshot();
currentImage = snapshot.createBufferedImage();
Graphics2D g = scaledImage.createGraphics();
g.drawImage(currentImage, 0, 0, scaledImage.getWidth(),
scaledImage.getHeight(), null);
g.draw(gPath); //绘制路径
g.dispose();
display.setIcon(new ImageIcon(scaledImage));
pack();
}
/**
* This method initializes jContentPane
*
* @return javax.swing.JPanel
*/
private JPanel getJContentPane() {
if (jContentPane == null) {
display = new JLabel();
jContentPane = new JPanel();
jContentPane.setLayout(new BorderLayout());
jContentPane.add(display, BorderLayout.CENTER);
jContentPane.add(getHistoryPanel(), BorderLayout.EAST);
jContentPane.add(getActionPanel(), BorderLayout.NORTH);
display.setPreferredSize(new Dimension(320, 480));
display.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent event) {
touch(event);
}
public void mousePressed(MouseEvent event) {
stime = new java.sql.Timestamp(System.currentTimeMillis()).toString();
double scalex = ((double) currentImage.getWidth())
/ ((double) scaledImage.getWidth());
double scaley = ((double) currentImage.getHeight())
/ ((double) scaledImage.getHeight());
aPoint = event.getPoint(); //得到当前鼠标点
startxx = aPoint.x;
startyy = aPoint.y;
startxx = (int) (startxx * scalex);
startyy = (int) (startyy * scaley);
System.out.println("startxx = " + startxx);
System.out.println("startyy = " + startyy);
gPath.moveTo(aPoint.x,aPoint.y); //设置路径点
}
public void mouseReleased(MouseEvent event) {
etime = new java.sql.Timestamp(System.currentTimeMillis()).toString();
System.out.println("getInitialDelay = " + returntime(stime,etime));
double scalex = ((double) currentImage.getWidth())
/ ((double) scaledImage.getWidth());
double scaley = ((double) currentImage.getHeight())
/ ((double) scaledImage.getHeight());
aPoint = event.getPoint(); //得到当前鼠标点
endxx = aPoint.x;
endyy = aPoint.y;
endxx = (int) (endxx * scalex);
endyy = (int) (endyy * scaley);
System.out.println("endxx = " + endxx);
System.out.println("endyy = " + endyy);
if (startxx == endxx && startyy == endyy)
{
if(returntime(stime,etime) < 300)
System.out.println("touch event");
else{
System.out.println("longpress");
addAction(newFlingAction(Direction.MOUSE, 1, 1000));
}
}
else{
addAction(newFlingAction(Direction.MOUSE, 10, 1000));
}
gPath.moveTo(aPoint.x,aPoint.y); //设置路径点
}
});
display.addMouseMotionListener(new MouseMotionAdapter() {
@Override
public void mouseDragged(MouseEvent event) {
double scalex = ((double) currentImage.getWidth())
/ ((double) scaledImage.getWidth());
double scaley = ((double) currentImage.getHeight())
/ ((double) scaledImage.getHeight());
aPoint.x = (int) (aPoint.x * scalex);
aPoint.y = (int) (aPoint.y * scaley);
aPoint = event.getPoint(); //得到当前鼠标点
gPath.lineTo(aPoint.x, aPoint.y); //设置路径
gPath = new GeneralPath(); //重新实例化GeneralPath对象
gPath.moveTo(aPoint.x, aPoint.y);
refreshDisplay(); //重绘组件
}
});
}
return jContentPane;
}
/**
* This method initializes historyPanel
*
* @return javax.swing.JScrollPane
*/
private JScrollPane getHistoryPanel() {
if (historyPanel == null) {
historyPanel = new JScrollPane();
historyPanel.getViewport().setView(getHistoryList());
}
return historyPanel;
}
private JList getHistoryList() {
if (historyList == null) {
actionListModel = new ActionListModel();
historyList = new JList(actionListModel);
}
没有合适的资源?快使用搜索试试~ 我知道了~
温馨提示
近研究monkeyrunner, 其中monkey_recorder.py的界面不是很好操作,点起来很麻烦,对runner的源码做了一些修改,现在用起来方便多了, 经过测试运行很稳定,但是鼠标拖拽屏幕的功能没有实现,算是一个遗憾吧,后面有时间再研究加上 ------------------------------ 这段时间有空,已经实现了鼠标拖拽,还有些不足之处,后期继续优化
资源推荐
资源详情
资源评论
收起资源包目录
(实现鼠标拖拽)优化monkeyrunner源码使recorder.py更易于操作 (170个子文件)
AdbMonkeyDevice.class 17KB
JythonUtils.class 15KB
MonkeyRecorderFrame.class 13KB
MonkeyDevice.class 13KB
MonkeyRunnerHelp.class 10KB
HwhRecorderFrame.class 10KB
SdkConstants.class 9KB
MonkeyRunner.class 9KB
MonkeyRunnerStarter.class 9KB
ScriptRunner.class 8KB
EasyMonkeyDevice.class 8KB
MonkeyImage.class 7KB
MonkeyManager.class 6KB
MonkeyImageBase.class 6KB
MonkeyRunnerOptions.class 5KB
MonkeyControllerFrame.class 5KB
HierarchyViewer.class 5KB
AdbBackend.class 5KB
VariableFrame$VariableTableModel.class 4KB
VariableFrame.class 4KB
MonkeyRecorderFrame$3.class 4KB
MonkeyFormatter.class 3KB
VariableFrame$VariableTableModel$1.class 3KB
TouchAction.class 3KB
ThirtyTwoBitColorModel.class 3KB
PressAction.class 3KB
ImageUtils.class 3KB
DragAction.class 2KB
MonkeyRecorder.class 2KB
AdbMonkeyDevice$1.class 2KB
AdbMonkeyDevice$2.class 2KB
By.class 2KB
CaptureRawAndConvertedImage.class 2KB
PyDictUtilBuilder.class 2KB
TouchPressType.class 2KB
ActionListModel.class 2KB
SixteenBitColorModel.class 2KB
DragAction$Direction.class 2KB
PhysicalButton.class 2KB
MonkeyRecorderFrame$14.class 2KB
WaitAction.class 2KB
LinearInterpolator.class 2KB
MonkeyRecorderFrame$4.class 2KB
CaptureRawAndConvertedImage$MonkeyRunnerRawImage.class 2KB
HwhRunner.class 2KB
HwhRecorderFrame$8.class 2KB
IMonkeyDevice.class 2KB
TypeAction.class 2KB
MonkeyControllerFrame$PressAction.class 1KB
MonkeyRecorderFrame$12.class 1KB
MonkeyRecorderFrame$11.class 1KB
MonkeyRecorderFrame$10.class 1KB
MonkeyController$1.class 1KB
MonkeyRecorderFrame$13.class 1KB
MonkeyRecorderFrame$9.class 1KB
MonkeyFormatter$PrintWriterWithHeader.class 1KB
MonkeyControllerFrame$5.class 1KB
MonkeyRecorderFrame$8.class 1KB
MonkeyControllerFrame$4.class 1KB
LinearInterpolator$Point.class 1KB
LoggingOutputReceiver.class 1KB
VariableFrame$VariableHolder.class 1KB
MonkeyRunnerHelp$Type.class 1KB
MonkeyControllerFrame$6.class 1KB
MonkeyRunnerStarter$1.class 1KB
VariableFrame$VariableTableModel$1$1.class 1KB
MonkeyRunnerHelp$3.class 1KB
MonkeyRecorderFrame$5.class 1KB
MonkeyRecorderFrame$6.class 1KB
MonkeyRecorderFrame$7.class 1KB
MonkeyControllerFrame$3.class 1KB
VariableFrame$1.class 1KB
MonkeyRunnerHelp$2.class 1KB
MonkeyRecorder$1.class 1KB
VariableFrame$3.class 1KB
MonkeyRunnerHelp$4.class 1KB
HwhRecorderFrame$7.class 1KB
CommandOutputCapture.class 1KB
MonkeyController$1$1.class 1022B
MonkeyRunnerHelp$1.class 1007B
JythonUtils$1.class 976B
HwhRecorderFrame$3.class 972B
HwhRecorderFrame$6.class 950B
HwhRecorderFrame$4.class 950B
HwhRecorderFrame$5.class 950B
HwhRunner$1.class 949B
JythonUtils$3.class 949B
MonkeyController.class 944B
StubBackend.class 938B
MonkeyControllerFrame$2.class 928B
JythonUtils$2.class 884B
MonkeyControllerFrame$1.class 872B
MonkeyRecorderFrame$1.class 850B
AdbMonkeyImage.class 840B
VariableFrame$2.class 838B
MonkeyRecorderFrame$2.class 766B
MonkeyRunnerException.class 710B
MonkeyImageBase$BufferedImageMonkeyImage.class 703B
HwhRecorderFrame$1.class 702B
MonkeyRunnerExported.class 644B
共 170 条
- 1
- 2
Q5914002
- 粉丝: 4
- 资源: 20
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
- 1
- 2
- 3
前往页