Android Frontend Finished
Also made some minor modifications to the routing calculations in the backend
This commit is contained in:
parent
6406c9da1b
commit
c938efcf0d
11 changed files with 174 additions and 14 deletions
|
@ -10,6 +10,12 @@ routing::RoutingOptions::Road makeValue(jint option)
|
|||
return static_cast<routing::RoutingOptions::Road>(road);
|
||||
}
|
||||
|
||||
routing::EdgeEstimator::Strategy makeStrategyValue(jint strategy)
|
||||
{
|
||||
int convertedStrat = static_cast<int>(strategy);
|
||||
return static_cast<routing::EdgeEstimator::Strategy>(convertedStrat);
|
||||
}
|
||||
|
||||
extern "C"
|
||||
{
|
||||
|
||||
|
@ -22,6 +28,14 @@ Java_com_mapswithme_maps_routing_RoutingOptions_nativeHasOption(JNIEnv * env, jc
|
|||
return static_cast<jboolean>(routingOptions.Has(road));
|
||||
}
|
||||
|
||||
JNIEXPORT jint JNICALL
|
||||
Java_com_mapswithme_maps_routing_RoutingOptions_nativeGetStrategy(JNIEnv * env, jclass clazz)
|
||||
{
|
||||
CHECK(g_framework, ("Framework isn't created yet!"));
|
||||
routing::EdgeEstimator::Strategy routingStrategy = routing::EdgeEstimator::LoadRoutingStrategyFromSettings();
|
||||
return static_cast<jint>(routingStrategy);
|
||||
}
|
||||
|
||||
JNIEXPORT void JNICALL
|
||||
Java_com_mapswithme_maps_routing_RoutingOptions_nativeAddOption(JNIEnv * env, jclass clazz, jint option)
|
||||
{
|
||||
|
@ -32,7 +46,6 @@ Java_com_mapswithme_maps_routing_RoutingOptions_nativeAddOption(JNIEnv * env, jc
|
|||
routing::RoutingOptions::SaveCarOptionsToSettings(routingOptions);
|
||||
}
|
||||
|
||||
|
||||
JNIEXPORT void JNICALL
|
||||
Java_com_mapswithme_maps_routing_RoutingOptions_nativeRemoveOption(JNIEnv * env, jclass clazz, jint option)
|
||||
{
|
||||
|
@ -42,4 +55,11 @@ Java_com_mapswithme_maps_routing_RoutingOptions_nativeRemoveOption(JNIEnv * env,
|
|||
routingOptions.Remove(road);
|
||||
routing::RoutingOptions::SaveCarOptionsToSettings(routingOptions);
|
||||
}
|
||||
|
||||
JNIEXPORT void JNICALL
|
||||
Java_com_mapswithme_maps_routing_RoutingOptions_nativeSetStrategy(JNIEnv * env, jclass clazz, jint strategy)
|
||||
{
|
||||
CHECK(g_framework, ("Framework isn't created yet!"));
|
||||
routing::EdgeEstimator::SaveRoutingStrategyToSettings(makeStrategyValue(strategy));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -110,4 +110,46 @@
|
|||
android:layout_width="wrap_content"
|
||||
android:layout_height="match_parent"/>
|
||||
</LinearLayout>
|
||||
<View
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="3dp"
|
||||
android:background="@android:color/darker_gray"/>
|
||||
<TextView
|
||||
android:text="@string/driving_options_subheader2"
|
||||
android:textAppearance="?android:attr/textAppearance"
|
||||
android:textColor="?colorAccent"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center_vertical"
|
||||
android:layout_marginTop="@dimen/margin_half_double_plus"
|
||||
android:paddingEnd="@dimen/margin_base"
|
||||
android:paddingStart="@dimen/margin_base"/>
|
||||
<RadioGroup
|
||||
android:id="@+id/routing_strategy_types"
|
||||
android:orientation="vertical"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="@dimen/margin_base">
|
||||
<RadioButton
|
||||
android:id="@+id/use_strategy_fastest"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:padding="@dimen/margin_half_plus"
|
||||
android:checked="true"
|
||||
android:text="@string/use_strategy_fastest"/>
|
||||
<RadioButton
|
||||
android:id="@+id/use_strategy_shortest"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:padding="@dimen/margin_half_plus"
|
||||
android:checked="false"
|
||||
android:text="@string/use_strategy_shortest"/>
|
||||
<RadioButton
|
||||
android:id="@+id/use_strategy_fewerTurns"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:padding="@dimen/margin_half_plus"
|
||||
android:checked="false"
|
||||
android:text="@string/use_strategy_fewerTurns"/>
|
||||
</RadioGroup>
|
||||
</LinearLayout>
|
||||
|
|
|
@ -651,10 +651,14 @@
|
|||
<string name="access_rules_author_only">Online editing</string>
|
||||
<string name="driving_options_title">Routing options</string>
|
||||
<string name="driving_options_subheader">Avoid on every route</string>
|
||||
<string name="driving_options_subheader2">Routing Strategy</string>
|
||||
<string name="avoid_tolls">Toll roads</string>
|
||||
<string name="avoid_unpaved">Unpaved roads</string>
|
||||
<string name="avoid_ferry">Ferry crossings</string>
|
||||
<string name="avoid_motorways">Motorways</string>
|
||||
<string name="use_strategy_fastest">Fastest</string>
|
||||
<string name="use_strategy_shortest">Shortest</string>
|
||||
<string name="use_strategy_fewerTurns">Fewer turns</string>
|
||||
<string name="unable_to_calc_alert_title">Unable to calculate route</string>
|
||||
<string name="unable_to_calc_alert_subtitle">Unfortunately, we couldn\'t find a route, probably due to the options you have chosen. Please change the settings and try again.</string>
|
||||
<string name="define_to_avoid_btn">Define roads to avoid</string>
|
||||
|
|
|
@ -3,6 +3,7 @@ package com.mapswithme.maps.routing;
|
|||
import androidx.annotation.NonNull;
|
||||
|
||||
import com.mapswithme.maps.settings.RoadType;
|
||||
import com.mapswithme.maps.settings.RoutingStrategyType;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
@ -24,9 +25,21 @@ public class RoutingOptions
|
|||
return nativeHasOption(roadType.ordinal());
|
||||
}
|
||||
|
||||
public static int getStrategy()
|
||||
{
|
||||
return nativeGetStrategy();
|
||||
}
|
||||
|
||||
public static void setStrategy(@NonNull RoutingStrategyType routingStrategyType)
|
||||
{
|
||||
nativeSetStrategy(routingStrategyType.ordinal());
|
||||
}
|
||||
|
||||
private static native void nativeAddOption(int option);
|
||||
private static native void nativeRemoveOption(int option);
|
||||
private static native boolean nativeHasOption(int option);
|
||||
private static native int nativeGetStrategy();
|
||||
private static native void nativeSetStrategy(int strategy);
|
||||
|
||||
public static boolean hasAnyOptions()
|
||||
{
|
||||
|
@ -49,4 +62,10 @@ public class RoutingOptions
|
|||
}
|
||||
return roadTypes;
|
||||
}
|
||||
|
||||
public static RoutingStrategyType getActiveRoutingStrategyType()
|
||||
{
|
||||
int strategyType = getStrategy();
|
||||
return RoutingStrategyType.values()[strategyType];
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,6 +6,7 @@ import android.view.LayoutInflater;
|
|||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.CompoundButton;
|
||||
import android.widget.RadioGroup;
|
||||
import android.widget.Switch;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
|
@ -25,8 +26,11 @@ import java.util.Set;
|
|||
public class DrivingOptionsFragment extends BaseMwmToolbarFragment
|
||||
{
|
||||
public static final String BUNDLE_ROAD_TYPES = "road_types";
|
||||
public static final String BUNDLE_ROUTING_STRATEGY_TYPE = "routing_strategy_type";
|
||||
@NonNull
|
||||
private Set<RoadType> mRoadTypes = Collections.emptySet();
|
||||
@NonNull
|
||||
private RoutingStrategyType mStrategy = RoutingStrategyType.Fastest;
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
|
@ -38,6 +42,9 @@ public class DrivingOptionsFragment extends BaseMwmToolbarFragment
|
|||
mRoadTypes = savedInstanceState != null && savedInstanceState.containsKey(BUNDLE_ROAD_TYPES)
|
||||
? makeRouteTypes(savedInstanceState)
|
||||
: RoutingOptions.getActiveRoadTypes();
|
||||
mStrategy = savedInstanceState != null && savedInstanceState.containsKey(BUNDLE_ROUTING_STRATEGY_TYPE)
|
||||
? makeRoutingStrategyType(savedInstanceState)
|
||||
: RoutingOptions.getActiveRoutingStrategyType();
|
||||
return root;
|
||||
}
|
||||
|
||||
|
@ -53,6 +60,13 @@ public class DrivingOptionsFragment extends BaseMwmToolbarFragment
|
|||
return result;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
private RoutingStrategyType makeRoutingStrategyType(@NonNull Bundle bundle)
|
||||
{
|
||||
RoutingStrategyType result = Objects.requireNonNull((RoutingStrategyType)bundle.getSerializable(BUNDLE_ROUTING_STRATEGY_TYPE));
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSaveInstanceState(@NonNull Bundle outState)
|
||||
{
|
||||
|
@ -63,12 +77,15 @@ public class DrivingOptionsFragment extends BaseMwmToolbarFragment
|
|||
savedRoadTypes.add(each.ordinal());
|
||||
}
|
||||
outState.putIntegerArrayList(BUNDLE_ROAD_TYPES, savedRoadTypes);
|
||||
|
||||
outState.putSerializable(BUNDLE_ROUTING_STRATEGY_TYPE, mStrategy);
|
||||
}
|
||||
|
||||
private boolean areSettingsNotChanged()
|
||||
{
|
||||
Set<RoadType> lastActiveRoadTypes = RoutingOptions.getActiveRoadTypes();
|
||||
return mRoadTypes.equals(lastActiveRoadTypes);
|
||||
RoutingStrategyType lastActiveStrategyType = RoutingOptions.getActiveRoutingStrategyType();
|
||||
return mRoadTypes.equals(lastActiveRoadTypes) && mStrategy.equals(lastActiveStrategyType);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -104,6 +121,26 @@ public class DrivingOptionsFragment extends BaseMwmToolbarFragment
|
|||
CompoundButton.OnCheckedChangeListener dirtyBtnListener =
|
||||
new ToggleRoutingOptionListener(RoadType.Dirty);
|
||||
dirtyRoadsBtn.setOnCheckedChangeListener(dirtyBtnListener);
|
||||
|
||||
RadioGroup strategyRadioGroup = root.findViewById(R.id.routing_strategy_types);
|
||||
RoutingStrategyType currentStrategy = RoutingOptions.getActiveRoutingStrategyType();
|
||||
int currentCheckedStrategyId;
|
||||
switch (currentStrategy)
|
||||
{
|
||||
case Shortest:
|
||||
currentCheckedStrategyId = R.id.use_strategy_shortest;
|
||||
break;
|
||||
case FewerTurns:
|
||||
currentCheckedStrategyId = R.id.use_strategy_fewerTurns;
|
||||
break;
|
||||
default:
|
||||
currentCheckedStrategyId = R.id.use_strategy_fastest;
|
||||
break;
|
||||
}
|
||||
strategyRadioGroup.check(currentCheckedStrategyId);
|
||||
RadioGroup.OnCheckedChangeListener strategyRadioGroupListener =
|
||||
new ToggleRoutingStrategyListener();
|
||||
strategyRadioGroup.setOnCheckedChangeListener(strategyRadioGroupListener);
|
||||
}
|
||||
|
||||
private static class ToggleRoutingOptionListener implements CompoundButton.OnCheckedChangeListener
|
||||
|
@ -125,4 +162,26 @@ public class DrivingOptionsFragment extends BaseMwmToolbarFragment
|
|||
RoutingOptions.removeOption(mRoadType);
|
||||
}
|
||||
}
|
||||
|
||||
private static class ToggleRoutingStrategyListener implements RadioGroup.OnCheckedChangeListener
|
||||
{
|
||||
private ToggleRoutingStrategyListener() {}
|
||||
|
||||
@Override
|
||||
public void onCheckedChanged(RadioGroup group, int checkedId)
|
||||
{
|
||||
switch (checkedId)
|
||||
{
|
||||
case R.id.use_strategy_fastest:
|
||||
RoutingOptions.setStrategy(RoutingStrategyType.Fastest);
|
||||
break;
|
||||
case R.id.use_strategy_shortest:
|
||||
RoutingOptions.setStrategy(RoutingStrategyType.Shortest);
|
||||
break;
|
||||
case R.id.use_strategy_fewerTurns:
|
||||
RoutingOptions.setStrategy(RoutingStrategyType.FewerTurns);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,8 @@
|
|||
package com.mapswithme.maps.settings;
|
||||
|
||||
public enum RoutingStrategyType
|
||||
{
|
||||
Fastest,
|
||||
Shortest,
|
||||
FewerTurns
|
||||
}
|
|
@ -110,6 +110,8 @@ void RoutingSettings::LoadSession(Framework & framework)
|
|||
settings::Delete(kStartCoordsCachedSettings);
|
||||
settings::Delete(kFinishCoordsCachedSettings);
|
||||
settings::Delete(kRouterTypeCachedSettings);
|
||||
settings::Delete(kRouterStrategyCachedSettings);
|
||||
settings::Delete(kAvoidRoutingOptionSettings);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -128,16 +128,23 @@ double GetCarClimbPenalty(EdgeEstimator::Purpose /* purpose */, double /* tangen
|
|||
|
||||
string const EdgeEstimator::kRoutingStrategySettings = "router_strategy";
|
||||
|
||||
//static
|
||||
// static
|
||||
EdgeEstimator::Strategy EdgeEstimator::LoadRoutingStrategyFromSettings()
|
||||
{
|
||||
uint32_t mode = 0;
|
||||
int mode = 0;
|
||||
if (!settings::Get(kRoutingStrategySettings, mode))
|
||||
mode = 0;
|
||||
|
||||
return (EdgeEstimator::Strategy) mode;
|
||||
}
|
||||
|
||||
// static
|
||||
void EdgeEstimator::SaveRoutingStrategyToSettings(Strategy strategy)
|
||||
{
|
||||
settings::Set(kRoutingStrategySettings,
|
||||
strings::to_string(static_cast<int>(strategy)));
|
||||
}
|
||||
|
||||
EdgeEstimator::EdgeEstimator(double maxWeightSpeedKMpH, SpeedKMpH const & offroadSpeedKMpH,
|
||||
DataSource * /*dataSourcePtr*/, std::shared_ptr<NumMwmIds> /*numMwmIds*/)
|
||||
: m_maxWeightSpeedMpS(KmphToMps(maxWeightSpeedKMpH))
|
||||
|
@ -268,7 +275,7 @@ public:
|
|||
{
|
||||
if (this->GetStrategy() == EdgeEstimator::Strategy::FewerTurns)
|
||||
{
|
||||
return 24 * 60 * 60;
|
||||
return 60 * 60;
|
||||
}
|
||||
}
|
||||
return 0.0 /* seconds */;
|
||||
|
@ -279,7 +286,7 @@ public:
|
|||
{
|
||||
if (this->GetStrategy() == EdgeEstimator::Strategy::FewerTurns)
|
||||
{
|
||||
return 24 * 60 * 60;
|
||||
return 60 * 60;
|
||||
}
|
||||
}
|
||||
return 0.0;
|
||||
|
@ -328,7 +335,7 @@ public:
|
|||
{
|
||||
if (this->GetStrategy() == EdgeEstimator::Strategy::FewerTurns)
|
||||
{
|
||||
return 24 * 60 * 60;
|
||||
return 60 * 60;
|
||||
}
|
||||
}
|
||||
return 20.0 /* seconds */;
|
||||
|
@ -339,7 +346,7 @@ public:
|
|||
{
|
||||
if (this->GetStrategy() == EdgeEstimator::Strategy::FewerTurns)
|
||||
{
|
||||
return 24 * 60 * 60;
|
||||
return 60 * 60;
|
||||
}
|
||||
}
|
||||
return 0.0;
|
||||
|
@ -404,7 +411,7 @@ double CarEstimator::GetUTurnPenalty(Purpose purpose) const
|
|||
{
|
||||
if (this->GetStrategy() == EdgeEstimator::Strategy::FewerTurns)
|
||||
{
|
||||
return 24 * 60 * 60;
|
||||
return 60 * 60;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -420,7 +427,7 @@ double CarEstimator::GetTurnPenalty(Purpose purpose) const
|
|||
{
|
||||
if (this->GetStrategy() == EdgeEstimator::Strategy::FewerTurns)
|
||||
{
|
||||
return 24 * 60 * 60;
|
||||
return 60 * 60;
|
||||
}
|
||||
}
|
||||
return 0.0;
|
||||
|
|
|
@ -43,6 +43,7 @@ public:
|
|||
virtual ~EdgeEstimator() = default;
|
||||
|
||||
static Strategy LoadRoutingStrategyFromSettings();
|
||||
static void SaveRoutingStrategyToSettings(Strategy strategy);
|
||||
|
||||
double CalcHeuristic(ms::LatLon const & from, ms::LatLon const & to) const;
|
||||
// Estimates time in seconds it takes to go from point |from| to point |to| along a leap (fake)
|
||||
|
|
|
@ -576,8 +576,6 @@ bool IndexGraph::IsTurn(Segment const & u, Segment const & v) const
|
|||
|
||||
if (!(endPointU == startPointV))
|
||||
{
|
||||
LOG(LDEBUG, ("Turn checking: u and v are not connected"));
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -596,7 +594,7 @@ bool IndexGraph::IsTurn(Segment const & u, Segment const & v) const
|
|||
//convert to degree value
|
||||
angle = angle * 180 / 3.141592;
|
||||
|
||||
if (abs(angle) >= 30)
|
||||
if (abs(angle) >= 15)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
#!/usr/bin/python
|
||||
#!/usr/local/bin/python
|
||||
import os, sys, shutil, collections
|
||||
from optparse import OptionParser
|
||||
|
||||
|
|
Reference in a new issue