8ce8caa69c3bd9bc3b2b07884197cb0fdd48e7d0.svn-base
8.54 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
340
341
342
343
344
345
346
347
348
package com.ivt.android.me.ui.activity.withdraw;
import android.app.Dialog;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;
import com.ivt.android.me.R;
import com.ivt.android.me.api.UserApiBean;
import com.ivt.android.me.bean.BaseBean;
import com.ivt.android.me.bean.evenbus.CodeBean;
import com.ivt.android.me.constant.BaseInfo;
import com.ivt.android.me.constant.CodeUtils;
import com.ivt.android.me.ui.base.BaseActivity;
import com.ivt.android.me.utils.httputil.HttpUtils;
import com.ivt.android.me.utils.httputil.HttpUtils.HttpCallback;
import com.ivt.android.me.utils.httputil.JsonUtils;
import com.ivt.android.me.utils.publics.MyToastUtils;
import com.ivt.android.me.utils.publics.StringUtils;
import com.lidroid.xutils.ViewUtils;
import com.lidroid.xutils.view.annotation.ViewInject;
import com.lidroid.xutils.view.annotation.event.OnClick;
import de.greenrobot.event.EventBus;
public class MtToChActivity extends BaseActivity {
@ViewInject(R.id.china_num)
private TextView china_num;
@ViewInject(R.id.account_one)
private TextView account_one;
@ViewInject(R.id.account_two)
private TextView account_two;
@ViewInject(R.id.account_th)
private TextView account_th;
@ViewInject(R.id.bt_one)
private TextView bt_one;
@ViewInject(R.id.bt_two)
private TextView bt_two;
@ViewInject(R.id.bt_th)
private TextView bt_th;
@ViewInject(R.id.myset)
private Button myset;
@ViewInject(R.id.acc_layout_second_bg1)
private RelativeLayout acc_layout_second_bg1;
@ViewInject(R.id.acc_layout_second_bg2)
private RelativeLayout acc_layout_second_bg2;
@ViewInject(R.id.acc_layout_second_bg3)
private RelativeLayout acc_layout_second_bg3;
@ViewInject(R.id.acc_back_btn)
private ImageView acc_back_btn;
int me = 0;
int china = 0;
MtoCDialog medio;
/**
* 汇率公式 蜜糖 = f*r
**/
float f = 1;
int total = 0;
/**
* 自定义中花费的蜜糖
*/
int hua_mi = 0;
/**
* 自定义中得到的中国币
*/
int hua_china = 0;
String value;
@Override
public int getResLayoutId() {
// TODO Auto-generated method stub
return R.layout.activity_mt_to_ch;
}
@Override
protected void findViews() {
// TODO Auto-generated method stub
ViewUtils.inject(this);
}
@Override
protected void processLogic() {
// TODO Auto-generated method stub
value = this.getIntent().getStringExtra("value");
if (!StringUtils.isEmpty(value)) {
f = Float.parseFloat(value);
bt_one.setText((int) (60 / f) + "蜜糖");
bt_two.setText((int) (300 / f) + "蜜糖");
bt_th.setText((int) (900 / f) + "蜜糖");
}
total = this.getIntent().getIntExtra("total", 0);
china_num.setText(total + "");
}
@OnClick({ R.id.acc_layout_second_bg1, R.id.acc_layout_second_bg2,
R.id.acc_layout_second_bg3, R.id.myset, R.id.acc_back_btn })
public void onClick(View v) {
Intent intent = null;
switch (v.getId()) {
case R.id.acc_back_btn:
EventBus.getDefault().post(new CodeBean(CodeUtils.DUIHUA,Integer.parseInt(china_num.getText().toString())));
this.finish();
break;
case R.id.acc_layout_second_bg1:
me = (int) (60/f);
china = 60;
new MtoCDialog(this, R.style.dialog).show();
break;
case R.id.acc_layout_second_bg2:
me = (int) ( 300/f);
china = 300;
new MtoCDialog(this, R.style.dialog).show();
break;
case R.id.acc_layout_second_bg3:
me = (int) ( 900/f);
china = 900;
new MtoCDialog(this, R.style.dialog).show();
break;
case R.id.myset:
new MyMToChinaDialog(this, R.style.dialog).show();
break;
default:
break;
}
}
/**
* 系统兑换的dialog
*
* @author 郎咸智
*
* 2016-6-21 上午11:27:15
*/
public class MtoCDialog extends Dialog implements
View.OnClickListener {
private TextView text;
private Button t;
private Button n;
private Context context;
public MtoCDialog(Context context, int theme) {
super(context, theme);
// TODO Auto-generated constructor stub
this.context = context;
}
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
this.setContentView(R.layout.dialog_mtoc);
t = (Button) this.findViewById(R.id.mtc_true);
n = (Button) this.findViewById(R.id.mtc_no);
text = (TextView) this.findViewById(R.id.mtc_text);
t.setOnClickListener(this);
n.setOnClickListener(this);
text.setText("你将用" + me + "蜜糖兑换" + china + "中国币");
}
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
switch (v.getId()) {
case R.id.mtc_true:
DuiXian(me, this);
break;
case R.id.mtc_no:
this.dismiss();
break;
default:
break;
}
}
}
/**
* 自定义的dialog
*
* @author 郎咸智
*
* 2016-6-21 上午11:27:26
*/
public class MyMToChinaDialog extends Dialog implements
View.OnClickListener, TextWatcher {
private TextView mt_text;
private Button mtc_true;
private Button mtc_no;
private TextView china_num;
private EditText ed_mitang;
private Context context;
public MyMToChinaDialog(Context context, int theme) {
super(context, theme);
// TODO Auto-generated constructor stub
this.context = context;
}
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
this.setContentView(R.layout.dialog_mymtoc);
mt_text = (TextView) this.findViewById(R.id.mt_text);
mtc_true = (Button) this.findViewById(R.id.mtc_true);
mtc_no = (Button) this.findViewById(R.id.mtc_no);
mt_text.setText("账户余额" + total + "蜜糖");
mtc_true.setOnClickListener(this);
mtc_no.setOnClickListener(this);
china_num = (TextView) this.findViewById(R.id.china_num);
ed_mitang = (EditText) this.findViewById(R.id.ed_mitang);
ed_mitang.addTextChangedListener(this);
}
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
switch (v.getId()) {
case R.id.mtc_true:
DuiXian(hua_mi, this);
break;
case R.id.mtc_no:
this.dismiss();
break;
default:
break;
}
}
@Override
public void beforeTextChanged(CharSequence s, int start, int count,
int after) {
// TODO Auto-generated method stub
}
@Override
public void onTextChanged(CharSequence s, int start, int before,
int count) {
// TODO Auto-generated method stub
if (s.length() > 0) {
int t = Integer.parseInt(s.toString());
if (t > total) {
t = total;
ed_mitang.setText(t + "");
}
hua_mi = t;
hua_china = (int) (t * f);
if (hua_china < 1) {
china_num.setText(0 + " 中国币");
} else {
china_num.setText(hua_china + " 中国币");
}
} else {
china_num.setText(0 + " 中国币");
hua_china = 0;
hua_mi = 0;
}
}
@Override
public void afterTextChanged(Editable s) {
// TODO Auto-generated method stub
}
}
private void DuiXian(final int mitang, final Dialog dia) {
// 请求的路径
String requestUrl = UserApiBean.withdraw(BaseInfo.UserId,
BaseInfo.Captcha, mitang + "");
HttpUtils.get(requestUrl, new HttpCallback() {
@Override
public void onSuccess(String data) {
// TODO Auto-generated method stub
BaseBean user1 = JsonUtils.deserialize(data, BaseBean.class);
int code = user1.getCode();
String description = user1.getDescription();
if (code == 0) {
MyToastUtils.showToast(MtToChActivity.this, "提现成功");
String t = china_num.getText().toString();
int t1 = Integer.parseInt(t);
t1 = t1 - mitang;
total = t1 - mitang;
if (t1 > 0) {
china_num.setText(t1 + "");
} else {
china_num.setText("0");
}
if (dia.isShowing()) {
dia.dismiss();
}
} else if (code == 8000) {
MyToastUtils.showToast(MtToChActivity.this, "蜜糖币余额不足");
} else if (code == 8001) {
MyToastUtils.showToast(MtToChActivity.this, "提现金额必须为" + (f)
+ "的倍数");
}
else {
MyToastUtils.showToast(MtToChActivity.this, "服务器繁忙,提现失败");
}
}
@Override
public void onError(String msg) {
// TODO Auto-generated method stub
super.onError(msg);
MyToastUtils.showToast(MtToChActivity.this, "网络异常,提现失败" + msg);
}
});
}
@Override
public void onEventMainThread(CodeBean code) {
// TODO Auto-generated method stub
}
}