Commit 57a3af64 authored by haukda60920's avatar haukda60920
Browse files

chart for humidity

parent 14f7b782
......@@ -14,10 +14,6 @@
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity
android:name=".control.SettingsActivity"
android:label="@string/title_activity_settings">
</activity>
adb<activity
android:name=".MainActivity"
android:label="@string/app_name">
<intent-filter>
......
......@@ -2,14 +2,14 @@ package com.history
import android.annotation.SuppressLint
import android.content.Context
import android.graphics.Color
import android.util.Log
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.BaseAdapter
import com.example.hbox.history.axisStyler.HumidityAxisStyler
import com.example.hbox.history.axisStyler.TemperatureAxisStyler
import com.example.hbox.history.dataSetStyler.TemperaturDataSetStyler
import com.example.hbox.history.dataSetStyler.HumidityDataSetStyler
import com.example.hbox.history.dataSetStyler.TemperatureDataSetStyler
import com.example.hbox.history.limitLinesFormatter.WeekdayLimitLinesCreator
import com.github.mikephil.charting.charts.LineChart
import com.github.mikephil.charting.data.Entry
......@@ -33,15 +33,29 @@ class ChartListViewAdapter(private val context: Context, private val sensorList:
sensorList[position].data?.forEach {
entries.add(Entry(it.date.toFloat(), it.value))
}
// style dataset
val lineDataSet = LineDataSet(entries, sensorList[position].name)
TemperaturDataSetStyler.styleDataSet(lineDataSet)
// style axis
TemperatureAxisStyler.styleXAxis(view.xAxis)
TemperatureAxisStyler.styleYAxisLeft(view.axisLeft)
TemperatureAxisStyler.styleYAxisRight(view.axisRight)
when(sensorList[position].type) {
"temperature" -> {
// style dataset
TemperatureDataSetStyler.styleDataSet(lineDataSet)
// style axis
TemperatureAxisStyler.styleXAxis(view.xAxis)
TemperatureAxisStyler.styleYAxisLeft(view.axisLeft)
TemperatureAxisStyler.styleYAxisRight(view.axisRight)
}
"humidity" -> {
// style dataset
HumidityDataSetStyler.styleDataSet(lineDataSet)
// style axis
HumidityAxisStyler.styleXAxis(view.xAxis)
HumidityAxisStyler.styleYAxisLeft(view.axisLeft)
HumidityAxisStyler.styleYAxisRight(view.axisRight)
}
}
// add weekdays
WeekdayLimitLinesCreator.create(view.xAxis, sensorList[position])
......
......@@ -13,7 +13,6 @@ import com.google.gson.Gson
import com.history.ChartListViewAdapter
import com.history.History
import com.history.Sensor
import org.json.JSONObject
import java.net.HttpURLConnection
import java.net.URL
......
package com.example.hbox.history.axisFormatter
import com.github.mikephil.charting.components.AxisBase
import com.github.mikephil.charting.formatter.IAxisValueFormatter
import java.text.DecimalFormat
class HumidityFormatter : IAxisValueFormatter {
override fun getFormattedValue(value: Float, axis: AxisBase?): String {
val df = DecimalFormat("#")
//df.roundingMode = RoundingMode.CEILING
return df.format(value) + " %"
}
}
\ No newline at end of file
......@@ -2,10 +2,9 @@ package com.example.hbox.history.axisFormatter
import com.github.mikephil.charting.components.AxisBase
import com.github.mikephil.charting.formatter.IAxisValueFormatter
import com.github.mikephil.charting.utils.ColorTemplate
import java.text.DecimalFormat
class NullDigitsFormatter : IAxisValueFormatter {
class TemperatureFormatter : IAxisValueFormatter {
override fun getFormattedValue(value: Float, axis: AxisBase?): String {
val df = DecimalFormat("#")
......
package com.example.hbox.history.axisStyler
import android.graphics.Color
import com.example.hbox.history.axisFormatter.HumidityFormatter
import com.example.hbox.history.axisFormatter.TemperatureFormatter
import com.example.hbox.history.axisFormatter.TimeFormatter
import com.github.mikephil.charting.components.XAxis
import com.github.mikephil.charting.components.YAxis
class HumidityAxisStyler {
companion object {
fun styleXAxis(xAxis: XAxis) : XAxis {
xAxis.position = XAxis.XAxisPosition.BOTTOM
return xAxis.apply {
valueFormatter = TimeFormatter()
setDrawAxisLine(false)
setDrawGridLines(false)
setDrawLimitLinesBehindData(true)
textSize = 14f
}
}
fun styleYAxisRight(yAxis: YAxis) : YAxis {
return yAxis.apply {
setDrawAxisLine(false)
setDrawLabels(false)
setDrawGridLines(false)
}
}
fun styleYAxisLeft(yAxis: YAxis) : YAxis {
return yAxis.apply {
setDrawAxisLine(false)
textSize = 14f
valueFormatter = HumidityFormatter()
axisMinimum = 20f
axisMaximum = 90f
setDrawGridLines(true)
gridColor = Color.DKGRAY
setLabelCount(8,true)
}
}
}
}
\ No newline at end of file
package com.example.hbox.history.axisStyler
import android.graphics.Color
import com.example.hbox.history.axisFormatter.NullDigitsFormatter
import com.example.hbox.history.axisFormatter.TemperatureFormatter
import com.example.hbox.history.axisFormatter.TimeFormatter
import com.github.mikephil.charting.components.XAxis
import com.github.mikephil.charting.components.YAxis
......@@ -31,7 +31,7 @@ class TemperatureAxisStyler {
return yAxis.apply {
setDrawAxisLine(false)
textSize = 14f
valueFormatter = NullDigitsFormatter()
valueFormatter = TemperatureFormatter()
axisMinimum = 16f
axisMaximum = 32f
setDrawGridLines(true)
......
package com.example.hbox.history.dataSetStyler
import android.graphics.Color
import com.github.mikephil.charting.data.LineDataSet
class HumidityDataSetStyler {
companion object {
fun styleDataSet (lineDataSet : LineDataSet) : LineDataSet {
return lineDataSet.apply{
lineWidth = 0f
color = Color.argb(255,15,15,255)
fillColor = Color.argb(255,15,15,255)
fillAlpha = 100
mode = LineDataSet.Mode.CUBIC_BEZIER
setDrawFilled(true)
setDrawCircles(false)
setDrawValues(false)
}
}
}
}
\ No newline at end of file
......@@ -3,7 +3,7 @@ package com.example.hbox.history.dataSetStyler
import android.graphics.Color
import com.github.mikephil.charting.data.LineDataSet
class TemperaturDataSetStyler {
class TemperatureDataSetStyler {
companion object {
fun styleDataSet (lineDataSet : LineDataSet) : LineDataSet {
return lineDataSet.apply{
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment