高德地图--到店类应用解说

本文档详细介绍了如何在地图应用中替换过时的云图SDK,包括更新搜索和定位功能,解决常见问题如地图页面显示问题,以及如何将列表视图转换为地图视图等。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

问题1:demo不能运行?

key值和tableid的值在特定的位置,仔细看文档,并且key
值和tableid的值对应同一 开发者。

问题2:更换SDK?

因为demo是旧版的所以需要将基础地图、定位、搜索、云图的SDK换成最新版,最新版将搜索和云图合并在同一个SDK中,
定位的方法是旧的方法,将新的定位方法插入在制定位置插入就行,
旧的方法内有监听定位发生改变的函数,所以其他的就不用管了。


        mlocationClient = new AMapLocationClient(this);
        mLocationOption = new AMapLocationClientOption();
        // 设置定位监听
        mlocationClient.setLocationListener(this);
        // 设置为高精度定位模式
        mLocationOption.setLocationMode(AMapLocationClientOption.AMapLocationMode.Hight_Accuracy);
        // 设置定位参数
        mlocationClient.setLocationOption(mLocationOption); 
        mlocationClient.startLocation();

    private void stopLocation() {

         if (mlocationClient != null) {
                mlocationClient.stopLocation();
                mlocationClient.onDestroy();
            }
            mlocationClient = null;

    }

问题3:进入时,地图页面显示整个城市的检索对象?

不需要用intent传送的值,需要根据定位的坐标获取城市的名称,然后进行搜索,


    @Override
    public void onLocationChanged(AMapLocation amapLocation) {
        if (mListener != null && amapLocation != null) {
            if (amapLocation != null && amapLocation.getErrorCode() == 0) {
                mListener.onLocationChanged(amapLocation);// 显示系统小蓝点
                // aMap.moveCamera(CameraUpdateFactory.zoomTo(18));
            } else {
                String errText = "定位失败," + amapLocation.getErrorCode() + ": " + amapLocation.getErrorInfo();
                Log.e("AmapErr", errText);
            }
            if (amapLocation.getErrorCode() == 0) {
                // 如果地理位置获取不存在问题的话,存入当前的经纬度
                // 并且设置当前的城市
                setCurrentCity(amapLocation.getCity());
                // mCurrentSearchType = ARROUND_SEARCH_TYPE;
                String cityName = amapLocation.getCity();
                searchByLocal(cityName);
            }

        }

    }

private void searchByLocal(String name) {
        mCurrentSearchType = LOCAL_SEARCH_TYPE;

        String localName = name;
        SearchBound bound = new SearchBound(localName); 
        Log.i("aOOO222", bound.toString());
        try {
            amapQuery = new CloudSearch.Query(Const.mTableID, "", bound);
            // amapQuery.setPageSize(10);
            // amapQuery.setPageNum(mCurrentPageNum);           
            amapCloudSearch.searchCloudAsyn(amapQuery);
        } catch (AMapCloudException e) {
            e.printStackTrace();
        }
    }

问题4: 更换云图SDK?

需要将搜索和云图SDK换成搜索SDK,然后需要改为errorCode==1000,
原来等于0时获取搜索结果,现在是1000

@Override
    public void onCloudSearched(CloudResult result, int errorCode) {
        // TODO Auto-generated method stub
        mPullRefreshListView.onRefreshComplete();
        mPullRefreshListView.clearAnimation();
        dissmissProgressDialog();
        if (errorCode ==1000 && result != null) {
            ArrayList<CloudItem> cloudResult = result.getClouds();
            Log.i("QWQWR", 1+"");
            if (cloudResult != null && cloudResult.size() > 0) {
                mCoudItemList.addAll(cloudResult);
                mAdapter.notifyDataSetChanged();
            } else {
                Toast.makeText(mApplicationContext, R.string.error_no_more_item, Toast.LENGTH_SHORT).show();
            }

        } else if (errorCode == Const.ERROR_CODE_SOCKE_TIME_OUT) {
            ToastUtil.show(this.getApplicationContext(), R.string.error_socket_timeout);
        } else if (errorCode == Const.ERROR_CODE_UNKNOW_HOST) {
            ToastUtil.show(this.getApplicationContext(), R.string.error_network);
        } else if (errorCode == Const.ERROR_CODE_FAILURE_AUTH) {
            ToastUtil.show(this.getApplicationContext(), R.string.error_key);
        } else if (errorCode == Const.ERROR_CODE_SCODE) {
            ToastUtil.show(this.getApplicationContext(), R.string.error_scode);
        } else if (errorCode == Const.ERROR_CODE_TABLEID) {
            ToastUtil.show(this.getApplicationContext(), R.string.error_table_id);
        } else {
            ToastUtil.show(this.getApplicationContext(), getString(R.string.error_other) + errorCode);
        }
        if (mCoudItemList == null || mCoudItemList.size() == 0) {
            // mPullRefreshListView.setMode(Mode.DISABLED);
            mLLYNoData.setVisibility(View.VISIBLE);
        } else {
            mLLYNoData.setVisibility(View.GONE);
            // mPullRefreshListView.setMode(Mode.PULL_FROM_END);
        }
    }

问题4:将index页中listview,换成map。

package com.amap.cloud.scheme.act;

import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import android.app.Activity;
import android.app.Dialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.DialogInterface.OnCancelListener;
import android.graphics.BitmapFactory;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.KeyEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.PopupWindow.OnDismissListener;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.amap.api.location.AMapLocation;
import com.amap.api.location.AMapLocationClient;
import com.amap.api.location.AMapLocationClientOption;
import com.amap.api.location.AMapLocationListener;
import com.amap.api.maps.AMap;
import com.amap.api.maps.AMap.InfoWindowAdapter;
import com.amap.api.maps.AMap.OnInfoWindowClickListener;
import com.amap.api.maps.AMap.OnMapLoadedListener;
import com.amap.api.maps.AMap.OnMarkerClickListener;
import com.amap.api.maps.CameraUpdateFactory;
import com.amap.api.maps.LocationSource;
import com.amap.api.maps.model.BitmapDescriptorFactory;
import com.amap.api.maps.model.LatLng;
import com.amap.api.maps.model.Marker;
import com.amap.api.maps.model.MarkerOptions;
import com.amap.api.maps.model.MyLocationStyle;
import com.amap.api.maps.MapView;
import com.amap.api.maps.UiSettings;
import com.amap.api.services.cloud.CloudItem;
import com.amap.api.services.cloud.CloudItemDetail;
import com.amap.api.services.cloud.CloudResult;
import com.amap.api.services.cloud.CloudSearch;
import com.amap.api.services.cloud.CloudSearch.OnCloudSearchListener;
import com.amap.api.services.cloud.CloudSearch.SearchBound;
import com.amap.api.services.core.AMapException;
import com.amap.api.services.core.LatLonPoint;
import com.amap.api.services.district.DistrictItem;
import com.amap.api.services.district.DistrictResult;
import com.amap.api.services.district.DistrictSearch;
import com.amap.api.services.district.DistrictSearch.OnDistrictSearchListener;
import com.amap.api.services.district.DistrictSearchQuery;
import com.amap.cloud.scheme.adapter.DistrictListAdapter;
import com.amap.cloud.scheme.constant.BundleFlag;
import com.amap.cloud.scheme.constant.BundleResult;
import com.amap.cloud.scheme.constant.Const;
import com.amap.cloud.scheme.model.City;
import com.amap.cloud.scheme.model.MarkerStatus;
import com.amap.cloud.scheme.popup.CityChoosePopupWindow;
import com.amap.cloud.scheme.util.CityUtil;
import com.amap.cloud.scheme.util.ToastUtil;
import com.amap.cloud.scheme.util.Utils;
import com.amap.yuntu.scheme.R;
import com.handmark.pulltorefresh.library.PullToRefreshBase.OnLastItemVisibleListener;

