diff --git a/app/app.iml b/app/app.iml index e1ed02b..da2d840 100644 --- a/app/app.iml +++ b/app/app.iml @@ -67,15 +67,18 @@ + + + diff --git a/app/src/main/java/uk/org/openseizuredetector/MainActivity.java b/app/src/main/java/uk/org/openseizuredetector/MainActivity.java index 976b426..750b3ab 100644 --- a/app/src/main/java/uk/org/openseizuredetector/MainActivity.java +++ b/app/src/main/java/uk/org/openseizuredetector/MainActivity.java @@ -26,23 +26,14 @@ package uk.org.openseizuredetector; import android.app.Activity; -import android.app.ActivityManager; -import android.app.ActivityManager.RunningServiceInfo; import android.app.AlertDialog; -import android.content.ComponentName; -import android.content.Context; import android.content.Intent; import android.content.pm.PackageManager; -import android.content.pm.PackageInfo; -import android.content.ServiceConnection; import android.content.SharedPreferences; import android.graphics.Color; -import android.graphics.PorterDuff; import android.graphics.drawable.Drawable; -import android.net.Uri; import android.os.Bundle; import android.os.Handler; -import android.os.IBinder; import android.os.Message; import android.os.Messenger; import android.preference.PreferenceManager; @@ -57,15 +48,10 @@ import android.widget.TextView; import android.widget.Button; import java.lang.reflect.Field; -import java.net.InetAddress; -import java.net.NetworkInterface; import java.util.ArrayList; -import java.util.Enumeration; import java.util.Timer; import java.util.TimerTask; -import org.apache.http.conn.util.InetAddressUtils; - //MPAndroidChart import com.github.mikephil.charting.charts.LineChart; import com.github.mikephil.charting.data.Entry; @@ -77,6 +63,9 @@ public class MainActivity extends Activity { private int okColour = Color.BLUE; private int warnColour = Color.MAGENTA; private int alarmColour = Color.RED; + private int okTextColour = Color.WHITE; + private int warnTextColour = Color.WHITE; + private int alarmTextColour = Color.BLACK; private OsdUtil mUtil; private SdServiceConnection mConnection; private Menu mOptionsMenu; @@ -307,18 +296,26 @@ public class MainActivity extends Activity { final Runnable serverStatusRunnable = new Runnable() { public void run() { TextView tv; - tv = (TextView) findViewById(R.id.textView1); if (mUtil.isServerRunning()) { + tv = (TextView) findViewById(R.id.serverStatusTv); tv.setText("Server Running OK"); tv.setBackgroundColor(okColour); - tv = (TextView) findViewById(R.id.textView2); + tv.setTextColor(okTextColour); + tv = (TextView) findViewById(R.id.serverIpTv); tv.setText("Access Server at http://" + mUtil.getLocalIpAddress() + ":8080"); tv.setBackgroundColor(okColour); + tv.setTextColor(okTextColour); } else { - tv.setText("*** Server Stopped ***"); - tv.setBackgroundColor(alarmColour); + tv = (TextView) findViewById(R.id.serverStatusTv); + tv.setText("Server Stopped"); + tv.setBackgroundColor(warnColour); + tv.setTextColor(warnTextColour); + tv = (TextView) findViewById(R.id.serverIpTv); + tv.setText("--"); + tv.setBackgroundColor(warnColour); + tv.setTextColor(warnTextColour); } @@ -330,53 +327,71 @@ public class MainActivity extends Activity { && !mConnection.mSdServer.mSdData.fallAlarmStanding) { tv.setText("OK"); tv.setBackgroundColor(okColour); + tv.setTextColor(okTextColour); } if ((mConnection.mSdServer.mSdData.alarmState == 1) && !mConnection.mSdServer.mSdData.alarmStanding && !mConnection.mSdServer.mSdData.fallAlarmStanding) { tv.setText("WARNING"); tv.setBackgroundColor(warnColour); + tv.setTextColor(warnTextColour); } if (mConnection.mSdServer.mSdData.alarmState == 4) { tv.setText("FAULT"); tv.setBackgroundColor(warnColour); + tv.setTextColor(warnTextColour); } if (mConnection.mSdServer.mSdData.alarmStanding) { tv.setText("**ALARM**"); tv.setBackgroundColor(alarmColour); + tv.setTextColor(alarmTextColour); } if (mConnection.mSdServer.mSdData.fallAlarmStanding) { tv.setText("**FALL**"); tv.setBackgroundColor(alarmColour); + tv.setTextColor(alarmTextColour); } tv = (TextView) findViewById(R.id.pebTimeTv); tv.setText(mConnection.mSdServer.mSdData.dataTime.format("%H:%M:%S")); + tv.setBackgroundColor(okColour); + tv.setTextColor(okTextColour); + // Pebble Connected Phrase tv = (TextView) findViewById(R.id.pebbleTv); if (mConnection.mSdServer.mSdData.pebbleConnected) { tv.setText("Pebble Watch Connected OK"); tv.setBackgroundColor(okColour); + tv.setTextColor(okTextColour); + } else { - tv.setText("** Pebble Watch NOT Connected **"); - tv.setBackgroundColor(alarmColour); + tv.setText("Pebble Watch NOT Connected"); + tv.setBackgroundColor(warnColour); + tv.setTextColor(warnTextColour); } tv = (TextView) findViewById(R.id.appTv); if (mConnection.mSdServer.mSdData.pebbleAppRunning) { tv.setText("Pebble App OK"); tv.setBackgroundColor(okColour); + tv.setTextColor(okTextColour); } else { - tv.setText("** Pebble App NOT Running **"); - tv.setBackgroundColor(alarmColour); + tv.setText("Pebble App NOT Running"); + tv.setBackgroundColor(warnColour); + tv.setTextColor(warnTextColour); } tv = (TextView) findViewById(R.id.battTv); tv.setText("Pebble Battery = " + String.valueOf(mConnection.mSdServer.mSdData.batteryPc) + "%"); - if (mConnection.mSdServer.mSdData.batteryPc <= 20) + if (mConnection.mSdServer.mSdData.batteryPc <= 20) { tv.setBackgroundColor(alarmColour); - if (mConnection.mSdServer.mSdData.batteryPc > 20) + tv.setTextColor(alarmTextColour); + } + if (mConnection.mSdServer.mSdData.batteryPc > 20) { tv.setBackgroundColor(warnColour); - if (mConnection.mSdServer.mSdData.batteryPc >= 40) + tv.setTextColor(warnTextColour); + } + if (mConnection.mSdServer.mSdData.batteryPc >= 40) { tv.setBackgroundColor(okColour); - + tv.setTextColor(okTextColour); + } // Set ProgressBars to show margin to alarm. long powerPc = mConnection.mSdServer.mSdData.roiPower * 100 / mConnection.mSdServer.mSdData.alarmThresh; @@ -411,15 +426,25 @@ public class MainActivity extends Activity { if (specPc > 100) pbDrawable = getResources().getDrawable(R.drawable.progress_bar_red); //pb.getProgressDrawable().setColorFilter(colour, PorterDuff.Mode.SRC_IN); pb.setProgressDrawable(pbDrawable); - } else { + } else { // Not bound to server tv = (TextView) findViewById(R.id.alarmTv); - tv.setText("Not Connected to Server"); + tv.setText("------"); tv.setBackgroundColor(warnColour); + tv.setTextColor(warnTextColour); + } } catch (Exception e) { Log.v(TAG, "ServerStatusRunnable: Exception - " + e.toString()); } + // deal with latch alarms button + Button acceptAlarmButton = (Button) findViewById(R.id.acceptAlarmButton); + if (mConnection.mBound) + if (mConnection.mSdServer.isLatchAlarms()) { + acceptAlarmButton.setEnabled(true); + } else { + acceptAlarmButton.setEnabled(false); + } // Deal with Cancel Audible button Button cancelAudibleButton = diff --git a/app/src/main/java/uk/org/openseizuredetector/SdDataSourcePebble.java b/app/src/main/java/uk/org/openseizuredetector/SdDataSourcePebble.java index 9e94d9d..9f69513 100644 --- a/app/src/main/java/uk/org/openseizuredetector/SdDataSourcePebble.java +++ b/app/src/main/java/uk/org/openseizuredetector/SdDataSourcePebble.java @@ -363,6 +363,7 @@ public class SdDataSourcePebble extends SdDataSource { * Attempt to start the pebble_sd watch app on the pebble watch. */ public void startWatchApp() { + Log.v(TAG, "startWatchApp()"); PebbleKit.startAppOnPebble(mContext, SD_UUID); } @@ -371,6 +372,7 @@ public class SdDataSourcePebble extends SdDataSource { * stop the pebble_sd watch app on the pebble watch. */ public void stopWatchApp() { + Log.v(TAG, "stopWatchApp()"); PebbleKit.closeAppOnPebble(mContext, SD_UUID); } @@ -395,6 +397,7 @@ public class SdDataSourcePebble extends SdDataSource { * If the watch app is not running, it attempts to re-start it. */ public void getPebbleStatus() { + Log.v(TAG, "getPebbleStatus()"); Time tnow = new Time(Time.getCurrentTimezone()); long tdiff; tnow.setToNow(); diff --git a/app/src/main/java/uk/org/openseizuredetector/SdServer.java b/app/src/main/java/uk/org/openseizuredetector/SdServer.java index 1becade..b05a7e7 100644 --- a/app/src/main/java/uk/org/openseizuredetector/SdServer.java +++ b/app/src/main/java/uk/org/openseizuredetector/SdServer.java @@ -224,8 +224,13 @@ public class SdServer extends Service implements SdDataReceiver { // release the wake lock to allow CPU to sleep and reduce // battery drain. if (mWakeLock != null) { - mWakeLock.release(); - Log.v(TAG, "Released Wake Lock to allow device to sleep."); + try { + mWakeLock.release(); + Log.v(TAG, "Released Wake Lock to allow device to sleep."); + } catch (Exception e) { + Log.e(TAG, "Error Releasing Wakelock - " + e.toString()); + mUtil.showToast("Error Releasing Wakelock"); + } } else { Log.d(TAG, "mmm...mWakeLock is null, so not releasing lock. This shouldn't happen!"); } @@ -505,6 +510,9 @@ public class SdServer extends Service implements SdDataReceiver { return mCancelAudibleTimeRemaining; } + public boolean isLatchAlarms() { + return mLatchAlarms; + } /** diff --git a/app/src/main/java/uk/org/openseizuredetector/StartupActivity.java b/app/src/main/java/uk/org/openseizuredetector/StartupActivity.java index e69569d..daa4cc8 100644 --- a/app/src/main/java/uk/org/openseizuredetector/StartupActivity.java +++ b/app/src/main/java/uk/org/openseizuredetector/StartupActivity.java @@ -52,6 +52,10 @@ public class StartupActivity extends Activity { private int okColour = Color.BLUE; private int warnColour = Color.MAGENTA; private int alarmColour = Color.RED; + private int okTextColour = Color.WHITE; + private int warnTextColour = Color.BLACK; + private int alarmTextColour = Color.BLACK; + private OsdUtil mUtil; private Timer mUiTimer; @@ -111,6 +115,13 @@ public class StartupActivity extends Activity { TextView tv = (TextView)findViewById(R.id.dataSourceTextView); tv.setText("DataSource = "+dataSourceName); + // disable pebble configuration button if we have not selected the pebble datasource + if (!dataSourceName.equals("Pebble")) { + Log.v(TAG, "Not Pebble Datasource - deactivating Pebble Button"); + Button b = (Button) findViewById(R.id.pebbleButton); + b.setEnabled(false); + } + if (mUtil.isServerRunning()) { Log.v(TAG, "onStart() - server running - stopping it"); mUtil.stopServer(); @@ -160,11 +171,13 @@ public class StartupActivity extends Activity { if (mUtil.isServerRunning()) { tv.setText("Background Service Running OK"); tv.setBackgroundColor(okColour); + tv.setTextColor(okTextColour); pb.setIndeterminateDrawable(getResources().getDrawable(R.drawable.start_server)); pb.setProgressDrawable(getResources().getDrawable(R.drawable.start_server)); } else { tv.setText("Waiting for Background Service..."); tv.setBackgroundColor(alarmColour); + tv.setTextColor(alarmTextColour); pb.setIndeterminate(true); allOk = false; } @@ -175,11 +188,13 @@ public class StartupActivity extends Activity { if (mConnection.mBound) { tv.setText("Bound to Service OK"); tv.setBackgroundColor(okColour); + tv.setTextColor(okTextColour); pb.setIndeterminateDrawable(getResources().getDrawable(R.drawable.start_server)); pb.setProgressDrawable(getResources().getDrawable(R.drawable.start_server)); } else { tv.setText("Binding to Background Service..."); tv.setBackgroundColor(alarmColour); + tv.setTextColor(alarmTextColour); pb.setIndeterminate(true); allOk = false; } @@ -190,11 +205,13 @@ public class StartupActivity extends Activity { if (mConnection.pebbleConnected()) { tv.setText("Pebble Watch Connected OK"); tv.setBackgroundColor(okColour); + tv.setTextColor(okTextColour); pb.setIndeterminateDrawable(getResources().getDrawable(R.drawable.start_server)); pb.setProgressDrawable(getResources().getDrawable(R.drawable.start_server)); } else { tv.setText("Waiting to Connect to Pebble Watch....."); tv.setBackgroundColor(alarmColour); + tv.setTextColor(alarmTextColour); pb.setIndeterminate(true); allOk = false; } @@ -205,11 +222,13 @@ public class StartupActivity extends Activity { if (mConnection.pebbleAppRunning()) { tv.setText("Watch App Running OK"); tv.setBackgroundColor(okColour); + tv.setTextColor(okTextColour); pb.setIndeterminateDrawable(getResources().getDrawable(R.drawable.start_server)); pb.setProgressDrawable(getResources().getDrawable(R.drawable.start_server)); } else { tv.setText("Waiting for Watch App to Start....."); tv.setBackgroundColor(alarmColour); + tv.setTextColor(alarmTextColour); pb.setIndeterminate(true); allOk = false; } @@ -221,11 +240,13 @@ public class StartupActivity extends Activity { if (mConnection.hasSdData()) { tv.setText("Seizure Detector Data Received OK"); tv.setBackgroundColor(okColour); + tv.setTextColor(okTextColour); pb.setIndeterminateDrawable(getResources().getDrawable(R.drawable.start_server)); pb.setProgressDrawable(getResources().getDrawable(R.drawable.start_server)); } else { tv.setText("Waiting for Seizure Detector Data..."); tv.setBackgroundColor(alarmColour); + tv.setTextColor(alarmTextColour); pb.setIndeterminate(true); allOk = false; } @@ -237,11 +258,13 @@ public class StartupActivity extends Activity { if (mConnection.hasSdSettings()) { tv.setText("Seizure Detector Settings Received OK"); tv.setBackgroundColor(okColour); + tv.setTextColor(okTextColour); pb.setIndeterminateDrawable(getResources().getDrawable(R.drawable.start_server)); pb.setProgressDrawable(getResources().getDrawable(R.drawable.start_server)); } else { tv.setText("Waiting for Seizure Detector Settings..."); tv.setBackgroundColor(alarmColour); + tv.setTextColor(alarmTextColour); pb.setIndeterminate(true); allOk = false; } diff --git a/app/src/main/res/drawable/progress_bar_red.xml b/app/src/main/res/drawable/progress_bar_red.xml index 4fc1392..f8b1a34 100644 --- a/app/src/main/res/drawable/progress_bar_red.xml +++ b/app/src/main/res/drawable/progress_bar_red.xml @@ -20,10 +20,10 @@ diff --git a/app/src/main/res/drawable/progress_bar_yellow.xml b/app/src/main/res/drawable/progress_bar_yellow.xml index b501d6f..6bf7dc0 100644 --- a/app/src/main/res/drawable/progress_bar_yellow.xml +++ b/app/src/main/res/drawable/progress_bar_yellow.xml @@ -20,10 +20,10 @@ diff --git a/app/src/main/res/layout/main.xml b/app/src/main/res/layout/main.xml index 0fb75eb..591abb3 100644 --- a/app/src/main/res/layout/main.xml +++ b/app/src/main/res/layout/main.xml @@ -1,139 +1,139 @@ - - - - - - - + android:layout_width="fill_parent" + android:layout_height="fill_parent" + android:orientation="vertical"> + + + - - - + android:layout_width="fill_parent" + android:layout_height="wrap_content" + android:orientation="horizontal"> + + + + + + android:layout_width="fill_parent" + android:layout_height="wrap_content" + android:orientation="horizontal"> - - - + + + + + + + + + + + + + + + - + - + - + - + - + - -