Update icons and add some logic

This commit is contained in:
vshcherb 2014-03-13 00:10:25 +01:00
parent 7f958ebf27
commit 721a264720
34 changed files with 388 additions and 172 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.8 KiB

After

Width:  |  Height:  |  Size: 4.7 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.8 KiB

After

Width:  |  Height:  |  Size: 4.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.7 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.8 KiB

After

Width:  |  Height:  |  Size: 4.7 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.8 KiB

After

Width:  |  Height:  |  Size: 4.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.7 KiB

View file

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true" android:drawable="@drawable/map_btn_info_p" />
<item android:state_enabled="false" android:drawable="@drawable/map_btn_info_p" />
<item android:drawable="@drawable/map_btn_info_o" />
</selector>

View file

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true" android:drawable="@drawable/map_btn_navigate_p" />
<item android:state_enabled="false" android:drawable="@drawable/map_btn_navigate_p" />
<item android:drawable="@drawable/map_btn_navigate_o" />
</selector>

View file

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true" android:drawable="@drawable/map_btn_plain_p" />
<item android:state_enabled="false" android:drawable="@drawable/map_btn_plain_p" />
<item android:drawable="@drawable/map_btn_plain_o" />
</selector>

View file

@ -4,9 +4,12 @@ import net.osmand.data.RotatedTileBox;
import net.osmand.plus.OsmandSettings.CommonPreference;
import net.osmand.plus.R;
import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.views.controls.MapAppModeControl;
import net.osmand.plus.views.controls.MapCancelControl;
import net.osmand.plus.views.controls.MapControls;
import net.osmand.plus.views.controls.MapInfoControl;
import net.osmand.plus.views.controls.MapMenuControls;
import net.osmand.plus.views.controls.MapNavigateControl;
import net.osmand.plus.views.controls.MapZoomControls;
import net.osmand.plus.views.controls.RulerControl;
import net.osmand.plus.views.controls.SmallMapMenuControls;
@ -32,18 +35,19 @@ public class MapControlsLayer extends OsmandMapLayer {
private MapZoomControls zoomControls;
private MapMenuControls mapMenuControls;
private RulerControl rulerControl;
private SmallMapMenuControls mapSmallMenuControls;
private MapCancelControl mapCancelNavigationControl;
private RulerControl rulerControl;
private MapInfoControl mapInfoNavigationControl;
private MapNavigateControl mapNavigationControl;
private MapAppModeControl mapAppModeControl;
private float scaleCoefficient;
private SeekBar transparencyBar;
private LinearLayout transparencyBarLayout;
private static CommonPreference<Integer> settingsToTransparency;
public MapControlsLayer(MapActivity activity){
this.mapActivity = activity;
@ -59,16 +63,39 @@ public class MapControlsLayer extends OsmandMapLayer {
scaleCoefficient = view.getScaleCoefficient();
FrameLayout parent = (FrameLayout) view.getParent();
Handler showUIHandler = new Handler();
zoomControls = init(new MapZoomControls(mapActivity, showUIHandler, scaleCoefficient), parent);
mapMenuControls = init(new MapMenuControls(mapActivity, showUIHandler, scaleCoefficient), parent);
mapSmallMenuControls = init(new SmallMapMenuControls(mapActivity, showUIHandler, scaleCoefficient), parent);
mapCancelNavigationControl = init(new MapCancelControl(mapActivity, showUIHandler, scaleCoefficient), parent);
rulerControl = init(new RulerControl(zoomControls, mapActivity, showUIHandler, scaleCoefficient), parent);
int rightGravity = Gravity.RIGHT | Gravity.BOTTOM;
int leftGravity = Gravity.LEFT | Gravity.BOTTOM;
// default buttons
zoomControls = init(new MapZoomControls(mapActivity, showUIHandler, scaleCoefficient), parent,
rightGravity);
mapMenuControls = init(new MapMenuControls(mapActivity, showUIHandler, scaleCoefficient), parent,
leftGravity);
// calculate route buttons
mapSmallMenuControls = init(new SmallMapMenuControls(mapActivity, showUIHandler, scaleCoefficient), parent,
leftGravity);
mapCancelNavigationControl = init(new MapCancelControl(mapActivity, showUIHandler, scaleCoefficient), parent,
leftGravity);
mapInfoNavigationControl = init(new MapInfoControl(mapActivity, showUIHandler, scaleCoefficient), parent,
leftGravity);
mapNavigationControl = init(new MapNavigateControl(mapActivity, showUIHandler, scaleCoefficient), parent,
rightGravity);
mapAppModeControl = init(new MapAppModeControl(mapActivity, showUIHandler, scaleCoefficient), parent,
rightGravity);
rulerControl = init(new RulerControl(zoomControls, mapActivity, showUIHandler, scaleCoefficient), parent,
rightGravity);
mapCancelNavigationControl.setMargin(mapSmallMenuControls.getWidth());
mapInfoNavigationControl.setMargin(mapSmallMenuControls.getWidth() + mapCancelNavigationControl.getWidth());
mapAppModeControl.setMargin(mapNavigationControl.getWidth());
initTransparencyBar(view, parent);
}
private <T extends MapControls> T init(T c, FrameLayout parent) {
private <T extends MapControls> T init(T c, FrameLayout parent, int gravity) {
c.init(parent);
c.setGravity(gravity);
return c;
}
@ -85,17 +112,22 @@ public class MapControlsLayer extends OsmandMapLayer {
shadowColor = shadw;
updatextColor(textColor, shadw, rulerControl, zoomControls, mapMenuControls);
}
// default buttons
boolean showDefaultButtons = false; //!mapActivity.getRoutingHelper().isRouteCalculated() && !mapActivity.getRoutingHelper().isFollowingMode();
checkVisibilityAndDraw(showDefaultButtons, zoomControls, canvas, tileBox, nightMode);
checkVisibilityAndDraw(showDefaultButtons, mapMenuControls, canvas, tileBox, nightMode);
boolean showZooms = false; //!mapActivity.getRoutingHelper().isRouteCalculated() && !mapActivity.getRoutingHelper().isFollowingMode();
checkVisibilityAndDraw(showZooms, zoomControls, canvas, tileBox, nightMode);
// route calculation buttons
boolean showRouteCalculationControls = !mapMenuControls.isVisible();
checkVisibilityAndDraw(showRouteCalculationControls, mapSmallMenuControls, canvas, tileBox, nightMode);
checkVisibilityAndDraw(showRouteCalculationControls, mapCancelNavigationControl, canvas, tileBox, nightMode);
checkVisibilityAndDraw(showRouteCalculationControls, mapInfoNavigationControl, canvas, tileBox, nightMode);
checkVisibilityAndDraw(showRouteCalculationControls, mapAppModeControl, canvas, tileBox, nightMode);
checkVisibilityAndDraw(showRouteCalculationControls, mapNavigationControl, canvas, tileBox, nightMode);
boolean showMenu = false;// !mapActivity.getRoutingHelper().isFollowingMode();
checkVisibilityAndDraw(showMenu, mapMenuControls, canvas, tileBox, nightMode);
boolean showSmallMenu = !mapMenuControls.isVisible();
checkVisibilityAndDraw(showSmallMenu, mapSmallMenuControls, canvas, tileBox, nightMode);
checkVisibilityAndDraw(showSmallMenu, mapCancelNavigationControl, canvas, tileBox, nightMode);
// the last one to check zoom controls visibility
// the last one to check other controls visibility
int vmargin = mapNavigationControl.isVisible() || zoomControls.isVisible() ? zoomControls.getHeight() : 0;
rulerControl.setVerticalMargin(vmargin);
checkVisibilityAndDraw(true, rulerControl, canvas, tileBox, nightMode);
}

View file

@ -0,0 +1,56 @@
package net.osmand.plus.views.controls;
import net.osmand.data.RotatedTileBox;
import net.osmand.plus.OsmandSettings;
import net.osmand.plus.R;
import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.views.OsmandMapLayer.DrawSettings;
import android.graphics.Canvas;
import android.graphics.drawable.Drawable;
import android.os.Handler;
import android.view.View;
import android.widget.Button;
import android.widget.FrameLayout;
public class MapAppModeControl extends MapControls {
private Button settingsAppModeButton;
private OsmandSettings settings;
private Drawable drawable;
private int cachedId;
public MapAppModeControl(MapActivity mapActivity, Handler showUIHandler, float scaleCoefficient) {
super(mapActivity, showUIHandler, scaleCoefficient);
settings = mapActivity.getMyApplication().getSettings();
}
@Override
public void showControls(FrameLayout parent) {
settingsAppModeButton = addButton(parent, R.string.routing_preferences_descr, R.drawable.map_btn_plain);
settingsAppModeButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO
}
});
}
@Override
public void hideControls(FrameLayout layout) {
removeButton(layout, settingsAppModeButton);
layout.removeView(settingsAppModeButton);
mapActivity.accessibleContent.remove(settingsAppModeButton);
}
@Override
public void onDraw(Canvas canvas, RotatedTileBox tileBox, DrawSettings nightMode) {
int id = settings.getApplicationMode().getIconId();
if(cachedId != id && settingsAppModeButton.getBackground().getBounds().width() > 0) {
cachedId = id;
drawable = mapActivity.getResources().getDrawable(id);
drawable.setBounds(settingsAppModeButton.getBackground().getBounds());
}
drawable.draw(canvas);
}
}

