a
554325746@qq.com
2019-12-25 7340eb0b160eacbbd0f3c2289e3ac6150da235f3
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
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
package com.basic.security.fragment;
 
import android.os.Bundle;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.GridView;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.Spinner;
 
import com.basic.security.base.BaseFragment;
import com.basic.security.manager.HintDoorAccessManager;
import com.basic.security.model.HintDoorAccess;
import com.basic.security.model.ModelAdapter;
import com.basic.security.utils.KeyboardUtil;
import com.basic.security.utils.ResolutionAdaptation;
import com.basic.security.utils.SocketUtil;
import com.basic.security.utils.ToastUtil;
 
import org.androidannotations.annotations.AfterViews;
import org.androidannotations.annotations.Click;
import org.androidannotations.annotations.EFragment;
import org.androidannotations.annotations.ViewById;
 
import java.util.ArrayList;
import java.util.List;
 
@EFragment
public class HintDoorAccessFragment extends BaseFragment {
    @ViewById
    CheckBox ck_access_identity, ck_access_name, ck_confirm_pass_identity, ck_confirm_pass_name,
            ck_refuse_pass_identity, ck_refuse_pass_name;
    @ViewById
    EditText et_no_register_message, et_access_hint, et_not_reached_time_hint, et_not_reached_time_remind, et_confirm_pass_hint,
            et_refuse_pass_hint;
    @ViewById
    ImageView iv_access_hint_check, iv_access_hint_show, iv_not_reached_time_check, iv_not_reached_time_show,
            iv_confirm_pass_check, iv_confirm_pass_show, iv_refuse_pass_check, iv_refuse_pass_show;
    @ViewById
    Button btn_pass_hint_save, btn_pass_hint_cancel, btn_check_message_save, btn_check_message_cancel;
    @ViewById
    RelativeLayout rl_check_hint;
    @ViewById
    GridView gv_hint;
    @ViewById
    Spinner time_unit;
    private ModelAdapter hintDoorAccess = null;
    private int intTag = -1; // 0 允许通行的editText  1 未到时间的 2 确认通行的  3 拒绝通行的
    private int accessPassTag = 0;
    private int notReachTimeTag = 1;
    private int confirmPassTag = 2;
    private int refusePassTag = 3;
    private List<String> mList = new ArrayList(); // 添加弹出框中要显示的数据
    private List<String> currentCheckedMessages = new ArrayList(); // 当前选中的提示语集合,一般只有一个
    private int temple = -1;
 
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        return inflater.inflate(ResolutionAdaptation.fragment_hint_door_access(), container, false);
    }
 
    public void show() {
        super.show();
        hintDoorAccess = HintDoorAccessManager.getHintDoorAccessDocument();
        initSetData();
    }
 
    public void hide() {
        super.hide();
        intTag = -1;
    }
 
    @AfterViews
    public void afterViews() {
        timeUnitCombox();
    }
 
    private void timeUnitCombox() {
        String[] arr = {"分钟", "小时", "天"};
        ArrayAdapter<String> adapter = new ArrayAdapter<String>(getContext(), com.basic.security.utils.ResolutionAdaptation.spinner_item(), arr);
        time_unit.setPopupBackgroundResource(com.basic.security.utils.RUtils.R_color_press_menu_text);
        time_unit.setAdapter(adapter);
    }
 
    private void initSetData() { // 1  选中   0 未选中
        if (hintDoorAccess == null) {
            hintDoorAccess = HintDoorAccessManager.getHintDoorAccessDocument();
        }
        et_no_register_message.setText(hintDoorAccess.getString("no_register"));
        if (!TextUtils.isEmpty(hintDoorAccess.getString("access_identity")) &&
                "1".equals(hintDoorAccess.getString("access_identity"))) {
            ck_access_identity.setChecked(true);
        } else {
            ck_access_identity.setChecked(false);
        }
        if (!TextUtils.isEmpty(hintDoorAccess.getString("access_name")) &&
                "1".equals(hintDoorAccess.getString("access_name"))) {
            ck_access_name.setChecked(true);
        } else {
            ck_access_name.setChecked(false);
        }
        et_access_hint.setText(hintDoorAccess.getString("access_hint"));
        String time_text = hintDoorAccess.getString("time_unit");
        if (!TextUtils.isEmpty(time_text)) {
            if ("分钟".equals(time_text)) {
                time_unit.setSelection(0);
            } else if ("小时".equals(time_text)) {
                time_unit.setSelection(1);
            } else {
                time_unit.setSelection(2);
            }
        } else {
            time_unit.setSelection(0);
        }
        et_not_reached_time_hint.setText(hintDoorAccess.getString("not_reached_time_hint"));
        et_not_reached_time_remind.setText(hintDoorAccess.getString("not_reached_time_remind"));
        if (!TextUtils.isEmpty(hintDoorAccess.getString("confirm_pass_identity")) &&
                "1".equals(hintDoorAccess.getString("confirm_pass_identity"))) {
            ck_confirm_pass_identity.setChecked(true);
        } else {
            ck_confirm_pass_identity.setChecked(false);
        }
        if (!TextUtils.isEmpty(hintDoorAccess.getString("confirm_pass_name")) &&
                "1".equals(hintDoorAccess.getString("confirm_pass_name"))) {
            ck_confirm_pass_name.setChecked(true);
        } else {
            ck_confirm_pass_name.setChecked(false);
        }
        et_confirm_pass_hint.setText(hintDoorAccess.getString("confirm_pass_hint"));
        if (!TextUtils.isEmpty(hintDoorAccess.getString("refuse_pass_identity")) &&
                "1".equals(hintDoorAccess.getString("refuse_pass_identity"))) {
            ck_refuse_pass_identity.setChecked(true);
        } else {
            ck_refuse_pass_identity.setChecked(false);
        }
        if (!TextUtils.isEmpty(hintDoorAccess.getString("refuse_pass_name")) &&
                "1".equals(hintDoorAccess.getString("refuse_pass_name"))) {
            ck_refuse_pass_name.setChecked(true);
        } else {
            ck_refuse_pass_name.setChecked(false);
        }
        et_refuse_pass_hint.setText(hintDoorAccess.getString("refuse_pass_hint"));
    }
 
    @Click
    void iv_access_hint_check() {
        KeyboardUtil.hideSoftKeyboard();
        intTag = accessPassTag;
        showPopupWindow(intTag);
    }
 
    @Click
    void iv_access_hint_show() {
        KeyboardUtil.hideSoftKeyboard();
        String message = "";
        if (ck_access_identity.isChecked()) {
            message = "家长   ";
        }
        if (ck_access_name.isChecked()) {
            message = message + "刘克   ";
        }
        if (!TextUtils.isEmpty(et_access_hint.getText().toString().trim())) {
            message = message + et_access_hint.getText().toString().trim();
        }
        if (!TextUtils.isEmpty(message)) {
            ToastUtil.showNormalToast(message);
        }
    }
 
    @Click
    void iv_not_reached_time_check() {
        KeyboardUtil.hideSoftKeyboard();
        intTag = notReachTimeTag;
        showPopupWindow(intTag);
    }
 
    @Click
    void iv_not_reached_time_show() {
        if (!TextUtils.isEmpty(et_not_reached_time_hint.getText().toString())) {
            ToastUtil.showNormalToast(et_not_reached_time_hint.getText().toString());
        }
        KeyboardUtil.hideSoftKeyboard();
    }
 
    @Click
    void iv_confirm_pass_check() {
        KeyboardUtil.hideSoftKeyboard();
        intTag = confirmPassTag;
        showPopupWindow(intTag);
    }
 
    @Click
    void iv_confirm_pass_show() {
        KeyboardUtil.hideSoftKeyboard();
        String message = "";
        if (ck_confirm_pass_identity.isChecked()) {
            message = "家长   ";
        }
        if (ck_confirm_pass_name.isChecked()) {
            message = message + "刘克   ";
        }
        if (!TextUtils.isEmpty(et_confirm_pass_hint.getText().toString().trim())) {
            message = message + et_confirm_pass_hint.getText().toString().trim();
        }
        if (!TextUtils.isEmpty(message)) {
            ToastUtil.showNormalToast(message);
        }
    }
 
    @Click
    void iv_refuse_pass_check() {
        KeyboardUtil.hideSoftKeyboard();
        intTag = refusePassTag;
        showPopupWindow(intTag);
    }
 
    @Click
    void iv_refuse_pass_show() {
        KeyboardUtil.hideSoftKeyboard();
        String message = "";
        if (ck_refuse_pass_identity.isChecked()) {
            message = "家长   ";
        }
        if (ck_refuse_pass_name.isChecked()) {
            message = message + "刘克   ";
        }
        if (!TextUtils.isEmpty(et_refuse_pass_hint.getText().toString().trim())) {
            message = message + et_refuse_pass_hint.getText().toString().trim();
        }
        if (!TextUtils.isEmpty(message)) {
            ToastUtil.showNormalToast(message);
        }
    }
 
    @Click
    void btn_pass_hint_save() {// 1  选中   0 未选中
        if (hintDoorAccess == null) {
            hintDoorAccess = HintDoorAccessManager.getHintDoorAccessDocument();
        }
        String no_register_message = et_no_register_message.getText().toString().trim();
        String access_hint = et_access_hint.getText().toString().trim();
        String not_reached_time_hint = et_not_reached_time_hint.getText().toString().trim();
        String not_reached_time_remind = et_not_reached_time_remind.getText().toString().trim();
        String confirm_pass_hint = et_confirm_pass_hint.getText().toString().trim();
        String refuse_pass_hint = et_refuse_pass_hint.getText().toString().trim();
        if (TextUtils.isEmpty(no_register_message)) {
            ToastUtil.show("未注册提示信息不能为空");
            return;
        }
        if (TextUtils.isEmpty(access_hint)) {
            ToastUtil.show("允许通行提示语不能为空");
            return;
        }
        if (TextUtils.isEmpty(not_reached_time_hint)) {
            ToastUtil.show("未到通行时间提示语不能为空");
            return;
        }
        if (TextUtils.isEmpty(not_reached_time_remind)) {
            ToastUtil.show("请设置开始前提示时间");
            return;
        }
        if (TextUtils.isEmpty(confirm_pass_hint)) {
            ToastUtil.show("确认通行提示语不能为空");
            return;
        }
        if (TextUtils.isEmpty(refuse_pass_hint)) {
            ToastUtil.show("拒绝通行提示语不能为空");
            return;
        }
        hintDoorAccess.setString(HintDoorAccess.no_register, no_register_message);
        hintDoorAccess.setString("access_identity", ck_access_identity.isChecked() ? "1" : "0");
        hintDoorAccess.setString("access_name", ck_access_name.isChecked() ? "1" : "0");
        hintDoorAccess.setString("access_hint", access_hint);
        hintDoorAccess.setString("not_reached_time_hint", not_reached_time_hint);
        hintDoorAccess.setString("not_reached_time_remind", not_reached_time_remind);
        hintDoorAccess.setString("time_unit", time_unit.getSelectedItem().toString());
        hintDoorAccess.setString("confirm_pass_identity", ck_confirm_pass_identity.isChecked() ? "1" : "0");
        hintDoorAccess.setString("confirm_pass_name", ck_confirm_pass_name.isChecked() ? "1" : "0");
        hintDoorAccess.setString("confirm_pass_hint", confirm_pass_hint);
        hintDoorAccess.setString("refuse_pass_identity", ck_refuse_pass_identity.isChecked() ? "1" : "0");
        hintDoorAccess.setString("refuse_pass_name", ck_refuse_pass_name.isChecked() ? "1" : "0");
        hintDoorAccess.setString("refuse_pass_hint", refuse_pass_hint);
        hintDoorAccess.setString("table", "hint_door_access");
        HintDoorAccessManager.saveHintDoorAccess(hintDoorAccess);
        SocketUtil.rpcCallSaveHintDoorAccess(hintDoorAccess);
        ToastUtil.show("保存成功");
    }
 
    @Click
    void btn_pass_hint_cancel() {
        mainActivity().showFragment(mainActivity().fragment_person_manage);
    }
 
    private void showPopupWindow(int tag) {
        mList.clear();
        currentCheckedMessages.clear();
        if (tag == accessPassTag) {
            for (int i = 0; i < 5; i++) {
                mList.add("欢迎光临" + i);
            }
        } else if (tag == notReachTimeTag) {
            for (int i = 0; i < 6; i++) {
                mList.add("未到通行时间" + i);
            }
        } else if (tag == confirmPassTag) {
            for (int i = 0; i < 7; i++) {
                mList.add("确认通行" + i);
            }
        } else if (tag == refusePassTag) {
            for (int i = 0; i < 8; i++) {
                mList.add("拒绝通行" + i);
            }
        }
        rl_check_hint.setVisibility(View.VISIBLE);
        gv_hint.setAdapter(new gridViewAdapter());
    }
 
    @Click
    void btn_check_message_save() {
        temple = -1;
        if (currentCheckedMessages.size() > 1) {
            ToastUtil.show("只能选一个");
            return;
        }
        rl_check_hint.setVisibility(View.GONE);
        if (currentCheckedMessages.size() == 1) {
            if (intTag == accessPassTag) {
                et_access_hint.setText(currentCheckedMessages.get(0));
            } else if (intTag == notReachTimeTag) {
                et_not_reached_time_hint.setText(currentCheckedMessages.get(0));
            } else if (intTag == confirmPassTag) {
                et_confirm_pass_hint.setText(currentCheckedMessages.get(0));
            } else if (intTag == refusePassTag) {
                et_refuse_pass_hint.setText(currentCheckedMessages.get(0));
            }
        }
        intTag = -1;
    }
 
    @Click
    void btn_check_message_cancel() {
        temple = -1;
        intTag = -1;
        rl_check_hint.setVisibility(View.GONE);
    }
 
    private class gridViewAdapter extends BaseAdapter {
        public int getCount() {
            return mList == null ? 0 : mList.size();
        }
 
        public Object getItem(int position) {
            return mList.get(position);
        }
 
        public long getItemId(int position) {
            return position;
        }
 
        public View getView(int position, View convertView, ViewGroup parent) {
            ViewHolder viewHolder;
            if (convertView == null) {
                //加载子布局
                convertView = LayoutInflater.from(getContext()).inflate(com.basic.security.utils.ResolutionAdaptation.item_identity_list(), parent, false);
                viewHolder = new ViewHolder();
                viewHolder.checkBox = convertView.findViewById(com.basic.security.utils.RUtils.R_id_item_ck);
                convertView.setTag(viewHolder);
            } else {
                viewHolder = (ViewHolder) convertView.getTag();
            }
            viewHolder.checkBox.setText(mList.get(position));
            // 设置单选
            viewHolder.checkBox.setId(position * 11);
            viewHolder.checkBox.setOnCheckedChangeListener((buttonView, isChecked) -> {
                if (isChecked) {
                    currentCheckedMessages.clear();
                    currentCheckedMessages.add(mList.get(position));
                    if (temple != -1) {
                        CheckBox tempButton = getActivity().findViewById(temple);
                        if (tempButton != null) {
                            tempButton.setChecked(false);
                        }
                    }
                    temple = buttonView.getId();
                }
            });
            if (position * 11 == temple) {
                viewHolder.checkBox.setChecked(true);//将本次点击的RadioButton设置为选中状态
            } else {
                viewHolder.checkBox.setChecked(false);
            }
            return convertView;
        }
 
        class ViewHolder {
            private CheckBox checkBox;
        }
    }
}