From 3051fb506952e0e745d0287021ac60d649ba17d0 Mon Sep 17 00:00:00 2001 From: crimean Date: Thu, 21 Mar 2019 21:48:02 +0300 Subject: [PATCH] Route details UI fixes --- .../drawable/btn_circle_transparent_full.xml | 8 + .../res/layout/fragment_show_all_routes.xml | 168 +++++++++++------- OsmAnd/res/values/sizes.xml | 1 + .../osmand/plus/base/ContextMenuFragment.java | 5 +- .../dashboard/DashNavigationFragment.java | 3 +- .../ChooseRouteFragment.java | 47 +++-- .../MapRouteInfoMenu.java | 10 +- .../RouteDetailsFragment.java | 9 - 8 files changed, 149 insertions(+), 102 deletions(-) create mode 100644 OsmAnd/res/drawable/btn_circle_transparent_full.xml diff --git a/OsmAnd/res/drawable/btn_circle_transparent_full.xml b/OsmAnd/res/drawable/btn_circle_transparent_full.xml new file mode 100644 index 0000000000..ef92e877da --- /dev/null +++ b/OsmAnd/res/drawable/btn_circle_transparent_full.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/OsmAnd/res/layout/fragment_show_all_routes.xml b/OsmAnd/res/layout/fragment_show_all_routes.xml index 82104734e6..98aaaa6490 100644 --- a/OsmAnd/res/layout/fragment_show_all_routes.xml +++ b/OsmAnd/res/layout/fragment_show_all_routes.xml @@ -21,67 +21,74 @@ + android:background="?attr/flow_toolbar_bg" /> - - - + + android:paddingRight="20dp" /> - + + - - @@ -105,16 +112,25 @@ android:gravity="center_vertical" android:orientation="horizontal"> - + + + + + - + - + - + + + + + diff --git a/OsmAnd/res/values/sizes.xml b/OsmAnd/res/values/sizes.xml index 286f80081a..87d3b0a278 100644 --- a/OsmAnd/res/values/sizes.xml +++ b/OsmAnd/res/values/sizes.xml @@ -283,6 +283,7 @@ 8dp 18dp 52dp + 40dp 52dp diff --git a/OsmAnd/src/net/osmand/plus/base/ContextMenuFragment.java b/OsmAnd/src/net/osmand/plus/base/ContextMenuFragment.java index 30dc259d2e..d45e559bba 100644 --- a/OsmAnd/src/net/osmand/plus/base/ContextMenuFragment.java +++ b/OsmAnd/src/net/osmand/plus/base/ContextMenuFragment.java @@ -13,6 +13,7 @@ import android.support.annotation.NonNull; import android.support.annotation.Nullable; import android.support.v4.app.FragmentActivity; import android.support.v4.app.FragmentManager; +import android.support.v7.view.ContextThemeWrapper; import android.text.ClipboardManager; import android.util.TypedValue; import android.view.GestureDetector; @@ -171,7 +172,9 @@ public abstract class ContextMenuFragment extends BaseOsmAndFragment { preferredMapLang = app.getSettings().MAP_PREFERRED_LOCALE.get(); transliterateNames = app.getSettings().MAP_TRANSLITERATE_NAMES.get(); - view = inflater.inflate(getMainLayoutId(), container, false); + ContextThemeWrapper context = + new ContextThemeWrapper(mapActivity, !nightMode ? R.style.OsmandLightTheme : R.style.OsmandDarkTheme); + view = LayoutInflater.from(context).inflate(getMainLayoutId(), container, false); currentMenuState = getInitialMenuState(); Bundle args = getArguments(); if (args != null) { diff --git a/OsmAnd/src/net/osmand/plus/dashboard/DashNavigationFragment.java b/OsmAnd/src/net/osmand/plus/dashboard/DashNavigationFragment.java index 8ae31ae377..ba1dee07b2 100644 --- a/OsmAnd/src/net/osmand/plus/dashboard/DashNavigationFragment.java +++ b/OsmAnd/src/net/osmand/plus/dashboard/DashNavigationFragment.java @@ -15,6 +15,7 @@ import android.widget.TextView; import net.osmand.plus.R; import net.osmand.plus.activities.MapActivity; +import net.osmand.plus.routepreparationmenu.ChooseRouteFragment; import net.osmand.plus.routepreparationmenu.RouteDetailsFragment; import net.osmand.plus.dashboard.tools.DashFragmentData; import net.osmand.plus.routing.RoutingHelper; @@ -42,7 +43,7 @@ public class DashNavigationFragment extends DashBaseFragment { public void onClick(View view) { Activity activity = getActivity(); if (activity instanceof MapActivity) { - RouteDetailsFragment.showInstance((MapActivity) activity); + ChooseRouteFragment.showInstance(((MapActivity) activity).getSupportFragmentManager()); } } }); diff --git a/OsmAnd/src/net/osmand/plus/routepreparationmenu/ChooseRouteFragment.java b/OsmAnd/src/net/osmand/plus/routepreparationmenu/ChooseRouteFragment.java index 0a0246fab0..ea7a34c5a7 100644 --- a/OsmAnd/src/net/osmand/plus/routepreparationmenu/ChooseRouteFragment.java +++ b/OsmAnd/src/net/osmand/plus/routepreparationmenu/ChooseRouteFragment.java @@ -14,6 +14,7 @@ import android.support.v4.app.Fragment; import android.support.v4.app.FragmentManager; import android.support.v4.app.FragmentPagerAdapter; import android.support.v4.view.ViewPager; +import android.support.v7.view.ContextThemeWrapper; import android.text.Html; import android.text.TextUtils; import android.view.LayoutInflater; @@ -62,6 +63,7 @@ public class ChooseRouteFragment extends BaseOsmAndFragment implements ContextMe public static final String TAG = "ChooseRouteFragment"; public static final String ROUTE_INDEX_KEY = "route_index_key"; + public static final String ROUTE_INFO_STATE_KEY = "route_info_state_key"; @Nullable private LockableViewPager viewPager; @@ -80,6 +82,7 @@ public class ChooseRouteFragment extends BaseOsmAndFragment implements ContextMe private boolean wasDrawerDisabled; private boolean publicTransportMode; + private int routeInfoMenuState = -1; @Nullable @Override @@ -94,11 +97,14 @@ public class ChooseRouteFragment extends BaseOsmAndFragment implements ContextMe Bundle args = getArguments(); if (args != null) { routeIndex = args.getInt(ROUTE_INDEX_KEY); + routeInfoMenuState = args.getInt(ROUTE_INFO_STATE_KEY, -1); } if (routes != null && !routes.isEmpty()) { publicTransportMode = true; } - View view = inflater.inflate(R.layout.fragment_show_all_routes, null); + ContextThemeWrapper context = + new ContextThemeWrapper(mapActivity, !nightMode ? R.style.OsmandLightTheme : R.style.OsmandDarkTheme); + View view = LayoutInflater.from(context).inflate(R.layout.fragment_show_all_routes, null); AndroidUtils.addStatusBarPadding21v(mapActivity, view); solidToolbarView = view.findViewById(R.id.toolbar_layout); solidToolbarHeight = getResources().getDimensionPixelSize(R.dimen.dashboard_map_toolbar); @@ -209,6 +215,9 @@ public class ChooseRouteFragment extends BaseOsmAndFragment implements ContextMe MapActivity mapActivity = getMapActivity(); if (mapActivity != null) { mapActivity.getSupportFragmentManager().beginTransaction().remove(this).commitAllowingStateLoss(); + if (routeInfoMenuState != -1) { + mapActivity.getMapLayers().getMapControlsLayer().showRouteInfoMenu(routeInfoMenuState); + } } } catch (Exception e) { // ignore @@ -331,7 +340,6 @@ public class ChooseRouteFragment extends BaseOsmAndFragment implements ContextMe } private void buildMenuButtons(@NonNull View view) { - OsmandApplication app = requireMyApplication(); View backButton = view.findViewById(R.id.back_button); View backButtonFlow = view.findViewById(R.id.back_button_flow); OnClickListener backOnClick = new OnClickListener() { @@ -343,7 +351,6 @@ public class ChooseRouteFragment extends BaseOsmAndFragment implements ContextMe backButton.setOnClickListener(backOnClick); backButtonFlow.setOnClickListener(backOnClick); - int buttonsVisible = 3; OnClickListener printOnClick = new OnClickListener() { @Override public void onClick(View v) { @@ -354,11 +361,6 @@ public class ChooseRouteFragment extends BaseOsmAndFragment implements ContextMe View printRouteFlow = view.findViewById(R.id.print_route_flow); printRoute.setOnClickListener(printOnClick); printRouteFlow.setOnClickListener(printOnClick); - if (publicTransportMode) { - printRoute.setVisibility(View.GONE); - printRouteFlow.setVisibility(View.GONE); - buttonsVisible--; - } View saveRoute = view.findViewById(R.id.save_as_gpx); View saveRouteFlow = view.findViewById(R.id.save_as_gpx_flow); @@ -374,11 +376,6 @@ public class ChooseRouteFragment extends BaseOsmAndFragment implements ContextMe }; saveRoute.setOnClickListener(saveOnClick); saveRouteFlow.setOnClickListener(saveOnClick); - if (publicTransportMode) { - saveRoute.setVisibility(View.GONE); - saveRouteFlow.setVisibility(View.GONE); - buttonsVisible--; - } View shareRoute = view.findViewById(R.id.share_as_gpx); View shareRouteFlow = view.findViewById(R.id.share_as_gpx_flow); @@ -419,13 +416,11 @@ public class ChooseRouteFragment extends BaseOsmAndFragment implements ContextMe }; shareRoute.setOnClickListener(shareOnClick); shareRouteFlow.setOnClickListener(shareOnClick); + if (publicTransportMode) { - shareRoute.setVisibility(View.GONE); - shareRouteFlow.setVisibility(View.GONE); - buttonsVisible--; - } - if (buttonsVisible == 0) { + view.findViewById(R.id.toolbar_options).setVisibility(View.GONE); view.findViewById(R.id.toolbar_options_flow).setVisibility(View.GONE); + view.findViewById(R.id.toolbar_options_flow_bg).setVisibility(View.GONE); } } @@ -691,6 +686,22 @@ public class ChooseRouteFragment extends BaseOsmAndFragment implements ContextMe } } + static boolean showFromRouteInfo(FragmentManager fragmentManager, int routeIndex, int routeInfoState) { + try { + ChooseRouteFragment fragment = new ChooseRouteFragment(); + Bundle args = new Bundle(); + args.putInt(ROUTE_INDEX_KEY, routeIndex); + args.putInt(ROUTE_INFO_STATE_KEY, routeInfoState); + fragment.setArguments(args); + fragmentManager.beginTransaction() + .add(R.id.routeMenuContainer, fragment, TAG) + .commitAllowingStateLoss(); + return true; + } catch (Exception e) { + return false; + } + } + public class RoutesPagerAdapter extends FragmentPagerAdapter { private int routesCount; diff --git a/OsmAnd/src/net/osmand/plus/routepreparationmenu/MapRouteInfoMenu.java b/OsmAnd/src/net/osmand/plus/routepreparationmenu/MapRouteInfoMenu.java index 525b1597b7..83ae9cf7a9 100644 --- a/OsmAnd/src/net/osmand/plus/routepreparationmenu/MapRouteInfoMenu.java +++ b/OsmAnd/src/net/osmand/plus/routepreparationmenu/MapRouteInfoMenu.java @@ -609,7 +609,7 @@ public class MapRouteInfoMenu implements IRouteInformationListener, CardListener if (mapActivity != null) { if (card instanceof SimpleRouteCard) { hide(); - RouteDetailsFragment.showInstance(mapActivity); + ChooseRouteFragment.showFromRouteInfo(mapActivity.getSupportFragmentManager(), 0, getCurrentMenuState()); } } } @@ -633,14 +633,15 @@ public class MapRouteInfoMenu implements IRouteInformationListener, CardListener } else if (card instanceof PublicTransportCard) { if (buttonIndex == PublicTransportCard.DETAILS_BUTTON_INDEX) { hide(); - ChooseRouteFragment.showInstance(mapActivity.getSupportFragmentManager(), ((PublicTransportCard) card).getRouteId()); + ChooseRouteFragment.showFromRouteInfo(mapActivity.getSupportFragmentManager(), + ((PublicTransportCard) card).getRouteId(), getCurrentMenuState()); } else if (buttonIndex == PublicTransportCard.SHOW_BUTTON_INDEX) { setupCards(); openMenuHeaderOnly(); } } else if (card instanceof SimpleRouteCard) { hide(); - RouteDetailsFragment.showInstance(mapActivity); + ChooseRouteFragment.showFromRouteInfo(mapActivity.getSupportFragmentManager(), 0, getCurrentMenuState()); } } } @@ -1261,7 +1262,8 @@ public class MapRouteInfoMenu implements IRouteInformationListener, CardListener } if (app.getRoutingHelper().isPublicTransportMode()) { if (isTransportRouteCalculated()) { - ChooseRouteFragment.showInstance(mapActivity.getSupportFragmentManager(), app.getTransportRoutingHelper().getCurrentRoute()); + ChooseRouteFragment.showFromRouteInfo(mapActivity.getSupportFragmentManager(), + app.getTransportRoutingHelper().getCurrentRoute(), getCurrentMenuState()); } } else { mapActivity.getMapLayers().getMapControlsLayer().startNavigation(); diff --git a/OsmAnd/src/net/osmand/plus/routepreparationmenu/RouteDetailsFragment.java b/OsmAnd/src/net/osmand/plus/routepreparationmenu/RouteDetailsFragment.java index c4932db1c0..c9ff8efdac 100644 --- a/OsmAnd/src/net/osmand/plus/routepreparationmenu/RouteDetailsFragment.java +++ b/OsmAnd/src/net/osmand/plus/routepreparationmenu/RouteDetailsFragment.java @@ -1511,13 +1511,4 @@ public class RouteDetailsFragment extends ContextMenuFragment implements PublicT final int timeInSeconds = model.getExpectedTime(); return Algorithms.formatDuration(timeInSeconds, app.accessibilityEnabled()); } - - public static boolean showInstance(@NonNull MapActivity mapActivity) { - try { - ChooseRouteFragment.showInstance(mapActivity.getSupportFragmentManager()); - return true; - } catch (RuntimeException e) { - return false; - } - } } \ No newline at end of file