Add altitude info

This commit is contained in:
Victor Shcherb 2011-12-05 00:26:46 +01:00
parent 60bef86647
commit 2c64a2cafc
8 changed files with 65 additions and 6 deletions

View file

@ -1,5 +1,16 @@
<?xml version="1.0" encoding="utf-8" standalone="no"?> <?xml version="1.0" encoding="utf-8" standalone="no"?>
<resources> <resources>
<string name="tip_recent_changes_0_6_9_t">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
</string>
<string name="show_altitude_info_descr">Show current altitude information on map</string>
<string name="show_altitude_info">Show altitude</string>
<string name="use_transparent_map_theme_descr">Use transparent map controls (requires application restart)</string> <string name="use_transparent_map_theme_descr">Use transparent map controls (requires application restart)</string>
<string name="use_transparent_map_theme">Transparent theme</string> <string name="use_transparent_map_theme">Transparent theme</string>

View file

@ -88,7 +88,8 @@
</PreferenceScreen> </PreferenceScreen>
<PreferenceScreen android:key="appearance_settings" android:title="@string/appearance_settings" android:summary="@string/appearance_settings_descr"> <PreferenceScreen android:key="appearance_settings" android:title="@string/appearance_settings" android:summary="@string/appearance_settings_descr">
<CheckBoxPreference android:key="transparent_map_theme" android:title="@string/use_transparent_map_theme" android:summary="@string/use_transparent_map_theme_descr"></CheckBoxPreference> <CheckBoxPreference android:key="transparent_map_theme" android:title="@string/use_transparent_map_theme" android:summary="@string/use_transparent_map_theme_descr"/>
<CheckBoxPreference android:key="show_altitude_info" android:title="@string/show_altitude_info" android:summary="@string/show_altitude_info_descr"/>
</PreferenceScreen> </PreferenceScreen>
<PreferenceScreen android:key = "osm_settings" android:title="@string/osm_settings" android:summary="@string/osm_settings_descr"> <PreferenceScreen android:key = "osm_settings" android:title="@string/osm_settings" android:summary="@string/osm_settings_descr">

View file

