no message
This commit is contained in:
@@ -18,8 +18,11 @@ import javax.swing.JButton;
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.JSlider;
|
||||
import javax.swing.JTextField;
|
||||
import javax.swing.border.EmptyBorder;
|
||||
import javax.swing.event.ChangeEvent;
|
||||
import javax.swing.event.ChangeListener;
|
||||
|
||||
public class Client extends JFrame {
|
||||
JLabel label;
|
||||
@@ -44,6 +47,8 @@ public class Client extends JFrame {
|
||||
JButton btn = new JButton("链接");
|
||||
btnPanel.add(btn, BorderLayout.CENTER);
|
||||
|
||||
JSlider jSlider=createSlider();
|
||||
btnPanel.add(jSlider,BorderLayout.SOUTH);
|
||||
|
||||
JPanel panelContainer = new JPanel(new BorderLayout());
|
||||
panelContainer.add(ipPanel, BorderLayout.NORTH);
|
||||
@@ -66,7 +71,7 @@ public class Client extends JFrame {
|
||||
setDefaultCloseOperation(EXIT_ON_CLOSE);
|
||||
setBounds(360, 20, 350, 600);
|
||||
|
||||
setTitle("屏幕共享 by 万剑");
|
||||
setTitle("屏幕共享");
|
||||
btn.addMouseListener(new MouseAdapter() {
|
||||
@Override
|
||||
public void mouseClicked(MouseEvent e) {
|
||||
@@ -84,7 +89,7 @@ public class Client extends JFrame {
|
||||
@Override
|
||||
public void mouseClicked(MouseEvent mouseEvent) {
|
||||
super.mouseClicked(mouseEvent);
|
||||
System.out.println("down " + mouseEvent);
|
||||
// System.out.println("down " + mouseEvent);
|
||||
int x = mouseEvent.getX();
|
||||
int y = mouseEvent.getY();
|
||||
try {
|
||||
@@ -101,7 +106,7 @@ public class Client extends JFrame {
|
||||
@Override
|
||||
public void mouseReleased(MouseEvent mouseEvent) {
|
||||
super.mouseReleased(mouseEvent);
|
||||
System.out.println("up mouseReleased");
|
||||
// System.out.println("up mouseReleased");
|
||||
try {
|
||||
int x = mouseEvent.getX();
|
||||
int y = mouseEvent.getY();
|
||||
@@ -123,11 +128,11 @@ public class Client extends JFrame {
|
||||
int y = mouseEvent.getY();
|
||||
if (!isMove) {
|
||||
isMove = true;
|
||||
System.out.println("down mouseDragged " + mouseEvent.getX() + " " + mouseEvent.getY());
|
||||
// System.out.println("down mouseDragged " + mouseEvent.getX() + " " + mouseEvent.getY());
|
||||
|
||||
writer.write("DOWN" + (x * 1.0f / label.getWidth()) + "#" + (y * 1.0f / label.getHeight()));
|
||||
} else {
|
||||
System.out.println("move mouseDragged " + mouseEvent.getX() + " " + mouseEvent.getY());
|
||||
// System.out.println("move mouseDragged " + mouseEvent.getX() + " " + mouseEvent.getY());
|
||||
|
||||
writer.write("MOVE" + (x * 1.0f / label.getWidth()) + "#" + (y * 1.0f / label.getHeight()));
|
||||
}
|
||||
@@ -144,6 +149,29 @@ public class Client extends JFrame {
|
||||
|
||||
}
|
||||
|
||||
private JSlider createSlider() {
|
||||
int minimum = 30;
|
||||
int maximum = 100;
|
||||
JSlider slider = new JSlider(minimum, maximum,maximum);
|
||||
|
||||
slider.addChangeListener(new ChangeListener() {
|
||||
@Override
|
||||
public void stateChanged(ChangeEvent changeEvent) {
|
||||
try {
|
||||
int v=((JSlider) changeEvent.getSource()).getValue();
|
||||
writer.write("DEGREE"+v);
|
||||
writer.newLine();
|
||||
writer.flush();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
return slider;
|
||||
}
|
||||
|
||||
private JPanel createTableBar() {
|
||||
JPanel bar = new JPanel(new BorderLayout());
|
||||
JButton menu = new JButton("menu");
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package com.wanjian.puppet;
|
||||
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.Canvas;
|
||||
import android.graphics.Matrix;
|
||||
import android.graphics.Point;
|
||||
import android.hardware.input.InputManager;
|
||||
@@ -41,6 +42,8 @@ public class Main {
|
||||
|
||||
private static IWindowManager wm;
|
||||
|
||||
private static float scale = 1;
|
||||
|
||||
public static void main(String[] args) throws ClassNotFoundException, NoSuchMethodException, InvocationTargetException, IllegalAccessException, IOException {
|
||||
|
||||
System.out.println("start!");
|
||||
@@ -50,8 +53,13 @@ public class Main {
|
||||
|
||||
while (true) {
|
||||
System.out.println("listen.....");
|
||||
LocalSocket socket = serverSocket.accept();
|
||||
acceptConnect(socket);
|
||||
try {
|
||||
LocalSocket socket = serverSocket.accept();
|
||||
acceptConnect(socket);
|
||||
} catch (Exception e) {
|
||||
serverSocket = new LocalServerSocket("puppet-ver1");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -109,6 +117,8 @@ public class Main {
|
||||
private final String HOME = "HOME";
|
||||
private final String BACK = "BACK";
|
||||
|
||||
private final String DEGREE = "DEGREE";
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
super.run();
|
||||
@@ -131,13 +141,15 @@ public class Main {
|
||||
} else if (line.startsWith(MOVE)) {
|
||||
hanlerMove(line.substring(MOVE.length()));
|
||||
} else if (line.startsWith(UP)) {
|
||||
hanlerUp(line.substring(UP.length()));
|
||||
handlerUp(line.substring(UP.length()));
|
||||
} else if (line.startsWith(MENU)) {
|
||||
menu();
|
||||
} else if (line.startsWith(HOME)) {
|
||||
pressHome();
|
||||
} else if (line.startsWith(BACK)) {
|
||||
back();
|
||||
} else if (line.startsWith(DEGREE)) {
|
||||
scale = Float.parseFloat(line.substring(DEGREE.length())) / 100;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
@@ -153,7 +165,7 @@ public class Main {
|
||||
}.start();
|
||||
}
|
||||
|
||||
private static void hanlerUp(String line) {
|
||||
private static void handlerUp(String line) {
|
||||
Point point = getXY(line);
|
||||
if (point != null) {
|
||||
try {
|
||||
@@ -195,7 +207,6 @@ public class Main {
|
||||
float scaleY = Float.parseFloat(s[1]);
|
||||
point.x *= scaleX;
|
||||
point.y *= scaleY;
|
||||
System.out.println("point x=" + point.x + " y=" + point.y);
|
||||
return point;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
@@ -211,10 +222,13 @@ public class Main {
|
||||
outputStream.write(v);
|
||||
}
|
||||
|
||||
|
||||
public static Bitmap screenshot() throws Exception {
|
||||
|
||||
String surfaceClassName;
|
||||
Point size = SurfaceControlVirtualDisplayFactory.getCurrentDisplaySize(false);
|
||||
size.x *= scale;
|
||||
size.y *= scale;
|
||||
Bitmap b = null;
|
||||
if (Build.VERSION.SDK_INT <= 17) {
|
||||
surfaceClassName = "android.view.Surface";
|
||||
@@ -223,7 +237,9 @@ public class Main {
|
||||
// b = android.view.SurfaceControl.screenshot(size.x, size.y);
|
||||
}
|
||||
b = (Bitmap) Class.forName(surfaceClassName).getDeclaredMethod("screenshot", new Class[]{Integer.TYPE, Integer.TYPE}).invoke(null, new Object[]{Integer.valueOf(size.x), Integer.valueOf(size.y)});
|
||||
|
||||
int rotation = wm.getRotation();
|
||||
|
||||
if (rotation == 0) {
|
||||
return b;
|
||||
}
|
||||
@@ -236,6 +252,7 @@ public class Main {
|
||||
m.postRotate(-270.0f);
|
||||
}
|
||||
return Bitmap.createBitmap(b, 0, 0, size.x, size.y, m, false);
|
||||
|
||||
}
|
||||
|
||||
private static void menu() throws InvocationTargetException, IllegalAccessException {
|
||||
@@ -248,17 +265,14 @@ public class Main {
|
||||
|
||||
|
||||
private static void touchUp(float clientX, float clientY) throws InvocationTargetException, IllegalAccessException {
|
||||
System.out.println("up " + clientX + " " + clientY);
|
||||
injectMotionEvent(im, injectInputEventMethod, InputDeviceCompat.SOURCE_TOUCHSCREEN, 1, downTime, SystemClock.uptimeMillis(), clientX, clientY, 1.0f);
|
||||
}
|
||||
|
||||
private static void touchMove(float clientX, float clientY) throws InvocationTargetException, IllegalAccessException {
|
||||
System.out.println("move " + clientX + " " + clientY);
|
||||
injectMotionEvent(im, injectInputEventMethod, InputDeviceCompat.SOURCE_TOUCHSCREEN, 2, downTime, SystemClock.uptimeMillis(), clientX, clientY, 1.0f);
|
||||
}
|
||||
|
||||
private static void touchDown(float clientX, float clientY) throws InvocationTargetException, IllegalAccessException {
|
||||
System.out.println("down " + clientX + " " + clientY);
|
||||
downTime = SystemClock.uptimeMillis();
|
||||
injectMotionEvent(im, injectInputEventMethod, InputDeviceCompat.SOURCE_TOUCHSCREEN, 0, downTime, downTime, clientX, clientY, 1.0f);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user