From d8b358229165d88dcef97028329b50bb2ab3c8e9 Mon Sep 17 00:00:00 2001 From: Graham Jones Date: Fri, 19 Jan 2024 20:49:41 +0000 Subject: [PATCH] Tidied up new user interface (and fixed problem with re-loading only activity from Android Studio) --- app/src/main/AndroidManifest.xml | 2 +- .../openseizuredetector/FragmentCommon.java | 62 ++++++++--------- .../openseizuredetector/FragmentOsdAlg.java | 7 -- .../openseizuredetector/MainActivity2.java | 27 +++++--- app/src/main/res/layout/fragment_common.xml | 66 +++++-------------- app/src/main/res/layout/fragment_osdalg.xml | 10 +-- app/src/main/res/layout/fragment_system.xml | 2 +- app/src/main/res/values/strings.xml | 1 + 8 files changed, 67 insertions(+), 110 deletions(-) diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 917802a..e86502a 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -2,7 +2,7 @@ + android:versionName="4.2.1m"> diff --git a/app/src/main/java/uk/org/openseizuredetector/FragmentCommon.java b/app/src/main/java/uk/org/openseizuredetector/FragmentCommon.java index c3a44c9..3fefb1d 100644 --- a/app/src/main/java/uk/org/openseizuredetector/FragmentCommon.java +++ b/app/src/main/java/uk/org/openseizuredetector/FragmentCommon.java @@ -12,6 +12,7 @@ import android.widget.TextView; public class FragmentCommon extends FragmentOsdBaseClass { String TAG = "FragmentCommon"; + public FragmentCommon() { // Required empty public constructor } @@ -81,37 +82,16 @@ public class FragmentCommon extends FragmentOsdBaseClass { protected void updateUi() { //Log.d(TAG,"updateUi()"); TextView tv; - tv = (TextView)mRootView.findViewById(R.id.fragment_common_tv1); - if (mConnection.mBound) { - tv.setText("Bound to Server"); - } else { - tv.setText("****NOT BOUND TO SERVER***"); - return; - } if (mUtil.isServerRunning()) { - //LinearLayout ll = (LinearLayout) findViewById(R.id.statusLayout); - //ll.setBackgroundColor(okColour); - //ll = (LinearLayout) findViewById(R.id.watchStatusLl); - //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); - } + if (mConnection.mSdServer.mLogNDA) + tv.setText(getString(R.string.ServerRunningOK) + " - NDA Logging"); + else + tv.setText(getString(R.string.ServerRunningOK)); + tv.setBackgroundColor(okColour); + tv.setTextColor(okTextColour); tv = (TextView) mRootView.findViewById(R.id.alarmTv); if ((mConnection.mSdServer.mSdData.alarmState == 0) @@ -146,7 +126,7 @@ public class FragmentCommon extends FragmentOsdBaseClass { tv = (TextView) mRootView.findViewById(R.id.algsTv); - tv.setText("Algorithms"); + tv.setText(R.string.algorithms); tv.setBackgroundColor(okColour); tv.setTextColor(okTextColour); tv = (TextView) mRootView.findViewById(R.id.osdAlgTv); @@ -168,7 +148,7 @@ public class FragmentCommon extends FragmentOsdBaseClass { tv.setPaintFlags(tv.getPaintFlags() & ~Paint.STRIKE_THRU_TEXT_FLAG); } else { tv.setBackgroundColor(okColour); - tv.setTextColor(okTextColour); + tv.setTextColor(Color.GRAY); tv.setPaintFlags(tv.getPaintFlags() | Paint.STRIKE_THRU_TEXT_FLAG); } tv = (TextView) mRootView.findViewById(R.id.hrAlgTv); @@ -179,7 +159,7 @@ public class FragmentCommon extends FragmentOsdBaseClass { tv.setPaintFlags(tv.getPaintFlags() & ~Paint.STRIKE_THRU_TEXT_FLAG); } else { tv.setBackgroundColor(okColour); - tv.setTextColor(okTextColour); + tv.setTextColor(Color.GRAY); tv.setPaintFlags(tv.getPaintFlags() | Paint.STRIKE_THRU_TEXT_FLAG); } tv = (TextView) mRootView.findViewById(R.id.o2AlgTv); @@ -190,7 +170,7 @@ public class FragmentCommon extends FragmentOsdBaseClass { tv.setPaintFlags(tv.getPaintFlags() & ~Paint.STRIKE_THRU_TEXT_FLAG); } else { tv.setBackgroundColor(okColour); - tv.setTextColor(okTextColour); + tv.setTextColor(Color.GRAY); tv.setPaintFlags(tv.getPaintFlags() | Paint.STRIKE_THRU_TEXT_FLAG); } } @@ -199,10 +179,25 @@ public class FragmentCommon extends FragmentOsdBaseClass { tv.setText(R.string.ServerStopped); tv.setBackgroundColor(warnColour); tv.setTextColor(warnTextColour); - tv = (TextView) mRootView.findViewById(R.id.serverIpTv); - tv.setText("--"); + + /** FIXME - check this is not needed for this fragment + tv = (TextView) mRootView.findViewById(R.id.serverIpTv); + tv.setText("--"); + tv.setBackgroundColor(warnColour); + tv.setTextColor(warnTextColour); + */ + } + + tv = (TextView) mRootView.findViewById(R.id.dataSourceInfoTv); + if (mConnection.mSdServer.mSdDataSourceName.equals("Phone")) { + tv.setText(getString(R.string.DataSource) + " = " + "Phone (Demo Mode)"); tv.setBackgroundColor(warnColour); tv.setTextColor(warnTextColour); + } else { + tv.setText(getString(R.string.DataSource) + " = " + mConnection.mSdServer.mSdDataSourceName); + tv.setBackgroundColor(okColour); + tv.setTextColor(okTextColour); + } // deal with latch alarms button @@ -254,6 +249,5 @@ public class FragmentCommon extends FragmentOsdBaseClass { } - } } diff --git a/app/src/main/java/uk/org/openseizuredetector/FragmentOsdAlg.java b/app/src/main/java/uk/org/openseizuredetector/FragmentOsdAlg.java index 4965f0f..a6ae061 100644 --- a/app/src/main/java/uk/org/openseizuredetector/FragmentOsdAlg.java +++ b/app/src/main/java/uk/org/openseizuredetector/FragmentOsdAlg.java @@ -44,13 +44,6 @@ public class FragmentOsdAlg extends FragmentOsdBaseClass { protected void updateUi() { //Log.d(TAG,"updateUi()"); TextView tv; - tv = (TextView)mRootView.findViewById(R.id.fragment_osdalg_tv1); - if (mConnection.mBound) { - tv.setText("Bound to Server"); - } else { - tv.setText("****NOT BOUND TO SERVER***"); - return; - } ///////////////////////////////////////////////////// diff --git a/app/src/main/java/uk/org/openseizuredetector/MainActivity2.java b/app/src/main/java/uk/org/openseizuredetector/MainActivity2.java index ef63ea7..88e6de2 100644 --- a/app/src/main/java/uk/org/openseizuredetector/MainActivity2.java +++ b/app/src/main/java/uk/org/openseizuredetector/MainActivity2.java @@ -61,12 +61,10 @@ public class MainActivity2 extends AppCompatActivity { //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()"); + mUtil.writeToSysLogFile("MainActivity2.onCreate()"); mContext = this; - + /** if (savedInstanceState == null) { // Instantiate a ViewPager2 and a PagerAdapter. mFragmentPager = findViewById(R.id.fragment_pager); @@ -77,6 +75,7 @@ public class MainActivity2 extends AppCompatActivity { .add(R.id.fragment_common_container_view, FragmentCommon.class, null) .commit(); } + */ } /** @@ -98,7 +97,7 @@ public class MainActivity2 extends AppCompatActivity { SharedPreferences SP = PreferenceManager .getDefaultSharedPreferences(getBaseContext()); boolean audibleAlarm = SP.getBoolean("AudibleAlarm", true); - Log.v(TAG, "onStart - auidbleAlarm = " + audibleAlarm); + Log.v(TAG, "onStart - audibleAlarm = " + audibleAlarm); TextView tv; tv = (TextView) findViewById(R.id.versionTv); @@ -108,11 +107,12 @@ public class MainActivity2 extends AppCompatActivity { tv.setTextColor(okTextColour); if (mUtil.isServerRunning()) { - mUtil.writeToSysLogFile("MainActivity.onStart - Binding to Server"); + Log.i(TAG, "MainActivity2.onStart() - Binding to Server"); + mUtil.writeToSysLogFile("MainActivity2.onStart - Binding to Server"); mUtil.bindToServer(getApplicationContext(), mConnection); } else { - Log.i(TAG, "onStart() - Server Not Running"); - mUtil.writeToSysLogFile("MainActivity.onStart - Server Not Running"); + Log.i(TAG, "MainActivity2.onStart() - Server Not Running"); + mUtil.writeToSysLogFile("MainActivity2.onStart - Server Not Running"); } @@ -139,6 +139,15 @@ public class MainActivity2 extends AppCompatActivity { protected void onResume() { super.onResume(); Log.i(TAG, "onResume()"); + // 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(); + } @@ -182,7 +191,7 @@ public class MainActivity2 extends AppCompatActivity { Log.i(TAG, "Stopping Server"); mUtil.unbindFromServer(getApplicationContext(), mConnection); stopServer(); - finish(); + //finish(); } else { Log.i(TAG, "Starting Server"); startServer(); diff --git a/app/src/main/res/layout/fragment_common.xml b/app/src/main/res/layout/fragment_common.xml index 42aacb9..4556bc4 100644 --- a/app/src/main/res/layout/fragment_common.xml +++ b/app/src/main/res/layout/fragment_common.xml @@ -2,33 +2,28 @@ - + android:text="---" /> - + android:text="---" /> - - - - - - - - + android:text="Algorithms: " /> - - - --> - + + + + - diff --git a/app/src/main/res/layout/fragment_osdalg.xml b/app/src/main/res/layout/fragment_osdalg.xml index da7eaa2..cdf49dc 100644 --- a/app/src/main/res/layout/fragment_osdalg.xml +++ b/app/src/main/res/layout/fragment_osdalg.xml @@ -7,7 +7,7 @@ @@ -52,14 +52,6 @@ android:layout_width="match_parent" android:layout_height="match_parent" /> - - - \ No newline at end of file diff --git a/app/src/main/res/layout/fragment_system.xml b/app/src/main/res/layout/fragment_system.xml index 3d1898a..235d8b6 100644 --- a/app/src/main/res/layout/fragment_system.xml +++ b/app/src/main/res/layout/fragment_system.xml @@ -9,7 +9,7 @@ diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index f900a11..b188ce7 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -565,4 +565,5 @@ Heart Rate Algorithm "Heart Rate History (bpm): " minutes + "Algorithms: "