正在查看: 爱心e站 v1.0.0 应用的 BNaviMainActivity.java JAVA 源代码文件
本页面展示 JAVA 反编译生成的源代码文件,支持语法高亮显示。 仅供安全研究与技术分析使用,严禁用于任何非法用途。请遵守相关法律法规。
正在查看: 爱心e站 v1.0.0 应用的 BNaviMainActivity.java JAVA 源代码文件
本页面展示 JAVA 反编译生成的源代码文件,支持语法高亮显示。 仅供安全研究与技术分析使用,严禁用于任何非法用途。请遵守相关法律法规。
package com.example.baidumap;
import android.app.Activity;
import android.content.Intent;
import android.os.Build;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;
import com.baidu.mapapi.bikenavi.BikeNavigateHelper;
import com.baidu.mapapi.bikenavi.adapter.IBEngineInitListener;
import com.baidu.mapapi.bikenavi.adapter.IBRoutePlanListener;
import com.baidu.mapapi.bikenavi.model.BikeRoutePlanError;
import com.baidu.mapapi.bikenavi.params.BikeNaviLaunchParam;
import com.baidu.mapapi.map.BaiduMap;
import com.baidu.mapapi.map.BitmapDescriptor;
import com.baidu.mapapi.map.BitmapDescriptorFactory;
import com.baidu.mapapi.map.MapStatus;
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.model.LatLng;
import com.baidu.mapapi.walknavi.WalkNavigateHelper;
import com.baidu.mapapi.walknavi.adapter.IWEngineInitListener;
import com.baidu.mapapi.walknavi.adapter.IWRoutePlanListener;
import com.baidu.mapapi.walknavi.model.WalkRoutePlanError;
import com.baidu.mapapi.walknavi.params.WalkNaviLaunchParam;
import java.util.ArrayList;
public class BNaviMainActivity extends Activity {
private static boolean isPermissionRequested = false;
BitmapDescriptor bdA = BitmapDescriptorFactory.fromResource(R.drawable.icon_marka);
BitmapDescriptor bdB = BitmapDescriptorFactory.fromResource(R.drawable.icon_markb);
private LatLng endPt;
private BaiduMap mBaiduMap;
private MapView mMapView;
private Marker mMarkerA;
private Marker mMarkerB;
private BikeNavigateHelper mNaviHelper;
private WalkNavigateHelper mWNaviHelper;
BikeNaviLaunchParam param;
private LatLng startPt;
WalkNaviLaunchParam walkParam;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_bnavi_main);
this.startPt = (LatLng) getIntent().getParcelableExtra("start");
this.endPt = (LatLng) getIntent().getParcelableExtra("end");
requestPermission();
this.mMapView = (MapView) findViewById(R.id.mapview);
initMapStatus();
initOverlay();
Button bikeBtn = (Button) findViewById(R.id.button);
bikeBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
BNaviMainActivity.this.startBikeNavi();
}
});
Button walkBtn = (Button) findViewById(R.id.button1);
walkBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
BNaviMainActivity.this.startWalkNavi();
}
});
try {
this.mNaviHelper = BikeNavigateHelper.getInstance();
this.mWNaviHelper = WalkNavigateHelper.getInstance();
} catch (Exception e) {
e.printStackTrace();
}
this.param = new BikeNaviLaunchParam().stPt(this.startPt).endPt(this.endPt);
this.walkParam = new WalkNaviLaunchParam().stPt(this.startPt).endPt(this.endPt);
findViewById(R.id.iv_back).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
BNaviMainActivity.this.finish();
}
});
}
private void initMapStatus() {
this.mBaiduMap = this.mMapView.getMap();
MapStatus.Builder builder = new MapStatus.Builder();
builder.target(this.endPt).zoom(19.0f);
this.mBaiduMap.setMapStatus(MapStatusUpdateFactory.newMapStatus(builder.build()));
}
public void initOverlay() {
LatLng llA = this.startPt;
LatLng llB = this.endPt;
MarkerOptions ooA = new MarkerOptions().position(llA).icon(this.bdA).zIndex(9).draggable(true);
this.mMarkerA = (Marker) this.mBaiduMap.addOverlay(ooA);
this.mMarkerA.setDraggable(true);
MarkerOptions ooB = new MarkerOptions().position(llB).icon(this.bdB).zIndex(5);
this.mMarkerB = (Marker) this.mBaiduMap.addOverlay(ooB);
this.mMarkerB.setDraggable(true);
this.mBaiduMap.setOnMarkerDragListener(new BaiduMap.OnMarkerDragListener() {
@Override
public void onMarkerDrag(Marker marker) {
}
@Override
public void onMarkerDragEnd(Marker marker) {
if (marker != BNaviMainActivity.this.mMarkerA) {
if (marker == BNaviMainActivity.this.mMarkerB) {
BNaviMainActivity.this.endPt = marker.getPosition();
}
} else {
BNaviMainActivity.this.startPt = marker.getPosition();
}
BNaviMainActivity.this.param.stPt(BNaviMainActivity.this.startPt).endPt(BNaviMainActivity.this.endPt);
BNaviMainActivity.this.walkParam.stPt(BNaviMainActivity.this.startPt).endPt(BNaviMainActivity.this.endPt);
}
@Override
public void onMarkerDragStart(Marker marker) {
}
});
}
public void startBikeNavi() {
Log.d("View", "startBikeNavi");
try {
this.mNaviHelper.initNaviEngine(this, new IBEngineInitListener() {
@Override
public void engineInitSuccess() {
Log.d("View", "engineInitSuccess");
BNaviMainActivity.this.routePlanWithParam();
}
@Override
public void engineInitFail() {
Log.d("View", "engineInitFail");
}
});
} catch (Exception e) {
Log.d("Exception", "startBikeNavi");
e.printStackTrace();
}
}
public void startWalkNavi() {
Log.d("View", "startBikeNavi");
try {
this.mWNaviHelper.initNaviEngine(this, new IWEngineInitListener() {
@Override
public void engineInitSuccess() {
Log.d("View", "engineInitSuccess");
BNaviMainActivity.this.routePlanWithWalkParam();
}
@Override
public void engineInitFail() {
Log.d("View", "engineInitFail");
}
});
} catch (Exception e) {
Log.d("Exception", "startBikeNavi");
e.printStackTrace();
}
}
public void routePlanWithParam() {
this.mNaviHelper.routePlanWithParams(this.param, new IBRoutePlanListener() {
@Override
public void onRoutePlanStart() {
Log.d("View", "onRoutePlanStart");
}
@Override
public void onRoutePlanSuccess() {
Log.d("View", "onRoutePlanSuccess");
Intent intent = new Intent();
intent.setClass(BNaviMainActivity.this, BNaviGuideActivity.class);
BNaviMainActivity.this.startActivity(intent);
}
@Override
public void onRoutePlanFail(BikeRoutePlanError error) {
Log.d("View", "onRoutePlanFail");
}
});
}
public void routePlanWithWalkParam() {
try {
this.mWNaviHelper.routePlanWithParams(this.walkParam, new IWRoutePlanListener() {
@Override
public void onRoutePlanStart() {
Log.d("View", "onRoutePlanStart");
}
@Override
public void onRoutePlanSuccess() {
Log.d("View", "onRoutePlanSuccess");
Intent intent = new Intent();
intent.setClass(BNaviMainActivity.this, WNaviGuideActivity.class);
BNaviMainActivity.this.startActivity(intent);
}
@Override
public void onRoutePlanFail(WalkRoutePlanError error) {
Log.d("View", "onRoutePlanFail");
}
});
} catch (Exception e) {
if (e.getMessage().equals("the distance is less than 30 meters")) {
Toast.makeText(this, "距离小于30米,不能使用步行导航", 0).show();
}
e.printStackTrace();
}
}
private void requestPermission() {
if (Build.VERSION.SDK_INT >= 23 && !isPermissionRequested) {
isPermissionRequested = true;
ArrayList<String> permissions = new ArrayList<>();
if (checkSelfPermission("android.permission.ACCESS_FINE_LOCATION") != 0) {
permissions.add("android.permission.ACCESS_FINE_LOCATION");
}
if (permissions.size() != 0) {
requestPermissions((String[]) permissions.toArray(new String[permissions.size()]), 0);
}
}
}
@Override
protected void onPause() {
super.onPause();
this.mMapView.onPause();
}
@Override
protected void onResume() {
super.onResume();
this.mMapView.onResume();
}
@Override
protected void onDestroy() {
super.onDestroy();
this.mMapView.onDestroy();
this.bdA.recycle();
this.bdB.recycle();
}
}