use of com.jweihao.jdemo.utils.OnItemClickLisenter in project KL2 by jweihao.
the class GaoDeActivity method initListener.
private void initListener() {
// 监测地图画面的移动
mAMap.setOnCameraChangeListener(new AMap.OnCameraChangeListener() {
@Override
public void onCameraChangeFinish(CameraPosition cameraPosition) {
if (null != location && null != cameraPosition && isSearchData) {
mIvLocation.setImageResource(R.mipmap.location_gps_black);
zoom = cameraPosition.zoom;
if (null != mSelectByListMarker) {
mSelectByListMarker.setVisible(false);
}
getAddressInfoByLatLong(cameraPosition.target.latitude, cameraPosition.target.longitude);
startTransAnimator();
// doSearchQuery(true, "", location.getCity(), new LatLonPoint(cameraPosition.target.latitude, cameraPosition.target.longitude));
}
if (!isSearchData) {
isSearchData = true;
}
}
@Override
public void onCameraChange(CameraPosition cameraPosition) {
}
});
// 设置触摸地图监听器
mAMap.setOnMapClickListener(new AMap.OnMapClickListener() {
@Override
public void onMapClick(LatLng latLng) {
isSearchData = true;
}
});
// Poi搜索监听器
mOnPoiSearchListener = new onPoiSearchLintener();
// 逆地址搜索监听器
mOnGeocodeSearchListener = new GeocodeSearch.OnGeocodeSearchListener() {
@Override
public void onRegeocodeSearched(RegeocodeResult regeocodeResult, int i) {
if (i == 1000) {
if (regeocodeResult != null) {
userSelectPoiItem = DataConversionUtils.changeToPoiItem(regeocodeResult);
if (null != mList) {
mList.clear();
}
mList.addAll(regeocodeResult.getRegeocodeAddress().getPois());
if (null != userSelectPoiItem) {
mList.add(0, userSelectPoiItem);
}
mAddressAdapter.setList(mList);
mRecyclerView.smoothScrollToPosition(0);
}
}
}
@Override
public void onGeocodeSearched(GeocodeResult geocodeResult, int i) {
}
};
// gps定位监听器
mAMapLocationListener = new AMapLocationListener() {
@Override
public void onLocationChanged(AMapLocation loc) {
try {
if (null != loc) {
stopLocation();
if (loc.getErrorCode() == 0) {
// 可在其中解析amapLocation获取相应内容。
location = loc;
SPUtils.putString(GaoDeActivity.this, DatasKey.LOCATION_INFO, gson.toJson(location));
doWhenLocationSucess();
} else {
// 定位失败时,可通过ErrCode(错误码)信息来确定失败的原因,errInfo是错误信息,详见错误码表。
Log.e("AmapError", "location Error, ErrCode:" + loc.getErrorCode() + ", errInfo:" + loc.getErrorInfo());
}
}
} catch (Exception ex) {
ex.printStackTrace();
}
}
};
// recycleview列表监听器
mAddressAdapter.setOnItemClickLisenter(new OnItemClickLisenter() {
@Override
public void onItemClick(int position) {
try {
isSearchData = false;
mIvLocation.setImageResource(R.mipmap.location_gps_black);
moveMapCamera(mList.get(position).getLatLonPoint().getLatitude(), mList.get(position).getLatLonPoint().getLongitude());
refleshSelectByListMark(mList.get(position).getLatLonPoint().getLatitude(), mList.get(position).getLatLonPoint().getLongitude());
} catch (Exception ex) {
ex.printStackTrace();
}
}
});
// 控件点击监听器
mOnClickListener = new View.OnClickListener() {
@Override
public void onClick(View view) {
switch(view.getId()) {
case R.id.iv_back:
finish();
break;
case R.id.iv_search:
// Toast.makeText(MainActivity.this, "搜索", Toast.LENGTH_SHORT).show();
startActivityForResult(new Intent(GaoDeActivity.this, SearchActivity.class), SEARCHREQUESTCODE);
break;
case R.id.iv_location:
// Toast.makeText(MainActivity.this, "定位", Toast.LENGTH_SHORT).show();
mIvLocation.setImageResource(R.mipmap.location_gps_green);
if (null != mSelectByListMarker) {
mSelectByListMarker.setVisible(false);
}
if (null == location) {
startLocation();
} else {
doWhenLocationSucess();
}
break;
case R.id.bt_send:
if (null != mList && 0 < mList.size() && null != mAddressAdapter) {
int position = mAddressAdapter.getSelectPositon();
if (position < 0) {
position = 0;
} else if (position > mList.size()) {
position = mList.size();
}
PoiItem poiItem = mList.get(position);
Toast.makeText(GaoDeActivity.this, "发送:" + poiItem.getTitle() + " " + poiItem.getSnippet() + " " + "纬度:" + poiItem.getLatLonPoint().getLatitude() + " " + "经度:" + poiItem.getLatLonPoint().getLongitude(), Toast.LENGTH_SHORT).show();
}
break;
default:
break;
}
}
};
mIvBack.setOnClickListener(mOnClickListener);
mIvSearch.setOnClickListener(mOnClickListener);
mIvLocation.setOnClickListener(mOnClickListener);
mBtSend.setOnClickListener(mOnClickListener);
}
use of com.jweihao.jdemo.utils.OnItemClickLisenter in project KL2 by jweihao.
the class SearchActivity method initListener.
private void initListener() {
mOnClickListener = new View.OnClickListener() {
@Override
public void onClick(View view) {
switch(view.getId()) {
case R.id.iv_back:
finish();
break;
default:
break;
}
}
};
mIvBack.setOnClickListener(mOnClickListener);
mEtSearch.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {
}
@Override
public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
}
@Override
public void afterTextChanged(Editable editable) {
if (null != editable) {
if (0 == editable.length()) {
// 没有输入则清空搜索记录
mList.clear();
mSearchAddressAdapter.setList(mList, "");
} else {
if (null != location) {
doSearchQuery(editable.toString(), location.getCity(), new LatLonPoint(location.getLatitude(), location.getLongitude()));
} else {
doSearchQuery(editable.toString(), "", null);
}
}
}
}
});
mOnItemClickLisenter = new OnItemClickLisenter() {
@Override
public void onItemClick(int position) {
PoiItem poiItem = mList.get(position);
if (null != poiItem) {
// 获取信息并回传上一页面
Intent intent = new Intent();
intent.putExtra(DatasKey.SEARCH_INFO, poiItem);
setResult(RESULT_OK, intent);
finish();
}
}
};
mSearchAddressAdapter.setOnItemClickLisenter(mOnItemClickLisenter);
mOnPoiSearchListener = new PoiSearch.OnPoiSearchListener() {
@Override
public void onPoiSearched(PoiResult result, int i) {
if (i == 1000) {
if (result != null && result.getQuery() != null) {
// 搜索poi的结果
if (result.getQuery().equals(mQuery)) {
// 是否是同一条
if (null != mList) {
mList.clear();
}
// 取得第一页的poiitem数据,页数从数字0开始
mList.addAll(result.getPois());
if (null != mSearchAddressAdapter) {
mSearchAddressAdapter.setList(mList, mEtSearch.getText().toString().trim());
mRecyclerView.smoothScrollToPosition(0);
}
}
}
}
}
@Override
public void onPoiItemSearched(PoiItem poiItem, int i) {
}
};
}
Aggregations