Skip to content

Commit d44784a

Browse files
committed
Update to version 2.0.0 with new features
Finished features: - Video bit rate option - Max mirroring size option - Video mirroring toggle - Device screen toggle - Stay awake mode toggle Upcoming feature: - Video recording toggle - Audio recording toggle - TCP/IP connection mode
1 parent 7c5db33 commit d44784a

File tree

3 files changed

+486
-73
lines changed

3 files changed

+486
-73
lines changed

src/Scrcpy_GUI.java

+113-16
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,12 @@
33
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Main.java to edit this template
44
*/
55

6-
import java.io.*;
6+
import java.io.BufferedReader;
7+
import java.io.IOException;
8+
import java.io.InputStreamReader;
79
import java.util.*;
10+
import java.util.regex.Matcher;
11+
import java.util.regex.Pattern;
812

913
/**
1014
*
@@ -13,9 +17,9 @@
1317
public class Scrcpy_GUI {
1418

1519
/**
16-
* Method to list devices connected to the computer,
17-
* this method execute {@code adb devices} command using ProcessBuilder.
18-
*
20+
* Method to list devices connected to the computer, this method execute
21+
* {@code adb devices} command using ProcessBuilder.
22+
*
1923
* @return {@code List<String> output}
2024
* @author opelooo
2125
*/
@@ -44,12 +48,13 @@ public static List<String> adb_devices() {
4448

4549
return output;
4650
}
47-
51+
4852
/**
49-
* Method to run scrcpy,
50-
* this method execute {@code scrcpy -s device_code -m 1024 -b 2M} command using ProcessBuilder.
51-
*
53+
* Method to run scrcpy, this method execute
54+
* {@code scrcpy -s device_code -m 1024 -b 2M} command using ProcessBuilder.
55+
*
5256
* @param device_code device ID from adb devices list
57+
*
5358
* @author opelooo
5459
*/
5560
public static void run_scrcpy(String device_code) {
@@ -68,20 +73,67 @@ public static void run_scrcpy(String device_code) {
6873
}
6974
}).start(); // Start the new thread
7075
}
71-
76+
77+
/**
78+
* Method to customize run scrcpy, this method execute
79+
* {@code scrcpy -s device_code -m 1024 -b 2M} command using ProcessBuilder.
80+
*
81+
* @param device_code device ID from adb devices list
82+
* @param maxSize maximum size of mirroring panel
83+
* @param bitRate bit rate transfer for mirroring
84+
* @param videoOn toggle mirror the video
85+
* @param screenOn toggle phone screen on or off
86+
* @param stayAwake toggle option to stay awake mode
87+
*
88+
* @author opelooo
89+
*/
90+
public static void custom_run_scrcpy(
91+
String device_code, String maxSize, String bitRate,
92+
boolean videoOn, boolean screenOn, boolean stayAwake) {
93+
new Thread(() -> {
94+
try {
95+
// creating list of process
96+
List<String> list = new ArrayList<>();
97+
list.add("scrcpy");
98+
list.add("-s");
99+
list.add(device_code);
100+
list.add(String.format("-m %s", maxSize));
101+
list.add(String.format("-b %s", bitRate));
102+
103+
if (!videoOn) {
104+
list.add("--no-video");
105+
}
106+
if (!screenOn) {
107+
list.add("--turn-screen-off");
108+
}
109+
if (stayAwake) {
110+
list.add("--stay-awake");
111+
}
112+
113+
// Create a process
114+
ProcessBuilder pb = new ProcessBuilder(list);
115+
116+
pb.start();
117+
// Optionally, monitor the process if needed
118+
} catch (IOException e) {
119+
e.printStackTrace(); // Handle exceptions properly
120+
}
121+
}).start(); // Start the new thread
122+
}
123+
72124
/**
73-
* Method to get device info product manufaturer,
74-
* this method execute
75-
* {@code adb -s device_code shell getprop ro.product.manufacturer} command using ProcessBuilder.
76-
*
125+
* Method to get device info product manufaturer, this method execute
126+
* {@code adb -s device_code shell getprop ro.product.manufacturer} command
127+
* using ProcessBuilder.
128+
*
77129
* @param device_code device ID from adb devices list
78-
* @return {@code String output}
130+
* @return {@code String output}
79131
* @author opelooo
80132
*/
81133
public static String adb_device_info(String device_code) {
82134
String output = new String();
83135
try {
84-
// Create a process to execute 'adb devices'
136+
// Create a process
85137
ProcessBuilder pb
86138
= new ProcessBuilder(
87139
"adb", "-s", device_code, "shell",
@@ -107,9 +159,54 @@ public static String adb_device_info(String device_code) {
107159

108160
return output;
109161
}
162+
163+
/**
164+
* Method to get device info IP Address, this method execute
165+
* {@code adb -s device_code shell ip route} command
166+
* using ProcessBuilder. After that, the output filtered using regex.
167+
*
168+
* @param device_code device ID from adb devices list
169+
* @return {@code String device_ip_addr}
170+
* @author opelooo
171+
*/
172+
public static String adb_get_device_ip(String device_code) {
173+
String device_ip_addr = new String();
174+
try {
175+
// Create a process to execute 'adb devices'
176+
ProcessBuilder pb
177+
= new ProcessBuilder(
178+
"adb", "-s", device_code, "shell",
179+
"ip", "route"
180+
);
181+
Process process = pb.start();
110182

111-
public static void adb_connect_tcpip() {
183+
String regex = "src (\\b(?:\\d{1,3}\\.){3}\\d{1,3}\\b)";
184+
185+
BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream()));
186+
String line;
187+
188+
while ((line = reader.readLine()) != null) {
189+
// Compile the pattern and create a matcher
190+
Pattern pattern = Pattern.compile(regex);
191+
Matcher matcher = pattern.matcher(line.trim());
192+
193+
// If an IP address is found, assign it to device_ip_addr
194+
if (line.contains("wlan") && matcher.find()) {
195+
device_ip_addr = matcher.group(1);
196+
}
197+
}
198+
199+
// Wait for the process to complete
200+
process.waitFor();
201+
} catch (IOException | InterruptedException e) {
202+
e.printStackTrace(); // Handle exceptions properly
203+
}
204+
205+
return device_ip_addr;
206+
}
112207

208+
public static void adb_connect_tcpip(String device_code) {
209+
113210
}
114211

115212
}

0 commit comments

Comments
 (0)