Added the main fragments for the new main activity - still need to populate them and add the main menu, but swiping between them works

This commit is contained in:
Graham Jones
2023-09-01 21:43:42 +01:00
parent d2577c1e0e
commit 3ce91f89ab
15 changed files with 744 additions and 23 deletions

View File

@@ -0,0 +1,227 @@
package uk.org.openseizuredetector;
import android.graphics.Color;
import android.graphics.Paint;
import android.os.Bundle;
import android.util.Log;
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 {
String TAG = "FragmentCommon";
public FragmentCommon() {
// Required empty public constructor
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
return inflater.inflate(R.layout.fragment_common, container, false);
}
@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
// Deal with the 'AcceptAlarm Button'
Button button = (Button) mRootView.findViewById(R.id.acceptAlarmButton);
button.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Log.v(TAG, "acceptAlarmButton.onClick()");
if (mConnection.mBound) {
if ((mConnection.mSdServer.mSmsTimer != null)
&& (mConnection.mSdServer.mSmsTimer.mTimeLeft > 0)) {
Log.i(TAG, "acceptAlarmButton.onClick() - Stopping SMS Timer");
mUtil.showToast(getString(R.string.SMSAlarmCancelledMsg));
mConnection.mSdServer.stopSmsTimer();
} else {
Log.v(TAG, "acceptAlarmButton.onClick() - Accepting Alarm");
mConnection.mSdServer.acceptAlarm();
}
}
}
});
// Deal with the 'Cancel Audible Button'
button = (Button) mRootView.findViewById(R.id.cancelAudibleButton);
button.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Log.v(TAG, "cancelAudibleButton.onClick()");
if (mConnection.mBound) {
mConnection.mSdServer.cancelAudible();
}
}
});
// Deal with the 'Raise Alarm'
button = (Button) mRootView.findViewById(R.id.manualAlarmButton);
button.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Log.v(TAG, "manualAlarmButton.onClick()");
if (mConnection.mBound) {
mConnection.mSdServer.raiseManualAlarm();
}
}
});
}
@Override
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);
}
tv = (TextView) mRootView.findViewById(R.id.algsTv);
tv.setText("Algorithms");
tv.setBackgroundColor(okColour);
tv.setTextColor(okTextColour);
tv = (TextView) mRootView.findViewById(R.id.osdAlgTv);
tv.setText("OSD ");
if (mConnection.mSdServer.mSdData.mOsdAlarmActive) {
tv.setBackgroundColor(okColour);
tv.setTextColor(okTextColour);
tv.setPaintFlags(tv.getPaintFlags() & ~Paint.STRIKE_THRU_TEXT_FLAG);
} else {
tv.setBackgroundColor(warnColour);
tv.setTextColor(warnTextColour);
tv.setPaintFlags(tv.getPaintFlags() | Paint.STRIKE_THRU_TEXT_FLAG);
}
tv = (TextView) mRootView.findViewById(R.id.cnnAlgTv);
tv.setText("CNN ");
if (mConnection.mSdServer.mSdData.mCnnAlarmActive) {
tv.setBackgroundColor(okColour);
tv.setTextColor(okTextColour);
tv.setPaintFlags(tv.getPaintFlags() & ~Paint.STRIKE_THRU_TEXT_FLAG);
} else {
tv.setBackgroundColor(okColour);
tv.setTextColor(okTextColour);
tv.setPaintFlags(tv.getPaintFlags() | Paint.STRIKE_THRU_TEXT_FLAG);
}
tv = (TextView) mRootView.findViewById(R.id.hrAlgTv);
tv.setText("HR ");
if (mConnection.mSdServer.mSdData.mHRAlarmActive) {
tv.setBackgroundColor(okColour);
tv.setTextColor(okTextColour);
tv.setPaintFlags(tv.getPaintFlags() & ~Paint.STRIKE_THRU_TEXT_FLAG);
} else {
tv.setBackgroundColor(okColour);
tv.setTextColor(okTextColour);
tv.setPaintFlags(tv.getPaintFlags() | Paint.STRIKE_THRU_TEXT_FLAG);
}
tv = (TextView) mRootView.findViewById(R.id.o2AlgTv);
tv.setText("O2 ");
if (mConnection.mSdServer.mSdData.mO2SatAlarmActive) {
tv.setBackgroundColor(okColour);
tv.setTextColor(okTextColour);
tv.setPaintFlags(tv.getPaintFlags() & ~Paint.STRIKE_THRU_TEXT_FLAG);
} else {
tv.setBackgroundColor(okColour);
tv.setTextColor(okTextColour);
tv.setPaintFlags(tv.getPaintFlags() | Paint.STRIKE_THRU_TEXT_FLAG);
}
}
} else {
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);
}
// deal with latch alarms button
Button acceptAlarmButton = (Button) mRootView.findViewById(R.id.acceptAlarmButton);
if (mConnection.mBound) {
if ((mConnection.mSdServer.mSmsTimer != null)
&& (mConnection.mSdServer.mSmsTimer.mTimeLeft > 0)) {
acceptAlarmButton.setText(getString(R.string.SMSWillBeSentIn) + " " +
mConnection.mSdServer.mSmsTimer.mTimeLeft / 1000 +
" s - " + getString(R.string.Cancel));
acceptAlarmButton.setBackgroundColor(alarmColour);
acceptAlarmButton.setEnabled(true);
} else {
acceptAlarmButton.setText(R.string.AcceptAlarm);
acceptAlarmButton.setBackgroundColor(Color.GRAY);
if (mConnection.mBound)
if ((mConnection.mSdServer.isLatchAlarms())
|| mConnection.mSdServer.mSdData.mFallActive) {
acceptAlarmButton.setEnabled(true);
} else {
acceptAlarmButton.setEnabled(false);
}
}
} else {
acceptAlarmButton.setText(getString(R.string.AcceptAlarm));
acceptAlarmButton.setBackgroundColor(Color.DKGRAY);
acceptAlarmButton.setEnabled(false);
}
// Deal with Cancel Audible button
Button cancelAudibleButton =
(Button) mRootView.findViewById(R.id.cancelAudibleButton);
if (mConnection.mBound)
if (mConnection.mSdServer.isAudibleCancelled()) {
cancelAudibleButton.setText(getString(R.string.AudibleAlarmsCancelledFor)
+ " " + mConnection.mSdServer.
cancelAudibleTimeRemaining()
+ " sec");
cancelAudibleButton.setEnabled(true);
} else {
if (mConnection.mSdServer.mAudibleAlarm) {
cancelAudibleButton.setText(R.string.CancelAudibleAlarms);
cancelAudibleButton.setEnabled(true);
} else {
cancelAudibleButton.setText(R.string.AudibleAlarmsOff);
cancelAudibleButton.setEnabled(false);
}
}
}
}

