Browse Source

地址搜索修改

huyuguo 4 years ago
parent
commit
71aeae060b

+ 25 - 339
app/src/main/java/com/electric/chargingpile/activity/SearchActivity.java

@ -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
}

+ 32 - 54
app/src/main/res/layout/activity_search.xml

@ -1,5 +1,6 @@
1 1
<?xml version="1.0" encoding="utf-8"?>
2 2
<com.zhy.autolayout.AutoLinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
3
    xmlns:tools="http://schemas.android.com/tools"
3 4
    android:layout_width="match_parent"
4 5
    android:layout_height="match_parent"
5 6
    android:background="@color/activity_bgcolor"
@ -14,11 +15,11 @@
14 15
        <RelativeLayout
15 16
            android:layout_width="0dp"
16 17
            android:layout_height="match_parent"
17
            android:layout_weight="5"
18
            android:layout_marginLeft="16dp"
18 19
            android:layout_marginTop="7dp"
19 20
            android:layout_marginBottom="7dp"
20
            android:background="@drawable/bg"
21
            android:layout_marginLeft="16dp">
21
            android:layout_weight="5"
22
            android:background="@drawable/bg">
22 23

23 24

24 25
            <EditText
@ -26,29 +27,29 @@
26 27
                android:layout_width="fill_parent"
27 28
                android:layout_height="match_parent"
28 29
                android:layout_alignParentTop="true"
29
                android:layout_toRightOf="@+id/iv_sou"
30
                android:background="#f1f1f1"
31 30
                android:layout_marginTop="1dp"
31
                android:layout_marginRight="13dp"
32 32
                android:layout_marginBottom="1dp"
33
                android:hint="请输入要查找的地名"
33
                android:layout_toRightOf="@+id/iv_sou"
34
                android:background="#f1f1f1"
34 35
                android:focusable="true"
36
                android:hint="请输入要查找的地名"
35 37
                android:imeOptions="actionSearch"
36 38
                android:singleLine="true"
37 39
                android:textColorHint="@color/ui_68"
38 40
                android:textCursorDrawable="@drawable/search_biao"
39
                android:textSize="14sp"
40
                android:layout_marginRight="13dp" />
41
                android:textSize="14sp" />
41 42

42 43
            <ImageView
43 44
                android:id="@+id/iv_search_clear"
44 45
                android:layout_width="wrap_content"
45 46
                android:layout_height="wrap_content"
47
                android:layout_alignEnd="@+id/et_search"
48
                android:layout_alignRight="@+id/et_search"
49
                android:layout_centerVertical="true"
46 50
                android:contentDescription="@null"
47 51
                android:padding="5dp"
48
                android:src="@drawable/icon_edit_delete2_0"
49
                android:layout_centerVertical="true"
50
                android:layout_alignRight="@+id/et_search"
51
                android:layout_alignEnd="@+id/et_search" />
52
                android:src="@drawable/icon_edit_delete2_0" />
52 53

53 54
            <ImageView
54 55
                android:id="@+id/iv_sou"
@ -68,19 +69,19 @@
68 69
            android:layout_centerVertical="true"
69 70
            android:contentDescription="@null"
70 71
            android:gravity="center"
71
            android:paddingBottom="5dp"
72 72
            android:paddingLeft="16dp"
73
            android:paddingRight="16dp"
74 73
            android:paddingTop="5dp"
74
            android:paddingRight="16dp"
75
            android:paddingBottom="5dp"
75 76
            android:text="取消"
76 77
            android:textColor="@color/lvse"
77 78
            android:textSize="15sp" />
78 79

79 80
        <LinearLayout
80 81
            android:id="@+id/ll_menu"
81
            android:background="@color/white"
82 82
            android:layout_width="match_parent"
83 83
            android:layout_height="50dp"
84
            android:background="@color/white"
84 85

85 86
            android:orientation="vertical"
86 87
            android:visibility="gone">
@ -90,30 +91,31 @@
90 91
                android:layout_width="match_parent"
91 92
                android:layout_height="0dp"
92 93
                android:layout_weight="1">
94

93 95
                <ImageView
94 96
                    android:layout_width="0dp"
95 97
                    android:layout_height="match_parent"
96
                    android:padding="5dp"
97 98
                    android:layout_weight="1"
98
                    android:src="@drawable/icon_screening"/>
99
                    android:padding="5dp"
100
                    android:src="@drawable/icon_screening" />
99 101

100 102
                <TextView
101 103
                    android:id="@+id/address_search"
102 104
                    android:layout_width="0dp"
103 105
                    android:layout_height="match_parent"
104 106
                    android:layout_weight="6"
105
                    android:text="找地名:"
106 107
                    android:gravity="center_vertical"
107 108
                    android:paddingLeft="5dp"
108
                    android:textSize="18sp"
109
                    android:textColor="@color/text_light_grey"/>
109
                    android:text="找地名:"
110
                    android:textColor="@color/text_light_grey"
111
                    android:textSize="18sp" />
110 112
            </LinearLayout>
