add map rotating to compass

git-svn-id: https://osmand.googlecode.com/svn/trunk@437 e29c36b1-1cfa-d876-8d93-3434fc2bb7b8
This commit is contained in:
Victor Shcherb 2010-08-05 08:27:52 +00:00
parent 92150907d8
commit ad181e8945
8 changed files with 52 additions and 19 deletions

View file

@ -1,5 +1,10 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<resources> <resources>
<string name="rotate_map_compass_opt">По направлению компаса</string>
<string name="rotate_map_bearing_opt">По направлению движения</string>
<string name="rotate_map_none_opt">Не вращать</string>
<string name="rotate_map_to_bearing_descr">Выберите способ как вращать карту</string>
<string name="rotate_map_to_bearing">Вращать карту</string>
<string name="show_route">Показать маршрут</string> <string name="show_route">Показать маршрут</string>
<string name="fav_imported_sucessfully">Избранные точки успешно импортированы</string> <string name="fav_imported_sucessfully">Избранные точки успешно импортированы</string>
<string name="fav_file_to_load_not_found">GPX файл, содержащий точки, не был найден в {0}</string> <string name="fav_file_to_load_not_found">GPX файл, содержащий точки, не был найден в {0}</string>
@ -237,8 +242,6 @@
<string name="navigate_to_point">Отметить точку</string> <string name="navigate_to_point">Отметить точку</string>
<string name="map_view_3d_descr">Вклюсить 3D вид для карты</string> <string name="map_view_3d_descr">Вклюсить 3D вид для карты</string>
<string name="map_view_3d">3D вид</string> <string name="map_view_3d">3D вид</string>
<string name="rotate_map_to_bearing_descr">Вращать карту при изменении направления движения</string>
<string name="rotate_map_to_bearing">Вращать карту</string>
<string name="show_poi_over_map_description">Показывать слой POI</string> <string name="show_poi_over_map_description">Показывать слой POI</string>
<string name="show_poi_over_map">POI</string> <string name="show_poi_over_map">POI</string>
<string name="map_tile_source_descr">Загружать недостающие части карты из : </string> <string name="map_tile_source_descr">Загружать недостающие части карты из : </string>

View file

@ -1,5 +1,10 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<resources> <resources>
<string name="rotate_map_compass_opt">To compass</string>
<string name="rotate_map_bearing_opt">To direction of movement</string>
<string name="rotate_map_none_opt">No rotate</string>
<string name="rotate_map_to_bearing_descr">Select way how to rotate map</string>
<string name="rotate_map_to_bearing">Rotate map</string>
<string name="show_route">Show route</string> <string name="show_route">Show route</string>
<string name="fav_imported_sucessfully">Favorite points were succesfully imported</string> <string name="fav_imported_sucessfully">Favorite points were succesfully imported</string>
<string name="fav_file_to_load_not_found">GPX file to load favorite points is not found at {0}</string> <string name="fav_file_to_load_not_found">GPX file to load favorite points is not found at {0}</string>
@ -237,8 +242,7 @@ See osmand.googlecode.com.</string>
<string name="navigate_to_point">Mark point</string> <string name="navigate_to_point">Mark point</string>
<string name="map_view_3d_descr">Enable 3D view of the map</string> <string name="map_view_3d_descr">Enable 3D view of the map</string>
<string name="map_view_3d">Map View 3D</string> <string name="map_view_3d">Map View 3D</string>
<string name="rotate_map_to_bearing_descr">Rotate map to bearing of your direction</string>
<string name="rotate_map_to_bearing">Rotate map</string>
<string name="show_poi_over_map_description">Show POI over map (use last chosen filter)</string> <string name="show_poi_over_map_description">Show POI over map (use last chosen filter)</string>
<string name="show_poi_over_map">Show POI</string> <string name="show_poi_over_map">Show POI</string>
<string name="map_tile_source_descr">Choose the source of tiles : </string> <string name="map_tile_source_descr">Choose the source of tiles : </string>

View file