View File

@@ -0,0 +1,43 @@
package uk.org.openseizuredetector;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
public class FragmentDataSharing extends FragmentSdDataViewer {
String TAG = "FragmentDataSharing";
public FragmentDataSharing() {
// Required empty public constructor
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
return inflater.inflate(R.layout.fragment_data_sharing, container, false);
}
@Override
protected void updateUi() {
Log.d(TAG,"updateUi()");
TextView tv;
tv = (TextView)mRootView.findViewById(R.id.fragment_data_sharing_tv1);
if (mConnection.mBound) {
tv.setText("Bound to Server");
} else {
tv.setText("****NOT BOUND TO SERVER***");
return;
}
}
}

View File

@@ -37,14 +37,14 @@ public class FragmentHrAlg extends FragmentSdDataViewer {
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
return inflater.inflate(R.layout.fragment_osdalg, container, false);
return inflater.inflate(R.layout.fragment_hr_alg, container, false);
}
@Override
protected void updateUi() {
Log.d(TAG,"updateUi()");
TextView tv;
tv = (TextView)mRootView.findViewById(R.id.fragment_osdalg_tv1);
tv = (TextView)mRootView.findViewById(R.id.fragment_hr_alg_tv1);
if (mConnection.mBound) {
tv.setText("Bound to Server");
} else {

View File

@@ -0,0 +1,43 @@
package uk.org.openseizuredetector;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
public class FragmentMlAlg extends FragmentSdDataViewer {
String TAG = "FragmentMlAlg";
public FragmentMlAlg() {
// Required empty public constructor
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
return inflater.inflate(R.layout.fragment_ml_alg, container, false);
}
@Override
protected void updateUi() {
Log.d(TAG,"updateUi()");
TextView tv;
tv = (TextView)mRootView.findViewById(R.id.fragment_ml_alg_tv1);
if (mConnection.mBound) {
tv.setText("Bound to Server");
} else {
tv.setText("****NOT BOUND TO SERVER***");
return;
}
}
}

View File

@@ -1,6 +1,7 @@
package uk.org.openseizuredetector;
import android.content.Context;
import android.graphics.Color;
import android.os.Bundle;
import androidx.fragment.app.Fragment;
@@ -25,6 +26,14 @@ public class FragmentSdDataViewer extends Fragment {
Timer mUiTimer;
protected View mRootView;
protected int okColour = Color.BLUE;
protected int warnColour = Color.MAGENTA;
protected int alarmColour = Color.RED;
protected int okTextColour = Color.WHITE;
protected int warnTextColour = Color.WHITE;
protected int alarmTextColour = Color.BLACK;
public FragmentSdDataViewer() {
// Required empty public constructor

View File

@@ -0,0 +1,68 @@
package uk.org.openseizuredetector;
import android.content.Intent;
import android.os.Bundle;
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";
public FragmentSystem() {
// Required empty public constructor
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
return inflater.inflate(R.layout.fragment_system, container, false);
}
public void onViewCreated(View view, Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
// Handle Edit Settings Button
ImageButton button = (ImageButton) mRootView.findViewById(R.id.settingsButton);
button.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Log.i(TAG, "settingsButton.onClick()");
try {
Intent prefsIntent = new Intent(
mContext,
PrefActivity.class);
mContext.startActivity(prefsIntent);
} catch (Exception ex) {
Log.i(TAG, "exception starting settings activity " + ex.toString());
}
}
});
}
@Override
protected void updateUi() {
Log.d(TAG,"updateUi()");
TextView tv;
tv = (TextView)mRootView.findViewById(R.id.fragment_system_tv1);
if (mConnection.mBound) {
tv.setText("Bound to Server");
} else {
tv.setText("****NOT BOUND TO SERVER***");
return;
}
}
}

