From eca7114aaf527da5e5340fa1d35dabebbdc65531 Mon Sep 17 00:00:00 2001 From: Dmitry Yunitsky Date: Thu, 11 Jun 2015 03:14:11 +0300 Subject: [PATCH] Pedestrian icon in routing. --- .../src/com/mapswithme/maps/MWMActivity.java | 11 +++ .../com/mapswithme/maps/data/RouterTypes.java | 30 ++++++++ .../maps/search/SearchFragment.java | 68 ++++++++++++------- 3 files changed, 86 insertions(+), 23 deletions(-) create mode 100644 android/src/com/mapswithme/maps/data/RouterTypes.java diff --git a/android/src/com/mapswithme/maps/MWMActivity.java b/android/src/com/mapswithme/maps/MWMActivity.java index 373a3d0489..9761f2edd6 100644 --- a/android/src/com/mapswithme/maps/MWMActivity.java +++ b/android/src/com/mapswithme/maps/MWMActivity.java @@ -57,6 +57,7 @@ import com.mapswithme.maps.bookmarks.data.BookmarkManager; import com.mapswithme.maps.bookmarks.data.MapObject; import com.mapswithme.maps.bookmarks.data.MapObject.ApiPoint; import com.mapswithme.maps.bookmarks.data.ParcelablePoint; +import com.mapswithme.maps.data.RouterTypes; import com.mapswithme.maps.data.RoutingResultCodes; import com.mapswithme.maps.location.LocationHelper; import com.mapswithme.maps.location.LocationPredictor; @@ -997,12 +998,21 @@ public class MWMActivity extends BaseMwmFragmentActivity startWatchingExternalStorage(); refreshZoomButtonsVisibility(); + refreshRouterIcon(); SearchController.getInstance().onResume(); mPlacePage.onResume(); mLikesManager.showLikeDialogForCurrentSession(); } + private void refreshRouterIcon() + { + if (RouterTypes.getRouterType().equals(RouterTypes.ROUTER_VEHICLE)) + mIvStartRouting.setImageResource(R.drawable.ic_route); + else + mIvStartRouting.setImageResource(R.drawable.ic_walk); + } + private void refreshZoomButtonsVisibility() { UiUtils.showIf(MWMApplication.get().nativeGetBoolean(SettingsActivity.ZOOM_BUTTON_ENABLED, true) || @@ -1714,6 +1724,7 @@ public class MWMActivity extends BaseMwmFragmentActivity { InputUtils.hideKeyboard(mBottomButtons); mFadeView.fadeOut(); + refreshRouterIcon(); } } diff --git a/android/src/com/mapswithme/maps/data/RouterTypes.java b/android/src/com/mapswithme/maps/data/RouterTypes.java new file mode 100644 index 0000000000..9a5fee4d94 --- /dev/null +++ b/android/src/com/mapswithme/maps/data/RouterTypes.java @@ -0,0 +1,30 @@ +package com.mapswithme.maps.data; + +import android.content.Context; +import android.content.SharedPreferences; + +import com.mapswithme.maps.MWMApplication; +import com.mapswithme.maps.R; + +public class RouterTypes +{ + private static final String KEY_ROUTER = "Router"; + + public static final String ROUTER_PEDESTRIAN = "pedestrian"; + public static final String ROUTER_VEHICLE = "vehicle"; + + private RouterTypes() {} + + public static void saveRouterType(String routerType) + { + final MWMApplication application = MWMApplication.get(); + final SharedPreferences prefs = application.getSharedPreferences(application.getString(R.string.pref_file_name), Context.MODE_PRIVATE); + prefs.edit().putString(KEY_ROUTER, routerType).commit(); + } + + public static String getRouterType() + { + final MWMApplication application = MWMApplication.get(); + return application.getSharedPreferences(application.getString(R.string.pref_file_name), Context.MODE_PRIVATE).getString(KEY_ROUTER, ROUTER_VEHICLE); + } +} diff --git a/android/src/com/mapswithme/maps/search/SearchFragment.java b/android/src/com/mapswithme/maps/search/SearchFragment.java index 8a69dddac6..342ca15917 100644 --- a/android/src/com/mapswithme/maps/search/SearchFragment.java +++ b/android/src/com/mapswithme/maps/search/SearchFragment.java @@ -23,6 +23,7 @@ import com.mapswithme.maps.MWMActivity; import com.mapswithme.maps.R; import com.mapswithme.maps.base.BaseMwmListFragment; import com.mapswithme.maps.base.OnBackPressListener; +import com.mapswithme.maps.data.RouterTypes; import com.mapswithme.maps.location.LocationHelper; import com.mapswithme.util.InputUtils; import com.mapswithme.util.Language; @@ -109,28 +110,6 @@ public class SearchFragment extends BaseMwmListFragment implements View.OnClickL return mEtSearchQuery.getText().toString(); } - // TODO: This code only for demonstration purposes and will be removed soon - private boolean tryChangeMapStyleCmd(String str) - { - // Hook for shell command on change map style - final boolean isDark = str.equals("mapstyle:dark"); - final boolean isLight = isDark ? false : str.equals("mapstyle:light"); - - if (!isDark && !isLight) - return false; - - // close Search panel - mEtSearchQuery.setText(null); - InputUtils.hideKeyboard(mEtSearchQuery); - getActivity().onBackPressed(); - - // change map style for the Map activity - final int mapStyle = isDark ? Framework.MAP_STYLE_DARK : Framework.MAP_STYLE_LIGHT; - MWMActivity.setMapStyle(getActivity(), mapStyle); - - return true; - } - private void setUpView(ViewGroup root) { mBtnVoice = root.findViewById(R.id.search_voice_input); @@ -146,7 +125,8 @@ public class SearchFragment extends BaseMwmListFragment implements View.OnClickL public void afterTextChanged(Editable s) { // TODO: This code only for demonstration purposes and will be removed soon - if (tryChangeMapStyleCmd(s.toString())) + if (tryChangeMapStyle(s.toString()) || + tryChangeRouter(s.toString())) return; if (runSearch() == STATUS_QUERY_EMPTY) @@ -221,6 +201,48 @@ public class SearchFragment extends BaseMwmListFragment implements View.OnClickL listView.addHeaderView(getActivity().getLayoutInflater().inflate(R.layout.header_default, listView, false), null, false); } + + // FIXME: This code only for demonstration purposes and will be removed soon + private boolean tryChangeMapStyle(String str) + { + // Hook for shell command on change map style + final boolean isDark = str.equals("mapstyle:dark"); + final boolean isLight = isDark ? false : str.equals("mapstyle:light"); + + if (!isDark && !isLight) + return false; + + // close Search panel + mEtSearchQuery.setText(null); + InputUtils.hideKeyboard(mEtSearchQuery); + getActivity().onBackPressed(); + + // change map style for the Map activity + final int mapStyle = isDark ? Framework.MAP_STYLE_DARK : Framework.MAP_STYLE_LIGHT; + MWMActivity.setMapStyle(getActivity(), mapStyle); + + return true; + } + + private boolean tryChangeRouter(String query) + { + final boolean pedestrian = query.equals("pedestrian:on"); + final boolean wehicle = query.equals("pedestrian:off"); + + if (!pedestrian && !wehicle) + return false; + + mEtSearchQuery.setText(null); + InputUtils.hideKeyboard(mEtSearchQuery); + getActivity().onBackPressed(); + + RouterTypes.saveRouterType(pedestrian ? RouterTypes.ROUTER_PEDESTRIAN : RouterTypes.ROUTER_VEHICLE); + + return false; + } + // FIXME: This code only for demonstration purposes and will be removed soon + + @Override public void onResume() {