52
52
public class PreviewActivity extends Activity implements Device .Delegate , FrameProcessor .Delegate , Device .StreamDelegate , ConnectivityChangeReceiver .NetworkStateInteraction {
53
53
private ImageView thermalImageView ;
54
54
private volatile boolean imageCaptureRequested = false ;
55
-
56
55
private volatile Device flirOneDevice ;
57
56
private FrameProcessor frameProcessor ;
58
-
59
57
private String lastSavedPath ;
60
-
61
- //控制警告是否打开
62
58
private ToggleButton warnButton ;
63
-
64
- //播放警告音
65
59
private MediaPlayer mp , mp_strong ;
66
-
67
- //拍照音效
68
60
private SoundPool sp ;
69
61
private int sound ;
70
-
71
- //查看图片
72
62
private ImageButton showImage ;
73
63
private ImageHelp imageHelp ;
74
-
75
- //设置阈值
76
64
private Button showDialog ;
77
65
ThresholdHelp thresholdHelp ;
78
-
79
- //保存图片信息
80
66
private double maxTemp , meantTemp ;
81
67
private int maxX , maxY ;
82
-
83
- //点击屏幕获取温度
84
68
private int width ;
85
69
private int height ;
86
70
private short [] thermalPixels ;
87
-
88
- //nfc
89
71
private TextView showNfcResult ;
90
72
private String nfc_result ;
91
-
92
- //检测网络状态
93
73
private TextView showNetworkState ;
94
-
95
- //手机串号
96
74
private TextView showTeleimei ;
97
-
98
- //校准
99
75
private Device .TuningState currentTuningState = Device .TuningState .Unknown ;
100
76
101
- //Device.Delegate接口实现的方法,设备已连接
102
77
public void onDeviceConnected (Device device ) {
103
78
runOnUiThread (new Runnable () {
104
79
@ Override
@@ -109,10 +84,8 @@ public void run() {
109
84
110
85
flirOneDevice = device ;
111
86
flirOneDevice .startFrameStream (this );
112
-
113
87
}
114
88
115
- //Device.Delegate接口实现的方法,设备未连接
116
89
public void onDeviceDisconnected (Device device ) {
117
90
118
91
runOnUiThread (new Runnable () {
@@ -133,7 +106,6 @@ public void run() {
133
106
public void onTuningStateChanged (Device .TuningState tuningState ) {
134
107
135
108
currentTuningState = tuningState ;
136
- //当热成像设备正在连接
137
109
if (tuningState == Device .TuningState .InProgress ) {
138
110
runOnUiThread (new Thread () {
139
111
@ Override
@@ -148,7 +120,6 @@ public void run() {
148
120
}
149
121
});
150
122
} else {
151
- //连接成功
152
123
runOnUiThread (new Thread () {
153
124
@ Override
154
125
public void run () {
@@ -166,7 +137,6 @@ public void onAutomaticTuningChanged(boolean deviceWillTuneAutomatically) {
166
137
167
138
}
168
139
169
- //显示更新热成像视图
170
140
private void updateThermalImageView (final Bitmap frame ) {
171
141
runOnUiThread (new Runnable () {
172
142
@ Override
@@ -176,7 +146,6 @@ public void run() {
176
146
});
177
147
}
178
148
179
- //Device.StreamDelegate实现的方法,处理视图
180
149
public void onFrameReceived (Frame frame ) {
181
150
182
151
if (currentTuningState != Device .TuningState .InProgress ) {
@@ -186,18 +155,15 @@ public void onFrameReceived(Frame frame) {
186
155
187
156
private Bitmap thermalBitmap = null ;
188
157
189
- //FrameProcessor.Delegate接口实现的方法,的获取温度,视图处理器授权方法,将访问每次的frame的产生,实时进行扫描
190
158
public void onFrameProcessed (final RenderedImage renderedImage ) {
191
159
192
160
if (renderedImage .imageType () == RenderedImage .ImageType .ThermalRadiometricKelvinImage ) {
193
161
// Note: this code is not optimized
194
162
195
- thermalPixels = renderedImage .thermalPixelData (); //thermalPixels[76800]
196
- //每次扫描都会产生这样的一串数组
163
+ thermalPixels = renderedImage .thermalPixelData ();
197
164
198
- // 计算中心周围9个像素的平均值
199
165
width = renderedImage .width ();
200
- height = renderedImage .height (); //width * height = 76800
166
+ height = renderedImage .height ();
201
167
int centerPixelIndex = width * (height / 2 ) + (width / 2 );
202
168
int [] centerPixelIndexes = new int []{
203
169
centerPixelIndex , centerPixelIndex - 1 , centerPixelIndex + 1 ,
@@ -209,7 +175,6 @@ public void onFrameProcessed(final RenderedImage renderedImage) {
209
175
centerPixelIndex + width + 1
210
176
};
211
177
212
- //扫描全屏温度并进行高温预警
213
178
new Thread (new Runnable () {
214
179
short [] thermalPixels = renderedImage .thermalPixelData ();
215
180
int width = renderedImage .width ();
@@ -250,7 +215,7 @@ public void run() {
250
215
}).start ();
251
216
//////
252
217
253
- double averageTemp = 0 ; //平均温度,单位K
218
+ double averageTemp = 0 ;
254
219
255
220
for (int i = 0 ; i < centerPixelIndexes .length ; i ++) { //centerPixelIndexes.length = 9
256
221
// Remember: all primitives are signed, we want the unsigned value,
@@ -263,7 +228,6 @@ public void run() {
263
228
NumberFormat numberFormat = NumberFormat .getInstance ();
264
229
numberFormat .setMaximumFractionDigits (2 );
265
230
numberFormat .setMinimumFractionDigits (2 );
266
- //显示温度
267
231
final String spotMeterValue = numberFormat .format (averageC ) + "ºC" ;
268
232
269
233
runOnUiThread (new Runnable () {
@@ -297,7 +261,6 @@ public void run() {
297
261
updateThermalImageView (thermalBitmap );
298
262
}
299
263
300
- //捕获图像
301
264
if (this .imageCaptureRequested ) {
302
265
imageCaptureRequested = false ;
303
266
final Context context = this ;
@@ -334,8 +297,6 @@ public void onScanCompleted(String path, Uri uri) {
334
297
}
335
298
336
299
}
337
-
338
- //捕获图像单击事件
339
300
public void onCaptureImageClicked (View v ) {
340
301
341
302
if (flirOneDevice == null && lastSavedPath != null ) {
@@ -372,7 +333,6 @@ private void setThumb() {
372
333
}
373
334
}
374
335
375
- //获取文件名
376
336
private String getFileName () {
377
337
Date date = new Date ();
378
338
DateFormat format = new SimpleDateFormat ("yyyyMMddHHmmss" );
@@ -381,7 +341,6 @@ private String getFileName() {
381
341
return fileName ;
382
342
}
383
343
384
- //热成像主界面
385
344
@ Override
386
345
protected void onStart () {
387
346
super .onStart ();
@@ -405,7 +364,6 @@ protected void onStart() {
405
364
406
365
ScaleGestureDetector mScaleDetector ;
407
366
408
- //开机提示
409
367
private ProgressBar loading ;
410
368
private ImageView spotMeterIcon ;
411
369
@@ -415,15 +373,12 @@ protected void onCreate(Bundle savedInstanceState) {
415
373
this .requestWindowFeature (Window .FEATURE_NO_TITLE );
416
374
setContentView (R .layout .activity_preview );
417
375
418
- //启动上传服务
419
376
Intent serviceIntent = new Intent (PreviewActivity .this , UpLoadService .class );
420
377
startService (serviceIntent );
421
378
422
- //显示开机提示
423
379
spotMeterIcon = (ImageView ) findViewById (R .id .spotMeterIcon );
424
380
loading = (ProgressBar ) findViewById (R .id .loading );
425
381
426
- //网络检测
427
382
IntentFilter intentFilter = new IntentFilter ();
428
383
intentFilter .addAction (ConnectivityManager .CONNECTIVITY_ACTION );
429
384
ConnectivityChangeReceiver receiver = new ConnectivityChangeReceiver ();
@@ -433,8 +388,6 @@ protected void onCreate(Bundle savedInstanceState) {
433
388
//网络状态
434
389
showNetworkState = (TextView ) findViewById (R .id .show_network_state );
435
390
436
- //手机串号
437
- //设置手机串号
438
391
try {
439
392
showTeleimei = (TextView ) findViewById (R .id .show_teleimei );
440
393
TelephonyManager telephonyManager = (TelephonyManager ) this .getSystemService (Context .TELEPHONY_SERVICE );
@@ -458,11 +411,9 @@ public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
458
411
}
459
412
});
460
413
461
- //音效
462
414
sp = new SoundPool (10 , AudioManager .STREAM_SYSTEM , 5 );//第一个参数为同时播放数据流的最大个数,第二数据流类型,第三为声音质量
463
415
sound = sp .load (this , R .raw .sound , 0 );
464
416
465
- //阈值
466
417
showDialog = (Button ) findViewById (R .id .showDialog );
467
418
thresholdHelp = new ThresholdHelp (PreviewActivity .this , showDialog );
468
419
thresholdHelp .setThreshold ();
@@ -473,7 +424,6 @@ public void onClick(View v) {
473
424
}
474
425
});
475
426
476
- //设置默认滤镜
477
427
RenderedImage .ImageType defaultImageType = RenderedImage .ImageType .BlendedMSXRGBA8888Image ;
478
428
frameProcessor = new FrameProcessor (this , this , EnumSet .of (defaultImageType , RenderedImage .ImageType .ThermalRadiometricKelvinImage ));
479
429
@@ -494,15 +444,12 @@ public boolean onScale(ScaleGestureDetector detector) {
494
444
}
495
445
});
496
446
497
- //查看所有图片按钮设置缩略图
498
447
showImage = (ImageButton ) findViewById (R .id .showImage );
499
448
imageHelp = new ImageHelp (GlobalConfig .IMAGE_PATH );
500
449
setThumb ();
501
450
502
- //检查所有图片的时间
503
451
imageHelp .checkAllImagesDate ();
504
452
505
- //点击查看所有图片按钮进入图片展示页面
506
453
showImage .setOnClickListener (new View .OnClickListener () {
507
454
@ Override
508
455
public void onClick (View v ) {
@@ -511,7 +458,6 @@ public void onClick(View v) {
511
458
}
512
459
});
513
460
514
- //获取nfc 数据
515
461
showNfcResult = (TextView ) findViewById (R .id .show_nfc_result );
516
462
if (getIntent () != null ) {
517
463
nfc_result = getIntent ().getStringExtra ("nfcresult" );
@@ -553,7 +499,6 @@ protected void onDestroy() {
553
499
super .onDestroy ();
554
500
}
555
501
556
- //网络状态改变时设置提示文字
557
502
@ Override
558
503
public void setNetworkState (String state ) {
559
504
if (state != null ) {
0 commit comments