Started on battery history screen for new UI - not working yet, but it runs without crashing
This commit is contained in:
144
app/src/main/java/uk/org/openseizuredetector/FragmentBatt.java
Normal file
144
app/src/main/java/uk/org/openseizuredetector/FragmentBatt.java
Normal file
@@ -0,0 +1,144 @@
|
|||||||
|
package uk.org.openseizuredetector;
|
||||||
|
|
||||||
|
import android.graphics.Color;
|
||||||
|
import android.os.Bundle;
|
||||||
|
import android.util.Log;
|
||||||
|
import android.view.LayoutInflater;
|
||||||
|
import android.view.View;
|
||||||
|
import android.view.ViewGroup;
|
||||||
|
import android.widget.TextView;
|
||||||
|
|
||||||
|
import androidx.appcompat.widget.SwitchCompat;
|
||||||
|
|
||||||
|
import com.github.mikephil.charting.charts.LineChart;
|
||||||
|
import com.github.mikephil.charting.components.XAxis;
|
||||||
|
import com.github.mikephil.charting.components.YAxis;
|
||||||
|
import com.github.mikephil.charting.data.Entry;
|
||||||
|
import com.github.mikephil.charting.data.LineData;
|
||||||
|
import com.github.mikephil.charting.data.LineDataSet;
|
||||||
|
import com.github.mikephil.charting.utils.ValueFormatter;
|
||||||
|
|
||||||
|
import java.text.DecimalFormat;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
|
|
||||||
|
public class FragmentBatt extends FragmentOsdBaseClass {
|
||||||
|
String TAG = "FragmentBatt";
|
||||||
|
|
||||||
|
LineChart mLineChart;
|
||||||
|
LineData lineData;
|
||||||
|
LineDataSet lineDataSet;
|
||||||
|
List<Entry> watchHistory = new ArrayList<>();
|
||||||
|
List<Entry> phoneHistory = new ArrayList<>();
|
||||||
|
List<String> hrHistoryStrings = new ArrayList<>();
|
||||||
|
List<String> hrAveragesStrings = new ArrayList<>();
|
||||||
|
private List<Entry> listToDisplay;
|
||||||
|
private List<String> listToDisplayStrings;
|
||||||
|
|
||||||
|
|
||||||
|
public FragmentBatt() {
|
||||||
|
// Required empty public constructor
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onCreate(Bundle savedInstanceState) {
|
||||||
|
super.onCreate(savedInstanceState);
|
||||||
|
lineDataSet = new LineDataSet(new ArrayList<Entry>(), "Battery history");
|
||||||
|
//lineDataSet.setColors(ColorTemplate.JOYFUL_COLORS);
|
||||||
|
lineDataSet.setValueTextColor(Color.BLACK);
|
||||||
|
lineDataSet.setValueTextSize(18f);
|
||||||
|
lineDataSet.setDrawValues(false);
|
||||||
|
lineDataSet.setCircleSize(0f);
|
||||||
|
lineDataSet.setLineWidth(3f);
|
||||||
|
//lineDataSetAverage = new LineDataSet(new ArrayList<Entry>(),"Heart rate history" );
|
||||||
|
//lineDataSetAverage.setColors(ColorTemplate.JOYFUL_COLORS);
|
||||||
|
//lineDataSetAverage.setValueTextColor(Color.BLACK);
|
||||||
|
//lineDataSetAverage.setValueTextSize(18f);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onResume() {
|
||||||
|
super.onResume();
|
||||||
|
mLineChart = mRootView.findViewById(R.id.lineChart);
|
||||||
|
mLineChart.getLegend().setEnabled(false);
|
||||||
|
XAxis xAxis = mLineChart.getXAxis();
|
||||||
|
xAxis.setPosition(XAxis.XAxisPosition.BOTTOM);
|
||||||
|
xAxis.setTextSize(10f);
|
||||||
|
xAxis.setDrawAxisLine(true);
|
||||||
|
xAxis.setDrawLabels(true);
|
||||||
|
// Note: the default text colour is BLACK, so does not show up on black background!!!
|
||||||
|
// This took a lot of finding....
|
||||||
|
xAxis.setTextColor(Color.WHITE);
|
||||||
|
|
||||||
|
YAxis yAxis = mLineChart.getAxisLeft();
|
||||||
|
yAxis.setAxisMinValue(40f);
|
||||||
|
yAxis.setAxisMaxValue(240f);
|
||||||
|
yAxis.setDrawGridLines(true);
|
||||||
|
yAxis.setDrawLabels(true);
|
||||||
|
yAxis.setTextColor(Color.WHITE);
|
||||||
|
// Inhibit the decimal part of the y axis labels.
|
||||||
|
yAxis.setValueFormatter(new ValueFormatter() {
|
||||||
|
@Override
|
||||||
|
public String getFormattedValue(float v) {
|
||||||
|
DecimalFormat format = new DecimalFormat("###");
|
||||||
|
return format.format(v);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
YAxis yAxis2 = mLineChart.getAxisRight();
|
||||||
|
yAxis2.setDrawGridLines(false);
|
||||||
|
yAxis2.setEnabled(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
||||||
|
Bundle savedInstanceState) {
|
||||||
|
// Inflate the layout for this fragment
|
||||||
|
return inflater.inflate(R.layout.fragment_batt, container, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void updateUi() {
|
||||||
|
Log.d(TAG, "updateUi()");
|
||||||
|
if (mConnection.mBound) {
|
||||||
|
|
||||||
|
int nWatchBattArr = mConnection.mSdServer.mSdData.watchBattBuff.getNumVals();
|
||||||
|
double watchBattArr[] = mConnection.mSdServer.mSdData.watchBattBuff.getVals(); // This gives us a simple vector of hr values to plot.
|
||||||
|
int nPhoneBattArr = mConnection.mSdServer.mSdData.phoneBattBuff.getNumVals();
|
||||||
|
double phoneBattArr[] = mConnection.mSdServer.mSdData.phoneBattBuff.getVals();
|
||||||
|
if (Objects.nonNull(mConnection.mSdServer.mSdData.watchBattBuff) && nWatchBattArr > 0) {
|
||||||
|
Log.v(TAG, "hrWatchBattBuff.getNumVals=" + nWatchBattArr);
|
||||||
|
lineDataSet.clear();
|
||||||
|
String xVals[] = new String[nWatchBattArr];
|
||||||
|
for (int i = 0; i < nWatchBattArr; i++) {
|
||||||
|
//Log.d(TAG,"i="+i+", HR="+hrHistArr[i]);
|
||||||
|
xVals[i] = String.valueOf(i);
|
||||||
|
lineDataSet.addEntry(new Entry((float) watchBattArr[i], i));
|
||||||
|
}
|
||||||
|
Log.d(TAG, "xVals=" + Arrays.toString(xVals) + ", lneDataSet=" + lineDataSet.toSimpleString());
|
||||||
|
lineDataSet.setColors(new int[]{0xffff0000});
|
||||||
|
LineData watchBattHistLineData = new LineData(xVals, lineDataSet);
|
||||||
|
|
||||||
|
|
||||||
|
mLineChart.setData(watchBattHistLineData);
|
||||||
|
mLineChart.getData().notifyDataChanged();
|
||||||
|
mLineChart.notifyDataSetChanged();
|
||||||
|
mLineChart.refreshDrawableState();
|
||||||
|
float xSpan = (nWatchBattArr * 5.0f) / 60.0f; // time in minutes assuming one point every 5 seconds.
|
||||||
|
mLineChart.setDescription(getString(R.string.watch_batt_hist)
|
||||||
|
+ String.format("%.1f", xSpan)
|
||||||
|
+ " " + getString(R.string.minutes));
|
||||||
|
mLineChart.setDescriptionTextSize(12f);
|
||||||
|
mLineChart.invalidate();
|
||||||
|
//if (mConnection.mBound){
|
||||||
|
// lineChart.postInvalidate();
|
||||||
|
//}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -26,7 +26,7 @@ import java.util.Objects;
|
|||||||
|
|
||||||
|
|
||||||
public class FragmentHrAlg extends FragmentOsdBaseClass {
|
public class FragmentHrAlg extends FragmentOsdBaseClass {
|
||||||
String TAG = "FragmentOsdAlg";
|
String TAG = "FragmentHrAlg";
|
||||||
|
|
||||||
LineChart mLineChart;
|
LineChart mLineChart;
|
||||||
LineData lineData;
|
LineData lineData;
|
||||||
|
|||||||
@@ -295,7 +295,7 @@ public class MainActivity2 extends AppCompatActivity {
|
|||||||
case 1:
|
case 1:
|
||||||
return new FragmentHrAlg();
|
return new FragmentHrAlg();
|
||||||
case 2:
|
case 2:
|
||||||
return new FragmentMlAlg();
|
return new FragmentBatt();
|
||||||
case 3:
|
case 3:
|
||||||
return new FragmentSystem();
|
return new FragmentSystem();
|
||||||
case 4:
|
case 4:
|
||||||
|
|||||||
@@ -67,6 +67,9 @@ public class SdData implements Parcelable {
|
|||||||
public long batteryPc; // watch battery
|
public long batteryPc; // watch battery
|
||||||
public int phoneBatteryPc;
|
public int phoneBatteryPc;
|
||||||
|
|
||||||
|
public CircBuf watchBattBuff = new CircBuf(24*3600/5, -1); // 24 hour buffer
|
||||||
|
public CircBuf phoneBattBuff = new CircBuf(24*3600/5, -1); // 24 hour buffer
|
||||||
|
|
||||||
/* Heart Rate Alarm Settings */
|
/* Heart Rate Alarm Settings */
|
||||||
public boolean mHRAlarmActive = false;
|
public boolean mHRAlarmActive = false;
|
||||||
public boolean mHRNullAsAlarm = false;
|
public boolean mHRNullAsAlarm = false;
|
||||||
@@ -166,6 +169,7 @@ public class SdData implements Parcelable {
|
|||||||
specPower = jo.optInt("specPower");
|
specPower = jo.optInt("specPower");
|
||||||
roiPower = jo.optInt("roiPower");
|
roiPower = jo.optInt("roiPower");
|
||||||
batteryPc = jo.optInt("batteryPc");
|
batteryPc = jo.optInt("batteryPc");
|
||||||
|
watchBattBuff.add(batteryPc);
|
||||||
watchConnected = jo.optBoolean("watchConnected");
|
watchConnected = jo.optBoolean("watchConnected");
|
||||||
watchAppRunning = jo.optBoolean("watchAppRunning");
|
watchAppRunning = jo.optBoolean("watchAppRunning");
|
||||||
alarmState = jo.optInt("alarmState");
|
alarmState = jo.optInt("alarmState");
|
||||||
|
|||||||
@@ -360,6 +360,7 @@ public abstract class SdDataSource {
|
|||||||
mSamplePeriod = (short) dataObject.getInt("analysisPeriod");
|
mSamplePeriod = (short) dataObject.getInt("analysisPeriod");
|
||||||
mSampleFreq = (short) dataObject.getInt("sampleFreq");
|
mSampleFreq = (short) dataObject.getInt("sampleFreq");
|
||||||
mSdData.batteryPc = (short) dataObject.getInt("battery");
|
mSdData.batteryPc = (short) dataObject.getInt("battery");
|
||||||
|
mSdData.watchBattBuff.add(mSdData.batteryPc);
|
||||||
|
|
||||||
Log.v(TAG, "updateFromJSON - mSamplePeriod=" + mSamplePeriod + " mSampleFreq=" + mSampleFreq);
|
Log.v(TAG, "updateFromJSON - mSamplePeriod=" + mSamplePeriod + " mSampleFreq=" + mSampleFreq);
|
||||||
mUtil.writeToSysLogFile("SDDataSource.updateFromJSON - Settings Received");
|
mUtil.writeToSysLogFile("SDDataSource.updateFromJSON - Settings Received");
|
||||||
@@ -443,6 +444,7 @@ public abstract class SdDataSource {
|
|||||||
double[] fft = null;
|
double[] fft = null;
|
||||||
// Update phone battery level - it is done here so it is called for all data sources.
|
// Update phone battery level - it is done here so it is called for all data sources.
|
||||||
mSdData.phoneBatteryPc = getPhoneBatteryLevel();
|
mSdData.phoneBatteryPc = getPhoneBatteryLevel();
|
||||||
|
mSdData.phoneBattBuff.add(mSdData.phoneBatteryPc);
|
||||||
try {
|
try {
|
||||||
// FIXME - Use specified sampleFreq, not this hard coded one
|
// FIXME - Use specified sampleFreq, not this hard coded one
|
||||||
mSampleFreq = 25;
|
mSampleFreq = 25;
|
||||||
|
|||||||
31
app/src/main/res/layout/fragment_batt.xml
Normal file
31
app/src/main/res/layout/fragment_batt.xml
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
tools:context=".FragmentOsdBaseClass">
|
||||||
|
|
||||||
|
<androidx.appcompat.widget.LinearLayoutCompat
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:background="@color/okBackgroundColor"
|
||||||
|
android:orientation="vertical">
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:text="@string/battery_history"
|
||||||
|
android:textColor="@color/okTextColor" />
|
||||||
|
|
||||||
|
|
||||||
|
<com.github.mikephil.charting.charts.LineChart
|
||||||
|
android:id="@+id/lineChart"
|
||||||
|
android:layout_width="fill_parent"
|
||||||
|
android:layout_height="fill_parent">
|
||||||
|
|
||||||
|
</com.github.mikephil.charting.charts.LineChart>
|
||||||
|
|
||||||
|
</androidx.appcompat.widget.LinearLayoutCompat>
|
||||||
|
|
||||||
|
|
||||||
|
</FrameLayout>
|
||||||
@@ -566,4 +566,6 @@
|
|||||||
<string name="heart_rate_history_bpm">"Heart Rate History (bpm): "</string>
|
<string name="heart_rate_history_bpm">"Heart Rate History (bpm): "</string>
|
||||||
<string name="minutes">minutes</string>
|
<string name="minutes">minutes</string>
|
||||||
<string name="algorithms">"Algorithms: "</string>
|
<string name="algorithms">"Algorithms: "</string>
|
||||||
|
<string name="battery_history">Battery History</string>
|
||||||
|
<string name="watch_batt_hist">Watch Battery History (%)</string>
|
||||||
</resources>
|
</resources>
|
||||||
|
|||||||
Reference in New Issue
Block a user