mWayPointList;
52 | private UiSettings mUiSettings;
53 |
54 | @Override
55 | protected void onCreate(@Nullable Bundle savedInstanceState) {
56 | super.onCreate(savedInstanceState);
57 | this.requestWindowFeature(Window.FEATURE_NO_TITLE);
58 | this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
59 | WindowManager.LayoutParams.FLAG_FULLSCREEN);
60 | setContentView(R.layout.activity_nav);
61 | mAMapNaviView = (AMapNaviView) findViewById(R.id.navi_view);
62 | mAMapNaviView.onCreate(savedInstanceState);
63 | //实例化语音引擎
64 | mTtsManager = TTSController.getInstance(getApplicationContext());
65 | mTtsManager.init();
66 | initHudMap();
67 | MapActivity.TEXT_GO_MODE = 0;
68 | EventBus.getDefault().register(this);
69 | }
70 |
71 | private void initHudMap() {
72 | mAMapNavi = AMapNavi.getInstance(this);
73 | mUiSettings = mAMapNaviView.getMap().getUiSettings();
74 | mUiSettings.setRotateGesturesEnabled(false);
75 | mAMapNaviView.setAMapNaviViewListener(this);
76 | mAMapNavi.addAMapNaviListener(mTtsManager);
77 | mAMapNavi.addAMapNaviListener(this);
78 | mAMapNavi.setEmulatorNaviSpeed(60);
79 | }
80 |
81 | @Override
82 | protected void onResume() {
83 | super.onResume();
84 | }
85 |
86 | @Override
87 | protected void onDestroy() {
88 | super.onDestroy();
89 | mTtsManager.stopSpeaking();
90 | mAMapNaviView.onDestroy();
91 | //since 1.6.0
92 | //不再在naviview destroy的时候自动执行AMapNavi.stopNavi();
93 | //请自行执行
94 | mAMapNavi.stopNavi();
95 | mAMapNavi.destroy();
96 | mTtsManager.destroy();
97 | EventBus.getDefault().unregister(this);
98 | }
99 |
100 | /**
101 | * EventBus 接收
102 | */
103 |
104 | @Subscribe(threadMode = ThreadMode.MAIN)
105 | public void onEvent(NaviLatLngBean naviLatLngBean) {
106 | mStartLatlng = naviLatLngBean.getStartNaviLatLng();
107 | mEndLatlng = naviLatLngBean.getStopNaviLatLng();
108 | startNav();
109 | }
110 |
111 | private void startNav() {
112 | mStartList.add(mStartLatlng);
113 | mEndList.add(mEndLatlng);
114 | int strategy = 0;
115 | try {
116 | strategy = mAMapNavi.strategyConvert(true, false, false, false, false);
117 | } catch (Exception e) {
118 | e.printStackTrace();
119 | }
120 | if (MapUtil.PathPlanningMode==0){
121 | boolean ss = mAMapNavi.calculateDriveRoute(mStartList, mEndList, mWayPointList, PathPlanningStrategy.DRIVING_DEFAULT);
122 | }else if (MapUtil.PathPlanningMode==1){
123 | boolean ss = mAMapNavi.calculateDriveRoute(mStartList, mEndList, mWayPointList, PathPlanningStrategy.DRIVING_SHORTEST_DISTANCE);
124 | }else if (MapUtil.PathPlanningMode==2){
125 | boolean ss = mAMapNavi.calculateDriveRoute(mStartList, mEndList, mWayPointList, PathPlanningStrategy.DRIVING_AVOID_CONGESTION);
126 | }
127 |
128 | LogUtil.e("导航策略:" + MapUtil.PathPlanningMode);
129 | }
130 |
131 | @Override
132 | public void onNaviSetting() {
133 |
134 | }
135 |
136 | @Override
137 | public void onNaviCancel() {
138 |
139 | finish();
140 | }
141 |
142 | @Override
143 | public boolean onNaviBackClick() {
144 | return false;
145 | }
146 |
147 | @Override
148 | public void onNaviMapMode(int i) {
149 |
150 | }
151 |
152 | @Override
153 | public void onNaviTurnClick() {
154 |
155 | }
156 |
157 | @Override
158 | public void onNextRoadClick() {
159 |
160 | }
161 |
162 | @Override
163 | public void onScanViewButtonClick() {
164 |
165 | }
166 |
167 | @Override
168 | public void onLockMap(boolean b) {
169 |
170 | }
171 |
172 | @Override
173 | public void onNaviViewLoaded() {
174 |
175 | }
176 |
177 | @Override
178 | public void onInitNaviFailure() {
179 |
180 | }
181 |
182 | @Override
183 | public void onInitNaviSuccess() {
184 | /**
185 | * 方法:
186 | * int strategy=mAMapNavi.strategyConvert(congestion, avoidhightspeed, cost, hightspeed, multipleroute);
187 | * 参数:
188 | * @congestion 躲避拥堵
189 | * @avoidhightspeed 不走高速
190 | * @cost 避免收费
191 | * @hightspeed 高速优先
192 | * @multipleroute 多路径
193 | *
194 | * 说明:
195 | * 以上参数都是boolean类型,其中multipleroute参数表示是否多条路线,如果为true则此策略会算出多条路线。
196 | * 注意:
197 | * 不走高速与高速优先不能同时为true
198 | * 高速优先与避免收费不能同时为true
199 | */
200 |
201 | }
202 |
203 | @Override
204 | public void onStartNavi(int i) {
205 |
206 | }
207 |
208 | @Override
209 | public void onTrafficStatusUpdate() {
210 |
211 | }
212 |
213 | @Override
214 | public void onLocationChange(AMapNaviLocation aMapNaviLocation) {
215 |
216 | }
217 |
218 | @Override
219 | public void onGetNavigationText(int i, String s) {
220 |
221 | }
222 |
223 | @Override
224 | public void onEndEmulatorNavi() {
225 |
226 | }
227 |
228 | @Override
229 | public void onArriveDestination() {
230 |
231 | }
232 |
233 | @Override
234 | public void onCalculateRouteSuccess() {
235 | mAMapNavi.setEmulatorNaviSpeed(60);
236 | AMapNavi.getInstance(this).startNavi(NaviType.EMULATOR);
237 | }
238 |
239 | @Override
240 | public void onCalculateRouteFailure(int i) {
241 |
242 | }
243 |
244 | @Override
245 | public void onReCalculateRouteForYaw() {
246 |
247 | }
248 |
249 | @Override
250 | public void onReCalculateRouteForTrafficJam() {
251 |
252 | }
253 |
254 | @Override
255 | public void onArrivedWayPoint(int i) {
256 |
257 | }
258 |
259 | @Override
260 | public void onGpsOpenStatus(boolean b) {
261 |
262 | }
263 |
264 | @Override
265 | public void onNaviInfoUpdate(NaviInfo naviInfo) {
266 |
267 | }
268 |
269 | @Override
270 | public void onNaviInfoUpdated(AMapNaviInfo aMapNaviInfo) {
271 |
272 | }
273 |
274 | @Override
275 | public void updateCameraInfo(AMapNaviCameraInfo[] aMapNaviCameraInfos) {
276 |
277 | }
278 |
279 | @Override
280 | public void onServiceAreaUpdate(AMapServiceAreaInfo[] aMapServiceAreaInfos) {
281 |
282 | }
283 |
284 | @Override
285 | public void showCross(AMapNaviCross aMapNaviCross) {
286 |
287 | }
288 |
289 | @Override
290 | public void hideCross() {
291 |
292 | }
293 |
294 | @Override
295 | public void showLaneInfo(AMapLaneInfo[] aMapLaneInfos, byte[] bytes, byte[] bytes1) {
296 |
297 | }
298 |
299 | @Override
300 | public void hideLaneInfo() {
301 |
302 | }
303 |
304 | @Override
305 | public void onCalculateMultipleRoutesSuccess(int[] ints) {
306 |
307 | }
308 |
309 | @Override
310 | public void notifyParallelRoad(int i) {
311 |
312 | }
313 |
314 | @Override
315 | public void OnUpdateTrafficFacility(AMapNaviTrafficFacilityInfo aMapNaviTrafficFacilityInfo) {
316 |
317 | }
318 |
319 | @Override
320 | public void OnUpdateTrafficFacility(AMapNaviTrafficFacilityInfo[] aMapNaviTrafficFacilityInfos) {
321 |
322 | }
323 |
324 | @Override
325 | public void OnUpdateTrafficFacility(TrafficFacilityInfo trafficFacilityInfo) {
326 |
327 | }
328 |
329 | @Override
330 | public void updateAimlessModeStatistics(AimLessModeStat aimLessModeStat) {
331 |
332 | }
333 |
334 | @Override
335 | public void updateAimlessModeCongestionInfo(AimLessModeCongestionInfo aimLessModeCongestionInfo) {
336 |
337 | }
338 |
339 | @Override
340 | public void onPlayRing(int i) {
341 |
342 | }
343 |
344 |
345 |
346 |
347 | /* @Subscribe(threadMode = ThreadMode.MAIN)
348 | public void onEvent(String msg) {
349 | if (msg.equalsIgnoreCase("PhoneComming")) {
350 | Intent intent = new Intent();
351 | intent.setAction(MyVar.STATICACTION);
352 | sendBroadcast(intent);
353 | }
354 | }*/
355 | }
356 |
--------------------------------------------------------------------------------
/app/src/main/java/com/test/map/TTSController.java:
--------------------------------------------------------------------------------
1 | package com.test.map;
2 |
3 | import android.content.Context;
4 | import android.os.Bundle;
5 | import android.os.Handler;
6 | import android.os.Message;
7 | import android.widget.Toast;
8 |
9 | import com.amap.api.navi.MyNaviListener;
10 | import com.amap.api.navi.model.AMapLaneInfo;
11 | import com.amap.api.navi.model.AMapNaviCameraInfo;
12 | import com.amap.api.navi.model.AMapNaviCross;
13 | import com.amap.api.navi.model.AMapNaviInfo;
14 | import com.amap.api.navi.model.AMapNaviLocation;
15 | import com.amap.api.navi.model.AMapNaviTrafficFacilityInfo;
16 | import com.amap.api.navi.model.AMapServiceAreaInfo;
17 | import com.amap.api.navi.model.AimLessModeCongestionInfo;
18 | import com.amap.api.navi.model.AimLessModeStat;
19 | import com.amap.api.navi.model.AmapCarLocation;
20 | import com.amap.api.navi.model.NaviInfo;
21 | import com.autonavi.tbt.TrafficFacilityInfo;
22 | import com.iflytek.cloud.ErrorCode;
23 | import com.iflytek.cloud.InitListener;
24 | import com.iflytek.cloud.SpeechConstant;
25 | import com.iflytek.cloud.SpeechError;
26 | import com.iflytek.cloud.SpeechSynthesizer;
27 | import com.iflytek.cloud.SpeechUtility;
28 | import com.iflytek.cloud.SynthesizerListener;
29 | import com.test.map.util.LogUtil;
30 |
31 | import java.util.LinkedList;
32 |
33 | /**
34 | * 当前DEMO的播报方式是队列模式。其原理就是依次将需要播报的语音放入链表中,播报过程是从头开始依次往后播报。
35 | *
36 | * 导航SDK原则上是不提供语音播报模块的,如果您觉得此种播报方式不能满足你的需求,请自行优化或改进。
37 | */
38 | public class TTSController implements MyNaviListener {
39 |
40 | /**
41 | * 请替换您自己申请的ID。
42 | */
43 | private final String appId = "59146818"; //59146818 5350db8d
44 |
45 | public static TTSController ttsManager;
46 | private Context mContext;
47 | private SpeechSynthesizer mTts;
48 | private boolean isPlaying = false;
49 | private LinkedList wordList = new LinkedList();
50 | private final int TTS_PLAY = 1;
51 | private final int CHECK_TTS_PLAY = 2;
52 | private Handler handler = new Handler() {
53 | @Override
54 | public void handleMessage(Message msg) {
55 | super.handleMessage(msg);
56 | switch (msg.what) {
57 | case TTS_PLAY:
58 | synchronized (mTts) {
59 | if (!isPlaying && mTts != null && wordList.size() > 0) {
60 | isPlaying = true;
61 | String playtts = wordList.removeFirst();
62 | if (mTts == null) {
63 | createSynthesizer();
64 | }
65 | mTts.startSpeaking(playtts, new SynthesizerListener() {
66 | @Override
67 | public void onCompleted(SpeechError arg0) {
68 | LogUtil.e("onSpeak onCompleted........");
69 | isPlaying = false;
70 | handler.obtainMessage(1).sendToTarget();
71 | }
72 |
73 | @Override
74 | public void onEvent(int arg0, int arg1, int arg2, Bundle arg3) {
75 | }
76 |
77 | @Override
78 | public void onBufferProgress(int arg0, int arg1, int arg2, String arg3) {
79 | // 合成进度
80 | isPlaying = true;
81 |
82 | }
83 |
84 | @Override
85 | public void onSpeakBegin() {
86 | //开始播放
87 | isPlaying = true;
88 | LogUtil.e("onSpeakBegin....");
89 | }
90 |
91 | @Override
92 | public void onSpeakPaused() {
93 |
94 | }
95 |
96 | @Override
97 | public void onSpeakProgress(int arg0, int arg1, int arg2) {
98 | //播放进度
99 | isPlaying = true;
100 | }
101 |
102 | @Override
103 | public void onSpeakResumed() {
104 | //继续播放
105 | isPlaying = true;
106 |
107 | }
108 | });
109 | }
110 | }
111 | break;
112 | case CHECK_TTS_PLAY:
113 | if (!isPlaying) {
114 | handler.obtainMessage(1).sendToTarget();
115 | }
116 | break;
117 | }
118 |
119 | }
120 | };
121 |
122 | private TTSController(Context context) {
123 | mContext = context.getApplicationContext();
124 | SpeechUtility.createUtility(mContext, SpeechConstant.APPID + "=" + appId);
125 | if (mTts == null) {
126 | createSynthesizer();
127 | }
128 | }
129 |
130 | private void createSynthesizer() {
131 | mTts = SpeechSynthesizer.createSynthesizer(mContext,
132 | new InitListener() {
133 | @Override
134 | public void onInit(int errorcode) {
135 | if (ErrorCode.SUCCESS == errorcode) {
136 | } else {
137 | Toast.makeText(mContext, "语音合成初始化失败!", Toast.LENGTH_SHORT);
138 | }
139 | }
140 | });
141 | }
142 |
143 | public void init() {
144 | //设置发音人
145 | mTts.setParameter(SpeechConstant.VOICE_NAME, "xiaoyan"); //xiaoyan 支持年轻女声小燕,年轻男声小宇,中老年男声老孙,可爱蜡笔小新等声音
146 | //设置语速,值范围:[0, 100],默认值:50
147 | mTts.setParameter(SpeechConstant.SPEED, "55");
148 | //设置音量
149 | mTts.setParameter(SpeechConstant.VOLUME, "tts_volume");
150 | //设置语调
151 | mTts.setParameter(SpeechConstant.PITCH, "tts_pitch");
152 | }
153 |
154 | public static TTSController getInstance(Context context) {
155 | if (ttsManager == null) {
156 | ttsManager = new TTSController(context);
157 | }
158 | return ttsManager;
159 | }
160 |
161 | public void stopSpeaking() {
162 | if (wordList != null) {
163 | wordList.clear();
164 | }
165 | if (mTts != null) {
166 | mTts.stopSpeaking();
167 | }
168 | isPlaying = false;
169 | }
170 |
171 | public void destroy() {
172 | if (wordList != null) {
173 | wordList.clear();
174 | }
175 | if (mTts != null) {
176 | mTts.destroy();
177 | }
178 | }
179 |
180 | /****************************************************************************
181 | * 以下都是导航相关接口
182 | ****************************************************************************/
183 |
184 |
185 | @Override
186 | public void onArriveDestination() {
187 | }
188 |
189 | @Override
190 | public void onArrivedWayPoint(int arg0) {
191 | }
192 |
193 | @Override
194 | public void onCalculateRouteFailure(int arg0) {
195 | if (wordList != null)
196 | wordList.addLast("路线规划失败");
197 | }
198 |
199 | @Override
200 | public void onCalculateRouteSuccess() {
201 | }
202 |
203 | @Override
204 | public void onEndEmulatorNavi() {
205 | }
206 |
207 | @Override
208 | public void onGetNavigationText(int arg0, String arg1) {
209 | if (wordList != null)
210 | wordList.addLast(arg1);
211 | handler.obtainMessage(CHECK_TTS_PLAY).sendToTarget();
212 | }
213 |
214 |
215 | @Override
216 | public void onInitNaviFailure() {
217 | }
218 |
219 | @Override
220 | public void onInitNaviSuccess() {
221 | }
222 |
223 | @Override
224 | public void onLocationChange(AMapNaviLocation arg0) {
225 | }
226 |
227 | @Override
228 | public void onReCalculateRouteForTrafficJam() {
229 | if (wordList != null)
230 | wordList.addLast("前方路线拥堵,路线重新规划");
231 | }
232 |
233 | @Override
234 | public void onReCalculateRouteForYaw() {
235 | if (wordList != null)
236 | wordList.addLast("路线重新规划");
237 | }
238 |
239 | @Override
240 | public void onStartNavi(int arg0) {
241 | }
242 |
243 | @Override
244 | public void onTrafficStatusUpdate() {
245 | }
246 |
247 | @Override
248 | public void onGpsOpenStatus(boolean enabled) {
249 | }
250 |
251 | @Override
252 | public void onNaviInfoUpdate(NaviInfo naviinfo) {
253 |
254 | }
255 |
256 | @Override
257 | public void onNaviInfoUpdated(AMapNaviInfo aMapNaviInfo) {
258 |
259 | }
260 |
261 | @Override
262 | public void updateCameraInfo(AMapNaviCameraInfo[] infoArray) {
263 |
264 | }
265 |
266 | @Override
267 | public void onServiceAreaUpdate(AMapServiceAreaInfo[] infoArray) {
268 |
269 | }
270 |
271 | @Override
272 | public void showCross(AMapNaviCross aMapNaviCross) {
273 |
274 | }
275 |
276 | @Override
277 | public void hideCross() {
278 |
279 | }
280 |
281 | @Override
282 | public void showLaneInfo(AMapLaneInfo[] laneInfos, byte[] laneBackgroundInfo, byte[] laneRecommendedInfo) {
283 |
284 | }
285 |
286 |
287 | @Override
288 | public void hideLaneInfo() {
289 |
290 | }
291 |
292 | @Override
293 | public void onCalculateMultipleRoutesSuccess(int[] routeIds) {
294 |
295 | }
296 |
297 | @Override
298 | public void notifyParallelRoad(int parallelRoadType) {
299 |
300 | }
301 |
302 | @Override
303 | public void OnUpdateTrafficFacility(AMapNaviTrafficFacilityInfo aMapNaviTrafficFacilityInfo) {
304 |
305 | }
306 |
307 | @Override
308 | public void OnUpdateTrafficFacility(AMapNaviTrafficFacilityInfo[] infos) {
309 |
310 | }
311 |
312 | @Override
313 | public void OnUpdateTrafficFacility(TrafficFacilityInfo trafficFacilityInfo) {
314 |
315 | }
316 |
317 | @Override
318 | public void updateAimlessModeStatistics(AimLessModeStat aimLessModeStat) {
319 |
320 | }
321 |
322 | @Override
323 | public void updateAimlessModeCongestionInfo(AimLessModeCongestionInfo aimLessModeCongestionInfo) {
324 |
325 | }
326 |
327 | @Override
328 | public void onPlayRing(int type) {
329 |
330 | }
331 |
332 |
333 | @Override
334 | public void carProjectionChange(AmapCarLocation mCarProjectionChange) {
335 |
336 | }
337 |
338 |
339 | }
340 |
--------------------------------------------------------------------------------
/app/src/main/java/com/test/map/adapter/MapHistoryListAdapter.java:
--------------------------------------------------------------------------------
1 | package com.test.map.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.TextView;
9 |
10 | import com.test.map.R;
11 | import com.test.map.sqlite.MapHistoryBean;
12 | import com.test.map.util.LogUtil;
13 |
14 | import java.util.List;
15 |
16 |
17 | /**
18 | * Created by FAN on 2017/5/11.
19 | */
20 | public class MapHistoryListAdapter extends BaseAdapter {
21 | private List data;
22 | private LayoutInflater layoutInflater;
23 | private Context context;
24 |
25 | public MapHistoryListAdapter(Context context, List been) {
26 | this.context = context;
27 | this.data = been;
28 | this.layoutInflater = LayoutInflater.from(context);
29 | }
30 |
31 | @Override
32 | public int getCount() {
33 | return data.size();
34 | }
35 |
36 | /**
37 | * 获得某一位置的数据
38 | */
39 | @Override
40 | public Object getItem(int position) {
41 | return data.get(position);
42 | }
43 |
44 | /**
45 | * 获得唯一标识
46 | */
47 | @Override
48 | public long getItemId(int position) {
49 | return position;
50 | }
51 |
52 |
53 | @Override
54 | public View getView(int position, View convertView, ViewGroup parent) {
55 | ViewHolder viewHolder = null;
56 | if (convertView == null) {
57 | viewHolder = new ViewHolder();
58 | //获得组件,实例化组件
59 | convertView = layoutInflater.inflate(R.layout.map_history_list_item, null);
60 | viewHolder.mapHistory_Name = (TextView) convertView.findViewById(R.id.map_history_name);
61 | convertView.setTag(viewHolder);
62 | } else {
63 | viewHolder = (ViewHolder) convertView.getTag();
64 | }
65 | //绑定数据
66 | if (null==data.get(position).getName()){
67 | LogUtil.e("kong null");
68 | }else {
69 | viewHolder.mapHistory_Name.setText(data.get(position).getName());
70 | }
71 |
72 |
73 | return convertView;
74 | }
75 |
76 | public final class ViewHolder {
77 | public TextView mapHistory_Name;
78 | }
79 | }
80 |
--------------------------------------------------------------------------------
/app/src/main/java/com/test/map/adapter/PoiSearchListAdapter.java:
--------------------------------------------------------------------------------
1 | package com.test.map.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.TextView;
9 |
10 | import com.test.map.R;
11 |
12 | import java.util.List;
13 | import java.util.Map;
14 |
15 |
16 | /**
17 | * Created by FAN on 2017/5/11.
18 | */
19 | public class PoiSearchListAdapter extends BaseAdapter {
20 | private List