Add buttons to right pane, add zoom buttons (optionally), fix navigation start with delay

This commit is contained in:
Victor Shcherb 2014-06-15 13:40:32 +02:00
parent d9a7c973b3
commit 7cc3889e82
14 changed files with 150 additions and 45 deletions

View file

@ -9,6 +9,9 @@
3. All your modified/created strings are in the top of the file (to make easier find what\'s translated).
PLEASE: Have a look at http://code.google.com/p/osmand/wiki/UIConsistency, it may really improve your and our work :-) Thx - Hardy
-->
<string name="show_zoom_buttons_navigation_descr">Show zoom buttons during navigation</string>
<string name="show_zoom_buttons_navigation">Show zoom buttons</string>
<string name="save_as_favorites_points">Save as group of favorites</string>
<string name="select_destination_and_intermediate_points">Select waypoints</string>
<string name="layer_amenity_label">Point labels</string>

View file

@ -19,5 +19,7 @@
android:key="keep_informing"
android:title="@string/keep_informing"
android:summary="@string/keep_informing_descr" />
<CheckBoxPreference android:title="@string/show_zoom_buttons_navigation" android:summary="@string/show_zoom_buttons_navigation_descr" android:key="show_zoom_buttons_navigation" />
</PreferenceCategory>
</PreferenceScreen>

View file

@ -849,6 +849,11 @@ public class OsmandSettings {
// this value string is synchronized with settings_pref.xml preference name
public final OsmandPreference<Boolean> SHOW_FAVORITES = new BooleanPreference("show_favorites", false).makeGlobal();
public final CommonPreference<Boolean> SHOW_ZOOM_BUTTONS_NAVIGATION = new BooleanPreference("show_zoom_buttons_navigation", false).makeProfile().cache();
{
SHOW_ZOOM_BUTTONS_NAVIGATION.setModeDefaultValue(ApplicationMode.PEDESTRIAN, true);
}
// Json
public final OsmandPreference<String> SELECTED_GPX = new StringPreference("selected_gpx", "").makeGlobal();

View file

@ -89,6 +89,8 @@ public class SettingsNavigationActivity extends SettingsBaseActivity {
}
registerListPreference(settings.KEEP_INFORMING, screen, keepInformingNames, keepInformingValues);
registerBooleanPreference(settings.SHOW_ZOOM_BUTTONS_NAVIGATION, screen);
autoZoomMapPreference = (ListPreference) screen.findPreference(settings.AUTO_ZOOM_MAP.getId());
autoZoomMapPreference.setOnPreferenceChangeListener(this);

View file

@ -4,6 +4,7 @@ import java.util.ArrayList;
import java.util.List;
import net.osmand.data.RotatedTileBox;
import net.osmand.plus.OsmandSettings;
import net.osmand.plus.OsmandSettings.CommonPreference;
import net.osmand.plus.R;
import net.osmand.plus.activities.MapActivity;
@ -23,6 +24,7 @@ import android.graphics.Color;
import android.graphics.PointF;
import android.os.Handler;
import android.view.Gravity;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup.LayoutParams;
@ -39,6 +41,7 @@ public class MapControlsLayer extends OsmandMapLayer {
private int shadowColor = -1;
private MapZoomControls zoomControls;
private MapZoomControls zoomSideControls;
private MapMenuControls mapMenuControls;
private RulerControl rulerControl;
@ -55,9 +58,11 @@ public class MapControlsLayer extends OsmandMapLayer {
private SeekBar transparencyBar;
private LinearLayout transparencyBarLayout;
private static CommonPreference<Integer> settingsToTransparency;
private OsmandSettings settings;
public MapControlsLayer(MapActivity activity){
this.mapActivity = activity;
settings = activity.getMyApplication().getSettings();
}
@Override
@ -72,10 +77,13 @@ public class MapControlsLayer extends OsmandMapLayer {
Handler showUIHandler = new Handler();
int rightGravity = Gravity.RIGHT | Gravity.BOTTOM;
int leftGravity = Gravity.LEFT | Gravity.BOTTOM;
int rightCenterGravity = Gravity.RIGHT | 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,
leftGravity);
mapRoutePlanControl = init(new MapRoutePlanControl(mapActivity, showUIHandler, scaleCoefficient), parent,
@ -104,13 +112,26 @@ public class MapControlsLayer extends OsmandMapLayer {
}
private <T extends MapControls> T init(T c, FrameLayout parent, int gravity) {
c.init(parent);
private <T extends MapControls> T init(final T c, FrameLayout parent, int gravity) {
c.setGravity(gravity);
c.init(parent);
allControls.add(c);
c.setNotifyClick(new Runnable() {
@Override
public void run() {
notifyClicked(c);
}
});
return c;
}
protected void notifyClicked(MapControls m) {
if(mapNavigationControl != null) {
mapNavigationControl.stopCounter();
}
}
@Override
public void destroyLayer() {
}
@ -134,7 +155,7 @@ public class MapControlsLayer extends OsmandMapLayer {
routePlanningMode = true;
}
boolean routeFollowingMode = !routePlanningMode && rh.isFollowingMode();
boolean showDefaultButtons = !routeFollowingMode && !routePlanningMode;
boolean showDefaultButtons = !routePlanningMode && (!routeFollowingMode || settings.SHOW_ZOOM_BUTTONS_NAVIGATION.get());
if(routePlanningMode) {
forceHideView(zoomControls);
forceHideView(mapMenuControls);
@ -152,6 +173,7 @@ public class MapControlsLayer extends OsmandMapLayer {
checkVisibilityAndDraw(showRouteCalculationControls, mapInfoNavigationControl, canvas, tileBox, nightMode);
checkVisibilityAndDraw(showRouteCalculationControls, mapAppModeControl, canvas, tileBox, nightMode);
checkVisibilityAndDraw(showRouteCalculationControls, mapNavigationControl, canvas, tileBox, nightMode);
checkVisibilityAndDraw(showRouteCalculationControls, zoomSideControls, canvas, tileBox, nightMode);
// the last one to check other controls visibility
int vmargin = mapNavigationControl.isVisible() || zoomControls.isVisible() ? zoomControls.getHeight() : 0;
@ -188,13 +210,25 @@ public class MapControlsLayer extends OsmandMapLayer {
@Override
public boolean onSingleTap(PointF point, RotatedTileBox tileBox) {
for(MapControls m : allControls) {
if(m.isVisible() && m.onSingleTap(point, tileBox)){
return true;
}
}
return false;
}
@Override
public boolean onTouchEvent(MotionEvent event, RotatedTileBox tileBox) {
if(!mapActivity.getRoutingHelper().isRoutePlanningMode() && mapActivity.getRoutingHelper().isFollowingMode()) {
if(!settings.SHOW_ZOOM_BUTTONS_NAVIGATION.get()) {
zoomControls.showWithDelay((FrameLayout) mapActivity.getMapView().getParent(), TIMEOUT_TO_SHOW_BUTTONS);
mapMenuControls.showWithDelay((FrameLayout) mapActivity.getMapView().getParent(), TIMEOUT_TO_SHOW_BUTTONS);
}
mapRoutePlanControl.showWithDelay((FrameLayout) mapActivity.getMapView().getParent(), TIMEOUT_TO_SHOW_BUTTONS);
}
for(MapControls m : allControls) {
if(m.isVisible() && m.onSingleTap(point, tileBox)){
if(m.isVisible() && m.onTouchEvent(event, tileBox)){
return true;
}
}

View file

@ -25,6 +25,7 @@ public class MapCancelControl extends MapControls {
cancelButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
notifyClicked();
if(mapActivity.getRoutingHelper().isFollowingMode()) {
mapActivity.getMapActions().stopNavigationActionConfirm(mapActivity.getMapView());
} else {

View file

@ -9,6 +9,7 @@ import android.graphics.PointF;
import android.graphics.drawable.Drawable;
import android.os.Handler;
import android.view.Gravity;
import android.view.MotionEvent;
import android.view.View;
import android.widget.Button;
import android.widget.FrameLayout;
@ -29,6 +30,7 @@ public abstract class MapControls {
protected int vmargin;
protected int width;
protected int height;
protected Runnable notifyClick;
public MapControls(MapActivity mapActivity, Handler showUIHandler, float scaleCoefficient) {
this.mapActivity = mapActivity;
@ -66,6 +68,16 @@ public abstract class MapControls {
return button;
}
public void setNotifyClick(Runnable notifyClick) {
this.notifyClick = notifyClick;
}
protected void notifyClicked() {
if(notifyClick != null) {
notifyClick.run();
}
}
private void applyAttributes(Context ctx, FrameLayout parent, View button, int stringId, int resourceId,
int extraMargin) {
@ -154,6 +166,14 @@ public abstract class MapControls {
return visible;
}
protected boolean isLeft() {
return (Gravity.LEFT & gravity) == Gravity.LEFT;
}
protected boolean isBottom() {
return (Gravity.BOTTOM & gravity) == Gravity.BOTTOM;
}
protected void initControls(FrameLayout layout) {
}
@ -165,6 +185,11 @@ public abstract class MapControls {
public abstract void onDraw(Canvas canvas, RotatedTileBox tileBox, DrawSettings nightMode);
public boolean onTouchEvent(MotionEvent event, RotatedTileBox tileBox) {
return false;
}
public boolean onSingleTap(PointF point, RotatedTileBox tileBox) {
return false;
}

View file

@ -40,6 +40,7 @@ public class MapMenuControls extends MapControls {
// double lon = activity.getMapView().getLongitude();
// MainMenuActivity.backToMainMenuDialog(activity, new LatLon(lat, lon));
mapActivity.getMapActions().openOptionsMenuAsList();
notifyClicked();
}
});
}

View file

@ -4,7 +4,6 @@ import gnu.trove.list.array.TIntArrayList;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.atomic.AtomicInteger;
import net.osmand.data.RotatedTileBox;
import net.osmand.plus.OsmandApplication;
@ -12,8 +11,8 @@ import net.osmand.plus.OsmandSettings;
import net.osmand.plus.R;
import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.routing.RoutingHelper;
import net.osmand.plus.views.ShadowText;
import net.osmand.plus.views.OsmandMapLayer.DrawSettings;
import net.osmand.plus.views.ShadowText;
import android.app.AlertDialog;
import android.app.AlertDialog.Builder;
import android.content.DialogInterface;
@ -26,6 +25,7 @@ import android.graphics.Rect;
import android.graphics.drawable.Drawable;
import android.os.Handler;
import android.text.TextPaint;
import android.view.MotionEvent;
import android.view.View;
import android.widget.Button;
import android.widget.FrameLayout;
@ -38,7 +38,7 @@ public class MapNavigateControl extends MapControls {
private Bitmap mapMagnifier;
private TextPaint counterTextPaint;
private Paint bitmapPaint;
private static AtomicInteger startCounter = new AtomicInteger();
private static long startCounter = 0;
public MapNavigateControl(MapRouteInfoControl ri, MapActivity mapActivity, Handler showUIHandler, float scaleCoefficient) {
@ -53,25 +53,30 @@ public class MapNavigateControl extends MapControls {
public void startCounter() {
OsmandSettings settings = mapActivity.getMyApplication().getSettings();
startCounter.set(settings.DELAY_TO_START_NAVIGATION.get());
if (startCounter <= 0) {
startCounter = System.currentTimeMillis() + settings.DELAY_TO_START_NAVIGATION.get() * 1000;
delayStart = new Runnable() {
@Override
public void run() {
int cnt = startCounter.decrementAndGet();
if (cnt == 0) {
if (startCounter > 0) {
if (System.currentTimeMillis() > startCounter) {
startCounter = 0;
startNavigation();
} else if (cnt > 0)
} else {
mapActivity.refreshMap();
showUIHandler.postDelayed(delayStart, 1000);
}
}
}
};
if(startCounter.get() > 0) {
delayStart.run();
}
}
private void startNavigation() {
startCounter.set(-1);
stopCounter();
OsmandApplication app = mapActivity.getMyApplication();
RoutingHelper routingHelper = app.getRoutingHelper();
if(routingHelper.isFollowingMode()) {
@ -99,6 +104,7 @@ public class MapNavigateControl extends MapControls {
navigateButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
notifyClicked();
startNavigation();
}
});
@ -117,7 +123,7 @@ public class MapNavigateControl extends MapControls {
@Override
public void hideControls(FrameLayout layout) {
removeButton(layout, navigateButton);
startCounter.set(-1);
stopCounter();
}
@Override
@ -127,10 +133,15 @@ public class MapNavigateControl extends MapControls {
}
}
public boolean onTouchEvent(MotionEvent event, RotatedTileBox tileBox) {
stopCounter();
return false;
}
public boolean onSingleTap(PointF point, RotatedTileBox tileBox) {
startCounter.set(-1);
stopCounter();
if (navigateShadow.getBounds().contains((int) point.x, (int) point.y)) {
startCounter.set(-1);
openDialog();
return true;
}
@ -155,10 +166,10 @@ public class MapNavigateControl extends MapControls {
@Override
public void onClick(DialogInterface dialog, int which) {
notifyClicked();
dialog.dismiss();
mapActivity.getMyApplication().getSettings().DELAY_TO_START_NAVIGATION.set(opt.get(which));
startCounter();
}
});
bld.show();
@ -186,8 +197,8 @@ public class MapNavigateControl extends MapControls {
if(navigateShadow.getBounds().width() > 0) {
navigateShadow.draw(canvas);
}
int get = startCounter.get();
if (get > 0) {
if (startCounter > 0) {
int get = (int) ((startCounter -System.currentTimeMillis()) / 1000l);
final String text = get + "";
float length = counterTextPaint.measureText(text);
ShadowText.draw(text, canvas, navigateButton.getLeft() + (navigateButton.getWidth() - length - 2) / 2,
@ -208,4 +219,9 @@ public class MapNavigateControl extends MapControls {
}
return width ;
}
public void stopCounter() {
startCounter = 0;
}
}

View file

@ -90,6 +90,7 @@ public class MapRouteInfoControl extends MapControls implements IRouteInformatio
infoButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
notifyClicked();
if(dialog != null) {
hideDialog();
} else {

View file

@ -25,6 +25,7 @@ public class MapRoutePlanControl extends MapControls {
routePlanButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
notifyClicked();
mapActivity.getRoutingHelper().setRoutePlanningMode(true);
mapActivity.getMapViewTrackingUtilities().switchToRoutePlanningMode();
mapActivity.refreshMap();

View file

@ -119,6 +119,7 @@ public class MapRoutePreferencesControl extends MapControls {
@Override
public void onClick(View v) {
notifyClicked();
if(dialog != null) {
dialog.hide();
dialog = null;

View file

@ -68,11 +68,19 @@ public class MapZoomControls extends MapControls {
@Override
protected void showControls(FrameLayout parent) {
int minimumWidth = view.getResources().getDrawable(R.drawable.map_zoom_in).getMinimumWidth();
int minimumHeight = view.getResources().getDrawable(R.drawable.map_zoom_in).getMinimumWidth();
vmargin = 0;
zoomInButton = addButton(parent, R.string.zoomIn, R.drawable.map_zoom_in);
if(isBottom()) {
zoomOutButton = addButton(parent, R.string.zoomOut, R.drawable.map_zoom_out, minimumWidth);
} else {
vmargin = minimumHeight;
zoomOutButton = addButton(parent, R.string.zoomOut, R.drawable.map_zoom_out);
}
zoomInButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
notifyClicked();
if (view.isZooming()) {
mapActivity.changeZoom(2);
} else {
@ -86,6 +94,7 @@ public class MapZoomControls extends MapControls {
zoomOutButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
notifyClicked();
mapActivity.changeZoom(-1);
}
});
@ -94,7 +103,9 @@ public class MapZoomControls extends MapControls {
@Override
public void initControls(FrameLayout parent) {
if(isBottom()) {
zoomShadow = view.getResources().getDrawable(R.drawable.zoom_background).mutate();
}
mapMagnifier = BitmapFactory.decodeResource(view.getResources(), R.drawable.map_magnifier);
bitmapPaint = new Paint();
}
@ -147,7 +158,7 @@ public class MapZoomControls extends MapControls {
if (zoomOutButton.isEnabled() != zoomOutEnabled) {
zoomOutButton.setEnabled(zoomOutEnabled);
}
if (isBottom()) {
if (view.isZooming()) {
showZoomLevel = true;
showZoomLevelButton = false;
@ -163,6 +174,7 @@ public class MapZoomControls extends MapControls {
drawZoomLevel(canvas, tileBox, !showZoomLevelButton);
}
}
}
private void sendMessageToShowZoomLevel() {
Message msg = Message.obtain(showUIHandler, new Runnable() {

View file

@ -25,6 +25,7 @@ public class SmallMapMenuControls extends MapControls {
backToMenuButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
notifyClicked();
mapActivity.getMapActions().openOptionsMenuAsList();
}
});