rk
昨天 4a8ff39b0fab0627ef8f7459587d514cc01c3676
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
package com.example.settinglibrary;
 
import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Build;
import android.os.Bundle;
import androidx.annotation.RequiresApi;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.CompoundButton;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.PopupWindow;
import android.widget.Switch;
import android.widget.TextView;
import com.example.datalibrary.activity.BaseActivity;
import com.example.datalibrary.utils.PWTextUtils;
 
import java.math.BigDecimal;
 
 
/**
 * author : shangrog
 * date : 2019/5/27 6:34 PM
 * description :最小人脸界面
 */
 
public class GateMinFaceActivity extends BaseActivity {
    private EditText mfEtAmount;
    private int minimumFace;
    private int thirty = 30;
    private int twoHundered = 200;
    private static final int TEN = 10;
    private float faceThreshold;
    private float thirtyLevel = 0.3f;
    private float twoHunderedLevel = 0.8f;
    private static final float TEN_LEVEL  = 0.1f;
 
    private LinearLayout linerMinFace;
    private TextView minFaceText;
    private Button minFace;
    private String tagMsg = "";
    private ViewGroup minRepresent;
    private ViewGroup faceThresholdGroup;
    private EditText mfEtFaceThreshold;
    private Button minFaceThreshold;
    private Button multiFaceBtn;
    private Button maskBtn;
    private int showWidth;
    private int showXLocation;
 