View file

@ -4,12 +4,10 @@ import net.osmand.data.RotatedTileBox;
import net.osmand.plus.R;
import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.views.OsmandMapLayer.DrawSettings;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.drawable.Drawable;
import android.os.Handler;
import android.view.Gravity;
import android.view.View;
import android.view.ViewGroup.LayoutParams;
import android.widget.Button;
import android.widget.FrameLayout;
@ -23,32 +21,29 @@ public class MapCancelControl extends MapControls {
@Override
public void showControls(FrameLayout parent) {
Context ctx = mapActivity;
cancelButton = new Button(ctx);
cancelButton.setContentDescription(ctx.getString(R.string.cancel_navigation));
cancelButton.setBackgroundResource(R.drawable.map_btn_cancel);
android.widget.FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT,
Gravity.BOTTOM | Gravity.LEFT);
params.leftMargin = ctx.getResources().getDrawable(R.drawable.map_btn_hmenu).getMinimumWidth();
parent.addView(cancelButton, params);
cancelButton.setEnabled(true);
cancelButton = addButton(parent, R.string.cancel_navigation, R.drawable.map_btn_cancel);
cancelButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
mapActivity.getMapActions().stopNavigationWithoutConfirm();
}
});
mapActivity.accessibleContent.add(cancelButton);
}
@Override
public void hideControls(FrameLayout layout) {
layout.removeView(cancelButton);
mapActivity.accessibleContent.remove(cancelButton);
removeButton(layout, cancelButton);
}
@Override
public void onDraw(Canvas canvas, RotatedTileBox tileBox, DrawSettings nightMode) {
}
public int getWidth() {
if (width == 0) {
Drawable buttonDrawable = mapActivity.getResources().getDrawable(R.drawable.map_btn_cancel);
width = buttonDrawable.getMinimumWidth();
}
return width ;
}
}

