package com.basic.security.activity.helper; import android.Manifest; import android.content.pm.PackageManager; import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.os.SystemClock; import android.support.v4.app.ActivityCompat; import android.support.v4.app.Fragment; import android.view.View; import android.widget.ImageView; import com.basic.security.activity.MainActivity; import com.basic.security.base.BaseApplication; import com.basic.security.base.BaseFragment; import com.basic.security.fragment.CameraFragment; import com.basic.security.utils.Constants; import com.basic.security.utils.yuv.pull.client.ServerUIMain; import com.basic.security.utils.yuv.pull.client.ServerUIMain2; import com.basic.security.utils.yuv.pull.client.SocketClient; import org.androidannotations.annotations.Background; import org.androidannotations.annotations.Click; import org.androidannotations.annotations.EActivity; import org.androidannotations.annotations.UiThread; import org.androidannotations.annotations.ViewById; import java.util.HashSet; import java.util.Set; @EActivity public abstract class MaCamera extends MaFragments { public static final int REQUEST_CAMERA_PERMISSION = 200; public Set fragmentHasCamera = new HashSet<>(); @Override public void toggleCamera(BaseFragment showFragment) { if (!fragmentHasCamera.contains(showFragment)) { ((CameraFragment) fragment_camera).showOverlay(); } else { ((CameraFragment) fragment_camera).hideOverlay(); } } @ViewById public ImageView test_image_rgb, test_image_gray, test_remote_camera, test_remote_camera2; boolean get_video_started = false; @Click public void get_video() { // if (!get_video_started) { // get_video_started = true; // { // ServerUIMain serverUIMain = new ServerUIMain(); // SocketClient server = new SocketClient(); // server.setOnDataListener(serverUIMain); // server.start(); // } // { // ServerUIMain2 serverUIMain = new ServerUIMain2(); // SocketClient server = new SocketClient(); // server.setOnDataListener(serverUIMain); // server.start(); // } // } } @UiThread public void setRemoteVideoImage(Bitmap bitmap) { test_remote_camera.setImageBitmap(bitmap); } @UiThread public void setRemoteVideoImage2(Bitmap bitmap) { test_remote_camera2.setImageBitmap(bitmap); } @Background public void startViewCameraThread() { while (true) { try { SystemClock.sleep(2000); if (BaseApplication.getApplication().activity != null && ((MainActivity) BaseApplication.getApplication().activity).mainActivityInitComplete) { updateCameraImages(); } } catch (Exception e) { e.printStackTrace(); } } } @UiThread public void updateCameraImages() { try { Bitmap image_rgb = BitmapFactory.decodeFile("/data/data/com.basic.security/files/image_rgb.jpg"); Bitmap image_gray = BitmapFactory.decodeFile("/data/data/com.basic.security/files/image_gray.jpg"); if (image_rgb != null) { test_image_rgb.setImageBitmap(image_rgb); } if (image_gray != null) { test_image_gray.setImageBitmap(image_gray); } } catch (Exception e) { e.printStackTrace(); } } @ViewById public View showCapturedImagesLL; public void addCameras() { if (ActivityCompat.checkSelfPermission(this, Manifest.permission.CAMERA) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) { ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.CAMERA, Manifest.permission.WRITE_EXTERNAL_STORAGE}, REQUEST_CAMERA_PERMISSION); } if (Constants.showCapturedImages) { showCapturedImagesLL.setVisibility(View.VISIBLE); startViewCameraThread(); } } public void addCameraToFragment() { fragmentHasCamera.add(fragment_su_auto_wait_face); fragmentHasCamera.add(fragment_admin_face_login); fragmentHasCamera.add(fragment_home); fragmentHasCamera.add(fragment_door_access_success); fragmentHasCamera.add(fragment_door_access_confirm); fragmentHasCamera.add(fragment_door_access_fail); fragmentHasCamera.add(fragment_door_access_result); fragmentHasCamera.add(fragment_su_logged_ic_wait_face); fragmentHasCamera.add(fragment_su_logged_nic_wait_face); fragmentHasCamera.add(fragment_su_auto_ic_wait_idcard); fragmentHasCamera.add(fragment_su_auto_wait_admin); fragmentHasCamera.add(fragment_su_logged_ic_wait_idcard); fragmentHasCamera.add(fragment_sign_up_success); fragmentHasCamera.add(fragment_su_logged_nic_wait_detail); fragmentHasCamera.add(fragment_su_logged_wait_face); fragmentHasCamera.add(fragment_su_logged_ic_compare_success); } public boolean shouldDetectFace() { boolean shouldDetectFace = false; if (currentFragment == fragment_admin_face_login || currentFragment == fragment_home || currentFragment == fragment_su_logged_ic_wait_face || currentFragment == fragment_su_auto_wait_face || currentFragment == fragment_su_logged_nic_wait_face || currentFragment == fragment_account_setting || currentFragment == fragment_door_access_success || currentFragment == fragment_door_access_confirm || currentFragment == fragment_su_auto_ic_wait_idcard || currentFragment == fragment_su_auto_wait_admin || currentFragment == fragment_su_logged_ic_wait_idcard || currentFragment == fragment_door_access_fail || currentFragment == fragment_door_access_result || currentFragment == fragment_sign_up_success || currentFragment == fragment_su_logged_nic_wait_detail || currentFragment == fragment_su_logged_ic_compare_success || currentFragment == fragment_verify_id_card || currentFragment == fragment_su_auto_nic_wait_detail ) { shouldDetectFace = true; } return shouldDetectFace; } public boolean needCompareFeature() { if (currentFragment == fragment_admin_face_login || currentFragment == fragment_su_logged_ic_wait_face || currentFragment == fragment_su_auto_ic_wait_idcard || currentFragment == fragment_su_auto_wait_face || currentFragment == fragment_su_logged_nic_wait_face || currentFragment == fragment_account_setting|| currentFragment == fragment_su_logged_ic_compare_success|| currentFragment == fragment_su_logged_ic_wait_idcard ) { return true; } return false; } public int shouldExtractFeature = 1; public void setShouldExtractFeature(int shouldExtractFeature) { this.shouldExtractFeature = shouldExtractFeature; } public int shouldExtractFeature() { if (shouldDetectFace()) { return shouldExtractFeature; } return 0; } }