@ -12,7 +12,7 @@
<!-- <CheckBoxPreference android:key="show_transport_over_map" android:title="@string/show_transport_over_map" android:summary="@string/show_transport_over_map_description"></CheckBoxPreference> --> <!-- <CheckBoxPreference android:key="show_transport_over_map" android:title="@string/show_transport_over_map" android:summary="@string/show_transport_over_map_description"></CheckBoxPreference> -->
<CheckBoxPreference android:title="@string/auto_zoom_map" android:summary="@string/auto_zoom_map_descr" android:key="auto_zoom_map"></CheckBoxPreference> <CheckBoxPreference android:title="@string/auto_zoom_map" android:summary="@string/auto_zoom_map_descr" android:key="auto_zoom_map"></CheckBoxPreference>
<CheckBoxPreference android:key="show_view_angle" android:title="@string/show_view_angle" android:summary="@string/show_view_angle_descr"></CheckBoxPreference> <CheckBoxPreference android:key="show_view_angle" android:title="@string/show_view_angle" android:summary="@string/show_view_angle_descr"></CheckBoxPreference>
<CheckBoxPreference android:key="rotate_map_to_bearing" android:title="@string/rotate_map_to_bearing" android:summary="@string/rotate_map_to_bearing_descr"></CheckBoxPreference> <ListPreference android:key="rotate_map" android:title="@string/rotate_map_to_bearing" android:summary="@string/rotate_map_to_bearing_descr"></ListPreference>
<ListPreference android:key="map_screen_orientation" android:title="@string/map_screen_orientation" android:summary="@string/map_screen_orientation_descr"></ListPreference> <ListPreference android:key="map_screen_orientation" android:title="@string/map_screen_orientation" android:summary="@string/map_screen_orientation_descr"></ListPreference>
<ListPreference android:key="position_on_map" android:title="@string/position_on_map" android:summary="@string/position_on_map_descr"></ListPreference> <ListPreference android:key="position_on_map" android:title="@string/position_on_map" android:summary="@string/position_on_map_descr"></ListPreference>
<CheckBoxPreference android:key="use_trackball_for_movements" android:title="@string/use_trackball" android:summary="@string/use_trackball_descr"></CheckBoxPreference> <CheckBoxPreference android:key="use_trackball_for_movements" android:title="@string/use_trackball" android:summary="@string/use_trackball_descr"></CheckBoxPreference>

View file

@ -270,12 +270,16 @@ public class OsmandSettings {
} }
// this value string is synchronized with settings_pref.xml preference name // this value string is synchronized with settings_pref.xml preference name
public static final String ROTATE_MAP_TO_BEARING = "rotate_map_to_bearing"; //$NON-NLS-1$ public static final String ROTATE_MAP = "rotate_map"; //$NON-NLS-1$
public static final boolean ROTATE_MAP_TO_BEARING_DEF = false; public static final int ROTATE_MAP_TO_BEARING_DEF = 0;
public static final int ROTATE_MAP_NONE = 0;
public static final int ROTATE_MAP_BEARING = 1;
public static final int ROTATE_MAP_COMPASS = 2;
public static boolean isRotateMapToBearing(Context ctx) { // return 0 - no rotate, 1 - to bearing, 2 - to compass
public static int getRotateMap(Context ctx) {
SharedPreferences prefs = ctx.getSharedPreferences(SHARED_PREFERENCES_NAME, Context.MODE_WORLD_READABLE); SharedPreferences prefs = ctx.getSharedPreferences(SHARED_PREFERENCES_NAME, Context.MODE_WORLD_READABLE);
return prefs.getBoolean(ROTATE_MAP_TO_BEARING, ROTATE_MAP_TO_BEARING_DEF); return prefs.getInt(ROTATE_MAP, ROTATE_MAP_TO_BEARING_DEF);
} }
// this value string is synchronized with settings_pref.xml preference name // this value string is synchronized with settings_pref.xml preference name

View file

