Procházet zdrojové kódy

开始运动

Signed-off-by: duanchangpeng <838560574@qq.com>
duanchangpeng před 4 roky
rodič
revize
375f2009ef

+ 1 - 0
README.md

@@ -14,6 +14,7 @@ goal
 
 https://github.com/AAChartModel/AAChartCore-Kotlin/blob/master/CHINESE-README.md
 
+
 3.bottonNav fragment
 4.首页每个小部件拆fragment
 5.设置界面要整起来

+ 15 - 9
app/src/main/java/com/example/watch/ui/activity/BaseData.kt

@@ -1,16 +1,17 @@
 package com.example.watch.ui.activity
 
+import java.text.DecimalFormat
+
 class BaseData {
     val heigh = 146
     val sex = 1
-    val age = 6
-    val weight = 41
+    val age = 4
+    val weight = 21
     val head = "123.jpg"
-    val peaceHr = 100
+    val peaceHr = 95
 
-//  运动强度计算
+    //  运动强度计算
     public fun calcActivity(Hr: Int, Sex: Int, Weight: Int, Age: Int, T: Int): String {
-        var res = "0"
         var calc: Double
         if (Sex == 1) {
             calc =
@@ -21,7 +22,8 @@ class BaseData {
         }
 //        强度最大100
         calc = if (calc >= 100.0) 100.0 else calc
-        res = calc.toInt().toString()
+        println(calc)
+        val res = calc.toInt().toString()
         return res
     }
 
@@ -36,22 +38,26 @@ class BaseData {
     }
 
     //    todo 计算全部消耗
-    public fun calcSumCalc(Hr: Int, Sex: Int, Weight: Int, Age: Int, T: Int): String {
+    public fun calcSumCalc(calorie: Int): String {
         var res = "0"
-        var calc = Hr.toDouble() * 0.98
+        var calc = calorie / weight
+        val df = DecimalFormat("######0.00")
         if (calc > 1) {
             res = calc.toInt().toString()
+        } else {
+            res = df.format(calc.toDouble())
         }
         return res
     }
 
     //    todo 计算CK
     public fun calcCk(Hr: Int): String {
+//        卡路里除以体重
         var res = "0"
         var calc = Hr.toDouble() / weight
         if (calc > 1) {
             res = calc.toInt().toString()
-        }else{
+        } else {
         }
         return res
     }

+ 27 - 11
app/src/main/java/com/example/watch/ui/activity/MainActivity.kt

@@ -336,10 +336,13 @@ class MainActivity : AppCompatActivity(), ScannerFragment.OnDeviceSelectedListen
         findViewById<TextView>(R.id.head_status).text =
             "心率带已连接 电量" + getString(R.string.battery, batteryLevel)
     }
-//   卡路里和全部卡路里
+
+    //   卡路里和全部卡路里以及CK
     override fun onSportReceived(device: BluetoothDevice, step: Int, distance: Int, calorie: Int) {
         findViewById<TextView>(R.id.sportNum).text = calorie.toString()
-        findViewById<TextView>(R.id.calNum).text = (calorie*1.25).toInt().toString()
+        findViewById<TextView>(R.id.calNum).text = (calorie * 1.25).toInt().toString()
+        findViewById<TextView>(R.id.ckNum).text = BaseData().calcCk(calorie)
+
     }
 
     //    连续两次回退
@@ -385,14 +388,12 @@ class MainActivity : AppCompatActivity(), ScannerFragment.OnDeviceSelectedListen
 //    其中,HR =心率(次/分钟) W =体重(公斤) A=年龄(岁) T =锻炼持续时间的时间(以小时计)
         this.findViewById<TextView>(R.id.activLevel).text =
             BaseData().calcActivity(heartRate, BaseData().sex, BaseData().weight, BaseData().age, 1)
-////    todo 全部卡路里
+
+//        根据运动强度加载不同的背景色,状态栏颜色 和 提示语
+        headStatus(10)
+//    todo 全部卡路里
 //        this.findViewById<TextView>(R.id.calNum).text =
 //            BaseData().calcSumCalc(heartRate, BaseData().sex, BaseData().weight, BaseData().age, 1)
-
-//     todo CK
-        this.findViewById<TextView>(R.id.ckNum).text =
-            BaseData().calcSumCalc(heartRate, BaseData().sex, BaseData().weight, BaseData().age, 1)
-
     }
 
     fun setDeafultData() {
@@ -419,13 +420,13 @@ class MainActivity : AppCompatActivity(), ScannerFragment.OnDeviceSelectedListen
     //    开始运动
     fun beginSport() {
 //        开始
-        var beginBtn = findViewById<Button>(R.id.beginBtn)
+        val beginBtn = findViewById<Button>(R.id.beginBtn)
         beginBtn.setOnClickListener {
             showToast("运动计时已开")
             timeInter()
         }
 
-        var reportHr = findViewById<Button>(R.id.reportHr)
+        val reportHr = findViewById<Button>(R.id.reportHr)
         reportHr.setOnClickListener {
             showToast("心率已上报 todo")
         }
@@ -447,13 +448,28 @@ class MainActivity : AppCompatActivity(), ScannerFragment.OnDeviceSelectedListen
         }
 
         //          结束
-        var btn_stop = findViewById<Button>(R.id.btn_stop)
+        val btn_stop = findViewById<Button>(R.id.btn_stop)
         btn_stop.setOnClickListener {
             showToast("运动计时已终止")
             findViewById<Button>(R.id.beginBtn).text = "开始运动"
             timer.cancel()
         }
     }
+
+    fun headStatus(activLevel: Int) {
+        val activLevel = this.findViewById<TextView>(R.id.activLevel)
+        var levelText = "激活放松"
+        when (activLevel) {
+            in 0..39 -> levelText = "激活放松"
+            in 40..54 -> levelText = "激活放松"
+            in 55..69 -> levelText = "激活放松"
+            in 70..79 -> levelText = "激活放松"
+            in 80..89 -> levelText = "激活放松"
+            in 90..109 -> levelText = "激活放松"
+        }
+
+
+    }
 }
 
 

+ 1 - 1
app/src/main/res/layout/activity_main.xml

@@ -78,7 +78,7 @@
                         </RelativeLayout>
 
                         <TextView
-                            android:id="@+id/textView8"
+                            android:id="@+id/act_level_text"
                             android:layout_width="90dp"
                             android:layout_height="30dp"
                             android:layout_gravity="center"