V3.0.4 - Fixed problem with crashing after server stopped, and crash when selecting install watch app menu option. And I think I have finally sorted the problem of multiple

versions of the server running...but might be wrong - clsoe the issue anyway and see what happens.
Also tidied up main app screen when server stopped or in fault condition.
Closes #13, Closes #12, Closes #11
This commit is contained in:
Graham Jones
2019-03-17 13:41:48 +00:00
parent cb2bf280e0
commit 33a11f0e73
9 changed files with 109 additions and 79 deletions

View File

@@ -159,13 +159,12 @@ public class MainActivity extends AppCompatActivity {
public boolean onCreateOptionsMenu(Menu menu) {
Log.i(TAG, "onCreateOptionsMenu()");
getMenuInflater().inflate(R.menu.main_activity_actions, menu);
mOptionsMenu = menu;
if (mConnection.mSdServer.mSdDataSourceName != "Pebble") {
Log.v(TAG,"Disabling Pebble Specific Menu Items");
menu.findItem(R.id.action_instal_watch_app).setEnabled(false);
menu.findItem(R.id.action_launch_pebble_app).setEnabled(false);
}
//mOptionsMenu = menu;
//if (mConnection.mSdServer.mSdDataSourceName != "Pebble") {
// Log.v(TAG,"Disabling Pebble Specific Menu Items");
// menu.findItem(R.id.action_instal_watch_app).setEnabled(false);
// menu.findItem(R.id.action_launch_pebble_app).setEnabled(false);
//}
return true;
}
@@ -173,15 +172,17 @@ public class MainActivity extends AppCompatActivity {
public boolean onOptionsItemSelected(MenuItem item) {
Log.i(TAG, "onOptionsItemSelected() : " + item.getItemId() + " selected");
switch (item.getItemId()) {
case R.id.action_launch_pebble_app:
/*case R.id.action_launch_pebble_app:
Log.i(TAG, "action_launch_pebble_app");
mConnection.mSdServer.mSdDataSource.startPebbleApp();
return true;
case R.id.action_instal_watch_app:
*/
case R.id.action_install_watch_app:
Log.i(TAG, "action_install_watch_app");
mConnection.mSdServer.mSdDataSource.installWatchApp();
return true;
case R.id.action_accept_alarm:
case R.id.action_accept_alarm:
Log.i(TAG, "action_accept_alarm");
if (mConnection.mBound) {
mConnection.mSdServer.acceptAlarm();
@@ -281,10 +282,13 @@ public class MainActivity extends AppCompatActivity {
String versionName = mUtil.getAppVersionName();
tv.setText("OpenSeizureDetector Android App Version " + versionName);
Log.i(TAG,"onStart() - binding to server");
mUtil.writeToSysLogFile("MainActivity.onStart - Binding to Server");
mUtil.bindToServer(this, mConnection);
if (mUtil.isServerRunning()) {
mUtil.writeToSysLogFile("MainActivity.onStart - Binding to Server");
mUtil.bindToServer(this, mConnection);
} else {
Log.i(TAG,"onStart() - Server Not Running");
mUtil.writeToSysLogFile("MainActivity.onStart - Server Not Running");
}
// start timer to refresh user interface every second.
mUiTimer = new Timer();
mUiTimer.schedule(new TimerTask() {
@@ -395,21 +399,11 @@ public class MainActivity extends AppCompatActivity {
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.alarmState == 6) {
tv.setText("MUTE");
tv.setBackgroundColor(warnColour);
tv.setTextColor(warnTextColour);
}
if (mConnection.mSdServer.mSdData.alarmState == 7) {
tv.setText("NET FAULT");
tv.setBackgroundColor(warnColour);
tv.setTextColor(warnTextColour);
}
if (mConnection.mSdServer.mSdData.alarmStanding) {
tv.setText("**ALARM**");
tv.setBackgroundColor(alarmColour);
@@ -420,6 +414,7 @@ public class MainActivity extends AppCompatActivity {
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);
@@ -526,12 +521,79 @@ public class MainActivity extends AppCompatActivity {
pbDrawable = getResources().getDrawable(R.drawable.progress_bar_red);
//pb.getProgressDrawable().setColorFilter(colour, PorterDuff.Mode.SRC_IN);
pb.setProgressDrawable(pbDrawable);
// Fault Conditions - We override the values in the UI because we do not know
// if the stored ones are correct or not with a fault present.
if ((mConnection.mSdServer.mSdData.alarmState == 4) ||
(mConnection.mSdServer.mSdData.alarmState == 7)) {
tv = (TextView) findViewById(R.id.alarmTv);
if (mConnection.mSdServer.mSdData.alarmState == 4) {
tv.setText("FAULT");
tv.setBackgroundColor(warnColour);
tv.setTextColor(warnTextColour);
}
if (mConnection.mSdServer.mSdData.alarmState == 7) {
tv.setText("NET FAULT");
tv.setBackgroundColor(warnColour);
tv.setTextColor(warnTextColour);
}
tv = (TextView) findViewById(R.id.pebTimeTv);
tv.setText(mConnection.mSdServer.mSdData.dataTime.format("%H:%M:%S"));
tv.setBackgroundColor(okColour);
tv.setTextColor(okTextColour);
tv = (TextView) findViewById(R.id.pebTimeTv);
tv.setText("--:--:--");
tv.setBackgroundColor(warnColour);
tv.setTextColor(warnTextColour);
tv = (TextView) findViewById(R.id.pebbleTv);
tv.setText("HR = ---");
tv.setBackgroundColor(warnColour);
tv.setTextColor(warnTextColour);
tv = (TextView) findViewById(R.id.appTv);
tv.setText("Watch App -----");
tv.setBackgroundColor(warnColour);
tv.setTextColor(warnTextColour);
tv = (TextView) findViewById(R.id.battTv);
tv.setText("Watch Battery = ---%");
tv.setBackgroundColor(warnColour);
tv.setTextColor(warnTextColour);
}
} else { // Not bound to server
tv = (TextView) findViewById(R.id.alarmTv);
tv.setText("------");
tv.setBackgroundColor(warnColour);
tv.setTextColor(warnTextColour);
tv = (TextView) findViewById(R.id.pebTimeTv);
tv.setText(mConnection.mSdServer.mSdData.dataTime.format("%H:%M:%S"));
tv.setBackgroundColor(okColour);
tv.setTextColor(okTextColour);
tv = (TextView) findViewById(R.id.pebTimeTv);
tv.setText("--:--:--");
tv.setBackgroundColor(warnColour);
tv.setTextColor(warnTextColour);
tv = (TextView) findViewById(R.id.pebbleTv);
tv.setText("HR = ---");
tv.setBackgroundColor(warnColour);
tv.setTextColor(warnTextColour);
tv = (TextView) findViewById(R.id.appTv);
tv.setText("Watch App -----");
tv.setBackgroundColor(warnColour);
tv.setTextColor(warnTextColour);
tv = (TextView) findViewById(R.id.battTv);
tv.setText("Watch Battery = ---%");
tv.setBackgroundColor(warnColour);
tv.setTextColor(warnTextColour);
}
} catch (Exception e) {
Log.e(TAG, "ServerStatusRunnable: Exception - ");

View File

@@ -24,6 +24,8 @@
package uk.org.openseizuredetector;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.os.Handler;
import android.util.Log;
import android.widget.Toast;
@@ -81,7 +83,17 @@ public abstract class SdDataSource {
/**
* Install the watch app on the watch.
*/
public void installWatchApp() { Log.v(TAG,"installWatchApp"); }
public void installWatchApp() {
Log.v(TAG,"installWatchApp");
try {
String url = "http://www.openseizuredetector.org.uk/?page_id=1207";
Intent i = new Intent(Intent.ACTION_VIEW);
i.setData(Uri.parse(url));
mContext.startActivity(i);
} catch (Exception ex) {
Log.i(TAG, "exception starting install watch app activity " + ex.toString());
}
}
public void startPebbleApp() { Log.v(TAG,"startPebbleApp()"); }

View File

@@ -739,52 +739,6 @@ public class SdDataSourcePebble extends SdDataSource {
nRawData = 0;
}
/**
* Install the wach app that is bundled in the 'assets' folder of this
* phone app.
* from https://github.com/pebble-examples/pebblekit-android-example/blob/master/android/Eclipse/src/com/getpebble/pebblekitexample/MainActivity.java#L148
*/
@Override
public void installWatchApp() {
Log.v(TAG, "SdDataSourcePebble.installWatchApp()");
mUtil.writeToSysLogFile("SdDataSourcePebble.installWatchApp()");
final String WATCHAPP_FILENAME = "pebble_sd.pbw";
try {
// Read .pbw from assets/
Intent intent = new Intent(Intent.ACTION_VIEW);
File file = new File(mContext.getExternalFilesDir(null), WATCHAPP_FILENAME);
InputStream is = mContext.getResources().getAssets().open(WATCHAPP_FILENAME);
OutputStream os = new FileOutputStream(file);
byte[] pbw = new byte[is.available()];
is.read(pbw);
os.write(pbw);
is.close();
os.close();
// Install via Pebble Android app
intent.setDataAndType(Uri.fromFile(file), "application/pbw");
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
mContext.startActivity(intent);
} catch (IOException e) {
mUtil.writeToSysLogFile("SdDataSourcePebble.installWatchApp() - app install failed"+e.toString());
Toast.makeText(mContext, "App install failed: " + e.getLocalizedMessage(), Toast.LENGTH_LONG).show();
}
}
/**
* Install the OpenSeizureDetector watch app onto the watch from Pebble AppStore
* based on https://forums.getpebble.com/discussion/13128/install-watch-app-pebble-store-from-android-companion-app
*/
public void installWatchAppFromPebbleAppStore() {
Intent myIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("pebble://appstore/54d28a43e4d94c043f000008"));
myIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK);
mContext.startActivity(myIntent);
}
/**
* Open Pebble or Pebble Time app. If it is not installed, open Play store so the user can install it.

View File

@@ -501,6 +501,7 @@ public class StartupActivity extends Activity {
+ "http://openseizuredetector.org.uk, or the app Facebook page at https://www.facebook.com/openseizuredetector. "
+ "so I can get in touch if necessary.\nThank you! Graham \ngraham@openseizuredetector.org.uk "
+ "\n\nChanges in this version:"
+ "\n- V3.0.4 - Fixed issues with install watch app, and stopping server resulting in crashes"
+ "\n- V3.0.3 - Fixed problem with crash on phone boot if Auto Start on Boot option selected"
+ "\n- Upgraded to be compatible with Android Version 9"
+ "\n- Added support a Garmin based seizure detector with Heart Rate alarm "
@@ -536,6 +537,7 @@ public class StartupActivity extends Activity {
+ "http://openseizuredetector.org.uk, or the app Facebook page at https://www.facebook.com/openseizuredetector. "
+ "so I can get in touch if necessary.\nThank you! Graham \ngraham@openseizuredetector.org.uk "
+ "\n\nChanges in this version:"
+ "\n- V3.0.4 - Fixed issues with install watch app, and stopping server resulting in crashes"
+ "\n- V3.0.3 - Fixed problem with crash on phone boot if Auto Start on Boot option selected"
+ "\n- Upgraded to be compatible with Android Version 9"
+ "\n- Added support for a Garmin based seizure detector with Heart Rate alarm "