去除屏幕方向判断,兼容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 {
JLabel label;
boolean isMove = false;
JLabel tips;
public Client() throws IOException {
setLayout(new BorderLayout(0, 0));
@@ -45,7 +46,13 @@ 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);
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);
@@ -155,6 +162,7 @@ public class Client extends JFrame {
public void stateChanged(ChangeEvent changeEvent) {
try {
int v = ((JSlider) changeEvent.getSource()).getValue();
tips.setText("清晰度 " + v + "%");
writer.write("DEGREE" + v);
writer.newLine();
writer.flush();

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);