opt
This commit is contained in:
@@ -47,4 +47,6 @@ public class AMapConstants {
|
||||
*/
|
||||
public static final String COMMAND_START_NAVI = "com.ileja.navi.route.confirm";
|
||||
|
||||
public static final String COMMAND_CHOOSE_PATH = "com.zhidao.route.plan";
|
||||
|
||||
}
|
||||
|
||||
@@ -2,6 +2,9 @@ package com.mogo.module.navi.constants;
|
||||
|
||||
import android.net.Uri;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author zyz
|
||||
* @since 2019-10-02
|
||||
@@ -42,4 +45,32 @@ public class DataConstants {
|
||||
public static final String COMPANY_ADDRESS_LATITUDE = "companyAddressLatitude";
|
||||
public static final String COMPANY_ADDRESS_LONGITUDE = "companyAddressLongitude";
|
||||
|
||||
// 泛化语义
|
||||
public static final String STRATEGY_THE_TIME_SHORTEST_PATH = "STRATEGY_THE_TIME_SHORTEST_PATH";
|
||||
public static final String[] WORDS_STRATEGY_THE_TIME_SHORTEST_PATH = {"最快的"};
|
||||
public static final String STRATEGY_THE_DISTANCE_SHORTEST_PATH = "STRATEGY_THE_DISTANCE_SHORTEST_PATH";
|
||||
public static final String[] WORDS_STRATEGY_THE_DISTANCE_SHORTED_PATH = {"路程最短的"};
|
||||
|
||||
// 第x个选个
|
||||
public static final String STRATEGY_THE_FIRST_PATH = "STRATEGY_THE_FIRST_PATH";
|
||||
public static final String[] WORDS_STRATEGY_THE_FIRST_PATH = {"第一个"};
|
||||
public static final String STRATEGY_THE_SECOND_PATH = "STRATEGY_THE_SECOND_PATH";
|
||||
public static final String[] WORDS_STRATEGY_THE_SECOND_PATH = {"第二个"};
|
||||
public static final String STRATEGY_THE_THIRD_PATH = "STRATEGY_THE_THIRD_PATH";
|
||||
public static final String[] WORDS_STRATEGY_THE_THIRD_PATH = {"第三个"};
|
||||
|
||||
// 开始导航
|
||||
public static final String STRATEGY_START_NAVI = "STRATEGY_START_NAVI";
|
||||
public static final String[] WORDS_STRATEGY_START_NAVI = {"开始导航", "开始"};
|
||||
|
||||
public static final Map< String, String[] > sCmds = new HashMap<>();
|
||||
|
||||
static {
|
||||
sCmds.put( STRATEGY_THE_TIME_SHORTEST_PATH, WORDS_STRATEGY_THE_TIME_SHORTEST_PATH );
|
||||
sCmds.put( STRATEGY_THE_DISTANCE_SHORTEST_PATH, WORDS_STRATEGY_THE_DISTANCE_SHORTED_PATH );
|
||||
sCmds.put( STRATEGY_THE_FIRST_PATH, WORDS_STRATEGY_THE_FIRST_PATH );
|
||||
sCmds.put( STRATEGY_THE_SECOND_PATH, WORDS_STRATEGY_THE_SECOND_PATH );
|
||||
sCmds.put( STRATEGY_THE_THIRD_PATH, WORDS_STRATEGY_THE_THIRD_PATH );
|
||||
sCmds.put( STRATEGY_START_NAVI, WORDS_STRATEGY_START_NAVI );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,7 +4,6 @@ import android.content.Context;
|
||||
import android.text.TextUtils;
|
||||
import android.view.View;
|
||||
import com.mogo.map.navi.MogoCalculatePath;
|
||||
import com.mogo.map.search.inputtips.MogoTip;
|
||||
import com.mogo.module.navi.R;
|
||||
import com.mogo.module.navi.ui.adapter.base.RecycleBaseAdapter;
|
||||
import com.mogo.module.navi.ui.adapter.base.RecycleViewHolder;
|
||||
@@ -53,8 +52,8 @@ public class CalculatePathAdapter extends RecycleBaseAdapter<MogoCalculatePath>
|
||||
if (holder.getLayoutPosition() >= 2) {
|
||||
mName.setVisibility(View.GONE);
|
||||
}
|
||||
holder.setText(R.id.amap_calculate_item_strategy_time, item.getTime());
|
||||
holder.setText(R.id.amap_calculate_item_strategy_distance, item.getDistance());
|
||||
holder.setText(R.id.amap_calculate_item_strategy_time, item.getFormattedTime());
|
||||
holder.setText(R.id.amap_calculate_item_strategy_distance, item.getFormattedDistance());
|
||||
holder.setText(R.id.amap_calculate_item_strategy_desc, item.getDesc());
|
||||
|
||||
if (TextUtils.isEmpty(item.getDesc())) {
|
||||
|
||||
@@ -11,25 +11,26 @@ import com.mogo.commons.voice.IMogoVoiceCmdCallBack
|
||||
import com.mogo.map.MogoLatLng
|
||||
import com.mogo.map.navi.IMogoNaviListener
|
||||
import com.mogo.map.navi.MogoCalculatePath
|
||||
import com.mogo.map.navi.MogoNaviInfo
|
||||
import com.mogo.map.navi.MogoTraffic
|
||||
import com.mogo.module.common.MogoModulePaths
|
||||
import com.mogo.map.navi.MogoNaviConfig
|
||||
import com.mogo.module.common.map.MapCenterPointStrategy
|
||||
import com.mogo.module.common.map.Scene
|
||||
import com.mogo.module.navi.R
|
||||
import com.mogo.module.navi.constants.AMapConstants
|
||||
import com.mogo.module.navi.constants.DataConstants
|
||||
import com.mogo.module.navi.constants.SearchServiceHolder
|
||||
import com.mogo.module.navi.manager.SettingManager
|
||||
import com.mogo.module.navi.ui.adapter.CalculatePathAdapter
|
||||
import com.mogo.module.navi.ui.base.BaseFragment
|
||||
import com.mogo.service.intent.IMogoIntentListener
|
||||
import com.mogo.utils.UiThreadHandler
|
||||
import com.mogo.utils.logger.Logger
|
||||
import kotlinx.android.synthetic.main.fragment_search_category.group_path
|
||||
import kotlinx.android.synthetic.main.fragment_search_category.pb_path
|
||||
import kotlinx.android.synthetic.main.fragment_search_category.rv_search_result
|
||||
import kotlinx.android.synthetic.main.fragment_search_category.tv_navi_navi
|
||||
import kotlinx.android.synthetic.main.include_search_bar.et_navi_search
|
||||
import kotlinx.android.synthetic.main.include_search_bar.iv_navi_back
|
||||
import org.json.JSONObject
|
||||
|
||||
/**
|
||||
* @author zyz
|
||||
@@ -37,24 +38,34 @@ import kotlinx.android.synthetic.main.include_search_bar.iv_navi_back
|
||||
*/
|
||||
class ChoosePathFragment : BaseFragment(), IMogoNaviListener, IMogoVoiceCmdCallBack, IMogoIntentListener {
|
||||
|
||||
var mTimeShortestPosition = -1
|
||||
var mDistanceShortestPosition = -1
|
||||
|
||||
override fun onCmdSelected(cmd: String?) {
|
||||
when (cmd) {
|
||||
"firstPath" -> {
|
||||
DataConstants.STRATEGY_THE_FIRST_PATH -> {
|
||||
selectItem(0)
|
||||
startNavi()
|
||||
|
||||
}
|
||||
"secondPath" -> {
|
||||
DataConstants.STRATEGY_THE_SECOND_PATH -> {
|
||||
selectItem(1)
|
||||
startNavi()
|
||||
|
||||
}
|
||||
"thirdPath" -> {
|
||||
DataConstants.STRATEGY_THE_THIRD_PATH -> {
|
||||
selectItem(2)
|
||||
startNavi()
|
||||
|
||||
}
|
||||
"startNavi" -> {
|
||||
DataConstants.STRATEGY_START_NAVI -> {
|
||||
startNavi()
|
||||
}
|
||||
DataConstants.STRATEGY_THE_DISTANCE_SHORTEST_PATH -> {
|
||||
// 路程最短
|
||||
selectItem(mDistanceShortestPosition)
|
||||
startNavi()
|
||||
}
|
||||
DataConstants.STRATEGY_THE_TIME_SHORTEST_PATH -> {
|
||||
// 时间最短
|
||||
selectItem(mTimeShortestPosition)
|
||||
startNavi()
|
||||
}
|
||||
"retry" -> {
|
||||
@@ -63,45 +74,15 @@ class ChoosePathFragment : BaseFragment(), IMogoNaviListener, IMogoVoiceCmdCallB
|
||||
"cancel" -> {
|
||||
SearchServiceHolder.fragmentManager.clearAll()
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private fun selectItem(index: Int) {
|
||||
|
||||
if (mAdapter.list.size > index) {
|
||||
if (mAdapter.list.size > index && index > 0) {
|
||||
selectPath(mAdapter.list[index])
|
||||
}
|
||||
}
|
||||
|
||||
override fun onCmdAction(speakText: String?) {
|
||||
}
|
||||
|
||||
override fun onCmdCancel(speakText: String?) {
|
||||
}
|
||||
|
||||
override fun onSpeakEnd(speakText: String?) {
|
||||
}
|
||||
|
||||
override fun onSpeakSelectTimeOut(speakText: String?) {
|
||||
}
|
||||
|
||||
override fun onInitNaviFailure() {
|
||||
}
|
||||
|
||||
override fun onInitNaviSuccess() {
|
||||
}
|
||||
|
||||
override fun onNaviInfoUpdate(naviinfo: MogoNaviInfo?) {
|
||||
}
|
||||
|
||||
override fun onStartNavi() {
|
||||
}
|
||||
|
||||
override fun onStopNavi() {
|
||||
}
|
||||
|
||||
override fun onCalculateSuccess() {
|
||||
var calculatedStrategies = SearchServiceHolder.getNavi().calculatedStrategies
|
||||
if (calculatedStrategies != null && calculatedStrategies.size > 0) {
|
||||
@@ -115,9 +96,33 @@ class ChoosePathFragment : BaseFragment(), IMogoNaviListener, IMogoVoiceCmdCallB
|
||||
return@postDelayed
|
||||
}
|
||||
SearchServiceHolder.getNavi().itemClickInteraction.onItemClicked(calculatedStrategies[0].tagId)
|
||||
|
||||
if (calculatedStrategies.size == 1) {
|
||||
// 一条路线,自动开启导航
|
||||
startNavi()
|
||||
}
|
||||
}, 500L)
|
||||
|
||||
if (calculatedStrategies.size > 1) {
|
||||
|
||||
var timeShortest = Integer.MAX_VALUE
|
||||
var distanceShortest = Integer.MAX_VALUE
|
||||
|
||||
for (i in 0 until calculatedStrategies.size) {
|
||||
if (timeShortest > calculatedStrategies[i].time) {
|
||||
timeShortest = calculatedStrategies[i].time
|
||||
mTimeShortestPosition = i
|
||||
}
|
||||
if (distanceShortest > calculatedStrategies[i].distance) {
|
||||
distanceShortest = calculatedStrategies[i].distance
|
||||
mDistanceShortestPosition = i
|
||||
}
|
||||
}
|
||||
|
||||
Logger.d(TAG, "mTimeShortestPosition = ${mTimeShortestPosition}, mDistanceShortestPosition = $mDistanceShortestPosition")
|
||||
AIAssist.getInstance(context).speakTTSVoice(String.format("已为你规划处%d条路线,请选择", calculatedStrategies.size))
|
||||
}
|
||||
}
|
||||
AIAssist.getInstance(context).speakTTSVoice(String.format("已为你规划处%d条路线,请选择", calculatedStrategies.size))
|
||||
pb_path.visibility = View.GONE
|
||||
group_path.visibility = View.GONE
|
||||
tv_navi_navi.text = getString(R.string.start_navi)
|
||||
@@ -132,10 +137,6 @@ class ChoosePathFragment : BaseFragment(), IMogoNaviListener, IMogoVoiceCmdCallB
|
||||
pb_path.visibility = View.GONE
|
||||
|
||||
registerRetryVoice()
|
||||
|
||||
}
|
||||
|
||||
override fun onUpdateTraffic(traffic: MogoTraffic?) {
|
||||
}
|
||||
|
||||
private lateinit var mAdapter: CalculatePathAdapter
|
||||
@@ -143,24 +144,16 @@ class ChoosePathFragment : BaseFragment(), IMogoNaviListener, IMogoVoiceCmdCallB
|
||||
return R.layout.fragment_search_category
|
||||
}
|
||||
|
||||
val firstPath: String = "第一个"
|
||||
val secondPath: String = "第二个"
|
||||
val thirdPath: String = "第三个"
|
||||
val startNavi: String = "开始导航"
|
||||
|
||||
var mogoTip: MogoLatLng? = null
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
mogoTip = arguments?.getParcelable<MogoLatLng>(AMapConstants.KEY_PARCELABLE)
|
||||
|
||||
}
|
||||
|
||||
// 是否开启导航
|
||||
var isStartedNavi = false
|
||||
|
||||
override fun onViewCreated(
|
||||
view: View,
|
||||
savedInstanceState: Bundle?) {
|
||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||
|
||||
super.onViewCreated(view, savedInstanceState)
|
||||
iv_navi_back.setOnClickListener {
|
||||
@@ -199,13 +192,14 @@ class ChoosePathFragment : BaseFragment(), IMogoNaviListener, IMogoVoiceCmdCallB
|
||||
|
||||
SearchServiceHolder.getMarkerManger().removeMarkers()
|
||||
|
||||
AIAssist.getInstance(context).registerUnWakeupCommand("firstPath", arrayOf<String>(firstPath), this)
|
||||
AIAssist.getInstance(context).registerUnWakeupCommand("secondPath", arrayOf<String>(secondPath), this)
|
||||
AIAssist.getInstance(context).registerUnWakeupCommand("thirdPath", arrayOf<String>(thirdPath), this)
|
||||
AIAssist.getInstance(context).registerUnWakeupCommand("startNavi", arrayOf<String>(startNavi, "开始"), this)
|
||||
DataConstants.sCmds.entries.filter {
|
||||
it != null && !TextUtils.isEmpty(it.key) && (it.value?.isNotEmpty() ?: false)
|
||||
}.forEach {
|
||||
AIAssist.getInstance(mContext).registerUnWakeupCommand(it.key, it.value, this@ChoosePathFragment)
|
||||
}
|
||||
|
||||
SearchServiceHolder.intentManager.registerIntentListener(AMapConstants.COMMAND_START_NAVI, this)
|
||||
|
||||
SearchServiceHolder.intentManager.registerIntentListener(AMapConstants.COMMAND_CHOOSE_PATH, this)
|
||||
}
|
||||
|
||||
private fun registerRetryVoice() {
|
||||
@@ -214,7 +208,6 @@ class ChoosePathFragment : BaseFragment(), IMogoNaviListener, IMogoVoiceCmdCallB
|
||||
|
||||
private fun unregisterRetryVoice() {
|
||||
AIAssist.getInstance(context).unregisterUnWakeupCommand("retry")
|
||||
|
||||
}
|
||||
|
||||
private fun retry() {
|
||||
@@ -227,7 +220,6 @@ class ChoosePathFragment : BaseFragment(), IMogoNaviListener, IMogoVoiceCmdCallB
|
||||
if (TextUtils.isEmpty(mAdapter.selectTag)) {
|
||||
return
|
||||
}
|
||||
// moveMapToRight()
|
||||
|
||||
SearchServiceHolder.getNavi().startNavi(!SettingManager.isMonitor())
|
||||
SearchServiceHolder.getMapUIController().recoverLockMode()
|
||||
@@ -253,21 +245,81 @@ class ChoosePathFragment : BaseFragment(), IMogoNaviListener, IMogoVoiceCmdCallB
|
||||
SearchServiceHolder.getNavi().clearCalculatePaths()
|
||||
}
|
||||
|
||||
AIAssist.getInstance(context).unregisterUnWakeupCommand("firstPath")
|
||||
AIAssist.getInstance(context).unregisterUnWakeupCommand("secondPath")
|
||||
AIAssist.getInstance(context).unregisterUnWakeupCommand("thirdPath")
|
||||
AIAssist.getInstance(context).unregisterUnWakeupCommand("startNavi")
|
||||
DataConstants.sCmds.entries.filter {
|
||||
it != null && !TextUtils.isEmpty(it.key) && (it.value?.isNotEmpty() ?: false)
|
||||
}.forEach {
|
||||
AIAssist.getInstance(mContext).unregisterUnWakeupCommand(it.key)
|
||||
}
|
||||
|
||||
SearchServiceHolder.intentManager.unregisterIntentListener(AMapConstants.COMMAND_START_NAVI, this)
|
||||
SearchServiceHolder.intentManager.unregisterIntentListener(AMapConstants.COMMAND_CHOOSE_PATH, this)
|
||||
}
|
||||
|
||||
override fun onIntentReceived(intentStr: String?, intent: Intent?) {
|
||||
if (TextUtils.equals(AMapConstants.COMMAND_START_NAVI, intentStr)) {
|
||||
startNavi()
|
||||
when (intentStr) {
|
||||
AMapConstants.COMMAND_START_NAVI -> {
|
||||
startNavi()
|
||||
}
|
||||
AMapConstants.COMMAND_CHOOSE_PATH -> {
|
||||
choosePath(intent)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun choosePath(intent: Intent?) {
|
||||
var dataJsonStr = intent?.getStringExtra("data") ?: ""
|
||||
try {
|
||||
var jsonObj = JSONObject(dataJsonStr)
|
||||
var routePlan = jsonObj.optString("route_plan", " ")
|
||||
when (routePlan) {
|
||||
"最快" -> {
|
||||
// 时间最短
|
||||
selectItem(mTimeShortestPosition)
|
||||
startNavi()
|
||||
}
|
||||
"不走高速" -> {
|
||||
// 仅在导航场景下,⽀持第三⽅进⾏路线偏好的重新选择。
|
||||
// 避免收费 | 1
|
||||
// 多策略算路 | 2
|
||||
// 不走高速 | 3
|
||||
// 躲避拥堵 | 4
|
||||
// 不走高速且避免收费 | 5
|
||||
// 不走高速且躲避拥堵 | 6
|
||||
// 躲避收费和拥堵 | 7
|
||||
// 不走高速躲避收费和拥堵 | 8
|
||||
// 高速优先 | 20
|
||||
// 躲避拥堵且高速优先 | 24
|
||||
var prefer = 3
|
||||
val config = MogoNaviConfig().congestion(prefer == 4)
|
||||
.cost(prefer == 1 || prefer == 7)
|
||||
.highSpeed(prefer == 20)
|
||||
.avoidSpeed(prefer == 3)
|
||||
SearchServiceHolder.getNavi().reCalculateRoute(config)
|
||||
}
|
||||
"最近" -> {
|
||||
// 路程最短
|
||||
selectItem(mDistanceShortestPosition)
|
||||
startNavi()
|
||||
}
|
||||
"躲避拥堵" -> {
|
||||
var prefer = 4
|
||||
val config = MogoNaviConfig().congestion(prefer == 4)
|
||||
.cost(prefer == 1 || prefer == 7)
|
||||
.highSpeed(prefer == 20)
|
||||
.avoidSpeed(prefer == 3)
|
||||
SearchServiceHolder.getNavi().reCalculateRoute(config)
|
||||
}
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
companion object {
|
||||
|
||||
@JvmField
|
||||
val TAG: String = "ChoosePathFragment"
|
||||
|
||||
fun newInstance(searchPoi: MogoLatLng): Fragment {
|
||||
MapCenterPointStrategy.setMapCenterPointByScene(SearchServiceHolder.getMapUIController(), Scene.CALCULATE_PATH)
|
||||
var bundle = Bundle()
|
||||
|
||||
Reference in New Issue
Block a user