xuxiuxi
2017-07-14 bcefcf7249692e61574438d3857e737c2fd29ca7
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
package cn.com.basic.face.dialog;
 
import android.content.Context;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.widget.PopupWindow;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;
 
import com.bsk.zhangbo.demoforbsk.R;
import cn.com.basic.face.base.MainActivity;
import cn.com.basic.face.discern.common.CommonVariables;
import cn.com.basic.face.fragment.CheckInFragment;
import cn.com.basic.face.service.DictionaryMng;
import cn.com.basic.face.util.Constant;
import cn.com.basic.face.util.OkClickedListener;
 
import com.lidroid.xutils.ViewUtils;
import com.lidroid.xutils.view.annotation.ViewInject;
import com.lidroid.xutils.view.annotation.event.OnClick;
import cn.com.basic.face.dialog.wheelview.adapter.BaseWheelAdapter;
import cn.com.basic.face.dialog.wheelview.widget.WheelView;
 
import java.util.ArrayList;
import java.util.List;
 
import cn.com.basic.face.discern.entity.Dictionary;
 
public class SelectDialog extends PopupWindow {
    private final View parentView;
    @ViewInject(R.id.dialog_select_title)
    private TextView dialog_select_title;
    @ViewInject(R.id.dialog_select_list_view)
    private WheelView dialog_select_list_view;
    @ViewInject(R.id.dialog_select_add_separator)
    private View dialog_select_add_separator;
    @ViewInject(R.id.dialog_select_add)
    private TextView dialog_select_add;
 
    private List list = new ArrayList();
 
    public static List visitorTypeList = new ArrayList();
    public static List attenderTypeList = new ArrayList();
    public static List genderList = new ArrayList();
    public static List idTypeList = new ArrayList();
    public static List visitReasonList = new ArrayList();
    private static List<String> resolutionList = new ArrayList();
    private static List<String> protocolList = new ArrayList();
    private static List<String> cameraBrandList = new ArrayList();
    private static List<String> departmentDictionaryList = new ArrayList();
    private static List<String> postDictionaryList = new ArrayList();
    private int type;
 
    public static void setVisitorTypeList(List visitorTypeList) {
        SelectDialog.visitorTypeList = visitorTypeList;
    }
 
    public static void setAttenderTypeList(List attenderTypeList) {
        SelectDialog.attenderTypeList = attenderTypeList;
    }
 
    public static void setGenderList(List genderList) {
        SelectDialog.genderList = genderList;
    }
 
    public static void setIdTypeList(List idTypeList) {
        SelectDialog.idTypeList = idTypeList;
    }
 
    public SelectDialog(View parentView, int type, OkClickedListener okButtonClickedListener, String defaultValue) {
        this.type = type;
        this.parentView = parentView;
        View view = LayoutInflater.from(MainActivity.getInstance()).inflate(R.layout.dialog_select,null);
        ViewUtils.inject(this, view);
        setTitleAndList(type);
        WheelView.WheelViewStyle style = new WheelView.WheelViewStyle();
        style.selectedTextColor = Color.parseColor("#11c3e3");
        style.textColor = Color.parseColor("#bcc6cf");
        style.selectedTextSize = 22;
        style.textSize = 16;
        style.holoBorderColor = Color.parseColor("#11c3e3");
 
        if(type == Constant.DialogSelectType.VISIT_REASON
                || type == Constant.DialogSelectType.PROTOCOL
                || type == Constant.DialogSelectType.RESOLUTION
                || type == Constant.DialogSelectType.CAMERA_BRAND
                ) {
            dialog_select_add_separator.setVisibility(View.VISIBLE);
            dialog_select_add.setVisibility(View.VISIBLE);
        }
 
        dialog_select_list_view.setWheelAdapter(new WheelAdapter(MainActivity.getInstance()));
        dialog_select_list_view.setSkin(WheelView.Skin.Holo);
        if (list != null && list.size() > 0) {
            dialog_select_list_view.setWheelData(list);
            Object itemObj = list.get(0);
            if (itemObj instanceof String && defaultValue != null && !"".equals(defaultValue)) {
                int selected = 0;
                for (int i = 0; i < list.size(); i++) {
                    if (defaultValue.equals(list.get(i))) {
                        selected = i;
                        break;
                    }
                }
                dialog_select_list_view.setSelection(selected);
            }
        }
        dialog_select_list_view.setWheelSize(5);
        dialog_select_list_view.setBackgroundResource(R.color.colorBackground);
        dialog_select_list_view.setStyle(style);
 
        view.setOnTouchListener(new View.OnTouchListener() {
            @Override
            public boolean onTouch(View view, MotionEvent motionEvent) {
            View popLayout = view.findViewById(R.id.dialog_select_linear_layout);
            int top = popLayout.getTop();
            int bottom = popLayout.getBottom();
            int left = popLayout.getLeft();
            int right = popLayout.getRight();
            int y = (int) motionEvent.getY();
            int x = (int) motionEvent.getX();
            if (motionEvent.getAction() == MotionEvent.ACTION_UP){
                if (y<top || y> bottom){
                    dismiss();
                }
                if (x < left || x > right){
                    dismiss();
                }
 
            }
            return true;
            }
        });
 
        setOutsideTouchable(true);
        this.setContentView(view);
        this.setHeight(RelativeLayout.LayoutParams.MATCH_PARENT);
        this.setWidth(RelativeLayout.LayoutParams.MATCH_PARENT);
        this.setFocusable(true);
        this.setBackgroundDrawable(new ColorDrawable(0x7f000000));
        this.setAnimationStyle(R.style.PopupAnimation);
        okButtonClickedListeners.add(okButtonClickedListener);
        this.showAtLocation(parentView, Gravity.CENTER,0,0);
    }
 
