-
Notifications
You must be signed in to change notification settings - Fork 1
/
SearchHBSKActivity.java
250 lines (212 loc) · 6.92 KB
/
SearchHBSKActivity.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
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
package com.tudaidai.tuantrip;
import android.app.Activity;
import android.app.Dialog;
import android.app.ProgressDialog;
import android.content.DialogInterface;
import android.content.DialogInterface.OnCancelListener;
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.TextView;
import android.widget.Toast;
import com.tudaidai.tuantrip.app.TuanTripApp;
import com.tudaidai.tuantrip.types.Cities;
import com.tudaidai.tuantrip.types.City;
import com.tudaidai.tuantrip.types.Group;
import com.tudaidai.tuantrip.util.NotificationsUtil;
public class SearchHBSKActivity extends Activity {
static final boolean DEBUG = TuanTripSettings.DEBUG;
static final String TAG = "SearchHBSKActivity";
TextView startCityEdit;
TextView endCityEdit;
static final int STARTCITY_DIALOG = 0;
static final int ENDCITY_DIALOG = 1;
private Group<City> mCities;
private int witchcity = 0;// 0是出发城市,1到达城市
protected ProgressDialog mProgressDialog;
protected void dismissProgressDialog() {
if (mProgressDialog != null)
mProgressDialog.dismiss();
}
protected void startProgressBar(String title, String content) {
// if(mProgressDialog==null)
mProgressDialog = ProgressDialog.show(this, title, content);
mProgressDialog.setCancelable(true);
mProgressDialog.show();
}
protected void onCreate(Bundle paramBundle) {
super.onCreate(paramBundle);
setContentView(R.layout.search_hbsk_activity);
startCityEdit = (TextView) findViewById(R.id.startCityEdit);
startCityEdit.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
witchcity = 0;
if (mCities == null || mCities.size() == 0) {
Void[] as1 = new Void[0];
new CitiesTask().execute(as1);
} else {
showDialog(STARTCITY_DIALOG);
}
}
});
endCityEdit = (TextView) findViewById(R.id.endCityEdit);
endCityEdit.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
witchcity = 1;
if (mCities == null || mCities.size() == 0) {
Void[] as1 = new Void[0];
new CitiesTask().execute(as1);
} else {
showDialog(ENDCITY_DIALOG);
}
}
});
Button okButton = (Button) findViewById(R.id.okButton);
okButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
if (startCityEdit.getText().toString().trim().equals("")) {
Toast.makeText(SearchHBSKActivity.this, "出发地不能为空",
Toast.LENGTH_SHORT).show();
return;
} else if (endCityEdit.getText().toString().trim().equals("")) {
Toast.makeText(SearchHBSKActivity.this, "目的地不能为空",
Toast.LENGTH_SHORT).show();
return;
}
String[] as = new String[2];
as[0] = startCityEdit.getText().toString().trim();
as[1] = endCityEdit.getText().toString().trim();
Intent intent = new Intent(SearchHBSKActivity.this,
HBSKActivity.class);
intent.putExtra(HBSKActivity.EXTRA_OPTION, as);
startActivity(intent);
}
});
TextView t1 = (TextView) findViewById(R.id.t1);
t1.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
getCity(v);
}
});
TextView t2 = (TextView) findViewById(R.id.t2);
t2.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
getCity(v);
}
});
TextView t3 = (TextView) findViewById(R.id.t3);
t3.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
getCity(v);
}
});
TextView t4 = (TextView) findViewById(R.id.t4);
t4.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
getCity(v);
}
});
}
@Override
protected Dialog onCreateDialog(int id) {
switch (id) {
case STARTCITY_DIALOG:
CityPickerDialog citydialog = new CityPickerDialog(this, mCities);
citydialog.setOnCancelListener(new OnCancelListener() {
@Override
public void onCancel(DialogInterface dialog) {
CityPickerDialog citypickerdialog = (CityPickerDialog) dialog;
String city1 = citypickerdialog.getChosenCityName();
if (!city1.equals("-1")) {
startCityEdit.setText(city1);
}
removeDialog(STARTCITY_DIALOG);
}
});
return citydialog;
case ENDCITY_DIALOG:
CityPickerDialog citydialog1 = new CityPickerDialog(this, mCities);
citydialog1.setOnCancelListener(new OnCancelListener() {
@Override
public void onCancel(DialogInterface dialog) {
CityPickerDialog citypickerdialog = (CityPickerDialog) dialog;
String city1 = citypickerdialog.getChosenCityName();
if (!city1.equals("-1")) {
endCityEdit.setText(city1);
}
removeDialog(ENDCITY_DIALOG);
}
});
return citydialog1;
}
return null;
}
class CitiesTask extends AsyncTask<Void, Void, Cities> {
private Exception mReason;
private CitiesTask() {
}
protected Cities doInBackground(Void... paramArrayOfVoid) {
if (DEBUG)
Log.d("CitiesTask", "doInBackground()");
TuanTrip localTuanTrip = (TuanTrip) SearchHBSKActivity.this
.getApplication();
TuanTripApp localTuanTripApp = localTuanTrip.getTuanTripApp();
Cities citys = null;
try {
citys = localTuanTripApp.getAirportCities();
} catch (Exception localException) {
this.mReason = localException;
citys = null;
}
return citys;
}
protected void onCancelled() {
super.onCancelled();
SearchHBSKActivity.this.dismissProgressDialog();
}
protected void onPostExecute(Cities paramCities) {
if (paramCities == null) {
NotificationsUtil.ToastReasonForFailure(
SearchHBSKActivity.this, mReason);
} else if (paramCities.mHttpResult.getStat() == TuanTripSettings.POSTSUCCESS) {
mCities = paramCities.mCities;
if (mCities != null && mCities.size() != 0) {
if (witchcity == 0) {
showDialog(STARTCITY_DIALOG);
} else {
showDialog(ENDCITY_DIALOG);
}
}
} else if (paramCities.mHttpResult.getStat() == TuanTripSettings.POSTFAILED) {
Toast.makeText(SearchHBSKActivity.this,
paramCities.mHttpResult.getMessage(),
Toast.LENGTH_SHORT).show();
} else {
NotificationsUtil.ToastReasonForFailure(
SearchHBSKActivity.this, mReason);
}
SearchHBSKActivity.this.dismissProgressDialog();
}
protected void onPreExecute() {
if (DEBUG)
Log.d("TodayActivity", "onPreExecute()");
startProgressBar("获取城市列表", "加载中...");
}
}
private void getCity(View v) {
String city = ((TextView) v).getText().toString();
startCityEdit.setText(city.split("-")[0]);
endCityEdit.setText(city.split("-")[1]);
}
}