package org.galexander.sshd; import android.app.Activity; import android.os.Bundle; import android.content.Context; import android.content.SharedPreferences; import android.content.Intent; import android.widget.CheckBox; import android.widget.EditText; import android.widget.TextView; import android.widget.Button; import android.view.View; import android.view.Menu; import android.view.MenuItem; import android.net.Uri; import java.io.File; import java.io.FileReader; import java.io.BufferedReader; public class SimpleSSHD extends Activity { private TextView log_view; private Button startstop_view; public static SimpleSSHD curr = null; private UpdaterThread updater = null; public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); Prefs.init(this); setContentView(R.layout.main); log_view = (TextView)findViewById(R.id.log); startstop_view = (Button)findViewById(R.id.startstop); } public void onResume() { super.onResume(); curr = this; update_startstop(); updater = new UpdaterThread(); updater.start(); } public void onPause() { curr = null; updater.interrupt(); super.onPause(); } public boolean onCreateOptionsMenu(Menu menu) { getMenuInflater().inflate(R.menu.main_menu, menu); return true; } public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { case R.id.settings: startActivity(new Intent(this, Settings.class)); return true; case R.id.about: { Intent i = new Intent(Intent.ACTION_VIEW); i.setData(Uri.parse("http://www.galexander.org/software/simplesshd")); startActivity(i); } return true; default: return super.onOptionsItemSelected(item); } } public void update_startstop() { if (SimpleSSHDService.is_started()) { startstop_view.setText("STOP"); startstop_view.setTextColor(0xFF881111); } else { startstop_view.setText("START"); startstop_view.setTextColor(0xFF118811); } } public void startstop_clicked(View v) { Intent i = new Intent(this, SimpleSSHDService.class); if (SimpleSSHDService.is_started()) { i.putExtra("stop", true); } startService(i); } public void update_log() { String[] lines = new String[50]; int curr_line = 0; boolean wrapped = false; try { File f = new File(Prefs.get_path(), "dropbear.err"); if (f.exists()) { BufferedReader r = new BufferedReader( new FileReader(f)); try { String l; while ((l = r.readLine()) != null) { lines[curr_line++] = l; if (curr_line >= lines.length) { curr_line = 0; wrapped = true; } } } finally { r.close(); } } } catch (Exception e) { } int i; i = (wrapped ? curr_line : 0); String output = ""; do { output = output + lines[i] + "\n"; i++; i %= lines.length; } while (i != curr_line); log_view.setText(output); } }