View File

@@ -0,0 +1,43 @@
package uk.org.openseizuredetector;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
public class FragmentWebServer extends FragmentSdDataViewer {
String TAG = "FragmentWebServer";
public FragmentWebServer() {
// Required empty public constructor
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
return inflater.inflate(R.layout.fragment_web_server, container, false);
}
@Override
protected void updateUi() {
Log.d(TAG,"updateUi()");
TextView tv;
tv = (TextView)mRootView.findViewById(R.id.fragment_web_server_tv1);
if (mConnection.mBound) {
tv.setText("Bound to Server");
} else {
tv.setText("****NOT BOUND TO SERVER***");
return;
}
}
}

View File

@@ -8,6 +8,8 @@ import androidx.viewpager2.widget.ViewPager2;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
public class MainActivity2 extends AppCompatActivity {
private String TAG = "MainActivity2";
@@ -22,11 +24,14 @@ public class MainActivity2 extends AppCompatActivity {
mFragmentPager = findViewById(R.id.fragment_pager);
mFragmentStateAdapter = new ScreenSlideFragmentPagerAdapter(this);
mFragmentPager.setAdapter(mFragmentStateAdapter);
//getSupportFragmentManager().beginTransaction()
// .setReorderingAllowed(true)
// .add(R.id.fragment_container_view, FragmentOsdAlg.class, null)
// .commit();
getSupportFragmentManager().beginTransaction()
.setReorderingAllowed(true)
.add(R.id.fragment_common_container_view, FragmentCommon.class, null)
.commit();
}
}
@Override
@@ -58,6 +63,15 @@ public class MainActivity2 extends AppCompatActivity {
return new FragmentOsdAlg();
case 1:
return new FragmentHrAlg();
case 2:
return new FragmentMlAlg();
case 3:
return new FragmentWebServer();
case 4:
return new FragmentDataSharing();
case 5:
return new FragmentSystem();
default:
Log.e(TAG,"createFragment() - invalid Position "+position);
return null;
@@ -66,7 +80,7 @@ public class MainActivity2 extends AppCompatActivity {
@Override
public int getItemCount() {
return 2;
return 6;
}
}
}

View File

@@ -517,7 +517,7 @@ public class SdServer extends Service implements SdDataReceiver {
soundUri = null;
}
Intent i = new Intent(getApplicationContext(), MainActivity.class);
Intent i = new Intent(getApplicationContext(), MainActivity2.class);
i.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
PendingIntent contentIntent =
PendingIntent.getActivity(this,
@@ -569,7 +569,7 @@ public class SdServer extends Service implements SdDataReceiver {
mUtil.writeToSysLogFile("SdServer.showMainActivity - Activity is already shown on top, not doing anything");
} else {
Log.i(TAG, "showMainActivity(): Showing Main Activity");
Intent i = new Intent(getApplicationContext(), MainActivity.class);
Intent i = new Intent(getApplicationContext(), MainActivity2.class);
i.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT | Intent.FLAG_ACTIVITY_NEW_TASK);
this.startActivity(i);
}
@@ -1733,7 +1733,7 @@ public class SdServer extends Service implements SdDataReceiver {
iconId = R.drawable.datasharing_fault_24x24;
titleStr = getString(R.string.datasharing_notification_title);
Intent i = new Intent(getApplicationContext(), MainActivity.class);
Intent i = new Intent(getApplicationContext(), MainActivity2.class);
i.putExtra("action", "showDataSharingDialog");
i.setAction("showDataSharingDialog");
i.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);