|
@ -8,7 +8,9 @@ import android.content.Intent;
|
8
|
8
|
import android.database.Cursor;
|
9
|
9
|
import android.os.Bundle;
|
10
|
10
|
import android.os.Handler;
|
|
11
|
|
11
|
12
|
import androidx.appcompat.app.AlertDialog;
|
|
13
|
|
12
|
14
|
import android.text.Editable;
|
13
|
15
|
import android.text.TextUtils;
|
14
|
16
|
import android.text.TextWatcher;
|
|
@ -61,7 +63,7 @@ public class SearchActivity extends Activity implements OnClickListener, Inputti
|
61
|
63
|
private TextView tvSearch;
|
62
|
64
|
private Toast toast = null;
|
63
|
65
|
private EditText etSearch;
|
64
|
|
private ImageView ivClear, iv_clear_address;
|
|
66
|
private ImageView ivClear;
|
65
|
67
|
private ListView lvContent;
|
66
|
68
|
private SearchAdapter adapter;
|
67
|
69
|
private List<Map<String, String>> list = new ArrayList<Map<String, String>>();
|
|
@ -71,14 +73,12 @@ public class SearchActivity extends Activity implements OnClickListener, Inputti
|
71
|
73
|
private HistoryInfo history;
|
72
|
74
|
|
73
|
75
|
private Map<String, String> map;
|
74
|
|
private Map<String, String> history_map;
|
75
|
76
|
|
76
|
77
|
private View convertView = null;
|
77
|
78
|
|
78
|
79
|
private boolean stype = true;
|
79
|
80
|
InputMethodManager imm;
|
80
|
|
private LinearLayout ll_menu, ll_address, ll_zhan;
|
81
|
|
private TextView searchZhan, searchAddress;
|
|
81
|
private LinearLayout ll_menu;
|
82
|
82
|
ListView historyList;
|
83
|
83
|
private PoiResult poiResult;// poi返回的结果
|
84
|
84
|
private int currentPage = 0;// 当前页面,从0开始计数
|
|
@ -93,27 +93,8 @@ public class SearchActivity extends Activity implements OnClickListener, Inputti
|
93
|
93
|
super.onCreate(savedInstanceState);
|
94
|
94
|
setContentView(R.layout.activity_search);
|
95
|
95
|
BarColorUtil.initStatusBarColor(SearchActivity.this);
|
96
|
|
|
97
|
|
// String jing = "116.63800787798";
|
98
|
|
// String wei = "39.896712151452";
|
99
|
|
// int position_jing = jing.length() - jing.indexOf(".") - 1;
|
100
|
|
// int position_wei = wei.length() - wei.indexOf(".") - 1;
|
101
|
|
// Log.e("1111",position_jing+"------"+position_wei);
|
102
|
|
// requestManager = PoCRequestManager.from(this);
|
103
|
|
// mPoiSearch = PoiSearch.newInstance();
|
104
|
|
// mPoiSearch.setOnGetPoiSearchResultListener(this);
|
105
|
96
|
stype = getIntent().getBooleanExtra("searchtype", true);
|
106
|
97
|
initView();
|
107
|
|
// Test(23.3456001);
|
108
|
|
}
|
109
|
|
|
110
|
|
private void Test(double d) {
|
111
|
|
|
112
|
|
String s = String.valueOf(d);
|
113
|
|
|
114
|
|
s = s.substring(s.indexOf('.') + 1);
|
115
|
|
|
116
|
|
Log.e("int===", s.length() + "");
|
117
|
98
|
}
|
118
|
99
|
|
119
|
100
|
private void initView() {
|
|
@ -123,28 +104,12 @@ public class SearchActivity extends Activity implements OnClickListener, Inputti
|
123
|
104
|
tvSearch.setOnClickListener(this);
|
124
|
105
|
ivClear = (ImageView) findViewById(R.id.iv_search_clear);
|
125
|
106
|
ivClear.setOnClickListener(this);
|
126
|
|
// ll_menu = (LinearLayout) findViewById(R.id.ll_menu);
|
127
|
|
// ll_address = (LinearLayout) findViewById(R.id.ll_address);
|
128
|
|
// ll_address.setOnClickListener(this);
|
129
|
|
// ll_zhan = (LinearLayout) findViewById(R.id.ll_zhan);
|
130
|
|
// ll_zhan.setOnClickListener(this);
|
131
|
|
// searchAddress = (TextView) findViewById(R.id.address_search);
|
132
|
|
//
|
133
|
|
// searchZhan = (TextView) findViewById(R.id.zhan_search);
|
134
|
107
|
|
135
|
108
|
etSearch = (EditText) findViewById(R.id.et_search);
|
136
|
|
// if (stype) {
|
137
|
|
// etSearch.setHint("输入想查找的位置");
|
138
|
|
// } else {
|
139
|
|
// etSearch.setHint("输入想查找的站名");
|
140
|
|
// }
|
141
|
109
|
etSearch.setOnClickListener(new OnClickListener() {
|
142
|
110
|
@Override
|
143
|
111
|
public void onClick(View v) {
|
144
|
112
|
|
145
|
|
// if (!TextUtils.isEmpty(etSearch.getText().toString().trim())) {
|
146
|
|
// ll_menu.setVisibility(View.VISIBLE);
|
147
|
|
// }
|
148
|
113
|
DBOpenHandler db = new DBOpenHandler(SearchActivity.this, "");
|
149
|
114
|
Cursor c = db.query();
|
150
|
115
|
System.err.println(c.getCount());
|
|
@ -158,65 +123,51 @@ public class SearchActivity extends Activity implements OnClickListener, Inputti
|
158
|
123
|
hList.clear();
|
159
|
124
|
while (c.moveToNext()) {
|
160
|
125
|
history = new HistoryInfo();
|
161
|
|
history.setIds(c.getString(c
|
162
|
|
.getColumnIndex("keyword")));
|
163
|
|
// Log.e("11111111",c.getString(c
|
164
|
|
// .getColumnIndex("keyword")));
|
165
|
|
history.setJing(c.getString(c
|
166
|
|
.getColumnIndex("jing")));
|
167
|
|
history.setWei(c.getString(c
|
168
|
|
.getColumnIndex("wei")));
|
|
126
|
history.setIds(c.getString(c.getColumnIndex("keyword")));
|
|
127
|
history.setJing(c.getString(c.getColumnIndex("jing")));
|
|
128
|
history.setWei(c.getString(c.getColumnIndex("wei")));
|
169
|
129
|
hList.add(history);
|
170
|
130
|
}
|
171
|
131
|
|
172
|
|
|
173
|
132
|
SimpleCursorAdapter adapter = new SimpleCursorAdapter(SearchActivity.this, R.layout.history_item, c, from, to);
|
174
|
133
|
historyList.setAdapter(adapter);
|
175
|
|
|
176
|
134
|
}
|
177
|
135
|
});
|
178
|
136
|
etSearch.setOnEditorActionListener(new TextView.OnEditorActionListener() {
|
179
|
137
|
@Override
|
180
|
138
|
public boolean onEditorAction(TextView textView, int i, KeyEvent keyEvent) {
|
181
|
|
// searchInPoi();
|
182
|
|
// ll_menu.setVisibility(View.GONE);
|
183
|
139
|
imm.hideSoftInputFromWindow(etSearch.getWindowToken(), 0);
|
184
|
|
|
185
|
140
|
return true;
|
186
|
141
|
}
|
187
|
142
|
});
|
188
|
143
|
etSearch.addTextChangedListener(new TextWatcher() {
|
189
|
144
|
@Override
|
190
|
145
|
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
|
191
|
|
|
192
|
146
|
}
|
193
|
147
|
|
194
|
148
|
@Override
|
195
|
149
|
public void onTextChanged(CharSequence s, int start, int before, int count) {
|
196
|
150
|
String newText = s.toString().trim();
|
197
|
|
Log.e("newText", newText);
|
198
|
|
if (!TextUtils.isEmpty(etSearch.getText().toString().trim())) {
|
|
151
|
if (!TextUtils.isEmpty(newText)) {
|
199
|
152
|
keyWord = newText;
|
200
|
153
|
doSearchQuery();
|
201
|
154
|
lvContent.setVisibility(View.VISIBLE);
|
202
|
155
|
historyList.setVisibility(View.GONE);
|
|
156
|
ivClear.setVisibility(View.VISIBLE);
|
203
|
157
|
} else {
|
204
|
158
|
list.clear();
|
205
|
159
|
mList.clear();
|
206
|
160
|
historyList.setVisibility(View.VISIBLE);
|
207
|
161
|
lvContent.setVisibility(View.GONE);
|
208
|
|
Log.e("444", "444");
|
|
162
|
ivClear.setVisibility(View.GONE);
|
209
|
163
|
}
|
210
|
|
|
211
|
164
|
}
|
212
|
165
|
|
213
|
166
|
@Override
|
214
|
167
|
public void afterTextChanged(Editable s) {
|
215
|
|
|
216
|
168
|
}
|
217
|
169
|
});
|
218
|
170
|
etSearch.setOnKeyListener(new OnKeyListener() {
|
219
|
|
|
220
|
171
|
@Override
|
221
|
172
|
public boolean onKey(View v, int keyCode, KeyEvent event) {
|
222
|
173
|
if (keyCode == KeyEvent.KEYCODE_ENTER
|
|
@ -225,9 +176,7 @@ public class SearchActivity extends Activity implements OnClickListener, Inputti
|
225
|
176
|
if (imm.isActive()) {
|
226
|
177
|
View view = getWindow().peekDecorView();
|
227
|
178
|
if (view != null) {
|
228
|
|
imm.hideSoftInputFromWindow(view.getWindowToken(),
|
229
|
|
0);
|
230
|
|
// ll_menu.setVisibility(View.GONE);
|
|
179
|
imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
|
231
|
180
|
}
|
232
|
181
|
}
|
233
|
182
|
if (TextUtils.isEmpty(etSearch.getText().toString().trim())) {
|
|
@ -263,7 +212,6 @@ public class SearchActivity extends Activity implements OnClickListener, Inputti
|
263
|
212
|
|
264
|
213
|
@Override
|
265
|
214
|
public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
|
266
|
|
// imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
|
267
|
215
|
}
|
268
|
216
|
});
|
269
|
217
|
historyList.setOnScrollListener(new AbsListView.OnScrollListener() {
|
|
@ -290,7 +238,6 @@ public class SearchActivity extends Activity implements OnClickListener, Inputti
|
290
|
238
|
intent.putExtra("zhan_name", hList.get(position).getIds());
|
291
|
239
|
intent.putExtra("jing", hList.get(position).getJing());
|
292
|
240
|
intent.putExtra("wei", hList.get(position).getWei());
|
293
|
|
// Log.e("2222",hList.get(position).getKeyword());
|
294
|
241
|
ProfileManager.getInstance().setSearchAddress(getApplicationContext(), hList.get(position).getIds());
|
295
|
242
|
setResult(101, intent);
|
296
|
243
|
finish();
|
|
@ -299,7 +246,6 @@ public class SearchActivity extends Activity implements OnClickListener, Inputti
|
299
|
246
|
if (v != null) {
|
300
|
247
|
imm.hideSoftInputFromWindow(v.getWindowToken(), 0);
|
301
|
248
|
}
|
302
|
|
// MainMapActivity.search_back = true;
|
303
|
249
|
}
|
304
|
250
|
});
|
305
|
251
|
|
|
@ -317,10 +263,8 @@ public class SearchActivity extends Activity implements OnClickListener, Inputti
|
317
|
263
|
values.put("type", list.get(position).get("address"));
|
318
|
264
|
values.put("jing", list.get(position).get("jing"));
|
319
|
265
|
values.put("wei", list.get(position).get("wei"));
|
320
|
|
|
321
|
266
|
db.insert(values);
|
322
|
267
|
|
323
|
|
|
324
|
268
|
Cursor c = db.query();
|
325
|
269
|
System.err.println(c.getCount());
|
326
|
270
|
if (c.getCount() <= 0) {
|
|
@ -328,15 +272,12 @@ public class SearchActivity extends Activity implements OnClickListener, Inputti
|
328
|
272
|
}
|
329
|
273
|
String[] from = {"keyword", "type"};
|
330
|
274
|
int[] to = {R.id.search_name, R.id.search_address};
|
331
|
|
SimpleCursorAdapter historyAdapter = new SimpleCursorAdapter(SearchActivity.this, R.layout.history_item, c, from, to);
|
|
275
|
SimpleCursorAdapter historyAdapter = new SimpleCursorAdapter(SearchActivity.this, R.layout.history_item, c, from, to, 0);
|
332
|
276
|
historyList.setAdapter(historyAdapter);
|
333
|
277
|
Intent intent = new Intent();
|
334
|
278
|
intent.putExtra("zhan_name", list.get(position).get("name"));
|
335
|
279
|
intent.putExtra("jing", list.get(position).get("jing"));
|
336
|
280
|
intent.putExtra("wei", list.get(position).get("wei"));
|
337
|
|
Log.e("jing", list.get(position).get("jing"));
|
338
|
|
Log.e("zhan_name", list.get(position).get("name"));
|
339
|
|
Log.e("wei", list.get(position).get("wei"));
|
340
|
281
|
ProfileManager.getInstance().setSearchAddress(getApplicationContext(), list.get(position).get("name"));
|
341
|
282
|
setResult(101, intent);
|
342
|
283
|
View v = getWindow().peekDecorView();
|
|
@ -376,38 +317,15 @@ public class SearchActivity extends Activity implements OnClickListener, Inputti
|
376
|
317
|
hList.clear();
|
377
|
318
|
while (c.moveToNext()) {
|
378
|
319
|
history = new HistoryInfo();
|
379
|
|
history.setIds(c.getString(c
|
380
|
|
.getColumnIndex("keyword")));
|
381
|
|
history.setJing(c.getString(c
|
382
|
|
.getColumnIndex("jing")));
|
383
|
|
history.setWei(c.getString(c
|
384
|
|
.getColumnIndex("wei")));
|
|
320
|
history.setIds(c.getString(c.getColumnIndex("keyword")));
|
|
321
|
history.setJing(c.getString(c.getColumnIndex("jing")));
|
|
322
|
history.setWei(c.getString(c.getColumnIndex("wei")));
|
385
|
323
|
hList.add(history);
|
386
|
324
|
}
|
387
|
325
|
|
388
|
|
for (int i = 0; i < hList.size(); i++) {
|
389
|
|
Log.e(i + "==", hList.get(i).getIds());
|
390
|
|
}
|
391
|
|
|
392
|
326
|
String[] from = {"keyword", "type"};
|
393
|
327
|
int[] to = {R.id.search_name, R.id.search_address};
|
394
|
|
final SimpleCursorAdapter adapter3 = new SimpleCursorAdapter(SearchActivity.this, R.layout.history_item, c, from, to);
|
395
|
|
// TextView footview = new TextView(this);
|
396
|
|
// footview.setText("清楚历史记录");
|
397
|
|
// footview.setHeight();
|
398
|
|
// LinearLayout.LayoutParams mLayoutParams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,
|
399
|
|
// LinearLayout.LayoutParams.WRAP_CONTENT);
|
400
|
|
// LinearLayout layout = new LinearLayout(this);
|
401
|
|
// //设置布局水平方向
|
402
|
|
// layout.setOrientation(LinearLayout.HORIZONTAL);
|
403
|
|
// //文本内容
|
404
|
|
// TextView footview = new TextView(this);
|
405
|
|
// footview.setText("清楚历史记录");
|
406
|
|
// footview.setGravity(Gravity.CENTER_VERTICAL);
|
407
|
|
// //把文本加入到layout中
|
408
|
|
// layout.addView(footview, mLayoutParams);
|
409
|
|
// //设置layout的重力方向,即对齐方式是
|
410
|
|
// layout.setGravity(Gravity.CENTER);
|
|
328
|
final SimpleCursorAdapter adapter3 = new SimpleCursorAdapter(SearchActivity.this, R.layout.history_item, c, from, to, 0);
|
411
|
329
|
|
412
|
330
|
convertView = LayoutInflater.from(getApplicationContext()).inflate(R.layout.item_clear, null);
|
413
|
331
|
historyList.addFooterView(convertView);
|
|
@ -430,77 +348,11 @@ public class SearchActivity extends Activity implements OnClickListener, Inputti
|
430
|
348
|
});
|
431
|
349
|
builder.setNegativeButton("取消", null);
|
432
|
350
|
builder.create().show();
|
433
|
|
|
434
|
351
|
}
|
435
|
352
|
});
|
436
|
353
|
historyList.setAdapter(adapter3);
|
437
|
|
|
438
|
|
|
439
|
354
|
}
|
440
|
355
|
|
441
|
|
// private void searchInPoi() {
|
442
|
|
// lvContent.setVisibility(View.VISIBLE);
|
443
|
|
// historyList.setVisibility(View.GONE);
|
444
|
|
// String search = etSearch.getText().toString().trim();
|
445
|
|
// if (MainFragment.center != null) {
|
446
|
|
//// mPoiSearch.searchNearby((new PoiNearbySearchOption())z
|
447
|
|
//// .location(MainFragment.center).keyword(search)
|
448
|
|
//// .pageCapacity(20).pageNum(0).radius(10000));
|
449
|
|
// mPoiSearch.searchInCity(new PoiCitySearchOption().city(MainApplication.atCity).keyword(search).pageCapacity(20).pageNum(0));
|
450
|
|
//
|
451
|
|
// }
|
452
|
|
// }
|
453
|
|
|
454
|
|
|
455
|
|
// @Override
|
456
|
|
// public void onRequestFinished(int resultCode, Bundle payload) {
|
457
|
|
// int flag = payload.getInt(PoCService.INTENT_EXTRA_WORKER_TYPE);
|
458
|
|
// switch (flag) {
|
459
|
|
// case PoCRequestManager.CHARGING_WORE_TYPE_GET_ZHAN_SEARCH:
|
460
|
|
// Gson g = new Gson();
|
461
|
|
// Type type = new TypeToken<List<Zhan>>() {
|
462
|
|
// }.getType();
|
463
|
|
// List<Zhan> l = g.fromJson(payload.getString("zhansearch"), type);
|
464
|
|
// list.clear();
|
465
|
|
// mList.clear();
|
466
|
|
// if (l != null && l.size() > 0) {
|
467
|
|
// for (int i = 0; i < l.size(); i++) {
|
468
|
|
// map = new HashMap<String, String>();
|
469
|
|
// map.put("name", l.get(i).getZhan_name());
|
470
|
|
// map.put("address", l.get(i).getZhan_address());
|
471
|
|
// map.put("jing", l.get(i).getPoi_jing() + "");
|
472
|
|
// map.put("wei", l.get(i).getPoi_wei() + "");
|
473
|
|
// map.put("url", l.get(i).getPic() + "");
|
474
|
|
// list.add(map);
|
475
|
|
// if (MainFragment.center != null) {
|
476
|
|
// double dwei = Double.parseDouble(l.get(i)
|
477
|
|
// .getPoi_wei());
|
478
|
|
// double djing = Double.parseDouble(l.get(i)
|
479
|
|
// .getPoi_jing());
|
480
|
|
// LatLng ll = new LatLng(dwei, djing);
|
481
|
|
// double d = DistanceUtil.getDistance(MainFragment.center, ll);
|
482
|
|
// l.get(i).setDistance(Util.getDistance(d));
|
483
|
|
// }
|
484
|
|
// mList.add(l.get(i));
|
485
|
|
//
|
486
|
|
// }
|
487
|
|
// Log.e("!!!",mList.size()+"");
|
488
|
|
// } else {
|
489
|
|
//
|
490
|
|
// Toast.makeText(SearchActivity.this, "抱歉,没有找到相关的信息",
|
491
|
|
// Toast.LENGTH_SHORT).show();
|
492
|
|
// }
|
493
|
|
// ll_menu.setVisibility(View.GONE);
|
494
|
|
// list.clear();
|
495
|
|
// mList.clear();
|
496
|
|
// adapter.notifyDataSetChanged();
|
497
|
|
// break;
|
498
|
|
//
|
499
|
|
// default:
|
500
|
|
// break;
|
501
|
|
// }
|
502
|
|
// }
|
503
|
|
|
504
|
356
|
@Override
|
505
|
357
|
public void onClick(View v) {
|
506
|
358
|
switch (v.getId()) {
|
|
@ -527,80 +379,14 @@ public class SearchActivity extends Activity implements OnClickListener, Inputti
|
527
|
379
|
|
528
|
380
|
//界面搜索框内清空图标
|
529
|
381
|
case R.id.iv_search_clear:
|
530
|
|
|
|
382
|
ivClear.setVisibility(View.GONE);
|
531
|
383
|
etSearch.setText("");
|
532
|
384
|
list.clear();
|
533
|
385
|
mList.clear();
|
534
|
386
|
adapter.notifyDataSetChanged();
|
535
|
387
|
lvContent.setVisibility(View.GONE);
|
536
|
388
|
historyList.setVisibility(View.VISIBLE);
|
537
|
|
// DBOpenHandler db = new DBOpenHandler(SearchActivity.this, "");
|
538
|
|
// Cursor c = db.query();
|
539
|
|
// System.err.println(c.getCount());
|
540
|
|
// if (c.getCount() <= 0) {
|
541
|
|
// return;
|
542
|
|
// }
|
543
|
|
//
|
544
|
|
//
|
545
|
|
// hList.clear();
|
546
|
|
// while (c.moveToNext()) {
|
547
|
|
// history = new HistoryInfo();
|
548
|
|
// history.setIds(c.getString(c
|
549
|
|
// .getColumnIndex("keyword")));
|
550
|
|
// history.setJing(c.getString(c
|
551
|
|
// .getColumnIndex("jing")));
|
552
|
|
// history.setWei(c.getString(c
|
553
|
|
// .getColumnIndex("wei")));
|
554
|
|
// hList.add(history);
|
555
|
|
// }
|
556
|
|
//
|
557
|
|
// String[] from = {"keyword", "type"};
|
558
|
|
// int[] to = {R.id.search_name, R.id.search_address};
|
559
|
|
// final SimpleCursorAdapter adapter3 = new SimpleCursorAdapter(SearchActivity.this, R.layout.history_item, c, from, to);
|
560
|
|
// convertView = LayoutInflater.from(getApplicationContext()).inflate(R.layout.item_clear, null);
|
561
|
|
// historyList.addFooterView(convertView);
|
562
|
|
// TextView tv_clear = (TextView) convertView.findViewById(R.id.tv_historyClear);
|
563
|
|
// tv_clear.setOnClickListener(new OnClickListener() {
|
564
|
|
// @Override
|
565
|
|
// public void onClick(View v) {
|
566
|
|
// new com.electric.chargingpile.view.AlertDialog(SearchActivity.this).builder()
|
567
|
|
// .setMsg("您确定要清空搜索历史吗?")
|
568
|
|
// .setPositiveButton("确定", new View.OnClickListener() {
|
569
|
|
// @Override
|
570
|
|
// public void onClick(View v) {
|
571
|
|
// DBOpenHandler db = new DBOpenHandler(SearchActivity.this, "");
|
572
|
|
// db.delTable();
|
573
|
|
// historyList.setVisibility(View.GONE);
|
574
|
|
// adapter3.notifyDataSetChanged();
|
575
|
|
// }
|
576
|
|
// }).setNegativeButton("取消", new View.OnClickListener() {
|
577
|
|
// @Override
|
578
|
|
// public void onClick(View v) {
|
579
|
|
//
|
580
|
|
//
|
581
|
|
// }
|
582
|
|
// }).show();
|
583
|
|
//
|
584
|
|
// }
|
585
|
|
// });
|
586
|
|
// historyList.setAdapter(adapter3);
|
587
|
|
// historyList.setVisibility(View.VISIBLE);
|
588
|
|
// lvContent.setVisibility(View.GONE);
|
589
|
|
// ll_menu.setVisibility(View.GONE);
|
590
|
|
|
591
|
389
|
break;
|
592
|
|
//按地点搜索
|
593
|
|
// case R.id.ll_address:
|
594
|
|
// searchInPoi();
|
595
|
|
// ll_menu.setVisibility(View.GONE);
|
596
|
|
// imm.hideSoftInputFromWindow(v.getWindowToken(), 0);
|
597
|
|
// break;
|
598
|
|
// //按站点搜索
|
599
|
|
// case R.id.ll_zhan:
|
600
|
|
// getSearchZhan();
|
601
|
|
// ll_menu.setVisibility(View.GONE);
|
602
|
|
// imm.hideSoftInputFromWindow(v.getWindowToken(), 0);
|
603
|
|
// break;
|
604
|
390
|
}
|
605
|
391
|
}
|
606
|
392
|
|
|
@ -626,9 +412,7 @@ public class SearchActivity extends Activity implements OnClickListener, Inputti
|
626
|
412
|
poiResult = result;
|
627
|
413
|
// 取得搜索到的poiitems有多少页
|
628
|
414
|
List<PoiItem> mList = poiResult.getPois();// 取得第一页的poiitem数据,页数从数字0开始
|
629
|
|
// List<PoiItem> mList = result.getAllPoi();
|
630
|
|
List<SuggestionCity> suggestionCities = poiResult
|
631
|
|
.getSearchSuggestionCitys();// 当搜索不到poiitem数据时,会返回含有搜索关键字的城市信息
|
|
415
|
List<SuggestionCity> suggestionCities = poiResult.getSearchSuggestionCitys();// 当搜索不到poiitem数据时,会返回含有搜索关键字的城市信息
|
632
|
416
|
|
633
|
417
|
if (mList != null && mList.size() > 0) {
|
634
|
418
|
list.clear();
|
|
@ -647,48 +431,26 @@ public class SearchActivity extends Activity implements OnClickListener, Inputti
|
647
|
431
|
list.add(map);
|
648
|
432
|
}
|
649
|
433
|
if (list != null && list.size() > 0) {
|
650
|
|
|
651
|
|
|
652
|
434
|
runOnUiThread(new Runnable() {
|
653
|
435
|
@Override
|
654
|
436
|
public void run() {
|
655
|
437
|
adapter.notifyDataSetChanged();
|
656
|
438
|
}
|
657
|
439
|
});
|
658
|
|
|
659
|
|
|
660
|
440
|
}
|
661
|
441
|
|
662
|
442
|
} catch (Exception e) {
|
663
|
443
|
e.printStackTrace();
|
664
|
444
|
}
|
665
|
445
|
} else {
|
666
|
|
Toast.makeText(SearchActivity.this, "抱歉,未找到结果", Toast.LENGTH_SHORT)
|
667
|
|
.show();
|
|
446
|
Toast.makeText(SearchActivity.this, "抱歉,未找到结果", Toast.LENGTH_SHORT).show();
|
668
|
447
|
list.clear();
|
669
|
448
|
adapter.notifyDataSetChanged();
|
670
|
449
|
}
|
671
|
|
|
672
|
|
// if (poiItems != null && poiItems.size() > 0) {
|
673
|
|
//// aMap.clear();// 清理之前的图标
|
674
|
|
// PoiOverlay poiOverlay = new PoiOverlay(aMap, poiItems);
|
675
|
|
// poiOverlay.removeFromMap();
|
676
|
|
// poiOverlay.addToMap();
|
677
|
|
// poiOverlay.zoomToSpan();
|
678
|
|
// } else if (suggestionCities != null
|
679
|
|
// && suggestionCities.size() > 0) {
|
680
|
|
// showSuggestCity(suggestionCities);
|
681
|
|
// } else {
|
682
|
|
//// ToastUtil.show(PoiKeywordSearchActivity.this,
|
683
|
|
//// R.string.no_result);
|
684
|
|
// }
|
685
|
450
|
}
|
686
|
451
|
} else {
|
687
|
|
// ToastUtil.show(PoiKeywordSearchActivity.this,
|
688
|
|
// R.string.no_result);
|
689
|
452
|
}
|
690
|
453
|
} else {
|
691
|
|
// ToastUtil.showerror(this, rCode);
|
692
|
454
|
}
|
693
|
455
|
}
|
694
|
456
|
|
|
@ -725,15 +487,11 @@ public class SearchActivity extends Activity implements OnClickListener, Inputti
|
725
|
487
|
public View getView(int position, View convertView, ViewGroup parent) {
|
726
|
488
|
ViewHolder viewHolder = null;
|
727
|
489
|
if (convertView == null) {
|
728
|
|
convertView = LayoutInflater.from(context).inflate(
|
729
|
|
R.layout.item_search, null);
|
|
490
|
convertView = LayoutInflater.from(context).inflate(R.layout.item_search, null);
|
730
|
491
|
viewHolder = new ViewHolder();
|
731
|
|
viewHolder.name = (TextView) convertView
|
732
|
|
.findViewById(R.id.search_name);
|
733
|
|
viewHolder.address = (TextView) convertView
|
734
|
|
.findViewById(R.id.search_address);
|
735
|
|
viewHolder.zhan = (ImageView) convertView
|
736
|
|
.findViewById(R.id.search_zhan);
|
|
492
|
viewHolder.name = (TextView) convertView.findViewById(R.id.search_name);
|
|
493
|
viewHolder.address = (TextView) convertView.findViewById(R.id.search_address);
|
|
494
|
viewHolder.zhan = (ImageView) convertView.findViewById(R.id.search_zhan);
|
737
|
495
|
convertView.setTag(viewHolder);
|
738
|
496
|
} else {
|
739
|
497
|
viewHolder = (ViewHolder) convertView.getTag();
|
|
@ -746,9 +504,7 @@ public class SearchActivity extends Activity implements OnClickListener, Inputti
|
746
|
504
|
} else {
|
747
|
505
|
viewHolder.zhan.setVisibility(View.VISIBLE);
|
748
|
506
|
if (!TextUtils.isEmpty(list.get(position).get("url"))) {
|
749
|
|
ImageLoader.getInstance().init(
|
750
|
|
ImageLoaderConfiguration
|
751
|
|
.createDefault(SearchActivity.this));
|
|
507
|
ImageLoader.getInstance().init(ImageLoaderConfiguration.createDefault(SearchActivity.this));
|
752
|
508
|
DisplayImageOptions.Builder builder = new DisplayImageOptions.Builder();
|
753
|
509
|
builder.cacheInMemory(true);
|
754
|
510
|
builder.cacheOnDisc(true);
|
|
@ -756,9 +512,7 @@ public class SearchActivity extends Activity implements OnClickListener, Inputti
|
756
|
512
|
builder.showImageForEmptyUri(R.drawable.image_default);
|
757
|
513
|
builder.showImageOnFail(R.drawable.image_default);
|
758
|
514
|
builder.displayer(new RoundedBitmapDisplayer(0));
|
759
|
|
ImageLoader.getInstance().displayImage(
|
760
|
|
list.get(position).get("url"), viewHolder.zhan,
|
761
|
|
builder.build());
|
|
515
|
ImageLoader.getInstance().displayImage(list.get(position).get("url"), viewHolder.zhan, builder.build());
|
762
|
516
|
} else {
|
763
|
517
|
viewHolder.zhan.setImageResource(R.drawable.image_default);
|
764
|
518
|
}
|
|
@ -772,54 +526,6 @@ public class SearchActivity extends Activity implements OnClickListener, Inputti
|
772
|
526
|
}
|
773
|
527
|
}
|
774
|
528
|
|
775
|
|
// @Override
|
776
|
|
// public void onGetPoiDetailResult(PoiDetailResult result) {
|
777
|
|
// if (result.error != SearchResult.ERRORNO.NO_ERROR) {
|
778
|
|
// Toast.makeText(SearchActivity.this, "抱歉,未找到结果", Toast.LENGTH_SHORT)
|
779
|
|
// .show();
|
780
|
|
// }
|
781
|
|
// }
|
782
|
|
|
783
|
|
// @Override
|
784
|
|
// public void onGetPoiResult(PoiResult result) {
|
785
|
|
// if (result == null
|
786
|
|
// || result.error == SearchResult.ERRORNO.RESULT_NOT_FOUND) {
|
787
|
|
//// Toast.makeText(SearchActivity.this, "抱歉,没有搜到相关信息\n" +
|
788
|
|
//// "您可尝试切换城市搜索", Toast.LENGTH_LONG)
|
789
|
|
//// .show();
|
790
|
|
// showTextToast("抱歉,没有搜到相关信息\n" +
|
791
|
|
// "您可尝试切换城市搜索");
|
792
|
|
// list.clear();
|
793
|
|
// adapter.notifyDataSetChanged();
|
794
|
|
// return;
|
795
|
|
// }
|
796
|
|
// if (result.error == SearchResult.ERRORNO.NO_ERROR) {
|
797
|
|
// List<PoiInfo> mList = result.getAllPoi();
|
798
|
|
// if (mList != null && mList.size() > 0) {
|
799
|
|
// list.clear();
|
800
|
|
// try {
|
801
|
|
// for (int i = 0; i < mList.size(); i++) {
|
802
|
|
// map = new HashMap<String, String>();
|
803
|
|
// map.put("name", mList.get(i).name);
|
804
|
|
// map.put("address", mList.get(i).address);
|
805
|
|
// map.put("jing", mList.get(i).location.longitude + "");
|
806
|
|
// map.put("wei", mList.get(i).location.latitude + "");
|
807
|
|
// map.put("url", "");
|
808
|
|
// list.add(map);
|
809
|
|
// }
|
810
|
|
// adapter.notifyDataSetChanged();
|
811
|
|
// } catch (Exception e) {
|
812
|
|
// e.printStackTrace();
|
813
|
|
// }
|
814
|
|
// }else {
|
815
|
|
// Toast.makeText(SearchActivity.this, "抱歉,未找到结果", Toast.LENGTH_LONG)
|
816
|
|
// .show();
|
817
|
|
// }
|
818
|
|
//
|
819
|
|
// return;
|
820
|
|
// }
|
821
|
|
// }
|
822
|
|
|
823
|
529
|
@Override
|
824
|
530
|
protected void onPause() {
|
825
|
531
|
super.onPause();
|
|
@ -848,7 +554,6 @@ public class SearchActivity extends Activity implements OnClickListener, Inputti
|
848
|
554
|
* 开始进行poi搜索
|
849
|
555
|
*/
|
850
|
556
|
protected void doSearchQuery() {
|
851
|
|
// showProgressDialog();// 显示进度框
|
852
|
557
|
currentPage = 0;
|
853
|
558
|
query = new PoiSearch.Query(keyWord, "", MainApplication.atCity);// 第一个参数表示搜索字符串,第二个参数表示poi搜索类型,第三个参数表示poi搜索区域(空字符串代表全国)
|
854
|
559
|
query.setPageSize(10);// 设置每页最多返回多少条poiitem
|
|
@ -858,23 +563,4 @@ public class SearchActivity extends Activity implements OnClickListener, Inputti
|
858
|
563
|
poiSearch.setOnPoiSearchListener(this);
|
859
|
564
|
poiSearch.searchPOIAsyn();
|
860
|
565
|
}
|
861
|
|
|
862
|
|
|
863
|
|
// @Override
|
864
|
|
// public void onGetInputtips(List<Tip> tipList, int rCode) {
|
865
|
|
// if (rCode == 1000) {// 正确返回
|
866
|
|
// List<String> listString = new ArrayList<String>();
|
867
|
|
// for (int i = 0; i < tipList.size(); i++) {
|
868
|
|
// listString.add(tipList.get(i).getName());
|
869
|
|
// }
|
870
|
|
// ArrayAdapter<String> aAdapter = new ArrayAdapter<String>(
|
871
|
|
// getApplicationContext(),
|
872
|
|
// R.layout.route_inputs, listString);
|
873
|
|
// searchText.setAdapter(aAdapter);
|
874
|
|
// aAdapter.notifyDataSetChanged();
|
875
|
|
// } else {
|
876
|
|
//// ToastUtil.showerror(this, rCode);
|
877
|
|
// }
|
878
|
|
//
|
879
|
|
// }
|
880
|
566
|
}
|