View file

@ -3,9 +3,15 @@ package net.osmand.plus.views.controls;
import net.osmand.data.RotatedTileBox;
import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.views.OsmandMapLayer.DrawSettings;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.PointF;
import android.graphics.drawable.Drawable;
import android.os.Handler;
import android.view.Gravity;
import android.view.View;
import android.view.ViewGroup.LayoutParams;
import android.widget.Button;
import android.widget.FrameLayout;
@ -17,12 +23,63 @@ public abstract class MapControls {
protected int shadowColor;
private boolean visible;
private long delayTime;
protected int gravity = Gravity.BOTTOM | Gravity.RIGHT;
protected int margin;
protected int vmargin;
protected int width;
protected int height;
public MapControls(MapActivity mapActivity, Handler showUIHandler, float scaleCoefficient) {
this.mapActivity = mapActivity;
this.showUIHandler = showUIHandler;
this.scaleCoefficient = scaleCoefficient;
}
public void setGravity(int gravity) {
this.gravity = gravity;
}
public void setMargin(int margin) {
this.margin = margin;
}
public void setVerticalMargin(int vmargin) {
this.vmargin = vmargin;
}
protected Button addButton(FrameLayout parent, int stringId, int resourceId) {
return addButton(parent, stringId, resourceId, 0);
}
protected Button addButton(FrameLayout parent, int stringId, int resourceId, int extraMargin) {
Context ctx = mapActivity;
Button button = new Button(ctx);
button.setContentDescription(ctx.getString(stringId));
button.setBackgroundResource(resourceId);
Drawable d = ctx.getResources().getDrawable(resourceId);
android.widget.FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(d.getMinimumWidth(), d.getMinimumHeight(),
gravity);
if((gravity & Gravity.LEFT) == Gravity.LEFT) {
params.leftMargin = margin + extraMargin;
} else {
params.rightMargin = margin + extraMargin;
}
if((gravity & Gravity.BOTTOM) == Gravity.BOTTOM) {
params.bottomMargin = vmargin;
} else {
params.topMargin = vmargin;
}
parent.addView(button, params);
button.setEnabled(true);
mapActivity.accessibleContent.add(button);
return button;
}
protected void removeButton(FrameLayout layout, View b) {
layout.removeView(b);
mapActivity.accessibleContent.remove(b);
}
public void updateTextColor(int textColor, int shadowColor) {
this.shadowColor = shadowColor;

View file

@ -0,0 +1,49 @@
package net.osmand.plus.views.controls;
import net.osmand.data.RotatedTileBox;
import net.osmand.plus.R;
import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.views.OsmandMapLayer.DrawSettings;
import android.graphics.Canvas;
import android.graphics.drawable.Drawable;
import android.os.Handler;
import android.view.View;
import android.widget.Button;
import android.widget.FrameLayout;
public class MapInfoControl extends MapControls {
private Button infoButton;
public MapInfoControl(MapActivity mapActivity, Handler showUIHandler, float scaleCoefficient) {
super(mapActivity, showUIHandler, scaleCoefficient);
}
@Override
public void showControls(FrameLayout parent) {
infoButton = addButton(parent, R.string.info_button, R.drawable.map_btn_info);
infoButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO
}
});
}
@Override
public void hideControls(FrameLayout layout) {
removeButton(layout, infoButton);
}
@Override
public void onDraw(Canvas canvas, RotatedTileBox tileBox, DrawSettings nightMode) {
}
public int getWidth() {
if (width == 0) {
Drawable buttonDrawable = mapActivity.getResources().getDrawable(R.drawable.map_btn_info);
width = buttonDrawable.getMinimumWidth();
}
return width ;
}
}

