|
@@ -66,6 +66,7 @@ public class Video extends AppCompatActivity {
|
66
|
66
|
final int countDownInterval = 3 * 1000; // 1分钟
|
67
|
67
|
final Handler handler = new Handler();
|
68
|
68
|
LinearLayout l1, l2;
|
|
69
|
+ RelativeLayout layoutMsg;
|
69
|
70
|
Button bt1, bt2, bt3, bt4, bt5;
|
70
|
71
|
String[] permissions = new String[]{android.Manifest.permission.READ_EXTERNAL_STORAGE, android.Manifest.permission.WRITE_EXTERNAL_STORAGE};
|
71
|
72
|
List<String> mPermissionList = new ArrayList<>();
|
|
@@ -78,7 +79,7 @@ public class Video extends AppCompatActivity {
|
78
|
79
|
private TextView countdownTextView;
|
79
|
80
|
private int totalTime = 4;
|
80
|
81
|
private RelativeLayout mainPage;
|
81
|
|
- private TextView tvHistory;
|
|
82
|
+ private TextView tvHistory, tvQuestion;
|
82
|
83
|
private TextView tvConnect;
|
83
|
84
|
private ImageView imgConnect;
|
84
|
85
|
|
|
@@ -123,11 +124,13 @@ public class Video extends AppCompatActivity {
|
123
|
124
|
setContentView(binding.getRoot());
|
124
|
125
|
countdownTextView = findViewById(R.id.countdownTextView);
|
125
|
126
|
tvConnect = findViewById(R.id.tvConnect);
|
|
127
|
+ tvQuestion = findViewById(R.id.tvQuestion);
|
126
|
128
|
imgConnect = findViewById(R.id.imgConnect);
|
127
|
129
|
mainPage = findViewById(R.id.mainPage);
|
128
|
130
|
bt1 = findViewById(R.id.bt1);
|
129
|
131
|
l1 = findViewById(R.id.l1);
|
130
|
132
|
l2 = findViewById(R.id.l2);
|
|
133
|
+ layoutMsg = findViewById(R.id.layoutMsg);
|
131
|
134
|
bt1 = findViewById(R.id.bt1);
|
132
|
135
|
bt2 = findViewById(R.id.bt2);
|
133
|
136
|
bt3 = findViewById(R.id.bt3);
|
|
@@ -139,18 +142,7 @@ public class Video extends AppCompatActivity {
|
139
|
142
|
long initialDelay1 = 1;
|
140
|
143
|
long period1 = 1;
|
141
|
144
|
service.scheduleAtFixedRate(new Task1(), initialDelay1, period1, TimeUnit.SECONDS);
|
142
|
|
- handler.postDelayed(new Runnable() {
|
143
|
|
- @Override
|
144
|
|
- public void run() {
|
145
|
|
- totalTime--;
|
146
|
|
- countdownTextView.setText(String.valueOf(totalTime));
|
147
|
|
- if (totalTime > 0) {
|
148
|
|
- handler.postDelayed(this, 1000);
|
149
|
|
- } else {
|
150
|
|
- // 倒计时结束,执行相应操作
|
151
|
|
- }
|
152
|
|
- }
|
153
|
|
- }, 1000);
|
|
145
|
+
|
154
|
146
|
new Thread(new Runnable() {
|
155
|
147
|
@Override
|
156
|
148
|
public void run() {
|
|
@@ -160,29 +152,44 @@ public class Video extends AppCompatActivity {
|
160
|
152
|
binding.handleCap.setOnClickListener(new View.OnClickListener() {
|
161
|
153
|
@Override
|
162
|
154
|
public void onClick(View v) {
|
163
|
|
- SoundPool soundPool = new SoundPool.Builder().setMaxStreams(1).build();
|
164
|
|
- int soundId = soundPool.load(Video.this, R.raw.kuaimen, 1); // 加载音频资源
|
165
|
|
- soundPool.setOnLoadCompleteListener(new SoundPool.OnLoadCompleteListener() {
|
|
155
|
+ handler.postDelayed(new Runnable() {
|
166
|
156
|
@Override
|
167
|
|
- public void onLoadComplete(SoundPool soundPool, int sampleId, int status) {
|
168
|
|
- soundPool.play(soundId, 1, 1, 1, 0, 1); // 播放音频
|
|
157
|
+ public void run() {
|
|
158
|
+ totalTime--;
|
|
159
|
+ countdownTextView.setText(String.valueOf(totalTime));
|
|
160
|
+ countdownTextView.setVisibility(View.VISIBLE);
|
|
161
|
+ if (totalTime > 0) {
|
|
162
|
+ handler.postDelayed(this, 1000);
|
|
163
|
+ } else {
|
|
164
|
+ totalTime = 4;
|
|
165
|
+ countdownTextView.setVisibility(View.GONE);
|
|
166
|
+ SoundPool soundPool = new SoundPool.Builder().setMaxStreams(1).build();
|
|
167
|
+ int soundId = soundPool.load(Video.this, R.raw.kuaimen, 1); // 加载音频资源
|
|
168
|
+ soundPool.setOnLoadCompleteListener(new SoundPool.OnLoadCompleteListener() {
|
|
169
|
+ @Override
|
|
170
|
+ public void onLoadComplete(SoundPool soundPool, int sampleId, int status) {
|
|
171
|
+ soundPool.play(soundId, 1, 1, 1, 0, 1); // 播放音频
|
|
172
|
+ }
|
|
173
|
+ });
|
|
174
|
+ Bitmap bitmap = binding.mSurfaceview.getBitmap(1920, 1080);
|
|
175
|
+ saveImageToGallery(getApplicationContext(), bitmap);
|
|
176
|
+ try {
|
|
177
|
+ File file = new File(getSdPath(), System.currentTimeMillis() + ".jpg");
|
|
178
|
+ OutputStream outputStream = new FileOutputStream(file);
|
|
179
|
+
|
|
180
|
+ bitmap.compress(Bitmap.CompressFormat.JPEG, 100, outputStream);
|
|
181
|
+
|
|
182
|
+ outputStream.close();
|
|
183
|
+ Toast.makeText(Video.this, "图片已保存到" + getSdPath() + "目录", Toast.LENGTH_SHORT).show();
|
|
184
|
+ } catch (FileNotFoundException e) {
|
|
185
|
+ throw new RuntimeException(e);
|
|
186
|
+ } catch (IOException e) {
|
|
187
|
+ throw new RuntimeException(e);
|
|
188
|
+ }
|
|
189
|
+ }
|
169
|
190
|
}
|
170
|
|
- });
|
171
|
|
- Bitmap bitmap = binding.mSurfaceview.getBitmap(1920, 1080);
|
172
|
|
- saveImageToGallery(getApplicationContext(), bitmap);
|
173
|
|
- try {
|
174
|
|
- File file = new File(getSdPath(), System.currentTimeMillis() + ".jpg");
|
175
|
|
- OutputStream outputStream = new FileOutputStream(file);
|
176
|
|
-
|
177
|
|
- bitmap.compress(Bitmap.CompressFormat.JPEG, 100, outputStream);
|
178
|
|
-
|
179
|
|
- outputStream.close();
|
180
|
|
- Toast.makeText(Video.this, "图片已保存到" + getSdPath() + "目录", Toast.LENGTH_SHORT).show();
|
181
|
|
- } catch (FileNotFoundException e) {
|
182
|
|
- throw new RuntimeException(e);
|
183
|
|
- } catch (IOException e) {
|
184
|
|
- throw new RuntimeException(e);
|
185
|
|
- }
|
|
191
|
+ }, 1000);
|
|
192
|
+
|
186
|
193
|
}
|
187
|
194
|
});
|
188
|
195
|
|
|
@@ -190,22 +197,27 @@ public class Video extends AppCompatActivity {
|
190
|
197
|
binding.handlerecord.setOnClickListener(new View.OnClickListener() {
|
191
|
198
|
@Override
|
192
|
199
|
public void onClick(View v) {
|
193
|
|
- //录像按钮
|
|
200
|
+ String path = getSdPath() + System.currentTimeMillis() + ".avi";
|
194
|
201
|
if (!recordFlag) {
|
195
|
|
- int i = JPGStartRecord(getSdPath() + System.currentTimeMillis() + ".avi");
|
|
202
|
+ int i = JPGStartRecord(path);
|
196
|
203
|
if (i == 0) {
|
197
|
204
|
recordFlag = true;
|
198
|
|
- binding.handlerecord.setImageResource(R.drawable.ic_app_video_recording);
|
|
205
|
+// binding.handlerecord.setImageResource(R.drawable.ic_app_video_recording);
|
|
206
|
+ binding.openDir.setImageResource(R.drawable.ic_app_compare_an);
|
199
|
207
|
}
|
200
|
208
|
|
201
|
209
|
} else {
|
202
|
210
|
recordFlag = false;
|
203
|
211
|
JPGStopRecord();
|
204
|
212
|
binding.handlerecord.setImageResource(R.drawable.ic_app_video);
|
|
213
|
+ binding.openDir.setImageResource(R.drawable.ic_app_compare);
|
205
|
214
|
Intent intent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE);
|
206
|
215
|
Uri uri = Uri.fromFile(new File(getSdPath()));
|
207
|
216
|
intent.setData(uri);
|
208
|
217
|
getApplicationContext().sendBroadcast(intent);
|
|
218
|
+ Intent intent2 = new Intent(Video.this, VideoViewActivity.class);
|
|
219
|
+ intent2.putExtra("extra_data", path);
|
|
220
|
+ startActivity(intent2);
|
209
|
221
|
}
|
210
|
222
|
}
|
211
|
223
|
});
|
|
@@ -217,6 +229,14 @@ public class Video extends AppCompatActivity {
|
217
|
229
|
}
|
218
|
230
|
});
|
219
|
231
|
|
|
232
|
+ binding.tvQuestion.setOnClickListener(new View.OnClickListener() {
|
|
233
|
+ @Override
|
|
234
|
+ public void onClick(View v) {
|
|
235
|
+ Intent intent = new Intent(Video.this, QuestionActivity.class);
|
|
236
|
+ startActivity(intent);
|
|
237
|
+ }
|
|
238
|
+ });
|
|
239
|
+
|
220
|
240
|
bt1.setOnClickListener(new View.OnClickListener() {
|
221
|
241
|
@Override
|
222
|
242
|
public void onClick(View view) {
|
|
@@ -302,26 +322,44 @@ public class Video extends AppCompatActivity {
|
302
|
322
|
length = inputStream.read(bytes);
|
303
|
323
|
Log.e(TAG, "serverSocketInit: length = " + length + Arrays.toString(bytes));
|
304
|
324
|
//抓取一张图片
|
305
|
|
- runOnUiThread(new Runnable() {
|
|
325
|
+
|
|
326
|
+ handler.postDelayed(new Runnable() {
|
306
|
327
|
@Override
|
307
|
328
|
public void run() {
|
308
|
|
- Bitmap bitmap = binding.mSurfaceview.getBitmap(1920, 1080);
|
309
|
|
- saveImageToGallery(getApplicationContext(), bitmap);
|
310
|
|
- try {
|
311
|
|
- File file = new File(getSdPath(), System.currentTimeMillis() + ".jpg");
|
312
|
|
- OutputStream outputStream = new FileOutputStream(file);
|
313
|
|
-
|
314
|
|
- bitmap.compress(Bitmap.CompressFormat.JPEG, 100, outputStream);
|
315
|
|
-
|
316
|
|
- outputStream.close();
|
317
|
|
- Toast.makeText(Video.this, "图片已保存到" + getSdPath() + "目录", Toast.LENGTH_SHORT).show();
|
318
|
|
- } catch (FileNotFoundException e) {
|
319
|
|
- throw new RuntimeException(e);
|
320
|
|
- } catch (IOException e) {
|
321
|
|
- throw new RuntimeException(e);
|
|
329
|
+ totalTime--;
|
|
330
|
+ countdownTextView.setText(String.valueOf(totalTime));
|
|
331
|
+ countdownTextView.setVisibility(View.VISIBLE);
|
|
332
|
+ if (totalTime > 0) {
|
|
333
|
+ handler.postDelayed(this, 1000);
|
|
334
|
+ } else {
|
|
335
|
+ totalTime = 4;
|
|
336
|
+ countdownTextView.setVisibility(View.GONE);
|
|
337
|
+ SoundPool soundPool = new SoundPool.Builder().setMaxStreams(1).build();
|
|
338
|
+ int soundId = soundPool.load(Video.this, R.raw.kuaimen, 1); // 加载音频资源
|
|
339
|
+ soundPool.setOnLoadCompleteListener(new SoundPool.OnLoadCompleteListener() {
|
|
340
|
+ @Override
|
|
341
|
+ public void onLoadComplete(SoundPool soundPool, int sampleId, int status) {
|
|
342
|
+ soundPool.play(soundId, 1, 1, 1, 0, 1); // 播放音频
|
|
343
|
+ }
|
|
344
|
+ });
|
|
345
|
+ Bitmap bitmap = binding.mSurfaceview.getBitmap(1920, 1080);
|
|
346
|
+ saveImageToGallery(getApplicationContext(), bitmap);
|
|
347
|
+ try {
|
|
348
|
+ File file = new File(getSdPath(), System.currentTimeMillis() + ".jpg");
|
|
349
|
+ OutputStream outputStream = new FileOutputStream(file);
|
|
350
|
+
|
|
351
|
+ bitmap.compress(Bitmap.CompressFormat.JPEG, 100, outputStream);
|
|
352
|
+
|
|
353
|
+ outputStream.close();
|
|
354
|
+ Toast.makeText(Video.this, "图片已保存到" + getSdPath() + "目录", Toast.LENGTH_SHORT).show();
|
|
355
|
+ } catch (FileNotFoundException e) {
|
|
356
|
+ throw new RuntimeException(e);
|
|
357
|
+ } catch (IOException e) {
|
|
358
|
+ throw new RuntimeException(e);
|
|
359
|
+ }
|
322
|
360
|
}
|
323
|
361
|
}
|
324
|
|
- });
|
|
362
|
+ }, 1000);
|
325
|
363
|
|
326
|
364
|
|
327
|
365
|
inputStream.close();
|
|
@@ -495,7 +533,9 @@ public class Video extends AppCompatActivity {
|
495
|
533
|
@Override
|
496
|
534
|
public void run() {
|
497
|
535
|
tvConnect.setText("暂未与设备链接");
|
|
536
|
+ tvConnect.setVisibility(View.GONE);
|
498
|
537
|
imgConnect.setImageResource(R.drawable.disconnect);
|
|
538
|
+ imgConnect.setVisibility(View.GONE);
|
499
|
539
|
l2.setVisibility(View.VISIBLE);
|
500
|
540
|
l1.setVisibility(View.GONE);
|
501
|
541
|
}
|
|
@@ -508,6 +548,7 @@ public class Video extends AppCompatActivity {
|
508
|
548
|
imgConnect.setImageResource(R.drawable.right);
|
509
|
549
|
l1.setVisibility(View.VISIBLE);
|
510
|
550
|
l2.setVisibility(View.GONE);
|
|
551
|
+ layoutMsg.setVisibility(View.GONE);
|
511
|
552
|
}
|
512
|
553
|
});
|
513
|
554
|
} else {
|
|
@@ -515,7 +556,9 @@ public class Video extends AppCompatActivity {
|
515
|
556
|
@Override
|
516
|
557
|
public void run() {
|
517
|
558
|
tvConnect.setText("暂未与设备链接");
|
|
559
|
+ tvConnect.setVisibility(View.GONE);
|
518
|
560
|
imgConnect.setImageResource(R.drawable.disconnect);
|
|
561
|
+ imgConnect.setVisibility(View.GONE);
|
519
|
562
|
l2.setVisibility(View.VISIBLE);
|
520
|
563
|
l1.setVisibility(View.GONE);
|
521
|
564
|
}
|