diff --git a/OsmAnd/src/net/osmand/plus/OsmAndLocationProvider.java b/OsmAnd/src/net/osmand/plus/OsmAndLocationProvider.java index 1d5cacaa12..da3c2c4ffa 100644 --- a/OsmAnd/src/net/osmand/plus/OsmAndLocationProvider.java +++ b/OsmAnd/src/net/osmand/plus/OsmAndLocationProvider.java @@ -281,6 +281,7 @@ public class OsmAndLocationProvider implements SensorEventListener { default: return; } + if (mGravs != null && mGeoMags != null) { float[] mRotationM = new float[9]; boolean success = SensorManager.getRotationMatrix(mRotationM, null, mGravs, mGeoMags); @@ -289,6 +290,8 @@ public class OsmAndLocationProvider implements SensorEventListener { } float[] orientation = SensorManager.getOrientation(mRotationM, new float[3]); val = (float) Math.toDegrees(orientation[0]); + } else if(event.sensor.getType() != Sensor.TYPE_ORIENTATION){ + return; } if (currentScreenOrientation == 1) { diff --git a/OsmAnd/src/net/osmand/plus/activities/MapActivity.java b/OsmAnd/src/net/osmand/plus/activities/MapActivity.java index 4d9b85a6b3..61e57d2059 100644 --- a/OsmAnd/src/net/osmand/plus/activities/MapActivity.java +++ b/OsmAnd/src/net/osmand/plus/activities/MapActivity.java @@ -11,13 +11,11 @@ import net.osmand.access.AccessibilityPlugin; import net.osmand.access.AccessibleActivity; import net.osmand.access.AccessibleToast; import net.osmand.access.MapAccessibilityActions; -import net.osmand.binary.RouteDataObject; import net.osmand.data.LatLon; import net.osmand.map.MapTileDownloader.DownloadRequest; import net.osmand.map.MapTileDownloader.IMapDownloaderCallback; import net.osmand.plus.ApplicationMode; import net.osmand.plus.BusyIndicator; -import net.osmand.plus.OsmAndLocationProvider; import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandPlugin; import net.osmand.plus.OsmandSettings; @@ -94,6 +92,7 @@ public class MapActivity extends AccessibleActivity { private ProgressDialog startProgressDialog; private List dialogProviders = new ArrayList(2); private StateChangedListener applicationModeListener; + private FrameLayout lockView; private Notification getNotification() { @@ -176,9 +175,15 @@ public class MapActivity extends AccessibleActivity { mapView.setZoom(14); } } - addDialogProvider(mapActions); OsmandPlugin.onMapActivityCreate(this); + if(lockView != null) { + ((FrameLayout)mapView.getParent()).addView(lockView); + } + } + + public void addLockView(FrameLayout lockView) { + this.lockView = lockView; } private void createProgressBarForRouting() { @@ -676,4 +681,5 @@ public class MapActivity extends AccessibleActivity { getMapView().refreshMap(); } + } diff --git a/OsmAnd/src/net/osmand/plus/audionotes/AudioVideoNotesPlugin.java b/OsmAnd/src/net/osmand/plus/audionotes/AudioVideoNotesPlugin.java index 275c7c2b6d..cfe07bb7c1 100644 --- a/OsmAnd/src/net/osmand/plus/audionotes/AudioVideoNotesPlugin.java +++ b/OsmAnd/src/net/osmand/plus/audionotes/AudioVideoNotesPlugin.java @@ -41,9 +41,9 @@ import net.osmand.plus.activities.LocalIndexesActivity.LoadLocalIndexTask; import net.osmand.plus.activities.MapActivity; import net.osmand.plus.activities.SettingsActivity; import net.osmand.plus.views.MapInfoLayer; -import net.osmand.plus.views.MapStackControl; import net.osmand.plus.views.OsmandMapTileView; -import net.osmand.plus.views.TextInfoControl; +import net.osmand.plus.views.mapwidgets.StackWidgetView; +import net.osmand.plus.views.mapwidgets.TextInfoWidget; import net.osmand.util.Algorithms; import org.apache.commons.logging.Log; @@ -93,7 +93,7 @@ public class AudioVideoNotesPlugin extends OsmandPlugin { private static Method mRegisterMediaButtonEventReceiver; private static Method mUnregisterMediaButtonEventReceiver; private OsmandApplication app; - private TextInfoControl recordControl; + private TextInfoWidget recordControl; public final CommonPreference AV_EXTERNAL_RECORDER ; public final CommonPreference AV_EXTERNAL_PHOTO_CAM ; @@ -438,7 +438,7 @@ public class AudioVideoNotesPlugin extends OsmandPlugin { private void registerWidget(MapActivity activity) { MapInfoLayer mapInfoLayer = activity.getMapLayers().getMapInfoLayer(); if (mapInfoLayer != null ) { - recordControl = new TextInfoControl(activity, 0, mapInfoLayer.getPaintText(), mapInfoLayer.getPaintSubText()); + recordControl = new TextInfoWidget(activity, 0, mapInfoLayer.getPaintText(), mapInfoLayer.getPaintSubText()); recordControl.setImageDrawable(activity.getResources().getDrawable(R.drawable.monitoring_rec_inactive)); setRecordListener(recordControl, activity); mapInfoLayer.getMapInfoControls().registerSideWidget(recordControl, @@ -449,7 +449,7 @@ public class AudioVideoNotesPlugin extends OsmandPlugin { } } - private void setRecordListener(final TextInfoControl recordPlaceControl, final MapActivity mapActivity) { + private void setRecordListener(final TextInfoWidget recordPlaceControl, final MapActivity mapActivity) { recordPlaceControl.setText(app.getString(R.string.av_control_start), ""); updateWidgetIcon(recordPlaceControl); recordPlaceControl.setOnClickListener(new View.OnClickListener() { @@ -462,7 +462,7 @@ public class AudioVideoNotesPlugin extends OsmandPlugin { } - private void updateWidgetIcon(final TextInfoControl recordPlaceControl) { + private void updateWidgetIcon(final TextInfoWidget recordPlaceControl) { recordPlaceControl.setImageDrawable(activity.getResources().getDrawable(R.drawable.widget_icon_av_inactive)); if (AV_DEFAULT_ACTION.get() == AV_DEFAULT_ACTION_VIDEO) { recordPlaceControl.setImageDrawable(activity.getResources().getDrawable(R.drawable.widget_icon_video)); @@ -797,7 +797,7 @@ public class AudioVideoNotesPlugin extends OsmandPlugin { recordControl.setText(app.getString(R.string.av_control_stop), ""); recordControl.setImageDrawable(activity.getResources().getDrawable(R.drawable.widget_icon_av_active)); final MapInfoLayer mil = mapActivity.getMapLayers().getMapInfoLayer(); - final MapStackControl par = mil.getRightStack(); + final StackWidgetView par = mil.getRightStack(); final boolean contains = par.getAllViews().contains(recordControl); if(!contains) { par.addStackView(recordControl); diff --git a/OsmAnd/src/net/osmand/plus/distancecalculator/DistanceCalculatorPlugin.java b/OsmAnd/src/net/osmand/plus/distancecalculator/DistanceCalculatorPlugin.java index 4e78261885..a85e4f3967 100644 --- a/OsmAnd/src/net/osmand/plus/distancecalculator/DistanceCalculatorPlugin.java +++ b/OsmAnd/src/net/osmand/plus/distancecalculator/DistanceCalculatorPlugin.java @@ -16,7 +16,7 @@ import net.osmand.plus.activities.MapActivity; import net.osmand.plus.views.MapInfoLayer; import net.osmand.plus.views.OsmandMapLayer; import net.osmand.plus.views.OsmandMapTileView; -import net.osmand.plus.views.TextInfoControl; +import net.osmand.plus.views.mapwidgets.TextInfoWidget; import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.graphics.Canvas; @@ -34,7 +34,7 @@ public class DistanceCalculatorPlugin extends OsmandPlugin { private static final String ID = "osmand.distance"; private OsmandApplication app; private DistanceCalculatorLayer distanceCalculatorLayer; - private TextInfoControl distanceControl; + private TextInfoWidget distanceControl; private List measurementPoints = new ArrayList(); private int distanceMeasurementMode = 0; @@ -108,8 +108,8 @@ public class DistanceCalculatorPlugin extends OsmandPlugin { } } - private TextInfoControl createDistanceControl(final MapActivity activity, Paint paintText, Paint paintSubText) { - final TextInfoControl distanceControl = new TextInfoControl(activity, 0, paintText, paintSubText); + private TextInfoWidget createDistanceControl(final MapActivity activity, Paint paintText, Paint paintSubText) { + final TextInfoWidget distanceControl = new TextInfoWidget(activity, 0, paintText, paintSubText); distanceControl.setOnClickListener(new View.OnClickListener() { @Override diff --git a/OsmAnd/src/net/osmand/plus/extrasettings/OsmandExtraSettings.java b/OsmAnd/src/net/osmand/plus/extrasettings/OsmandExtraSettings.java index 76e9b9e5f9..f13db164ad 100644 --- a/OsmAnd/src/net/osmand/plus/extrasettings/OsmandExtraSettings.java +++ b/OsmAnd/src/net/osmand/plus/extrasettings/OsmandExtraSettings.java @@ -12,8 +12,8 @@ import net.osmand.plus.OsmandSettings.OsmandPreference; import net.osmand.plus.R; import net.osmand.plus.activities.MapActivity; import net.osmand.plus.activities.SettingsActivity; -import net.osmand.plus.views.MapInfoControls; -import net.osmand.plus.views.MapInfoControls.MapInfoControlRegInfo; +import net.osmand.plus.views.mapwidgets.MapWidgetRegistry; +import net.osmand.plus.views.mapwidgets.MapWidgetRegistry.MapWidgetRegInfo; import net.osmand.plus.views.MapInfoLayer; import net.osmand.plus.views.OsmandMapTileView; import net.osmand.plus.voice.CommandPlayer; @@ -61,10 +61,10 @@ public class OsmandExtraSettings extends OsmandPlugin { registerControls = true; final OsmandMapTileView view = activity.getMapView(); final MapInfoLayer mapInfoLayer = activity.getMapLayers().getMapInfoLayer(); - final MapInfoControls mapInfoControls = mapInfoLayer.getMapInfoControls(); + final MapWidgetRegistry mapInfoControls = mapInfoLayer.getMapInfoControls(); final OsmandPreference textSizePref = view.getSettings().MAP_TEXT_SIZE; - final MapInfoControlRegInfo textSize = mapInfoControls.registerAppearanceWidget(R.drawable.widget_text_size, R.string.map_text_size, + final MapWidgetRegInfo textSize = mapInfoControls.registerAppearanceWidget(R.drawable.widget_text_size, R.string.map_text_size, "text_size", textSizePref); textSize.setStateChangeListener(new Runnable() { @Override @@ -89,7 +89,7 @@ public class OsmandExtraSettings extends OsmandPlugin { b.show(); } }); - final MapInfoControlRegInfo showRuler = mapInfoControls.registerAppearanceWidget(R.drawable.widget_ruler, R.string.map_widget_show_ruler, + final MapWidgetRegInfo showRuler = mapInfoControls.registerAppearanceWidget(R.drawable.widget_ruler, R.string.map_widget_show_ruler, "showRuler", view.getSettings().SHOW_RULER); showRuler.setStateChangeListener(new Runnable() { @Override @@ -99,7 +99,7 @@ public class OsmandExtraSettings extends OsmandPlugin { } }); - final MapInfoControlRegInfo transparent = mapInfoControls.registerAppearanceWidget(R.drawable.widget_transparent_skin, R.string.map_widget_transparent, + final MapWidgetRegInfo transparent = mapInfoControls.registerAppearanceWidget(R.drawable.widget_transparent_skin, R.string.map_widget_transparent, "transparent", view.getSettings().TRANSPARENT_MAP_THEME); transparent.setStateChangeListener(new Runnable() { @Override @@ -109,7 +109,7 @@ public class OsmandExtraSettings extends OsmandPlugin { } }); - final MapInfoControlRegInfo showDestinationArrow = mapInfoControls.registerAppearanceWidget(R.drawable.widget_show_destination_arrow, R.string.map_widget_show_destination_arrow, + final MapWidgetRegInfo showDestinationArrow = mapInfoControls.registerAppearanceWidget(R.drawable.widget_show_destination_arrow, R.string.map_widget_show_destination_arrow, "show_destination_arrow", view.getSettings().SHOW_DESTINATION_ARROW); showDestinationArrow.setStateChangeListener(new Runnable() { @Override diff --git a/OsmAnd/src/net/osmand/plus/monitoring/OsmandMonitoringPlugin.java b/OsmAnd/src/net/osmand/plus/monitoring/OsmandMonitoringPlugin.java index f45d827369..ef8c9b32ee 100644 --- a/OsmAnd/src/net/osmand/plus/monitoring/OsmandMonitoringPlugin.java +++ b/OsmAnd/src/net/osmand/plus/monitoring/OsmandMonitoringPlugin.java @@ -17,13 +17,13 @@ import net.osmand.plus.R; import net.osmand.plus.activities.MapActivity; import net.osmand.plus.activities.SavingTrackHelper; import net.osmand.plus.activities.SettingsActivity; -import net.osmand.plus.views.MapInfoControl; import net.osmand.plus.views.MapInfoLayer; import net.osmand.plus.views.MonitoringInfoControl; import net.osmand.plus.views.MonitoringInfoControl.MonitoringInfoControlServices; import net.osmand.plus.views.MonitoringInfoControl.ValueHolder; +import net.osmand.plus.views.mapwidgets.BaseMapWidget; +import net.osmand.plus.views.mapwidgets.TextInfoWidget; import net.osmand.plus.views.OsmandMapTileView; -import net.osmand.plus.views.TextInfoControl; import org.apache.commons.logging.Log; @@ -43,7 +43,7 @@ public class OsmandMonitoringPlugin extends OsmandPlugin implements MonitoringIn private OsmandSettings settings; private OsmandApplication app; private static final Log log = PlatformUtil.getLog(OsmandMonitoringPlugin.class); - private MapInfoControl monitoringControl; + private BaseMapWidget monitoringControl; public OsmandMonitoringPlugin(OsmandApplication app) { this.app = app; @@ -186,11 +186,11 @@ public class OsmandMonitoringPlugin extends OsmandPlugin implements MonitoringIn /** * creates (if it wasn't created previously) the control to be added on a MapInfoLayer that shows a monitoring state (recorded/stopped) */ - private MapInfoControl createMonitoringControl(final MapActivity map, Paint paintText, Paint paintSubText) { + private BaseMapWidget createMonitoringControl(final MapActivity map, Paint paintText, Paint paintSubText) { final Drawable monitoringBig = map.getResources().getDrawable(R.drawable.monitoring_rec_big); final Drawable monitoringSmall = map.getResources().getDrawable(R.drawable.monitoring_rec_small); final Drawable monitoringInactive = map.getResources().getDrawable(R.drawable.monitoring_rec_inactive); - monitoringControl = new TextInfoControl(map, 0, paintText, paintSubText) { + monitoringControl = new TextInfoWidget(map, 0, paintText, paintSubText) { long lastUpdateTime; @Override public boolean updateInfo() { diff --git a/OsmAnd/src/net/osmand/plus/parkingpoint/ParkingPositionPlugin.java b/OsmAnd/src/net/osmand/plus/parkingpoint/ParkingPositionPlugin.java index 68c66ac82d..24486287d6 100644 --- a/OsmAnd/src/net/osmand/plus/parkingpoint/ParkingPositionPlugin.java +++ b/OsmAnd/src/net/osmand/plus/parkingpoint/ParkingPositionPlugin.java @@ -17,10 +17,10 @@ import net.osmand.plus.OsmandSettings.CommonPreference; import net.osmand.plus.R; import net.osmand.plus.activities.MapActivity; import net.osmand.plus.views.AnimateDraggingMapThread; -import net.osmand.plus.views.MapInfoControl; import net.osmand.plus.views.MapInfoLayer; import net.osmand.plus.views.OsmandMapTileView; -import net.osmand.plus.views.TextInfoControl; +import net.osmand.plus.views.mapwidgets.BaseMapWidget; +import net.osmand.plus.views.mapwidgets.TextInfoWidget; import android.app.AlertDialog; import android.app.AlertDialog.Builder; import android.app.Dialog; @@ -55,7 +55,7 @@ public class ParkingPositionPlugin extends OsmandPlugin { private OsmandApplication app; private ParkingPositionLayer parkingLayer; - private MapInfoControl parkingPlaceControl; + private BaseMapWidget parkingPlaceControl; private final CommonPreference parkingLat; private final CommonPreference parkingLon; private CommonPreference parkingType; @@ -447,8 +447,8 @@ public class ParkingPositionPlugin extends OsmandPlugin { * the current position on the map * and the location of the parked car */ - private TextInfoControl createParkingPlaceInfoControl(final MapActivity map, Paint paintText, Paint paintSubText) { - TextInfoControl parkingPlaceControl = new TextInfoControl(map, 0, paintText, paintSubText) { + private TextInfoWidget createParkingPlaceInfoControl(final MapActivity map, Paint paintText, Paint paintSubText) { + TextInfoWidget parkingPlaceControl = new TextInfoWidget(map, 0, paintText, paintSubText) { private float[] calculations = new float[1]; private int cachedMeters = 0; diff --git a/OsmAnd/src/net/osmand/plus/views/ImageViewControl.java b/OsmAnd/src/net/osmand/plus/views/ImageViewControl.java deleted file mode 100644 index 0ef8cc89d4..0000000000 --- a/OsmAnd/src/net/osmand/plus/views/ImageViewControl.java +++ /dev/null @@ -1,12 +0,0 @@ -package net.osmand.plus.views; - -import android.content.Context; -import android.widget.ImageView; - -public abstract class ImageViewControl extends ImageView implements MapControlUpdateable { - - public ImageViewControl(Context context) { - super(context); - } - -} \ No newline at end of file diff --git a/OsmAnd/src/net/osmand/plus/views/MapControlUpdateable.java b/OsmAnd/src/net/osmand/plus/views/MapControlUpdateable.java deleted file mode 100644 index 58f11e152b..0000000000 --- a/OsmAnd/src/net/osmand/plus/views/MapControlUpdateable.java +++ /dev/null @@ -1,9 +0,0 @@ -package net.osmand.plus.views; - - -public interface MapControlUpdateable { - - public boolean updateInfo(); - - -} \ No newline at end of file diff --git a/OsmAnd/src/net/osmand/plus/views/MapInfoLayer.java b/OsmAnd/src/net/osmand/plus/views/MapInfoLayer.java index 49736e3cfd..729e211414 100644 --- a/OsmAnd/src/net/osmand/plus/views/MapInfoLayer.java +++ b/OsmAnd/src/net/osmand/plus/views/MapInfoLayer.java @@ -11,9 +11,7 @@ import java.util.List; import java.util.Set; import net.osmand.access.AccessibleToast; -import net.osmand.binary.RouteDataObject; import net.osmand.plus.ApplicationMode; -import net.osmand.plus.OsmAndLocationProvider; import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandPlugin; import net.osmand.plus.OsmandSettings; @@ -22,9 +20,18 @@ import net.osmand.plus.R; import net.osmand.plus.activities.MapActivity; import net.osmand.plus.activities.SettingsActivity; import net.osmand.plus.extrasettings.OsmandExtraSettings; -import net.osmand.plus.routing.RouteDirectionInfo; import net.osmand.plus.routing.RoutingHelper; -import net.osmand.plus.views.MapInfoControls.MapInfoControlRegInfo; +import net.osmand.plus.views.mapwidgets.BaseMapWidget; +import net.osmand.plus.views.mapwidgets.ImageViewWidget; +import net.osmand.plus.views.mapwidgets.MapInfoWidgetsFactory; +import net.osmand.plus.views.mapwidgets.MapInfoWidgetsFactory.TopTextView; +import net.osmand.plus.views.mapwidgets.MapWidgetRegistry; +import net.osmand.plus.views.mapwidgets.MapWidgetRegistry.MapWidgetRegInfo; +import net.osmand.plus.views.mapwidgets.NextTurnInfoWidget; +import net.osmand.plus.views.mapwidgets.RouteInfoWidgetsFactory; +import net.osmand.plus.views.mapwidgets.StackWidgetView; +import net.osmand.plus.views.mapwidgets.TextInfoWidget; +import net.osmand.plus.views.mapwidgets.UpdateableWidget; import net.osmand.render.RenderingRuleProperty; import net.osmand.render.RenderingRulesStorage; import net.osmand.util.Algorithms; @@ -36,16 +43,12 @@ import android.content.DialogInterface.OnClickListener; import android.graphics.Canvas; import android.graphics.Color; import android.graphics.Paint; -import android.graphics.Paint.Align; import android.graphics.Paint.Style; import android.graphics.Rect; import android.graphics.RectF; import android.graphics.drawable.Drawable; -import android.text.TextPaint; import android.util.DisplayMetrics; -import android.util.TypedValue; import android.view.Gravity; -import android.view.MotionEvent; import android.view.View; import android.view.View.MeasureSpec; import android.view.ViewGroup; @@ -80,21 +83,23 @@ public class MapInfoLayer extends OsmandMapLayer { private int STATUS_BAR_MARGIN_X = -4; private ImageView backToLocation; + private TopTextView topText; private View progressBar; // groups - private MapStackControl rightStack; - private MapStackControl leftStack; + private StackWidgetView rightStack; + private StackWidgetView leftStack; private LinearLayout statusBar; - private MapInfoControl lanesControl; - private MapInfoControl alarmControl; - private MapInfoControls mapInfoControls; - private TopTextView topText; + private BaseMapWidget lanesControl; + private BaseMapWidget alarmControl; + private MapWidgetRegistry mapInfoControls; private MonitoringInfoControl monitoringServices; private String ADDITIONAL_VECTOR_RENDERING_CATEGORY; + + public MapInfoLayer(MapActivity map, RouteLayer layer){ this.map = map; this.routeLayer = layer; @@ -141,7 +146,7 @@ public class MapInfoLayer extends OsmandMapLayer { paintImg.setAntiAlias(true); - mapInfoControls = new MapInfoControls(map.getMyApplication().getSettings()); + mapInfoControls = new MapWidgetRegistry(map.getMyApplication().getSettings()); monitoringServices = new MonitoringInfoControl(); } @@ -166,7 +171,7 @@ public class MapInfoLayer extends OsmandMapLayer { return monitoringServices; } - public MapInfoControls getMapInfoControls() { + public MapWidgetRegistry getMapInfoControls() { return mapInfoControls; } @@ -180,7 +185,8 @@ public class MapInfoLayer extends OsmandMapLayer { public void registerAllControls(){ statusBar = new LinearLayout(view.getContext()); statusBar.setOrientation(LinearLayout.HORIZONTAL); - RouteInfoControls ric = new RouteInfoControls(scaleCoefficient); + RouteInfoWidgetsFactory ric = new RouteInfoWidgetsFactory(scaleCoefficient); + MapInfoWidgetsFactory mic = new MapInfoWidgetsFactory(scaleCoefficient); OsmandApplication app = view.getApplication(); lanesControl = ric.createLanesControl(app.getRoutingHelper(), view); lanesControl.setBackgroundDrawable(view.getResources().getDrawable(R.drawable.box_free)); @@ -192,53 +198,52 @@ public class MapInfoLayer extends OsmandMapLayer { EnumSet exceptCar = EnumSet.of(ApplicationMode.BICYCLE, ApplicationMode.PEDESTRIAN, ApplicationMode.DEFAULT); EnumSet none = EnumSet.noneOf(ApplicationMode.class); RoutingHelper routingHelper = app.getRoutingHelper(); - NextTurnInfoControl bigInfoControl = ric.createNextInfoControl(routingHelper, app, view.getSettings(), paintText, + NextTurnInfoWidget bigInfoControl = ric.createNextInfoControl(routingHelper, app, view.getSettings(), paintText, paintSubText, false); mapInfoControls.registerSideWidget(bigInfoControl, R.drawable.widget_next_turn, R.string.map_widget_next_turn,"next_turn", true, carBicycleDefault, none, 5); - NextTurnInfoControl smallInfoControl = ric.createNextInfoControl(routingHelper, app, view.getSettings(), + NextTurnInfoWidget smallInfoControl = ric.createNextInfoControl(routingHelper, app, view.getSettings(), paintSmallText, paintSmallSubText, true); mapInfoControls.registerSideWidget(smallInfoControl, R.drawable.widget_next_turn, R.string.map_widget_next_turn_small, "next_turn_small", true, EnumSet.of(ApplicationMode.PEDESTRIAN), none, 10); - NextTurnInfoControl nextNextInfoControl = ric.createNextNextInfoControl(routingHelper, app, view.getSettings(), + NextTurnInfoWidget nextNextInfoControl = ric.createNextNextInfoControl(routingHelper, app, view.getSettings(), paintSmallText, paintSmallSubText, true); mapInfoControls.registerSideWidget(nextNextInfoControl, R.drawable.widget_next_turn, R.string.map_widget_next_next_turn, "next_next_turn",true, carBicycleDefault, none, 15); //MiniMapControl miniMap = ric.createMiniMapControl(routingHelper, view); //mapInfoControls.registerSideWidget(miniMap, R.drawable.widget_next_turn, R.string.map_widget_mini_route, "mini_route", true, none, none, 20); // right stack - TextInfoControl intermediateDist = ric.createIntermediateDistanceControl(map, paintText, paintSubText); + TextInfoWidget intermediateDist = ric.createIntermediateDistanceControl(map, paintText, paintSubText); mapInfoControls.registerSideWidget(intermediateDist, R.drawable.widget_intermediate, R.string.map_widget_intermediate_distance, "intermediate_distance", false, all, none, 3); - TextInfoControl dist = ric.createDistanceControl(map, paintText, paintSubText); + TextInfoWidget dist = ric.createDistanceControl(map, paintText, paintSubText); mapInfoControls.registerSideWidget(dist, R.drawable.widget_target, R.string.map_widget_distance, "distance", false, all, none, 5); - TextInfoControl time = ric.createTimeControl(map, paintText, paintSubText); + TextInfoWidget time = ric.createTimeControl(map, paintText, paintSubText); mapInfoControls.registerSideWidget(time, R.drawable.widget_time, R.string.map_widget_time, "time",false, all, none, 10); - TextInfoControl speed = ric.createSpeedControl(map, paintText, paintSubText); + TextInfoWidget speed = ric.createSpeedControl(map, paintText, paintSubText); mapInfoControls.registerSideWidget(speed, R.drawable.widget_speed, R.string.map_widget_speed, "speed", false, all, none, 15); - TextInfoControl gpsInfo = ric.createGPSInfoControl(map, paintText, paintSubText); + TextInfoWidget gpsInfo = mic.createGPSInfoControl(map, paintText, paintSubText); mapInfoControls.registerSideWidget(gpsInfo, R.drawable.widget_gps_info, R.string.map_widget_gps_info, "gps_info", false, none, none, 17); - TextInfoControl maxspeed = ric.createMaxSpeedControl(map, paintText, paintSubText); + TextInfoWidget maxspeed = ric.createMaxSpeedControl(map, paintText, paintSubText); mapInfoControls.registerSideWidget(maxspeed, R.drawable.widget_max_speed, R.string.map_widget_max_speed, "max_speed", false, none, none, 18); - TextInfoControl alt = ric.createAltitudeControl(map, paintText, paintSubText); + TextInfoWidget alt = mic.createAltitudeControl(map, paintText, paintSubText); mapInfoControls.registerSideWidget(alt, R.drawable.widget_altitude, R.string.map_widget_altitude, "altitude", false, EnumSet.of(ApplicationMode.PEDESTRIAN), none, 20); // Top widgets - ImageViewControl compassView = createCompassView(map); - mapInfoControls.registerTopWidget(compassView, R.drawable.compass, R.string.map_widget_compass, "compass", MapInfoControls.LEFT_CONTROL, all, 5); + ImageViewWidget compassView = mic.createCompassView(map); + mapInfoControls.registerTopWidget(compassView, R.drawable.compass, R.string.map_widget_compass, "compass", MapWidgetRegistry.LEFT_CONTROL, all, 5); View config = createConfiguration(); - mapInfoControls.registerTopWidget(config, R.drawable.widget_config, R.string.map_widget_config, "config", MapInfoControls.RIGHT_CONTROL, all, 10).required(ApplicationMode.DEFAULT); + mapInfoControls.registerTopWidget(config, R.drawable.widget_config, R.string.map_widget_config, "config", MapWidgetRegistry.RIGHT_CONTROL, all, 10).required(ApplicationMode.DEFAULT); mapInfoControls.registerTopWidget(monitoringServices.createMonitoringWidget(view, map), R.drawable.monitoring, R.string.map_widget_monitoring_services, - "monitoring_services", MapInfoControls.LEFT_CONTROL, exceptCar, 12); - mapInfoControls.registerTopWidget(createLockInfo(map), R.drawable.lock_enabled, R.string.bg_service_screen_lock, "bgService", - MapInfoControls.LEFT_CONTROL, none, 15); - backToLocation = createBackToLocation(map); - mapInfoControls.registerTopWidget(backToLocation, R.drawable.widget_backtolocation, R.string.map_widget_back_to_loc, "back_to_location", MapInfoControls.RIGHT_CONTROL, all, 5); - + "monitoring_services", MapWidgetRegistry.LEFT_CONTROL, exceptCar, 12); + mapInfoControls.registerTopWidget(mic.createLockInfo(map), R.drawable.lock_enabled, R.string.bg_service_screen_lock, "bgService", + MapWidgetRegistry.LEFT_CONTROL, none, 15); + backToLocation = mic.createBackToLocation(map); + mapInfoControls.registerTopWidget(backToLocation, R.drawable.widget_backtolocation, R.string.map_widget_back_to_loc, "back_to_location", MapWidgetRegistry.RIGHT_CONTROL, all, 5); View globus = createGlobus(); - mapInfoControls.registerTopWidget(globus, R.drawable.globus, R.string.map_widget_map_select, "progress", MapInfoControls.RIGHT_CONTROL, none, 15); + mapInfoControls.registerTopWidget(globus, R.drawable.globus, R.string.map_widget_map_select, "progress", MapWidgetRegistry.RIGHT_CONTROL, none, 15); - topText = new TopTextView(app, map); + topText = mic.createStreetView(app, map, paintText); mapInfoControls.registerTopWidget(topText, R.drawable.street_name, R.string.map_widget_top_text, - "street_name", MapInfoControls.MAIN_CONTROL, carBicycleDefault, 100); + "street_name", MapWidgetRegistry.MAIN_CONTROL, carBicycleDefault, 100); // Register appearance widgets registerAppearanceWidgets(); @@ -246,7 +251,7 @@ public class MapInfoLayer extends OsmandMapLayer { private void registerAppearanceWidgets() { - final MapInfoControlRegInfo vectorRenderer = mapInfoControls.registerAppearanceWidget(R.drawable.widget_rendering_style, R.string.map_widget_renderer, + final MapWidgetRegInfo vectorRenderer = mapInfoControls.registerAppearanceWidget(R.drawable.widget_rendering_style, R.string.map_widget_renderer, "renderer", view.getSettings().RENDERER); final OsmandApplication app = view.getApplication(); vectorRenderer.setStateChangeListener(new Runnable() { @@ -285,7 +290,7 @@ public class MapInfoLayer extends OsmandMapLayer { } }); - final MapInfoControlRegInfo dayNight = mapInfoControls.registerAppearanceWidget(R.drawable.widget_day_night_mode, R.string.map_widget_day_night, + final MapWidgetRegInfo dayNight = mapInfoControls.registerAppearanceWidget(R.drawable.widget_day_night_mode, R.string.map_widget_day_night, "dayNight", view.getSettings().DAYNIGHT_MODE); dayNight.setStateChangeListener(new Runnable() { @Override @@ -310,7 +315,7 @@ public class MapInfoLayer extends OsmandMapLayer { } }); - final MapInfoControlRegInfo displayViewDirections = mapInfoControls.registerAppearanceWidget(R.drawable.widget_viewing_direction, R.string.map_widget_view_direction, + final MapWidgetRegInfo displayViewDirections = mapInfoControls.registerAppearanceWidget(R.drawable.widget_viewing_direction, R.string.map_widget_view_direction, "viewDirection", view.getSettings().SHOW_VIEW_ANGLE); displayViewDirections.setStateChangeListener(new Runnable() { @Override @@ -343,7 +348,7 @@ public class MapInfoLayer extends OsmandMapLayer { icon = f.getInt(null); } catch(Exception e){ } - MapInfoControlRegInfo w = mapInfoControls.registerAppearanceWidget(icon, propertyName, "rend_"+p.getAttrName(), pref, categoryName); + MapWidgetRegInfo w = mapInfoControls.registerAppearanceWidget(icon, propertyName, "rend_"+p.getAttrName(), pref, categoryName); w.setStateChangeListener(new Runnable() { @Override public void run() { @@ -361,7 +366,7 @@ public class MapInfoLayer extends OsmandMapLayer { icon = f.getInt(null); } catch(Exception e){ } - MapInfoControlRegInfo w = mapInfoControls.registerAppearanceWidget(icon, propertyName, "rend_"+p.getAttrName(), pref, categoryName); + MapWidgetRegInfo w = mapInfoControls.registerAppearanceWidget(icon, propertyName, "rend_"+p.getAttrName(), pref, categoryName); w.setStateChangeListener(new Runnable() { @Override public void run() { @@ -403,8 +408,8 @@ public class MapInfoLayer extends OsmandMapLayer { public void createControls() { // 1. Create view groups and controls statusBar.setBackgroundDrawable(view.getResources().getDrawable(R.drawable.box_top)); - rightStack = new MapStackControl(view.getContext()); - leftStack = new MapStackControl(view.getContext()); + rightStack = new StackWidgetView(view.getContext()); + leftStack = new StackWidgetView(view.getContext()); // 2. Preparations Rect topRectPadding = new Rect(); @@ -466,9 +471,9 @@ public class MapInfoLayer extends OsmandMapLayer { recreateControls(); } - public Set getSpecificVisibleCategories(Set m) { + public Set getSpecificVisibleCategories(Set m) { Set s = new LinkedHashSet(); - for(MapInfoControlRegInfo ms : m){ + for(MapWidgetRegInfo ms : m){ if(ms.getCategory() != null) { s.add(ms.getCategory()); } @@ -479,8 +484,8 @@ public class MapInfoLayer extends OsmandMapLayer { return s; } - public void fillAppearanceWidgets(Set widgets, String category, ArrayList registry) { - for(MapInfoControlRegInfo w : widgets ) { + public void fillAppearanceWidgets(Set widgets, String category, ArrayList registry) { + for(MapWidgetRegInfo w : widgets ) { if(Algorithms.objectEquals(w.getCategory(), category)) { registry.add(w); } @@ -500,7 +505,7 @@ public class MapInfoLayer extends OsmandMapLayer { list.add(map.getString(R.string.map_widget_left_stack)); list.addAll(mapInfoControls.getLeft()); - Set widgets = mapInfoControls.getAppearanceWidgets(); + Set widgets = mapInfoControls.getAppearanceWidgets(); Set cats = getSpecificVisibleCategories(widgets); list.add(map.getString(R.string.map_widget_appearance)); fillAppearanceWidgets(widgets, null, list); @@ -523,8 +528,8 @@ public class MapInfoLayer extends OsmandMapLayer { final TextView tv = (TextView) v.findViewById(R.id.title); final CheckBox ch = ((CheckBox) v.findViewById(R.id.check_item)); Object o = list.get(position); - if(o instanceof MapInfoControlRegInfo) { - final MapInfoControlRegInfo mi = (MapInfoControlRegInfo) o; + if(o instanceof MapWidgetRegInfo) { + final MapWidgetRegInfo mi = (MapWidgetRegInfo) o; String s = mi.visibleCollapsed(mode)? " - " : " "; if(mi.message != null) { @@ -586,8 +591,8 @@ public class MapInfoLayer extends OsmandMapLayer { @Override public void onClick(DialogInterface dialog, int which) { Object o = list.get(which); - if (o instanceof MapInfoControlRegInfo) { - final MapInfoControlRegInfo mi = (MapInfoControlRegInfo) o; + if (o instanceof MapWidgetRegInfo) { + final MapWidgetRegInfo mi = (MapWidgetRegInfo) o; final boolean selecteable = mi.selecteable(); boolean check = mi.visibleCollapsed(mode) || mi.visible(mode); if (check || selecteable) { @@ -659,7 +664,6 @@ public class MapInfoLayer extends OsmandMapLayer { statusBar.setBackgroundDrawable(view.getResources().getDrawable(boxTop)); paintText.setColor(textColor); - topText.getPaint().setColor(textColor); paintSubText.setColor(textColor); paintSmallText.setColor(textColor); paintSmallSubText.setColor(textColor); @@ -669,7 +673,6 @@ public class MapInfoLayer extends OsmandMapLayer { rightStack.setShadowColor(textShadowColor); paintText.setFakeBoldText(textBold); - topText.getPaint().setFakeBoldText(textBold); paintSubText.setFakeBoldText(textBold); paintSmallText.setFakeBoldText(textBold); paintSmallSubText.setFakeBoldText(textBold); @@ -691,17 +694,17 @@ public class MapInfoLayer extends OsmandMapLayer { alarmControl.updateInfo(); for (int i = 0; i < statusBar.getChildCount(); i++) { View v = statusBar.getChildAt(i); - if (v instanceof MapControlUpdateable) { - ((MapControlUpdateable) v).updateInfo(); + if (v instanceof UpdateableWidget) { + ((UpdateableWidget) v).updateInfo(); } } } - public MapStackControl getRightStack() { + public StackWidgetView getRightStack() { return rightStack; } - public MapStackControl getLeftStack() { + public StackWidgetView getLeftStack() { return leftStack; } @@ -756,208 +759,5 @@ public class MapInfoLayer extends OsmandMapLayer { return globus; } - private ImageView createBackToLocation(final MapActivity map){ - ImageView backToLocation = new ImageViewControl(view.getContext()) { - - @Override - public boolean updateInfo() { - boolean enabled = map.getMyApplication().getLocationProvider().getLastKnownLocation() != null; - enabled = enabled && !map.getMapViewTrackingUtilities().isMapLinkedToLocation(); - setEnabled(enabled); - return true; - } - }; - backToLocation.setPadding((int) (5 * scaleCoefficient), 0, (int) (5 * scaleCoefficient), 0); - backToLocation.setImageDrawable(map.getResources().getDrawable(R.drawable.back_to_loc)); - backToLocation.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - map.getMapViewTrackingUtilities().backToLocationImpl(); - } - }); - return backToLocation; - } - - private ImageView createLockInfo(final MapActivity map) { - final ImageView lockView = new ImageView(view.getContext()); - final Drawable lockEnabled = view.getResources().getDrawable(R.drawable.lock_enabled); - final Drawable lockDisabled = view.getResources().getDrawable(R.drawable.lock_disabled); - lockView.setBackgroundDrawable(lockDisabled); - final FrameLayout transparentLockView = new FrameLayout(view.getContext()); - FrameLayout.LayoutParams fparams = new FrameLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT, Gravity.CENTER); - transparentLockView.setLayoutParams(fparams); - transparentLockView.setOnTouchListener(new View.OnTouchListener() { - @Override - public boolean onTouch(View v, MotionEvent event) { - if (event.getAction() == MotionEvent.ACTION_UP) { - int[] locs = new int[2]; - lockView.getLocationOnScreen(locs); - int x = (int) event.getX() - locs[0]; - int y = (int) event.getY() - locs[1]; - transparentLockView.getLocationOnScreen(locs); - x += locs[0]; - y += locs[1]; - if (lockView.getWidth() >= x && x >= 0 && lockView.getHeight() >= y && y >= 0) { - lockView.performClick(); - return true; - } - blinkIcon(); - AccessibleToast.makeText(transparentLockView.getContext(), R.string.screen_is_locked, Toast.LENGTH_LONG).show(); - return true; - } - return true; - } - - private void blinkIcon() { - lockView.setBackgroundDrawable(lockDisabled); - view.postDelayed(new Runnable() { - @Override - public void run() { - lockView.setBackgroundDrawable(lockEnabled); - } - }, 300); - } - - }); - final FrameLayout parent = (FrameLayout) view.getParent(); - lockView.setOnClickListener(new View.OnClickListener() { - protected boolean isScreenLocked; - - @Override - public void onClick(View v) { - if (!isScreenLocked) { - parent.addView(transparentLockView); - map.getMapViewTrackingUtilities().backToLocationImpl(); - } else { - parent.removeView(transparentLockView); - } - isScreenLocked = !isScreenLocked; - if (isScreenLocked) { - lockView.setBackgroundDrawable(lockEnabled); - } else { - lockView.setBackgroundDrawable(lockDisabled); - } - map.getMapViewTrackingUtilities().backToLocationImpl(); - } - }); - return lockView; - } - - - private ImageViewControl createCompassView(final MapActivity map){ - final Drawable compass = map.getResources().getDrawable(R.drawable.compass); - final int mw = (int) compass.getMinimumWidth() ; - final int mh = (int) compass.getMinimumHeight() ; - final OsmandMapTileView view = map.getMapView(); - ImageViewControl compassView = new ImageViewControl(map) { - private float cachedRotate = 0; - @Override - protected void onDraw(Canvas canvas) { - canvas.save(); - canvas.rotate(view.getRotate(), mw / 2, mh / 2); - compass.draw(canvas); - canvas.restore(); - } - - @Override - public boolean updateInfo() { - if(view.getRotate() != cachedRotate) { - cachedRotate = view.getRotate(); - invalidate(); - return true; - } - return false; - } - }; - compassView.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - map.getMapViewTrackingUtilities().switchRotateMapMode(); - } - }); - compassView.setImageDrawable(compass); - return compassView; - } - - private static class TopTextView extends TextView implements MapControlUpdateable { - private final RoutingHelper routingHelper; - private final MapActivity map; - private int shadowColor = Color.WHITE; - private OsmAndLocationProvider locationProvider; - - public TopTextView(OsmandApplication app, MapActivity map) { - super(map); - this.routingHelper = app.getRoutingHelper(); - locationProvider = app.getLocationProvider(); - this.map = map; - getPaint().setTextAlign(Align.CENTER); - setTextColor(Color.BLACK); - } - - @Override - protected void onDraw(Canvas canvas) { - ShadowText.draw(getText().toString(), canvas, getWidth() / 2, getHeight() - 4 * scaleCoefficient, - getPaint(), shadowColor); - } - - public void setShadowColor(int shadowColor) { - this.shadowColor = shadowColor; - } - - @Override - public boolean updateInfo() { - String text = null; - if (routingHelper != null && routingHelper.isRouteCalculated()) { - if (routingHelper.isFollowingMode()) { - text = routingHelper.getCurrentName(); - } else { - int di = map.getMapLayers().getRouteInfoLayer().getDirectionInfo(); - if (di >= 0 && map.getMapLayers().getRouteInfoLayer().isVisible()) { - RouteDirectionInfo next = routingHelper.getRouteDirections().get(di); - text = RoutingHelper.formatStreetName(next.getStreetName(), next.getRef()); - } - } - } else if(map.getMapViewTrackingUtilities().isMapLinkedToLocation()) { - RouteDataObject rt = locationProvider.getLastKnownRouteSegment(); - if(rt != null) { - text = RoutingHelper.formatStreetName(rt.getName(), rt.getRef()); - } - } - if(text == null) { - text = ""; - } - if (!text.equals(getText().toString())) { - TextPaint pp = new TextPaint(getPaint()); - if (!text.equals("")) { - pp.setTextSize(20 * scaleCoefficient); - float ts = pp.measureText(text); - int wth = getWidth(); - while (ts > wth && pp.getTextSize() > (16 * scaleCoefficient)) { - pp.setTextSize(pp.getTextSize() - 1); - ts = pp.measureText(text); - } - boolean dots = false; - while (ts > wth) { - dots = true; - text = text.substring(0, text.length() - 2); - ts = pp.measureText(text); - } - if (dots) { - text += ".."; - } - setTextSize(TypedValue.COMPLEX_UNIT_PX, pp.getTextSize()); - setContentDescription(text); - } else { - setTextSize(TypedValue.COMPLEX_UNIT_PX, 7); - setContentDescription(getResources().getString(R.string.map_widget_top_text)); - } - setText(text); - invalidate(); - return true; - } - return false; - } - - } } diff --git a/OsmAnd/src/net/osmand/plus/views/MapInfoControl.java b/OsmAnd/src/net/osmand/plus/views/mapwidgets/BaseMapWidget.java similarity index 92% rename from OsmAnd/src/net/osmand/plus/views/MapInfoControl.java rename to OsmAnd/src/net/osmand/plus/views/mapwidgets/BaseMapWidget.java index 1cc4045d98..f58accd6c3 100644 --- a/OsmAnd/src/net/osmand/plus/views/MapInfoControl.java +++ b/OsmAnd/src/net/osmand/plus/views/mapwidgets/BaseMapWidget.java @@ -1,6 +1,7 @@ -package net.osmand.plus.views; +package net.osmand.plus.views.mapwidgets; import net.osmand.plus.ClientContext; +import net.osmand.plus.views.ShadowText; import android.content.Context; import android.graphics.Canvas; import android.graphics.Color; @@ -9,7 +10,7 @@ import android.graphics.Rect; import android.graphics.drawable.Drawable; import android.view.View; -public abstract class MapInfoControl extends View implements MapControlUpdateable { +public abstract class BaseMapWidget extends View implements UpdateableWidget { int width = 0; int height = 0; Rect padding = new Rect(); @@ -17,7 +18,7 @@ public abstract class MapInfoControl extends View implements MapControlUpdateabl private String contentTitle; - public MapInfoControl(Context ctx) { + public BaseMapWidget(Context ctx) { super(ctx); } diff --git a/OsmAnd/src/net/osmand/plus/views/mapwidgets/ImageViewWidget.java b/OsmAnd/src/net/osmand/plus/views/mapwidgets/ImageViewWidget.java new file mode 100644 index 0000000000..b337e194df --- /dev/null +++ b/OsmAnd/src/net/osmand/plus/views/mapwidgets/ImageViewWidget.java @@ -0,0 +1,12 @@ +package net.osmand.plus.views.mapwidgets; + +import android.content.Context; +import android.widget.ImageView; + +public abstract class ImageViewWidget extends ImageView implements UpdateableWidget { + + public ImageViewWidget(Context context) { + super(context); + } + +} \ No newline at end of file diff --git a/OsmAnd/src/net/osmand/plus/views/mapwidgets/MapInfoWidgetsFactory.java b/OsmAnd/src/net/osmand/plus/views/mapwidgets/MapInfoWidgetsFactory.java new file mode 100644 index 0000000000..7e1ddf3432 --- /dev/null +++ b/OsmAnd/src/net/osmand/plus/views/mapwidgets/MapInfoWidgetsFactory.java @@ -0,0 +1,315 @@ +package net.osmand.plus.views.mapwidgets; + +import net.osmand.Location; +import net.osmand.access.AccessibleToast; +import net.osmand.binary.RouteDataObject; +import net.osmand.plus.OsmAndFormatter; +import net.osmand.plus.OsmAndLocationProvider; +import net.osmand.plus.OsmandApplication; +import net.osmand.plus.R; +import net.osmand.plus.OsmAndLocationProvider.GPSInfo; +import net.osmand.plus.activities.MapActivity; +import net.osmand.plus.routing.RouteDirectionInfo; +import net.osmand.plus.routing.RoutingHelper; +import net.osmand.plus.views.OsmandMapTileView; +import net.osmand.plus.views.ShadowText; +import android.graphics.Canvas; +import android.graphics.Color; +import android.graphics.Paint; +import android.graphics.Paint.Align; +import android.graphics.drawable.Drawable; +import android.text.TextPaint; +import android.util.TypedValue; +import android.view.Gravity; +import android.view.MotionEvent; +import android.view.View; +import android.widget.FrameLayout; +import android.widget.ImageView; +import android.widget.TextView; +import android.widget.Toast; +import android.widget.LinearLayout.LayoutParams; + +public class MapInfoWidgetsFactory { + + private float scaleCoefficient; + + public MapInfoWidgetsFactory(float scaleCoefficient){ + this.scaleCoefficient = scaleCoefficient; + } + + public TextInfoWidget createAltitudeControl(final MapActivity map, Paint paintText, Paint paintSubText) { + final TextInfoWidget altitudeControl = new TextInfoWidget(map, 0, paintText, paintSubText) { + private int cachedAlt = 0; + + @Override + public boolean updateInfo() { + // draw speed + Location loc = map.getMyApplication().getLastKnownLocation(); + if (loc != null && loc.hasAltitude()) { + double compAlt = loc.getAltitude(); + if (cachedAlt != (int) compAlt) { + cachedAlt = (int) compAlt; + String ds = OsmAndFormatter.getFormattedAlt(cachedAlt, map.getMyApplication()); + int ls = ds.lastIndexOf(' '); + if (ls == -1) { + setText(ds, null); + } else { + setText(ds.substring(0, ls), ds.substring(ls + 1)); + } + return true; + } + } else if (cachedAlt != 0) { + cachedAlt = 0; + setText(null, null); + return true; + } + return false; + } + }; + altitudeControl.setText(null, null); + altitudeControl.setImageDrawable(map.getResources().getDrawable(R.drawable.info_altitude)); + return altitudeControl; + } + + public TextInfoWidget createGPSInfoControl(final MapActivity map, Paint paintText, Paint paintSubText) { + final OsmandApplication app = map.getMyApplication(); + final OsmAndLocationProvider loc = app.getLocationProvider(); + final TextInfoWidget gpsInfoControl = new TextInfoWidget(map, 3, paintText, paintSubText) { + private int u = -1; + private int f = -1; + + @Override + public boolean updateInfo() { + GPSInfo gpsInfo = loc.getGPSInfo(); + if(gpsInfo.usedSatellites != u || gpsInfo.foundSatellites != f) { + u = gpsInfo.usedSatellites; + f = gpsInfo.foundSatellites; + setText(gpsInfo.usedSatellites+"/"+gpsInfo.foundSatellites, ""); + return true; + } + return false; + } + }; + gpsInfoControl.setImageDrawable(app.getResources().getDrawable(R.drawable.info_gps_info)); + gpsInfoControl.setText(null, null); + return gpsInfoControl; + } + + + public ImageView createBackToLocation(final MapActivity map){ + ImageView backToLocation = new ImageViewWidget(map) { + + @Override + public boolean updateInfo() { + boolean enabled = map.getMyApplication().getLocationProvider().getLastKnownLocation() != null; + enabled = enabled && !map.getMapViewTrackingUtilities().isMapLinkedToLocation(); + setEnabled(enabled); + return true; + } + }; + backToLocation.setPadding((int) (5 * scaleCoefficient), 0, (int) (5 * scaleCoefficient), 0); + backToLocation.setImageDrawable(map.getResources().getDrawable(R.drawable.back_to_loc)); + backToLocation.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + map.getMapViewTrackingUtilities().backToLocationImpl(); + } + }); + return backToLocation; + } + private static boolean isScreenLocked = false; + public ImageView createLockInfo(final MapActivity map) { + final OsmandMapTileView view = map.getMapView(); + final ImageView lockView = new ImageView(view.getContext()); + final Drawable lockEnabled = view.getResources().getDrawable(R.drawable.lock_enabled); + final Drawable lockDisabled = view.getResources().getDrawable(R.drawable.lock_disabled); + if (isScreenLocked) { + map.getMapViewTrackingUtilities().backToLocationImpl(); + lockView.setBackgroundDrawable(lockEnabled); + } else { + lockView.setBackgroundDrawable(lockDisabled); + } + final FrameLayout transparentLockView = new FrameLayout(view.getContext()); + FrameLayout.LayoutParams fparams = new FrameLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT, Gravity.CENTER); + transparentLockView.setLayoutParams(fparams); + transparentLockView.setOnTouchListener(new View.OnTouchListener() { + @Override + public boolean onTouch(View v, MotionEvent event) { + if (event.getAction() == MotionEvent.ACTION_UP) { + int[] locs = new int[2]; + lockView.getLocationOnScreen(locs); + int x = (int) event.getX() - locs[0]; + int y = (int) event.getY() - locs[1]; + transparentLockView.getLocationOnScreen(locs); + x += locs[0]; + y += locs[1]; + if (lockView.getWidth() >= x && x >= 0 && lockView.getHeight() >= y && y >= 0) { + lockView.performClick(); + return true; + } + blinkIcon(); + AccessibleToast.makeText(transparentLockView.getContext(), R.string.screen_is_locked, Toast.LENGTH_SHORT).show(); + return true; + } + return true; + } + + private void blinkIcon() { + lockView.setBackgroundDrawable(lockDisabled); + view.postDelayed(new Runnable() { + @Override + public void run() { + lockView.setBackgroundDrawable(lockEnabled); + } + }, 300); + } + + }); + final FrameLayout parent = (FrameLayout) view.getParent(); + lockView.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + if (isScreenLocked) { + parent.removeView(transparentLockView); + } + isScreenLocked = !isScreenLocked; + if (isScreenLocked) { + parent.addView(transparentLockView); + map.getMapViewTrackingUtilities().backToLocationImpl(); + lockView.setBackgroundDrawable(lockEnabled); + } else { + lockView.setBackgroundDrawable(lockDisabled); + } + } + }); + if(isScreenLocked){ + map.addLockView(transparentLockView); + } + return lockView; + } + + + public ImageViewWidget createCompassView(final MapActivity map){ + final Drawable compass = map.getResources().getDrawable(R.drawable.compass); + final int mw = (int) compass.getMinimumWidth() ; + final int mh = (int) compass.getMinimumHeight() ; + final OsmandMapTileView view = map.getMapView(); + ImageViewWidget compassView = new ImageViewWidget(map) { + private float cachedRotate = 0; + @Override + protected void onDraw(Canvas canvas) { + canvas.save(); + canvas.rotate(view.getRotate(), mw / 2, mh / 2); + compass.draw(canvas); + canvas.restore(); + } + + @Override + public boolean updateInfo() { + if(view.getRotate() != cachedRotate) { + cachedRotate = view.getRotate(); + invalidate(); + return true; + } + return false; + } + }; + compassView.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + map.getMapViewTrackingUtilities().switchRotateMapMode(); + } + }); + compassView.setImageDrawable(compass); + return compassView; + } + + public TopTextView createStreetView(OsmandApplication app, MapActivity map, Paint paintText){ + return new TopTextView(app, map, paintText); + } + + public class TopTextView extends TextView implements UpdateableWidget { + private final RoutingHelper routingHelper; + private final MapActivity map; + private int shadowColor = Color.WHITE; + private OsmAndLocationProvider locationProvider; + private Paint paintText; + + public TopTextView(OsmandApplication app, MapActivity map, Paint paintText) { + super(map); + this.paintText = paintText; + this.routingHelper = app.getRoutingHelper(); + locationProvider = app.getLocationProvider(); + this.map = map; + getPaint().setTextAlign(Align.CENTER); + setTextColor(Color.BLACK); + } + + @Override + protected void onDraw(Canvas canvas) { + getPaint().setColor(paintText.getColor()); + getPaint().setFakeBoldText(paintText.isFakeBoldText()); + ShadowText.draw(getText().toString(), canvas, getWidth() / 2, getHeight() - 4 * scaleCoefficient, + getPaint(), shadowColor); + } + + public void setShadowColor(int shadowColor) { + this.shadowColor = shadowColor; + } + + @Override + public boolean updateInfo() { + String text = null; + if (routingHelper != null && routingHelper.isRouteCalculated()) { + if (routingHelper.isFollowingMode()) { + text = routingHelper.getCurrentName(); + } else { + int di = map.getMapLayers().getRouteInfoLayer().getDirectionInfo(); + if (di >= 0 && map.getMapLayers().getRouteInfoLayer().isVisible()) { + RouteDirectionInfo next = routingHelper.getRouteDirections().get(di); + text = RoutingHelper.formatStreetName(next.getStreetName(), next.getRef()); + } + } + } else if(map.getMapViewTrackingUtilities().isMapLinkedToLocation()) { + RouteDataObject rt = locationProvider.getLastKnownRouteSegment(); + if(rt != null) { + text = RoutingHelper.formatStreetName(rt.getName(), rt.getRef()); + } + } + if(text == null) { + text = ""; + } + if (!text.equals(getText().toString())) { + TextPaint pp = new TextPaint(getPaint()); + if (!text.equals("")) { + pp.setTextSize(20 * scaleCoefficient); + float ts = pp.measureText(text); + int wth = getWidth(); + while (ts > wth && pp.getTextSize() > (16 * scaleCoefficient)) { + pp.setTextSize(pp.getTextSize() - 1); + ts = pp.measureText(text); + } + boolean dots = false; + while (ts > wth) { + dots = true; + ts = pp.measureText(text); + text = text.substring(0, text.length() - 2); + } + if (dots) { + text += ".."; + } + setTextSize(TypedValue.COMPLEX_UNIT_PX, pp.getTextSize()); + setContentDescription(text); + } else { + setTextSize(TypedValue.COMPLEX_UNIT_PX, 7); + setContentDescription(getResources().getString(R.string.map_widget_top_text)); + } + setText(text); + invalidate(); + return true; + } + return false; + } + + } +} diff --git a/OsmAnd/src/net/osmand/plus/views/MapInfoControls.java b/OsmAnd/src/net/osmand/plus/views/mapwidgets/MapWidgetRegistry.java similarity index 80% rename from OsmAnd/src/net/osmand/plus/views/MapInfoControls.java rename to OsmAnd/src/net/osmand/plus/views/mapwidgets/MapWidgetRegistry.java index c0e38184ab..6af60622d5 100644 --- a/OsmAnd/src/net/osmand/plus/views/MapInfoControls.java +++ b/OsmAnd/src/net/osmand/plus/views/mapwidgets/MapWidgetRegistry.java @@ -1,4 +1,4 @@ -package net.osmand.plus.views; +package net.osmand.plus.views.mapwidgets; import java.util.Comparator; import java.util.EnumSet; @@ -13,6 +13,7 @@ import net.osmand.plus.ApplicationMode; import net.osmand.plus.OsmandSettings; import net.osmand.plus.OsmandSettings.CommonPreference; import net.osmand.plus.OsmandSettings.OsmandPreference; +import net.osmand.plus.views.OsmandMapTileView; import net.osmand.util.Algorithms; import android.view.View; import android.view.ViewGroup; @@ -20,18 +21,18 @@ import android.widget.LinearLayout; import android.widget.LinearLayout.LayoutParams; import android.widget.TextView; -public class MapInfoControls { +public class MapWidgetRegistry { public static final int LEFT_CONTROL = -1; public static final int RIGHT_CONTROL = 1; public static final int MAIN_CONTROL = 0; - private Set appearanceWidgets = new LinkedHashSet(); - private Set left = new TreeSet(); - private Set right = new TreeSet(); - private Set top = new TreeSet(new Comparator() { + private Set appearanceWidgets = new LinkedHashSet(); + private Set left = new TreeSet(); + private Set right = new TreeSet(); + private Set top = new TreeSet(new Comparator() { @Override - public int compare(MapInfoControlRegInfo object1, MapInfoControlRegInfo object2) { + public int compare(MapWidgetRegInfo object1, MapWidgetRegInfo object2) { if (object1.position != object2.position) { if(object1.position == LEFT_CONTROL) { return -1; @@ -52,7 +53,7 @@ public class MapInfoControls { private final OsmandSettings settings; - public MapInfoControls(OsmandSettings settings) { + public MapWidgetRegistry(OsmandSettings settings) { this.settings = settings; for(ApplicationMode ms : ApplicationMode.values() ) { @@ -70,9 +71,9 @@ public class MapInfoControls { } - public MapInfoControlRegInfo registerAppearanceWidget(int drawable, int messageId, String key, + public MapWidgetRegInfo registerAppearanceWidget(int drawable, int messageId, String key, OsmandPreference pref) { - MapInfoControlRegInfo ii = new MapInfoControlRegInfo(); + MapWidgetRegInfo ii = new MapWidgetRegInfo(); ii.defaultModes = EnumSet.noneOf(ApplicationMode.class); ii.defaultCollapsible = null; ii.key = key; @@ -86,7 +87,7 @@ public class MapInfoControls { } public void removeApperanceWidgets(String category) { - Iterator it = appearanceWidgets.iterator(); + Iterator it = appearanceWidgets.iterator(); while(it.hasNext()) { if(Algorithms.objectEquals(it.next().category, category)) { it.remove(); @@ -94,9 +95,9 @@ public class MapInfoControls { } } - public MapInfoControlRegInfo registerAppearanceWidget(int drawable, String message, String key, + public MapWidgetRegInfo registerAppearanceWidget(int drawable, String message, String key, CommonPreference pref, String subcategory) { - MapInfoControlRegInfo ii = new MapInfoControlRegInfo(); + MapWidgetRegInfo ii = new MapWidgetRegInfo(); ii.defaultModes = EnumSet.noneOf(ApplicationMode.class); ii.defaultCollapsible = null; ii.key = key; @@ -111,9 +112,9 @@ public class MapInfoControls { return ii; } - public MapInfoControlRegInfo registerTopWidget(View m, int drawable, int messageId, String key, int left, + public MapWidgetRegInfo registerTopWidget(View m, int drawable, int messageId, String key, int left, EnumSet appDefaultModes, int priorityOrder) { - MapInfoControlRegInfo ii = new MapInfoControlRegInfo(); + MapWidgetRegInfo ii = new MapWidgetRegInfo(); ii.defaultModes = appDefaultModes.clone(); ii.defaultCollapsible = null; ii.key = key; @@ -146,9 +147,9 @@ public class MapInfoControls { - public void registerSideWidget(MapInfoControl m, int drawable, int messageId, String key, boolean left, + public void registerSideWidget(BaseMapWidget m, int drawable, int messageId, String key, boolean left, EnumSet appDefaultModes, EnumSet defaultCollapsible, int priorityOrder) { - MapInfoControlRegInfo ii = new MapInfoControlRegInfo(); + MapWidgetRegInfo ii = new MapWidgetRegInfo(); ii.defaultModes = appDefaultModes.clone(); ii.defaultCollapsible = defaultCollapsible.clone(); ii.key = key; @@ -189,8 +190,8 @@ public class MapInfoControls { } } - private void restoreModes(Set set, Set mi, ApplicationMode mode) { - for (MapInfoControlRegInfo m : mi) { + private void restoreModes(Set set, Set mi, ApplicationMode mode) { + for (MapWidgetRegInfo m : mi) { if (m.preference == null) { if (m.visibleModes.contains(mode)) { set.add(m.key); @@ -203,7 +204,7 @@ public class MapInfoControls { } } - public void changeVisibility(MapInfoControlRegInfo m) { + public void changeVisibility(MapWidgetRegInfo m) { boolean selecteable = m.selecteable(); if (selecteable) { ApplicationMode mode = settings.APPLICATION_MODE.get(); @@ -247,37 +248,37 @@ public class MapInfoControls { } } - public Set getLeft() { + public Set getLeft() { return left; } - public Set getRight() { + public Set getRight() { return right; } - public Set getTop() { + public Set getTop() { return top; } - public Set getAppearanceWidgets() { + public Set getAppearanceWidgets() { return appearanceWidgets; } - public void populateStackControl(MapStackControl stack, OsmandMapTileView v, boolean left){ + public void populateStackControl(StackWidgetView stack, OsmandMapTileView v, boolean left){ ApplicationMode appMode = settings.getApplicationMode(); - Set st = left ? this.left : this.right; - for (MapInfoControlRegInfo r : st) { + Set st = left ? this.left : this.right; + for (MapWidgetRegInfo r : st) { if (r.visibleCollapsible != null && r.visibleCollapsible.contains(appMode)) { - stack.addCollapsedView((MapInfoControl) r.m); + stack.addCollapsedView((BaseMapWidget) r.m); } else if (r.visibleModes.contains(appMode)) { - stack.addStackView((MapInfoControl) r.m); + stack.addStackView((BaseMapWidget) r.m); } } } public void populateStatusBar(ViewGroup statusBar){ ApplicationMode appMode = settings.getApplicationMode(); - for (MapInfoControlRegInfo r : top) { + for (MapWidgetRegInfo r : top) { boolean main = r.position == MAIN_CONTROL; if (r.visibleModes.contains(appMode)) { LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT, main? 1 : 0); @@ -289,8 +290,8 @@ public class MapInfoControls { } } - private void resetDefault(ApplicationMode mode, Set set ){ - for(MapInfoControlRegInfo ri : set) { + private void resetDefault(ApplicationMode mode, Set set ){ + for(MapWidgetRegInfo ri : set) { if(ri.preference != null) { ri.preference.resetToDefault(); } else { @@ -326,7 +327,7 @@ public class MapInfoControls { } - public static class MapInfoControlRegInfo implements Comparable { + public static class MapWidgetRegInfo implements Comparable { public View m; public int drawable; public int messageId; @@ -369,7 +370,7 @@ public class MapInfoControls { return visibleModes.contains(mode); } - public MapInfoControlRegInfo required(ApplicationMode... modes){ + public MapWidgetRegInfo required(ApplicationMode... modes){ for(ApplicationMode ms : modes) { visibleModes.add(ms); } @@ -397,13 +398,13 @@ public class MapInfoControls { return false; if (getClass() != obj.getClass()) return false; - MapInfoControlRegInfo other = (MapInfoControlRegInfo) obj; + MapWidgetRegInfo other = (MapWidgetRegInfo) obj; if (messageId != other.messageId) return false; return true; } @Override - public int compareTo(MapInfoControlRegInfo another) { + public int compareTo(MapWidgetRegInfo another) { if (messageId == another.messageId) { return 0; } diff --git a/OsmAnd/src/net/osmand/plus/views/MiniMapControl.java b/OsmAnd/src/net/osmand/plus/views/mapwidgets/MiniMapWidget.java similarity index 83% rename from OsmAnd/src/net/osmand/plus/views/MiniMapControl.java rename to OsmAnd/src/net/osmand/plus/views/mapwidgets/MiniMapWidget.java index 8a526f3075..4181582aaa 100644 --- a/OsmAnd/src/net/osmand/plus/views/MiniMapControl.java +++ b/OsmAnd/src/net/osmand/plus/views/mapwidgets/MiniMapWidget.java @@ -1,6 +1,8 @@ -package net.osmand.plus.views; +package net.osmand.plus.views.mapwidgets; import net.osmand.plus.R; +import net.osmand.plus.views.MapInfoLayer; +import net.osmand.plus.views.OsmandMapTileView; import android.content.Context; import android.graphics.Canvas; import android.graphics.Color; @@ -11,7 +13,7 @@ import android.graphics.Paint.Style; import android.graphics.Path; import android.view.View; -public class MiniMapControl extends MapInfoControl { +public class MiniMapWidget extends BaseMapWidget { private float scaleCoefficient = MapInfoLayer.scaleCoefficient; private final float scaleMiniRoute = 0.15f; private final float width = 96 * scaleCoefficient; @@ -24,7 +26,7 @@ public class MiniMapControl extends MapInfoControl { private Paint fillBlack; protected Path miniMapPath = null; - public MiniMapControl(Context ctx, OsmandMapTileView view) { + public MiniMapWidget(Context ctx, OsmandMapTileView view) { super(ctx); this.view = view; @@ -59,13 +61,9 @@ public class MiniMapControl extends MapInfoControl { protected void onDraw(Canvas canvas) { super.onDraw(canvas); - //to change color immediately when needed + // to change color immediately when needed // could be deleted in future - if (view.getSettings().FLUORESCENT_OVERLAYS.get() && false) { - paintMiniRoute.setColor(getResources().getColor(R.color.nav_track_fluorescent)); - } else { - paintMiniRoute.setColor(getResources().getColor(R.color.nav_track)); - } + paintMiniRoute.setColor(getResources().getColor(R.color.nav_track)); if (miniMapPath != null && !miniMapPath.isEmpty()) { canvas.save(); diff --git a/OsmAnd/src/net/osmand/plus/views/NextTurnInfoControl.java b/OsmAnd/src/net/osmand/plus/views/mapwidgets/NextTurnInfoWidget.java similarity index 94% rename from OsmAnd/src/net/osmand/plus/views/NextTurnInfoControl.java rename to OsmAnd/src/net/osmand/plus/views/mapwidgets/NextTurnInfoWidget.java index 104988debf..d319e0f8dc 100644 --- a/OsmAnd/src/net/osmand/plus/views/NextTurnInfoControl.java +++ b/OsmAnd/src/net/osmand/plus/views/mapwidgets/NextTurnInfoWidget.java @@ -1,7 +1,8 @@ -package net.osmand.plus.views; +package net.osmand.plus.views.mapwidgets; import net.osmand.plus.OsmAndFormatter; import net.osmand.plus.R; +import net.osmand.plus.views.MapInfoLayer; import net.osmand.router.TurnType; import android.content.Context; import android.graphics.Canvas; @@ -13,7 +14,7 @@ import android.graphics.Path; -public class NextTurnInfoControl extends MapInfoControl { +public class NextTurnInfoWidget extends BaseMapWidget { private float scaleCoefficient = MapInfoLayer.scaleCoefficient; private float width; @@ -36,7 +37,7 @@ public class NextTurnInfoControl extends MapInfoControl { protected int turnImminent; protected boolean horisontalMini; - public NextTurnInfoControl(Context ctx, Paint textPaint, Paint subtextPaint, boolean horisontalMini) { + public NextTurnInfoWidget(Context ctx, Paint textPaint, Paint subtextPaint, boolean horisontalMini) { super(ctx); this.textPaint = textPaint; this.subtextPaint = subtextPaint; diff --git a/OsmAnd/src/net/osmand/plus/views/RouteInfoControls.java b/OsmAnd/src/net/osmand/plus/views/mapwidgets/RouteInfoWidgetsFactory.java similarity index 84% rename from OsmAnd/src/net/osmand/plus/views/RouteInfoControls.java rename to OsmAnd/src/net/osmand/plus/views/mapwidgets/RouteInfoWidgetsFactory.java index 4c8db50427..5ebe3618d5 100644 --- a/OsmAnd/src/net/osmand/plus/views/RouteInfoControls.java +++ b/OsmAnd/src/net/osmand/plus/views/mapwidgets/RouteInfoWidgetsFactory.java @@ -1,4 +1,4 @@ -package net.osmand.plus.views; +package net.osmand.plus.views.mapwidgets; import java.util.Arrays; @@ -8,7 +8,6 @@ import net.osmand.binary.RouteDataObject; import net.osmand.data.LatLon; import net.osmand.plus.OsmAndFormatter; import net.osmand.plus.OsmAndLocationProvider; -import net.osmand.plus.OsmAndLocationProvider.GPSInfo; import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandSettings; import net.osmand.plus.OsmandSettings.OsmandPreference; @@ -20,6 +19,10 @@ import net.osmand.plus.routing.AlarmInfo; import net.osmand.plus.routing.RouteCalculationResult.NextDirectionInfo; import net.osmand.plus.routing.RouteDirectionInfo; import net.osmand.plus.routing.RoutingHelper; +import net.osmand.plus.views.AnimateDraggingMapThread; +import net.osmand.plus.views.OsmandMapTileView; +import net.osmand.plus.views.RouteInfoLayer; +import net.osmand.plus.views.TurnPathHelper; import net.osmand.router.TurnType; import net.osmand.util.Algorithms; import android.content.Context; @@ -37,16 +40,16 @@ import android.graphics.drawable.Drawable; import android.text.format.DateFormat; import android.view.View; -public class RouteInfoControls { +public class RouteInfoWidgetsFactory { public float scaleCoefficient = 1; - public RouteInfoControls(float scaleCoefficient){ + public RouteInfoWidgetsFactory(float scaleCoefficient){ this.scaleCoefficient = scaleCoefficient; } - public NextTurnInfoControl createNextInfoControl(final RoutingHelper routingHelper, Context ctx, + public NextTurnInfoWidget createNextInfoControl(final RoutingHelper routingHelper, Context ctx, final OsmandSettings settings, Paint textPaint, Paint subtextPaint, boolean horisontalMini) { - final NextTurnInfoControl nextTurnInfo = new NextTurnInfoControl(ctx, textPaint, subtextPaint, horisontalMini) { + final NextTurnInfoWidget nextTurnInfo = new NextTurnInfoWidget(ctx, textPaint, subtextPaint, horisontalMini) { NextDirectionInfo calc1 = new NextDirectionInfo(); TurnType straight = TurnType.valueOf(TurnType.C, true); @@ -129,9 +132,9 @@ public class RouteInfoControls { return nextTurnInfo; } - public NextTurnInfoControl createNextNextInfoControl(final RoutingHelper routingHelper, Context ctx, + public NextTurnInfoWidget createNextNextInfoControl(final RoutingHelper routingHelper, Context ctx, final OsmandSettings settings, Paint textPaint, Paint subtextPaint, boolean horisontalMini) { - final NextTurnInfoControl nextTurnInfo = new NextTurnInfoControl(ctx, textPaint, subtextPaint, horisontalMini) { + final NextTurnInfoWidget nextTurnInfo = new NextTurnInfoWidget(ctx, textPaint, subtextPaint, horisontalMini) { NextDirectionInfo calc1 = new NextDirectionInfo(); @Override public boolean updateInfo() { @@ -212,13 +215,13 @@ public class RouteInfoControls { } - protected TextInfoControl createTimeControl(final MapActivity map, Paint paintText, Paint paintSubText){ + public TextInfoWidget createTimeControl(final MapActivity map, Paint paintText, Paint paintSubText){ final RoutingHelper routingHelper = map.getRoutingHelper(); final Drawable time = map.getResources().getDrawable(R.drawable.info_time); final Drawable timeToGo = map.getResources().getDrawable(R.drawable.info_time_to_go); final OsmandApplication ctx = map.getMyApplication(); final OsmandPreference showArrival = ctx.getSettings().SHOW_ARRIVAL_TIME_OTHERWISE_EXPECTED_TIME; - final TextInfoControl leftTimeControl = new TextInfoControl(map, 0, paintText, paintSubText) { + final TextInfoWidget leftTimeControl = new TextInfoWidget(map, 0, paintText, paintSubText) { private long cachedLeftTime = 0; @Override @@ -276,45 +279,12 @@ public class RouteInfoControls { return leftTimeControl; } - protected TextInfoControl createAltitudeControl(final MapActivity map, Paint paintText, Paint paintSubText) { - final TextInfoControl altitudeControl = new TextInfoControl(map, 0, paintText, paintSubText) { - private int cachedAlt = 0; - - @Override - public boolean updateInfo() { - // draw speed - Location loc = map.getMyApplication().getLastKnownLocation(); - if (loc != null && loc.hasAltitude()) { - double compAlt = loc.getAltitude(); - if (cachedAlt != (int) compAlt) { - cachedAlt = (int) compAlt; - String ds = OsmAndFormatter.getFormattedAlt(cachedAlt, map.getMyApplication()); - int ls = ds.lastIndexOf(' '); - if (ls == -1) { - setText(ds, null); - } else { - setText(ds.substring(0, ls), ds.substring(ls + 1)); - } - return true; - } - } else if (cachedAlt != 0) { - cachedAlt = 0; - setText(null, null); - return true; - } - return false; - } - }; - altitudeControl.setText(null, null); - altitudeControl.setImageDrawable(map.getResources().getDrawable(R.drawable.info_altitude)); - return altitudeControl; - } - protected TextInfoControl createMaxSpeedControl(final MapActivity map, Paint paintText, Paint paintSubText) { + public TextInfoWidget createMaxSpeedControl(final MapActivity map, Paint paintText, Paint paintSubText) { final RoutingHelper rh = map.getMyApplication().getRoutingHelper(); final OsmAndLocationProvider locationProvider = map.getMyApplication().getLocationProvider(); final MapViewTrackingUtilities trackingUtilities = map.getMapViewTrackingUtilities(); - final TextInfoControl speedControl = new TextInfoControl(map, 3, paintText, paintSubText) { + final TextInfoWidget speedControl = new TextInfoWidget(map, 3, paintText, paintSubText) { private float cachedSpeed = 0; @Override @@ -354,33 +324,11 @@ public class RouteInfoControls { } - protected TextInfoControl createGPSInfoControl(final MapActivity map, Paint paintText, Paint paintSubText) { - final OsmandApplication app = map.getMyApplication(); - final OsmAndLocationProvider loc = app.getLocationProvider(); - final TextInfoControl gpsInfoControl = new TextInfoControl(map, 3, paintText, paintSubText) { - private int u = -1; - private int f = -1; - - @Override - public boolean updateInfo() { - GPSInfo gpsInfo = loc.getGPSInfo(); - if(gpsInfo.usedSatellites != u || gpsInfo.foundSatellites != f) { - u = gpsInfo.usedSatellites; - f = gpsInfo.foundSatellites; - setText(gpsInfo.usedSatellites+"/"+gpsInfo.foundSatellites, ""); - return true; - } - return false; - } - }; - gpsInfoControl.setImageDrawable(app.getResources().getDrawable(R.drawable.info_gps_info)); - gpsInfoControl.setText(null, null); - return gpsInfoControl; - } - protected TextInfoControl createSpeedControl(final MapActivity map, Paint paintText, Paint paintSubText) { + + public TextInfoWidget createSpeedControl(final MapActivity map, Paint paintText, Paint paintSubText) { final OsmandApplication app = map.getMyApplication(); - final TextInfoControl speedControl = new TextInfoControl(map, 3, paintText, paintSubText) { + final TextInfoWidget speedControl = new TextInfoWidget(map, 3, paintText, paintSubText) { private float cachedSpeed = 0; @Override @@ -419,7 +367,7 @@ public class RouteInfoControls { return speedControl; } - public abstract static class DistanceToPointInfoControl extends TextInfoControl { + public abstract static class DistanceToPointInfoControl extends TextInfoWidget { private final OsmandMapTileView view; private float[] calculations = new float[1]; @@ -484,7 +432,7 @@ public class RouteInfoControls { } } - protected TextInfoControl createDistanceControl(final MapActivity map, Paint paintText, Paint paintSubText) { + public TextInfoWidget createDistanceControl(final MapActivity map, Paint paintText, Paint paintSubText) { final OsmandMapTileView view = map.getMapView(); DistanceToPointInfoControl distanceControl = new DistanceToPointInfoControl(map, 0, paintText, paintSubText, map.getResources() .getDrawable(R.drawable.info_target), view) { @@ -504,7 +452,7 @@ public class RouteInfoControls { return distanceControl; } - protected TextInfoControl createIntermediateDistanceControl(final MapActivity map, Paint paintText, Paint paintSubText) { + public TextInfoWidget createIntermediateDistanceControl(final MapActivity map, Paint paintText, Paint paintSubText) { final OsmandMapTileView view = map.getMapView(); final TargetPointsHelper targets = map.getMyApplication().getTargetPointsHelper(); DistanceToPointInfoControl distanceControl = new DistanceToPointInfoControl(map, 0, paintText, paintSubText, map.getResources() @@ -535,8 +483,8 @@ public class RouteInfoControls { return distanceControl; } - protected MiniMapControl createMiniMapControl(final RoutingHelper routingHelper, OsmandMapTileView view) { - final MiniMapControl miniMapControl = new MiniMapControl(view.getContext(), view) { + public MiniMapWidget createMiniMapControl(final RoutingHelper routingHelper, OsmandMapTileView view) { + final MiniMapWidget miniMapControl = new MiniMapWidget(view.getContext(), view) { @Override public boolean updateInfo() { boolean visible = routingHelper.isFollowingMode(); @@ -549,7 +497,7 @@ public class RouteInfoControls { } private static final float miniCoeff = 2f; - protected MapInfoControl createLanesControl(final RoutingHelper routingHelper, final OsmandMapTileView view) { + public BaseMapWidget createLanesControl(final RoutingHelper routingHelper, final OsmandMapTileView view) { final Path laneStraight = new Path(); Matrix pathTransform = new Matrix(); pathTransform.postScale(scaleCoefficient / miniCoeff, scaleCoefficient / miniCoeff); @@ -567,7 +515,7 @@ public class RouteInfoControls { final float w = 72 * scaleCoefficient / miniCoeff; - final MapInfoControl lanesControl = new MapInfoControl(view.getContext()) { + final BaseMapWidget lanesControl = new BaseMapWidget(view.getContext()) { int[] lanes = null; boolean imminent = false; @@ -649,7 +597,7 @@ public class RouteInfoControls { } - protected MapInfoControl createAlarmInfoControl(final OsmandApplication app, MapActivity ma) { + public BaseMapWidget createAlarmInfoControl(final OsmandApplication app, MapActivity ma) { final RoutingHelper rh = app.getRoutingHelper(); final OsmandSettings settings = app.getSettings(); final OsmAndLocationProvider locationProvider = app.getLocationProvider(); @@ -670,7 +618,7 @@ public class RouteInfoControls { ptext.setAntiAlias(true); ptext.setTextAlign(Align.CENTER); - final MapInfoControl alarm = new MapInfoControl(ma) { + final BaseMapWidget alarm = new BaseMapWidget(ma) { private String text = ""; private Bitmap img = null; private int imgId; @@ -688,7 +636,7 @@ public class RouteInfoControls { RouteDataObject ro = locationProvider.getLastKnownRouteSegment(); Location loc = locationProvider.getLastKnownLocation(); if(ro != null && loc != null) { - alarm = rh.calculateMostImportantAlarm(ro, loc, settings.METRIC_SYSTEM.get(), cams); + alarm = RoutingHelper.calculateMostImportantAlarm(ro, loc, settings.METRIC_SYSTEM.get(), cams); } else { alarm = null; } diff --git a/OsmAnd/src/net/osmand/plus/views/MapStackControl.java b/OsmAnd/src/net/osmand/plus/views/mapwidgets/StackWidgetView.java similarity index 84% rename from OsmAnd/src/net/osmand/plus/views/MapStackControl.java rename to OsmAnd/src/net/osmand/plus/views/mapwidgets/StackWidgetView.java index aef22bbc55..d6138f1d8b 100644 --- a/OsmAnd/src/net/osmand/plus/views/MapStackControl.java +++ b/OsmAnd/src/net/osmand/plus/views/mapwidgets/StackWidgetView.java @@ -1,9 +1,10 @@ -package net.osmand.plus.views; +package net.osmand.plus.views.mapwidgets; import java.util.ArrayList; import java.util.List; import net.osmand.plus.R; +import net.osmand.plus.views.MapInfoLayer; import android.content.Context; import android.graphics.Bitmap; import android.graphics.BitmapFactory; @@ -15,9 +16,9 @@ import android.view.View; import android.view.ViewGroup; import android.widget.ImageView; -public class MapStackControl extends ViewGroup { - List stackViews = new ArrayList(); - List collapsedViews = new ArrayList(); +public class StackWidgetView extends ViewGroup { + List stackViews = new ArrayList(); + List collapsedViews = new ArrayList(); ImageView expandView; // by default opened private boolean isCollapsed = false; @@ -27,7 +28,7 @@ public class MapStackControl extends ViewGroup { List cacheStackDrawables = new ArrayList(); private int stackDrawable; - public MapStackControl(Context context) { + public StackWidgetView(Context context) { super(context); final Bitmap arrowDown = BitmapFactory.decodeResource(context.getResources(), R.drawable.arrow_down); final Bitmap arrowUp = BitmapFactory.decodeResource(context.getResources(), R.drawable.arrow_up); @@ -52,11 +53,11 @@ public class MapStackControl extends ViewGroup { @Override public void onClick(View v) { isCollapsed = !isCollapsed; - MapStackControl.this.requestLayout(); - MapStackControl.this.invalidate(); + StackWidgetView.this.requestLayout(); + StackWidgetView.this.invalidate(); } }); - MapStackControl.this.addView(expandView); + StackWidgetView.this.addView(expandView); } public void setExpandImageDrawable(Drawable d) { @@ -73,26 +74,26 @@ public class MapStackControl extends ViewGroup { } public void updateInfo() { - for (MapInfoControl v : stackViews) { + for (BaseMapWidget v : stackViews) { v.updateInfo(); } // update even if collapsed to know if view becomes visible - for (MapInfoControl v : collapsedViews) { + for (BaseMapWidget v : collapsedViews) { v.updateInfo(); } } - public void addStackView(MapInfoControl v) { + public void addStackView(BaseMapWidget v) { stackViews.add(v); v.setShadowColor(shadowColor); - MapStackControl.this.addView(v, getChildCount()); + StackWidgetView.this.addView(v, getChildCount()); } - public void addCollapsedView(MapInfoControl v) { + public void addCollapsedView(BaseMapWidget v) { collapsedViews.add(v); v.setShadowColor(shadowColor); - MapStackControl.this.addView(v, getChildCount()); + StackWidgetView.this.addView(v, getChildCount()); } public void clearAllViews(){ @@ -103,16 +104,16 @@ public class MapStackControl extends ViewGroup { } } - public List getStackViews() { + public List getStackViews() { return stackViews; } - public List getCollapsedViews() { + public List getCollapsedViews() { return collapsedViews; } - public List getAllViews(){ - List l = new ArrayList(); + public List getAllViews(){ + List l = new ArrayList(); l.addAll(stackViews); l.addAll(collapsedViews); return l; @@ -146,7 +147,7 @@ public class MapStackControl extends ViewGroup { boolean first = true; int cacheStack = 0; if (stackViews != null) { - for (MapInfoControl c : stackViews) { + for (BaseMapWidget c : stackViews) { cacheStack++; if (c.getVisibility() != View.GONE) { c.setBackgroundDrawable(first ? topDrawable : getStackDrawable(cacheStack)); @@ -163,7 +164,7 @@ public class MapStackControl extends ViewGroup { } } isCollapsible = false; - for (MapInfoControl c : collapsedViews) { + for (BaseMapWidget c : collapsedViews) { cacheStack++; if (c.getVisibility() != View.GONE) { isCollapsible = true; @@ -249,10 +250,10 @@ public class MapStackControl extends ViewGroup { public void setShadowColor(int shadowColor) { this.shadowColor = shadowColor; - for(MapInfoControl c : stackViews) { + for(BaseMapWidget c : stackViews) { c.setShadowColor(shadowColor); } - for(MapInfoControl c : collapsedViews) { + for(BaseMapWidget c : collapsedViews) { c.setShadowColor(shadowColor); } diff --git a/OsmAnd/src/net/osmand/plus/views/TextInfoControl.java b/OsmAnd/src/net/osmand/plus/views/mapwidgets/TextInfoWidget.java similarity index 92% rename from OsmAnd/src/net/osmand/plus/views/TextInfoControl.java rename to OsmAnd/src/net/osmand/plus/views/mapwidgets/TextInfoWidget.java index af3172584b..de9c3677ef 100644 --- a/OsmAnd/src/net/osmand/plus/views/TextInfoControl.java +++ b/OsmAnd/src/net/osmand/plus/views/mapwidgets/TextInfoWidget.java @@ -1,11 +1,12 @@ -package net.osmand.plus.views; +package net.osmand.plus.views.mapwidgets; +import net.osmand.plus.views.MapInfoLayer; import android.content.Context; import android.graphics.Canvas; import android.graphics.Paint; import android.graphics.drawable.Drawable; -public class TextInfoControl extends MapInfoControl { +public class TextInfoWidget extends BaseMapWidget { String text; Paint textPaint; @@ -15,7 +16,7 @@ public class TextInfoControl extends MapInfoControl { private Drawable imageDrawable; private float scaleCoefficient; - public TextInfoControl(Context ctx, int leftMargin, Paint textPaint, Paint subtextPaint) { + public TextInfoWidget(Context ctx, int leftMargin, Paint textPaint, Paint subtextPaint) { super(ctx); scaleCoefficient = MapInfoLayer.scaleCoefficient; this.leftMargin = leftMargin; diff --git a/OsmAnd/src/net/osmand/plus/views/mapwidgets/UpdateableWidget.java b/OsmAnd/src/net/osmand/plus/views/mapwidgets/UpdateableWidget.java new file mode 100644 index 0000000000..58989a78c5 --- /dev/null +++ b/OsmAnd/src/net/osmand/plus/views/mapwidgets/UpdateableWidget.java @@ -0,0 +1,9 @@ +package net.osmand.plus.views.mapwidgets; + + +public interface UpdateableWidget { + + public boolean updateInfo(); + + +} \ No newline at end of file