Skip to content

Commit

Permalink
实现了内置和外置导航
Browse files Browse the repository at this point in the history
  • Loading branch information
gaolei committed Mar 30, 2017
1 parent 91eb229 commit 393c22b
Show file tree
Hide file tree
Showing 60 changed files with 3,187 additions and 283 deletions.
3 changes: 0 additions & 3 deletions BiuBike/.idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 10 additions & 1 deletion BiuBike/app/build.gradle
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
apply plugin: 'com.android.application'

android {
signingConfigs {
config_release {
keyAlias 'bike'
keyPassword 'bikeup'
storeFile file('/Users/gaolei/Work/CompanyProject/Bike/BiuBike/BiuBike/biubike.jks')
storePassword 'bikeup'
}
}
compileSdkVersion 25
buildToolsVersion "25.0.0"
defaultConfig {
Expand All @@ -26,12 +34,13 @@ dependencies {
})
compile 'com.android.support:appcompat-v7:25.1.0'
testCompile 'junit:junit:4.12'
compile files('libs/locSDK_6.13.jar')
compile files('libs/baidumapapi_base_v4_1_1.jar')
compile files('libs/baidumapapi_map_v4_1_1.jar')
compile files('libs/nineoldandroids-2.4.0.jar')
compile 'com.android.support:recyclerview-v7:25.1.0'
compile files('libs/baidumapapi_util_v4_1_1.jar')
compile files('libs/gson-2.2.1.jar')
compile project(':xrecyclerview')
compile files('libs/BaiduNaviSDK_3.2.0.jar')
compile files('libs/httpmime-4.1.2.jar')
}
Binary file added BiuBike/app/libs/BaiduNaviSDK_3.2.0.jar
Binary file not shown.
Binary file added BiuBike/app/libs/httpmime-4.1.2.jar
Binary file not shown.
34 changes: 27 additions & 7 deletions BiuBike/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,19 @@
<!-- 访问网络,网络定位需要上网 -->
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.WAKE_LOCK"/>
<uses-permission android:name="android.permission.GET_TASKS"/>
<uses-permission android:name="android.permission.WRITE_SETTINGS"/>
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.GET_TASKS" />
<uses-permission android:name="android.permission.WRITE_SETTINGS" />

<uses-permission android:name="android.permission.BROADCAST_STICKY" />
<uses-permission android:name="android.permission.WRITE_SETTINGS" />
<!-- 来电消音 -->
<uses-permission android:name="android.permission.PROCESS_OUTGOING_CALLS" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" />
<uses-permission android:name="android.permission.RECORD_AUDIO" />
<!-- 摄影机 -->
<uses-permission android:name="android.permission.CAMERA" />


<application
Expand Down Expand Up @@ -50,7 +60,16 @@
<activity android:name=".activity.RouteDetailActivity" />
<activity android:name=".activity.MyRouteActivity" />
<activity android:name=".activity.NavigationActivity" />
<activity android:name=".activity.LocationDemo" />
<activity
android:name=".activity.BDInnerNaviActivity"
android:configChanges="orientation|screenSize|keyboard|keyboardHidden"
android:theme="@android:style/Theme.NoTitleBar.Fullscreen">
<intent-filter>
<action android:name="android.intent.action.VIEW" />

<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>

<receiver android:name=".MainActivity$LocationReceiver">
<intent-filter>
Expand All @@ -69,9 +88,10 @@
android:name="com.baidu.location.f"
android:enabled="true"
android:process=":remote"></service>
<service android:name="com.biubike.service.RouteService"
android:process=":Daemon"
></service>
<service
android:name="com.biubike.service.RouteService"
android:process=":Daemon"></service>

</application>


Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions BiuBike/app/src/main/assets/channel
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
baidu
3 changes: 3 additions & 0 deletions BiuBike/app/src/main/java/com/biubike/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@
import com.biubike.map.MyOrientationListener;
import com.biubike.map.RouteLineAdapter;
import com.biubike.service.RouteService;
import com.biubike.util.LocationManager;
import com.biubike.util.Utils;

