导航菜单

页面标题

页面副标题

爱心e站 v1.0.0 - MechanismOnMapActivity.java 源代码

正在查看: 爱心e站 v1.0.0 应用的 MechanismOnMapActivity.java JAVA 源代码文件

本页面展示 JAVA 反编译生成的源代码文件,支持语法高亮显示。 仅供安全研究与技术分析使用,严禁用于任何非法用途。请遵守相关法律法规。


package com.newheyd.JZKFcanjiren.Activity;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import com.baidu.location.BDLocation;
import com.baidu.location.BDLocationListener;
import com.baidu.location.LocationClient;
import com.baidu.location.LocationClientOption;
import com.baidu.mapapi.map.BaiduMap;
import com.baidu.mapapi.map.BitmapDescriptor;
import com.baidu.mapapi.map.BitmapDescriptorFactory;
import com.baidu.mapapi.map.InfoWindow;
import com.baidu.mapapi.map.MapStatus;
import com.baidu.mapapi.map.MapStatusUpdate;
import com.baidu.mapapi.map.MapStatusUpdateFactory;
import com.baidu.mapapi.map.MapView;
import com.baidu.mapapi.map.Marker;
import com.baidu.mapapi.map.MarkerOptions;
import com.baidu.mapapi.map.MyLocationData;
import com.baidu.mapapi.map.OverlayOptions;
import com.baidu.mapapi.model.LatLng;
import com.iflytek.cloud.SpeechConstant;
import com.newheyd.JZKFcanjiren.BaseActivity;
import com.newheyd.JZKFcanjiren.Bean.MechanismBean;
import com.newheyd.JZKFcanjiren.R;
import com.newheyd.JZKFcanjiren.Utils.StastisticUtil;
import com.newheyd.JZKFcanjiren.Utils.ToastUtils;
import com.newheyd.JZKFcanjiren.Utils.locationUtil.LocationAddrUtil;
import com.newheyd.JZKFcanjiren.View.InfoWindowView;
import com.newheyd.JZKFcanjiren.View.TitleView;
import com.newheyd.JZKFcanjiren.config.NewHYConfig;
import com.newheyd.JZKFcanjiren.model.BaseResult;
import com.newheyd.JZKFcanjiren.model.DataParser;
import com.newheyd.JZKFcanjiren.net.CommonDataListTask;
import com.newheyd.JZKFcanjiren.net.NewHYTask;
import com.newheyd.JZKFcanjiren.net.RequestServiceList;
import java.util.ArrayList;
import java.util.HashMap;