@ -142,6 +142,7 @@ public class MapActivity extends Activity implements IMapLocationListener, Senso
private Handler mapPositionHandler = null; private Handler mapPositionHandler = null;
private int APP_NOTIFICATION_ID; private int APP_NOTIFICATION_ID;
private int currentScreenOrientation; private int currentScreenOrientation;
private int currentMapRotation;
private Dialog progressDlg = null; private Dialog progressDlg = null;
@ -397,7 +398,7 @@ public class MapActivity extends Activity implements IMapLocationListener, Senso
private void registerUnregisterSensor(Location location){ private void registerUnregisterSensor(Location location){
boolean show = OsmandSettings.isShowingViewAngle(this); boolean show = OsmandSettings.isShowingViewAngle(this) || OsmandSettings.getRotateMap(this) == OsmandSettings.ROTATE_MAP_COMPASS;
// show point view only if gps enabled // show point view only if gps enabled
if (sensorRegistered && (location == null || !show)) { if (sensorRegistered && (location == null || !show)) {
Log.d(LogUtil.TAG, "Disable sensor"); //$NON-NLS-1$ Log.d(LogUtil.TAG, "Disable sensor"); //$NON-NLS-1$
@ -463,11 +464,11 @@ public class MapActivity extends Activity implements IMapLocationListener, Senso
if (isMapLinkedToLocation()) { if (isMapLinkedToLocation()) {
if(OsmandSettings.isAutoZoomEnabled(this) && location.hasSpeed()){ if(OsmandSettings.isAutoZoomEnabled(this) && location.hasSpeed()){
int z = defineZoomFromSpeed(location.getSpeed(), mapView.getZoom()); int z = defineZoomFromSpeed(location.getSpeed(), mapView.getZoom());
if(mapView.getZoom() != z){ if(mapView.getZoom() != z && !mapView.mapIsAnimating()){
mapView.setZoom(z); mapView.setZoom(z);
} }
} }
if (location.hasBearing() && OsmandSettings.isRotateMapToBearing(this)) { if (location.hasBearing() && currentMapRotation == OsmandSettings.ROTATE_MAP_BEARING && !mapView.mapIsAnimating()) {
mapView.setRotate(-location.getBearing()); mapView.setRotate(-location.getBearing());
} }
mapView.setLatLon(location.getLatitude(), location.getLongitude()); mapView.setLatLon(location.getLatitude(), location.getLongitude());
@ -644,7 +645,8 @@ public class MapActivity extends Activity implements IMapLocationListener, Senso
} }
private void updateApplicationModeSettings(){ private void updateApplicationModeSettings(){
if(!OsmandSettings.isRotateMapToBearing(this)){ currentMapRotation = OsmandSettings.getRotateMap(this);
if(currentMapRotation == OsmandSettings.ROTATE_MAP_NONE){
mapView.setRotate(0); mapView.setRotate(0);
} }
if(!OsmandSettings.isShowingViewAngle(this)){ if(!OsmandSettings.isShowingViewAngle(this)){
@ -836,7 +838,11 @@ public class MapActivity extends Activity implements IMapLocationListener, Senso
if(currentScreenOrientation == 1){ if(currentScreenOrientation == 1){
val += 90; val += 90;
} }
if (currentMapRotation == OsmandSettings.ROTATE_MAP_COMPASS && !mapView.mapIsAnimating()) {
mapView.setRotate(-val);
}
locationLayer.setHeading(val); locationLayer.setHeading(val);
} }
public boolean onCreateOptionsMenu(Menu menu) { public boolean onCreateOptionsMenu(Menu menu) {

View file

@ -80,6 +80,7 @@ public class SettingsActivity extends PreferenceActivity implements OnPreference
private ListPreference applicationMode; private ListPreference applicationMode;
private ListPreference saveTrackInterval; private ListPreference saveTrackInterval;
private ListPreference rotateMap;
private ListPreference tileSourcePreference; private ListPreference tileSourcePreference;
private ListPreference positionOnMap; private ListPreference positionOnMap;
private ListPreference routerPreference; private ListPreference routerPreference;
@ -98,7 +99,6 @@ public class SettingsActivity extends PreferenceActivity implements OnPreference
// new BooleanPreference(OsmandSettings.SHOW_POI_OVER_MAP, OsmandSettings.SHOW_POI_OVER_MAP_DEF ), // new BooleanPreference(OsmandSettings.SHOW_POI_OVER_MAP, OsmandSettings.SHOW_POI_OVER_MAP_DEF ),
// new BooleanPreference(OsmandSettings.SHOW_OSM_BUGS, OsmandSettings.SHOW_OSM_BUGS_DEF), // new BooleanPreference(OsmandSettings.SHOW_OSM_BUGS, OsmandSettings.SHOW_OSM_BUGS_DEF),
new BooleanPreference(OsmandSettings.USE_INTERNET_TO_DOWNLOAD_TILES, OsmandSettings.USE_INTERNET_TO_DOWNLOAD_TILES_DEF), new BooleanPreference(OsmandSettings.USE_INTERNET_TO_DOWNLOAD_TILES, OsmandSettings.USE_INTERNET_TO_DOWNLOAD_TILES_DEF),
new BooleanPreference(OsmandSettings.ROTATE_MAP_TO_BEARING, OsmandSettings.ROTATE_MAP_TO_BEARING_DEF),
new BooleanPreference(OsmandSettings.SHOW_VIEW_ANGLE, OsmandSettings.SHOW_VIEW_ANGLE_DEF), new BooleanPreference(OsmandSettings.SHOW_VIEW_ANGLE, OsmandSettings.SHOW_VIEW_ANGLE_DEF),
new BooleanPreference(OsmandSettings.USE_TRACKBALL_FOR_MOVEMENTS, OsmandSettings.USE_TRACKBALL_FOR_MOVEMENTS_DEF), new BooleanPreference(OsmandSettings.USE_TRACKBALL_FOR_MOVEMENTS, OsmandSettings.USE_TRACKBALL_FOR_MOVEMENTS_DEF),
new BooleanPreference(OsmandSettings.USE_ENGLISH_NAMES, OsmandSettings.USE_ENGLISH_NAMES_DEF), new BooleanPreference(OsmandSettings.USE_ENGLISH_NAMES, OsmandSettings.USE_ENGLISH_NAMES_DEF),
@ -140,6 +140,8 @@ public class SettingsActivity extends PreferenceActivity implements OnPreference
userPassword.setOnPreferenceChangeListener(this); userPassword.setOnPreferenceChangeListener(this);
rotateMap =(ListPreference) screen.findPreference(OsmandSettings.ROTATE_MAP);
rotateMap.setOnPreferenceChangeListener(this);
saveTrackInterval =(ListPreference) screen.findPreference(OsmandSettings.SAVE_TRACK_INTERVAL); saveTrackInterval =(ListPreference) screen.findPreference(OsmandSettings.SAVE_TRACK_INTERVAL);
saveTrackInterval.setOnPreferenceChangeListener(this); saveTrackInterval.setOnPreferenceChangeListener(this);
positionOnMap =(ListPreference) screen.findPreference(OsmandSettings.POSITION_ON_MAP); positionOnMap =(ListPreference) screen.findPreference(OsmandSettings.POSITION_ON_MAP);
@ -232,6 +234,9 @@ public class SettingsActivity extends PreferenceActivity implements OnPreference
routeServiceWaitInterval.setEntryValues(ints); routeServiceWaitInterval.setEntryValues(ints);
routeServiceWaitInterval.setValue(OsmandSettings.getServiceOffWaitInterval(this)/1000+""); //$NON-NLS-1$ routeServiceWaitInterval.setValue(OsmandSettings.getServiceOffWaitInterval(this)/1000+""); //$NON-NLS-1$
rotateMap.setEntries(new String[]{getString(R.string.rotate_map_none_opt), getString(R.string.rotate_map_bearing_opt), getString(R.string.rotate_map_compass_opt)});
rotateMap.setEntryValues(new String[]{OsmandSettings.ROTATE_MAP_NONE+"", OsmandSettings.ROTATE_MAP_BEARING+"", OsmandSettings.ROTATE_MAP_COMPASS+""}); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
rotateMap.setValue(OsmandSettings.getRotateMap(this)+""); //$NON-NLS-1$
routeServiceProvider.setEntries(new String[]{getString(R.string.gps_provider), getString(R.string.network_provider)}); routeServiceProvider.setEntries(new String[]{getString(R.string.gps_provider), getString(R.string.network_provider)});
routeServiceProvider.setEntryValues(new String[]{LocationManager.GPS_PROVIDER, LocationManager.NETWORK_PROVIDER}); routeServiceProvider.setEntryValues(new String[]{LocationManager.GPS_PROVIDER, LocationManager.NETWORK_PROVIDER});
@ -397,6 +402,9 @@ public class SettingsActivity extends PreferenceActivity implements OnPreference
} else if (preference == routeServiceWaitInterval) { } else if (preference == routeServiceWaitInterval) {
edit.putInt(OsmandSettings.SERVICE_OFF_WAIT_INTERVAL, Integer.parseInt((String) newValue) * 1000); edit.putInt(OsmandSettings.SERVICE_OFF_WAIT_INTERVAL, Integer.parseInt((String) newValue) * 1000);
edit.commit(); edit.commit();
} else if (preference == rotateMap) {
edit.putInt(OsmandSettings.ROTATE_MAP, Integer.parseInt((String) newValue));
edit.commit();
} else if (preference == routeServiceProvider) { } else if (preference == routeServiceProvider) {
edit.putString(OsmandSettings.SERVICE_OFF_PROVIDER, (String) newValue); edit.putString(OsmandSettings.SERVICE_OFF_PROVIDER, (String) newValue);
edit.commit(); edit.commit();
@ -501,7 +509,7 @@ public class SettingsActivity extends PreferenceActivity implements OnPreference
edit.putBoolean(OsmandSettings.USE_INTERNET_TO_DOWNLOAD_TILES, true); edit.putBoolean(OsmandSettings.USE_INTERNET_TO_DOWNLOAD_TILES, true);
// edit.putBoolean(OsmandSettings.SHOW_POI_OVER_MAP, _); // edit.putBoolean(OsmandSettings.SHOW_POI_OVER_MAP, _);
edit.putBoolean(OsmandSettings.SHOW_TRANSPORT_OVER_MAP, false); edit.putBoolean(OsmandSettings.SHOW_TRANSPORT_OVER_MAP, false);
edit.putBoolean(OsmandSettings.ROTATE_MAP_TO_BEARING, true); edit.putInt(OsmandSettings.ROTATE_MAP, OsmandSettings.ROTATE_MAP_BEARING);
edit.putBoolean(OsmandSettings.SHOW_VIEW_ANGLE, false); edit.putBoolean(OsmandSettings.SHOW_VIEW_ANGLE, false);
edit.putBoolean(OsmandSettings.AUTO_ZOOM_MAP, true); edit.putBoolean(OsmandSettings.AUTO_ZOOM_MAP, true);
edit.putBoolean(OsmandSettings.SHOW_OSM_BUGS, false); edit.putBoolean(OsmandSettings.SHOW_OSM_BUGS, false);
@ -515,8 +523,8 @@ public class SettingsActivity extends PreferenceActivity implements OnPreference
// edit.putBoolean(OsmandSettings.USE_INTERNET_TO_DOWNLOAD_TILES, _); // edit.putBoolean(OsmandSettings.USE_INTERNET_TO_DOWNLOAD_TILES, _);
// edit.putBoolean(OsmandSettings.USE_INTERNET_TO_CALCULATE_ROUTE, _); // edit.putBoolean(OsmandSettings.USE_INTERNET_TO_CALCULATE_ROUTE, _);
edit.putBoolean(OsmandSettings.SHOW_POI_OVER_MAP, true); edit.putBoolean(OsmandSettings.SHOW_POI_OVER_MAP, true);
edit.putBoolean(OsmandSettings.ROTATE_MAP_TO_BEARING, true); edit.putInt(OsmandSettings.ROTATE_MAP, OsmandSettings.ROTATE_MAP_BEARING);
edit.putBoolean(OsmandSettings.SHOW_VIEW_ANGLE, false); edit.putBoolean(OsmandSettings.SHOW_VIEW_ANGLE, true);
edit.putBoolean(OsmandSettings.AUTO_ZOOM_MAP, false); edit.putBoolean(OsmandSettings.AUTO_ZOOM_MAP, false);
// edit.putBoolean(OsmandSettings.SHOW_OSM_BUGS, _); // edit.putBoolean(OsmandSettings.SHOW_OSM_BUGS, _);
// edit.putBoolean(OsmandSettings.USE_ENGLISH_NAMES, _); // edit.putBoolean(OsmandSettings.USE_ENGLISH_NAMES, _);
@ -528,7 +536,7 @@ public class SettingsActivity extends PreferenceActivity implements OnPreference
} else if(preset == ApplicationMode.PEDESTRIAN){ } else if(preset == ApplicationMode.PEDESTRIAN){
// edit.putBoolean(OsmandSettings.USE_INTERNET_TO_DOWNLOAD_TILES, _); // edit.putBoolean(OsmandSettings.USE_INTERNET_TO_DOWNLOAD_TILES, _);
edit.putBoolean(OsmandSettings.SHOW_POI_OVER_MAP, true); edit.putBoolean(OsmandSettings.SHOW_POI_OVER_MAP, true);
edit.putBoolean(OsmandSettings.ROTATE_MAP_TO_BEARING, false); edit.putInt(OsmandSettings.ROTATE_MAP, OsmandSettings.ROTATE_MAP_COMPASS);
edit.putBoolean(OsmandSettings.SHOW_VIEW_ANGLE, true); edit.putBoolean(OsmandSettings.SHOW_VIEW_ANGLE, true);
edit.putBoolean(OsmandSettings.AUTO_ZOOM_MAP, false); edit.putBoolean(OsmandSettings.AUTO_ZOOM_MAP, false);
// if(useInternetToDownloadTiles.isChecked()){ // if(useInternetToDownloadTiles.isChecked()){
@ -543,7 +551,7 @@ public class SettingsActivity extends PreferenceActivity implements OnPreference
} else if(preset == ApplicationMode.DEFAULT){ } else if(preset == ApplicationMode.DEFAULT){
// edit.putBoolean(OsmandSettings.USE_INTERNET_TO_DOWNLOAD_TILES, _); // edit.putBoolean(OsmandSettings.USE_INTERNET_TO_DOWNLOAD_TILES, _);
edit.putBoolean(OsmandSettings.SHOW_POI_OVER_MAP, true); edit.putBoolean(OsmandSettings.SHOW_POI_OVER_MAP, true);
edit.putBoolean(OsmandSettings.ROTATE_MAP_TO_BEARING, false); edit.putInt(OsmandSettings.ROTATE_MAP, OsmandSettings.ROTATE_MAP_NONE);
edit.putBoolean(OsmandSettings.SHOW_VIEW_ANGLE, false); edit.putBoolean(OsmandSettings.SHOW_VIEW_ANGLE, false);
edit.putBoolean(OsmandSettings.AUTO_ZOOM_MAP, false); edit.putBoolean(OsmandSettings.AUTO_ZOOM_MAP, false);
// edit.putBoolean(OsmandSettings.SHOW_OSM_BUGS, _); // edit.putBoolean(OsmandSettings.SHOW_OSM_BUGS, _);

View file

@ -155,6 +155,10 @@ public class AnimateDraggingMapThread implements Runnable {
stopped = true; stopped = true;
} }
public boolean isAnimating(){
return currentThread != null;
}
/** /**
* Stop dragging sync * Stop dragging sync
*/ */

View file

@ -511,6 +511,10 @@ public class OsmandMapTileView extends SurfaceView implements IMapDownloaderCall
public boolean mapIsRefreshing(){ public boolean mapIsRefreshing(){
return handler.hasMessages(1); return handler.hasMessages(1);
} }
public boolean mapIsAnimating(){
return animatedDraggingThread != null && animatedDraggingThread.isAnimating();
}
// this method could be called in non UI thread // this method could be called in non UI thread
public void refreshMap() { public void refreshMap() {
if(!handler.hasMessages(1)){ if(!handler.hasMessages(1)){