import java.util.List;
Expand Down Expand Up @@ -223,6 +224,8 @@ public void onReceiveLocation(BDLocation bdLocation) {
current_addr.setText(bdLocation.getAddrStr());
currentLL = new LatLng(bdLocation.getLatitude(),
bdLocation.getLongitude());
LocationManager.getInstance().setCurrentLL(currentLL);
LocationManager.getInstance().setAddress(bdLocation.getAddrStr());
startNodeStr = PlanNode.withLocation(currentLL);
//option.setScanSpan(5000),每隔5000ms这个方法就会调用一次,而有些我们只想调用一次,所以要判断一下isFirstLoc
if (isFirstLoc) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,263 @@
package com.biubike.activity;

import android.app.Activity;
import android.content.Intent;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.util.Log;
import android.view.View;

import com.baidu.navisdk.adapter.BNRouteGuideManager;
import com.baidu.navisdk.adapter.BNRouteGuideManager.CustomizedLayerItem;
import com.baidu.navisdk.adapter.BNRouteGuideManager.OnNavigationListener;
import com.baidu.navisdk.adapter.BNRoutePlanNode;
import com.baidu.navisdk.adapter.BNRoutePlanNode.CoordinateType;
import com.baidu.navisdk.adapter.BNaviBaseCallbackModel;
import com.baidu.navisdk.adapter.BaiduNaviCommonModule;
import com.baidu.navisdk.adapter.NaviModuleFactory;
import com.baidu.navisdk.adapter.NaviModuleImpl;
import com.biubike.R;
import com.biubike.util.NavUtil;

import java.util.ArrayList;
import java.util.List;
import static com.biubike.util.NavUtil.activityList;

/**
* 诱导界面
*
* @author sunhao04
*
*/
public class BDInnerNaviActivity extends Activity {

private final String TAG = BDInnerNaviActivity.class.getName();
private BNRoutePlanNode mBNRoutePlanNode = null;
private BaiduNaviCommonModule mBaiduNaviCommonModule = null;

/*
* 对于导航模块有两种方式来实现发起导航。 1:使用通用接口来实现 2:使用传统接口来实现
*
*/
// 是否使用通用接口
private boolean useCommonInterface = true;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

activityList.add(this);
createHandler();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
}
View view = null;
if (useCommonInterface) {
//使用通用接口
mBaiduNaviCommonModule = NaviModuleFactory.getNaviModuleManager().getNaviCommonModule(
NaviModuleImpl.BNaviCommonModuleConstants.ROUTE_GUIDE_MODULE, this,
BNaviBaseCallbackModel.BNaviBaseCallbackConstants.CALLBACK_ROUTEGUIDE_TYPE, mOnNavigationListener);
if(mBaiduNaviCommonModule != null) {
mBaiduNaviCommonModule.onCreate();
view = mBaiduNaviCommonModule.getView();
}

} else {
//使用传统接口
view = BNRouteGuideManager.getInstance().onCreate(this,mOnNavigationListener);
}


if (view != null) {
setContentView(view);
}

Intent intent = getIntent();
if (intent != null) {
Bundle bundle = intent.getExtras();
if (bundle != null) {
mBNRoutePlanNode = (BNRoutePlanNode) bundle.getSerializable(NavUtil.ROUTE_PLAN_NODE);
}
}
//显示自定义图标
if (hd != null) {
hd.sendEmptyMessageAtTime(MSG_SHOW, 5000);
}
}

@Override
protected void onResume() {
super.onResume();
if(useCommonInterface) {
if(mBaiduNaviCommonModule != null) {
mBaiduNaviCommonModule.onResume();
}
} else {
BNRouteGuideManager.getInstance().onResume();
}



}

protected void onPause() {
super.onPause();

if(useCommonInterface) {
if(mBaiduNaviCommonModule != null) {
mBaiduNaviCommonModule.onPause();
}
} else {
BNRouteGuideManager.getInstance().onPause();
}

};

@Override
protected void onDestroy() {
super.onDestroy();
if(useCommonInterface) {
if(mBaiduNaviCommonModule != null) {
mBaiduNaviCommonModule.onDestroy();
}
} else {
BNRouteGuideManager.getInstance().onDestroy();
}
activityList.remove(this);

}

@Override
protected void onStop() {
super.onStop();
if(useCommonInterface) {
if(mBaiduNaviCommonModule != null) {
mBaiduNaviCommonModule.onStop();
}
} else {
BNRouteGuideManager.getInstance().onStop();
}

}

