双生树
-
2011-10-04
android input核心代码
-
2011-10-04
android input_dev结构和鼠标记录代码
http://www.netmite.com/android/mydroid/1.5/kernel/include/linux/input.h
代码来自 http://blog.sina.com.cn/flza
#include
#include
#include
#includestatic int event0_fd = -1;
struct input_event ev0[64];//for handling event0, mouse/key/ts
static int handle_event0() {
int button = 0, realx = 0, realy = 0, i, rd;rd = read(event0_fd, ev0, sizeof(struct input_event) * 64);
if ( rd < sizeof(struct input_event) ) return 0;for (i = 0; i < rd / sizeof(struct input_event); i++) {
printf("", ev0[i].type, ev0[i].code, ev0[i].value);
if (ev0[i].type == 3 && ev0[i].code == 0)
realx = ev0[i].value;
else if (ev0[i].type == 3 && ev0[i].code == 1)
realy = ev0[i].value;
else if (ev0[i].type == 1) {
if (ev0[i].code == 158) {
//if key esc then exit
return 0;
}
} else if (ev0[i].type == 0 && ev0[i].code == 0 && ev0[i].value == 0) {
realx = 0, realy = 0;
}
printf("event(%d): type: %d; code: %3d; value: %3d; realx: %3d; realy: %3d\n", i,
ev0[i].type, ev0[i].code, ev0[i].value, realx, realy);
}return 1;
}int main(void) {
int done = 1;
printf("sizeof(struct input_event) = %d\n", sizeof(struct input_event));event0_fd = open("/dev/input/event0", O_RDWR);
if ( event0_fd < 0 )
return -1;while ( done ) {
printf("begin handel_event0...\n");
done = handle_event0();
printf("end handel_event0...\n");
}if ( event0_fd > 0 ) {
close(event0_fd);
event0_fd = -1;
}return 0;
}
交叉编译好了push到系统里面执行就可以看到效果
-
2011-05-17
一个小的java shell
import java.net.*;
import java.io.*;
class Servicer implements Runnable {
Socket s;
public Servicer(Socket s) {
this.s = s;
}
public void run() {
try {
InputStream ips = s.getInputStream();
OutputStream ops = s.getOutputStream();
BufferedReader br = new BufferedReader(new InputStreamReader(ips));
DataOutputStream dos = new DataOutputStream(ops);
while (true) {
String strWord = br.readLine();
//接收到"quit",程序退出
if (strWord.equalsIgnoreCase("quit")){
break;
}
System.out.println(strWord);
String strs = exec(strWord, null);
dos.writeBytes("you cmd---->"+ strWord +"\r\n");
dos.writeBytes("execed---->\r\n" + strs + System.getProperty("line.separator"));
//System.out.println(strs);
//System.out.println("debug");
}
br.close();
dos.close();
s.close();
} catch (Exception e) {
e.printStackTrace();
}
}
public static String exec(String cmd, Writer out) throws IOException
{
StringBuffer sb = new StringBuffer();
int len = 0;
byte by[] = new byte[cmd.length() * 10];
Process p = Runtime.getRuntime().exec(cmd);
InputStream is = p.getInputStream();
while((len = is.read(by)) != -1)
{
String str = new String(by, 0, len);
if(out != null)
{
out.write(str);
out.flush();
}
sb.append(str);
}
is.close();
return sb.toString();
}}
class Shell {
public static void main(String[] args) {
try {
ServerSocket ss = new ServerSocket(8001);
while (true) {
Socket s = ss.accept();
new Thread(new Servicer(s)).start();
}
} catch (Exception e) {
e.printStackTrace();
}
}
}抽空继续改进
1) 中文乱码了貌似
2)有的命令执行时貌似有bug?
3)增加文件上传下载功能
-
2011-05-11
纪念下我的第一个java图形化程序
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;import javax.swing.JButton;
import javax.swing.JFileChooser;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
public class CopyFile {/**
* @param args
*/
private File srcFile;
private File desFile;public static void main(String[] args) {
new CopyFile().init();
}
public void init(){
final JFrame f = new JFrame("copy file");
f.setLayout( new FlowLayout());
JButton btn1 = new JButton("选择文件");
JButton btn2 = new JButton("复制文件");
f.add(btn1);
f.add(btn2);
btn1.addActionListener(new ActionListener(){@Override
public void actionPerformed(ActionEvent arg0) {
JFileChooser chooser = new JFileChooser();
int ret = chooser.showOpenDialog(f);
if(ret == JFileChooser.APPROVE_OPTION){
srcFile = chooser.getSelectedFile();
}
}
});
btn2.addActionListener(new ActionListener(){@Override
public void actionPerformed(ActionEvent e) {
JFileChooser chooser = new JFileChooser();
int ret = chooser.showSaveDialog(f);
if(ret == JFileChooser.APPROVE_OPTION){
desFile = chooser.getSelectedFile();
try{
copy(srcFile,desFile);
JOptionPane.showMessageDialog(f, "success");
}catch(Exception e1){
JOptionPane.showMessageDialog(f, "lalalal");
}
}
}
});
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.setBounds(300,200,400,100);
f.setVisible(true);
}
public void copy(File srcFile,File desFile) throws Exception{
FileInputStream fis = new FileInputStream(srcFile);
BufferedInputStream bis = new BufferedInputStream(fis);
FileOutputStream fos = new FileOutputStream(desFile);
BufferedOutputStream bos = new BufferedOutputStream(fos);
byte[] buf = new byte[1024];
while (bis.read(buf)!=-1){
System.out.println(buf);
bos.write(buf);
}
bis.close();
bos.close();
System.out.println("end");
}
} -
2011-03-31
最简单的开始 纪念我的第一个java程序 - [myself]
[本日志已设置加密]







