a
554325746@qq.com
2019-10-24 c61e776980f038bb0e195f7753a3d7e127d6028f
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
package com.basic.security.activity;
 
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.hardware.usb.UsbDevice;
import android.hardware.usb.UsbManager;
import android.media.MediaPlayer;
import android.os.Handler;
import android.os.Looper;
import android.os.SystemClock;
import android.view.View;
import android.view.WindowManager;
import android.widget.LinearLayout;
 
import com.alfeye.readcardlib.readcard.ReadCardUtil;
import com.basic.security.R;
import com.basic.security.activity.helper.MaLoggedInTimeoutToLogout;
import com.basic.security.base.BaseApplication;
import com.basic.security.manager.DatabaseManager;
import com.basic.security.manager.IdCardManager;
import com.basic.security.service.KeepLifeService;
import com.basic.security.service.NodeNameService;
import com.basic.security.service.UpgradeAppService;
import com.basic.security.utils.ANRWatchDog;
import com.basic.security.utils.AudioPlayer;
import com.basic.security.utils.Base64Util;
import com.basic.security.utils.Constants;
import com.basic.security.utils.KeyboardUtil;
import com.basic.security.utils.PermissionHelper;
import com.basic.security.utils.SocketUtil;
import com.basic.security.utils.ToastUtil;
import com.basic.security.utils.socket.RelayServerUtil2;
import com.basic.security.utils.socket.server.IndoorSocketServer;
import com.firefly.api.FireflyApi;
 
import org.androidannotations.annotations.AfterViews;
import org.androidannotations.annotations.Click;
import org.androidannotations.annotations.EActivity;
import org.androidannotations.annotations.UiThread;
import org.androidannotations.annotations.ViewById;
 
import static com.basic.security.utils.Constants.isNewIDCardReader;
 
@EActivity(R.layout.activity_main)
public class MainActivity extends MaLoggedInTimeoutToLogout {
    public static boolean faceDbInitComplete = false;
    public static long lastTimeDetectedFace = 0;
    //1是usb模式   0是串口模式   5.1.1
    public static boolean mainActivityInitComplete = false;
    public static boolean allUiLoaded = false;
    private static FireflyApi mFireflyApi;
    private final Handler _uiHandler1 = new Handler(Looper.getMainLooper());
    //新的pad  白色   身份证读卡器
    public ReadCardUtil readCardUtil;
    @ViewById
    public View long_click_view;
    @ViewById
    LinearLayout id111;
 
    BroadcastReceiver mUsbAttachReceiver = new BroadcastReceiver() {
        public void onReceive(Context context, Intent intent) {
            String action = intent.getAction();
            BaseApplication.getApplication().executorService.execute(() -> {
                SystemClock.sleep(6 * 1000);
                try {
                    BaseApplication.getApplication().activity.runOnUiThread(() -> {
                        fragment_camera.resetCamera();
                        if (!fragment_camera.rgb_camera.resetCamera) {
                            BaseApplication.getApplication().executorService.execute(() -> {
                                SystemClock.sleep(6 * 1000);
                                BaseApplication.getApplication().activity.runOnUiThread(() -> {
                                    fragment_camera.resetCamera();
                                });
                            });
                        }
                    });
                } catch (Exception e) {
                    e.printStackTrace();
                }
            });
        }
    };
    long lastTimeDetach = 0;
    BroadcastReceiver mUsbDetachReceiver = new BroadcastReceiver() {
        public void onReceive(Context context, Intent intent) {
            String action = intent.getAction();
            lastTimeDetach = System.currentTimeMillis();
            System.out.println("MainActivity.onReceive mUsbDetachReceiver ");
 
            if (UsbManager.ACTION_USB_DEVICE_DETACHED.equals(action)) {
                UsbDevice device = (UsbDevice) intent.getParcelableExtra(UsbManager.EXTRA_DEVICE);
                if (device != null) {
                }
            }
        }
    };
    MediaPlayer mediaPlayer;
 
    public MainActivity() {
        Base64Util.init();
        DatabaseManager.setCustomDatabaseFiles(this);
    }
 
    public static FireflyApi getFireflyApi() {
        return mFireflyApi;
    }
 
    @Override
    protected void onDestroy() {
        super.onDestroy();
        unregisterReceiver(mUsbDetachReceiver);
        unregisterReceiver(mUsbAttachReceiver);
    }
 
