Modified mainactivity to use generic utilities. Added more rows to startup screen.

This commit is contained in:
Graham Jones
2015-11-20 22:58:26 +00:00
parent 63604bc25b
commit 856b3c5d3d
6 changed files with 263 additions and 208 deletions

View File

@@ -65,26 +65,20 @@
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/jni" isTestSource="true" /> <sourceFolder url="file://$MODULE_DIR$/src/androidTest/jni" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/rs" isTestSource="true" /> <sourceFolder url="file://$MODULE_DIR$/src/androidTest/rs" isTestSource="true" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/assets" /> <excludeFolder url="file://$MODULE_DIR$/build/intermediates/assets" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/bundles" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/classes" /> <excludeFolder url="file://$MODULE_DIR$/build/intermediates/classes" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/coverage-instrumented-classes" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/dependency-cache" /> <excludeFolder url="file://$MODULE_DIR$/build/intermediates/dependency-cache" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/dex" /> <excludeFolder url="file://$MODULE_DIR$/build/intermediates/dex" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/dex-cache" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.android.support/appcompat-v7/22.2.1/jars" /> <excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.android.support/appcompat-v7/22.2.1/jars" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.android.support/support-v4/22.2.1/jars" /> <excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.android.support/support-v4/22.2.1/jars" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/incremental" /> <excludeFolder url="file://$MODULE_DIR$/build/intermediates/incremental" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/jacoco" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/javaResources" /> <excludeFolder url="file://$MODULE_DIR$/build/intermediates/javaResources" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/libs" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/lint" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/manifests" /> <excludeFolder url="file://$MODULE_DIR$/build/intermediates/manifests" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/ndk" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/pre-dexed" /> <excludeFolder url="file://$MODULE_DIR$/build/intermediates/pre-dexed" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/proguard" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/res" /> <excludeFolder url="file://$MODULE_DIR$/build/intermediates/res" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/resources" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/rs" /> <excludeFolder url="file://$MODULE_DIR$/build/intermediates/rs" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/symbols" /> <excludeFolder url="file://$MODULE_DIR$/build/intermediates/symbols" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/tmp" />
<excludeFolder url="file://$MODULE_DIR$/build/outputs" /> <excludeFolder url="file://$MODULE_DIR$/build/outputs" />
<excludeFolder url="file://$MODULE_DIR$/build/tmp" /> <excludeFolder url="file://$MODULE_DIR$/build/tmp" />
</content> </content>

View File

