Add toolbar settings
This commit is contained in:
parent
db09ed83f4
commit
fefdca8b88
9 changed files with 298 additions and 160 deletions
Binary file not shown.
Before Width: | Height: | Size: 1.3 KiB |
BIN
OsmAnd/res/drawable/poi_parking_pos_info.png
Normal file
BIN
OsmAnd/res/drawable/poi_parking_pos_info.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.2 KiB |
|
@ -9,6 +9,11 @@
|
||||||
1. All your modified/created strings are in the top of the file (to make easier find what's translated).
|
1. All your modified/created strings are in the top of the file (to make easier find what's translated).
|
||||||
PLEASE: Have a look at http://code.google.com/p/osmand/wiki/UIConsistency, it may really improve your and our work :-) Thx - Hardy
|
PLEASE: Have a look at http://code.google.com/p/osmand/wiki/UIConsistency, it may really improve your and our work :-) Thx - Hardy
|
||||||
-->
|
-->
|
||||||
|
<string name="map_widget_map_select">Map selection</string>
|
||||||
|
<string name="map_widget_back_to_loc">Where am I</string>
|
||||||
|
<string name="map_widget_lock_screen">Lock screen</string>
|
||||||
|
<string name="map_widget_compass">Compass</string>
|
||||||
|
<string name="map_widget_top_stack">Status bar</string>
|
||||||
<string name="map_widget_reset">Reset to default</string>
|
<string name="map_widget_reset">Reset to default</string>
|
||||||
<string name="map_widget_right_stack">Right side</string>
|
<string name="map_widget_right_stack">Right side</string>
|
||||||
<string name="map_widget_left_stack">Left side</string>
|
<string name="map_widget_left_stack">Left side</string>
|
||||||
|
|
|
@ -1,12 +1,17 @@
|
||||||
package net.osmand.plus.background;
|
package net.osmand.plus.background;
|
||||||
|
|
||||||
|
import java.util.EnumSet;
|
||||||
|
|
||||||
import net.osmand.plus.NavigationService;
|
import net.osmand.plus.NavigationService;
|
||||||
import net.osmand.plus.OsmandApplication;
|
import net.osmand.plus.OsmandApplication;
|
||||||
import net.osmand.plus.OsmandPlugin;
|
import net.osmand.plus.OsmandPlugin;
|
||||||
import net.osmand.plus.OsmandSettings;
|
import net.osmand.plus.OsmandSettings;
|
||||||
import net.osmand.plus.R;
|
import net.osmand.plus.R;
|
||||||
|
import net.osmand.plus.activities.ApplicationMode;
|
||||||
import net.osmand.plus.activities.MapActivity;
|
import net.osmand.plus.activities.MapActivity;
|
||||||
import net.osmand.plus.activities.SettingsActivity;
|
import net.osmand.plus.activities.SettingsActivity;
|
||||||
|
import net.osmand.plus.views.ImageViewControl;
|
||||||
|
import net.osmand.plus.views.MapInfoLayer;
|
||||||
import net.osmand.plus.views.OsmandMapTileView;
|
import net.osmand.plus.views.OsmandMapTileView;
|
||||||
import android.app.AlertDialog;
|
import android.app.AlertDialog;
|
||||||
import android.app.AlertDialog.Builder;
|
import android.app.AlertDialog.Builder;
|
||||||
|
@ -29,9 +34,6 @@ import android.widget.AdapterView.OnItemSelectedListener;
|
||||||
import android.widget.ArrayAdapter;
|
import android.widget.ArrayAdapter;
|
||||||
import android.widget.CheckBox;
|
import android.widget.CheckBox;
|
||||||
import android.widget.CompoundButton;
|
import android.widget.CompoundButton;
|
||||||
import android.widget.ImageView;
|
|
||||||
import android.widget.LinearLayout;
|
|
||||||
import android.widget.LinearLayout.LayoutParams;
|
|
||||||
import android.widget.Spinner;
|
import android.widget.Spinner;
|
||||||
|
|
||||||
public class OsmandBackgroundServicePlugin extends OsmandPlugin {
|
public class OsmandBackgroundServicePlugin extends OsmandPlugin {
|
||||||
|
@ -72,10 +74,17 @@ public class OsmandBackgroundServicePlugin extends OsmandPlugin {
|
||||||
@Override
|
@Override
|
||||||
public void registerLayers(MapActivity activity) {
|
public void registerLayers(MapActivity activity) {
|
||||||
backgroundServiceLayer = new OsmandBackgroundServiceLayer(activity);
|
backgroundServiceLayer = new OsmandBackgroundServiceLayer(activity);
|
||||||
|
MapInfoLayer layer = activity.getMapLayers().getMapInfoLayer();
|
||||||
|
ImageViewControl lockView = createBgServiceView( activity.getMapView(), activity);
|
||||||
|
// TODO icon
|
||||||
|
layer.getMapInfoControls().registerTopWidget(lockView, R.drawable.monitoring_rec_big, R.string.map_widget_lock_screen, "lock_view", true, EnumSet.allOf(ApplicationMode.class), 10);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void updateLayers(OsmandMapTileView mapView, MapActivity activity) {
|
public void updateLayers(OsmandMapTileView mapView, MapActivity activity) {
|
||||||
|
if(backgroundServiceLayer == null) {
|
||||||
|
registerLayers(activity);
|
||||||
|
}
|
||||||
if (isScreenLocked) {
|
if (isScreenLocked) {
|
||||||
mapView.addLayer(backgroundServiceLayer, mapView.getLayers().size());
|
mapView.addLayer(backgroundServiceLayer, mapView.getLayers().size());
|
||||||
} else {
|
} else {
|
||||||
|
@ -159,16 +168,17 @@ public class OsmandBackgroundServicePlugin extends OsmandPlugin {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @param statusBar
|
|
||||||
* @param view
|
|
||||||
* @param map
|
|
||||||
*/
|
*/
|
||||||
public void createBgServiceView(final LinearLayout statusBar, final OsmandMapTileView view, final MapActivity map) {
|
public ImageViewControl createBgServiceView(final OsmandMapTileView view, final MapActivity map) {
|
||||||
// TODO Lock icons
|
// TODO Lock icons
|
||||||
final Drawable lock = view.getResources().getDrawable(R.drawable.monitoring_rec_big);
|
final Drawable lock = view.getResources().getDrawable(R.drawable.monitoring_rec_big);
|
||||||
final Drawable unLock = view.getResources().getDrawable(R.drawable.monitoring_rec_inactive);
|
final Drawable unLock = view.getResources().getDrawable(R.drawable.monitoring_rec_inactive);
|
||||||
|
final ImageViewControl lockView = new ImageViewControl(view.getContext()) {
|
||||||
final ImageView lockView = new ImageView(view.getContext());
|
@Override
|
||||||
|
public boolean updateInfo() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
if (isScreenLocked) {
|
if (isScreenLocked) {
|
||||||
lockView.setBackgroundDrawable(lock);
|
lockView.setBackgroundDrawable(lock);
|
||||||
|
@ -189,7 +199,7 @@ public class OsmandBackgroundServicePlugin extends OsmandPlugin {
|
||||||
}
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
statusBar.addView(lockView, new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
|
return lockView;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
12
OsmAnd/src/net/osmand/plus/views/ImageViewControl.java
Normal file
12
OsmAnd/src/net/osmand/plus/views/ImageViewControl.java
Normal file
|
@ -0,0 +1,12 @@
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,9 @@
|
||||||
|
package net.osmand.plus.views;
|
||||||
|
|
||||||
|
|
||||||
|
public interface MapControlUpdateable {
|
||||||
|
|
||||||
|
public boolean updateInfo();
|
||||||
|
|
||||||
|
|
||||||
|
}
|
|
@ -7,7 +7,7 @@ import android.graphics.Rect;
|
||||||
import android.graphics.drawable.Drawable;
|
import android.graphics.drawable.Drawable;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
|
|
||||||
public abstract class MapInfoControl extends View {
|
public abstract class MapInfoControl extends View implements MapControlUpdateable {
|
||||||
int width = 0;
|
int width = 0;
|
||||||
int height = 0;
|
int height = 0;
|
||||||
Rect padding = new Rect();
|
Rect padding = new Rect();
|
||||||
|
@ -56,6 +56,7 @@ public abstract class MapInfoControl extends View {
|
||||||
canvas.clipRect(0, 0, getWWidth(),getWHeight());
|
canvas.clipRect(0, 0, getWWidth(),getWHeight());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public boolean updateInfo() { return false; }
|
public boolean updateInfo() { return false; }
|
||||||
|
|
||||||
protected boolean updateVisibility(boolean visible) {
|
protected boolean updateVisibility(boolean visible) {
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
package net.osmand.plus.views;
|
package net.osmand.plus.views;
|
||||||
|
|
||||||
|
import java.util.Comparator;
|
||||||
import java.util.EnumSet;
|
import java.util.EnumSet;
|
||||||
import java.util.LinkedHashMap;
|
import java.util.LinkedHashMap;
|
||||||
import java.util.LinkedHashSet;
|
import java.util.LinkedHashSet;
|
||||||
|
@ -7,27 +8,30 @@ import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.TreeSet;
|
import java.util.TreeSet;
|
||||||
|
|
||||||
|
import android.view.View;
|
||||||
|
import android.view.ViewGroup;
|
||||||
|
import android.widget.LinearLayout;
|
||||||
|
import android.widget.TextView;
|
||||||
|
import android.widget.LinearLayout.LayoutParams;
|
||||||
|
|
||||||
import net.osmand.plus.OsmandSettings;
|
import net.osmand.plus.OsmandSettings;
|
||||||
import net.osmand.plus.activities.ApplicationMode;
|
import net.osmand.plus.activities.ApplicationMode;
|
||||||
import android.graphics.Paint;
|
|
||||||
|
|
||||||
public class MapInfoControls {
|
public class MapInfoControls {
|
||||||
|
|
||||||
private Set<MapInfoControlRegInfo> left = new TreeSet<MapInfoControls.MapInfoControlRegInfo>();
|
private Set<MapInfoControlRegInfo> left = new TreeSet<MapInfoControls.MapInfoControlRegInfo>();
|
||||||
private Set<MapInfoControlRegInfo> right = new TreeSet<MapInfoControls.MapInfoControlRegInfo>();
|
private Set<MapInfoControlRegInfo> right = new TreeSet<MapInfoControls.MapInfoControlRegInfo>();
|
||||||
|
private Set<MapInfoControlRegInfo> topleft = new TreeSet<MapInfoControls.MapInfoControlRegInfo>();
|
||||||
|
private Set<MapInfoControlRegInfo> topright = new TreeSet<MapInfoControls.MapInfoControlRegInfo>(new Comparator<MapInfoControlRegInfo>() {
|
||||||
|
@Override
|
||||||
|
public int compare(MapInfoControlRegInfo object1, MapInfoControlRegInfo object2) {
|
||||||
|
return -object1.compareTo(object2);
|
||||||
|
}
|
||||||
|
});
|
||||||
private Map<ApplicationMode, Set<String>> visibleElements = new LinkedHashMap<ApplicationMode, Set<String>>();
|
private Map<ApplicationMode, Set<String>> visibleElements = new LinkedHashMap<ApplicationMode, Set<String>>();
|
||||||
private final OsmandSettings settings;
|
private final OsmandSettings settings;
|
||||||
|
|
||||||
|
|
||||||
public interface MapInfoControlFactoryMethod {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param mapView
|
|
||||||
* @param paints array of paints (4) 0 - normal, 1 - subtext, 2 - small, 3 - small subtext
|
|
||||||
*/
|
|
||||||
public MapInfoControl createControl(OsmandMapTileView mapView, Paint[] paints);
|
|
||||||
}
|
|
||||||
|
|
||||||
public MapInfoControls(OsmandSettings settings) {
|
public MapInfoControls(OsmandSettings settings) {
|
||||||
this.settings = settings;
|
this.settings = settings;
|
||||||
|
|
||||||
|
@ -46,6 +50,36 @@ public class MapInfoControls {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public MapInfoControlRegInfo registerTopWidget(View m, int drawable, int messageId, String key, boolean left,
|
||||||
|
EnumSet<ApplicationMode> appDefaultModes, int priorityOrder) {
|
||||||
|
MapInfoControlRegInfo ii = new MapInfoControlRegInfo();
|
||||||
|
ii.defaultModes = appDefaultModes.clone();
|
||||||
|
ii.defaultCollapsible = null;
|
||||||
|
ii.key = key;
|
||||||
|
ii.visibleModes = EnumSet.noneOf(ApplicationMode.class);
|
||||||
|
ii.visibleCollapsible = null;
|
||||||
|
for(ApplicationMode ms : ApplicationMode.values() ) {
|
||||||
|
boolean def = appDefaultModes.contains(ms);
|
||||||
|
Set<String> set = visibleElements.get(ms);
|
||||||
|
if(set != null) {
|
||||||
|
def = set.contains(key);
|
||||||
|
}
|
||||||
|
if(def){
|
||||||
|
ii.visibleModes.add(ms);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ii.drawable = drawable;
|
||||||
|
ii.messageId = messageId;
|
||||||
|
ii.m = m;
|
||||||
|
ii.priorityOrder = priorityOrder;
|
||||||
|
if(left) {
|
||||||
|
this.topleft.add(ii);
|
||||||
|
} else {
|
||||||
|
this.topright.add(ii);
|
||||||
|
}
|
||||||
|
return ii;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public void registerSideWidget(MapInfoControl m, int drawable, int messageId, String key, boolean left,
|
public void registerSideWidget(MapInfoControl m, int drawable, int messageId, String key, boolean left,
|
||||||
|
@ -85,7 +119,7 @@ public class MapInfoControls {
|
||||||
for(MapInfoControlRegInfo m : mi){
|
for(MapInfoControlRegInfo m : mi){
|
||||||
if(m.visibleModes.contains(mode)) {
|
if(m.visibleModes.contains(mode)) {
|
||||||
set.add(m.key) ;
|
set.add(m.key) ;
|
||||||
} else if(m.visibleCollapsible.contains(mode)) {
|
} else if(m.visibleCollapsible != null && m.visibleCollapsible.contains(mode)) {
|
||||||
set.add("+"+m.key) ;
|
set.add("+"+m.key) ;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -97,14 +131,18 @@ public class MapInfoControls {
|
||||||
LinkedHashSet<String> set = new LinkedHashSet<String>();
|
LinkedHashSet<String> set = new LinkedHashSet<String>();
|
||||||
restoreModes(set, left, mode);
|
restoreModes(set, left, mode);
|
||||||
restoreModes(set, right, mode);
|
restoreModes(set, right, mode);
|
||||||
|
restoreModes(set, topleft, mode);
|
||||||
|
restoreModes(set, topright, mode);
|
||||||
this.visibleElements.put(mode, set);
|
this.visibleElements.put(mode, set);
|
||||||
}
|
}
|
||||||
this.visibleElements.get(mode).remove(m.key);
|
this.visibleElements.get(mode).remove(m.key);
|
||||||
this.visibleElements.get(mode).remove("+" + m.key);
|
this.visibleElements.get(mode).remove("+" + m.key);
|
||||||
m.visibleModes.remove(mode);
|
m.visibleModes.remove(mode);
|
||||||
m.visibleCollapsible.remove(mode);
|
if(m.visibleCollapsible != null) {
|
||||||
|
m.visibleCollapsible.remove(mode);
|
||||||
|
}
|
||||||
if(visible) {
|
if(visible) {
|
||||||
if(collapse) {
|
if(collapse && m.visibleCollapsible != null) {
|
||||||
m.visibleCollapsible.add(mode);
|
m.visibleCollapsible.add(mode);
|
||||||
this.visibleElements.get(mode).add("+" + m.key);
|
this.visibleElements.get(mode).add("+" + m.key);
|
||||||
} else {
|
} else {
|
||||||
|
@ -128,28 +166,51 @@ public class MapInfoControls {
|
||||||
return right;
|
return right;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void registerTopBarButton(MapInfoControlFactoryMethod m, int drawable, int messageId, boolean left,
|
public Set<MapInfoControlRegInfo> getTopLeft() {
|
||||||
EnumSet<ApplicationMode> appModes, int priorityOrder) {
|
return topleft;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Set<MapInfoControlRegInfo> getTopRight() {
|
||||||
|
return topright;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void populateStackControl(MapStackControl stack, OsmandMapTileView v, boolean left){
|
public void populateStackControl(MapStackControl stack, OsmandMapTileView v, boolean left){
|
||||||
ApplicationMode appMode = settings.getApplicationMode();
|
ApplicationMode appMode = settings.getApplicationMode();
|
||||||
Set<MapInfoControlRegInfo> st = left ? this.left : this.right;
|
Set<MapInfoControlRegInfo> st = left ? this.left : this.right;
|
||||||
for (MapInfoControlRegInfo r : st) {
|
for (MapInfoControlRegInfo r : st) {
|
||||||
if (r.visibleCollapsible.contains(appMode)) {
|
if (r.visibleCollapsible != null && r.visibleCollapsible.contains(appMode)) {
|
||||||
stack.addCollapsedView(r.m);
|
stack.addCollapsedView((MapInfoControl) r.m);
|
||||||
} else if (r.visibleModes.contains(appMode)) {
|
} else if (r.visibleModes.contains(appMode)) {
|
||||||
stack.addStackView(r.m);
|
stack.addStackView((MapInfoControl) r.m);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void populateStatusBar(ViewGroup statusBar, TextView topView){
|
||||||
|
ApplicationMode appMode = settings.getApplicationMode();
|
||||||
|
for (MapInfoControlRegInfo r : topleft) {
|
||||||
|
if (r.visibleModes.contains(appMode)) {
|
||||||
|
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
|
||||||
|
statusBar.addView((View) r.m, params);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
LayoutParams pms = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.FILL_PARENT, LinearLayout.LayoutParams.FILL_PARENT, 1);
|
||||||
|
statusBar.addView(topView, pms);
|
||||||
|
for (MapInfoControlRegInfo r : topright) {
|
||||||
|
if (r.visibleModes.contains(appMode)) {
|
||||||
|
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
|
||||||
|
statusBar.addView((View) r.m, params);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void resetDefault(ApplicationMode mode, Set<MapInfoControlRegInfo> set ){
|
private void resetDefault(ApplicationMode mode, Set<MapInfoControlRegInfo> set ){
|
||||||
for(MapInfoControlRegInfo ri : set) {
|
for(MapInfoControlRegInfo ri : set) {
|
||||||
ri.visibleCollapsible.remove(mode);
|
if(ri.visibleCollapsible != null) {
|
||||||
|
ri.visibleCollapsible.remove(mode);
|
||||||
|
}
|
||||||
ri.visibleModes.remove(mode);
|
ri.visibleModes.remove(mode);
|
||||||
if(ri.defaultCollapsible.contains(mode)) {
|
if(ri.defaultCollapsible != null && ri.defaultCollapsible.contains(mode)) {
|
||||||
ri.visibleCollapsible.add(mode);
|
ri.visibleCollapsible.add(mode);
|
||||||
}
|
}
|
||||||
if(ri.defaultModes.contains(mode)) {
|
if(ri.defaultModes.contains(mode)) {
|
||||||
|
@ -162,6 +223,8 @@ public class MapInfoControls {
|
||||||
ApplicationMode appMode = settings.getApplicationMode();
|
ApplicationMode appMode = settings.getApplicationMode();
|
||||||
resetDefault(appMode, left);
|
resetDefault(appMode, left);
|
||||||
resetDefault(appMode, right);
|
resetDefault(appMode, right);
|
||||||
|
resetDefault(appMode, topleft);
|
||||||
|
resetDefault(appMode, topright);
|
||||||
this.visibleElements.put(appMode, null);
|
this.visibleElements.put(appMode, null);
|
||||||
settings.MAP_INFO_CONTROLS.set("");
|
settings.MAP_INFO_CONTROLS.set("");
|
||||||
}
|
}
|
||||||
|
@ -176,7 +239,7 @@ public class MapInfoControls {
|
||||||
|
|
||||||
|
|
||||||
public static class MapInfoControlRegInfo implements Comparable<MapInfoControlRegInfo> {
|
public static class MapInfoControlRegInfo implements Comparable<MapInfoControlRegInfo> {
|
||||||
public MapInfoControl m;
|
public View m;
|
||||||
public int drawable;
|
public int drawable;
|
||||||
public int messageId;
|
public int messageId;
|
||||||
private String key;
|
private String key;
|
||||||
|
@ -187,12 +250,24 @@ public class MapInfoControls {
|
||||||
public int priorityOrder;
|
public int priorityOrder;
|
||||||
|
|
||||||
public boolean visibleCollapsed(ApplicationMode mode){
|
public boolean visibleCollapsed(ApplicationMode mode){
|
||||||
return visibleCollapsible.contains(mode);
|
return visibleCollapsible != null && visibleCollapsible.contains(mode);
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean collapseEnabled(ApplicationMode mode){
|
||||||
|
return visibleCollapsible != null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean visible(ApplicationMode mode){
|
public boolean visible(ApplicationMode mode){
|
||||||
return visibleModes.contains(mode);
|
return visibleModes.contains(mode);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public MapInfoControlRegInfo required(ApplicationMode... modes){
|
||||||
|
for(ApplicationMode ms : modes) {
|
||||||
|
visibleModes.add(ms);
|
||||||
|
}
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int hashCode() {
|
public int hashCode() {
|
||||||
return messageId;
|
return messageId;
|
||||||
|
|
|
@ -4,12 +4,10 @@ package net.osmand.plus.views;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.EnumSet;
|
import java.util.EnumSet;
|
||||||
|
|
||||||
import net.osmand.plus.OsmandPlugin;
|
|
||||||
import net.osmand.plus.OsmandSettings;
|
import net.osmand.plus.OsmandSettings;
|
||||||
import net.osmand.plus.R;
|
import net.osmand.plus.R;
|
||||||
import net.osmand.plus.activities.ApplicationMode;
|
import net.osmand.plus.activities.ApplicationMode;
|
||||||
import net.osmand.plus.activities.MapActivity;
|
import net.osmand.plus.activities.MapActivity;
|
||||||
import net.osmand.plus.background.OsmandBackgroundServicePlugin;
|
|
||||||
import net.osmand.plus.routing.RouteDirectionInfo;
|
import net.osmand.plus.routing.RouteDirectionInfo;
|
||||||
import net.osmand.plus.routing.RoutingHelper;
|
import net.osmand.plus.routing.RoutingHelper;
|
||||||
import net.osmand.plus.views.MapInfoControls.MapInfoControlRegInfo;
|
import net.osmand.plus.views.MapInfoControls.MapInfoControlRegInfo;
|
||||||
|
@ -59,23 +57,19 @@ public class MapInfoLayer extends OsmandMapLayer {
|
||||||
private Paint paintSmallSubText;
|
private Paint paintSmallSubText;
|
||||||
private Paint paintImg;
|
private Paint paintImg;
|
||||||
|
|
||||||
private float cachedRotate = 0;
|
|
||||||
|
|
||||||
// layout pseudo-constants
|
// layout pseudo-constants
|
||||||
private int STATUS_BAR_MARGIN_X = -4;
|
private int STATUS_BAR_MARGIN_X = -4;
|
||||||
|
|
||||||
private ImageView backToLocation;
|
private ImageView backToLocation;
|
||||||
private ImageView compassView;
|
|
||||||
private View progressBar;
|
private View progressBar;
|
||||||
|
|
||||||
// groups
|
// groups
|
||||||
private MapStackControl rightStack;
|
private MapStackControl rightStack;
|
||||||
private MapStackControl leftStack;
|
private MapStackControl leftStack;
|
||||||
private ViewGroup statusBar;
|
private LinearLayout statusBar;
|
||||||
private MapInfoControl lanesControl;
|
private MapInfoControl lanesControl;
|
||||||
private MapInfoControl alarmControl;
|
private MapInfoControl alarmControl;
|
||||||
private TextView topText;
|
private TextView topText;
|
||||||
|
|
||||||
private MapInfoControls mapInfoControls;
|
private MapInfoControls mapInfoControls;
|
||||||
|
|
||||||
public MapInfoLayer(MapActivity map, RouteLayer layer){
|
public MapInfoLayer(MapActivity map, RouteLayer layer){
|
||||||
|
@ -150,10 +144,8 @@ public class MapInfoLayer extends OsmandMapLayer {
|
||||||
@Override
|
@Override
|
||||||
public void initLayer(final OsmandMapTileView view) {
|
public void initLayer(final OsmandMapTileView view) {
|
||||||
this.view = view;
|
this.view = view;
|
||||||
|
|
||||||
registerAllControls();
|
registerAllControls();
|
||||||
createControls();
|
createControls();
|
||||||
applyTheme();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void applyTheme() {
|
public void applyTheme() {
|
||||||
|
@ -179,7 +171,8 @@ public class MapInfoLayer extends OsmandMapLayer {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void registerAllControls(){
|
public void registerAllControls(){
|
||||||
statusBar = createStatusBar();
|
statusBar = new LinearLayout(view.getContext());
|
||||||
|
statusBar.setOrientation(LinearLayout.HORIZONTAL);
|
||||||
RouteInfoControls ric = new RouteInfoControls(scaleCoefficient);
|
RouteInfoControls ric = new RouteInfoControls(scaleCoefficient);
|
||||||
lanesControl = ric.createLanesControl(view.getApplication().getRoutingHelper(), view);
|
lanesControl = ric.createLanesControl(view.getApplication().getRoutingHelper(), view);
|
||||||
lanesControl.setBackgroundDrawable(view.getResources().getDrawable(R.drawable.box_free));
|
lanesControl.setBackgroundDrawable(view.getResources().getDrawable(R.drawable.box_free));
|
||||||
|
@ -212,6 +205,15 @@ public class MapInfoLayer extends OsmandMapLayer {
|
||||||
TextInfoControl alt = ric.createAltitudeControl(map, paintText, paintSubText);
|
TextInfoControl alt = ric.createAltitudeControl(map, paintText, paintSubText);
|
||||||
mapInfoControls.registerSideWidget(alt, R.drawable.ic_altitude, R.string.map_widget_altitude, "altitude", false, EnumSet.of(ApplicationMode.PEDESTRIAN), none, 20);
|
mapInfoControls.registerSideWidget(alt, R.drawable.ic_altitude, R.string.map_widget_altitude, "altitude", false, EnumSet.of(ApplicationMode.PEDESTRIAN), none, 20);
|
||||||
|
|
||||||
|
ImageViewControl compassView = createCompassView(map);
|
||||||
|
mapInfoControls.registerTopWidget(compassView, R.drawable.compass, R.string.map_widget_compass, "compass", true, all, 5);
|
||||||
|
backToLocation = createBackToLocation(map);
|
||||||
|
mapInfoControls.registerTopWidget(backToLocation, R.drawable.default_mode_small, R.string.map_widget_back_to_loc, "back_to_location", false, all, 5);
|
||||||
|
|
||||||
|
View globusAndProgress = createGlobusAndProgress();
|
||||||
|
mapInfoControls.registerTopWidget(globusAndProgress, R.drawable.globus, R.string.map_widget_map_select, "progress", false, all, 10).required(ApplicationMode.values());
|
||||||
|
|
||||||
|
topText = new TopTextView(routingHelper, map);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void recreateControls(){
|
public void recreateControls(){
|
||||||
|
@ -222,6 +224,9 @@ public class MapInfoLayer extends OsmandMapLayer {
|
||||||
mapInfoControls.populateStackControl(leftStack, view, true);
|
mapInfoControls.populateStackControl(leftStack, view, true);
|
||||||
leftStack.requestLayout();
|
leftStack.requestLayout();
|
||||||
rightStack.requestLayout();
|
rightStack.requestLayout();
|
||||||
|
|
||||||
|
statusBar.removeAllViews();
|
||||||
|
mapInfoControls.populateStatusBar(statusBar, topText);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void createControls() {
|
public void createControls() {
|
||||||
|
@ -233,7 +238,8 @@ public class MapInfoLayer extends OsmandMapLayer {
|
||||||
// 2. Preparations
|
// 2. Preparations
|
||||||
Rect topRectPadding = new Rect();
|
Rect topRectPadding = new Rect();
|
||||||
view.getResources().getDrawable(R.drawable.box_top).getPadding(topRectPadding);
|
view.getResources().getDrawable(R.drawable.box_top).getPadding(topRectPadding);
|
||||||
|
// for measurement
|
||||||
|
statusBar.addView(backToLocation);
|
||||||
STATUS_BAR_MARGIN_X = (int) (STATUS_BAR_MARGIN_X * scaleCoefficient);
|
STATUS_BAR_MARGIN_X = (int) (STATUS_BAR_MARGIN_X * scaleCoefficient);
|
||||||
statusBar.measure(MeasureSpec.UNSPECIFIED, MeasureSpec.UNSPECIFIED);
|
statusBar.measure(MeasureSpec.UNSPECIFIED, MeasureSpec.UNSPECIFIED);
|
||||||
Rect statusBarPadding = new Rect();
|
Rect statusBarPadding = new Rect();
|
||||||
|
@ -284,6 +290,8 @@ public class MapInfoLayer extends OsmandMapLayer {
|
||||||
parent.addView(alarmControl);
|
parent.addView(alarmControl);
|
||||||
alarmControl.setVisibility(View.GONE);
|
alarmControl.setVisibility(View.GONE);
|
||||||
lanesControl.setVisibility(View.GONE);
|
lanesControl.setVisibility(View.GONE);
|
||||||
|
|
||||||
|
// update and create controls
|
||||||
applyTheme();
|
applyTheme();
|
||||||
recreateControls();
|
recreateControls();
|
||||||
}
|
}
|
||||||
|
@ -293,6 +301,9 @@ public class MapInfoLayer extends OsmandMapLayer {
|
||||||
|
|
||||||
final ArrayList<Object> list = new ArrayList<Object>();
|
final ArrayList<Object> list = new ArrayList<Object>();
|
||||||
list.add(map.getString(R.string.map_widget_reset));
|
list.add(map.getString(R.string.map_widget_reset));
|
||||||
|
list.add(map.getString(R.string.map_widget_top_stack));
|
||||||
|
list.addAll(mapInfoControls.getTopLeft());
|
||||||
|
list.addAll(mapInfoControls.getTopRight());
|
||||||
list.add(map.getString(R.string.map_widget_right_stack));
|
list.add(map.getString(R.string.map_widget_right_stack));
|
||||||
list.addAll(mapInfoControls.getRight());
|
list.addAll(mapInfoControls.getRight());
|
||||||
list.add(map.getString(R.string.map_widget_left_stack));
|
list.add(map.getString(R.string.map_widget_left_stack));
|
||||||
|
@ -309,19 +320,20 @@ public class MapInfoLayer extends OsmandMapLayer {
|
||||||
if (v == null) {
|
if (v == null) {
|
||||||
v = map.getLayoutInflater().inflate(R.layout.layers_list_activity_item, null);
|
v = map.getLayoutInflater().inflate(R.layout.layers_list_activity_item, null);
|
||||||
}
|
}
|
||||||
TextView tv = (TextView) v.findViewById(R.id.title);
|
final TextView tv = (TextView) v.findViewById(R.id.title);
|
||||||
final CheckBox ch = ((CheckBox) v.findViewById(R.id.check_item));
|
final CheckBox ch = ((CheckBox) v.findViewById(R.id.check_item));
|
||||||
Object o = list.get(position);
|
Object o = list.get(position);
|
||||||
if(o instanceof MapInfoControlRegInfo) {
|
if(o instanceof MapInfoControlRegInfo) {
|
||||||
final MapInfoControlRegInfo mi = (MapInfoControlRegInfo) o;
|
final MapInfoControlRegInfo mi = (MapInfoControlRegInfo) o;
|
||||||
tv.setText(map.getString(mi.messageId));
|
String s = mi.visibleCollapsed(mode)? " - " : " ";
|
||||||
|
tv.setText(s +map.getString(mi.messageId) +s);
|
||||||
// Put the image on the TextView
|
// Put the image on the TextView
|
||||||
if (mi.drawable != 0) {
|
if (mi.drawable != 0) {
|
||||||
tv.setPadding((int) (12 *scaleCoefficient), 0, 0, 0);
|
tv.setPadding((int) (12 *scaleCoefficient), 0, 0, 0);
|
||||||
tv.setCompoundDrawablesWithIntrinsicBounds(mi.drawable, 0, 0, 0);
|
tv.setCompoundDrawablesWithIntrinsicBounds(mi.drawable, 0, 0, 0);
|
||||||
} else {
|
} else {
|
||||||
tv.setCompoundDrawablesWithIntrinsicBounds(0, 0, 0, 0);
|
tv.setCompoundDrawablesWithIntrinsicBounds(0, 0, 0, 0);
|
||||||
tv.setPadding((int) (27 *scaleCoefficient), 0, 0, 0);
|
tv.setPadding((int) (30 *scaleCoefficient), 0, 0, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean check = mi.visibleCollapsed(mode) || mi.visible(mode);
|
boolean check = mi.visibleCollapsed(mode) || mi.visible(mode);
|
||||||
|
@ -331,10 +343,17 @@ public class MapInfoLayer extends OsmandMapLayer {
|
||||||
@Override
|
@Override
|
||||||
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
|
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
|
||||||
if(!isChecked) {
|
if(!isChecked) {
|
||||||
mapInfoControls.changeVisibility(mi, false, false);
|
if(mi.visible(mode) && mi.collapseEnabled(mode)) {
|
||||||
|
mapInfoControls.changeVisibility(mi, true, true);
|
||||||
|
ch.setChecked(true);
|
||||||
|
} else {
|
||||||
|
mapInfoControls.changeVisibility(mi, false, false);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
mapInfoControls.changeVisibility(mi, true, false);
|
mapInfoControls.changeVisibility(mi, true, false);
|
||||||
}
|
}
|
||||||
|
String s = mi.visibleCollapsed(mode) ? " - " : " ";
|
||||||
|
tv.setText(s + map.getString(mi.messageId) + s);
|
||||||
recreateControls();
|
recreateControls();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -398,60 +417,16 @@ public class MapInfoLayer extends OsmandMapLayer {
|
||||||
// update data on draw
|
// update data on draw
|
||||||
rightStack.updateInfo();
|
rightStack.updateInfo();
|
||||||
leftStack.updateInfo();
|
leftStack.updateInfo();
|
||||||
if(view.getRotate() != cachedRotate) {
|
|
||||||
cachedRotate = view.getRotate();
|
|
||||||
compassView.invalidate();
|
|
||||||
}
|
|
||||||
lanesControl.updateInfo();
|
lanesControl.updateInfo();
|
||||||
alarmControl.updateInfo();
|
alarmControl.updateInfo();
|
||||||
updateTopText();
|
for(int i=0; i<statusBar.getChildCount(); i++) {
|
||||||
|
View v = statusBar.getChildAt(i);
|
||||||
|
if(v instanceof MapControlUpdateable) {
|
||||||
|
((MapControlUpdateable)v).updateInfo();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updateTopText() {
|
|
||||||
String text = null;
|
|
||||||
RoutingHelper helper = routeLayer.getHelper();
|
|
||||||
if (routeLayer != null && helper.isRouteCalculated()) {
|
|
||||||
if (helper.isFollowingMode()) {
|
|
||||||
text = helper.getCurrentName();
|
|
||||||
} else {
|
|
||||||
int di = map.getMapLayers().getRouteInfoLayer().getDirectionInfo();
|
|
||||||
if (di >= 0 && map.getMapLayers().getRouteInfoLayer().isVisible()) {
|
|
||||||
RouteDirectionInfo next = helper.getRouteDirections().get(di);
|
|
||||||
text = helper.formatStreetName(next.getStreetName(), next.getRef());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if(text == null) {
|
|
||||||
text = "";
|
|
||||||
}
|
|
||||||
if (!text.equals(topText.getText().toString())) {
|
|
||||||
TextPaint pp = new TextPaint(topText.getPaint());
|
|
||||||
if (!text.equals("")) {
|
|
||||||
pp.setTextSize(25 * scaleCoefficient);
|
|
||||||
float ts = pp.measureText(text);
|
|
||||||
int wth = topText.getWidth();
|
|
||||||
while (ts > wth && pp.getTextSize() > (14 * 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 += "..";
|
|
||||||
}
|
|
||||||
topText.setTextSize(TypedValue.COMPLEX_UNIT_PX, pp.getTextSize());
|
|
||||||
} else {
|
|
||||||
topText.setTextSize(TypedValue.COMPLEX_UNIT_PX, 7);
|
|
||||||
}
|
|
||||||
topText.setText(text);
|
|
||||||
topText.invalidate();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void destroyLayer() {
|
public void destroyLayer() {
|
||||||
|
@ -471,54 +446,10 @@ public class MapInfoLayer extends OsmandMapLayer {
|
||||||
return progressBar;
|
return progressBar;
|
||||||
}
|
}
|
||||||
|
|
||||||
private ViewGroup createStatusBar() {
|
|
||||||
LinearLayout statusBar = new LinearLayout(view.getContext());
|
private View createGlobusAndProgress(){
|
||||||
statusBar.setOrientation(LinearLayout.HORIZONTAL);
|
|
||||||
|
|
||||||
// Compass icon
|
|
||||||
final Drawable compass = view.getResources().getDrawable(R.drawable.compass);
|
|
||||||
final int mw = (int) compass.getMinimumWidth() ;
|
|
||||||
final int mh = (int) compass.getMinimumHeight() ;
|
|
||||||
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
|
|
||||||
compassView = new ImageView(view.getContext()) {
|
|
||||||
@Override
|
|
||||||
protected void onDraw(Canvas canvas) {
|
|
||||||
canvas.save();
|
|
||||||
canvas.rotate(view.getRotate(), mw / 2, mh / 2);
|
|
||||||
compass.draw(canvas);
|
|
||||||
canvas.restore();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
compassView.setOnClickListener(new View.OnClickListener() {
|
|
||||||
@Override
|
|
||||||
public void onClick(View v) {
|
|
||||||
map.switchRotateMapMode();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
compassView.setImageDrawable(compass);
|
|
||||||
statusBar.addView(compassView, params);
|
|
||||||
addBgView(statusBar);
|
|
||||||
|
|
||||||
// Space (future text)
|
|
||||||
params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.FILL_PARENT, LinearLayout.LayoutParams.FILL_PARENT, 1);
|
|
||||||
topText = new TextView(view.getContext()) {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void onDraw(Canvas canvas) {
|
|
||||||
ShadowText.draw(getText().toString(), canvas, topText.getWidth() / 2, topText.getHeight() - 4 * scaleCoefficient, topText.getPaint());
|
|
||||||
}
|
|
||||||
};
|
|
||||||
topText.getPaint().setTextAlign(Align.CENTER);
|
|
||||||
topText.setTextColor(Color.BLACK);
|
|
||||||
statusBar.addView(topText, params);
|
|
||||||
|
|
||||||
// Map and progress icon
|
|
||||||
Drawable globusDrawable = view.getResources().getDrawable(R.drawable.globus);
|
Drawable globusDrawable = view.getResources().getDrawable(R.drawable.globus);
|
||||||
|
|
||||||
params = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
|
|
||||||
FrameLayout fl = new FrameLayout(view.getContext());
|
FrameLayout fl = new FrameLayout(view.getContext());
|
||||||
statusBar.addView(fl, params);
|
|
||||||
|
|
||||||
FrameLayout.LayoutParams fparams = new FrameLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
|
FrameLayout.LayoutParams fparams = new FrameLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
|
||||||
ImageView globus = new ImageView(view.getContext());
|
ImageView globus = new ImageView(view.getContext());
|
||||||
globus.setImageDrawable(globusDrawable);
|
globus.setImageDrawable(globusDrawable);
|
||||||
|
@ -531,38 +462,133 @@ public class MapInfoLayer extends OsmandMapLayer {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
fl.addView(globus, fparams);
|
fl.addView(globus, fparams);
|
||||||
|
|
||||||
fparams = new FrameLayout.LayoutParams(globusDrawable.getMinimumWidth(), globusDrawable.getMinimumHeight());
|
fparams = new FrameLayout.LayoutParams(globusDrawable.getMinimumWidth(), globusDrawable.getMinimumHeight());
|
||||||
progressBar = new View(view.getContext());
|
progressBar = new View(view.getContext());
|
||||||
progressBar.setOnClickListener(new View.OnClickListener() {
|
progressBar.setOnClickListener(new View.OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View v) {
|
public void onClick(View v) {
|
||||||
map.getMapLayers().selectMapLayer(view);
|
openViewConfigureDialog();
|
||||||
|
// map.getMapLayers().selectMapLayer(view);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
fl.addView(progressBar, fparams);
|
fl.addView(progressBar, fparams);
|
||||||
|
return fl;
|
||||||
// Back to location icon
|
}
|
||||||
params = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
|
|
||||||
params.leftMargin = (int) (5 * scaleCoefficient);
|
private ImageView createBackToLocation(final MapActivity map){
|
||||||
params.rightMargin = (int) (5 * scaleCoefficient);
|
ImageView backToLocation = new ImageView(view.getContext());
|
||||||
backToLocation = new ImageView(view.getContext());
|
backToLocation.setPadding((int) (5 * scaleCoefficient), 0, (int) (5 * scaleCoefficient), 0);
|
||||||
backToLocation.setImageDrawable(view.getResources().getDrawable(R.drawable.back_to_loc));
|
backToLocation.setImageDrawable(map.getResources().getDrawable(R.drawable.back_to_loc));
|
||||||
backToLocation.setOnClickListener(new View.OnClickListener() {
|
backToLocation.setOnClickListener(new View.OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View v) {
|
public void onClick(View v) {
|
||||||
map.backToLocationImpl();
|
map.backToLocationImpl();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
statusBar.addView(backToLocation, params);
|
return backToLocation;
|
||||||
return statusBar;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void addBgView(final LinearLayout statusBar) {
|
|
||||||
final OsmandBackgroundServicePlugin backgroundServicePlugin = OsmandPlugin.getEnabledPlugin(OsmandBackgroundServicePlugin.class);
|
private ImageViewControl createCompassView(final MapActivity map){
|
||||||
if (backgroundServicePlugin != null) {
|
final Drawable compass = map.getResources().getDrawable(R.drawable.compass);
|
||||||
backgroundServicePlugin.createBgServiceView(statusBar, view, map);
|
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.switchRotateMapMode();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
compassView.setImageDrawable(compass);
|
||||||
|
return compassView;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static class TopTextView extends TextView implements MapControlUpdateable {
|
||||||
|
private final RoutingHelper routingHelper;
|
||||||
|
private final MapActivity map;
|
||||||
|
|
||||||
|
public TopTextView(RoutingHelper routingHelper, MapActivity map) {
|
||||||
|
super(map);
|
||||||
|
this.routingHelper = routingHelper;
|
||||||
|
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());
|
||||||
|
}
|
||||||
|
|
||||||
|
@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());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(text == null) {
|
||||||
|
text = "";
|
||||||
|
}
|
||||||
|
if (!text.equals(getText().toString())) {
|
||||||
|
TextPaint pp = new TextPaint(getPaint());
|
||||||
|
if (!text.equals("")) {
|
||||||
|
pp.setTextSize(25 * scaleCoefficient);
|
||||||
|
float ts = pp.measureText(text);
|
||||||
|
int wth = getWidth();
|
||||||
|
while (ts > wth && pp.getTextSize() > (14 * 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());
|
||||||
|
} else {
|
||||||
|
setTextSize(TypedValue.COMPLEX_UNIT_PX, 7);
|
||||||
|
}
|
||||||
|
setText(text);
|
||||||
|
invalidate();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue