Переглянути джерело

开始运动

Signed-off-by: duanchangpeng <838560574@qq.com>
duanchangpeng 4 роки тому
батько
коміт
df3c25594f

+ 11 - 1
README.md

@@ -2,8 +2,18 @@
 
 Kotlin watch 
 
-1.数据渲染
+ask
+1.ck,calc的计算公式
+2.电量获取
+
+
+
+goal
+1.数据渲染 √
 2.心律图跑起来
+
+https://github.com/AAChartModel/AAChartCore-Kotlin/blob/master/CHINESE-README.md
+
 3.bottonNav fragment
 4.首页每个小部件拆fragment
 5.设置界面要整起来

+ 45 - 0
app/src/main/java/com/example/watch/ui/activity/MainActivity.kt

@@ -14,6 +14,7 @@ import android.os.Handler
 import android.os.Looper
 import android.provider.Settings
 import android.provider.Settings.SettingNotFoundException
+import android.util.Log
 import android.view.KeyEvent
 import android.view.View
 import android.view.WindowManager
@@ -34,6 +35,8 @@ import com.yanzhenjie.permission.AndPermission
 import com.yanzhenjie.permission.runtime.Permission
 import kotlinx.android.synthetic.main.activity_main.*
 import timber.log.Timber
+import java.util.*
+import kotlin.concurrent.fixedRateTimer
 
 
 class MainActivity : AppCompatActivity(), ScannerFragment.OnDeviceSelectedListener,
@@ -76,6 +79,9 @@ class MainActivity : AppCompatActivity(), ScannerFragment.OnDeviceSelectedListen
 
 //        填写基础身体数据
         setDeafultData()
+
+//        开始运动
+        beginSport()
     }
 
     fun setStatusBarColor() {
@@ -406,6 +412,45 @@ class MainActivity : AppCompatActivity(), ScannerFragment.OnDeviceSelectedListen
         findViewById<TextView>(R.id.unchain).setTextColor(Color.parseColor("#AACC03"))
 
     }
+
+    //    开始运动
+    fun beginSport() {
+//        开始
+        var beginBtn = findViewById<Button>(R.id.beginBtn)
+        beginBtn.setOnClickListener {
+            showToast("运动计时已开")
+            timeInter()
+        }
+
+        var reportHr = findViewById<Button>(R.id.reportHr)
+        reportHr.setOnClickListener {
+            showToast("心率已上报 todo")
+        }
+    }
+
+    fun timeInter() {
+        lateinit var timer: Timer
+        var milliseconds: Long = 1000
+        timer = fixedRateTimer("", false, 0, 1000) {
+            val hours = milliseconds % 1000
+            val minutes = milliseconds / 1000 / 60
+            val seconds = milliseconds / 1000 % 60
+            val showHours = if (hours > 9) hours else "0" + hours;
+            val showminutes = if (minutes > 9) minutes else "0" + minutes;
+            val showseconds = if (seconds > 9) seconds else "0" + seconds;
+            val task = "运动时长" + showHours + ":" + showminutes + ":" + showseconds
+            findViewById<Button>(R.id.beginBtn).text = task
+            milliseconds = milliseconds + 1000
+        }
+
+        //          结束
+        var btn_stop = findViewById<Button>(R.id.btn_stop)
+        btn_stop.setOnClickListener {
+            showToast("运动计时已终止")
+            findViewById<Button>(R.id.beginBtn).text = "开始运动"
+            timer.cancel()
+        }
+    }
 }
 
 

+ 41 - 36
app/src/main/res/layout/activity_main.xml

@@ -70,9 +70,9 @@
                                 android:layout_height="82dp"
                                 android:layout_alignParentTop="true"
                                 android:layout_alignParentRight="true"
-                                android:text="%"
                                 android:layout_marginTop="10dp"
                                 android:paddingLeft="10dp"
+                                android:text="%"
                                 android:textColor="@color/white"
                                 android:textSize="20dp" />
                         </RelativeLayout>
@@ -111,25 +111,27 @@
                             <RelativeLayout
                                 android:layout_width="match_parent"
                                 android:layout_height="match_parent">
