Skip to content

Commit

Permalink
Issue mooshim#34: Numerical label on graph
Browse files Browse the repository at this point in the history
  • Loading branch information
eldstal committed Oct 3, 2016
1 parent 854ba5f commit b85aa5f
Show file tree
Hide file tree
Showing 2 changed files with 109 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();

Expand All @@ -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};

Expand Down Expand Up @@ -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();
}

Expand Down Expand Up @@ -445,6 +469,12 @@ public void onRefreshButton(View v) {

private void setLineValues(int i,List<PointValue>data) {
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
Expand Down
105 changes: 78 additions & 27 deletions app/src/main/res/layout/activity_graphing.xml
Original file line number Diff line number Diff line change
@@ -1,20 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent">

<lecho.lib.hellocharts.view.LineChartView
android:id="@+id/lineChart1"
android:layout_width="match_parent"
android:layout_height="match_parent"
/>
<lecho.lib.hellocharts.view.LineChartView
android:id="@+id/lineChart2"
android:layout_width="match_parent"
android:layout_height="match_parent"
/>

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
Expand All @@ -31,25 +21,86 @@
android:background="#80000000"
android:padding="4dp"
android:text="REFRESH"
android:layout_marginEnd="16dp" />
android:layout_marginEnd="10dp" />
</LinearLayout>

<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="right"
android:layout_marginBottom="4dp"
android:layout_gravity="bottom">
<Button
android:id="@+id/config_btn"
android:onClick="onConfigButton"
android:layout_width="wrap_content"
android:layout_height="34dp"
android:textColor="@android:color/white"
android:background="#80000000"
android:padding="4dp"
android:text="CONFIG"
android:layout_marginEnd="16dp"/>
android:layout_height="match_parent">

<FrameLayout
android:id="@+id/all_charts"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="10">

<lecho.lib.hellocharts.view.LineChartView
android:id="@+id/lineChart2"
android:layout_width="match_parent"
android:layout_height="match_parent"
/>

<lecho.lib.hellocharts.view.LineChartView
android:id="@+id/lineChart1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="top" />

</FrameLayout>

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="left"
android:layout_marginBottom="4dp"
android:layout_weight="0"
android:orientation="horizontal"
android:layout_gravity="bottom">

<RelativeLayout
android:id="@+id/chart_labels"
android:orientation="horizontal"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:layout_weight="10">

<TextView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:id="@+id/chart_label_1"
android:layout_alignParentLeft="true"
android:textSize="25dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:id="@+id/chart_label_2"
android:layout_alignParentRight="true"
android:textSize="25dp" />
</RelativeLayout>

<Button
android:id="@+id/config_btn"
android:onClick="onConfigButton"
android:layout_width="wrap_content"
android:layout_height="34dp"
android:textColor="@android:color/white"
android:background="#80000000"
android:padding="4dp"
android:text="CONFIG"
android:gravity="right"
android:layout_marginEnd="10dp"/>

</LinearLayout>

</LinearLayout>

<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">

</LinearLayout>

Expand Down

0 comments on commit b85aa5f

Please sign in to comment.