View file

@ -1,72 +0,0 @@
package net.osmand.plus.views.controls;
import gnu.trove.list.array.TIntArrayList;
import java.util.ArrayList;
import java.util.List;
import net.osmand.plus.OsmandSettings;
import net.osmand.plus.R;
import net.osmand.plus.views.OsmandMapTileView;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.view.View;
public class MapMagnifier {
public static View.OnLongClickListener getOnClickMagnifierListener(final OsmandMapTileView view) {
final View.OnLongClickListener listener = new View.OnLongClickListener() {
@Override
public boolean onLongClick(View notUseCouldBeNull) {
final OsmandSettings.OsmandPreference<Float> zoomScale = view.getSettings().MAP_ZOOM_SCALE_BY_DENSITY;
final AlertDialog.Builder bld = new AlertDialog.Builder(view.getContext());
float scale = view.getZoomScale();
int p = (int) ((scale > 0 ? 1 : -1) * Math.round(scale * scale * 100)) + 100;
final TIntArrayList tlist = new TIntArrayList(new int[] { 75, 100, 150, 200, 300, 400, 500 });
final List<String> values = new ArrayList<String>();
int i = -1;
for (int k = 0; k <= tlist.size(); k++) {
final boolean end = k == tlist.size();
if (i == -1) {
if ((end || p < tlist.get(k))) {
values.add(p + "%");
i = k;
} else if (p == tlist.get(k)) {
i = k;
}
}
if (k < tlist.size()) {
values.add(tlist.get(k) + "%");
}
}
if (values.size() != tlist.size()) {
tlist.insert(i, p);
}
bld.setTitle(R.string.map_magnifier);
bld.setSingleChoiceItems(values.toArray(new String[values.size()]), i,
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
int p = tlist.get(which);
float newScale;
if (p >= 100) {
newScale = (float) Math.sqrt((tlist.get(which) - 100f) / 100f);
} else {
newScale = -(float) Math.sqrt((100f - tlist.get(which)) / 100f);
}
zoomScale.set(newScale - (float) Math.sqrt(Math.max(view.getDensity() - 1, 0)));
view.getAnimatedDraggingThread().startZooming(view.getZoom(),
view.getSettingsZoomScale(), false);
dialog.dismiss();
}
});
bld.show();
return true;
}
};
return listener;
}
}

