no message

This commit is contained in:
wanjian
2017-04-05 15:37:04 +08:00
parent 5bb02f3be1
commit 40f1cc742d
3 changed files with 55 additions and 13 deletions

BIN
Main.dex

Binary file not shown.

View File

@@ -18,8 +18,11 @@ import javax.swing.JButton;
import javax.swing.JFrame; import javax.swing.JFrame;
import javax.swing.JLabel; import javax.swing.JLabel;
import javax.swing.JPanel; import javax.swing.JPanel;
import javax.swing.JSlider;
import javax.swing.JTextField; import javax.swing.JTextField;
import javax.swing.border.EmptyBorder; import javax.swing.border.EmptyBorder;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
public class Client extends JFrame { public class Client extends JFrame {
JLabel label; JLabel label;
@@ -44,6 +47,8 @@ public class Client extends JFrame {
JButton btn = new JButton("链接"); JButton btn = new JButton("链接");
btnPanel.add(btn, BorderLayout.CENTER); btnPanel.add(btn, BorderLayout.CENTER);
JSlider jSlider=createSlider();
btnPanel.add(jSlider,BorderLayout.SOUTH);
JPanel panelContainer = new JPanel(new BorderLayout()); JPanel panelContainer = new JPanel(new BorderLayout());
panelContainer.add(ipPanel, BorderLayout.NORTH); panelContainer.add(ipPanel, BorderLayout.NORTH);
@@ -66,7 +71,7 @@ public class Client extends JFrame {
setDefaultCloseOperation(EXIT_ON_CLOSE); setDefaultCloseOperation(EXIT_ON_CLOSE);
setBounds(360, 20, 350, 600); setBounds(360, 20, 350, 600);
setTitle("屏幕共享 by 万剑"); setTitle("屏幕共享");
btn.addMouseListener(new MouseAdapter() { btn.addMouseListener(new MouseAdapter() {
@Override @Override
public void mouseClicked(MouseEvent e) { public void mouseClicked(MouseEvent e) {
@@ -84,7 +89,7 @@ public class Client extends JFrame {
@Override @Override
public void mouseClicked(MouseEvent mouseEvent) { public void mouseClicked(MouseEvent mouseEvent) {
super.mouseClicked(mouseEvent); super.mouseClicked(mouseEvent);
System.out.println("down " + mouseEvent); // System.out.println("down " + mouseEvent);
int x = mouseEvent.getX(); int x = mouseEvent.getX();
int y = mouseEvent.getY(); int y = mouseEvent.getY();
try { try {
@@ -101,7 +106,7 @@ public class Client extends JFrame {
@Override @Override
public void mouseReleased(MouseEvent mouseEvent) { public void mouseReleased(MouseEvent mouseEvent) {
super.mouseReleased(mouseEvent); super.mouseReleased(mouseEvent);
System.out.println("up mouseReleased"); // System.out.println("up mouseReleased");
try { try {
int x = mouseEvent.getX(); int x = mouseEvent.getX();
int y = mouseEvent.getY(); int y = mouseEvent.getY();
@@ -123,11 +128,11 @@ public class Client extends JFrame {
int y = mouseEvent.getY(); int y = mouseEvent.getY();
if (!isMove) { if (!isMove) {
isMove = true; 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())); writer.write("DOWN" + (x * 1.0f / label.getWidth()) + "#" + (y * 1.0f / label.getHeight()));
} else { } 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())); 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() { private JPanel createTableBar() {
JPanel bar = new JPanel(new BorderLayout()); JPanel bar = new JPanel(new BorderLayout());
JButton menu = new JButton("menu"); JButton menu = new JButton("menu");

View File

@@ -1,6 +1,7 @@
package com.wanjian.puppet; package com.wanjian.puppet;
import android.graphics.Bitmap; import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Matrix; import android.graphics.Matrix;
import android.graphics.Point; import android.graphics.Point;
import android.hardware.input.InputManager; import android.hardware.input.InputManager;
@@ -41,6 +42,8 @@ public class Main {
private static IWindowManager wm; private static IWindowManager wm;
private static float scale = 1;
public static void main(String[] args) throws ClassNotFoundException, NoSuchMethodException, InvocationTargetException, IllegalAccessException, IOException { public static void main(String[] args) throws ClassNotFoundException, NoSuchMethodException, InvocationTargetException, IllegalAccessException, IOException {
System.out.println("start!"); System.out.println("start!");
@@ -50,8 +53,13 @@ public class Main {
while (true) { while (true) {
System.out.println("listen....."); System.out.println("listen.....");
try {
LocalSocket socket = serverSocket.accept(); LocalSocket socket = serverSocket.accept();
acceptConnect(socket); 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 HOME = "HOME";
private final String BACK = "BACK"; private final String BACK = "BACK";
private final String DEGREE = "DEGREE";
@Override @Override
public void run() { public void run() {
super.run(); super.run();
@@ -131,13 +141,15 @@ public class Main {
} else if (line.startsWith(MOVE)) { } else if (line.startsWith(MOVE)) {
hanlerMove(line.substring(MOVE.length())); hanlerMove(line.substring(MOVE.length()));
} else if (line.startsWith(UP)) { } else if (line.startsWith(UP)) {
hanlerUp(line.substring(UP.length())); handlerUp(line.substring(UP.length()));
} else if (line.startsWith(MENU)) { } else if (line.startsWith(MENU)) {
menu(); menu();
} else if (line.startsWith(HOME)) { } else if (line.startsWith(HOME)) {
pressHome(); pressHome();
} else if (line.startsWith(BACK)) { } else if (line.startsWith(BACK)) {
back(); back();
} else if (line.startsWith(DEGREE)) {
scale = Float.parseFloat(line.substring(DEGREE.length())) / 100;
} }
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
@@ -153,7 +165,7 @@ public class Main {
}.start(); }.start();
} }
private static void hanlerUp(String line) { private static void handlerUp(String line) {
Point point = getXY(line); Point point = getXY(line);
if (point != null) { if (point != null) {
try { try {
@@ -195,7 +207,6 @@ public class Main {
float scaleY = Float.parseFloat(s[1]); float scaleY = Float.parseFloat(s[1]);
point.x *= scaleX; point.x *= scaleX;
point.y *= scaleY; point.y *= scaleY;
System.out.println("point x=" + point.x + " y=" + point.y);
return point; return point;
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
@@ -211,10 +222,13 @@ public class Main {
outputStream.write(v); outputStream.write(v);
} }
public static Bitmap screenshot() throws Exception { public static Bitmap screenshot() throws Exception {
String surfaceClassName; String surfaceClassName;
Point size = SurfaceControlVirtualDisplayFactory.getCurrentDisplaySize(false); Point size = SurfaceControlVirtualDisplayFactory.getCurrentDisplaySize(false);
size.x *= scale;
size.y *= scale;
Bitmap b = null; Bitmap b = null;
if (Build.VERSION.SDK_INT <= 17) { if (Build.VERSION.SDK_INT <= 17) {
surfaceClassName = "android.view.Surface"; surfaceClassName = "android.view.Surface";
@@ -223,7 +237,9 @@ public class Main {
// b = android.view.SurfaceControl.screenshot(size.x, size.y); // 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)}); 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(); int rotation = wm.getRotation();
if (rotation == 0) { if (rotation == 0) {
return b; return b;
} }
@@ -236,6 +252,7 @@ public class Main {
m.postRotate(-270.0f); m.postRotate(-270.0f);
} }
return Bitmap.createBitmap(b, 0, 0, size.x, size.y, m, false); return Bitmap.createBitmap(b, 0, 0, size.x, size.y, m, false);
} }
private static void menu() throws InvocationTargetException, IllegalAccessException { 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 { 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); 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 { 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); 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 { private static void touchDown(float clientX, float clientY) throws InvocationTargetException, IllegalAccessException {
System.out.println("down " + clientX + " " + clientY);
downTime = SystemClock.uptimeMillis(); downTime = SystemClock.uptimeMillis();
injectMotionEvent(im, injectInputEventMethod, InputDeviceCompat.SOURCE_TOUCHSCREEN, 0, downTime, downTime, clientX, clientY, 1.0f); injectMotionEvent(im, injectInputEventMethod, InputDeviceCompat.SOURCE_TOUCHSCREEN, 0, downTime, downTime, clientX, clientY, 1.0f);