lmw
2023-03-11 4df5bb59e5fe9f9d140e5610f7772dd8a05a28d4
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
406
407
408
409
410
411
412
413
414
//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by Fernflower decompiler)
//
 
package com.fuban.driver.utils.citypickerview;
 
import android.annotation.SuppressLint;
import android.content.Context;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.View.OnClickListener;
import android.widget.PopupWindow;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.PopupWindow.OnDismissListener;
 
import com.fuban.driver.R;
import com.lljjcoder.Interface.OnCityItemClickListener;
import com.lljjcoder.bean.CityBean;
import com.lljjcoder.bean.DistrictBean;
import com.lljjcoder.bean.ProvinceBean;
import com.lljjcoder.citywheel.CityConfig;
import com.lljjcoder.citywheel.CityParseHelper;
import com.lljjcoder.citywheel.CityConfig.WheelType;
import com.lljjcoder.style.citylist.Toast.ToastUtils;
import com.lljjcoder.style.citypickerview.R.id;
import com.lljjcoder.style.citypickerview.R.layout;
import com.lljjcoder.style.citypickerview.R.style;
import com.lljjcoder.style.citypickerview.widget.CanShow;
import com.lljjcoder.style.citypickerview.widget.wheel.OnWheelChangedListener;
import com.lljjcoder.style.citypickerview.widget.wheel.WheelView;
import com.lljjcoder.style.citypickerview.widget.wheel.adapters.ArrayWheelAdapter;
import com.lljjcoder.utils.utils;
import java.util.ArrayList;
import java.util.List;
 
public class CityPickerView implements CanShow, OnWheelChangedListener {
    private String TAG = "citypicker_log";
    private PopupWindow popwindow;
    private View popview;
    private WheelView mViewProvince;
    private WheelView mViewCity;
    private WheelView mViewDistrict;
    private RelativeLayout mRelativeTitleBg;
    private TextView mTvOK;
    private TextView mTvTitle;
    private TextView mTvCancel;
    private OnCityItemClickListener mBaseListener;
    private CityParseHelper parseHelper;
    private CityConfig config;
    private Context context;
    private List<ProvinceBean> proArra;
 
    public void setOnCityItemClickListener(OnCityItemClickListener listener) {
        this.mBaseListener = listener;
    }
 
    public CityPickerView() {
    }
 
    public void setConfig(CityConfig config) {
        this.config = config;
    }
 
    public void init(Context context) {
        this.context = context;
        this.parseHelper = new CityParseHelper();
        if (this.parseHelper.getProvinceBeanArrayList().isEmpty()) {
            this.parseHelper.initData(context);
        }
 
    }
 
