Added functionality to switch data sources (network data source does not work yet though!).
This commit is contained in:
@@ -36,6 +36,7 @@ import android.net.Uri;
|
||||
import android.os.IBinder;
|
||||
import android.util.Log;
|
||||
import android.view.MenuItem;
|
||||
import android.widget.Toast;
|
||||
|
||||
import org.apache.http.conn.util.InetAddressUtils;
|
||||
|
||||
@@ -177,6 +178,13 @@ public class OsdUtil {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Display a Toast message on screen.
|
||||
* @param msg - message to display.
|
||||
*/
|
||||
public void showToast(String msg) {
|
||||
Toast.makeText(mContext, msg,
|
||||
Toast.LENGTH_LONG).show();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -37,6 +37,7 @@ interface SdDataReceiver {
|
||||
*/
|
||||
public abstract class SdDataSource {
|
||||
public SdData mSdData;
|
||||
public String mName = "undefined";
|
||||
protected Context mContext;
|
||||
protected SdDataReceiver mSdDataReceiver;
|
||||
private String TAG = "SdDataSource";
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
package uk.org.openseizuredetector;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
/**
|
||||
* Created by graham on 22/11/15.
|
||||
*/
|
||||
public class SdDataSourceNetwork extends SdDataSource {
|
||||
|
||||
public SdDataSourceNetwork(Context context, SdDataReceiver sdDataReceiver) {
|
||||
super(context,sdDataReceiver);
|
||||
mName = "Network";
|
||||
}
|
||||
}
|
||||
@@ -97,6 +97,7 @@ public class SdDataSourcePebble extends SdDataSource {
|
||||
|
||||
public SdDataSourcePebble(Context context, SdDataReceiver sdDataReceiver) {
|
||||
super(context,sdDataReceiver);
|
||||
mName = "Pebble";
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -84,6 +84,7 @@ public class SdServer extends Service implements SdDataReceiver {
|
||||
private WakeLock mWakeLock = null;
|
||||
public SdDataSource mSdDataSource;
|
||||
public SdData mSdData;
|
||||
private String mSdDataSourceName = "undefined"; // The name of the data soruce specified in the preferences.
|
||||
private boolean mLatchAlarms = false;
|
||||
private boolean mCancelAudible = false;
|
||||
private boolean mAudibleAlarm = false;
|
||||
@@ -96,6 +97,7 @@ public class SdServer extends Service implements SdDataReceiver {
|
||||
private boolean mLogAlarms = true;
|
||||
private boolean mLogData = false;
|
||||
private File mOutFile;
|
||||
private OsdUtil mUtil;
|
||||
|
||||
private final IBinder mBinder = new SdBinder();
|
||||
|
||||
@@ -134,6 +136,7 @@ public class SdServer extends Service implements SdDataReceiver {
|
||||
public void onCreate() {
|
||||
Log.v(TAG, "onCreate()");
|
||||
|
||||
mUtil = new OsdUtil(getApplicationContext());
|
||||
|
||||
// Create a wake lock, but don't use it until the service is started.
|
||||
PowerManager powerManager = (PowerManager) getSystemService(POWER_SERVICE);
|
||||
@@ -152,7 +155,22 @@ public class SdServer extends Service implements SdDataReceiver {
|
||||
// Update preferences.
|
||||
Log.v(TAG, "onStartCommand() - calling updatePrefs()");
|
||||
updatePrefs();
|
||||
mSdDataSource = new SdDataSourcePebble(this.getApplicationContext(), this);
|
||||
|
||||
Log.v(TAG, "onStartCommand: Datasource =" + mSdDataSourceName);
|
||||
switch (mSdDataSourceName) {
|
||||
case "Pebble":
|
||||
Log.v(TAG,"Selecting Pebble DataSource");
|
||||
mSdDataSource = new SdDataSourcePebble(this.getApplicationContext(), this);
|
||||
break;
|
||||
case "Network":
|
||||
Log.v(TAG, "Selecting Network DataSource");
|
||||
mSdDataSource = new SdDataSourceNetwork(this.getApplicationContext(),this);
|
||||
break;
|
||||
default:
|
||||
Log.v(TAG, "Datasource " + mSdDataSourceName + " not recognised - Exiting");
|
||||
mUtil.showToast("Datasource " + mSdDataSourceName + " not recognised - Exiting");
|
||||
return 1;
|
||||
}
|
||||
mSdDataSource.start();
|
||||
|
||||
|
||||
@@ -491,6 +509,8 @@ public class SdServer extends Service implements SdDataReceiver {
|
||||
SharedPreferences SP = PreferenceManager
|
||||
.getDefaultSharedPreferences(getBaseContext());
|
||||
try {
|
||||
mSdDataSourceName = SP.getString("DataSource","undefined");
|
||||
Log.v(TAG,"updatePrefs() - DataSource = "+mSdDataSourceName);
|
||||
mLatchAlarms = SP.getBoolean("LatchAlarms", false);
|
||||
Log.v(TAG, "updatePrefs() - mLatchAlarms = " + mLatchAlarms);
|
||||
mAudibleFaultWarning = SP.getBoolean("AudibleFaultWarning", true);
|
||||
|
||||
@@ -26,11 +26,13 @@ package uk.org.openseizuredetector;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.graphics.Color;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.preference.PreferenceManager;
|
||||
import android.util.Log;
|
||||
import android.view.View;
|
||||
import android.widget.Button;
|
||||
@@ -101,6 +103,14 @@ public class StartupActivity extends Activity {
|
||||
@Override
|
||||
protected void onStart() {
|
||||
super.onStart();
|
||||
|
||||
// Display the DataSource name
|
||||
SharedPreferences SP = PreferenceManager
|
||||
.getDefaultSharedPreferences(getBaseContext());;
|
||||
String dataSourceName = SP.getString("DataSource","undefined");
|
||||
TextView tv = (TextView)findViewById(R.id.dataSourceTextView);
|
||||
tv.setText("DataSource = "+dataSourceName);
|
||||
|
||||
if (mUtil.isServerRunning()) {
|
||||
Log.v(TAG, "onStart() - server running - stopping it");
|
||||
mUtil.stopServer();
|
||||
|
||||
@@ -26,7 +26,7 @@
|
||||
android:layout_height="wrap_content"
|
||||
android:textAppearance="?android:attr/textAppearanceMedium"
|
||||
android:text="Starting......"
|
||||
android:id="@+id/textView3"
|
||||
android:id="@+id/dataSourceTextView"
|
||||
android:layout_gravity="center_horizontal" />
|
||||
|
||||
<LinearLayout
|
||||
|
||||
@@ -5,8 +5,8 @@
|
||||
<item>"Network"</item>
|
||||
</string-array>
|
||||
<string-array name="datasource_list_values">
|
||||
<item>"pebble"</item>
|
||||
<item>"network"</item>
|
||||
<item>"Pebble"</item>
|
||||
<item>"Network"</item>
|
||||
</string-array>
|
||||
|
||||
</resources>
|
||||
Reference in New Issue
Block a user