View file

@ -8,17 +8,14 @@ import net.osmand.data.RotatedTileBox;
import net.osmand.plus.ApplicationMode;
import net.osmand.plus.R;
import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.views.OsmandMapTileView;
import net.osmand.plus.views.OsmandMapLayer.DrawSettings;
import android.content.Context;
import net.osmand.plus.views.OsmandMapTileView;
import android.graphics.Canvas;
import android.graphics.PointF;
import android.graphics.drawable.Drawable;
import android.os.Handler;
import android.view.Gravity;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup.LayoutParams;
import android.widget.Button;
import android.widget.FrameLayout;
@ -34,19 +31,8 @@ public class MapMenuControls extends MapControls {
}
private void initBackToMenuButton(final OsmandMapTileView view, FrameLayout parent) {
android.widget.FrameLayout.LayoutParams params;
Context ctx = view.getContext();
backToMenuButton = new Button(ctx);
backToMenuButton.setContentDescription(ctx.getString(R.string.backToMenu));
backToMenuButton.setBackgroundResource(R.drawable.map_btn_menu);
params = new FrameLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT,
Gravity.BOTTOM | Gravity.LEFT);
parent.addView(backToMenuButton, params);
backToMenuButton.setEnabled(true);
backToMenuButton = addButton(parent, R.string.backToMenu, R.drawable.map_btn_menu);
modeShadow = view.getResources().getDrawable(R.drawable.zoom_background);
backToMenuButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
@ -56,8 +42,6 @@ public class MapMenuControls extends MapControls {
mapActivity.getMapActions().openOptionsMenuAsList();
}
});
mapActivity.accessibleContent.add(backToMenuButton);
}
@Override
@ -67,8 +51,7 @@ public class MapMenuControls extends MapControls {
@Override
public void hideControls(FrameLayout layout) {
layout.removeView(backToMenuButton);
mapActivity.accessibleContent.remove(backToMenuButton);
removeButton(layout, backToMenuButton);
}
@Override

View file

@ -0,0 +1,49 @@
package net.osmand.plus.views.controls;
import net.osmand.data.RotatedTileBox;
import net.osmand.plus.R;
import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.views.OsmandMapLayer.DrawSettings;
import android.graphics.Canvas;
import android.graphics.drawable.Drawable;
import android.os.Handler;
import android.view.View;
import android.widget.Button;
import android.widget.FrameLayout;
public class MapNavigateControl extends MapControls {
private Button navigateButton;
public MapNavigateControl(MapActivity mapActivity, Handler showUIHandler, float scaleCoefficient) {
super(mapActivity, showUIHandler, scaleCoefficient);
}
@Override
public void showControls(FrameLayout parent) {
navigateButton = addButton(parent, R.string.get_directions, R.drawable.map_btn_navigate);
navigateButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO
}
});
}
@Override
public void hideControls(FrameLayout layout) {
removeButton(layout, navigateButton);
}
@Override
public void onDraw(Canvas canvas, RotatedTileBox tileBox, DrawSettings nightMode) {
}
public int getWidth() {
if (width == 0) {
Drawable buttonDrawable = mapActivity.getResources().getDrawable(R.drawable.map_btn_navigate);
width = buttonDrawable.getMinimumWidth();
}
return width ;
}
}

View file

