From cfe612933f33d0668ca72c8c9856636fe78a625d Mon Sep 17 00:00:00 2001 From: Graham Jones Date: Fri, 19 Jan 2024 20:53:18 +0000 Subject: [PATCH] Applied Android Studio code formatting to all java files --- .../AuthenticateActivity.java | 65 +++++---- .../openseizuredetector/BLEScanActivity.java | 8 +- .../BootBroadcastReceiver.java | 4 +- .../uk/org/openseizuredetector/CircBuf.java | 23 +-- .../EditEventActivity.java | 39 ++--- .../ExportDataActivity.java | 18 +-- .../FragmentDataSharing.java | 5 +- .../openseizuredetector/FragmentHrAlg.java | 19 +-- .../openseizuredetector/FragmentMlAlg.java | 5 +- .../openseizuredetector/FragmentOsdAlg.java | 5 +- .../FragmentOsdBaseClass.java | 9 +- .../openseizuredetector/FragmentSystem.java | 12 +- .../FragmentWebServer.java | 5 +- .../openseizuredetector/GattAttributes.java | 1 + .../openseizuredetector/LocationFinder.java | 11 +- .../org/openseizuredetector/LogManager.java | 14 +- .../org/openseizuredetector/MainActivity.java | 18 +-- .../openseizuredetector/MainActivity2.java | 54 ++++--- .../openseizuredetector/MlModelManager.java | 5 +- .../OsdUncaughtExceptionHandler.java | 4 +- .../uk/org/openseizuredetector/OsdUtil.java | 38 +++-- .../org/openseizuredetector/PrefActivity.java | 4 +- .../openseizuredetector/RemoteDbActivity.java | 13 +- .../ReportSeizureActivity.java | 41 +++--- .../uk/org/openseizuredetector/SdAlgHr.java | 54 +++---- .../uk/org/openseizuredetector/SdAlgNn.java | 7 +- .../uk/org/openseizuredetector/SdData.java | 6 +- .../org/openseizuredetector/SdDataSource.java | 134 +++++++++--------- .../openseizuredetector/SdDataSourceAw.java | 25 ++-- .../openseizuredetector/SdDataSourceBLE.java | 97 ++++++------- .../SdDataSourceNetwork.java | 67 ++++----- .../SdDataSourcePebble.java | 28 ++-- .../SdDataSourcePhone.java | 17 +-- .../uk/org/openseizuredetector/SdServer.java | 27 ++-- .../SdServiceConnection.java | 21 +-- .../org/openseizuredetector/SdWebServer.java | 22 +-- .../openseizuredetector/StartupActivity.java | 40 +++--- .../openseizuredetector/WebApiConnection.java | 22 +-- .../WebApiConnection_firebase.java | 6 +- .../WebApiConnection_osdapi.java | 18 +-- 40 files changed, 497 insertions(+), 514 deletions(-) diff --git a/app/src/main/java/uk/org/openseizuredetector/AuthenticateActivity.java b/app/src/main/java/uk/org/openseizuredetector/AuthenticateActivity.java index 90afe8e..a3979e3 100644 --- a/app/src/main/java/uk/org/openseizuredetector/AuthenticateActivity.java +++ b/app/src/main/java/uk/org/openseizuredetector/AuthenticateActivity.java @@ -66,8 +66,8 @@ public class AuthenticateActivity extends AppCompatActivity { logoutBtn.setOnClickListener(onLogout); // Components required only for osdapi backend - if (LogManager.USE_FIREBASE_BACKEND) { } - else { + if (LogManager.USE_FIREBASE_BACKEND) { + } else { mConnection = new SdServiceConnection(getApplicationContext()); Button registerBtn = (Button) findViewById(R.id.RegisterBtn); @@ -84,7 +84,7 @@ public class AuthenticateActivity extends AppCompatActivity { new View.OnClickListener() { @Override public void onClick(View view) { - Log.v(TAG,"aboutDataSharingBtn.onClick()"); + Log.v(TAG, "aboutDataSharingBtn.onClick()"); String url = OsdUtil.DATA_SHARING_URL; Intent i = new Intent(Intent.ACTION_VIEW); i.setData(Uri.parse(url)); @@ -97,7 +97,7 @@ public class AuthenticateActivity extends AppCompatActivity { new View.OnClickListener() { @Override public void onClick(View view) { - Log.v(TAG,"privacyPolicyBtn.onClick()"); + Log.v(TAG, "privacyPolicyBtn.onClick()"); String url = OsdUtil.PRIVACY_POLICY_URL; Intent i = new Intent(Intent.ACTION_VIEW); i.setData(Uri.parse(url)); @@ -150,14 +150,13 @@ public class AuthenticateActivity extends AppCompatActivity { } private void initialiseServiceConnection() { - Log.v(TAG,"initialiseServiceConnection()"); + Log.v(TAG, "initialiseServiceConnection()"); mLm = mConnection.mSdServer.mLm; mWac = mConnection.mSdServer.mLm.mWac; updateUi(); } - // Called after the Firebase Auth UI has completed private ActivityResultLauncher signInLauncher = registerForActivityResult( new FirebaseAuthUIActivityResultContract(), @@ -170,13 +169,13 @@ public class AuthenticateActivity extends AppCompatActivity { private void updateUi() { - Log.v(TAG,"updateUi()"); + Log.v(TAG, "updateUi()"); LinearLayout loginLl = (LinearLayout) findViewById(R.id.login_ui); LinearLayout osdApiLoginLl = (LinearLayout) findViewById(R.id.login_osdapi_ui); LinearLayout logoutLl = (LinearLayout) findViewById(R.id.logout_ui); if (mWac == null) { - Log.i(TAG,"mWac is null - not updating UI"); + Log.i(TAG, "mWac is null - not updating UI"); return; } @@ -204,7 +203,7 @@ public class AuthenticateActivity extends AppCompatActivity { } }); } else { - Log.v(TAG,"updateUi() - not logged in.."); + Log.v(TAG, "updateUi() - not logged in.."); loginLl.setVisibility(View.VISIBLE); logoutLl.setVisibility(View.GONE); if (!LogManager.USE_FIREBASE_BACKEND) { @@ -252,19 +251,19 @@ public class AuthenticateActivity extends AppCompatActivity { // FIXME - make this work with Google Authentication like we do for Firebase. String uname = mUnameEt.getText().toString(); String passwd = mPasswdEt.getText().toString(); - Log.v(TAG,"onOK() - uname="+uname+", passwd="+passwd); + Log.v(TAG, "onOK() - uname=" + uname + ", passwd=" + passwd); mWac.authenticate(uname, passwd, new WebApiConnection.StringCallback() { @Override public void accept(String retVal) { if (retVal != null) { - Log.d(TAG,"Authentication Success - token is "+retVal); + Log.d(TAG, "Authentication Success - token is " + retVal); mUtil.showToast("Login Successful"); saveAuthToken(retVal); updateUi(); } else { - Log.e(TAG,"onOk: Authentication failure for "+uname+", "+passwd); + Log.e(TAG, "onOk: Authentication failure for " + uname + ", " + passwd); mUtil.showToast("ERROR: Authentication Failed - Please Try Again"); - mUtil.writeToSysLogFile("AuthActivity - Authorisation failed for "+uname+", "+passwd); + mUtil.writeToSysLogFile("AuthActivity - Authorisation failed for " + uname + ", " + passwd); } } }); @@ -273,29 +272,29 @@ public class AuthenticateActivity extends AppCompatActivity { }; View.OnClickListener onLogout = new View.OnClickListener() { - @Override - public void onClick(View view) { - Log.v(TAG, "onLogout"); - if (LogManager.USE_FIREBASE_BACKEND) { - AuthUI.getInstance() - .signOut(getApplicationContext()) - .addOnCompleteListener(new OnCompleteListener() { - public void onComplete(@NonNull Task task) { - // user is now signed out - updateUi(); - } - }); + @Override + public void onClick(View view) { + Log.v(TAG, "onLogout"); + if (LogManager.USE_FIREBASE_BACKEND) { + AuthUI.getInstance() + .signOut(getApplicationContext()) + .addOnCompleteListener(new OnCompleteListener() { + public void onComplete(@NonNull Task task) { + // user is now signed out + updateUi(); + } + }); + } else { + if (mWac != null) { + mWac.logout(); + saveAuthToken(null); } else { - if (mWac != null) { - mWac.logout(); - saveAuthToken(null); - } else { - Log.e(TAG,"logout() - mWac is null - not doing anything"); - } + Log.e(TAG, "logout() - mWac is null - not doing anything"); } - updateUi(); } - }; + updateUi(); + } + }; View.OnClickListener onRegister = new View.OnClickListener() { diff --git a/app/src/main/java/uk/org/openseizuredetector/BLEScanActivity.java b/app/src/main/java/uk/org/openseizuredetector/BLEScanActivity.java index 6825a39..d53b065 100644 --- a/app/src/main/java/uk/org/openseizuredetector/BLEScanActivity.java +++ b/app/src/main/java/uk/org/openseizuredetector/BLEScanActivity.java @@ -292,7 +292,7 @@ public class BLEScanActivity extends ListActivity { try { mBluetoothLeScanner.startScan(mLeScanCallback); } catch (SecurityException e) { - Log.e(TAG,"startScan - SecurityException while starting scan"); + Log.e(TAG, "startScan - SecurityException while starting scan"); Toast toast = Toast.makeText(this, "ERROR Starting Scan - Security Exception", Toast.LENGTH_SHORT); toast.show(); @@ -304,7 +304,7 @@ public class BLEScanActivity extends ListActivity { try { mBluetoothLeScanner.stopScan(mLeScanCallback); } catch (SecurityException e) { - Log.e(TAG,"stopScan - SecurityException while stopping scan"); + Log.e(TAG, "stopScan - SecurityException while stopping scan"); Toast toast = Toast.makeText(this, "ERROR Stopping Scan - Security Exception", Toast.LENGTH_SHORT); toast.show(); } @@ -360,7 +360,7 @@ public class BLEScanActivity extends ListActivity { try { Log.v(TAG, "addDevice - " + device.getName()); } catch (SecurityException e) { - Log.e(TAG,"addDevice() - security exception getting device name"); + Log.e(TAG, "addDevice() - security exception getting device name"); } mLeDevices.add(device); } @@ -425,7 +425,7 @@ public class BLEScanActivity extends ListActivity { try { Log.v(TAG, "ScanCallback - " + result.getDevice().getName()); } catch (SecurityException e) { - Log.e(TAG,"ScanCallback - security exception getting device name"); + Log.e(TAG, "ScanCallback - security exception getting device name"); } mLeDeviceListAdapter.addDevice(result.getDevice()); mLeDeviceListAdapter.notifyDataSetChanged(); diff --git a/app/src/main/java/uk/org/openseizuredetector/BootBroadcastReceiver.java b/app/src/main/java/uk/org/openseizuredetector/BootBroadcastReceiver.java index 6a781d2..e7958da 100644 --- a/app/src/main/java/uk/org/openseizuredetector/BootBroadcastReceiver.java +++ b/app/src/main/java/uk/org/openseizuredetector/BootBroadcastReceiver.java @@ -46,8 +46,8 @@ public class BootBroadcastReceiver extends BroadcastReceiver { Log.v(TAG, "onReceive()"); SharedPreferences SP = PreferenceManager .getDefaultSharedPreferences(context); - boolean autoStart = SP.getBoolean("AutoStart",false); - Log.v(TAG,"onReceive() - autoStart = "+autoStart); + boolean autoStart = SP.getBoolean("AutoStart", false); + Log.v(TAG, "onReceive() - autoStart = " + autoStart); if (autoStart && Intent.ACTION_BOOT_COMPLETED.equals(intent.getAction())) { Intent startUpIntent = new Intent(context, StartupActivity.class); startUpIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); diff --git a/app/src/main/java/uk/org/openseizuredetector/CircBuf.java b/app/src/main/java/uk/org/openseizuredetector/CircBuf.java index 4875cf6..d0bfdb9 100644 --- a/app/src/main/java/uk/org/openseizuredetector/CircBuf.java +++ b/app/src/main/java/uk/org/openseizuredetector/CircBuf.java @@ -6,9 +6,9 @@ import java.util.ArrayList; public class CircBuf { /* - * A circular buffer used to calculate rolling averages - * Based loosely on https://gist.github.com/hardik-vala/dc2d19fa7c5108536fbbff96b4fcf105 - */ + * A circular buffer used to calculate rolling averages + * Based loosely on https://gist.github.com/hardik-vala/dc2d19fa7c5108536fbbff96b4fcf105 + */ private final static String TAG = "CircBuf"; private double[] mBuff; @@ -35,7 +35,7 @@ public class CircBuf { /** * Add value val to the circular buffer. */ - Log.d(TAG,"add() - before: mHead="+mHead+", mTail="+mTail); + Log.d(TAG, "add() - before: mHead=" + mHead + ", mTail=" + mTail); //System.out.println(TAG+" add() - before: mHead="+mHead+", mTail="+mTail); if (mIsFull) mHead = (mHead + 1) % mBuffLen; @@ -44,7 +44,7 @@ public class CircBuf { mTail = (mTail + 1) % mBuffLen; if (mTail == mHead) mIsFull = true; - Log.d(TAG,"add() - after: mHead="+mHead+", mTail="+mTail); + Log.d(TAG, "add() - after: mHead=" + mHead + ", mTail=" + mTail); //System.out.println(TAG+" add() - before: mHead="+mHead+", mTail="+mTail); } @@ -60,7 +60,7 @@ public class CircBuf { if (mHead > mTail) { numElements = (mTail + mBuffLen) - mHead; } else { - numElements = mTail-mHead; + numElements = mTail - mHead; } } return numElements; @@ -68,11 +68,12 @@ public class CircBuf { /** * Returns a double array of buffer items in order of their insertion time + * * @return double[] of buffer items */ - public double[] getVals () { + public double[] getVals() { int numElements = getNumVals(); - System.out.println(TAG+" getVals() - numElements=" + numElements); + System.out.println(TAG + " getVals() - numElements=" + numElements); double[] retArr = new double[numElements]; for (int i = 0; i < numElements; i++) { retArr[i] = mBuff[(mHead + i) % mBuffLen]; @@ -89,18 +90,18 @@ public class CircBuf { int hrCount = 0; double valArr[] = getVals(); double retVal; - for (int n=0; n0) { + if (hrCount > 0) { retVal = hrSum / hrCount; } else { retVal = -1; } - return(retVal); + return (retVal); } } \ No newline at end of file diff --git a/app/src/main/java/uk/org/openseizuredetector/EditEventActivity.java b/app/src/main/java/uk/org/openseizuredetector/EditEventActivity.java index ccdc01e..2a00c6b 100644 --- a/app/src/main/java/uk/org/openseizuredetector/EditEventActivity.java +++ b/app/src/main/java/uk/org/openseizuredetector/EditEventActivity.java @@ -3,7 +3,9 @@ package uk.org.openseizuredetector; import android.content.Context; import android.os.Bundle; import android.os.Handler; + import androidx.appcompat.app.AppCompatActivity; + import android.util.Log; import android.view.View; import android.widget.Button; @@ -205,7 +207,7 @@ public class EditEventActivity extends AppCompatActivity { int alarmStateVal = Integer.parseInt(alarmStateStr); alarmStateStr = mUtil.alarmStatusToString(alarmStateVal); } catch (Exception e) { - Log.v(TAG,"updateUi: alarmState does not parse to int so displaying it as string: " +alarmStateStr); + Log.v(TAG, "updateUi: alarmState does not parse to int so displaying it as string: " + alarmStateStr); } tv.setText(alarmStateStr); tv = (TextView) findViewById(R.id.eventNotsTv); @@ -219,7 +221,7 @@ public class EditEventActivity extends AppCompatActivity { SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); tv.setText(dateFormat.format(dataTime)); } catch (Exception e) { - Log.e(TAG,"updateUI: Error Parsing dataDate "+e.getLocalizedMessage()); + Log.e(TAG, "updateUI: Error Parsing dataDate " + e.getLocalizedMessage()); tv.setText("---"); } @@ -234,9 +236,9 @@ public class EditEventActivity extends AppCompatActivity { } // Populate the event sub-types radio button list. - Log.v(TAG,"updateUi() - meventsubtypeshashmap="+mEventSubTypesHashMap+", mEventSubtypesListChanged="+mEventSubTypesListChanged); + Log.v(TAG, "updateUi() - meventsubtypeshashmap=" + mEventSubTypesHashMap + ", mEventSubtypesListChanged=" + mEventSubTypesListChanged); if (mEventSubTypesHashMap != null && mEventSubTypesListChanged) { - Log.v(TAG,"UpdateUi() - populating event sub types list"); + Log.v(TAG, "UpdateUi() - populating event sub types list"); if (mEventObj.getString("type") != null) { // based on https://androidexample.com/create-a-simple-listview ArrayList subtypesArrayList = mEventSubTypesHashMap.get(mEventObj.getString("type")); @@ -265,11 +267,10 @@ public class EditEventActivity extends AppCompatActivity { } } catch (JSONException e) { - Log.e(TAG,"Error Parsing mEventObj: "+e.getMessage()); + Log.e(TAG, "Error Parsing mEventObj: " + e.getMessage()); } - } // updateUi() View.OnClickListener onCancel = @@ -287,14 +288,14 @@ public class EditEventActivity extends AppCompatActivity { @Override public void onClick(View view) { //m_status=true; - TextView tv = (TextView)findViewById(R.id.eventNotsTv); + TextView tv = (TextView) findViewById(R.id.eventNotsTv); try { - mEventObj.put("desc",tv.getText()); - mEventObj.put("id",mEventId); // Add event Id to event object manually because firestore does not include it by default. + mEventObj.put("desc", tv.getText()); + mEventObj.put("id", mEventId); // Add event Id to event object manually because firestore does not include it by default. } catch (JSONException e) { - Log.e(TAG,"Error writing mEventObj: "+e.getMessage()); + Log.e(TAG, "Error writing mEventObj: " + e.getMessage()); } - Log.v(TAG, "onOK() - eventObj="+mEventObj.toString()); + Log.v(TAG, "onOK() - eventObj=" + mEventObj.toString()); try { mWac.updateEvent(mEventObj, new WebApiConnection.JSONObjectCallback() { @@ -314,7 +315,7 @@ public class EditEventActivity extends AppCompatActivity { } }); } catch (Exception e) { - Log.e(TAG,"onOK() - ERROR: "+e.getMessage()+" : " +e.toString()); + Log.e(TAG, "onOK() - ERROR: " + e.getMessage() + " : " + e.toString()); e.printStackTrace(); mUtil.showToast("Error Updating Event"); updateUi(); @@ -327,16 +328,16 @@ public class EditEventActivity extends AppCompatActivity { new RadioGroup.OnCheckedChangeListener() { @Override public void onCheckedChanged(RadioGroup group, int checkedId) { - Log.v(TAG,"onEventTypeChange() - id="+checkedId); - RadioButton b = (RadioButton)findViewById(group.getCheckedRadioButtonId()); + Log.v(TAG, "onEventTypeChange() - id=" + checkedId); + RadioButton b = (RadioButton) findViewById(group.getCheckedRadioButtonId()); String selectedEventType = b.getText().toString(); try { mEventObj.put("type", selectedEventType); } catch (JSONException e) { - Log.e(TAG,"Error setting mEventObj.type: "+e.getMessage()); + Log.e(TAG, "Error setting mEventObj.type: " + e.getMessage()); } mEventSubTypesListChanged = true; - Log.v(TAG,"onEventTypeChange() - mEventSubTypesListChanged="+mEventSubTypesListChanged); + Log.v(TAG, "onEventTypeChange() - mEventSubTypesListChanged=" + mEventSubTypesListChanged); updateUi(); } }; @@ -344,13 +345,13 @@ public class EditEventActivity extends AppCompatActivity { new RadioGroup.OnCheckedChangeListener() { @Override public void onCheckedChanged(RadioGroup group, int checkedId) { - Log.v(TAG,"onEventSubTypeChange() - id="+checkedId); - RadioButton b = (RadioButton)findViewById(group.getCheckedRadioButtonId()); + Log.v(TAG, "onEventSubTypeChange() - id=" + checkedId); + RadioButton b = (RadioButton) findViewById(group.getCheckedRadioButtonId()); String selectedEventSubType = b.getText().toString(); try { mEventObj.put("subType", selectedEventSubType); } catch (JSONException e) { - Log.e(TAG,"Error setting mEventObj.type: "+e.getMessage()); + Log.e(TAG, "Error setting mEventObj.type: " + e.getMessage()); } updateUi(); } diff --git a/app/src/main/java/uk/org/openseizuredetector/ExportDataActivity.java b/app/src/main/java/uk/org/openseizuredetector/ExportDataActivity.java index 0b6faf4..3c43bf2 100644 --- a/app/src/main/java/uk/org/openseizuredetector/ExportDataActivity.java +++ b/app/src/main/java/uk/org/openseizuredetector/ExportDataActivity.java @@ -226,14 +226,14 @@ public class ExportDataActivity extends AppCompatActivity public void hideProgressBar() { runOnUiThread(new Runnable() { - public void run() { - ProgressBar pb = (ProgressBar) findViewById(R.id.exportPb); - pb.setIndeterminate(true); - pb.setVisibility(View.INVISIBLE); - mExportBtn.setEnabled(true); - mExportBtn.setVisibility(View.VISIBLE); + public void run() { + ProgressBar pb = (ProgressBar) findViewById(R.id.exportPb); + pb.setIndeterminate(true); + pb.setVisibility(View.INVISIBLE); + mExportBtn.setEnabled(true); + mExportBtn.setVisibility(View.VISIBLE); - } + } }); } @@ -265,8 +265,8 @@ public class ExportDataActivity extends AppCompatActivity // Perform operations on the document using its URI. //mUtil.showToast("URI="+uri.toString()); Log.v(TAG, "onActivityResult() - exporting to file " + uri.toString()); - mLm.exportToCsvFile(mEndDate, mDuration,uri, (boolean b)-> { - Log.v(TAG,"onActivityResult callback"); + mLm.exportToCsvFile(mEndDate, mDuration, uri, (boolean b) -> { + Log.v(TAG, "onActivityResult callback"); hideProgressBar(); }); diff --git a/app/src/main/java/uk/org/openseizuredetector/FragmentDataSharing.java b/app/src/main/java/uk/org/openseizuredetector/FragmentDataSharing.java index 43c6ee8..2a01ca9 100644 --- a/app/src/main/java/uk/org/openseizuredetector/FragmentDataSharing.java +++ b/app/src/main/java/uk/org/openseizuredetector/FragmentDataSharing.java @@ -9,6 +9,7 @@ import android.widget.TextView; public class FragmentDataSharing extends FragmentOsdBaseClass { String TAG = "FragmentDataSharing"; + public FragmentDataSharing() { // Required empty public constructor } @@ -28,9 +29,9 @@ public class FragmentDataSharing extends FragmentOsdBaseClass { @Override protected void updateUi() { - Log.d(TAG,"updateUi()"); + Log.d(TAG, "updateUi()"); TextView tv; - tv = (TextView)mRootView.findViewById(R.id.fragment_data_sharing_tv1); + tv = (TextView) mRootView.findViewById(R.id.fragment_data_sharing_tv1); if (mConnection.mBound) { tv.setText("Bound to Server"); } else { diff --git a/app/src/main/java/uk/org/openseizuredetector/FragmentHrAlg.java b/app/src/main/java/uk/org/openseizuredetector/FragmentHrAlg.java index 3e363a1..957cff9 100644 --- a/app/src/main/java/uk/org/openseizuredetector/FragmentHrAlg.java +++ b/app/src/main/java/uk/org/openseizuredetector/FragmentHrAlg.java @@ -52,7 +52,7 @@ public class FragmentHrAlg extends FragmentOsdBaseClass { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); - lineDataSet = new LineDataSet(new ArrayList(),"Heart rate history" ); + lineDataSet = new LineDataSet(new ArrayList(), "Heart rate history"); //lineDataSet.setColors(ColorTemplate.JOYFUL_COLORS); lineDataSet.setValueTextColor(Color.BLACK); lineDataSet.setValueTextSize(18f); @@ -99,6 +99,7 @@ public class FragmentHrAlg extends FragmentOsdBaseClass { yAxis2.setDrawGridLines(false); yAxis2.setEnabled(false); } + @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { @@ -118,9 +119,9 @@ public class FragmentHrAlg extends FragmentOsdBaseClass { tvCurrent = mRootView.findViewById(R.id.textView2); if (Objects.nonNull(tvCurrent)) { if (Objects.nonNull(tvHr)) - tvHr.setText( String.valueOf((short)mConnection.mSdServer.mSdData.mHR)); + tvHr.setText(String.valueOf((short) mConnection.mSdServer.mSdData.mHR)); if (Objects.nonNull(tvAvgAHr)) - tvAvgAHr.setText( String.valueOf((short)mConnection.mSdServer.mSdData + tvAvgAHr.setText(String.valueOf((short) mConnection.mSdServer.mSdData .mAdaptiveHrAverage)); tvCurrent.setText(new StringBuilder() .append("\nResult of checks: Adaptive Hr Alarm Standing: ") @@ -137,16 +138,16 @@ public class FragmentHrAlg extends FragmentOsdBaseClass { int nHistArr = hrHist.getNumVals(); double hrHistArr[] = hrHist.getVals(); // This gives us a simple vector of hr values to plot. if (Objects.nonNull(hrHist) && nHistArr > 0) { - Log.v(TAG, "hrHist.getNumVals="+nHistArr); + Log.v(TAG, "hrHist.getNumVals=" + nHistArr); lineDataSet.clear(); String xVals[] = new String[nHistArr]; - for (int i = 0; i 0) { tv.setText(getString(R.string.HR_Equals) + " " + Math.round(mConnection.mSdServer.mSdData.mHR) + " bpm\n" - +"(av = " - +Math.round(mConnection.mSdServer.mSdData.mAdaptiveHrAverage)+", " - +Math.round(mConnection.mSdServer.mSdData.mAverageHrAverage)+" bpm)\n" - + getString(R.string.SpO2)+" = " + Math.round(mConnection.mSdServer.mSdData.mO2Sat) + "%"); + + "(av = " + + Math.round(mConnection.mSdServer.mSdData.mAdaptiveHrAverage) + ", " + + Math.round(mConnection.mSdServer.mSdData.mAverageHrAverage) + " bpm)\n" + + getString(R.string.SpO2) + " = " + Math.round(mConnection.mSdServer.mSdData.mO2Sat) + "%"); } else { tv.setText(getString(R.string.HR_Equals) + " " + Math.round(mConnection.mSdServer.mSdData.mHR) + " bpm\n" - +"(av = " - +Math.round(mConnection.mSdServer.mSdData.mAdaptiveHrAverage)+", " - +Math.round(mConnection.mSdServer.mSdData.mAverageHrAverage)+" bpm)\n" - + getString(R.string.SpO2)+" = ---%"); + + "(av = " + + Math.round(mConnection.mSdServer.mSdData.mAdaptiveHrAverage) + ", " + + Math.round(mConnection.mSdServer.mSdData.mAverageHrAverage) + " bpm)\n" + + getString(R.string.SpO2) + " = ---%"); } if (mConnection.mSdServer.mSdData.mHRAlarmStanding || mConnection.mSdServer.mSdData.mAdaptiveHrAlarmStanding @@ -821,7 +821,7 @@ public class MainActivity extends AppCompatActivity { " (" + getString(R.string.Threshold) + "=" + mConnection.mSdServer.mSdData.alarmThresh + ")"); ((TextView) findViewById(R.id.spectrumTv)).setText(getString(R.string.SpectrumRatioEquals) + specRatio + " (" + getString(R.string.Threshold) + "=" + mConnection.mSdServer.mSdData.alarmRatioThresh + ")"); - ((TextView) findViewById(R.id.pSeizureTv)).setText(getString(R.string.seizure_probability)+" = " + pSeizurePc + "%"); + ((TextView) findViewById(R.id.pSeizureTv)).setText(getString(R.string.seizure_probability) + " = " + pSeizurePc + "%"); ProgressBar pb; Drawable pbDrawable; diff --git a/app/src/main/java/uk/org/openseizuredetector/MainActivity2.java b/app/src/main/java/uk/org/openseizuredetector/MainActivity2.java index 88e6de2..59950fa 100644 --- a/app/src/main/java/uk/org/openseizuredetector/MainActivity2.java +++ b/app/src/main/java/uk/org/openseizuredetector/MainActivity2.java @@ -45,36 +45,37 @@ public class MainActivity2 extends AppCompatActivity { private OsdUtil mUtil; private SdServiceConnection mConnection; final Handler serverStatusHandler = new Handler(); + @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main2); - Log.i(TAG, "onCreate()"); + Log.i(TAG, "onCreate()"); - // Set our custom uncaught exception handler to report issues. - //Thread.setDefaultUncaughtExceptionHandler(new OsdUncaughtExceptionHandler(MainActivity.this)); - new UCEHandler.Builder(this) - .addCommaSeparatedEmailAddresses("crashreports@openseizuredetector.org.uk,") - .build(); + // Set our custom uncaught exception handler to report issues. + //Thread.setDefaultUncaughtExceptionHandler(new OsdUncaughtExceptionHandler(MainActivity.this)); + new UCEHandler.Builder(this) + .addCommaSeparatedEmailAddresses("crashreports@openseizuredetector.org.uk,") + .build(); - //int i = 5/0; // Force exception to test handler. - mUtil = new OsdUtil(getApplicationContext(), serverStatusHandler); - mConnection = new SdServiceConnection(getApplicationContext()); - mUtil.writeToSysLogFile("MainActivity2.onCreate()"); - mContext = this; + //int i = 5/0; // Force exception to test handler. + mUtil = new OsdUtil(getApplicationContext(), serverStatusHandler); + mConnection = new SdServiceConnection(getApplicationContext()); + mUtil.writeToSysLogFile("MainActivity2.onCreate()"); + mContext = this; /** - if (savedInstanceState == null) { - // Instantiate a ViewPager2 and a PagerAdapter. - mFragmentPager = findViewById(R.id.fragment_pager); - mFragmentStateAdapter = new ScreenSlideFragmentPagerAdapter(this); - mFragmentPager.setAdapter(mFragmentStateAdapter); - getSupportFragmentManager().beginTransaction() - .setReorderingAllowed(true) - .add(R.id.fragment_common_container_view, FragmentCommon.class, null) - .commit(); - } + if (savedInstanceState == null) { + // Instantiate a ViewPager2 and a PagerAdapter. + mFragmentPager = findViewById(R.id.fragment_pager); + mFragmentStateAdapter = new ScreenSlideFragmentPagerAdapter(this); + mFragmentPager.setAdapter(mFragmentStateAdapter); + getSupportFragmentManager().beginTransaction() + .setReorderingAllowed(true) + .add(R.id.fragment_common_container_view, FragmentCommon.class, null) + .commit(); + } */ } @@ -127,8 +128,6 @@ public class MainActivity2 extends AppCompatActivity { } - - @Override protected void onPause() { super.onPause(); @@ -151,7 +150,6 @@ public class MainActivity2 extends AppCompatActivity { } - @Override public void onBackPressed() { if (Objects.isNull(mFragmentPager) || mFragmentPager.getCurrentItem() == 0) { @@ -278,21 +276,20 @@ public class MainActivity2 extends AppCompatActivity { } - - /** * A simple pager adapter that represents 5 ScreenSlidePageFragment objects, in * sequence. */ private class ScreenSlideFragmentPagerAdapter extends FragmentStateAdapter { private String TAG = "ScreenSlideFragmentPagerAdapter"; + public ScreenSlideFragmentPagerAdapter(FragmentActivity fa) { super(fa); } @Override public Fragment createFragment(int position) { - switch(position) { + switch (position) { case 0: return new FragmentOsdAlg(); case 1: @@ -305,7 +302,7 @@ public class MainActivity2 extends AppCompatActivity { return new FragmentDataSharing(); default: - Log.e(TAG,"createFragment() - invalid Position "+position); + Log.e(TAG, "createFragment() - invalid Position " + position); return null; } } @@ -329,7 +326,6 @@ public class MainActivity2 extends AppCompatActivity { } - private void showAbout() { mUtil.writeToSysLogFile("MainActivity.showAbout()"); View aboutView = getLayoutInflater().inflate(R.layout.about_layout, null, false); diff --git a/app/src/main/java/uk/org/openseizuredetector/MlModelManager.java b/app/src/main/java/uk/org/openseizuredetector/MlModelManager.java index c0a33b6..0e872ca 100644 --- a/app/src/main/java/uk/org/openseizuredetector/MlModelManager.java +++ b/app/src/main/java/uk/org/openseizuredetector/MlModelManager.java @@ -35,7 +35,7 @@ public class MlModelManager { public boolean mModelReady = false; private final String mUrlBase = "https://openseizuredetector.org.uk/static/MLmodels/"; private final String mModelIndexFname = "MLmodels.json"; - RequestQueue mQueue; + RequestQueue mQueue; public interface JSONObjectCallback { public void accept(JSONObject retValObj); @@ -43,7 +43,7 @@ public class MlModelManager { public MlModelManager(Context context) { - Log.i(TAG,"MlModelManager Constructor"); + Log.i(TAG, "MlModelManager Constructor"); mContext = context; mUtil = new OsdUtil(mContext, new Handler()); mQueue = Volley.newRequestQueue(mContext); @@ -55,7 +55,6 @@ public class MlModelManager { } - /** * Retrieve the file containing the list of available ML models from the server. * Calls the specified callback function, passing a JSONObject as a parameter when the data has been received and parsed. diff --git a/app/src/main/java/uk/org/openseizuredetector/OsdUncaughtExceptionHandler.java b/app/src/main/java/uk/org/openseizuredetector/OsdUncaughtExceptionHandler.java index 7d4cfed..77b257d 100644 --- a/app/src/main/java/uk/org/openseizuredetector/OsdUncaughtExceptionHandler.java +++ b/app/src/main/java/uk/org/openseizuredetector/OsdUncaughtExceptionHandler.java @@ -160,8 +160,8 @@ public class OsdUncaughtExceptionHandler implements Thread.UncaughtExceptionHand }); builder.setMessage("Please report the " + "problem by email using the button below so we can fix it.\n" + - "You can review the information being sent in the next screen:"+ - "\n"+errorContent.toString()); + "You can review the information being sent in the next screen:" + + "\n" + errorContent.toString()); Dialog dialog = builder.create(); //dialog.getWindow().setType(WindowManager.LayoutParams.TYPE_SYSTEM_ALERT); dialog.show(); diff --git a/app/src/main/java/uk/org/openseizuredetector/OsdUtil.java b/app/src/main/java/uk/org/openseizuredetector/OsdUtil.java index 972e053..07bbbd0 100644 --- a/app/src/main/java/uk/org/openseizuredetector/OsdUtil.java +++ b/app/src/main/java/uk/org/openseizuredetector/OsdUtil.java @@ -325,13 +325,13 @@ public class OsdUtil { * * @param msgStr */ - public void writeToSysLogFile(String msgStr,String logType) { - writeLogEntryToLocalDb(msgStr,logType); - } - public void writeToSysLogFile(String msgStr) { - writeLogEntryToLocalDb(msgStr,"v"); + public void writeToSysLogFile(String msgStr, String logType) { + writeLogEntryToLocalDb(msgStr, logType); } + public void writeToSysLogFile(String msgStr) { + writeLogEntryToLocalDb(msgStr, "v"); + } /** @@ -403,12 +403,11 @@ public class OsdUtil { public File[] getDataFilesList() { File[] files = getDataStorageDir().listFiles(); - Log.d("Files", "Size: "+ files.length); - for (int i = 0; i < files.length; i++) - { + Log.d("Files", "Size: " + files.length); + for (int i = 0; i < files.length; i++) { Log.d("Files", "FileName:" + files[i].getName()); } - return(files); + return (files); } /* Checks if external storage is available for read and write */ @@ -459,6 +458,7 @@ public class OsdUtil { * It first attempts to parse it as a long integer, in which case it is assumed to * be a unix timestamp. * If that fails it attempts to parse it as yyyy-MM-dd'T'HH:mm:ss'Z' format. + * * @param dateStr String reprenting a date * @return Date object or null if parsing fails. */ @@ -468,7 +468,7 @@ public class OsdUtil { Long tstamp = Long.parseLong(dateStr); dataTime = new Date(tstamp); } catch (NumberFormatException e) { - Log.v(TAG, "remoteEventsAdapter.getView: Error Parsing dataDate as Long: " + e.getLocalizedMessage()+" trying as string"); + Log.v(TAG, "remoteEventsAdapter.getView: Error Parsing dataDate as Long: " + e.getLocalizedMessage() + " trying as string"); try { SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'"); dataTime = dateFormat.parse(dateStr); @@ -477,7 +477,7 @@ public class OsdUtil { dataTime = null; } } - return(dataTime); + return (dataTime); } @@ -503,20 +503,20 @@ public class OsdUtil { break; } - return(retVal); + return (retVal); } private static boolean openDb() { Log.d(TAG, "openDb"); try { if (mSysLogDb == null) { - Log.i(TAG,"openDb: mSysLogDb is null - initialising"); + Log.i(TAG, "openDb: mSysLogDb is null - initialising"); mSysLogDb = new OsdSysLogHelper(mContext).getWritableDatabase(); } else { - Log.i(TAG,"openDb: mSysLogDb has been initialised already so not doing anything"); + Log.i(TAG, "openDb: mSysLogDb has been initialised already so not doing anything"); } if (!checkTableExists(mSysLogDb, mSysLogTableName)) { - Log.e(TAG, "ERROR - Table "+mSysLogTableName+" does not exist"); + Log.e(TAG, "ERROR - Table " + mSysLogTableName + " does not exist"); return false; } else { Log.d(TAG, "table " + mSysLogTableName + " exists ok"); @@ -565,7 +565,7 @@ public class OsdUtil { + 0 + ")"; mSysLogDb.execSQL(SQLStr); - Log.v(TAG, "syslog entry written to database: "+logText); + Log.v(TAG, "syslog entry written to database: " + logText); pruneSysLogDb(); } catch (SQLException e) { @@ -612,7 +612,6 @@ public class OsdUtil { /** * Executes the sqlite query (=SELECT statement) * Use as new SelectQueryTask(xxx,xxx,xx,xxxx).execute() - * */ static private class SelectQueryTask extends AsyncTask { // Based on https://stackoverflow.com/a/21120199/2104584 @@ -669,7 +668,6 @@ public class OsdUtil { } - /** * pruneSysLogDb() removes data that is older than 7 days */ @@ -728,13 +726,13 @@ public class OsdUtil { public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { // This database is only a cache for online data, so its upgrade policy is // to simply to discard the data and start over - Log.i(TAG,"onUpgrade()"); + Log.i(TAG, "onUpgrade()"); db.execSQL("Drop table if exists " + mSysLogTableName + ";"); onCreate(db); } public void onDowngrade(SQLiteDatabase db, int oldVersion, int newVersion) { - Log.i(TAG,"onDowngrade()"); + Log.i(TAG, "onDowngrade()"); onUpgrade(db, oldVersion, newVersion); } } diff --git a/app/src/main/java/uk/org/openseizuredetector/PrefActivity.java b/app/src/main/java/uk/org/openseizuredetector/PrefActivity.java index 8d0227f..a99ff18 100644 --- a/app/src/main/java/uk/org/openseizuredetector/PrefActivity.java +++ b/app/src/main/java/uk/org/openseizuredetector/PrefActivity.java @@ -152,7 +152,7 @@ public class PrefActivity extends PreferenceActivity implements SharedPreference Intent i; i = new Intent(this, StartupActivity.class); startActivity(i); - Log.i(TAG,"onSharedPreferenceChanged() - finishing PrefActivity"); + Log.i(TAG, "onSharedPreferenceChanged() - finishing PrefActivity"); finish(); return; } else { @@ -218,7 +218,7 @@ public class PrefActivity extends PreferenceActivity implements SharedPreference protected void onStop() { super.onStop(); mUtil.writeToSysLogFile("PrefActvity.onStop()"); - Log.i(TAG,"onStop()"); + Log.i(TAG, "onStop()"); } /** diff --git a/app/src/main/java/uk/org/openseizuredetector/RemoteDbActivity.java b/app/src/main/java/uk/org/openseizuredetector/RemoteDbActivity.java index 0060bbc..3fab821 100644 --- a/app/src/main/java/uk/org/openseizuredetector/RemoteDbActivity.java +++ b/app/src/main/java/uk/org/openseizuredetector/RemoteDbActivity.java @@ -9,7 +9,9 @@ import android.os.Bundle; import android.os.CountDownTimer; import android.os.Handler; import android.preference.PreferenceManager; + import androidx.appcompat.app.AppCompatActivity; + import android.util.Log; import android.view.View; import android.webkit.WebSettings; @@ -114,7 +116,7 @@ public class RemoteDbActivity extends AppCompatActivity { private HashMap getAuthHeaders() { HashMap headersMap = new HashMap<>(); String authToken = getAuthToken(); - headersMap.put("Authorization", "Token "+authToken); + headersMap.put("Authorization", "Token " + authToken); return (headersMap); } @@ -125,7 +127,7 @@ public class RemoteDbActivity extends AppCompatActivity { } private void updateUi() { - Log.v(TAG,"updateUi()"); + Log.v(TAG, "updateUi()"); TextView tv; Button btn; // Local Database Information @@ -137,10 +139,9 @@ public class RemoteDbActivity extends AppCompatActivity { //tv.setText(String.format("%d",datapointsCount)); - // Remote Database Information - tv = (TextView)findViewById(R.id.authStatusTv); - btn = (Button)findViewById(R.id.auth_button); + tv = (TextView) findViewById(R.id.authStatusTv); + btn = (Button) findViewById(R.id.auth_button); if (mLm != null) { if (mLm.mWac.isLoggedIn()) { tv.setText("Authenticated"); @@ -158,7 +159,7 @@ public class RemoteDbActivity extends AppCompatActivity { public void onClick(View view) { Log.v(TAG, "onAuth"); Intent i; - i =new Intent(mContext, AuthenticateActivity.class); + i = new Intent(mContext, AuthenticateActivity.class); startActivity(i); } }; diff --git a/app/src/main/java/uk/org/openseizuredetector/ReportSeizureActivity.java b/app/src/main/java/uk/org/openseizuredetector/ReportSeizureActivity.java index c626114..447c23e 100644 --- a/app/src/main/java/uk/org/openseizuredetector/ReportSeizureActivity.java +++ b/app/src/main/java/uk/org/openseizuredetector/ReportSeizureActivity.java @@ -209,24 +209,23 @@ public class ReportSeizureActivity extends AppCompatActivity { } - private void updateUi() { //Log.v(TAG,"updateUi()"); TextView tv; Button btn; RadioButton b; - tv = (TextView)findViewById(R.id.date_day_tv); - tv.setText(String.format("%02d",mDay)); - tv = (TextView)findViewById(R.id.date_mon_tv); - tv.setText(String.format("%02d",mMonth+1)); // Month counted from zero - tv = (TextView)findViewById(R.id.date_year_tv); - tv.setText(String.format("%04d",mYear)); - tv = (TextView)findViewById(R.id.time_hh_tv); - tv.setText(String.format("%02d",mHour)); - tv = (TextView)findViewById(R.id.time_mm_tv); - tv.setText(String.format("%02d",mMinute)); - tv = (TextView)findViewById(R.id.msg_tv); + tv = (TextView) findViewById(R.id.date_day_tv); + tv.setText(String.format("%02d", mDay)); + tv = (TextView) findViewById(R.id.date_mon_tv); + tv.setText(String.format("%02d", mMonth + 1)); // Month counted from zero + tv = (TextView) findViewById(R.id.date_year_tv); + tv.setText(String.format("%04d", mYear)); + tv = (TextView) findViewById(R.id.time_hh_tv); + tv.setText(String.format("%02d", mHour)); + tv = (TextView) findViewById(R.id.time_mm_tv); + tv.setText(String.format("%02d", mMinute)); + tv = (TextView) findViewById(R.id.msg_tv); tv.setText(mMsg); // Populate event type button group if necessary @@ -250,12 +249,12 @@ public class ReportSeizureActivity extends AppCompatActivity { if (b != null) { seizureTypeStr = b.getText().toString(); } - Log.i(TAG,"updateUi - SeizureType="+seizureTypeStr); + Log.i(TAG, "updateUi - SeizureType=" + seizureTypeStr); // Populate the event sub-types radio button list. - Log.v(TAG,"updateUi() - meventsubtypeshashmap="+mEventSubTypesHashMap+", mEventSubtypesListChanged="+mEventSubTypesListChanged); + Log.v(TAG, "updateUi() - meventsubtypeshashmap=" + mEventSubTypesHashMap + ", mEventSubtypesListChanged=" + mEventSubTypesListChanged); if (mEventSubTypesHashMap != null && mRedrawEventSubTypesList) { - Log.v(TAG,"UpdateUi() - populating event sub types list"); + Log.v(TAG, "UpdateUi() - populating event sub types list"); if (seizureTypeStr != null) { // based on https://androidexample.com/create-a-simple-listview ArrayList subtypesArrayList = mEventSubTypesHashMap.get(seizureTypeStr); @@ -281,8 +280,8 @@ public class ReportSeizureActivity extends AppCompatActivity { String notesStr = null; Log.v(TAG, "onOk"); //SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); - String dateStr=String.format("%4d-%02d-%02d %02d:%02d:30",mYear,mMonth+1,mDay, mHour, mMinute); - Log.v(TAG, "onOk() - dateSTr="+dateStr); + String dateStr = String.format("%4d-%02d-%02d %02d:%02d:30", mYear, mMonth + 1, mDay, mHour, mMinute); + Log.v(TAG, "onOk() - dateSTr=" + dateStr); // Read seizure type from radio buttons int checkedRadioButtonId = mEventTypeRg.getCheckedRadioButtonId(); @@ -290,19 +289,19 @@ public class ReportSeizureActivity extends AppCompatActivity { if (b != null) { seizureTypeStr = b.getText().toString(); } - Log.i(TAG,"onOk() - SeizureType="+seizureTypeStr); + Log.i(TAG, "onOk() - SeizureType=" + seizureTypeStr); checkedRadioButtonId = mEventSubTypeRg.getCheckedRadioButtonId(); b = (RadioButton) findViewById(checkedRadioButtonId); if (b != null) { seizureSubTypeStr = b.getText().toString(); } - Log.i(TAG,"onOk() - SeizureSubType="+seizureSubTypeStr); + Log.i(TAG, "onOk() - SeizureSubType=" + seizureSubTypeStr); - TextView tv = (TextView)findViewById(R.id.eventNotesTv); + TextView tv = (TextView) findViewById(R.id.eventNotesTv); notesStr = tv.getText().toString(); - mLm.createLocalEvent(dateStr,5,seizureTypeStr, seizureSubTypeStr, notesStr, + mLm.createLocalEvent(dateStr, 5, seizureTypeStr, seizureSubTypeStr, notesStr, mConnection.mSdServer.mSdData.toSettingsJSON()); mUtil.showToast("Seizure Event Created"); finish(); diff --git a/app/src/main/java/uk/org/openseizuredetector/SdAlgHr.java b/app/src/main/java/uk/org/openseizuredetector/SdAlgHr.java index cea9139..ed20b6f 100644 --- a/app/src/main/java/uk/org/openseizuredetector/SdAlgHr.java +++ b/app/src/main/java/uk/org/openseizuredetector/SdAlgHr.java @@ -36,7 +36,7 @@ public class SdAlgHr { mAdaptiveHrBuff = new CircBuf(mAdaptiveHrAlarmWindowDp, -1.0); mAverageHrBuff = new CircBuf(mAverageHrAlarmWindowDp, -1.0); // FIXME - this is a hard coded 3 hour period (at 5 second intervals) - mHrHist = new CircBuf((int)(3 * 3600 / 5), -1); + mHrHist = new CircBuf((int) (3 * 3600 / 5), -1); } public void close() { @@ -72,34 +72,33 @@ public class SdAlgHr { mSimpleHrAlarmActive = SP.getBoolean("HRAlarmActive", false); mSimpleHrAlarmThreshMin = readDoublePref(SP, "HRThreshMin", "20"); mSimpleHrAlarmThreshMax = readDoublePref(SP, "HRThreshMax", "150"); - Log.d(TAG,"updatePrefs(): mSimpleHrAlarmActive="+mSimpleHrAlarmActive); - Log.d(TAG,"updatePrefs(): mSimpleHrAlarmThreshMin="+mSimpleHrAlarmThreshMin); - Log.d(TAG,"updatePrefs(): mSimpleHrAlarmThreshMax="+mSimpleHrAlarmThreshMax); + Log.d(TAG, "updatePrefs(): mSimpleHrAlarmActive=" + mSimpleHrAlarmActive); + Log.d(TAG, "updatePrefs(): mSimpleHrAlarmThreshMin=" + mSimpleHrAlarmThreshMin); + Log.d(TAG, "updatePrefs(): mSimpleHrAlarmThreshMax=" + mSimpleHrAlarmThreshMax); mAdaptiveHrAlarmActive = SP.getBoolean("HRAdaptiveAlarmActive", false); mAdaptiveHrAlarmWindowSecs = readDoublePref(SP, "HRAdaptiveAlarmWindowSecs", "30"); - mAdaptiveHrAlarmWindowDp = (int)Math.round(mAdaptiveHrAlarmWindowSecs/5.0); + mAdaptiveHrAlarmWindowDp = (int) Math.round(mAdaptiveHrAlarmWindowSecs / 5.0); mAdaptiveHrAlarmThresh = readDoublePref(SP, "HRAdaptiveAlarmThresh", "20"); - Log.d(TAG,"updatePrefs(): mAdaptiveHrAlarmActive="+mAdaptiveHrAlarmActive); - Log.d(TAG,"updatePrefs(): mAdaptiveHrWindowSecs="+mAdaptiveHrAlarmWindowSecs); - Log.d(TAG,"updatePrefs(): mAdaptiveHrWindowDp="+mAdaptiveHrAlarmWindowDp); - Log.d(TAG,"updatePrefs(): mAdaptiveHrAlarmThresh="+mAdaptiveHrAlarmThresh); + Log.d(TAG, "updatePrefs(): mAdaptiveHrAlarmActive=" + mAdaptiveHrAlarmActive); + Log.d(TAG, "updatePrefs(): mAdaptiveHrWindowSecs=" + mAdaptiveHrAlarmWindowSecs); + Log.d(TAG, "updatePrefs(): mAdaptiveHrWindowDp=" + mAdaptiveHrAlarmWindowDp); + Log.d(TAG, "updatePrefs(): mAdaptiveHrAlarmThresh=" + mAdaptiveHrAlarmThresh); mAverageHrAlarmActive = SP.getBoolean("HRAverageAlarmActive", false); mAverageHrAlarmWindowSecs = readDoublePref(SP, "HRAverageAlarmWindowSecs", "120"); - mAverageHrAlarmWindowDp = (int)Math.round(mAverageHrAlarmWindowSecs/5.0); + mAverageHrAlarmWindowDp = (int) Math.round(mAverageHrAlarmWindowSecs / 5.0); mAverageHrAlarmThreshMin = readDoublePref(SP, "HRAverageAlarmThreshMin", "40"); mAverageHrAlarmThreshMax = readDoublePref(SP, "HRAverageAlarmThreshMax", "120"); - Log.d(TAG,"updatePrefs(): mAverageHrAlarmActive="+mAverageHrAlarmActive); - Log.d(TAG,"updatePrefs(): mAverageHrAlarmWindowSecs="+mAverageHrAlarmWindowSecs); - Log.d(TAG,"updatePrefs(): mAverageHrAlarmWindowDp="+mAverageHrAlarmWindowDp); - Log.d(TAG,"updatePrefs(): mAverageHrAlarmThreshMin="+mAverageHrAlarmThreshMin); - Log.d(TAG,"updatePrefs(): mAverageHrAlarmThreshMax="+mAverageHrAlarmThreshMax); + Log.d(TAG, "updatePrefs(): mAverageHrAlarmActive=" + mAverageHrAlarmActive); + Log.d(TAG, "updatePrefs(): mAverageHrAlarmWindowSecs=" + mAverageHrAlarmWindowSecs); + Log.d(TAG, "updatePrefs(): mAverageHrAlarmWindowDp=" + mAverageHrAlarmWindowDp); + Log.d(TAG, "updatePrefs(): mAverageHrAlarmThreshMin=" + mAverageHrAlarmThreshMin); + Log.d(TAG, "updatePrefs(): mAverageHrAlarmThreshMax=" + mAverageHrAlarmThreshMax); } - private boolean checkSimpleHr(double hrVal) { /** * Check heart rate value against simple thresholds @@ -107,15 +106,16 @@ public class SdAlgHr { boolean retVal = false; if (mSimpleHrAlarmActive) { if ((hrVal > mSimpleHrAlarmThreshMax) - || (hrVal hrThreshMax) { retVal = true; } - Log.d(TAG, "checkAdaptiveHr() - hrVal="+hrVal+", avHr="+avHr+", thresholds=("+hrThreshMin+", "+hrThreshMax+"): Alarm="+retVal); + Log.d(TAG, "checkAdaptiveHr() - hrVal=" + hrVal + ", avHr=" + avHr + ", thresholds=(" + hrThreshMin + ", " + hrThreshMax + "): Alarm=" + retVal); - return(retVal); + return (retVal); } private boolean checkAverageHr(double hrVal) { @@ -172,12 +175,11 @@ public class SdAlgHr { if (avHr > mAverageHrAlarmThreshMax) { retVal = true; } - Log.d(TAG, "checkAverageHr() - hrVal="+hrVal+", avHr="+avHr+", thresholds=("+mAverageHrAlarmThreshMin+", "+mAverageHrAlarmThreshMin+"): Alarm="+retVal); - return(retVal); + Log.d(TAG, "checkAverageHr() - hrVal=" + hrVal + ", avHr=" + avHr + ", thresholds=(" + mAverageHrAlarmThreshMin + ", " + mAverageHrAlarmThreshMin + "): Alarm=" + retVal); + return (retVal); } - public ArrayList checkHr(double hrVal) { /** * Checks the current Heart Rate reading hrVal against the @@ -185,7 +187,7 @@ public class SdAlgHr { * and returns an ArrayList of the alarm status of each algorithm in the above order. * true=ALARM, false=OK. */ - Log.v(TAG, "checkHr("+hrVal+")"); + Log.v(TAG, "checkHr(" + hrVal + ")"); mAdaptiveHrBuff.add(hrVal); mAverageHrBuff.add(hrVal); mHrHist.add(hrVal); @@ -193,7 +195,7 @@ public class SdAlgHr { retVal.add(checkSimpleHr(hrVal)); retVal.add(checkAdaptiveHr(hrVal)); retVal.add(checkAverageHr(hrVal)); - return(retVal); + return (retVal); } } diff --git a/app/src/main/java/uk/org/openseizuredetector/SdAlgNn.java b/app/src/main/java/uk/org/openseizuredetector/SdAlgNn.java index c74b04e..5391198 100644 --- a/app/src/main/java/uk/org/openseizuredetector/SdAlgNn.java +++ b/app/src/main/java/uk/org/openseizuredetector/SdAlgNn.java @@ -99,6 +99,7 @@ public class SdAlgNn { * getPseizureFmt1 - calculate probability of sdData representing seizure-like movement * using a model with input format #1, which is a simple vector of 125 accelerometer vector * magnitude readings. + * * @param sdData - seizure detector data as input to the model * @return probability of data representing seizure-like movement. */ @@ -125,7 +126,7 @@ public class SdAlgNn { double stdDev; stdDev = calcRawDataStd(sdData); if (stdDev < mSdThresh) { - Log.d(TAG, "getPseizure - acceleration stdev below movement threshold: std="+stdDev+", thresh="+mSdThresh); + Log.d(TAG, "getPseizure - acceleration stdev below movement threshold: std=" + stdDev + ", thresh=" + mSdThresh); return (0); } @@ -135,11 +136,11 @@ public class SdAlgNn { pSeizure = getPseizureFmt1(sdData); break; default: - Log.e(TAG,"getPSeizure - invalid model ID "+mModelId); + Log.e(TAG, "getPSeizure - invalid model ID " + mModelId); pSeizure = 0; } - return(pSeizure); + return (pSeizure); } private double calcRawDataStd(SdData sdData) { diff --git a/app/src/main/java/uk/org/openseizuredetector/SdData.java b/app/src/main/java/uk/org/openseizuredetector/SdData.java index bf5fb0c..ac41a10 100644 --- a/app/src/main/java/uk/org/openseizuredetector/SdData.java +++ b/app/src/main/java/uk/org/openseizuredetector/SdData.java @@ -182,7 +182,7 @@ public class SdData implements Parcelable { try { mO2Sat = jo.optDouble("o2Sat"); } catch (Exception e) { - Log.w(TAG,"Error parsing o2Sat value"); + Log.w(TAG, "Error parsing o2Sat value"); mO2Sat = -1; } haveData = true; @@ -249,7 +249,7 @@ public class SdData implements Parcelable { jsonObj.put("rawData3D", raw3DArr); retval = jsonObj.toString(); - Log.v(TAG,"retval rawData="+retval); + Log.v(TAG, "retval rawData=" + retval); } catch (Exception ex) { Log.v(TAG, "Error Creating Data Object - " + ex.toString()); retval = "Error Creating Data Object - " + ex.toString(); @@ -302,7 +302,7 @@ public class SdData implements Parcelable { jsonObj.put("o2SatAlarmStanding", mO2SatAlarmStanding); jsonObj.put("o2SatThreshMin", mO2SatThreshMin); jsonObj.put("dataSourceName", dataSourceName); - Log.v(TAG,"phoneAppVersion="+phoneAppVersion); + Log.v(TAG, "phoneAppVersion=" + phoneAppVersion); jsonObj.put("phoneAppVersion", phoneAppVersion); jsonObj.put("watchPartNo", watchPartNo); jsonObj.put("watchSdName", watchSdName); diff --git a/app/src/main/java/uk/org/openseizuredetector/SdDataSource.java b/app/src/main/java/uk/org/openseizuredetector/SdDataSource.java index f64ea8b..c9c8073 100644 --- a/app/src/main/java/uk/org/openseizuredetector/SdDataSource.java +++ b/app/src/main/java/uk/org/openseizuredetector/SdDataSource.java @@ -154,7 +154,6 @@ public abstract class SdDataSource { } - // Start timer to check status of watch regularly. mDataStatusTime = new Time(Time.getCurrentTimezone()); // use a timer to check the status of the pebble app on the same frequency @@ -342,7 +341,7 @@ public abstract class SdDataSource { } } catch (JSONException e) { // If we get an error, just set rawData3D to zero - Log.i(TAG,"updateFromJSON - error parsing 3D data - setting it to zero"); + Log.i(TAG, "updateFromJSON - error parsing 3D data - setting it to zero"); for (i = 0; i < mSdData.rawData3D.length; i++) { mSdData.rawData3D[i] = 0.; } @@ -449,7 +448,7 @@ public abstract class SdDataSource { mSampleFreq = 25; double freqRes = 1.0 * mSampleFreq / mSdData.mNsamp; Log.v(TAG, "doAnalysis(): mSampleFreq=" + mSampleFreq + " mNSamp=" + mSdData.mNsamp + ": freqRes=" + freqRes); - Log.v(TAG,"doAnalysis(): rawData=" + Arrays.toString(mSdData.rawData)); + Log.v(TAG, "doAnalysis(): rawData=" + Arrays.toString(mSdData.rawData)); // Set the frequency bounds for the analysis in fft output bin numbers. nMin = (int) (mAlarmFreqMin / freqRes); nMax = (int) (mAlarmFreqMax / freqRes); @@ -526,11 +525,11 @@ public abstract class SdDataSource { Log.e(TAG, "doAnalysis - Exception during Analysis"); mUtil.writeToSysLogFile("doAnalysis - Exception during analysis - " + e.toString()); mUtil.writeToSysLogFile("doAnalysis: Exception at Line Number: " + e.getCause().getStackTrace()[0].getLineNumber() + ", " + e.getCause().getStackTrace()[0].toString()); - mUtil.writeToSysLogFile("doAnalysis: mSdData.mNsamp="+mSdData.mNsamp); - mUtil.writeToSysLogFile("doAnalysis: alarmFreqMin="+mAlarmFreqMin+" nMin="+nMin); - mUtil.writeToSysLogFile("doAnalysis: alarmFreqMax="+mAlarmFreqMax+" nMax="+nMax); - mUtil.writeToSysLogFile("doAnalysis: nFreqCutoff.="+nFreqCutoff); - mUtil.writeToSysLogFile("doAnalysis: fft.length="+fft.length); + mUtil.writeToSysLogFile("doAnalysis: mSdData.mNsamp=" + mSdData.mNsamp); + mUtil.writeToSysLogFile("doAnalysis: alarmFreqMin=" + mAlarmFreqMin + " nMin=" + nMin); + mUtil.writeToSysLogFile("doAnalysis: alarmFreqMax=" + mAlarmFreqMax + " nMax=" + nMax); + mUtil.writeToSysLogFile("doAnalysis: nFreqCutoff.=" + nFreqCutoff); + mUtil.writeToSysLogFile("doAnalysis: fft.length=" + fft.length); mWatchAppRunningCheck = false; } @@ -547,7 +546,7 @@ public abstract class SdDataSource { o2SatCheck(); fallCheck(); muteCheck(); - Log.v(TAG,"after fallCheck, mSdData.fallAlarmStanding="+mSdData.fallAlarmStanding); + Log.v(TAG, "after fallCheck, mSdData.fallAlarmStanding=" + mSdData.fallAlarmStanding); mSdDataReceiver.onSdDataReceived(mSdData); // and tell SdServer we have received data. } @@ -564,20 +563,20 @@ public abstract class SdDataSource { // Avoid potential divide by zero issue if (mSdData.specPower == 0) mSdData.specPower = 1; - Log.v(TAG, "alarmCheck() - roiPower="+mSdData.roiPower+" specPower="+ mSdData.specPower+" ratio="+10*mSdData.roiPower/ mSdData.specPower); + Log.v(TAG, "alarmCheck() - roiPower=" + mSdData.roiPower + " specPower=" + mSdData.specPower + " ratio=" + 10 * mSdData.roiPower / mSdData.specPower); if (mSdData.mOsdAlarmActive) { // Is the current set of data representing an alarm state? if ((mSdData.roiPower > mAlarmThresh) && ((10 * mSdData.roiPower / mSdData.specPower) > mAlarmRatioThresh)) { inAlarm = true; - mSdData.alarmCause = mSdData.alarmCause+"OsdAlg "; + mSdData.alarmCause = mSdData.alarmCause + "OsdAlg "; } } if (mSdData.mCnnAlarmActive) { if (mSdData.mPseizure > 0.5) { inAlarm = true; - mSdData.alarmCause = mSdData.alarmCause+"CnnAlg "; + mSdData.alarmCause = mSdData.alarmCause + "CnnAlg "; } } @@ -646,7 +645,7 @@ public abstract class SdDataSource { mSdData.mHRAlarmStanding = true; mSdData.mAdaptiveHrAlarmStanding = false; mSdData.mAverageHrAlarmStanding = false; - mSdData.alarmCause = mSdData.alarmCause+"HrNull "; + mSdData.alarmCause = mSdData.alarmCause + "HrNull "; } else { Log.i(TAG, "Heart Rate Fault (HR<0)"); @@ -659,13 +658,13 @@ public abstract class SdDataSource { mSdData.mHRFaultStanding = false; mSdData.mHRAlarmStanding = checkResults.get(0); if (mSdData.mHRAlarmStanding) - mSdData.alarmCause = mSdData.alarmCause+"HR "; + mSdData.alarmCause = mSdData.alarmCause + "HR "; mSdData.mAdaptiveHrAlarmStanding = checkResults.get(1); if (mSdData.mAdaptiveHrAlarmStanding) - mSdData.alarmCause = mSdData.alarmCause+"HR_ADAPT "; + mSdData.alarmCause = mSdData.alarmCause + "HR_ADAPT "; mSdData.mAverageHrAlarmStanding = checkResults.get(2); if (mSdData.mAverageHrAlarmStanding) - mSdData.alarmCause = mSdData.alarmCause+"HR_AVG "; + mSdData.alarmCause = mSdData.alarmCause + "HR_AVG "; // Show an ALARM state if any of the HR alarms is standing. if (mSdData.mHRAlarmStanding | mSdData.mAdaptiveHrAlarmStanding | mSdData.mAverageHrAlarmStanding) { mSdData.alarmState = 2; @@ -693,17 +692,17 @@ public abstract class SdDataSource { Log.i(TAG, "Oxygen Saturation Null - Alarming"); mSdData.mO2SatFaultStanding = false; mSdData.mO2SatAlarmStanding = true; - mSdData.alarmCause = mSdData.alarmCause+"O2_NULL "; + mSdData.alarmCause = mSdData.alarmCause + "O2_NULL "; } else { Log.i(TAG, "Oxygen Saturation Fault (O2Sat<0)"); mSdData.mO2SatFaultStanding = true; mSdData.mO2SatAlarmStanding = false; } - } else if (mSdData.mO2Sat < mSdData.mO2SatThreshMin) { + } else if (mSdData.mO2Sat < mSdData.mO2SatThreshMin) { Log.i(TAG, "Oxygen Saturation Abnormal - " + mSdData.mO2Sat + " %"); mSdData.mO2SatFaultStanding = false; mSdData.mO2SatAlarmStanding = true; - mSdData.alarmCause = mSdData.alarmCause+"O2SAT "; + mSdData.alarmCause = mSdData.alarmCause + "O2SAT "; } else { mSdData.mO2SatFaultStanding = false; mSdData.mO2SatAlarmStanding = false; @@ -740,12 +739,12 @@ public abstract class SdDataSource { if (mSdData.rawData[i + j] < minAcc) minAcc = mSdData.rawData[i + j]; if (mSdData.rawData[i + j] > maxAcc) maxAcc = mSdData.rawData[i + j]; } - Log.d(TAG, "check_fall() - minAcc=" + minAcc +" (mFallThreshMin="+mFallThreshMin+ "), maxAcc=" + maxAcc+" (mFallThreshMax="+mFallThreshMax+")") ; + Log.d(TAG, "check_fall() - minAcc=" + minAcc + " (mFallThreshMin=" + mFallThreshMin + "), maxAcc=" + maxAcc + " (mFallThreshMax=" + mFallThreshMax + ")"); if ((minAcc < mFallThreshMin) && (maxAcc > mFallThreshMax)) { Log.d(TAG, "check_fall() ****FALL DETECTED***** minAcc=" + minAcc + ", maxAcc=" + maxAcc); Log.d(TAG, "check_fall() - ****FALL DETECTED****"); mSdData.fallAlarmStanding = true; - mSdData.alarmCause = mSdData.alarmCause+"FALL "; + mSdData.alarmCause = mSdData.alarmCause + "FALL "; return; } if (mMute != 0) { @@ -825,13 +824,14 @@ public abstract class SdDataSource { // Check we have seen a fidget within the required period, or else assume a fault because watch is not being worn if (mFidgetDetectorEnabled) { - if (mLastFidget == null) mLastFidget = tnow; // Initialise last fidget time on startup. + if (mLastFidget == null) + mLastFidget = tnow; // Initialise last fidget time on startup. double accStd = calcRawDataStd(mSdData); if (accStd > mFidgetThreshold) { mLastFidget = tnow; } else { - Log.d(TAG,"onStatus() - Fidget Detector - low movement - is watch being worn?"); + Log.d(TAG, "onStatus() - Fidget Detector - low movement - is watch being worn?"); tdiff = (tnow.toMillis(false) - mLastFidget.toMillis(false)); if (tdiff > (mFidgetPeriod) * 60 * 1000) { Log.e(TAG, "onStatus() - Fidget Not Detected - is watch being worn?"); @@ -878,7 +878,7 @@ public abstract class SdDataSource { mSdData.mHrFrozenFaultStanding = false; } else { tdiff = (tnow.toMillis(false) - mHrStatusTime.toMillis(false)); - if (tdiff > mHrFrozenPeriod *1000.) { + if (tdiff > mHrFrozenPeriod * 1000.) { mSdData.mHrFrozenFaultStanding = true; } else { mSdData.mHrFrozenFaultStanding = false; @@ -889,7 +889,7 @@ public abstract class SdDataSource { void nnAnalysis() { //Check the current set of data using the neural network model to look for alarms. - Log.d(TAG,"nnAnalysis"); + Log.d(TAG, "nnAnalysis"); if (mSdData.mCnnAlarmActive) { float pSeizure = mSdAlgNn.getPseizure(mSdData); Log.d(TAG, "nnAnalysis - nnResult=" + pSeizure); @@ -904,9 +904,9 @@ public abstract class SdDataSource { * Read a preference value, and return it as a double. * FIXME - this should be in osdUtil so other classes can use it. * - * @param SP - Shared Preferences object + * @param SP - Shared Preferences object * @param prefName - name of preference to read. - * @param defVal - default value if it is not stored. + * @param defVal - default value if it is not stored. * @return double value of the stored specified preference, or the default value. */ private double readDoublePref(SharedPreferences SP, String prefName, String defVal) { @@ -937,10 +937,10 @@ public abstract class SdDataSource { String appRestartTimeoutStr = SP.getString("AppRestartTimeout", "10"); mAppRestartTimeout = Integer.parseInt(appRestartTimeoutStr); Log.v(TAG, "updatePrefs() - mAppRestartTimeout = " + mAppRestartTimeout); - mUtil.writeToSysLogFile( "updatePrefs() - mAppRestartTimeout = " + mAppRestartTimeout); + mUtil.writeToSysLogFile("updatePrefs() - mAppRestartTimeout = " + mAppRestartTimeout); } catch (Exception ex) { Log.v(TAG, "updatePrefs() - Problem with AppRestartTimeout preference!"); - mUtil.writeToSysLogFile( "updatePrefs() - Problem with AppRestartTimeout preference!"); + mUtil.writeToSysLogFile("updatePrefs() - Problem with AppRestartTimeout preference!"); Toast toast = Toast.makeText(mContext, "Problem Parsing AppRestartTimeout Preference", Toast.LENGTH_SHORT); toast.show(); } @@ -950,10 +950,10 @@ public abstract class SdDataSource { String faultTimerPeriodStr = SP.getString("FaultTimerPeriod", "30"); mFaultTimerPeriod = Integer.parseInt(faultTimerPeriodStr); Log.v(TAG, "updatePrefs() - mFaultTimerPeriod = " + mFaultTimerPeriod); - mUtil.writeToSysLogFile( "updatePrefs() - mFaultTimerPeriod = " + mFaultTimerPeriod); + mUtil.writeToSysLogFile("updatePrefs() - mFaultTimerPeriod = " + mFaultTimerPeriod); } catch (Exception ex) { Log.v(TAG, "updatePrefs() - Problem with FaultTimerPeriod preference!"); - mUtil.writeToSysLogFile( "updatePrefs() - Problem with FaultTimerPeriod preference!"); + mUtil.writeToSysLogFile("updatePrefs() - Problem with FaultTimerPeriod preference!"); Toast toast = Toast.makeText(mContext, "Problem Parsing FaultTimerPeriod Preference", Toast.LENGTH_SHORT); toast.show(); } @@ -964,7 +964,7 @@ public abstract class SdDataSource { mFidgetPeriod = readDoublePref(SP, "FidgetDetectorPeriod", "20"); // minutes Log.v(TAG, "updatePrefs() - mFidgetPeriod = " + mFidgetPeriod); mFidgetThreshold = readDoublePref(SP, "FidgetDetectorThreshold", "0.6 "); - Log.d(TAG,"updatePrefs(): mFidgetThreshold="+mFidgetThreshold); + Log.d(TAG, "updatePrefs(): mFidgetThreshold=" + mFidgetThreshold); } catch (Exception ex) { Log.v(TAG, "updatePrefs() - Problem with FidgetDetector preferences!"); @@ -978,57 +978,57 @@ public abstract class SdDataSource { prefStr = SP.getString("BLE_Device_Addr", "SET_FROM_XML"); mBleDeviceAddr = prefStr; Log.v(TAG, "mBLEDeviceAddr=" + mBleDeviceAddr); - mUtil.writeToSysLogFile( "mBLEDeviceAddr=" + mBleDeviceAddr); + mUtil.writeToSysLogFile("mBLEDeviceAddr=" + mBleDeviceAddr); prefStr = SP.getString("BLE_Device_Name", "SET_FROM_XML"); mBleDeviceName = prefStr; Log.v(TAG, "mBLEDeviceName=" + mBleDeviceName); - mUtil.writeToSysLogFile( "mBLEDeviceName=" + mBleDeviceName); + mUtil.writeToSysLogFile("mBLEDeviceName=" + mBleDeviceName); prefStr = SP.getString("PebbleDebug", "SET_FROM_XML"); if (prefStr != null) { mDebug = (short) Integer.parseInt(prefStr); Log.v(TAG, "updatePrefs() Debug = " + mDebug); - mUtil.writeToSysLogFile( "updatePrefs() Debug = " + mDebug); + mUtil.writeToSysLogFile("updatePrefs() Debug = " + mDebug); prefStr = SP.getString("PebbleDisplaySpectrum", "SET_FROM_XML"); mDisplaySpectrum = (short) Integer.parseInt(prefStr); Log.v(TAG, "updatePrefs() DisplaySpectrum = " + mDisplaySpectrum); - mUtil.writeToSysLogFile( "updatePrefs() DisplaySpectrum = " + mDisplaySpectrum); + mUtil.writeToSysLogFile("updatePrefs() DisplaySpectrum = " + mDisplaySpectrum); prefStr = SP.getString("PebbleUpdatePeriod", "SET_FROM_XML"); mDataUpdatePeriod = (short) Integer.parseInt(prefStr); Log.v(TAG, "updatePrefs() DataUpdatePeriod = " + mDataUpdatePeriod); - mUtil.writeToSysLogFile( "updatePrefs() DataUpdatePeriod = " + mDataUpdatePeriod); + mUtil.writeToSysLogFile("updatePrefs() DataUpdatePeriod = " + mDataUpdatePeriod); prefStr = SP.getString("MutePeriod", "SET_FROM_XML"); mMutePeriod = (short) Integer.parseInt(prefStr); Log.v(TAG, "updatePrefs() MutePeriod = " + mMutePeriod); - mUtil.writeToSysLogFile( "updatePrefs() MutePeriod = " + mMutePeriod); + mUtil.writeToSysLogFile("updatePrefs() MutePeriod = " + mMutePeriod); prefStr = SP.getString("ManAlarmPeriod", "SET_FROM_XML"); mManAlarmPeriod = (short) Integer.parseInt(prefStr); Log.v(TAG, "updatePrefs() ManAlarmPeriod = " + mManAlarmPeriod); - mUtil.writeToSysLogFile( "updatePrefs() ManAlarmPeriod = " + mManAlarmPeriod); + mUtil.writeToSysLogFile("updatePrefs() ManAlarmPeriod = " + mManAlarmPeriod); prefStr = SP.getString("PebbleSdMode", "SET_FROM_XML"); mPebbleSdMode = (short) Integer.parseInt(prefStr); Log.v(TAG, "updatePrefs() PebbleSdMode = " + mPebbleSdMode); - mUtil.writeToSysLogFile( "updatePrefs() PebbleSdMode = " + mPebbleSdMode); + mUtil.writeToSysLogFile("updatePrefs() PebbleSdMode = " + mPebbleSdMode); prefStr = SP.getString("SampleFreq", "SET_FROM_XML"); mSampleFreq = (short) Integer.parseInt(prefStr); Log.v(TAG, "updatePrefs() SampleFreq = " + mSampleFreq); - mUtil.writeToSysLogFile( "updatePrefs() SampleFreq = " + mSampleFreq); + mUtil.writeToSysLogFile("updatePrefs() SampleFreq = " + mSampleFreq); prefStr = SP.getString("SamplePeriod", "SET_FROM_XML"); mSamplePeriod = (short) Integer.parseInt(prefStr); Log.v(TAG, "updatePrefs() AnalysisPeriod = " + mSamplePeriod); - mUtil.writeToSysLogFile( "updatePrefs() AnalysisPeriod = " + mSamplePeriod); + mUtil.writeToSysLogFile("updatePrefs() AnalysisPeriod = " + mSamplePeriod); prefStr = SP.getString("AlarmFreqMin", "SET_FROM_XML"); mAlarmFreqMin = (short) Integer.parseInt(prefStr); Log.v(TAG, "updatePrefs() AlarmFreqMin = " + mAlarmFreqMin); - mUtil.writeToSysLogFile( "updatePrefs() AlarmFreqMin = " + mAlarmFreqMin); + mUtil.writeToSysLogFile("updatePrefs() AlarmFreqMin = " + mAlarmFreqMin); prefStr = SP.getString("AlarmFreqMax", "SET_FROM_XML"); mAlarmFreqMax = (short) Integer.parseInt(prefStr); @@ -1038,58 +1038,58 @@ public abstract class SdDataSource { prefStr = SP.getString("WarnTime", "SET_FROM_XML"); mWarnTime = (short) Integer.parseInt(prefStr); Log.v(TAG, "updatePrefs() WarnTime = " + mWarnTime); - mUtil.writeToSysLogFile( "updatePrefs() WarnTime = " + mWarnTime); + mUtil.writeToSysLogFile("updatePrefs() WarnTime = " + mWarnTime); prefStr = SP.getString("AlarmTime", "SET_FROM_XML"); mAlarmTime = (short) Integer.parseInt(prefStr); Log.v(TAG, "updatePrefs() AlarmTime = " + mAlarmTime); - mUtil.writeToSysLogFile( "updatePrefs() AlarmTime = " + mAlarmTime); + mUtil.writeToSysLogFile("updatePrefs() AlarmTime = " + mAlarmTime); prefStr = SP.getString("AlarmThresh", "SET_FROM_XML"); mAlarmThresh = (short) Integer.parseInt(prefStr); Log.v(TAG, "updatePrefs() AlarmThresh = " + mAlarmThresh); - mUtil.writeToSysLogFile( "updatePrefs() AlarmThresh = " + mAlarmThresh); + mUtil.writeToSysLogFile("updatePrefs() AlarmThresh = " + mAlarmThresh); prefStr = SP.getString("AlarmRatioThresh", "SET_FROM_XML"); mAlarmRatioThresh = (short) Integer.parseInt(prefStr); Log.v(TAG, "updatePrefs() AlarmRatioThresh = " + mAlarmRatioThresh); - mUtil.writeToSysLogFile( "updatePrefs() AlarmRatioThresh = " + mAlarmRatioThresh); + mUtil.writeToSysLogFile("updatePrefs() AlarmRatioThresh = " + mAlarmRatioThresh); mFallActive = SP.getBoolean("FallActive", false); Log.v(TAG, "updatePrefs() FallActive = " + mFallActive); - mUtil.writeToSysLogFile( "updatePrefs() FallActive = " + mFallActive); + mUtil.writeToSysLogFile("updatePrefs() FallActive = " + mFallActive); prefStr = SP.getString("FallThreshMin", "SET_FROM_XML"); mFallThreshMin = (short) Integer.parseInt(prefStr); Log.v(TAG, "updatePrefs() FallThreshMin = " + mFallThreshMin); - mUtil.writeToSysLogFile( "updatePrefs() FallThreshMin = " + mFallThreshMin); + mUtil.writeToSysLogFile("updatePrefs() FallThreshMin = " + mFallThreshMin); prefStr = SP.getString("FallThreshMax", "SET_FROM_XML"); mFallThreshMax = (short) Integer.parseInt(prefStr); Log.v(TAG, "updatePrefs() FallThreshMax = " + mFallThreshMax); - mUtil.writeToSysLogFile( "updatePrefs() FallThreshMax = " + mFallThreshMax); + mUtil.writeToSysLogFile("updatePrefs() FallThreshMax = " + mFallThreshMax); prefStr = SP.getString("FallWindow", "SET_FROM_XML"); mFallWindow = (short) Integer.parseInt(prefStr); Log.v(TAG, "updatePrefs() FallWindow = " + mFallWindow); - mUtil.writeToSysLogFile( "updatePrefs() FallWindow = " + mFallWindow); + mUtil.writeToSysLogFile("updatePrefs() FallWindow = " + mFallWindow); mSdData.mOsdAlarmActive = SP.getBoolean("OsdAlarmActive", false); Log.v(TAG, "updatePrefs() OsdAlarmActive = " + mSdData.mOsdAlarmActive); - mUtil.writeToSysLogFile( "updatePrefs() OsdAlarmActive = " + mSdData.mOsdAlarmActive); + mUtil.writeToSysLogFile("updatePrefs() OsdAlarmActive = " + mSdData.mOsdAlarmActive); mSdData.mCnnAlarmActive = SP.getBoolean("CnnAlarmActive", false); Log.v(TAG, "updatePrefs() CnnAlarmActive = " + mSdData.mCnnAlarmActive); - mUtil.writeToSysLogFile( "updatePrefs() CnnAlarmActive = " + mSdData.mCnnAlarmActive); + mUtil.writeToSysLogFile("updatePrefs() CnnAlarmActive = " + mSdData.mCnnAlarmActive); mSdData.mHRAlarmActive = SP.getBoolean("HRAlarmActive", false); Log.v(TAG, "updatePrefs() HRAlarmActive = " + mSdData.mHRAlarmActive); - mUtil.writeToSysLogFile( "updatePrefs() HRAlarmActive = " + mSdData.mHRAlarmActive); + mUtil.writeToSysLogFile("updatePrefs() HRAlarmActive = " + mSdData.mHRAlarmActive); mSdData.mHRNullAsAlarm = SP.getBoolean("HRNullAsAlarm", false); Log.v(TAG, "updatePrefs() HRNullAsAlarm = " + mSdData.mHRNullAsAlarm); - mUtil.writeToSysLogFile( "updatePrefs() HRNullAsAlarm = " + mSdData.mHRNullAsAlarm); + mUtil.writeToSysLogFile("updatePrefs() HRNullAsAlarm = " + mSdData.mHRNullAsAlarm); mHrFrozenAlarm = SP.getBoolean("HrFrozenAlarm", true); Log.v(TAG, "updatePrefs() - mHrFrozenAlarm = " + mHrFrozenAlarm); @@ -1098,42 +1098,42 @@ public abstract class SdDataSource { prefStr = SP.getString("HRThreshMin", "SET_FROM_XML"); mSdData.mHRThreshMin = (short) Integer.parseInt(prefStr); Log.v(TAG, "updatePrefs() HRThreshMin = " + mSdData.mHRThreshMin); - mUtil.writeToSysLogFile( "updatePrefs() HRThreshMin = " + mSdData.mHRThreshMin); + mUtil.writeToSysLogFile("updatePrefs() HRThreshMin = " + mSdData.mHRThreshMin); prefStr = SP.getString("HRThreshMax", "SET_FROM_XML"); mSdData.mHRThreshMax = (short) Integer.parseInt(prefStr); Log.v(TAG, "updatePrefs() HRThreshMax = " + mSdData.mHRThreshMax); - mUtil.writeToSysLogFile( "updatePrefs() HRThreshMax = " + mSdData.mHRThreshMax); + mUtil.writeToSysLogFile("updatePrefs() HRThreshMax = " + mSdData.mHRThreshMax); mSdData.mAdaptiveHrAlarmActive = SP.getBoolean("HRAdaptiveAlarmActive", false); mSdData.mAdaptiveHrAlarmWindowSecs = readDoublePref(SP, "HRAdaptiveAlarmWindowSecs", "30"); mSdData.mAdaptiveHrAlarmThresh = readDoublePref(SP, "HRAdaptiveAlarmThresh", "20"); - Log.d(TAG,"updatePrefs(): mAdaptiveHrAlarmActive="+mSdData.mAdaptiveHrAlarmActive); - Log.d(TAG,"updatePrefs(): mAdaptiveHrWindowSecs="+mSdData.mAdaptiveHrAlarmWindowSecs); - Log.d(TAG,"updatePrefs(): mAdaptiveHrAlarmThresh="+mSdData.mAdaptiveHrAlarmThresh); + Log.d(TAG, "updatePrefs(): mAdaptiveHrAlarmActive=" + mSdData.mAdaptiveHrAlarmActive); + Log.d(TAG, "updatePrefs(): mAdaptiveHrWindowSecs=" + mSdData.mAdaptiveHrAlarmWindowSecs); + Log.d(TAG, "updatePrefs(): mAdaptiveHrAlarmThresh=" + mSdData.mAdaptiveHrAlarmThresh); mSdData.mAverageHrAlarmActive = SP.getBoolean("HRAverageAlarmActive", false); mSdData.mAverageHrAlarmWindowSecs = readDoublePref(SP, "HRAverageAlarmWindowSecs", "120"); mSdData.mAverageHrAlarmThreshMin = readDoublePref(SP, "HRAverageAlarmThreshMin", "40"); mSdData.mAverageHrAlarmThreshMax = readDoublePref(SP, "HRAverageAlarmThreshMax", "120"); - Log.d(TAG,"updatePrefs(): mAverageHrAlarmActive="+mSdData.mAverageHrAlarmActive); - Log.d(TAG,"updatePrefs(): mAverageHrAlarmWindowSecs="+mSdData.mAverageHrAlarmWindowSecs); - Log.d(TAG,"updatePrefs(): mAverageHrAlarmThreshMin="+mSdData.mAverageHrAlarmThreshMin); - Log.d(TAG,"updatePrefs(): mAverageHrAlarmThreshMax="+mSdData.mAverageHrAlarmThreshMax); + Log.d(TAG, "updatePrefs(): mAverageHrAlarmActive=" + mSdData.mAverageHrAlarmActive); + Log.d(TAG, "updatePrefs(): mAverageHrAlarmWindowSecs=" + mSdData.mAverageHrAlarmWindowSecs); + Log.d(TAG, "updatePrefs(): mAverageHrAlarmThreshMin=" + mSdData.mAverageHrAlarmThreshMin); + Log.d(TAG, "updatePrefs(): mAverageHrAlarmThreshMax=" + mSdData.mAverageHrAlarmThreshMax); mSdData.mO2SatAlarmActive = SP.getBoolean("O2SatAlarmActive", false); Log.v(TAG, "updatePrefs() O2SatAlarmActive = " + mSdData.mO2SatAlarmActive); - mUtil.writeToSysLogFile( "updatePrefs() O2SatAlarmActive = " + mSdData.mO2SatAlarmActive); + mUtil.writeToSysLogFile("updatePrefs() O2SatAlarmActive = " + mSdData.mO2SatAlarmActive); mSdData.mO2SatNullAsAlarm = SP.getBoolean("O2SatNullAsAlarm", false); Log.v(TAG, "updatePrefs() O2SatNullAsAlarm = " + mSdData.mO2SatNullAsAlarm); - mUtil.writeToSysLogFile( "updatePrefs() O2SatNullAsAlarm = " + mSdData.mO2SatNullAsAlarm); + mUtil.writeToSysLogFile("updatePrefs() O2SatNullAsAlarm = " + mSdData.mO2SatNullAsAlarm); prefStr = SP.getString("O2SatThreshMin", "SET_FROM_XML"); mSdData.mO2SatThreshMin = (short) Integer.parseInt(prefStr); Log.v(TAG, "updatePrefs() O2SatThreshMin = " + mSdData.mO2SatThreshMin); - mUtil.writeToSysLogFile( "updatePrefs() O2SatThreshMin = " + mSdData.mO2SatThreshMin); + mUtil.writeToSysLogFile("updatePrefs() O2SatThreshMin = " + mSdData.mO2SatThreshMin); } else { Log.v(TAG, "updatePrefs() - prefStr is null - WHY????"); diff --git a/app/src/main/java/uk/org/openseizuredetector/SdDataSourceAw.java b/app/src/main/java/uk/org/openseizuredetector/SdDataSourceAw.java index e028c24..749baef 100644 --- a/app/src/main/java/uk/org/openseizuredetector/SdDataSourceAw.java +++ b/app/src/main/java/uk/org/openseizuredetector/SdDataSourceAw.java @@ -40,9 +40,9 @@ import java.nio.IntBuffer; import java.util.Timer; import java.util.TimerTask; import java.util.UUID; -import com.google.android.gms.wearable .MessageEvent; -import com.google.android.gms.wearable.WearableListenerService; +import com.google.android.gms.wearable.MessageEvent; +import com.google.android.gms.wearable.WearableListenerService; /** @@ -229,7 +229,7 @@ public class SdDataSourceAw extends SdDataSource { } catch (Exception e) { Log.v(TAG, "Error in stop() - " + e.toString()); - mUtil.writeToSysLogFile("SdDataSourceAw.stop() - error - "+e.toString()); + mUtil.writeToSysLogFile("SdDataSourceAw.stop() - error - " + e.toString()); } } @@ -342,7 +342,7 @@ public class SdDataSourceAw extends SdDataSource { } catch (Exception ex) { Log.v(TAG, "updatePrefs() - Problem parsing preferences!"); - mUtil.writeToSysLogFile("SdDataSourceAw.updatePrefs() - ERROR "+ex.toString()); + mUtil.writeToSysLogFile("SdDataSourceAw.updatePrefs() - ERROR " + ex.toString()); Toast toast = Toast.makeText(mContext, "Problem Parsing Preferences - Something won't work - Please go back to Settings and correct it!", Toast.LENGTH_SHORT); toast.show(); } @@ -360,10 +360,10 @@ public class SdDataSourceAw extends SdDataSource { Log.d(TAG, event); - String [] message = event.split("--"); + String[] message = event.split("--"); if (message[0].equals(SERVICE_CALLED_WEAR)) { - Log.d(TAG,"message detected"); + Log.d(TAG, "message detected"); Log.v(TAG, "Setting mWatchAppRunningCheck to true"); mWatchAppRunningCheck = true; } @@ -460,9 +460,9 @@ public class SdDataSourceAw extends SdDataSource { //int y = (rawDataBytes[i+2] & 0xff) | (rawDataBytes[i+3] << 8); //int z = (rawDataBytes[i+4] & 0xff) | (rawDataBytes[i+5] << 8); //Log.v(TAG,"x="+x+", y="+y+", z="+z); - Log.v(TAG,"x="+x); + Log.v(TAG, "x=" + x); if (nRawData < MAX_RAW_DATA) { - rawData[nRawData] = (int)Math.sqrt(x); + rawData[nRawData] = (int) Math.sqrt(x); } else { Log.i(TAG, "WARNING - rawData Buffer Full"); } @@ -477,7 +477,7 @@ public class SdDataSourceAw extends SdDataSource { // } else { // Log.i(TAG, "WARNING - rawData Buffer Full"); // } - // } + // } } } @@ -514,7 +514,7 @@ public class SdDataSourceAw extends SdDataSource { // first close the watch app if it is running. // FIXME - Make this work with Android Wear Log.v(TAG, "startWatchApp() - starting watch app after 5 seconds delay..."); - // Wait 5 seconds then start the app. + // Wait 5 seconds then start the app. Timer appStartTimer = new Timer(); appStartTimer.schedule(new TimerTask() { @Override @@ -736,7 +736,7 @@ public class SdDataSourceAw extends SdDataSource { * ignored! */ private void analyseRawData() { - Log.v(TAG,"analyserawData()"); + Log.v(TAG, "analyserawData()"); //DoubleFFT_1D fft = new DoubleFFT_1D(MAX_RAW_DATA); //fft.realForward(rawData); // FIXME - rawData should really be a circular buffer. @@ -744,9 +744,6 @@ public class SdDataSourceAw extends SdDataSource { } - - - } diff --git a/app/src/main/java/uk/org/openseizuredetector/SdDataSourceBLE.java b/app/src/main/java/uk/org/openseizuredetector/SdDataSourceBLE.java index d5dca22..1777cb9 100644 --- a/app/src/main/java/uk/org/openseizuredetector/SdDataSourceBLE.java +++ b/app/src/main/java/uk/org/openseizuredetector/SdDataSourceBLE.java @@ -101,8 +101,8 @@ public class SdDataSourceBLE extends SdDataSource { public static String CHAR_OSD_BATT_DATA = "000085e9-0002-1000-8000-00805f9b34fb"; public static String CHAR_OSD_WATCH_ID = "000085e9-0003-1000-8000-00805f9b34fb"; public static String CHAR_OSD_WATCH_FW = "000085e9-0004-1000-8000-00805f9b34fb"; - public static String CHAR_OSD_ACC_FMT= "000085e9-0005-1000-8000-00805f9b34fb"; - // Valid values are 0: 8 bit vector magnitude scaled so 1g=44 + public static String CHAR_OSD_ACC_FMT = "000085e9-0005-1000-8000-00805f9b34fb"; + // Valid values are 0: 8 bit vector magnitude scaled so 1g=44 public final static int ACC_FMT_8BIT = 0; public final static int ACC_FMT_16BIT = 1; @@ -245,13 +245,13 @@ public class SdDataSourceBLE extends SdDataSource { mSdData.watchConnected = false; Log.i(TAG, "onConnectionStateChange(): Disconnected from GATT server"); /**Log.i(TAG, "onConnectionStateChange(): Disconnected from GATT server - reconnecting after delay..."); - bleDisconnect(); // Tidy up connections - // Wait 2 seconds to give the server chance to shutdown, then re-start it - mHandler.postDelayed(new Runnable() { - public void run() { - bleConnect(); - } - }, 2000); + bleDisconnect(); // Tidy up connections + // Wait 2 seconds to give the server chance to shutdown, then re-start it + mHandler.postDelayed(new Runnable() { + public void run() { + bleConnect(); + } + }, 2000); */ } } @@ -319,7 +319,7 @@ public class SdDataSourceBLE extends SdDataSource { Log.v(TAG, "Battery Data Service Service Discovered"); for (BluetoothGattCharacteristic gattCharacteristic : gattCharacteristics) { String charUuidStr = gattCharacteristic.getUuid().toString(); - Log.v(TAG,"batt char="+charUuidStr); + Log.v(TAG, "batt char=" + charUuidStr); if (charUuidStr.equals(CHAR_BATT_DATA)) { Log.v(TAG, "Subscribing to Battery Data Change Notifications"); setCharacteristicNotification(gattCharacteristic, true); @@ -352,14 +352,14 @@ public class SdDataSourceBLE extends SdDataSource { * of a given characteristic. * Because only one BLE operation can be taking place at a time, it may fail, in which case * the read is re-tried after a 100ms delay. - * @param gattCharacteristic - the characteristic to be read. + * @param gattCharacteristic - the characteristic to be read. */ private void executeReadCharacteristic(BluetoothGattCharacteristic gattCharacteristic) { boolean retVal = mBluetoothGatt.readCharacteristic(gattCharacteristic); if (retVal) { - Log.d(TAG,"executeReadCharacteristic - read initiated successfully"); + Log.d(TAG, "executeReadCharacteristic - read initiated successfully"); } else { - Log.d(TAG,"executeReadCharacteristic - read initiation failed - waiting, then re-trying"); + Log.d(TAG, "executeReadCharacteristic - read initiation failed - waiting, then re-trying"); mHandler.postDelayed(new Runnable() { public void run() { Log.w(TAG, "Executing delayed read of characteristic"); @@ -368,6 +368,7 @@ public class SdDataSourceBLE extends SdDataSource { }, 100); } } + private boolean permissionsOK() { if (ActivityCompat.checkSelfPermission(mContext, Manifest.permission.BLUETOOTH_CONNECT) != PackageManager.PERMISSION_GRANTED) { // TODO: Consider calling @@ -377,7 +378,7 @@ public class SdDataSourceBLE extends SdDataSource { // int[] grantResults) // to handle the case where the user grants the permission. See the documentation // for ActivityCompat#requestPermissions for more details. - Log.e(TAG,"permissionsOK() - Bluetooth Permmission Not Granted"); + Log.e(TAG, "permissionsOK() - Bluetooth Permmission Not Granted"); mUtil.showToast("ERROR - Bluetooth Permission not Granted"); return (false); } else { @@ -392,7 +393,7 @@ public class SdDataSourceBLE extends SdDataSource { * If the data is acceleration data, we add it to a buffer - it is analysed once the buffer is full. * Heart rate data is written directly to sdData to be used in future analysis. */ - Log.v(TAG,"onDataReceived: Characteristic="+characteristic.getUuid().toString()); + Log.v(TAG, "onDataReceived: Characteristic=" + characteristic.getUuid().toString()); if (characteristic.getUuid().toString().equals(CHAR_HEART_RATE_MEASUREMENT)) { int flag = characteristic.getProperties(); //Log.d(TAG,"onDataReceived() - flag = "+flag); @@ -413,17 +414,16 @@ public class SdDataSourceBLE extends SdDataSource { mSdData.mHR = (double) heartRate; } Log.d(TAG, String.format("onDataReceived(): CHAR_HEART_RATE_MEASUREMENT: %d", heartRate)); - } - else if (characteristic.getUuid().toString().equals(CHAR_OSD_ACC_DATA) + } else if (characteristic.getUuid().toString().equals(CHAR_OSD_ACC_DATA) || characteristic.getUuid().toString().equals(CHAR_INFINITIME_ACC_DATA)) { //Log.v(TAG,"Received OSD ACC DATA"+characteristic.getValue()); byte[] rawDataBytes = characteristic.getValue(); short[] newAccVals = parseDataToAccVals(rawDataBytes); - Log.v(TAG, "onDataReceived(): CHAR_OSD_ACC_DATA: numSamples = " + rawDataBytes.length+" nRawData="+nRawData); + Log.v(TAG, "onDataReceived(): CHAR_OSD_ACC_DATA: numSamples = " + rawDataBytes.length + " nRawData=" + nRawData); //Log.v(TAG, "onDataReceived() - rawDataBytes="+ Arrays.toString(rawDataBytes)); //Log.v(TAG, "onDataReceived() - newAccVals="+Arrays.toString(newAccVals)); - for (int i = 0; i < newAccVals.length;i++) { - if (nRawData < MAX_RAW_DATA ) { + for (int i = 0; i < newAccVals.length; i++) { + if (nRawData < MAX_RAW_DATA) { switch (mAccFmt) { case ACC_FMT_8BIT: case ACC_FMT_16BIT: @@ -433,7 +433,7 @@ public class SdDataSourceBLE extends SdDataSource { case ACC_FMT_3D: // 3d data is x1,y1,z1, x2,y2,z2 ... xn,yn,zn // We only do this every third value, then process x, y and z simultaneously. - if (i+2 < newAccVals.length) { + if (i + 2 < newAccVals.length) { if (i % 3 == 0) { short x, y, z; x = newAccVals[i]; @@ -450,8 +450,8 @@ public class SdDataSourceBLE extends SdDataSource { } break; default: - Log.e(TAG,"INVALID ACCELERATION FORMAT"+mAccFmt); - mUtil.showToast("INVALID ACCELERATION FORMAT "+mAccFmt); + Log.e(TAG, "INVALID ACCELERATION FORMAT" + mAccFmt); + mUtil.showToast("INVALID ACCELERATION FORMAT " + mAccFmt); } } else { @@ -459,9 +459,9 @@ public class SdDataSourceBLE extends SdDataSource { mSdData.watchAppRunning = true; for (i = 0; i < rawData.length; i++) { mSdData.rawData[i] = rawData[i]; - mSdData.rawData3D[i*3] = rawData3d[i*3]; - mSdData.rawData3D[i*3 +1] = rawData3d[i*3 +1]; - mSdData.rawData3D[i*3 +2] = rawData3d[i*3 +2]; + mSdData.rawData3D[i * 3] = rawData3d[i * 3]; + mSdData.rawData3D[i * 3 + 1] = rawData3d[i * 3 + 1]; + mSdData.rawData3D[i * 3 + 2] = rawData3d[i * 3 + 2]; //Log.v(TAG,"onDataReceived() i="+i+", "+rawData[i]); } mSdData.mNsamp = rawData.length; @@ -473,37 +473,31 @@ public class SdDataSourceBLE extends SdDataSource { nRawData = 0; } } - } - else if (characteristic.getUuid().toString().equals(CHAR_OSD_BATT_DATA)) { + } else if (characteristic.getUuid().toString().equals(CHAR_OSD_BATT_DATA)) { byte batteryPc = characteristic.getValue()[0]; mSdData.batteryPc = batteryPc; - Log.v(TAG,"onDataReceived(): CHAR_OSD_BATT_DATA: " + String.format("%d", batteryPc)); + Log.v(TAG, "onDataReceived(): CHAR_OSD_BATT_DATA: " + String.format("%d", batteryPc)); mSdData.haveSettings = true; - } - else if (characteristic.getUuid().toString().equals(CHAR_BATT_DATA)) { + } else if (characteristic.getUuid().toString().equals(CHAR_BATT_DATA)) { byte batteryPc = characteristic.getValue()[0]; mSdData.batteryPc = batteryPc; - Log.v(TAG,"onDataReceived(): CHAR_BATT_DATA: " + String.format("%d", batteryPc)); + Log.v(TAG, "onDataReceived(): CHAR_BATT_DATA: " + String.format("%d", batteryPc)); mSdData.haveSettings = true; - } - else if (characteristic.getUuid().toString().equals(CHAR_OSD_WATCH_ID)) { + } else if (characteristic.getUuid().toString().equals(CHAR_OSD_WATCH_ID)) { byte[] rawDataBytes = characteristic.getValue(); String watchId = new String(rawDataBytes, StandardCharsets.UTF_8); - Log.v(TAG,"Received Watch ID: "+watchId); + Log.v(TAG, "Received Watch ID: " + watchId); mSdData.watchSdName = watchId; - } - else if (characteristic.getUuid().toString().equals(CHAR_OSD_WATCH_FW)) { + } else if (characteristic.getUuid().toString().equals(CHAR_OSD_WATCH_FW)) { byte[] rawDataBytes = characteristic.getValue(); String watchFwVer = new String(rawDataBytes, StandardCharsets.UTF_8); - Log.v(TAG,"Received Watch Firmware Version: "+watchFwVer); + Log.v(TAG, "Received Watch Firmware Version: " + watchFwVer); mSdData.watchSdVersion = watchFwVer; - } - else if (characteristic.getUuid().toString().equals(CHAR_OSD_ACC_FMT)) { + } else if (characteristic.getUuid().toString().equals(CHAR_OSD_ACC_FMT)) { mAccFmt = characteristic.getValue()[0]; - Log.v(TAG,"Received Acceleration format code: "+mAccFmt); - } - else { - Log.v(TAG,"Unrecognised Characteristic Updated "+ + Log.v(TAG, "Received Acceleration format code: " + mAccFmt); + } else { + Log.v(TAG, "Unrecognised Characteristic Updated " + characteristic.getUuid().toString()); } } @@ -513,14 +507,14 @@ public class SdDataSourceBLE extends SdDataSource { switch (mAccFmt) { case ACC_FMT_8BIT: retArr = new short[rawDataBytes.length]; - for (int i = 0; i < rawDataBytes.length;i++) { + for (int i = 0; i < rawDataBytes.length; i++) { retArr[i] = (short) (1000 * rawDataBytes[i] / 64); // Scale to mg } break; case ACC_FMT_16BIT: case ACC_FMT_3D: // from https://stackoverflow.com/questions/5625573/byte-array-to-short-array-and-back-again-in-java - retArr = new short[rawDataBytes.length/2]; + retArr = new short[rawDataBytes.length / 2]; // to turn bytes to shorts as either big endian or little endian. ByteBuffer.wrap(rawDataBytes) .order(ByteOrder.LITTLE_ENDIAN) @@ -528,17 +522,18 @@ public class SdDataSourceBLE extends SdDataSource { .get(retArr); break; default: - Log.e(TAG,"INVALID ACCELERATION FORMAT"+mAccFmt); - mUtil.showToast("INVALID ACCELERATION FORMAT "+mAccFmt); + Log.e(TAG, "INVALID ACCELERATION FORMAT" + mAccFmt); + mUtil.showToast("INVALID ACCELERATION FORMAT " + mAccFmt); retArr = new short[0]; } - return(retArr); + return (retArr); } + @Override public void onCharacteristicRead(BluetoothGatt gatt, BluetoothGattCharacteristic characteristic, int status) { - Log.v(TAG,"onCharacteristicRead"); + Log.v(TAG, "onCharacteristicRead"); if (status == BluetoothGatt.GATT_SUCCESS) { onDataReceived(characteristic); } @@ -553,7 +548,7 @@ public class SdDataSourceBLE extends SdDataSource { @Override public void onDescriptorWrite(BluetoothGatt gatt, BluetoothGattDescriptor descriptor, int status) { - Log.v(TAG,"onDescriptorWrite(): Characteristic " + descriptor.getUuid() + " changed"); + Log.v(TAG, "onDescriptorWrite(): Characteristic " + descriptor.getUuid() + " changed"); waitForDescriptorWrite = false; } }; diff --git a/app/src/main/java/uk/org/openseizuredetector/SdDataSourceNetwork.java b/app/src/main/java/uk/org/openseizuredetector/SdDataSourceNetwork.java index 118258e..f5c57be 100644 --- a/app/src/main/java/uk/org/openseizuredetector/SdDataSourceNetwork.java +++ b/app/src/main/java/uk/org/openseizuredetector/SdDataSourceNetwork.java @@ -38,17 +38,18 @@ public class SdDataSourceNetwork extends SdDataSource { mName = "Network"; } - @Override public void start() { + @Override + public void start() { // Update preferences. - Log.v(TAG,"start(): calling updatePrefs()"); + Log.v(TAG, "start(): calling updatePrefs()"); mUtil.writeToSysLogFile("SdDataSourceNetwork().start()"); updatePrefs(); // Start timer to retrieve seizure detector data regularly. mStatusTime = new Time(Time.getCurrentTimezone()); mStatusTime.setToNow(); - if (mDataUpdateTimer ==null) { - Log.v(TAG,"start(): starting data update timer"); + if (mDataUpdateTimer == null) { + Log.v(TAG, "start(): starting data update timer"); mDataUpdateTimer = new Timer(); mDataUpdateTimer.schedule(new TimerTask() { @Override @@ -57,17 +58,18 @@ public class SdDataSourceNetwork extends SdDataSource { } }, 0, mDataUpdatePeriod); } else { - Log.v(TAG,"start(): data update timer already running."); + Log.v(TAG, "start(): data update timer already running."); } } - @Override public void stop() { + @Override + public void stop() { mUtil.writeToSysLogFile("SdDataSourceNetwork().stop()"); // Stop the data update timer - if (mDataUpdateTimer !=null) { - Log.v(TAG,"stop(): cancelling status timer"); + if (mDataUpdateTimer != null) { + Log.v(TAG, "stop(): cancelling status timer"); mDataUpdateTimer.cancel(); mDataUpdateTimer.purge(); mDataUpdateTimer = null; @@ -76,7 +78,6 @@ public class SdDataSourceNetwork extends SdDataSource { } - /** * updatePrefs() - update basic settings from the SharedPreferences * - defined in res/xml/prefs.xml @@ -86,21 +87,21 @@ public class SdDataSourceNetwork extends SdDataSource { mUtil.writeToSysLogFile("SdDataSourceNetwork().updatePrefs()"); SharedPreferences SP = PreferenceManager .getDefaultSharedPreferences(mContext); - mServerIP = SP.getString("ServerIP","192.168.1.175"); - Log.v(TAG,"updatePrefs() - mServerIP = "+mServerIP); + mServerIP = SP.getString("ServerIP", "192.168.1.175"); + Log.v(TAG, "updatePrefs() - mServerIP = " + mServerIP); try { - String dataUpdatePeriodStr = SP.getString("DataUpdatePeriod","2000"); + String dataUpdatePeriodStr = SP.getString("DataUpdatePeriod", "2000"); mDataUpdatePeriod = Integer.parseInt(dataUpdatePeriodStr); - Log.v(TAG,"updatePrefs() - mDataUpdatePeriod = "+mDataUpdatePeriod); - String connectTimeoutPeriodStr = SP.getString("ConnectTimeoutPeriod","5000"); + Log.v(TAG, "updatePrefs() - mDataUpdatePeriod = " + mDataUpdatePeriod); + String connectTimeoutPeriodStr = SP.getString("ConnectTimeoutPeriod", "5000"); mConnnectTimeoutPeriod = Integer.parseInt(connectTimeoutPeriodStr); - Log.v(TAG,"updatePrefs() - mConnectTimeoutPeriod = "+mConnnectTimeoutPeriod); - String readTimeoutPeriodStr = SP.getString("ReadTimeoutPeriod","5000"); + Log.v(TAG, "updatePrefs() - mConnectTimeoutPeriod = " + mConnnectTimeoutPeriod); + String readTimeoutPeriodStr = SP.getString("ReadTimeoutPeriod", "5000"); mReadTimeoutPeriod = Integer.parseInt(readTimeoutPeriodStr); - Log.v(TAG,"updatePrefs() - mReadTimeoutPeriod = "+mReadTimeoutPeriod); + Log.v(TAG, "updatePrefs() - mReadTimeoutPeriod = " + mReadTimeoutPeriod); } catch (Exception ex) { - Log.v(TAG,"updatePrefs() - Problem parsing preferences!"); - mUtil.writeToSysLogFile("SdDataSourceNetwork().updatePrefs() - " +ex.toString()); + Log.v(TAG, "updatePrefs() - Problem parsing preferences!"); + mUtil.writeToSysLogFile("SdDataSourceNetwork().updatePrefs() - " + ex.toString()); showToast("Problem Parsing Preferences - Something won't work"); } } @@ -117,6 +118,7 @@ public class SdDataSourceNetwork extends SdDataSource { private class DownloadSdDataTask extends AsyncTask { private SdData sdData; + @Override protected SdData doInBackground(String... urls) { // params comes from the execute() call: params[0] is the url. @@ -124,23 +126,23 @@ public class SdDataSourceNetwork extends SdDataSource { try { String result = downloadUrl(urls[0]); if (result.startsWith("Unable to retrieve web page")) { - Log.v(TAG,"doInBackground() - Unable to retrieve data"); + Log.v(TAG, "doInBackground() - Unable to retrieve data"); sdData.serverOK = false; sdData.watchConnected = false; sdData.watchAppRunning = false; sdData.alarmState = ALARM_STATE_NETFAULT; sdData.alarmPhrase = "Warning - No Connection to Server"; - Log.v(TAG,"doInBackground(): No Connection to Server - sdData = "+sdData.toString()); + Log.v(TAG, "doInBackground(): No Connection to Server - sdData = " + sdData.toString()); } else { - Log.v(TAG,"doInBackground - result = "+result); + Log.v(TAG, "doInBackground - result = " + result); sdData.fromJSON(result); // Populate mSdData using the received data. sdData.serverOK = true; - if (sdData.batteryPc>0) { + if (sdData.batteryPc > 0) { sdData.haveSettings = true; } mStatusTime.setToNow(); - Log.v(TAG,"doInBackground(): sdData = "+sdData.toString()); + Log.v(TAG, "doInBackground(): sdData = " + sdData.toString()); } return (sdData); @@ -150,14 +152,15 @@ public class SdDataSourceNetwork extends SdDataSource { sdData.watchAppRunning = false; sdData.alarmState = ALARM_STATE_NETFAULT; sdData.alarmPhrase = "Warning - No Connection to Server"; - Log.v(TAG,"doInBackground(): IOException - "+e.toString()); + Log.v(TAG, "doInBackground(): IOException - " + e.toString()); return sdData; } } + // onPostExecute displays the results of the AsyncTask. @Override protected void onPostExecute(SdData sdData) { - Log.v(TAG,"onPostExecute() - sdData = "+sdData.toString()); + Log.v(TAG, "onPostExecute() - sdData = " + sdData.toString()); mSdDataReceiver.onSdDataReceived(sdData); } } @@ -178,24 +181,24 @@ public class SdDataSourceNetwork extends SdDataSource { try { String result = downloadUrl(urls[0]); if (result.startsWith("Unable to retrieve web page")) { - Log.v(TAG,"doInBackground() - Error accepting alarm"); + Log.v(TAG, "doInBackground() - Error accepting alarm"); } else { - Log.v(TAG,"doInBackground(): Alarm Accepted"); + Log.v(TAG, "doInBackground(): Alarm Accepted"); } } catch (IOException e) { - Log.v(TAG,"doInBackground(): IOException - "+e.toString()); + Log.v(TAG, "doInBackground(): IOException - " + e.toString()); } return "Done"; } + // onPostExecute displays the results of the AsyncTask. @Override protected void onPostExecute(String s) { - Log.v(TAG,"onPostExecute() - s="+s); + Log.v(TAG, "onPostExecute() - s=" + s); } } - // Given a URL, establishes an HttpUrlConnection and retrieves // the web page content as a InputStream, which it returns as // a string. @@ -241,6 +244,4 @@ public class SdDataSourceNetwork extends SdDataSource { } - - } diff --git a/app/src/main/java/uk/org/openseizuredetector/SdDataSourcePebble.java b/app/src/main/java/uk/org/openseizuredetector/SdDataSourcePebble.java index 10ef90f..090964c 100644 --- a/app/src/main/java/uk/org/openseizuredetector/SdDataSourcePebble.java +++ b/app/src/main/java/uk/org/openseizuredetector/SdDataSourcePebble.java @@ -45,7 +45,6 @@ import java.util.TimerTask; import java.util.UUID; - /** * Abstract class for a seizure detector data source. Subclasses include a pebble smart watch data source and a * network data source. @@ -166,7 +165,7 @@ public class SdDataSourcePebble extends SdDataSource { // use a timer to check the status of the pebble app on the same frequency // as we get app data. if (mStatusTimer == null) { - Log.v(TAG, "start(): starting status timer with period "+mDataUpdatePeriod*1000 + " ms"); + Log.v(TAG, "start(): starting status timer with period " + mDataUpdatePeriod * 1000 + " ms"); mUtil.writeToSysLogFile("SdDataSourcePebble.start() - starting status timer"); mStatusTimer = new Timer(); mStatusTimer.schedule(new TimerTask() { @@ -185,7 +184,7 @@ public class SdDataSourcePebble extends SdDataSource { getPebbleSdSettings(); if (mSettingsTimer == null) { Log.v(TAG, "start(): starting settings timer"); - mUtil.writeToSysLogFile("SdDataSourcePebble.start() - starting settings timer with period "+1000*mSettingsPeriod); + mUtil.writeToSysLogFile("SdDataSourcePebble.start() - starting settings timer with period " + 1000 * mSettingsPeriod); mSettingsTimer = new Timer(); mSettingsTimer.schedule(new TimerTask() { @Override @@ -230,7 +229,7 @@ public class SdDataSourcePebble extends SdDataSource { } catch (Exception e) { Log.v(TAG, "Error in stop() - " + e.toString()); - mUtil.writeToSysLogFile("SdDataSourcePebble.stop() - error - "+e.toString()); + mUtil.writeToSysLogFile("SdDataSourcePebble.stop() - error - " + e.toString()); } } @@ -343,8 +342,8 @@ public class SdDataSourcePebble extends SdDataSource { Log.v(TAG, "updatePrefs() FallWindow = " + mFallWindow); } catch (Exception ex) { - Log.v(TAG, "updatePrefs() - Problem parsing preferences! - prefStr="+prefStr); - mUtil.writeToSysLogFile("SdDataSourcePebble.updatePrefs() - ERROR "+ex.toString()); + Log.v(TAG, "updatePrefs() - Problem parsing preferences! - prefStr=" + prefStr); + mUtil.writeToSysLogFile("SdDataSourcePebble.updatePrefs() - ERROR " + ex.toString()); Toast toast = Toast.makeText(mContext, "Problem Parsing Preferences - Something won't work - Please go back to Settings and correct it!", Toast.LENGTH_SHORT); toast.show(); } @@ -437,16 +436,16 @@ public class SdDataSourcePebble extends SdDataSource { byte[] rawDataBytes = data.getBytes(KEY_RAW_DATA); for (int i = 0; i < rawDataBytes.length - 4; i += 4) { // 4 bytes per sample int b0 = rawDataBytes[i]; - int b1 = rawDataBytes[i+1] & 0xff; - int b2 = rawDataBytes[i+2] & 0xff; - int b3 = rawDataBytes[i+3] & 0xff; + int b1 = rawDataBytes[i + 1] & 0xff; + int b2 = rawDataBytes[i + 2] & 0xff; + int b3 = rawDataBytes[i + 3] & 0xff; int x = (b3 | b2 << 8 | b1 << 16 | b0 << 24); //int y = (rawDataBytes[i+2] & 0xff) | (rawDataBytes[i+3] << 8); //int z = (rawDataBytes[i+4] & 0xff) | (rawDataBytes[i+5] << 8); //Log.v(TAG,"x="+x+", y="+y+", z="+z); - Log.v(TAG,"b0="+b0+", b1="+b1+", b2="+b2+", b3="+b3+", x="+x); + Log.v(TAG, "b0=" + b0 + ", b1=" + b1 + ", b2=" + b2 + ", b3=" + b3 + ", x=" + x); if (nRawData < MAX_RAW_DATA) { - rawData[nRawData] = (int)Math.sqrt(x); + rawData[nRawData] = (int) Math.sqrt(x); } else { Log.i(TAG, "WARNING - rawData Buffer Full"); } @@ -461,7 +460,7 @@ public class SdDataSourcePebble extends SdDataSource { // } else { // Log.i(TAG, "WARNING - rawData Buffer Full"); // } - // } + // } } } @@ -498,7 +497,7 @@ public class SdDataSourcePebble extends SdDataSource { // first close the watch app if it is running. PebbleKit.closeAppOnPebble(mContext, SD_UUID); Log.v(TAG, "startWatchApp() - starting watch app after 5 seconds delay..."); - // Wait 5 seconds then start the app. + // Wait 5 seconds then start the app. Timer appStartTimer = new Timer(); appStartTimer.schedule(new TimerTask() { @Override @@ -727,7 +726,7 @@ public class SdDataSourcePebble extends SdDataSource { * ignored! */ private void analyseRawData() { - Log.v(TAG,"analyserawData()"); + Log.v(TAG, "analyserawData()"); //DoubleFFT_1D fft = new DoubleFFT_1D(MAX_RAW_DATA); //fft.realForward(rawData); // FIXME - rawData should really be a circular buffer. @@ -774,7 +773,6 @@ public class SdDataSourcePebble extends SdDataSource { } - } diff --git a/app/src/main/java/uk/org/openseizuredetector/SdDataSourcePhone.java b/app/src/main/java/uk/org/openseizuredetector/SdDataSourcePhone.java index a741585..0550c18 100644 --- a/app/src/main/java/uk/org/openseizuredetector/SdDataSourcePhone.java +++ b/app/src/main/java/uk/org/openseizuredetector/SdDataSourcePhone.java @@ -79,7 +79,7 @@ public class SdDataSourcePhone extends SdDataSource implements SensorEventListen mUtil.writeToSysLogFile("SdDataSourcePhone.start()"); mSensorManager = (SensorManager) mContext.getSystemService(Context.SENSOR_SERVICE); mSensor = mSensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER); - mSensorManager.registerListener(this, mSensor , SensorManager.SENSOR_DELAY_GAME); + mSensorManager.registerListener(this, mSensor, SensorManager.SENSOR_DELAY_GAME); super.start(); } @@ -95,22 +95,19 @@ public class SdDataSourcePhone extends SdDataSource implements SensorEventListen } - - - @Override public void onSensorChanged(SensorEvent event) { if (event.sensor.getType() == Sensor.TYPE_ACCELEROMETER) { // we initially start in mMode=0, which calculates the sample frequency returned by the sensor, then enters mMode=1, which is normal operation. if (mMode == 0) { - if (mStartEvent==null) { - Log.v(TAG,"onSensorChanged(): mMode=0 - Starting Sample Rate Check - mNSamp = "+mSdData.mNsamp); - Log.v(TAG,"onSensorChanged(): saving initial event data"); + if (mStartEvent == null) { + Log.v(TAG, "onSensorChanged(): mMode=0 - Starting Sample Rate Check - mNSamp = " + mSdData.mNsamp); + Log.v(TAG, "onSensorChanged(): saving initial event data"); mStartEvent = event; mStartTs = event.timestamp; mSdData.mNsamp = 0; } else { - mSdData.mNsamp ++; + mSdData.mNsamp++; } Log.v(TAG, "onSensorChanged - mMode=" + mMode + " mNSamp=" + mSdData.mNsamp); if (mSdData.mNsamp >= mSdData.rawData.length) { @@ -179,12 +176,10 @@ public class SdDataSourcePhone extends SdDataSource implements SensorEventListen @Override public void onAccuracyChanged(Sensor sensor, int accuracy) { - Log.v(TAG,"onAccuracyChanged()"); + Log.v(TAG, "onAccuracyChanged()"); } - - } diff --git a/app/src/main/java/uk/org/openseizuredetector/SdServer.java b/app/src/main/java/uk/org/openseizuredetector/SdServer.java index 2d7b46f..44bdb49 100644 --- a/app/src/main/java/uk/org/openseizuredetector/SdServer.java +++ b/app/src/main/java/uk/org/openseizuredetector/SdServer.java @@ -260,7 +260,7 @@ public class SdServer extends Service implements SdDataReceiver { Log.v(TAG, "onStartCommand() - calling updatePrefs()"); updatePrefs(); - Log.v(TAG, "onStartCommand: Datasource =" + mSdDataSourceName + ", phoneAppVersion="+mUtil.getAppVersionName()); + Log.v(TAG, "onStartCommand: Datasource =" + mSdDataSourceName + ", phoneAppVersion=" + mUtil.getAppVersionName()); mSdData.dataSourceName = mSdDataSourceName; mSdData.phoneAppVersion = mUtil.getAppVersionName(); switch (mSdDataSourceName) { @@ -278,7 +278,7 @@ public class SdServer extends Service implements SdDataReceiver { Log.v(TAG, "Selecting Network DataSource"); mUtil.writeToSysLogFile("SdServer.onStartCommand() - creating SdDataSourceNetwork"); mSdDataSource = new SdDataSourceNetwork(this.getApplicationContext(), mHandler, this); - Log.i(TAG,"Disabling remote logging when using network data source"); + Log.i(TAG, "Disabling remote logging when using network data source"); mLogDataRemote = false; break; case "Garmin": @@ -306,7 +306,7 @@ public class SdServer extends Service implements SdDataReceiver { // Create our log manager. mLm = new LogManager(this, mLogDataRemote, mLogDataRemoteMobile, mAuthToken, mEventDuration, - mRemoteLogPeriod, mLogNDA ,mAutoPruneDb, mDataRetentionPeriod, mSdData); + mRemoteLogPeriod, mLogNDA, mAutoPruneDb, mDataRetentionPeriod, mSdData); if (mSMSAlarm) { Log.v(TAG, "Creating LocationFinder"); @@ -316,7 +316,6 @@ public class SdServer extends Service implements SdDataReceiver { mSdDataSource.start(); - // Record last time we sent an SMS so we can limit rate of SMS // sending to one per minute. We set it to one minute ago (60000 milliseconds) mSMSTime = new Time(Time.getCurrentTimezone()); @@ -478,7 +477,7 @@ public class SdServer extends Service implements SdDataReceiver { Uri soundUri = null; if ((alarmLevel == mCurrentNotificationAlarmLevel) && (isNotificationShown(NOTIFICATION_ID))) { - Log.v(TAG,"showNotification - notification already shown at specified alarm level - not doing anything"); + Log.v(TAG, "showNotification - notification already shown at specified alarm level - not doing anything"); return; } Log.v(TAG, "showNotification() - alarmLevel=" + alarmLevel); @@ -586,7 +585,7 @@ public class SdServer extends Service implements SdDataReceiver { } } else { mUtil.showToast("OpenSeizureDetector: showMainActvity Failed to Display Activity"); - Log.e(TAG,"OpenSeizureDetector: showMainActvity Failed to Display Activity"); + Log.e(TAG, "OpenSeizureDetector: showMainActvity Failed to Display Activity"); } } @@ -1345,7 +1344,7 @@ public class SdServer extends Service implements SdDataReceiver { Log.i(TAG, "SmsTimer.onFinish() - Last Location is Null so sending first SMS without location."); } } else { - Log.e(TAG,"SmsTimer.onFinish - mLocationFinder is null - this should not happen!"); + Log.e(TAG, "SmsTimer.onFinish - mLocationFinder is null - this should not happen!"); mUtil.showToast(getString(R.string.mLocationFinder_is_null_msg)); } Log.i(TAG, "SmsTimer.onFinish() - Sending to " + mSMSNumbers.length + " Numbers"); @@ -1373,7 +1372,6 @@ public class SdServer extends Service implements SdDataReceiver { /** * onSdLocationReceived - called with the best estimate location after mLocationReceiver times out. - * */ private void sendSMS(String phoneNo, String msgStr) { Log.i(TAG, "sendSMS() - Sending to " + phoneNo); @@ -1618,11 +1616,11 @@ public class SdServer extends Service implements SdDataReceiver { Log.v(TAG, "checkEvents() - haveUnvalidatedEvent = " + haveUnvalidatedEvent); if (haveUnvalidatedEvent) { - Log.v(TAG,"checkEvents() - showing event notification and cancelling datashare notification."); + Log.v(TAG, "checkEvents() - showing event notification and cancelling datashare notification."); showEventNotification(); mNM.cancel(DATASHARE_NOTIFICATION_ID); } else { - Log.v(TAG,"checkEvents() - cancelling event and datashare notifications"); + Log.v(TAG, "checkEvents() - cancelling event and datashare notifications"); mNM.cancel(EVENT_NOTIFICATION_ID); mNM.cancel(DATASHARE_NOTIFICATION_ID); } @@ -1678,7 +1676,7 @@ public class SdServer extends Service implements SdDataReceiver { Uri soundUri = null; if (isNotificationShown(EVENT_NOTIFICATION_ID)) { - Log.v(TAG,"showEventNotification() - notification is already shown, so not doing anything"); + Log.v(TAG, "showEventNotification() - notification is already shown, so not doing anything"); return; } @@ -1727,7 +1725,7 @@ public class SdServer extends Service implements SdDataReceiver { Uri soundUri = null; if (isNotificationShown(DATASHARE_NOTIFICATION_ID)) { - Log.v(TAG,"showDataShareNotification() - notification is already shown, so not doing anything"); + Log.v(TAG, "showDataShareNotification() - notification is already shown, so not doing anything"); return; } @@ -1781,6 +1779,7 @@ public class SdServer extends Service implements SdDataReceiver { /** * isNotificationShown - returns true if the specified notificationID is shown, otherwise returns false. + * * @param notificationId - Notification ID to check * @return true if the specified notification is displayed, otherwise false. */ @@ -1789,10 +1788,10 @@ public class SdServer extends Service implements SdDataReceiver { StatusBarNotification[] notifications = mNotificationManager.getActiveNotifications(); for (StatusBarNotification notification : notifications) { if (notification.getId() == notificationId) { - return(true); + return (true); } } - return(false); + return (false); } } diff --git a/app/src/main/java/uk/org/openseizuredetector/SdServiceConnection.java b/app/src/main/java/uk/org/openseizuredetector/SdServiceConnection.java index 93911e6..633df8f 100644 --- a/app/src/main/java/uk/org/openseizuredetector/SdServiceConnection.java +++ b/app/src/main/java/uk/org/openseizuredetector/SdServiceConnection.java @@ -31,7 +31,6 @@ import android.os.IBinder; import android.util.Log; - /** * Defines callbacks for service binding, passed to bindService() */ @@ -68,11 +67,12 @@ public class SdServiceConnection implements ServiceConnection { /** * Check if the service has received seizure detector data. + * * @return true if data has been received. */ public boolean hasSdData() { - if (mSdServer!=null) { - if (mSdServer.mSdData!=null) { + if (mSdServer != null) { + if (mSdServer.mSdData != null) { return mSdServer.mSdData.haveData; } } @@ -81,11 +81,12 @@ public class SdServiceConnection implements ServiceConnection { /** * Check if the service has received seizure detector settings. + * * @return true if settings have been received. */ public boolean hasSdSettings() { - if (mSdServer!=null) { - if (mSdServer.mSdData!=null) { + if (mSdServer != null) { + if (mSdServer.mSdData != null) { if (mSdServer.mSdData.haveSettings) { return true; } @@ -96,11 +97,12 @@ public class SdServiceConnection implements ServiceConnection { /** * Check if the pebble watch is connected to the server device via bluetooth. + * * @return true if watch connected. */ public boolean watchConnected() { - if (mSdServer!=null) { - if (mSdServer.mSdData!=null) { + if (mSdServer != null) { + if (mSdServer.mSdData != null) { if (mSdServer.mSdData.watchConnected) { return true; } @@ -111,11 +113,12 @@ public class SdServiceConnection implements ServiceConnection { /** * 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 != null) { + if (mSdServer.mSdData != null) { if (mSdServer.mSdData.watchAppRunning) { return true; } diff --git a/app/src/main/java/uk/org/openseizuredetector/SdWebServer.java b/app/src/main/java/uk/org/openseizuredetector/SdWebServer.java index 720eac8..d777932 100644 --- a/app/src/main/java/uk/org/openseizuredetector/SdWebServer.java +++ b/app/src/main/java/uk/org/openseizuredetector/SdWebServer.java @@ -114,7 +114,7 @@ public class SdWebServer extends NanoHTTPD { answer = mSdServer.mSdDataSource.updateFromJSON(files.get("postData")); } } else { - Log.i(TAG,"Web server received data, but datasource is not set to 'Garmin' - Ignoring"); + Log.i(TAG, "Web server received data, but datasource is not set to 'Garmin' - Ignoring"); mUtil.showToast("Web server received data, but datasource is not set to 'Garmin' - Ignoring"); } break; @@ -152,10 +152,10 @@ public class SdWebServer extends NanoHTTPD { Log.v(TAG, " files=" + files.toString()); // Send the data to the SdDataSource so the app can pick it up. if (parameters != null) { - Log.v(TAG,"passing parameters to data source"); + Log.v(TAG, "passing parameters to data source"); answer = mSdServer.mSdDataSource.updateFromJSON(parameters.get("dataObj").toString()); } else { - Log.v(TAG,"Passing postData to data source"); + Log.v(TAG, "Passing postData to data source"); answer = mSdServer.mSdDataSource.updateFromJSON(files.get("postData")); } //mSdServer.mSdDataSource.updateFromJSON(parameters.toString()); @@ -209,12 +209,12 @@ public class SdWebServer extends NanoHTTPD { } else { Log.v(TAG, "WebServer.serve() - Unknown uri -" + uri); - answer = "{'msg' : 'Unknown URI: "+uri+"'}"; + answer = "{'msg' : 'Unknown URI: " + uri + "'}"; } } res = new NanoHTTPD.Response(answer); res.setMimeType(responseMimeType); - Log.v(TAG,"WebServer.serve() - returning "+res.getData()+", mime="+res.getMimeType()+", status="+res.getStatus()); + Log.v(TAG, "WebServer.serve() - returning " + res.getData() + ", mime=" + res.getMimeType() + ", status=" + res.getStatus()); return (res); } @@ -248,13 +248,13 @@ public class SdWebServer extends NanoHTTPD { try { JSONObject jsonObj = new JSONObject(); File[] fileList = mUtil.getDataFilesList(); - Log.v(TAG, "serveLogFile(): fileList=" + fileList.toString()+", length="+fileList.length); + Log.v(TAG, "serveLogFile(): fileList=" + fileList.toString() + ", length=" + fileList.length); JSONArray arr = new JSONArray(); - for (int i = 0; i < fileList.length; i++) { - Log.v(TAG, "serveLogFile(): file[" + i + "]=" + fileList[i]); - arr.put(fileList[i].getName()); - } - jsonObj.put("logFileList", arr); + for (int i = 0; i < fileList.length; i++) { + Log.v(TAG, "serveLogFile(): file[" + i + "]=" + fileList[i]); + arr.put(fileList[i].getName()); + } + jsonObj.put("logFileList", arr); res = new NanoHTTPD.Response(NanoHTTPD.Response.Status.OK, "text/html", jsonObj.toString()); } catch (Exception ex) { diff --git a/app/src/main/java/uk/org/openseizuredetector/StartupActivity.java b/app/src/main/java/uk/org/openseizuredetector/StartupActivity.java index 9467b7c..ba07a03 100644 --- a/app/src/main/java/uk/org/openseizuredetector/StartupActivity.java +++ b/app/src/main/java/uk/org/openseizuredetector/StartupActivity.java @@ -113,8 +113,6 @@ public class StartupActivity extends AppCompatActivity { }; - - @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); @@ -205,17 +203,17 @@ public class StartupActivity extends AppCompatActivity { if (mUtil.isServerRunning()) { - Log.i(TAG, "onStart() - server running - stopping it - isServerRunning="+mUtil.isServerRunning()); + Log.i(TAG, "onStart() - server running - stopping it - isServerRunning=" + mUtil.isServerRunning()); mUtil.writeToSysLogFile("StartupActivity.onStart() - server already running - stopping it."); mUtil.stopServer(); } else { - Log.i(TAG, "onStart() - server not running - isServerRunning="+mUtil.isServerRunning()); + Log.i(TAG, "onStart() - server not running - isServerRunning=" + mUtil.isServerRunning()); } // Wait 0.1 second to give the server chance to shutdown in case we have just shut it down below, then start it mHandler.postDelayed(new Runnable() { public void run() { - mUtil.writeToSysLogFile("StartupActivity.onStart() - starting server after delay - isServerRunning="+mUtil.isServerRunning()); - Log.i(TAG, "onStart() - starting server after delay -isServerRunning="+mUtil.isServerRunning()); + mUtil.writeToSysLogFile("StartupActivity.onStart() - starting server after delay - isServerRunning=" + mUtil.isServerRunning()); + Log.i(TAG, "onStart() - starting server after delay -isServerRunning=" + mUtil.isServerRunning()); mUtil.startServer(); // Bind to the service. Log.i(TAG, "onStart() - binding to server"); @@ -232,7 +230,7 @@ public class StartupActivity extends AppCompatActivity { } else { boolean preventBatteryOptWarning = SP.getBoolean("PreventBatteryOptWarning", false); if (preventBatteryOptWarning) { - Log.i(TAG,"PreventBatteryOptWarning is true, so not displaying battery optimisation dialog"); + Log.i(TAG, "PreventBatteryOptWarning is true, so not displaying battery optimisation dialog"); } else { Log.e(TAG, "Power Management Problem - not ignoring Battery Optimisations"); //mUtil.showToast("WARNING - Phone is Optimising OpenSeizureDetector Battery Usage - this is likely to prevent it working correctly when running on battery!"); @@ -302,7 +300,7 @@ public class StartupActivity extends AppCompatActivity { pb = (ProgressBar) findViewById(R.id.progressBar1); if (arePermissionsOK()) { if (smsAlarmsActive && !areSMSPermissions1OK()) { - Log.i(TAG,"SMS permissions NOT OK"); + Log.i(TAG, "SMS permissions NOT OK"); tv.setText(getString(R.string.SmsPermissionWarning)); tv.setBackgroundColor(alarmColour); tv.setTextColor(alarmTextColour); @@ -311,14 +309,14 @@ public class StartupActivity extends AppCompatActivity { requestSMSPermissions(); allOk = false; } else if (smsAlarmsActive && !areLocationPermissions1OK()) { - Log.i(TAG,"Location permissions NOT OK"); + Log.i(TAG, "Location permissions NOT OK"); tv.setText(getString(R.string.SmsPermissionWarning)); tv.setBackgroundColor(alarmColour); tv.setTextColor(alarmTextColour); requestLocationPermissions1(); allOk = false; } else if (smsAlarmsActive && !areLocationPermissions2OK()) { - Log.i(TAG,"Location permissions2 NOT OK"); + Log.i(TAG, "Location permissions2 NOT OK"); tv.setText(getString(R.string.SmsPermissionWarning)); tv.setBackgroundColor(alarmColour); tv.setTextColor(alarmTextColour); @@ -479,10 +477,10 @@ public class StartupActivity extends AppCompatActivity { } } - /** - * checkFirstRun - checks to see if this is the first run of the app after installation or upgrade. - * if it is, the relevant dialog message is displayed. If not, the routine just exists so start-up can continue. - */ + /** + * checkFirstRun - checks to see if this is the first run of the app after installation or upgrade. + * if it is, the relevant dialog message is displayed. If not, the routine just exists so start-up can continue. + */ public void checkFirstRun() { String storedVersionName = ""; String versionName; @@ -640,7 +638,7 @@ public class StartupActivity extends AppCompatActivity { for (int i = 0; i < SMS_PERMISSIONS_1.length; i++) { if (ContextCompat.checkSelfPermission(this, SMS_PERMISSIONS_1[i]) != PackageManager.PERMISSION_GRANTED) { - Log.i(TAG, "areSMSPermissions1OK: "+SMS_PERMISSIONS_1[i] + " Permission Not Granted"); + Log.i(TAG, "areSMSPermissions1OK: " + SMS_PERMISSIONS_1[i] + " Permission Not Granted"); allOk = false; } } @@ -663,7 +661,7 @@ public class StartupActivity extends AppCompatActivity { public boolean areLocationPermissions2OK() { boolean allOk = true; - Log.v(TAG, "areSMSPermissions2OK() - SDK="+android.os.Build.VERSION.SDK_INT); + Log.v(TAG, "areSMSPermissions2OK() - SDK=" + android.os.Build.VERSION.SDK_INT); if (android.os.Build.VERSION.SDK_INT < 29) { Log.d(TAG, "areLocationPermission2OK() - SDK <29 (Android 10) so permission not required"); allOk = true; @@ -712,7 +710,7 @@ public class StartupActivity extends AppCompatActivity { .setPositiveButton(getString(R.string.okBtnTxt), new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { dialog.cancel(); - Log.i(TAG,"requestSMSPermissions(): Launching ActivityCompat.requestPermissions()"); + Log.i(TAG, "requestSMSPermissions(): Launching ActivityCompat.requestPermissions()"); ActivityCompat.requestPermissions(StartupActivity.this, SMS_PERMISSIONS_1, 45); @@ -749,9 +747,9 @@ public class StartupActivity extends AppCompatActivity { } }) .setNegativeButton(getString(R.string.cancelBtnTxt), new DialogInterface.OnClickListener() { - public void onClick(DialogInterface dialog, int id) { - dialog.cancel(); - } + public void onClick(DialogInterface dialog, int id) { + dialog.cancel(); + } }) .create().show(); } @@ -773,7 +771,7 @@ public class StartupActivity extends AppCompatActivity { .setPositiveButton(getString(R.string.okBtnTxt), new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { dialog.cancel(); - Log.i(TAG,"requestSMSPermissions(): Launching ActivityCompat.requestPermissions()"); + Log.i(TAG, "requestSMSPermissions(): Launching ActivityCompat.requestPermissions()"); ActivityCompat.requestPermissions(StartupActivity.this, LOCATION_PERMISSIONS_2, 44); diff --git a/app/src/main/java/uk/org/openseizuredetector/WebApiConnection.java b/app/src/main/java/uk/org/openseizuredetector/WebApiConnection.java index 38dc627..655d533 100644 --- a/app/src/main/java/uk/org/openseizuredetector/WebApiConnection.java +++ b/app/src/main/java/uk/org/openseizuredetector/WebApiConnection.java @@ -139,19 +139,20 @@ public abstract class WebApiConnection { /** * Mark all of the events with IDs contained in eventList as the specified type and subtype. - * @param eventList list of String IDs of the events to mark as unknown. + * + * @param eventList list of String IDs of the events to mark as unknown. * @param typeStr * @param subTypeStr * @return true if request sent successfully or false. */ - private boolean markEventsAsTypeSubType(ArrayListeventList, String typeStr, String subTypeStr) { - if (eventList.size()>0) { - Log.i(TAG,"markEventsAsTypeSubtype - eventList.size()="+eventList.size()); - Log.i(TAG,"markEventsAsSypeSubtype - eventList(0) = "+eventList.get(0)); + private boolean markEventsAsTypeSubType(ArrayList eventList, String typeStr, String subTypeStr) { + if (eventList.size() > 0) { + Log.i(TAG, "markEventsAsTypeSubtype - eventList.size()=" + eventList.size()); + Log.i(TAG, "markEventsAsSypeSubtype - eventList(0) = " + eventList.get(0)); getEvent(eventList.get(0), new WebApiConnection.JSONObjectCallback() { @Override public void accept(JSONObject eventObj) { - Log.v(TAG, "markEventsAsTypeSubtype.getEvent.callback: "+eventObj); + Log.v(TAG, "markEventsAsTypeSubtype.getEvent.callback: " + eventObj); if (eventObj != null) { Log.v(TAG, "markEventsAsTypeSubtype.getEvent.callback: eventObj=" + eventObj.toString()); try { @@ -161,7 +162,7 @@ public abstract class WebApiConnection { if (notesStr == null) notesStr = new String(""); notesStr = notesStr + " bulk type/subtype set"; eventObj.put("desc", notesStr); - updateEvent(eventObj,new WebApiConnection.JSONObjectCallback() { + updateEvent(eventObj, new WebApiConnection.JSONObjectCallback() { @Override public void accept(JSONObject eventObj) { if (eventObj != null) { @@ -176,7 +177,7 @@ public abstract class WebApiConnection { } }); } catch (JSONException e) { - Log.e(TAG,"markEventsAsTypeSubtype.getEvent.callback: Error editing eventObj"); + Log.e(TAG, "markEventsAsTypeSubtype.getEvent.callback: Error editing eventObj"); mUtil.showToast("markEventsAsTypeSubtype.getEvent.callback: Error editing eventObj"); } } else { @@ -186,11 +187,11 @@ public abstract class WebApiConnection { } }); } else { - Log.i(TAG,"markEventsAsTypeSubtype(): No more events to Modify"); + Log.i(TAG, "markEventsAsTypeSubtype(): No more events to Modify"); mUtil.showToast("No more unvalidated events to modify."); } - return(true); + return (true); } /** @@ -240,6 +241,7 @@ public abstract class WebApiConnection { markUnverifiedEventsAsTypeSubtype("Unknown", ""); return true; } + public boolean markUnverifiedEventsAsFalseAlarm() { markUnverifiedEventsAsTypeSubtype("False Alarm", ""); return true; diff --git a/app/src/main/java/uk/org/openseizuredetector/WebApiConnection_firebase.java b/app/src/main/java/uk/org/openseizuredetector/WebApiConnection_firebase.java index 5c3fdc0..0cc0a6c 100644 --- a/app/src/main/java/uk/org/openseizuredetector/WebApiConnection_firebase.java +++ b/app/src/main/java/uk/org/openseizuredetector/WebApiConnection_firebase.java @@ -95,7 +95,7 @@ public class WebApiConnection_firebase extends WebApiConnection { } else { try { JSONObject retObj = new JSONObject(); - retObj.put("id",auth.getCurrentUser().getUid()); + retObj.put("id", auth.getCurrentUser().getUid()); retObj.put("username", auth.getCurrentUser().getDisplayName()); retObj.put("email", auth.getCurrentUser().getEmail()); callback.accept(retObj); @@ -121,7 +121,7 @@ public class WebApiConnection_firebase extends WebApiConnection { // passes the newly created documentId to function callback on successful completion, or null on error. public boolean createEvent(final int osdAlarmState, final Date eventDate, final String type, final String subType, final String eventDesc, final String dataJSON, StringCallback callback) { - // FIXME - save type, subtype, eventDesc and dataJSON + // FIXME - save type, subtype, eventDesc and dataJSON Log.v(TAG, "createEvent()"); String userId = null; @@ -424,7 +424,7 @@ public class WebApiConnection_firebase extends WebApiConnection { } public boolean getCnnModelInfo(JSONObjectCallback callback) { - Log.w(TAG,"getCnnModelInfo() - FIXME - not implemented yet!"); + Log.w(TAG, "getCnnModelInfo() - FIXME - not implemented yet!"); return false; } diff --git a/app/src/main/java/uk/org/openseizuredetector/WebApiConnection_osdapi.java b/app/src/main/java/uk/org/openseizuredetector/WebApiConnection_osdapi.java index d027336..b7cfc02 100644 --- a/app/src/main/java/uk/org/openseizuredetector/WebApiConnection_osdapi.java +++ b/app/src/main/java/uk/org/openseizuredetector/WebApiConnection_osdapi.java @@ -41,7 +41,7 @@ public class WebApiConnection_osdapi extends WebApiConnection { public void close() { super.close(); - Log.i(TAG,"stop()"); + Log.i(TAG, "stop()"); mQueue.stop(); } @@ -110,8 +110,6 @@ public class WebApiConnection_osdapi extends WebApiConnection { } - - public boolean isLoggedIn() { String authToken = getStoredToken(); Log.v(TAG, "isLoggedIn(): token=" + authToken); @@ -119,7 +117,7 @@ public class WebApiConnection_osdapi extends WebApiConnection { Log.v(TAG, "isLogged in - not logged in"); return (false); } else { - Log.v(TAG,"isLoggedIn - logged in ok"); + Log.v(TAG, "isLoggedIn - logged in ok"); return (true); } @@ -315,7 +313,7 @@ public class WebApiConnection_osdapi extends WebApiConnection { } else { Log.e(TAG, "getEvents(): Error: - request returned null networkResponse"); } - } else{ + } else { Log.e(TAG, "getEvents(): Error: - request returned null response"); } callback.accept(null); @@ -517,6 +515,7 @@ public class WebApiConnection_osdapi extends WebApiConnection { /** * Retieve the user profile of the authenticated user from the server, and return it to the callback function. + * * @param callback - function to be called with a JSONObject as a parameter that contains the user profile data. * @return true if request sent successfully, or else false. */ @@ -572,8 +571,6 @@ public class WebApiConnection_osdapi extends WebApiConnection { } - - /** * Retrieve the file containing the standard event types from the server. * Calls the specified callback function, passing a JSONObject as a parameter when the data has been received and parsed. @@ -680,11 +677,10 @@ public class WebApiConnection_osdapi extends WebApiConnection { } - - /** * Retrieve a trivial file from the server to check we have a good server connection. - * sets mServerConnectionOk. + * sets mServerConnectionOk. + * * @return true if request sent successfully or else false. */ public boolean checkServerConnection() { @@ -714,7 +710,7 @@ public class WebApiConnection_osdapi extends WebApiConnection { } public boolean getCnnModelInfo(JSONObjectCallback callback) { - Log.w(TAG,"getCnnModelInfo() - FIXME - not implemented yet!"); + Log.w(TAG, "getCnnModelInfo() - FIXME - not implemented yet!"); return false; }