Zoom controls for landscape orientation moved to the left. Distance between zoom controls minimized

This commit is contained in:
Denis 2014-10-08 13:06:14 +03:00
parent 64eeb3401d
commit 337feb83cc
2 changed files with 80 additions and 5 deletions

View file

@ -3,6 +3,11 @@ package net.osmand.plus.views;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; 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.data.RotatedTileBox;
import net.osmand.plus.OsmandSettings; import net.osmand.plus.OsmandSettings;
import net.osmand.plus.OsmandSettings.CommonPreference; import net.osmand.plus.OsmandSettings.CommonPreference;
@ -82,12 +87,18 @@ public class MapControlsLayer extends OsmandMapLayer {
int rightGravity = Gravity.RIGHT | Gravity.BOTTOM; int rightGravity = Gravity.RIGHT | Gravity.BOTTOM;
int leftGravity = Gravity.LEFT | Gravity.BOTTOM; int leftGravity = Gravity.LEFT | Gravity.BOTTOM;
int rightCenterGravity = Gravity.RIGHT | Gravity.CENTER; int rightCenterGravity = Gravity.RIGHT | Gravity.CENTER;
int leftCenterGravity = Gravity.LEFT | Gravity.CENTER;
// default buttons // default buttons
zoomControls = init(new MapZoomControls(mapActivity, showUIHandler, scaleCoefficient), parent, zoomControls = init(new MapZoomControls(mapActivity, showUIHandler, scaleCoefficient), parent,
rightGravity); rightGravity);
if (getScreenOrientation() == ActivityInfo.SCREEN_ORIENTATION_PORTRAIT){
zoomSideControls = init(new MapZoomControls(mapActivity, showUIHandler, scaleCoefficient), parent, zoomSideControls = init(new MapZoomControls(mapActivity, showUIHandler, scaleCoefficient), parent,
rightCenterGravity); rightCenterGravity);
} else {
zoomSideControls = init(new MapZoomControls(mapActivity, showUIHandler, scaleCoefficient), parent,
leftCenterGravity);
}
mapMenuControls = init(new MapMenuControls(mapActivity, showUIHandler, scaleCoefficient), parent, mapMenuControls = init(new MapMenuControls(mapActivity, showUIHandler, scaleCoefficient), parent,
leftGravity); leftGravity);
mapRoutePlanControl = init(new MapRoutePlanControl(mapActivity, showUIHandler, scaleCoefficient), parent, mapRoutePlanControl = init(new MapRoutePlanControl(mapActivity, showUIHandler, scaleCoefficient), parent,
@ -329,4 +340,67 @@ public class MapControlsLayer extends OsmandMapLayer {
public WaypointDialogHelper getWaypointDialogHelper() { public WaypointDialogHelper getWaypointDialogHelper() {
return waypointDialogHelper; 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;
}
} }

View file

@ -1,5 +1,6 @@
package net.osmand.plus.views.controls; package net.osmand.plus.views.controls;
import android.view.Gravity;
import gnu.trove.list.array.TIntArrayList; import gnu.trove.list.array.TIntArrayList;
import java.util.ArrayList; import java.util.ArrayList;
@ -74,7 +75,7 @@ public class MapZoomControls extends MapControls {
if(isBottom()) { if(isBottom()) {
zoomOutButton = addButton(parent, R.string.zoomOut, R.drawable.map_zoom_out, minimumWidth); zoomOutButton = addButton(parent, R.string.zoomOut, R.drawable.map_zoom_out, minimumWidth);
} else { } else {
vmargin = minimumHeight; vmargin = minimumHeight - (minimumHeight / 6);
zoomOutButton = addButton(parent, R.string.zoomOut, R.drawable.map_zoom_out); zoomOutButton = addButton(parent, R.string.zoomOut, R.drawable.map_zoom_out);
} }
zoomInButton.setOnClickListener(new View.OnClickListener() { zoomInButton.setOnClickListener(new View.OnClickListener() {