111 113

112 114
            <View
113 115
                android:layout_width="match_parent"
114 116
                android:layout_height="0.5dp"
115 117
                android:background="@color/title_line"
116
                android:visibility="gone"/>
118
                android:visibility="gone" />
117 119

118 120
            <LinearLayout
119 121
                android:id="@+id/ll_zhan"
@ -126,27 +128,28 @@
126 128
                    android:layout_height="match_parent"
127 129
                    android:layout_weight="1"
128 130
                    android:padding="5dp"
129
                    android:src="@drawable/icon_screening"/>
131
                    android:src="@drawable/icon_screening" />
132

130 133
                <TextView
131 134
                    android:id="@+id/zhan_search"
132 135
                    android:layout_width="0dp"
133 136
                    android:layout_height="match_parent"
134 137
                    android:layout_weight="6"
135
                    android:text="找电桩:"
136 138
                    android:gravity="center_vertical"
137 139
                    android:paddingLeft="5dp"
138
                    android:textSize="18sp"
139
                    android:textColor="@color/text_light_grey"/>
140

140
                    android:text="找电桩:"
141
                    android:textColor="@color/text_light_grey"
142
                    android:textSize="18sp" />
141 143
            </LinearLayout>
142 144
        </LinearLayout>
143 145

144 146
    </com.zhy.autolayout.AutoLinearLayout>
147

145 148
    <View
146 149
        android:layout_width="match_parent"
147 150
        android:layout_height="0.5dp"
148 151
        android:background="@color/ui_titleline"
149
        android:visibility="visible"/>
152
        android:visibility="visible" />
150 153

151 154
    <ListView
152 155
        android:id="@+id/lv_search_list"
@ -158,7 +161,7 @@
158 161
        android:divider="#dddddd"
159 162
        android:dividerHeight="0.5dp"
160 163
        android:fadingEdge="none"
161
        android:listSelector="@color/transparent"/>
164
        android:listSelector="@color/transparent" />
162 165

163 166
    <ListView
164 167
        android:id="@+id/lv_history_list"
@ -170,30 +173,5 @@
170 173
        android:divider="#dddddd"
171 174
        android:dividerHeight="0.5dp"
172 175
        android:fadingEdge="none"
173
        android:listSelector="@color/transparent"/>
174

175
    <!--<LinearLayout-->
176
    <!--android:id="@+id/ll_clear"-->
177
    <!--android:layout_width="match_parent"-->
178
    <!--android:layout_height="wrap_content"-->
179
    <!--android:orientation="vertical">-->
180

181
    <!--<View-->
182
    <!--android:layout_width="match_parent"-->
183
    <!--android:layout_height="0.5dp"-->
184
    <!--android:background="#dddddd"/>-->
185

186

187
    <!--<TextView-->
188
    <!--android:id="@+id/tv_historyClear"-->
189
    <!--android:layout_width="match_parent"-->
190
    <!--android:layout_height="45dp"-->
191
    <!--android:background="@color/white"-->
192
    <!--android:text="清除历史记录"-->
193
    <!--android:textColor="@color/hintColor"-->
194
    <!--android:gravity="center"-->
195
    <!--android:textSize="15sp"/>-->
196

197
    <!--</LinearLayout>-->
198

176
        android:listSelector="@color/transparent" />
199 177
</com.zhy.autolayout.AutoLinearLayout>

+ 6 - 6
app/src/main/res/layout/item_search.xml

@ -3,23 +3,23 @@
3 3
    android:layout_width="match_parent"
4 4
    android:layout_height="wrap_content"
5 5
    android:background="@color/white"
6
    android:orientation="vertical" >
6
    android:orientation="vertical">
7 7

8 8
    <RelativeLayout
9 9
        android:id="@+id/search_real"
10 10
        android:layout_width="wrap_content"
11
        android:layout_height="wrap_content" >
11
        android:layout_height="wrap_content">
12 12

13 13
        <ImageView
14 14
            android:id="@+id/search_image"
15 15
            android:layout_width="wrap_content"
16 16
            android:layout_height="wrap_content"
17 17
            android:layout_centerVertical="true"
18
            android:layout_marginLeft="16dp"
18 19
            android:contentDescription="@null"
19
            android:paddingRight="14dp"
20 20
            android:paddingTop="20dp"
21
            android:paddingRight="14dp"
21 22
            android:paddingBottom="20dp"
22
            android:layout_marginLeft="16dp"
23 23
            android:src="@drawable/icon_search1117" />
24 24

25 25
        <ImageView
@ -40,9 +40,9 @@
40 40
        android:layout_toRightOf="@id/search_real"
41 41
        android:gravity="center_vertical"
42 42
        android:orientation="vertical"
43
        android:paddingBottom="10dp"
43
        android:paddingTop="10dp"
44 44
        android:paddingRight="10dp"
45
        android:paddingTop="10dp" >
45
        android:paddingBottom="10dp">
46 46

47 47
        <TextView
48 48
            android:id="@+id/search_name"