From 3dd616590cbd0ca37c923d113fb5d9dc31a4f441 Mon Sep 17 00:00:00 2001 From: Alexander Sytnyk Date: Mon, 14 Aug 2017 17:41:24 +0300 Subject: [PATCH] Add some improvements (2) --- OsmAnd/res/values/sizes.xml | 1 + OsmAnd/src/net/osmand/plus/OsmandSettings.java | 1 + .../measurementtool/MeasurementToolFragment.java | 7 ++++++- .../OptionsBottomSheetDialogFragment.java | 16 +++++++++++++++- .../SnapToRoadBottomSheetDialogFragment.java | 14 ++++++++++++++ .../net/osmand/plus/views/OsmandMapTileView.java | 7 ++++++- 6 files changed, 43 insertions(+), 3 deletions(-) diff --git a/OsmAnd/res/values/sizes.xml b/OsmAnd/res/values/sizes.xml index c8165ab7b4..d1cb1205ec 100644 --- a/OsmAnd/res/values/sizes.xml +++ b/OsmAnd/res/values/sizes.xml @@ -157,4 +157,5 @@ 64dp 48dp + 360dp \ No newline at end of file diff --git a/OsmAnd/src/net/osmand/plus/OsmandSettings.java b/OsmAnd/src/net/osmand/plus/OsmandSettings.java index 03147d4e8b..d7f0a3d237 100644 --- a/OsmAnd/src/net/osmand/plus/OsmandSettings.java +++ b/OsmAnd/src/net/osmand/plus/OsmandSettings.java @@ -1246,6 +1246,7 @@ public class OsmandSettings { public static final int BOTTOM_CONSTANT = 1; public static final int MIDDLE_BOTTOM_CONSTANT = 2; public static final int MIDDLE_TOP_CONSTANT = 3; + public static final int LANDSCAPE_MIDDLE_RIGHT_CONSTANT = 4; public final CommonPreference CENTER_POSITION_ON_MAP = new BooleanPreference("center_position_on_map", false).makeProfile(); // this value string is synchronized with settings_pref.xml preference name diff --git a/OsmAnd/src/net/osmand/plus/measurementtool/MeasurementToolFragment.java b/OsmAnd/src/net/osmand/plus/measurementtool/MeasurementToolFragment.java index e86f140f28..a99f9b19a0 100644 --- a/OsmAnd/src/net/osmand/plus/measurementtool/MeasurementToolFragment.java +++ b/OsmAnd/src/net/osmand/plus/measurementtool/MeasurementToolFragment.java @@ -62,6 +62,7 @@ import java.util.List; import java.util.Locale; import static net.osmand.plus.GPXUtilities.GPXFile; +import static net.osmand.plus.OsmandSettings.LANDSCAPE_MIDDLE_RIGHT_CONSTANT; import static net.osmand.plus.OsmandSettings.MIDDLE_TOP_CONSTANT; import static net.osmand.plus.helpers.GpxImportHelper.GPX_SUFFIX; @@ -471,7 +472,11 @@ public class MeasurementToolFragment extends Fragment { } OsmandMapTileView tileView = mapActivity.getMapView(); previousMapPosition = tileView.getMapPosition(); - tileView.setMapPosition(MIDDLE_TOP_CONSTANT); + if (portrait) { + tileView.setMapPosition(MIDDLE_TOP_CONSTANT); + } else { + tileView.setMapPosition(LANDSCAPE_MIDDLE_RIGHT_CONSTANT); + } mapActivity.refreshMap(); } } diff --git a/OsmAnd/src/net/osmand/plus/measurementtool/OptionsBottomSheetDialogFragment.java b/OsmAnd/src/net/osmand/plus/measurementtool/OptionsBottomSheetDialogFragment.java index fa085978bd..225e96a64a 100644 --- a/OsmAnd/src/net/osmand/plus/measurementtool/OptionsBottomSheetDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/measurementtool/OptionsBottomSheetDialogFragment.java @@ -8,6 +8,8 @@ import android.view.ContextThemeWrapper; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; +import android.view.Window; +import android.view.WindowManager; import android.widget.ImageView; import net.osmand.AndroidUtils; @@ -21,6 +23,7 @@ public class OptionsBottomSheetDialogFragment extends BottomSheetDialogFragment private OptionsOnClickListener listener; private boolean addLineMode; + private boolean portrait; public void setOptionsOnClickListener(OptionsOnClickListener listener) { this.listener = listener; @@ -35,7 +38,7 @@ public class OptionsBottomSheetDialogFragment extends BottomSheetDialogFragment public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { final boolean nightMode = getMyApplication().getDaynightHelper().isNightModeForMapControls(); final int themeRes = nightMode ? R.style.OsmandDarkTheme : R.style.OsmandLightTheme; - boolean portrait = AndroidUiHelper.isOrientationPortrait(getActivity()); + portrait = AndroidUiHelper.isOrientationPortrait(getActivity()); final View mainView = View.inflate(new ContextThemeWrapper(getContext(), themeRes), R.layout.fragment_options_bottom_sheet_dialog, null); if (portrait) { @@ -112,6 +115,17 @@ public class OptionsBottomSheetDialogFragment extends BottomSheetDialogFragment return mainView; } + @Override + public void onStart() { + super.onStart(); + if (!portrait) { + final Window window = getDialog().getWindow(); + WindowManager.LayoutParams params = window.getAttributes(); + params.width = getActivity().getResources().getDimensionPixelSize(R.dimen.landscape_bottom_sheet_dialog_fragment_width); + window.setAttributes(params); + } + } + @Override protected Drawable getContentIcon(@DrawableRes int id) { return getIcon(id, getMyApplication().getSettings().isLightContent() ? R.color.on_map_icon_color : 0); diff --git a/OsmAnd/src/net/osmand/plus/measurementtool/SnapToRoadBottomSheetDialogFragment.java b/OsmAnd/src/net/osmand/plus/measurementtool/SnapToRoadBottomSheetDialogFragment.java index 231d88b6c4..81a6794140 100644 --- a/OsmAnd/src/net/osmand/plus/measurementtool/SnapToRoadBottomSheetDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/measurementtool/SnapToRoadBottomSheetDialogFragment.java @@ -9,6 +9,8 @@ import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.view.ViewTreeObserver; +import android.view.Window; +import android.view.WindowManager; import android.widget.ImageView; import android.widget.LinearLayout; import android.widget.TextView; @@ -18,6 +20,7 @@ import net.osmand.plus.ApplicationMode; import net.osmand.plus.OsmandSettings; import net.osmand.plus.R; import net.osmand.plus.base.BottomSheetDialogFragment; +import net.osmand.plus.helpers.AndroidUiHelper; import java.util.ArrayList; import java.util.List; @@ -80,6 +83,17 @@ public class SnapToRoadBottomSheetDialogFragment extends BottomSheetDialogFragme return view; } + @Override + public void onStart() { + super.onStart(); + if (!AndroidUiHelper.isOrientationPortrait(getActivity())) { + final Window window = getDialog().getWindow(); + WindowManager.LayoutParams params = window.getAttributes(); + params.width = getActivity().getResources().getDimensionPixelSize(R.dimen.landscape_bottom_sheet_dialog_fragment_width); + window.setAttributes(params); + } + } + private int getNavBarHeight() { if (!hasNavBar()) { return 0; diff --git a/OsmAnd/src/net/osmand/plus/views/OsmandMapTileView.java b/OsmAnd/src/net/osmand/plus/views/OsmandMapTileView.java index 4ddb967c7d..79aa23f434 100644 --- a/OsmAnd/src/net/osmand/plus/views/OsmandMapTileView.java +++ b/OsmAnd/src/net/osmand/plus/views/OsmandMapTileView.java @@ -585,7 +585,12 @@ public class OsmandMapTileView implements IMapDownloaderCallback { } else { ratioy = 0.5f; } - final float ratiox = mapPositionX == 0 ? 0.5f : 0.75f; + final float ratiox; + if (mapPosition == OsmandSettings.LANDSCAPE_MIDDLE_RIGHT_CONSTANT) { + ratiox = 0.7f; + } else { + ratiox = mapPositionX == 0 ? 0.5f : 0.75f; + } final int cy = (int) (ratioy * view.getHeight()); final int cx = (int) (ratiox * view.getWidth()); if (currentViewport.getPixWidth() != view.getWidth() || currentViewport.getPixHeight() != view.getHeight() ||