add text in the circles that will update as listenForData gets data
This commit is contained in:
parent
45a2376d86
commit
1f7458c806
@ -4,7 +4,6 @@ import android.Manifest
|
||||
import android.bluetooth.BluetoothAdapter
|
||||
import android.bluetooth.BluetoothDevice
|
||||
import android.bluetooth.BluetoothSocket
|
||||
import android.content.Context
|
||||
import android.content.pm.PackageManager
|
||||
import android.os.Bundle
|
||||
import android.util.Log
|
||||
@ -26,6 +25,7 @@ import java.text.SimpleDateFormat
|
||||
import java.util.*
|
||||
import android.graphics.Color
|
||||
import androidx.core.content.ContextCompat
|
||||
import android.widget.TextView
|
||||
|
||||
class MainActivity : AppCompatActivity() {
|
||||
|
||||
@ -44,6 +44,9 @@ class MainActivity : AppCompatActivity() {
|
||||
|
||||
private lateinit var lineChart: LineChart
|
||||
|
||||
private lateinit var tempCircle: TextView
|
||||
private lateinit var humCircle: TextView
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
enableEdgeToEdge()
|
||||
@ -54,6 +57,9 @@ class MainActivity : AppCompatActivity() {
|
||||
lineChart = findViewById(R.id.Chart)
|
||||
setupChart()
|
||||
|
||||
tempCircle = findViewById(R.id.temp_circle)
|
||||
humCircle = findViewById(R.id.hum_circle)
|
||||
|
||||
bluetoothManager = getSystemService(BLUETOOTH_SERVICE) as android.bluetooth.BluetoothManager
|
||||
bluetoothAdapter = bluetoothManager.adapter
|
||||
if (bluetoothAdapter == null) {
|
||||
@ -130,6 +136,8 @@ class MainActivity : AppCompatActivity() {
|
||||
Log.d(tag, "Store: $reading")
|
||||
|
||||
runOnUiThread {
|
||||
tempCircle.text = getString(R.string.temp_format, temp)
|
||||
humCircle.text = getString(R.string.hum_format, hum)
|
||||
updateChartData()
|
||||
}
|
||||
|
||||
|
||||
@ -18,7 +18,7 @@
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent" />
|
||||
|
||||
<View
|
||||
<TextView
|
||||
android:id="@+id/temp_circle"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="120dp"
|
||||
@ -27,13 +27,18 @@
|
||||
android:layout_marginStart="0dp"
|
||||
android:layout_marginEnd="0dp"
|
||||
android:background="@drawable/temp_circle"
|
||||
android:gravity="center"
|
||||
android:text="--°C"
|
||||
android:textColor="@android:color/white"
|
||||
android:textSize="18sp"
|
||||
android:textStyle="bold"
|
||||
app:layout_constraintTop_toBottomOf="@+id/connect_btn"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintEnd_toStartOf="@+id/hum_circle"
|
||||
app:layout_constraintHorizontal_chainStyle="spread"
|
||||
app:layout_constraintBottom_toBottomOf="@+id/hum_circle" />
|
||||
|
||||
<View
|
||||
<TextView
|
||||
android:id="@+id/hum_circle"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="120dp"
|
||||
@ -42,6 +47,11 @@
|
||||
android:layout_marginStart="0dp"
|
||||
android:layout_marginEnd="0dp"
|
||||
android:background="@drawable/hum_circle"
|
||||
android:gravity="center"
|
||||
android:text="--%"
|
||||
android:textColor="@android:color/white"
|
||||
android:textSize="18sp"
|
||||
android:textStyle="bold"
|
||||
app:layout_constraintTop_toBottomOf="@+id/connect_btn"
|
||||
app:layout_constraintStart_toEndOf="@+id/temp_circle"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
|
||||
@ -1,5 +1,9 @@
|
||||
<resources>
|
||||
<string name="app_name" translatable="false">I2D_Project_15_app</string>
|
||||
|
||||
<string name="connect_btn">Connect to HC-05</string>
|
||||
<string name="connected">Connected to HC-05</string>
|
||||
|
||||
<string name="temp_format" translatable="false">%.1f°C</string>
|
||||
<string name="hum_format" translatable="false">%.1f%%</string>
|
||||
</resources>
|
||||
Loading…
Reference in New Issue
Block a user