    @SuppressLint("WrongConstant")
    private void initCityPickerPopwindow() {
        if (this.config == null) {
            throw new IllegalArgumentException("please set config first...");
        } else {
            if (this.parseHelper == null) {
                this.parseHelper = new CityParseHelper();
            }
 
            if (this.parseHelper.getProvinceBeanArrayList().isEmpty()) {
                ToastUtils.showLongToast(this.context, "请在Activity中增加init操作");
            } else {
                LayoutInflater layoutInflater = LayoutInflater.from(this.context);
                this.popview = layoutInflater.inflate(R.layout.pop_citypicker, (ViewGroup)null);
                this.mViewProvince = (WheelView)this.popview.findViewById(id.id_province);
                this.mViewCity = (WheelView)this.popview.findViewById(id.id_city);
                this.mViewDistrict = (WheelView)this.popview.findViewById(id.id_district);
                this.mRelativeTitleBg = (RelativeLayout)this.popview.findViewById(id.rl_title);
                this.mTvOK = (TextView)this.popview.findViewById(id.tv_confirm);
                this.mTvTitle = (TextView)this.popview.findViewById(id.tv_title);
                this.mTvCancel = (TextView)this.popview.findViewById(id.tv_cancel);
                this.popwindow = new PopupWindow(this.popview, -1, -2);
                this.popwindow.setAnimationStyle(style.AnimBottom);
                this.popwindow.setBackgroundDrawable(new ColorDrawable());
                this.popwindow.setTouchable(true);
                this.popwindow.setOutsideTouchable(false);
                this.popwindow.setFocusable(true);
                this.popwindow.setOnDismissListener(new OnDismissListener() {
                    public void onDismiss() {
                        if (CityPickerView.this.config.isShowBackground()) {
                            utils.setBackgroundAlpha(CityPickerView.this.context, 1.0F);
                        }
 
                    }
                });
                if (!TextUtils.isEmpty(this.config.getTitleBackgroundColorStr())) {
                    if (this.config.getTitleBackgroundColorStr().startsWith("#")) {
                        this.mRelativeTitleBg.setBackgroundColor(Color.parseColor(this.config.getTitleBackgroundColorStr()));
                    } else {
                        this.mRelativeTitleBg.setBackgroundColor(Color.parseColor("#" + this.config.getTitleBackgroundColorStr()));
                    }
                }
 
                if (!TextUtils.isEmpty(this.config.getTitle())) {
                    this.mTvTitle.setText(this.config.getTitle());
                }
 
                if (this.config.getTitleTextSize() > 0) {
                    this.mTvTitle.setTextSize((float)this.config.getTitleTextSize());
                }
 
                if (!TextUtils.isEmpty(this.config.getTitleTextColorStr())) {
                    if (this.config.getTitleTextColorStr().startsWith("#")) {
                        this.mTvTitle.setTextColor(Color.parseColor(this.config.getTitleTextColorStr()));
                    } else {
                        this.mTvTitle.setTextColor(Color.parseColor("#" + this.config.getTitleTextColorStr()));
                    }
                }
 
                if (!TextUtils.isEmpty(this.config.getConfirmTextColorStr())) {
                    if (this.config.getConfirmTextColorStr().startsWith("#")) {
                        this.mTvOK.setTextColor(Color.parseColor(this.config.getConfirmTextColorStr()));
                    } else {
                        this.mTvOK.setTextColor(Color.parseColor("#" + this.config.getConfirmTextColorStr()));
                    }
                }
 
                if (!TextUtils.isEmpty(this.config.getConfirmText())) {
                    this.mTvOK.setText(this.config.getConfirmText());
                }
 
                if (this.config.getConfirmTextSize() > 0) {
                    this.mTvOK.setTextSize((float)this.config.getConfirmTextSize());
                }
 
                if (!TextUtils.isEmpty(this.config.getCancelTextColorStr())) {
                    if (this.config.getCancelTextColorStr().startsWith("#")) {
                        this.mTvCancel.setTextColor(Color.parseColor(this.config.getCancelTextColorStr()));
                    } else {
                        this.mTvCancel.setTextColor(Color.parseColor("#" + this.config.getCancelTextColorStr()));
                    }
                }
 
                if (!TextUtils.isEmpty(this.config.getCancelText())) {
                    this.mTvCancel.setText(this.config.getCancelText());
                }
 
                if (this.config.getCancelTextSize() > 0) {
                    this.mTvCancel.setTextSize((float)this.config.getCancelTextSize());
                }
 
                if (this.config.getWheelType() == WheelType.PRO) {
                    this.mViewCity.setVisibility(8);
                    this.mViewDistrict.setVisibility(8);
                } else if (this.config.getWheelType() == WheelType.PRO_CITY) {
                    this.mViewDistrict.setVisibility(8);
                } else {
                    this.mViewProvince.setVisibility(0);
                    this.mViewCity.setVisibility(0);
                    this.mViewDistrict.setVisibility(0);
                }
 
                this.mViewProvince.addChangingListener(this);
                this.mViewCity.addChangingListener(this);
                this.mViewDistrict.addChangingListener(this);
                this.mTvCancel.setOnClickListener(new OnClickListener() {
                    public void onClick(View v) {
                        CityPickerView.this.mBaseListener.onCancel();
                        CityPickerView.this.hide();
                    }
                });
                this.mTvOK.setOnClickListener(new OnClickListener() {
                    public void onClick(View v) {
                        if (CityPickerView.this.parseHelper != null) {
                            if (CityPickerView.this.config.getWheelType() == WheelType.PRO) {
                                CityPickerView.this.mBaseListener.onSelected(CityPickerView.this.parseHelper.getProvinceBean(), new CityBean(), new DistrictBean());
                            } else if (CityPickerView.this.config.getWheelType() == WheelType.PRO_CITY) {
                                CityPickerView.this.mBaseListener.onSelected(CityPickerView.this.parseHelper.getProvinceBean(), CityPickerView.this.parseHelper.getCityBean(), new DistrictBean());
                            } else {
                                CityPickerView.this.mBaseListener.onSelected(CityPickerView.this.parseHelper.getProvinceBean(), CityPickerView.this.parseHelper.getCityBean(), CityPickerView.this.parseHelper.getDistrictBean());
                            }
                        } else {
                            CityPickerView.this.mBaseListener.onSelected(new ProvinceBean(), new CityBean(), new DistrictBean());
                        }
 
                        CityPickerView.this.hide();
                    }
                });
                this.setUpData();
                if (this.config != null && this.config.isShowBackground()) {
                    utils.setBackgroundAlpha(this.context, 0.5F);
                }
 
            }
        }
    }
 
