From 6aa48d1a94def73fe5ad58183ae4c531e6db588e Mon Sep 17 00:00:00 2001 From: madwasp79 Date: Wed, 3 Jul 2019 10:33:55 +0300 Subject: [PATCH] refactoring --- .../activities/actions/AppModeDialog.java | 20 ++++++++---------- .../MapRouteInfoMenu.java | 21 ++++++++----------- 2 files changed, 18 insertions(+), 23 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/activities/actions/AppModeDialog.java b/OsmAnd/src/net/osmand/plus/activities/actions/AppModeDialog.java index ac4c8e2257..c8b17f5781 100644 --- a/OsmAnd/src/net/osmand/plus/activities/actions/AppModeDialog.java +++ b/OsmAnd/src/net/osmand/plus/activities/actions/AppModeDialog.java @@ -86,19 +86,17 @@ public class AppModeDialog { int buttonWidth = AndroidUtils.dpToPx(a, (int) a.getResources().getDimension(R.dimen.route_info_modes_height)); List modes = new ArrayList<>(ApplicationMode.values(app)); final HorizontalScrollView sv = ll.findViewById(R.id.app_modes_scroll_container); - - if (app.getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT) { - for (int i = 0; i < modes.size(); i++) { - if (modes.get(i).equals(app.getSettings().getApplicationMode()) - && (i - 1) * buttonWidth > AndroidUtils.getScreenWidth(a)) { + final ApplicationMode activeMode = app.getSettings().getApplicationMode(); + final boolean orientationPortrait = app.getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT; + + for (int i = 0; i < modes.size(); i++) { + if (modes.get(i).equals(activeMode)) { + if (orientationPortrait && i * buttonWidth > AndroidUtils.getScreenWidth(a)) { scrollLength[0] = i * buttonWidth - AndroidUtils.getScreenWidth(a); - } - } - } else { - for (int i = 0; i < modes.size(); i++) { - if (modes.get(i).equals(app.getSettings().getApplicationMode())) { + } else if (!orientationPortrait && + i * buttonWidth > app.getResources().getDimension(R.dimen.dashboard_land_width)){ scrollLength[0] = i * buttonWidth - (int) app.getResources() - .getDimension(R.dimen.dashboard_land_width); + .getDimension(R.dimen.dashboard_land_width); } } } diff --git a/OsmAnd/src/net/osmand/plus/routepreparationmenu/MapRouteInfoMenu.java b/OsmAnd/src/net/osmand/plus/routepreparationmenu/MapRouteInfoMenu.java index 20dd0511b2..f5da3b2472 100644 --- a/OsmAnd/src/net/osmand/plus/routepreparationmenu/MapRouteInfoMenu.java +++ b/OsmAnd/src/net/osmand/plus/routepreparationmenu/MapRouteInfoMenu.java @@ -841,19 +841,16 @@ public class MapRouteInfoMenu implements IRouteInformationListener, CardListener } final int[] scrollLength = {0}; - int buttonWidth = AndroidUtils.dpToPx(mapActivity, - (int) mapActivity.getResources().getDimension(R.dimen.route_info_modes_height)); - if (app.getResources().getConfiguration().orientation - == Configuration.ORIENTATION_PORTRAIT) { - for (int i = 0; i < values.size(); i++) { - if (values.get(i).equals(app.getSettings().getApplicationMode()) - && (i - 1) * buttonWidth > AndroidUtils.getScreenWidth(mapActivity)) { + int buttonWidth = AndroidUtils.dpToPx(mapActivity, (int) mapActivity.getResources().getDimension(R.dimen.route_info_modes_height)); + final boolean orientationPortrait = app.getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT; + final ApplicationMode activeMode = app.getSettings().getApplicationMode(); + + for (int i = 0; i < values.size(); i++) { + if (values.get(i).equals(activeMode)) { + if (orientationPortrait && i * buttonWidth > AndroidUtils.getScreenWidth(mapActivity)) { scrollLength[0] = i * buttonWidth - AndroidUtils.getScreenWidth(mapActivity); - } - } - } else { - for (int i = 0; i < values.size(); i++) { - if (values.get(i).equals(app.getSettings().getApplicationMode())) { + } else if (!orientationPortrait && + i * buttonWidth > app.getResources().getDimension(R.dimen.dashboard_land_width)){ scrollLength[0] = i * buttonWidth - (int) app.getResources() .getDimension(R.dimen.dashboard_land_width); }