    private BigDecimal faceThresholdDecimal;
    private BigDecimal levelValue;
    private Switch multiFaceSw;
    private Switch maskSw;
    private View maskLv;
    private View multiLv;
    private boolean isMultiIdentify = false;
    private boolean isMaskIdentify = false;
 
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_gate_minface);
 
        init();
    }
 
 
    public void init() {
        Intent intent = getIntent();
        levelValue = new BigDecimal(TEN_LEVEL  + "");
        minimumFace = intent.getIntExtra("minimumFace" , 0);
        faceThreshold = intent.getFloatExtra("faceThreshold" , 0);
 
        isMultiIdentify = intent.getBooleanExtra("isMultiIdentify" , false);
        isMaskIdentify = intent.getBooleanExtra("isMaskIdentify" , false);
        minRepresent = findViewById(R.id.minRepresent);
 
        linerMinFace = findViewById(R.id.linerminface);
        minFaceText = findViewById(R.id.minFaceText);
        minFace = findViewById(R.id.minface);
 
        ImageView mfDecrease = findViewById(R.id.mf_Decrease);
        ImageView mfIncrease = findViewById(R.id.mf_Increase);
        mfEtAmount = findViewById(R.id.mf_etAmount);
        ImageView mfSave = findViewById(R.id.mf_save);
        mfEtAmount.setText(minimumFace + "");
        // 人脸置信度
        faceThresholdGroup = findViewById(R.id.faceThreshold);
        mfEtFaceThreshold = findViewById(R.id.mf_et_face_threshold);
        ImageView mfFaceThreshold = findViewById(R.id.mf_face_threshold);
        ImageView mfPlusFaceThreshold = findViewById(R.id.mf_plus_face_threshold);
        minFaceThreshold = findViewById(R.id.min_face_threshold);
        mfEtFaceThreshold.setText(faceThreshold + "");
 
        PWTextUtils.setOnDismissListener(new PopupWindow.OnDismissListener() {
            @Override
            public void onDismiss() {
                minFace.setBackground(getDrawable(R.mipmap.icon_setting_question));
                minFaceThreshold.setBackground(getDrawable(R.mipmap.icon_setting_question));
                maskBtn.setBackground(getDrawable(R.mipmap.icon_setting_question));
                multiFaceBtn.setBackground(getDrawable(R.mipmap.icon_setting_question));
            }
        });
        // 考勤模式下支持多人识别和口罩识别,其他模式不支持
        boolean isAttendance = intent.getBooleanExtra("isAttendance" , false);
        multiLv = findViewById(R.id.multiFaceLv);
        maskLv = findViewById(R.id.maskLv);
        if (isAttendance){
            multiLv.setVisibility(View.VISIBLE);
            maskLv.setVisibility(View.VISIBLE);
        }
        else{
            multiLv.setVisibility(View.GONE);
            maskLv.setVisibility(View.GONE);
        }
        multiFaceBtn = findViewById(R.id.multiFaceBtn);
        multiFaceBtn.setText("");
 
        maskBtn = findViewById(R.id.maskBtn);
        maskBtn.setText("");
 
        multiFaceSw = findViewById(R.id.multiFaceSw);
        maskSw = findViewById(R.id.maskSw);
 
        if (isMultiIdentify) {
            multiFaceSw.setChecked(true);
        } else {
            multiFaceSw.setChecked(false);
        }
 
        if (isMaskIdentify) {
            maskSw.setChecked(true);
        } else {
            maskSw.setChecked(false);
        }
 
        multiFaceSw.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                if (isChecked) {
                    multiFaceSw.setChecked(true);
                } else {
                    multiFaceSw.setChecked(false);
                }
                isMultiIdentify = isChecked;
            }
        });
 
        maskSw.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                if (isChecked) {
                    maskSw.setChecked(true);
                } else {
                    maskSw.setChecked(false);
                }
                isMaskIdentify = isChecked;
            }
        });
 
        // 人脸置信度 增减按钮
        mfFaceThreshold.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (faceThreshold > thirtyLevel && faceThreshold <= twoHunderedLevel) {
                    faceThresholdDecimal = new BigDecimal(faceThreshold + "");
                    faceThreshold = faceThresholdDecimal.subtract(levelValue).floatValue();
                    mfEtFaceThreshold.setText(faceThreshold + "");
                }
            }
        });
        mfPlusFaceThreshold.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (faceThreshold >= thirtyLevel && faceThreshold < twoHunderedLevel) {
                    faceThresholdDecimal = new BigDecimal(faceThreshold + "");
                    faceThreshold = faceThresholdDecimal.add(levelValue).floatValue();
                    mfEtFaceThreshold.setText(faceThreshold + "");
                }
            }
        });
 
        // 最小人脸增减按钮
        mfDecrease.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (minimumFace > thirty && minimumFace <= twoHundered) {
                    minimumFace = minimumFace - TEN;
                    mfEtAmount.setText(minimumFace + "");
                }
            }
        });
 
        mfIncrease.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (minimumFace >= thirty && minimumFace < twoHundered) {
                    minimumFace = minimumFace + TEN;
                    mfEtAmount.setText(minimumFace + "");
                }
            }
        });
 
        mfSave.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
 
        minFace.setOnClickListener(new View.OnClickListener() {
            @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
            @Override
            public void onClick(View v) {
                if (tagMsg.equals(getString(R.string.cw_minface))) {
                    tagMsg = "";
                    return;
                }
                tagMsg = getString(R.string.cw_minface);
                minFace.setBackground(getDrawable(R.mipmap.icon_setting_question_hl));
                PWTextUtils.showDescribeText(minRepresent, minFaceText, GateMinFaceActivity.this,
                        getString(R.string.cw_minface), showWidth, showXLocation);
            }
        });
 
        minFaceThreshold.setOnClickListener(new View.OnClickListener() {
            @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
            @Override
            public void onClick(View v) {
                if (tagMsg.equals(getString(R.string.cw_face_threshold))) {
                    tagMsg = "";
                    return;
                }
                tagMsg = getString(R.string.cw_face_threshold);
                minFaceThreshold.setBackground(getDrawable(R.mipmap.icon_setting_question_hl));
                PWTextUtils.showDescribeText(faceThresholdGroup, minFaceThreshold, GateMinFaceActivity.this,
                        getString(R.string.cw_face_threshold), showWidth, showXLocation);
            }
        });
 
        multiFaceBtn.setOnClickListener(new View.OnClickListener() {
            @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
            @Override
            public void onClick(View v) {
                if (tagMsg.equals(getString(R.string.cw_multi_identify))) {
                    tagMsg = "";
                    return;
                }
                tagMsg = getString(R.string.cw_multi_identify);
                multiFaceBtn.setBackground(getDrawable(R.mipmap.icon_setting_question_hl));
                PWTextUtils.showDescribeText(faceThresholdGroup, multiFaceBtn, GateMinFaceActivity.this,
                        getString(R.string.cw_multi_identify), showWidth, showXLocation);
            }
        });
 
        maskBtn.setOnClickListener(new View.OnClickListener() {
            @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
            @Override
            public void onClick(View v) {
                if (tagMsg.equals(getString(R.string.cw_mask_identify))) {
                    tagMsg = "";
                    return;
                }
                tagMsg = getString(R.string.cw_mask_identify);
                maskBtn.setBackground(getDrawable(R.mipmap.icon_setting_question_hl));
                PWTextUtils.showDescribeText(faceThresholdGroup, maskBtn, GateMinFaceActivity.this,
                        getString(R.string.cw_mask_identify), showWidth, showXLocation);
            }
        });
    }
 
    @Override
    public void finish() {
        Intent intent = new Intent();
        intent.putExtra("minimumFace", minimumFace);
        intent.putExtra("faceThreshold", faceThreshold);
        intent.putExtra("isMultiIdentify", isMultiIdentify);
        intent.putExtra("isMaskIdentify", isMaskIdentify);
        setResult(Activity.RESULT_OK, intent);
        super.finish();
    }
 
    private void showAlertAndExit(String message) {
        AlertDialog.Builder builder = new AlertDialog.Builder(this);
        builder.setMessage(message);
        builder.setCancelable(false);
        builder.setNeutralButton("OK", new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int which) {
                finish();
            }
        });
        builder.show();
    }
 
    @Override
    public void onWindowFocusChanged(boolean hasFocus) {
        super.onWindowFocusChanged(hasFocus);
        showWidth = minRepresent.getWidth();
        showXLocation = (int) minRepresent.getX();
    }
 
}