Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@ public class Constants {
public static final String PREFS_KEY_SETTINGS_SHOW_POINTERS = "settings_show_pointers" ;
public static final String PREFS_KEY_SETTINGS_ACCESS_KEY = "settings_access_key";
public static final String PREFS_KEY_SETTINGS_FILE_TRANSFER = "settings_file_transfer";
public static final String PREFS_KEY_SETTINGS_ZLIB_COMPRESSION = "settings_zlib_compression";
public static final String PREFS_KEY_SETTINGS_CROPPING_LEFT = "settings_cropping_left";
public static final String PREFS_KEY_SETTINGS_CROPPING_TOP = "settings_cropping_top";
public static final String PREFS_KEY_SETTINGS_CROPPING_WIDTH = "settings_cropping_width";
public static final String PREFS_KEY_SETTINGS_CROPPING_HEIGHT = "settings_cropping_height";

/*
persisted runtime values shared between components
Expand Down
118 changes: 116 additions & 2 deletions app/src/main/java/net/christianbeier/droidvnc_ng/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import android.content.SharedPreferences;
import android.content.pm.PackageManager;
import android.content.res.Resources;
import android.graphics.Point;
import android.net.ConnectivityManager;
import android.net.LinkProperties;
import android.net.Network;
Expand Down Expand Up @@ -59,6 +60,7 @@
import android.util.Log;
import android.util.Pair;
import android.util.TypedValue;
import android.view.Display;
import android.view.View;
import android.view.WindowManager;
import android.widget.Button;
Expand Down Expand Up @@ -128,6 +130,11 @@ protected void onCreate(Bundle savedInstanceState) {
intent.putExtra(MainService.EXTRA_SHOW_POINTERS, prefs.getBoolean(Constants.PREFS_KEY_SETTINGS_SHOW_POINTERS, mDefaults.getShowPointers()));
intent.putExtra(MainService.EXTRA_SCALING, prefs.getFloat(Constants.PREFS_KEY_SETTINGS_SCALING, mDefaults.getScaling()));
intent.putExtra(MainService.EXTRA_ACCESS_KEY, prefs.getString(Constants.PREFS_KEY_SETTINGS_ACCESS_KEY, mDefaults.getAccessKey()));
intent.putExtra(MainService.EXTRA_ZLIB_COMPRESSION, prefs.getInt(Constants.PREFS_KEY_SETTINGS_ZLIB_COMPRESSION, 1));
intent.putExtra(MainService.EXTRA_CROPPING_LEFT, prefs.getInt(Constants.PREFS_KEY_SETTINGS_CROPPING_LEFT, 0));
intent.putExtra(MainService.EXTRA_CROPPING_TOP, prefs.getInt(Constants.PREFS_KEY_SETTINGS_CROPPING_TOP, 0));
intent.putExtra(MainService.EXTRA_CROPPING_WIDTH, prefs.getInt(Constants.PREFS_KEY_SETTINGS_CROPPING_WIDTH, 0));
intent.putExtra(MainService.EXTRA_CROPPING_HEIGHT, prefs.getInt(Constants.PREFS_KEY_SETTINGS_CROPPING_HEIGHT, 0));
if(mIsMainServiceRunning) {
intent.setAction(MainService.ACTION_STOP);
}
Expand Down Expand Up @@ -508,7 +515,8 @@ public void afterTextChanged(Editable editable) {
});
}

Slider scaling = findViewById(R.id.settings_scaling);
final TextView finalResolution = findViewById(R.id.final_resolution);
final Slider scaling = findViewById(R.id.settings_scaling);
scaling.setValue(
prefs.getFloat(Constants.PREFS_KEY_SETTINGS_SCALING,
(float) Math.ceil(mDefaults.getScaling() * 100 / scaling.getStepSize()) * scaling.getStepSize() / 100)
Expand All @@ -518,8 +526,11 @@ public void afterTextChanged(Editable editable) {
SharedPreferences.Editor ed = prefs.edit();
ed.putFloat(Constants.PREFS_KEY_SETTINGS_SCALING, value/100);
ed.apply();
updateFinalResolution(finalResolution, value / 100);
});

updateFinalResolution(finalResolution, scaling.getValue() / 100);

final SwitchMaterial showPointers = findViewById(R.id.settings_show_pointers);
showPointers.setChecked(prefs.getBoolean(Constants.PREFS_KEY_SETTINGS_SHOW_POINTERS, mDefaults.getShowPointers()));
showPointers.setOnCheckedChangeListener((compoundButton, b) -> {
Expand All @@ -539,6 +550,83 @@ public void afterTextChanged(Editable editable) {
showPointers.setEnabled(!b);
});

final Slider zlibCompression = findViewById(R.id.settings_zlib_compression);
zlibCompression.setValue(prefs.getInt(Constants.PREFS_KEY_SETTINGS_ZLIB_COMPRESSION, 1));
zlibCompression.setLabelFormatter(value -> String.valueOf((int) value));
zlibCompression.addOnChangeListener((slider, value, fromUser) -> {
SharedPreferences.Editor ed = prefs.edit();
ed.putInt(Constants.PREFS_KEY_SETTINGS_ZLIB_COMPRESSION, (int) value);
ed.apply();
});

final EditText croppingLeft = findViewById(R.id.settings_cropping_left);
croppingLeft.setText(String.valueOf(prefs.getInt(Constants.PREFS_KEY_SETTINGS_CROPPING_LEFT, 0)));
croppingLeft.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {}
@Override
public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
try {
SharedPreferences.Editor ed = prefs.edit();
ed.putInt(Constants.PREFS_KEY_SETTINGS_CROPPING_LEFT, Integer.parseInt(charSequence.toString()));
ed.apply();
} catch (NumberFormatException e) {}
}
@Override
public void afterTextChanged(Editable editable) {}
});

final EditText croppingTop = findViewById(R.id.settings_cropping_top);
croppingTop.setText(String.valueOf(prefs.getInt(Constants.PREFS_KEY_SETTINGS_CROPPING_TOP, 0)));
croppingTop.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {}
@Override
public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
try {
SharedPreferences.Editor ed = prefs.edit();
ed.putInt(Constants.PREFS_KEY_SETTINGS_CROPPING_TOP, Integer.parseInt(charSequence.toString()));
ed.apply();
} catch (NumberFormatException e) {}
}
@Override
public void afterTextChanged(Editable editable) {}
});

final EditText croppingWidth = findViewById(R.id.settings_cropping_width);
croppingWidth.setText(String.valueOf(prefs.getInt(Constants.PREFS_KEY_SETTINGS_CROPPING_WIDTH, 0)));
croppingWidth.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {}
@Override
public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
try {
SharedPreferences.Editor ed = prefs.edit();
ed.putInt(Constants.PREFS_KEY_SETTINGS_CROPPING_WIDTH, Integer.parseInt(charSequence.toString()));
ed.apply();
} catch (NumberFormatException e) {}
}
@Override
public void afterTextChanged(Editable editable) {}
});

final EditText croppingHeight = findViewById(R.id.settings_cropping_height);
croppingHeight.setText(String.valueOf(prefs.getInt(Constants.PREFS_KEY_SETTINGS_CROPPING_HEIGHT, 0)));
croppingHeight.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {}
@Override
public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
try {
SharedPreferences.Editor ed = prefs.edit();
ed.putInt(Constants.PREFS_KEY_SETTINGS_CROPPING_HEIGHT, Integer.parseInt(charSequence.toString()));
ed.apply();
} catch (NumberFormatException e) {}
}
@Override
public void afterTextChanged(Editable editable) {}
});

TextView about = findViewById(R.id.about);
about.setText(getString(R.string.main_activity_about, BuildConfig.VERSION_NAME));

Expand Down Expand Up @@ -831,6 +919,22 @@ private void updatePermissionsDisplay() {

}

private void updateFinalResolution(TextView finalResolution, float scaling) {
Point size = new Point();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
Display display = getDisplay();
if (display != null) {
display.getRealSize(size);
}
} else {
getWindowManager().getDefaultDisplay().getRealSize(size);
}

int finalWidth = (int) (size.x * scaling);
int finalHeight = (int) (size.y * scaling);
finalResolution.setText(finalWidth + "x" + finalHeight);
}

private void updateAddressesDisplay() {
Log.d(TAG, "updateAddressesDisplay: " + MainService.isServerActive());

Expand Down Expand Up @@ -916,6 +1020,11 @@ private void onServerStarted() {
findViewById(R.id.settings_view_only).setEnabled(false);
findViewById(R.id.settings_file_transfer).setEnabled(false);
findViewById(R.id.settings_show_pointers).setEnabled(false);
findViewById(R.id.settings_zlib_compression).setEnabled(false);
findViewById(R.id.settings_cropping_left).setEnabled(false);
findViewById(R.id.settings_cropping_top).setEnabled(false);
findViewById(R.id.settings_cropping_width).setEnabled(false);
findViewById(R.id.settings_cropping_height).setEnabled(false);

startGettingClientList();

Expand Down Expand Up @@ -947,6 +1056,11 @@ private void onServerStopped() {
// pointers depend on view-only being disabled
findViewById(R.id.settings_show_pointers).setEnabled(true);
}
findViewById(R.id.settings_zlib_compression).setEnabled(true);
findViewById(R.id.settings_cropping_left).setEnabled(true);
findViewById(R.id.settings_cropping_top).setEnabled(true);
findViewById(R.id.settings_cropping_width).setEnabled(true);
findViewById(R.id.settings_cropping_height).setEnabled(true);

stopGettingClientList();

Expand Down Expand Up @@ -994,4 +1108,4 @@ private void stopGettingClientList() {
}
}

}
}
24 changes: 20 additions & 4 deletions app/src/main/java/net/christianbeier/droidvnc_ng/MainService.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.SharedPreferences;
import android.content.pm.ServiceInfo;
import android.net.ConnectivityManager;
Expand Down Expand Up @@ -71,6 +72,8 @@

public class MainService extends Service {


public static final String EXTRA_ZLIB_COMPRESSION = "net.christianbeier.droidvnc_ng.EXTRA_ZLIB_COMPRESSION";
private static final String TAG = "MainService";
static final int NOTIFICATION_ID = 11;
public final static String ACTION_START = "net.christianbeier.droidvnc_ng.ACTION_START";
Expand All @@ -88,6 +91,10 @@ public class MainService extends Service {
public static final String EXTRA_VIEW_ONLY = "net.christianbeier.droidvnc_ng.EXTRA_VIEW_ONLY";
public static final String EXTRA_SHOW_POINTERS = "net.christianbeier.droidvnc_ng.EXTRA_SHOW_POINTERS";
public static final String EXTRA_SCALING = "net.christianbeier.droidvnc_ng.EXTRA_SCALING";
public static final String EXTRA_CROPPING_LEFT = "net.christianbeier.droidvnc_ng.EXTRA_CROPPING_LEFT";
public static final String EXTRA_CROPPING_TOP = "net.christianbeier.droidvnc_ng.EXTRA_CROPPING_TOP";
public static final String EXTRA_CROPPING_WIDTH = "net.christianbeier.droidvnc_ng.EXTRA_CROPPING_WIDTH";
public static final String EXTRA_CROPPING_HEIGHT = "net.christianbeier.droidvnc_ng.EXTRA_CROPPING_HEIGHT";
/**
* Only used on Android 12 and earlier.
*/
Expand Down Expand Up @@ -205,7 +212,7 @@ public void onServiceUnregistered(NsdServiceInfo nsdServiceInfo) {
}

@SuppressWarnings("BooleanMethodIsAlwaysInverted")
private native boolean vncStartServer(int width, int height, int port, String desktopName, String password, String httpRootDir);
private native boolean vncStartServer(int width, int height, int port, String desktopName, String password, String httpRootDir, int crop_left, int crop_top, int crop_width, int crop_height, int zlibCompression);
private native boolean vncStopServer();
private native boolean vncIsActive();
private native long vncConnectReverse(String host, int port);
Expand Down Expand Up @@ -396,15 +403,19 @@ public int onStartCommand(Intent intent, int flags, int startId)
Intent startIntent = Objects.requireNonNull(MainServicePersistData.loadStartIntent(this));
int port = startIntent.getIntExtra(EXTRA_PORT, PreferenceManager.getDefaultSharedPreferences(this).getInt(Constants.PREFS_KEY_SETTINGS_PORT, mDefaults.getPort()));
String password = startIntent.getStringExtra(EXTRA_PASSWORD) != null ? startIntent.getStringExtra(EXTRA_PASSWORD) : PreferenceManager.getDefaultSharedPreferences(this).getString(Constants.PREFS_KEY_SETTINGS_PASSWORD, mDefaults.getPassword());
// get device name
String name = Utils.getDeviceName(this);

boolean status = vncStartServer(displayMetrics.widthPixels,
displayMetrics.heightPixels,
port,
name,
password,
getFilesDir().getAbsolutePath() + File.separator + "novnc");
getFilesDir().getAbsolutePath() + File.separator + "novnc",
startIntent.getIntExtra(EXTRA_CROPPING_LEFT, 0),
startIntent.getIntExtra(EXTRA_CROPPING_TOP, 0),
startIntent.getIntExtra(EXTRA_CROPPING_WIDTH, 0),
startIntent.getIntExtra(EXTRA_CROPPING_HEIGHT, 0),
startIntent.getIntExtra(EXTRA_ZLIB_COMPRESSION, 1));
Intent answer = new Intent(ACTION_START);
answer.putExtra(EXTRA_REQUEST_ID, startIntent.getStringExtra(EXTRA_REQUEST_ID));
answer.putExtra(EXTRA_REQUEST_SUCCESS, status);
Expand Down Expand Up @@ -451,7 +462,12 @@ public int onStartCommand(Intent intent, int flags, int startId)
port,
name,
password,
getFilesDir().getAbsolutePath() + File.separator + "novnc");
getFilesDir().getAbsolutePath() + File.separator + "novnc",
startIntent.getIntExtra(EXTRA_CROPPING_LEFT, 0),
startIntent.getIntExtra(EXTRA_CROPPING_TOP, 0),
startIntent.getIntExtra(EXTRA_CROPPING_WIDTH, 0),
startIntent.getIntExtra(EXTRA_CROPPING_HEIGHT, 0),
startIntent.getIntExtra(EXTRA_ZLIB_COMPRESSION, 1));

Intent answer = new Intent(ACTION_START);
answer.putExtra(EXTRA_REQUEST_ID, startIntent.getStringExtra(EXTRA_REQUEST_ID));
Expand Down
Loading
Loading