去除屏幕方向判断,兼容Android8.0

This commit is contained in:
wanjian
2018-08-25 14:44:52 +08:00
parent 7d306fc743
commit 47d27c9542
5 changed files with 53 additions and 36 deletions

BIN
Main.dex

Binary file not shown.

View File

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

View File

@@ -10,7 +10,7 @@ import android.os.IBinder;
public interface IWindowManager { public interface IWindowManager {
void getInitialDisplaySize(int i, Point displaySize); void getInitialDisplaySize(int i, Point displaySize);
int getRotation(); // int getRotation();
void getRealDisplaySize(Point displaySize); 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 { public static void main(String[] args) throws ClassNotFoundException, NoSuchMethodException, InvocationTargetException, IllegalAccessException, IOException {
System.out.println("start!"); 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"); LocalServerSocket serverSocket = new LocalServerSocket("puppet-ver1");
init(); init();
@@ -51,6 +59,7 @@ public class Main {
LocalSocket socket = serverSocket.accept(); LocalSocket socket = serverSocket.accept();
acceptConnect(socket); acceptConnect(socket);
} catch (Exception e) { } catch (Exception e) {
System.out.println(e.getMessage());
serverSocket = new LocalServerSocket("puppet-ver1"); serverSocket = new LocalServerSocket("puppet-ver1");
} }
@@ -93,8 +102,8 @@ public class Main {
outputStream.write(byteArrayOutputStream.toByteArray()); outputStream.write(byteArrayOutputStream.toByteArray());
outputStream.flush(); outputStream.flush();
} }
} catch (Exception e) { } catch (Throwable e) {
e.printStackTrace(); System.out.println(e.getMessage());
} }
} }
}.start(); }.start();
@@ -126,7 +135,7 @@ public class Main {
return; return;
} }
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); System.out.println(e.getMessage());
return; return;
} }
try { try {
@@ -146,13 +155,13 @@ public class Main {
scale = Float.parseFloat(line.substring(DEGREE.length())) / 100; scale = Float.parseFloat(line.substring(DEGREE.length())) / 100;
} }
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); System.out.println(e.getMessage());
} }
} }
} catch (Exception e) { } catch (Throwable e) {
e.printStackTrace(); System.out.println(e.getMessage());
} }
} }
@@ -165,7 +174,7 @@ public class Main {
try { try {
touchUp(point.x, point.y); touchUp(point.x, point.y);
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); System.out.println(e.getMessage());
} }
} }
} }
@@ -176,7 +185,7 @@ public class Main {
try { try {
touchMove(point.x, point.y); touchMove(point.x, point.y);
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); System.out.println(e.getMessage());
} }
} }
} }
@@ -187,7 +196,7 @@ public class Main {
try { try {
touchDown(point.x, point.y); touchDown(point.x, point.y);
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); System.out.println(e.getMessage());
} }
} }
} }
@@ -203,7 +212,7 @@ public class Main {
point.y *= scaleY; point.y *= scaleY;
return point; return point;
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); System.out.println(e.getMessage());
} }
return null; 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)}); 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;
} // }
Matrix m = new Matrix(); Matrix m = new Matrix();
if (rotation == 1) { // if (rotation == 1) {
m.postRotate(-90.0f); // m.postRotate(-90.0f);
} else if (rotation == 2) { // } else if (rotation == 2) {
m.postRotate(-180.0f); // m.postRotate(-180.0f);
} else if (rotation == 3) { // } else if (rotation == 3) {
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);
} }

View File

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