    @AfterViews
    protected void afterViews() {
        allUiLoaded = true;
        IntentFilter filter = new IntentFilter(UsbManager.ACTION_USB_DEVICE_ATTACHED);
        registerReceiver(mUsbAttachReceiver, filter);
        filter = new IntentFilter(UsbManager.ACTION_USB_DEVICE_DETACHED);
        registerReceiver(mUsbDetachReceiver, filter);
 
        if (Constants.isOutdoor) {
            RelayServerUtil2.startOpenDoorThread();
        }
        if (!PermissionHelper.hasWriteStoragePermission(this)) {
            PermissionHelper.requestWriteStoragePermission(this);
        }
        getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); // 保持屏幕常亮
        hideSystemUIThread();
        addFragments();
        addCameraToFragment();
        addVideoViewToFragment();
        addToolbarButtonsToFragment();
        addTimeoutToBlank();
        addIdCardPhoneComponent();
        addBackgroundAndBorderComponent();
        addCameras();
        setUpClickHook();
        addFaceComponents();
        addSystemSettingTabs();
        addSystemSettingHintTabs();
        addPersonManagerComponents();
        logoutChecker();
        hideOneFragment(fragment_menu);
        hideOneFragment(fragment_person_identity);
        hideOneFragment(fragment_face_list);
        hideOneFragment(fragment_face_detail);
        hideOneFragment(fragment_org_person);
        hideOneFragment(fragment_system_setting_tabs);
        hideOneFragment(fragment_su_auto_ic_wait_phone);
        hideOneFragment(fragment_su_logged_ic_wait_idcard);
        hideOneFragment(fragment_su_logged_ic_compare_success);
        hideOneFragment(fragment_background_and_border);
        if (Constants.isOutdoor) {
            showFragment(fragment_home);
        }
        if (Constants.isIndoor) {
            showFragment(fragment_guest_mode);
        }
        checkDeviceId();
        stopService(new Intent(this, KeepLifeService.class));
        stopService(new Intent(this, UpgradeAppService.class));
        stopService(new Intent(this, NodeNameService.class));
 
        startService(new Intent(this, KeepLifeService.class));
        startService(new Intent(this, UpgradeAppService.class));
        startService(new Intent(this, NodeNameService.class));
        if (Constants.isIndoor) {
            IndoorSocketServer.startServer();
        }
        mainActivityInitComplete = true;
 
        if (Constants.autoRestart) {
            new ANRWatchDog().start();
        }
 
    }
 
    protected void onResume() {
        super.onResume();
//        WebRtcBroadCastReceiver.webRtcClientConnected = false;
//        WebRtcBroadCastReceiver.webRtcServerStarted = false;
        if (Constants.needIdCardModule) {
            Intent intent1 = new Intent();
            intent1.setPackage("com.basic.project.idcardservice");
            intent1.setAction("com.basic.read.IDCard");
            intent1.putExtra("type", "start_service");
            intent1.setFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES);
            startService(intent1);
        }
    }
    public long startTime = 0;
    public void onBackPressed() {
        long currentTime = System.currentTimeMillis();
        if ((currentTime - startTime) >= 2000) {
            ToastUtil.show("再按一次退出");
            startTime = currentTime;
        } else {
            exitApp();
        }
    }
 
    private void exitApp() {
        if (Constants.needIdCardModule) {
            if (Constants.needIdCardModule) {
                if (isNewIDCardReader) {
                    if (readCardUtil != null) {
                        readCardUtil.stopReadCard();
                        readCardUtil.destroy();
                    }
                } else {
                    IdCardManager.unRegisterBroadcast(this);
                }
            }
        }
        finish();
        System.exit(0);
    }
 
    protected void onPause() {
        super.onPause();
        KeyboardUtil.hideSoftKeyboard();
    }
 
    protected void onStop() {
        super.onStop();
    }
 
    @Click
    public void batch_move_to_org() {
        fragment_face_list.batch_move_to_org();
    }
 
    @Click
    public void batch_delete_person() {
        fragment_face_list.batch_delete_person();
    }
 
    @Click
    public void batch_cancel() {
        fragment_face_list.exitBatchMode();
    }
 
    public String requestFrame() {
        return currentFragment == fragment_guest_mode ? Constants.TRUE : Constants.FALSE;
    }
 
    @UiThread
    public void showAnswerCall(boolean show) {
        BaseApplication.getApplication().executorService.execute(new Runnable() {
            @Override
            public void run() {
                if (show) {
                    mediaPlayer = AudioPlayer.play(mediaPlayer);
                } else {
                    AudioPlayer.stop(mediaPlayer);
                    mediaPlayer = null;
                }
            }
        });
 
//        answerCall.setVisibility(show ? View.VISIBLE : View.GONE);
    }
 
 
    public void answerCall() {
        Intent launchIntent = getPackageManager().getLaunchIntentForPackage("org.appspot.apprtc");
        if (launchIntent != null) {
            launchIntent.putExtra("ip", SocketUtil.getRpcCallIp());
            launchIntent.putExtra("cameraIndex", "0");
            launchIntent.putExtra("orientation", "landscape");
            launchIntent.putExtra("localCameraRotation", "0");
//            launchIntent.putExtra("contactName", "张三");
            launchIntent.putExtra("remoteCameraRotation", "270");
            startActivity(launchIntent);
        }
    }
}