From 2c64a2cafccf48e22239670ddec66ae2e092eac8 Mon Sep 17 00:00:00 2001 From: Victor Shcherb Date: Mon, 5 Dec 2011 00:26:46 +0100 Subject: [PATCH] Add altitude info --- OsmAnd/res/values/strings.xml | 11 ++++++ OsmAnd/res/xml/settings_pref.xml | 3 +- OsmAnd/src/net/osmand/OsmAndFormatter.java | 10 ++++++ .../src/net/osmand/plus/OsmandSettings.java | 6 +++- .../plus/activities/SettingsActivity.java | 2 -- .../activities/TipsAndTricksActivity.java | 2 +- .../net/osmand/plus/views/MapInfoControl.java | 2 +- .../net/osmand/plus/views/MapInfoLayer.java | 35 +++++++++++++++++++ 8 files changed, 65 insertions(+), 6 deletions(-) diff --git a/OsmAnd/res/values/strings.xml b/OsmAnd/res/values/strings.xml index 8154722195..a0280ffa09 100644 --- a/OsmAnd/res/values/strings.xml +++ b/OsmAnd/res/values/strings.xml @@ -1,5 +1,16 @@ + Changes in 0.6.9 : +\n\t- Improved offline map rendering +\n\t- Native speedy offline rendering - look in experimental features (may not work on some devices) +\n\t- Massive look and feel changes +\n\t- Altitude info +\n\t- New translations (Vienamese, Polish) +\n\t- Other small features + + + Show current altitude information on map + Show altitude Use transparent map controls (requires application restart) Transparent theme diff --git a/OsmAnd/res/xml/settings_pref.xml b/OsmAnd/res/xml/settings_pref.xml index ae95fb48b0..13d374b984 100644 --- a/OsmAnd/res/xml/settings_pref.xml +++ b/OsmAnd/res/xml/settings_pref.xml @@ -88,7 +88,8 @@ - + + diff --git a/OsmAnd/src/net/osmand/OsmAndFormatter.java b/OsmAnd/src/net/osmand/OsmAndFormatter.java index d9c83ad845..176364f476 100644 --- a/OsmAnd/src/net/osmand/OsmAndFormatter.java +++ b/OsmAnd/src/net/osmand/OsmAndFormatter.java @@ -81,6 +81,16 @@ public class OsmAndFormatter { return ((int) meters) + " " + ctx.getString(R.string.m); //$NON-NLS-1$ } } + + public static String getFormattedAlt(double alt, Context ctx) { + OsmandSettings settings = OsmandSettings.getOsmandSettings(ctx); + MetricsConstants mc = settings.METRIC_SYSTEM.get(); + if (mc == MetricsConstants.KILOMETERS_AND_METERS) { + return ((int) alt) + " " + ctx.getString(R.string.m); + } else { + return ((int) (alt * FOOTS_IN_ONE_METER)) + " " + ctx.getString(R.string.foot); + } + } public static String getFormattedSpeed(float metersperseconds, Context ctx) { OsmandSettings settings = OsmandSettings.getOsmandSettings(ctx); diff --git a/OsmAnd/src/net/osmand/plus/OsmandSettings.java b/OsmAnd/src/net/osmand/plus/OsmandSettings.java index 1997f2a97c..f8d106e167 100644 --- a/OsmAnd/src/net/osmand/plus/OsmandSettings.java +++ b/OsmAnd/src/net/osmand/plus/OsmandSettings.java @@ -1050,15 +1050,19 @@ public class OsmandSettings { public final OsmandPreference SHOW_ARRIVAL_TIME_OTHERWISE_EXPECTED_TIME = new BooleanPreference("show_arrival_time", true, true); + // UI boxes public final CommonPreference TRANSPARENT_MAP_THEME = - new BooleanPreference("transparent_map_theme", true, true); + new BooleanPreference("transparent_map_theme", true, false); { TRANSPARENT_MAP_THEME.setModeDefaultValue(ApplicationMode.CAR, false); TRANSPARENT_MAP_THEME.setModeDefaultValue(ApplicationMode.BICYCLE, false); TRANSPARENT_MAP_THEME.setModeDefaultValue(ApplicationMode.PEDESTRIAN, true); } + public final CommonPreference SHOW_ALTITUDE_INFO = + new BooleanPreference("show_altitude_info", false, false); + public enum DayNightMode { AUTO(R.string.daynight_mode_auto), DAY(R.string.daynight_mode_day), diff --git a/OsmAnd/src/net/osmand/plus/activities/SettingsActivity.java b/OsmAnd/src/net/osmand/plus/activities/SettingsActivity.java index 68b13d776e..2185bd25ea 100644 --- a/OsmAnd/src/net/osmand/plus/activities/SettingsActivity.java +++ b/OsmAnd/src/net/osmand/plus/activities/SettingsActivity.java @@ -87,8 +87,6 @@ public class SettingsActivity extends PreferenceActivity implements OnPreference private Map> listPrefValues = new LinkedHashMap>(); - - private void registerBooleanPreference(OsmandPreference b, PreferenceScreen screen){ CheckBoxPreference p = (CheckBoxPreference) screen.findPreference(b.getId()); p.setOnPreferenceChangeListener(this); diff --git a/OsmAnd/src/net/osmand/plus/activities/TipsAndTricksActivity.java b/OsmAnd/src/net/osmand/plus/activities/TipsAndTricksActivity.java index 482d6e3454..44cfdd4963 100644 --- a/OsmAnd/src/net/osmand/plus/activities/TipsAndTricksActivity.java +++ b/OsmAnd/src/net/osmand/plus/activities/TipsAndTricksActivity.java @@ -14,7 +14,7 @@ import android.widget.TextView; public class TipsAndTricksActivity { private int[][] tipNamesAndDescriptions = new int[][] { - {R.string.tip_recent_changes,R.string.tip_recent_changes_0_6_8_t}, + {R.string.tip_recent_changes,R.string.tip_recent_changes_0_6_9_t}, {R.string.tip_rotation_switching,R.string.tip_rotation_switching_t}, {R.string.tip_update_index,R.string.tip_update_index_t}, {R.string.tip_day_night_mode,R.string.tip_day_night_mode_t}, diff --git a/OsmAnd/src/net/osmand/plus/views/MapInfoControl.java b/OsmAnd/src/net/osmand/plus/views/MapInfoControl.java index 6a04627385..358a297118 100644 --- a/OsmAnd/src/net/osmand/plus/views/MapInfoControl.java +++ b/OsmAnd/src/net/osmand/plus/views/MapInfoControl.java @@ -50,7 +50,7 @@ public abstract class MapInfoControl extends View { protected void drawShadowText(Canvas cv, String text, float centerX, float centerY, Paint textPaint) { int c = textPaint.getColor(); textPaint.setStyle(Style.STROKE); - textPaint.setColor(Color.LTGRAY); + textPaint.setColor(Color.WHITE); textPaint.setStrokeWidth(4); cv.drawText(text, centerX, centerY, textPaint); // reset diff --git a/OsmAnd/src/net/osmand/plus/views/MapInfoLayer.java b/OsmAnd/src/net/osmand/plus/views/MapInfoLayer.java index 96a6d970bc..ec2180afb3 100644 --- a/OsmAnd/src/net/osmand/plus/views/MapInfoLayer.java +++ b/OsmAnd/src/net/osmand/plus/views/MapInfoLayer.java @@ -43,6 +43,7 @@ public class MapInfoLayer extends OsmandMapLayer { private float cachedRotate = 0; private boolean showArrivalTime = true; + private boolean showAltitude = false; private boolean showMiniMap = false; // layout pseudo-constants @@ -120,6 +121,7 @@ public class MapInfoLayer extends OsmandMapLayer { } leftStack.setExpandImageDrawable(view.getResources().getDrawable(expand).mutate()); statusBar.setBackgroundDrawable(view.getResources().getDrawable(boxTop).mutate()); + showAltitude = view.getSettings().SHOW_ALTITUDE_INFO.get(); } public void createTopBarElements() { @@ -129,6 +131,7 @@ public class MapInfoLayer extends OsmandMapLayer { rightStack = new MapStackControl(view.getContext()); rightStack.addStackView(createDistanceControl()); + rightStack.addStackView(createAltitudeControl()); rightStack.addCollapsedView(createSpeedControl()); rightStack.addCollapsedView(createTimeControl()); @@ -244,6 +247,38 @@ public class MapInfoLayer extends OsmandMapLayer { return speedControl; } + private TextInfoControl createAltitudeControl(){ + final TextInfoControl altitudeControl = new TextInfoControl(map, 0, paintText, paintSubText) { + private int cachedAlt = 0; + + @Override + public boolean updateInfo() { + // draw speed + if (showAltitude && + map.getLastKnownLocation() != null && map.getLastKnownLocation().hasAltitude()) { + if (cachedAlt != (int) map.getLastKnownLocation().getAltitude()) { + cachedAlt = (int) map.getLastKnownLocation().getAltitude(); + String ds = OsmAndFormatter.getFormattedAlt(cachedAlt, map); + 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); + return altitudeControl; + } + private TextInfoControl createTimeControl(){ final Drawable time = view.getResources().getDrawable(R.drawable.info_time); final Drawable timeToGo = view.getResources().getDrawable(R.drawable.info_time_to_go);