Browse Source

设置,修改bug

chenzubin 2 months ago
parent
commit
07297fc78d

+ 6 - 0
app/build.gradle

@@ -16,6 +16,10 @@ android {
16 16
         testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
17 17
     }
18 18
 
19
+    lintOptions {
20
+        abortOnError false
21
+    }
22
+
19 23
     signingConfigs {
20 24
         release {
21 25
             storeFile file('src/key/key.keystore')
@@ -71,4 +75,6 @@ dependencies {
71 75
     implementation 'com.github.getActivity:XXPermissions:20.0'
72 76
     implementation 'androidx.databinding:databinding-runtime:4.0.0'
73 77
     implementation 'com.github.zrunker:ZImageView:v1.0'
78
+    implementation "androidx.lifecycle:lifecycle-viewmodel:2.2.0"
79
+    implementation "androidx.lifecycle:lifecycle-extensions:2.2.0"
74 80
 }

+ 8 - 5
app/src/main/AndroidManifest.xml

@@ -24,13 +24,12 @@
24 24
         android:theme="@style/Theme.MainTheme"
25 25
         tools:targetApi="31">
26 26
         <activity
27
+            android:name=".SettingActivity"
28
+            android:exported="false" />
29
+        <activity
27 30
             android:name=".HistoryActivity"
28
-            android:exported="true" >
29
-            <intent-filter>
30
-                <action android:name="android.intent.action.MAIN" />
31
+            android:exported="true">
31 32
 
32
-                <category android:name="android.intent.category.LAUNCHER" />
33
-            </intent-filter>
34 33
         </activity>
35 34
 
36 35
         <meta-data
@@ -62,7 +61,11 @@
62 61
         <activity
63 62
             android:name=".MainActivity"
64 63
             android:exported="true">
64
+            <intent-filter>
65
+                <action android:name="android.intent.action.MAIN" />
65 66
 
67
+                <category android:name="android.intent.category.LAUNCHER" />
68
+            </intent-filter>
66 69
         </activity>
67 70
         <activity
68 71
             android:name=".ShowImageActivity"

+ 1 - 0
app/src/main/java/com/cfmlg/mlg/HistoryActivity.java

@@ -42,6 +42,7 @@ public class HistoryActivity extends AppCompatActivity {
42 42
             }
43 43
         });
44 44
 
45
+        getStatus();
45 46
 
46 47
         binding.imgTime.setOnClickListener(new View.OnClickListener() {
47 48
             @Override

+ 20 - 0
app/src/main/java/com/cfmlg/mlg/MainViewModel.java

@@ -0,0 +1,20 @@
1
+package com.cfmlg.mlg;
2
+
3
+import androidx.lifecycle.LiveData;
4
+import androidx.lifecycle.MutableLiveData;
5
+import androidx.lifecycle.ViewModel;
6
+
7
+public class MainViewModel extends ViewModel {
8
+
9
+    private MutableLiveData<Integer> selectedRadioId = new MutableLiveData<>();
10
+//    private MutableLiveData<Integer> selectedRadioid = new MutableLiveData<>();
11
+
12
+    public LiveData<Integer> getSelectedRadioId() {
13
+        return selectedRadioId;
14
+    }
15
+
16
+    public void setSelectedRadioId(int id) {
17
+        selectedRadioId.setValue(id);
18
+    }
19
+
20
+}

+ 46 - 0
app/src/main/java/com/cfmlg/mlg/SettingActivity.java

@@ -0,0 +1,46 @@
1
+package com.cfmlg.mlg;
2
+
3
+import androidx.appcompat.app.AppCompatActivity;
4
+import androidx.databinding.DataBindingUtil;
5
+
6
+import android.os.Bundle;
7
+import android.view.View;
8
+import android.widget.RadioButton;
9
+import android.widget.RadioGroup;
10
+
11
+import com.cfmlg.mlg.databinding.ActivitySettingBinding;
12
+
13
+public class SettingActivity extends AppCompatActivity {
14
+
15
+    public static int ladyTime = 2;
16
+    @Override
17
+    protected void onCreate(Bundle savedInstanceState) {
18
+        super.onCreate(savedInstanceState);
19
+        ActivitySettingBinding binding = DataBindingUtil.setContentView(this, R.layout.activity_setting);
20
+
21
+        binding.radioGroup1.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
22
+            @Override
23
+            public void onCheckedChanged(RadioGroup group, int checkedId) {
24
+                if(R.id.radioButton2 == checkedId) {
25
+                    binding.layoutTime.setVisibility(View.VISIBLE);
26
+                } else {
27
+                    binding.layoutTime.setVisibility(View.GONE);
28
+                    ladyTime = 0;
29
+                }
30
+            }
31
+        });
32
+
33
+        binding.radioGroup2.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
34
+            @Override
35
+            public void onCheckedChanged(RadioGroup group, int checkedId) {
36
+                if(R.id.radioButton3 == checkedId) {
37
+                    ladyTime = 4;
38
+                } else if(R.id.radioButton4 == checkedId) {
39
+                    ladyTime = 7;
40
+                } else {
41
+                    ladyTime = 12;
42
+                }
43
+            }
44
+        });
45
+    }
46
+}

