智慧城市 v1.2.1版本的 MD5 值为:d4aeacb5153a2710d0b6882be5dd2b15

以下内容为反编译后的 AMapLocationActivity2D.java 源代码,内容仅作参考


package io.rong.imkit.feature.location;

import android.animation.Animator;
import android.animation.AnimatorListenerAdapter;
import android.animation.ValueAnimator;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.location.Location;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.text.TextUtils;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewConfiguration;
import android.view.ViewGroup;
import android.view.animation.DecelerateInterpolator;
import android.widget.AbsListView;
import android.widget.AdapterView;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.ListAdapter;
import android.widget.ListView;
import android.widget.ProgressBar;
import android.widget.TextView;
import android.widget.Toast;
import androidx.appcompat.app.AlertDialog;
import com.amap.api.maps2d.AMap;
import com.amap.api.maps2d.CameraUpdate;
import com.amap.api.maps2d.CameraUpdateFactory;
import com.amap.api.maps2d.LocationSource;
import com.amap.api.maps2d.MapView;
import com.amap.api.maps2d.model.BitmapDescriptor;
import com.amap.api.maps2d.model.BitmapDescriptorFactory;
import com.amap.api.maps2d.model.CameraPosition;
import com.amap.api.maps2d.model.LatLng;
import com.amap.api.maps2d.model.Marker;
import com.amap.api.maps2d.model.MarkerOptions;
import com.amap.api.maps2d.model.MyLocationStyle;
import com.amap.api.services.core.LatLonPoint;
import com.amap.api.services.core.PoiItem;
import com.amap.api.services.geocoder.GeocodeResult;
import com.amap.api.services.geocoder.GeocodeSearch;
import com.amap.api.services.geocoder.RegeocodeAddress;
import com.amap.api.services.geocoder.RegeocodeQuery;
import com.amap.api.services.geocoder.RegeocodeResult;
import com.amap.api.services.poisearch.PoiResult;
import com.amap.api.services.poisearch.PoiSearch;
import io.rong.common.RLog;
import io.rong.imkit.R;
import io.rong.imkit.activity.RongBaseActivity;
import io.rong.imkit.utils.RongUtils;
import java.util.ArrayList;
import java.util.List;
public class AMapLocationActivity2D extends RongBaseActivity implements LocationSource, AMap.OnCameraChangeListener, GeocodeSearch.OnGeocodeSearchListener, IMyLocationChangedListener, View.OnClickListener {
    private static final int PAGE_COUNT = 20;
    private static final int REQUEST_CODE_ASK_PERMISSIONS = 100;
    private static final int REQUEST_OPEN_LOCATION_SERVICE = 50;
    private static final int REQUEST_SEARCH_LOCATION = 1;
    private static final String TAG = "AMapLocationActivity2D";
    private float Y;
    ValueAnimator animator;
    private float downY;
    private float lastY;
    private ProgressBar listLoadingView;
    private ListView listViewNearby;
    private AMap mAMap;
    private MapView mAMapView;
    private BitmapDescriptor mBitmapDescriptor;
    private GeocodeSearch mGeocodeSearch;
    private Handler mHandler;
    private double mLatResult;
    private double mLngResult;
    private LocationSource.OnLocationChangedListener mLocationChangedListener;
    private TextView mLocationTip;
    private Marker mMarker;
    private double mMyLat;
    private double mMyLng;
    private String mMyPoi;
    private String mPoiResult;
    private int mTouchSlop;
    private NearbyListAdapter nearbyListAdapter;
    private int currentPage = 1;
    private int flag = 0;
    private String cityCode = "";
    private AbsListView.OnScrollListener onScrollListener = new AbsListView.OnScrollListener() {
        @Override
        public void onScrollStateChanged(AbsListView absListView, int i) {
        }

        @Override
        public void onScroll(AbsListView absListView, int i, int i2, int i3) {
            View childAt;
            if (i == 0 || i + i2 != i3 || (childAt = AMapLocationActivity2D.this.listViewNearby.getChildAt(AMapLocationActivity2D.this.listViewNearby.getChildCount() - 1)) == null || childAt.getBottom() != AMapLocationActivity2D.this.listViewNearby.getHeight()) {
                return;
            }
            AMapLocationActivity2D.this.loadNextPageNearByView();
        }
    };