@@ -74,9 +74,8 @@ public class MainActivity extends Activity {
private int okColour = Color.BLUE; private int okColour = Color.BLUE;
private int warnColour = Color.MAGENTA; private int warnColour = Color.MAGENTA;
private int alarmColour = Color.RED; private int alarmColour = Color.RED;
OsdUtil mUtil; private OsdUtil mUtil;
SdServer mSdServer; private SdServiceConnection mConnection;
boolean mBound = false;
private Menu mOptionsMenu; private Menu mOptionsMenu;
private Intent sdServerIntent; private Intent sdServerIntent;
@@ -92,6 +91,7 @@ public class MainActivity extends Activity {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
mUtil = new OsdUtil(this); mUtil = new OsdUtil(this);
mConnection = new SdServiceConnection(this);
// Initialise the User Interface // Initialise the User Interface
setContentView(R.layout.main); setContentView(R.layout.main);
@@ -119,8 +119,8 @@ public class MainActivity extends Activity {
button.setOnClickListener(new View.OnClickListener() { button.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) { public void onClick(View v) {
Log.v(TAG, "acceptAlarmButton.onClick()"); Log.v(TAG, "acceptAlarmButton.onClick()");
if (mBound) { if (mConnection.mBound) {
mSdServer.acceptAlarm(); mConnection.mSdServer.acceptAlarm();
} }
} }
}); });
@@ -163,46 +163,46 @@ public class MainActivity extends Activity {
case R.id.action_accept_alarm: case R.id.action_accept_alarm:
Log.v(TAG, "action_accept_alarm"); Log.v(TAG, "action_accept_alarm");
if (mBound) { if (mConnection.mBound) {
mSdServer.acceptAlarm(); mConnection.mSdServer.acceptAlarm();
} }
return true; return true;
case R.id.action_start_stop: case R.id.action_start_stop:
// Respond to the start/stop server menu item. // Respond to the start/stop server menu item.
Log.v(TAG, "action_sart_stop"); Log.v(TAG, "action_sart_stop");
if (mBound) { if (mConnection.mBound) {
Log.v(TAG, "Stopping Server"); Log.v(TAG, "Stopping Server");
unbindFromServer(); mUtil.unbindFromServer(this, mConnection);
stopServer(); stopServer();
} else { } else {
Log.v(TAG, "Starting Server"); Log.v(TAG, "Starting Server");
startServer(); startServer();
// and bind to it so we can see its data // and bind to it so we can see its data
bindToServer(); mUtil.bindToServer(this, mConnection);
} }
return true; return true;
case R.id.action_test_fault_beep: case R.id.action_test_fault_beep:
Log.v(TAG, "action_test_fault_beep"); Log.v(TAG, "action_test_fault_beep");
if (mBound) { if (mConnection.mBound) {
mSdServer.faultWarningBeep(); mConnection.mSdServer.faultWarningBeep();
} }
return true; return true;
case R.id.action_test_alarm_beep: case R.id.action_test_alarm_beep:
Log.v(TAG, "action_test_alarm_beep"); Log.v(TAG, "action_test_alarm_beep");
if (mBound) { if (mConnection.mBound) {
mSdServer.alarmBeep(); mConnection.mSdServer.alarmBeep();
} }
return true; return true;
case R.id.action_test_warning_beep: case R.id.action_test_warning_beep:
Log.v(TAG, "action_test_warning_beep"); Log.v(TAG, "action_test_warning_beep");
if (mBound) { if (mConnection.mBound) {
mSdServer.warningBeep(); mConnection.mSdServer.warningBeep();
} }
return true; return true;
case R.id.action_test_sms_alarm: case R.id.action_test_sms_alarm:
Log.v(TAG, "action_test_sms_alarm"); Log.v(TAG, "action_test_sms_alarm");
if (mBound) { if (mConnection.mBound) {
mSdServer.sendSMSAlarm(); mConnection.mSdServer.sendSMSAlarm();
} }
return true; return true;
case R.id.action_settings: case R.id.action_settings:
@@ -236,93 +236,19 @@ public class MainActivity extends Activity {
TextView tv; TextView tv;
tv = (TextView) findViewById(R.id.versionTv); tv = (TextView) findViewById(R.id.versionTv);
String versionName = "unknown"; String versionName = mUtil.getAppVersionName();
// From http://stackoverflow.com/questions/4471025/
// how-can-you-get-the-manifest-version-number-
// from-the-apps-layout-xml-variable
final PackageManager packageManager = getPackageManager();
if (packageManager != null) {
try {
PackageInfo packageInfo = packageManager.getPackageInfo(getPackageName(), 0);
versionName = packageInfo.versionName;
} catch (PackageManager.NameNotFoundException e) {
Log.v(TAG, "failed to find versionName");
versionName = null;
}
}
tv.setText("OpenSeizureDetector Server Version " + versionName); tv.setText("OpenSeizureDetector Server Version " + versionName);
if (!mUtil.isServerRunning()) { mUtil.bindToServer(this, mConnection);
Log.v(TAG, "Server not Running - Starting Server");
startServer();
} else {
Log.v(TAG, "Server Already Running OK");
}
// and bind to it so we can see its data
bindToServer();
} }
@Override @Override
protected void onStop() { protected void onStop() {
super.onStop(); super.onStop();
unbindFromServer(); mUtil.unbindFromServer(this,mConnection);
} }
/**
* Defines callbacks for service binding, passed to bindService()
*/
private ServiceConnection mConnection = new ServiceConnection() {
@Override
public void onServiceConnected(ComponentName className,
IBinder service) {
// We've bound to LocalService, cast the IBinder and get LocalService instance
SdServer.SdBinder binder = (SdServer.SdBinder) service;
mSdServer = binder.getService();
mBound = true;
if (mSdServer != null) {
Log.v(TAG, "onServiceConnected() - Asking server to update its settings");
mSdServer.updatePrefs();
} else {
Log.v(TAG, "onServiceConnected() - mSdServer is null - this is wrong!");
}
}
@Override
public void onServiceDisconnected(ComponentName arg0) {
Log.v(TAG, "onServiceDisonnected()");
mBound = false;
}
};
/**
* bind to an already running server.
*/
private void bindToServer() {
Log.v(TAG, "bindToServer() - binding to SdServer");
Intent intent = new Intent(this, SdServer.class);
bindService(intent, mConnection, Context.BIND_AUTO_CREATE);
}
/**
* unbind from server
*/
private void unbindFromServer() {
// unbind this activity from the service if it is bound.
if (mBound) {
Log.v(TAG, "unbindFromServer() - unbinding");
try {
unbindService(mConnection);
mBound = false;
} catch (Exception ex) {
Log.e(TAG, "unbindFromServer() - error unbinding service - " + ex.toString());
}
} else {
Log.v(TAG, "unbindFromServer() - not bound to server - ignoring");
}
}
private void startServer() { private void startServer() {
mUtil.startServer(); mUtil.startServer();
@@ -351,38 +277,6 @@ public class MainActivity extends Activity {
} }
/**
* get the ip address of the phone.
* Based on http://stackoverflow.com/questions/11015912/how-do-i-get-ip-address-in-ipv4-format
*/
public String getLocalIpAddress() {
try {
for (Enumeration<NetworkInterface> en = NetworkInterface
.getNetworkInterfaces(); en.hasMoreElements(); ) {
NetworkInterface intf = en.nextElement();
for (Enumeration<InetAddress> enumIpAddr = intf
.getInetAddresses(); enumIpAddr.hasMoreElements(); ) {
InetAddress inetAddress = enumIpAddr.nextElement();
//Log.v(TAG,"ip1--:" + inetAddress);
//Log.v(TAG,"ip2--:" + inetAddress.getHostAddress());
// for getting IPV4 format
if (!inetAddress.isLoopbackAddress()
&& InetAddressUtils.isIPv4Address(
inetAddress.getHostAddress())) {
String ip = inetAddress.getHostAddress().toString();
//Log.v(TAG,"ip---::" + ip);
return ip;
}
}
}
} catch (Exception ex) {
Log.e("IP Address", ex.toString());
}
return null;
}
/* /*
* updateServerStatus - called by the uiTimer timer periodically. * updateServerStatus - called by the uiTimer timer periodically.
@@ -405,7 +299,7 @@ public class MainActivity extends Activity {
tv.setBackgroundColor(okColour); tv.setBackgroundColor(okColour);
tv = (TextView) findViewById(R.id.textView2); tv = (TextView) findViewById(R.id.textView2);
tv.setText("Access Server at http://" tv.setText("Access Server at http://"
+ getLocalIpAddress() + mUtil.getLocalIpAddress()
+ ":8080"); + ":8080");
tv.setBackgroundColor(okColour); tv.setBackgroundColor(okColour);
} else { } else {
@@ -415,33 +309,33 @@ public class MainActivity extends Activity {
try { try {
if (mBound) { if (mConnection.mBound) {
tv = (TextView) findViewById(R.id.alarmTv); tv = (TextView) findViewById(R.id.alarmTv);
if ((mSdServer.mSdData.alarmState == 0) if ((mConnection.mSdServer.mSdData.alarmState == 0)
&& !mSdServer.mSdData.alarmStanding && !mConnection.mSdServer.mSdData.alarmStanding
&& !mSdServer.mSdData.fallAlarmStanding) { && !mConnection.mSdServer.mSdData.fallAlarmStanding) {
tv.setText("OK"); tv.setText("OK");
tv.setBackgroundColor(okColour); tv.setBackgroundColor(okColour);
} }
if ((mSdServer.mSdData.alarmState == 1) if ((mConnection.mSdServer.mSdData.alarmState == 1)
&& !mSdServer.mSdData.alarmStanding && !mConnection.mSdServer.mSdData.alarmStanding
&& !mSdServer.mSdData.fallAlarmStanding) { && !mConnection.mSdServer.mSdData.fallAlarmStanding) {
tv.setText("WARNING"); tv.setText("WARNING");
tv.setBackgroundColor(warnColour); tv.setBackgroundColor(warnColour);
} }
if (mSdServer.mSdData.alarmStanding) { if (mConnection.mSdServer.mSdData.alarmStanding) {
tv.setText("**ALARM**"); tv.setText("**ALARM**");
tv.setBackgroundColor(alarmColour); tv.setBackgroundColor(alarmColour);
} }
if (mSdServer.mSdData.fallAlarmStanding) { if (mConnection.mSdServer.mSdData.fallAlarmStanding) {
tv.setText("**FALL**"); tv.setText("**FALL**");
tv.setBackgroundColor(alarmColour); tv.setBackgroundColor(alarmColour);
} }
tv = (TextView) findViewById(R.id.pebTimeTv); tv = (TextView) findViewById(R.id.pebTimeTv);
tv.setText(mSdServer.mSdData.dataTime.format("%H:%M:%S")); tv.setText(mConnection.mSdServer.mSdData.dataTime.format("%H:%M:%S"));
// Pebble Connected Phrase // Pebble Connected Phrase
tv = (TextView) findViewById(R.id.pebbleTv); tv = (TextView) findViewById(R.id.pebbleTv);
if (mSdServer.mSdData.pebbleConnected) { if (mConnection.mSdServer.mSdData.pebbleConnected) {
tv.setText("Pebble Watch Connected OK"); tv.setText("Pebble Watch Connected OK");
tv.setBackgroundColor(okColour); tv.setBackgroundColor(okColour);
} else { } else {
@@ -449,7 +343,7 @@ public class MainActivity extends Activity {
tv.setBackgroundColor(alarmColour); tv.setBackgroundColor(alarmColour);
} }
tv = (TextView) findViewById(R.id.appTv); tv = (TextView) findViewById(R.id.appTv);
if (mSdServer.mSdData.pebbleAppRunning) { if (mConnection.mSdServer.mSdData.pebbleAppRunning) {
tv.setText("Pebble App OK"); tv.setText("Pebble App OK");
tv.setBackgroundColor(okColour); tv.setBackgroundColor(okColour);
} else { } else {
@@ -457,19 +351,19 @@ public class MainActivity extends Activity {
tv.setBackgroundColor(alarmColour); tv.setBackgroundColor(alarmColour);
} }
tv = (TextView) findViewById(R.id.battTv); tv = (TextView) findViewById(R.id.battTv);
tv.setText("Pebble Battery = " + String.valueOf(mSdServer.mSdData.batteryPc) + "%"); tv.setText("Pebble Battery = " + String.valueOf(mConnection.mSdServer.mSdData.batteryPc) + "%");
if (mSdServer.mSdData.batteryPc <= 20) if (mConnection.mSdServer.mSdData.batteryPc <= 20)
tv.setBackgroundColor(alarmColour); tv.setBackgroundColor(alarmColour);
if (mSdServer.mSdData.batteryPc > 20) if (mConnection.mSdServer.mSdData.batteryPc > 20)
tv.setBackgroundColor(warnColour); tv.setBackgroundColor(warnColour);
if (mSdServer.mSdData.batteryPc >= 40) if (mConnection.mSdServer.mSdData.batteryPc >= 40)
tv.setBackgroundColor(okColour); tv.setBackgroundColor(okColour);
tv = (TextView) findViewById(R.id.debugTv); tv = (TextView) findViewById(R.id.debugTv);
String specStr = ""; String specStr = "";
for (int i = 0; i < 10; i++) for (int i = 0; i < 10; i++)
specStr = specStr specStr = specStr
+ mSdServer.mSdData.simpleSpec[i] + mConnection.mSdServer.mSdData.simpleSpec[i]
+ ", "; + ", ";
tv.setText("Spec = " + specStr); tv.setText("Spec = " + specStr);
} else { } else {
@@ -493,8 +387,8 @@ public class MainActivity extends Activity {
// Y Values // Y Values
ArrayList<Entry> yVals = new ArrayList<Entry>(); ArrayList<Entry> yVals = new ArrayList<Entry>();
for (int i = 0; i < 10; i++) { for (int i = 0; i < 10; i++) {
if (mSdServer != null) if (mConnection.mSdServer != null)
yVals.add(new Entry(mSdServer.mSdData.simpleSpec[i], i)); yVals.add(new Entry(mConnection.mSdServer.mSdData.simpleSpec[i], i));
else else
yVals.add(new Entry(i, i)); yVals.add(new Entry(i, i));
} }
@@ -524,33 +418,11 @@ public class MainActivity extends Activity {
super.onResume(); super.onResume();
} }
//public void updateUi() {
// String statusPhrase;
// String alarmPhrase;
// String viewText = "Unknown";
//}
private String getAppVersionName() {
String versionName = "unknown";
// From http://stackoverflow.com/questions/4471025/
// how-can-you-get-the-manifest-version-number-
// from-the-apps-layout-xml-variable
final PackageManager packageManager = getPackageManager();
if (packageManager != null) {
try {
PackageInfo packageInfo = packageManager.getPackageInfo(getPackageName(), 0);
versionName = packageInfo.versionName;
} catch (PackageManager.NameNotFoundException e) {
Log.v(TAG, "failed to find versionName");
versionName = null;
}
}
return versionName;
}
private void showAbout() { private void showAbout() {
View aboutView = getLayoutInflater().inflate(R.layout.about_layout, null, false); View aboutView = getLayoutInflater().inflate(R.layout.about_layout, null, false);
String versionName = getAppVersionName(); String versionName = mUtil.getAppVersionName();
Log.v(TAG, "showAbout() - version name = " + versionName); Log.v(TAG, "showAbout() - version name = " + versionName);
AlertDialog.Builder builder = new AlertDialog.Builder(this); AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setIcon(R.drawable.icon_24x24); builder.setIcon(R.drawable.icon_24x24);

View File

@@ -30,11 +30,19 @@ import android.content.ComponentName;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.content.ServiceConnection; import android.content.ServiceConnection;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.net.Uri; import android.net.Uri;
import android.os.IBinder; import android.os.IBinder;
import android.util.Log; import android.util.Log;
import android.view.MenuItem; import android.view.MenuItem;
import org.apache.http.conn.util.InetAddressUtils;
import java.net.InetAddress;
import java.net.NetworkInterface;
import java.util.Enumeration;
/** /**
* OsdUtil - OpenSeizureDetector Utilities * OsdUtil - OpenSeizureDetector Utilities
* Deals with starting and stopping the background service and binding to it to receive data. * Deals with starting and stopping the background service and binding to it to receive data.
@@ -119,6 +127,55 @@ public class OsdUtil {
} }
} }
public String getAppVersionName() {
String versionName = "unknown";
// From http://stackoverflow.com/questions/4471025/
// how-can-you-get-the-manifest-version-number-
// from-the-apps-layout-xml-variable
final PackageManager packageManager = mContext.getPackageManager();
if (packageManager != null) {
try {
PackageInfo packageInfo = packageManager.getPackageInfo(mContext.getPackageName(), 0);
versionName = packageInfo.versionName;
} catch (PackageManager.NameNotFoundException e) {
Log.v(TAG, "failed to find versionName");
versionName = null;
}
}
return versionName;
}
/**
* get the ip address of the phone.
* Based on http://stackoverflow.com/questions/11015912/how-do-i-get-ip-address-in-ipv4-format
*/
public String getLocalIpAddress() {
try {
for (Enumeration<NetworkInterface> en = NetworkInterface
.getNetworkInterfaces(); en.hasMoreElements(); ) {
NetworkInterface intf = en.nextElement();
for (Enumeration<InetAddress> enumIpAddr = intf
.getInetAddresses(); enumIpAddr.hasMoreElements(); ) {
InetAddress inetAddress = enumIpAddr.nextElement();
//Log.v(TAG,"ip1--:" + inetAddress);
//Log.v(TAG,"ip2--:" + inetAddress.getHostAddress());
// for getting IPV4 format
if (!inetAddress.isLoopbackAddress()
&& InetAddressUtils.isIPv4Address(
inetAddress.getHostAddress())) {
String ip = inetAddress.getHostAddress().toString();
//Log.v(TAG,"ip---::" + ip);
return ip;
}
}
}
} catch (Exception ex) {
Log.e("IP Address", ex.toString());
}
return null;
}

View File

@@ -94,4 +94,35 @@ public class SdServiceConnection implements ServiceConnection {
return false; return false;
} }
/**
* Check if the pebble watch is connected to the server device via bluetooth.
* @return true if watch connected.
*/
public boolean pebbleConnected() {
if (mSdServer!=null) {
if (mSdServer.mSdData!=null) {
if (mSdServer.mSdData.pebbleConnected) {
return true;
}
}
}
return false;
}
/**
* Check if the openseizuredetector pebble watch app is running..
* @return true if watch app running.
*/
public boolean pebbleAppRunning() {
if (mSdServer!=null) {
if (mSdServer.mSdData!=null) {
if (mSdServer.mSdData.pebbleAppRunning) {
return true;
}
}
}
return false;
}
} }

