From 33e32527525127e1e137561d598c8eb8ad6772d9 Mon Sep 17 00:00:00 2001 From: Roberto Viola Date: Sun, 23 Jun 2024 09:48:39 +0200 Subject: [PATCH 01/13] trying to fix non distance mode #9 --- .../android_remote/MainActivity.java | 42 ++++++++++++------- 1 file changed, 26 insertions(+), 16 deletions(-) diff --git a/app/src/main/java/org/cagnulein/android_remote/MainActivity.java b/app/src/main/java/org/cagnulein/android_remote/MainActivity.java index 879f08c..2581dcc 100644 --- a/app/src/main/java/org/cagnulein/android_remote/MainActivity.java +++ b/app/src/main/java/org/cagnulein/android_remote/MainActivity.java @@ -288,28 +288,38 @@ public void set_display_nd_touch() { if (landscape){ this_dev_width = this_dev_width - 96; }else { //100 is the height of nav bar but need multiples of 8. - this_dev_height = this_dev_height - 96; + //this_dev_height = this_dev_height - 96; } } 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) { - linearLayout.setPadding((int) (((remote_device_aspect_ratio - this_device_aspect_ratio)*this_dev_width)/2),0,(int) (((remote_device_aspect_ratio - this_device_aspect_ratio)*this_dev_width)/2),0); - } else if (remote_device_aspect_ratio < this_device_aspect_ratio) { - linearLayout.setPadding(0,(int) (((this_device_aspect_ratio - remote_device_aspect_ratio)*this_dev_width)),0,0); - } - }else{ //Landscape - float this_device_aspect_ratio = this_dev_width/this_dev_height; - if (remote_device_aspect_ratio > this_device_aspect_ratio) { - linearLayout.setPadding(0,(int) (((remote_device_aspect_ratio - this_device_aspect_ratio)*this_dev_height)/2),0,(int) (((remote_device_aspect_ratio - this_device_aspect_ratio)*this_dev_height)/2)); - } else if (remote_device_aspect_ratio < this_device_aspect_ratio) { - linearLayout.setPadding(((int) (((this_device_aspect_ratio - remote_device_aspect_ratio)*this_dev_height))/2),0,((int) (((this_device_aspect_ratio - remote_device_aspect_ratio)*this_dev_height))/2),0); + float this_device_aspect_ratio; + int padding = 0; + /*if(context.getSharedPreferences(PREFERENCE_KEY, 0).getBoolean("original_aspect_ratio", false))*/ { + if (!landscape) { + //Portrait + this_device_aspect_ratio = this_dev_height/this_dev_width; + if (remote_device_aspect_ratio > this_device_aspect_ratio) { + padding = (int)((this_dev_width - (this_dev_height / remote_device_aspect_ratio)) / 2); + linearLayout.setPadding(padding,0,padding,0); + } else if (remote_device_aspect_ratio < this_device_aspect_ratio) { + //linearLayout.setPadding(0,(int) (((this_device_aspect_ratio - remote_device_aspect_ratio)*this_dev_width)),0,0); + } + + }else{ //Landscape + this_device_aspect_ratio = this_dev_width/this_dev_height; + if (remote_device_aspect_ratio > this_device_aspect_ratio) { + padding = (int)((this_dev_height - (this_dev_width / remote_device_aspect_ratio)) / 2); + linearLayout.setPadding(0,(int) (((remote_device_aspect_ratio - this_device_aspect_ratio)*this_dev_height)/2),0,(int) (((remote_device_aspect_ratio - this_device_aspect_ratio)*this_dev_height)/2)); + } else if (remote_device_aspect_ratio < this_device_aspect_ratio) { + //padding = (int)((this_dev_height - (this_dev_width / remote_device_aspect_ratio)) / 2); + //linearLayout.setPadding(((int) (((this_device_aspect_ratio - remote_device_aspect_ratio)*this_dev_height))/2),0,((int) (((this_device_aspect_ratio - remote_device_aspect_ratio)*this_dev_height))/2),0); + } + } + logger.info("aspect_ratio " + landscape + " " + remote_device_aspect_ratio + " " + this_device_aspect_ratio + " " + this_dev_width + " " + this_dev_height + " " + padding + " " + remote_device_height + " " + remote_device_width); + } - }*/ if (!no_control) { surfaceView.setOnTouchListener((v, event) -> scrcpy.touchevent(event, surfaceView.getWidth(), surfaceView.getHeight(), landscape)); } From 10cdd9e682868b12d466e40b11c755070c94790b Mon Sep 17 00:00:00 2001 From: Roberto Viola Date: Tue, 25 Jun 2024 12:42:17 +0200 Subject: [PATCH 02/13] fixing crash --- app/build.gradle | 2 +- .../main/java/org/cagnulein/android_remote/FileLogger.java | 6 ++++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 690a87d..762754f 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -9,7 +9,7 @@ android { applicationId "org.cagnulein.android_remote" minSdkVersion 29 targetSdkVersion 32 - versionCode 13 + versionCode 14 versionName "2.1" testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" setProperty("archivesBaseName", "android_remote") diff --git a/app/src/main/java/org/cagnulein/android_remote/FileLogger.java b/app/src/main/java/org/cagnulein/android_remote/FileLogger.java index 95ecc18..a252bc2 100644 --- a/app/src/main/java/org/cagnulein/android_remote/FileLogger.java +++ b/app/src/main/java/org/cagnulein/android_remote/FileLogger.java @@ -36,8 +36,10 @@ public void log(Level level, String msg) { super.log(level, msg); if(true/*debuglog*/) { try { - writer.write(String.format("[%s] %s: %s%n", java.time.LocalDateTime.now(), level, msg)); - writer.flush(); + if(writer != null) { + writer.write(String.format("[%s] %s: %s%n", java.time.LocalDateTime.now(), level, msg)); + writer.flush(); + } } catch (IOException e) { e.printStackTrace(); } From df25f9e85e68fcd127c1e30f97d9d03b2546952f Mon Sep 17 00:00:00 2001 From: Roberto Viola Date: Wed, 26 Jun 2024 15:45:58 +0200 Subject: [PATCH 03/13] if a phone has a huge display, in non distance mode, it will show as strched (width > heigth) --- app/src/main/AndroidManifest.xml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 37f43c6..7958fe2 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -26,7 +26,8 @@ From 2089e269c35f95219d7d7c86abaf3d0e2980f820 Mon Sep 17 00:00:00 2001 From: Roberto Viola Date: Wed, 26 Jun 2024 17:36:59 +0200 Subject: [PATCH 04/13] Update MainActivity.java --- .../org/cagnulein/android_remote/MainActivity.java | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/org/cagnulein/android_remote/MainActivity.java b/app/src/main/java/org/cagnulein/android_remote/MainActivity.java index 2581dcc..759367e 100644 --- a/app/src/main/java/org/cagnulein/android_remote/MainActivity.java +++ b/app/src/main/java/org/cagnulein/android_remote/MainActivity.java @@ -296,16 +296,17 @@ public void set_display_nd_touch() { float this_device_aspect_ratio; int padding = 0; /*if(context.getSharedPreferences(PREFERENCE_KEY, 0).getBoolean("original_aspect_ratio", false))*/ { - if (!landscape) { + /*if (!landscape)*/ { //Portrait this_device_aspect_ratio = this_dev_height/this_dev_width; if (remote_device_aspect_ratio > this_device_aspect_ratio) { padding = (int)((this_dev_width - (this_dev_height / remote_device_aspect_ratio)) / 2); - linearLayout.setPadding(padding,0,padding,0); + linearLayout.setPadding(padding, 0, padding, 0); } else if (remote_device_aspect_ratio < this_device_aspect_ratio) { - //linearLayout.setPadding(0,(int) (((this_device_aspect_ratio - remote_device_aspect_ratio)*this_dev_width)),0,0); + padding = (int)((this_dev_height - (this_dev_width / remote_device_aspect_ratio)) / 2); + linearLayout.setPadding(0, padding 0, padding); } - +/* }else{ //Landscape this_device_aspect_ratio = this_dev_width/this_dev_height; if (remote_device_aspect_ratio > this_device_aspect_ratio) { @@ -316,7 +317,7 @@ public void set_display_nd_touch() { //linearLayout.setPadding(((int) (((this_device_aspect_ratio - remote_device_aspect_ratio)*this_dev_height))/2),0,((int) (((this_device_aspect_ratio - remote_device_aspect_ratio)*this_dev_height))/2),0); } - } + }*/ logger.info("aspect_ratio " + landscape + " " + remote_device_aspect_ratio + " " + this_device_aspect_ratio + " " + this_dev_width + " " + this_dev_height + " " + padding + " " + remote_device_height + " " + remote_device_width); } From d240e6e7bbd73f29fd5ce50bde5c1f502508c3b8 Mon Sep 17 00:00:00 2001 From: Roberto Viola Date: Wed, 26 Jun 2024 17:40:21 +0200 Subject: [PATCH 05/13] Update MainActivity.java --- .../main/java/org/cagnulein/android_remote/MainActivity.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/java/org/cagnulein/android_remote/MainActivity.java b/app/src/main/java/org/cagnulein/android_remote/MainActivity.java index 759367e..8cda5e7 100644 --- a/app/src/main/java/org/cagnulein/android_remote/MainActivity.java +++ b/app/src/main/java/org/cagnulein/android_remote/MainActivity.java @@ -296,7 +296,7 @@ public void set_display_nd_touch() { float this_device_aspect_ratio; int padding = 0; /*if(context.getSharedPreferences(PREFERENCE_KEY, 0).getBoolean("original_aspect_ratio", false))*/ { - /*if (!landscape)*/ { + /*if (!landscape) {*/ //Portrait this_device_aspect_ratio = this_dev_height/this_dev_width; if (remote_device_aspect_ratio > this_device_aspect_ratio) { From 185eaea1b718d97157a0062e3094039db88b987f Mon Sep 17 00:00:00 2001 From: Roberto Viola Date: Wed, 26 Jun 2024 17:42:57 +0200 Subject: [PATCH 06/13] Update MainActivity.java --- .../main/java/org/cagnulein/android_remote/MainActivity.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/java/org/cagnulein/android_remote/MainActivity.java b/app/src/main/java/org/cagnulein/android_remote/MainActivity.java index 8cda5e7..64f46b5 100644 --- a/app/src/main/java/org/cagnulein/android_remote/MainActivity.java +++ b/app/src/main/java/org/cagnulein/android_remote/MainActivity.java @@ -304,7 +304,7 @@ public void set_display_nd_touch() { linearLayout.setPadding(padding, 0, padding, 0); } else if (remote_device_aspect_ratio < this_device_aspect_ratio) { padding = (int)((this_dev_height - (this_dev_width / remote_device_aspect_ratio)) / 2); - linearLayout.setPadding(0, padding 0, padding); + linearLayout.setPadding(0, padding, 0, padding); } /* }else{ //Landscape From 183885c7600c72765620ba85ad659b5c188f3f1b Mon Sep 17 00:00:00 2001 From: Roberto Viola Date: Thu, 27 Jun 2024 11:47:50 +0200 Subject: [PATCH 07/13] is it any better? --- .../android_remote/MainActivity.java | 54 +++++++++------ app/src/main/res/layout-land/surface.xml | 65 ------------------- 2 files changed, 35 insertions(+), 84 deletions(-) delete mode 100644 app/src/main/res/layout-land/surface.xml diff --git a/app/src/main/java/org/cagnulein/android_remote/MainActivity.java b/app/src/main/java/org/cagnulein/android_remote/MainActivity.java index 64f46b5..380f5a8 100644 --- a/app/src/main/java/org/cagnulein/android_remote/MainActivity.java +++ b/app/src/main/java/org/cagnulein/android_remote/MainActivity.java @@ -45,6 +45,7 @@ import java.util.concurrent.Executors; import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicInteger; +import java.util.logging.Level; import io.github.muntashirakon.adb.AbsAdbConnectionManager; import io.github.muntashirakon.adb.AdbPairingRequiredException; @@ -92,8 +93,9 @@ public void onServiceConnected(ComponentName componentName, IBinder iBinder) { scrcpy = ((Scrcpy.MyServiceBinder) iBinder).getService(); scrcpy.setServiceCallbacks(MainActivity.this); serviceBound = true; + Log.d("screen", screenHeight + " " + screenWidth); if (first_time) { - scrcpy.start(surface, serverAdr, screenHeight, screenWidth); + scrcpy.start(surface, serverAdr, screenWidth, screenHeight); int count = 100; while (count!=0 && !scrcpy.check_socket_connection()){ count --; @@ -118,7 +120,7 @@ public void onServiceConnected(ComponentName componentName, IBinder iBinder) { first_time = false; } } else { - scrcpy.setParms(surface, screenWidth, screenHeight); + scrcpy.setParms(surface, screenHeight, screenWidth); } set_display_nd_touch(); } @@ -275,6 +277,7 @@ public void get_saved_preferences(){ @SuppressLint("ClickableViewAccessibility") public void set_display_nd_touch() { + final View decodeSurface = findViewById(R.id.decoder_surface); DisplayMetrics metrics = new DisplayMetrics(); if (ViewConfiguration.get(context).hasPermanentMenuKey()) { getWindowManager().getDefaultDisplay().getMetrics(metrics); @@ -286,39 +289,47 @@ public void set_display_nd_touch() { float this_dev_width = metrics.widthPixels; if (nav && !no_control){ if (landscape){ - this_dev_width = this_dev_width - 96; + //this_dev_width = this_dev_width - 96; }else { //100 is the height of nav bar but need multiples of 8. //this_dev_height = this_dev_height - 96; } } - float remote_device_aspect_ratio = remote_device_height/remote_device_width; - float this_device_aspect_ratio; int padding = 0; - /*if(context.getSharedPreferences(PREFERENCE_KEY, 0).getBoolean("original_aspect_ratio", false))*/ { - /*if (!landscape) {*/ + float remote_device_aspect_ratio = 0; + /*if(context.getSharedPreferences(PREFERENCE_KEY, 0).getBoolean("original_aspect_ratio", false))*/ { + if (!landscape) { //Portrait + remote_device_aspect_ratio = remote_device_height/remote_device_width; this_device_aspect_ratio = this_dev_height/this_dev_width; if (remote_device_aspect_ratio > this_device_aspect_ratio) { padding = (int)((this_dev_width - (this_dev_height / remote_device_aspect_ratio)) / 2); - linearLayout.setPadding(padding, 0, padding, 0); + if(padding >= 0) + linearLayout.setPadding(padding, 0, padding, 0); } else if (remote_device_aspect_ratio < this_device_aspect_ratio) { - padding = (int)((this_dev_height - (this_dev_width / remote_device_aspect_ratio)) / 2); - linearLayout.setPadding(0, padding, 0, padding); + padding = (int)((this_dev_height - (this_dev_width * remote_device_aspect_ratio)) / 2); + if(padding >= 0) + linearLayout.setPadding(0, padding, 0, padding); } -/* - }else{ //Landscape - this_device_aspect_ratio = this_dev_width/this_dev_height; + + }else{ + //Landscape + remote_device_aspect_ratio = remote_device_width/remote_device_height; + this_device_aspect_ratio = this_dev_height/this_dev_width; if (remote_device_aspect_ratio > this_device_aspect_ratio) { - padding = (int)((this_dev_height - (this_dev_width / remote_device_aspect_ratio)) / 2); - linearLayout.setPadding(0,(int) (((remote_device_aspect_ratio - this_device_aspect_ratio)*this_dev_height)/2),0,(int) (((remote_device_aspect_ratio - this_device_aspect_ratio)*this_dev_height)/2)); + padding = (int)((this_dev_width - (this_dev_height / remote_device_aspect_ratio)) / 2); + if(padding >= 0) + linearLayout.setPadding(padding, 0, padding, 0); } else if (remote_device_aspect_ratio < this_device_aspect_ratio) { - //padding = (int)((this_dev_height - (this_dev_width / remote_device_aspect_ratio)) / 2); - //linearLayout.setPadding(((int) (((this_device_aspect_ratio - remote_device_aspect_ratio)*this_dev_height))/2),0,((int) (((this_device_aspect_ratio - remote_device_aspect_ratio)*this_dev_height))/2),0); + padding = (int)((this_dev_height - (this_dev_width * remote_device_aspect_ratio)) / 2); + if(padding >= 0) + linearLayout.setPadding(0, padding, 0, padding); } + } + if(padding < 0) + linearLayout.setPadding(0, 0, 0, 0); - }*/ - logger.info("aspect_ratio " + landscape + " " + remote_device_aspect_ratio + " " + this_device_aspect_ratio + " " + this_dev_width + " " + this_dev_height + " " + padding + " " + remote_device_height + " " + remote_device_width); + Log.d("aspect_ratio ", landscape + " " + remote_device_aspect_ratio + " " + this_device_aspect_ratio + " " + this_dev_width + " " + this_dev_height + " " + padding + " " + remote_device_width + " " + remote_device_height + " " + screenWidth + " " + screenHeight); } if (!no_control) { @@ -456,6 +467,7 @@ private void start_Scrcpy_service() { @SuppressLint("SourceLockedOrientationActivity") @Override public void loadNewRotation() { + Log.d("aspect_ratio", "loadNewRotation"); if (first_time){ int[] rem_res = scrcpy.get_remote_device_resolution(); remote_device_height = rem_res[1]; @@ -467,6 +479,10 @@ public void loadNewRotation() { result_of_Rotation = true; landscape = !landscape; swapDimensions(); + runOnUiThread(() -> { + set_display_nd_touch(); + }); + /*if (landscape) { setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE); } else { diff --git a/app/src/main/res/layout-land/surface.xml b/app/src/main/res/layout-land/surface.xml deleted file mode 100644 index 23b2823..0000000 --- a/app/src/main/res/layout-land/surface.xml +++ /dev/null @@ -1,65 +0,0 @@ - - - - - - - - -