Fix issues

This commit is contained in:
Victor Shcherb 2015-03-14 01:02:35 +01:00
parent 47ab27b5d1
commit 7f93abc332
9 changed files with 312 additions and 542 deletions

View file

@ -0,0 +1,15 @@
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true"><shape android:shape="rectangle">
<solid android:color="@color/map_widget_light_pressed" />
<corners android:radius="@dimen/map_button_rect_rad" />
<stroke android:width="@dimen/map_button_stroke" android:color="@color/map_widget_stroke" />
</shape></item>
<item><shape android:shape="rectangle">
<solid android:color="@color/map_widget_light_trans" />
<corners android:radius="@dimen/map_button_rect_rad" />
<stroke android:width="@dimen/map_button_stroke" android:color="@color/map_widget_stroke" />
</shape></item>
</selector>

View file

@ -2,13 +2,64 @@
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:orientation="vertical">
android:layout_gravity="bottom"
android:orientation="vertical" >
<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<FrameLayout
android:id="@+id/map_app_mode_shadow"
android:layout_width="@dimen/map_button_shadow_width"
android:layout_height="@dimen/map_button_shadow_height"
android:layout_gravity="bottom|left"
android:layout_marginBottom="@dimen/map_button_shadow_margin"
android:layout_marginLeft="@dimen/map_button_shadow_margin"
android:background="@drawable/btn_round_trans" >
<ImageView
android:id="@+id/map_app_mode_icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="top|center"
android:layout_marginTop="3dp"
android:src="@drawable/ic_action_remove_light" />
<TextView
android:id="@+id/map_app_mode_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="top|center"
android:layout_marginTop="3dp"
android:textSize="@dimen/map_button_text_size" />
</FrameLayout>
<LinearLayout
android:id="@+id/map_transparency_layout"
android:layout_height="wrap_content"
android:visibility="gone"
android:layout_width="wrap_content"
android:layout_gravity="bottom|center"
android:layout_marginBottom="@dimen/map_button_size"
android:orientation="horizontal" >
<SeekBar
android:id="@+id/map_transparency_seekbar"
android:layout_height="wrap_content"
android:layout_width="@dimen/map_trans_seek_size"
android:layout_gravity="center"
/>
<ImageButton
android:id="@+id/map_transparency_hide"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:background="@drawable/btn_circle_transparent"
android:src="@drawable/headliner_close" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
@ -17,18 +68,18 @@
android:layout_marginLeft="@dimen/map_button_margin" >
<ImageButton
android:id="@+id/map_menu_button"
android:layout_width="@dimen/map_button_size"
android:layout_height="@dimen/map_button_size"
android:background="@drawable/btn_round"
android:id="@+id/map_menu_button"
android:src="@drawable/ic_action_remove_light" />
<ImageButton
android:id="@+id/map_route_info_button"
android:layout_width="@dimen/map_button_size"
android:layout_height="@dimen/map_button_size"
android:layout_marginLeft="@dimen/map_button_spacing"
android:background="@drawable/btn_round"
android:id="@+id/map_route_info_button"
android:src="@drawable/ic_action_remove_light" />
</LinearLayout>
@ -62,7 +113,7 @@
android:src="@drawable/ic_action_remove_light" />
<ImageButton
android:id="@+id/map_zoom_out_button"
android:id="@+id/map_zoom_out_button"
android:layout_width="@dimen/map_button_size"
android:layout_height="@dimen/map_button_size"
android:layout_marginTop="@dimen/map_button_spacing"
@ -77,63 +128,63 @@
android:layout_height="wrap_content" >
<LinearLayout
android:id="@+id/map_route_preparation_layout"
android:layout_width="match_parent"
android:layout_height="@dimen/map_route_buttons_height"
android:id="@+id/map_route_preparation_layout"
android:layout_gravity="bottom" >
<ImageButton
android:layout_width="@dimen/map_route_buttons_width"
android:layout_height="match_parent"
<ImageButton
android:id="@+id/map_cancel_route_button"
android:background="@drawable/btn_flat"
android:layout_gravity="center_vertical"
android:src="@drawable/ic_action_remove_light" />
<ImageButton
android:layout_width="@dimen/map_route_buttons_width"
android:layout_height="match_parent"
android:layout_gravity="center_vertical"
android:background="@drawable/btn_flat"
android:src="@drawable/ic_action_remove_light" />
<ImageButton
android:id="@+id/map_waypoints_route_button"
android:background="@drawable/btn_flat"
android:layout_gravity="center_vertical"
android:src="@drawable/ic_action_remove_light" />
<ImageButton
android:layout_width="@dimen/map_route_buttons_width"
android:layout_height="match_parent"
android:background="@drawable/btn_flat"
android:id="@+id/map_options_route_button"
android:layout_gravity="center_vertical"
android:background="@drawable/btn_flat"
android:src="@drawable/ic_action_remove_light" />
<TextView
<ImageButton
android:id="@+id/map_options_route_button"
android:layout_width="@dimen/map_route_buttons_width"
android:layout_height="match_parent"
android:layout_gravity="center_vertical"
android:background="@drawable/btn_flat"
android:src="@drawable/ic_action_remove_light" />
<TextView
android:id="@+id/map_go_route_button"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/btn_flat"
android:layout_gravity="center_vertical"
android:id="@+id/map_go_route_button"
android:background="@drawable/btn_flat"
android:drawableLeft="@drawable/ic_action_remove_light"
android:drawablePadding="4dp"
android:gravity="center_vertical"
android:paddingLeft="12dp"
android:drawableLeft="@drawable/ic_action_remove_light"
android:textSize="20sp"
android:textStyle="bold"
android:drawablePadding="4dp" />
android:textStyle="bold" />
</LinearLayout>
<LinearLayout
android:id="@+id/map_context_menu_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/map_context_menu_layout"
android:visibility="gone"
android:background="@drawable/btn_flat"
android:layout_gravity="bottom">
android:layout_gravity="bottom"
android:background="@drawable/btn_flat"
android:visibility="gone" >
<TextView
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_weight="1"
android:ellipsize="end"
android:gravity="center">
android:gravity="center" >
</TextView>
<ImageButton