@ -82,6 +82,16 @@ public class OsmAndFormatter {
} }
} }
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) { public static String getFormattedSpeed(float metersperseconds, Context ctx) {
OsmandSettings settings = OsmandSettings.getOsmandSettings(ctx); OsmandSettings settings = OsmandSettings.getOsmandSettings(ctx);
MetricsConstants mc = settings.METRIC_SYSTEM.get(); MetricsConstants mc = settings.METRIC_SYSTEM.get();

View file

@ -1050,15 +1050,19 @@ public class OsmandSettings {
public final OsmandPreference<Boolean> SHOW_ARRIVAL_TIME_OTHERWISE_EXPECTED_TIME = public final OsmandPreference<Boolean> SHOW_ARRIVAL_TIME_OTHERWISE_EXPECTED_TIME =
new BooleanPreference("show_arrival_time", true, true); new BooleanPreference("show_arrival_time", true, true);
// UI boxes // UI boxes
public final CommonPreference<Boolean> TRANSPARENT_MAP_THEME = public final CommonPreference<Boolean> 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.CAR, false);
TRANSPARENT_MAP_THEME.setModeDefaultValue(ApplicationMode.BICYCLE, false); TRANSPARENT_MAP_THEME.setModeDefaultValue(ApplicationMode.BICYCLE, false);
TRANSPARENT_MAP_THEME.setModeDefaultValue(ApplicationMode.PEDESTRIAN, true); TRANSPARENT_MAP_THEME.setModeDefaultValue(ApplicationMode.PEDESTRIAN, true);
} }
public final CommonPreference<Boolean> SHOW_ALTITUDE_INFO =
new BooleanPreference("show_altitude_info", false, false);
public enum DayNightMode { public enum DayNightMode {
AUTO(R.string.daynight_mode_auto), AUTO(R.string.daynight_mode_auto),
DAY(R.string.daynight_mode_day), DAY(R.string.daynight_mode_day),

View file

@ -87,8 +87,6 @@ public class SettingsActivity extends PreferenceActivity implements OnPreference
private Map<String, Map<String, ?>> listPrefValues = new LinkedHashMap<String, Map<String, ?>>(); private Map<String, Map<String, ?>> listPrefValues = new LinkedHashMap<String, Map<String, ?>>();
private void registerBooleanPreference(OsmandPreference<Boolean> b, PreferenceScreen screen){ private void registerBooleanPreference(OsmandPreference<Boolean> b, PreferenceScreen screen){
CheckBoxPreference p = (CheckBoxPreference) screen.findPreference(b.getId()); CheckBoxPreference p = (CheckBoxPreference) screen.findPreference(b.getId());
p.setOnPreferenceChangeListener(this); p.setOnPreferenceChangeListener(this);

View file

@ -14,7 +14,7 @@ import android.widget.TextView;
public class TipsAndTricksActivity { public class TipsAndTricksActivity {
private int[][] tipNamesAndDescriptions = new int[][] { 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_rotation_switching,R.string.tip_rotation_switching_t},
{R.string.tip_update_index,R.string.tip_update_index_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}, {R.string.tip_day_night_mode,R.string.tip_day_night_mode_t},

View file

@ -50,7 +50,7 @@ public abstract class MapInfoControl extends View {
protected void drawShadowText(Canvas cv, String text, float centerX, float centerY, Paint textPaint) { protected void drawShadowText(Canvas cv, String text, float centerX, float centerY, Paint textPaint) {
int c = textPaint.getColor(); int c = textPaint.getColor();
textPaint.setStyle(Style.STROKE); textPaint.setStyle(Style.STROKE);
textPaint.setColor(Color.LTGRAY); textPaint.setColor(Color.WHITE);
textPaint.setStrokeWidth(4); textPaint.setStrokeWidth(4);
cv.drawText(text, centerX, centerY, textPaint); cv.drawText(text, centerX, centerY, textPaint);
// reset // reset

View file

@ -43,6 +43,7 @@ public class MapInfoLayer extends OsmandMapLayer {
private float cachedRotate = 0; private float cachedRotate = 0;
private boolean showArrivalTime = true; private boolean showArrivalTime = true;
private boolean showAltitude = false;
private boolean showMiniMap = false; private boolean showMiniMap = false;
// layout pseudo-constants // layout pseudo-constants
@ -120,6 +121,7 @@ public class MapInfoLayer extends OsmandMapLayer {
} }
leftStack.setExpandImageDrawable(view.getResources().getDrawable(expand).mutate()); leftStack.setExpandImageDrawable(view.getResources().getDrawable(expand).mutate());
statusBar.setBackgroundDrawable(view.getResources().getDrawable(boxTop).mutate()); statusBar.setBackgroundDrawable(view.getResources().getDrawable(boxTop).mutate());
showAltitude = view.getSettings().SHOW_ALTITUDE_INFO.get();
} }
public void createTopBarElements() { public void createTopBarElements() {
@ -129,6 +131,7 @@ public class MapInfoLayer extends OsmandMapLayer {
rightStack = new MapStackControl(view.getContext()); rightStack = new MapStackControl(view.getContext());
rightStack.addStackView(createDistanceControl()); rightStack.addStackView(createDistanceControl());
rightStack.addStackView(createAltitudeControl());
rightStack.addCollapsedView(createSpeedControl()); rightStack.addCollapsedView(createSpeedControl());
rightStack.addCollapsedView(createTimeControl()); rightStack.addCollapsedView(createTimeControl());
@ -244,6 +247,38 @@ public class MapInfoLayer extends OsmandMapLayer {
return speedControl; 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(){ private TextInfoControl createTimeControl(){
final Drawable time = view.getResources().getDrawable(R.drawable.info_time); final Drawable time = view.getResources().getDrawable(R.drawable.info_time);
final Drawable timeToGo = view.getResources().getDrawable(R.drawable.info_time_to_go); final Drawable timeToGo = view.getResources().getDrawable(R.drawable.info_time_to_go);