@Override
public void onBackPressed() {
if(useCommonInterface) {
if(mBaiduNaviCommonModule != null) {
mBaiduNaviCommonModule.onBackPressed(false);
}
} else {
BNRouteGuideManager.getInstance().onBackPressed(false);
}
}

public void onConfigurationChanged(android.content.res.Configuration newConfig) {
super.onConfigurationChanged(newConfig);
if(useCommonInterface) {
if(mBaiduNaviCommonModule != null) {
mBaiduNaviCommonModule.onConfigurationChanged(newConfig);
}
} else {
BNRouteGuideManager.getInstance().onConfigurationChanged(newConfig);
}

};


@Override
public boolean onKeyDown(int keyCode, android.view.KeyEvent event) {
if(useCommonInterface) {
if(mBaiduNaviCommonModule != null) {
Bundle mBundle = new Bundle();
mBundle.putInt(RouteGuideModuleConstants.KEY_TYPE_KEYCODE, keyCode);
mBundle.putParcelable(RouteGuideModuleConstants.KEY_TYPE_EVENT, event);
mBaiduNaviCommonModule.setModuleParams(RouteGuideModuleConstants.METHOD_TYPE_ON_KEY_DOWN, mBundle);
try {
Boolean ret = (Boolean)mBundle.get(RET_COMMON_MODULE);
if(ret) {
return true;
}
}catch(Exception e){
e.printStackTrace();
}
}
}
return super.onKeyDown(keyCode, event);
}
@Override
protected void onStart() {
super.onStart();
// TODO Auto-generated method stub
if(useCommonInterface) {
if(mBaiduNaviCommonModule != null) {
mBaiduNaviCommonModule.onStart();
}
} else {
BNRouteGuideManager.getInstance().onStart();
}
}
private void addCustomizedLayerItems() {
List<CustomizedLayerItem> items = new ArrayList<CustomizedLayerItem>();
CustomizedLayerItem item1 = null;
if (mBNRoutePlanNode != null) {
item1 = new CustomizedLayerItem(mBNRoutePlanNode.getLongitude(), mBNRoutePlanNode.getLatitude(),
mBNRoutePlanNode.getCoordinateType(), getResources().getDrawable(R.mipmap.ic_launcher),
CustomizedLayerItem.ALIGN_CENTER);
items.add(item1);

BNRouteGuideManager.getInstance().setCustomizedLayerItems(items);
}
BNRouteGuideManager.getInstance().showCustomizedLayer(true);
}

private static final int MSG_SHOW = 1;
private static final int MSG_HIDE = 2;
private static final int MSG_RESET_NODE = 3;
private Handler hd = null;

private void createHandler() {
if (hd == null) {
hd = new Handler(getMainLooper()) {
public void handleMessage(android.os.Message msg) {
if (msg.what == MSG_SHOW) {
addCustomizedLayerItems();
} else if (msg.what == MSG_HIDE) {
BNRouteGuideManager.getInstance().showCustomizedLayer(false);
} else if (msg.what == MSG_RESET_NODE) {
BNRouteGuideManager.getInstance().resetEndNodeInNavi(
new BNRoutePlanNode(116.21142, 40.85087, "百度大厦11", null, CoordinateType.GCJ02));
}
};
};
}
}

private OnNavigationListener mOnNavigationListener = new OnNavigationListener() {

@Override
public void onNaviGuideEnd() {
//退出导航
finish();
}

@Override
public void notifyOtherAction(int actionType, int arg1, int arg2, Object obj) {

if (actionType == 0) {
//导航到达目的地 自动退出
Log.i(TAG, "notifyOtherAction actionType = " + actionType + ",导航到达目的地!");
}

Log.i(TAG, "actionType:" + actionType + "arg1:" + arg1 + "arg2:" + arg2 + "obj:" + obj.toString());
}

};

private final static String RET_COMMON_MODULE = "module.ret";

private interface RouteGuideModuleConstants {
final static int METHOD_TYPE_ON_KEY_DOWN = 0x01;
final static String KEY_TYPE_KEYCODE = "keyCode";
final static String KEY_TYPE_EVENT = "event";
}
}
Loading

0 comments on commit 393c22b

Please sign in to comment.