zhangzengfei
2020-03-31 0ce893695d32ab686f9e2309509e80c6feb0d380
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
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.base.BaseApplication;
import com.basic.security.base.BaseFragment;
import com.basic.security.utils.Constants;
 
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<Fragment> fragmentHasCamera = new HashSet<>();
    @ViewById
    public ImageView test_image_rgb, test_image_gray, test_remote_camera, test_remote_camera2;
    @ViewById
    public View showCapturedImagesLL;
    public int shouldExtractFeature = 1;
    boolean get_video_started = false;
 
    @Override
    public void toggleCamera(BaseFragment showFragment) {
        if (!fragmentHasCamera.contains(showFragment)) {
            fragment_camera.showOverlay();
        } else {
            fragment_camera.hideOverlay();
        }
    }
 
    @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);
    }
 
    public void startViewCameraThread() {
        BaseApplication.getApplication().executorService.execute(() -> {
            while (true) {
                try {
                    SystemClock.sleep(2000);
                    if (BaseApplication.getApplication().activity != null &&
                            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();
        }
    }
 
    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 void setShouldExtractFeature(int shouldExtractFeature) {
        this.shouldExtractFeature = shouldExtractFeature;
    }
 
    public int shouldExtractFeature() {
        if (shouldDetectFace()) {
            return shouldExtractFeature;
        }
        return 0;
    }
 
 
}