Browse Source

重构开始按钮

Signed-off-by: duanchangpeng <838560574@qq.com>
duanchangpeng 4 năm trước cách đây
mục cha
commit
ebb40d990c

+ 26 - 17
app/src/main/java/com/example/watch/ui/activity/MainActivity.kt

@@ -440,26 +440,39 @@ class MainActivity : AppCompatActivity(), ScannerFragment.OnDeviceSelectedListen
         findViewById<Button>(R.id.chainBtn).setVisibility(View.GONE); // 隐藏
         findViewById<TextView>(R.id.unchain).text = "心率带已连接"
         findViewById<TextView>(R.id.unchain).setTextColor(Color.parseColor("#AACC03"))
-
     }
 
+    //        1开始2结束
+    var BtnState = 1
+
     //    开始运动
     fun beginSport() {
 //        开始
         val beginBtn = findViewById<Button>(R.id.beginBtn)
-        beginBtn.setOnClickListener {
-            showToast("运动计时已开")
-            timeInter()
-        }
 
-        val reportHr = findViewById<Button>(R.id.reportHr)
-        reportHr.setOnClickListener {
-            showToast("心率已上报 todo")
+        beginBtn.setOnClickListener {
+            if (BtnState == 1) {
+                BtnState = 2
+                showToast("运动计时已开")
+                beginBtn.text = "停止运动"
+                beginBtn.setBackgroundResource(R.drawable.btn_pause)
+                timeInter()
+            } else {
+                BtnState = 1
+                showToast("运动计时已终止")
+                beginBtn.text = "开始运动"
+                beginBtn.setBackgroundResource(R.drawable.btn_begin)
+                timer.cancel()
+            }
+            val reportHr = findViewById<Button>(R.id.reportHr)
+            reportHr.setOnClickListener {
+                showToast("心率已上报 todo")
+            }
         }
     }
 
+    lateinit var timer: Timer
     fun timeInter() {
-        lateinit var timer: Timer
         var milliseconds: Long = 1000
         timer = fixedRateTimer("", false, 0, 1000) {
             val hours = milliseconds % 1000
@@ -468,17 +481,13 @@ class MainActivity : AppCompatActivity(), ScannerFragment.OnDeviceSelectedListen
             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
+            val task = "运动时长 " + showHours + ":" + showminutes + ":" + showseconds
+            findViewById<Button>(R.id.beginTime).text = task
             milliseconds = milliseconds + 1000
         }
+        val beginBtn = findViewById<Button>(R.id.beginBtn)
+        if (BtnState == 2) {
 
-        //          结束
-        val btn_stop = findViewById<Button>(R.id.btn_stop)
-        btn_stop.setOnClickListener {
-            showToast("运动计时已终止")
-            findViewById<Button>(R.id.beginBtn).text = "开始运动"
-            timer.cancel()
         }
     }
 

+ 0 - 8
app/src/main/java/com/example/watch/ui/activity/SettingActivity.kt

@@ -29,14 +29,6 @@ class SettingActivity : AppCompatActivity() {
 //        推出登录
         logout()
 
-//        val imageView: ImageView = findViewById<View>(R.id.imageView) as ImageView
-//        //图片点击的时候,启动动画效果
-//        //图片点击的时候,启动动画效果
-//        imageView.setOnClickListener({
-//            val scalegetAnim: Animation = Animate().getScaleAnimation()
-//            imageView.startAnimation(scalegetAnim)
-//        })
-
     }
     private fun logout() {
         findViewById<Button>(R.id.logout).setOnClickListener {

BIN
app/src/main/res/drawable/btn_begin.png


BIN
app/src/main/res/drawable/btn_pause.png


BIN
app/src/main/res/drawable/btn_report.png


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

@@ -31,7 +31,6 @@
             android:layout_height="match_parent"
             android:layout_centerHorizontal="true"
             android:layout_weight="1"
-            android:layout_marginTop="3dp"
             layout="@layout/main_chart_part" />
     </LinearLayout>
 

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

@@ -122,7 +122,6 @@
         </LinearLayout>
 
         <LinearLayout
-            android:id="@+id/curent_version"
             android:layout_width="match_parent"
             android:layout_height="60dp"
             android:background="@color/white"
@@ -150,6 +149,7 @@
                 android:text="已连接  电量 34%" />
         </LinearLayout>
         <LinearLayout
+            android:id="@+id/curent_version"
             android:layout_width="match_parent"
             android:layout_height="60dp"
             android:background="@color/white"

+ 8 - 9
app/src/main/res/layout/main_basic.xml

@@ -162,7 +162,6 @@
                     </LinearLayout>
                 </LinearLayout>
             </LinearLayout>
-
         </LinearLayout>
         <LinearLayout
             android:id="@+id/contectPart"
@@ -359,32 +358,32 @@
             android:orientation="horizontal">
 
             <Button
-                android:id="@+id/btn_stop"
+                android:id="@+id/beginBtn"
                 android:layout_width="70dp"
                 android:layout_height="30dp"
                 android:layout_marginLeft="20dp"
-                android:background="@drawable/gary_btn"
+                android:background="@drawable/btn_begin"
                 android:gravity="center"
-                android:textColor="@color/red"
-                android:text="停止运动" />
+                android:textColor="@color/white"
+                android:text="开始运动" />
 
             <Button
-                android:id="@+id/beginBtn"
+                android:id="@+id/beginTime"
                 android:layout_width="210dp"
                 android:layout_height="30dp"
                 android:layout_marginLeft="15dp"
                 android:layout_marginRight="15dp"
                 android:background="@drawable/round_btn"
                 android:gravity="center"
-                android:text="开始运动"
-                android:textColor="@color/green" />
+                android:text="运动时长 00:00:00"
+                android:textColor="@color/black" />
 
             <Button
                 android:id="@+id/reportHr"
                 android:layout_width="70dp"
                 android:layout_height="30dp"
                 android:layout_marginRight="20dp"
-                android:background="@drawable/gary_btn"
+                android:background="@drawable/btn_report"
                 android:gravity="center"
                 android:text="心率上报"
                 android:textColor="#fff" />