    private List<ProvinceBean> getProArrData(List<ProvinceBean> array) {
        List<ProvinceBean> provinceBeanList = new ArrayList();
 
        int i;
        for(i = 0; i < array.size(); ++i) {
            provinceBeanList.add(array.get(i));
        }
 
        if (!this.config.isShowGAT()) {
            provinceBeanList.remove(provinceBeanList.size() - 1);
            provinceBeanList.remove(provinceBeanList.size() - 1);
            provinceBeanList.remove(provinceBeanList.size() - 1);
        }
 
        this.proArra = new ArrayList();
 
        for(i = 0; i < provinceBeanList.size(); ++i) {
            this.proArra.add(provinceBeanList.get(i));
        }
 
        return this.proArra;
    }
 
    private void setUpData() {
        if (this.parseHelper != null && this.config != null) {
            this.getProArrData(this.parseHelper.getProvinceBeenArray());
            int provinceDefault = -1;
            if (!TextUtils.isEmpty(this.config.getDefaultProvinceName()) && this.proArra.size() > 0) {
                for(int i = 0; i < this.proArra.size(); ++i) {
                    if (((ProvinceBean)this.proArra.get(i)).getName().contains(this.config.getDefaultProvinceName())) {
                        provinceDefault = i;
                        break;
                    }
                }
            }
 
            ArrayWheelAdapter arrayWheelAdapter = new ArrayWheelAdapter(this.context, this.proArra);
            this.mViewProvince.setViewAdapter(arrayWheelAdapter);
            if (this.config.getCustomItemLayout() != CityConfig.NONE && this.config.getCustomItemTextViewId() != CityConfig.NONE) {
                arrayWheelAdapter.setItemResource(this.config.getCustomItemLayout());
                arrayWheelAdapter.setItemTextResource(this.config.getCustomItemTextViewId());
            } else {
                arrayWheelAdapter.setItemResource(layout.default_item_city);
                arrayWheelAdapter.setItemTextResource(id.default_item_city_name_tv);
            }
 
            if (-1 != provinceDefault) {
                this.mViewProvince.setCurrentItem(provinceDefault);
            }
 
            this.mViewProvince.setVisibleItems(this.config.getVisibleItems());
            this.mViewCity.setVisibleItems(this.config.getVisibleItems());
            this.mViewDistrict.setVisibleItems(this.config.getVisibleItems());
            this.mViewProvince.setCyclic(this.config.isProvinceCyclic());
            this.mViewCity.setCyclic(this.config.isCityCyclic());
            this.mViewDistrict.setCyclic(this.config.isDistrictCyclic());
            this.mViewProvince.setDrawShadows(this.config.isDrawShadows());
            this.mViewCity.setDrawShadows(this.config.isDrawShadows());
            this.mViewDistrict.setDrawShadows(this.config.isDrawShadows());
            this.mViewProvince.setLineColorStr(this.config.getLineColor());
            this.mViewProvince.setLineWidth(this.config.getLineHeigh());
            this.mViewCity.setLineColorStr(this.config.getLineColor());
            this.mViewCity.setLineWidth(this.config.getLineHeigh());
            this.mViewDistrict.setLineColorStr(this.config.getLineColor());
            this.mViewDistrict.setLineWidth(this.config.getLineHeigh());
            this.updateCities();
            this.updateAreas();
        }
    }
 
    private void updateCities() {
        if (this.parseHelper != null && this.config != null) {
            int pCurrent = this.mViewProvince.getCurrentItem();
            ProvinceBean mProvinceBean = (ProvinceBean)this.proArra.get(pCurrent);
            this.parseHelper.setProvinceBean(mProvinceBean);
            if (this.parseHelper.getPro_CityMap() != null) {
                List<CityBean> cities = (List)this.parseHelper.getPro_CityMap().get(mProvinceBean.getName());
                if (cities != null) {
                    int cityDefault = -1;
                    if (!TextUtils.isEmpty(this.config.getDefaultCityName()) && cities.size() > 0) {
                        for(int i = 0; i < cities.size(); ++i) {
                            if (this.config.getDefaultCityName().contains(((CityBean)cities.get(i)).getName())) {
                                cityDefault = i;
                                break;
                            }
                        }
                    }
 
                    ArrayWheelAdapter cityWheel = new ArrayWheelAdapter(this.context, cities);
                    if (this.config.getCustomItemLayout() != CityConfig.NONE && this.config.getCustomItemTextViewId() != CityConfig.NONE) {
                        cityWheel.setItemResource(this.config.getCustomItemLayout());
                        cityWheel.setItemTextResource(this.config.getCustomItemTextViewId());
                    } else {
                        cityWheel.setItemResource(layout.default_item_city);
                        cityWheel.setItemTextResource(id.default_item_city_name_tv);
                    }
 
                    this.mViewCity.setViewAdapter(cityWheel);
                    if (-1 != cityDefault) {
                        this.mViewCity.setCurrentItem(cityDefault);
                    } else {
                        this.mViewCity.setCurrentItem(0);
                    }
 
                    this.updateAreas();
                }
            }
        }
    }
 
