Tidied up new user interface (and fixed problem with re-loading only activity from Android Studio)

This commit is contained in:
Graham Jones
2024-01-19 20:49:41 +00:00
parent 65c8a2a12b
commit d8b3582291
8 changed files with 67 additions and 110 deletions

View File

@@ -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 {
}
}
}

View File

@@ -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;
}
/////////////////////////////////////////////////////

View File

@@ -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();