Skip to content

Commit a036bf5

Browse files
committed
优化 应用流转宽高比例自由缩放
1 parent d1df4b7 commit a036bf5

File tree

1 file changed

+40
-6
lines changed
  • easycontrol/app/src/main/java/top/eiyooooo/easycontrol/app/client/view

1 file changed

+40
-6
lines changed

easycontrol/app/src/main/java/top/eiyooooo/easycontrol/app/client/view/SmallView.java

Lines changed: 40 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,8 @@ public SmallView(ClientView clientView) {
7373
clientView.device.small_l_p_height = shortEdge * 4 / 5;
7474
clientView.device.small_l_l_width = longEdge * 4 / 5;
7575
clientView.device.small_l_l_height = shortEdge * 4 / 5;
76-
clientView.device.small_free_width = shortEdge * 4 / 5;
77-
clientView.device.small_free_height = longEdge * 4 / 5;
76+
clientView.device.small_free_width = shortEdge * 2 / 5;
77+
clientView.device.small_free_height = shortEdge * 3 / 5;
7878
}
7979
// 设置监听控制
8080
setFloatVideoListener();
@@ -87,12 +87,19 @@ public SmallView(ClientView clientView) {
8787
if (InitSize < 2) return;
8888

8989
if (clientView.mode == 1 && clientView.device.setResolution) {
90+
boolean checkPosition = false;
9091
if (clientView.device.small_free_x == 0 && clientView.device.small_free_y == 0) {
9192
clientView.updateMaxSize(new Pair<>(clientView.device.small_free_width, clientView.device.small_free_height));
9293
ViewGroup.LayoutParams layoutParams = clientView.textureView.getLayoutParams();
93-
smallViewParams.x = clientView.device.small_free_x = (shortEdge - layoutParams.width) / 2;
94-
smallViewParams.y = clientView.device.small_free_y = (longEdge - layoutParams.height) / 2;
94+
if (LocalIsPortrait()) {
95+
smallViewParams.x = clientView.device.small_free_x = (shortEdge - layoutParams.width) / 2;
96+
smallViewParams.y = clientView.device.small_free_y = (longEdge - layoutParams.height) / 2;
97+
} else {
98+
smallViewParams.x = clientView.device.small_free_x = (longEdge - layoutParams.width) / 2;
99+
smallViewParams.y = clientView.device.small_free_y = (shortEdge - layoutParams.height) / 2;
100+
}
95101
AppData.windowManager.updateViewLayout(smallView.getRoot(), smallViewParams);
102+
checkPosition = true;
96103
InitPos = true;
97104
}
98105

@@ -106,8 +113,35 @@ public SmallView(ClientView clientView) {
106113
smallViewParams.y = clientView.device.small_free_y;
107114
AppData.windowManager.updateViewLayout(smallView.getRoot(), smallViewParams);
108115
clientView.updateMaxSize(new Pair<>(clientView.device.small_free_width, clientView.device.small_free_height));
116+
checkPosition = true;
109117
InitPos = true;
110118
}
119+
120+
boolean LocalIsPortrait = LocalIsPortrait();
121+
if (checkPosition || LocalIsPortrait != LastLocalIsPortrait) {
122+
LastLocalIsPortrait = LocalIsPortrait;
123+
view.postDelayed(() -> {
124+
int[] location = new int[2];
125+
view.getLocationOnScreen(location);
126+
int viewRight = location[0] + view.getWidth();
127+
int viewBottom = location[1] + view.getHeight();
128+
int width, height;
129+
if (LocalIsPortrait) {
130+
width = shortEdge;
131+
height = longEdge;
132+
} else {
133+
width = longEdge;
134+
height = shortEdge;
135+
}
136+
if (location[0] < 0 || location[1] < 0 || viewRight > width || viewBottom > height) {
137+
clientView.device.small_free_x = 0;
138+
clientView.device.small_free_y = 0;
139+
clientView.device.small_free_width = shortEdge * 2 / 5;
140+
clientView.device.small_free_height = shortEdge * 3 / 5;
141+
clientView.updateMaxSize(clientView.getMaxSize());
142+
}
143+
}, 500);
144+
}
111145
return;
112146
}
113147

@@ -395,8 +429,8 @@ private void setButtonListener(ControlPacket controlPacket) {
395429
clientView.device.small_l_p_height = shortEdge * 4 / 5;
396430
clientView.device.small_l_l_width = longEdge * 4 / 5;
397431
clientView.device.small_l_l_height = shortEdge * 4 / 5;
398-
clientView.device.small_free_width = shortEdge * 4 / 5;
399-
clientView.device.small_free_height = longEdge * 4 / 5;
432+
clientView.device.small_free_width = shortEdge * 2 / 5;
433+
clientView.device.small_free_height = shortEdge * 3 / 5;
400434
clientView.updateMaxSize(clientView.getMaxSize());
401435
barViewTimer();
402436
});

0 commit comments

Comments
 (0)