1
0
mirror of http://galexander.org/git/simplesshd.git synced 2024-12-29 09:28:07 +00:00

get rid of the old prefs machinery

This commit is contained in:
Greg Alexander 2014-12-17 18:43:01 -05:00
parent e49cf68feb
commit 76eb76fac4
2 changed files with 1 additions and 111 deletions

View File

@ -3,81 +3,10 @@
android:orientation="vertical" android:orientation="vertical"
android:layout_width="fill_parent" android:layout_width="fill_parent"
android:layout_height="fill_parent"> android:layout_height="fill_parent">
<ScrollView
android:layout_width="fill_parent"
android:layout_height="1dp"
android:layout_weight="1">
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<TextView android:id="@+id/onboot_lab"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_alignParentTop="@+id/onboot"
android:layout_alignBottom="@+id/onboot"
android:gravity="center_vertical"
android:text="Start on boot"
android:textAppearance="?android:attr/textAppearanceMedium" />
<CheckBox android:id="@+id/onboot"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_alignParentRight="true" />
<TextView android:id="@+id/port_lab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/onboot"
android:text="Port"
android:textAppearance="?android:attr/textAppearanceMedium" />
<EditText android:id="@+id/port"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:layout_below="@+id/onboot"
android:layout_alignParentRight="true"
android:textAppearance="?android:attr/textAppearanceMedium"
android:singleLine="true"
android:inputType="numberDecimal" />
<TextView android:id="@+id/path_lab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/port"
android:text="Path to authorized_keys"
android:textAppearance="?android:attr/textAppearanceSmall" />
<EditText android:id="@+id/path"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/path_lab"
android:textAppearance="?android:attr/textAppearanceMedium"
android:singleLine="true" />
<TextView android:id="@+id/shell_lab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/path"
android:text="Login shell"
android:textAppearance="?android:attr/textAppearanceSmall" />
<EditText android:id="@+id/shell"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/shell_lab"
android:textAppearance="?android:attr/textAppearanceMedium"
android:singleLine="true" />
<TextView android:id="@+id/home_lab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/shell"
android:text="Home directory"
android:textAppearance="?android:attr/textAppearanceSmall" />
<EditText android:id="@+id/home"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/home_lab"
android:textAppearance="?android:attr/textAppearanceMedium"
android:singleLine="true" />
</RelativeLayout>
</ScrollView>
<Button android:id="@+id/startstop" <Button android:id="@+id/startstop"
android:layout_width="fill_parent" android:layout_width="fill_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="Start" android:text="Start"
android:textAppearance="?android:attr/textAppearanceLarge" android:textAppearance="?android:attr/textAppearanceLarge"
android:onClick="startstop_clicked" /> android:onClick="startstop_clicked" />

View File

@ -15,8 +15,6 @@ import android.net.Uri;
public class SimpleSSHD extends Activity public class SimpleSSHD extends Activity
{ {
private CheckBox onboot_view;
private EditText port_view, path_view, shell_view, home_view;
private Button startstop_view; private Button startstop_view;
public void onCreate(Bundle savedInstanceState) public void onCreate(Bundle savedInstanceState)
@ -24,24 +22,17 @@ public class SimpleSSHD extends Activity
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
Prefs.init(this); Prefs.init(this);
setContentView(R.layout.main); setContentView(R.layout.main);
onboot_view = (CheckBox)findViewById(R.id.onboot);
port_view = (EditText)findViewById(R.id.port);
path_view = (EditText)findViewById(R.id.path);
shell_view = (EditText)findViewById(R.id.shell);
home_view = (EditText)findViewById(R.id.home);
startstop_view = (Button)findViewById(R.id.startstop); startstop_view = (Button)findViewById(R.id.startstop);
} }
public void onResume() { public void onResume() {
super.onResume(); super.onResume();
load_prefs();
update_startstop(); update_startstop();
SimpleSSHDService.activity = this; SimpleSSHDService.activity = this;
} }
public void onPause() { public void onPause() {
SimpleSSHDService.activity = null; SimpleSSHDService.activity = null;
save_prefs();
super.onPause(); super.onPause();
} }
@ -76,40 +67,10 @@ public class SimpleSSHD extends Activity
} }
public void startstop_clicked(View v) { public void startstop_clicked(View v) {
save_prefs();
Intent i = new Intent(this, SimpleSSHDService.class); Intent i = new Intent(this, SimpleSSHDService.class);
if (SimpleSSHDService.is_started()) { if (SimpleSSHDService.is_started()) {
i.putExtra("stop", true); i.putExtra("stop", true);
} }
startService(i); startService(i);
} }
private void load_prefs() {
onboot_view.setChecked(Prefs.get_onboot());
port_view.setText(Integer.toString(Prefs.get_port()));
path_view.setText(Prefs.get_path());
shell_view.setText(Prefs.get_shell());
home_view.setText(Prefs.get_home());
}
private void save_prefs() {
SharedPreferences.Editor edit = Prefs.edit();
boolean b = onboot_view.isChecked();
if (b != Prefs.get_onboot()) { edit.putBoolean("onboot", b); }
int i;
try {
i = Integer.valueOf(port_view.getText().toString());
} catch (Exception e) {
i = 0;
}
if (i != Prefs.get_port()) { edit.putInt("port", i); }
String s = path_view.getText().toString();
if (!s.equals(Prefs.get_path())) { edit.putString("path", s); }
s = shell_view.getText().toString();
if (!s.equals(Prefs.get_shell())) { edit.putString("shell", s); }
s = home_view.getText().toString();
if (!s.equals(Prefs.get_home())) { edit.putString("home", s); }
edit.commit();
}
} }