Search in sources :

Example 1 with OnItemClickLisenter

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);
}
Also used : AMapLocation(com.amap.api.location.AMapLocation) AMap(com.amap.api.maps2d.AMap) OnItemClickLisenter(com.jweihao.jdemo.utils.OnItemClickLisenter) AMapLocationListener(com.amap.api.location.AMapLocationListener) Intent(android.content.Intent) ImageView(android.widget.ImageView) View(android.view.View) RecyclerView(android.support.v7.widget.RecyclerView) MapView(com.amap.api.maps2d.MapView) LatLonPoint(com.amap.api.services.core.LatLonPoint) CameraPosition(com.amap.api.maps2d.model.CameraPosition) GeocodeSearch(com.amap.api.services.geocoder.GeocodeSearch) RegeocodeResult(com.amap.api.services.geocoder.RegeocodeResult) PoiItem(com.amap.api.services.core.PoiItem) LatLng(com.amap.api.maps2d.model.LatLng) GeocodeResult(com.amap.api.services.geocoder.GeocodeResult)

Example 2 with OnItemClickLisenter

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) {
        }
    };
}
Also used : PoiSearch(com.amap.api.services.poisearch.PoiSearch) PoiResult(com.amap.api.services.poisearch.PoiResult) OnItemClickLisenter(com.jweihao.jdemo.utils.OnItemClickLisenter) Intent(android.content.Intent) ImageView(android.widget.ImageView) RecyclerView(android.support.v7.widget.RecyclerView) View(android.view.View) LatLonPoint(com.amap.api.services.core.LatLonPoint) TextWatcher(android.text.TextWatcher) Editable(android.text.Editable) PoiItem(com.amap.api.services.core.PoiItem) LatLonPoint(com.amap.api.services.core.LatLonPoint)

Aggregations

Intent (android.content.Intent)2 RecyclerView (android.support.v7.widget.RecyclerView)2 View (android.view.View)2 ImageView (android.widget.ImageView)2 LatLonPoint (com.amap.api.services.core.LatLonPoint)2 PoiItem (com.amap.api.services.core.PoiItem)2 OnItemClickLisenter (com.jweihao.jdemo.utils.OnItemClickLisenter)2 Editable (android.text.Editable)1 TextWatcher (android.text.TextWatcher)1 AMapLocation (com.amap.api.location.AMapLocation)1 AMapLocationListener (com.amap.api.location.AMapLocationListener)1 AMap (com.amap.api.maps2d.AMap)1 MapView (com.amap.api.maps2d.MapView)1 CameraPosition (com.amap.api.maps2d.model.CameraPosition)1 LatLng (com.amap.api.maps2d.model.LatLng)1 GeocodeResult (com.amap.api.services.geocoder.GeocodeResult)1 GeocodeSearch (com.amap.api.services.geocoder.GeocodeSearch)1 RegeocodeResult (com.amap.api.services.geocoder.RegeocodeResult)1 PoiResult (com.amap.api.services.poisearch.PoiResult)1 PoiSearch (com.amap.api.services.poisearch.PoiSearch)1