Compare commits

...

10 Commits

Author SHA1 Message Date
wanjian
07172aaafe Merge branch 'master' of https://github.com/android-notes/androidScreenShareAndControl 2018-08-25 14:45:14 +08:00
wanjian
47d27c9542 去除屏幕方向判断,兼容Android8.0 2018-08-25 14:44:52 +08:00
wanjian
6f89f70fe5 Update README.md 2018-06-19 13:13:08 +08:00
wanjian
89fde42cdf Update README.md 2018-05-17 09:51:28 +08:00
wanjian
7d306fc743 no message 2018-05-17 09:49:03 +08:00
wanjian
60c4841855 Update README.md 2018-05-17 09:47:44 +08:00
wanjian
ced2cbbf99 Update README.md 2018-01-03 20:15:57 +08:00
wanjian
ff2f1e7aed no message 2018-01-03 20:14:23 +08:00
wanjian
92ee21ae3d Update README.md 2017-07-28 18:29:08 +08:00
wanjian
eeafd04c25 Update README.md 2017-07-28 18:22:06 +08:00
8 changed files with 89 additions and 38 deletions

BIN
Main.dex

Binary file not shown.

View File

@@ -1,6 +1,7 @@
### 免root兼容所有Android版本屏幕共享及远程控制。
### 效果
![demo](https://github.com/android-notes/androidScreenShareAndControl/blob/master/demo.gif?raw=true)
### 使用方式
对于mac 笔记本用户:
@@ -20,7 +21,7 @@
* 新建命令窗口,然后执行 `adb forward tcp:8888 localabstract:puppet-ver1`
* 运行lib目录下的Client用于显示和控制,点击连接按钮即可
注意高版本的android手机需要去开发者选项中开启 允许模拟点击
完整命令如下
```html
@@ -185,3 +186,36 @@ public interface IRotationWatcher {
[https://github.com/android-notes/androidScreenShareAndControl](https://github.com/android-notes/androidScreenShareAndControl)
### 附 编译class方式
最简单的方式:
`android studio`中右击`com.wanjian.puppet.Main`这个文件,选择 `run Main.main()`编译后的class文件就会自动保存到
`androidScreenShareAndControl/shareandcontrollib/build/intermediates/classes/debug` 这个目录中
方式2
*`android sdk`目录下的`android.jar``supportv4.jar`拷贝到
`androidScreenShareAndControl/shareandcontrollib/src/main/java`
目录下
* 同时在这个目录下新建`classes`文件夹用于保存编译后的class文件并把命令行切换到这个目录
* 执行如下命令,其中`android.jar``support-v4-23.4.0-sources.jar``android sdk`中的`jar`包,一个在`platforms/android-xx`文件夹下,一个在`extras/android/m2repository/com/android/support/support-v4`下。(命令中间用:分割windows的话需要用;分割)
* `javac -cp android.jar:support-v4-23.4.0-sources.jar:./ com/wanjian/puppet/Main.java -d classes`
* 这样就会在classes文件夹中生成class文件了 (JDK版本不能太高不然会提示 unsupported class file version 52.0)
![img](https://raw.githubusercontent.com/android-notes/blogimg/master/%E6%89%93%E5%8C%85class%E5%92%8Cdex.png)
### 打包dex方式
首先命令窗口切换到 `androidScreenShareAndControl/shareandcontrollib/build/intermediates/classes/debug` 目录下,可以看到
所有编译生成的class文件如果没有先执行上面步骤生成class文件。
然后使用 `dx --dex --output=Main.dex ./`命令生成dex文件。dx命令文件在 `sdk/build-tools/版本号`
![dex](https://raw.githubusercontent.com/android-notes/androidScreenShareAndControl/master/dex-package.png)

BIN
demo.gif Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.3 MiB

BIN
dex-package.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 446 KiB

View File

@@ -27,6 +27,7 @@ import javax.swing.event.ChangeListener;
public class Client extends JFrame {
JLabel label;
boolean isMove = false;
JLabel tips;
public Client() throws IOException {
setLayout(new BorderLayout(0, 0));
@@ -45,10 +46,16 @@ public class Client extends JFrame {
JPanel btnPanel = new JPanel(new BorderLayout(5, 5));
JButton btn = new JButton("链接");
btnPanel.add(btn, BorderLayout.CENTER);
btnPanel.add(btn, BorderLayout.NORTH);
JSlider jSlider=createSlider();
btnPanel.add(jSlider,BorderLayout.SOUTH);
tips = new JLabel();
tips.setBorder(new EmptyBorder(0, 8, 0, 0));
tips.setText("清晰度 100%");
btnPanel.add(tips, BorderLayout.CENTER);
JSlider jSlider = createSlider();
btnPanel.add(jSlider, BorderLayout.SOUTH);
JPanel panelContainer = new JPanel(new BorderLayout());
panelContainer.add(ipPanel, BorderLayout.NORTH);
@@ -148,14 +155,15 @@ public class Client extends JFrame {
private JSlider createSlider() {
int minimum = 30;
int maximum = 100;
JSlider slider = new JSlider(minimum, maximum,maximum);
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);
int v = ((JSlider) changeEvent.getSource()).getValue();
tips.setText("清晰度 " + v + "%");
writer.write("DEGREE" + v);
writer.newLine();
writer.flush();
} catch (Exception e) {

View File

@@ -10,7 +10,7 @@ import android.os.IBinder;
public interface IWindowManager {
void getInitialDisplaySize(int i, Point displaySize);
int getRotation();
// int getRotation();
void getRealDisplaySize(Point displaySize);

View File

@@ -41,6 +41,14 @@ public class Main {
public static void main(String[] args) throws ClassNotFoundException, NoSuchMethodException, InvocationTargetException, IllegalAccessException, IOException {
System.out.println("start!");
Thread.setDefaultUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() {
@Override
public void uncaughtException(Thread t, Throwable e) {
System.out.println(e.getMessage());
}
});
LocalServerSocket serverSocket = new LocalServerSocket("puppet-ver1");
init();
@@ -51,6 +59,7 @@ public class Main {
LocalSocket socket = serverSocket.accept();
acceptConnect(socket);
} catch (Exception e) {
System.out.println(e.getMessage());
serverSocket = new LocalServerSocket("puppet-ver1");
}
@@ -93,8 +102,8 @@ public class Main {
outputStream.write(byteArrayOutputStream.toByteArray());
outputStream.flush();
}
} catch (Exception e) {
e.printStackTrace();
} catch (Throwable e) {
System.out.println(e.getMessage());
}
}
}.start();
@@ -126,7 +135,7 @@ public class Main {
return;
}
} catch (Exception e) {
e.printStackTrace();
System.out.println(e.getMessage());
return;
}
try {
@@ -146,13 +155,13 @@ public class Main {
scale = Float.parseFloat(line.substring(DEGREE.length())) / 100;
}
} catch (Exception e) {
e.printStackTrace();
System.out.println(e.getMessage());
}
}
} catch (Exception e) {
e.printStackTrace();
} catch (Throwable e) {
System.out.println(e.getMessage());
}
}
@@ -165,7 +174,7 @@ public class Main {
try {
touchUp(point.x, point.y);
} catch (Exception e) {
e.printStackTrace();
System.out.println(e.getMessage());
}
}
}
@@ -176,7 +185,7 @@ public class Main {
try {
touchMove(point.x, point.y);
} catch (Exception e) {
e.printStackTrace();
System.out.println(e.getMessage());
}
}
}
@@ -187,7 +196,7 @@ public class Main {
try {
touchDown(point.x, point.y);
} catch (Exception e) {
e.printStackTrace();
System.out.println(e.getMessage());
}
}
}
@@ -203,7 +212,7 @@ public class Main {
point.y *= scaleY;
return point;
} catch (Exception e) {
e.printStackTrace();
System.out.println(e.getMessage());
}
return null;
}
@@ -232,19 +241,19 @@ public class Main {
}
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;
}
// int rotation = wm.getRotation();
//
// if (rotation == 0) {
// return b;
// }
Matrix m = new Matrix();
if (rotation == 1) {
m.postRotate(-90.0f);
} else if (rotation == 2) {
m.postRotate(-180.0f);
} else if (rotation == 3) {
m.postRotate(-270.0f);
}
// if (rotation == 1) {
// m.postRotate(-90.0f);
// } else if (rotation == 2) {
// m.postRotate(-180.0f);
// } else if (rotation == 3) {
// m.postRotate(-270.0f);
// }
return Bitmap.createBitmap(b, 0, 0, size.x, size.y, m, false);
}

View File

@@ -33,7 +33,7 @@ public class SurfaceControlVirtualDisplayFactory implements VirtualDisplayFactor
if (VERSION.SDK_INT >= 18) {
wm = Stub.asInterface((IBinder) getServiceMethod.invoke(null, new Object[]{"window"}));
wm.getInitialDisplaySize(0, displaySize);
rotation = wm.getRotation();
// rotation = wm.getRotation();
} else if (VERSION.SDK_INT == 17) {
DisplayInfo di = IDisplayManager.Stub.asInterface((IBinder) getServiceMethod.invoke(null, new Object[]{"display"})).getDisplayInfo(0);
displaySize.x = ((Integer) DisplayInfo.class.getDeclaredField("logicalWidth").get(di)).intValue();
@@ -42,13 +42,13 @@ public class SurfaceControlVirtualDisplayFactory implements VirtualDisplayFactor
} else {
wm = Stub.asInterface((IBinder) getServiceMethod.invoke(null, new Object[]{"window"}));
wm.getRealDisplaySize(displaySize);
rotation = wm.getRotation();
}
if ((rotate && rotation == 1) || rotation == 3) {
int swap = displaySize.x;
displaySize.x = displaySize.y;
displaySize.y = swap;
// rotation = wm.getRotation();
}
// if ((rotate && rotation == 1) || rotation == 3) {
// int swap = displaySize.x;
// displaySize.x = displaySize.y;
// displaySize.y = swap;
// }
return displaySize;
} catch (Exception e) {
throw new AssertionError(e);