-
Notifications
You must be signed in to change notification settings - Fork 1
/
PrivateActivity.java
158 lines (136 loc) · 4.99 KB
/
PrivateActivity.java
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
package com.tudaidai.tuantrip;
import com.tudaidai.tuantrip.app.TuanTripApp;
import com.tudaidai.tuantrip.types.BaseResult;
import com.tudaidai.tuantrip.types.User;
import com.tudaidai.tuantrip.util.NotificationsUtil;
import android.app.Activity;
import android.app.ProgressDialog;
import android.content.Intent;
import android.os.AsyncTask;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
public class PrivateActivity extends Activity {
static final boolean DEBUG = true;
static final String TAG = "PrivateActivity";
private EditText mEmailEdit;
private EditText mNewPwdEdit;
private EditText mOldPwdEdit;
private EditText mPhoneEdit;
private ProgressDialog mProgressDialog;
private EditText mRePwdEdit;
private User mUser;
private EditText mUserEdit;
private void dismissProgressDialog() {
mProgressDialog.dismiss();
}
private void startProgressBar(String title, String content) {
mProgressDialog = ProgressDialog.show(this, title, content);
mProgressDialog.show();
}
private void onUpdateTaskComplete(BaseResult baseResult, Exception exception) {
if (baseResult == null) {
NotificationsUtil.ToastReasonForFailure(this, exception);
} else if (baseResult.mHttpResult.getStat() == TuanTripSettings.POSTSUCCESS) {
Toast.makeText(this, baseResult.mHttpResult.getMessage(),
Toast.LENGTH_SHORT).show();
((TuanTrip) getApplication()).loginOut();
Intent localIntent4 = new Intent(this, LoginActivity.class);
localIntent4.putExtra(LoginActivity.EXTRA_OPTION,
LoginActivity.OPTION_SET);
startActivity(localIntent4);
finish();
} else if (baseResult.mHttpResult.getStat() == TuanTripSettings.POSTFAILED) {
Toast.makeText(this, baseResult.mHttpResult.getMessage(),
Toast.LENGTH_SHORT).show();
} else if (baseResult.mHttpResult.getStat() == TuanTripSettings.LOGINFAILED) {
Toast.makeText(this, baseResult.mHttpResult.getMessage(),
Toast.LENGTH_SHORT).show();
((TuanTrip) getApplication()).loginOut();
Intent localIntent4 = new Intent(this, LoginActivity.class);
localIntent4.putExtra(LoginActivity.EXTRA_OPTION,
LoginActivity.OPTION_SUBMIT_ORDER);
startActivity(localIntent4);
} else {
NotificationsUtil.ToastReasonForFailure(this, exception);
}
dismissProgressDialog();
}
private void ensureUi() {
mEmailEdit = (EditText) findViewById(R.id.emailEdit);
mEmailEdit.setText(mUser.getEmail());
mUserEdit = (EditText) findViewById(R.id.userEdit);
mUserEdit.setText(mUser.getUname());
mPhoneEdit = (EditText) findViewById(R.id.phoneEdit);
mPhoneEdit.setText(mUser.getPhone());
mOldPwdEdit = (EditText) findViewById(R.id.oldPwdEdit);
mNewPwdEdit = (EditText) findViewById(R.id.newPwdEdit);
mRePwdEdit = (EditText) findViewById(R.id.rePwdEdit);
Button okButton = (Button) findViewById(R.id.okButton);
okButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
if (!mNewPwdEdit.getText().toString().trim()
.equals(mRePwdEdit.getText().toString().trim())) {
Toast.makeText(PrivateActivity.this, "两次密码不一致",
Toast.LENGTH_SHORT).show();
return;
}
String[] as = new String[4];
as[0] = mPhoneEdit.getText().toString();
as[1] = mOldPwdEdit.getText().toString();
as[2] = mNewPwdEdit.getText().toString();
as[3] = mRePwdEdit.getText().toString();
new UpdateTask().execute(as);
}
});
}
protected void onCreate(Bundle paramBundle) {
super.onCreate(paramBundle);
setContentView(R.layout.private_activity);
this.mUser = ((TuanTrip) getApplication()).getUser();
ensureUi();
}
class UpdateTask extends AsyncTask<String, Void, BaseResult> {
private static final boolean DEBUG = TuanTripSettings.DEBUG;
private static final String TAG = "UpdateTask";
private Exception mReason = null;
private UpdateTask() {
}
protected BaseResult doInBackground(String... paramArray) {
if (DEBUG)
Log.d(TAG, "doInBackground()");
BaseResult baseResult = null;
try {
TuanTrip tuanTrip = (TuanTrip) PrivateActivity.this
.getApplication();
TuanTripApp tuanTripApp = tuanTrip.getTuanTripApp();
baseResult = tuanTripApp.updateUser(paramArray);
} catch (Exception localException) {
if (DEBUG)
Log.d(TAG, "Caught Exception.", localException);
this.mReason = localException;
baseResult = null;
}
return baseResult;
}
protected void onCancelled() {
super.onCancelled();
dismissProgressDialog();
}
protected void onPostExecute(BaseResult baseResult) {
if (DEBUG)
Log.d(TAG, "onPostExecute(): ");
onUpdateTaskComplete(baseResult, this.mReason);
}
protected void onPreExecute() {
if (DEBUG)
Log.d(TAG, "onPreExecute()");
startProgressBar("提交资料", "提交中...");
}
}
}