View File

@@ -26,6 +26,9 @@ package uk.org.openseizuredetector;
import android.app.Activity; import android.app.Activity;
import android.content.Intent; import android.content.Intent;
import android.content.pm.PackageManager;
import android.graphics.Color;
import android.graphics.drawable.Drawable;
import android.os.Bundle; import android.os.Bundle;
import android.os.Handler; import android.os.Handler;
import android.util.Log; import android.util.Log;
@@ -44,6 +47,10 @@ import java.util.TimerTask;
*/ */
public class StartupActivity extends Activity { public class StartupActivity extends Activity {
private String TAG = "StartupActivity"; private String TAG = "StartupActivity";
private int okColour = Color.BLUE;
private int warnColour = Color.MAGENTA;
private int alarmColour = Color.RED;
private OsdUtil mUtil; private OsdUtil mUtil;
private Timer mUiTimer; private Timer mUiTimer;
private SdServiceConnection mConnection; private SdServiceConnection mConnection;
@@ -73,6 +80,22 @@ public class StartupActivity extends Activity {
} }
}); });
b = (Button)findViewById(R.id.pebbleButton);
b.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Log.v(TAG, "pebble button clicked");
try {
PackageManager pm = getPackageManager();
Intent pebbleAppIntent = pm.getLaunchIntentForPackage("com.getpebble.android");
startActivity(pebbleAppIntent);
} catch (Exception ex) {
Log.v(TAG, "exception starting pebble App " + ex.toString());
}
}
});
} }
@Override @Override
@@ -126,12 +149,12 @@ public class StartupActivity extends Activity {
pb = (ProgressBar) findViewById(R.id.progressBar1); pb = (ProgressBar) findViewById(R.id.progressBar1);
if (mUtil.isServerRunning()) { if (mUtil.isServerRunning()) {
tv.setText("Background Service Running OK"); tv.setText("Background Service Running OK");
pb.setIndeterminate(false); tv.setBackgroundColor(okColour);
pb.setMax(100); pb.setIndeterminateDrawable(getResources().getDrawable(R.drawable.start_server));
pb.setProgress(100); pb.setProgressDrawable(getResources().getDrawable(R.drawable.start_server));
pb.setVisibility(0);
} else { } else {
tv.setText("Waiting for Background Service..."); tv.setText("Waiting for Background Service...");
tv.setBackgroundColor(alarmColour);
pb.setIndeterminate(true); pb.setIndeterminate(true);
allOk = false; allOk = false;
} }
@@ -141,42 +164,74 @@ public class StartupActivity extends Activity {
pb = (ProgressBar) findViewById(R.id.progressBar2); pb = (ProgressBar) findViewById(R.id.progressBar2);
if (mConnection.mBound) { if (mConnection.mBound) {
tv.setText("Bound to Service OK"); tv.setText("Bound to Service OK");
pb.setIndeterminate(false); tv.setBackgroundColor(okColour);
pb.setMax(100); pb.setIndeterminateDrawable(getResources().getDrawable(R.drawable.start_server));
pb.setProgress(100); pb.setProgressDrawable(getResources().getDrawable(R.drawable.start_server));
pb.setVisibility(0);
} else { } else {
tv.setText("Binding to Background Service..."); tv.setText("Binding to Background Service...");
tv.setBackgroundColor(alarmColour);
pb.setIndeterminate(true); pb.setIndeterminate(true);
allOk = false; allOk = false;
} }
// Do we have seizure detector data? // Is Pebble Watch Connected?
tv = (TextView) findViewById(R.id.textItem3); tv = (TextView) findViewById(R.id.textItem3);
pb = (ProgressBar) findViewById(R.id.progressBar3); pb = (ProgressBar) findViewById(R.id.progressBar3);
if (mConnection.hasSdData()) { if (mConnection.pebbleConnected()) {
tv.setText("Seizure Detector Data Received OK"); tv.setText("Pebble Watch Connected OK");
pb.setIndeterminate(false); tv.setBackgroundColor(okColour);
pb.setMax(100); pb.setIndeterminateDrawable(getResources().getDrawable(R.drawable.start_server));
pb.setProgress(100); pb.setProgressDrawable(getResources().getDrawable(R.drawable.start_server));
pb.setVisibility(0);
} else { } else {
tv.setText("Waiting for Seizure Detector Data..."); tv.setText("Waiting to Connect to Pebble Watch.....");
tv.setBackgroundColor(alarmColour);
pb.setIndeterminate(true); pb.setIndeterminate(true);
allOk = false; allOk = false;
} }
// Do we have seizure detector settings yet? // Is Pebble Watch App Running?
tv = (TextView) findViewById(R.id.textItem4); tv = (TextView) findViewById(R.id.textItem4);
pb = (ProgressBar) findViewById(R.id.progressBar4); pb = (ProgressBar) findViewById(R.id.progressBar4);
if (mConnection.pebbleAppRunning()) {
tv.setText("Watch App Running OK");
tv.setBackgroundColor(okColour);
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);
pb.setIndeterminate(true);
allOk = false;
}
// Do we have seizure detector data?
tv = (TextView) findViewById(R.id.textItem5);
pb = (ProgressBar) findViewById(R.id.progressBar5);
if (mConnection.hasSdData()) {
tv.setText("Seizure Detector Data Received OK");
tv.setBackgroundColor(okColour);
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);
pb.setIndeterminate(true);
allOk = false;
}
// Do we have seizure detector settings yet?
tv = (TextView) findViewById(R.id.textItem6);
pb = (ProgressBar) findViewById(R.id.progressBar6);
if (mConnection.hasSdSettings()) { if (mConnection.hasSdSettings()) {
tv.setText("Seizure Detector Settings Received OK"); tv.setText("Seizure Detector Settings Received OK");
pb.setIndeterminate(false); tv.setBackgroundColor(okColour);
pb.setMax(100); pb.setIndeterminateDrawable(getResources().getDrawable(R.drawable.start_server));
pb.setProgress(100); pb.setProgressDrawable(getResources().getDrawable(R.drawable.start_server));
pb.setVisibility(0);
} else { } else {
tv.setText("Waiting for Seizure Detector Settings..."); tv.setText("Waiting for Seizure Detector Settings...");
tv.setBackgroundColor(alarmColour);
pb.setIndeterminate(true); pb.setIndeterminate(true);
allOk = false; allOk = false;
} }

