add application mode to settings

git-svn-id: https://osmand.googlecode.com/svn/trunk@163 e29c36b1-1cfa-d876-8d93-3434fc2bb7b8
This commit is contained in:
Victor Shcherb 2010-06-15 11:45:50 +00:00
parent c120a93ab7
commit 600747da08
6 changed files with 187 additions and 13 deletions

View file

@ -41,15 +41,19 @@ public class ToDoConstants {
// DONE: Load transport routes in swing.
// TODO: Create transport index, create transport activity
// 44. Introduce settings presets (car/bicycle/pedestrian/default) - show different icons for car (bigger),
// possibly change fonts, position
// GOT : Victor
// 44. Introduce settings presets (car/bicycle/pedestrian/default) - show different icons for car (bigger), possibly change fonts, position
// DONE : Introduce settings property in settings screen
// TODO : check if all is correct, change visible icon over map for car
// 45. Autozoom feature (for car navigation)
// DONE : settings preferences done
// TODO : add to Map activity algorithm of auto zooming in setLocation method
// 36. Postcode search
// 37. Get rid of exit button (!). Think about when notification should go & how clear resources if it is necessary
// DONE :
// TODO : add to app settings preference (Refresh indexes).
// 34. Suppport navigation for calculated route (example of get route from internet is in swing app).
// IDEA : Victor have ideas
@ -58,7 +62,7 @@ public class ToDoConstants {
// FUTURE RELEASES
// 43. Enable poi filter by name (?)
// 40. Support simple vector road rendering (require new index file)
// 40. Support simple vector road rendering (require new index file) (?)
// 26. Show the whole street on map (when it is chosen in search activity). Possibly extend that story to show layer with streets. (?)
// BUGS Android

View file

@ -1,5 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="search_settings">Search settings</string>
<string name="osm_settings">Osm settings</string>
<string name="auto_zoom_map_descr">Auto zoom map according to the speed</string>
<string name="auto_zoom_map">Auto zoom map</string>
<string name="additional_settings">Additional settings</string>
<string name="settings_preset_descr">Select predefined settings</string>
<string name="settings_preset">Application mode</string>
<string name="settings">Settings</string>
<string name="save_current_track_descr">Save current track to SD</string>
<string name="save_current_track">Save current track</string>
<string name="save_track_interval_descr">Choose time interval to save track</string>

View file

@ -1,23 +1,40 @@
<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen
xmlns:android="http://schemas.android.com/apk/res/android">
<PreferenceCategory android:title="@string/app_settings"><CheckBoxPreference android:summary="@string/use_english_names_descr" android:title="@string/use_english_names" android:key="use_english_names"></CheckBoxPreference>
<EditTextPreference android:title="@string/user_name" android:summary="@string/user_name_descr" android:key="user_name"></EditTextPreference>
<PreferenceCategory android:title="@string/app_settings">
<ListPreference android:summary="@string/settings_preset_descr" android:title="@string/settings_preset" android:key="application_mode"></ListPreference>
</PreferenceCategory>
<PreferenceCategory android:title="@string/map_preferences">
<CheckBoxPreference android:key="use_internet_to_download_tiles" android:title="@string/use_internet" android:summary="@string/use_internet_to_download_tile"></CheckBoxPreference>
<ListPreference android:title="@string/map_tile_source" android:summary="@string/map_tile_source_descr" android:key="map_tile_sources"></ListPreference>
<CheckBoxPreference android:key="show_poi_over_map" android:title="@string/show_poi_over_map" android:summary="@string/show_poi_over_map_description"></CheckBoxPreference>
<CheckBoxPreference android:key="show_osm_bugs" android:title="@string/show_osm_bugs" android:summary="@string/show_osm_bugs_descr"></CheckBoxPreference>
<ListPreference android:title="@string/map_tile_source" android:summary="@string/map_tile_source_descr" android:key="map_tile_sources"></ListPreference>
<PreferenceScreen android:title="@string/additional_settings">
<CheckBoxPreference android:title="@string/auto_zoom_map" android:summary="@string/auto_zoom_map_descr" android:key="auto_zoom_map"></CheckBoxPreference>
<CheckBoxPreference android:key="rotate_map_to_bearing" android:title="@string/rotate_map_to_bearing" android:summary="@string/rotate_map_to_bearing_descr"></CheckBoxPreference>
<CheckBoxPreference android:key="show_view_angle" android:title="@string/show_view_angle" android:summary="@string/show_view_angle_descr"></CheckBoxPreference>
<ListPreference android:key="position_on_map" android:title="@string/position_on_map" android:summary="@string/position_on_map_descr"></ListPreference>
</PreferenceScreen>
</PreferenceCategory>
<PreferenceCategory android:title="@string/search_settings">
<CheckBoxPreference android:summary="@string/use_english_names_descr" android:title="@string/use_english_names" android:key="use_english_names"></CheckBoxPreference>
</PreferenceCategory>
<PreferenceCategory android:title="@string/monitor_preferences">
<CheckBoxPreference android:summary="@string/save_track_to_gpx_descrp" android:title="@string/save_track_to_gpx" android:key="save_track_to_gpx"></CheckBoxPreference>
<ListPreference android:summary="@string/save_track_interval_descr" android:title="@string/save_track_interval" android:key="save_track_interval"></ListPreference>
<Preference android:summary="@string/save_current_track_descr" android:title="@string/save_current_track" android:key="save_current_track"></Preference>
</PreferenceCategory>
<PreferenceCategory android:title="@string/osm_settings">
<CheckBoxPreference android:key="show_osm_bugs" android:title="@string/show_osm_bugs" android:summary="@string/show_osm_bugs_descr"></CheckBoxPreference>
<EditTextPreference android:title="@string/user_name" android:summary="@string/user_name_descr" android:key="user_name"></EditTextPreference>
</PreferenceCategory>
</PreferenceScreen>

View file

@ -13,6 +13,22 @@ import com.osmand.osm.LatLon;
public class OsmandSettings {
public enum ApplicationMode {
DEFAULT("Default"),
CAR("Car"),
BICYCLE("Bicycle"),
PEDESTRIAN("Pedestrian");
private final String name;
ApplicationMode(String name){
this.name = name;
}
@Override
public String toString() {
return name;
}
}
// These settings are stored in SharedPreferences
public static final String SHARED_PREFERENCES_NAME = "com.osmand.settings";
@ -45,6 +61,23 @@ public class OsmandSettings {
return prefs.edit().putString(USER_NAME, name).commit();
}
// this value string is synchronized with settings_pref.xml preference name
public static final String APPLICATION_MODE = "application_mode";
public static ApplicationMode getApplicationMode(Context ctx) {
SharedPreferences prefs = ctx.getSharedPreferences(SHARED_PREFERENCES_NAME, Context.MODE_WORLD_READABLE);
String s = prefs.getString(APPLICATION_MODE, ApplicationMode.DEFAULT.name());
try {
return ApplicationMode.valueOf(s);
} catch (IllegalArgumentException e) {
return ApplicationMode.DEFAULT;
}
}
public static boolean setApplicationMode(Context ctx, ApplicationMode p){
SharedPreferences prefs = ctx.getSharedPreferences(SHARED_PREFERENCES_NAME, Context.MODE_WORLD_READABLE);
return prefs.edit().putString(APPLICATION_MODE, p.name()).commit();
}
// this value string is synchronized with settings_pref.xml preference name
public static final String SAVE_CURRENT_TRACK = "save_current_track";
@ -77,6 +110,13 @@ public class OsmandSettings {
return prefs.getBoolean(SHOW_VIEW_ANGLE, true);
}
// this value string is synchronized with settings_pref.xml preference name
public static final String AUTO_ZOOM_MAP = "auto_zoom_map";
public static boolean isAutoZoomEnabled(Context ctx){
SharedPreferences prefs = ctx.getSharedPreferences(SHARED_PREFERENCES_NAME, Context.MODE_WORLD_READABLE);
return prefs.getBoolean(AUTO_ZOOM_MAP, false);
}
// this value string is synchronized with settings_pref.xml preference name
public static final String ROTATE_MAP_TO_BEARING = "rotate_map_to_bearing";
public static boolean isRotateMapToBearing(Context ctx){

View file

@ -16,6 +16,7 @@ import android.preference.Preference.OnPreferenceChangeListener;
import com.osmand.OsmandSettings;
import com.osmand.R;
import com.osmand.OsmandSettings.ApplicationMode;
import com.osmand.map.TileSourceManager;
import com.osmand.map.TileSourceManager.TileSourceTemplate;
@ -33,12 +34,18 @@ public class SettingsActivity extends PreferenceActivity implements OnPreference
private CheckBoxPreference saveTrackToGpx;
private ListPreference saveTrackInterval;
private Preference saveCurrentTrack;
private ListPreference applicationMode;
private CheckBoxPreference autoZoom;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
addPreferencesFromResource(R.xml.settings_pref);
PreferenceScreen screen = getPreferenceScreen();
applicationMode =(ListPreference) screen.findPreference(OsmandSettings.APPLICATION_MODE);
applicationMode.setOnPreferenceChangeListener(this);
useInternetToDownloadTiles = (CheckBoxPreference) screen.findPreference(OsmandSettings.USE_INTERNET_TO_DOWNLOAD_TILES);
useInternetToDownloadTiles.setOnPreferenceChangeListener(this);
showPoiOnMap =(CheckBoxPreference) screen.findPreference(OsmandSettings.SHOW_POI_OVER_MAP);
@ -47,6 +54,8 @@ public class SettingsActivity extends PreferenceActivity implements OnPreference
rotateMapToBearing.setOnPreferenceChangeListener(this);
showViewAngle =(CheckBoxPreference) screen.findPreference(OsmandSettings.SHOW_VIEW_ANGLE);
showViewAngle.setOnPreferenceChangeListener(this);
autoZoom =(CheckBoxPreference) screen.findPreference(OsmandSettings.AUTO_ZOOM_MAP);
autoZoom.setOnPreferenceChangeListener(this);
showOsmBugs =(CheckBoxPreference) screen.findPreference(OsmandSettings.SHOW_OSM_BUGS);
showOsmBugs.setOnPreferenceChangeListener(this);
@ -73,6 +82,10 @@ public class SettingsActivity extends PreferenceActivity implements OnPreference
@Override
protected void onResume() {
super.onResume();
updateAllSettings();
}
public void updateAllSettings(){
useInternetToDownloadTiles.setChecked(OsmandSettings.isUsingInternetToDownloadTiles(this));
showPoiOnMap.setChecked(OsmandSettings.isShowingPoiOverMap(this));
rotateMapToBearing.setChecked(OsmandSettings.isRotateMapToBearing(this));
@ -80,6 +93,7 @@ public class SettingsActivity extends PreferenceActivity implements OnPreference
showOsmBugs.setChecked(OsmandSettings.isShowingOsmBugs(this));
saveTrackToGpx.setChecked(OsmandSettings.isSavingTrackToGpx(this));
useEnglishNames.setChecked(OsmandSettings.usingEnglishNames(this));
autoZoom.setChecked(OsmandSettings.isAutoZoomEnabled(this));
String[] e = new String[] { "Center", "Bottom" };
positionOnMap.setEntryValues(e);
positionOnMap.setEntries(e);
@ -90,6 +104,17 @@ public class SettingsActivity extends PreferenceActivity implements OnPreference
saveTrackInterval.setEntryValues(new String[]{"1", "2", "5", "15", "30", "60", "300"});
saveTrackInterval.setValue(OsmandSettings.getSavingTrackInterval(this)+"");
ApplicationMode[] presets = ApplicationMode.values();
String[] values = new String[presets.length];
String[] valueEntries = new String[presets.length];
for(int i=0; i<presets.length; i++){
values[i] = presets[i].toString();
valueEntries[i] = presets[i].name();
}
applicationMode.setEntries(values);
applicationMode.setEntryValues(valueEntries);
applicationMode.setValue(OsmandSettings.getApplicationMode(this).name());
List<TileSourceTemplate> list = TileSourceManager.getKnownSourceTemplates();
String[] entries = new String[list.size()];
@ -101,7 +126,11 @@ public class SettingsActivity extends PreferenceActivity implements OnPreference
tileSourcePreference.setEntryValues(entries);
tileSourcePreference.setValue(OsmandSettings.getMapTileSourceName(this));
String mapName = " " +OsmandSettings.getMapTileSourceName(this);
tileSourcePreference.setSummary(tileSourcePreference.getSummary() + mapName);
String summary = tileSourcePreference.getSummary().toString();
if (summary.lastIndexOf(':') != -1) {
summary = summary.substring(0, summary.lastIndexOf(':') + 1);
}
tileSourcePreference.setSummary(summary + mapName);
}
@ -109,7 +138,15 @@ public class SettingsActivity extends PreferenceActivity implements OnPreference
public boolean onPreferenceChange(Preference preference, Object newValue) {
SharedPreferences prefs = getSharedPreferences(OsmandSettings.SHARED_PREFERENCES_NAME, Context.MODE_WORLD_READABLE);
Editor edit = prefs.edit();
if(preference == showPoiOnMap){
if(preference == applicationMode){
edit.putString(OsmandSettings.APPLICATION_MODE, (String) newValue);
setAppMode(ApplicationMode.valueOf(newValue.toString()), edit);
edit.commit();
updateAllSettings();
} else if(preference == autoZoom){
edit.putBoolean(OsmandSettings.AUTO_ZOOM_MAP, (Boolean) newValue);
edit.commit();
} else if(preference == showPoiOnMap){
edit.putBoolean(OsmandSettings.SHOW_POI_OVER_MAP, (Boolean) newValue);
edit.commit();
} else if(preference == useInternetToDownloadTiles){
@ -157,4 +194,62 @@ public class SettingsActivity extends PreferenceActivity implements OnPreference
return true;
}
public void setAppMode(ApplicationMode preset, Editor edit){
if(preset == ApplicationMode.CAR){
edit.putBoolean(OsmandSettings.USE_INTERNET_TO_DOWNLOAD_TILES, true);
// edit.putBoolean(OsmandSettings.SHOW_POI_OVER_MAP, _);
edit.putBoolean(OsmandSettings.ROTATE_MAP_TO_BEARING, true);
edit.putBoolean(OsmandSettings.SHOW_VIEW_ANGLE, false);
edit.putBoolean(OsmandSettings.AUTO_ZOOM_MAP, true);
edit.putBoolean(OsmandSettings.SHOW_OSM_BUGS, false);
// edit.putBoolean(OsmandSettings.USE_ENGLISH_NAMES, _);
edit.putBoolean(OsmandSettings.SAVE_TRACK_TO_GPX, true);
edit.putInt(OsmandSettings.SAVE_TRACK_INTERVAL, 15);
edit.putInt(OsmandSettings.POSITION_ON_MAP, OsmandSettings.BOTTOM_CONSTANT);
// edit.putString(OsmandSettings.MAP_TILE_SOURCES, _);
} else if(preset == ApplicationMode.BICYCLE){
// edit.putBoolean(OsmandSettings.USE_INTERNET_TO_DOWNLOAD_TILES, _);
edit.putBoolean(OsmandSettings.SHOW_POI_OVER_MAP, true);
edit.putBoolean(OsmandSettings.ROTATE_MAP_TO_BEARING, true);
edit.putBoolean(OsmandSettings.SHOW_VIEW_ANGLE, false);
edit.putBoolean(OsmandSettings.AUTO_ZOOM_MAP, false);
// edit.putBoolean(OsmandSettings.SHOW_OSM_BUGS, _);
// edit.putBoolean(OsmandSettings.USE_ENGLISH_NAMES, _);
edit.putBoolean(OsmandSettings.SAVE_TRACK_TO_GPX, true);
edit.putInt(OsmandSettings.SAVE_TRACK_INTERVAL, 30);
edit.putInt(OsmandSettings.POSITION_ON_MAP, OsmandSettings.BOTTOM_CONSTANT);
// edit.putString(OsmandSettings.MAP_TILE_SOURCES, _);
} else if(preset == ApplicationMode.PEDESTRIAN){
// edit.putBoolean(OsmandSettings.USE_INTERNET_TO_DOWNLOAD_TILES, _);
edit.putBoolean(OsmandSettings.SHOW_POI_OVER_MAP, true);
edit.putBoolean(OsmandSettings.ROTATE_MAP_TO_BEARING, false);
edit.putBoolean(OsmandSettings.SHOW_VIEW_ANGLE, true);
edit.putBoolean(OsmandSettings.AUTO_ZOOM_MAP, false);
if(useInternetToDownloadTiles.isChecked()){
edit.putBoolean(OsmandSettings.SHOW_OSM_BUGS, true);
}
// edit.putBoolean(OsmandSettings.USE_ENGLISH_NAMES, _);
edit.putBoolean(OsmandSettings.SAVE_TRACK_TO_GPX, false);
// edit.putInt(OsmandSettings.SAVE_TRACK_INTERVAL, _);
edit.putInt(OsmandSettings.POSITION_ON_MAP, OsmandSettings.CENTER_CONSTANT);
// edit.putString(OsmandSettings.MAP_TILE_SOURCES, _);
} else if(preset == ApplicationMode.DEFAULT){
// edit.putBoolean(OsmandSettings.USE_INTERNET_TO_DOWNLOAD_TILES, _);
edit.putBoolean(OsmandSettings.SHOW_POI_OVER_MAP, true);
edit.putBoolean(OsmandSettings.ROTATE_MAP_TO_BEARING, false);
edit.putBoolean(OsmandSettings.SHOW_VIEW_ANGLE, false);
edit.putBoolean(OsmandSettings.AUTO_ZOOM_MAP, false);
// edit.putBoolean(OsmandSettings.SHOW_OSM_BUGS, _);
// edit.putBoolean(OsmandSettings.USE_ENGLISH_NAMES, _);
// edit.putBoolean(OsmandSettings.SAVE_TRACK_TO_GPX, _);
// edit.putInt(OsmandSettings.SAVE_TRACK_INTERVAL, _);
edit.putInt(OsmandSettings.POSITION_ON_MAP, OsmandSettings.CENTER_CONSTANT);
// edit.putString(OsmandSettings.MAP_TILE_SOURCES, _);
}
}
}

View file

@ -10,6 +10,7 @@ import android.graphics.RectF;
import android.graphics.Paint.Style;
import android.location.Location;
import com.osmand.OsmandSettings.ApplicationMode;
import com.osmand.osm.MapUtils;
public class PointLocationLayer implements OsmandMapLayer {
@ -22,6 +23,7 @@ public class PointLocationLayer implements OsmandMapLayer {
private Paint area;
private Paint headingPaint;
private Path pathForDirection;
private ApplicationMode preset = ApplicationMode.DEFAULT;
protected Location lastKnownLocation = null;
@ -149,6 +151,14 @@ public class PointLocationLayer implements OsmandMapLayer {
}
public ApplicationMode getPreset() {
return preset;
}
public void setSettingsPreset(ApplicationMode preset) {
this.preset = preset;
}
@Override
public boolean drawInScreenPixels() {
return false;