/**
 * 云图Item list展现,进入APP先提示定位。如果定位成功,按照当前位置10km周边搜索;如果定位失败,按照默认城市北京搜索
 * 点击城市名称可选择该城市某个区或者切换城市进行本地搜索。
 * 
 * @author ligen
 *
 */
public class IndexMapActivity extends Activity
        implements OnClickListener, OnLastItemVisibleListener, OnCloudSearchListener, AMapLocationListener,
        LocationSource, OnMarkerClickListener, OnInfoWindowClickListener, InfoWindowAdapter, OnMapLoadedListener {

    private static final String WHOLE_CITY = "全城";
    private final int CITY_CHOOSE_REQUEST_CODE = 10;
    private final int POI_CHOOSE_REQUEST_CODE = 20;

    private LinearLayout mBtnAreaChoose;
    private ImageView mBtnMap;
    private ArrayList<City> mCityList;
    private ArrayList<String> mCityLetterList;
    private HashMap<String, Integer> mCityMap;
    private TextView mCurrentCityDistrictTextview;
    private String mCurrentDistrict;
    private String[] mLetterStrs = { "常", "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O",
            "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z" };

    private CloudSearch mCloudSearch;
    private CloudSearch.Query mQuery;
    @SuppressWarnings("unused")
    private LatLonPoint mCenterPoint = new LatLonPoint(39.911823, 116.394829);
    private String mKeywords = "";
    private ArrayList<CloudItem> mCoudItemList = new ArrayList<CloudItem>();
    private Dialog mProgressDialog = null;
    private Context mApplicationContext;
    private CityChoosePopupWindow mPopupWindow;
    private ImageView mUpDownArrow;
    private String mCurrentCity;
    private LinearLayout mInfoData;
    // -------------------------------------------------
    private MarkerStatus mLastMarkerStatus;
    private AMapLocationClient mlocationClient;
    private AMapLocationClientOption mLocationOption;
    private MapView mMapView;
    private AMap mAMap;
    private UiSettings mUiSettings;
    private LinearLayout mBtnDetail;
    private TextView mTextViewName;
    private TextView mDaohang;
    //private TextView mTextViewAddress;
    @SuppressWarnings("unused")
    private CloudItem mCurrentItem = null;
    private OnClickListener mPopupWindowClickListener = new OnClickListener() {

        @Override
        public void onClick(View v) {
            switch (v.getId()) {

            case R.id.change_city_linearlayout:
                gotoCityListActivity();
                break;

            default:
                break;
            }

        }
    };

    private OnItemClickListener mGridViewItemListener = new OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {

            mChosenDistrictIndex = arg2;
            mCurrentDistrict = mDistrictsOfCurrentCity[arg2];
            mCurrentCityDistrictTextview.setText(getCurrentCity() + mCurrentDistrict);
            Toast.makeText(mApplicationContext, getCurrentCity(), Toast.LENGTH_SHORT).show();
            mCoudItemList.clear();
            mAMap.clear();
            searchByLocal();
            addMarkersToMap();
            mPopupWindow.dismiss();
        }
    };
    private String[] mDistrictsOfCurrentCity;
    private int mChosenDistrictIndex = -1;
    // private int mFirstVisibleItem;
    private int mVisibleItemCount;
    private RelativeLayout mSearchBarLinearLayout;
    private EditText minputEditText;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_index);
        mApplicationContext = this.getApplicationContext();

        // 注册云图搜索监听
        mCloudSearch = new CloudSearch(this);
        mCloudSearch.setOnCloudSearchListener(this);
        showProgressDialog(Const.LODING_LOCATION);
        // ---------------------------------------------------------
        mMapView = (MapView) findViewById(R.id.index_map);
        mMapView.onCreate(savedInstanceState);
        init();
        initLocation();
        setUpInteractiveControls();
        mCurrentCity = getResources().getString(R.string.default_city);
    }

    private void initLocation() {
        // TODO Auto-generated method stub
        mlocationClient = new AMapLocationClient(this);
        mLocationOption = new AMapLocationClientOption();
        // 设置定位监听
        mlocationClient.setLocationListener(this);
        // 设置为高精度定位模式
        mLocationOption.setLocationMode(AMapLocationClientOption.AMapLocationMode.Hight_Accuracy);
        // 设置定位参数
        mlocationClient.setLocationOption(mLocationOption);
        mlocationClient.startLocation();
    }

    // --------------------------------------------------------------------------

    private void init() {
        if (mAMap == null) {
            mAMap = mMapView.getMap();
            initMap();
            setMapUi();
            setMapListener();
        }
    }

    private void setMapListener() {
        // mAMap.setOnMarkerDragListener(this);// 设置marker可拖拽事件监听器
        mAMap.setOnMapLoadedListener(this);// 设置amap加载成功事件监听器
        mAMap.setOnMarkerClickListener(this);// 设置点击marker事件监听器
        mAMap.setOnInfoWindowClickListener(this);// 设置点击infoWindow事件监听器
        mAMap.setInfoWindowAdapter(this);// 设置自定义InfoWindow样式
    }

    private void initMap() {
        mAMap.setLocationSource(this);
        mAMap.getUiSettings().setMyLocationButtonEnabled(true);// 设置默认定位按钮是否显示
        mAMap.setMyLocationEnabled(true);// 设置为true表示显示定位层并可触发定位,false表示隐藏定位层并不可触发定位,默认是false
        // aMap.moveCamera(CameraUpdateFactory.zoomTo(17));
        initLocationStyle();
    }

    private void initLocationStyle() {
        MyLocationStyle myLocationStyle = new MyLocationStyle();// 自定义系统定位蓝点
        myLocationStyle.myLocationIcon(BitmapDescriptorFactory.fromResource(R.drawable.location_stake_z));// 自定义定位蓝点图标
        mAMap.setMyLocationStyle(myLocationStyle); // 将自定义的 myLocationStyle
                                                    // 对象添加到地图上
    }

    private void setMapUi() {
        mUiSettings = mAMap.getUiSettings();
        mUiSettings.setZoomControlsEnabled(true);
        mUiSettings.setScaleControlsEnabled(true);
        mUiSettings.setRotateGesturesEnabled(false);
        mUiSettings.setTiltGesturesEnabled(false);
    }

    private void addMarkersToMap() {

        int size = mCoudItemList.size();
        for (int i = 0; i < size; i++) {

            // 根据该poi的经纬度进行marker点的添加
            MarkerOptions markerOption = new MarkerOptions();
            markerOption.position(new LatLng(mCoudItemList.get(i).getLatLonPoint().getLatitude(),
                    mCoudItemList.get(i).getLatLonPoint().getLongitude()));
            Marker marker = mAMap.addMarker(markerOption);

            MarkerStatus markerStatus = new MarkerStatus(i);
            markerStatus.setCloudItem(mCoudItemList.get(i));
            markerStatus.setMarker(marker);
            if (i == 0) {
                markerChosen(markerStatus);
            }
            setMarkerBasedonStatus(markerStatus);
            marker.setObject(markerStatus);
        }

    }

    /**
     * 切换城市的时候,将地图中心设置为该城市的
     * 
     * @param name
     */

    private void getCityCenter(String name) {

        DistrictSearch search = new DistrictSearch(mApplicationContext);
        DistrictSearchQuery query = new DistrictSearchQuery();
        query.setKeywords(name);// 传入关键字
        query.setKeywordsLevel(DistrictSearchQuery.KEYWORDS_PROVINCE);
        // query.setShowBoundary(true);// 是否返回边界值
        search.setQuery(query);
        search.searchDistrictAsyn();
        search.setOnDistrictSearchListener(new OnDistrictSearchListener() {

            @Override
            public void onDistrictSearched(DistrictResult result) {
                // TODO Auto-generated method stub
                if (result.getAMapException().getErrorCode() == 1000) {

                    ArrayList<DistrictItem> item = result.getDistrict();
                    LatLonPoint center = item.get(0).getCenter();
                    LatLng latlng = new LatLng(center.getLatitude(), center.getLongitude());
                    mAMap.moveCamera(CameraUpdateFactory.newLatLng(latlng));
                    mAMap.moveCamera(CameraUpdateFactory.zoomTo(10));
                    Log.i("Bosss", result.toString());
                } else {
                    Toast.makeText(mApplicationContext, result.toString(), Toast.LENGTH_SHORT).show();
                    Log.i("AOsss", result.toString());

                }

            }
        });

    }

    /**
     * marker被选中之后,需要更改marker的样式,以及在底部bar显示信息
     * 
     * @param markerStatus
     */
    private void markerChosen(MarkerStatus markerStatus) {
        markerStatus.pressStatusToggle();
        mCurrentItem = (CloudItem) markerStatus.getCloudItem();
        mTextViewName.setText(mCurrentItem.getTitle());
        //mTextViewAddress.setText(mCurrentItem.getSnippet());
        setMarkerBasedonStatus(markerStatus);
    }

    private void setMarkerBasedonStatus(MarkerStatus status) {
        if (status.getIsPressed()) {
            status.getMarker().setIcon(BitmapDescriptorFactory
                    .fromBitmap(BitmapFactory.decodeResource(getResources(), status.getmResPressed())));
        } else {
            status.getMarker().setIcon(BitmapDescriptorFactory
                    .fromBitmap(BitmapFactory.decodeResource(getResources(), status.getmResUnPressed())));
        }
    }
    // -------------------------------------------------------

    /**
     * 方法必须重写
     */
    @Override
    protected void onResume() {
        super.onResume();
        mMapView.onResume();
    }

    /**
     * 方法必须重写
     */
    @Override
    protected void onPause() {
        super.onPause();
        mMapView.onPause();
        stopLocation();// 停止定位
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        mMapView.onDestroy();
        if (null != mlocationClient) {
            mlocationClient.onDestroy();
        }
    }

    private long exitTime = 0;
    private HashMap<String, String[]> mDistrictsOfcityMap = new HashMap<String, String[]>();;

    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        if (keyCode == KeyEvent.KEYCODE_BACK && event.getAction() == KeyEvent.ACTION_DOWN) {
            if ((System.currentTimeMillis() - exitTime) > 2000) {
                Toast.makeText(this, getResources().getString(R.string.press_more_then_exit), Toast.LENGTH_SHORT)
                        .show();
                ;
                exitTime = System.currentTimeMillis();
            } else {
                finish();
                System.exit(0);
            }
            return true;
        }
        return super.onKeyDown(keyCode, event);
    }

    /**
     * 销毁定位
     */
    private void stopLocation() {
        // -------------------------------------------------------------------------
        if (mlocationClient != null) {
            mlocationClient.stopLocation();
            mlocationClient.onDestroy();
        }
        mlocationClient = null;

    }

    /**
     * 进行默认的搜索 类型为根据城市行政区的搜索 默认的城市可以自己配置
     * 
     * @param pagenum
     */
    private void searchDefault() {
        mCurrentCity = getResources().getString(R.string.default_city);
        searchByLocal();
    }

    /**
     * 根据选择的城市和行政区进行搜索
     * 
     * @param pagenum
     */
    private void searchByLocal() {

        showProgressDialog(Const.LODING_GET_DATA);
        String localName = "";
        if (mCurrentDistrict != null && !mCurrentDistrict.equals("") && !mCurrentDistrict.equals(WHOLE_CITY)) {
            localName = getCurrentCity() + mCurrentDistrict;
        } else {
            localName = getCurrentCity();
        }
        SearchBound bound = new SearchBound(localName);
        try {
            mQuery = new CloudSearch.Query(Const.mTableID, mKeywords, bound);

            mCloudSearch.searchCloudAsyn(mQuery);
        } catch (AMapException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

    }

    private void searchByLocal1() {

        showProgressDialog(Const.LODING_GET_DATA);
        String localName = getCurrentCity();

        SearchBound bound = new SearchBound(localName);
        try {
            mQuery = new CloudSearch.Query(Const.mTableID, "", bound);

            mCloudSearch.searchCloudAsyn(mQuery);
        } catch (AMapException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

    }

    private void setUpInteractiveControls() {

        minputEditText = (EditText) findViewById(R.id.input_edittext);
        mSearchBarLinearLayout = (RelativeLayout) findViewById(R.id.search_bar_layout);
        mCurrentCityDistrictTextview = (TextView) findViewById(R.id.current_city_district_textview);
        mUpDownArrow = (ImageView) findViewById(R.id.up_down_arrow);
        mBtnAreaChoose = (LinearLayout) findViewById(R.id.btn_area_choose);
        mBtnAreaChoose.setOnClickListener(this);
        mBtnMap = (ImageView) findViewById(R.id.btn_map);
        mBtnMap.setOnClickListener(this);
        // --------------------------------------------------
        mBtnDetail = (LinearLayout) findViewById(R.id.poi_detail);
        mTextViewName = (TextView) findViewById(R.id.poi_name);
        //mTextViewAddress = (TextView) findViewById(R.id.poi_address);
        mInfoData=(LinearLayout) findViewById(R.id.main_charg_dialog);
         mDaohang=(TextView) findViewById(R.id.main_charg_navigation);
         mDaohang.setOnClickListener(this);
        mBtnDetail.setOnClickListener(this);
    }
    private void gotoDetailActivity() {

        if (mCurrentItem != null) {
            mInfoData.setVisibility(View.GONE);
            Intent intent = new Intent(this, DetailActivity.class);
            intent.putExtra(BundleFlag.CLOUD_ITEM, mCurrentItem);
            intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            startActivity(intent);
        }

    }

    @Override
    public void onClick(View v) {

        switch (v.getId()) {

        case R.id.btn_area_choose:
            showAreaPopupWindow();
            break;

        case R.id.btn_map:
            gotoMapActivity();
            break;

        case R.id.input_edittext:
            gotoKeywordInputActivity();
            break;
        case R.id.poi_detail:
            gotoDetailActivity();
            break;
        case R.id.main_charg_navigation:
            onDaoHangClick();

        default:
            break;
        }

    }
    public void onDaoHangClick() {
        Intent intent = new Intent(this, RouteMapActivity.class);
        intent.putExtra(BundleFlag.CLOUD_ITEM, mCurrentItem);
        this.startActivity(intent);
    }

    private void gotoKeywordInputActivity() {

        Intent intent = new Intent(this, KeywordListActivity.class);
        startActivityForResult(intent, POI_CHOOSE_REQUEST_CODE);
    }

    private void gotoMapActivity() {

        ArrayList<CloudItem> currentVisibleItems = new ArrayList<CloudItem>();

        for (int i = 0; i < mCoudItemList.size(); i++) {
            currentVisibleItems.add(mCoudItemList.get(i));
        }

        Intent intent = new Intent(this, IndexListActivity.class);
        intent.putParcelableArrayListExtra(BundleFlag.CLOUD_ITEM_LIST, currentVisibleItems);
        startActivity(intent);
    }

    private void showAreaPopupWindow() {

        mPopupWindow = new CityChoosePopupWindow(this, mPopupWindowClickListener);

        mPopupWindow.showAsDropDown(mSearchBarLinearLayout);
        mUpDownArrow.setBackgroundResource(R.drawable.arrow_up_white);

        mPopupWindow.setOnDismissListener(new OnDismissListener() {

            @Override
            public void onDismiss() {
                mUpDownArrow.setBackgroundResource(R.drawable.arrow_down_white);
            }
        });

        if (mCityLetterList == null || mCityList == null || mCityMap == null)
            createCityListForCityChoose();
        updatePopupWindowData();

    }

    private void updatePopupWindowData() {

        mDistrictsOfCurrentCity = getDistrictsBasedonCityName(getCurrentCity());
        mPopupWindow.getDistrictGridView()
                .setAdapter(new DistrictListAdapter(this, mDistrictsOfCurrentCity, mChosenDistrictIndex));
        mPopupWindow.getDistrictGridView().setOnItemClickListener(mGridViewItemListener);
        mPopupWindow.getCurrentCityTextView().setText(getCurrentCity());
        mCurrentCityDistrictTextview.setText(getCurrentCity());
    }

    private void createCityListForCityChoose() {
        try {
            String content = Utils.getAssetsFie(this, "city.json");
            dealWithJson(content);
        } catch (IOException e) {
            Log.e("aaa", "city init failed", e);
        }
    }

    private void dealWithJson(String content) {

        try {
            JSONObject json = new JSONObject(content);
            String status = json.getString("status");
            if ("200".equals(status)) {
                JSONObject result = json.getJSONObject("result");
                // int cityVersion = result.optInt("version");
                JSONObject data = result.getJSONObject("city");
                HashMap<String, Integer> tempCityHashMap = new HashMap<String, Integer>();
                ArrayList<String> temp_city_letter_list = new ArrayList<String>();
                ArrayList<City> tempCityList = new ArrayList<City>();
                for (int m = 0; m < mLetterStrs.length; m++) {
                    String key = mLetterStrs[m];
                    JSONArray array = data.optJSONArray(key);
                    if (array == null) {
                        continue;
                    }
                    temp_city_letter_list.add(key);
                    for (int i = 0; i < array.length(); i++) {
                        JSONObject json_city = array.getJSONObject(i);
                        City model_item = new City();
                        model_item.name = json_city.optString("name");
                        model_item.code = json_city.optString("cityCode");
                        if (i == 0) {
                            model_item.letter = key;
                            tempCityHashMap.put(key, tempCityList.size());
                        }
                        tempCityList.add(model_item);
                    }
                }

                if (mCityList == null || mCityList.size() <= 0) {
                    mCityList = tempCityList;
                    mCityMap = tempCityHashMap;
                    mCityLetterList = temp_city_letter_list;
                }
            } else {
                if (mCityList == null || mCityList.size() <= 0) {
                    showErrorDialog(getString(R.string.city_get_error));
                }

            }
        } catch (JSONException e) {
            e.printStackTrace();
        }

    }

    private void showErrorDialog(String string) {

        Dialog dialog = new Dialog(this);

        dialog.setOnCancelListener(new OnCancelListener() {

            @Override
            public void onCancel(DialogInterface dialog) {
                // TODO Auto-generated method stub

            }
        });

        dialog.show();

    }

    private void gotoCityListActivity() {

        Intent intent = new Intent(this, CityListActivity.class);
        intent.putExtra(BundleFlag.CITY_LIST, mCityList);
        intent.putStringArrayListExtra(BundleFlag.CITY_LETTERS, mCityLetterList);
        intent.putExtra(BundleFlag.CITY_MAP, mCityMap);
        startActivityForResult(intent, CITY_CHOOSE_REQUEST_CODE);

    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        if (CITY_CHOOSE_REQUEST_CODE == requestCode && resultCode == BundleResult.SUCCESS) {
            City city = (City) data.getSerializableExtra(BundleFlag.CITY_MODEL);
            if (city != null) {
                setCity(city);
                getCityCenter(city.name.toString());

            }
            mCoudItemList.clear();

            // ******************************************************mAdapter.notifyDataSetChanged();
            mCurrentDistrict = "";
            searchByLocal1();
            mAMap.clear();
            addMarkersToMap();
            return;
        }

        if (requestCode == POI_CHOOSE_REQUEST_CODE && resultCode == BundleResult.SUCCESS) {
            String selectedItem = (String) data.getSerializableExtra(BundleFlag.POI_ITEM);
            mKeywords = selectedItem;

            mCoudItemList.clear();

            // **********************************************************mAdapter.notifyDataSetChanged();
            searchByLocal();
            mAMap.clear();
            addMarkersToMap();
            minputEditText.setText(selectedItem);
            return;
        }

        super.onActivityResult(requestCode, resultCode, data);
    }

    private void setCity(City city) {
        mChosenDistrictIndex = -1;
        setCurrentCity(city.name.toString());
        updatePopupWindowData();
    }

    /**
     * 根据城市名字,得到该城市下对应的所有行政区的字符串数组
     * 
     * @param city
     * @return
     */
    private String[] getDistrictsBasedonCityName(String city) {

        if (mDistrictsOfcityMap.containsKey(city)) {
            return mDistrictsOfcityMap.get(city);
        }

        CityUtil cityUtil = new CityUtil(this, city);
        List<String> lists = cityUtil.getItsDistricts();
        String[] districtsOfThisCity = lists.toArray(new String[lists.size()]);
        mDistrictsOfcityMap.put(city, districtsOfThisCity);

        return districtsOfThisCity;
    }

    private void showProgressDialog(String message) {
        mProgressDialog = ToastUtil.createLoadingDialog(this, message);
        mProgressDialog.setCancelable(true);
        mProgressDialog.show();
    }

    private void dissmissProgressDialog() {
        if (mProgressDialog != null && mProgressDialog.isShowing()) {
            mProgressDialog.dismiss();
        }
    }

    @Override
    public void onLastItemVisible() {
        // TODO Auto-generated method stub
    }

    @Override
    public void onCloudItemDetailSearched(CloudItemDetail item, int errorCode) {
        // TODO Auto-generated method stub

    }

    @Override
    public void onCloudSearched(CloudResult result, int errorCode) {
        // TODO Auto-generated method stub

        dissmissProgressDialog();
        if (errorCode == 1000 && result != null) {
            ArrayList<CloudItem> cloudResult = result.getClouds();
            Log.i("QWQWR", 1 + "");
            if (cloudResult != null && cloudResult.size() > 0) {
                mCoudItemList.addAll(cloudResult);
                mAMap.clear();
                addMarkersToMap();
                // *********************************************************mAdapter.notifyDataSetChanged();
            } else {
                Toast.makeText(mApplicationContext, R.string.error_no_more_item, Toast.LENGTH_SHORT).show();
            }

        } else if (errorCode == Const.ERROR_CODE_SOCKE_TIME_OUT) {
            ToastUtil.show(this.getApplicationContext(), R.string.error_socket_timeout);
        } else if (errorCode == Const.ERROR_CODE_UNKNOW_HOST) {
            ToastUtil.show(this.getApplicationContext(), R.string.error_network);
        } else if (errorCode == Const.ERROR_CODE_FAILURE_AUTH) {
            ToastUtil.show(this.getApplicationContext(), R.string.error_key);
        } else if (errorCode == Const.ERROR_CODE_SCODE) {
            ToastUtil.show(this.getApplicationContext(), R.string.error_scode);
        } else if (errorCode == Const.ERROR_CODE_TABLEID) {
            ToastUtil.show(this.getApplicationContext(), R.string.error_table_id);
        } else {
            ToastUtil.show(this.getApplicationContext(), getString(R.string.error_other) + errorCode);
        }
        if (mCoudItemList == null || mCoudItemList.size() == 0) {
            // mPullRefreshListView.setMode(Mode.DISABLED);
            //mLLYNoData.setVisibility(View.VISIBLE);
        } else {
            //mLLYNoData.setVisibility(View.GONE);
            // mPullRefreshListView.setMode(Mode.PULL_FROM_END);
        }
    }

    public String getCurrentCity() {
        return mCurrentCity;
    }

    private void setCurrentCity(String mCurrentCity) {
        if (mCurrentCity == null)
            mCurrentCity = "未能定位当前城市";

        mCurrentCity = mCurrentCity.replace("市", "");
        mCurrentCityDistrictTextview.setText(mCurrentCity);
        this.mCurrentCity = mCurrentCity;
    }

    /**
     * 地理位置变化回调
     */
    @Override
    public void onLocationChanged(AMapLocation location) {
        // TODO Auto-generated method stub
        dissmissProgressDialog();
        stopLocation();
        if (location == null) {
            // 如果没有地理位置数据返回,则进行默认的搜索
            searchDefault();
            return;
        }

        if (location.getErrorCode() == 0) {
            // 如果地理位置获取不存在问题的话,存入当前的经纬度
            Double geoLat = location.getLatitude();
            Double geoLng = location.getLongitude();
            mCenterPoint = new LatLonPoint(geoLat, geoLng);
            // 并且设置当前的城市
            setCurrentCity(location.getCity());
            searchByLocal1();
        } else {
            ToastUtil.show(this.getApplicationContext(), getResources().getString(R.string.locate_fail));
            searchDefault();
        }
    }

    @Override
    public void activate(OnLocationChangedListener arg0) {
        // TODO Auto-generated method stub

    }

    @Override
    public void deactivate() {
        // TODO Auto-generated method stub

    }

    @Override
    public boolean onMarkerClick(Marker arg0) {
        // TODO Auto-generated method stub
        if (mLastMarkerStatus != null) {
            mLastMarkerStatus.pressStatusToggle();
            setMarkerBasedonStatus(mLastMarkerStatus);
        }

        mInfoData.setVisibility(View.VISIBLE);
        MarkerStatus newMarkerStatus = (MarkerStatus) arg0.getObject();
        markerChosen(newMarkerStatus);
        mLastMarkerStatus = newMarkerStatus;
        return false;

    }

    @Override
    public void onInfoWindowClick(Marker arg0) {
        // TODO Auto-generated method stub

    }

    @Override
    public View getInfoContents(Marker arg0) {
        // TODO Auto-generated method stub
        return null;
    }

    @Override
    public View getInfoWindow(Marker arg0) {
        // TODO Auto-generated method stub
        return null;
    }

    @Override
    public void onMapLoaded() {
        // TODO Auto-generated method stub

    }

}
package com.amap.cloud.scheme.act;

import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import android.app.Activity;
import android.app.Dialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.DialogInterface.OnCancelListener;
import android.content.Intent;
import android.location.Location;
import android.os.Bundle;
import android.util.Log;
import android.view.KeyEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.AbsListView;
import android.widget.AbsListView.OnScrollListener;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.PopupWindow.OnDismissListener;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.amap.api.location.AMapLocation;
import com.amap.api.location.AMapLocationClient;
import com.amap.api.location.AMapLocationClientOption;
import com.amap.api.location.AMapLocationListener;
import com.amap.api.maps.LocationSource.OnLocationChangedListener;
import com.amap.api.services.cloud.CloudItem;
import com.amap.api.services.cloud.CloudItemDetail;
import com.amap.api.services.cloud.CloudResult;
import com.amap.api.services.cloud.CloudSearch;
import com.amap.api.services.cloud.CloudSearch.OnCloudSearchListener;
import com.amap.api.services.cloud.CloudSearch.SearchBound;
import com.amap.api.services.core.AMapException;
import com.amap.api.services.core.LatLonPoint;
import com.amap.cloud.scheme.adapter.CloudItemListAdapter;
import com.amap.cloud.scheme.adapter.DistrictListAdapter;
import com.amap.cloud.scheme.constant.BundleFlag;
import com.amap.cloud.scheme.constant.BundleResult;
import com.amap.cloud.scheme.constant.Const;
import com.amap.cloud.scheme.model.City;
import com.amap.cloud.scheme.popup.CityChoosePopupWindow1;
import com.amap.cloud.scheme.util.CityUtil;
import com.amap.cloud.scheme.util.ToastUtil;
import com.amap.cloud.scheme.util.Utils;
import com.amap.yuntu.scheme.R;
import com.handmark.pulltorefresh.library.ILoadingLayout;
import com.handmark.pulltorefresh.library.PullToRefreshBase;
import com.handmark.pulltorefresh.library.PullToRefreshBase.Mode;
import com.handmark.pulltorefresh.library.PullToRefreshBase.OnLastItemVisibleListener;
import com.handmark.pulltorefresh.library.PullToRefreshBase.OnRefreshListener;
import com.handmark.pulltorefresh.library.PullToRefreshListView;

/**
 * 云图Item list展现,进入APP先提示定位。如果定位成功,按照当前位置10km周边搜索;如果定位失败,按照默认城市北京搜索
 * 点击城市名称可选择该城市某个区或者切换城市进行本地搜索。
 * 
 * @author ligen
 *
 */
public class IndexListActivity extends Activity implements OnClickListener, OnRefreshListener<ListView>,
        OnLastItemVisibleListener, OnCloudSearchListener, OnScrollListener {

    private static final String WHOLE_CITY = "全城";
    private final int CITY_CHOOSE_REQUEST_CODE = 10;
    private final int POI_CHOOSE_REQUEST_CODE = 20;

    private LinearLayout mBtnAreaChoose;
    private ImageView mBtnMap;
    private ArrayList<City> mCityList;
    private ArrayList<String> mCityLetterList;
    private HashMap<String, Integer> mCityMap;
    private TextView mCurrentCityDistrictTextview;
    private String mCurrentDistrict;
    // private LocationManagerProxy mAMapLocManager = null;

    // 快捷搜索词
    private String[] mLetterStrs = { "常", "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O",
            "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z" };

    private PullToRefreshListView mPullRefreshListView;
    private CloudItemListAdapter mAdapter;
    private CloudSearch mCloudSearch;
    private CloudSearch.Query mQuery;
    private LatLonPoint mCenterPoint = new LatLonPoint(39.911823, 116.394829);
    private String mKeywords = "";
    private ArrayList<CloudItem> mCoudItemList = new ArrayList<CloudItem>();
    private ArrayList<CloudItem> mCloudItems = new ArrayList<CloudItem>();
    private Dialog mProgressDialog = null;
    private Context mApplicationContext;
    private CityChoosePopupWindow1 mPopupWindow;
    private ImageView mUpDownArrow;
    private String mCurrentCity;
    private int mCurrentPageNum = 0;
    private LinearLayout mLLYNoData;
    private final static int LOCAL_SEARCH_TYPE = 1;
    private final static int ARROUND_SEARCH_TYPE = 2;
    private int mCurrentSearchType = ARROUND_SEARCH_TYPE;

    private OnClickListener mPopupWindowClickListener = new OnClickListener() {

        @Override
        public void onClick(View v) {
            switch (v.getId()) {

            case R.id.change_city_linearlayout:
                gotoCityListActivity();
                break;

            default:
                break;
            }

        }
    };

    private OnItemClickListener mGridViewItemListener = new OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {

            mChosenDistrictIndex = arg2;
            mCurrentDistrict = mDistrictsOfCurrentCity[arg2];
            mCurrentCityDistrictTextview.setText(getCurrentCity() + mCurrentDistrict);
            mCoudItemList.clear();
            mAdapter.notifyDataSetChanged();
            searchByLocal(0);
            mPopupWindow.dismiss();
        }
    };
    private String[] mDistrictsOfCurrentCity;
    private int mChosenDistrictIndex = -1;
    private int mFirstVisibleItem;
    private int mVisibleItemCount;
    private RelativeLayout mSearchBarLinearLayout;
    private EditText minputEditText;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_index_list);
        mApplicationContext = this;
        mCoudItemList = getIntent().getParcelableArrayListExtra(BundleFlag.CLOUD_ITEM_LIST);
        Log.i("QQQQ", mCoudItemList.toString());
        // 注册云图搜索监听
        mCloudSearch = new CloudSearch(this);
        mCloudSearch.setOnCloudSearchListener(this);
        if (mCoudItemList == null) {
            showProgressDialog(Const.LODING_GET_DATA);
        } else {
            dissmissProgressDialog();
        }

        setUpInteractiveControls();
        mCurrentCity = getResources().getString(R.string.default_city);

    }

    /**
     * 方法必须重写
     */
    @Override
    protected void onPause() {
        super.onPause();
    }

    private long exitTime = 0;
    private HashMap<String, String[]> mDistrictsOfcityMap = new HashMap<String, String[]>();;

    /**
     * 销毁定位
     */

    /**
     * 进行默认的搜索 类型为根据城市行政区的搜索 默认的城市可以自己配置
     * 
     * @param pagenum
     */
    private void searchDefault(int pagenum) {
        mCurrentCity = getResources().getString(R.string.default_city);
        searchByLocal(pagenum);
    }

    /**
     * 根据经纬度进行周边搜索
     * 
     * @param pagenum
     */
    private void searchByArround(int pagenum) {
        mCurrentSearchType = ARROUND_SEARCH_TYPE;
        if (mCoudItemList == null || mCoudItemList.size() == 0) {
            mCurrentPageNum = 0;
        } else {
            mCurrentPageNum = pagenum;
        }
        showProgressDialog(Const.LODING_GET_DATA);
        SearchBound bound = new SearchBound(new LatLonPoint(mCenterPoint.getLatitude(), mCenterPoint.getLongitude()),
                Const.SEARCH_AROUND);

        try {
            mQuery = new CloudSearch.Query(Const.mTableID, mKeywords, bound);
            mQuery.setPageSize(10);
            mQuery.setPageNum(pagenum);
            mCloudSearch.searchCloudAsyn(mQuery);

        } catch (AMapException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

    }

    /**
     * 根据选择的城市和行政区进行搜索
     * 
     * @param pagenum
     */
    private void searchByLocal(int pagenum) {
        mCurrentSearchType = LOCAL_SEARCH_TYPE;
        if (mCoudItemList == null || mCoudItemList.size() == 0) {
            mCurrentPageNum = 0;
        } else {
            mCurrentPageNum = pagenum;
        }
        showProgressDialog(Const.LODING_GET_DATA);
        String localName = "";
        if (mCurrentDistrict != null && !mCurrentDistrict.equals("") && !mCurrentDistrict.equals(WHOLE_CITY)) {
            localName = getCurrentCity() + mCurrentDistrict;
        } else {
            localName = getCurrentCity();
        }
        SearchBound bound = new SearchBound(localName);
        try {
            mQuery = new CloudSearch.Query(Const.mTableID, mKeywords, bound);
            mQuery.setPageSize(10);
            mQuery.setPageNum(mCurrentPageNum);
            mCloudSearch.searchCloudAsyn(mQuery);
        } catch (AMapException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

    }

    private void setUpInteractiveControls() {

        mLLYNoData = (LinearLayout) findViewById(R.id.lly_noData1);
        minputEditText = (EditText) findViewById(R.id.input_edittext1);
        mSearchBarLinearLayout = (RelativeLayout) findViewById(R.id.search_bar_layout1);
        mCurrentCityDistrictTextview = (TextView) findViewById(R.id.current_city_district_textview1);
        mUpDownArrow = (ImageView) findViewById(R.id.up_down_arrow1);

        mBtnAreaChoose = (LinearLayout) findViewById(R.id.btn_area_choose1);
        mBtnAreaChoose.setOnClickListener(this);

        mBtnMap = (ImageView) findViewById(R.id.btn_map1);
        mBtnMap.setOnClickListener(this);

        // Set a listener to be invoked when the list should be refreshed.
        mPullRefreshListView = (PullToRefreshListView) findViewById(R.id.pull_refresh_list1);
        mPullRefreshListView.setOnRefreshListener(this);
        mPullRefreshListView.setMode(Mode.PULL_FROM_END);
        // Add an end-of-list listener
        mPullRefreshListView.setOnLastItemVisibleListener(this);
        ListView actualListView = mPullRefreshListView.getRefreshableView();
        // Need to use the Actual ListView when registering for Context Menu
        registerForContextMenu(actualListView);
        mAdapter = new CloudItemListAdapter(mApplicationContext, mCoudItemList);
        // You can also just use setListAdapter(mAdapter) or
        // mPullRefreshListView.setAdapter(mAdapter)
        actualListView.setAdapter(mAdapter);
        mPullRefreshListView.setOnScrollListener(this);
    }

    @Override
    public void onClick(View v) {

        switch (v.getId()) {

        case R.id.btn_area_choose1:
            showAreaPopupWindow();
            break;

        case R.id.btn_map1:
            gotoMapActivity();
            break;

        case R.id.input_edittext1:
            gotoKeywordInputActivity();
            break;

        default:
            break;
        }

    }

    private void gotoKeywordInputActivity() {

        Intent intent = new Intent(this, KeywordListActivity.class);
        startActivityForResult(intent, POI_CHOOSE_REQUEST_CODE);
    }

    private void gotoMapActivity() {

        this.finish();
    }

    private void showAreaPopupWindow() {

        mPopupWindow = new CityChoosePopupWindow1(this, mPopupWindowClickListener);

        mPopupWindow.showAsDropDown(mSearchBarLinearLayout);
        mUpDownArrow.setBackgroundResource(R.drawable.arrow_down_white);

        mPopupWindow.setOnDismissListener(new OnDismissListener() {

            @Override
            public void onDismiss() {
                mUpDownArrow.setBackgroundResource(R.drawable.arrow_up_white);
            }
        });

        if (mCityLetterList == null || mCityList == null || mCityMap == null)
            createCityListForCityChoose();

        updatePopupWindowData();

    }

    private void updatePopupWindowData() {

        mDistrictsOfCurrentCity = getDistrictsBasedonCityName(getCurrentCity());

        mPopupWindow.getDistrictGridView()
                .setAdapter(new DistrictListAdapter(this, mDistrictsOfCurrentCity, mChosenDistrictIndex));

        mPopupWindow.getDistrictGridView().setOnItemClickListener(mGridViewItemListener);

        mPopupWindow.getCurrentCityTextView().setText(getCurrentCity());

        mCurrentCityDistrictTextview.setText(getCurrentCity());
    }

    private void createCityListForCityChoose() {
        try {
            String content = Utils.getAssetsFie(this, "city.json");
            dealWithJson(content);
        } catch (IOException e) {
            Log.e("aaa", "city init failed", e);
        }
    }

    private void dealWithJson(String content) {

        try {
            JSONObject json = new JSONObject(content);
            String status = json.getString("status");
            if ("200".equals(status)) {
                JSONObject result = json.getJSONObject("result");
                int cityVersion = result.optInt("version");
                JSONObject data = result.getJSONObject("city");
                HashMap<String, Integer> tempCityHashMap = new HashMap<String, Integer>();
                ArrayList<String> temp_city_letter_list = new ArrayList<String>();
                ArrayList<City> tempCityList = new ArrayList<City>();
                for (int m = 0; m < mLetterStrs.length; m++) {
                    String key = mLetterStrs[m];
                    JSONArray array = data.optJSONArray(key);
                    if (array == null) {
                        continue;
                    }
                    temp_city_letter_list.add(key);
                    for (int i = 0; i < array.length(); i++) {
                        JSONObject json_city = array.getJSONObject(i);
                        City model_item = new City();
                        model_item.name = json_city.optString("name");
                        model_item.code = json_city.optString("cityCode");
                        if (i == 0) {
                            model_item.letter = key;
                            tempCityHashMap.put(key, tempCityList.size());
                        }
                        tempCityList.add(model_item);
                    }
                }

                if (mCityList == null || mCityList.size() <= 0) {
                    mCityList = tempCityList;
                    mCityMap = tempCityHashMap;
                    mCityLetterList = temp_city_letter_list;
                }
            } else {
                if (mCityList == null || mCityList.size() <= 0) {
                    showErrorDialog(getString(R.string.city_get_error));
                }

            }
        } catch (JSONException e) {
            e.printStackTrace();
        }

    }

    private void showErrorDialog(String string) {

        Dialog dialog = new Dialog(this);

        dialog.setOnCancelListener(new OnCancelListener() {

            @Override
            public void onCancel(DialogInterface dialog) {
                // TODO Auto-generated method stub

            }
        });

        dialog.show();

    }

    private void gotoCityListActivity() {

        Intent intent = new Intent(this, CityListActivity.class);
        intent.putExtra(BundleFlag.CITY_LIST, mCityList);
        intent.putStringArrayListExtra(BundleFlag.CITY_LETTERS, mCityLetterList);
        intent.putExtra(BundleFlag.CITY_MAP, mCityMap);
        startActivityForResult(intent, CITY_CHOOSE_REQUEST_CODE);

    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        if (CITY_CHOOSE_REQUEST_CODE == requestCode && resultCode == BundleResult.SUCCESS) {
            City city = (City) data.getSerializableExtra(BundleFlag.CITY_MODEL);
            if (city != null) {
                setCity(city);
            }
            mCoudItemList.clear();
            mAdapter.notifyDataSetChanged();
            mCurrentDistrict = "";
            searchByLocal(0);
            return;
        }

        if (requestCode == POI_CHOOSE_REQUEST_CODE && resultCode == BundleResult.SUCCESS) {
            String selectedItem = (String) data.getSerializableExtra(BundleFlag.POI_ITEM);
            mKeywords = selectedItem;
            mCoudItemList.clear();
            mAdapter.notifyDataSetChanged();
            searchByLocal(0);
            minputEditText.setText(selectedItem);
            return;
        }

        super.onActivityResult(requestCode, resultCode, data);
    }

    private void setCity(City city) {
        mChosenDistrictIndex = -1;
        setCurrentCity(city.name.toString());
        updatePopupWindowData();
    }

    /**
     * 根据城市名字,得到该城市下对应的所有行政区的字符串数组
     * 
     * @param city
     * @return
     */
    private String[] getDistrictsBasedonCityName(String city) {

        if (mDistrictsOfcityMap.containsKey(city)) {
            return mDistrictsOfcityMap.get(city);
        }

        CityUtil cityUtil = new CityUtil(this, city);
        List<String> lists = cityUtil.getItsDistricts();
        String[] districtsOfThisCity = lists.toArray(new String[lists.size()]);
        mDistrictsOfcityMap.put(city, districtsOfThisCity);

        return districtsOfThisCity;
    }

    private void showProgressDialog(String message) {
        mProgressDialog = ToastUtil.createLoadingDialog(this, message);
        mProgressDialog.setCancelable(true);
        mProgressDialog.show();
    }

    private void dissmissProgressDialog() {
        if (mProgressDialog != null && mProgressDialog.isShowing()) {
            mProgressDialog.dismiss();
        }
    }

    @Override
    public void onLastItemVisible() {
        // TODO Auto-generated method stub
    }

    @Override
    public void onCloudItemDetailSearched(CloudItemDetail item, int errorCode) {
        // TODO Auto-generated method stub

    }

    @Override
    public void onCloudSearched(CloudResult result, int errorCode) {
        // TODO Auto-generated method stub
        mPullRefreshListView.onRefreshComplete();
        mPullRefreshListView.clearAnimation();
        dissmissProgressDialog();
        if (errorCode == 1000 && result != null) {
            ArrayList<CloudItem> cloudResult = result.getClouds();
            Log.i("QWQWR", 1 + "");
            if (cloudResult != null && cloudResult.size() > 0) {
                mCoudItemList.addAll(cloudResult);
                mAdapter.notifyDataSetChanged();
            } else {
                Toast.makeText(mApplicationContext, R.string.error_no_more_item, Toast.LENGTH_SHORT).show();
            }

        } else if (errorCode == Const.ERROR_CODE_SOCKE_TIME_OUT) {
            ToastUtil.show(this.getApplicationContext(), R.string.error_socket_timeout);
        } else if (errorCode == Const.ERROR_CODE_UNKNOW_HOST) {
            ToastUtil.show(this.getApplicationContext(), R.string.error_network);
        } else if (errorCode == Const.ERROR_CODE_FAILURE_AUTH) {
            ToastUtil.show(this.getApplicationContext(), R.string.error_key);
        } else if (errorCode == Const.ERROR_CODE_SCODE) {
            ToastUtil.show(this.getApplicationContext(), R.string.error_scode);
        } else if (errorCode == Const.ERROR_CODE_TABLEID) {
            ToastUtil.show(this.getApplicationContext(), R.string.error_table_id);
        } else {
            ToastUtil.show(this.getApplicationContext(), getString(R.string.error_other) + errorCode);
        }
        if (mCoudItemList == null || mCoudItemList.size() == 0) {
            // mPullRefreshListView.setMode(Mode.DISABLED);
            mLLYNoData.setVisibility(View.VISIBLE);
        } else {
            mLLYNoData.setVisibility(View.GONE);
            // mPullRefreshListView.setMode(Mode.PULL_FROM_END);
        }
    }

    public String getCurrentCity() {
        return mCurrentCity;
    }

    private void setCurrentCity(String mCurrentCity) {
        if (mCurrentCity == null)
            mCurrentCity = "未能定位当前城市";
        mCurrentCity = mCurrentCity.replace("市", "");
        mCurrentCityDistrictTextview.setText(mCurrentCity);
        this.mCurrentCity = mCurrentCity;
    }

    @Override
    public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {

        mFirstVisibleItem = firstVisibleItem;
        mVisibleItemCount = visibleItemCount;

    }

    @Override
    public void onScrollStateChanged(AbsListView view, int scrollState) {
        // TODO Auto-generated method stub

    }

    /**
     * 地理位置变化回调
     */

    @Override
    public void onRefresh(PullToRefreshBase<ListView> refreshView) {
        // TODO Auto-generated method stub
        ILoadingLayout endLabels = mPullRefreshListView.getLoadingLayoutProxy(false, true);
        endLabels.setPullLabel(getResources().getString(R.string.pull_label));
        endLabels.setRefreshingLabel(getResources().getString(R.string.refresh_label));
        endLabels.setReleaseLabel(getResources().getString(R.string.release_label));
        endLabels.setLoadingDrawable(getResources().getDrawable(R.drawable.publicloading));
        mCurrentPageNum++;
        if (mCurrentSearchType == ARROUND_SEARCH_TYPE) {
            searchByArround(mCurrentPageNum);
        } else {
            searchByLocal(mCurrentPageNum);
        }
    }
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值