forked from organicmaps/organicmaps
[android] Added drive settings screen, create interface for core calls
This commit is contained in:
parent
74b767ede5
commit
8b6a5dc64a
12 changed files with 368 additions and 2 deletions
|
@ -469,7 +469,9 @@
|
|||
<activity
|
||||
android:name="com.mapswithme.maps.ugc.routes.EditCategoryDescriptionActivity"
|
||||
android:label="@string/description_guide"/>
|
||||
|
||||
<activity
|
||||
android:name="com.mapswithme.maps.settings.DrivingOptionsActivity"
|
||||
android:label="@string/driving_options_title"/>
|
||||
<service
|
||||
android:name="com.mapswithme.maps.background.WorkerService"
|
||||
android:permission="android.permission.BIND_JOB_SERVICE"
|
||||
|
|
|
@ -41,6 +41,7 @@ set(
|
|||
com/mapswithme/core/logging.cpp
|
||||
com/mapswithme/maps/bookmarks/data/Bookmark.cpp
|
||||
com/mapswithme/maps/bookmarks/data/BookmarkManager.cpp
|
||||
com/mapswithme/maps/bookmarks/data/RoutingOptions.cpp
|
||||
com/mapswithme/maps/discovery/DiscoveryManager.cpp
|
||||
com/mapswithme/maps/discovery/Locals.cpp
|
||||
com/mapswithme/maps/DisplayedCategories.cpp
|
||||
|
|
|
@ -0,0 +1,43 @@
|
|||
#include <jni.h>
|
||||
#include <android/jni/com/mapswithme/maps/Framework.hpp>
|
||||
#include <android/jni/com/mapswithme/core/jni_helper.hpp>
|
||||
#include "routing/routing_options.hpp"
|
||||
|
||||
unsigned int makeValue(jint option)
|
||||
{
|
||||
return 1u >> option;
|
||||
}
|
||||
|
||||
extern "C"
|
||||
{
|
||||
|
||||
JNIEXPORT jboolean JNICALL
|
||||
Java_com_mapswithme_maps_bookmarks_data_RoutingOptions_nativeHasOption(JNIEnv * env, jclass clazz, jint option)
|
||||
{
|
||||
CHECK(g_framework, ("Framework isn't created yet!"));
|
||||
routing::RoutingOptions routingOptions = routing::RoutingOptions::LoadCarOptionsFromSettings();
|
||||
routing::RoutingOptions::Road road = static_cast<routing::RoutingOptions::Road>(makeValue(option));
|
||||
return static_cast<jboolean>(routingOptions.Has(road));
|
||||
}
|
||||
|
||||
JNIEXPORT void JNICALL
|
||||
Java_com_mapswithme_maps_bookmarks_data_RoutingOptions_nativeAddOption(JNIEnv * env, jclass clazz, jint option)
|
||||
{
|
||||
CHECK(g_framework, ("Framework isn't created yet!"));
|
||||
routing::RoutingOptions routingOptions = routing::RoutingOptions::LoadCarOptionsFromSettings();
|
||||
routing::RoutingOptions::Road road = static_cast<routing::RoutingOptions::Road>(makeValue(option));
|
||||
routingOptions.Add(road);
|
||||
routing::RoutingOptions::SaveCarOptionsToSettings(routingOptions);
|
||||
}
|
||||
|
||||
|
||||
JNIEXPORT void JNICALL
|
||||
Java_com_mapswithme_maps_bookmarks_data_RoutingOptions_nativeRemoveOption(JNIEnv * env, jclass clazz, jint option)
|
||||
{
|
||||
CHECK(g_framework, ("Framework isn't created yet!"));
|
||||
routing::RoutingOptions routingOptions = routing::RoutingOptions::LoadCarOptionsFromSettings();
|
||||
routing::RoutingOptions::Road road = static_cast<routing::RoutingOptions::Road>(makeValue(option));
|
||||
routingOptions.Remove(road);
|
||||
routing::RoutingOptions::SaveCarOptionsToSettings(routingOptions);
|
||||
}
|
||||
}
|
128
android/res/layout/fragment_driving_options.xml
Normal file
128
android/res/layout/fragment_driving_options.xml
Normal file
|
@ -0,0 +1,128 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:orientation="vertical"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
<android.support.v7.widget.Toolbar
|
||||
android:id="@+id/toolbar"
|
||||
style="@style/MwmWidget.ToolbarStyle"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="?attr/actionBarSize"
|
||||
android:background="?colorPrimary"
|
||||
android:gravity="end|center_vertical"
|
||||
android:theme="@style/MwmWidget.ToolbarTheme"
|
||||
tools:ignore="UnusedAttribute">
|
||||
</android.support.v7.widget.Toolbar>
|
||||
<TextView
|
||||
android:text="@string/driving_options_subheader"
|
||||
android:textAppearance="?android:attr/textAppearanceMedium"
|
||||
android:textColor="?colorAccent"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:fontFamily="@string/robotoMedium"
|
||||
android:layout_gravity="center_vertical"
|
||||
android:layout_marginTop="@dimen/margin_half_double_plus"
|
||||
android:paddingLeft="@dimen/margin_base"
|
||||
android:paddingRight="@dimen/margin_base"
|
||||
android:paddingEnd="@dimen/margin_base"
|
||||
android:paddingStart="@dimen/margin_base"
|
||||
tools:targetApi="jelly_bean"/>
|
||||
<LinearLayout
|
||||
android:layout_marginTop="@dimen/margin_half_double_plus"
|
||||
android:orientation="horizontal"
|
||||
android:minHeight="@dimen/height_block_base"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:paddingLeft="@dimen/margin_base"
|
||||
android:paddingRight="@dimen/margin_base"
|
||||
android:paddingEnd="@dimen/margin_base"
|
||||
android:paddingStart="@dimen/margin_base">
|
||||
<TextView
|
||||
android:text="@string/avoid_tolls"
|
||||
android:textAppearance="?android:attr/textAppearance"
|
||||
android:layout_width="0dp"
|
||||
android:layout_weight="1"
|
||||
android:layout_height="match_parent"
|
||||
android:minHeight="@dimen/height_block_base"
|
||||
android:fontFamily="@string/robotoMedium"
|
||||
tools:targetApi="jelly_bean"/>
|
||||
<Switch
|
||||
android:id="@+id/avoid_tolls_btn"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="match_parent"/>
|
||||
</LinearLayout>
|
||||
<include layout="@layout/list_divider"/>
|
||||
<LinearLayout
|
||||
android:orientation="horizontal"
|
||||
android:minHeight="@dimen/height_block_base"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:paddingLeft="@dimen/margin_base"
|
||||
android:paddingRight="@dimen/margin_base"
|
||||
android:paddingEnd="@dimen/margin_base"
|
||||
android:paddingStart="@dimen/margin_base">
|
||||
<TextView
|
||||
android:text="@string/avoid_dirty_roads"
|
||||
android:textAppearance="?android:attr/textAppearance"
|
||||
android:layout_width="0dp"
|
||||
android:layout_weight="1"
|
||||
android:layout_height="match_parent"
|
||||
android:minHeight="@dimen/height_block_base"
|
||||
android:fontFamily="@string/robotoMedium"
|
||||
tools:targetApi="jelly_bean"/>
|
||||
<Switch
|
||||
android:id="@+id/avoid_dirty_roads_btn"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="match_parent"/>
|
||||
</LinearLayout>
|
||||
<include layout="@layout/list_divider"/>
|
||||
<LinearLayout
|
||||
android:orientation="horizontal"
|
||||
android:minHeight="@dimen/height_block_base"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:paddingLeft="@dimen/margin_base"
|
||||
android:paddingRight="@dimen/margin_base"
|
||||
android:paddingEnd="@dimen/margin_base"
|
||||
android:paddingStart="@dimen/margin_base">
|
||||
<TextView
|
||||
android:text="@string/avoid_ferries"
|
||||
android:textAppearance="?android:attr/textAppearance"
|
||||
android:layout_width="0dp"
|
||||
android:layout_weight="1"
|
||||
android:layout_height="match_parent"
|
||||
android:minHeight="@dimen/height_block_base"
|
||||
android:fontFamily="@string/robotoMedium"
|
||||
tools:targetApi="jelly_bean"/>
|
||||
<Switch
|
||||
android:id="@+id/avoid_ferries_btn"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="match_parent"/>
|
||||
</LinearLayout>
|
||||
<include layout="@layout/list_divider"/>
|
||||
<LinearLayout
|
||||
android:orientation="horizontal"
|
||||
android:minHeight="@dimen/height_block_base"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:paddingLeft="@dimen/margin_base"
|
||||
android:paddingRight="@dimen/margin_base"
|
||||
android:paddingEnd="@dimen/margin_base"
|
||||
android:paddingStart="@dimen/margin_base">
|
||||
<TextView
|
||||
android:text="@string/avoid_motorways"
|
||||
android:textAppearance="?android:attr/textAppearance"
|
||||
android:layout_width="0dp"
|
||||
android:layout_weight="1"
|
||||
android:layout_height="match_parent"
|
||||
android:minHeight="@dimen/height_block_base"
|
||||
android:fontFamily="@string/robotoMedium"
|
||||
tools:targetApi="jelly_bean"/>
|
||||
<Switch
|
||||
android:id="@+id/avoid_motorways_btn"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="match_parent"/>
|
||||
</LinearLayout>
|
||||
</LinearLayout>
|
11
android/res/menu/menu_driving_options.xml
Normal file
11
android/res/menu/menu_driving_options.xml
Normal file
|
@ -0,0 +1,11 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<menu
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto">
|
||||
<item
|
||||
app:showAsAction="always"
|
||||
android:id="@+id/done"
|
||||
android:visible="false"
|
||||
android:title="@string/done"
|
||||
android:icon="@drawable/ic_done"/>
|
||||
</menu>
|
|
@ -112,6 +112,13 @@
|
|||
android:entries="@array/power_management_scheme"
|
||||
android:entryValues="@array/power_management_scheme_values"
|
||||
android:order="15"/>
|
||||
<PreferenceScreen
|
||||
android:order="16"
|
||||
android:title="@string/driving_options_title">
|
||||
<intent
|
||||
android:targetClass="com.mapswithme.maps.settings.DrivingOptionsActivity"
|
||||
android:targetPackage="@string/app_id"/>
|
||||
</PreferenceScreen>
|
||||
</android.support.v7.preference.PreferenceCategory>
|
||||
|
||||
<android.support.v7.preference.PreferenceCategory
|
||||
|
|
|
@ -176,6 +176,10 @@ public class MwmActivity extends BaseMwmFragmentActivity
|
|||
private static final int REQ_CODE_LOCATION_PERMISSION = 1;
|
||||
private static final int REQ_CODE_DISCOVERY = 2;
|
||||
private static final int REQ_CODE_SHOW_SIMILAR_HOTELS = 3;
|
||||
private static final int REQ_CODE_ERROR_CALCULATE_ROUTE = 4;
|
||||
private static final int REQ_CODE_ERROR_CALCULATE_ROUTE_FIRST_TIME = 5;
|
||||
private static final String ERROR_CALCULATE_ROUTE = "error_calculate_route";
|
||||
private static final String ERROR_CALCULATE_ROUTE_FIRST_TIME = "`error_calculate_route_first_time";
|
||||
|
||||
// Map tasks that we run AFTER rendering initialized
|
||||
private final Stack<MapTask> mTasks = new Stack<>();
|
||||
|
@ -2694,4 +2698,29 @@ public class MwmActivity extends BaseMwmFragmentActivity
|
|||
getActivity().startLocationToPoint(null, false);
|
||||
}
|
||||
}
|
||||
|
||||
public void showUnableCalculateRouteDialog()
|
||||
{
|
||||
com.mapswithme.maps.dialog.AlertDialog dialog = new com.mapswithme.maps.dialog.AlertDialog.Builder()
|
||||
.setTitleId(R.string.unable_to_recalc_title)
|
||||
.setMessageId(R.string.unable_to_recalc_subtitle)
|
||||
.setPositiveBtnId(R.string.ok)
|
||||
.setReqCode(REQ_CODE_ERROR_CALCULATE_ROUTE)
|
||||
.setFragManagerStrategyType(com.mapswithme.maps.dialog.AlertDialog.FragManagerStrategyType.ACTIVITY_FRAGMENT_MANAGER)
|
||||
.build();
|
||||
dialog.show(getSupportFragmentManager(), ERROR_CALCULATE_ROUTE);
|
||||
}
|
||||
|
||||
public void showUnableCalculateRouteFirstTimeDialog()
|
||||
{
|
||||
com.mapswithme.maps.dialog.AlertDialog dialog = new com.mapswithme.maps.dialog.AlertDialog.Builder()
|
||||
.setTitleId(R.string.unable_to_calc_alert_subtitle)
|
||||
.setMessageId(R.string.unable_to_calc_alert_subtitle)
|
||||
.setPositiveBtnId(R.string.options)
|
||||
.setNegativeBtnId(R.string.cancel)
|
||||
.setReqCode(REQ_CODE_ERROR_CALCULATE_ROUTE_FIRST_TIME)
|
||||
.setFragManagerStrategyType(com.mapswithme.maps.dialog.AlertDialog.FragManagerStrategyType.ACTIVITY_FRAGMENT_MANAGER)
|
||||
.build();
|
||||
dialog.show(getSupportFragmentManager(), ERROR_CALCULATE_ROUTE_FIRST_TIME);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,8 @@
|
|||
package com.mapswithme.maps.bookmarks.data;
|
||||
|
||||
public class RoutingOptions
|
||||
{
|
||||
public static native void nativeAddOption(int option);
|
||||
public static native void nativeRemoveOption(int option);
|
||||
public static native boolean nativeHasOption(int option);
|
||||
}
|
|
@ -0,0 +1,26 @@
|
|||
package com.mapswithme.maps.settings;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.support.v4.app.FragmentActivity;
|
||||
|
||||
import com.mapswithme.maps.base.BaseMwmFragmentActivity;
|
||||
|
||||
public class DrivingOptionsActivity extends BaseMwmFragmentActivity
|
||||
{
|
||||
public static final String BUNDLE_REQUIRE_OPTIONS_MENU = "require_options_menu";
|
||||
|
||||
@Override
|
||||
protected Class<? extends Fragment> getFragmentClass()
|
||||
{
|
||||
return DrivingOptionsFragment.class;
|
||||
}
|
||||
|
||||
public static void startOptionMenuActivity(@NonNull FragmentActivity activity)
|
||||
{
|
||||
Intent intent = new Intent(activity, DrivingOptionsActivity.class)
|
||||
.putExtra(BUNDLE_REQUIRE_OPTIONS_MENU, true);
|
||||
activity.startActivity(intent);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,101 @@
|
|||
package com.mapswithme.maps.settings;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuInflater;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.CompoundButton;
|
||||
import android.widget.Switch;
|
||||
|
||||
import com.mapswithme.maps.R;
|
||||
import com.mapswithme.maps.base.BaseMwmToolbarFragment;
|
||||
import com.mapswithme.maps.bookmarks.data.RoutingOptions;
|
||||
|
||||
public class DrivingOptionsFragment extends BaseMwmToolbarFragment
|
||||
{
|
||||
@Nullable
|
||||
@Override
|
||||
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container,
|
||||
@Nullable Bundle savedInstanceState)
|
||||
{
|
||||
View root = inflater.inflate(R.layout.fragment_driving_options, container, false);
|
||||
initViews(root);
|
||||
setHasOptionsMenu(hasBundleOptionsMenu());
|
||||
return root;
|
||||
}
|
||||
|
||||
private boolean hasBundleOptionsMenu()
|
||||
{
|
||||
Bundle arguments = getArguments();
|
||||
if (arguments == null)
|
||||
return false;
|
||||
|
||||
return arguments.getBoolean(DrivingOptionsActivity.BUNDLE_REQUIRE_OPTIONS_MENU, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater)
|
||||
{
|
||||
inflater.inflate(R.menu.menu_tags_done, menu);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(MenuItem item)
|
||||
{
|
||||
if (item.getItemId() == R.id.done)
|
||||
{
|
||||
requireActivity().finish();
|
||||
return true;
|
||||
}
|
||||
|
||||
return super.onOptionsItemSelected(item);
|
||||
}
|
||||
|
||||
private void initViews(@NonNull View root)
|
||||
{
|
||||
Switch avoidTollsBtn = root.findViewById(R.id.avoid_tolls_btn);
|
||||
CompoundButton.OnCheckedChangeListener tollBtnListener =
|
||||
new ToggleRoutingOptionListener(RoadType.TOLL);
|
||||
avoidTollsBtn.setOnCheckedChangeListener(tollBtnListener);
|
||||
|
||||
Switch avoidMotorwaysBtn = root.findViewById(R.id.avoid_motorways_btn);
|
||||
CompoundButton.OnCheckedChangeListener motorwayBtnListener =
|
||||
new ToggleRoutingOptionListener(RoadType.MOTORWAY);
|
||||
avoidMotorwaysBtn.setOnCheckedChangeListener(motorwayBtnListener);
|
||||
|
||||
Switch avoidFerriesBtn = root.findViewById(R.id.avoid_ferries_btn);
|
||||
CompoundButton.OnCheckedChangeListener ferryBtnListener =
|
||||
new ToggleRoutingOptionListener(RoadType.FERRY);
|
||||
avoidFerriesBtn.setOnCheckedChangeListener(ferryBtnListener);
|
||||
|
||||
Switch avoidDirtyRoadsBtn = root.findViewById(R.id.avoid_dirty_roads_btn);
|
||||
CompoundButton.OnCheckedChangeListener dirtyBtnListener =
|
||||
new ToggleRoutingOptionListener(RoadType.DIRTY);
|
||||
avoidDirtyRoadsBtn.setOnCheckedChangeListener(dirtyBtnListener);
|
||||
}
|
||||
|
||||
private static class ToggleRoutingOptionListener implements CompoundButton.OnCheckedChangeListener
|
||||
{
|
||||
@NonNull
|
||||
private final RoadType mRoadType;
|
||||
|
||||
private ToggleRoutingOptionListener(@NonNull RoadType roadType)
|
||||
{
|
||||
mRoadType = roadType;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked)
|
||||
{
|
||||
if (isChecked)
|
||||
RoutingOptions.nativeAddOption(mRoadType.ordinal());
|
||||
else
|
||||
RoutingOptions.nativeRemoveOption(mRoadType.ordinal());
|
||||
}
|
||||
}
|
||||
}
|
10
android/src/com/mapswithme/maps/settings/RoadType.java
Normal file
10
android/src/com/mapswithme/maps/settings/RoadType.java
Normal file
|
@ -0,0 +1,10 @@
|
|||
package com.mapswithme.maps.settings;
|
||||
|
||||
public enum RoadType
|
||||
{
|
||||
USUAL,
|
||||
TOLL,
|
||||
MOTORWAY,
|
||||
FERRY,
|
||||
DIRTY
|
||||
}
|
|
@ -121,7 +121,7 @@ RoutingOptions::Road ChooseMainRoutingOptionRoad(RoutingOptions options)
|
|||
string DebugPrint(RoutingOptions const & routingOptions)
|
||||
{
|
||||
ostringstream ss;
|
||||
ss << "RoutingOptions: {";
|
||||
ss << "RoadType: {";
|
||||
|
||||
bool wasAppended = false;
|
||||
auto const append = [&](RoutingOptions::Road road) {
|
||||
|
|
Loading…
Add table
Reference in a new issue