From fefdca8b885a81e444f4cc15305bc1b9f97afa6b Mon Sep 17 00:00:00 2001 From: Victor Shcherb Date: Fri, 27 Jul 2012 00:41:50 +0200 Subject: [PATCH] Add toolbar settings --- .../drawable-hdpi/poi_parking_pos_info.png | Bin 1315 -> 0 bytes OsmAnd/res/drawable/poi_parking_pos_info.png | Bin 0 -> 1231 bytes OsmAnd/res/values/strings.xml | 5 + .../OsmandBackgroundServicePlugin.java | 30 +- .../osmand/plus/views/ImageViewControl.java | 12 + .../plus/views/MapControlUpdateable.java | 9 + .../net/osmand/plus/views/MapInfoControl.java | 3 +- .../osmand/plus/views/MapInfoControls.java | 121 ++++++-- .../net/osmand/plus/views/MapInfoLayer.java | 278 ++++++++++-------- 9 files changed, 298 insertions(+), 160 deletions(-) delete mode 100644 OsmAnd/res/drawable-hdpi/poi_parking_pos_info.png create mode 100644 OsmAnd/res/drawable/poi_parking_pos_info.png create mode 100644 OsmAnd/src/net/osmand/plus/views/ImageViewControl.java create mode 100644 OsmAnd/src/net/osmand/plus/views/MapControlUpdateable.java diff --git a/OsmAnd/res/drawable-hdpi/poi_parking_pos_info.png b/OsmAnd/res/drawable-hdpi/poi_parking_pos_info.png deleted file mode 100644 index 3b2ffb13bf6cf7f164e6d6115eb0c27e71fd98ff..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1315 zcmV+;1>E|HP)(_`g8%^e{{R4h=>PzAFaQARU;qF*m;eA5Z<1fd zMgRZ=sYygZRCwC#mP>C{RTRg6d!KXep|_>IJQcJ84iFU40iaS%08Na>fsaII&eS+i zzkpvt2PP&CjB!TLL_(rAlBhf)Xaa;ss65glr7hT7?(3Yh_g;HD=&2wUy)a?I8twP` z@3sExp+X4UNzvS4xeMSffV%+hIDmM*MWxjB`wDO+*r>~QLwQG)cU-x~jfpS5$pZ>V zN~OJNsx}Pt_b-E>L-=2-1*KH5)@1dW>M?+HWr0$81z59b%aiZD_|n@i_t#cc zok;nQ8~&V)I*+gKuzJ-Bj1`npXr&1%K!8Tma{fZjg-aED=p~6A)6+fNyW-XU z^&9rQd+6Y$`? zD!(1M$ez7ZSgD~ylls+|fn}T5!mdrgscr!*^gi?!c}7x+5Le*6!?=imqLVqk-~TH| zj-Dk=73J|VY zc*I#GvWT+;v3L=j2PZ;SfO>s~X3G$#4w2dDVcyvJ4*(Dl zDG-++&fvvR6a}4DhKR6wa52qxPFm3nZj9JAv?5S`%Vb}T@c z<$x{_nRP*)C`btzgIoE1PLF2~DlSbz}lV(_8~ z-Xc;^n1Z6nX}23(nzC3PAx$8OA=QBL;0v6)mfpQ+LXf$taZ4mr-n-fSUq*oU9ubd( zK%@gIw81Mv0P)us(rY4K@cwVzU01`7DLS1zpCO8u?%e6&p-4wt?_2#8X5rJr4 z_lh%InLNeF$=!LgF}@Qx5B!UbH|q!bf#twP;H`!ID<2!E4Gu){0u=~qj-(~I=4+=y zmd%)}_0dblw7&wr0mgvo5JJ%nfCT6V76B`Ohk(Jdnsw923Qz||fOEifInP1}{`!M| Z4FJ5tsPmTw#4!K>002ovPDHLkV1g$IV)Fn1 diff --git a/OsmAnd/res/drawable/poi_parking_pos_info.png b/OsmAnd/res/drawable/poi_parking_pos_info.png new file mode 100644 index 0000000000000000000000000000000000000000..c765cf5a61d579d7fa9d4240a81ba05b29af36cf GIT binary patch literal 1231 zcmV;=1Tg!FP)lFY! z_{2Fs4P5B%<$x@<=SYozMVd} zf8S@~+>hN`+1=p9mKK3WMmBE!{KJp;?`kF+Xtr`hEMnb#gWyRi?C>&Y`JTw$> z;@GG4ufF);BN6uvkO1j&md08KufO`nC%dlS7+~(kMU=1d^tLveH?1c(f>H{tG+ue| zP;VH{UrM=jwSel{WZXy2fEJ7i?*?$N0;ho1pX_kylQ z1?4PFhzbE>Gn}*JHo&83CzhWN|HbhWGsLlCY;*(TRA-2E+?ysTNt)8AH`w>nQ6^7cM`?vMklTqw5`e7X<8!)hp}RC z&Jab4VlgC1LhuG-4LVr9(lS)jcfbQRF3&7a$fcO#{~0pfTq z)kc|1S2Z{0i-d(iq9{b^0Il_s>71c<>l~+!f0s7um%juK0ChS&^*(`sHNY^i19+$0 zH}urn%Eq-pxJr3^=dSk)334B|;*+G7->zP~YHhj~_yM>G%=dyuU2s3J9(WuWq0=QE t^t%F`*j0fk;9M70rPIV+54rz-`~y_ZjTY! + Map selection + Where am I + Lock screen + Compass + Status bar Reset to default Right side Left side diff --git a/OsmAnd/src/net/osmand/plus/background/OsmandBackgroundServicePlugin.java b/OsmAnd/src/net/osmand/plus/background/OsmandBackgroundServicePlugin.java index 57dd3b63a2..581c1ff093 100644 --- a/OsmAnd/src/net/osmand/plus/background/OsmandBackgroundServicePlugin.java +++ b/OsmAnd/src/net/osmand/plus/background/OsmandBackgroundServicePlugin.java @@ -1,12 +1,17 @@ package net.osmand.plus.background; +import java.util.EnumSet; + import net.osmand.plus.NavigationService; import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandPlugin; import net.osmand.plus.OsmandSettings; import net.osmand.plus.R; +import net.osmand.plus.activities.ApplicationMode; import net.osmand.plus.activities.MapActivity; 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 android.app.AlertDialog; import android.app.AlertDialog.Builder; @@ -29,9 +34,6 @@ import android.widget.AdapterView.OnItemSelectedListener; import android.widget.ArrayAdapter; import android.widget.CheckBox; import android.widget.CompoundButton; -import android.widget.ImageView; -import android.widget.LinearLayout; -import android.widget.LinearLayout.LayoutParams; import android.widget.Spinner; public class OsmandBackgroundServicePlugin extends OsmandPlugin { @@ -72,10 +74,17 @@ public class OsmandBackgroundServicePlugin extends OsmandPlugin { @Override public void registerLayers(MapActivity 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 public void updateLayers(OsmandMapTileView mapView, MapActivity activity) { + if(backgroundServiceLayer == null) { + registerLayers(activity); + } if (isScreenLocked) { mapView.addLayer(backgroundServiceLayer, mapView.getLayers().size()); } 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 final Drawable lock = view.getResources().getDrawable(R.drawable.monitoring_rec_big); final Drawable unLock = view.getResources().getDrawable(R.drawable.monitoring_rec_inactive); - - final ImageView lockView = new ImageView(view.getContext()); + final ImageViewControl lockView = new ImageViewControl(view.getContext()) { + @Override + public boolean updateInfo() { + return false; + } + }; if (isScreenLocked) { 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; } /** diff --git a/OsmAnd/src/net/osmand/plus/views/ImageViewControl.java b/OsmAnd/src/net/osmand/plus/views/ImageViewControl.java new file mode 100644 index 0000000000..0ef8cc89d4 --- /dev/null +++ b/OsmAnd/src/net/osmand/plus/views/ImageViewControl.java @@ -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); + } + +} \ 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 new file mode 100644 index 0000000000..58f11e152b --- /dev/null +++ b/OsmAnd/src/net/osmand/plus/views/MapControlUpdateable.java @@ -0,0 +1,9 @@ +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/MapInfoControl.java b/OsmAnd/src/net/osmand/plus/views/MapInfoControl.java index 97f117ebf7..95ec0a40d7 100644 --- a/OsmAnd/src/net/osmand/plus/views/MapInfoControl.java +++ b/OsmAnd/src/net/osmand/plus/views/MapInfoControl.java @@ -7,7 +7,7 @@ import android.graphics.Rect; import android.graphics.drawable.Drawable; import android.view.View; -public abstract class MapInfoControl extends View { +public abstract class MapInfoControl extends View implements MapControlUpdateable { int width = 0; int height = 0; Rect padding = new Rect(); @@ -56,6 +56,7 @@ public abstract class MapInfoControl extends View { canvas.clipRect(0, 0, getWWidth(),getWHeight()); } + @Override public boolean updateInfo() { return false; } protected boolean updateVisibility(boolean visible) { diff --git a/OsmAnd/src/net/osmand/plus/views/MapInfoControls.java b/OsmAnd/src/net/osmand/plus/views/MapInfoControls.java index 0861d856a4..fed8fd24bb 100644 --- a/OsmAnd/src/net/osmand/plus/views/MapInfoControls.java +++ b/OsmAnd/src/net/osmand/plus/views/MapInfoControls.java @@ -1,5 +1,6 @@ package net.osmand.plus.views; +import java.util.Comparator; import java.util.EnumSet; import java.util.LinkedHashMap; import java.util.LinkedHashSet; @@ -7,27 +8,30 @@ import java.util.Map; import java.util.Set; 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.activities.ApplicationMode; -import android.graphics.Paint; public class MapInfoControls { private Set left = new TreeSet(); private Set right = new TreeSet(); + private Set topleft = new TreeSet(); + private Set topright = new TreeSet(new Comparator() { + @Override + public int compare(MapInfoControlRegInfo object1, MapInfoControlRegInfo object2) { + return -object1.compareTo(object2); + } + }); private Map> visibleElements = new LinkedHashMap>(); 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) { this.settings = settings; @@ -46,6 +50,36 @@ public class MapInfoControls { } + public MapInfoControlRegInfo registerTopWidget(View m, int drawable, int messageId, String key, boolean left, + EnumSet 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 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, @@ -85,7 +119,7 @@ public class MapInfoControls { for(MapInfoControlRegInfo m : mi){ if(m.visibleModes.contains(mode)) { set.add(m.key) ; - } else if(m.visibleCollapsible.contains(mode)) { + } else if(m.visibleCollapsible != null && m.visibleCollapsible.contains(mode)) { set.add("+"+m.key) ; } } @@ -97,14 +131,18 @@ public class MapInfoControls { LinkedHashSet set = new LinkedHashSet(); restoreModes(set, left, mode); restoreModes(set, right, mode); + restoreModes(set, topleft, mode); + restoreModes(set, topright, mode); this.visibleElements.put(mode, set); } this.visibleElements.get(mode).remove(m.key); this.visibleElements.get(mode).remove("+" + m.key); m.visibleModes.remove(mode); - m.visibleCollapsible.remove(mode); + if(m.visibleCollapsible != null) { + m.visibleCollapsible.remove(mode); + } if(visible) { - if(collapse) { + if(collapse && m.visibleCollapsible != null) { m.visibleCollapsible.add(mode); this.visibleElements.get(mode).add("+" + m.key); } else { @@ -128,28 +166,51 @@ public class MapInfoControls { return right; } - public void registerTopBarButton(MapInfoControlFactoryMethod m, int drawable, int messageId, boolean left, - EnumSet appModes, int priorityOrder) { - + public Set getTopLeft() { + return topleft; + } + + public Set getTopRight() { + return topright; } public void populateStackControl(MapStackControl stack, OsmandMapTileView v, boolean left){ ApplicationMode appMode = settings.getApplicationMode(); Set st = left ? this.left : this.right; for (MapInfoControlRegInfo r : st) { - if (r.visibleCollapsible.contains(appMode)) { - stack.addCollapsedView(r.m); + if (r.visibleCollapsible != null && r.visibleCollapsible.contains(appMode)) { + stack.addCollapsedView((MapInfoControl) r.m); } 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 set ){ for(MapInfoControlRegInfo ri : set) { - ri.visibleCollapsible.remove(mode); + if(ri.visibleCollapsible != null) { + ri.visibleCollapsible.remove(mode); + } ri.visibleModes.remove(mode); - if(ri.defaultCollapsible.contains(mode)) { + if(ri.defaultCollapsible != null && ri.defaultCollapsible.contains(mode)) { ri.visibleCollapsible.add(mode); } if(ri.defaultModes.contains(mode)) { @@ -162,6 +223,8 @@ public class MapInfoControls { ApplicationMode appMode = settings.getApplicationMode(); resetDefault(appMode, left); resetDefault(appMode, right); + resetDefault(appMode, topleft); + resetDefault(appMode, topright); this.visibleElements.put(appMode, null); settings.MAP_INFO_CONTROLS.set(""); } @@ -176,7 +239,7 @@ public class MapInfoControls { public static class MapInfoControlRegInfo implements Comparable { - public MapInfoControl m; + public View m; public int drawable; public int messageId; private String key; @@ -187,12 +250,24 @@ public class MapInfoControls { public int priorityOrder; 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){ return visibleModes.contains(mode); } + + public MapInfoControlRegInfo required(ApplicationMode... modes){ + for(ApplicationMode ms : modes) { + visibleModes.add(ms); + } + return this; + } + @Override public int hashCode() { return messageId; diff --git a/OsmAnd/src/net/osmand/plus/views/MapInfoLayer.java b/OsmAnd/src/net/osmand/plus/views/MapInfoLayer.java index 3e93e2d724..ef9898e47e 100644 --- a/OsmAnd/src/net/osmand/plus/views/MapInfoLayer.java +++ b/OsmAnd/src/net/osmand/plus/views/MapInfoLayer.java @@ -4,12 +4,10 @@ package net.osmand.plus.views; import java.util.ArrayList; import java.util.EnumSet; -import net.osmand.plus.OsmandPlugin; import net.osmand.plus.OsmandSettings; import net.osmand.plus.R; import net.osmand.plus.activities.ApplicationMode; import net.osmand.plus.activities.MapActivity; -import net.osmand.plus.background.OsmandBackgroundServicePlugin; import net.osmand.plus.routing.RouteDirectionInfo; import net.osmand.plus.routing.RoutingHelper; import net.osmand.plus.views.MapInfoControls.MapInfoControlRegInfo; @@ -59,23 +57,19 @@ public class MapInfoLayer extends OsmandMapLayer { private Paint paintSmallSubText; private Paint paintImg; - private float cachedRotate = 0; - // layout pseudo-constants private int STATUS_BAR_MARGIN_X = -4; private ImageView backToLocation; - private ImageView compassView; private View progressBar; // groups private MapStackControl rightStack; private MapStackControl leftStack; - private ViewGroup statusBar; + private LinearLayout statusBar; private MapInfoControl lanesControl; private MapInfoControl alarmControl; private TextView topText; - private MapInfoControls mapInfoControls; public MapInfoLayer(MapActivity map, RouteLayer layer){ @@ -150,10 +144,8 @@ public class MapInfoLayer extends OsmandMapLayer { @Override public void initLayer(final OsmandMapTileView view) { this.view = view; - registerAllControls(); createControls(); - applyTheme(); } public void applyTheme() { @@ -179,7 +171,8 @@ public class MapInfoLayer extends OsmandMapLayer { } public void registerAllControls(){ - statusBar = createStatusBar(); + statusBar = new LinearLayout(view.getContext()); + statusBar.setOrientation(LinearLayout.HORIZONTAL); RouteInfoControls ric = new RouteInfoControls(scaleCoefficient); lanesControl = ric.createLanesControl(view.getApplication().getRoutingHelper(), view); 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); 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(){ @@ -222,6 +224,9 @@ public class MapInfoLayer extends OsmandMapLayer { mapInfoControls.populateStackControl(leftStack, view, true); leftStack.requestLayout(); rightStack.requestLayout(); + + statusBar.removeAllViews(); + mapInfoControls.populateStatusBar(statusBar, topText); } public void createControls() { @@ -233,7 +238,8 @@ public class MapInfoLayer extends OsmandMapLayer { // 2. Preparations Rect topRectPadding = new Rect(); view.getResources().getDrawable(R.drawable.box_top).getPadding(topRectPadding); - + // for measurement + statusBar.addView(backToLocation); STATUS_BAR_MARGIN_X = (int) (STATUS_BAR_MARGIN_X * scaleCoefficient); statusBar.measure(MeasureSpec.UNSPECIFIED, MeasureSpec.UNSPECIFIED); Rect statusBarPadding = new Rect(); @@ -284,6 +290,8 @@ public class MapInfoLayer extends OsmandMapLayer { parent.addView(alarmControl); alarmControl.setVisibility(View.GONE); lanesControl.setVisibility(View.GONE); + + // update and create controls applyTheme(); recreateControls(); } @@ -293,6 +301,9 @@ public class MapInfoLayer extends OsmandMapLayer { final ArrayList list = new ArrayList(); 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.addAll(mapInfoControls.getRight()); list.add(map.getString(R.string.map_widget_left_stack)); @@ -309,19 +320,20 @@ public class MapInfoLayer extends OsmandMapLayer { if (v == 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)); Object o = list.get(position); if(o instanceof MapInfoControlRegInfo) { 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 if (mi.drawable != 0) { tv.setPadding((int) (12 *scaleCoefficient), 0, 0, 0); tv.setCompoundDrawablesWithIntrinsicBounds(mi.drawable, 0, 0, 0); } else { 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); @@ -331,10 +343,17 @@ public class MapInfoLayer extends OsmandMapLayer { @Override public void onCheckedChanged(CompoundButton buttonView, boolean 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 { mapInfoControls.changeVisibility(mi, true, false); } + String s = mi.visibleCollapsed(mode) ? " - " : " "; + tv.setText(s + map.getString(mi.messageId) + s); recreateControls(); } }); @@ -398,60 +417,16 @@ public class MapInfoLayer extends OsmandMapLayer { // update data on draw rightStack.updateInfo(); leftStack.updateInfo(); - if(view.getRotate() != cachedRotate) { - cachedRotate = view.getRotate(); - compassView.invalidate(); - } lanesControl.updateInfo(); alarmControl.updateInfo(); - updateTopText(); + for(int i=0; i= 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 public void destroyLayer() { @@ -471,54 +446,10 @@ public class MapInfoLayer extends OsmandMapLayer { return progressBar; } - private ViewGroup createStatusBar() { - LinearLayout statusBar = new LinearLayout(view.getContext()); - 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 + + private View createGlobusAndProgress(){ Drawable globusDrawable = view.getResources().getDrawable(R.drawable.globus); - - params = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); FrameLayout fl = new FrameLayout(view.getContext()); - statusBar.addView(fl, params); - FrameLayout.LayoutParams fparams = new FrameLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); ImageView globus = new ImageView(view.getContext()); globus.setImageDrawable(globusDrawable); @@ -531,38 +462,133 @@ public class MapInfoLayer extends OsmandMapLayer { } }); fl.addView(globus, fparams); - fparams = new FrameLayout.LayoutParams(globusDrawable.getMinimumWidth(), globusDrawable.getMinimumHeight()); progressBar = new View(view.getContext()); progressBar.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { - map.getMapLayers().selectMapLayer(view); + openViewConfigureDialog(); +// map.getMapLayers().selectMapLayer(view); } }); fl.addView(progressBar, fparams); - - // Back to location icon - params = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); - params.leftMargin = (int) (5 * scaleCoefficient); - params.rightMargin = (int) (5 * scaleCoefficient); - backToLocation = new ImageView(view.getContext()); - backToLocation.setImageDrawable(view.getResources().getDrawable(R.drawable.back_to_loc)); + return fl; + } + + private ImageView createBackToLocation(final MapActivity map){ + ImageView backToLocation = new ImageView(view.getContext()); + 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.backToLocationImpl(); } }); - statusBar.addView(backToLocation, params); - return statusBar; + return backToLocation; } - private void addBgView(final LinearLayout statusBar) { - final OsmandBackgroundServicePlugin backgroundServicePlugin = OsmandPlugin.getEnabledPlugin(OsmandBackgroundServicePlugin.class); - if (backgroundServicePlugin != null) { - backgroundServicePlugin.createBgServiceView(statusBar, view, map); + + 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.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; + } + }