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