diff --git a/app/build.gradle b/app/build.gradle index 092ad46..0cd1406 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -79,6 +79,7 @@ dependencies { //androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1' //androidTestImplementation 'androidx.test.espresso:espresso-intents:3.1.1' implementation 'com.techyourchance:threadposter:1.0.1' + implementation 'com.google.android.material:material' } repositories { diff --git a/app/src/main/java/uk/org/openseizuredetector/FragmentCommon.java b/app/src/main/java/uk/org/openseizuredetector/FragmentCommon.java index 703527f..c3a44c9 100644 --- a/app/src/main/java/uk/org/openseizuredetector/FragmentCommon.java +++ b/app/src/main/java/uk/org/openseizuredetector/FragmentCommon.java @@ -8,10 +8,9 @@ import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.Button; -import android.widget.LinearLayout; import android.widget.TextView; -public class FragmentCommon extends FragmentSdDataViewer { +public class FragmentCommon extends FragmentOsdBaseClass { String TAG = "FragmentCommon"; public FragmentCommon() { // Required empty public constructor @@ -80,7 +79,7 @@ public class FragmentCommon extends FragmentSdDataViewer { @Override protected void updateUi() { - Log.d(TAG,"updateUi()"); + //Log.d(TAG,"updateUi()"); TextView tv; tv = (TextView)mRootView.findViewById(R.id.fragment_common_tv1); if (mConnection.mBound) { @@ -113,6 +112,39 @@ public class FragmentCommon extends FragmentSdDataViewer { tv.setBackgroundColor(okColour); tv.setTextColor(okTextColour); } + + tv = (TextView) mRootView.findViewById(R.id.alarmTv); + if ((mConnection.mSdServer.mSdData.alarmState == 0) + && !mConnection.mSdServer.mSdData.alarmStanding + && !mConnection.mSdServer.mSdData.fallAlarmStanding) { + tv.setText(getString(R.string.okBtnTxt)); + tv.setBackgroundColor(okColour); + tv.setTextColor(okTextColour); + } + if ((mConnection.mSdServer.mSdData.alarmState == 1) + && !mConnection.mSdServer.mSdData.alarmStanding + && !mConnection.mSdServer.mSdData.fallAlarmStanding) { + tv.setText(R.string.Warning); + tv.setBackgroundColor(warnColour); + tv.setTextColor(warnTextColour); + } + if (mConnection.mSdServer.mSdData.alarmState == 6) { + tv.setText(R.string.Mute); + tv.setBackgroundColor(warnColour); + tv.setTextColor(warnTextColour); + } + if (mConnection.mSdServer.mSdData.alarmStanding) { + tv.setText(R.string.Alarm); + tv.setBackgroundColor(alarmColour); + tv.setTextColor(alarmTextColour); + } + if (mConnection.mSdServer.mSdData.fallAlarmStanding) { + tv.setText(R.string.Fall); + tv.setBackgroundColor(alarmColour); + tv.setTextColor(alarmTextColour); + } + + tv = (TextView) mRootView.findViewById(R.id.algsTv); tv.setText("Algorithms"); tv.setBackgroundColor(okColour); diff --git a/app/src/main/java/uk/org/openseizuredetector/FragmentDataSharing.java b/app/src/main/java/uk/org/openseizuredetector/FragmentDataSharing.java index aa0f320..43c6ee8 100644 --- a/app/src/main/java/uk/org/openseizuredetector/FragmentDataSharing.java +++ b/app/src/main/java/uk/org/openseizuredetector/FragmentDataSharing.java @@ -7,7 +7,7 @@ import android.view.View; import android.view.ViewGroup; import android.widget.TextView; -public class FragmentDataSharing extends FragmentSdDataViewer { +public class FragmentDataSharing extends FragmentOsdBaseClass { String TAG = "FragmentDataSharing"; public FragmentDataSharing() { // Required empty public constructor diff --git a/app/src/main/java/uk/org/openseizuredetector/FragmentHrAlg.java b/app/src/main/java/uk/org/openseizuredetector/FragmentHrAlg.java index 3c876e6..f81b662 100644 --- a/app/src/main/java/uk/org/openseizuredetector/FragmentHrAlg.java +++ b/app/src/main/java/uk/org/openseizuredetector/FragmentHrAlg.java @@ -1,27 +1,13 @@ package uk.org.openseizuredetector; -import android.graphics.Color; -import android.graphics.drawable.Drawable; import android.os.Bundle; import android.util.Log; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; -import android.widget.ProgressBar; import android.widget.TextView; -import com.github.mikephil.charting.charts.BarChart; -import com.github.mikephil.charting.components.XAxis; -import com.github.mikephil.charting.components.YAxis; -import com.github.mikephil.charting.data.BarData; -import com.github.mikephil.charting.data.BarDataSet; -import com.github.mikephil.charting.data.BarEntry; -import com.github.mikephil.charting.utils.ValueFormatter; - -import java.text.DecimalFormat; -import java.util.ArrayList; - -public class FragmentHrAlg extends FragmentSdDataViewer { +public class FragmentHrAlg extends FragmentOsdBaseClass { String TAG = "FragmentOsdAlg"; public FragmentHrAlg() { // Required empty public constructor diff --git a/app/src/main/java/uk/org/openseizuredetector/FragmentMlAlg.java b/app/src/main/java/uk/org/openseizuredetector/FragmentMlAlg.java index 228a6f5..0d982a5 100644 --- a/app/src/main/java/uk/org/openseizuredetector/FragmentMlAlg.java +++ b/app/src/main/java/uk/org/openseizuredetector/FragmentMlAlg.java @@ -7,7 +7,7 @@ import android.view.View; import android.view.ViewGroup; import android.widget.TextView; -public class FragmentMlAlg extends FragmentSdDataViewer { +public class FragmentMlAlg extends FragmentOsdBaseClass { String TAG = "FragmentMlAlg"; public FragmentMlAlg() { // Required empty public constructor diff --git a/app/src/main/java/uk/org/openseizuredetector/FragmentOsdAlg.java b/app/src/main/java/uk/org/openseizuredetector/FragmentOsdAlg.java index efaf2ad..4965f0f 100644 --- a/app/src/main/java/uk/org/openseizuredetector/FragmentOsdAlg.java +++ b/app/src/main/java/uk/org/openseizuredetector/FragmentOsdAlg.java @@ -10,8 +10,6 @@ import android.view.ViewGroup; import android.widget.ProgressBar; import android.widget.TextView; -import androidx.core.content.res.ResourcesCompat; - import com.github.mikephil.charting.charts.BarChart; import com.github.mikephil.charting.components.XAxis; import com.github.mikephil.charting.components.YAxis; @@ -23,7 +21,7 @@ import com.github.mikephil.charting.utils.ValueFormatter; import java.text.DecimalFormat; import java.util.ArrayList; -public class FragmentOsdAlg extends FragmentSdDataViewer { +public class FragmentOsdAlg extends FragmentOsdBaseClass { String TAG = "FragmentOsdAlg"; public FragmentOsdAlg() { // Required empty public constructor @@ -44,7 +42,7 @@ public class FragmentOsdAlg extends FragmentSdDataViewer { @Override protected void updateUi() { - Log.d(TAG,"updateUi()"); + //Log.d(TAG,"updateUi()"); TextView tv; tv = (TextView)mRootView.findViewById(R.id.fragment_osdalg_tv1); if (mConnection.mBound) { diff --git a/app/src/main/java/uk/org/openseizuredetector/FragmentSdDataViewer.java b/app/src/main/java/uk/org/openseizuredetector/FragmentOsdBaseClass.java similarity index 96% rename from app/src/main/java/uk/org/openseizuredetector/FragmentSdDataViewer.java rename to app/src/main/java/uk/org/openseizuredetector/FragmentOsdBaseClass.java index 6f87320..a71a35a 100644 --- a/app/src/main/java/uk/org/openseizuredetector/FragmentSdDataViewer.java +++ b/app/src/main/java/uk/org/openseizuredetector/FragmentOsdBaseClass.java @@ -17,8 +17,8 @@ import java.util.Timer; import java.util.TimerTask; -public class FragmentSdDataViewer extends Fragment { - String TAG = "FragmentSdDataViewer"; +public class FragmentOsdBaseClass extends Fragment { + String TAG = "FragmentOsdBaseClass"; Context mContext; OsdUtil mUtil; SdServiceConnection mConnection; @@ -35,7 +35,7 @@ public class FragmentSdDataViewer extends Fragment { - public FragmentSdDataViewer() { + public FragmentOsdBaseClass() { // Required empty public constructor } diff --git a/app/src/main/java/uk/org/openseizuredetector/FragmentSystem.java b/app/src/main/java/uk/org/openseizuredetector/FragmentSystem.java index 40a1093..4e2020e 100644 --- a/app/src/main/java/uk/org/openseizuredetector/FragmentSystem.java +++ b/app/src/main/java/uk/org/openseizuredetector/FragmentSystem.java @@ -6,12 +6,13 @@ import android.util.Log; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; -import android.widget.Button; import android.widget.ImageButton; import android.widget.TextView; -public class FragmentSystem extends FragmentSdDataViewer { - String TAG = "FragmentOsdAlg"; +import androidx.appcompat.widget.LinearLayoutCompat; + +public class FragmentSystem extends FragmentOsdBaseClass { + String TAG = "FragmentSystem"; public FragmentSystem() { // Required empty public constructor } @@ -53,16 +54,128 @@ public class FragmentSystem extends FragmentSdDataViewer { @Override protected void updateUi() { - Log.d(TAG,"updateUi()"); + //Log.d(TAG,"updateUi()"); TextView tv; - tv = (TextView)mRootView.findViewById(R.id.fragment_system_tv1); + + tv = (TextView)mRootView.findViewById(R.id.fragment_bound_to_server_tv); if (mConnection.mBound) { tv.setText("Bound to Server"); + tv.setTextColor(okTextColour); } else { tv.setText("****NOT BOUND TO SERVER***"); + tv.setTextColor(warnTextColour); return; } + LinearLayoutCompat ll = (LinearLayoutCompat)mRootView.findViewById(R.id.fragment_ll); + if (mUtil.isServerRunning()) { + ll.setBackgroundColor(okColour); + + tv = (TextView) mRootView.findViewById(R.id.serverStatusTv); + if (mConnection.mBound) { + if (mConnection.mSdServer.mSdDataSourceName.equals("Phone")) { + if (mConnection.mSdServer.mLogNDA) + tv.setText(getString(R.string.ServerRunningOK) + getString(R.string.DataSource) + " = " + "Phone" + "\n" + "(Demo Mode)" + "\nNDA Logging"); + else + tv.setText(getString(R.string.ServerRunningOK) + getString(R.string.DataSource) + " = " + "Phone" + "\n" + "(Demo Mode)"); + tv.setBackgroundColor(warnColour); + tv.setTextColor(warnTextColour); + } else { + if (mConnection.mSdServer.mLogNDA) + tv.setText(getString(R.string.ServerRunningOK) + getString(R.string.DataSource) + " = " + mConnection.mSdServer.mSdDataSourceName + "\nNDA Logging"); + else + tv.setText(getString(R.string.ServerRunningOK) + getString(R.string.DataSource) + " = " + mConnection.mSdServer.mSdDataSourceName); + tv.setBackgroundColor(okColour); + tv.setTextColor(okTextColour); + } + } + //Log.v(TAG,"UpdateUi() - displaying server IP address"); + tv = (TextView) mRootView.findViewById(R.id.serverIpTv); + tv.setText(getString(R.string.AccessServerAt) + " http://" + + mUtil.getLocalIpAddress() + + ":8080"); + tv.setBackgroundColor(okColour); + tv.setTextColor(okTextColour); + } else { + ll.setBackgroundColor(warnColour); + + tv = (TextView) mRootView.findViewById(R.id.serverStatusTv); + tv.setText(R.string.ServerStopped); + tv.setBackgroundColor(warnColour); + tv.setTextColor(warnTextColour); + tv = (TextView) mRootView.findViewById(R.id.serverIpTv); + tv.setText("--"); + tv.setBackgroundColor(warnColour); + tv.setTextColor(warnTextColour); + } + try { + if (mConnection.mBound) { + tv = (TextView) mRootView.findViewById(R.id.alarmTv); + if ((mConnection.mSdServer.mSdData.alarmState == 0) + && !mConnection.mSdServer.mSdData.alarmStanding + && !mConnection.mSdServer.mSdData.fallAlarmStanding) { + tv.setText(getString(R.string.okBtnTxt)); + tv.setBackgroundColor(okColour); + tv.setTextColor(okTextColour); + } + if ((mConnection.mSdServer.mSdData.alarmState == 1) + && !mConnection.mSdServer.mSdData.alarmStanding + && !mConnection.mSdServer.mSdData.fallAlarmStanding) { + tv.setText(R.string.Warning); + tv.setBackgroundColor(warnColour); + tv.setTextColor(warnTextColour); + } + if (mConnection.mSdServer.mSdData.alarmState == 6) { + tv.setText(R.string.Mute); + tv.setBackgroundColor(warnColour); + tv.setTextColor(warnTextColour); + } + if (mConnection.mSdServer.mSdData.alarmStanding) { + tv.setText(R.string.Alarm); + tv.setBackgroundColor(alarmColour); + tv.setTextColor(alarmTextColour); + } + if (mConnection.mSdServer.mSdData.fallAlarmStanding) { + tv.setText(R.string.Fall); + tv.setBackgroundColor(alarmColour); + tv.setTextColor(alarmTextColour); + } + + tv = (TextView) mRootView.findViewById(R.id.data_time_tv); + tv.setText(mConnection.mSdServer.mSdData.dataTime.format("%H:%M:%S")); + tv.setBackgroundColor(okColour); + tv.setTextColor(okTextColour); + + + tv = (TextView) mRootView.findViewById(R.id.fragment_watch_app_status_tv); + if (mConnection.mSdServer.mSdData.watchAppRunning) { + tv.setText(R.string.WatchAppOK); + tv.setBackgroundColor(okColour); + tv.setTextColor(okTextColour); + } else { + tv.setText(R.string.WatchAppNotRunning); + tv.setBackgroundColor(warnColour); + tv.setTextColor(warnTextColour); + } + tv = (TextView) mRootView.findViewById(R.id.battTv); + tv.setText(getString(R.string.WatchBatteryEquals) + String.valueOf(mConnection.mSdServer.mSdData.batteryPc) + "%"); + if (mConnection.mSdServer.mSdData.batteryPc <= 10) { + tv.setBackgroundColor(alarmColour); + tv.setTextColor(alarmTextColour); + } + if (mConnection.mSdServer.mSdData.batteryPc > 10) { + tv.setBackgroundColor(warnColour); + tv.setTextColor(warnTextColour); + } + if (mConnection.mSdServer.mSdData.batteryPc >= 20) { + tv.setBackgroundColor(okColour); + tv.setTextColor(okTextColour); + } + } + } catch (Exception e) { + Log.e(TAG, "UpdateUi: Exception - "); + e.printStackTrace(); + } } } diff --git a/app/src/main/java/uk/org/openseizuredetector/FragmentWebServer.java b/app/src/main/java/uk/org/openseizuredetector/FragmentWebServer.java index 09358bd..612785f 100644 --- a/app/src/main/java/uk/org/openseizuredetector/FragmentWebServer.java +++ b/app/src/main/java/uk/org/openseizuredetector/FragmentWebServer.java @@ -7,7 +7,7 @@ import android.view.View; import android.view.ViewGroup; import android.widget.TextView; -public class FragmentWebServer extends FragmentSdDataViewer { +public class FragmentWebServer extends FragmentOsdBaseClass { String TAG = "FragmentWebServer"; public FragmentWebServer() { // Required empty public constructor diff --git a/app/src/main/java/uk/org/openseizuredetector/MainActivity.java b/app/src/main/java/uk/org/openseizuredetector/MainActivity.java index 9ec8093..ab42708 100644 --- a/app/src/main/java/uk/org/openseizuredetector/MainActivity.java +++ b/app/src/main/java/uk/org/openseizuredetector/MainActivity.java @@ -642,7 +642,7 @@ public class MainActivity extends AppCompatActivity { tv.setTextColor(alarmTextColour); } - tv = (TextView) findViewById(R.id.pebTimeTv); + tv = (TextView) findViewById(R.id.data_time_tv); tv.setText(mConnection.mSdServer.mSdData.dataTime.format("%H:%M:%S")); tv.setBackgroundColor(okColour); tv.setTextColor(okTextColour); @@ -690,7 +690,7 @@ public class MainActivity extends AppCompatActivity { } */ - tv = (TextView) findViewById(R.id.appTv); + tv = (TextView) findViewById(R.id.fragment_watch_app_status_tv); if (mConnection.mSdServer.mSdData.watchAppRunning) { tv.setText(R.string.WatchAppOK); tv.setBackgroundColor(okColour); @@ -865,12 +865,12 @@ public class MainActivity extends AppCompatActivity { tv.setBackgroundColor(warnColour); tv.setTextColor(warnTextColour); } - tv = (TextView) findViewById(R.id.pebTimeTv); + tv = (TextView) findViewById(R.id.data_time_tv); tv.setText(mConnection.mSdServer.mSdData.dataTime.format("%H:%M:%S")); tv.setBackgroundColor(okColour); tv.setTextColor(okTextColour); - tv = (TextView) findViewById(R.id.pebTimeTv); + tv = (TextView) findViewById(R.id.data_time_tv); tv.setText("--:--:--"); tv.setBackgroundColor(warnColour); tv.setTextColor(warnTextColour); @@ -880,7 +880,7 @@ public class MainActivity extends AppCompatActivity { tv.setBackgroundColor(warnColour); tv.setTextColor(warnTextColour); - tv = (TextView) findViewById(R.id.appTv); + tv = (TextView) findViewById(R.id.fragment_watch_app_status_tv); tv.setText(getString(R.string.WatchApp) + " ----"); tv.setBackgroundColor(warnColour); tv.setTextColor(warnTextColour); @@ -895,12 +895,12 @@ public class MainActivity extends AppCompatActivity { tv.setText(R.string.Dashes); tv.setBackgroundColor(warnColour); tv.setTextColor(warnTextColour); - tv = (TextView) findViewById(R.id.pebTimeTv); + tv = (TextView) findViewById(R.id.data_time_tv); tv.setText(mConnection.mSdServer.mSdData.dataTime.format("%H:%M:%S")); tv.setBackgroundColor(okColour); tv.setTextColor(okTextColour); - tv = (TextView) findViewById(R.id.pebTimeTv); + tv = (TextView) findViewById(R.id.data_time_tv); tv.setText("--:--:--"); tv.setBackgroundColor(warnColour); tv.setTextColor(warnTextColour); @@ -910,7 +910,7 @@ public class MainActivity extends AppCompatActivity { tv.setBackgroundColor(warnColour); tv.setTextColor(warnTextColour); - tv = (TextView) findViewById(R.id.appTv); + tv = (TextView) findViewById(R.id.fragment_watch_app_status_tv); tv.setText(getString(R.string.WatchApp) + " -----"); tv.setBackgroundColor(warnColour); tv.setTextColor(warnTextColour); diff --git a/app/src/main/java/uk/org/openseizuredetector/MainActivity2.java b/app/src/main/java/uk/org/openseizuredetector/MainActivity2.java index 8a4ce8a..d61cfe6 100644 --- a/app/src/main/java/uk/org/openseizuredetector/MainActivity2.java +++ b/app/src/main/java/uk/org/openseizuredetector/MainActivity2.java @@ -1,24 +1,71 @@ package uk.org.openseizuredetector; +import androidx.appcompat.app.AlertDialog; import androidx.appcompat.app.AppCompatActivity; +import androidx.core.view.MenuCompat; import androidx.fragment.app.Fragment; import androidx.fragment.app.FragmentActivity; import androidx.viewpager2.adapter.FragmentStateAdapter; import androidx.viewpager2.widget.ViewPager2; +import android.content.Context; +import android.content.DialogInterface; +import android.content.Intent; +import android.content.SharedPreferences; +import android.graphics.Color; +import android.net.Uri; import android.os.Bundle; +import android.os.Handler; +import android.preference.PreferenceManager; import android.util.Log; +import android.view.Menu; +import android.view.MenuItem; import android.view.View; import android.widget.Button; +import android.widget.TextView; + +import com.rohitss.uceh.UCEHandler; + +import java.util.Timer; +import java.util.TimerTask; public class MainActivity2 extends AppCompatActivity { private String TAG = "MainActivity2"; + private int okColour = Color.BLUE; + private int warnColour = Color.MAGENTA; + private int alarmColour = Color.RED; + private int okTextColour = Color.WHITE; + private int warnTextColour = Color.WHITE; + private int alarmTextColour = Color.BLACK; + private ViewPager2 mFragmentPager; private FragmentStateAdapter mFragmentStateAdapter; + private Context mContext; + 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()"); + + // 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(""); + mUtil.writeToSysLogFile("* MainActivity Started *"); + mUtil.writeToSysLogFile("MainActivity.onCreate()"); + mContext = this; + + if (savedInstanceState == null) { // Instantiate a ViewPager2 and a PagerAdapter. mFragmentPager = findViewById(R.id.fragment_pager); @@ -29,11 +76,72 @@ public class MainActivity2 extends AppCompatActivity { .add(R.id.fragment_common_container_view, FragmentCommon.class, null) .commit(); } + } + /** + * Create Action Bar + */ + @Override + public boolean onCreateOptionsMenu(Menu menu) { + Log.i(TAG, "onCreateOptionsMenu()"); + getMenuInflater().inflate(R.menu.main_activity_actions, menu); + MenuCompat.setGroupDividerEnabled(menu, true); + return true; + } + + @Override + protected void onStart() { + super.onStart(); + Log.i(TAG, "onStart()"); + mUtil.writeToSysLogFile("MainActivity.onStart()"); + SharedPreferences SP = PreferenceManager + .getDefaultSharedPreferences(getBaseContext()); + boolean audibleAlarm = SP.getBoolean("AudibleAlarm", true); + Log.v(TAG, "onStart - auidbleAlarm = " + audibleAlarm); + + TextView tv; + tv = (TextView) findViewById(R.id.versionTv); + String versionName = mUtil.getAppVersionName(); + tv.setText(getString(R.string.AppTitleText) + " " + versionName); + tv.setBackgroundColor(okColour); + tv.setTextColor(okTextColour); + + if (mUtil.isServerRunning()) { + mUtil.writeToSysLogFile("MainActivity.onStart - Binding to Server"); + mUtil.bindToServer(getApplicationContext(), mConnection); + } else { + Log.i(TAG, "onStart() - Server Not Running"); + mUtil.writeToSysLogFile("MainActivity.onStart - Server Not Running"); + } } + @Override + protected void onStop() { + super.onStop(); + Log.i(TAG, "onStop() - unbinding from server"); + mUtil.writeToSysLogFile("MainActivity.onStop()"); + mUtil.unbindFromServer(getApplicationContext(), mConnection); + } + + + + + @Override + protected void onPause() { + super.onPause(); + Log.i(TAG, "onPause()"); + } + + @Override + protected void onResume() { + super.onResume(); + Log.i(TAG, "onResume()"); + } + + + @Override public void onBackPressed() { if (mFragmentPager.getCurrentItem() == 0) { @@ -46,6 +154,122 @@ public class MainActivity2 extends AppCompatActivity { } } + @Override + public boolean onOptionsItemSelected(MenuItem item) { + Log.i(TAG, "onOptionsItemSelected() : " + item.getItemId() + " selected"); + switch (item.getItemId()) { + /*case R.id.action_launch_pebble_app: + Log.i(TAG, "action_launch_pebble_app"); + mConnection.mSdServer.mSdDataSource.startPebbleApp(); + return true; + */ + case R.id.action_install_watch_app: + Log.i(TAG, "action_install_watch_app"); + mConnection.mSdServer.mSdDataSource.installWatchApp(); + return true; + + case R.id.action_accept_alarm: + Log.i(TAG, "action_accept_alarm"); + if (mConnection.mBound) { + mConnection.mSdServer.acceptAlarm(); + } + return true; + case R.id.action_start_stop: + // Respond to the start/stop server menu item. + Log.i(TAG, "action_start_stop"); + if (mConnection.mBound) { + Log.i(TAG, "Stopping Server"); + mUtil.unbindFromServer(getApplicationContext(), mConnection); + stopServer(); + finish(); + } else { + Log.i(TAG, "Starting Server"); + startServer(); + // and bind to it so we can see its data + Log.i(TAG, "Binding to Server"); + mUtil.bindToServer(getApplicationContext(), mConnection); + } + return true; + case R.id.action_test_alarm_beep: + Log.i(TAG, "action_test_alarm_beep"); + if (mConnection.mBound) { + mConnection.mSdServer.alarmBeep(); + } + return true; + case R.id.action_test_warning_beep: + Log.i(TAG, "action_test_warning_beep"); + if (mConnection.mBound) { + mConnection.mSdServer.warningBeep(); + } + return true; + case R.id.action_test_sms_alarm: + Log.i(TAG, "action_test_sms_alarm"); + if (mConnection.mBound) { + mConnection.mSdServer.sendSMSAlarm(); + } + return true; + + case R.id.action_authenticate_api: + Log.i(TAG, "action_autheticate_api"); + try { + Intent i = new Intent( + MainActivity2.this, + AuthenticateActivity.class); + this.startActivity(i); + } catch (Exception ex) { + Log.i(TAG, "exception starting export activity " + ex.toString()); + } + return true; + case R.id.action_about_datasharing: + Log.i(TAG, "action_about_datasharing"); + showDataSharingDialog(); + return true; + case R.id.action_logmanager: + Log.i(TAG, "action_logmanager"); + try { + Intent intent = new Intent( + MainActivity2.this, + LogManagerControlActivity.class); + this.startActivity(intent); + } catch (Exception ex) { + Log.i(TAG, "exception starting log manager activity " + ex.toString()); + } + return true; + case R.id.action_report_seizure: + Log.i(TAG, "action_report_seizure"); + try { + Intent intent = new Intent( + MainActivity2.this, + ReportSeizureActivity.class); + this.startActivity(intent); + } catch (Exception ex) { + Log.i(TAG, "exception starting Report Seizure activity " + ex.toString()); + } + return true; + case R.id.action_settings: + Log.i(TAG, "action_settings"); + try { + Intent prefsIntent = new Intent( + MainActivity2.this, + PrefActivity.class); + this.startActivity(prefsIntent); + } catch (Exception ex) { + Log.i(TAG, "exception starting settings activity " + ex.toString()); + } + return true; + case R.id.action_about: + Log.i(TAG, "action_about"); + showAbout(); + return true; + + default: + return super.onOptionsItemSelected(item); + } + } + + + + /** * A simple pager adapter that represents 5 ScreenSlidePageFragment objects, in * sequence. @@ -66,11 +290,9 @@ public class MainActivity2 extends AppCompatActivity { case 2: return new FragmentMlAlg(); case 3: - return new FragmentWebServer(); + return new FragmentSystem(); case 4: return new FragmentDataSharing(); - case 5: - return new FragmentSystem(); default: Log.e(TAG,"createFragment() - invalid Position "+position); @@ -80,7 +302,87 @@ public class MainActivity2 extends AppCompatActivity { @Override public int getItemCount() { - return 6; + return 5; } } + + private void startServer() { + mUtil.writeToSysLogFile("MainActivity.startServer()"); + Log.i(TAG, "startServer(): starting Server..."); + mUtil.startServer(); + } + + private void stopServer() { + mUtil.writeToSysLogFile("MainActivity.stopServer()"); + Log.i(TAG, "stopServer(): stopping Server..."); + mUtil.stopServer(); + } + + + + private void showAbout() { + mUtil.writeToSysLogFile("MainActivity.showAbout()"); + View aboutView = getLayoutInflater().inflate(R.layout.about_layout, null, false); + String versionName = mUtil.getAppVersionName(); + Log.i(TAG, "showAbout() - version name = " + versionName); + AlertDialog.Builder builder = new AlertDialog.Builder(this); + builder.setIcon(R.drawable.icon_24x24); + builder.setTitle("OpenSeizureDetector V" + versionName); + builder.setNeutralButton(getString(R.string.closeBtnTxt), new DialogInterface.OnClickListener() { + public void onClick(DialogInterface dialog, int id) { + dialog.cancel(); + } + }); + builder.setPositiveButton(R.string.privacy_policy_button_title, new DialogInterface.OnClickListener() { + public void onClick(DialogInterface dialog, int id) { + dialog.cancel(); + String url = OsdUtil.PRIVACY_POLICY_URL; + Intent i = new Intent(Intent.ACTION_VIEW); + i.setData(Uri.parse(url)); + startActivity(i); + dialog.cancel(); + } + }); + builder.setNegativeButton(R.string.data_sharing_button_title, new DialogInterface.OnClickListener() { + public void onClick(DialogInterface dialog, int id) { + dialog.cancel(); + String url = OsdUtil.DATA_SHARING_URL; + Intent i = new Intent(Intent.ACTION_VIEW); + i.setData(Uri.parse(url)); + startActivity(i); + dialog.cancel(); + } + }); + builder.setView(aboutView); + builder.create(); + builder.show(); + } + + private void showDataSharingDialog() { + mUtil.writeToSysLogFile("MainActivity.showDataSharingDialog()"); + View aboutView = getLayoutInflater().inflate(R.layout.data_sharing_dialog_layout, null, false); + AlertDialog.Builder builder = new AlertDialog.Builder(this); + builder.setIcon(R.drawable.datasharing_fault_24x24); + builder.setTitle(R.string.data_sharing_dialog_title); + builder.setNegativeButton(getString(R.string.cancel), null); + builder.setPositiveButton(getString(R.string.login), new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int which) { + Log.i(TAG, "dataSharingDialog.positiveButton.onClick()"); + try { + Intent i = new Intent( + MainActivity2.this, + AuthenticateActivity.class); + mContext.startActivity(i); + } catch (Exception ex) { + Log.i(TAG, "exception starting activity " + ex.toString()); + } + + } + }); + builder.setView(aboutView); + builder.create(); + builder.show(); + } + } \ No newline at end of file diff --git a/app/src/main/res/layout/fragment_common.xml b/app/src/main/res/layout/fragment_common.xml index d253d34..42aacb9 100644 --- a/app/src/main/res/layout/fragment_common.xml +++ b/app/src/main/res/layout/fragment_common.xml @@ -3,30 +3,31 @@ xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" - tools:context=".FragmentSdDataViewer"> + tools:context=".FragmentOsdBaseClass"> - - + android:orientation="vertical" + android:background="@color/okBackgroundColor" + > + + android:text="OpenSeizureDetector Common Components Status" + android:textColor="@color/okTextColor" + /> + android:text="@string/app_name" + android:textColor="@color/okTextColor" + /> + android:layout_height="wrap_content" + android:orientation="vertical"> + + + + + + + + + + + + android:orientation="horizontal"> + + + + + + android:orientation="horizontal"> + android:text="---" /> - + android:layout_height="wrap_content" + android:text="---" /> - - - - - - - - - - - - - + android:layout_height="wrap_content" + android:text="" + android:visibility="gone"/> + --> + + diff --git a/app/src/main/res/layout/fragment_data_sharing.xml b/app/src/main/res/layout/fragment_data_sharing.xml index e80d4ac..c284fb1 100644 --- a/app/src/main/res/layout/fragment_data_sharing.xml +++ b/app/src/main/res/layout/fragment_data_sharing.xml @@ -3,7 +3,7 @@ xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" - tools:context=".FragmentSdDataViewer"> + tools:context=".FragmentOsdBaseClass"> + tools:context=".FragmentOsdBaseClass"> + tools:context=".FragmentOsdBaseClass"> + tools:context=".FragmentOsdBaseClass"> + tools:context=".FragmentOsdBaseClass"> + tools:context=".FragmentOsdBaseClass"> - - + android:orientation="vertical" + android:id="@+id/fragment_ll"> + android:text="OpenSeizureDetector System Status" + android:textColor="@color/okTextColor" + android:background="@color/okBackgroundColor" + /> + - + + + + + - + android:text="---" /> + + + + + + + + + + + + + + + + diff --git a/app/src/main/res/layout/fragment_web_server.xml b/app/src/main/res/layout/fragment_web_server.xml index 79d7e9f..52d120e 100644 --- a/app/src/main/res/layout/fragment_web_server.xml +++ b/app/src/main/res/layout/fragment_web_server.xml @@ -3,7 +3,7 @@ xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" - tools:context=".FragmentSdDataViewer"> + tools:context=".FragmentOsdBaseClass"> diff --git a/app/src/main/res/values/colors.xml b/app/src/main/res/values/colors.xml index 3ab3e9c..3bcf48f 100644 --- a/app/src/main/res/values/colors.xml +++ b/app/src/main/res/values/colors.xml @@ -3,4 +3,6 @@ #3F51B5 #303F9F #FF4081 + #0000ff + #ffffff diff --git a/app/src/main/res/values/styles.xml b/app/src/main/res/values/styles.xml index 5885930..265a121 100644 --- a/app/src/main/res/values/styles.xml +++ b/app/src/main/res/values/styles.xml @@ -1,7 +1,7 @@ - + +