From c33a27f41687aac7cb6f429f5e685335c8033aa6 Mon Sep 17 00:00:00 2001 From: mingzhixian123 Date: Tue, 16 Apr 2024 12:09:41 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0V1.5.2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit V1.5.x将是V1版本最后的版本,不再进行功能性更新,只修复Bug - 修复崩溃问题 - 缩放UI,便于使用 - 提高稳定性 - 优化连接问题 - 支持分开记忆横竖屏小窗大小和位置 --- easycontrol/app/build.gradle | 4 +- .../saymzx/easycontrol/app/UsbActivity.java | 8 ++- .../saymzx/easycontrol/app/client/Client.java | 12 ++-- .../app/client/tools/ClientController.java | 34 ++++++++- .../app/client/tools/ClientStream.java | 15 ++-- .../app/client/view/FullActivity.java | 5 +- .../app/client/view/SmallView.java | 32 ++++++--- .../saymzx/easycontrol/app/entity/Device.java | 6 ++ .../easycontrol/app/helper/DbHelper.java | 20 +++++- .../app/helper/MyBroadcastReceiver.java | 23 ++++--- .../main/res/layout-land/activity_full.xml | 67 +++++++++--------- .../app/src/main/res/layout/activity_full.xml | 69 +++++++++---------- .../src/main/res/layout/module_small_view.xml | 48 ++++++------- .../top/saymzx/easycontrol/server/Server.java | 2 +- .../easycontrol/server/entity/Device.java | 5 +- .../server/helper/ControlPacket.java | 4 +- .../server/wrappers/WindowManager.java | 29 +++++--- 17 files changed, 232 insertions(+), 151 deletions(-) diff --git a/easycontrol/app/build.gradle b/easycontrol/app/build.gradle index bc56bd0c..fe7d95e8 100644 --- a/easycontrol/app/build.gradle +++ b/easycontrol/app/build.gradle @@ -10,8 +10,8 @@ android { applicationId "top.saymzx.easycontrol.app" minSdk 21 targetSdk 34 - versionCode 10406 - versionName "1.4.6" + versionCode 10502 + versionName "1.5.2" ndk { abiFilters "arm64-v8a", "armeabi-v7a", "x86", "x86_64" } diff --git a/easycontrol/app/src/main/java/top/saymzx/easycontrol/app/UsbActivity.java b/easycontrol/app/src/main/java/top/saymzx/easycontrol/app/UsbActivity.java index 4c9e8d29..a6da3864 100644 --- a/easycontrol/app/src/main/java/top/saymzx/easycontrol/app/UsbActivity.java +++ b/easycontrol/app/src/main/java/top/saymzx/easycontrol/app/UsbActivity.java @@ -16,10 +16,12 @@ public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); SharedPreferences sharedPreferences = this.getSharedPreferences("setting", Context.MODE_PRIVATE); if (sharedPreferences.getBoolean("isActive", false)) { - Intent intent = new Intent(); - intent.setAction(MyBroadcastReceiver.ACTION_UPDATE_USB); - sendBroadcast(intent); if (AppData.mainActivity == null) startActivity(new Intent(this, MainActivity.class)); + else { + Intent intent = new Intent(); + intent.setAction(MyBroadcastReceiver.ACTION_UPDATE_USB); + sendBroadcast(intent); + } } finish(); } diff --git a/easycontrol/app/src/main/java/top/saymzx/easycontrol/app/client/Client.java b/easycontrol/app/src/main/java/top/saymzx/easycontrol/app/client/Client.java index c2a25474..8c9834c6 100644 --- a/easycontrol/app/src/main/java/top/saymzx/easycontrol/app/client/Client.java +++ b/easycontrol/app/src/main/java/top/saymzx/easycontrol/app/client/Client.java @@ -15,6 +15,7 @@ import top.saymzx.easycontrol.app.databinding.ItemLoadingBinding; import top.saymzx.easycontrol.app.entity.AppData; import top.saymzx.easycontrol.app.entity.Device; +import top.saymzx.easycontrol.app.helper.PublicTools; import top.saymzx.easycontrol.app.helper.ViewTools; public class Client { @@ -89,6 +90,9 @@ private void close(ByteBuffer byteBuffer) { isClosed = true; // 临时设备 boolean isTempDevice = device.isTempDevice(); + // 更新数据库 + if (!isTempDevice) AppData.dbHelper.update(device); + allClient.remove(device.uuid); // 运行断开时操作 if (!isTempDevice && device.lockOnClose) clientController.handleAction("buttonLock", null, 0); else if (!isTempDevice && device.lightOnClose) clientController.handleAction("buttonLight", null, 0); @@ -96,11 +100,11 @@ private void close(ByteBuffer byteBuffer) { if (clientPlayer != null) clientPlayer.close(); if (clientController != null) clientController.close(); if (clientStream != null) clientStream.close(); - // 更新数据库 - if (!isTempDevice) AppData.dbHelper.update(device); - allClient.remove(device.uuid); // 如果设置了自动重连 - if (byteBuffer != null && device.reconnectOnClose) startDevice(device); + if (byteBuffer != null) { + PublicTools.logToast("Client", new String(byteBuffer.array()), true); + if (device.reconnectOnClose) startDevice(device); + } } } diff --git a/easycontrol/app/src/main/java/top/saymzx/easycontrol/app/client/tools/ClientController.java b/easycontrol/app/src/main/java/top/saymzx/easycontrol/app/client/tools/ClientController.java index 64f76233..7b92f1dc 100644 --- a/easycontrol/app/src/main/java/top/saymzx/easycontrol/app/client/tools/ClientController.java +++ b/easycontrol/app/src/main/java/top/saymzx/easycontrol/app/client/tools/ClientController.java @@ -19,6 +19,7 @@ import androidx.annotation.NonNull; import java.nio.ByteBuffer; +import java.nio.charset.StandardCharsets; import java.util.Objects; import java.util.UUID; import java.util.regex.Matcher; @@ -122,6 +123,9 @@ private void handleAction(String action, ByteBuffer byteBuffer) { case "checkClipBoard": checkClipBoard(); break; + case "updateSite": + updateSite(byteBuffer); + break; default: if (byteBuffer == null) break; case "writeByteBuffer": @@ -141,8 +145,8 @@ private void handleAction(String action, ByteBuffer byteBuffer) { break; } } catch (Exception ignored) { - PublicTools.logToast("controller", AppData.applicationContext.getString(R.string.toast_stream_closed) + action, true); - Client.sendAction(device.uuid, "close", ByteBuffer.allocate(1), 0); + byte[] err = ("controller" + AppData.applicationContext.getString(R.string.toast_stream_closed) + action).getBytes(StandardCharsets.UTF_8); + Client.sendAction(device.uuid, "close", ByteBuffer.wrap(err), 0); } } @@ -176,6 +180,7 @@ private synchronized void changeToSmall() { } else { if (smallView == null) smallView = new SmallView(device.uuid); AppData.uiHandler.post(smallView::show); + updateSite(null); } } @@ -246,12 +251,37 @@ private void updateVideoSize(ByteBuffer byteBuffer) { int height = byteBuffer.getInt(); if (width <= 100 || height <= 100) return; this.videoSize = new Pair<>(width, height); + updateSite(null); AppData.uiHandler.post(this::reCalculateTextureViewSize); } + private void updateSite(ByteBuffer byteBuffer) { + if (smallView == null || videoSize == null || !smallView.isShow()) return; + int x; + int y; + boolean isAuto = byteBuffer == null; + if (videoSize.first < videoSize.second) { + x = isAuto ? device.smallX : byteBuffer.getInt(); + y = isAuto ? device.smallY : byteBuffer.getInt(); + device.smallX = x; + device.smallY = y; + } else { + x = isAuto ? device.smallXLan : byteBuffer.getInt(); + y = isAuto ? device.smallYLan : byteBuffer.getInt(); + device.smallXLan = x; + device.smallYLan = y; + } + AppData.uiHandler.post(() -> smallView.updateView(x, y)); + } + // 重新计算TextureView大小 private void reCalculateTextureViewSize() { if (maxSize == null || videoSize == null) return; + Pair maxSize = this.maxSize; + if (smallView != null && smallView.isShow()) { + if (videoSize.first < videoSize.second) maxSize = new Pair<>(this.maxSize.first, this.maxSize.first); + else maxSize = new Pair<>(this.maxSize.second, this.maxSize.second); + } // 根据原画面大小videoSize计算在maxSize空间内的最大缩放大小 int tmp1 = videoSize.second * maxSize.first / videoSize.first; // 横向最大不会超出 diff --git a/easycontrol/app/src/main/java/top/saymzx/easycontrol/app/client/tools/ClientStream.java b/easycontrol/app/src/main/java/top/saymzx/easycontrol/app/client/tools/ClientStream.java index 46df03e3..1055583d 100644 --- a/easycontrol/app/src/main/java/top/saymzx/easycontrol/app/client/tools/ClientStream.java +++ b/easycontrol/app/src/main/java/top/saymzx/easycontrol/app/client/tools/ClientStream.java @@ -34,11 +34,13 @@ public class ClientStream { private static final boolean supportH265 = DecodecTools.isSupportH265(); private static final boolean supportOpus = DecodecTools.isSupportOpus(); + private static final int timeoutDelay = 1000 * 15; + public ClientStream(Device device, MyInterface.MyFunctionBoolean handle) { // 超时 Thread timeOutThread = new Thread(() -> { try { - Thread.sleep(5 * 1000); + Thread.sleep(timeoutDelay); PublicTools.logToast("stream", AppData.applicationContext.getString(R.string.toast_timeout), true); handle.run(false); if (connectThread != null) connectThread.interrupt(); @@ -87,6 +89,7 @@ private void startServer(Device device) throws Exception { private void connectServer(Device device) throws Exception { Thread.sleep(50); int reTry = 40; + int reTryTime = timeoutDelay / reTry; if (!device.isLinkDevice()) { long startTime = System.currentTimeMillis(); boolean mainConn = false; @@ -95,11 +98,11 @@ private void connectServer(Device device) throws Exception { try { if (!mainConn) { mainSocket = new Socket(); - mainSocket.connect(inetSocketAddress, 5000); + mainSocket.connect(inetSocketAddress, timeoutDelay / 2); mainConn = true; } videoSocket = new Socket(); - videoSocket.connect(inetSocketAddress, 3000); + videoSocket.connect(inetSocketAddress, timeoutDelay / 2); mainOutputStream = mainSocket.getOutputStream(); mainDataInputStream = new DataInputStream(mainSocket.getInputStream()); videoDataInputStream = new DataInputStream(videoSocket.getInputStream()); @@ -109,8 +112,8 @@ private void connectServer(Device device) throws Exception { if (mainSocket != null) mainSocket.close(); if (videoSocket != null) videoSocket.close(); // 如果超时,直接跳出循环 - if (System.currentTimeMillis() - startTime >= 4000) i = reTry; - else Thread.sleep(50); + if (System.currentTimeMillis() - startTime >= timeoutDelay / 2 - 1000) i = reTry; + else Thread.sleep(reTryTime); } } } @@ -122,7 +125,7 @@ private void connectServer(Device device) throws Exception { if (videoBufferStream == null) videoBufferStream = adb.tcpForward(device.serverPort); return; } catch (Exception ignored) { - Thread.sleep(50); + Thread.sleep(reTryTime); } } throw new Exception(AppData.applicationContext.getString(R.string.toast_connect_server)); diff --git a/easycontrol/app/src/main/java/top/saymzx/easycontrol/app/client/view/FullActivity.java b/easycontrol/app/src/main/java/top/saymzx/easycontrol/app/client/view/FullActivity.java index 9e60b10a..f4173838 100644 --- a/easycontrol/app/src/main/java/top/saymzx/easycontrol/app/client/view/FullActivity.java +++ b/easycontrol/app/src/main/java/top/saymzx/easycontrol/app/client/view/FullActivity.java @@ -135,7 +135,7 @@ private void setButtonListener() { clientController.handleAction(light ? "buttonLight" : "buttonLightOff", null, 0); changeBarView(); }); - activityFullBinding.bar.setOnClickListener(v -> changeBarView()); + activityFullBinding.buttonMore.setOnClickListener(v -> changeBarView()); activityFullBinding.buttonAutoRotate.setOnClickListener(v -> { autoRotate = !autoRotate; AppData.setting.setAutoRotate(autoRotate); @@ -152,7 +152,8 @@ private void setNavBarHide(boolean isShow) { private void changeBarView() { boolean toShowView = activityFullBinding.barView.getVisibility() == View.GONE; - ViewTools.viewAnim(activityFullBinding.barView, toShowView, PublicTools.dp2px(40f), 0, (isStart -> { + boolean isLandscape = lastOrientation == ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE || lastOrientation == ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE; + ViewTools.viewAnim(activityFullBinding.barView, toShowView, 0, PublicTools.dp2px(40f) * (isLandscape ? -1 : 1), (isStart -> { if (isStart && toShowView) activityFullBinding.barView.setVisibility(View.VISIBLE); else if (!isStart && !toShowView) activityFullBinding.barView.setVisibility(View.GONE); })); diff --git a/easycontrol/app/src/main/java/top/saymzx/easycontrol/app/client/view/SmallView.java b/easycontrol/app/src/main/java/top/saymzx/easycontrol/app/client/view/SmallView.java index 5f6ba0a6..6bed4173 100644 --- a/easycontrol/app/src/main/java/top/saymzx/easycontrol/app/client/view/SmallView.java +++ b/easycontrol/app/src/main/java/top/saymzx/easycontrol/app/client/view/SmallView.java @@ -74,7 +74,7 @@ public void show() { smallView.barView.setVisibility(View.GONE); smallViewParams.x = device.smallX; smallViewParams.y = device.smallY; - updateMaxSize(device.smallLength, device.smallLength); + updateMaxSize(); if (!Objects.equals(device.startApp, "")) { smallView.buttonHome.setVisibility(View.GONE); smallView.buttonSwitch.setVisibility(View.GONE); @@ -214,28 +214,40 @@ private void setReSizeListener() { int sizeX = (int) (event.getRawX() - smallViewParams.x); int sizeY = (int) (event.getRawY() - smallViewParams.y); int length = Math.max(sizeX, sizeY); - updateMaxSize(length, length); + ViewGroup.LayoutParams textureViewLayoutParams = clientController.getTextureView().getLayoutParams(); + if (textureViewLayoutParams.width < textureViewLayoutParams.height) device.smallLength = length; + else device.smallLengthLan = length; + updateMaxSize(); return true; }); } private void updateSite(int x, int y) { - device.smallX = x; - device.smallY = y; + ByteBuffer byteBuffer = ByteBuffer.allocate(8); + byteBuffer.putInt(x); + byteBuffer.putInt(y); + byteBuffer.flip(); + clientController.handleAction("updateSite", byteBuffer, 0); + } + + public void updateView(int x, int y) { smallViewParams.x = x; smallViewParams.y = y; AppData.windowManager.updateViewLayout(smallView.getRoot(), smallViewParams); } - private void updateMaxSize(int w, int h) { - device.smallLength = w; + private void updateMaxSize() { ByteBuffer byteBuffer = ByteBuffer.allocate(8); - byteBuffer.putInt(w); - byteBuffer.putInt(h); + byteBuffer.putInt(device.smallLength); + byteBuffer.putInt(device.smallLengthLan); byteBuffer.flip(); clientController.handleAction("updateMaxSize", byteBuffer, 0); } + public boolean isShow() { + return isShow; + } + // 设置键盘监听 private void setKeyEvent() { smallView.editText.setInputType(InputType.TYPE_NULL); @@ -262,7 +274,9 @@ public void checkSizeAndSite() { // 检测到大小超出 if (width > screenMaxWidth + 200 || height > screenMaxHeight + 200) { int maxLength = Math.min(screenMaxWidth, screenMaxHeight); - updateMaxSize(maxLength, maxLength); + if (width < height) device.smallLength = maxLength; + else device.smallLengthLan = maxLength; + updateMaxSize(); updateSite(0, statusBarHeight); return; } diff --git a/easycontrol/app/src/main/java/top/saymzx/easycontrol/app/entity/Device.java b/easycontrol/app/src/main/java/top/saymzx/easycontrol/app/entity/Device.java index b169a5b9..69bb6b30 100644 --- a/easycontrol/app/src/main/java/top/saymzx/easycontrol/app/entity/Device.java +++ b/easycontrol/app/src/main/java/top/saymzx/easycontrol/app/entity/Device.java @@ -37,6 +37,9 @@ public class Device { public int smallX = 200; public int smallY = 200; public int smallLength = 800; + public int smallXLan = 200; + public int smallYLan = 200; + public int smallLengthLan = 800; public int miniY = 200; public Device(String uuid, int type) { @@ -90,6 +93,9 @@ public Device clone(String uuid) { newDevice.smallX = smallX; newDevice.smallY = smallY; newDevice.smallLength = smallLength; + newDevice.smallXLan = smallXLan; + newDevice.smallYLan = smallYLan; + newDevice.smallLengthLan = smallLengthLan; newDevice.miniY = miniY; return newDevice; } diff --git a/easycontrol/app/src/main/java/top/saymzx/easycontrol/app/helper/DbHelper.java b/easycontrol/app/src/main/java/top/saymzx/easycontrol/app/helper/DbHelper.java index 605f2937..cf5ffcfd 100644 --- a/easycontrol/app/src/main/java/top/saymzx/easycontrol/app/helper/DbHelper.java +++ b/easycontrol/app/src/main/java/top/saymzx/easycontrol/app/helper/DbHelper.java @@ -14,7 +14,7 @@ public class DbHelper extends SQLiteOpenHelper { private static final String dataBaseName = "app.db"; - private static final int version = 19; + private static final int version = 23; private final String tableName = "DevicesDb"; public DbHelper(Context context) { @@ -57,6 +57,9 @@ public void onCreate(SQLiteDatabase db) { stringBuilder.append("smallX integer,"); stringBuilder.append("smallY integer,"); stringBuilder.append("smallLength integer,"); + stringBuilder.append("smallXLan integer,"); + stringBuilder.append("smallYLan integer,"); + stringBuilder.append("smallLengthLan integer,"); stringBuilder.append("miniY integer);"); db.execSQL(stringBuilder.toString()); } @@ -151,6 +154,9 @@ private ContentValues getValues(Device device) { values.put("smallX", device.smallX); values.put("smallY", device.smallY); values.put("smallLength", device.smallLength); + values.put("smallXLan", device.smallXLan); + values.put("smallYLan", device.smallYLan); + values.put("smallLengthLan", device.smallLengthLan); values.put("miniY", device.miniY); return values; } @@ -280,6 +286,18 @@ private Device getDeviceFormCursor(Cursor cursor) { device.smallLength = cursor.getInt(i); break; } + case "smallXLan": { + device.smallXLan = cursor.getInt(i); + break; + } + case "smallYLan": { + device.smallYLan = cursor.getInt(i); + break; + } + case "smallLengthLan": { + device.smallLengthLan = cursor.getInt(i); + break; + } case "miniY": { device.miniY = cursor.getInt(i); break; diff --git a/easycontrol/app/src/main/java/top/saymzx/easycontrol/app/helper/MyBroadcastReceiver.java b/easycontrol/app/src/main/java/top/saymzx/easycontrol/app/helper/MyBroadcastReceiver.java index 683e14cf..480ea6f8 100644 --- a/easycontrol/app/src/main/java/top/saymzx/easycontrol/app/helper/MyBroadcastReceiver.java +++ b/easycontrol/app/src/main/java/top/saymzx/easycontrol/app/helper/MyBroadcastReceiver.java @@ -9,9 +9,7 @@ import android.hardware.usb.UsbDevice; import android.hardware.usb.UsbManager; import android.os.Build; -import android.util.Log; -import java.io.IOException; import java.nio.ByteBuffer; import java.util.Map; @@ -84,8 +82,10 @@ private void handleControl(Intent intent) { private void onConnectUsb(Context context, Intent intent) { UsbDevice usbDevice = intent.getParcelableExtra(UsbManager.EXTRA_DEVICE); if (usbDevice == null || AppData.usbManager == null) return; - @SuppressLint("MutableImplicitPendingIntent") PendingIntent permissionIntent = PendingIntent.getBroadcast(context, 0, new Intent(ACTION_USB_PERMISSION), PendingIntent.FLAG_MUTABLE); - AppData.usbManager.requestPermission(usbDevice, permissionIntent); + if (!AppData.usbManager.hasPermission(usbDevice)) { + @SuppressLint("MutableImplicitPendingIntent") PendingIntent permissionIntent = PendingIntent.getBroadcast(context, 0, new Intent(ACTION_USB_PERMISSION), PendingIntent.FLAG_MUTABLE); + AppData.usbManager.requestPermission(usbDevice, permissionIntent); + } } public synchronized void updateUSB() { @@ -93,9 +93,11 @@ public synchronized void updateUSB() { AdbTools.usbDevicesList.clear(); for (Map.Entry entry : AppData.usbManager.getDeviceList().entrySet()) { UsbDevice usbDevice = entry.getValue(); + if (usbDevice == null) return; if (AppData.usbManager.hasPermission(usbDevice)) { // 有线设备使用序列号作为唯一标识符 String uuid = usbDevice.getSerialNumber(); + if (uuid == null) return; // 若没有该设备,则新建设备 Device device = AppData.dbHelper.getByUUID(uuid); if (device == null) { @@ -111,14 +113,13 @@ public synchronized void updateUSB() { public synchronized void resetUSB() { if (AppData.usbManager == null) return; - for (Map.Entry entry : AppData.usbManager.getDeviceList().entrySet()) { - UsbDevice usbDevice = entry.getValue(); - if (AppData.usbManager.hasPermission(usbDevice)) { - try { - new UsbChannel(usbDevice).close(); - } catch (IOException ignored) { - } + try { + for (Map.Entry entry : AppData.usbManager.getDeviceList().entrySet()) { + UsbDevice usbDevice = entry.getValue(); + if (usbDevice == null) return; + if (AppData.usbManager.hasPermission(usbDevice)) new UsbChannel(usbDevice).close(); } + } catch (Exception ignored) { } } diff --git a/easycontrol/app/src/main/res/layout-land/activity_full.xml b/easycontrol/app/src/main/res/layout-land/activity_full.xml index 29f78078..b891fc7f 100644 --- a/easycontrol/app/src/main/res/layout-land/activity_full.xml +++ b/easycontrol/app/src/main/res/layout-land/activity_full.xml @@ -21,12 +21,12 @@ @@ -45,7 +45,7 @@ android:layout_height="0dp" android:layout_weight="2" android:focusable="false" - android:padding="6dp" + android:padding="4dp" android:src="@drawable/o" android:tint="@color/onBackground" /> @@ -55,7 +55,7 @@ android:layout_height="0dp" android:layout_weight="2" android:focusable="false" - android:padding="6dp" + android:padding="4dp" android:src="@drawable/caret_left" android:tint="@color/onBackground" /> @@ -65,7 +65,7 @@ android:layout_height="0dp" android:layout_weight="1" android:focusable="false" - android:padding="6dp" + android:padding="4dp" android:src="@drawable/un_auto" android:tint="@color/onCardBackground" /> @@ -80,37 +80,32 @@ android:orientation="horizontal" /> - - - - + android:layout_gravity="top|start" + android:focusable="false" + android:padding="4dp" + android:paddingTop="20dp" + android:src="@drawable/bars" + android:tint="@color/onCardBackground" /> + android:padding="8dp"> @@ -129,7 +124,7 @@ android:layout_height="match_parent" android:layout_weight="1" android:focusable="false" - android:padding="2dp" + android:padding="4dp" android:src="@drawable/minus" android:tint="@color/onCardBackground" /> @@ -139,7 +134,7 @@ android:layout_height="match_parent" android:layout_weight="1" android:focusable="false" - android:padding="2dp" + android:padding="4dp" android:src="@drawable/window_restore" android:tint="@color/onCardBackground" /> @@ -149,14 +144,14 @@ android:layout_height="match_parent" android:layout_weight="1" android:focusable="false" - android:padding="2dp" + android:padding="4dp" android:src="@drawable/x" android:tint="@color/alert" /> @@ -175,7 +170,7 @@ android:layout_height="match_parent" android:layout_weight="1" android:focusable="false" - android:padding="2dp" + android:padding="4dp" android:src="@drawable/not_equal" android:tint="@color/onCardBackground" /> @@ -185,7 +180,7 @@ android:layout_height="match_parent" android:layout_weight="1" android:focusable="false" - android:padding="2dp" + android:padding="4dp" android:src="@drawable/power" android:tint="@color/onCardBackground" /> @@ -195,7 +190,7 @@ android:layout_height="match_parent" android:layout_weight="1" android:focusable="false" - android:padding="2dp" + android:padding="4dp" android:src="@drawable/lightbulb_off" android:tint="@color/onCardBackground" /> diff --git a/easycontrol/app/src/main/res/layout/activity_full.xml b/easycontrol/app/src/main/res/layout/activity_full.xml index ed96d557..50dc1ae9 100644 --- a/easycontrol/app/src/main/res/layout/activity_full.xml +++ b/easycontrol/app/src/main/res/layout/activity_full.xml @@ -29,11 +29,11 @@ @@ -52,7 +52,7 @@ android:layout_height="match_parent" android:layout_weight="2" android:focusable="false" - android:padding="6dp" + android:padding="4dp" android:src="@drawable/o" android:tint="@color/onBackground" /> @@ -62,7 +62,7 @@ android:layout_height="match_parent" android:layout_weight="2" android:focusable="false" - android:padding="6dp" + android:padding="4dp" android:src="@drawable/caret_left" android:tint="@color/onBackground" /> @@ -72,44 +72,39 @@ android:layout_height="match_parent" android:layout_weight="1" android:focusable="false" - android:padding="6dp" + android:padding="4dp" android:src="@drawable/un_auto" android:tint="@color/onCardBackground" /> - - - - + + android:padding="8dp"> @@ -128,7 +123,7 @@ android:layout_height="match_parent" android:layout_weight="1" android:focusable="false" - android:padding="2dp" + android:padding="4dp" android:src="@drawable/minus" android:tint="@color/onCardBackground" /> @@ -138,7 +133,7 @@ android:layout_height="match_parent" android:layout_weight="1" android:focusable="false" - android:padding="2dp" + android:padding="4dp" android:src="@drawable/window_restore" android:tint="@color/onCardBackground" /> @@ -148,14 +143,14 @@ android:layout_height="match_parent" android:layout_weight="1" android:focusable="false" - android:padding="2dp" + android:padding="4dp" android:src="@drawable/x" android:tint="@color/alert" /> @@ -174,7 +169,7 @@ android:layout_height="match_parent" android:layout_weight="1" android:focusable="false" - android:padding="2dp" + android:padding="4dp" android:src="@drawable/not_equal" android:tint="@color/onCardBackground" /> @@ -184,7 +179,7 @@ android:layout_height="match_parent" android:layout_weight="1" android:focusable="false" - android:padding="2dp" + android:padding="4dp" android:src="@drawable/power" android:tint="@color/onCardBackground" /> @@ -194,7 +189,7 @@ android:layout_height="match_parent" android:layout_weight="1" android:focusable="false" - android:padding="2dp" + android:padding="4dp" android:src="@drawable/lightbulb_off" android:tint="@color/onCardBackground" /> diff --git a/easycontrol/app/src/main/res/layout/module_small_view.xml b/easycontrol/app/src/main/res/layout/module_small_view.xml index bae1a370..d5abab74 100644 --- a/easycontrol/app/src/main/res/layout/module_small_view.xml +++ b/easycontrol/app/src/main/res/layout/module_small_view.xml @@ -31,7 +31,7 @@ @@ -53,7 +53,7 @@ android:layout_height="match_parent" android:layout_weight="1" android:focusable="false" - android:padding="3dp" + android:padding="4dp" android:src="@drawable/o" android:tint="@color/onCardBackground" /> @@ -63,7 +63,7 @@ android:layout_height="match_parent" android:layout_weight="1" android:focusable="false" - android:padding="3dp" + android:padding="4dp" android:src="@drawable/caret_left" android:tint="@color/onCardBackground" /> @@ -72,16 +72,16 @@ @@ -92,15 +92,15 @@ android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="top|center_horizontal" - android:layout_marginTop="25dp" + android:layout_marginTop="35dp" android:background="@drawable/background_cron" android:elevation="6dp" android:orientation="vertical" - android:padding="6dp"> + android:padding="8dp"> @@ -119,7 +119,7 @@ android:layout_height="match_parent" android:layout_weight="1" android:focusable="false" - android:padding="2dp" + android:padding="4dp" android:src="@drawable/minus" android:tint="@color/onCardBackground" /> @@ -129,7 +129,7 @@ android:layout_height="match_parent" android:layout_weight="1" android:focusable="false" - android:padding="2dp" + android:padding="4dp" android:src="@drawable/expand" android:tint="@color/onCardBackground" /> @@ -139,14 +139,14 @@ android:layout_height="match_parent" android:layout_weight="1" android:focusable="false" - android:padding="2dp" + android:padding="4dp" android:src="@drawable/x" android:tint="@color/alert" /> @@ -165,7 +165,7 @@ android:layout_height="match_parent" android:layout_weight="1" android:focusable="false" - android:padding="2dp" + android:padding="4dp" android:src="@drawable/not_equal" android:tint="@color/onCardBackground" /> @@ -175,7 +175,7 @@ android:layout_height="match_parent" android:layout_weight="1" android:focusable="false" - android:padding="2dp" + android:padding="4dp" android:src="@drawable/power" android:tint="@color/onCardBackground" /> @@ -185,7 +185,7 @@ android:layout_height="match_parent" android:layout_weight="1" android:focusable="false" - android:padding="2dp" + android:padding="4dp" android:src="@drawable/lightbulb_off" android:tint="@color/onCardBackground" /> @@ -195,7 +195,7 @@ diff --git a/easycontrol/server/src/main/java/top/saymzx/easycontrol/server/Server.java b/easycontrol/server/src/main/java/top/saymzx/easycontrol/server/Server.java index 01a45f43..8283f420 100644 --- a/easycontrol/server/src/main/java/top/saymzx/easycontrol/server/Server.java +++ b/easycontrol/server/src/main/java/top/saymzx/easycontrol/server/Server.java @@ -38,7 +38,7 @@ public final class Server { private static final Object object = new Object(); - private static final int timeoutDelay = 1000 * 5; + private static final int timeoutDelay = 1000 * 20; public static void main(String... args) { try { diff --git a/easycontrol/server/src/main/java/top/saymzx/easycontrol/server/entity/Device.java b/easycontrol/server/src/main/java/top/saymzx/easycontrol/server/entity/Device.java index 11b29682..d88a91a9 100644 --- a/easycontrol/server/src/main/java/top/saymzx/easycontrol/server/entity/Device.java +++ b/easycontrol/server/src/main/java/top/saymzx/easycontrol/server/entity/Device.java @@ -237,8 +237,7 @@ private static void injectEvent(InputEvent inputEvent) { try { if (displayId != Display.DEFAULT_DISPLAY) InputManager.setDisplayId(inputEvent, displayId); InputManager.injectInputEvent(inputEvent, InputManager.INJECT_INPUT_EVENT_MODE_ASYNC); - } catch (Exception e) { - System.out.println(e.toString()); + } catch (Exception ignored) { } } @@ -272,7 +271,7 @@ public static void changePower(int mode) { public static void rotateDevice() { boolean accelerometerRotation = !WindowManager.isRotationFrozen(displayId); - WindowManager.freezeRotation((displayInfo.rotation == 0 || displayInfo.rotation == 3) ? 1 : 0, displayId); + WindowManager.freezeRotation(displayId, (displayInfo.rotation == 0 || displayInfo.rotation == 3) ? 1 : 0); if (accelerometerRotation) WindowManager.thawRotation(displayId); } diff --git a/easycontrol/server/src/main/java/top/saymzx/easycontrol/server/helper/ControlPacket.java b/easycontrol/server/src/main/java/top/saymzx/easycontrol/server/helper/ControlPacket.java index 768e7388..daefe096 100644 --- a/easycontrol/server/src/main/java/top/saymzx/easycontrol/server/helper/ControlPacket.java +++ b/easycontrol/server/src/main/java/top/saymzx/easycontrol/server/helper/ControlPacket.java @@ -3,8 +3,6 @@ */ package top.saymzx.easycontrol.server.helper; -import android.system.ErrnoException; - import java.io.IOException; import java.nio.ByteBuffer; import java.nio.charset.StandardCharsets; @@ -16,6 +14,7 @@ public final class ControlPacket { public static void sendVideoEvent(long pts, ByteBuffer data) throws IOException { int size = data.remaining() + 8; + if (size < 8) return; ByteBuffer byteBuffer = ByteBuffer.allocate(4 + size); byteBuffer.putInt(size); byteBuffer.putLong(pts); @@ -26,6 +25,7 @@ public static void sendVideoEvent(long pts, ByteBuffer data) throws IOException public static void sendAudioEvent(ByteBuffer data) throws IOException { int size = data.remaining(); + if (size < 0) return; ByteBuffer byteBuffer = ByteBuffer.allocate(5 + size); byteBuffer.put((byte) 1); byteBuffer.putInt(size); diff --git a/easycontrol/server/src/main/java/top/saymzx/easycontrol/server/wrappers/WindowManager.java b/easycontrol/server/src/main/java/top/saymzx/easycontrol/server/wrappers/WindowManager.java index 12eaf91e..6e468fdc 100644 --- a/easycontrol/server/src/main/java/top/saymzx/easycontrol/server/wrappers/WindowManager.java +++ b/easycontrol/server/src/main/java/top/saymzx/easycontrol/server/wrappers/WindowManager.java @@ -4,6 +4,7 @@ package top.saymzx.easycontrol.server.wrappers; import android.os.IInterface; +import android.view.Display; import android.view.IRotationWatcher; import java.lang.reflect.Method; @@ -40,27 +41,39 @@ public static void init(IInterface m) { public static void freezeRotation(int displayId, int rotation) { try { - if (freezeDisplayRotationMethod != null) freezeDisplayRotationMethod.invoke(manager, displayId, rotation); - else if (freezeRotationMethod != null) freezeRotationMethod.invoke(manager, rotation); + if (freezeDisplayRotationMethod == null) throw new Exception("no display"); + freezeDisplayRotationMethod.invoke(manager, displayId, rotation); } catch (Exception ignored) { + try { + if (freezeRotationMethod != null && displayId == Display.DEFAULT_DISPLAY) freezeRotationMethod.invoke(manager, rotation); + } catch (Exception ignored1) { + } } } public static boolean isRotationFrozen(int displayId) { try { - if (isDisplayRotationFrozenMethod != null) return (boolean) isDisplayRotationFrozenMethod.invoke(manager, displayId); - else if (isRotationFrozenMethod != null) return (boolean) isRotationFrozenMethod.invoke(manager); - return false; + if (isDisplayRotationFrozenMethod != null) throw new Exception("no display"); + return (boolean) isDisplayRotationFrozenMethod.invoke(manager, displayId); } catch (Exception ignored) { - return false; + try { + if (isRotationFrozenMethod != null && displayId == Display.DEFAULT_DISPLAY) return (boolean) isRotationFrozenMethod.invoke(manager); + return false; + } catch (Exception ignored1) { + return false; + } } } public static void thawRotation(int displayId) { try { - if (thawDisplayRotationMethod != null) thawDisplayRotationMethod.invoke(manager, displayId); - else if (thawRotationMethod != null) thawRotationMethod.invoke(manager); + if (thawDisplayRotationMethod != null) throw new Exception("no display"); + thawDisplayRotationMethod.invoke(manager, displayId); } catch (Exception ignored) { + try { + if (thawRotationMethod != null && displayId == Display.DEFAULT_DISPLAY) thawRotationMethod.invoke(manager); + } catch (Exception ignored1) { + } } }