    @OnClick(R.id.dialog_select_ok)
    public void dialog_select_ok_click(View view) {
        for (OkClickedListener okButtonClickedListener : okButtonClickedListeners) {
            if (dialog_select_list_view.getCurrentPosition() >= 0) {
                Object o = list.get(dialog_select_list_view.getCurrentPosition());
                String value = "";
                if (o instanceof Dictionary) {
                    value = ((Dictionary) o).getName();
                } else {
                    value = o+"";
                }
                okButtonClickedListener.onSelected(value);
            }
        }
        dismiss();
    }
 
    @OnClick(R.id.dialog_select_cancel)
    public void dialog_select_cancel_click(View view) {
        dismiss();
    }
 
    private List<OkClickedListener> okButtonClickedListeners = new ArrayList<OkClickedListener>();
 
    public void addOkButtonClickedListener(OkClickedListener okButtonClickedListener) {
        this.okButtonClickedListeners.add(okButtonClickedListener);
    }
 
    private void setTitleAndList(int type) {
        String tile = "";
        switch (type) {
            case Constant.DialogSelectType.GENDER:
                tile = "性别";
                list = genderList;
                break;
            case Constant.DialogSelectType.ID_TYPE:
                tile = "证件类型";
                list = idTypeList;
                break;
            case Constant.DialogSelectType.VISITOR_TYPE:
                tile = "访客类型";
                list = visitorTypeList;
                break;
            case Constant.DialogSelectType.VISIT_REASON:
                tile = "请选择访问事由";
                list = visitReasonList;
                break;
            case Constant.DialogSelectType.RESOLUTION:
                tile = "请选择分辨率";
                list = resolutionList;
                break;
            case Constant.DialogSelectType.PROTOCOL:
                tile = "请选择通讯";
                list = protocolList;
                break;
            case Constant.DialogSelectType.CAMERA_BRAND:
                tile = "请选择摄像机品牌";
                list = cameraBrandList;
                break;
            case Constant.DialogSelectType.DEPARTMENT:
                tile = "请选择部门/班级";
                list = departmentDictionaryList;
                break;
            case Constant.DialogSelectType.POST:
                tile = "请选择职务";
                list = postDictionaryList;
                break;
        }
        dialog_select_title.setText(tile);
    }
 
    @OnClick(R.id.dialog_select_add)
    public void dialog_select_add_click(View view) {
        dismiss();
        Toast.makeText(MainActivity.getInstance(), "添加", Toast.LENGTH_SHORT);
        new AddDialog(parentView, type, new OkClickedListener() {
            public void onSelected(String value) {
                CheckInFragment.getInstance().setVisitReasonText(value);
                switch (type) {
                    case Constant.DialogSelectType.VISIT_REASON:
                        CheckInFragment.getInstance().setVisitReasonText(value);
                        break;
                    case Constant.DialogSelectType.RESOLUTION:
                        DictionaryMng.getInstance().addDictionary(Constant.DialogSelectType.RESOLUTION, CommonVariables.DictionaryType.RESOLUTION, value);
                        break;
                    case Constant.DialogSelectType.PROTOCOL:
                        DictionaryMng.getInstance().addDictionary(Constant.DialogSelectType.PROTOCOL, CommonVariables.DictionaryType.PROTOCOL, value);
                        break;
                    case Constant.DialogSelectType.CAMERA_BRAND:
                        DictionaryMng.getInstance().addDictionary(Constant.DialogSelectType.CAMERA_BRAND, CommonVariables.DictionaryType.CAMERA_BRAND, value);
                        break;
                }
            }
        });
    }
 
    public static void setVisitReasonList(List visitReasonList) {
        SelectDialog.visitReasonList = visitReasonList;
    }
 
    public static void setResolutionList(List<String> resolutionList) {
        SelectDialog.resolutionList = resolutionList;
    }
 
    public static void setProtocolList(List<String> protocolList) {
        SelectDialog.protocolList = protocolList;
    }
 
    public static void setCameraBrandList(List<String> cameraBrandList) {
        SelectDialog.cameraBrandList = cameraBrandList;
    }
 
    public static void setDepartmentDictionaryList(List<String> departmentDictionaryList) {
        SelectDialog.departmentDictionaryList = departmentDictionaryList;
    }
 
    public static void setPostDictionaryList(List<String> postDictionaryList) {
        SelectDialog.postDictionaryList = postDictionaryList;
    }
 
 
    public static class WheelAdapter extends BaseWheelAdapter<String> {
        private Context mContext;
 
        public WheelAdapter(Context context) {
            mContext = context;
        }
 
        @Override
        protected View bindView(int position, View convertView, ViewGroup parent) {
            ViewHolder viewHolder;
            if (convertView == null) {
                viewHolder = new ViewHolder();
                convertView = LayoutInflater.from(mContext).inflate(R.layout.dialog_row, null);
                viewHolder.textView = (TextView) convertView.findViewById(R.id.item_wheel_name);
                convertView.setTag(viewHolder);
            } else {
                viewHolder = (ViewHolder) convertView.getTag();
            }
            viewHolder.textView.setText(mList.get(position)+"");
            return convertView;
        }
 
        static class ViewHolder {
            TextView textView;
        }
 
    }
 
 
}