├── app
├── .gitignore
├── src
│ ├── main
│ │ ├── res
│ │ │ ├── mipmap-hdpi
│ │ │ │ └── ic_launcher.png
│ │ │ ├── mipmap-mdpi
│ │ │ │ └── ic_launcher.png
│ │ │ ├── mipmap-xhdpi
│ │ │ │ └── ic_launcher.png
│ │ │ ├── mipmap-xxhdpi
│ │ │ │ └── ic_launcher.png
│ │ │ ├── mipmap-xxxhdpi
│ │ │ │ └── ic_launcher.png
│ │ │ ├── drawable-xhdpi
│ │ │ │ ├── back_btn_image.png
│ │ │ │ ├── map_traffic_white.png
│ │ │ │ ├── map_traffic_hl_white.png
│ │ │ │ ├── prefer_setting_btn_off.png
│ │ │ │ ├── prefer_setting_btn_on.png
│ │ │ │ ├── route_car_result_prefer_icon_normal.png
│ │ │ │ ├── route_car_result_prefer_icon_selected.png
│ │ │ │ └── button_background_white.xml
│ │ │ ├── drawable
│ │ │ │ ├── map_sticker_verydanger_hl.png
│ │ │ │ └── route_car_result_prefer_icon.xml
│ │ │ ├── values
│ │ │ │ ├── strings.xml
│ │ │ │ ├── styles.xml
│ │ │ │ ├── dimens.xml
│ │ │ │ └── colors.xml
│ │ │ ├── values-w820dp
│ │ │ │ └── dimens.xml
│ │ │ └── layout
│ │ │ │ ├── activity_basic_navi.xml
│ │ │ │ ├── adapter_strategy_choose.xml
│ │ │ │ ├── activity_strategy_choose.xml
│ │ │ │ └── activity_calculate_route.xml
│ │ ├── java
│ │ │ └── com
│ │ │ │ └── amap
│ │ │ │ └── multiroute
│ │ │ │ ├── Bean
│ │ │ │ ├── StrategyStateBean.java
│ │ │ │ └── StrategyBean.java
│ │ │ │ ├── StrategyChooseActivity.java
│ │ │ │ ├── adapter
│ │ │ │ └── StrategyChooseAdapter.java
│ │ │ │ ├── RouteNaviActivity.java
│ │ │ │ ├── util
│ │ │ │ └── Utils.java
│ │ │ │ └── CalculateRouteActivity.java
│ │ └── AndroidManifest.xml
│ ├── test
│ │ └── java
│ │ │ └── com
│ │ │ └── amap
│ │ │ └── multiroute
│ │ │ └── ExampleUnitTest.java
│ └── androidTest
│ │ └── java
│ │ └── com
│ │ └── amap
│ │ └── multiroute
│ │ └── ApplicationTest.java
├── proguard-rules.pro
└── build.gradle
├── settings.gradle
├── resource
├── app-debug.apk
├── download.png
├── navi_snapshot.png
├── route_snapshot.png
└── strategy_snapshot.png
├── .idea
├── copyright
│ └── profiles_settings.xml
├── encodings.xml
├── modules.xml
├── runConfigurations.xml
├── gradle.xml
├── compiler.xml
└── misc.xml
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── .gitignore
├── gradle.properties
├── README.md
├── gradlew.bat
└── gradlew
/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':app'
2 |
--------------------------------------------------------------------------------
/resource/app-debug.apk:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/amap-demo/android-multiroute-display/HEAD/resource/app-debug.apk
--------------------------------------------------------------------------------
/resource/download.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/amap-demo/android-multiroute-display/HEAD/resource/download.png
--------------------------------------------------------------------------------
/.idea/copyright/profiles_settings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
--------------------------------------------------------------------------------
/resource/navi_snapshot.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/amap-demo/android-multiroute-display/HEAD/resource/navi_snapshot.png
--------------------------------------------------------------------------------
/resource/route_snapshot.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/amap-demo/android-multiroute-display/HEAD/resource/route_snapshot.png
--------------------------------------------------------------------------------
/resource/strategy_snapshot.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/amap-demo/android-multiroute-display/HEAD/resource/strategy_snapshot.png
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/amap-demo/android-multiroute-display/HEAD/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | *.iml
2 | .gradle
3 | /local.properties
4 | /.idea/workspace.xml
5 | /.idea/libraries
6 | .DS_Store
7 | /build
8 | /captures
9 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/amap-demo/android-multiroute-display/HEAD/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/amap-demo/android-multiroute-display/HEAD/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/amap-demo/android-multiroute-display/HEAD/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/amap-demo/android-multiroute-display/HEAD/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/amap-demo/android-multiroute-display/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xhdpi/back_btn_image.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/amap-demo/android-multiroute-display/HEAD/app/src/main/res/drawable-xhdpi/back_btn_image.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xhdpi/map_traffic_white.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/amap-demo/android-multiroute-display/HEAD/app/src/main/res/drawable-xhdpi/map_traffic_white.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable/map_sticker_verydanger_hl.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/amap-demo/android-multiroute-display/HEAD/app/src/main/res/drawable/map_sticker_verydanger_hl.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xhdpi/map_traffic_hl_white.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/amap-demo/android-multiroute-display/HEAD/app/src/main/res/drawable-xhdpi/map_traffic_hl_white.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xhdpi/prefer_setting_btn_off.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/amap-demo/android-multiroute-display/HEAD/app/src/main/res/drawable-xhdpi/prefer_setting_btn_off.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xhdpi/prefer_setting_btn_on.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/amap-demo/android-multiroute-display/HEAD/app/src/main/res/drawable-xhdpi/prefer_setting_btn_on.png
--------------------------------------------------------------------------------
/.idea/encodings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xhdpi/route_car_result_prefer_icon_normal.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/amap-demo/android-multiroute-display/HEAD/app/src/main/res/drawable-xhdpi/route_car_result_prefer_icon_normal.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xhdpi/route_car_result_prefer_icon_selected.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/amap-demo/android-multiroute-display/HEAD/app/src/main/res/drawable-xhdpi/route_car_result_prefer_icon_selected.png
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Wed Jul 12 11:56:38 CST 2017
2 | distributionBase=GRADLE_USER_HOME
3 | distributionPath=wrapper/dists
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 | distributionUrl=https\://services.gradle.org/distributions/gradle-3.3-all.zip
7 |
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | AndroidNaviMultirouteDisplay
3 | 58eedde4
4 | 避免拥堵
5 | 避免收费
6 | 不走高速
7 | 高速优先
8 |
9 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xhdpi/button_background_white.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/route_car_result_prefer_icon.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/app/src/main/res/values-w820dp/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 | 64dp
6 |
7 |
--------------------------------------------------------------------------------
/app/src/test/java/com/amap/multiroute/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package com.amap.multiroute;
2 |
3 | import org.junit.Test;
4 |
5 | import static org.junit.Assert.*;
6 |
7 | /**
8 | * To work on unit tests, switch the Test Artifact in the Build Variants view.
9 | */
10 | public class ExampleUnitTest {
11 | @Test
12 | public void addition_isCorrect() throws Exception {
13 | assertEquals(4, 2 + 2);
14 | }
15 | }
--------------------------------------------------------------------------------
/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/app/src/androidTest/java/com/amap/multiroute/ApplicationTest.java:
--------------------------------------------------------------------------------
1 | package com.amap.multiroute;
2 |
3 | import android.app.Application;
4 | import android.test.ApplicationTestCase;
5 |
6 | /**
7 | * Testing Fundamentals
8 | */
9 | public class ApplicationTest extends ApplicationTestCase {
10 | public ApplicationTest() {
11 | super(Application.class);
12 | }
13 | }
--------------------------------------------------------------------------------
/app/src/main/res/values/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 16dp
4 | 16dp
5 | 48dp
6 | 5dp
7 | 18sp
8 | 30dp
9 |
10 |
11 |
--------------------------------------------------------------------------------
/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #3F51B5
4 | #303F9F
5 | #FF4081
6 | #307EFE
7 | #737373
8 | #535353
9 | #f6f6f6
10 | #ebebeb
11 | #ffffff
12 |
13 |
14 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_basic_navi.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
12 |
13 |
14 |
15 |
--------------------------------------------------------------------------------
/.idea/modules.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/.idea/runConfigurations.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
11 |
12 |
--------------------------------------------------------------------------------
/.idea/gradle.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
--------------------------------------------------------------------------------
/app/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # By default, the flags in this file are appended to flags specified
3 | # in /Users/ligen/develope/android-sdk-macosx/tools/proguard/proguard-android.txt
4 | # You can edit the include path and order by changing the proguardFiles
5 | # directive in build.gradle.
6 | #
7 | # For more details, see
8 | # http://developer.android.com/guide/developing/tools/proguard.html
9 |
10 | # Add any project specific keep options here:
11 |
12 | # If your project uses WebView with JS, uncomment the following
13 | # and specify the fully qualified class name to the JavaScript interface
14 | # class:
15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16 | # public *;
17 | #}
18 |
--------------------------------------------------------------------------------
/.idea/compiler.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
--------------------------------------------------------------------------------
/app/src/main/java/com/amap/multiroute/Bean/StrategyStateBean.java:
--------------------------------------------------------------------------------
1 | package com.amap.multiroute.Bean;
2 |
3 | /**
4 | * Created by ligen on 16/10/31.
5 | */
6 | public class StrategyStateBean {
7 | private int mStrategyCode;
8 | private boolean mOpen;
9 |
10 | public StrategyStateBean(int strategyCode, boolean open) {
11 | setStrategyCode(strategyCode);
12 | setOpen(open);
13 | }
14 |
15 | public int getStrategyCode() {
16 | return mStrategyCode;
17 | }
18 |
19 | public void setStrategyCode(int mStrategyCode) {
20 | this.mStrategyCode = mStrategyCode;
21 | }
22 |
23 | public boolean isOpen() {
24 | return mOpen;
25 | }
26 |
27 | public void setOpen(boolean mOpen) {
28 | this.mOpen = mOpen;
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | # Project-wide Gradle settings.
2 |
3 | # IDE (e.g. Android Studio) users:
4 | # Gradle settings configured through the IDE *will override*
5 | # any settings specified in this file.
6 |
7 | # For more details on how to configure your build environment visit
8 | # http://www.gradle.org/docs/current/userguide/build_environment.html
9 |
10 | # Specifies the JVM arguments used for the daemon process.
11 | # The setting is particularly useful for tweaking memory settings.
12 | # Default value: -Xmx10248m -XX:MaxPermSize=256m
13 | # org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
14 |
15 | # When configured, Gradle will run in incubating parallel mode.
16 | # This option should only be used with decoupled projects. More details, visit
17 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
18 | # org.gradle.parallel=true
19 | android.useDeprecatedNdk=true
--------------------------------------------------------------------------------
/app/build.gradle:
--------------------------------------------------------------------------------
1 | buildscript {
2 | repositories {
3 | jcenter()
4 | }
5 | }
6 | apply plugin: 'com.android.application'
7 |
8 | android {
9 | compileSdkVersion 23
10 | buildToolsVersion '25.0.0'
11 |
12 | defaultConfig {
13 | applicationId "com.amap.multiroute"
14 | minSdkVersion 14
15 | targetSdkVersion 26
16 | versionCode 1
17 | versionName "1.0"
18 | ndk {
19 | abiFilters 'armeabi-v7a'
20 | }
21 | }
22 | buildTypes {
23 | release {
24 | minifyEnabled false
25 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
26 | }
27 | }
28 | sourceSets {
29 | main {
30 | jniLibs.srcDirs = ['libs']
31 | }
32 | }
33 | }
34 |
35 | dependencies {
36 | compile fileTree(dir: 'libs', include: '*.jar')
37 | testCompile 'junit:junit:4.12'
38 | compile 'com.android.support:appcompat-v7:23.2.1'
39 | compile 'com.amap.api:navi-3dmap:latest.integration'
40 | }
41 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/adapter_strategy_choose.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
17 |
18 |
26 |
27 |
--------------------------------------------------------------------------------
/app/src/main/java/com/amap/multiroute/Bean/StrategyBean.java:
--------------------------------------------------------------------------------
1 | package com.amap.multiroute.Bean;
2 |
3 | /**
4 | * Created by ligen on 16/11/2.
5 | */
6 | public class StrategyBean {
7 | private boolean mCongestion;
8 | private boolean mCost;
9 | private boolean mHightspeed;
10 | private boolean mAvoidhightspeed;
11 |
12 | public StrategyBean(boolean congestion,boolean cost,boolean highspeed,boolean avoidhighspeed){
13 | setCongestion(congestion);
14 | setCost(cost);
15 | setHightspeed(highspeed);
16 | setAvoidhightspeed(avoidhighspeed);
17 | }
18 |
19 | public boolean isCongestion() {
20 | return mCongestion;
21 | }
22 |
23 | public void setCongestion(boolean mCongestion) {
24 | this.mCongestion = mCongestion;
25 | }
26 |
27 | public boolean isCost() {
28 | return mCost;
29 | }
30 |
31 | public void setCost(boolean mCost) {
32 | this.mCost = mCost;
33 | }
34 |
35 | public boolean isHightspeed() {
36 | return mHightspeed;
37 | }
38 |
39 | public void setHightspeed(boolean mHightspeed) {
40 | this.mHightspeed = mHightspeed;
41 | }
42 |
43 | public boolean isAvoidhightspeed() {
44 | return mAvoidhightspeed;
45 | }
46 |
47 | public void setAvoidhightspeed(boolean mAvoidhightspeed) {
48 | this.mAvoidhightspeed = mAvoidhightspeed;
49 | }
50 | }
51 |
--------------------------------------------------------------------------------
/.idea/misc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
--------------------------------------------------------------------------------
/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
28 |
31 |
32 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
44 |
47 |
48 |
49 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_strategy_choose.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
14 |
15 |
27 |
28 |
34 |
35 |
36 |
37 |
46 |
47 |
48 |
54 |
55 |
61 |
62 |
63 |
64 |
65 |
66 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # android-navi-multiroute-display
2 | 多路径规划、导航示例
3 | ## 前述 ##
4 | - [高德官网申请Key](http://lbs.amap.com/dev/#/).
5 | - 阅读[参考手册](http://a.amap.com/lbs/static/unzip/Android_Map_Doc/index.html).
6 | - [科大讯飞开放平台申请Appid](http://www.xfyun.cn/services/online_tts).
7 | - 工程基于Android 导航 SDK、科大讯飞在线语音合成SDK实现
8 |
9 |
10 | ## 扫一扫安装##
11 | 
12 |
13 |
14 | ##多路径规划、导航示例
15 | ## 使用方法##
16 | ###1:配置搭建AndroidSDK工程###
17 | - [Android Studio工程搭建方法](http://lbs.amap.com/api/android-sdk/guide/creat-project/android-studio-creat-project/#add-jars).
18 | - [通过maven库引入SDK方法](http://lbsbbs.amap.com/forum.php?mod=viewthread&tid=18786).
19 |
20 |
21 | ###2:运行示例配置项###
22 | - AndroidManifest.xml 配置高德开放平台key
23 | ```java
24 |
30 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 | ```
45 | - string.xml 配置科大讯飞Appid
46 | ```java
47 | 科大讯飞Appid
48 | ```
49 | - CalculateRouteActivity 设置导航起终点
50 | ```java
51 | private NaviLatLng endLatlng; //导航终点
52 | private NaviLatLng startLatlng; //导航起点
53 | ```
54 | - CalculateRouteActivity 选择模拟\真实导航
55 | ```java
56 | /**
57 | * 开始导航
58 | */
59 | private void startNavi() {
60 | Intent gpsintent = new Intent(getApplicationContext(), RouteNaviActivity.class);
61 | gpsintent.putExtra("gps", false); // gps 为true为真实导航,为false为模拟导航
62 | startActivity(gpsintent);
63 | }
64 | ```
65 |
66 | ##效果展示##
67 | ####多路径规划
68 | 
69 |
70 | ####驾车偏好设置
71 | 
72 |
73 | ####导航
74 | 
75 |
76 |
77 |
78 |
79 |
--------------------------------------------------------------------------------
/gradlew.bat:
--------------------------------------------------------------------------------
1 | @if "%DEBUG%" == "" @echo off
2 | @rem ##########################################################################
3 | @rem
4 | @rem Gradle startup script for Windows
5 | @rem
6 | @rem ##########################################################################
7 |
8 | @rem Set local scope for the variables with windows NT shell
9 | if "%OS%"=="Windows_NT" setlocal
10 |
11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
12 | set DEFAULT_JVM_OPTS=
13 |
14 | set DIRNAME=%~dp0
15 | if "%DIRNAME%" == "" set DIRNAME=.
16 | set APP_BASE_NAME=%~n0
17 | set APP_HOME=%DIRNAME%
18 |
19 | @rem Find java.exe
20 | if defined JAVA_HOME goto findJavaFromJavaHome
21 |
22 | set JAVA_EXE=java.exe
23 | %JAVA_EXE% -version >NUL 2>&1
24 | if "%ERRORLEVEL%" == "0" goto init
25 |
26 | echo.
27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
28 | echo.
29 | echo Please set the JAVA_HOME variable in your environment to match the
30 | echo location of your Java installation.
31 |
32 | goto fail
33 |
34 | :findJavaFromJavaHome
35 | set JAVA_HOME=%JAVA_HOME:"=%
36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
37 |
38 | if exist "%JAVA_EXE%" goto init
39 |
40 | echo.
41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
42 | echo.
43 | echo Please set the JAVA_HOME variable in your environment to match the
44 | echo location of your Java installation.
45 |
46 | goto fail
47 |
48 | :init
49 | @rem Get command-line arguments, handling Windowz variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 | if "%@eval[2+2]" == "4" goto 4NT_args
53 |
54 | :win9xME_args
55 | @rem Slurp the command line arguments.
56 | set CMD_LINE_ARGS=
57 | set _SKIP=2
58 |
59 | :win9xME_args_slurp
60 | if "x%~1" == "x" goto execute
61 |
62 | set CMD_LINE_ARGS=%*
63 | goto execute
64 |
65 | :4NT_args
66 | @rem Get arguments from the 4NT Shell from JP Software
67 | set CMD_LINE_ARGS=%$
68 |
69 | :execute
70 | @rem Setup the command line
71 |
72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
73 |
74 | @rem Execute Gradle
75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
76 |
77 | :end
78 | @rem End local scope for the variables with windows NT shell
79 | if "%ERRORLEVEL%"=="0" goto mainEnd
80 |
81 | :fail
82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
83 | rem the _cmd.exe /c_ return code!
84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
85 | exit /b 1
86 |
87 | :mainEnd
88 | if "%OS%"=="Windows_NT" endlocal
89 |
90 | :omega
91 |
--------------------------------------------------------------------------------
/app/src/main/java/com/amap/multiroute/StrategyChooseActivity.java:
--------------------------------------------------------------------------------
1 | package com.amap.multiroute;
2 |
3 | import android.app.Activity;
4 | import android.content.Intent;
5 | import android.os.Bundle;
6 | import android.view.KeyEvent;
7 | import android.view.View;
8 | import android.widget.LinearLayout;
9 | import android.widget.ListView;
10 |
11 | import com.amap.multiroute.Bean.StrategyStateBean;
12 | import com.amap.multiroute.adapter.StrategyChooseAdapter;
13 | import com.amap.multiroute.util.Utils;
14 |
15 | import java.util.ArrayList;
16 | import java.util.List;
17 |
18 | /**
19 | * 驾车偏好设置
20 | */
21 | public class StrategyChooseActivity extends Activity implements View.OnClickListener {
22 | private boolean congestion, cost, hightspeed, avoidhightspeed;
23 | List mStrategys = new ArrayList();
24 | private ListView mStrategyChooseListView;
25 | private StrategyChooseAdapter mStrategyAdapter;
26 | private LinearLayout mBackLayout;
27 |
28 | @Override
29 | protected void onCreate(Bundle savedInstanceState) {
30 | super.onCreate(savedInstanceState);
31 | getActivityIntent();
32 | mStrategys.add(new StrategyStateBean(Utils.AVOID_CONGESTION, congestion));
33 | mStrategys.add(new StrategyStateBean(Utils.AVOID_COST, cost));
34 | mStrategys.add(new StrategyStateBean(Utils.AVOID_HIGHSPEED, avoidhightspeed));
35 | mStrategys.add(new StrategyStateBean(Utils.PRIORITY_HIGHSPEED, hightspeed));
36 | setContentView(R.layout.activity_strategy_choose);
37 | mStrategyAdapter = new StrategyChooseAdapter(this.getApplicationContext(), mStrategys);
38 | mStrategyChooseListView = (ListView) findViewById(R.id.strategy_choose_list);
39 | mStrategyChooseListView.setAdapter(mStrategyAdapter);
40 | mBackLayout = (LinearLayout) findViewById(R.id.title_lly_back);
41 | mBackLayout.setOnClickListener(this);
42 | }
43 |
44 | @Override
45 | protected void onPause() {
46 | super.onPause();
47 | }
48 |
49 | @Override
50 | public boolean onKeyDown(int keyCode, KeyEvent event) {
51 | if (keyCode == KeyEvent.KEYCODE_BACK) {
52 | setResultIntent();
53 | }
54 | return super.onKeyDown(keyCode, event);
55 | }
56 |
57 | private void setResultIntent(){
58 | Intent intent = new Intent();
59 | for (StrategyStateBean bean : mStrategys) {
60 | if (bean.getStrategyCode() == Utils.AVOID_CONGESTION) {
61 | intent.putExtra(Utils.INTENT_NAME_AVOID_CONGESTION, bean.isOpen());
62 | }
63 |
64 | if (bean.getStrategyCode() == Utils.AVOID_COST) {
65 | intent.putExtra(Utils.INTENT_NAME_AVOID_COST, bean.isOpen());
66 | }
67 |
68 | if (bean.getStrategyCode() == Utils.AVOID_HIGHSPEED) {
69 | intent.putExtra(Utils.INTENT_NAME_AVOID_HIGHSPEED, bean.isOpen());
70 | }
71 |
72 | if (bean.getStrategyCode() == Utils.PRIORITY_HIGHSPEED) {
73 | intent.putExtra(Utils.INTENT_NAME_PRIORITY_HIGHSPEED, bean.isOpen());
74 | }
75 | }
76 | this.setResult(Utils.ACTIVITY_RESULT_CODE, intent);
77 | }
78 |
79 | private void getActivityIntent() {
80 | Intent intent = this.getIntent();
81 | if (intent == null) {
82 | return;
83 | }
84 | congestion = intent.getBooleanExtra(Utils.INTENT_NAME_AVOID_CONGESTION, false);
85 | cost = intent.getBooleanExtra(Utils.INTENT_NAME_AVOID_COST, false);
86 | avoidhightspeed = intent.getBooleanExtra(Utils.INTENT_NAME_AVOID_HIGHSPEED, false);
87 | hightspeed = intent.getBooleanExtra(Utils.INTENT_NAME_PRIORITY_HIGHSPEED, false);
88 | }
89 |
90 | @Override
91 | public void onClick(View view) {
92 | if(view.getId() == R.id.title_lly_back){
93 | setResultIntent();
94 | this.finish();
95 | }
96 | }
97 | }
98 |
--------------------------------------------------------------------------------
/app/src/main/java/com/amap/multiroute/adapter/StrategyChooseAdapter.java:
--------------------------------------------------------------------------------
1 | package com.amap.multiroute.adapter;
2 |
3 | import android.content.Context;
4 | import android.view.LayoutInflater;
5 | import android.view.View;
6 | import android.view.ViewGroup;
7 | import android.widget.BaseAdapter;
8 | import android.widget.ImageView;
9 | import android.widget.TextView;
10 |
11 | import com.amap.multiroute.Bean.StrategyStateBean;
12 | import com.amap.multiroute.R;
13 | import com.amap.multiroute.util.Utils;
14 |
15 | import java.util.List;
16 |
17 | /**
18 | * 驾车偏好设置adapter,高速优先与不走高速、避免收费互斥
19 | * Created by ligen on 16/10/28.
20 | */
21 | public class StrategyChooseAdapter extends BaseAdapter implements View.OnClickListener {
22 |
23 | private Context mContext;
24 | private List mStrategys;
25 |
26 | public StrategyChooseAdapter(Context context, List strategys) {
27 | mContext = context;
28 | mStrategys = strategys;
29 | }
30 |
31 | @Override
32 | public int getCount() {
33 | return mStrategys.size();
34 | }
35 |
36 | @Override
37 | public StrategyStateBean getItem(int i) {
38 | return mStrategys.get(i);
39 | }
40 |
41 | @Override
42 | public long getItemId(int i) {
43 | return i;
44 | }
45 |
46 | @Override
47 | public View getView(int i, View view, ViewGroup viewGroup) {
48 | Holder holder;
49 | if (view == null) {
50 | holder = new Holder();
51 | view = LayoutInflater.from(mContext).inflate(R.layout.adapter_strategy_choose, null);
52 | holder.mStrategyNameText = (TextView) view.findViewById(R.id.strategy_name);
53 | holder.mStrategyChooseFlagImage = (ImageView) view.findViewById(R.id.strategy_choose_flag);
54 | holder.mStrategyBean = mStrategys.get(i);
55 | view.setTag(holder);
56 | } else {
57 | holder = (Holder) view.getTag();
58 | }
59 | view.setOnClickListener(this);
60 | StrategyStateBean strategyBean = mStrategys.get(i);
61 | if (strategyBean != null) {
62 | int strategyCode = strategyBean.getStrategyCode();
63 | String strategyName = getStrategyName(strategyCode);
64 | holder.mStrategyNameText.setText(strategyName);
65 |
66 | }
67 | if (holder != null && holder.mStrategyBean != null) {
68 | boolean isOpen = holder.mStrategyBean.isOpen();
69 | if (isOpen) {
70 | holder.mStrategyChooseFlagImage.setBackgroundResource(R.drawable.prefer_setting_btn_on);
71 | } else {
72 | holder.mStrategyChooseFlagImage.setBackgroundResource(R.drawable.prefer_setting_btn_off);
73 | }
74 | }
75 |
76 | return view;
77 | }
78 |
79 | private String getStrategyName(int strategyCode) {
80 | String strategyName = "";
81 | switch (strategyCode) {
82 | case Utils.AVOID_CONGESTION:
83 | strategyName = mContext.getString(R.string.congestion);
84 | break;
85 | case Utils.AVOID_COST:
86 | strategyName = mContext.getString(R.string.cost);
87 | break;
88 | case Utils.AVOID_HIGHSPEED:
89 | strategyName = mContext.getString(R.string.avoidhightspeed);
90 | break;
91 | case Utils.PRIORITY_HIGHSPEED:
92 | strategyName = mContext.getString(R.string.hightspeed);
93 | break;
94 | default:
95 | break;
96 | }
97 | return strategyName;
98 | }
99 |
100 | @Override
101 | public void onClick(View view) {
102 | Holder holder = (Holder) view.getTag();
103 | if (holder == null || holder.mStrategyBean == null) {
104 | return;
105 | }
106 | if (holder.mStrategyBean.isOpen()) {
107 | holder.mStrategyBean.setOpen(false);
108 | } else {
109 | holder.mStrategyBean.setOpen(true);
110 | }
111 |
112 | int strategyCode = holder.mStrategyBean.getStrategyCode();
113 |
114 | if (strategyCode == Utils.PRIORITY_HIGHSPEED) {
115 | for (StrategyStateBean bean : mStrategys) {
116 | if (bean.getStrategyCode() == Utils.AVOID_COST || bean.getStrategyCode() == Utils.AVOID_HIGHSPEED) {
117 | bean.setOpen(false);
118 | }
119 | }
120 | }
121 |
122 | if (strategyCode == Utils.AVOID_COST || strategyCode == Utils.AVOID_HIGHSPEED) {
123 | for (StrategyStateBean bean : mStrategys) {
124 | if (bean.getStrategyCode() == Utils.PRIORITY_HIGHSPEED) {
125 | bean.setOpen(false);
126 | }
127 | }
128 | }
129 | notifyDataSetChanged();
130 | }
131 |
132 | public class Holder {
133 | public TextView mStrategyNameText;
134 | public ImageView mStrategyChooseFlagImage;
135 | public StrategyStateBean mStrategyBean;
136 | }
137 | }
138 |
--------------------------------------------------------------------------------
/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 |
3 | ##############################################################################
4 | ##
5 | ## Gradle start up script for UN*X
6 | ##
7 | ##############################################################################
8 |
9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
10 | DEFAULT_JVM_OPTS=""
11 |
12 | APP_NAME="Gradle"
13 | APP_BASE_NAME=`basename "$0"`
14 |
15 | # Use the maximum available, or set MAX_FD != -1 to use that value.
16 | MAX_FD="maximum"
17 |
18 | warn ( ) {
19 | echo "$*"
20 | }
21 |
22 | die ( ) {
23 | echo
24 | echo "$*"
25 | echo
26 | exit 1
27 | }
28 |
29 | # OS specific support (must be 'true' or 'false').
30 | cygwin=false
31 | msys=false
32 | darwin=false
33 | case "`uname`" in
34 | CYGWIN* )
35 | cygwin=true
36 | ;;
37 | Darwin* )
38 | darwin=true
39 | ;;
40 | MINGW* )
41 | msys=true
42 | ;;
43 | esac
44 |
45 | # Attempt to set APP_HOME
46 | # Resolve links: $0 may be a link
47 | PRG="$0"
48 | # Need this for relative symlinks.
49 | while [ -h "$PRG" ] ; do
50 | ls=`ls -ld "$PRG"`
51 | link=`expr "$ls" : '.*-> \(.*\)$'`
52 | if expr "$link" : '/.*' > /dev/null; then
53 | PRG="$link"
54 | else
55 | PRG=`dirname "$PRG"`"/$link"
56 | fi
57 | done
58 | SAVED="`pwd`"
59 | cd "`dirname \"$PRG\"`/" >/dev/null
60 | APP_HOME="`pwd -P`"
61 | cd "$SAVED" >/dev/null
62 |
63 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
64 |
65 | # Determine the Java command to use to start the JVM.
66 | if [ -n "$JAVA_HOME" ] ; then
67 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
68 | # IBM's JDK on AIX uses strange locations for the executables
69 | JAVACMD="$JAVA_HOME/jre/sh/java"
70 | else
71 | JAVACMD="$JAVA_HOME/bin/java"
72 | fi
73 | if [ ! -x "$JAVACMD" ] ; then
74 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
75 |
76 | Please set the JAVA_HOME variable in your environment to match the
77 | location of your Java installation."
78 | fi
79 | else
80 | JAVACMD="java"
81 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
82 |
83 | Please set the JAVA_HOME variable in your environment to match the
84 | location of your Java installation."
85 | fi
86 |
87 | # Increase the maximum file descriptors if we can.
88 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
89 | MAX_FD_LIMIT=`ulimit -H -n`
90 | if [ $? -eq 0 ] ; then
91 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
92 | MAX_FD="$MAX_FD_LIMIT"
93 | fi
94 | ulimit -n $MAX_FD
95 | if [ $? -ne 0 ] ; then
96 | warn "Could not set maximum file descriptor limit: $MAX_FD"
97 | fi
98 | else
99 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
100 | fi
101 | fi
102 |
103 | # For Darwin, add options to specify how the application appears in the dock
104 | if $darwin; then
105 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
106 | fi
107 |
108 | # For Cygwin, switch paths to Windows format before running java
109 | if $cygwin ; then
110 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
111 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
112 | JAVACMD=`cygpath --unix "$JAVACMD"`
113 |
114 | # We build the pattern for arguments to be converted via cygpath
115 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
116 | SEP=""
117 | for dir in $ROOTDIRSRAW ; do
118 | ROOTDIRS="$ROOTDIRS$SEP$dir"
119 | SEP="|"
120 | done
121 | OURCYGPATTERN="(^($ROOTDIRS))"
122 | # Add a user-defined pattern to the cygpath arguments
123 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
124 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
125 | fi
126 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
127 | i=0
128 | for arg in "$@" ; do
129 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
130 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
131 |
132 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
133 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
134 | else
135 | eval `echo args$i`="\"$arg\""
136 | fi
137 | i=$((i+1))
138 | done
139 | case $i in
140 | (0) set -- ;;
141 | (1) set -- "$args0" ;;
142 | (2) set -- "$args0" "$args1" ;;
143 | (3) set -- "$args0" "$args1" "$args2" ;;
144 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
145 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
146 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
147 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
148 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
149 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
150 | esac
151 | fi
152 |
153 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
154 | function splitJvmOpts() {
155 | JVM_OPTS=("$@")
156 | }
157 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
158 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
159 |
160 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
161 |
--------------------------------------------------------------------------------
/app/src/main/java/com/amap/multiroute/RouteNaviActivity.java:
--------------------------------------------------------------------------------
1 | package com.amap.multiroute;
2 |
3 | import android.app.Activity;
4 | import android.os.Bundle;
5 | import android.view.Window;
6 | import android.widget.Toast;
7 |
8 | import com.amap.api.navi.AMapNavi;
9 | import com.amap.api.navi.AMapNaviListener;
10 | import com.amap.api.navi.AMapNaviView;
11 | import com.amap.api.navi.AMapNaviViewListener;
12 | import com.amap.api.navi.model.AMapLaneInfo;
13 | import com.amap.api.navi.model.AMapModelCross;
14 | import com.amap.api.navi.model.AMapNaviCameraInfo;
15 | import com.amap.api.navi.model.AMapNaviCross;
16 | import com.amap.api.navi.model.AMapNaviInfo;
17 | import com.amap.api.navi.model.AMapNaviLocation;
18 | import com.amap.api.navi.model.AMapNaviTrafficFacilityInfo;
19 | import com.amap.api.navi.model.AMapServiceAreaInfo;
20 | import com.amap.api.navi.model.AimLessModeCongestionInfo;
21 | import com.amap.api.navi.model.AimLessModeStat;
22 | import com.amap.api.navi.model.NaviInfo;
23 | import com.autonavi.tbt.TrafficFacilityInfo;
24 |
25 | /**
26 | * 按照选定策略导航
27 | */
28 | public class RouteNaviActivity extends Activity implements AMapNaviListener, AMapNaviViewListener {
29 |
30 | AMapNaviView mAMapNaviView;
31 | AMapNavi mAMapNavi;
32 |
33 |
34 | @Override
35 | protected void onCreate(Bundle savedInstanceState) {
36 | super.onCreate(savedInstanceState);
37 | requestWindowFeature(Window.FEATURE_NO_TITLE);
38 | setContentView(R.layout.activity_basic_navi);
39 |
40 |
41 | mAMapNaviView = (AMapNaviView) findViewById(R.id.navi_view);
42 | mAMapNaviView.onCreate(savedInstanceState);
43 | mAMapNaviView.setAMapNaviViewListener(this);
44 |
45 | mAMapNavi = AMapNavi.getInstance(getApplicationContext());
46 | mAMapNavi.addAMapNaviListener(this);
47 | mAMapNavi.setUseInnerVoice(true);
48 |
49 | mAMapNavi.setEmulatorNaviSpeed(60);
50 | boolean gps=getIntent().getBooleanExtra("gps", false);
51 | if(gps){
52 | mAMapNavi.startNavi(AMapNavi.GPSNaviMode);
53 | }else{
54 | mAMapNavi.startNavi(AMapNavi.EmulatorNaviMode);
55 | }
56 |
57 |
58 | }
59 |
60 | @Override
61 | protected void onResume() {
62 | super.onResume();
63 | mAMapNaviView.onResume();
64 | }
65 |
66 | @Override
67 | protected void onPause() {
68 | super.onPause();
69 | mAMapNaviView.onPause();
70 |
71 | //
72 | // 停止导航之后,会触及底层stop,然后就不会再有回调了,但是讯飞当前还是没有说完的半句话还是会说完
73 | // mAMapNavi.stopNavi();
74 | }
75 |
76 | @Override
77 | protected void onDestroy() {
78 | super.onDestroy();
79 | mAMapNaviView.onDestroy();
80 | mAMapNavi.stopNavi();
81 | // mAMapNavi.destroy();
82 |
83 | }
84 |
85 | @Override
86 | public void onInitNaviFailure() {
87 | Toast.makeText(this, "init navi Failed", Toast.LENGTH_SHORT).show();
88 | }
89 |
90 | @Override
91 | public void onInitNaviSuccess() {
92 | }
93 |
94 | @Override
95 | public void onStartNavi(int type) {
96 |
97 | }
98 |
99 | @Override
100 | public void onTrafficStatusUpdate() {
101 |
102 | }
103 |
104 | @Override
105 | public void onLocationChange(AMapNaviLocation location) {
106 |
107 | }
108 |
109 | @Override
110 | public void onGetNavigationText(int type, String text) {
111 |
112 | }
113 |
114 | @Override
115 | public void onGetNavigationText(String s) {
116 |
117 | }
118 |
119 | @Override
120 | public void onEndEmulatorNavi() {
121 | }
122 |
123 | @Override
124 | public void onArriveDestination() {
125 | }
126 |
127 | @Override
128 | public void onCalculateRouteFailure(int errorInfo) {
129 | }
130 |
131 | @Override
132 | public void onReCalculateRouteForYaw() {
133 |
134 | }
135 |
136 | @Override
137 | public void onReCalculateRouteForTrafficJam() {
138 |
139 | }
140 |
141 | @Override
142 | public void onArrivedWayPoint(int wayID) {
143 |
144 | }
145 |
146 | @Override
147 | public void onGpsOpenStatus(boolean enabled) {
148 | }
149 |
150 | @Override
151 | public void onNaviSetting() {
152 | }
153 |
154 | @Override
155 | public void onNaviMapMode(int isLock) {
156 |
157 | }
158 |
159 | @Override
160 | public void onNaviCancel() {
161 | finish();
162 | }
163 |
164 | @Override
165 | public void onNaviTurnClick() {
166 |
167 | }
168 |
169 | @Override
170 | public void onNextRoadClick() {
171 |
172 | }
173 |
174 | @Override
175 | public void onScanViewButtonClick() {
176 | }
177 |
178 | @Deprecated
179 | @Override
180 | public void onNaviInfoUpdated(AMapNaviInfo naviInfo) {
181 | }
182 |
183 | @Override
184 | public void updateCameraInfo(AMapNaviCameraInfo[] aMapNaviCameraInfos) {
185 |
186 | }
187 |
188 | @Override
189 | public void updateIntervalCameraInfo(AMapNaviCameraInfo aMapNaviCameraInfo, AMapNaviCameraInfo aMapNaviCameraInfo1, int i) {
190 |
191 | }
192 |
193 | @Override
194 | public void onServiceAreaUpdate(AMapServiceAreaInfo[] aMapServiceAreaInfos) {
195 |
196 | }
197 |
198 | @Override
199 | public void onNaviInfoUpdate(NaviInfo naviinfo) {
200 | }
201 |
202 | @Override
203 | public void OnUpdateTrafficFacility(TrafficFacilityInfo trafficFacilityInfo) {
204 |
205 | }
206 |
207 | @Override
208 | public void OnUpdateTrafficFacility(AMapNaviTrafficFacilityInfo aMapNaviTrafficFacilityInfo) {
209 |
210 | }
211 |
212 | @Override
213 | public void showCross(AMapNaviCross aMapNaviCross) {
214 | }
215 |
216 | @Override
217 | public void hideCross() {
218 | }
219 |
220 | @Override
221 | public void showModeCross(AMapModelCross aMapModelCross) {
222 |
223 | }
224 |
225 | @Override
226 | public void hideModeCross() {
227 |
228 | }
229 |
230 | @Override
231 | public void showLaneInfo(AMapLaneInfo[] laneInfos, byte[] laneBackgroundInfo, byte[] laneRecommendedInfo) {
232 |
233 | }
234 |
235 | @Override
236 | public void showLaneInfo(AMapLaneInfo aMapLaneInfo) {
237 |
238 | }
239 |
240 | @Override
241 | public void hideLaneInfo() {
242 |
243 | }
244 |
245 | @Override
246 | public void onCalculateRouteSuccess(int[] ints) {
247 |
248 | }
249 |
250 | @Override
251 | public void notifyParallelRoad(int i) {
252 |
253 | }
254 |
255 | @Override
256 | public void OnUpdateTrafficFacility(AMapNaviTrafficFacilityInfo[] aMapNaviTrafficFacilityInfos) {
257 |
258 | }
259 |
260 | @Override
261 | public void updateAimlessModeStatistics(AimLessModeStat aimLessModeStat) {
262 |
263 | }
264 |
265 | @Override
266 | public void updateAimlessModeCongestionInfo(AimLessModeCongestionInfo aimLessModeCongestionInfo) {
267 |
268 | }
269 |
270 | @Override
271 | public void onPlayRing(int i) {
272 |
273 | }
274 |
275 | @Override
276 | public void onLockMap(boolean isLock) {
277 | }
278 |
279 | @Override
280 | public void onNaviViewLoaded() {
281 | }
282 |
283 | @Override
284 | public boolean onNaviBackClick() {
285 | return false;
286 | }
287 |
288 | }
289 |
--------------------------------------------------------------------------------
/app/src/main/java/com/amap/multiroute/util/Utils.java:
--------------------------------------------------------------------------------
1 | package com.amap.multiroute.util;
2 |
3 | import android.text.Html;
4 | import android.text.Spanned;
5 |
6 | import com.amap.api.navi.model.AMapNaviPath;
7 | import com.amap.api.navi.model.AMapNaviStep;
8 | import com.amap.multiroute.Bean.StrategyBean;
9 |
10 | import java.text.DecimalFormat;
11 | import java.util.HashMap;
12 | import java.util.List;
13 |
14 | public class Utils {
15 | private static DecimalFormat fnum = new DecimalFormat("##0.0");
16 | public static final int AVOID_CONGESTION = 4; // 躲避拥堵
17 | public static final int AVOID_COST = 5; // 避免收费
18 | public static final int AVOID_HIGHSPEED = 6; //不走高速
19 | public static final int PRIORITY_HIGHSPEED = 7; //高速优先
20 |
21 | public static final int START_ACTIVITY_REQUEST_CODE = 1;
22 | public static final int ACTIVITY_RESULT_CODE = 2;
23 |
24 | public static final String INTENT_NAME_AVOID_CONGESTION = "AVOID_CONGESTION";
25 | public static final String INTENT_NAME_AVOID_COST = "AVOID_COST";
26 | public static final String INTENT_NAME_AVOID_HIGHSPEED = "AVOID_HIGHSPEED";
27 | public static final String INTENT_NAME_PRIORITY_HIGHSPEED = "PRIORITY_HIGHSPEED";
28 |
29 |
30 | public static String getFriendlyTime(int s) {
31 | String timeDes = "";
32 | int h = s / 3600;
33 | if (h > 0) {
34 | timeDes += h + "小时";
35 | }
36 | int min = (int) (s % 3600) / 60;
37 | if (min > 0) {
38 | timeDes += min + "分";
39 | }
40 | return timeDes;
41 | }
42 |
43 | public static String getFriendlyDistance(int m) {
44 | float dis = m / 1000f;
45 | String disDes = fnum.format(dis) + "公里";
46 | return disDes;
47 | }
48 |
49 | /**
50 | * 计算path对应的标签
51 | *
52 | * @param paths 多路径规划回调的所有路径
53 | * @param ints 多路径线路ID
54 | * @param pathIndex 当前路径索引
55 | * @param strategyBean 封装策略bean
56 | * @return path对应标签描述
57 | */
58 | public static String getStrategyDes(HashMap paths, int[] ints, int pathIndex, StrategyBean strategyBean) {
59 | int StrategyTAGIndex = pathIndex + 1;
60 | String StrategyTAG = "方案" + StrategyTAGIndex;
61 |
62 | int minTime = Integer.MAX_VALUE;
63 | int minDistance = Integer.MAX_VALUE;
64 | int minTrafficLightNumber = Integer.MAX_VALUE;
65 | int minCost = Integer.MAX_VALUE;
66 | for (int i = 0; i < ints.length; i++) {
67 | if (pathIndex == i) {
68 | continue;
69 | }
70 | AMapNaviPath path = paths.get(ints[i]);
71 | if (path == null) {
72 | continue;
73 | }
74 | int trafficListNumber = getTrafficNumber(path);
75 | if (trafficListNumber < minTrafficLightNumber) {
76 | minTrafficLightNumber = trafficListNumber;
77 | }
78 |
79 | if (path.getTollCost() < minCost) {
80 | minCost = path.getTollCost();
81 | }
82 |
83 | if (path.getAllTime() < minTime) {
84 | minTime = path.getAllTime();
85 | }
86 | if (path.getAllLength() < minDistance) {
87 | minDistance = path.getAllLength();
88 | }
89 | }
90 | AMapNaviPath indexPath = paths.get(ints[pathIndex]);
91 | int indexTrafficLightNumber = getTrafficNumber(indexPath);
92 | int indexCost = indexPath.getTollCost();
93 | int indexTime = indexPath.getAllTime();
94 | int indexDistance = indexPath.getAllLength();
95 | if (indexTrafficLightNumber < minTrafficLightNumber) {
96 | StrategyTAG = "红绿灯少";
97 | }
98 | if (indexCost < minCost) {
99 | StrategyTAG = "收费较少";
100 | }
101 |
102 | if (Math.round(indexDistance / 100f) < Math.round(minDistance / 100f)) { // 展示距离精确到千米保留一位小数,比较时按照展示数据处理
103 | StrategyTAG = "距离最短";
104 | }
105 | if (indexTime / 60 < minTime / 60) { //展示时间精确到分钟,比较时按照展示数据处理
106 | StrategyTAG = "时间最短";
107 | }
108 | boolean isMulti = isMultiStrategy(strategyBean);
109 | if (strategyBean.isCongestion() && pathIndex == 0 && !isMulti) {
110 | StrategyTAG = "躲避拥堵";
111 | }
112 | if (strategyBean.isAvoidhightspeed() && pathIndex == 0 && !isMulti) {
113 | StrategyTAG = "不走高速";
114 | }
115 | if (strategyBean.isCost() && pathIndex == 0 && !isMulti) {
116 | StrategyTAG = "避免收费";
117 | }
118 | if (pathIndex == 0 && StrategyTAG.startsWith("方案")) {
119 | StrategyTAG = "推荐";
120 | }
121 | return StrategyTAG;
122 | }
123 |
124 |
125 | /**
126 | * 判断驾车偏好设置是否同时选中多个策略
127 | *
128 | * @param strategyBean 驾车策略bean
129 | * @return
130 | */
131 | public static boolean isMultiStrategy(StrategyBean strategyBean) {
132 | boolean isMultiStrategy = false;
133 | if (strategyBean.isCongestion()) {
134 | if (strategyBean.isAvoidhightspeed() || strategyBean.isCost() || strategyBean.isHightspeed()) {
135 | isMultiStrategy = true;
136 | } else {
137 | isMultiStrategy = false;
138 | }
139 | }
140 | if (strategyBean.isCost()) {
141 | if (strategyBean.isCongestion() || strategyBean.isAvoidhightspeed()) {
142 | isMultiStrategy = true;
143 | } else {
144 | isMultiStrategy = false;
145 | }
146 | }
147 | if (strategyBean.isAvoidhightspeed()) {
148 | if (strategyBean.isCongestion() || strategyBean.isCost()) {
149 | isMultiStrategy = true;
150 | } else {
151 | isMultiStrategy = false;
152 | }
153 | }
154 | if (strategyBean.isHightspeed()) {
155 | if (strategyBean.isCongestion()) {
156 | isMultiStrategy = true;
157 | } else {
158 | isMultiStrategy = false;
159 | }
160 | }
161 | return isMultiStrategy;
162 | }
163 |
164 | public static Spanned getRouteOverView(AMapNaviPath path) {
165 | String routeOverView = "";
166 | if (path == null) {
167 | Html.fromHtml(routeOverView);
168 | }
169 |
170 | int cost = path.getTollCost();
171 | if (cost > 0) {
172 | routeOverView += "过路费约" + cost + "元";
173 | }
174 | int trafficLightNumber = getTrafficNumber(path);
175 | if (trafficLightNumber > 0) {
176 | routeOverView += "红绿灯" + trafficLightNumber + "个";
177 | }
178 | return Html.fromHtml(routeOverView);
179 | }
180 |
181 | public static int getTrafficNumber(AMapNaviPath path) {
182 | int trafficLightNumber = 0;
183 | if (path == null) {
184 | return trafficLightNumber;
185 | }
186 | List steps = path.getSteps();
187 | for (AMapNaviStep step : steps) {
188 | trafficLightNumber += step.getTrafficLightNumber();
189 | }
190 | return trafficLightNumber;
191 | }
192 | }
193 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_calculate_route.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
18 |
26 |
27 |
34 |
35 |
43 |
44 |
49 |
50 |
55 |
56 |
63 |
64 |
69 |
70 |
71 |
79 |
80 |
86 |
87 |
92 |
93 |
100 |
101 |
106 |
107 |
108 |
109 |
117 |
118 |
124 |
125 |
130 |
131 |
138 |
139 |
144 |
145 |
146 |
147 |
148 |
149 |
153 |
154 |
158 |
159 |
170 |
171 |
182 |
183 |
184 |
185 |
186 |
--------------------------------------------------------------------------------
/app/src/main/java/com/amap/multiroute/CalculateRouteActivity.java:
--------------------------------------------------------------------------------
1 | package com.amap.multiroute;
2 |
3 | import android.app.Activity;
4 | import android.content.Intent;
5 | import android.os.Bundle;
6 | import android.util.Log;
7 | import android.util.SparseArray;
8 | import android.view.View;
9 | import android.widget.Button;
10 | import android.widget.ImageView;
11 | import android.widget.LinearLayout;
12 | import android.widget.TextView;
13 | import android.widget.Toast;
14 |
15 | import com.amap.api.maps.AMap;
16 | import com.amap.api.maps.CameraUpdateFactory;
17 | import com.amap.api.maps.MapView;
18 | import com.amap.api.maps.UiSettings;
19 | import com.amap.api.navi.AMapNavi;
20 | import com.amap.api.navi.AMapNaviException;
21 | import com.amap.api.navi.AMapNaviListener;
22 | import com.amap.api.navi.model.AMapLaneInfo;
23 | import com.amap.api.navi.model.AMapModelCross;
24 | import com.amap.api.navi.model.AMapNaviCameraInfo;
25 | import com.amap.api.navi.model.AMapNaviCross;
26 | import com.amap.api.navi.model.AMapNaviInfo;
27 | import com.amap.api.navi.model.AMapNaviLocation;
28 | import com.amap.api.navi.model.AMapNaviPath;
29 | import com.amap.api.navi.model.AMapNaviTrafficFacilityInfo;
30 | import com.amap.api.navi.model.AMapServiceAreaInfo;
31 | import com.amap.api.navi.model.AimLessModeCongestionInfo;
32 | import com.amap.api.navi.model.AimLessModeStat;
33 | import com.amap.api.navi.model.NaviInfo;
34 | import com.amap.api.navi.model.NaviLatLng;
35 | import com.amap.api.navi.view.RouteOverLay;
36 | import com.amap.multiroute.Bean.StrategyBean;
37 | import com.amap.multiroute.util.Utils;
38 | import com.autonavi.tbt.TrafficFacilityInfo;
39 |
40 | import java.util.ArrayList;
41 | import java.util.HashMap;
42 | import java.util.List;
43 |
44 | /**
45 | * 驾车路径规划并展示对应的路线标签
46 | */
47 | public class CalculateRouteActivity extends Activity implements AMapNaviListener, View.OnClickListener, AMap.OnMapLoadedListener {
48 | private StrategyBean mStrategyBean;
49 | private static final float ROUTE_UNSELECTED_TRANSPARENCY = 0.3F;
50 | private static final float ROUTE_SELECTED_TRANSPARENCY = 1F;
51 |
52 | /**
53 | * 导航对象(单例)
54 | */
55 | private AMapNavi mAMapNavi;
56 |
57 | private MapView mMapView;
58 | private AMap mAMap;
59 | private NaviLatLng endLatlng = new NaviLatLng(39.90759,116.392582);
60 | private NaviLatLng startLatlng = new NaviLatLng(39.993537, 116.472875);
61 | private List startList = new ArrayList();
62 | /**
63 | * 途径点坐标集合
64 | */
65 | private List wayList = new ArrayList();
66 | /**
67 | * 终点坐标集合[建议就一个终点]
68 | */
69 | private List endList = new ArrayList();
70 | /**
71 | * 保存当前算好的路线
72 | */
73 | private SparseArray routeOverlays = new SparseArray();
74 | /*
75 | * strategyFlag转换出来的值都对应PathPlanningStrategy常量,用户也可以直接传入PathPlanningStrategy常量进行算路。
76 | * 如:mAMapNavi.calculateDriveRoute(mStartList, mEndList, mWayPointList,PathPlanningStrategy.DRIVING_DEFAULT);
77 | */
78 | int strategyFlag = 0;
79 |
80 | private Button mStartNaviButton;
81 | private LinearLayout mRouteLineLayoutOne, mRouteLinelayoutTwo, mRouteLineLayoutThree;
82 | private View mRouteViewOne, mRouteViewTwo, mRouteViewThree;
83 | private TextView mRouteTextStrategyOne, mRouteTextStrategyTwo, mRouteTextStrategyThree;
84 | private TextView mRouteTextTimeOne, mRouteTextTimeTwo, mRouteTextTimeThree;
85 | private TextView mRouteTextDistanceOne, mRouteTextDistanceTwo, mRouteTextDistanceThree;
86 | private TextView mCalculateRouteOverView;
87 | private ImageView mImageTraffic, mImageStrategy;
88 |
89 | private int routeID = -1;
90 |
91 | @Override
92 | protected void onCreate(Bundle savedInstanceState) {
93 | super.onCreate(savedInstanceState);
94 | setContentView(R.layout.activity_calculate_route);
95 | mMapView = (MapView) findViewById(R.id.navi_view);
96 | mMapView.onCreate(savedInstanceState);// 此方法必须重写
97 | initView();
98 | init();
99 | initNavi();
100 | }
101 |
102 | @Override
103 | public void onClick(View view) {
104 | switch (view.getId()) {
105 | case R.id.calculate_route_start_navi:
106 | startNavi();
107 | break;
108 | case R.id.route_line_one:
109 | focuseRouteLine(true, false, false);
110 | break;
111 | case R.id.route_line_two:
112 | focuseRouteLine(false, true, false);
113 | break;
114 | case R.id.route_line_three:
115 | focuseRouteLine(false, false, true);
116 | break;
117 | case R.id.map_traffic:
118 | setTraffic();
119 | break;
120 | case R.id.strategy_choose:
121 | strategyChoose();
122 | break;
123 | default:
124 | break;
125 | }
126 |
127 | }
128 |
129 | /**
130 | * 驾车路径规划计算
131 | */
132 | private void calculateDriveRoute() {
133 | try {
134 | strategyFlag = mAMapNavi.strategyConvert(mStrategyBean.isCongestion(), mStrategyBean.isCost(), mStrategyBean.isAvoidhightspeed(), mStrategyBean.isHightspeed(), true);
135 | } catch (Exception e) {
136 | e.printStackTrace();
137 | }
138 | mAMapNavi.calculateDriveRoute(startList, endList, wayList, strategyFlag);
139 | }
140 |
141 | /**
142 | * 接收驾车偏好设置项
143 | *
144 | * @param requestCode
145 | * @param resultCode
146 | * @param data
147 | */
148 |
149 | @Override
150 | protected void onActivityResult(int requestCode, int resultCode, Intent data) {
151 | if (Utils.ACTIVITY_RESULT_CODE == resultCode) {
152 | boolean congestion = data.getBooleanExtra(Utils.INTENT_NAME_AVOID_CONGESTION, false);
153 | mStrategyBean.setCongestion(congestion);
154 | boolean cost = data.getBooleanExtra(Utils.INTENT_NAME_AVOID_COST, false);
155 | mStrategyBean.setCost(cost);
156 | boolean avoidhightspeed = data.getBooleanExtra(Utils.INTENT_NAME_AVOID_HIGHSPEED, false);
157 | mStrategyBean.setAvoidhightspeed(avoidhightspeed);
158 | boolean hightspeed = data.getBooleanExtra(Utils.INTENT_NAME_PRIORITY_HIGHSPEED, false);
159 | mStrategyBean.setHightspeed(hightspeed);
160 | calculateDriveRoute();
161 | }
162 | }
163 |
164 | /**
165 | * 导航初始化
166 | */
167 | private void initNavi() {
168 | mStrategyBean = new StrategyBean(false, false, false, false);
169 | startList.add(startLatlng);
170 | endList.add(endLatlng);
171 | mAMapNavi = AMapNavi.getInstance(getApplicationContext());
172 | mAMapNavi.addAMapNaviListener(this);
173 |
174 | }
175 |
176 | private void initView() {
177 | mStartNaviButton = (Button) findViewById(R.id.calculate_route_start_navi);
178 | mStartNaviButton.setOnClickListener(this);
179 |
180 | mImageTraffic = (ImageView) findViewById(R.id.map_traffic);
181 | mImageTraffic.setOnClickListener(this);
182 | mImageStrategy = (ImageView) findViewById(R.id.strategy_choose);
183 | mImageStrategy.setOnClickListener(this);
184 |
185 | mCalculateRouteOverView = (TextView) findViewById(R.id.calculate_route_navi_overview);
186 |
187 | mRouteLineLayoutOne = (LinearLayout) findViewById(R.id.route_line_one);
188 | mRouteLineLayoutOne.setOnClickListener(this);
189 | mRouteLinelayoutTwo = (LinearLayout) findViewById(R.id.route_line_two);
190 | mRouteLinelayoutTwo.setOnClickListener(this);
191 | mRouteLineLayoutThree = (LinearLayout) findViewById(R.id.route_line_three);
192 | mRouteLineLayoutThree.setOnClickListener(this);
193 |
194 | mRouteViewOne = (View) findViewById(R.id.route_line_one_view);
195 | mRouteViewTwo = (View) findViewById(R.id.route_line_two_view);
196 | mRouteViewThree = (View) findViewById(R.id.route_line_three_view);
197 |
198 | mRouteTextStrategyOne = (TextView) findViewById(R.id.route_line_one_strategy);
199 | mRouteTextStrategyTwo = (TextView) findViewById(R.id.route_line_two_strategy);
200 | mRouteTextStrategyThree = (TextView) findViewById(R.id.route_line_three_strategy);
201 |
202 | mRouteTextTimeOne = (TextView) findViewById(R.id.route_line_one_time);
203 | mRouteTextTimeTwo = (TextView) findViewById(R.id.route_line_two_time);
204 | mRouteTextTimeThree = (TextView) findViewById(R.id.route_line_three_time);
205 |
206 | mRouteTextDistanceOne = (TextView) findViewById(R.id.route_line_one_distance);
207 | mRouteTextDistanceTwo = (TextView) findViewById(R.id.route_line_two_distance);
208 | mRouteTextDistanceThree = (TextView) findViewById(R.id.route_line_three_distance);
209 | }
210 |
211 |
212 | /**
213 | * 初始化AMap对象
214 | */
215 | private void init() {
216 | if (mAMap == null) {
217 | mAMap = mMapView.getMap();
218 | mAMap.setTrafficEnabled(false);
219 | mAMap.setOnMapLoadedListener(this);
220 | mImageTraffic.setImageResource(R.drawable.map_traffic_white);
221 | UiSettings uiSettings = mAMap.getUiSettings();
222 | uiSettings.setZoomControlsEnabled(false);
223 | }
224 | }
225 |
226 | /**
227 | * 绘制路径规划结果
228 | *
229 | * @param routeId 路径规划线路ID
230 | * @param path AMapNaviPath
231 | */
232 | private void drawRoutes(int routeId, AMapNaviPath path) {
233 | mAMap.moveCamera(CameraUpdateFactory.changeTilt(0));
234 | RouteOverLay routeOverLay = new RouteOverLay(mAMap, path, this);
235 | try {
236 | routeOverLay.setWidth(60f);
237 | } catch (AMapNaviException e) {
238 | e.printStackTrace();
239 | }
240 | routeOverLay.setTrafficLine(true);
241 | routeOverLay.addToMap();
242 | routeOverlays.put(routeId, routeOverLay);
243 | }
244 |
245 |
246 | /**
247 | * 开始导航
248 | */
249 | private void startNavi() {
250 | if (routeID != -1){
251 | mAMapNavi.selectRouteId(routeID);
252 | Intent gpsintent = new Intent(getApplicationContext(), RouteNaviActivity.class);
253 | gpsintent.putExtra("gps", false); // gps 为true为真实导航,为false为模拟导航
254 | startActivity(gpsintent);
255 | }
256 | }
257 |
258 | /**
259 | * 路线tag选中设置
260 | *
261 | * @param lineOne
262 | * @param lineTwo
263 | * @param lineThree
264 | */
265 | private void focuseRouteLine(boolean lineOne, boolean lineTwo, boolean lineThree) {
266 | Log.d("LG", "lineOne:" + lineOne + " lineTwo:" + lineTwo + " lineThree:" + lineThree);
267 | setLinelayoutOne(lineOne);
268 | setLinelayoutTwo(lineTwo);
269 | setLinelayoutThree(lineThree);
270 | }
271 |
272 | /**
273 | * 地图实时交通开关
274 | */
275 | private void setTraffic() {
276 | if (mAMap.isTrafficEnabled()) {
277 | mImageTraffic.setImageResource(R.drawable.map_traffic_white);
278 | mAMap.setTrafficEnabled(false);
279 | } else {
280 | mImageTraffic.setImageResource(R.drawable.map_traffic_hl_white);
281 | mAMap.setTrafficEnabled(true);
282 | }
283 | }
284 |
285 | private void cleanRouteOverlay() {
286 | for (int i = 0; i < routeOverlays.size(); i++) {
287 | int key = routeOverlays.keyAt(i);
288 | RouteOverLay overlay = routeOverlays.get(key);
289 | overlay.removeFromMap();
290 | overlay.destroy();
291 | }
292 | routeOverlays.clear();
293 | }
294 |
295 | /**
296 | * 跳转到驾车偏好设置页面
297 | */
298 | private void strategyChoose() {
299 | Intent intent = new Intent(this, StrategyChooseActivity.class);
300 | intent.putExtra(Utils.INTENT_NAME_AVOID_CONGESTION, mStrategyBean.isCongestion());
301 | intent.putExtra(Utils.INTENT_NAME_AVOID_COST, mStrategyBean.isCost());
302 | intent.putExtra(Utils.INTENT_NAME_AVOID_HIGHSPEED, mStrategyBean.isAvoidhightspeed());
303 | intent.putExtra(Utils.INTENT_NAME_PRIORITY_HIGHSPEED, mStrategyBean.isHightspeed());
304 | startActivityForResult(intent, Utils.START_ACTIVITY_REQUEST_CODE);
305 | }
306 |
307 | /**
308 | * @param paths 多路线回调路线
309 | * @param ints 多路线回调路线ID
310 | */
311 | private void setRouteLineTag(HashMap paths, int[] ints) {
312 | if (ints.length < 1) {
313 | visiableRouteLine(false, false, false);
314 | return;
315 | }
316 | int indexOne = 0;
317 | String stragegyTagOne = paths.get(ints[indexOne]).getLabels();
318 | setLinelayoutOneContent(ints[indexOne], stragegyTagOne);
319 | if (ints.length == 1) {
320 | visiableRouteLine(true, false, false);
321 | focuseRouteLine(true, false, false);
322 | return;
323 | }
324 |
325 | int indexTwo = 1;
326 | String stragegyTagTwo = paths.get(ints[indexTwo]).getLabels();
327 | setLinelayoutTwoContent(ints[indexTwo], stragegyTagTwo);
328 | if (ints.length == 2) {
329 | visiableRouteLine(true, true, false);
330 | focuseRouteLine(true, false, false);
331 | return;
332 | }
333 |
334 | int indexThree = 2;
335 | String stragegyTagThree = paths.get(ints[indexThree]).getLabels();
336 | setLinelayoutThreeContent(ints[indexThree], stragegyTagThree);
337 | if (ints.length >= 3) {
338 | visiableRouteLine(true, true, true);
339 | focuseRouteLine(true, false, false);
340 | }
341 |
342 | }
343 |
344 | private void visiableRouteLine(boolean lineOne, boolean lineTwo, boolean lineThree) {
345 | setLinelayoutOneVisiable(lineOne);
346 | setLinelayoutTwoVisiable(lineTwo);
347 | setLinelayoutThreeVisiable(lineThree);
348 | }
349 |
350 | private void setLinelayoutOneVisiable(boolean visiable) {
351 | if (visiable) {
352 | mRouteLineLayoutOne.setVisibility(View.VISIBLE);
353 | } else {
354 | mRouteLineLayoutOne.setVisibility(View.GONE);
355 | }
356 | }
357 |
358 | private void setLinelayoutTwoVisiable(boolean visiable) {
359 | if (visiable) {
360 | mRouteLinelayoutTwo.setVisibility(View.VISIBLE);
361 | } else {
362 | mRouteLinelayoutTwo.setVisibility(View.GONE);
363 | }
364 | }
365 |
366 | private void setLinelayoutThreeVisiable(boolean visiable) {
367 | if (visiable) {
368 | mRouteLineLayoutThree.setVisibility(View.VISIBLE);
369 | } else {
370 | mRouteLineLayoutThree.setVisibility(View.GONE);
371 | }
372 | }
373 |
374 | /**
375 | * 设置第一条线路Tab 内容
376 | *
377 | * @param routeID 路线ID
378 | * @param strategy 策略标签
379 | */
380 | private void setLinelayoutOneContent(int routeID, String strategy) {
381 | mRouteLineLayoutOne.setTag(routeID);
382 | RouteOverLay overlay = routeOverlays.get(routeID);
383 | overlay.zoomToSpan();
384 | AMapNaviPath path = overlay.getAMapNaviPath();
385 | mRouteTextStrategyOne.setText(strategy);
386 | String timeDes = Utils.getFriendlyTime(path.getAllTime());
387 | mRouteTextTimeOne.setText(timeDes);
388 | String disDes = Utils.getFriendlyDistance(path.getAllLength());
389 | mRouteTextDistanceOne.setText(disDes);
390 | }
391 |
392 | /**
393 | * 设置第二条路线Tab 内容
394 | *
395 | * @param routeID 路线ID
396 | * @param strategy 策略标签
397 | */
398 | private void setLinelayoutTwoContent(int routeID, String strategy) {
399 | mRouteLinelayoutTwo.setTag(routeID);
400 | RouteOverLay overlay = routeOverlays.get(routeID);
401 | AMapNaviPath path = overlay.getAMapNaviPath();
402 | mRouteTextStrategyTwo.setText(strategy);
403 | String timeDes = Utils.getFriendlyTime(path.getAllTime());
404 | mRouteTextTimeTwo.setText(timeDes);
405 | String disDes = Utils.getFriendlyDistance(path.getAllLength());
406 | mRouteTextDistanceTwo.setText(disDes);
407 | }
408 |
409 | /**
410 | * 设置第三条路线Tab 内容
411 | *
412 | * @param routeID 路线ID
413 | * @param strategy 策略标签
414 | */
415 | private void setLinelayoutThreeContent(int routeID, String strategy) {
416 | mRouteLineLayoutThree.setTag(routeID);
417 | RouteOverLay overlay = routeOverlays.get(routeID);
418 | AMapNaviPath path = overlay.getAMapNaviPath();
419 | mRouteTextStrategyThree.setText(strategy);
420 | String timeDes = Utils.getFriendlyTime(path.getAllTime());
421 | mRouteTextTimeThree.setText(timeDes);
422 | String disDes = Utils.getFriendlyDistance(path.getAllLength());
423 | mRouteTextDistanceThree.setText(disDes);
424 | }
425 |
426 | /**
427 | * 第一条路线是否focus
428 | *
429 | * @param focus focus为true 突出颜色显示,标示为选中状态,为false则标示非选中状态
430 | */
431 | private void setLinelayoutOne(boolean focus) {
432 | if (mRouteLineLayoutOne.getVisibility() != View.VISIBLE) {
433 | return;
434 | }
435 | try {
436 | RouteOverLay overlay = routeOverlays.get((int)mRouteLineLayoutOne.getTag());
437 | if (focus) {
438 | routeID = (int) mRouteLineLayoutOne.getTag();
439 | mCalculateRouteOverView.setText(Utils.getRouteOverView(overlay.getAMapNaviPath()));
440 | mAMapNavi.selectRouteId(routeID);
441 | overlay.setTransparency(ROUTE_SELECTED_TRANSPARENCY);
442 | mRouteViewOne.setVisibility(View.VISIBLE);
443 | mRouteTextStrategyOne.setTextColor(getResources().getColor(R.color.colorBlue));
444 | mRouteTextTimeOne.setTextColor(getResources().getColor(R.color.colorBlue));
445 | mRouteTextDistanceOne.setTextColor(getResources().getColor(R.color.colorBlue));
446 | } else {
447 | overlay.setTransparency(ROUTE_UNSELECTED_TRANSPARENCY);
448 | mRouteViewOne.setVisibility(View.INVISIBLE);
449 | mRouteTextStrategyOne.setTextColor(getResources().getColor(R.color.colorDark));
450 | mRouteTextTimeOne.setTextColor(getResources().getColor(R.color.colorBlack));
451 | mRouteTextDistanceOne.setTextColor(getResources().getColor(R.color.colorDark));
452 | }
453 | } catch (Exception e) {
454 | e.printStackTrace();
455 | }
456 | }
457 |
458 | /**
459 | * 第二条路线是否focus
460 | *
461 | * @param focus focus为true 突出颜色显示,标示为选中状态,为false则标示非选中状态
462 | */
463 | private void setLinelayoutTwo(boolean focus) {
464 | if (mRouteLinelayoutTwo.getVisibility() != View.VISIBLE) {
465 | return;
466 | }
467 | try {
468 | RouteOverLay overlay = routeOverlays.get((int) mRouteLinelayoutTwo.getTag());
469 | if (focus) {
470 | routeID = (int) mRouteLinelayoutTwo.getTag();
471 | mCalculateRouteOverView.setText(Utils.getRouteOverView(overlay.getAMapNaviPath()));
472 | mAMapNavi.selectRouteId(routeID);
473 | overlay.setTransparency(ROUTE_SELECTED_TRANSPARENCY);
474 | mRouteViewTwo.setVisibility(View.VISIBLE);
475 | mRouteTextStrategyTwo.setTextColor(getResources().getColor(R.color.colorBlue));
476 | mRouteTextTimeTwo.setTextColor(getResources().getColor(R.color.colorBlue));
477 | mRouteTextDistanceTwo.setTextColor(getResources().getColor(R.color.colorBlue));
478 | } else {
479 | overlay.setTransparency(ROUTE_UNSELECTED_TRANSPARENCY);
480 | mRouteViewTwo.setVisibility(View.INVISIBLE);
481 | mRouteTextStrategyTwo.setTextColor(getResources().getColor(R.color.colorDark));
482 | mRouteTextTimeTwo.setTextColor(getResources().getColor(R.color.colorBlack));
483 | mRouteTextDistanceTwo.setTextColor(getResources().getColor(R.color.colorDark));
484 | }
485 | } catch (Exception e) {
486 | e.printStackTrace();
487 | }
488 | }
489 |
490 | /**
491 | * 第三条路线是否focus
492 | *
493 | * @param focus focus为true 突出颜色显示,标示为选中状态,为false则标示非选中状态
494 | */
495 | private void setLinelayoutThree(boolean focus) {
496 | if (mRouteLineLayoutThree.getVisibility() != View.VISIBLE) {
497 | return;
498 | }
499 | try {
500 | RouteOverLay overlay = routeOverlays.get((int) mRouteLineLayoutThree.getTag());
501 | if (overlay == null) {
502 | return;
503 | }
504 | if (focus) {
505 | routeID = (int) mRouteLineLayoutThree.getTag();
506 | mCalculateRouteOverView.setText(Utils.getRouteOverView(overlay.getAMapNaviPath()));
507 | mAMapNavi.selectRouteId(routeID);
508 | overlay.setTransparency(ROUTE_SELECTED_TRANSPARENCY);
509 | mRouteViewThree.setVisibility(View.VISIBLE);
510 | mRouteTextStrategyThree.setTextColor(getResources().getColor(R.color.colorBlue));
511 | mRouteTextTimeThree.setTextColor(getResources().getColor(R.color.colorBlue));
512 | mRouteTextDistanceThree.setTextColor(getResources().getColor(R.color.colorBlue));
513 | } else {
514 | overlay.setTransparency(ROUTE_UNSELECTED_TRANSPARENCY);
515 | mRouteViewThree.setVisibility(View.INVISIBLE);
516 | mRouteTextStrategyThree.setTextColor(getResources().getColor(R.color.colorDark));
517 | mRouteTextTimeThree.setTextColor(getResources().getColor(R.color.colorBlack));
518 | mRouteTextDistanceThree.setTextColor(getResources().getColor(R.color.colorDark));
519 | }
520 | } catch (Exception e) {
521 | e.printStackTrace();
522 | }
523 | }
524 |
525 | /**
526 | * 方法必须重写
527 | */
528 | @Override
529 | protected void onResume() {
530 | super.onResume();
531 | mMapView.onResume();
532 | }
533 |
534 | /**
535 | * 方法必须重写
536 | */
537 | @Override
538 | protected void onPause() {
539 | super.onPause();
540 | mMapView.onPause();
541 | }
542 |
543 | /**
544 | * 方法必须重写
545 | */
546 | @Override
547 | protected void onSaveInstanceState(Bundle outState) {
548 | super.onSaveInstanceState(outState);
549 | mMapView.onSaveInstanceState(outState);
550 | }
551 |
552 | /**
553 | * 方法必须重写
554 | */
555 | @Override
556 | protected void onDestroy() {
557 | super.onDestroy();
558 | mMapView.onDestroy();
559 | if (mAMapNavi != null) {
560 | mAMapNavi.destroy();
561 | }
562 | }
563 |
564 | @Override
565 | public void onInitNaviFailure() {
566 |
567 | }
568 |
569 | @Override
570 | public void onInitNaviSuccess() {
571 |
572 | }
573 |
574 | @Override
575 | public void onStartNavi(int i) {
576 |
577 | }
578 |
579 | @Override
580 | public void onTrafficStatusUpdate() {
581 |
582 | }
583 |
584 | @Override
585 | public void onLocationChange(AMapNaviLocation aMapNaviLocation) {
586 |
587 | }
588 |
589 | @Override
590 | public void onGetNavigationText(int i, String s) {
591 |
592 | }
593 |
594 | @Override
595 | public void onGetNavigationText(String s) {
596 |
597 | }
598 |
599 | @Override
600 | public void onEndEmulatorNavi() {
601 |
602 | }
603 |
604 | @Override
605 | public void onArriveDestination() {
606 |
607 | }
608 |
609 | @Override
610 | public void onCalculateRouteFailure(int i) {
611 | Toast.makeText(this.getApplicationContext(),"错误码"+i,Toast.LENGTH_LONG).show();
612 | }
613 |
614 | @Override
615 | public void onReCalculateRouteForYaw() {
616 |
617 | }
618 |
619 | @Override
620 | public void onReCalculateRouteForTrafficJam() {
621 |
622 | }
623 |
624 | @Override
625 | public void onArrivedWayPoint(int i) {
626 |
627 | }
628 |
629 | @Override
630 | public void onGpsOpenStatus(boolean b) {
631 |
632 | }
633 |
634 | @Override
635 | public void onNaviInfoUpdated(AMapNaviInfo aMapNaviInfo) {
636 |
637 | }
638 |
639 | @Override
640 | public void updateCameraInfo(AMapNaviCameraInfo[] aMapNaviCameraInfos) {
641 |
642 | }
643 |
644 | @Override
645 | public void updateIntervalCameraInfo(AMapNaviCameraInfo aMapNaviCameraInfo, AMapNaviCameraInfo aMapNaviCameraInfo1, int i) {
646 |
647 | }
648 |
649 | @Override
650 | public void onServiceAreaUpdate(AMapServiceAreaInfo[] aMapServiceAreaInfos) {
651 |
652 | }
653 |
654 | @Override
655 | public void onNaviInfoUpdate(NaviInfo naviInfo) {
656 |
657 | }
658 |
659 | @Override
660 | public void OnUpdateTrafficFacility(AMapNaviTrafficFacilityInfo aMapNaviTrafficFacilityInfo) {
661 |
662 | }
663 |
664 | @Override
665 | public void OnUpdateTrafficFacility(TrafficFacilityInfo trafficFacilityInfo) {
666 |
667 | }
668 |
669 | @Override
670 | public void showCross(AMapNaviCross aMapNaviCross) {
671 |
672 | }
673 |
674 | @Override
675 | public void hideCross() {
676 |
677 | }
678 |
679 | @Override
680 | public void showModeCross(AMapModelCross aMapModelCross) {
681 |
682 | }
683 |
684 | @Override
685 | public void hideModeCross() {
686 |
687 | }
688 |
689 | @Override
690 | public void showLaneInfo(AMapLaneInfo[] aMapLaneInfos, byte[] bytes, byte[] bytes1) {
691 |
692 | }
693 |
694 | @Override
695 | public void showLaneInfo(AMapLaneInfo aMapLaneInfo) {
696 |
697 | }
698 |
699 | @Override
700 | public void hideLaneInfo() {
701 |
702 | }
703 |
704 | @Override
705 | public void onCalculateRouteSuccess(int[] ints) {
706 | cleanRouteOverlay();
707 | HashMap paths = mAMapNavi.getNaviPaths();
708 | for (int i = 0; i < ints.length; i++) {
709 | AMapNaviPath path = paths.get(ints[i]);
710 | if (path != null) {
711 | drawRoutes(ints[i], path);
712 | }
713 | }
714 | setRouteLineTag(paths, ints);
715 | mAMap.setMapType(AMap.MAP_TYPE_NAVI);
716 | }
717 |
718 | @Override
719 | public void notifyParallelRoad(int i) {
720 |
721 | }
722 |
723 | @Override
724 | public void OnUpdateTrafficFacility(AMapNaviTrafficFacilityInfo[] aMapNaviTrafficFacilityInfos) {
725 |
726 | }
727 |
728 | @Override
729 | public void updateAimlessModeStatistics(AimLessModeStat aimLessModeStat) {
730 |
731 | }
732 |
733 | @Override
734 | public void updateAimlessModeCongestionInfo(AimLessModeCongestionInfo aimLessModeCongestionInfo) {
735 |
736 | }
737 |
738 | @Override
739 | public void onPlayRing(int i) {
740 |
741 | }
742 |
743 | @Override
744 | public void onMapLoaded() {
745 | calculateDriveRoute();
746 | }
747 | }
748 |
--------------------------------------------------------------------------------