Skip to content

Commit

Permalink
MainActivity,Constants: use Extras to convey info to MainService
Browse files Browse the repository at this point in the history
  • Loading branch information
bk138 committed Aug 14, 2022
1 parent 7796cae commit 29f598a
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 6 deletions.
10 changes: 8 additions & 2 deletions app/src/main/java/net/christianbeier/droidvnc_ng/Constants.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,21 @@

public class Constants {

public static final int DEFAULT_PORT = 5900;
public static final int DEFAULT_PORT_LISTEN = 5900;
public static final int DEFAULT_PORT_REVERSE = 5500;
public static final int DEFAULT_PORT_REPEATER = 5500;
public static final float DEFAULT_SCALING = 1.0f;
public static final String PREFS_KEY_SETTINGS_PORT = "settings_port";
public static final String DEFAULT_PASSWORD = "";
public static final boolean DEFAULT_FILE_TRANSFER = true;
public static final boolean DEFAULT_VIEW_ONLY = false;

public static final String PREFS_KEY_SETTINGS_PORT_LISTEN = "settings_port";
public static final String PREFS_KEY_SETTINGS_PASSWORD = "settings_password" ;
public static final String PREFS_KEY_SETTINGS_START_ON_BOOT = "settings_start_on_boot" ;
public static final String PREFS_KEY_SETTINGS_SCALING = "settings_scaling" ;
public static final String PREFS_KEY_REVERSE_VNC_LAST_HOST = "reverse_vnc_last_host" ;
public static final String PREFS_KEY_REPEATER_VNC_LAST_HOST = "repeater_vnc_last_host" ;
public static final String PREFS_KEY_REPEATER_VNC_LAST_ID = "repeater_vnc_last_id" ;
public static final String PREFS_KEY_SETTINGS_FILE_TRANSFER = "settings_file_transfer" ;
public static final String PREFS_KEY_SETTINGS_VIEW_ONLY = "settings_view_only" ;
}
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,11 @@ protected void onCreate(Bundle savedInstanceState) {
}
else {
intent.setAction(MainService.ACTION_START);
intent.putExtra(MainService.EXTRA_PASSWORD, prefs.getString(Constants.PREFS_KEY_SETTINGS_PASSWORD, Constants.DEFAULT_PASSWORD));
intent.putExtra(MainService.EXTRA_SCALING, prefs.getFloat(Constants.PREFS_KEY_SETTINGS_SCALING, Constants.DEFAULT_SCALING));
intent.putExtra(MainService.EXTRA_FILE_TRANSFER, prefs.getBoolean(Constants.PREFS_KEY_SETTINGS_FILE_TRANSFER, Constants.DEFAULT_FILE_TRANSFER));
intent.putExtra(MainService.EXTRA_VIEW_ONLY, prefs.getBoolean(Constants.PREFS_KEY_SETTINGS_VIEW_ONLY, Constants.DEFAULT_VIEW_ONLY));
intent.putExtra(MainService.EXTRA_LISTEN_PORT, prefs.getInt(Constants.PREFS_KEY_SETTINGS_PORT_LISTEN, Constants.DEFAULT_PORT_LISTEN));
}
mButtonToggle.setEnabled(false);

Expand Down Expand Up @@ -217,7 +222,7 @@ protected void onCreate(Bundle savedInstanceState) {


final EditText port = findViewById(R.id.settings_port);
port.setText(String.valueOf(prefs.getInt(Constants.PREFS_KEY_SETTINGS_PORT, Constants.DEFAULT_PORT)));
port.setText(String.valueOf(prefs.getInt(Constants.PREFS_KEY_SETTINGS_PORT_LISTEN, Constants.DEFAULT_PORT_LISTEN)));
port.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {
Expand All @@ -228,7 +233,7 @@ public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2)
public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
try {
SharedPreferences.Editor ed = prefs.edit();
ed.putInt(Constants.PREFS_KEY_SETTINGS_PORT, Integer.parseInt(charSequence.toString()));
ed.putInt(Constants.PREFS_KEY_SETTINGS_PORT_LISTEN, Integer.parseInt(charSequence.toString()));
ed.commit();
} catch(NumberFormatException e) {
// nop
Expand All @@ -240,10 +245,10 @@ public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
public void afterTextChanged(Editable editable) {
if(port.getText().length() == 0) {
// hint that default is set
port.setHint(String.valueOf(Constants.DEFAULT_PORT));
port.setHint(String.valueOf(Constants.DEFAULT_PORT_LISTEN));
// and set default
SharedPreferences.Editor ed = prefs.edit();
ed.putInt(Constants.PREFS_KEY_SETTINGS_PORT, Constants.DEFAULT_PORT);
ed.putInt(Constants.PREFS_KEY_SETTINGS_PORT_LISTEN, Constants.DEFAULT_PORT_LISTEN);
ed.commit();
}
}
Expand Down

0 comments on commit 29f598a

Please sign in to comment.