PresonInfoFragment.java
15.3 KB
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
package com.hjx.personalcenter.fragment;
import android.app.Activity;
import android.graphics.Color;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.util.Log;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;
import com.bigkoo.pickerview.TimePickerView;
import com.hjx.personalcenter.R;
import com.hjx.personalcenter.customdialog.CitysListDialog;
import com.hjx.personalcenter.customdialog.CountryDialog;
import com.hjx.personalcenter.customdialog.GradeListDialog;
import com.hjx.personalcenter.customdialog.ProvinceListDialog;
import com.hjx.personalcenter.customdialog.SchoolListDialog;
import com.hjx.personalcenter.db.Content;
import com.hjx.personalcenter.db.SaveParam;
import com.hjx.personalcenter.http.HttpManager;
import com.hjx.personalcenter.interfaces.DialogCallBack;
import com.hjx.personalcenter.model.CityInfo;
import com.hjx.personalcenter.model.CountyInfo;
import com.hjx.personalcenter.model.GradeInfo;
import com.hjx.personalcenter.model.ProvinceInfo;
import com.hjx.personalcenter.model.SchoolInfo;
import com.hjx.personalcenter.util.AlertUtils;
import com.hjx.personalcenter.util.BrithdayStar;
import com.hjx.personalcenter.util.GetDevicesUtil;
import com.mylhyl.circledialog.CircleDialog;
import com.mylhyl.circledialog.callback.ConfigDialog;
import com.mylhyl.circledialog.params.DialogParams;
import org.apache.http.util.TextUtils;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
/**
* Created by h on 2017/8/12.
*/
public class PresonInfoFragment extends Fragment implements View.OnClickListener, DialogCallBack.GradeCallBack, DialogCallBack.ProvincesCallBack
, DialogCallBack.CitysCallBack, DialogCallBack.CountryCallBack, DialogCallBack.SchoolCallBack {
private View mView;
private int type;
private TimePickerView pvTime;
private EditText tv_username1, tv_useinfo_adress1, tv_useinfo_qq;
private TextView tv_sex, tv_useinfo_adress, tv_useinfo_birthday, tv_useinfo_school, tv_useinfo_gender;
public static String TABLAYOUT_FRAGMENT = "presonfragment";
private ImageView my_adress,my_sex,my_bthday,my_grade,my_school;
public static PresonInfoFragment newInstance(int type) {
PresonInfoFragment fragment = new PresonInfoFragment();
Bundle bundle = new Bundle();
bundle.putSerializable(TABLAYOUT_FRAGMENT, type);
fragment.setArguments(bundle);
return fragment;
}
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
if (mView == null) {
mView = inflater.inflate(R.layout.fragment_changge_presonal_info, container, false);
initView(mView);
initData();
setLister();
initTimePicker();
}
return mView;
}
//初始化
private void initView(View mView) {
tv_username1 = (EditText) mView.findViewById(R.id.tv_username1);
tv_useinfo_adress1 = (EditText) mView.findViewById(R.id.tv_useinfo_adress1);
tv_useinfo_qq = (EditText) mView.findViewById(R.id.tv_useinfo_qq);
tv_sex = (TextView) mView.findViewById(R.id.tv_sex);
tv_useinfo_adress = (TextView) mView.findViewById(R.id.tv_useinfo_adress);
tv_useinfo_birthday = (TextView) mView.findViewById(R.id.tv_useinfo_birthday);
tv_useinfo_school = (TextView) mView.findViewById(R.id.tv_useinfo_school);
tv_useinfo_gender = (TextView) mView.findViewById(R.id.tv_useinfo_gender);
my_adress = (ImageView) mView.findViewById(R.id.my_adress);
my_sex = (ImageView) mView.findViewById(R.id.my_sex);
my_bthday = (ImageView) mView.findViewById(R.id.my_bthday);
my_grade = (ImageView) mView.findViewById(R.id.my_grade);
my_school = (ImageView) mView.findViewById(R.id.my_school);
}
private void initData() {
}
private void setLister() {
tv_sex.setOnClickListener(this);
tv_useinfo_adress.setOnClickListener(this);
tv_useinfo_birthday.setOnClickListener(this);
tv_useinfo_school.setOnClickListener(this);
tv_useinfo_gender.setOnClickListener(this);
my_adress.setOnClickListener(this);
my_sex.setOnClickListener(this);
my_bthday.setOnClickListener(this);
my_grade.setOnClickListener(this);
my_school.setOnClickListener(this);
}
@Override
public void onClick(View v) {
String presonal1 = tv_username1.getText().toString().trim();
String presonal2 = tv_useinfo_adress1.getText().toString().trim();
String presonal3 = tv_sex.getText().toString().trim();
String presonal4 = tv_useinfo_adress.getText().toString().trim();
String presonal5 = tv_useinfo_birthday.getText().toString().trim();
String presonal6 = tv_useinfo_school.getText().toString().trim();
String presonal7 = tv_useinfo_gender.getText().toString().trim();
String presonal8 = tv_useinfo_qq.getText().toString().trim();
switch (v.getId()) {
case R.id.tv_sex:
case R.id.my_sex:
final String[] items = {"男", "女"};
new CircleDialog.Builder(getActivity())
.configDialog(new ConfigDialog() {
@Override
public void onConfig(DialogParams params) {
//增加弹出动画
params.gravity = Gravity.CENTER;
}
})
.setTitle("请选择性别")
.setWidth(0.5f)
.setItems(items, new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int
position, long id) {
switch (position) {
case 0:
tv_sex.setText("男");
break;
case 1:
tv_sex.setText("女");
break;
}
}
})
.show();
break;
case R.id.tv_useinfo_adress:
case R.id.my_adress:
ProvinceListDialog.getInstance((DialogCallBack.ProvincesCallBack) PresonInfoFragment.this).show(getChildFragmentManager(), "ProvinceListDialog");
break;
case R.id.tv_useinfo_birthday:
case R.id.my_bthday:
pvTime.show(tv_useinfo_birthday);//弹出时间选择器,传递参数过去,回调的时候则可以绑定此view
break;
case R.id.tv_useinfo_school:
case R.id.my_school:
if (TextUtils.isEmpty(presonal4) ||
TextUtils.isEmpty(presonal7)) {
AlertUtils.showToast(getActivity(), "请先选择地区和年级!");
return;
} else {
SchoolListDialog.getInstance((DialogCallBack.SchoolCallBack) PresonInfoFragment.this).show(getChildFragmentManager(), "SchoolListDialog");
}
break;
case R.id.tv_useinfo_gender:
case R.id.my_grade:
GradeListDialog.getInstance((DialogCallBack.GradeCallBack) PresonInfoFragment.this).show(getChildFragmentManager(), "GradeListDialog");
break;
case R.id.presonal_sub:
if (Content.changeinfoflag == 1) {
Log.e("test","你提交个人信息");
if (TextUtils.isEmpty(presonal1) ||
TextUtils.isEmpty(presonal2) || TextUtils.isEmpty(presonal3) || TextUtils.isEmpty(presonal4) ||
TextUtils.isEmpty(presonal5) || TextUtils.isEmpty(presonal7) ||
TextUtils.isEmpty(presonal8)) {
AlertUtils.showToast(getActivity(), "请将信息填写完整!");
return;
} else {
int a = 0, b = 0;
int d = 1;
Object schoolids;
Long f = null;
//保存星座
BrithdayStar brithdayStar = new BrithdayStar();
String s = brithdayStar.getConstellations(tv_useinfo_birthday.getText().toString());
SaveParam.getInstance().saveLoginParam(getActivity(), SaveParam.CONSTELLATION, s);
String regionId = SaveParam.getInstance().getLoginParam(getActivity(), SaveParam.COUNTRY);
String regionId1 = SaveParam.getInstance().getLoginParam(getActivity(), SaveParam.CITYS);
if (regionId == null) {
regionId = regionId1;
}
String grade = SaveParam.getInstance().getCustomizeParam(getActivity(), SaveParam.GRADENS);
String schoolid = SaveParam.getInstance().getLoginParam(getActivity(), SaveParam.SCHOOOlID);
String type = SaveParam.getInstance().getCustomizeParam(getActivity(), SaveParam.ACCOUNT);
String userID = SaveParam.getInstance().getLoginParam(getActivity(), "userId");
String devicenumber = GetDevicesUtil.getDevicesInfo(getActivity()).getDeviceNumber();
String changeinfo = null;
if ("男".equals(presonal3)) {
changeinfo = "male";
} else {
changeinfo = "female";
}
try {
a = Integer.parseInt(regionId);
b = Integer.parseInt(grade);
if (TextUtils.isEmpty(presonal6)) {
schoolids = null;
} else {
schoolids = Long.parseLong(schoolid);
}
d = Integer.parseInt(type);
f = Long.parseLong(userID);
//提交个人信息
HttpManager.getInstance().changepresonalinfo(getActivity(),
f, d, presonal1, presonal5, b, a, schoolids, presonal8, changeinfo, presonal4 + presonal2, devicenumber);
} catch (Exception e) {
e.printStackTrace();
}
}
break;
}
}
}
//自定义时间选择器
private void initTimePicker() {
//控制时间范围(如果不设置范围,则使用默认时间1900-2100年,此段代码可注释)
//因为系统Calendar的月份是从0-11的,所以如果是调用Calendar的set方法来设置时间,月份的范围也要是从0-11
// Calendar selectedDate = Calendar.getInstance();
// Calendar startDate = Calendar.getInstance();
// startDate.set(1900, 1, 1);
// Calendar endDate = Calendar.getInstance();
// endDate.set(2100, 1, 1);
//时间选择器
pvTime = new TimePickerView.Builder(getActivity(), new TimePickerView.OnTimeSelectListener() {
@Override
public void onTimeSelect(Date date, View v) {//选中事件回调
// 这里回调过来的v,就是show()方法里面所添加的 View 参数,如果show的时候没有添加参数,v则为null
/*btn_Time.setText(getTime(date));*/
TextView btn = (TextView) v;
btn.setText(getTime(date));
}
})
//年月日时分秒 的显示与否,不设置则默认全部显示
.setType(new boolean[]{true, true, true, false, false, false})
.setLabel("", "", "", "", "", "")
.isCenterLabel(false)
.setDividerColor(Color.DKGRAY)
.setContentSize(21)
// .setDate(selectedDate)
// .setRangDate(startDate, endDate)
.setBackgroundId(0x80000000) //设置外部遮罩颜色
.setDecorView(null)
.setTitleText("出生日期")
.setTitleSize(22)
.setCancelColor(Color.GRAY)
.setSubCalSize(22)
.setDividerColor(Color.GRAY)
.setSubmitColor(Color.GRAY)
.build();
}
private String getTime(Date date) {//可根据需要自行截取数据显示
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
return format.format(date);
}
@Override
public void onAttach(Activity activity) {
super.onAttach(activity);
View rootView = activity.getWindow().getDecorView();
TextView sub = (TextView) rootView.findViewById(R.id.presonal_sub);
sub.setOnClickListener(this);
}
@Override
public void province1OnItemClick(ArrayList<CityInfo.CitiesBean> data, int position, int type) {
String regionName = data.get(position).getRegionName();
String provice = SaveParam.getInstance().getLoginParam(getActivity(), "sheng");
SaveParam.getInstance().saveLoginParam(getActivity(), "shi", regionName);
CountryDialog.getInstance((DialogCallBack.CountryCallBack) this).show(getChildFragmentManager(), "CountryDialog");
tv_useinfo_adress.setText("");
tv_useinfo_adress.setText(provice + regionName);
}
@Override
public void province2OnItemClick(ArrayList<CountyInfo.CountiesBean> data, int position, int type) {
String regionName = data.get(position).getRegionName();
String provices = SaveParam.getInstance().getLoginParam(getActivity(), "sheng");
String citys = SaveParam.getInstance().getLoginParam(getActivity(), "shi");
tv_useinfo_adress.setText("");
tv_useinfo_adress.setText(provices + citys + regionName);
}
@Override
public void province3OnItemClick(ArrayList<GradeInfo.DataBean.ChildrenBean> data, int position, int type) {
String regionName = data.get(position).getName();
tv_useinfo_gender.setText(regionName);
}
@Override
public void provinceOnItemClick(ArrayList<ProvinceInfo.ProvincesBean> data, int position, int type) {
String regionName = data.get(position).getRegionName();
SaveParam.getInstance().saveLoginParam(getActivity(), "sheng", regionName);
CitysListDialog.getInstance((DialogCallBack.CitysCallBack) PresonInfoFragment.this).show(getChildFragmentManager(), "CitysListDialog");
tv_useinfo_adress.setText("");
tv_useinfo_adress.setText(regionName);
}
@Override
public void provinceO4nItemClick(ArrayList<SchoolInfo.DataBean> data, int position, int type) {
String regionName = data.get(position).getSchoolName();
tv_useinfo_school.setText(regionName);
}
}