From 86bbdabb4c6372a0351a38f9666299ac69704bc0 Mon Sep 17 00:00:00 2001 From: Victor Shcherb Date: Thu, 12 Mar 2015 00:35:13 +0100 Subject: [PATCH] Update buttons --- OsmAnd/res/drawable/btn_circle_blue.xml | 2 +- OsmAnd/res/values/colors.xml | 7 +- OsmAnd/res/values/sizes.xml | 2 +- .../osmand/plus/OsmAndAppCustomization.java | 1 - .../plus/sherpafy/SherpafyCustomization.java | 4 - .../osmand/plus/views/MapControlsLayer.java | 310 +++++++----------- .../views/controls/MapRouteInfoControl.java | 76 ++--- .../controls/MapRoutePreferencesControl.java | 268 +++++++-------- 8 files changed, 272 insertions(+), 398 deletions(-) diff --git a/OsmAnd/res/drawable/btn_circle_blue.xml b/OsmAnd/res/drawable/btn_circle_blue.xml index 12d1edcf49..34a59dea72 100644 --- a/OsmAnd/res/drawable/btn_circle_blue.xml +++ b/OsmAnd/res/drawable/btn_circle_blue.xml @@ -2,7 +2,7 @@ - + diff --git a/OsmAnd/res/values/colors.xml b/OsmAnd/res/values/colors.xml index 0cf6f87e4d..ce5ae7fab0 100644 --- a/OsmAnd/res/values/colors.xml +++ b/OsmAnd/res/values/colors.xml @@ -11,11 +11,12 @@ #be39464d #333333 - #aaffffff + #eeffffff #aa3f3f3f - #eeffffff + #88ffffff #ddcccccc - #3030FF + #30A0FF + #dd30D0FF #39464d diff --git a/OsmAnd/res/values/sizes.xml b/OsmAnd/res/values/sizes.xml index fa4725999a..67d0ead6e5 100644 --- a/OsmAnd/res/values/sizes.xml +++ b/OsmAnd/res/values/sizes.xml @@ -55,7 +55,7 @@ 24dp 32dp 80dp - 20dp + 18dp 4dp 4dp 3dp diff --git a/OsmAnd/src/net/osmand/plus/OsmAndAppCustomization.java b/OsmAnd/src/net/osmand/plus/OsmAndAppCustomization.java index b96c5e4845..a4e72b8ce6 100644 --- a/OsmAnd/src/net/osmand/plus/OsmAndAppCustomization.java +++ b/OsmAnd/src/net/osmand/plus/OsmAndAppCustomization.java @@ -151,7 +151,6 @@ public class OsmAndAppCustomization { return osmandSettings.getExternalStorageDirectory(); } - public boolean showNavigationControls() { return true;} public boolean onlyTourDownload() { return false; diff --git a/OsmAnd/src/net/osmand/plus/sherpafy/SherpafyCustomization.java b/OsmAnd/src/net/osmand/plus/sherpafy/SherpafyCustomization.java index 6e2ca75ffb..739a99438b 100644 --- a/OsmAnd/src/net/osmand/plus/sherpafy/SherpafyCustomization.java +++ b/OsmAnd/src/net/osmand/plus/sherpafy/SherpafyCustomization.java @@ -739,9 +739,5 @@ public class SherpafyCustomization extends OsmAndAppCustomization { a.startActivityForResult(newIntent, 0); } - @Override - public boolean showNavigationControls() { - return false; - } } diff --git a/OsmAnd/src/net/osmand/plus/views/MapControlsLayer.java b/OsmAnd/src/net/osmand/plus/views/MapControlsLayer.java index f96b6a3e9a..2a85bdfb88 100644 --- a/OsmAnd/src/net/osmand/plus/views/MapControlsLayer.java +++ b/OsmAnd/src/net/osmand/plus/views/MapControlsLayer.java @@ -48,7 +48,7 @@ import android.widget.SeekBar; public class MapControlsLayer extends OsmandMapLayer { private static final int TIMEOUT_TO_SHOW_BUTTONS = 5000; - private static class MapControl { + private static class MapHudButton { ImageView iv; int bgDark; int bgLight; @@ -60,12 +60,12 @@ public class MapControlsLayer extends OsmandMapLayer { boolean f = true; - public MapControl setRoundTransparent() { + public MapHudButton setRoundTransparent() { setBg(R.drawable.btn_circle_trans); return this; } - public MapControl setBg(int dayBg, int nightBg) { + public MapHudButton setBg(int dayBg, int nightBg) { bgDark = nightBg; bgLight = dayBg; f = true; @@ -73,15 +73,15 @@ public class MapControlsLayer extends OsmandMapLayer { } - public MapControl setBg(int bg) { + public MapHudButton setBg(int bg) { bgDark = bg; bgLight = bg; f = true; return this; } - public static MapControl create(ImageView iv, int resId) { - MapControl mc = new MapControl(); + public static MapHudButton create(ImageView iv, int resId) { + MapHudButton mc = new MapHudButton(); mc.iv = iv; mc.resId = resId; mc.setBg(R.drawable.btn_circle); @@ -113,7 +113,9 @@ public class MapControlsLayer extends OsmandMapLayer { } f = false; nightMode = night; - iv.setBackgroundDrawable(ctx.getResources().getDrawable(night ? bgDark : bgLight)); + if(bgDark != 0 && bgLight != 0) { + iv.setBackgroundDrawable(ctx.getResources().getDrawable(night ? bgDark : bgLight)); + } iv.setImageDrawable(ctx.getIconsCache().getIcon(resId, nightMode ? resDark : resLight)); } @@ -121,25 +123,11 @@ public class MapControlsLayer extends OsmandMapLayer { } - - private List controls = new ArrayList(); - - + private List controls = new ArrayList(); private final MapActivity mapActivity; private int shadowColor = -1; - - private MapZoomControls zoomControls; - private MapZoomControls zoomSideControls; - private MapMenuControls mapMenuControls; - private RulerControl rulerControl; - - private SmallMapMenuControls mapSmallMenuControls; - private MapCancelControl mapCancelNavigationControl; - private MapRouteInfoControl mapInfoNavigationControl; - private MapNavigateControl mapNavigationControl; - private MapRoutePlanControl mapRoutePlanControl; - private MapRoutePreferencesControl mapAppModeControl; - private List allControls = new ArrayList(); +// private RulerControl rulerControl; +// private List allControls = new ArrayList(); private float scaleCoefficient; @@ -148,11 +136,14 @@ public class MapControlsLayer extends OsmandMapLayer { private static CommonPreference settingsToTransparency; private OsmandSettings settings; - - private MapControl backToLocationControl; + private MapHudButton backToLocationControl; + private MapHudButton menuControl; + private View routePreparationLayout; + private MapRouteInfoControl mapRouteInfoControl; + private MapHudButton optionsRouteControl; - private MapControl menuControl; + private MapRoutePreferencesControl optionsRouteControlDialog; public MapControlsLayer(MapActivity activity){ @@ -173,62 +164,69 @@ public class MapControlsLayer extends OsmandMapLayer { public void initLayer(final OsmandMapTileView view) { scaleCoefficient = view.getScaleCoefficient(); FrameLayout parent = getParent(); - Handler showUIHandler = new Handler(); - int rightGravity = Gravity.RIGHT | Gravity.BOTTOM; - int leftGravity = Gravity.LEFT | Gravity.BOTTOM; - int rightCenterGravity = Gravity.RIGHT | Gravity.CENTER; - int leftCenterGravity = Gravity.LEFT | Gravity.CENTER; - - initNewControls(); - // default buttons - zoomControls = init(new MapZoomControls(mapActivity, showUIHandler, scaleCoefficient), parent, - rightGravity); - if (ScreenOrientationHelper.getScreenOrientation(mapActivity) == 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); - // calculate route buttons - mapSmallMenuControls = init(new SmallMapMenuControls(mapActivity, showUIHandler, scaleCoefficient), parent, - leftGravity); - mapCancelNavigationControl = init(new MapCancelControl(mapActivity, showUIHandler, scaleCoefficient), parent, - leftGravity); - mapInfoNavigationControl = init(new MapRouteInfoControl(mapActivity.getMapLayers().getContextMenuLayer(), - mapActivity, showUIHandler, scaleCoefficient), parent, - leftGravity); - mapNavigationControl = init(new MapNavigateControl(mapInfoNavigationControl, mapActivity, showUIHandler, scaleCoefficient), parent, - rightGravity); - mapAppModeControl = init(new MapRoutePreferencesControl(mapActivity, showUIHandler, scaleCoefficient), parent, - rightGravity); - - rulerControl = init(new RulerControl(zoomControls, mapActivity, showUIHandler, scaleCoefficient), parent, - rightGravity); + // TODO +// rulerControl = init(new RulerControl(zoomControls, mapActivity, showUIHandler, scaleCoefficient), parent, +// rightGravity); initTransparencyBar(view, parent); - - mapRoutePlanControl.setMargin(mapMenuControls.getWidth()); - mapCancelNavigationControl.setMargin(mapSmallMenuControls.getWidth()); - mapInfoNavigationControl.setMargin(mapSmallMenuControls.getWidth() + mapCancelNavigationControl.getWidth()); - mapAppModeControl.setMargin(mapNavigationControl.getWidth()); - - ; } private void initNewControls() { initZooms(); initControls(); + initRouteControls(); } + + private void initRouteControls() { + routePreparationLayout = mapActivity.findViewById(R.id.map_route_preparation_layout); + View cancelRouteButton = mapActivity.findViewById(R.id.map_cancel_route_button); + controls.add(MapHudButton.create((ImageView) cancelRouteButton, R.drawable.ic_action_remove_dark)); + + cancelRouteButton.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + notifyClicked(); + if(mapActivity.getRoutingHelper().isFollowingMode()) { + mapActivity.getMapActions().stopNavigationActionConfirm(mapActivity.getMapView()); + } else { + mapActivity.getMapActions().stopNavigationWithoutConfirm(); + } + } + }); + mapRouteInfoControl = new MapRouteInfoControl(mapActivity.getMapLayers().getContextMenuLayer(), + mapActivity); + + View waypointsButton = mapActivity.findViewById(R.id.map_waypoints_route_button); + controls.add(MapHudButton.create((ImageView) waypointsButton, R.drawable.ic_action_flage_dark)); + waypointsButton.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + notifyClicked(); + mapRouteInfoControl.showHideDialog(); + } + }); + + View optionsRouteButton = mapActivity.findViewById(R.id.map_options_route_button); + optionsRouteControl = MapHudButton.create((ImageView) optionsRouteButton, settings.getApplicationMode().getSmallIcon(false)); + optionsRouteControlDialog = new MapRoutePreferencesControl(mapActivity); + controls.add(optionsRouteControl); + optionsRouteButton.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + notifyClicked(); + optionsRouteControlDialog.showAndHideDialog(); + } + }); + } + + public void showDialog(){ + mapRouteInfoControl.setShowDialog(); + } private void initControls() { View backToLocation = mapActivity.findViewById(R.id.map_my_location_button); - backToLocationControl = MapControl.create((ImageView) backToLocation, R.drawable.ic_action_get_my_location).setBg(R.drawable.btn_circle_blue) + backToLocationControl = MapHudButton.create((ImageView) backToLocation, R.drawable.ic_action_get_my_location).setBg(R.drawable.btn_circle_blue) ; controls.add(backToLocationControl); @@ -240,7 +238,7 @@ public class MapControlsLayer extends OsmandMapLayer { }); View backToMenuButton = mapActivity.findViewById(R.id.map_menu_button); - menuControl = MapControl.create((ImageView) backToMenuButton, R.drawable.ic_navigation_drawer). + menuControl = MapHudButton.create((ImageView) backToMenuButton, R.drawable.ic_navigation_drawer). setBg(R.drawable.btn_round, R.drawable.btn_round_night); controls.add(menuControl); backToMenuButton.setOnClickListener(new View.OnClickListener() { @@ -260,7 +258,7 @@ public class MapControlsLayer extends OsmandMapLayer { }); View routePlanButton = mapActivity.findViewById(R.id.map_route_info_button); - controls.add(MapControl.create((ImageView) routePlanButton, R.drawable.ic_action_info_dark). + controls.add(MapHudButton.create((ImageView) routePlanButton, R.drawable.ic_action_info_dark). setBg(R.drawable.btn_round, R.drawable.btn_round_night)); routePlanButton.setOnClickListener(new View.OnClickListener() { @Override @@ -277,7 +275,7 @@ public class MapControlsLayer extends OsmandMapLayer { private void initZooms() { final OsmandMapTileView view = mapActivity.getMapView(); View zoomInButton = mapActivity.findViewById(R.id.map_zoom_in_button); - controls.add(MapControl.create((ImageView) zoomInButton, R.drawable.ic_action_zoom_in).setRoundTransparent() + controls.add(MapHudButton.create((ImageView) zoomInButton, R.drawable.ic_action_zoom_in).setRoundTransparent() ); zoomInButton.setOnClickListener(new View.OnClickListener() { @Override @@ -294,7 +292,7 @@ public class MapControlsLayer extends OsmandMapLayer { final View.OnLongClickListener listener = MapZoomControls.getOnClickMagnifierListener(view); zoomInButton.setOnLongClickListener(listener); View zoomOutButton = mapActivity.findViewById(R.id.map_zoom_out_button); - controls.add(MapControl.create((ImageView) zoomOutButton, R.drawable.ic_action_zoom_out).setRoundTransparent() + controls.add(MapHudButton.create((ImageView) zoomOutButton, R.drawable.ic_action_zoom_out).setRoundTransparent() ); zoomOutButton.setOnClickListener(new View.OnClickListener() { @Override @@ -308,35 +306,25 @@ public class MapControlsLayer extends OsmandMapLayer { public void startNavigation() { - if (mapNavigationControl == null) { - return; - } - mapNavigationControl.startNavigation(); + // TODO +// if (mapNavigationControl == null) { +// return; +// } +// mapNavigationControl.startNavigation(); } - private 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) { notifyClicked(); } protected void notifyClicked() { - if(mapNavigationControl != null) { - mapNavigationControl.stopCounter(); - } + // TODO +// if(mapNavigationControl != null) { +// mapNavigationControl.stopCounter(); +// } } @Override @@ -348,50 +336,26 @@ public class MapControlsLayer extends OsmandMapLayer { public void onDraw(Canvas canvas, RotatedTileBox tileBox, DrawSettings nightMode) { boolean isNight = nightMode != null && nightMode.isNightMode(); int shadw = isNight ? Color.TRANSPARENT : Color.WHITE; - int textColor = isNight ? mapActivity.getResources().getColor(R.color.widgettext_night) : Color.BLACK ; - if(shadowColor != shadw) { + int textColor = isNight ? mapActivity.getResources().getColor(R.color.widgettext_night) : Color.BLACK; + if (shadowColor != shadw) { shadowColor = shadw; - updatextColor(textColor, shadw, rulerControl, zoomControls, mapMenuControls); + // TODO +// updatextColor(textColor, shadw, rulerControl, zoomControls, mapMenuControls); } // default buttons boolean routePlanningMode = false; RoutingHelper rh = mapActivity.getRoutingHelper(); - if(rh.isRoutePlanningMode() ) { + if (rh.isRoutePlanningMode()) { routePlanningMode = true; - } else if((rh.isRouteCalculated() || rh.isRouteBeingCalculated()) && - !rh.isFollowingMode()){ + } else if ((rh.isRouteCalculated() || rh.isRouteBeingCalculated()) && !rh.isFollowingMode()) { routePlanningMode = true; } boolean routeFollowingMode = !routePlanningMode && rh.isFollowingMode(); - boolean showDefaultButtons = !routePlanningMode && (!routeFollowingMode || settings.SHOW_ZOOM_BUTTONS_NAVIGATION.get()); - if(routePlanningMode) { - forceHideView(zoomControls); - forceHideView(mapMenuControls); - forceHideView(mapRoutePlanControl); - } - checkVisibilityAndDraw(showDefaultButtons, zoomControls, canvas, tileBox, nightMode); - checkVisibilityAndDraw(showDefaultButtons, mapMenuControls, canvas, tileBox, nightMode); - // show only on touch - checkVisibilityAndDraw(false, mapRoutePlanControl, canvas, tileBox, nightMode); - - // route calculation buttons boolean showRouteCalculationControls = routePlanningMode; - boolean showNavigationControls = mapActivity.getMyApplication().getAppCustomization().showNavigationControls(); - checkVisibilityAndDraw(showRouteCalculationControls, mapSmallMenuControls, canvas, tileBox, nightMode); - checkVisibilityAndDraw(showNavigationControls && showRouteCalculationControls, mapCancelNavigationControl, canvas, tileBox, nightMode); - checkVisibilityAndDraw(showNavigationControls && showRouteCalculationControls, mapInfoNavigationControl, canvas, tileBox, nightMode); - checkVisibilityAndDraw(showNavigationControls && 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() + zoomControls.getTotalVerticalMargin()) : 0; - rulerControl.setVerticalMargin(vmargin); - checkVisibilityAndDraw(true, rulerControl, canvas, tileBox, nightMode); - - - /////////////////////////////////////////////// + + boolean showDefaultButtons = !routePlanningMode + && (!routeFollowingMode || settings.SHOW_ZOOM_BUTTONS_NAVIGATION.get()); + // ///////////////////////////////////////////// // new update boolean enabled = mapActivity.getMyApplication().getLocationProvider().getLastKnownLocation() != null; boolean tracked = mapActivity.getMapViewTrackingUtilities().isMapLinkedToLocation(); @@ -402,14 +366,19 @@ public class MapControlsLayer extends OsmandMapLayer { } else { backToLocationControl.setIconColorId(R.color.color_white); } - menuControl.setIconResId(mapActivity.getMyApplication().getSettings().USE_DASHBOARD_INSTEAD_OF_DRAWER.get() ? - R.drawable.ic_dashboard_dark : R.drawable.ic_navigation_drawer); - - for(MapControl mc : controls) { - mc.update(mapActivity.getMyApplication(), - nightMode == null ? false : nightMode.isNightMode()); + menuControl.setIconResId(mapActivity.getMyApplication().getSettings().USE_DASHBOARD_INSTEAD_OF_DRAWER.get() ? R.drawable.ic_dashboard_dark + : R.drawable.ic_navigation_drawer); + optionsRouteControl.setIconResId(settings.getApplicationMode().getSmallIcon(false)); + int vis = showRouteCalculationControls? View.VISIBLE : View.GONE; + if(routePreparationLayout.getVisibility() != vis) { + routePreparationLayout.setVisibility(vis); + mapRouteInfoControl.setVisible(showRouteCalculationControls); } - + + for (MapHudButton mc : controls) { + mc.update(mapActivity.getMyApplication(), nightMode == null ? false : nightMode.isNightMode()); + } + } @@ -419,57 +388,32 @@ public class MapControlsLayer extends OsmandMapLayer { m.updateTextColor(textColor, shadowColor); } } - - private void checkVisibilityAndDraw(boolean visibility, MapControls controls, Canvas canvas, - RotatedTileBox tileBox, DrawSettings nightMode) { - if(visibility != controls.isVisible() ){ - if(visibility) { - controls.show(getParent()); - } else { - controls.hide(getParent()); - } - } - if(controls.isVisible()) { - // FIXME -// controls.onDraw(canvas, tileBox, nightMode); - } - } - private FrameLayout getParent() { return (FrameLayout) mapActivity.findViewById(R.id.MapButtons); } - private void forceHideView(MapControls controls) { - if (controls.isVisible()) { - controls.forceHide(getParent()); - } - } - @Override public boolean onSingleTap(PointF point, RotatedTileBox tileBox) { - for(MapControls m : allControls) { - if(m.isVisible() && m.onSingleTap(point, tileBox)){ - return true; - } - } + // TODO stop counter & show buttons +// 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(getParent(), TIMEOUT_TO_SHOW_BUTTONS); - mapMenuControls.showWithDelay(getParent(), TIMEOUT_TO_SHOW_BUTTONS); - } - mapRoutePlanControl.showWithDelay(getParent(), TIMEOUT_TO_SHOW_BUTTONS); - } - for(MapControls m : allControls) { - if(m.isVisible() && m.onTouchEvent(event, tileBox)){ - return true; - } - } + // TODO stop counter & show buttons +// if(!mapActivity.getRoutingHelper().isRoutePlanningMode() && mapActivity.getRoutingHelper().isFollowingMode()) { +// if(!settings.SHOW_ZOOM_BUTTONS_NAVIGATION.get()) { +// zoomControls.showWithDelay(getParent(), TIMEOUT_TO_SHOW_BUTTONS); +// mapMenuControls.showWithDelay(getParent(), TIMEOUT_TO_SHOW_BUTTONS); +// } +// mapRoutePlanControl.showWithDelay(getParent(), TIMEOUT_TO_SHOW_BUTTONS); +// } return false; } @@ -539,22 +483,10 @@ public class MapControlsLayer extends OsmandMapLayer { } public void shiftLayout(int height) { - FrameLayout parent = getParent(); - parent.requestLayout(); - for(MapControls mc : allControls) { - if(mc.isBottom()){ - mc.setExtraVerticalMargin(height); - if( mc.isVisible()) { - mc.forceHide(parent); - mc.show(parent); - } - } - } + // TODO } - public void showDialog(){ - mapInfoNavigationControl.setShowDialog(); - } + } diff --git a/OsmAnd/src/net/osmand/plus/views/controls/MapRouteInfoControl.java b/OsmAnd/src/net/osmand/plus/views/controls/MapRouteInfoControl.java index abf04a4ec9..b8482ffd0a 100644 --- a/OsmAnd/src/net/osmand/plus/views/controls/MapRouteInfoControl.java +++ b/OsmAnd/src/net/osmand/plus/views/controls/MapRouteInfoControl.java @@ -31,7 +31,6 @@ import android.content.Intent; 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.Window; @@ -45,11 +44,9 @@ import android.widget.ListView; import android.widget.Spinner; import android.widget.TextView; -public class MapRouteInfoControl extends MapControls implements IRouteInformationListener { - private Button infoButton; +public class MapRouteInfoControl implements IRouteInformationListener { public static int directionInfo = -1; public static boolean controlVisible = false; - private final ContextMenuLayer contextMenu; private final RoutingHelper routingHelper; private OsmandMapTileView mapView; @@ -59,17 +56,17 @@ public class MapRouteInfoControl extends MapControls implements IRouteInformatio private boolean selectFromMapForTarget; private boolean showDialog = false; + private MapActivity mapActivity; public MapRouteInfoControl(ContextMenuLayer contextMenu, - MapActivity mapActivity, Handler showUIHandler, float scaleCoefficient) { - super(mapActivity, showUIHandler, scaleCoefficient); + MapActivity mapActivity) { this.contextMenu = contextMenu; + this.mapActivity = mapActivity; routingHelper = mapActivity.getRoutingHelper(); mapView = mapActivity.getMapView(); routingHelper.addListener(this); } - @Override public boolean onSingleTap(PointF point, RotatedTileBox tileBox) { if(selectFromMapTouch) { LatLon latlon = tileBox.getLatLonFromPixel(point.x, point.y); @@ -83,30 +80,31 @@ public class MapRouteInfoControl extends MapControls implements IRouteInformatio showDialog(); return true; } - return super.onSingleTap(point, tileBox); + return false; } - @Override - public void showControls(FrameLayout parent) { - infoButton = addButton(parent, R.string.route_info, R.drawable.map_btn_signpost); - if (showDialog){ - if (getTargets().getPointToNavigate() == null){ - showDialog(); - } - showDialog = false; - } - controlVisible = true; - infoButton.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - notifyClicked(); - if(dialog != null) { - hideDialog(); - } else { + public void setVisible(boolean visible) { + if(visible) { + if (showDialog){ + if (getTargets().getPointToNavigate() == null){ showDialog(); } + showDialog = false; } - }); + controlVisible = true; + } else { + hideDialog(); + controlVisible = false; + } + } + + + public void showHideDialog() { + if(dialog != null) { + hideDialog(); + } else { + showDialog(); + } } private Dialog createDialog() { @@ -137,7 +135,8 @@ public class MapRouteInfoControl extends MapControls implements IRouteInformatio lp.width = WindowManager.LayoutParams.WRAP_CONTENT; lp.height = WindowManager.LayoutParams.WRAP_CONTENT; lp.gravity = Gravity.BOTTOM; - lp.y = (int) (infoButton.getBottom() - infoButton.getTop() + scaleCoefficient * 5 + getExtraVerticalMargin()); + // TODO +// lp.y = (int) (infoButton.getBottom() - infoButton.getTop() + scaleCoefficient * 5 + getExtraVerticalMargin()); dialog.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND); dialog.getWindow().requestFeature(Window.FEATURE_NO_TITLE); dialog.getWindow().setAttributes(lp); @@ -253,26 +252,6 @@ public class MapRouteInfoControl extends MapControls implements IRouteInformatio return controlVisible; } - @Override - public void hideControls(FrameLayout layout) { - removeButton(layout, infoButton); - hideDialog(); - controlVisible = false; - } - - @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 ; - } - - private void attachListeners(final View mainView) { final OsmandApplication ctx = mapActivity.getMyApplication(); final Button simulateRoute = (Button) mainView.findViewById(R.id.SimulateRoute); @@ -449,11 +428,9 @@ public class MapRouteInfoControl extends MapControls implements IRouteInformatio public void showDialog() { dialog = createDialog(); dialog.show(); - infoButton.setBackgroundResource(R.drawable.map_btn_signpost_p); dialog.setOnDismissListener(new OnDismissListener() { @Override public void onDismiss(DialogInterface dlg) { - infoButton.setBackgroundResource(R.drawable.map_btn_signpost); dialog = null; } }); @@ -463,7 +440,6 @@ public class MapRouteInfoControl extends MapControls implements IRouteInformatio if (dialog != null) { dialog.hide(); dialog = null; - infoButton.setBackgroundResource(R.drawable.map_btn_signpost); } } diff --git a/OsmAnd/src/net/osmand/plus/views/controls/MapRoutePreferencesControl.java b/OsmAnd/src/net/osmand/plus/views/controls/MapRoutePreferencesControl.java index 400e58aebb..712f96e2dc 100644 --- a/OsmAnd/src/net/osmand/plus/views/controls/MapRoutePreferencesControl.java +++ b/OsmAnd/src/net/osmand/plus/views/controls/MapRoutePreferencesControl.java @@ -9,14 +9,13 @@ import java.util.Set; import net.osmand.CallbackWithObject; import net.osmand.Location; import net.osmand.data.LatLon; -import net.osmand.data.RotatedTileBox; import net.osmand.plus.ApplicationMode; import net.osmand.plus.GPXUtilities; -import net.osmand.plus.TargetPointsHelper; import net.osmand.plus.GPXUtilities.GPXFile; import net.osmand.plus.OsmandSettings; import net.osmand.plus.OsmandSettings.CommonPreference; import net.osmand.plus.R; +import net.osmand.plus.TargetPointsHelper; import net.osmand.plus.TargetPointsHelper.TargetPoint; import net.osmand.plus.activities.MapActivity; import net.osmand.plus.activities.SettingsBaseActivity; @@ -25,7 +24,6 @@ import net.osmand.plus.activities.actions.AppModeDialog; import net.osmand.plus.helpers.GpxUiHelper; import net.osmand.plus.routing.RouteProvider.GPXRouteParamsBuilder; import net.osmand.plus.routing.RouteProvider.RouteService; -import net.osmand.plus.views.OsmandMapLayer.DrawSettings; import net.osmand.router.GeneralRouter; import net.osmand.router.GeneralRouter.RoutingParameter; import net.osmand.router.GeneralRouter.RoutingParameterType; @@ -35,8 +33,6 @@ import android.app.Dialog; import android.content.Context; import android.content.DialogInterface; import android.content.DialogInterface.OnDismissListener; -import android.graphics.Canvas; -import android.os.Handler; import android.view.Gravity; import android.view.View; import android.view.ViewGroup; @@ -47,120 +43,107 @@ import android.widget.ArrayAdapter; import android.widget.CheckBox; import android.widget.CompoundButton; import android.widget.CompoundButton.OnCheckedChangeListener; -import android.widget.FrameLayout; -import android.widget.ImageButton; import android.widget.ListView; import android.widget.Spinner; import android.widget.TextView; -public class MapRoutePreferencesControl extends MapControls { - private ImageButton settingsAppModeButton; +public class MapRoutePreferencesControl { private OsmandSettings settings; - private int cachedId; private Dialog dialog; private ArrayAdapter listAdapter; - - public MapRoutePreferencesControl(MapActivity mapActivity, Handler showUIHandler, float scaleCoefficient) { - super(mapActivity, showUIHandler, scaleCoefficient); + private MapActivity mapActivity; + + public MapRoutePreferencesControl(MapActivity mapActivity) { + this.mapActivity = mapActivity; settings = mapActivity.getMyApplication().getSettings(); } - + private static class LocalRoutingParameter { - + public RoutingParameter routingParameter; public String getText(MapActivity mapActivity) { - return SettingsBaseActivity.getRoutingStringPropertyName(mapActivity, routingParameter.getId(), routingParameter.getName()); + return SettingsBaseActivity.getRoutingStringPropertyName(mapActivity, routingParameter.getId(), + routingParameter.getName()); } public boolean isSelected(OsmandSettings settings) { - final CommonPreference property = settings.getCustomRoutingBooleanProperty(routingParameter.getId()); + final CommonPreference property = settings.getCustomRoutingBooleanProperty(routingParameter + .getId()); return property.get(); } public void setSelected(OsmandSettings settings, boolean isChecked) { - final CommonPreference property = settings.getCustomRoutingBooleanProperty(routingParameter.getId()); - property.set(isChecked); + final CommonPreference property = settings.getCustomRoutingBooleanProperty(routingParameter + .getId()); + property.set(isChecked); } - + } - + private static class OtherLocalRoutingParameter extends LocalRoutingParameter { public String text; public boolean selected; public int id; - + public OtherLocalRoutingParameter(int id, String text, boolean selected) { this.text = text; this.selected = selected; this.id = id; } - + @Override public String getText(MapActivity mapActivity) { return text; } - + @Override public boolean isSelected(OsmandSettings settings) { return selected; } - + @Override public void setSelected(OsmandSettings settings, boolean isChecked) { selected = isChecked; } } - - @Override - public void showControls(FrameLayout parent) { - settingsAppModeButton = addImageButton(parent, R.string.route_preferences, R.drawable.map_btn_plain); - cachedId = 0; - settingsAppModeButton.setOnClickListener(new View.OnClickListener() { - - @Override - public void onClick(View v) { - notifyClicked(); - if(dialog != null) { - dialog.hide(); + + public void showAndHideDialog() { + if (dialog != null) { + dialog.hide(); + dialog = null; + } else { + dialog = showDialog(); + dialog.show(); + dialog.setOnDismissListener(new OnDismissListener() { + @Override + public void onDismiss(DialogInterface dlg) { dialog = null; - settingsAppModeButton.setBackgroundResource(R.drawable.map_btn_plain); - } else { - dialog = showDialog(); - dialog.show(); - settingsAppModeButton.setBackgroundResource(R.drawable.map_btn_plain_p); - dialog.setOnDismissListener(new OnDismissListener() { - @Override - public void onDismiss(DialogInterface dlg) { - settingsAppModeButton.setBackgroundResource(R.drawable.map_btn_plain); - dialog = null; - } - }); } - } - }); + }); + } } - + private Dialog showDialog() { - AlertDialog.Builder builder = new AlertDialog.Builder(mapActivity); - View ll = createLayout(); - builder.setView(ll); - //builder.setTitle(R.string.route_preferences); - Dialog dialog = builder.create(); - dialog.setCanceledOnTouchOutside(true); - WindowManager.LayoutParams lp = new WindowManager.LayoutParams(); - lp.copyFrom(dialog.getWindow().getAttributes()); - lp.width = WindowManager.LayoutParams.WRAP_CONTENT; - lp.height = WindowManager.LayoutParams.WRAP_CONTENT; - lp.gravity = Gravity.BOTTOM; - lp.y = (int) (settingsAppModeButton.getBottom() - settingsAppModeButton.getTop() + scaleCoefficient * 5); - dialog.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND); - dialog.getWindow().requestFeature(Window.FEATURE_NO_TITLE); - dialog.getWindow().setAttributes(lp); - return dialog; + AlertDialog.Builder builder = new AlertDialog.Builder(mapActivity); + View ll = createLayout(); + builder.setView(ll); + // builder.setTitle(R.string.route_preferences); + Dialog dialog = builder.create(); + dialog.setCanceledOnTouchOutside(true); + WindowManager.LayoutParams lp = new WindowManager.LayoutParams(); + lp.copyFrom(dialog.getWindow().getAttributes()); + lp.width = WindowManager.LayoutParams.WRAP_CONTENT; + lp.height = WindowManager.LayoutParams.WRAP_CONTENT; + lp.gravity = Gravity.BOTTOM; + // TODO +// lp.y = (int) (settingsAppModeButton.getBottom() - settingsAppModeButton.getTop() + scaleCoefficient * 5); + dialog.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND); + dialog.getWindow().requestFeature(Window.FEATURE_NO_TITLE); + dialog.getWindow().setAttributes(lp); + return dialog; } - - + private void updateGpxRoutingParameter(OtherLocalRoutingParameter gpxParam) { GPXRouteParamsBuilder rp = mapActivity.getRoutingHelper().getCurrentGPXRoute(); boolean selected = gpxParam.isSelected(settings); @@ -174,17 +157,18 @@ public class MapRoutePreferencesControl extends MapControls { Location end = ps.get(ps.size() - 1); TargetPoint pn = tg.getPointToNavigate(); boolean update = false; - if (pn == null || - MapUtils.getDistance(pn.point, new LatLon(first.getLatitude(), first.getLongitude())) < 10) { + if (pn == null + || MapUtils.getDistance(pn.point, new LatLon(first.getLatitude(), first.getLongitude())) < 10) { tg.navigateToPoint(new LatLon(end.getLatitude(), end.getLongitude()), false, -1); update = true; } - if (tg.getPointToStart() == null || - MapUtils.getDistance(tg.getPointToStart().point, new LatLon(end.getLatitude(), end.getLongitude())) < 10) { + if (tg.getPointToStart() == null + || MapUtils.getDistance(tg.getPointToStart().point, + new LatLon(end.getLatitude(), end.getLongitude())) < 10) { tg.setStartPoint(new LatLon(first.getLatitude(), first.getLongitude()), false, null); update = true; } - if(update) { + if (update) { tg.updateRouteAndReferesh(true); } } @@ -208,45 +192,47 @@ public class MapRoutePreferencesControl extends MapControls { if (gpxParam.id == R.string.fast_route_mode) { settings.FAST_ROUTE_MODE.set(selected); } - if (gpxParam.id == R.string.speak_favorites){ + if (gpxParam.id == R.string.speak_favorites) { settings.ANNOUNCE_NEARBY_FAVORITES.set(selected); } } - private List getRoutingParameters(ApplicationMode am) { List list = new ArrayList(); GPXRouteParamsBuilder rparams = mapActivity.getRoutingHelper().getCurrentGPXRoute(); - boolean osmandRouter = settings.ROUTER_SERVICE.get() == RouteService.OSMAND ; - if(!osmandRouter) { - list.add(new OtherLocalRoutingParameter(R.string.calculate_osmand_route_without_internet, - getString(R.string.calculate_osmand_route_without_internet), settings.GPX_ROUTE_CALC_OSMAND_PARTS.get())); - list.add(new OtherLocalRoutingParameter(R.string.fast_route_mode, - getString(R.string.fast_route_mode), settings.FAST_ROUTE_MODE.get())); + boolean osmandRouter = settings.ROUTER_SERVICE.get() == RouteService.OSMAND; + if (!osmandRouter) { + list.add(new OtherLocalRoutingParameter(R.string.calculate_osmand_route_without_internet, + getString(R.string.calculate_osmand_route_without_internet), settings.GPX_ROUTE_CALC_OSMAND_PARTS + .get())); + list.add(new OtherLocalRoutingParameter(R.string.fast_route_mode, getString(R.string.fast_route_mode), + settings.FAST_ROUTE_MODE.get())); return list; } - if(rparams != null) { + if (rparams != null) { GPXFile fl = rparams.getFile(); if (fl.hasRtePt()) { list.add(new OtherLocalRoutingParameter(R.string.use_points_as_intermediates, getString(R.string.use_points_as_intermediates), rparams.isUseIntermediatePointsRTE())); } - list.add(new OtherLocalRoutingParameter(R.string.gpx_option_reverse_route, + list.add(new OtherLocalRoutingParameter(R.string.gpx_option_reverse_route, getString(R.string.gpx_option_reverse_route), rparams.isReverse())); if (!rparams.isUseIntermediatePointsRTE()) { - list.add(new OtherLocalRoutingParameter(R.string.gpx_option_from_start_point, - getString(R.string.gpx_option_from_start_point), rparams.isPassWholeRoute())); + list.add(new OtherLocalRoutingParameter(R.string.gpx_option_from_start_point, + getString(R.string.gpx_option_from_start_point), rparams.isPassWholeRoute())); list.add(new OtherLocalRoutingParameter(R.string.gpx_option_calculate_first_last_segment, - getString(R.string.gpx_option_calculate_first_last_segment), rparams.isCalculateOsmAndRouteParts())); + getString(R.string.gpx_option_calculate_first_last_segment), rparams + .isCalculateOsmAndRouteParts())); } -// list.add(new OtherLocalRoutingParameter(R.string.announce_gpx_waypoints, -// getString(R.string.announce_gpx_waypoints), rparams.isAnnounceWaypoints())); + // list.add(new OtherLocalRoutingParameter(R.string.announce_gpx_waypoints, + // getString(R.string.announce_gpx_waypoints), rparams.isAnnounceWaypoints())); // Temporary disabled - // list.add(new GPXLocalRoutingParameter(R.string.calculate_osmand_route_gpx, - // getString(R.string.calculate_osmand_route_gpx), rparams.isCalculateOsmAndRoute())); + // list.add(new GPXLocalRoutingParameter(R.string.calculate_osmand_route_gpx, + // getString(R.string.calculate_osmand_route_gpx), rparams.isCalculateOsmAndRoute())); } - GeneralRouter rm = SettingsNavigationActivity.getRouter(mapActivity.getMyApplication().getDefaultRoutingConfig(), am); - if(rm == null || (rparams != null && !rparams.isCalculateOsmAndRoute())) { + GeneralRouter rm = SettingsNavigationActivity.getRouter(mapActivity.getMyApplication() + .getDefaultRoutingConfig(), am); + if (rm == null || (rparams != null && !rparams.isCalculateOsmAndRoute())) { return list; } for (RoutingParameter r : rm.getParameters().values()) { @@ -259,6 +245,7 @@ public class MapRoutePreferencesControl extends MapControls { return list; } + private String getString(int id) { return mapActivity.getString(id); } @@ -271,12 +258,12 @@ public class MapRoutePreferencesControl extends MapControls { final ListView lv = (ListView) settingsDlg.findViewById(android.R.id.list); final Set selected = new HashSet(); selected.add(am); - + setupSpinner(settingsDlg); - - - listAdapter = new ArrayAdapter(ctx, - R.layout.layers_list_activity_item, R.id.title, getRoutingParameters(am)) { + final float scaleCoefficient = mapActivity.getMapView().getScaleCoefficient(); + + listAdapter = new ArrayAdapter(ctx, R.layout.layers_list_activity_item, R.id.title, + getRoutingParameters(am)) { @Override public View getView(final int position, View convertView, ViewGroup parent) { View v = mapActivity.getLayoutInflater().inflate(R.layout.layers_list_activity_item, null); @@ -285,8 +272,8 @@ public class MapRoutePreferencesControl extends MapControls { final LocalRoutingParameter rp = getItem(position); tv.setText(rp.getText(mapActivity)); tv.setPadding((int) (5 * scaleCoefficient), 0, 0, 0); - if (rp.routingParameter != null && rp.routingParameter.getId().equals("short_way")){ - //if short route settings - it should be inverse of fast_route_mode + if (rp.routingParameter != null && rp.routingParameter.getId().equals("short_way")) { + // if short route settings - it should be inverse of fast_route_mode ch.setChecked(!settings.FAST_ROUTE_MODE.get()); } else { ch.setChecked(rp.isSelected(settings)); @@ -295,13 +282,13 @@ public class MapRoutePreferencesControl extends MapControls { ch.setOnCheckedChangeListener(new OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { - //if short way that it should set valut to fast mode opposite of current - if (rp.routingParameter != null && rp.routingParameter.getId().equals("short_way")){ + // if short way that it should set valut to fast mode opposite of current + if (rp.routingParameter != null && rp.routingParameter.getId().equals("short_way")) { settings.FAST_ROUTE_MODE.set(!isChecked); } rp.setSelected(settings, isChecked); - if(rp instanceof OtherLocalRoutingParameter) { + if (rp instanceof OtherLocalRoutingParameter) { updateGpxRoutingParameter((OtherLocalRoutingParameter) rp); } mapActivity.getRoutingHelper().recalculateRouteDueToSettingsChange(); @@ -310,31 +297,29 @@ public class MapRoutePreferencesControl extends MapControls { return v; } }; - - AppModeDialog.prepareAppModeView(mapActivity, selected, false, - (ViewGroup) settingsDlg.findViewById(R.id.TopBar), true, - new View.OnClickListener() { - @Override - public void onClick(View v) { - if(selected.size() > 0) { - ApplicationMode next = selected.iterator().next(); - settings.APPLICATION_MODE.set(next); - mapActivity.getRoutingHelper().recalculateRouteDueToSettingsChange(); - updateParameters(); - } - } - - }); + AppModeDialog.prepareAppModeView(mapActivity, selected, false, + (ViewGroup) settingsDlg.findViewById(R.id.TopBar), true, new View.OnClickListener() { + @Override + public void onClick(View v) { + if (selected.size() > 0) { + ApplicationMode next = selected.iterator().next(); + settings.APPLICATION_MODE.set(next); + mapActivity.getRoutingHelper().recalculateRouteDueToSettingsChange(); + updateParameters(); + } + } + + }); lv.setAdapter(listAdapter); return settingsDlg; } - + private void updateParameters() { ApplicationMode am = settings.APPLICATION_MODE.get(); listAdapter.setNotifyOnChange(false); listAdapter.clear(); - for(LocalRoutingParameter r : getRoutingParameters(am)) { + for (LocalRoutingParameter r : getRoutingParameters(am)) { listAdapter.add(r); } listAdapter.notifyDataSetChanged(); @@ -347,19 +332,19 @@ public class MapRoutePreferencesControl extends MapControls { @Override public void onItemSelected(AdapterView parent, View view, int position, long id) { - if(position == 0) { - if(mapActivity.getRoutingHelper().getCurrentGPXRoute() != null) { + if (position == 0) { + if (mapActivity.getRoutingHelper().getCurrentGPXRoute() != null) { mapActivity.getRoutingHelper().setGpxParams(null); settings.FOLLOW_THE_GPX_ROUTE.set(null); mapActivity.getRoutingHelper().recalculateRouteDueToSettingsChange(); } updateParameters(); - } else if(position == 1) { + } else if (position == 1) { openGPXFileSelection(gpxSpinner); - } else if(position == 2) { - // nothing to change - } - + } else if (position == 2) { + // nothing to change + } + } @Override @@ -370,7 +355,7 @@ public class MapRoutePreferencesControl extends MapControls { protected void openGPXFileSelection(final Spinner gpxSpinner) { GpxUiHelper.selectGPXFile(mapActivity, false, false, new CallbackWithObject() { - + @Override public boolean processResult(GPXFile[] result) { mapActivity.getMapActions().setGPXRouteParams(result[0]); @@ -388,34 +373,19 @@ public class MapRoutePreferencesControl extends MapControls { gpxActions.add(mapActivity.getString(R.string.shared_string_none)); gpxActions.add(mapActivity.getString(R.string.select_gpx)); GPXRouteParamsBuilder rp = mapActivity.getRoutingHelper().getCurrentGPXRoute(); - if(rp != null) { + if (rp != null) { gpxActions.add(new File(rp.getFile().path).getName()); } - - ArrayAdapter gpxAdapter = new ArrayAdapter(mapActivity, - android.R.layout.simple_spinner_item, - gpxActions - ); + + ArrayAdapter gpxAdapter = new ArrayAdapter(mapActivity, android.R.layout.simple_spinner_item, + gpxActions); gpxAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); gpxSpinner.setAdapter(gpxAdapter); - if(rp != null) { + if (rp != null) { gpxSpinner.setSelection(2); } else { gpxSpinner.setSelection(0); } } - @Override - public void hideControls(FrameLayout layout) { - removeButton(layout, settingsAppModeButton); - } - - @Override - public void onDraw(Canvas canvas, RotatedTileBox tileBox, DrawSettings nightMode) { - int id = settings.getApplicationMode().getSmallIcon(false); // settingsAppModeButton.isPressed() || dialog != null - if(cachedId != id && settingsAppModeButton.getLeft() > 0) { - cachedId = id; - settingsAppModeButton.setImageResource(id); - } - } }