Formatted HR history graph
This commit is contained in:
@@ -11,11 +11,14 @@ import android.widget.TextView;
|
|||||||
import androidx.appcompat.widget.SwitchCompat;
|
import androidx.appcompat.widget.SwitchCompat;
|
||||||
|
|
||||||
import com.github.mikephil.charting.charts.LineChart;
|
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.Entry;
|
||||||
import com.github.mikephil.charting.data.LineData;
|
import com.github.mikephil.charting.data.LineData;
|
||||||
import com.github.mikephil.charting.data.LineDataSet;
|
import com.github.mikephil.charting.data.LineDataSet;
|
||||||
import com.github.mikephil.charting.utils.ColorTemplate;
|
import com.github.mikephil.charting.utils.ValueFormatter;
|
||||||
|
|
||||||
|
import java.text.DecimalFormat;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@@ -25,7 +28,7 @@ import java.util.Objects;
|
|||||||
public class FragmentHrAlg extends FragmentOsdBaseClass {
|
public class FragmentHrAlg extends FragmentOsdBaseClass {
|
||||||
String TAG = "FragmentOsdAlg";
|
String TAG = "FragmentOsdAlg";
|
||||||
|
|
||||||
LineChart lineChart;
|
LineChart mLineChart;
|
||||||
LineData lineData;
|
LineData lineData;
|
||||||
LineDataSet lineDataSet;
|
LineDataSet lineDataSet;
|
||||||
List<Entry> hrHistory = new ArrayList<>();
|
List<Entry> hrHistory = new ArrayList<>();
|
||||||
@@ -50,10 +53,12 @@ public class FragmentHrAlg extends FragmentOsdBaseClass {
|
|||||||
public void onCreate(Bundle savedInstanceState) {
|
public void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
lineDataSet = new LineDataSet(new ArrayList<Entry>(),"Heart rate history" );
|
lineDataSet = new LineDataSet(new ArrayList<Entry>(),"Heart rate history" );
|
||||||
lineDataSet.setColors(ColorTemplate.JOYFUL_COLORS);
|
//lineDataSet.setColors(ColorTemplate.JOYFUL_COLORS);
|
||||||
lineDataSet.setValueTextColor(Color.BLACK);
|
lineDataSet.setValueTextColor(Color.BLACK);
|
||||||
lineDataSet.setValueTextSize(18f);
|
lineDataSet.setValueTextSize(18f);
|
||||||
lineDataSet.setDrawValues(false);
|
lineDataSet.setDrawValues(false);
|
||||||
|
lineDataSet.setCircleSize(0f);
|
||||||
|
lineDataSet.setLineWidth(3f);
|
||||||
//lineDataSetAverage = new LineDataSet(new ArrayList<Entry>(),"Heart rate history" );
|
//lineDataSetAverage = new LineDataSet(new ArrayList<Entry>(),"Heart rate history" );
|
||||||
//lineDataSetAverage.setColors(ColorTemplate.JOYFUL_COLORS);
|
//lineDataSetAverage.setColors(ColorTemplate.JOYFUL_COLORS);
|
||||||
//lineDataSetAverage.setValueTextColor(Color.BLACK);
|
//lineDataSetAverage.setValueTextColor(Color.BLACK);
|
||||||
@@ -61,6 +66,38 @@ public class FragmentHrAlg extends FragmentOsdBaseClass {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onResume() {
|
||||||
|
super.onResume();
|
||||||
|
mLineChart = mRootView.findViewById(R.id.lineChart);
|
||||||
|
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
|
@Override
|
||||||
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
||||||
Bundle savedInstanceState) {
|
Bundle savedInstanceState) {
|
||||||
@@ -85,17 +122,16 @@ public class FragmentHrAlg extends FragmentOsdBaseClass {
|
|||||||
tvAvgAHr.setText( String.valueOf((short)mConnection.mSdServer.mSdData
|
tvAvgAHr.setText( String.valueOf((short)mConnection.mSdServer.mSdData
|
||||||
.mAdaptiveHrAverage));
|
.mAdaptiveHrAverage));
|
||||||
tvCurrent.setText(new StringBuilder()
|
tvCurrent.setText(new StringBuilder()
|
||||||
.append(mConnection.mSdServer.mSdData.mAdaptiveHrAverage)
|
|
||||||
.append("\nResult of checks: Adaptive Hr Alarm Standing: ")
|
.append("\nResult of checks: Adaptive Hr Alarm Standing: ")
|
||||||
.append(mConnection.mSdServer.mSdData.mAdaptiveHrAlarmStanding)
|
.append(mConnection.mSdServer.mSdData.mAdaptiveHrAlarmStanding)
|
||||||
.append("\nAverage Hr Alarm Standing: ")
|
.append("\nAverage Hr Alarm Standing: ")
|
||||||
.append(mConnection.mSdServer.mSdData.mAdaptiveHrAlarmStanding)
|
.append(mConnection.mSdServer.mSdData.mAdaptiveHrAlarmStanding)
|
||||||
.toString());
|
.toString());
|
||||||
|
|
||||||
switchAverages = mRootView.findViewById(R.id.hr_average_switch);
|
//switchAverages = mRootView.findViewById(R.id.hr_average_switch);
|
||||||
|
|
||||||
if (Objects.nonNull(mConnection.mSdServer.mSdDataSource.mSdAlgHr)) {
|
if (Objects.nonNull(mConnection.mSdServer.mSdDataSource.mSdAlgHr)) {
|
||||||
Log.v(TAG,"mSdAlgHr si not null");
|
//Log.v(TAG,"mSdAlgHr is not null");
|
||||||
CircBuf hrHist = mConnection.mSdServer.mSdDataSource.mSdAlgHr.getHrHistBuff();
|
CircBuf hrHist = mConnection.mSdServer.mSdDataSource.mSdAlgHr.getHrHistBuff();
|
||||||
int nHistArr = hrHist.getNumVals();
|
int nHistArr = hrHist.getNumVals();
|
||||||
double hrHistArr[] = hrHist.getVals(); // This gives us a simple vector of hr values to plot.
|
double hrHistArr[] = hrHist.getVals(); // This gives us a simple vector of hr values to plot.
|
||||||
@@ -104,20 +140,22 @@ public class FragmentHrAlg extends FragmentOsdBaseClass {
|
|||||||
lineDataSet.clear();
|
lineDataSet.clear();
|
||||||
String xVals[] = new String[nHistArr];
|
String xVals[] = new String[nHistArr];
|
||||||
for (int i = 0; i<nHistArr; i++) {
|
for (int i = 0; i<nHistArr; i++) {
|
||||||
Log.d(TAG,"i="+i+", HR="+hrHistArr[i]);
|
//Log.d(TAG,"i="+i+", HR="+hrHistArr[i]);
|
||||||
xVals[i] = String.valueOf(i);
|
xVals[i] = String.valueOf(i);
|
||||||
lineDataSet.addEntry(new Entry((float)hrHistArr[i], i));
|
lineDataSet.addEntry(new Entry((float)hrHistArr[i], i));
|
||||||
}
|
}
|
||||||
Log.d(TAG,"xVals="+ Arrays.toString(xVals)+ ", lneDataSet="+lineDataSet.toSimpleString());
|
Log.d(TAG,"xVals="+ Arrays.toString(xVals)+ ", lneDataSet="+lineDataSet.toSimpleString());
|
||||||
|
lineDataSet.setColors(new int[] {0xffff0000});
|
||||||
LineData hrHistLineData = new LineData(xVals, lineDataSet);
|
LineData hrHistLineData = new LineData(xVals, lineDataSet);
|
||||||
|
|
||||||
lineChart = mRootView.findViewById(R.id.lineChart);
|
|
||||||
lineChart.setData(hrHistLineData);
|
|
||||||
|
|
||||||
lineChart.getData().notifyDataChanged();
|
mLineChart.setData(hrHistLineData);
|
||||||
lineChart.notifyDataSetChanged();
|
mLineChart.getData().notifyDataChanged();
|
||||||
lineChart.refreshDrawableState();
|
mLineChart.notifyDataSetChanged();
|
||||||
lineChart.invalidate();
|
mLineChart.refreshDrawableState();
|
||||||
|
float xSpan = (nHistArr * 5.0f)/60.0f; // time in minutes assuming one point every 5 seconds.
|
||||||
|
mLineChart.setDescription("Heart Ratee History - "+String.format("%.1f", xSpan)+" minutes");
|
||||||
|
mLineChart.invalidate();
|
||||||
//if (mConnection.mBound){
|
//if (mConnection.mBound){
|
||||||
// lineChart.postInvalidate();
|
// lineChart.postInvalidate();
|
||||||
//}
|
//}
|
||||||
|
|||||||
@@ -26,6 +26,7 @@ import android.widget.TextView;
|
|||||||
|
|
||||||
import com.rohitss.uceh.UCEHandler;
|
import com.rohitss.uceh.UCEHandler;
|
||||||
|
|
||||||
|
import java.util.Objects;
|
||||||
import java.util.Timer;
|
import java.util.Timer;
|
||||||
import java.util.TimerTask;
|
import java.util.TimerTask;
|
||||||
|
|
||||||
@@ -144,7 +145,7 @@ public class MainActivity2 extends AppCompatActivity {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onBackPressed() {
|
public void onBackPressed() {
|
||||||
if (mFragmentPager.getCurrentItem() == 0) {
|
if (Objects.isNull(mFragmentPager) || mFragmentPager.getCurrentItem() == 0) {
|
||||||
// If the user is currently looking at the first step, allow the system to handle the
|
// If the user is currently looking at the first step, allow the system to handle the
|
||||||
// Back button. This calls finish() on this activity and pops the back stack.
|
// Back button. This calls finish() on this activity and pops the back stack.
|
||||||
super.onBackPressed();
|
super.onBackPressed();
|
||||||
|
|||||||
@@ -11,7 +11,12 @@
|
|||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
android:background="@color/okBackgroundColor"
|
android:background="@color/okBackgroundColor"
|
||||||
android:orientation="vertical">
|
android:orientation="vertical">
|
||||||
<!-- TODO: Update blank fragment layout -->
|
<TextView
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:text="@string/heart_rate_algorithm"
|
||||||
|
android:textColor="@color/okTextColor"/>
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:id="@+id/fragment_hr_alg_tv1"
|
android:id="@+id/fragment_hr_alg_tv1"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
@@ -65,27 +70,22 @@
|
|||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:text=" bpm"
|
android:text=" bpm"
|
||||||
android:textColor="@color/okTextColor" />
|
android:textColor="@color/okTextColor" />
|
||||||
|
|
||||||
|
|
||||||
</androidx.appcompat.widget.LinearLayoutCompat>
|
</androidx.appcompat.widget.LinearLayoutCompat>
|
||||||
|
|
||||||
<TextView
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:text="Fragment_HrAlg" />
|
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:id="@+id/textView2"
|
android:id="@+id/textView2"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:text="TextView" />
|
android:text="TextView"
|
||||||
|
android:textColor="@color/okTextColor"/>
|
||||||
|
<!--
|
||||||
<androidx.appcompat.widget.SwitchCompat
|
<androidx.appcompat.widget.SwitchCompat
|
||||||
android:id="@+id/hr_average_switch"
|
android:id="@+id/hr_average_switch"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:text="Show averages" />
|
android:text="Show averages"
|
||||||
|
android:textColor="@color/okTextColor"/>
|
||||||
|
-->
|
||||||
<FrameLayout
|
<FrameLayout
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent">
|
android:layout_height="match_parent">
|
||||||
|
|||||||
@@ -562,4 +562,5 @@
|
|||||||
<string name="hello_blank_fragment">Hello blank fragment</string>
|
<string name="hello_blank_fragment">Hello blank fragment</string>
|
||||||
<string name="use_new_ui_summary">Use new swipeable user interface</string>
|
<string name="use_new_ui_summary">Use new swipeable user interface</string>
|
||||||
<string name="use_new_ui_title">Use New User Interface</string>
|
<string name="use_new_ui_title">Use New User Interface</string>
|
||||||
|
<string name="heart_rate_algorithm">Heart Rate Algorithm</string>
|
||||||
</resources>
|
</resources>
|
||||||
|
|||||||
Reference in New Issue
Block a user