Compare commits
3 Commits
4a4c5893af
...
cd0d94215d
| Author | SHA1 | Date | |
|---|---|---|---|
| cd0d94215d | |||
| 1f7458c806 | |||
| 45a2376d86 |
@ -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()
|
||||
}
|
||||
|
||||
|
||||
5
app/src/main/res/drawable/hum_circle.xml
Normal file
5
app/src/main/res/drawable/hum_circle.xml
Normal file
@ -0,0 +1,5 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<shape xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:shape="oval">
|
||||
<solid android:color="#0000FF"/>
|
||||
</shape>
|
||||
5
app/src/main/res/drawable/temp_circle.xml
Normal file
5
app/src/main/res/drawable/temp_circle.xml
Normal file
@ -0,0 +1,5 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<shape xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:shape="oval">
|
||||
<solid android:color="#FF0000"/>
|
||||
</shape>
|
||||
@ -18,6 +18,45 @@
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/temp_circle"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="120dp"
|
||||
app:layout_constraintDimensionRatio="1:1"
|
||||
android:layout_marginTop="16dp"
|
||||
android:layout_marginStart="0dp"
|
||||
android:layout_marginEnd="0dp"
|
||||
android:background="@drawable/temp_circle"
|
||||
android:gravity="center"
|
||||
android:text="@string/default_temp_text"
|
||||
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" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/hum_circle"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="120dp"
|
||||
app:layout_constraintDimensionRatio="1:1"
|
||||
android:layout_marginTop="16dp"
|
||||
android:layout_marginStart="0dp"
|
||||
android:layout_marginEnd="0dp"
|
||||
android:background="@drawable/hum_circle"
|
||||
android:gravity="center"
|
||||
android:text="@string/default_hum_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"
|
||||
app:layout_constraintBottom_toBottomOf="@+id/temp_circle" />
|
||||
|
||||
<com.github.mikephil.charting.charts.LineChart
|
||||
android:id="@+id/Chart"
|
||||
android:layout_width="0dp"
|
||||
@ -26,7 +65,7 @@
|
||||
android:layout_marginStart="16dp"
|
||||
android:layout_marginEnd="16dp"
|
||||
android:background="@android:color/white"
|
||||
app:layout_constraintTop_toBottomOf="@id/connect_btn"
|
||||
app:layout_constraintTop_toBottomOf="@id/temp_circle"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintBottom_toBottomOf="parent" />
|
||||
|
||||
@ -1,5 +1,11 @@
|
||||
<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>
|
||||
<string name="default_temp_text" translatable="false">--°C</string>
|
||||
<string name="default_hum_text" translatable="false">--%</string>
|
||||
</resources>
|
||||
Loading…
Reference in New Issue
Block a user