    private void updateAreas() {
        int pCurrent = this.mViewCity.getCurrentItem();
        if (this.parseHelper.getPro_CityMap() != null && this.parseHelper.getCity_DisMap() != null) {
            if (this.config.getWheelType() == WheelType.PRO_CITY || this.config.getWheelType() == WheelType.PRO_CITY_DIS) {
                CityBean mCityBean = (CityBean)((List)this.parseHelper.getPro_CityMap().get(this.parseHelper.getProvinceBean().getName())).get(pCurrent);
                this.parseHelper.setCityBean(mCityBean);
                if (this.config.getWheelType() == WheelType.PRO_CITY_DIS) {
                    List<DistrictBean> areas = (List)this.parseHelper.getCity_DisMap().get(this.parseHelper.getProvinceBean().getName() + mCityBean.getName());
                    if (areas == null) {
                        return;
                    }
 
                    int districtDefault = -1;
                    if (!TextUtils.isEmpty(this.config.getDefaultDistrict()) && areas.size() > 0) {
                        for(int i = 0; i < areas.size(); ++i) {
                            if (this.config.getDefaultDistrict().contains(((DistrictBean)areas.get(i)).getName())) {
                                districtDefault = i;
                                break;
                            }
                        }
                    }
 
                    ArrayWheelAdapter districtWheel = new ArrayWheelAdapter(this.context, areas);
                    if (this.config.getCustomItemLayout() != CityConfig.NONE && this.config.getCustomItemTextViewId() != CityConfig.NONE) {
                        districtWheel.setItemResource(this.config.getCustomItemLayout());
                        districtWheel.setItemTextResource(this.config.getCustomItemTextViewId());
                    } else {
                        districtWheel.setItemResource(layout.default_item_city);
                        districtWheel.setItemTextResource(id.default_item_city_name_tv);
                    }
 
                    this.mViewDistrict.setViewAdapter(districtWheel);
                    DistrictBean mDistrictBean = null;
                    if (this.parseHelper.getDisMap() == null) {
                        return;
                    }
 
                    if (-1 != districtDefault) {
                        this.mViewDistrict.setCurrentItem(districtDefault);
                        mDistrictBean = (DistrictBean)this.parseHelper.getDisMap().get(this.parseHelper.getProvinceBean().getName() + mCityBean.getName() + this.config.getDefaultDistrict());
                    } else {
                        this.mViewDistrict.setCurrentItem(0);
                        if (areas.size() > 0) {
                            mDistrictBean = (DistrictBean)areas.get(0);
                        }
                    }
 
                    this.parseHelper.setDistrictBean(mDistrictBean);
                }
            }
 
        }
    }
 
    public void showCityPicker() {
        this.initCityPickerPopwindow();
        popview.findViewById(R.id.id_district).setVisibility(View.GONE);
        popview.findViewById(R.id.ll_title_background).setBackgroundResource(R.drawable.bg_white_10_top);
        popview.findViewById(R.id.rl_title).setBackgroundResource(R.drawable.bg_white_10_top);
        mViewProvince.setBackgroundResource(R.color.white);
        if (!this.isShow()) {
            this.popwindow.showAtLocation(this.popview, 80, 0, 0);
        }
 
    }
 
    public void hide() {
        if (this.isShow()) {
            this.popwindow.dismiss();
        }
 
    }
 
    public boolean isShow() {
        return this.popwindow.isShowing();
    }
 
    public void onChanged(WheelView wheel, int oldValue, int newValue) {
        if (wheel == this.mViewProvince) {
            this.updateCities();
        } else if (wheel == this.mViewCity) {
            this.updateAreas();
        } else if (wheel == this.mViewDistrict && this.parseHelper != null && this.parseHelper.getCity_DisMap() != null) {
            DistrictBean mDistrictBean = (DistrictBean)((List)this.parseHelper.getCity_DisMap().get(this.parseHelper.getProvinceBean().getName() + this.parseHelper.getCityBean().getName())).get(newValue);
            this.parseHelper.setDistrictBean(mDistrictBean);
        }
 
    }
}