@ -1,14 +1,21 @@
package net.osmand.plus.views.controls;
import gnu.trove.list.array.TIntArrayList;
import java.util.ArrayList;
import java.util.List;
import net.osmand.data.RotatedTileBox;
import net.osmand.plus.OsmAndConstants;
import net.osmand.plus.OsmandSettings;
import net.osmand.plus.R;
import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.views.BaseMapLayer;
import net.osmand.plus.views.OsmandMapLayer.DrawSettings;
import net.osmand.plus.views.OsmandMapTileView;
import net.osmand.plus.views.ShadowText;
import android.content.Context;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
@ -19,9 +26,7 @@ import android.graphics.drawable.Drawable;
import android.os.Handler;
import android.os.Message;
import android.text.TextPaint;
import android.view.Gravity;
import android.view.View;
import android.view.ViewGroup.LayoutParams;
import android.widget.Button;
import android.widget.FrameLayout;
@ -53,7 +58,7 @@ public class MapZoomControls extends MapControls {
public boolean onSingleTap(PointF point, RotatedTileBox tileBox) {
if (isShowZoomLevel() && zoomShadow.getBounds().contains((int) point.x, (int) point.y)) {
MapMagnifier.getOnClickMagnifierListener(view).onLongClick(null);
getOnClickMagnifierListener(view).onLongClick(null);
return true;
}
return false;
@ -63,28 +68,8 @@ public class MapZoomControls extends MapControls {
@Override
protected void showControls(FrameLayout parent) {
int minimumWidth = view.getResources().getDrawable(R.drawable.map_zoom_in).getMinimumWidth();
Context ctx = view.getContext();
zoomInButton = new Button(ctx);
zoomInButton.setBackgroundResource(R.drawable.map_zoom_in);
android.widget.FrameLayout.LayoutParams params =
new FrameLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT, Gravity.BOTTOM
| Gravity.RIGHT);
params.setMargins(0, 0, 0, 0);
zoomInButton.setContentDescription(ctx.getString(R.string.zoomIn));
parent.addView(zoomInButton, params);
zoomOutButton = new Button(ctx);
zoomOutButton.setBackgroundResource(R.drawable.map_zoom_out);
params = new FrameLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT, Gravity.BOTTOM
| Gravity.RIGHT);
params.setMargins(0, 0, minimumWidth, 0);
zoomOutButton.setContentDescription(ctx.getString(R.string.zoomOut));
parent.addView(zoomOutButton, params);
mapActivity.accessibleContent.add(zoomInButton);
mapActivity.accessibleContent.add(zoomOutButton);
zoomInButton = addButton(parent, R.string.zoomIn, R.drawable.map_zoom_in);
zoomOutButton = addButton(parent, R.string.zoomOut, R.drawable.map_zoom_out, minimumWidth);
zoomInButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
@ -96,7 +81,7 @@ public class MapZoomControls extends MapControls {
}
});
final View.OnLongClickListener listener = MapMagnifier.getOnClickMagnifierListener(view);
final View.OnLongClickListener listener = getOnClickMagnifierListener(view);
zoomInButton.setOnLongClickListener(listener);
zoomOutButton.setOnClickListener(new View.OnClickListener() {
@Override
@ -116,10 +101,8 @@ public class MapZoomControls extends MapControls {
@Override
public void hideControls(FrameLayout layout) {
mapActivity.accessibleContent.remove(zoomInButton);
mapActivity.accessibleContent.remove(zoomOutButton);
layout.removeView(zoomInButton);
layout.removeView(zoomOutButton);
removeButton(layout, zoomInButton);
removeButton(layout, zoomOutButton);
}
private void drawZoomLevel(Canvas canvas, RotatedTileBox tb, boolean drawZoomLevel) {
@ -226,9 +209,68 @@ public class MapZoomControls extends MapControls {
}
public int getHeight() {
Drawable buttonDrawable = view.getResources().getDrawable(R.drawable.map_zoom_in);
return buttonDrawable.getMinimumHeight();
if (height == 0) {
Drawable buttonDrawable = view.getResources().getDrawable(R.drawable.map_zoom_in);
height = buttonDrawable.getMinimumHeight();
}
return height;
}
public static View.OnLongClickListener getOnClickMagnifierListener(final OsmandMapTileView view) {
final View.OnLongClickListener listener = new View.OnLongClickListener() {
@Override
public boolean onLongClick(View notUseCouldBeNull) {
final OsmandSettings.OsmandPreference<Float> zoomScale = view.getSettings().MAP_ZOOM_SCALE_BY_DENSITY;
final AlertDialog.Builder bld = new AlertDialog.Builder(view.getContext());
float scale = view.getZoomScale();
int p = (int) ((scale > 0 ? 1 : -1) * Math.round(scale * scale * 100)) + 100;
final TIntArrayList tlist = new TIntArrayList(new int[] { 75, 100, 150, 200, 300, 400, 500 });
final List<String> values = new ArrayList<String>();
int i = -1;
for (int k = 0; k <= tlist.size(); k++) {
final boolean end = k == tlist.size();
if (i == -1) {
if ((end || p < tlist.get(k))) {
values.add(p + "%");
i = k;
} else if (p == tlist.get(k)) {
i = k;
}
}
if (k < tlist.size()) {
values.add(tlist.get(k) + "%");
}
}
if (values.size() != tlist.size()) {
tlist.insert(i, p);
}
bld.setTitle(R.string.map_magnifier);
bld.setSingleChoiceItems(values.toArray(new String[values.size()]), i,
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
int p = tlist.get(which);
float newScale;
if (p >= 100) {
newScale = (float) Math.sqrt((tlist.get(which) - 100f) / 100f);
} else {
newScale = -(float) Math.sqrt((100f - tlist.get(which)) / 100f);
}
zoomScale.set(newScale - (float) Math.sqrt(Math.max(view.getDensity() - 1, 0)));
view.getAnimatedDraggingThread().startZooming(view.getZoom(),
view.getSettingsZoomScale(), false);
dialog.dismiss();
}
});
bld.show();
return true;
}
};
return listener;
}
}

View file

@ -80,7 +80,7 @@ public class RulerControl extends MapControls {
if (cacheRulerText != null) {
Rect bounds = rulerDrawable.getBounds();
int bottom = (int) (view.getHeight() - (!zoomControls.isVisible() ? 0 : zoomControls.getHeight()));
int bottom = (int) (view.getHeight() - vmargin);
if(bounds.bottom != bottom) {
bounds.bottom = bottom;
bounds.top = bounds.bottom - rulerDrawable.getMinimumHeight();

View file

@ -4,51 +4,58 @@ import net.osmand.data.RotatedTileBox;
import net.osmand.plus.R;
import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.views.OsmandMapLayer.DrawSettings;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.drawable.Drawable;
import android.os.Handler;
import android.view.Gravity;
import android.view.View;
import android.view.ViewGroup.LayoutParams;
import android.widget.Button;
import android.widget.FrameLayout;
public class SmallMapMenuControls extends MapControls {
private Button backToMenuButton;
public SmallMapMenuControls(MapActivity mapActivity, Handler showUIHandler, float scaleCoefficient) {
super(mapActivity, showUIHandler, scaleCoefficient);
}
@SuppressWarnings("deprecation")
@Override
public void showControls(FrameLayout parent) {
backToMenuButton = addButton(parent, R.string.backToMenu, R.drawable.map_btn_hmenu);
/*
Context ctx = mapActivity;
backToMenuButton = new Button(ctx);
backToMenuButton = new ImageButton(ctx);
backToMenuButton.setContentDescription(ctx.getString(R.string.backToMenu));
backToMenuButton.setBackgroundDrawable(ctx.getResources().getDrawable(R.drawable.map_btn_hmenu));
backToMenuButton.setImageResource(R.drawable.map_btn_hmenu);
android.widget.FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT,
Gravity.BOTTOM | Gravity.LEFT);
parent.addView(backToMenuButton, params);
backToMenuButton.setEnabled(true);
mapActivity.accessibleContent.add(backToMenuButton);*/
backToMenuButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
mapActivity.getMapActions().openOptionsMenuAsList();
}
});
mapActivity.accessibleContent.add(backToMenuButton);
}
@Override
public void hideControls(FrameLayout layout) {
layout.removeView(backToMenuButton);
mapActivity.accessibleContent.remove(backToMenuButton);
removeButton(layout, backToMenuButton);
}
@Override
public void onDraw(Canvas canvas, RotatedTileBox tileBox, DrawSettings nightMode) {
}
public int getWidth() {
if (width == 0) {
Drawable buttonDrawable = mapActivity.getResources().getDrawable(R.drawable.map_btn_hmenu);
width = buttonDrawable.getMinimumWidth();
}
return width ;
}
}