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