View File

@@ -37,7 +37,8 @@
<LinearLayout <LinearLayout
android:orientation="horizontal" android:orientation="horizontal"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content"> android:layout_height="wrap_content"
>
<ProgressBar <ProgressBar
android:layout_width="wrap_content" android:layout_width="wrap_content"
@@ -47,6 +48,7 @@
<TextView <TextView
android:layout_width="fill_parent" android:layout_width="fill_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:gravity="center_vertical"
android:text="New Text" android:text="New Text"
android:id="@+id/textItem1" /> android:id="@+id/textItem1" />
@@ -64,6 +66,7 @@
<TextView <TextView
android:layout_width="fill_parent" android:layout_width="fill_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:gravity="center_vertical"
android:text="New Text" android:text="New Text"
android:id="@+id/textItem2" /> android:id="@+id/textItem2" />
@@ -81,6 +84,7 @@
<TextView <TextView
android:layout_width="fill_parent" android:layout_width="fill_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:gravity="center_vertical"
android:text="New Text" android:text="New Text"
android:id="@+id/textItem3" /> android:id="@+id/textItem3" />
@@ -89,26 +93,68 @@
android:orientation="horizontal" android:orientation="horizontal"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content"> android:layout_height="wrap_content">
<ProgressBar <ProgressBar
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:id="@+id/progressBar4" /> android:id="@+id/progressBar4" />
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:text="New Text"
android:id="@+id/textItem4" />
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ProgressBar
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/progressBar5" />
<TextView <TextView
android:layout_width="fill_parent" android:layout_width="fill_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:text="New Text" android:text="New Text"
android:id="@+id/textItem4" /> android:gravity="center_vertical"
android:id="@+id/textItem5" />
</LinearLayout> </LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ProgressBar
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/progressBar6" />
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:text="New Text"
android:id="@+id/textItem6" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal">
<Button <Button
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:text="Edit Settings" android:text="Edit Settings"
android:id="@+id/settingsButton" android:id="@+id/settingsButton"
android:layout_gravity="center_horizontal" /> android:layout_gravity="center_horizontal" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Configure Pebble"
android:id="@+id/pebbleButton"
android:layout_gravity="center_horizontal" />
</LinearLayout>
</LinearLayout> </LinearLayout>