+ 37 - 7
app/src/main/java/com/cfmlg/mlg/Video.java

@@ -78,7 +78,7 @@ public class Video extends AppCompatActivity {
78 78
     private Surface mSurface = null;
79 79
     //return 1:  jpg  0:h264
80 80
     private TextView countdownTextView;
81
-    private int totalTime = 4;
81
+    private int totalTime = SettingActivity.ladyTime;
82 82
     private RelativeLayout mainPage;
83 83
     private TextView tvHistory, tvQuestion;
84 84
     private TextView tvConnect;
@@ -147,6 +147,20 @@ public class Video extends AppCompatActivity {
147 147
         service.scheduleAtFixedRate(new Task1(), initialDelay1, period1, TimeUnit.SECONDS);
148 148
 
149 149
         binding.imv.setImageBitmap(BitmapFactory.decodeResource(getResources(), R.drawable.ya));
150
+        binding.backup.setOnClickListener(new View.OnClickListener() {
151
+            @Override
152
+            public void onClick(View view) {
153
+                mainPage.setVisibility(View.VISIBLE);
154
+            }
155
+        });
156
+
157
+        binding.settings.setOnClickListener(new View.OnClickListener() {
158
+            @Override
159
+            public void onClick(View view) {
160
+                Intent intent2 = new Intent(Video.this, SettingActivity.class);
161
+                startActivity(intent2);
162
+            }
163
+        });
150 164
 
151 165
         new Thread(new Runnable() {
152 166
             @Override
@@ -178,7 +192,7 @@ public class Video extends AppCompatActivity {
178 192
                                 if (totalTime > 0) {
179 193
                                     handler.postDelayed(this, 1000);
180 194
                                 } else {
181
-                                    totalTime = 4;
195
+                                    totalTime = SettingActivity.ladyTime;
182 196
                                     countdownTextView.setVisibility(View.GONE);
183 197
                                     SoundPool soundPool = new SoundPool.Builder().setMaxStreams(1).build();
184 198
                                     int soundId = soundPool.load(Video.this, R.raw.kuaimen, 1); // 加载音频资源
@@ -224,13 +238,9 @@ public class Video extends AppCompatActivity {
224 238
                         }, 50);
225 239
                     }
226 240
                 }.start();
227
-
228
-
229
-
230 241
             }
231 242
         });
232 243
 
233
-
234 244
         binding.handlerecord.setOnClickListener(new View.OnClickListener() {
235 245
             @Override
236 246
             public void onClick(View v) {
@@ -286,6 +296,14 @@ public class Video extends AppCompatActivity {
286 296
                     @Override
287 297
                     public void run() {
288 298
                         circleView.setVisibility(View.GONE);
299
+                        String packageName = getApplicationContext().getPackageName();
300
+
301
+                        Intent intent = getApplicationContext().getPackageManager()
302
+                                .getLaunchIntentForPackage(packageName);
303
+                        intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
304
+
305
+                        startActivity(intent);
306
+                        finish();
289 307
                     }
290 308
                 }, 5000);
291 309
 
@@ -319,6 +337,13 @@ public class Video extends AppCompatActivity {
319 337
         });
320 338
     }
321 339
 
