From 4a1c21e5dc9c6bf2b52f5364761aadb15c3bba84 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Albin=20Eldst=C3=A5l-Damlin?= Date: Mon, 3 Oct 2016 23:06:33 +0200 Subject: [PATCH] Issue #34: Numerical label on graph --- .../activities/GraphingActivity.java | 32 +++++- app/src/main/res/layout/activity_graphing.xml | 105 +++++++++++++----- 2 files changed, 109 insertions(+), 28 deletions(-) diff --git a/app/src/main/java/com/mooshim/mooshimeter/activities/GraphingActivity.java b/app/src/main/java/com/mooshim/mooshimeter/activities/GraphingActivity.java index 2d11cf0..a5806d5 100644 --- a/app/src/main/java/com/mooshim/mooshimeter/activities/GraphingActivity.java +++ b/app/src/main/java/com/mooshim/mooshimeter/activities/GraphingActivity.java @@ -15,6 +15,7 @@ import android.view.WindowManager; import android.widget.Button; import android.widget.PopupWindow; +import android.widget.TextView; import android.widget.Toast; import com.mooshim.mooshimeter.R; @@ -73,6 +74,11 @@ public enum ChDispModes { LineChartView[] mChart={null,null}; Axis xAxis, yAxisLeft, yAxisRight; + TextView[] mChartLabel = {null, null}; + MooshimeterDeviceBase.Channel[] mChannel = {MooshimeterDeviceBase.Channel.CH1, + MooshimeterDeviceBase.Channel.CH2}; + + private String[] labelUnits = {"", ""}; private Timer refresh_timer = new Timer(); @@ -94,7 +100,6 @@ public enum ChDispModes { /////////////////////// // HELPER VARS /////////////////////// - //Create lists for storing actual value of points that are visible on the screen for both axises PointArrayWrapper[] axisValueHelpers={null,null}; @@ -223,6 +228,25 @@ protected void onCreate(Bundle savedInstanceState) { axisValueHelpers[1] = new PointArrayWrapper(); axisValueHelpers = new PointArrayWrapper[]{axisValueHelpers[0], axisValueHelpers[1]}; + // Labels below the charts + mChartLabel[0] = (TextView) findViewById(R.id.chart_label_1); + mChartLabel[1] = (TextView) findViewById(R.id.chart_label_2); + for (int i = 0; i < 2; i++) { + mChartLabel[i].setTextColor(mColorList[i]); + + // Figure out a good string representation of the channel's units + labelUnits[i] = mMeter.getSelectedDescriptor(mChannel[i]).units; + if(labelUnits.equals("K")) { + // The values have actually been converted to whatever the user set in preferences, + // it's just the string label that indicates Kelvin. + if (Util.getPreferenceBoolean(Util.preference_keys.USE_FAHRENHEIT)) { + labelUnits[i] = "F"; + } else { + labelUnits[i] = "C"; + } + } + } + time_start = Util.getNanoTime(); } @@ -445,6 +469,12 @@ public void onRefreshButton(View v) { private void setLineValues(int i,Listdata) { mChart[i].getLineChartData().getLines().get(0).setValues(data); + + String label = "NO VALUE"; + if (data.size() > 0) { + label = "" + data.get(data.size() - 1).getY() + labelUnits[i]; + } + mChartLabel[i].setText(label); } @Override diff --git a/app/src/main/res/layout/activity_graphing.xml b/app/src/main/res/layout/activity_graphing.xml index 2cd8f95..f877492 100644 --- a/app/src/main/res/layout/activity_graphing.xml +++ b/app/src/main/res/layout/activity_graphing.xml @@ -1,20 +1,10 @@ - - - + android:layout_marginEnd="10dp" /> -