View file

@ -48,15 +48,21 @@
<dimen name="dashboard_parking_left_margin">16dp</dimen>
<dimen name="dashboard_parking_icon_size">48dp</dimen>
<!-- map buttons -->
<dimen name="map_trans_seek_size">80dp</dimen>
<dimen name="map_button_text_size">18sp</dimen>
<dimen name="map_route_buttons_width">60dp</dimen>
<dimen name="map_route_buttons_height">54dp</dimen>
<dimen name="map_address_height">40dp</dimen>
<dimen name="map_button_size">48dp</dimen>
<dimen name="map_button_shadow_width">52dp</dimen>
<dimen name="map_button_shadow_height">85dp</dimen>
<dimen name="map_widget_icon">24dp</dimen>
<dimen name="map_widget_height">32dp</dimen>
<dimen name="map_widget_image">80dp</dimen>
<dimen name="map_button_spacing">15dp</dimen>
<dimen name="map_button_margin">4dp</dimen>
<dimen name="map_button_shadow_margin">2dp</dimen>
<dimen name="map_button_inset">4dp</dimen>
<dimen name="map_button_rect_rad">3dp</dimen>
<dimen name="map_button_stroke">1px</dimen>

View file

@ -48,6 +48,7 @@ public class QuickAction extends CustomPopupWindow {
private boolean animateTrack;
private ViewGroup mTrack;
private ArrayList<ActionItem> actionList;
private boolean top;
/**
* Constructor
@ -85,6 +86,11 @@ public class QuickAction extends CustomPopupWindow {
animStyle = ANIM_AUTO;
animateTrack = true;
}
public void setOnAnchorOnTop(boolean top) {
this.top = top;
}
/**
* Animate track
@ -150,7 +156,7 @@ public class QuickAction extends CustomPopupWindow {
boolean onTop = true;
// display on bottom
if (rootHeight > anchor.getTop()) {
if (rootHeight > anchor.getTop() || onTop) {
yPos = anchorRect.bottom;
onTop = false;
}

View file

@ -291,6 +291,7 @@ public class DashboardOnMap {
if(!routingHelper.isFollowingMode() && !routingHelper.isRoutePlanningMode()) {
mapActivity.getMapActions().enterRoutePlanningMode(null, null, false);
} else {
mapActivity.getRoutingHelper().setRoutePlanningMode(true);
mapActivity.getMapViewTrackingUtilities().switchToRoutePlanningMode();
mapActivity.refreshMap();
}

View file

@ -1,10 +1,17 @@
package net.osmand.plus.views;
import gnu.trove.list.array.TIntArrayList;
import java.util.ArrayList;
import java.util.List;
import net.londatiga.android.ActionItem;
import net.londatiga.android.QuickAction;
import net.osmand.core.android.MapRendererContext;
import net.osmand.data.RotatedTileBox;
import net.osmand.plus.ApplicationMode;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.OsmandPlugin;
import net.osmand.plus.OsmandSettings;
import net.osmand.plus.OsmandSettings.CommonPreference;
import net.osmand.plus.R;
@ -13,19 +20,18 @@ import net.osmand.plus.routing.RoutingHelper;
import net.osmand.plus.views.controls.MapControls;
import net.osmand.plus.views.controls.MapRouteInfoControl;
import net.osmand.plus.views.controls.MapRoutePreferencesControl;
import net.osmand.plus.views.controls.MapZoomControls;
import net.osmand.plus.views.corenative.NativeCoreContext;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.ColorFilter;
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.view.View.OnClickListener;
import android.view.ViewGroup.LayoutParams;
import android.widget.FrameLayout;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.LinearLayout;
@ -36,8 +42,6 @@ public class MapControlsLayer extends OsmandMapLayer {
private static final int TIMEOUT_TO_SHOW_BUTTONS = 5000;
public MapHudButton createHudButton(View iv, int resId) {
MapHudButton mc = new MapHudButton();
mc.iv = iv;
@ -70,11 +74,18 @@ public class MapControlsLayer extends OsmandMapLayer {
private static long startCounter;
private Runnable delayStart;
private Handler showUIHandler;
private ImageView appModeIcon;
private TextView zoomText;
private OsmandMapTileView mapView;
private OsmandApplication app;
private View mapAppModeShadow;
public MapControlsLayer(MapActivity activity) {
this.mapActivity = activity;
app = activity.getMyApplication();
settings = activity.getMyApplication().getSettings();
mapView = mapActivity.getMapView();
}
@Override
@ -85,18 +96,17 @@ public class MapControlsLayer extends OsmandMapLayer {
@Override
public void initLayer(final OsmandMapTileView view) {
scaleCoefficient = view.getScaleCoefficient();
FrameLayout parent = getParent();
// TODO
// rulerControl = init(new RulerControl(zoomControls, mapActivity, showUIHandler, scaleCoefficient), parent,
// rightGravity);
showUIHandler = new Handler();
initTransparencyBar(view, parent);
initTransparencyBar();
initZooms();
initControls();
initRouteControls();
initTopControls();
}
private class CompassDrawable extends Drawable {
private Drawable original;
@ -112,33 +122,33 @@ public class MapControlsLayer extends OsmandMapLayer {
original.draw(canvas);
canvas.restore();
}
@Override
public int getMinimumHeight() {
return original.getMinimumHeight();
}
@Override
public int getMinimumWidth() {
return original.getMinimumWidth();
}
@Override
public int getIntrinsicHeight() {
return original.getIntrinsicHeight();
}
@Override
public int getIntrinsicWidth() {
return original.getIntrinsicWidth();
}
@Override
public void setChangingConfigurations(int configs) {
super.setChangingConfigurations(configs);
original.setChangingConfigurations(configs);
}
@Override
public void setBounds(int left, int top, int right, int bottom) {
super.setBounds(left, top, right, bottom);
@ -175,10 +185,10 @@ public class MapControlsLayer extends OsmandMapLayer {
});
View compass = mapActivity.findViewById(R.id.map_compass_button);
// protected void onDraw(Canvas canvas) {
// }
compassHud = createHudButton((ImageView) compass, R.drawable.map_compass).setIconColorId(0)
.setBg(R.drawable.btn_inset_circle, R.drawable.btn_inset_circle_night);
// protected void onDraw(Canvas canvas) {
// }
compassHud = createHudButton((ImageView) compass, R.drawable.map_compass).setIconColorId(0).setBg(
R.drawable.btn_inset_circle, R.drawable.btn_inset_circle_night);
compassHud.compass = true;
controls.add(compassHud);
compass.setOnClickListener(new View.OnClickListener() {
@ -245,7 +255,7 @@ public class MapControlsLayer extends OsmandMapLayer {
public void onClick(View v) {
notifyClicked();
RoutingHelper routingHelper = mapActivity.getMyApplication().getRoutingHelper();
if(!routingHelper.isFollowingMode() && !routingHelper.isRoutePlanningMode()) {
if (!routingHelper.isFollowingMode() && !routingHelper.isRoutePlanningMode()) {
mapActivity.getMapActions().enterRoutePlanningMode(null, null, false);
} else {
startNavigation();
@ -290,6 +300,16 @@ public class MapControlsLayer extends OsmandMapLayer {
}
}
});
mapAppModeShadow = mapActivity.findViewById(R.id.map_app_mode_shadow);
mapAppModeShadow.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
onApplicationModePress(v);
}
});
appModeIcon = (ImageView) mapActivity.findViewById(R.id.map_app_mode_icon);
zoomText = (TextView) mapActivity.findViewById(R.id.map_app_mode_text);
View routePlanButton = mapActivity.findViewById(R.id.map_route_info_button);
controls.add(createHudButton((ImageView) routePlanButton, R.drawable.ic_action_gdirections_dark).setBg(
@ -298,9 +318,14 @@ public class MapControlsLayer extends OsmandMapLayer {
@Override
public void onClick(View v) {
notifyClicked();
mapActivity.getRoutingHelper().setRoutePlanningMode(true);
mapActivity.getMapViewTrackingUtilities().switchToRoutePlanningMode();
mapActivity.refreshMap();
RoutingHelper routingHelper = mapActivity.getRoutingHelper();
if (!routingHelper.isFollowingMode() && !routingHelper.isRoutePlanningMode()) {
mapActivity.getMapActions().enterRoutePlanningMode(null, null, false);
} else {
mapActivity.getRoutingHelper().setRoutePlanningMode(true);
mapActivity.getMapViewTrackingUtilities().switchToRoutePlanningMode();
mapActivity.refreshMap();
}
}
});
@ -322,11 +347,10 @@ public class MapControlsLayer extends OsmandMapLayer {
}
});
final View.OnLongClickListener listener = MapZoomControls.getOnClickMagnifierListener(view);
final View.OnLongClickListener listener = MapControlsLayer.getOnClickMagnifierListener(view);
zoomInButton.setOnLongClickListener(listener);
View zoomOutButton = mapActivity.findViewById(R.id.map_zoom_out_button);
controls.add(createHudButton((ImageView) zoomOutButton, R.drawable.ic_action_zoom_out)
.setRoundTransparent());
controls.add(createHudButton((ImageView) zoomOutButton, R.drawable.ic_action_zoom_out).setRoundTransparent());
zoomOutButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
@ -363,11 +387,11 @@ public class MapControlsLayer extends OsmandMapLayer {
startCounter = 0;
}
public void startCounter() {
OsmandSettings settings = mapActivity.getMyApplication().getSettings();
int del = settings.DELAY_TO_START_NAVIGATION.get();
if(del <= 0) {
if (del <= 0) {
return;
}
if (startCounter <= 0) {
@ -388,7 +412,7 @@ public class MapControlsLayer extends OsmandMapLayer {
};
delayStart.run();
}
}
protected void notifyClicked(MapControls m) {
@ -440,20 +464,33 @@ public class MapControlsLayer extends OsmandMapLayer {
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);
menuControl.setIconResId(settings.USE_DASHBOARD_INSTEAD_OF_DRAWER.get() ? R.drawable.ic_dashboard_dark
: R.drawable.ic_navigation_drawer);
if(routeFollowingMode || routePlanningMode) {
mapAppModeShadow.setVisibility(View.GONE);
} else {
mapAppModeShadow.setVisibility(View.VISIBLE);
if (!mapView.isZooming() || !OsmandPlugin.isDevelopment()) {
zoomText.setVisibility(View.GONE);
appModeIcon.setVisibility(View.VISIBLE);
appModeIcon.setImageResource(settings.getApplicationMode().getSmallIcon(isNight));
} else {
zoomText.setVisibility(View.VISIBLE);
appModeIcon.setVisibility(View.GONE);
zoomText.setText(getZoomLevel(tileBox));
}
}
optionsRouteControl.setIconResId(settings.getApplicationMode().getSmallIcon(true));
int vis = showRouteCalculationControls ? View.VISIBLE : View.GONE;
if (showRouteCalculationControls) {
((TextView) routeGoControl.iv).setTextColor(textColor);
final String text ;
final String text;
if (startCounter > 0) {
int get = (int) ((startCounter - System.currentTimeMillis()) / 1000l);
text = mapActivity.getString(R.string.shared_string_go) + " (" + get + ")";
} else {
text = mapActivity.getString(R.string.shared_string_go) ;
text = mapActivity.getString(R.string.shared_string_go);
}
((TextView) routeGoControl.iv).setText(text);
}
@ -461,8 +498,9 @@ public class MapControlsLayer extends OsmandMapLayer {
if (routePreparationLayout.getVisibility() != vis) {
routePreparationLayout.setVisibility(vis);
mapRouteInfoControlDialog.setVisible(showRouteCalculationControls);
if(showRouteCalculationControls) {
if(!mapActivity.getRoutingHelper().isFollowingMode() && !mapActivity.getRoutingHelper().isPauseNavigation()) {
if (showRouteCalculationControls) {
if (!mapActivity.getRoutingHelper().isFollowingMode()
&& !mapActivity.getRoutingHelper().isPauseNavigation()) {
startCounter();
}
} else {
@ -474,7 +512,7 @@ public class MapControlsLayer extends OsmandMapLayer {
if (mapRotate != cachedRotate) {
cachedRotate = mapRotate;
// Aply animation to image view
compassHud.iv.invalidate();
compassHud.iv.invalidate();
}
if (settings.ROTATE_MAP.get() == OsmandSettings.ROTATE_MAP_NONE) {
compassHud.setIconResId(isNight ? R.drawable.map_compass_niu_white : R.drawable.map_compass_niu);
@ -489,12 +527,9 @@ public class MapControlsLayer extends OsmandMapLayer {
}
}
private FrameLayout getParent() {
return (FrameLayout) mapActivity.findViewById(R.id.MapButtons);
}
public boolean onSingleTap(PointF point, RotatedTileBox tileBox) {
if(mapRouteInfoControlDialog.onSingleTap(point, tileBox)) {
if (mapRouteInfoControlDialog.onSingleTap(point, tileBox)) {
return true;
}
stopCounter();
@ -508,16 +543,9 @@ public class MapControlsLayer extends OsmandMapLayer {
}
// /////////////// Transparency bar /////////////////////////
private void initTransparencyBar(final OsmandMapTileView view, FrameLayout parent) {
int minimumHeight = view.getResources().getDrawable(R.drawable.map_zoom_in).getMinimumHeight();
android.widget.FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(LayoutParams.WRAP_CONTENT,
LayoutParams.WRAP_CONTENT, Gravity.BOTTOM | Gravity.CENTER);
params.setMargins(0, 0, 0, minimumHeight + 3);
transparencyBarLayout = new LinearLayout(view.getContext());
transparencyBarLayout.setVisibility(settingsToTransparency != null ? View.VISIBLE : View.GONE);
parent.addView(transparencyBarLayout, params);
transparencyBar = new SeekBar(view.getContext());
private void initTransparencyBar() {
transparencyBarLayout = (LinearLayout) mapActivity.findViewById(R.id.map_transparency_layout);
transparencyBar = (SeekBar) mapActivity.findViewById(R.id.map_transparency_seekbar);
transparencyBar.setMax(255);
if (settingsToTransparency != null) {
transparencyBar.setProgress(settingsToTransparency.get());
@ -540,12 +568,7 @@ public class MapControlsLayer extends OsmandMapLayer {
}
}
});
android.widget.LinearLayout.LayoutParams prms = new LinearLayout.LayoutParams((int) (scaleCoefficient * 100),
LayoutParams.WRAP_CONTENT);
transparencyBarLayout.addView(transparencyBar, prms);
ImageButton imageButton = new ImageButton(view.getContext());
prms = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
prms.setMargins((int) (2 * scaleCoefficient), (int) (2 * scaleCoefficient), 0, 0);
ImageButton imageButton = (ImageButton) mapActivity.findViewById(R.id.map_transparency_hide);
imageButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
@ -553,9 +576,6 @@ public class MapControlsLayer extends OsmandMapLayer {
hideTransparencyBar(settingsToTransparency);
}
});
imageButton.setContentDescription(view.getContext().getString(R.string.shared_string_close));
imageButton.setBackgroundResource(R.drawable.headliner_close);
transparencyBarLayout.addView(imageButton, prms);
}
public void showTransparencyBar(CommonPreference<Integer> transparenPreference) {
@ -575,7 +595,6 @@ public class MapControlsLayer extends OsmandMapLayer {
// TODO
}
private class MapHudButton {
View iv;
int bgDark;
@ -637,10 +656,12 @@ public class MapControlsLayer extends OsmandMapLayer {
iv.setBackgroundDrawable(ctx.getResources().getDrawable(night ? bgDark : bgLight));
}
if (iv instanceof ImageView) {
if(compass) {
((ImageView) iv).setImageDrawable(new CompassDrawable(ctx.getIconsCache().getIcon(resId, nightMode ? resDark : resLight)));
if (compass) {
((ImageView) iv).setImageDrawable(new CompassDrawable(ctx.getIconsCache().getIcon(resId,
nightMode ? resDark : resLight)));
} else {
((ImageView) iv).setImageDrawable(ctx.getIconsCache().getIcon(resId, nightMode ? resDark : resLight));
((ImageView) iv).setImageDrawable(ctx.getIconsCache()
.getIcon(resId, nightMode ? resDark : resLight));
}
} else if (iv instanceof TextView) {
((TextView) iv).setCompoundDrawablesWithIntrinsicBounds(
@ -649,4 +670,99 @@ public class MapControlsLayer extends OsmandMapLayer {
}
}
private void onApplicationModePress(View v) {
final QuickAction mQuickAction = new QuickAction(v);
mQuickAction.setOnAnchorOnTop(true);
List<ApplicationMode> vls = ApplicationMode.values(mapActivity.getMyApplication().getSettings());
final ApplicationMode[] modes = vls.toArray(new ApplicationMode[vls.size()]);
int[] icons = new int[vls.size()];
int[] values = new int[vls.size()];
for (int k = 0; k < modes.length; k++) {
icons[k] = modes[k].getSmallIcon(false);
values[k] = modes[k].getStringResource();
}
for (int i = 0; i < modes.length; i++) {
final ActionItem action = new ActionItem();
action.setTitle(mapActivity.getResources().getString(values[i]));
action.setIcon(mapActivity.getResources().getDrawable(icons[i]));
final int j = i;
action.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
mapActivity.getMyApplication().getSettings().APPLICATION_MODE.set(modes[j]);
mQuickAction.dismiss();
}
});
mQuickAction.addActionItem(action);
}
mQuickAction.setAnimStyle(QuickAction.ANIM_AUTO);
mQuickAction.show();
}
private String getZoomLevel(RotatedTileBox tb) {
String zoomText = tb.getZoom() + "";
double frac = tb.getMapDensity();
if (frac != 0) {
int ifrac = (int) (frac * 10);
zoomText += " ";
zoomText += Math.abs(ifrac) / 10;
if (ifrac % 10 != 0) {
zoomText += "." + Math.abs(ifrac) % 10;
}
}
return zoomText;
}
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> mapDensity = view.getSettings().MAP_DENSITY;
final AlertDialog.Builder bld = new AlertDialog.Builder(view.getContext());
int p = (int) (mapDensity.get() * 100);
final TIntArrayList tlist = new TIntArrayList(new int[] { 33, 50, 75, 100, 150, 200, 300, 400 });
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);
mapDensity.set(p / 100.0f);
view.setComplexZoom(view.getZoom(), view.getSettingsMapDensity());
MapRendererContext mapContext = NativeCoreContext.getMapRendererContext();
if (mapContext != null) {
mapContext.updateMapSettings();
}
dialog.dismiss();
}
});
bld.show();
return true;
}
};
return listener;
}
}

View file

@ -1,139 +0,0 @@
package net.osmand.plus.views.controls;
import java.util.List;
import net.londatiga.android.ActionItem;
import net.londatiga.android.QuickAction;
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.OsmandMapLayer.DrawSettings;
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.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.FrameLayout;
public class MapMenuControls extends MapControls {
private Button backToMenuButton;
private Drawable modeShadow;
private Drawable cacheAppModeIcon = null;
private ApplicationMode cacheApplicationMode = null;
public MapMenuControls(MapActivity mapActivity, Handler showUIHandler, float scaleCoefficient) {
super(mapActivity, showUIHandler, scaleCoefficient);
}
private void initBackToMenuButton(final OsmandMapTileView view, FrameLayout parent) {
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) {
// double lat = activity.getMapView().getLatitude();
// double lon = activity.getMapView().getLongitude();
// MainMenuActivity.backToMainMenuDialog(activity, new LatLon(lat, lon));
notifyClicked();
if(mapActivity.getMyApplication().getSettings().USE_DASHBOARD_INSTEAD_OF_DRAWER.get()) {
mapActivity.getDashboard().setDashboardVisibility(true);
} else {
mapActivity.getMapActions().onDrawerBack();
mapActivity.getMapActions().toggleDrawer();
}
}
});
}
@Override
public void showControls(FrameLayout layout) {
initBackToMenuButton(mapActivity.getMapView(), layout);
}
@Override
public void hideControls(FrameLayout layout) {
removeButton(layout, backToMenuButton);
}
@Override
public void onDraw(Canvas canvas, RotatedTileBox tileBox, DrawSettings nightMode) {
if(mapActivity.findViewById(R.id.MapButtons).getVisibility() == View.GONE) {
return;
}
drawApplicationMode(canvas, nightMode != null && nightMode.isNightMode());
}
private void drawApplicationMode(Canvas canvas, boolean nightMode) {
OsmandMapTileView view = mapActivity.getMapView();
ApplicationMode appMode = view.getSettings().getApplicationMode();
if(appMode != cacheApplicationMode){
modeShadow.setBounds(backToMenuButton.getLeft() + (int) (2 * scaleCoefficient), backToMenuButton.getTop() - (int) (24 * scaleCoefficient),
backToMenuButton.getRight() - (int) (4 * scaleCoefficient), backToMenuButton.getBottom());
cacheAppModeIcon = view.getResources().getDrawable(appMode.getSmallIcon(nightMode));
int l = modeShadow.getBounds().left + (modeShadow.getBounds().width() - cacheAppModeIcon.getMinimumWidth()) / 2;
int t = (int) (modeShadow.getBounds().top + 2 * scaleCoefficient);
cacheAppModeIcon.setBounds(l, t, l + cacheAppModeIcon.getMinimumWidth(), t + cacheAppModeIcon.getMinimumHeight());
}
modeShadow.draw(canvas);
if(cacheAppModeIcon != null){
cacheAppModeIcon.draw(canvas);
}
}
@Override
public boolean onSingleTap(PointF point, RotatedTileBox tileBox) {
if (modeShadow.getBounds().contains((int) point.x, (int) point.y)) {
onApplicationModePress();
return true;
}
return false;
}
private void onApplicationModePress() {
final QuickAction mQuickAction = new QuickAction(backToMenuButton);
List<ApplicationMode> vls = ApplicationMode.values(mapActivity.getMyApplication().getSettings());
final ApplicationMode[] modes = vls.toArray(new ApplicationMode[vls.size()]);
int[] icons = new int[vls.size()];
int[] values = new int[vls.size()];
for(int k = 0; k < modes.length; k++) {
icons[k] = modes[k].getSmallIcon(false);
values[k] = modes[k].getStringResource();
}
for (int i = 0; i < modes.length; i++) {
final ActionItem action = new ActionItem();
action.setTitle(mapActivity.getResources().getString(values[i]));
action.setIcon(mapActivity.getResources().getDrawable(icons[i]));
final int j = i;
action.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
mapActivity.getMyApplication().getSettings().APPLICATION_MODE.set(modes[j]);
mQuickAction.dismiss();
}
});
mQuickAction.addActionItem(action);
}
mQuickAction.setAnimStyle(QuickAction.ANIM_AUTO);
mQuickAction.show();
}
public int getWidth() {
if (width == 0) {
Drawable buttonDrawable = mapActivity.getResources().getDrawable(R.drawable.map_btn_menu);
width = buttonDrawable.getMinimumWidth();
}
return width ;
}
}

View file

@ -1,288 +0,0 @@
package net.osmand.plus.views.controls;
import gnu.trove.list.array.TIntArrayList;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.List;
import net.osmand.core.android.MapRendererContext;
import net.osmand.core.android.MapRendererView;
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 net.osmand.plus.views.corenative.NativeCoreContext;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.PointF;
import android.graphics.Rect;
import android.graphics.drawable.Drawable;
import android.os.Handler;
import android.os.Message;
import android.text.TextPaint;
import android.view.View;
import android.widget.Button;
import android.widget.FrameLayout;
public class MapZoomControls extends MapControls {
private static final int SHOW_ZOOM_LEVEL_MSG_ID = OsmAndConstants.UI_HANDLER_MAP_CONTROLS + 1;
private static final int SHOW_ZOOM_BUTTON_MSG_ID = OsmAndConstants.UI_HANDLER_MAP_CONTROLS + 2;
private static final int SHOW_ZOOM_LEVEL_DELAY = 1000;
private static final int SHOW_ZOOM_LEVEL_BUTTON_DELAY = 1500;
private Button zoomInButton;
private Button zoomOutButton;
private TextPaint zoomTextPaint;
private Drawable zoomShadow;
private Bitmap mapMagnifier;
private Paint bitmapPaint;
private boolean showZoomLevel = false;
private boolean showZoomLevelButton = false;
private OsmandMapTileView view;
public MapZoomControls(MapActivity mapActivity, Handler showUIHandler, float scaleCoefficient) {
super(mapActivity, showUIHandler, scaleCoefficient);
view = mapActivity.getMapView();
zoomTextPaint = new TextPaint();
zoomTextPaint.setTextSize(18 * scaleCoefficient);
zoomTextPaint.setAntiAlias(true);
zoomTextPaint.setFakeBoldText(true);
}
public boolean onSingleTap(PointF point, RotatedTileBox tileBox) {
if (isShowZoomLevel() && zoomShadow.getBounds().contains((int) point.x, (int) point.y)) {
getOnClickMagnifierListener(view).onLongClick(null);
return true;
}
return false;
}
@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 - (minimumHeight / 6);
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, System.currentTimeMillis());
} else {
mapActivity.changeZoom(1, System.currentTimeMillis());
}
}
});
final View.OnLongClickListener listener = getOnClickMagnifierListener(view);
zoomInButton.setOnLongClickListener(listener);
zoomOutButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
long time = Calendar.getInstance().getTime().getTime();
notifyClicked();
mapActivity.changeZoom(-1, System.currentTimeMillis());
}
});
zoomOutButton.setOnLongClickListener(listener);
}
@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();
}
@Override
public void hideControls(FrameLayout layout) {
removeButton(layout, zoomInButton);
removeButton(layout, zoomOutButton);
}
private void drawZoomLevel(Canvas canvas, RotatedTileBox tb, boolean drawZoomLevel) {
if (zoomShadow.getBounds().width() == 0) {
zoomShadow.setBounds(zoomInButton.getLeft() - 2, zoomInButton.getTop() - (int) (18 * scaleCoefficient),
zoomInButton.getRight(), zoomInButton.getBottom());
}
zoomShadow.draw(canvas);
if (drawZoomLevel) {
String zoomText = tb.getZoom() + "";
double frac = tb.getMapDensity();
if (frac != 0) {
int ifrac = (int) (frac * 10);
zoomText += " ";
zoomText += Math.abs(ifrac) / 10;
if (ifrac % 10 != 0) {
zoomText += "." + Math.abs(ifrac) % 10;
}
}
float length = zoomTextPaint.measureText(zoomText);
ShadowText.draw(zoomText, canvas, zoomInButton.getLeft() + (zoomInButton.getWidth() - length - 2) / 2,
zoomInButton.getTop() + 4 * scaleCoefficient, zoomTextPaint, shadowColor);
} else {
int size = (int) (16 * scaleCoefficient);
int top = (int) (zoomInButton.getTop() - size - 4 * scaleCoefficient);
int left = (int) (zoomInButton.getLeft() + (zoomInButton.getWidth() - mapMagnifier.getWidth() - 2 * scaleCoefficient) / 2);
// canvas density /2 ? size * 2
canvas.drawBitmap(mapMagnifier, null, new Rect(left, top, left + size * 2, top + size * 2), bitmapPaint);
}
}
@Override
public void onDraw(Canvas canvas, RotatedTileBox tileBox, DrawSettings nightMode) {
BaseMapLayer mainLayer = view.getMainLayer();
boolean zoomInEnabled = mainLayer != null && tileBox.getZoom() < mainLayer.getMaximumShownMapZoom();
boolean zoomOutEnabled = mainLayer != null && tileBox.getZoom() > mainLayer.getMinimumShownMapZoom();
if (zoomInButton.isEnabled() != zoomInEnabled) {
zoomInButton.setEnabled(zoomInEnabled);
}
if (zoomOutButton.isEnabled() != zoomOutEnabled) {
zoomOutButton.setEnabled(zoomOutEnabled);
}
if (isBottom()) {
if (view.isZooming()) {
showZoomLevel = true;
showZoomLevelButton = false;
showUIHandler.removeMessages(SHOW_ZOOM_LEVEL_MSG_ID);
showUIHandler.removeMessages(SHOW_ZOOM_BUTTON_MSG_ID);
} else {
if (isShowZoomLevel() && view.getSettings().SHOW_RULER.get()) {
hideZoomLevelInTime();
}
}
boolean drawZoomLevel = isShowZoomLevel() || !view.getSettings().SHOW_RULER.get();
if (drawZoomLevel) {
drawZoomLevel(canvas, tileBox, !showZoomLevelButton);
}
}
}
private void sendMessageToShowZoomLevel() {
Message msg = Message.obtain(showUIHandler, new Runnable() {
@Override
public void run() {
showZoomLevelButton = true;
sendMessageToShowZoomButton();
view.refreshMap();
}
});
msg.what = SHOW_ZOOM_LEVEL_MSG_ID;
showUIHandler.sendMessageDelayed(msg, SHOW_ZOOM_LEVEL_DELAY);
}
private void sendMessageToShowZoomButton() {
Message msg = Message.obtain(showUIHandler, new Runnable() {
@Override
public void run() {
showZoomLevelButton = false;
showZoomLevel = false;
view.refreshMap();
}
});
msg.what = SHOW_ZOOM_BUTTON_MSG_ID;
showUIHandler.sendMessageDelayed(msg, SHOW_ZOOM_LEVEL_BUTTON_DELAY);
}
private void hideZoomLevelInTime() {
if (!showUIHandler.hasMessages(SHOW_ZOOM_LEVEL_MSG_ID) && !showUIHandler.hasMessages(SHOW_ZOOM_BUTTON_MSG_ID)) {
sendMessageToShowZoomLevel();
}
}
@Override
public void updateTextColor(int textColor, int shadowColor) {
super.updateTextColor(textColor, shadowColor);
zoomTextPaint.setColor(textColor);
}
public boolean isShowZoomLevel() {
return showZoomLevel;
}
public int getHeight() {
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> mapDensity = view.getSettings().MAP_DENSITY;
final AlertDialog.Builder bld = new AlertDialog.Builder(view.getContext());
int p = (int) (mapDensity.get() * 100);
final TIntArrayList tlist = new TIntArrayList(new int[] {33, 50, 75, 100, 150, 200, 300, 400 });
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);
mapDensity.set(p / 100.0f);
view.setComplexZoom(view.getZoom(), view.getSettingsMapDensity());
MapRendererContext mapContext = NativeCoreContext.getMapRendererContext();
if(mapContext != null) {
mapContext.updateMapSettings();
}
dialog.dismiss();
}
});
bld.show();
return true;
}
};
return listener;
}
}

View file

@ -27,15 +27,13 @@ public class RulerControl extends MapControls {
double cacheRulerTileX = 0;
double cacheRulerTileY = 0;
float cacheRulerTextLen = 0;
MapZoomControls zoomControls;
Drawable rulerDrawable;
TextPaint rulerTextPaint;
final static double screenRulerPercent = 0.25;
boolean isNightRemembered = false;
public RulerControl(MapZoomControls zoomControls, MapActivity mapActivity, Handler showUIHandler, float scaleCoefficient) {
public RulerControl(MapActivity mapActivity, Handler showUIHandler, float scaleCoefficient) {
super(mapActivity, showUIHandler, scaleCoefficient);
this.zoomControls = zoomControls;
rulerTextPaint = new TextPaint();
rulerTextPaint.setTextSize(20 * scaleCoefficient);
rulerTextPaint.setAntiAlias(true);
@ -58,10 +56,10 @@ public class RulerControl extends MapControls {
@Override
public void onDraw(Canvas canvas, RotatedTileBox tb, DrawSettings nightMode) {
if( (zoomControls.isVisible() && zoomControls.isShowZoomLevel()) || !mapActivity.getMyApplication().getSettings().SHOW_RULER.get()){
if (!mapActivity.getMyApplication().getSettings().SHOW_RULER.get()) {
return;
}
if(mapActivity.findViewById(R.id.MapButtons).getVisibility() == View.GONE) {
if (mapActivity.findViewById(R.id.MapButtons).getVisibility() == View.GONE) {
return;
}
OsmandMapTileView view = mapActivity.getMapView();
@ -69,9 +67,10 @@ public class RulerControl extends MapControls {
// update cache
if (view.isZooming()) {
cacheRulerText = null;
} else if (((isNight != isNightRemembered) || (tb.getZoom() != cacheRulerZoom) ||
Math.abs(tb.getCenterTileX() - cacheRulerTileX) + Math.abs(tb.getCenterTileY() - cacheRulerTileY) > 1) &&
tb.getPixWidth() > 0){
} else if (((isNight != isNightRemembered) || (tb.getZoom() != cacheRulerZoom) || Math.abs(tb.getCenterTileX()
- cacheRulerTileX)
+ Math.abs(tb.getCenterTileY() - cacheRulerTileY) > 1)
&& tb.getPixWidth() > 0) {
cacheRulerZoom = (tb.getZoom());
cacheRulerTileX = tb.getCenterTileX();
cacheRulerTileY = tb.getCenterTileY();
@ -80,9 +79,11 @@ public class RulerControl extends MapControls {
double roundedDist = OsmAndFormatter.calculateRoundedDist(dist * screenRulerPercent, view.getApplication());
int cacheRulerDistPix = (int) (pixDensity * roundedDist);
cacheRulerText = ShadowText.create(OsmAndFormatter.getFormattedDistance((float) roundedDist, view.getApplication()));
cacheRulerText = ShadowText.create(OsmAndFormatter.getFormattedDistance((float) roundedDist,
view.getApplication()));
cacheRulerTextLen = rulerTextPaint.measureText(cacheRulerText.getText());
rulerDrawable = (isNight ? mapActivity.getResources().getDrawable(R.drawable.ruler_night) : mapActivity.getResources().getDrawable(R.drawable.ruler));
rulerDrawable = (isNight ? mapActivity.getResources().getDrawable(R.drawable.ruler_night) : mapActivity
.getResources().getDrawable(R.drawable.ruler));
Rect bounds = rulerDrawable.getBounds();
bounds.right = (int) (view.getWidth() - 7 * scaleCoefficient);
bounds.left = bounds.right - cacheRulerDistPix;
@ -93,16 +94,17 @@ public class RulerControl extends MapControls {
if (cacheRulerText != null) {
Rect bounds = rulerDrawable.getBounds();
int bottom = (int) (view.getHeight() - vmargin);
if(bounds.bottom != bottom) {
if (bounds.bottom != bottom) {
bounds.bottom = bottom;
bounds.top = bounds.bottom - rulerDrawable.getMinimumHeight();
rulerDrawable.setBounds(bounds);
rulerDrawable.invalidateSelf();
}
rulerDrawable.draw(canvas);
int shadowColor = isNight == true ? mapActivity.getResources().getColor(R.color.widgettext_shadow_night) : Color.WHITE;
cacheRulerText.draw(canvas, bounds.left + (bounds.width() - cacheRulerTextLen) / 2, bounds.bottom - 8 * scaleCoefficient,
rulerTextPaint, shadowColor);
int shadowColor = isNight == true ? mapActivity.getResources().getColor(R.color.widgettext_shadow_night)
: Color.WHITE;
cacheRulerText.draw(canvas, bounds.left + (bounds.width() - cacheRulerTextLen) / 2, bounds.bottom - 8
* scaleCoefficient, rulerTextPaint, shadowColor);
}
isNightRemembered = isNight;
}