Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

trying to fix non distance mode #9 #10

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
2 changes: 1 addition & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ android {
applicationId "org.cagnulein.android_remote"
minSdkVersion 29
targetSdkVersion 32
versionCode 17
versionCode 18
versionName "2.2"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
setProperty("archivesBaseName", "android_remote")
Expand Down
3 changes: 2 additions & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@
<activity
android:name=".MainActivity"
android:resizeableActivity="true"
android:launchMode="singleTask"
android:launchMode="singleTask"
android:screenOrientation="landscape"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
Expand Down
67 changes: 47 additions & 20 deletions app/src/main/java/org/cagnulein/android_remote/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,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;
Expand Down Expand Up @@ -101,8 +102,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 --;
Expand All @@ -127,7 +129,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();
}
Expand Down Expand Up @@ -345,6 +347,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);
Expand All @@ -356,30 +359,49 @@ 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;
//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);
}
float this_device_aspect_ratio;
int padding = 0;
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);
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);
if(padding >= 0)
linearLayout.setPadding(0, padding, 0, padding);
}

}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);
}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_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);
if(padding >= 0)
linearLayout.setPadding(0, padding, 0, padding);
}
}
if(padding < 0)
linearLayout.setPadding(0, 0, 0, 0);

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) {
surfaceView.setOnTouchListener((v, event) -> scrcpy.touchevent(event, surfaceView.getWidth(), surfaceView.getHeight(), landscape));
}
Expand Down Expand Up @@ -517,6 +539,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];
Expand All @@ -528,6 +551,10 @@ public void loadNewRotation() {
result_of_Rotation = true;
landscape = !landscape;
swapDimensions();
runOnUiThread(() -> {
set_display_nd_touch();
});

/*if (landscape) {
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
} else {
Expand Down
65 changes: 0 additions & 65 deletions app/src/main/res/layout-land/surface.xml

This file was deleted.

Loading