340
+    @Override
341
+    public void onResume() {
342
+        super.onResume();  // Always call the superclass method first
343
+
344
+        totalTime = SettingActivity.ladyTime;
345
+    }
346
+
322 347
     public boolean onTouchEvent(MotionEvent e) {
323 348
         float x = e.getX();
324 349
         float y = e.getY();
@@ -334,6 +359,11 @@ public class Video extends AppCompatActivity {
334 359
         return true;
335 360
     }
336 361
 
362
+    public void toHistory(View view) {
363
+        Intent intent2 = new Intent(Video.this, HistoryActivity.class);
364
+        startActivity(intent2);
365
+    }
366
+
337 367
     @Override
338 368
     protected void onDestroy() {
339 369
         super.onDestroy();
@@ -377,7 +407,7 @@ public class Video extends AppCompatActivity {
377 407
                         if (totalTime > 0) {
378 408
                             handler.postDelayed(this, 1000);
379 409
                         } else {
380
-                            totalTime = 4;
410
+                            totalTime = SettingActivity.ladyTime;
381 411
                             countdownTextView.setVisibility(View.GONE);
382 412
                             SoundPool soundPool = new SoundPool.Builder().setMaxStreams(1).build();
383 413
                             int soundId = soundPool.load(Video.this, R.raw.kuaimen, 1); // 加载音频资源

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


+ 105 - 0
app/src/main/res/layout/activity_setting.xml

@@ -0,0 +1,105 @@
1
+<?xml version="1.0" encoding="utf-8"?>
2
+<layout xmlns:android="http://schemas.android.com/apk/res/android"
3
+    xmlns:app="http://schemas.android.com/apk/res-auto"
4
+    xmlns:tools="http://schemas.android.com/tools">
5
+
6
+    <data></data>
7
+
8
+    <LinearLayout
9
+        android:layout_width="match_parent"
10
+        android:layout_height="match_parent"
11
+        android:orientation="vertical"
12
+        tools:context=".SettingActivity">
13
+
14
+        <LinearLayout
15
+            android:layout_width="match_parent"
16
+            android:layout_height="wrap_content"
17
+            android:orientation="horizontal"
18
+            tools:context=".SettingActivity">
19
+
20
+            <TextView
21
+                android:id="@+id/tvState"
22
+                android:layout_width="wrap_content"
23
+                android:layout_height="wrap_content"
24
+                android:layout_marginLeft="50dp"
25
+                android:layout_marginTop="50dp"
26
+                android:padding="10dp"
27
+                android:text="延迟拍摄"
28
+                android:textColor="@color/black" />
29
+
30
+            <RadioGroup
31
+                android:id="@+id/radioGroup1"
32
+                android:layout_width="match_parent"
33
+                android:layout_height="wrap_content"
34
+                android:layout_marginTop="48dp"
35
+                android:orientation="horizontal">
36
+
37
+                <RadioButton
38
+                    android:id="@+id/radioButton1"
39
+                    android:layout_width="wrap_content"
40
+                    android:layout_height="wrap_content"
41
+                    android:layout_gravity="center_horizontal"
42
+                    android:checked="true"
43
+                    android:text="关闭" />
44
+
45
+                <RadioButton
46
+                    android:id="@+id/radioButton2"
47
+                    android:layout_width="wrap_content"
48
+                    android:layout_height="wrap_content"
49
+                    android:layout_gravity="center_horizontal"
50
+                    android:checked="false"
51
+                    android:text="打开" />
52
+
53
+            </RadioGroup>
54
+        </LinearLayout>
55
+
56
+        <LinearLayout
57
+            android:id="@+id/layoutTime"
58
+            android:layout_width="match_parent"
59
+            android:layout_height="match_parent"
60
+            android:visibility="gone"
61
+            android:orientation="horizontal"
62
+            tools:context=".SettingActivity">
63
+
64
+            <TextView
65
+                android:id="@+id/tvTime"
66
+                android:layout_width="wrap_content"
67
+                android:layout_height="wrap_content"
68
+                android:layout_marginLeft="50dp"
69
+                android:layout_marginTop="50dp"
70
+                android:padding="10dp"
71
+                android:text="延迟时间"
72
+                android:textColor="@color/black" />
73
+
74
+            <RadioGroup
75
+                android:id="@+id/radioGroup2"
76
+                android:layout_width="match_parent"
77
+                android:layout_height="wrap_content"
78
+                android:layout_marginTop="48dp"
79
+                android:orientation="vertical">
80
+
81
+                <RadioButton
82
+                    android:id="@+id/radioButton3"
83
+                    android:layout_width="wrap_content"
84
+                    android:layout_height="wrap_content"
85
+                    android:checked="true"
86
+                    android:text="2秒" />
87
+
88
+                <RadioButton
89
+                    android:id="@+id/radioButton4"
90
+                    android:layout_width="wrap_content"
91
+                    android:layout_height="wrap_content"
92
+                    android:checked="false"
93
+                    android:text="5秒" />
94
+
95
+                <RadioButton
96
+                    android:id="@+id/radioButton5"
97
+                    android:layout_width="wrap_content"
98
+                    android:layout_height="wrap_content"
99
+                    android:checked="false"
100
+                    android:text="10秒" />
101
+
102
+            </RadioGroup>
103
+        </LinearLayout>
104
+    </LinearLayout>
105
+</layout>

+ 41 - 15
app/src/main/res/layout/activity_video.xml

@@ -8,13 +8,38 @@
8 8
     tools:context=".Video"
9 9
     tools:ignore="ExtraText">
10 10
 
11
+
12
+
11 13
     <TextureView
12 14
         android:id="@+id/mSurfaceview"
13 15
         android:layout_width="match_parent"
14 16
         android:layout_height="match_parent"
15 17
         tools:layout_editor_absoluteX="16dp"
16 18
         tools:layout_editor_absoluteY="0dp" />
19
+    <RelativeLayout
20
+        android:layout_width="wrap_content"
21
+        android:layout_height="match_parent"
22
+        app:layout_constraintLeft_toLeftOf="parent"
23
+        app:layout_constraintTop_toTopOf="parent"
24
+        >
17 25
 
26
+        <ImageButton
27
+            android:id="@+id/backup"
28
+            android:layout_width="50dp"
29
+            android:layout_height="50dp"
30
+            android:layout_alignParentBottom="true"
31
+            android:background="#00000000"
32
+            android:rotation="270"
33
+            android:src="@drawable/back" />
34
+
35
+        <ImageButton
36
+            android:id="@+id/settings"
37
+            android:layout_width="50dp"
38
+            android:layout_height="50dp"
39
+            android:layout_alignParentTop="true"
40
+            android:background="#00000000"
41
+            android:src="@drawable/setting" />
42
+    </RelativeLayout>
18 43
     <ImageButton
19 44
         android:id="@+id/imageConnect"
20 45
         android:layout_width="wrap_content"
@@ -25,19 +50,21 @@
25 50
         app:layout_constraintLeft_toLeftOf="parent"
26 51
         app:layout_constraintTop_toTopOf="parent"
27 52
         app:srcCompat="@drawable/fan" />
53
+
28 54
     <com.cfmlg.mlg.CustomImageView
29 55
         android:id="@+id/imv"
30 56
         android:layout_width="wrap_content"
31 57
         android:layout_height="wrap_content"
32
-        app:layout_constraintStart_toStartOf="parent"
33
-        app:layout_constraintEnd_toEndOf="parent"
34
-        app:layout_constraintTop_toTopOf="parent"
58
+        android:src="@drawable/ya"
59
+        android:visibility="gone"
35 60
         app:layout_constraintBottom_toBottomOf="parent"
61
+        app:layout_constraintEnd_toEndOf="parent"
36 62
         app:layout_constraintHorizontal_bias="0.5"
63
+        app:layout_constraintStart_toStartOf="parent"
64
+        app:layout_constraintTop_toTopOf="parent"
37 65
         app:layout_constraintVertical_bias="0.5"
38
-        android:src="@drawable/ya"
39
-        android:visibility="gone"
40 66
         tools:ignore="MissingConstraints" />
67
+
41 68
     <LinearLayout
42 69
         android:id="@+id/blakgrond"
43 70
         android:layout_width="wrap_content"
@@ -103,6 +130,7 @@
103 130
             android:layout_alignParentLeft="true"
104 131
             android:layout_alignParentBottom="true"
105 132
             android:layout_marginBottom="30dp"
133
+            android:onClick="toHistory"
106 134
             android:padding="10dp"
107 135
             android:rotation="270"
108 136
             android:text="历史记录"
@@ -135,8 +163,7 @@
135 163
             android:id="@+id/imgConnect"
136 164
             android:layout_width="200dp"
137 165
             android:layout_height="200dp"
138
-            android:layout_centerInParent="true"
139
-            >
166
+            android:layout_centerInParent="true">
140 167
 
141 168
         </ImageView>
142 169
 
@@ -158,8 +185,7 @@
158 185
                 android:layout_marginTop="10dp"
159 186
                 android:rotation="270"
160 187
                 android:text="未链接"
161
-                android:textColor="@color/material_dynamic_primary30"
162
-                 />
188
+                android:textColor="@color/material_dynamic_primary30" />
163 189
 
164 190
             <ImageView
165 191
                 android:id="@+id/t2"
@@ -347,14 +373,14 @@
347 373
 
348 374
         <com.cfmlg.mlg.CirclePercentView
349 375
             android:id="@+id/circleView"
350
-            app:stripeWidth="15dp"
351
-            app:centerTextSize="16sp"
352
-            app:percent="0"
353
-            android:rotation="270"
354
-            android:visibility="gone"
355 376
             android:layout_width="wrap_content"
356 377
             android:layout_height="wrap_content"
357
-            android:layout_centerInParent="true"/>
378
+            android:layout_centerInParent="true"
379
+            android:rotation="270"
380
+            android:visibility="gone"
381
+            app:centerTextSize="16sp"
382
+            app:percent="0"
383
+            app:stripeWidth="15dp" />
358 384
 
359 385
     </RelativeLayout>
360 386
 </androidx.constraintlayout.widget.ConstraintLayout>