MainActivity.java
76.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
package com.sunvote.xpadapp;
import android.Manifest;
import android.annotation.SuppressLint;
import android.app.Fragment;
import android.app.FragmentManager;
import android.app.FragmentTransaction;
import android.app.ProgressDialog;
import android.content.BroadcastReceiver;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.graphics.Color;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.os.Environment;
import android.os.Handler;
import android.os.Message;
import android.support.v4.app.ActivityCompat;
import android.support.v4.content.FileProvider;
import android.telephony.TelephonyManager;
import android.util.Log;
import android.view.KeyEvent;
import android.view.MotionEvent;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;
import com.sunvote.udptransfer.Config;
import com.sunvote.util.EncryptUtils;
import com.sunvote.util.LogUtil;
import com.sunvote.util.SPUtils;
import com.sunvote.util.StringUtils;
import com.sunvote.xpadapp.base.BaseActivity;
import com.sunvote.xpadapp.base.BaseFragment;
import com.sunvote.xpadapp.db.DBManager;
import com.sunvote.xpadapp.db.modal.BillInfo;
import com.sunvote.xpadapp.db.modal.MeetingInfo;
import com.sunvote.xpadapp.db.modal.MultiTitleItem;
import com.sunvote.xpadapp.fragments.AdminFragment;
import com.sunvote.xpadapp.fragments.AuthorizationFragment;
import com.sunvote.xpadapp.fragments.ComErrorFragment;
import com.sunvote.xpadapp.fragments.CommunicationTestFragment;
import com.sunvote.xpadapp.fragments.ContentVoteFragment;
import com.sunvote.xpadapp.fragments.DocumentBrowserFragment;
import com.sunvote.xpadapp.fragments.DownloadFragment;
import com.sunvote.xpadapp.fragments.ElectionCustomFragment;
import com.sunvote.xpadapp.fragments.ElectionFragment;
import com.sunvote.xpadapp.fragments.FirmUpdateFragment;
import com.sunvote.xpadapp.fragments.KeypadTestChoice10Fragment;
import com.sunvote.xpadapp.fragments.KeypadTestFragment;
import com.sunvote.xpadapp.fragments.MeetingWelcomeFragment;
import com.sunvote.xpadapp.fragments.MultiContentDetailFragment;
import com.sunvote.xpadapp.fragments.MultiContentFragment;
import com.sunvote.xpadapp.fragments.MultiPingshengFragment;
import com.sunvote.xpadapp.fragments.MultiTitleFragment;
import com.sunvote.xpadapp.fragments.UserResultVoteFragment;
import com.sunvote.xpadapp.fragments.NoFileFragment;
import com.sunvote.xpadapp.fragments.OfflineFragment;
import com.sunvote.xpadapp.fragments.OnLineFragment;
import com.sunvote.xpadapp.fragments.PDFContextShowFragment;
import com.sunvote.xpadapp.fragments.ResultElectionFragment;
import com.sunvote.xpadapp.fragments.ResultMultiVoteFragment;
import com.sunvote.xpadapp.fragments.ResultVoteFragment;
import com.sunvote.xpadapp.fragments.ShowIdFragment;
import com.sunvote.xpadapp.fragments.SigninFragment;
import com.sunvote.xpadapp.fragments.SinginResultFragment;
import com.sunvote.xpadapp.fragments.SingleTitleFragment;
import com.sunvote.xpadapp.presenter.ServicePresent;
import com.sunvote.xpadapp.presenter.XPadPresenter;
import com.sunvote.xpadapp.server.MoniService;
import com.sunvote.xpadapp.utils.FileUtil;
import com.sunvote.xpadapp.utils.SharedPreferencesUtil;
import com.sunvote.xpadcomm.ComListener;
import com.sunvote.xpadcomm.FileRecver;
import com.sunvote.xpadcomm.ScreenUtil;
import com.sunvote.xpadcomm.XPadApi;
import com.sunvote.xpadcomm.XPadApiInterface.BaseInfo;
import com.sunvote.xpadcomm.XPadApiInterface.CmdDataInfo;
import com.sunvote.xpadcomm.XPadApiInterface.KeypadInfo;
import com.sunvote.xpadcomm.XPadApiInterface.ModelInfo;
import com.sunvote.xpadcomm.XPadApiInterface.OnLineInfo;
import com.sunvote.xpadcomm.XPadApiInterface.VoteInfo;
import com.sunvote.xpadcomm.XPadSystem;
import java.io.File;
import java.io.UnsupportedEncodingException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Timer;
import java.util.TimerTask;
import java.util.UUID;
@SuppressLint("NewApi")
public class MainActivity extends BaseActivity implements ComListener {
private final int Msg_ComError = 0;
private final int Msg_Offline = 1;
private final int Msg_Online = 2;
private final int Msg_Download = 3;
private final int Msg_Welcome = 4;
// private final int Msg_Signin = 5;
// private final int Msg_QuickVote = 6;
// private final int Msg_SingleTitleVote = 7;
// private final int Msg_MultiTitleVote = 8;
// private final int Msg_SingleContentVote = 9;
// private final int Msg_MultiContentVote = 10;
// private final int Msg_ElectionVote = 11;
public static final int Msg_StopDownload = 12;
// private final int Msg_KeypadTest = 13;
private final int Msg_CommunicationTest = 14;//100次成功率
private final int Msg_ShowID = 15;
private final int Msg_HideShowID = 17;
// private final int Msg_MultiPingShengVote = 16;
private final int Msg_onVoteEvent = 20;
private final int Msg_onCommitSuccessEvent = 21;
private final int Msg_onCommitAllOkSuccessEvent = 22;
private final int Msg_onMultiPackageData = 23;//显示结果
private final int Msg_HideVoteResult = 24;
private final int Msg_ShowMultiVoteResult = 25;
private final int Msg_DBfileNotExist = 30;
private final int Msg_MatchInfo = 31;
private final int Msg_CommunicationTestHideResult = 32;
private final int Msg_onCommitErrorEvent = 33;
public static final int Msg_DocumentBroswer = 40;
private final int Msg_ShowBill = 41;
private final int Msg_ScreenDark = 50;
private final int Msg_ChangeBright = 51;
// private final int Msg_ChangeOffTime = 52;
private final int Msg_FirmUpdate = 53;
private final int Msg_HideFirmUpdate = 54;
public static final int MSG_DELAY_TO_VIEW = 56;
private final int Msg_ShowElectionVoteResult = 60;
private final int Msg_ShowCustomTitleResult = 61;
private final int MSG_SHOW_ADMIN = 100;
private final int MSG_CLEAN_FILE = 101;
public BroadcastReceiver batteryLevelRcvr;
// WifiManager wifiManager;
// WiFiConnecter wac;
private String TAG = "MainActivity";
FragmentManager fm = getFragmentManager();
private FileRecver cs = null;
private String ip = "192.168.0.105";
private int port = 15154;
private BaseFragment billFragment;
private BaseFragment currFragment;
public BaseFragment multiContentFragment;
private DownloadFragment downloadFragment;
private DocumentBrowserFragment docFragment;
public BaseFragment pdfFragment;
private Fragment showIdFragment;
public Fragment resultFragment;
private FirmUpdateFragment firmFragment;
private String wifiSsid;
private String wifiPwd;
private String serverIp;
private int serverPort;
public XPadPresenter presenter;
public OnLineInfo mOnlineInfo;
public BaseInfo mBaseInfo;
public KeypadInfo mKeypadInfo;
public VoteInfo mVoteInfo;
public ModelInfo mModelInfo;
public String meetingDir;
public MeetingInfo meetingInfo;
public BillInfo currBillInfo;
public BillInfo subBillInfo;
public DBManager dbm;
public int meetingId;
public int roleType;//1 正式代表 , 2 列席代表 0 未配置
private boolean inKeyTesting = false;
private boolean isChair=false;
private long lastTouchTime;
private Timer screenTimer;
private long scrTimerCnt;
private Integer brigntLevel;
private Integer darkTime;// minit
public long startVoteTime;// 启动投票时间 用于测试10选1 功能
public boolean isLoadPDF;
private boolean downloading = false;
public AdminFragment adminFragment;
private FrameLayout lockscreen;
private TextView terminalId;
private ImageView service;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
terminalId = findViewById(R.id.terminal_id);
service = findViewById(R.id.service);
lockscreen = findViewById(R.id.lockscreen);
if (service != null) {
service.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (mOnlineInfo.onLine == 1) {
showServiceDialog();
service.setVisibility(View.GONE);
} else {
Intent intent = new Intent(MainActivity.this, ConnectWifiActivity.class);
startActivity(intent);
}
}
});
}
mOnlineInfo = new OnLineInfo();
mOnlineInfo.onLine = 0;
presenter = new XPadPresenter(this);
setOnlineFragment();
darkTime = (Integer) SharedPreferencesUtil.getData(MainActivity.this, "darkTime", 3);
brigntLevel = (Integer) SharedPreferencesUtil.getData(MainActivity.this, "bright", 30);
ScreenUtil.setNormalMode(MainActivity.this, brigntLevel);
screenTimer = new Timer(true);
screenTimer.schedule(screenTask, 1000, 1000); // 延时1000ms后执行,1000ms执行一次
clearApkFile();
FirmUpdateFragment.clearUpdateFile();
if(!isUnlock()){
setUnlockScreen();
}
}
public void setTerminalId(int id) {
terminalId.setText(getString(R.string.terminal_id) + id);
}
@Override
public void onAttachedToWindow() {
hideBottomUIMenu();
super.onAttachedToWindow();
}
public void hideBottomUIMenu() {
// 隐藏虚拟按键,并且全屏
if (Build.VERSION.SDK_INT > 11 && Build.VERSION.SDK_INT < 19) { // lower
// api
View v = this.getWindow().getDecorView();
v.setSystemUiVisibility(View.GONE);
} else if (Build.VERSION.SDK_INT >= 19) {
// for new api versions.
View decorView = getWindow().getDecorView();
int uiOptions = View.SYSTEM_UI_FLAG_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY | 0x00002000;
decorView.setSystemUiVisibility(uiOptions);
}
}
public void showBottomUIMenu() {
// 隐藏虚拟按键,并且全屏
if (Build.VERSION.SDK_INT > 11 && Build.VERSION.SDK_INT < 19) { // lower
// api
View v = this.getWindow().getDecorView();
v.setSystemUiVisibility(View.GONE);
} else if (Build.VERSION.SDK_INT >= 19) {
// for new api versions.
View decorView = getWindow().getDecorView();
int uiOptions = View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY //| View.SYSTEM_UI_FLAG_FULLSCREEN
& ~0x00002000;
decorView.setSystemUiVisibility(uiOptions);
}
XPadSystem.setNavgationVisible(this);
}
@Override
protected void onResume() {
hideBottomUIMenu();
setTerminalId(XPadApi.getInstance().getClient().getUdpModuleNO());
super.onResume();
}
public void setBackgroundColor(int color){
findViewById(R.id.root).setBackgroundColor(color);
}
@Override
protected void onPause() {
LogUtil.i(TAG, "onPause");
super.onPause();
}
@Override
protected void onStop() {
LogUtil.i(TAG, "onstop");
XPadSystem.setNavgationVisible(this);
super.onStop();
}
@Override
protected void onDestroy() {
super.onDestroy();
showBottomUIMenu();
XPadApi.getInstance().closeCom();
if (batteryLevelRcvr != null) {
unregisterReceiver(batteryLevelRcvr);
}
System.exit(0);
}
public Handler myHandler = new Handler() {
@Override
public void handleMessage(Message msg) {
switch (msg.what) {
case Msg_ComError:
setComErrorFragment();
break;
case Msg_Offline:
setOfflineFragment();
break;
case Msg_Online:
setOnlineFragment();
break;
case Msg_Download:
if (!downloading) {
clearApkFile();
FirmUpdateFragment.clearUpdateFile();
downloading = true;
setDownloadFragment();
}
break;
case Msg_StopDownload:
downloading = false;
if (downloadFragment != null) {
downloadFragment.stopDownload();
hideDownloadFragment();
}
if (dbm != null) {
try {
dbm.closeDB();
dbm = null;
} catch (Exception e) {
LogUtil.e(TAG, e);
}
}
docFragment = null;
File apkFile = checkUpdateApkFile();
File firmFile = FirmUpdateFragment.checkFirmFile();
String str = String.format("Msg_StopDownload apkFile:%s ,firmFile:%s", apkFile != null ? "Y" : "N", firmFile != null ? "Y" : "N");
//Toast.makeText(MainActivity.this,str,Toast.LENGTH_SHORT).show();
LogUtil.d(TAG, "handleMessage: " + str);
if (firmFile != null) {
LogUtil.i(TAG, "handleMessage: firm update");
setFirmUpdateFragment();
} else if (apkFile != null) {
LogUtil.i(TAG, "handleMessage: install apk");
Intent intent1 = new Intent(MainActivity.this,MoniService.class);
stopService(intent1);
myHandler.removeCallbacks(installTask);
myHandler.postDelayed(installTask,2000);
// installApk(apkFile);
} else {
LogUtil.i(TAG, "handleMessage: stop download and getBaseStatus");
presenter.getBaseStatus();
}
// dbm.closeDB();
// if (meetingInfo != null) {
// setWelcomeFragment();
// } else {
// setOnlineFragment();
// }
break;
case Msg_Welcome:
setWelcomeFragment();
break;
case Msg_ShowBill:
BaseInfo baseInfo = (BaseInfo) msg.obj;
if (baseInfo.pageNo > 0) {
setPDFContextShowFragment(baseInfo);
} else {
showBill(null, baseInfo.pageNo);
}
break;
case Msg_DocumentBroswer:
setDocumentBrowserFragment();
break;
case MSG_DELAY_TO_VIEW:
if (mBaseInfo != null && mBaseInfo.billId == 255 &&(mVoteInfo.mode == 0 || mVoteInfo.mode == 1)) { // 自由浏览
freeBrowsing();
}
break;
case Msg_onVoteEvent:
VoteInfo vote = (VoteInfo) msg.obj;
doVote(vote);
break;
case Msg_onCommitSuccessEvent:
if (multiContentFragment != null) {
multiContentFragment.onVoteSubmitSuccess();
}
if (currFragment != null) {
XPadApi.VoteResultItem item = (XPadApi.VoteResultItem) msg.obj;
currFragment.onVoteSubmitSuccess(item);
}
break;
case Msg_onCommitErrorEvent:
if (multiContentFragment != null) {
multiContentFragment.onVoteSubmitError();
} else {
XPadApi.VoteResultItem item = (XPadApi.VoteResultItem) msg.obj;
if (currFragment != null) {
currFragment.onVoteSubmitError(item);
}
}
break;
case Msg_onCommitAllOkSuccessEvent:
if (multiContentFragment != null) {
multiContentFragment.onVoteSubmitAllOkSuccess();
}
if (currFragment != null) {
currFragment.onVoteSubmitAllOkSuccess();
}
break;
case Msg_onMultiPackageData:// 显示结果
break;
case Msg_ShowMultiVoteResult:
showMultiVoteResultFragment((byte[]) msg.obj);
break;
case Msg_ShowElectionVoteResult:
showResultElectionFragment((byte[]) msg.obj);
break;
case Msg_ShowCustomTitleResult:
showVoteResultFragment((byte[]) msg.obj);
break;
case Msg_HideVoteResult:// 隐藏结果
hideResultFragment();
break;
case Msg_DBfileNotExist:
setNoFileFragment();
break;
case Msg_CommunicationTest:
showCommucationFragment((byte[]) msg.obj);
break;
case Msg_ShowID:
setShowIdFragment();
break;
case Msg_HideShowID:
hideShowIdFragment();
break;
case Msg_MatchInfo:
KeypadInfo info = (KeypadInfo) msg.obj;
mKeypadInfo = info;
ShowMatchInfo(info);
break;
case Msg_CommunicationTestHideResult:
dlg.dismiss();
break;
case Msg_ScreenDark:
if (!App.isBackground(MainActivity.this)) {
ScreenUtil.setDarkMode(MainActivity.this);
}
break;
case Msg_ChangeBright:
brigntLevel = msg.arg1;
LogUtil.d(TAG, "-----change bright percent :" + brigntLevel);
ScreenUtil.setNormalMode(MainActivity.this, brigntLevel);
break;
case Msg_FirmUpdate:
setFirmUpdateFragment();
break;
case Msg_HideFirmUpdate:
hideFirmUpdateFragment();
break;
case MSG_SHOW_ADMIN:
showAdmin();
break;
case MSG_CLEAN_FILE:
Toast.makeText(MainActivity.this, "文件清除完成!", Toast.LENGTH_SHORT).show();
break;
default:
}
super.handleMessage(msg);
}
};
public void showAdmin() {
FragmentManager fm = getFragmentManager();
FragmentTransaction tx = fm.beginTransaction();
if (adminFragment == null) {
adminFragment = new AdminFragment();
tx.add(R.id.frame_content, adminFragment, "admin");
tx.addToBackStack("admin");
tx.commitAllowingStateLoss();
LogUtil.i(TAG, "showAdmin");
}
}
private void ShowMatchInfo(KeypadInfo info) {
if (info.cmd1 == 8) { // 配对
String strMsg = null;
if (info.ok == 1) {
strMsg = "键盘编号:" + info.keyId;
} else {
strMsg = "配对失败";
}
Toast.makeText(this, strMsg, Toast.LENGTH_SHORT).show();
} else if (info.cmd1 == 9) {
String strMsg = null;
if (info.ok == 1) {
strMsg = "键盘编号:" + info.keyId;
} else {
strMsg = "配置失败";
}
Toast.makeText(this, strMsg, Toast.LENGTH_SHORT).show();
}
setTerminalId(info.keyId);
}
private void hideResultFragment() {
setBackgroundColor(Color.parseColor("#720600"));
if (resultFragment == null) {
return;
}
FragmentManager fm = getFragmentManager();
FragmentTransaction tx = fm.beginTransaction();
tx.setCustomAnimations(android.R.animator.fade_in, android.R.animator.fade_out);
fm.popBackStack();
tx.remove(resultFragment);
tx.commitAllowingStateLoss();
resultFragment = null;
}
private ProgressDialog dlg = null;
private CommunicationTestFragment commFragment;
private void showCommucationFragment(byte[] info) {
if (dlg == null) {
dlg = new ProgressDialog(MainActivity.this);
dlg.setCancelable(true);// 设置是否可以通过点击Back键取消
dlg.setCanceledOnTouchOutside(true);// 设置在点击Dialog外是否取消Dialog进度条
}
if (!dlg.isShowing()) {
dlg.show();
}
dlg.setTitle("通讯测试");
dlg.setMessage("通讯测试 次数:" + info[0] + " 成功次数:" + info[1] + " 基站信号:" + info[2] + " 键盘信号:" + info[3]);
myHandler.removeCallbacks(closeDlg);
myHandler.postDelayed(closeDlg, 20 * 1000);
}
private Runnable closeDlg = new Runnable() {
@Override
public void run() {
Message message = new Message();
message.what = Msg_CommunicationTestHideResult;
myHandler.sendMessage(message);
}
};
public void removePDFContextShowFragment() {
if (pdfFragment != null) {
PDFContextShowFragment fr = (PDFContextShowFragment) pdfFragment;
fr.setCloseFile();
pdfFragment = null;
}
}
private void setPDFContextShowFragment(BaseInfo baseInfo) {
if (currBillInfo == null) {
Toast.makeText(this, "没找到议案信息", Toast.LENGTH_LONG).show();
return;
}
String dataPath = android.os.Environment.getExternalStorageDirectory().getAbsolutePath();
String filePath = dataPath + "/sunvote/" + meetingId + "/" + currBillInfo.billFile;
File file = new File(filePath);
if (!file.exists()) {
Toast.makeText(this, "议案文件未找到", Toast.LENGTH_LONG).show();
return;
}
FragmentManager fm = getFragmentManager();
FragmentTransaction tx = fm.beginTransaction();
PDFContextShowFragment fr = new PDFContextShowFragment();
fr.setInfo(filePath, currBillInfo.billFile, baseInfo.pageNo + "", "1", true);
if (isLoadPDF) {
if (!fr.PDFLastOpenFilename.equals(currBillInfo.billFile)) {
removePDFContextShowFragment();
isLoadPDF = false;
} else {
fr.setTopBarstate();
fr.setPageIndex(baseInfo.pageNo);
fr.lockPageState(1);
}
}
pdfFragment = fr;
tx.add(R.id.frame_content, fr, "PDF");
tx.addToBackStack("PDF");
tx.commitAllowingStateLoss();
}
private void showVoteResultFragment(VoteInfo vote) {
hideResultFragment();
FragmentManager fm = getFragmentManager();
FragmentTransaction transaction = fm.beginTransaction();
ResultVoteFragment fr = new ResultVoteFragment();
// fr.voteInfo = vote;
// fr.bill = currBillInfo;
fr.setVoteInfo(vote);
resultFragment = fr;
transaction.setCustomAnimations(android.R.animator.fade_in, android.R.animator.fade_out);
transaction.add(R.id.frame_content, fr);
transaction.addToBackStack("voteresult");
transaction.commitAllowingStateLoss();
LogUtil.i(TAG, "showVoteResultFragment 信标");
}
private void showSigninResultFragment(VoteInfo vote) {
hideResultFragment();
FragmentManager fm = getFragmentManager();
FragmentTransaction transaction = fm.beginTransaction();
SinginResultFragment fr = new SinginResultFragment();
fr.setResultInfo(vote.resultInfo);
resultFragment = fr;
transaction.setCustomAnimations(android.R.animator.fade_in, android.R.animator.fade_out);
transaction.add(R.id.frame_content, fr);
transaction.addToBackStack("signinresult");
transaction.commitAllowingStateLoss();
LogUtil.i(TAG, "showSigninResultFragment 信标");
}
private void showResultElectionFragment(byte[] buffer) {
int voteId = buffer[3] & 0xff;
if (dbm == null) {
Toast.makeText(this, "请先开始会议", Toast.LENGTH_LONG).show();
return;
}
currBillInfo = dbm.getBillInfo(meetingId, voteId);
if (currBillInfo == null) {
Toast.makeText(this, "显示选举结果失败,没有找到会议资料", Toast.LENGTH_LONG).show();
return;
}
if (currBillInfo.billNo == 0 && currBillInfo.billId == 0) {
Toast.makeText(this, "没找到议案信息", Toast.LENGTH_LONG).show();
return;
}
hideCurrFragment();
hideResultFragment();
FragmentTransaction transaction = fm.beginTransaction();
ResultElectionFragment fr = new ResultElectionFragment();
fr.data = buffer;
fr.bill = currBillInfo;
resultFragment = fr;
transaction.setCustomAnimations(android.R.animator.fade_in, android.R.animator.fade_out);
transaction.add(R.id.frame_content, fr);
transaction.addToBackStack("PDF");
transaction.commitAllowingStateLoss();
LogUtil.i(TAG, "showResultElectionFragment buffer");
}
private void showVoteResultFragment(byte[] buffer) {
int voteId = buffer[3] & 0xff;
if (dbm == null) {
Toast.makeText(this, "请先开始会议", Toast.LENGTH_LONG).show();
return;
}
currBillInfo = dbm.getBillInfo(meetingId, voteId);
roleType = dbm.getKeypadRole(XPadApi.getInstance().getClient().getUdpModuleNO());
if (currBillInfo == null) {
Toast.makeText(this, "显示批次结果失败,没有找到会议资料", Toast.LENGTH_LONG).show();
return;
}
if (currBillInfo.billOptions == null) {
Toast.makeText(this, "显示结果失败,选项为空", Toast.LENGTH_LONG).show();
return;
}
hideCurrFragment();
hideResultFragment();
FragmentTransaction transaction = fm.beginTransaction();
UserResultVoteFragment fr = new UserResultVoteFragment();
fr.setData(buffer);
fr.setOptions(currBillInfo.billOptions.split("/"));
resultFragment = fr;
transaction.setCustomAnimations(android.R.animator.fade_in, android.R.animator.fade_out);
transaction.add(R.id.frame_content, fr);
transaction.addToBackStack("voteresult");
transaction.commitAllowingStateLoss();
LogUtil.i(TAG, "showVoteResultFragment buffer");
}
private void showMultiVoteResultFragment(byte[] buffer) {
int voteId = buffer[3] & 0xff;
if (dbm == null) {
Toast.makeText(this, "请先开始会议", Toast.LENGTH_SHORT).show();
return;
}
currBillInfo = dbm.getBillInfo(meetingId, voteId);
if (currBillInfo == null) {
Toast.makeText(this, "显示批次结果失败,没有找到会议资料", Toast.LENGTH_SHORT).show();
return;
}
if (currBillInfo.billOptions == null) {
Toast.makeText(this, "显示批次结果失败,选项为空", Toast.LENGTH_SHORT).show();
return;
}
hideCurrFragment();
hideResultFragment();
FragmentManager fm = getFragmentManager();
FragmentTransaction transaction = fm.beginTransaction();
ResultMultiVoteFragment fr = new ResultMultiVoteFragment();
fr.bill = currBillInfo;
fr.data = buffer;
resultFragment = fr;
// transaction.setCustomAnimations(android.R.animator.fade_in,android.R.animator.fade_out);
transaction.add(R.id.frame_content, fr);
transaction.addToBackStack("multivote");
transaction.commitAllowingStateLoss();
LogUtil.i(TAG, "showMultiVoteResultFragment buffer");
}
private void setFirmUpdateFragment() {
LogUtil.i(TAG, "setFirmUpdateFragment: ");
FragmentManager fm = getFragmentManager();
FragmentTransaction transaction = fm.beginTransaction();
if (firmFragment == null) {
firmFragment = new FirmUpdateFragment();
}
transaction.setCustomAnimations(android.R.animator.fade_in, android.R.animator.fade_out);
transaction.replace(R.id.frame_content, firmFragment);
// transaction.addToBackStack(null);
transaction.commitAllowingStateLoss();
}
private void hideFirmUpdateFragment() {
if (firmFragment != null) {
FragmentManager fm = getFragmentManager();
FragmentTransaction tx = fm.beginTransaction();
tx.setCustomAnimations(android.R.animator.fade_in, android.R.animator.fade_out);
tx.remove(firmFragment);
tx.commitAllowingStateLoss();
firmFragment = null;
}
}
private OfflineFragment offlineFragment;
private void setOfflineFragment() {
service.setImageResource(R.drawable.scan_qrcode);
FragmentManager fm = getFragmentManager();
FragmentTransaction transaction = fm.beginTransaction();
transaction.setCustomAnimations(android.R.animator.fade_in, android.R.animator.fade_out);
if (offlineFragment == null) {
offlineFragment = new OfflineFragment();
transaction.add(R.id.frame_content, offlineFragment);
transaction.addToBackStack("offlineFragment");
LogUtil.i(TAG, "setOfflineFragment");
} else {
transaction.replace(R.id.frame_content, offlineFragment);
}
transaction.commitAllowingStateLoss();
Intent intent = new Intent(this,MoniService.class);
stopService(intent);
}
private ComErrorFragment comErrorFragment;
private void setComErrorFragment() {
FragmentManager fm = getFragmentManager();
FragmentTransaction transaction = fm.beginTransaction();
transaction.setCustomAnimations(android.R.animator.fade_in, android.R.animator.fade_out);
if (comErrorFragment == null) {
comErrorFragment = new ComErrorFragment();
transaction.add(R.id.frame_content, comErrorFragment);
transaction.addToBackStack("comErrorFragment");
} else {
transaction.replace(R.id.frame_content, comErrorFragment);
}
transaction.commitAllowingStateLoss();
LogUtil.i(TAG, "setComErrorFragment");
}
private OnLineFragment onLineFragment;
private void setOnlineFragment() {
FragmentManager fm = getFragmentManager();
FragmentTransaction transaction = fm.beginTransaction();
transaction.setCustomAnimations(android.R.animator.fade_in, android.R.animator.fade_out);
if (onLineFragment == null) {
onLineFragment = new OnLineFragment();
transaction.add(R.id.frame_content, onLineFragment);
transaction.addToBackStack("onLineFragment");
} else {
transaction.replace(R.id.frame_content, onLineFragment);
}
transaction.commitAllowingStateLoss();
LogUtil.i(TAG, "setOnlineFragment");
presenter.getBaseStatus();
service.setImageResource(R.drawable.service_server);
Intent intent = new Intent(this,MoniService.class);
startService(intent);
}
private void setShowIdFragment() {
FragmentManager fm = getFragmentManager();
FragmentTransaction transaction = fm.beginTransaction();
transaction.setCustomAnimations(android.R.animator.fade_in, android.R.animator.fade_out);
if (showIdFragment == null) {
showIdFragment = new ShowIdFragment();
transaction.add(R.id.frame_content, showIdFragment);
transaction.addToBackStack("showIdFragment");
transaction.commitAllowingStateLoss();
LogUtil.i(TAG, "showIdFragment");
}
}
private void hideShowIdFragment() {
if (showIdFragment != null) {
FragmentManager fm = getFragmentManager();
FragmentTransaction tx = fm.beginTransaction();
tx.setCustomAnimations(android.R.animator.fade_in, android.R.animator.fade_out);
tx.remove(showIdFragment);
tx.commitAllowingStateLoss();
showIdFragment = null;
}
}
private KeypadTestFragment keypadTestFragment;
private void setKeypadTestFragment() {
if (keypadTestFragment == null) {
inKeyTesting = true;
FragmentManager fm = getFragmentManager();
FragmentTransaction tx = fm.beginTransaction();
tx.setCustomAnimations(android.R.animator.fade_in, android.R.animator.fade_out);
keypadTestFragment = new KeypadTestFragment();
tx.add(R.id.frame_content, keypadTestFragment);
tx.addToBackStack("keypadTestFragment");
tx.commitAllowingStateLoss();
LogUtil.i(TAG, "keypadTestFragment");
}
}
private KeypadTestChoice10Fragment keypadTestChoice10Fragment;
private void setChoice10Fragment() {
inKeyTesting = true;
FragmentManager fm = getFragmentManager();
FragmentTransaction tx = fm.beginTransaction();
tx.setCustomAnimations(android.R.animator.fade_in, android.R.animator.fade_out);
if (keypadTestChoice10Fragment == null) {
keypadTestChoice10Fragment = new KeypadTestChoice10Fragment();
tx.add(R.id.frame_content, keypadTestChoice10Fragment);
tx.addToBackStack("setChoice10Fragment");
} else {
tx.replace(R.id.frame_content, keypadTestChoice10Fragment);
}
tx.commitAllowingStateLoss();
LogUtil.i(TAG, "setChoice10Fragment");
}
private void hideKeypadTestFragment() {
inKeyTesting = false;
if (keypadTestFragment != null) {
FragmentManager fm = getFragmentManager();
FragmentTransaction tx = fm.beginTransaction();
tx.setCustomAnimations(android.R.animator.fade_in, android.R.animator.fade_out);
tx.remove(keypadTestFragment);
tx.commitAllowingStateLoss();
keypadTestFragment = null;
}
LogUtil.i(TAG, "hideKeypadTestFragment");
}
private long lastSetDownloadTime = 0;
private void setDownloadFragment() {
if (System.currentTimeMillis() - lastSetDownloadTime < 5000) {
LogUtil.i(TAG, "ignore redownload");
return;
}
if (mKeypadInfo == null) {
presenter.getKeypadParam();
}
if (wifiSsid == null || wifiSsid.length() == 0) {
// Toast.makeText(this, "wifiSsid is null ", Toast.LENGTH_SHORT).show();
// return;
}
if (wifiPwd == null || wifiPwd.length() == 0) {
// Toast.makeText(this, "wifiPwd is null ", Toast.LENGTH_SHORT).show();
// return;
}
if (serverIp == null || serverIp.length() == 0) {
// Toast.makeText(this, "serverIp is null ", Toast.LENGTH_SHORT).show();
// return;
serverIp = Config.getInstance().serverIP;
}
// if(serverPort == 0){
// Toast.makeText(this, "serverPort is 0 ", Toast.LENGTH_SHORT);
// return;
// }
lastSetDownloadTime = System.currentTimeMillis();
FragmentTransaction transaction = fm.beginTransaction();
transaction.setCustomAnimations(android.R.animator.fade_in, android.R.animator.fade_out);
if (downloadFragment == null) {
downloadFragment = new DownloadFragment();
serverPort = 4002;
downloadFragment.setInfo(wifiSsid, wifiPwd, serverIp, serverPort, XPadApi.getInstance().getClient().getUdpModuleNO());
transaction.add(R.id.frame_content, downloadFragment);
transaction.addToBackStack("downloadFragment");
} else {
serverPort = 4002;
downloadFragment.setInfo(wifiSsid, wifiPwd, serverIp, serverPort, XPadApi.getInstance().getClient().getUdpModuleNO());
transaction.replace(R.id.frame_content, downloadFragment);
}
transaction.commitAllowingStateLoss();
LogUtil.i(TAG, "downloadFragment");
}
private void hideDownloadFragment() {
if (downloadFragment != null) {
FragmentTransaction tx = fm.beginTransaction();
tx.setCustomAnimations(android.R.animator.fade_in, android.R.animator.fade_out);
tx.remove(downloadFragment);
tx.commitAllowingStateLoss();
downloadFragment = null;
LogUtil.i(TAG, "hideDownloadFragment");
}
}
private MeetingWelcomeFragment meetingWelcomeFragment;
private void setWelcomeFragment() {
// if (mBaseInfo == null) {
// mBaseInfo = new BaseInfo();
// mBaseInfo.confId = 1;
// }
FragmentTransaction transaction = fm.beginTransaction();
transaction.setCustomAnimations(android.R.animator.fade_in, android.R.animator.fade_out);
if (meetingWelcomeFragment == null) {
meetingWelcomeFragment = new MeetingWelcomeFragment();
}
meetingWelcomeFragment.setMeeting();
transaction.replace(R.id.frame_content, meetingWelcomeFragment);
transaction.commitAllowingStateLoss();
LogUtil.i(TAG, "setWelcomeFragment");
}
private NoFileFragment noFileFragment;
private void setNoFileFragment() {
FragmentTransaction transaction = fm.beginTransaction();
transaction.setCustomAnimations(android.R.animator.fade_in, android.R.animator.fade_out);
if (noFileFragment == null) {
noFileFragment = new NoFileFragment();
noFileFragment.setMeetingId(meetingId);
transaction.add(R.id.frame_content, noFileFragment);
transaction.addToBackStack("setNoFileFragment");
} else {
transaction.replace(R.id.frame_content, noFileFragment);
}
transaction.commitAllowingStateLoss();
LogUtil.i(TAG,"setNoFileFragment");
}
private SigninFragment signinFragment;
private void setSigninFragment(VoteInfo info) {
hideDownloadFragment();
FragmentTransaction transaction = fm.beginTransaction();
transaction.setCustomAnimations(android.R.animator.fade_in, android.R.animator.fade_out);
signinFragment = new SigninFragment();
signinFragment.setInfo(info);
currFragment = signinFragment;
transaction.add(R.id.frame_content, currFragment);
transaction.commitAllowingStateLoss();
LogUtil.i(TAG,"setSigninFragment");
}
private void setQuickVoteFragment() {
FragmentTransaction transaction = fm.beginTransaction();
transaction.setCustomAnimations(android.R.animator.fade_in, android.R.animator.fade_out);
SingleTitleFragment fr = new SingleTitleFragment();
fr.setInfo(currBillInfo);
currFragment = fr;
transaction.add(R.id.frame_content, currFragment);
transaction.addToBackStack("setQuickVoteFragment");
transaction.commitAllowingStateLoss();
LogUtil.i(TAG,"setQuickVoteFragment");
}
private void setTitleVoteFragment(VoteInfo vote) {
hideDownloadFragment();
FragmentTransaction transaction = fm.beginTransaction();
transaction.setCustomAnimations(android.R.animator.fade_in, android.R.animator.fade_out);
SingleTitleFragment fr = new SingleTitleFragment();
fr.setInfo(currBillInfo, vote);
currFragment = fr;
transaction.add(R.id.frame_content, currFragment);
transaction.addToBackStack("titleVote");
transaction.commitAllowingStateLoss();
LogUtil.i(TAG,"setTitleVoteFragment");
}
private void setMultiTitleVoteFragment(VoteInfo vote) {
if (currBillInfo == null) {
Toast.makeText(this, "没找到议案信息", Toast.LENGTH_SHORT).show();
return;
}
ArrayList<MultiTitleItem> list = dbm.getMultiTitleItems(meetingId, currBillInfo.billId);
FragmentTransaction transaction = fm.beginTransaction();
transaction.setCustomAnimations(android.R.animator.fade_in, android.R.animator.fade_out);
MultiTitleFragment fr = new MultiTitleFragment();
fr.setInfo(currBillInfo, vote, list);
currFragment = fr;
transaction.add(R.id.frame_content, currFragment);
transaction.addToBackStack("multititleVote");
transaction.commitAllowingStateLoss();
LogUtil.i(TAG, "setMultiTitleVoteFragment");
}
private void setSingleContentVoteFragment() {
FragmentTransaction transaction = fm.beginTransaction();
transaction.setCustomAnimations(android.R.animator.fade_in, android.R.animator.fade_out);
ContentVoteFragment fr = new ContentVoteFragment();
fr.setInfo(currBillInfo);
currFragment = fr;
transaction.replace(R.id.frame_content, currFragment);
transaction.commitAllowingStateLoss();
LogUtil.i(TAG, "setSingleContentVoteFragment");
}
private void setMultiContentVoteFragment() {
ArrayList<MultiTitleItem> list = dbm.getMultiTitleItems(meetingId, currBillInfo.billId);
FragmentTransaction transaction = fm.beginTransaction();
transaction.setCustomAnimations(android.R.animator.fade_in, android.R.animator.fade_out);
MultiContentFragment fr = new MultiContentFragment();
fr.setInfo(currBillInfo, list);
currFragment = fr;
transaction.replace(R.id.frame_content, currFragment);
transaction.commitAllowingStateLoss();
LogUtil.i(TAG, "setMultiContentVoteFragment");
}
private void setDocumentBrowserFragment() {
ArrayList<BillInfo> list = dbm.getBillItemsMain(meetingId);
FragmentTransaction transaction = fm.beginTransaction();
transaction.setCustomAnimations(android.R.animator.fade_in, android.R.animator.fade_out);
if (docFragment == null) {
docFragment = new DocumentBrowserFragment();
docFragment.setInfo(list, false);
}
transaction.replace(R.id.frame_content, docFragment);
transaction.commitAllowingStateLoss();
LogUtil.i(TAG, "setDocumentBrowserFragment");
}
private void showBill(VoteInfo vInfo, final int pageNo) {
if (currBillInfo.billFile == null) {
return;
}
hideDownloadFragment();
FragmentManager fm = getFragmentManager();
FragmentTransaction tx = fm.beginTransaction();
tx.setCustomAnimations(android.R.animator.fade_in, android.R.animator.fade_out);
if (vInfo != null) {
MultiContentDetailFragment fr = new MultiContentDetailFragment();
fr.setInfo(currBillInfo, vInfo, false, pageNo, 1);
currFragment = fr;
tx.add(R.id.frame_content, currFragment, "fDetail");
tx.addToBackStack("fDetail");
tx.commitAllowingStateLoss();
LogUtil.i(TAG, "fDetail");
} else {
if (currFragment instanceof MultiContentDetailFragment) {
((MultiContentDetailFragment) currFragment).setPdfPage(pageNo);
LogUtil.i(TAG, "fDetail setPdfPage");
} else {
MultiContentDetailFragment fDetail = new MultiContentDetailFragment();
fDetail.setInfo(currBillInfo, vInfo, false, pageNo, 1);
currFragment = fDetail;
tx.add(R.id.frame_content, fDetail, "fDetail");
tx.addToBackStack("fDetail");
tx.commitAllowingStateLoss();
LogUtil.i(TAG, "MultiContentDetailFragment setPdfPage");
}
}
}
private void setMultiPinsShengFragment() {
ArrayList<MultiTitleItem> list = dbm.getMultiTitleItems(meetingId, currBillInfo.billId);
FragmentTransaction transaction = fm.beginTransaction();
transaction.setCustomAnimations(android.R.animator.fade_in, android.R.animator.fade_out);
MultiPingshengFragment fr = new MultiPingshengFragment();
fr.setInfo(currBillInfo, list);
currFragment = fr;
transaction.replace(R.id.frame_content, currFragment);
transaction.commitAllowingStateLoss();
LogUtil.i(TAG, "setMultiPinsShengFragment");
}
private void setElectionVoteFragment(VoteInfo vote) {
if (dbm == null) {
Toast.makeText(this, "请先开始会议", Toast.LENGTH_LONG).show();
return;
}
currBillInfo = dbm.getBillInfo(meetingId, vote.electInfo.voteid);
roleType = dbm.getKeypadRole(XPadApi.getInstance().getClient().getUdpModuleNO());
if (currBillInfo == null) {
Toast.makeText(this, "没找到议案信息", Toast.LENGTH_LONG).show();
return;
}
if (currBillInfo.billNo == 0 && currBillInfo.billId == 0) {
Toast.makeText(this, "没找到议案信息", Toast.LENGTH_LONG).show();
return;
}
ArrayList<MultiTitleItem> list = dbm.getCandidateList(meetingId, currBillInfo.billId);
FragmentTransaction transaction = fm.beginTransaction();
transaction.setCustomAnimations(android.R.animator.fade_in, android.R.animator.fade_out);
ElectionFragment fr = new ElectionFragment();
fr.setInfo(currBillInfo, list, vote);
currFragment = fr;
transaction.add(R.id.frame_content, currFragment);
transaction.addToBackStack("electionvote");
transaction.commitAllowingStateLoss();
LogUtil.i(TAG, "setElectionVoteFragment");
}
private void setCustomElectionVoteFragment(VoteInfo vote) {
if (currBillInfo == null) {
Toast.makeText(this, "没找到议案信息", Toast.LENGTH_LONG).show();
return;
}
if(currBillInfo.billNo==0 && currBillInfo.billId==0){
Toast.makeText(this, "没找到议案信息", Toast.LENGTH_LONG).show();
return;
}
if(currBillInfo.billOptions.split("/") == null){
Toast.makeText(this, "显示批次结果失败,选项为空", Toast.LENGTH_LONG).show();
return;
}
LogUtil.i(TAG,"setMultiTitleVoteFragment");
ArrayList<MultiTitleItem> list = dbm.getMultiTitleItems(meetingId, currBillInfo.billId);
FragmentTransaction transaction = fm.beginTransaction();
transaction.setCustomAnimations(android.R.animator.fade_in, android.R.animator.fade_out);
ElectionCustomFragment fr = new ElectionCustomFragment();
fr.setInfo(currBillInfo,list,vote);
currFragment = fr;
transaction.add(R.id.frame_content, currFragment);
transaction.addToBackStack("multititleVote");
transaction.commitAllowingStateLoss();
LogUtil.i(TAG, "setCustomElectionVoteFragment");
}
public void getBillInfo(int billId) {
currBillInfo = dbm.getBillInfo(meetingId, billId);
}
@Override
public void onComData(byte[] data, int len) {
// TODO Auto-generated method stub
}
@Override
public void onSendData(byte[] data, int len) {
// TODO Auto-generated method stub
}
@Override
public void onModelEvent(ModelInfo info) {
LogUtil.i(TAG, "onModelEvent");
mModelInfo = info;
if (firmFragment != null) {
Intent intent = new Intent();
intent.setAction("com.xpad.firm");
intent.putExtra("ver", info.sVer);
MainActivity.this.sendBroadcast(intent);
LogUtil.i(TAG, "send broadcast");
// firmFragment.setFirmVer(mModelInfo.sVer);
}
}
@Override
public void onBaseEvent(BaseInfo info) {
mBaseInfo = info;
LogUtil.i(TAG, "baseEvent:" + info);
meetingId = info.confId;
//attrib bit 6 1 表示服务可以申请,0,表示服务关闭
if((mBaseInfo.attrib & 0x20) != 0){
runOnUiThread(new Runnable() {
@Override
public void run() {
service.setVisibility(View.VISIBLE);
}
});
}else{
runOnUiThread(new Runnable() {
@Override
public void run() {
service.setVisibility(View.GONE);
}
});
}
if (info.confId != 0) {
if (dbm != null && dbm.confId != info.confId) {
dbm.closeDB();
docFragment = null;
}
if (dbm == null || !dbm.checkDB() || dbm.confId != info.confId) {
dbm = new DBManager(this, info.confId);// 如果没打开,则打开数据库
roleType = dbm.getKeypadRole(XPadApi.getInstance().getClient().getUdpModuleNO());
}
if (!dbm.checkDB()) {
Message message = new Message();
message.what = Msg_DBfileNotExist;
myHandler.sendMessage(message);
presenter.getVoteStatus();
return;
}
if (meetingInfo == null || info.billId <= 1) {
meetingInfo = dbm.getMettingInfo(info.confId);
roleType = dbm.getKeypadRole(XPadApi.getInstance().getClient().getUdpModuleNO());
}
if (info.billId == 0) { // 没有议案的情况,显示欢迎界面
if (mOnlineInfo.onLine == 1) {
removePDFContextShowFragment();
Message message = new Message();
message.what = Msg_Welcome;
myHandler.sendMessage(message);
}
} else if (info.billId == 255) { // 自由浏览
freeBrowsing();
} else {// 进入议案
currBillInfo = dbm.getBillInfo(info.confId, info.billId);
Message message = new Message();
message.what = Msg_ShowBill;
message.obj = info;
myHandler.sendMessage(message);
// processBaseEvent();
}
presenter.getVoteStatus();
// 显示会议标题
} else {// confId为0 ,表示停止会议
if (mOnlineInfo.onLine == 1) {
Message message = new Message();
message.what = Msg_Online;
myHandler.sendMessage(message);
}
if (dbm != null) {
dbm.closeDB();
}
}
}
private void freeBrowsing() {
if (dbm != null && dbm.checkDB()) {
removePDFContextShowFragment();
Message message = new Message();
message.what = Msg_DocumentBroswer;
myHandler.sendMessage(message);
}
}
@Override
public void onVoteEvent(VoteInfo info) {
startVoteTime = System.currentTimeMillis();
LogUtil.i(TAG, "onVoteEvent " + info);
if (downloading) {
Message message = new Message();
message.what = Msg_StopDownload;
myHandler.sendMessage(message);
}
Message message = new Message();
message.what = Msg_onVoteEvent;
message.obj = info;
myHandler.sendMessage(message);
}
private void hideCurrFragment() {
if (currFragment != null) {
LogUtil.i(TAG, "hideCurrFragment success, " + currFragment.getClass().getName());
FragmentManager fm = getFragmentManager();
FragmentTransaction tx = fm.beginTransaction();
tx.setCustomAnimations(android.R.animator.fade_in, android.R.animator.fade_out);
if(currFragment instanceof SingleTitleFragment) {
if (multiContentFragment != null) {
tx.remove(multiContentFragment);
multiContentFragment = null;
}
}
fm.popBackStack();
tx.remove(currFragment);
tx.commitAllowingStateLoss();
currFragment = null;
}
}
private void doVote(VoteInfo voteInfo) {
LogUtil.i(TAG,"doVote:" + voteInfo);
mVoteInfo=voteInfo;
if (voteInfo.mode == XPadApi.VoteType_KeypadTest) {
setKeypadTestFragment();
return;
} else if (voteInfo.mode == XPadApi.VoteType_Choice && voteInfo.mode5 == 10) {
setChoice10Fragment();
return;
} else if (voteInfo.mode == XPadApi.VoteType_Stop) {
if (inKeyTesting) {
hideKeypadTestFragment();
return;
}
}
if(mBaseInfo!=null){
if(mBaseInfo.billId==0 || mBaseInfo.billId==255){
removePDFContextShowFragment();
}
}
hideResultFragment();
/*
* 暂时去掉角色 if (mKeypadInfo != null && dbm != null) { roleType =
* dbm.getKeypadRole(mKeypadInfo.keyId); Log.d(TAG, "roleType:" +
* roleType); } if (roleType == 0) {// 列席代表不处理 return; }
*/
tmpMulResultBuffer = null;
if (!(voteInfo.mode == XPadApi.VoteType_Stop && voteInfo.mode1_msgType == 2
&& voteInfo.resultInfo.resultType == XPadApi.VoteType_BatchVote)) {
hideCurrFragment();
}
if (dbm == null || !dbm.checkDB() ) {
dbm = new DBManager(this, this.meetingId);// 如果没打开,则打开数据库
}
roleType = dbm.getKeypadRole(XPadApi.getInstance().getClient().getUdpModuleNO());
// voteInfo.voteid = 1;//debug
if (voteInfo.voteid > 0 && voteInfo.voteid < 255) {
try {
currBillInfo = dbm.getBillInfo(meetingId, voteInfo.voteid);
} catch (Exception e) {
e.printStackTrace();
}
if (currBillInfo == null) {
LogUtil.i(TAG, "BillInfo not found!!!");
}
}
if (voteInfo.mode == XPadApi.VoteType_Stop) {
int count = fm.getBackStackEntryCount();
LogUtil.i(TAG, "getBackStackEntryCount:" + count );
if(count > 1){
for(int i = 0; i < count ; i++){
LogUtil.i(TAG, "name:" + fm.getBackStackEntryAt(i).getName());
}
}
if (voteInfo.mode1_msgType == 2) { // 结果显示
if(voteInfo.resultInfo.resultType == XPadApi.VoteType_Stop){
showSigninResultFragment(voteInfo);
}else if (voteInfo.resultInfo.resultType == XPadApi.VoteType_BatchVote) { // 多项
if (currFragment != null) {
currFragment.onVoteEvent(voteInfo);
}
} else if (voteInfo.resultInfo.resultType !=101 && voteInfo.resultInfo.resultType != XPadApi.VoteType_BatchElect){
showVoteResultFragment(voteInfo);
}
}
} else if (voteInfo.mode == XPadApi.VoteType_Signin) {
if(isChair){
return;
}
if(roleType != 2){
setSigninFragment(voteInfo);
}
}else if (voteInfo.mode == XPadApi.VoteType_Evaluate){
}else if(voteInfo.mode == XPadApi.VoteType_BatchElect){
if(isChair){
return;
}
if(roleType != 2) {
setElectionVoteFragment(voteInfo);
}
}else {
if (voteInfo.mode == XPadApi.VoteType_BatchVote) {
/**
* 是否带票数限定,,对批次表决、批次评议、批次自定义评议有效
0 不限定
1 带票数限定
*/
if(voteInfo.fixballot==1){
if (dbm != null && dbm.checkDB()) {
if(isChair){
return;
}
if(roleType != 2){
setCustomElectionVoteFragment(voteInfo);
}
}else{
if(meetingId>0) {
Toast.makeText(this, "启动差额选举失败,会议" + meetingId + "不存在,请下载会议资料", Toast.LENGTH_LONG).show();
}
}
}else {
if (dbm != null && dbm.checkDB()) {
if(isChair){
return;
}
if(roleType != 2){
setMultiTitleVoteFragment(voteInfo);
}
}else{
LogUtil.i(TAG, "doVote: "+"启动批次表决失败,会议" + meetingId + "不存在,请下载会议资料");
if(meetingId>0) {
Toast.makeText(this, "启动批次表决失败,会议" + meetingId + "不存在,请下载会议资料", Toast.LENGTH_LONG).show();
}
}
}
} else {
if (voteInfo.init == 0 || checkHasBillFile(currBillInfo) == false) {
if(isChair){
return;
}
if(roleType != 2){
setTitleVoteFragment(voteInfo);
}
} else {
if(isChair){
return;
}
billFragment=null;
if(roleType != 2) {
showBill(voteInfo,1);
}
}
}
}
}
private boolean isInVoteState(){
if(mVoteInfo != null){
return mVoteInfo.mode > 0 ;
}
return false;
}
private boolean checkHasBillFile(BillInfo bill) {
return (bill != null && bill.billFile != null && bill.billFile.length() > 0);
}
@Override
public void onVoteSubmitSuccess(XPadApi.VoteResultItem item) {
Message message = new Message();
message.obj = item;
message.what = Msg_onCommitSuccessEvent;
myHandler.sendMessage(message);
}
@Override
public void onVoteSubmitAllOkSuccess() {
Message message = new Message();
message.what = Msg_onCommitAllOkSuccessEvent;
myHandler.sendMessage(message);
}
@Override
public void onKeyPadEvent(KeypadInfo info) {
LogUtil.i(TAG, "onKeyPadEvent");
mKeypadInfo = info;
XPadSystem.setStatusBarPadID(this, info.keyId);
XPadSystem.setStatusBarChannel(this, info.chan);
if (info.cmd1 == 8 || info.cmd1 == 9) {
Message message = new Message();
message.what = Msg_MatchInfo;
message.obj = info;
myHandler.sendMessage(message);
}
}
@Override
public void onOnLineEvent(OnLineInfo info) {
if (info.comError == 1) {
if (info.comError != mOnlineInfo.comError) {
Message message = new Message();
message.what = Msg_ComError;
myHandler.sendMessage(message);
}
LogUtil.i(TAG, "onOnLineEvent: comError");
} else {
if (info.onLine != mOnlineInfo.onLine) {
if (info.onLine == 1) {
Message message = new Message();
message.what = Msg_Online;
myHandler.sendMessage(message);
presenter.getBaseStatus();
LogUtil.i(TAG, "onOnLineEvent: onLine");
} else {
Message message = new Message();
message.what = Msg_Offline;
myHandler.sendMessage(message);
LogUtil.i(TAG, "onOnLineEvent: offLine");
}
} else if (info.onLine == 1) {
if (offlineFragment != null && offlineFragment.isVisible) {
Message message = new Message();
message.what = Msg_Online;
myHandler.sendMessage(message);
presenter.getBaseStatus();
LogUtil.i(TAG, "onOnLineEvent: onLine");
}
}
}
mOnlineInfo = info;
XPadSystem.setStatusBarDataIcon(this, info.tx, info.rx);
XPadSystem.setStatusBarChannel(this, info.chan);
XPadSystem.setStatusBarBaseId(this, getString(R.string.base_id) + ":" + info.baseId);
XPadSystem.setStatusBarSingal(this, info.rssi);
}
private CmdDataInfo cmdInfo;
private long lastRecvCmdDataTime;
private long lastCleanCmd;
private long lastAdminCmd;
@Override
public void onCmdData(CmdDataInfo info) {
if (cmdInfo != null && info.cmd == cmdInfo.cmd && Arrays.equals(info.data, cmdInfo.data)
&& (System.currentTimeMillis() - lastRecvCmdDataTime < 1000)) {
LogUtil.i(TAG, "onCmdData,recv same data, ignore!");
return;
}
lastRecvCmdDataTime = System.currentTimeMillis();
cmdInfo = info;
XPadApi.printDataBuf(info.data, info.data.length, "cmd:" + info.cmd + " data:");
if (info.cmd == 7) { // 键盘测试
Message message = new Message();
message.what = Msg_CommunicationTest;
message.obj = info.data;
myHandler.sendMessage(message);
} else if (info.cmd == 10) {// 显示编号
if (info.data[0] == 0) {
LogUtil.i(TAG, "Msg_HideShowID");
Message message = new Message();
message.what = Msg_HideShowID;
myHandler.sendMessage(message);
} else {
LogUtil.i(TAG, "Msg_ShowID");
Message message = new Message();
message.what = Msg_ShowID;
myHandler.sendMessage(message);
}
} else if (info.cmd == 5) {// 关机
XPadSystem.powerOffXPad(this);
finish();
Intent intent = new Intent(this,MoniService.class);
stopService(intent);
} else if (info.cmd == 50) {// 主控透传
byte cmd = info.data[0];
LogUtil.i(TAG, "cmd:" + cmd);
byte[] data = Arrays.copyOfRange(info.data, 1, 19);
Message message = null;
switch (cmd) {
case 0x31:// wifi ssid
wifiSsid = new String(data).trim();
LogUtil.i(TAG, "receve 0x31 wifi ssid:" + wifiSsid);
break;
case 0x32:// wifi pwd
wifiPwd = new String(data).trim();
LogUtil.i(TAG, "receve 0x32 wifi pwd:" + wifiPwd);
break;
case 0x33: // ip
serverIp = new String(data).trim();
LogUtil.i(TAG, "receve 0x33 server ip:" + serverIp);
break;
case 0x34: // start download
LogUtil.i(TAG, "receve start download");
message = new Message();
message.what = Msg_Download;
myHandler.sendMessage(message);
break;
case 0x35: // stop download
LogUtil.i(TAG, "receve stop download");
message = new Message();
message.what = Msg_StopDownload;
myHandler.sendMessage(message);
break;
case 0x36: // 暂去掉角色控制
LogUtil.i(TAG, "not support");
break;
case 0x37:
XPadSystem.rebootXPad(this);
break;
case 0x38:
message = new Message();
message.what = Msg_HideVoteResult;
myHandler.sendMessage(message);
break;
case 0x39:
message = new Message();
message.what = Msg_ChangeBright;
message.arg1 = info.data[1];
myHandler.sendMessage(message);
SharedPreferencesUtil.saveData(MainActivity.this, "bright", Integer.valueOf(info.data[1]));
break;
case 0x40:
if (info.data[1] == 0) {
message = new Message();
message.what = Msg_ScreenDark;
myHandler.sendMessage(message);
} else {
message = new Message();
message.what = Msg_ChangeBright;
message.arg1 = brigntLevel;
myHandler.sendMessage(message);
}
break;
case 0x41:
darkTime = Integer.valueOf(info.data[1]);
scrTimerCnt = 0;
LogUtil.i(TAG, "set darkTime:" + darkTime);
SharedPreferencesUtil.saveData(MainActivity.this, "darkTime", darkTime);
break;
case 0x42:
if (System.currentTimeMillis() - lastCleanCmd > 8000) {
lastCleanCmd = System.currentTimeMillis();
FileUtil.deleteFile(new File(Environment.getExternalStorageDirectory().getPath() + "/sunvote"), "sunvote.dat");
message = new Message();
message.what = MSG_CLEAN_FILE;
myHandler.sendMessage(message);
}
break;
case 0x43:
if (System.currentTimeMillis() - lastAdminCmd > 8000) {
lastAdminCmd = System.currentTimeMillis();
message = new Message();
message.what = MSG_SHOW_ADMIN;
myHandler.sendMessage(message);
}
break;
default:
break;
}
} else if (info.cmd == 66) {//66.加上一键统一清除会议文件功能。
FileUtil.deleteFile(new File(Environment.getExternalStorageDirectory().getPath() + "/sunvote"));
} else if (info.cmd == 67) {//67.遥控统一进入管理员界面
Message message = new Message();
message.what = MSG_SHOW_ADMIN;
myHandler.sendMessage(message);
}
}
private byte[] tmpMulResultBuffer;
@Override
public void onMultiPackageData(byte[] data, int len) {
LogUtil.i(TAG,"onMultiPackageData");
XPadApi.printDataBuf(data, len, "onMultiPackageData:");
byte[] buf = new byte[len];
Arrays.fill(buf, (byte) 0x0);
System.arraycopy(data, 0, buf, 0, len);
if(isInVoteState()){
return;
}
if ((data[0] & 0xff) == 0xF2 && data[1] == 20) {
if (tmpMulResultBuffer != null && Arrays.equals(buf, tmpMulResultBuffer)) {
Log.e(TAG, "onMultiPackageData same data,abort");
return;
}
tmpMulResultBuffer = buf;
Message message = new Message();
message.what = Msg_ShowMultiVoteResult;
message.obj = buf;
myHandler.sendMessage(message);
return;
}
//选举结果
if ((data[0] & 0xff) == 0xF2 && data[1] == 22) {
if (tmpMulResultBuffer != null && Arrays.equals(buf, tmpMulResultBuffer)) {
Log.e(TAG, "onMultiPackageData same data,abort");
return;
}
tmpMulResultBuffer = buf;
Message message = new Message();
message.what = Msg_ShowElectionVoteResult;
message.obj = buf;
myHandler.sendMessage(message);
return;
}
//自定义表决结果
if ((data[0] & 0xff) == 0xF2 && data[1] == 101) {
if (tmpMulResultBuffer != null && Arrays.equals(buf, tmpMulResultBuffer)) {
LogUtil.i(TAG, "onMultiPackageData same data,abort");
return;
}
tmpMulResultBuffer = buf;
Message message = new Message();
message.what = Msg_ShowCustomTitleResult;
message.obj = buf;
myHandler.sendMessage(message);
return;
}
String str;
try {
str = new String(buf, "GB2312").trim();
LogUtil.i(TAG, "onMultiPackageInfo:" + str);
Message message = new Message();
message.what = Msg_onMultiPackageData;
message.arg1 = len;
message.obj = str;
myHandler.sendMessage(message);
} catch (UnsupportedEncodingException e) {
LogUtil.e(TAG, e);
}
}
@Override
public void onVoteSubmitError(XPadApi.VoteResultItem item) {
Message message = new Message();
message.obj = item;
message.what = Msg_onCommitErrorEvent;
myHandler.sendMessage(message);
}
TimerTask screenTask = new TimerTask() {
public void run() {
scrTimerCnt++;
if (scrTimerCnt == darkTime * 60) {
scrTimerCnt = 0;
Message message = new Message();
message.what = Msg_ScreenDark;
myHandler.sendMessage(message);
}
}
};
@Override
public boolean dispatchTouchEvent(MotionEvent event) {
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:
scrTimerCnt = 0;
ScreenUtil.setNormalMode(MainActivity.this, brigntLevel);
LogUtil.i("CustomBtnonTouchEvent", "MotionEvent.ACTION_DOWN");
break;
case MotionEvent.ACTION_MOVE:
// LogUtil.i("CustomButton--onTouchEvent", "MotionEvent.ACTION_MOVE");
break;
case MotionEvent.ACTION_UP:
// LogUtil.i("CustomButton--onTouchEvent", "MotionEvent.ACTION_UP");
break;
default:
break;
}
return super.dispatchTouchEvent(event);
}
@Override
public void onFirmUpdate(int percent) {
if (firmFragment != null) {
firmFragment.onFirmUpdate(percent);
}
}
@Override
public void onFirmUpdateResult(boolean success, String msg) {
if (firmFragment != null) {
firmFragment.onFirmUpdateResult(success, msg);
}
}
@Override
public void onFirmUpdateInfo(String info) {
if (firmFragment != null) {
firmFragment.onFirmUpdateInfo(info);
}
}
@Override
public void onComCommunicationTest(int sendn, boolean checkOk) {
// if (adminFragment != null) {
// adminFragment.onComCommunicationTest(sendn, checkOk);
// }
}
private File checkUpdateApkFile() {
String filePath = Environment.getExternalStorageDirectory().getPath() + "/sunvote/apk/";
File file = new File(filePath);
if (file == null) {
LogUtil.i(TAG, "checkUpdateApkFile: no apk dir");
return null;
}
if (!file.exists()) {
LogUtil.i(TAG, "checkUpdateApkFile: no apk dir2");
return null;
}
File[] files = file.listFiles();
if (files == null || files.length == 0) {
LogUtil.i(TAG, "checkUpdateApkFile: no apk file");
return null;
}
return files[0];
}
private void clearApkFile() {
try {
String filePath = Environment.getExternalStorageDirectory().getPath() + "/sunvote/apk/";
File file = new File(filePath);
FileUtil.deleteFile(file);
filePath = Environment.getExternalStorageDirectory().getPath() + "/sunvote/apk.zip";
file = new File(filePath);
FileUtil.deleteFile(file);
} catch (Exception e) {
// TODO: handle exception
}
}
private Runnable installTask = new Runnable() {
@Override
public void run() {
File apkFile = checkUpdateApkFile();
if(apkFile != null){
installApk(apkFile);
}
}
};
protected void installApk(File apkFile) {
Intent intent = new Intent();
// 执行动作
intent.setAction(Intent.ACTION_VIEW);
// 执行的数据类型
// intent.setDataAndType(Uri.fromFile(apkFile), "application/vnd.android.package-archive");
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
intent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
Uri contentUri = FileProvider.getUriForFile(this, BuildConfig.APPLICATION_ID + ".fileProvider", apkFile);
intent.setDataAndType(contentUri, "application/vnd.android.package-archive");
} else {
intent.setDataAndType(Uri.fromFile(apkFile), "application/vnd.android.package-archive");
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
}
startActivity(intent);
}
public void showPDFFragment() {
PDFContextShowFragment pdfContextShowFragment = new PDFContextShowFragment();
pdfContextShowFragment.setInfo("/sdcard/ETest/androittext.pdf", "android", "1", "0", false);
FragmentManager fm = getFragmentManager();
FragmentTransaction transaction = fm.beginTransaction();
transaction.setCustomAnimations(android.R.animator.fade_in, android.R.animator.fade_out);
transaction.add(R.id.frame_content, pdfContextShowFragment);
transaction.addToBackStack("PDF");
transaction.commitAllowingStateLoss();
LogUtil.i(TAG, "showPDFFragment");
}
public void showServiceDialog() {
View servicePanel = findViewById(R.id.service_panel);
final ServicePresent servicePresent = new ServicePresent(this, servicePanel);
DialogInterface.OnDismissListener dismissListener = new DialogInterface.OnDismissListener() {
@Override
public void onDismiss(DialogInterface dialog) {
service.setVisibility(View.VISIBLE);
servicePresent.dismiss();
}
};
servicePresent.setDismissListener(dismissListener);
servicePresent.show();
}
public String getImei() {
TelephonyManager TelephonyMgr = (TelephonyManager) getSystemService(TELEPHONY_SERVICE);
String uid = UUID.randomUUID().toString().replace("-","").substring(0,15);
String saveIime = SPUtils.getString(this,"IMEI");
String szImei = "" ;
if (ActivityCompat.checkSelfPermission(this, Manifest.permission.READ_PHONE_STATE) == PackageManager.PERMISSION_GRANTED) {
szImei = TelephonyMgr.getDeviceId();
if("0000000000000".equals(szImei) || StringUtils.isEmpty(szImei)){
if(saveIime != null){
szImei = saveIime ;
}else{
szImei = uid;
}
}
}else{
if(saveIime != null){
szImei = saveIime ;
}else{
szImei = uid;
}
}
SPUtils.putString(this,"IMEI",szImei);
return szImei.toUpperCase();
}
public String password(){
String password = EncryptUtils.encryptMD5ToString( "SUNVOTE" + getImei() + "SUNVOTE");
password = EncryptUtils.encryptMD5ToString("SUNVOTE" + password + "SUNVOTE");
if(password.length() > 6){
password = password.substring(0,6);
}
return password;
}
public boolean isUnlock(){
String key = EncryptUtils.encryptMD5ToString(getImei() + password());
return SPUtils.getBoolean(this,key,false);
}
public void unlock(){
String key = EncryptUtils.encryptMD5ToString(getImei() + password());
SPUtils.putBoolean(this,key,true);
}
private AuthorizationFragment authorizationFragment ;
public void setUnlockScreen(){
if(authorizationFragment == null) {
FragmentTransaction transaction = fm.beginTransaction();
authorizationFragment = new AuthorizationFragment();
transaction.replace(R.id.lockscreen, authorizationFragment);
transaction.commit();
lockscreen.setVisibility(View.VISIBLE);
LogUtil.i(TAG, "setUnlockScreen");
}
}
public void removeUnlockScreen(){
if(authorizationFragment != null) {
FragmentManager fm = getFragmentManager();
FragmentTransaction tx = fm.beginTransaction();
tx.setCustomAnimations(android.R.animator.fade_in, android.R.animator.fade_out);
tx.remove(authorizationFragment);
tx.commitAllowingStateLoss();
lockscreen.setVisibility(View.GONE);
authorizationFragment = null;
}
}
@Override
public boolean dispatchKeyEvent(KeyEvent event) {
if(authorizationFragment != null) {
authorizationFragment.dispatchKeyEvent(event);
}
return super.dispatchKeyEvent(event);
}
}