|
package com.electric.chargingpile.activity;
import android.app.Activity;
import android.content.ContentValues;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.database.Cursor;
import android.os.Bundle;
import android.os.Handler;
import android.support.v7.app.AlertDialog;
import android.text.Editable;
import android.text.TextUtils;
import android.text.TextWatcher;
import android.util.Log;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.View.OnKeyListener;
import android.view.ViewGroup;
import android.view.inputmethod.InputMethodManager;
import android.widget.AbsListView;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.BaseAdapter;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.SimpleCursorAdapter;
import android.widget.TextView;
import android.widget.Toast;
import com.amap.api.services.core.PoiItem;
import com.amap.api.services.core.SuggestionCity;
import com.amap.api.services.help.Inputtips;
import com.amap.api.services.help.Tip;
import com.amap.api.services.poisearch.PoiResult;
import com.amap.api.services.poisearch.PoiSearch;
import com.amap.api.services.poisearch.PoiSearch.OnPoiSearchListener;
import com.electric.chargingpile.R;
import com.electric.chargingpile.application.MainApplication;
import com.electric.chargingpile.data.HistoryInfo;
import com.electric.chargingpile.data.Zhan;
import com.electric.chargingpile.manager.ProfileManager;
import com.electric.chargingpile.util.BarColorUtil;
import com.electric.chargingpile.util.DBOpenHandler;
import com.nostra13.universalimageloader.core.DisplayImageOptions;
import com.nostra13.universalimageloader.core.ImageLoader;
import com.nostra13.universalimageloader.core.ImageLoaderConfiguration;
import com.nostra13.universalimageloader.core.display.RoundedBitmapDisplayer;
import com.umeng.analytics.MobclickAgent;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class SearchActivity extends Activity implements OnClickListener, Inputtips.InputtipsListener, OnPoiSearchListener {
private TextView tvSearch;
private Toast toast = null;
private EditText etSearch;
private ImageView ivClear, iv_clear_address;
private ListView lvContent;
private SearchAdapter adapter;
private List<Map<String, String>> list = new ArrayList<Map<String, String>>();
private List<Map<String, String>> history_list = new ArrayList<Map<String, String>>();
private List<Zhan> mList = new ArrayList<Zhan>();
private List<HistoryInfo> hList = new ArrayList<HistoryInfo>();
private HistoryInfo history;
private Map<String, String> map;
private Map<String, String> history_map;
private View convertView = null;
private boolean stype = true;
InputMethodManager imm;
private LinearLayout ll_menu, ll_address, ll_zhan;
private TextView searchZhan, searchAddress;
ListView historyList;
private PoiResult poiResult;// poi返回的结果
private int currentPage = 0;// 当前页面,从0开始计数
private PoiSearch.Query query;// Poi查询条件类
private PoiSearch poiSearch;// POI搜索
private String keyWord = "";// 要输入的poi搜索关键字
private static final String TAG = "SearchActivity";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_search);
BarColorUtil.initStatusBarColor(SearchActivity.this);
// String jing = "116.63800787798";
// String wei = "39.896712151452";
// int position_jing = jing.length() - jing.indexOf(".") - 1;
// int position_wei = wei.length() - wei.indexOf(".") - 1;
// Log.e("1111",position_jing+"------"+position_wei);
// requestManager = PoCRequestManager.from(this);
// mPoiSearch = PoiSearch.newInstance();
// mPoiSearch.setOnGetPoiSearchResultListener(this);
stype = getIntent().getBooleanExtra("searchtype", true);
initView();
// Test(23.3456001);
}
private void Test(double d) {
String s = String.valueOf(d);
s = s.substring(s.indexOf('.') + 1);
Log.e("int===", s.length() + "");
}
private void initView() {
lvContent = (ListView) findViewById(R.id.lv_search_list);
historyList = (ListView) findViewById(R.id.lv_history_list);
tvSearch = (TextView) findViewById(R.id.tv_search);
tvSearch.setOnClickListener(this);
ivClear = (ImageView) findViewById(R.id.iv_search_clear);
ivClear.setOnClickListener(this);
// ll_menu = (LinearLayout) findViewById(R.id.ll_menu);
// ll_address = (LinearLayout) findViewById(R.id.ll_address);
// ll_address.setOnClickListener(this);
// ll_zhan = (LinearLayout) findViewById(R.id.ll_zhan);
// ll_zhan.setOnClickListener(this);
// searchAddress = (TextView) findViewById(R.id.address_search);
//
// searchZhan = (TextView) findViewById(R.id.zhan_search);
etSearch = (EditText) findViewById(R.id.et_search);
// if (stype) {
// etSearch.setHint("输入想查找的位置");
// } else {
// etSearch.setHint("输入想查找的站名");
// }
etSearch.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// if (!TextUtils.isEmpty(etSearch.getText().toString().trim())) {
// ll_menu.setVisibility(View.VISIBLE);
// }
DBOpenHandler db = new DBOpenHandler(SearchActivity.this, "");
Cursor c = db.query();
System.err.println(c.getCount());
if (c.getCount() <= 0) {
return;
}
String[] from = {"keyword", "type"};
int[] to = {R.id.search_name, R.id.search_address};
hList.clear();
while (c.moveToNext()) {
history = new HistoryInfo();
history.setIds(c.getString(c
.getColumnIndex("keyword")));
// Log.e("11111111",c.getString(c
// .getColumnIndex("keyword")));
history.setJing(c.getString(c
.getColumnIndex("jing")));
history.setWei(c.getString(c
.getColumnIndex("wei")));
hList.add(history);
}
SimpleCursorAdapter adapter = new SimpleCursorAdapter(SearchActivity.this, R.layout.history_item, c, from, to);
historyList.setAdapter(adapter);
}
});
etSearch.setOnEditorActionListener(new TextView.OnEditorActionListener() {
@Override
public boolean onEditorAction(TextView textView, int i, KeyEvent keyEvent) {
// searchInPoi();
// ll_menu.setVisibility(View.GONE);
imm.hideSoftInputFromWindow(etSearch.getWindowToken(), 0);
return true;
}
});
etSearch.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
String newText = s.toString().trim();
Log.e("newText", newText);
if (!TextUtils.isEmpty(etSearch.getText().toString().trim())) {
keyWord = newText;
doSearchQuery();
lvContent.setVisibility(View.VISIBLE);
historyList.setVisibility(View.GONE);
} else {
list.clear();
mList.clear();
historyList.setVisibility(View.VISIBLE);
lvContent.setVisibility(View.GONE);
Log.e("444", "444");
}
}
@Override
public void afterTextChanged(Editable s) {
}
});
etSearch.setOnKeyListener(new OnKeyListener() {
@Override
public boolean onKey(View v, int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_ENTER
&& event.getAction() == KeyEvent.ACTION_DOWN) { // 点击搜索键进行搜索。
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
if (imm.isActive()) {
View view = getWindow().peekDecorView();
if (view != null) {
imm.hideSoftInputFromWindow(view.getWindowToken(),
0);
// ll_menu.setVisibility(View.GONE);
}
}
if (TextUtils.isEmpty(etSearch.getText().toString().trim())) {
Toast.makeText(SearchActivity.this, "搜索内容不能为空",
Toast.LENGTH_SHORT).show();
} else {
}
return true;
}
return false;
}
});
String search_address = ProfileManager.getInstance().getSearchAddress(this);
Log.e("222", search_address);
if (search_address.equals("")) {
Log.e(TAG, "默认");
etSearch.setText("");
} else {
Log.e(TAG, search_address);
etSearch.setText(search_address);
etSearch.setSelection(etSearch.getText().length());
}
lvContent.setOnScrollListener(new AbsListView.OnScrollListener() {
@Override
public void onScrollStateChanged(AbsListView view, int scrollState) {
View v = getWindow().peekDecorView();
if (v != null) {
imm.hideSoftInputFromWindow(v.getWindowToken(), 0);
}
}
@Override
public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
// imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
}
});
historyList.setOnScrollListener(new AbsListView.OnScrollListener() {
@Override
public void onScrollStateChanged(AbsListView view, int scrollState) {
View v = getWindow().peekDecorView();
if (v != null) {
imm.hideSoftInputFromWindow(v.getWindowToken(), 0);
}
}
@Override
public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
}
});
adapter = new SearchAdapter(this, list);
lvContent.setAdapter(adapter);
historyList.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
Intent intent = new Intent();
intent.putExtra("zhan_name", hList.get(position).getIds());
intent.putExtra("jing", hList.get(position).getJing());
intent.putExtra("wei", hList.get(position).getWei());
// Log.e("2222",hList.get(position).getKeyword());
ProfileManager.getInstance().setSearchAddress(getApplicationContext(), hList.get(position).getIds());
setResult(101, intent);
finish();
View v = getWindow().peekDecorView();
if (v != null) {
imm.hideSoftInputFromWindow(v.getWindowToken(), 0);
}
// MainMapActivity.search_back = true;
}
});
lvContent.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
if (stype) {
DBOpenHandler db = new DBOpenHandler(SearchActivity.this, "");
db.queryOne(etSearch.getText().toString());
ContentValues values = new ContentValues();
values.put("time", System.currentTimeMillis());
values.put("keyword", list.get(position).get("name"));
values.put("type", list.get(position).get("address"));
values.put("jing", list.get(position).get("jing"));
values.put("wei", list.get(position).get("wei"));
db.insert(values);
Cursor c = db.query();
System.err.println(c.getCount());
if (c.getCount() <= 0) {
return;
}
String[] from = {"keyword", "type"};
int[] to = {R.id.search_name, R.id.search_address};
SimpleCursorAdapter historyAdapter = new SimpleCursorAdapter(SearchActivity.this, R.layout.history_item, c, from, to);
historyList.setAdapter(historyAdapter);
Intent intent = new Intent();
intent.putExtra("zhan_name", list.get(position).get("name"));
intent.putExtra("jing", list.get(position).get("jing"));
intent.putExtra("wei", list.get(position).get("wei"));
Log.e("jing", list.get(position).get("jing"));
Log.e("zhan_name", list.get(position).get("name"));
Log.e("wei", list.get(position).get("wei"));
ProfileManager.getInstance().setSearchAddress(getApplicationContext(), list.get(position).get("name"));
setResult(101, intent);
View v = getWindow().peekDecorView();
if (v != null) {
imm.hideSoftInputFromWindow(v.getWindowToken(), 0);
}
finish();
} else {
Intent intent = new Intent(SearchActivity.this,
ZhanDetailsNew.class);
intent.putExtra("zhan", mList.get(position));
startActivity(intent);
}
}
});
try {
imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
if (!imm.isActive()) {
ll_menu.setVisibility(View.GONE);
}
} catch (Exception e) {
e.printStackTrace();
}
if (search_address.equals("")) {
lvContent.setVisibility(View.GONE);
historyList.setVisibility(View.VISIBLE);
}
DBOpenHandler db = new DBOpenHandler(SearchActivity.this, "");
Cursor c = db.query();
System.err.println(c.getCount());
if (c.getCount() <= 0) {
return;
}
hList.clear();
while (c.moveToNext()) {
history = new HistoryInfo();
history.setIds(c.getString(c
.getColumnIndex("keyword")));
history.setJing(c.getString(c
.getColumnIndex("jing")));
history.setWei(c.getString(c
.getColumnIndex("wei")));
hList.add(history);
}
for (int i = 0; i < hList.size(); i++) {
Log.e(i + "==", hList.get(i).getIds());
}
String[] from = {"keyword", "type"};
int[] to = {R.id.search_name, R.id.search_address};
final SimpleCursorAdapter adapter3 = new SimpleCursorAdapter(SearchActivity.this, R.layout.history_item, c, from, to);
// TextView footview = new TextView(this);
// footview.setText("清楚历史记录");
// footview.setHeight();
// LinearLayout.LayoutParams mLayoutParams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,
// LinearLayout.LayoutParams.WRAP_CONTENT);
// LinearLayout layout = new LinearLayout(this);
// //设置布局水平方向
// layout.setOrientation(LinearLayout.HORIZONTAL);
// //文本内容
// TextView footview = new TextView(this);
// footview.setText("清楚历史记录");
// footview.setGravity(Gravity.CENTER_VERTICAL);
// //把文本加入到layout中
// layout.addView(footview, mLayoutParams);
// //设置layout的重力方向,即对齐方式是
// layout.setGravity(Gravity.CENTER);
convertView = LayoutInflater.from(getApplicationContext()).inflate(R.layout.item_clear, null);
historyList.addFooterView(convertView);
TextView tv_clear = (TextView) convertView.findViewById(R.id.tv_historyClear);
tv_clear.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
AlertDialog.Builder builder = new AlertDialog.Builder(SearchActivity.this);
builder.setTitle("提示");
builder.setMessage("确认删除历史记录?");
builder.setCancelable(false);
builder.setPositiveButton("确定", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
DBOpenHandler db = new DBOpenHandler(SearchActivity.this, "");
db.delTable();
historyList.setVisibility(View.GONE);
adapter3.notifyDataSetChanged();
}
});
builder.setNegativeButton("取消", null);
builder.create().show();
}
});
historyList.setAdapter(adapter3);
}
// private void searchInPoi() {
// lvContent.setVisibility(View.VISIBLE);
// historyList.setVisibility(View.GONE);
// String search = etSearch.getText().toString().trim();
// if (MainFragment.center != null) {
//// mPoiSearch.searchNearby((new PoiNearbySearchOption())z
//// .location(MainFragment.center).keyword(search)
//// .pageCapacity(20).pageNum(0).radius(10000));
// mPoiSearch.searchInCity(new PoiCitySearchOption().city(MainApplication.atCity).keyword(search).pageCapacity(20).pageNum(0));
//
// }
// }
// @Override
// public void onRequestFinished(int resultCode, Bundle payload) {
// int flag = payload.getInt(PoCService.INTENT_EXTRA_WORKER_TYPE);
// switch (flag) {
// case PoCRequestManager.CHARGING_WORE_TYPE_GET_ZHAN_SEARCH:
// Gson g = new Gson();
// Type type = new TypeToken<List<Zhan>>() {
// }.getType();
// List<Zhan> l = g.fromJson(payload.getString("zhansearch"), type);
// list.clear();
// mList.clear();
// if (l != null && l.size() > 0) {
// for (int i = 0; i < l.size(); i++) {
// map = new HashMap<String, String>();
// map.put("name", l.get(i).getZhan_name());
// map.put("address", l.get(i).getZhan_address());
// map.put("jing", l.get(i).getPoi_jing() + "");
// map.put("wei", l.get(i).getPoi_wei() + "");
// map.put("url", l.get(i).getPic() + "");
// list.add(map);
// if (MainFragment.center != null) {
// double dwei = Double.parseDouble(l.get(i)
// .getPoi_wei());
// double djing = Double.parseDouble(l.get(i)
// .getPoi_jing());
// LatLng ll = new LatLng(dwei, djing);
// double d = DistanceUtil.getDistance(MainFragment.center, ll);
// l.get(i).setDistance(Util.getDistance(d));
// }
// mList.add(l.get(i));
//
// }
// Log.e("!!!",mList.size()+"");
// } else {
//
// Toast.makeText(SearchActivity.this, "抱歉,没有找到相关的信息",
// Toast.LENGTH_SHORT).show();
// }
// ll_menu.setVisibility(View.GONE);
// list.clear();
// mList.clear();
// adapter.notifyDataSetChanged();
// break;
//
// default:
// break;
// }
// }
@Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.tv_search:
if (imm.isActive()) {
View view = getWindow().peekDecorView();
if (view != null) {
imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
}
}
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
if (MainMapActivity.ll_tuijian.getVisibility() == View.VISIBLE) {
MainMapActivity.ll_tuijian.setVisibility(View.GONE);
MainMapActivity.ll_map_control.setVisibility(View.VISIBLE);
MainMapActivity.ll_top_right.setVisibility(View.VISIBLE);
}
}
}, 500);
MainMapActivity.detailsBack = true;
finish();
break;
//界面搜索框内清空图标
case R.id.iv_search_clear:
etSearch.setText("");
list.clear();
mList.clear();
adapter.notifyDataSetChanged();
lvContent.setVisibility(View.GONE);
historyList.setVisibility(View.VISIBLE);
// DBOpenHandler db = new DBOpenHandler(SearchActivity.this, "");
// Cursor c = db.query();
// System.err.println(c.getCount());
// if (c.getCount() <= 0) {
// return;
// }
//
//
// hList.clear();
// while (c.moveToNext()) {
// history = new HistoryInfo();
// history.setIds(c.getString(c
// .getColumnIndex("keyword")));
// history.setJing(c.getString(c
// .getColumnIndex("jing")));
// history.setWei(c.getString(c
// .getColumnIndex("wei")));
// hList.add(history);
// }
//
// String[] from = {"keyword", "type"};
// int[] to = {R.id.search_name, R.id.search_address};
// final SimpleCursorAdapter adapter3 = new SimpleCursorAdapter(SearchActivity.this, R.layout.history_item, c, from, to);
// convertView = LayoutInflater.from(getApplicationContext()).inflate(R.layout.item_clear, null);
// historyList.addFooterView(convertView);
// TextView tv_clear = (TextView) convertView.findViewById(R.id.tv_historyClear);
// tv_clear.setOnClickListener(new OnClickListener() {
// @Override
// public void onClick(View v) {
// new com.electric.chargingpile.view.AlertDialog(SearchActivity.this).builder()
// .setMsg("您确定要清空搜索历史吗?")
// .setPositiveButton("确定", new View.OnClickListener() {
// @Override
// public void onClick(View v) {
// DBOpenHandler db = new DBOpenHandler(SearchActivity.this, "");
// db.delTable();
// historyList.setVisibility(View.GONE);
// adapter3.notifyDataSetChanged();
// }
// }).setNegativeButton("取消", new View.OnClickListener() {
// @Override
// public void onClick(View v) {
//
//
// }
// }).show();
//
// }
// });
// historyList.setAdapter(adapter3);
// historyList.setVisibility(View.VISIBLE);
// lvContent.setVisibility(View.GONE);
// ll_menu.setVisibility(View.GONE);
break;
//按地点搜索
// case R.id.ll_address:
// searchInPoi();
// ll_menu.setVisibility(View.GONE);
// imm.hideSoftInputFromWindow(v.getWindowToken(), 0);
// break;
// //按站点搜索
// case R.id.ll_zhan:
// getSearchZhan();
// ll_menu.setVisibility(View.GONE);
// imm.hideSoftInputFromWindow(v.getWindowToken(), 0);
// break;
}
}
private void showTextToast(String msg) {
if (toast == null) {
toast = Toast.makeText(getApplicationContext(), msg, Toast.LENGTH_SHORT);
} else {
toast.setText(msg);
}
toast.show();
}
@Override
public void onGetInputtips(List<Tip> list, int i) {
}
@Override
public void onPoiSearched(PoiResult result, int rCode) {
if (rCode == 1000) {
if (result != null && result.getQuery() != null) {// 搜索poi的结果
if (result.getQuery().equals(query)) {// 是否是同一条
poiResult = result;
// 取得搜索到的poiitems有多少页
List<PoiItem> mList = poiResult.getPois();// 取得第一页的poiitem数据,页数从数字0开始
// List<PoiItem> mList = result.getAllPoi();
List<SuggestionCity> suggestionCities = poiResult
.getSearchSuggestionCitys();// 当搜索不到poiitem数据时,会返回含有搜索关键字的城市信息
if (mList != null && mList.size() > 0) {
list.clear();
try {
for (int i = 0; i < mList.size(); i++) {
map = new HashMap<String, String>();
map.put("name", mList.get(i).getTitle());
Log.e("name", mList.get(i).getTitle());
map.put("address", mList.get(i).getSnippet());
Log.e("address", mList.get(i).getSnippet());
map.put("jing", mList.get(i).getLatLonPoint().getLongitude() + "");
Log.e("jing", mList.get(i).getLatLonPoint().getLongitude() + "");
map.put("wei", mList.get(i).getLatLonPoint().getLatitude() + "");
Log.e("wei", mList.get(i).getLatLonPoint().getLatitude() + "");
map.put("url", "");
list.add(map);
}
if (list != null && list.size() > 0) {
runOnUiThread(new Runnable() {
@Override
public void run() {
adapter.notifyDataSetChanged();
}
});
}
} catch (Exception e) {
e.printStackTrace();
}
} else {
Toast.makeText(SearchActivity.this, "抱歉,未找到结果", Toast.LENGTH_SHORT)
.show();
list.clear();
adapter.notifyDataSetChanged();
}
// if (poiItems != null && poiItems.size() > 0) {
//// aMap.clear();// 清理之前的图标
// PoiOverlay poiOverlay = new PoiOverlay(aMap, poiItems);
// poiOverlay.removeFromMap();
// poiOverlay.addToMap();
// poiOverlay.zoomToSpan();
// } else if (suggestionCities != null
// && suggestionCities.size() > 0) {
// showSuggestCity(suggestionCities);
// } else {
//// ToastUtil.show(PoiKeywordSearchActivity.this,
//// R.string.no_result);
// }
}
} else {
// ToastUtil.show(PoiKeywordSearchActivity.this,
// R.string.no_result);
}
} else {
// ToastUtil.showerror(this, rCode);
}
}
@Override
public void onPoiItemSearched(PoiItem poiItem, int i) {
}
public class SearchAdapter extends BaseAdapter {
private Context context;
private List<Map<String, String>> list;
public SearchAdapter(Context context, List<Map<String, String>> list) {
this.context = context;
this.list = list;
}
@Override
public int getCount() {
return list.size();
}
@Override
public Object getItem(int position) {
return list.get(position);
}
@Override
public long getItemId(int position) {
return position;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder viewHolder = null;
if (convertView == null) {
convertView = LayoutInflater.from(context).inflate(
R.layout.item_search, null);
viewHolder = new ViewHolder();
viewHolder.name = (TextView) convertView
.findViewById(R.id.search_name);
viewHolder.address = (TextView) convertView
.findViewById(R.id.search_address);
viewHolder.zhan = (ImageView) convertView
.findViewById(R.id.search_zhan);
convertView.setTag(viewHolder);
} else {
viewHolder = (ViewHolder) convertView.getTag();
}
viewHolder.name.setText(list.get(position).get("name"));
viewHolder.address.setText(list.get(position).get("address"));
if (stype) {
viewHolder.zhan.setVisibility(View.GONE);
} else {
viewHolder.zhan.setVisibility(View.VISIBLE);
if (!TextUtils.isEmpty(list.get(position).get("url"))) {
ImageLoader.getInstance().init(
ImageLoaderConfiguration
.createDefault(SearchActivity.this));
DisplayImageOptions.Builder builder = new DisplayImageOptions.Builder();
builder.cacheInMemory(true);
builder.cacheOnDisc(true);
builder.showStubImage(R.drawable.image_default);
builder.showImageForEmptyUri(R.drawable.image_default);
builder.showImageOnFail(R.drawable.image_default);
builder.displayer(new RoundedBitmapDisplayer(0));
ImageLoader.getInstance().displayImage(
list.get(position).get("url"), viewHolder.zhan,
builder.build());
} else {
viewHolder.zhan.setImageResource(R.drawable.image_default);
}
}
return convertView;
}
class ViewHolder {
TextView name, address;
ImageView zhan;
}
}
// @Override
// public void onGetPoiDetailResult(PoiDetailResult result) {
// if (result.error != SearchResult.ERRORNO.NO_ERROR) {
// Toast.makeText(SearchActivity.this, "抱歉,未找到结果", Toast.LENGTH_SHORT)
// .show();
// }
// }
// @Override
// public void onGetPoiResult(PoiResult result) {
// if (result == null
// || result.error == SearchResult.ERRORNO.RESULT_NOT_FOUND) {
//// Toast.makeText(SearchActivity.this, "抱歉,没有搜到相关信息\n" +
//// "您可尝试切换城市搜索", Toast.LENGTH_LONG)
//// .show();
// showTextToast("抱歉,没有搜到相关信息\n" +
// "您可尝试切换城市搜索");
// list.clear();
// adapter.notifyDataSetChanged();
// return;
// }
// if (result.error == SearchResult.ERRORNO.NO_ERROR) {
// List<PoiInfo> mList = result.getAllPoi();
// if (mList != null && mList.size() > 0) {
// list.clear();
// try {
// for (int i = 0; i < mList.size(); i++) {
// map = new HashMap<String, String>();
// map.put("name", mList.get(i).name);
// map.put("address", mList.get(i).address);
// map.put("jing", mList.get(i).location.longitude + "");
// map.put("wei", mList.get(i).location.latitude + "");
// map.put("url", "");
// list.add(map);
// }
// adapter.notifyDataSetChanged();
// } catch (Exception e) {
// e.printStackTrace();
// }
// }else {
// Toast.makeText(SearchActivity.this, "抱歉,未找到结果", Toast.LENGTH_LONG)
// .show();
// }
//
// return;
// }
// }
@Override
protected void onPause() {
super.onPause();
MobclickAgent.onPause(this);
}
@Override
protected void onResume() {
super.onResume();
MobclickAgent.onResume(this);
}
@Override
protected void onDestroy() {
super.onDestroy();
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
if (imm.isActive()) {
View view = getWindow().peekDecorView();
if (view != null) {
imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
}
}
}
/**
* 开始进行poi搜索
*/
protected void doSearchQuery() {
// showProgressDialog();// 显示进度框
currentPage = 0;
query = new PoiSearch.Query(keyWord, "", MainApplication.atCity);// 第一个参数表示搜索字符串,第二个参数表示poi搜索类型,第三个参数表示poi搜索区域(空字符串代表全国)
query.setPageSize(10);// 设置每页最多返回多少条poiitem
query.setPageNum(currentPage);// 设置查第一页
poiSearch = new PoiSearch(this, query);
poiSearch.setOnPoiSearchListener(this);
poiSearch.searchPOIAsyn();
}
// @Override
// public void onGetInputtips(List<Tip> tipList, int rCode) {
// if (rCode == 1000) {// 正确返回
// List<String> listString = new ArrayList<String>();
// for (int i = 0; i < tipList.size(); i++) {
// listString.add(tipList.get(i).getName());
// }
// ArrayAdapter<String> aAdapter = new ArrayAdapter<String>(
// getApplicationContext(),
// R.layout.route_inputs, listString);
// searchText.setAdapter(aAdapter);
// aAdapter.notifyDataSetChanged();
// } else {
//// ToastUtil.showerror(this, rCode);
// }
//
// }
}
|