From 8ced3ab635d4df237b9e04a7551ffba70b009889 Mon Sep 17 00:00:00 2001 From: Greg Alexander Date: Tue, 16 Dec 2014 11:20:36 -0500 Subject: [PATCH] and there's the start/stop button implementation --- src/org/galexander/sshd/SimpleSSHD.java | 20 +++++++++++++++++-- .../galexander/sshd/SimpleSSHDService.java | 7 +++++++ 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/src/org/galexander/sshd/SimpleSSHD.java b/src/org/galexander/sshd/SimpleSSHD.java index c6b58b8..df11963 100644 --- a/src/org/galexander/sshd/SimpleSSHD.java +++ b/src/org/galexander/sshd/SimpleSSHD.java @@ -29,16 +29,32 @@ public class SimpleSSHD extends Activity public void onResume() { load_prefs(); - /* XXX - update startstop_view */ + update_startstop(); + SimpleSSHDService.activity = this; } public void onPause() { + SimpleSSHDService.activity = null; save_prefs(); } + public void update_startstop() { + if (SimpleSSHDService.is_started()) { + startstop_view.setText("STOP"); + startstop_view.setTextColor(0xFFFF8888); + } else { + startstop_view.setText("START"); + startstop_view.setTextColor(0xFF88FF88); + } + } + private void startstop_clicked(View v) { save_prefs(); - /* XXX */ + Intent i = new Intent(this, SimpleSSHDService.class); + if (SimpleSSHDService.is_started() { + i.putExtra("stop", true); + } + startService(i); } private void load_prefs() { diff --git a/src/org/galexander/sshd/SimpleSSHDService.java b/src/org/galexander/sshd/SimpleSSHDService.java index 7ebac8d..a17d93e 100644 --- a/src/org/galexander/sshd/SimpleSSHDService.java +++ b/src/org/galexander/sshd/SimpleSSHDService.java @@ -6,6 +6,7 @@ import android.os.IBinder; public class SimpleSSHDService extends Service { public static int sshd_pid = 0; + public static SimpleSSHD activity = null; public int onStartCommand(Intent intent, int flags, int startId) { if ((intent == null) || @@ -14,9 +15,15 @@ public class SimpleSSHDService extends Service { stop_sshd(); } start_sshd(); + if (activity != null) { + activity.update_startstop(); + } return START_STICKY; } else { stop_sshd(); + if (activity != null) { + activity.update_startstop(); + } return START_NOT_STICKY; } }