Skip to content

Commit

Permalink
更新V1.5.2
Browse files Browse the repository at this point in the history
V1.5.x将是V1版本最后的版本,不再进行功能性更新,只修复Bug

- 修复崩溃问题
- 缩放UI,便于使用
- 提高稳定性
- 优化连接问题
- 支持分开记忆横竖屏小窗大小和位置
  • Loading branch information
mingzhixian committed Apr 16, 2024
1 parent c355de4 commit c33a27f
Show file tree
Hide file tree
Showing 17 changed files with 232 additions and 151 deletions.
4 changes: 2 additions & 2 deletions easycontrol/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -89,18 +90,21 @@ 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);
// 关闭组件
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);
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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":
Expand All @@ -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);
}
}

Expand Down Expand Up @@ -176,6 +180,7 @@ private synchronized void changeToSmall() {
} else {
if (smallView == null) smallView = new SmallView(device.uuid);
AppData.uiHandler.post(smallView::show);
updateSite(null);
}
}

Expand Down Expand Up @@ -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<Integer, Integer> 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;
// 横向最大不会超出
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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;
Expand All @@ -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());
Expand All @@ -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);
}
}
}
Expand All @@ -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));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
}));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand All @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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());
}
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
Expand Down
Loading

0 comments on commit c33a27f

Please sign in to comment.