From 337feb83cc37e50ade3a2a864ec6e77996afe184 Mon Sep 17 00:00:00 2001 From: Denis Date: Wed, 8 Oct 2014 13:06:14 +0300 Subject: [PATCH] Zoom controls for landscape orientation moved to the left. Distance between zoom controls minimized --- .../osmand/plus/views/MapControlsLayer.java | 82 ++++++++++++++++++- .../plus/views/controls/MapZoomControls.java | 3 +- 2 files changed, 80 insertions(+), 5 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/views/MapControlsLayer.java b/OsmAnd/src/net/osmand/plus/views/MapControlsLayer.java index f79203f3c2..d6f7645a0d 100644 --- a/OsmAnd/src/net/osmand/plus/views/MapControlsLayer.java +++ b/OsmAnd/src/net/osmand/plus/views/MapControlsLayer.java @@ -3,6 +3,11 @@ package net.osmand.plus.views; import java.util.ArrayList; import java.util.List; +import android.content.pm.ActivityInfo; +import android.util.DisplayMetrics; +import android.util.Log; +import android.view.Surface; +import net.osmand.PlatformUtil; import net.osmand.data.RotatedTileBox; import net.osmand.plus.OsmandSettings; import net.osmand.plus.OsmandSettings.CommonPreference; @@ -82,13 +87,19 @@ public class MapControlsLayer extends OsmandMapLayer { int rightGravity = Gravity.RIGHT | Gravity.BOTTOM; int leftGravity = Gravity.LEFT | Gravity.BOTTOM; int rightCenterGravity = Gravity.RIGHT | Gravity.CENTER; + int leftCenterGravity = Gravity.LEFT | Gravity.CENTER; // default buttons zoomControls = init(new MapZoomControls(mapActivity, showUIHandler, scaleCoefficient), parent, rightGravity); - zoomSideControls = init(new MapZoomControls(mapActivity, showUIHandler, scaleCoefficient), parent, - rightCenterGravity); - mapMenuControls = init(new MapMenuControls(mapActivity, showUIHandler, scaleCoefficient), parent, + if (getScreenOrientation() == ActivityInfo.SCREEN_ORIENTATION_PORTRAIT){ + zoomSideControls = init(new MapZoomControls(mapActivity, showUIHandler, scaleCoefficient), parent, + rightCenterGravity); + } else { + zoomSideControls = init(new MapZoomControls(mapActivity, showUIHandler, scaleCoefficient), parent, + leftCenterGravity); + } + mapMenuControls = init(new MapMenuControls(mapActivity, showUIHandler, scaleCoefficient), parent, leftGravity); mapRoutePlanControl = init(new MapRoutePlanControl(mapActivity, showUIHandler, scaleCoefficient), parent, leftGravity); @@ -184,7 +195,7 @@ public class MapControlsLayer extends OsmandMapLayer { // the last one to check other controls visibility int vmargin = mapNavigationControl.isVisible() || zoomControls.isVisible() ? - (zoomControls.getHeight() + zoomControls.getTotalVerticalMargin()): 0; + (zoomControls.getHeight() + zoomControls.getTotalVerticalMargin()) : 0; rulerControl.setVerticalMargin(vmargin); checkVisibilityAndDraw(true, rulerControl, canvas, tileBox, nightMode); } @@ -329,4 +340,67 @@ public class MapControlsLayer extends OsmandMapLayer { public WaypointDialogHelper getWaypointDialogHelper() { return waypointDialogHelper; } + + private int getScreenOrientation() { + int rotation = mapActivity.getWindowManager().getDefaultDisplay().getRotation(); + DisplayMetrics dm = new DisplayMetrics(); + mapActivity.getWindowManager().getDefaultDisplay().getMetrics(dm); + int width = dm.widthPixels; + int height = dm.heightPixels; + int orientation; + // if the device's natural orientation is portrait: + if ((rotation == Surface.ROTATION_0 + || rotation == Surface.ROTATION_180) && height > width || + (rotation == Surface.ROTATION_90 + || rotation == Surface.ROTATION_270) && width > height) { + switch(rotation) { + case Surface.ROTATION_0: + orientation = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT; + break; + case Surface.ROTATION_90: + orientation = ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE; + break; + case Surface.ROTATION_180: + orientation = + ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT; + break; + case Surface.ROTATION_270: + orientation = + ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE; + break; + default: + Log.e(PlatformUtil.TAG, "Unknown screen orientation. Defaulting to " + + "portrait."); + orientation = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT; + break; + } + } + // if the device's natural orientation is landscape or if the device + // is square: + else { + switch(rotation) { + case Surface.ROTATION_0: + orientation = ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE; + break; + case Surface.ROTATION_90: + orientation = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT; + break; + case Surface.ROTATION_180: + orientation = + ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE; + break; + case Surface.ROTATION_270: + orientation = + ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT; + break; + default: + Log.e(PlatformUtil.TAG, "Unknown screen orientation. Defaulting to " + + "landscape."); + orientation = ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE; + break; + } + } + + return orientation; + } } diff --git a/OsmAnd/src/net/osmand/plus/views/controls/MapZoomControls.java b/OsmAnd/src/net/osmand/plus/views/controls/MapZoomControls.java index 32c61eca0c..548a290b57 100644 --- a/OsmAnd/src/net/osmand/plus/views/controls/MapZoomControls.java +++ b/OsmAnd/src/net/osmand/plus/views/controls/MapZoomControls.java @@ -1,5 +1,6 @@ package net.osmand.plus.views.controls; +import android.view.Gravity; import gnu.trove.list.array.TIntArrayList; import java.util.ArrayList; @@ -74,7 +75,7 @@ public class MapZoomControls extends MapControls { if(isBottom()) { zoomOutButton = addButton(parent, R.string.zoomOut, R.drawable.map_zoom_out, minimumWidth); } else { - vmargin = minimumHeight; + vmargin = minimumHeight - (minimumHeight / 6); zoomOutButton = addButton(parent, R.string.zoomOut, R.drawable.map_zoom_out); } zoomInButton.setOnClickListener(new View.OnClickListener() {