-                            <TextView
-                                android:id="@+id/textView10"
-                                android:layout_width="match_parent"
-                                android:layout_height="match_parent"
-                                android:layout_weight="1"
-                                android:layout_gravity="center"
-                                android:gravity="center_vertical|center"
-                                android:text="王仪涵"
-                                android:textColor="@color/white" />
-                            <ImageView
-                                android:id="@+id/sex"
-                                android:layout_width="18dp"
-                                android:layout_height="18dp"
-                                android:gravity="center_vertical|left"
-                                android:layout_gravity="center"
-                                android:layout_alignParentRight="true"
-                                android:layout_marginTop="25dp"
-                                android:layout_marginRight="20dp"
-                                android:src="@drawable/male" />
+
+                                <TextView
+                                    android:id="@+id/textView10"
+                                    android:layout_width="match_parent"
+                                    android:layout_height="match_parent"
+                                    android:layout_gravity="center"
+                                    android:layout_weight="1"
+                                    android:gravity="center_vertical|center"
+                                    android:text="王仪涵"
+                                    android:textColor="@color/white" />
+
+                                <ImageView
+                                    android:id="@+id/sex"
+                                    android:layout_width="18dp"
+                                    android:layout_height="18dp"
+                                    android:layout_alignParentRight="true"
+                                    android:layout_gravity="center"
+                                    android:layout_marginTop="25dp"
+                                    android:layout_marginRight="20dp"
+                                    android:gravity="center_vertical|left"
+                                    android:src="@drawable/male" />
                             </RelativeLayout>
                         </LinearLayout>
                     </LinearLayout>
@@ -538,38 +540,40 @@
         <LinearLayout
             android:layout_width="match_parent"
             android:layout_height="30dp"
-            android:background="#fff"
             android:layout_gravity="center"
+            android:background="#fff"
             android:gravity="center"
             android:orientation="horizontal">
 
             <Button
-                android:id="@+id/button"
-                android:layout_width="60dp"
+                android:id="@+id/btn_stop"
+                android:layout_width="70dp"
                 android:layout_height="30dp"
+                android:layout_marginLeft="20dp"
                 android:background="@drawable/gary_btn"
                 android:gravity="center"
-                android:layout_marginLeft="20dp"
+                android:textColor="@color/red"
                 android:text="停止运动" />
 
             <Button
-                android:id="@+id/linkBtn"
+                android:id="@+id/beginBtn"
                 android:layout_width="210dp"
                 android:layout_height="30dp"
-                    android:background="@drawable/round_btn"
-                android:gravity="center"
-                android:text="运动时间 00:00:00"
                 android:layout_marginLeft="15dp"
                 android:layout_marginRight="15dp"
-                android:textColor="#333" />
+                android:background="@drawable/round_btn"
+                android:gravity="center"
+                android:text="开始运动"
+                android:textColor="@color/green" />
+
             <Button
-                android:id="@+id/button3"
-                android:layout_width="60dp"
+                android:id="@+id/reportHr"
+                android:layout_width="70dp"
                 android:layout_height="30dp"
+                android:layout_marginRight="20dp"
                 android:background="@drawable/gary_btn"
                 android:gravity="center"
                 android:text="心率上报"
-                android:layout_marginRight="20dp"
                 android:textColor="#fff" />
         </LinearLayout>
 
@@ -602,21 +606,22 @@
                 android:id="@+id/lineChart"
                 android:layout_width="match_parent"
                 android:layout_height="match_parent"
-                android:background="#ffffff"
                 android:layout_margin="16dp"
+                android:background="#ffffff"
                 tools:ignore="MissingClass" />
         </LinearLayout>
     </LinearLayout>
+
     <com.google.android.material.bottomnavigation.BottomNavigationView
         android:id="@+id/bottomNavigation"
         android:layout_width="0dp"
         android:layout_height="50dp"
-        android:paddingTop="0dp"
         android:background="#ccc"
+        android:paddingTop="0dp"
         app:itemIconSize="20dp"
+        app:labelVisibilityMode="labeled"
         app:layout_constraintBottom_toBottomOf="parent"
         app:layout_constraintLeft_toLeftOf="parent"
         app:layout_constraintRight_toRightOf="parent"
-        app:menu="@menu/bottom_nav_menu"
-        app:labelVisibilityMode="labeled" />
+        app:menu="@menu/bottom_nav_menu" />
 </androidx.constraintlayout.widget.ConstraintLayout>

+ 1 - 0
app/src/main/res/values/colors.xml

@@ -16,4 +16,5 @@
     <color name="blue">#028FE1</color>
     <color name="yellow">#F8BD2C</color>
     <color name="green">#AACC03</color>
+    <color name="red">#F90505</color>
 </resources>