public class MechanismOnMapActivity extends BaseActivity implements BaiduMap.OnMarkerClickListener, InfoWindowView.OnInfoWindowCall {
    public static final int REQUEST_SEARCH = 1;
    private static int ZOOM = 11;
    private BaiduMap mBaiduMap;
    private MapView mMapView;
    private TitleView mTitleView;
    private LocationClient mLocationClient = null;
    private MyLocationListener myListener = null;
    private LocationClientOption option = null;
    private String orgType = "";
    private ArrayList<MechanismBean> data = new ArrayList<>();
    private HashMap<String, String> paramsSearch = new HashMap<>();

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        setContentView(R.layout.activity_mechanism_on_map);
        super.onCreate(savedInstanceState);
        this.mMapView = (MapView) findViewById(R.id.mmap);
        this.mBaiduMap = this.mMapView.getMap();
        setConfig();
        startLocation();
        getOrgList();
        goStatistics();
    }

    public void goStatistics() {
        HashMap<String, String> map = LocationAddrUtil.getInstance().getLocationParam(this.mContext);
        StastisticUtil.getInstance().onEvent(this.mContext, "MechanismOnMapActivity", map);
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (-1 == resultCode) {
            switch (requestCode) {
                case 1:
                    this.paramsSearch = (HashMap) data.getSerializableExtra(SpeechConstant.PARAMS);
                    getOrgList();
                    break;
            }
        }
    }

    public void setConfig() {
        if (this.option == null) {
            this.option = new LocationClientOption();
        }
        this.option.setLocationMode(LocationClientOption.LocationMode.Hight_Accuracy);
        this.option.setOpenGps(true);
        this.option.setIsNeedAddress(true);
        this.option.setScanSpan(0);
        this.mBaiduMap.setMyLocationEnabled(true);
        this.mBaiduMap.setOnMarkerClickListener(this);
    }

    public void startLocation() {
        this.mLocationClient = new LocationClient(this.mContext);
        this.mLocationClient.setLocOption(this.option);
        if (this.myListener == null) {
            this.myListener = new MyLocationListener(this.mContext);
        }
        this.mLocationClient.registerLocationListener(this.myListener);
        this.mLocationClient.start();
    }

    public void endLocation() {
        if (this.mLocationClient != null) {
            this.mLocationClient.unRegisterLocationListener(this.myListener);
            this.mLocationClient.stop();
        }
    }

    @Override
    public boolean onMarkerClick(Marker marker) {
        MechanismBean bean = (MechanismBean) marker.getExtraInfo().getSerializable("bean");
        InfoWindowView infoWindowView = new InfoWindowView(this.mContext, bean);
        infoWindowView.setOnInfoWindowCall(this);
        InfoWindow mInfoWindow = new InfoWindow(infoWindowView, marker.getPosition(), 0);
        this.mBaiduMap.showInfoWindow(mInfoWindow);
        MapStatus mMapStatus = new MapStatus.Builder().target(marker.getPosition()).zoom(ZOOM).build();
        MapStatusUpdate mMapStatusUpdate = MapStatusUpdateFactory.newMapStatus(mMapStatus);
        this.mBaiduMap.setMapStatus(mMapStatusUpdate);
        return false;
    }

    @Override
    public void onClose() {
        if (this.mBaiduMap != null) {
            this.mBaiduMap.hideInfoWindow();
        }
    }

    class MyLocationListener implements BDLocationListener {
        private Context mContext;

        public MyLocationListener(Context mContext) {
            this.mContext = null;
            this.mContext = mContext;
        }

        @Override
        public void onReceiveLocation(BDLocation location) {
            if (location != null) {
                MyLocationData locData = new MyLocationData.Builder().accuracy(location.getRadius()).direction(90.0f).latitude(location.getLatitude()).longitude(location.getLongitude()).build();
                MechanismOnMapActivity.this.mBaiduMap.setMyLocationData(locData);
                LatLng cenpt = new LatLng(location.getLatitude(), location.getLongitude());
                MapStatus mMapStatus = new MapStatus.Builder().target(cenpt).zoom(MechanismOnMapActivity.ZOOM).build();
                MapStatusUpdate mMapStatusUpdate = MapStatusUpdateFactory.newMapStatus(mMapStatus);
                MechanismOnMapActivity.this.mBaiduMap.setMapStatus(mMapStatusUpdate);
            }
        }
    }

    public void getOrgList() {
        HashMap<String, String> params = new HashMap<>();
        params.put("orgType", this.orgType);
        params.put("pageNo", String.valueOf("1"));
        params.put("pageSize", String.valueOf(20));
        params.putAll(this.paramsSearch);
        NewHYTask task = new CommonDataListTask(RequestServiceList.REHABORG_ORGLIST, params, MechanismBean.class);
        executeRequest(task);
    }

    @Override
    public void onResponseBefore(NewHYTask task) {
        switch (task.getService()) {
            case REHABORG_ORGLIST:
                showProgress(NewHYConfig.LOADING_HINT, false);
                break;
        }
    }

    @Override
    public void onResponseAfter(NewHYTask task) {
        switch (task.getService()) {
            case REHABORG_ORGLIST:
                cancleProgress();
                break;
        }
    }

    @Override
    public void onResponseSuccessful(NewHYTask task, BaseResult object) {
        switch (task.getService()) {
            case REHABORG_ORGLIST:
                DataParser<MechanismBean> mResult = (DataParser) object;
                ArrayList<MechanismBean> lists = mResult.getObjects();
                this.data.clear();
                if (lists != null) {
                    this.data.addAll(lists);
                }
                freshData();
                break;
        }
    }

    public void freshData() {
        this.mBaiduMap.clear();
        for (int i = 0; i < this.data.size(); i++) {
            LatLng point = new LatLng(Double.parseDouble(this.data.get(i).getLatitude()), Double.parseDouble(this.data.get(i).getLongitude()));
            BitmapDescriptor bitmap = BitmapDescriptorFactory.fromResource(R.drawable.index_loc);
            Bundle bundle = new Bundle();
            bundle.putSerializable("bean", this.data.get(i));
            OverlayOptions option = new MarkerOptions().position(point).icon(bitmap).extraInfo(bundle);
            this.mBaiduMap.addOverlay(option);
        }
    }

    @Override
    public void onResponseError(NewHYTask task, BaseResult object) {
        switch (task.getService()) {
            case REHABORG_ORGLIST:
                ToastUtils.showShortToast(this.mContext, object.getMsg());
                break;
        }
    }

    @Override
    public void onServerError(NewHYTask task, int failedType) {
        switch (task.getService()) {
            case REHABORG_ORGLIST:
                onResultShow(failedType);
                break;
        }
    }

    @Override
    public void initViews() {
        this.mTitleView = (TitleView) findViewById(R.id.titleview);
        this.mTitleView.setSearchVisivle(true);
        this.mTitleView.setRightImg(R.mipmap.iv_search);
    }

    @Override
    public void setListener() {
        this.mTitleView.setOnTitleClik(new TitleView.BackListenner() {
            @Override
            public void BackSet() {
                MechanismOnMapActivity.this.finish();
            }
        }, new TitleView.RightListenner() {
            @Override
            public void RightSet() {
                Intent intent = new Intent(MechanismOnMapActivity.this.mContext, (Class<?>) MechanismSearchActivity.class);
                MechanismOnMapActivity.this.startActivityForResult(intent, 1);
            }
        });
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        endLocation();
    }
}