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);
|
}
|
}
|
}
|