Update controls

This commit is contained in:
Victor Shcherb 2012-07-28 01:03:47 +02:00
parent 78a6e787be
commit 1ca016b23b
4 changed files with 61 additions and 45 deletions

View file

@ -7,6 +7,12 @@ import net.osmand.plus.OsmandSettings;
import net.osmand.plus.R;
import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.activities.SettingsActivity;
import net.osmand.plus.views.ImageViewControl;
import net.osmand.plus.views.MapInfoControls;
import net.osmand.plus.views.MapInfoLayer;
import net.osmand.plus.views.OsmandMapTileView;
import android.app.AlertDialog;
import android.app.AlertDialog.Builder;
import android.content.BroadcastReceiver;
import android.content.ComponentName;
import android.content.Context;

View file

@ -497,6 +497,12 @@ public class RoutingHelper {
}
public synchronized String getCurrentName(){
NextDirectionInfo n = getNextRouteDirectionInfo(new NextDirectionInfo(), false);
if((n.imminent == 0 || n.imminent == 1) && (n.directionInfo != null)) {
String nm = n.directionInfo.getStreetName();
String rf = n.directionInfo.getRef();
return formatStreetName(nm, rf);
}
RouteSegmentResult rs = route.getCurrentSegmentResult();
if(rs != null) {
String nm = rs.getObject().getName();

View file

@ -8,24 +8,39 @@ import java.util.Map;
import java.util.Set;
import java.util.TreeSet;
import net.osmand.plus.OsmandSettings;
import net.osmand.plus.activities.ApplicationMode;
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;
public class MapInfoControls {
public static final int LEFT_CONTROL = -1;
public static final int RIGHT_CONTROL = 1;
public static final int MAIN_CONTROL = 0;
private Set<MapInfoControlRegInfo> left = 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>() {
private Set<MapInfoControlRegInfo> top = new TreeSet<MapInfoControls.MapInfoControlRegInfo>(new Comparator<MapInfoControlRegInfo>() {
@Override
public int compare(MapInfoControlRegInfo object1, MapInfoControlRegInfo object2) {
return -object1.compareTo(object2);
if (object1.position != object2.position) {
if(object1.position == LEFT_CONTROL) {
return -1;
} else if(object1.position == RIGHT_CONTROL) {
return 1;
} else {
return object2.position == LEFT_CONTROL ? 1 : -1;
}
}
int cmp = object1.priorityOrder - object2.priorityOrder;
if(object1.position == RIGHT_CONTROL) {
cmp = -cmp;
}
return cmp;
}
});
private Map<ApplicationMode, Set<String>> visibleElements = new LinkedHashMap<ApplicationMode, Set<String>>();
@ -50,7 +65,7 @@ public class MapInfoControls {
}
public MapInfoControlRegInfo registerTopWidget(View m, int drawable, int messageId, String key, boolean left,
public MapInfoControlRegInfo registerTopWidget(View m, int drawable, int messageId, String key, int left,
EnumSet<ApplicationMode> appDefaultModes, int priorityOrder) {
MapInfoControlRegInfo ii = new MapInfoControlRegInfo();
ii.defaultModes = appDefaultModes.clone();
@ -72,11 +87,8 @@ public class MapInfoControls {
ii.messageId = messageId;
ii.m = m;
ii.priorityOrder = priorityOrder;
if(left) {
this.topleft.add(ii);
} else {
this.topright.add(ii);
}
ii.position = left;
this.top.add(ii);
return ii;
}
@ -131,8 +143,7 @@ public class MapInfoControls {
LinkedHashSet<String> set = new LinkedHashSet<String>();
restoreModes(set, left, mode);
restoreModes(set, right, mode);
restoreModes(set, topleft, mode);
restoreModes(set, topright, mode);
restoreModes(set, top, mode);
this.visibleElements.put(mode, set);
}
this.visibleElements.get(mode).remove(m.key);
@ -166,12 +177,8 @@ public class MapInfoControls {
return right;
}
public Set<MapInfoControlRegInfo> getTopLeft() {
return topleft;
}
public Set<MapInfoControlRegInfo> getTopRight() {
return topright;
public Set<MapInfoControlRegInfo> getTop() {
return top;
}
public void populateStackControl(MapStackControl stack, OsmandMapTileView v, boolean left){
@ -186,20 +193,16 @@ public class MapInfoControls {
}
}
public void populateStatusBar(ViewGroup statusBar, TextView topView){
public void populateStatusBar(ViewGroup statusBar){
ApplicationMode appMode = settings.getApplicationMode();
for (MapInfoControlRegInfo r : topleft) {
for (MapInfoControlRegInfo 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);
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);
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT, main? 1 : 0);
statusBar.addView((View) r.m, params);
} else if (main) {
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT, 1);
statusBar.addView(new TextView(((View) r.m).getContext()), params);
}
}
}
@ -223,8 +226,7 @@ public class MapInfoControls {
ApplicationMode appMode = settings.getApplicationMode();
resetDefault(appMode, left);
resetDefault(appMode, right);
resetDefault(appMode, topleft);
resetDefault(appMode, topright);
resetDefault(appMode, top);
this.visibleElements.put(appMode, null);
settings.MAP_INFO_CONTROLS.set("");
}
@ -243,6 +245,7 @@ public class MapInfoControls {
public int drawable;
public int messageId;
private String key;
private int position;
private EnumSet<ApplicationMode> defaultModes;
private EnumSet<ApplicationMode> defaultCollapsible;
private EnumSet<ApplicationMode> visibleModes;
@ -268,6 +271,7 @@ public class MapInfoControls {
return this;
}
@Override
public int hashCode() {
return messageId;

View file

@ -77,11 +77,11 @@ public class MapInfoLayer extends OsmandMapLayer {
private LinearLayout statusBar;
private MapInfoControl lanesControl;
private MapInfoControl alarmControl;
private TextView topText;
private MapInfoControls mapInfoControls;
private boolean isScreenLocked = false;
private boolean isBgServiceStarted = false;
private TopTextView topText;
public MapInfoLayer(MapActivity map, RouteLayer layer){
this.map = map;
@ -217,21 +217,22 @@ public class MapInfoLayer extends OsmandMapLayer {
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);
mapInfoControls.registerTopWidget(compassView, R.drawable.compass, R.string.map_widget_compass, "compass", MapInfoControls.LEFT_CONTROL, all, 5);
View config = createConfiguration();
mapInfoControls.registerTopWidget(config, android.R.drawable.ic_menu_preferences, R.string.map_widget_config, "config", true, all, 10).required(ApplicationMode.values());
mapInfoControls.registerTopWidget(config, android.R.drawable.ic_menu_preferences, R.string.map_widget_config, "config", MapInfoControls.LEFT_CONTROL, all, 10).required(ApplicationMode.values());
// TODO icons and strings
View bgServiceView = createBgServiceView();
mapInfoControls.registerTopWidget(bgServiceView, R.drawable.monitoring_rec_big, R.string.bg_service_screen_lock, "bgService", true, all, 15);
mapInfoControls.registerTopWidget(bgServiceView, R.drawable.monitoring_rec_big, R.string.bg_service_screen_lock, "bgService", MapInfoControls.LEFT_CONTROL, all, 15);
backToLocation = createBackToLocation(map);
mapInfoControls.registerTopWidget(backToLocation, R.drawable.location_default, R.string.map_widget_back_to_loc, "back_to_location", false, all, 5);
mapInfoControls.registerTopWidget(backToLocation, R.drawable.location_default, R.string.map_widget_back_to_loc, "back_to_location", MapInfoControls.RIGHT_CONTROL, all, 5);
View globusAndProgress = createGlobusAndProgress();
mapInfoControls.registerTopWidget(globusAndProgress, R.drawable.globus, R.string.map_widget_map_select, "progress", false, all, 10);
mapInfoControls.registerTopWidget(globusAndProgress, R.drawable.globus, R.string.map_widget_map_select, "progress", MapInfoControls.RIGHT_CONTROL, all, 10);
topText = new TopTextView(routingHelper, map);
mapInfoControls.registerTopWidget(topText, R.drawable.arrow_up, R.string.map_widget_top_text, "street_name", MapInfoControls.MAIN_CONTROL, all, 100);
}
public void recreateControls(){
@ -244,7 +245,7 @@ public class MapInfoLayer extends OsmandMapLayer {
rightStack.requestLayout();
statusBar.removeAllViews();
mapInfoControls.populateStatusBar(statusBar, topText);
mapInfoControls.populateStatusBar(statusBar);
}
public void createControls() {
@ -320,8 +321,7 @@ public class MapInfoLayer extends OsmandMapLayer {
final ArrayList<Object> list = new ArrayList<Object>();
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.addAll(mapInfoControls.getTop());
list.add(map.getString(R.string.map_widget_right_stack));
list.addAll(mapInfoControls.getRight());
list.add(map.getString(R.string.map_widget_left_stack));
@ -437,10 +437,10 @@ public class MapInfoLayer extends OsmandMapLayer {
leftStack.updateInfo();
lanesControl.updateInfo();
alarmControl.updateInfo();
for(int i=0; i<statusBar.getChildCount(); i++) {
for (int i = 0; i < statusBar.getChildCount(); i++) {
View v = statusBar.getChildAt(i);
if(v instanceof MapControlUpdateable) {
((MapControlUpdateable)v).updateInfo();
if (v instanceof MapControlUpdateable) {
((MapControlUpdateable) v).updateInfo();
}
}
}