    public enum ScrollDirection {
        SCROLL_UP,
        SCROLL_DOWN
    }

    public void deactivate() {
    }

    public void onGeocodeSearched(GeocodeResult geocodeResult, int i) {
    }

    @Override
    public void onCreate(Bundle bundle) {
        super.onCreate(bundle);
        if (!LocationDelegate2D.getInstance().isBindedConversation()) {
            finish();
            return;
        }
        setContentView(R.layout.rc_location_2d_activity);
        initStatusBar(R.color.app_color_white);
        this.mAMapView = findViewById(R.id.rc_ext_amap);
        initNearbyView();
        this.mHandler = new Handler();
        this.mLocationTip = (TextView) findViewById(R.id.rc_ext_location_marker);
        ((ImageView) findViewById(R.id.rc_ext_my_location)).setOnClickListener(this);
        Button button = (Button) findViewById(R.id.rc_action_bar_ok);
        button.setText(getResources().getString(R.string.rc_send));
        button.setVisibility(0);
        button.setOnClickListener(this);
        this.mTitleBar.setTitle(R.string.rc_location_title);
        this.mAMapView.onCreate(bundle);
        if (RongUtils.isLocationServiceEnabled(this)) {
            initMap();
        } else {
            new AlertDialog.Builder(this).setTitle(getString(R.string.rc_location_sevice_dialog_title)).setMessage(getString(R.string.rc_location_sevice_dialog_messgae)).setPositiveButton(getString(R.string.rc_location_sevice_dialog_confirm), new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialogInterface, int i) {
                    try {
                        AMapLocationActivity2D.this.startActivityForResult(new Intent("android.settings.LOCATION_SOURCE_SETTINGS"), 50);
                    } catch (Exception unused) {
                        AMapLocationActivity2D.this.startActivityForResult(new Intent("android.settings.SETTINGS"), 50);
                    }
                }
            }).create().show();
        }
    }

    @Override
    public void onRequestPermissionsResult(int i, String[] strArr, int[] iArr) {
        if (i == 100) {
            if (iArr[0] == 0 && strArr[0].equals("android.permission.ACCESS_COARSE_LOCATION")) {
                initMap();
                return;
            }
            return;
        }
        super.onRequestPermissionsResult(i, strArr, iArr);
    }

    private void initMap() {
        AMap map = this.mAMapView.getMap();
        this.mAMap = map;
        map.setLocationSource(this);
        this.mAMap.setMyLocationEnabled(true);
        this.mAMap.getUiSettings().setZoomControlsEnabled(false);
        this.mAMap.getUiSettings().setMyLocationButtonEnabled(false);
        this.mAMap.setMapType(1);
        MyLocationStyle myLocationStyle = new MyLocationStyle();
        myLocationStyle.myLocationIcon(BitmapDescriptorFactory.fromResource(R.drawable.rc_location_my_locator));
        myLocationStyle.strokeWidth(0.0f);
        myLocationStyle.strokeColor(R.color.rc_main_theme);
        myLocationStyle.radiusFillColor(0);
        this.mAMap.setMyLocationStyle(myLocationStyle);
        GeocodeSearch geocodeSearch = new GeocodeSearch(this);
        this.mGeocodeSearch = geocodeSearch;
        geocodeSearch.setOnGeocodeSearchListener(this);
        LocationDelegate2D.getInstance().setMyLocationChangedListener(this);
    }

    public void onRegeocodeSearched(RegeocodeResult regeocodeResult, int i) {
        RLog.e(TAG, "onRegeocodeSearched");
        if (regeocodeResult != null) {
            RegeocodeAddress regeocodeAddress = regeocodeResult.getRegeocodeAddress();
            this.mLatResult = regeocodeResult.getRegeocodeQuery().getPoint().getLatitude();
            this.mLngResult = regeocodeResult.getRegeocodeQuery().getPoint().getLongitude();
            String replace = regeocodeResult.getRegeocodeAddress().getFormatAddress().replace(regeocodeAddress.getProvince(), "").replace(regeocodeAddress.getCity(), "").replace(regeocodeAddress.getDistrict(), "");
            this.mPoiResult = replace;
            this.mLocationTip.setText(replace);
            LatLng latLng = new LatLng(this.mLatResult, this.mLngResult);
            Marker marker = this.mMarker;
            if (marker != null) {
                marker.setPosition(latLng);
            }
            updateNearByView(this.mPoiResult);
            return;
        }
        Toast.makeText(this, getString(R.string.rc_location_fail), 0).show();
    }

    private String getMapUrl(double d, double d2) {
        return "http://restapi.amap.com/v3/staticmap?location=" + d2 + "," + d + "&zoom=16&scale=2&size=408*240&markers=mid,,A:" + d2 + "," + d + "&key=e09af6a2b26c02086e9216bd07c960ae";
    }

    public void activate(LocationSource.OnLocationChangedListener onLocationChangedListener) {
        this.mLocationChangedListener = onLocationChangedListener;
    }

    public void onCameraChange(CameraPosition cameraPosition) {
        RLog.d(TAG, "onCameraChange");
        if (Build.VERSION.SDK_INT < 11) {
            this.mMarker.setPosition(cameraPosition.target);
        }
    }

    public void onCameraChangeFinish(CameraPosition cameraPosition) {
        RLog.d(TAG, "onCameraChangeFinish");
        this.mGeocodeSearch.getFromLocationAsyn(new RegeocodeQuery(new LatLonPoint(cameraPosition.target.latitude, cameraPosition.target.longitude), 50.0f, "autonavi"));
        if (this.mMarker != null) {
            animMarker();
        }
    }

    public void addLocatedMarker(LatLng latLng, String str) {
        this.mBitmapDescriptor = BitmapDescriptorFactory.fromResource(R.drawable.rc_location_marker);
        MarkerOptions icon = new MarkerOptions().position(latLng).icon(this.mBitmapDescriptor);
        Marker marker = this.mMarker;
        if (marker != null) {
            marker.remove();
        }
        Marker addMarker = this.mAMap.addMarker(icon);
        this.mMarker = addMarker;
        addMarker.setPositionByPixels(this.mAMapView.getWidth() / 2, this.mAMapView.getHeight() / 2);
        this.mLocationTip.setText(String.format("%s", str));
    }

    private void animMarker() {
        if (Build.VERSION.SDK_INT > 11) {
            ValueAnimator valueAnimator = this.animator;
            if (valueAnimator != null) {
                valueAnimator.start();
                return;
            }
            ValueAnimator ofFloat = ValueAnimator.ofFloat(this.mAMapView.getHeight() / 2, (float) ((this.mAMapView.getHeight() / 2) - 30));
            this.animator = ofFloat;
            ofFloat.setInterpolator(new DecelerateInterpolator());
            this.animator.setDuration(150L);
            this.animator.setRepeatCount(1);
            this.animator.setRepeatMode(2);
            this.animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
                @Override
                public void onAnimationUpdate(ValueAnimator valueAnimator2) {
                    RLog.d(AMapLocationActivity2D.TAG, "onAnimationUpdate");
                    AMapLocationActivity2D.this.mMarker.setPositionByPixels(AMapLocationActivity2D.this.mAMapView.getWidth() / 2, Math.round(((Float) valueAnimator2.getAnimatedValue()).floatValue()));
                }
            });
            this.animator.addListener(new AnimatorListenerAdapter() {
                @Override
                public void onAnimationEnd(Animator animator) {
                    AMapLocationActivity2D.this.mMarker.setIcon(AMapLocationActivity2D.this.mBitmapDescriptor);
                }
            });
            this.animator.start();
        }
    }

    @Override
    public void onDestroy() {
        MapView mapView = this.mAMapView;
        if (mapView != null) {
            mapView.onDestroy();
        }
        LocationDelegate2D.getInstance().setMyLocationChangedListener(null);
        super.onDestroy();
    }

    @Override
    public void onMyLocationChanged(final AMapLocationInfo aMapLocationInfo) {
        RLog.d(TAG, "onLocationChanged");
        if (this.mLocationChangedListener != null) {
            this.mHandler.post(new Runnable() {
                @Override
                public void run() {
                    AMapLocationInfo aMapLocationInfo2 = aMapLocationInfo;
                    if (aMapLocationInfo2 != null) {
                        AMapLocationActivity2D aMapLocationActivity2D = AMapLocationActivity2D.this;
                        aMapLocationActivity2D.mMyLat = aMapLocationActivity2D.mLatResult = aMapLocationInfo2.getLat();
                        AMapLocationActivity2D aMapLocationActivity2D2 = AMapLocationActivity2D.this;
                        aMapLocationActivity2D2.mMyLng = aMapLocationActivity2D2.mLngResult = aMapLocationInfo.getLng();
                        AMapLocationActivity2D aMapLocationActivity2D3 = AMapLocationActivity2D.this;
                        aMapLocationActivity2D3.mMyPoi = aMapLocationActivity2D3.mPoiResult = aMapLocationInfo.getStreet() + aMapLocationInfo.getPoiname();
                        AMapLocationActivity2D.this.cityCode = aMapLocationInfo.getCitycode();
                        AMapLocationActivity2D aMapLocationActivity2D4 = AMapLocationActivity2D.this;
                        aMapLocationActivity2D4.updateNearByView(aMapLocationActivity2D4.mMyPoi);
                        Location location = new Location("AMap");
                        location.setLatitude(aMapLocationInfo.getLat());
                        location.setLongitude(aMapLocationInfo.getLng());
                        location.setTime(aMapLocationInfo.getTime());
                        location.setAccuracy(aMapLocationInfo.getAccuracy());
                        AMapLocationActivity2D.this.mLocationChangedListener.onLocationChanged(location);
                        LatLng latLng = new LatLng(AMapLocationActivity2D.this.mLatResult, AMapLocationActivity2D.this.mLngResult);
                        AMapLocationActivity2D aMapLocationActivity2D5 = AMapLocationActivity2D.this;
                        aMapLocationActivity2D5.addLocatedMarker(latLng, aMapLocationActivity2D5.mPoiResult);
                        AMapLocationActivity2D.this.mAMap.animateCamera(CameraUpdateFactory.changeLatLng(latLng), new AMap.CancelableCallback() {
                            public void onCancel() {
                            }

                            public void onFinish() {
                                AMapLocationActivity2D.this.mAMap.setOnCameraChangeListener(AMapLocationActivity2D.this);
                            }
                        });
                        return;
                    }
                    AMapLocationActivity2D aMapLocationActivity2D6 = AMapLocationActivity2D.this;
                    Toast.makeText(aMapLocationActivity2D6, aMapLocationActivity2D6.getString(R.string.rc_location_fail), 0).show();
                }
            });
        }
    }

    private void initNearbyView() {
        this.listViewNearby = (ListView) findViewById(R.id.rc_list_nearby);
        this.listLoadingView = (ProgressBar) findViewById(R.id.rc_ext_loading);
        this.listViewNearby.setVisibility(8);
        this.listLoadingView.setVisibility(0);
        this.mTouchSlop = ViewConfiguration.get(this).getScaledTouchSlop();
        this.listViewNearby.setOnScrollListener(this.onScrollListener);
        this.listViewNearby.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> adapterView, View view, int i, long j) {
                for (int i2 = 0; i2 < AMapLocationActivity2D.this.nearbyListAdapter.getCount(); i2++) {
                    MapNearbyInfo mapNearbyInfo = (MapNearbyInfo) AMapLocationActivity2D.this.nearbyListAdapter.getItem(i2);
                    if (i2 == i) {
                        mapNearbyInfo.setChecked(true);
                        AMapLocationActivity2D.this.mLngResult = mapNearbyInfo.getLongitude();
                        AMapLocationActivity2D.this.mLatResult = mapNearbyInfo.getLatitude();
                        AMapLocationActivity2D.this.mPoiResult = mapNearbyInfo.getPoi();
                        AMapLocationActivity2D aMapLocationActivity2D = AMapLocationActivity2D.this;
                        aMapLocationActivity2D.updateCheckedMapView(aMapLocationActivity2D.mLngResult, AMapLocationActivity2D.this.mLatResult, AMapLocationActivity2D.this.mPoiResult);
                    } else {
                        mapNearbyInfo.setChecked(false);
                    }
                }
                AMapLocationActivity2D.this.nearbyListAdapter.notifyDataSetChanged();
            }
        });
        this.listViewNearby.setOnTouchListener(new View.OnTouchListener() {
            @Override
            public boolean onTouch(View view, MotionEvent motionEvent) {
                AMapLocationActivity2D.this.Y = motionEvent.getRawY();
                int action = motionEvent.getAction();
                if (action == 0) {
                    AMapLocationActivity2D aMapLocationActivity2D = AMapLocationActivity2D.this;
                    aMapLocationActivity2D.downY = aMapLocationActivity2D.Y;
                    AMapLocationActivity2D aMapLocationActivity2D2 = AMapLocationActivity2D.this;
                    aMapLocationActivity2D2.lastY = aMapLocationActivity2D2.Y;
                } else if (action != 1) {
                    if (action == 2 && Math.abs(AMapLocationActivity2D.this.Y - AMapLocationActivity2D.this.downY) > AMapLocationActivity2D.this.mTouchSlop) {
                        if (AMapLocationActivity2D.this.Y - AMapLocationActivity2D.this.downY >= 0.0f && AMapLocationActivity2D.this.Y - AMapLocationActivity2D.this.lastY >= 0.0f) {
                            AMapLocationActivity2D aMapLocationActivity2D3 = AMapLocationActivity2D.this;
                            aMapLocationActivity2D3.lastY = aMapLocationActivity2D3.Y;
                            return AMapLocationActivity2D.this.handleScrollState(ScrollDirection.SCROLL_DOWN);
                        }
                        AMapLocationActivity2D aMapLocationActivity2D4 = AMapLocationActivity2D.this;
                        aMapLocationActivity2D4.lastY = aMapLocationActivity2D4.Y;
                        return AMapLocationActivity2D.this.handleScrollState(ScrollDirection.SCROLL_UP);
                    }
                } else {
                    AMapLocationActivity2D.this.Y = 0.0f;
                    if (AMapLocationActivity2D.this.flag == 1) {
                        AMapLocationActivity2D.this.flag = 0;
                        return true;
                    }
                    AMapLocationActivity2D.this.lastY = 0.0f;
                }
                return false;
            }
        });
    }

    public boolean handleScrollState(ScrollDirection scrollDirection) {
        int dimension = (int) getResources().getDimension(R.dimen.rc_location_nearby_list_min_height);
        int dimension2 = (int) getResources().getDimension(R.dimen.rc_location_nearby_list_max_height);
        if (scrollDirection == ScrollDirection.SCROLL_DOWN) {
            return updateListViewHeight(dimension2, dimension);
        }
        return updateListViewHeight(dimension, dimension2);
    }

    private boolean updateListViewHeight(int i, int i2) {
        int height = this.listViewNearby.getHeight();
        ListView listView = this.listViewNearby;
        if (listView != null && listView.getChildAt(0) != null) {
            if (this.listViewNearby.getChildAt(0).getTop() == 0 && Math.abs(this.Y - this.downY) > this.mTouchSlop && this.flag == 0 && height == i) {
                this.flag = 1;
            }
            if (this.flag == 1) {
                ViewGroup.LayoutParams layoutParams = this.listViewNearby.getLayoutParams();
                layoutParams.height = i2;
                this.listViewNearby.setLayoutParams(layoutParams);
                LatLng latLng = new LatLng(this.mLatResult, this.mLngResult);
                Marker marker = this.mMarker;
                if (marker != null) {
                    marker.setPosition(latLng);
                }
                FrameLayout.LayoutParams layoutParams2 = (FrameLayout.LayoutParams) this.mLocationTip.getLayoutParams();
                if (i < i2) {
                    layoutParams2.setMargins(RongUtils.dip2px(20.0f), RongUtils.dip2px(3.0f), RongUtils.dip2px(20.0f), 0);
                    this.mLocationTip.setLayoutParams(layoutParams2);
                } else {
                    layoutParams2.setMargins(RongUtils.dip2px(20.0f), RongUtils.dip2px(20.0f), RongUtils.dip2px(20.0f), 0);
                    this.mLocationTip.setLayoutParams(layoutParams2);
                }
                return true;
            }
        }
        return false;
    }

    public void updateNearByView(final String str) {
        PoiSearch.Query query = new PoiSearch.Query("", LocationConst.CATEGORY, "");
        query.setPageSize(20);
        this.currentPage = 1;
        query.setPageNum(1);
        PoiSearch poiSearch = new PoiSearch(this, query);
        double d = this.mLngResult;
        double d2 = this.mLatResult;
        if (d2 != 0.0d && d != 0.0d) {
            poiSearch.setBound(new PoiSearch.SearchBound(new LatLonPoint(d2, d), (int) LocationConst.DISTANCE));
            poiSearch.setOnPoiSearchListener(new PoiSearch.OnPoiSearchListener() {
                public void onPoiItemSearched(PoiItem poiItem, int i) {
                }

                public void onPoiSearched(PoiResult poiResult, int i) {
                    if (poiResult == null || poiResult.getPois().size() <= 0) {
                        return;
                    }
                    ArrayList arrayList = new ArrayList();
                    ArrayList pois = poiResult.getPois();
                    MapNearbyInfo mapNearbyInfo = new MapNearbyInfo();
                    mapNearbyInfo.setName(str);
                    mapNearbyInfo.setChecked(true);
                    mapNearbyInfo.setLongitude(AMapLocationActivity2D.this.mLngResult);
                    mapNearbyInfo.setLatitude(AMapLocationActivity2D.this.mLatResult);
                    mapNearbyInfo.setPoi(str);
                    arrayList.add(mapNearbyInfo);
                    for (int i2 = 0; i2 < pois.size(); i2++) {
                        PoiItem poiItem = (PoiItem) pois.get(i2);
                        MapNearbyInfo mapNearbyInfo2 = new MapNearbyInfo(poiItem.getTitle(), poiItem.getSnippet());
                        mapNearbyInfo2.setLongitude(poiItem.getLatLonPoint().getLongitude());
                        mapNearbyInfo2.setLatitude(poiItem.getLatLonPoint().getLatitude());
                        mapNearbyInfo2.setPoi(poiItem.getTitle());
                        arrayList.add(mapNearbyInfo2);
                    }
                    AMapLocationActivity2D aMapLocationActivity2D = AMapLocationActivity2D.this;
                    AMapLocationActivity2D aMapLocationActivity2D2 = AMapLocationActivity2D.this;
                    aMapLocationActivity2D.nearbyListAdapter = new NearbyListAdapter(aMapLocationActivity2D2, arrayList);
                    AMapLocationActivity2D.this.listViewNearby.setAdapter((ListAdapter) AMapLocationActivity2D.this.nearbyListAdapter);
                    AMapLocationActivity2D.this.listViewNearby.setVisibility(0);
                    AMapLocationActivity2D.this.listLoadingView.setVisibility(8);
                }
            });
            poiSearch.searchPOIAsyn();
            return;
        }
        this.listViewNearby.setVisibility(0);
        this.listLoadingView.setVisibility(8);
        Toast.makeText(this, getResources().getString(R.string.rc_location_fail), 0).show();
    }

    public void loadNextPageNearByView() {
        PoiSearch.Query query = new PoiSearch.Query("", LocationConst.CATEGORY, "");
        query.setPageSize(20);
        int i = this.currentPage + 1;
        this.currentPage = i;
        query.setPageNum(i);
        PoiSearch poiSearch = new PoiSearch(this, query);
        double d = this.mLngResult;
        double d2 = this.mLatResult;
        if (d2 != 0.0d && d != 0.0d) {
            poiSearch.setBound(new PoiSearch.SearchBound(new LatLonPoint(d2, d), (int) LocationConst.DISTANCE));
            poiSearch.setOnPoiSearchListener(new PoiSearch.OnPoiSearchListener() {
                public void onPoiItemSearched(PoiItem poiItem, int i2) {
                }

                public void onPoiSearched(PoiResult poiResult, int i2) {
                    if (poiResult == null || poiResult.getPois().size() <= 0) {
                        return;
                    }
                    ArrayList arrayList = new ArrayList();
                    ArrayList pois = poiResult.getPois();
                    for (int i3 = 0; i3 < pois.size(); i3++) {
                        PoiItem poiItem = (PoiItem) pois.get(i3);
                        MapNearbyInfo mapNearbyInfo = new MapNearbyInfo(poiItem.getTitle(), poiItem.getSnippet());
                        mapNearbyInfo.setLongitude(poiItem.getLatLonPoint().getLongitude());
                        mapNearbyInfo.setLatitude(poiItem.getLatLonPoint().getLatitude());
                        mapNearbyInfo.setPoi(poiItem.getTitle());
                        arrayList.add(mapNearbyInfo);
                    }
                    AMapLocationActivity2D.this.nearbyListAdapter.addItems(arrayList);
                    AMapLocationActivity2D.this.nearbyListAdapter.notifyDataSetChanged();
                }
            });
            poiSearch.searchPOIAsyn();
            return;
        }
        Toast.makeText(this, getResources().getString(R.string.rc_location_fail), 0).show();
    }

    @Override
    public void onClick(View view) {
        if (view.getId() == R.id.rc_ext_my_location) {
            handleMyLocation();
        } else if (view.getId() == R.id.rc_action_bar_ok) {
            handleOkButton();
        } else if (view.getId() == R.id.rc_search) {
            Intent intent = new Intent(this, SearchLocationActivity.class);
            intent.putExtra(LocationConst.CITY_CODE, this.cityCode);
            startActivityForResult(intent, 1);
        }
    }

    private void handleMyLocation() {
        if (this.mMyPoi != null) {
            this.mAMap.setOnCameraChangeListener((AMap.OnCameraChangeListener) null);
            this.mAMap.animateCamera(CameraUpdateFactory.changeLatLng(new LatLng(this.mMyLat, this.mMyLng)), new AMap.CancelableCallback() {
                public void onCancel() {
                }

                public void onFinish() {
                    AMapLocationActivity2D.this.mAMap.setOnCameraChangeListener(AMapLocationActivity2D.this);
                }
            });
            this.mLocationTip.setText(this.mMyPoi);
            this.mLatResult = this.mMyLat;
            this.mLngResult = this.mMyLng;
            this.mPoiResult = this.mMyPoi;
            LatLng latLng = new LatLng(this.mLatResult, this.mLngResult);
            updateNearByView(this.mMyPoi);
            Marker marker = this.mMarker;
            if (marker != null) {
                marker.setPosition(latLng);
                return;
            }
            return;
        }
        LocationDelegate2D.getInstance().updateMyLocation();
    }

    private void handleOkButton() {
        if (this.mLatResult == 0.0d && this.mLngResult == 0.0d && TextUtils.isEmpty(this.mPoiResult)) {
            Toast.makeText(this, getString(R.string.rc_location_temp_failed), 0).show();
            return;
        }
        Intent intent = new Intent();
        intent.putExtra("thumb", getMapUrl(this.mLatResult, this.mLngResult));
        intent.putExtra("lat", this.mLatResult);
        intent.putExtra("lng", this.mLngResult);
        intent.putExtra(LocationConst.POI, this.mPoiResult);
        setResult(-1, intent);
        finish();
    }

    @Override
    public void onActivityResult(int i, int i2, Intent intent) {
        super.onActivityResult(i, i2, intent);
        if (i != 1 || intent == null) {
            if (i == 50) {
                initMap();
                return;
            }
            return;
        }
        this.mLngResult = intent.getDoubleExtra(LocationConst.LONGITUDE, 0.0d);
        this.mLatResult = intent.getDoubleExtra(LocationConst.LATITUDE, 0.0d);
        this.mPoiResult = intent.getStringExtra(LocationConst.POI);
        resetViewHeight();
        updateToPosition(this.mLngResult, this.mLatResult, this.mPoiResult, true);
    }

    private void resetViewHeight() {
        if (this.listViewNearby != null) {
            ViewGroup.LayoutParams layoutParams = this.listViewNearby.getLayoutParams();
            layoutParams.height = (int) getResources().getDimension(R.dimen.rc_location_nearby_list_min_height);
            this.listViewNearby.setLayoutParams(layoutParams);
        }
        final FrameLayout.LayoutParams layoutParams2 = (FrameLayout.LayoutParams) this.mLocationTip.getLayoutParams();
        layoutParams2.setMargins(RongUtils.dip2px(20.0f), RongUtils.dip2px(20.0f), RongUtils.dip2px(20.0f), 0);
        this.mLocationTip.post(new Runnable() {
            @Override
            public void run() {
                AMapLocationActivity2D.this.mLocationTip.setLayoutParams(layoutParams2);
            }
        });
    }

    private void updateToPosition(double d, double d2, String str, boolean z) {
        if (str != null) {
            this.mLatResult = d2;
            this.mLngResult = d;
            this.mPoiResult = str;
            this.mLocationTip.setText(str);
            if (z) {
                updateNearByView(this.mPoiResult);
            }
            final LatLng latLng = new LatLng(this.mLatResult, this.mLngResult);
            CameraUpdate changeLatLng = CameraUpdateFactory.changeLatLng(latLng);
            this.mAMap.setOnCameraChangeListener((AMap.OnCameraChangeListener) null);
            this.mAMap.animateCamera(changeLatLng, new AMap.CancelableCallback() {
                public void onCancel() {
                }

                public void onFinish() {
                    AMapLocationActivity2D.this.mAMap.setOnCameraChangeListener(AMapLocationActivity2D.this);
                    if (AMapLocationActivity2D.this.mMarker != null) {
                        AMapLocationActivity2D.this.mMarker.setPosition(latLng);
                    }
                }
            });
        }
    }

    public void updateCheckedMapView(double d, double d2, String str) {
        updateToPosition(d, d2, str, false);
    }

    private class NearbyListAdapter extends BaseAdapter {
        Context context;
        List<MapNearbyInfo> nearbyInfoList;

        @Override
        public long getItemId(int i) {
            return i;
        }

        public NearbyListAdapter(Context context, List<MapNearbyInfo> list) {
            this.context = context;
            this.nearbyInfoList = list;
        }

        @Override
        public int getCount() {
            return this.nearbyInfoList.size();
        }

        @Override
        public Object getItem(int i) {
            List<MapNearbyInfo> list = this.nearbyInfoList;
            if (list == null || list.size() <= 0) {
                return null;
            }
            return this.nearbyInfoList.get(i);
        }

        @Override
        public View getView(int i, View view, ViewGroup viewGroup) {
            View view2;
            NearbyViewHolder nearbyViewHolder;
            MapNearbyInfo mapNearbyInfo = this.nearbyInfoList.get(i);
            if (view == null) {
                nearbyViewHolder = new NearbyViewHolder();
                view2 = View.inflate(this.context, R.layout.rc_location_map_nearby_info_item, null);
                nearbyViewHolder.tvNearbyName = (TextView) view2.findViewById(R.id.rc_nearby_name);
                nearbyViewHolder.tvNearbyAddress = (TextView) view2.findViewById(R.id.rc_nearby_address);
                nearbyViewHolder.ivNearbyChecked = (ImageView) view2.findViewById(R.id.rc_nearby_checked);
                view2.setTag(nearbyViewHolder);
            } else {
                view2 = view;
                nearbyViewHolder = (NearbyViewHolder) view.getTag();
            }
            if (i == 0) {
                nearbyViewHolder.tvNearbyAddress.setVisibility(8);
                nearbyViewHolder.tvNearbyName.setText(mapNearbyInfo.getName());
            } else {
                nearbyViewHolder.tvNearbyAddress.setVisibility(0);
                nearbyViewHolder.tvNearbyName.setText(mapNearbyInfo.getName());
                nearbyViewHolder.tvNearbyAddress.setText(mapNearbyInfo.getAddress());
            }
            if (mapNearbyInfo.getChecked()) {
                nearbyViewHolder.ivNearbyChecked.setVisibility(0);
            } else {
                nearbyViewHolder.ivNearbyChecked.setVisibility(8);
            }
            return view2;
        }

        public void addItems(List<MapNearbyInfo> list) {
            List<MapNearbyInfo> list2 = this.nearbyInfoList;
            if (list2 != null) {
                list2.addAll(list);
            }
        }

        class NearbyViewHolder {
            ImageView ivNearbyChecked;
            TextView tvNearbyAddress;
            TextView tvNearbyName;

            NearbyViewHolder() {
            }
        }
    }

    public class MapNearbyInfo {
        String address;
        boolean checked;
        double latitude;
        double longitude;
        String name;
        String poi;

        public MapNearbyInfo() {
        }

        public MapNearbyInfo(String str, String str2) {
            this.name = str;
            this.address = str2;
        }

        public String getName() {
            return this.name;
        }

        public void setName(String str) {
            this.name = str;
        }

        public String getAddress() {
            return this.address;
        }

        public void setAddress(String str) {
            this.address = str;
        }

        public double getLongitude() {
            return this.longitude;
        }

        public void setLongitude(double d) {
            this.longitude = d;
        }

        public double getLatitude() {
            return this.latitude;
        }

        public void setLatitude(double d) {
            this.latitude = d;
        }

        public String getPoi() {
            return this.poi;
        }

        public void setPoi(String str) {
            this.poi = str;
        }

        public boolean getChecked() {
            return this.checked;
        }

        public void setChecked(boolean z) {
            this.checked = z;
        }
    }
}