|
|
@@ -40,6 +40,12 @@ import java.net.NetworkInterface;
|
|
|
import java.net.SocketException;
|
|
|
import java.util.Enumeration;
|
|
|
|
|
|
+import android.app.ProgressDialog;
|
|
|
+import android.os.Handler;
|
|
|
+import android.os.Message;
|
|
|
+import org.las2mile.okio.message.BaseMsg;
|
|
|
+import org.las2mile.okio.message.resp.HartBeatMsgResp;
|
|
|
+
|
|
|
|
|
|
public class MainActivity extends Activity implements Scrcpy.ServiceCallbacks, SensorEventListener {
|
|
|
private static final String PREFERENCE_KEY = "default";
|
|
|
@@ -69,6 +75,44 @@ public class MainActivity extends Activity implements Scrcpy.ServiceCallbacks, S
|
|
|
private LinearLayout linearLayout;
|
|
|
private static boolean no_control = false;
|
|
|
|
|
|
+ ProgressDialog mainProgressDialog = null;
|
|
|
+ static final int ADB_CONNECT_START = 1;
|
|
|
+ static final int ADB_CONNECT_REAL_START = 2;
|
|
|
+ static final int ADB_CONNECT_SUC = 3;
|
|
|
+ static final int ADB_CONNECT_FAIL = 4;
|
|
|
+ static final int ADB_CONNECT_FAIL_HIDE = 5;
|
|
|
+ static final int SERVER_ENV_PREPARED = 6;
|
|
|
+ static final int GOT_REMOTE_VERSION = 7;
|
|
|
+ Handler mainHandler = new Handler(new Handler.Callback() {
|
|
|
+ @Override
|
|
|
+ public boolean handleMessage(Message message) {
|
|
|
+ int what = message.what;
|
|
|
+ Log.e("scrcpy",mainHandler+" Asset ADB_CONNECT_SUC "+what);
|
|
|
+ if(what == ADB_CONNECT_START){
|
|
|
+ showProgress();
|
|
|
+ mainHandler.sendEmptyMessageDelayed(ADB_CONNECT_REAL_START,500);
|
|
|
+ } else if(what == ADB_CONNECT_REAL_START){
|
|
|
+ sendCommands.SendAdbCommands(context, fileBase64, serverAdr, Integer.parseInt(serverPort), local_ip, videoBitrate, Math.max(screenHeight, screenWidth));
|
|
|
+ } else if(what == ADB_CONNECT_SUC){
|
|
|
+ setProgressMsg("与公司设备连接成功,正在初始化公司设备...");
|
|
|
+ } else if(what == ADB_CONNECT_FAIL){
|
|
|
+ setProgressMsg("与公司设备连接失败, 请确认IP与端口是否正确,再次点击重连。");
|
|
|
+ mainHandler.sendEmptyMessageDelayed(ADB_CONNECT_FAIL_HIDE,2000);
|
|
|
+ } else if(what == ADB_CONNECT_FAIL_HIDE){
|
|
|
+ hideProgress();
|
|
|
+ } else if(what == SERVER_ENV_PREPARED){
|
|
|
+ setProgressMsg("公司设备初始化完成,即将投屏...");
|
|
|
+ // hideProgress();
|
|
|
+ start_screen_copy_magic();
|
|
|
+ } else if(what == GOT_REMOTE_VERSION){
|
|
|
+ hideProgress();
|
|
|
+ HartBeatMsgResp hartBeatMsgResp = (HartBeatMsgResp)message.obj;
|
|
|
+ Toast.makeText(context, hartBeatMsgResp.remoteInfo, Toast.LENGTH_SHORT).show();
|
|
|
+ }
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
private final ServiceConnection serviceConnection = new ServiceConnection() {
|
|
|
@Override
|
|
|
public void onServiceConnected(ComponentName componentName, IBinder iBinder) {
|
|
|
@@ -131,6 +175,33 @@ public class MainActivity extends Activity implements Scrcpy.ServiceCallbacks, S
|
|
|
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public void onOkIoMsg(BaseMsg baseMsg){
|
|
|
+ Message msg = new Message();
|
|
|
+ msg.what = GOT_REMOTE_VERSION;
|
|
|
+ msg.obj = baseMsg;
|
|
|
+ mainHandler.sendMessage(msg);
|
|
|
+ }
|
|
|
+
|
|
|
+ private void showProgress(){
|
|
|
+ Log.e("scrcpy","Asset showProgress");
|
|
|
+ mainProgressDialog = new ProgressDialog(context);
|
|
|
+ mainProgressDialog.setTitle("提示");
|
|
|
+ mainProgressDialog.setMessage("正在连接公司设备...");
|
|
|
+ mainProgressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
|
|
|
+ mainProgressDialog.setIndeterminate(true);
|
|
|
+ mainProgressDialog.setCancelable(false);
|
|
|
+ mainProgressDialog.setCanceledOnTouchOutside(false);
|
|
|
+ mainProgressDialog.show();
|
|
|
+ }
|
|
|
+
|
|
|
+ private void setProgressMsg(String msg){
|
|
|
+ mainProgressDialog.setMessage(msg);
|
|
|
+ }
|
|
|
+
|
|
|
+ private void hideProgress(){
|
|
|
+ mainProgressDialog.dismiss();
|
|
|
+ }
|
|
|
|
|
|
@SuppressLint("SourceLockedOrientationActivity")
|
|
|
public void scrcpy_main(){
|
|
|
@@ -146,16 +217,22 @@ public class MainActivity extends Activity implements Scrcpy.ServiceCallbacks, S
|
|
|
} catch (IOException e) {
|
|
|
Log.e("Asset Manager", e.getMessage());
|
|
|
}
|
|
|
- sendCommands = new SendCommands();
|
|
|
+ sendCommands = new SendCommands(mainHandler);
|
|
|
|
|
|
startButton.setOnClickListener(v -> {
|
|
|
local_ip = wifiIpAddress();
|
|
|
getAttributes();
|
|
|
if (!serverAdr.isEmpty()) {
|
|
|
- if (sendCommands.SendAdbCommands(context, fileBase64, serverAdr, Integer.parseInt(serverPort), local_ip, videoBitrate, Math.max(screenHeight, screenWidth)) == 0) {
|
|
|
- start_screen_copy_magic();
|
|
|
- } else {
|
|
|
- Toast.makeText(context, "Network OR ADB connection failed", Toast.LENGTH_SHORT).show();
|
|
|
+ //原生逻辑
|
|
|
+ // if (sendCommands.SendAdbCommands(context, fileBase64, serverAdr, Integer.parseInt(serverPort), local_ip, videoBitrate, Math.max(screenHeight, screenWidth)) == 0) {
|
|
|
+ // start_screen_copy_magic();
|
|
|
+ // } else {
|
|
|
+ // Toast.makeText(context, "Network OR ADB connection failed", Toast.LENGTH_SHORT).show();
|
|
|
+ // }
|
|
|
+
|
|
|
+ //开始与adbd建立连接
|
|
|
+ if(first_time){
|
|
|
+ mainHandler.sendEmptyMessage(ADB_CONNECT_START);
|
|
|
}
|
|
|
} else {
|
|
|
Toast.makeText(context, "Server Address Empty", Toast.LENGTH_SHORT).show();
|
|
|
@@ -210,6 +287,7 @@ public class MainActivity extends Activity implements Scrcpy.ServiceCallbacks, S
|
|
|
}
|
|
|
float remote_device_aspect_ratio = remote_device_height/remote_device_width;
|
|
|
|
|
|
+ //改变渲染的边距
|
|
|
if (!landscape) { //Portrait
|
|
|
float this_device_aspect_ratio = this_dev_height/this_dev_width;
|
|
|
if (remote_device_aspect_ratio > this_device_aspect_ratio) {
|
|
|
@@ -296,8 +374,8 @@ public class MainActivity extends Activity implements Scrcpy.ServiceCallbacks, S
|
|
|
|
|
|
@SuppressLint("ClickableViewAccessibility")
|
|
|
private void start_screen_copy_magic() {
|
|
|
-// Log.e("Scrcpy: ","Starting scrcpy service");
|
|
|
- setContentView(R.layout.surface);
|
|
|
+ Log.e("Scrcpy: ","Starting scrcpy service");
|
|
|
+ setContentView(R.layout.surface);//开始渲染
|
|
|
final View decorView = getWindow().getDecorView();
|
|
|
decorView.setSystemUiVisibility(
|
|
|
View.SYSTEM_UI_FLAG_LAYOUT_STABLE
|