Auto switch day/night mode:
- added settings for sunrise/sunset,day,night,sensor auto switch - DayNightHelper contains the base switching logic - auto switching works only if render is selected which has its -night counterpart - light sensor threshold is currently hard coded git-svn-id: https://osmand.googlecode.com/svn/trunk@854 e29c36b1-1cfa-d876-8d93-3434fc2bb7b8
This commit is contained in:
parent
ed10675d40
commit
a60ef26f4d
12 changed files with 339 additions and 67 deletions
|
@ -56,7 +56,7 @@ package net.osmand;
|
|||
*
|
||||
* Known limitations:
|
||||
*
|
||||
* It is assumed that the data provided are within valie ranges
|
||||
* It is assumed that the data provided are within value ranges
|
||||
* (i.e. latitude between -90 and +90, longitude between 0 and 360,
|
||||
* a valid date, and time zone between -14 and +14.
|
||||
*
|
||||
|
@ -172,13 +172,9 @@ package net.osmand;
|
|||
*----------------------------------------------------------------------------*/
|
||||
|
||||
// Import required classes and packages
|
||||
import java.util.Calendar;
|
||||
import java.util.Date;
|
||||
import java.util.Locale;
|
||||
import java.text.MessageFormat;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.text.ParseException;
|
||||
import java.math.BigDecimal;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
import java.util.TimeZone;
|
||||
|
||||
|
||||
|
@ -189,7 +185,7 @@ import java.util.TimeZone;
|
|||
* This Java class performs calculations to determine the time of
|
||||
* sunrise and sunset given lat, long, and date.
|
||||
*
|
||||
* It is assumed that the data provided are within valie ranges
|
||||
* It is assumed that the data provided are within value ranges
|
||||
* (i.e. latitude between -90 and +90, longitude between 0 and 360,
|
||||
* a valid date, and time zone between -14 and +14.
|
||||
*
|
||||
|
@ -224,7 +220,7 @@ public class SunriseSunset
|
|||
private double dfMinRise, dfMinSet; // minute of event: SUNUP.BAS M3
|
||||
private double dfSinLat, dfCosLat; // sin and cos of latitude
|
||||
private double dfZenith; // SUNUP.BAS Z: Zenith
|
||||
private SimpleDateFormat dfmtDate; // formatting for date alone
|
||||
// private SimpleDateFormat dfmtDate; // formatting for date alone
|
||||
private SimpleDateFormat dfmtDateTime; // formatting for date and time
|
||||
private SimpleDateFormat dfmtYear; // formatting for year
|
||||
private SimpleDateFormat dfmtMonth; // formatting for month
|
||||
|
|
|
@ -14,7 +14,6 @@ public class ToDoConstants {
|
|||
|
||||
// For 0.5 release
|
||||
// 104. Add activity to show current loaded indexes and information about them
|
||||
// 108. Auto switch at night rendering.
|
||||
|
||||
// 97. For voice navigation consider current speed of vehicle. Especially when speed > 50 pronounce more than 200 m
|
||||
// 112. Investigate exiting/minimizing app (Issue)
|
||||
|
@ -48,6 +47,7 @@ public class ToDoConstants {
|
|||
// 105. Route mode fast/short (Issue)
|
||||
// 109. Update download index activity (introduce select/deselect all, update existing)
|
||||
// and make green text for already loaded indexes.
|
||||
// 108. Auto switch at night rendering.
|
||||
|
||||
// DONE SWING
|
||||
|
||||
|
|
|
@ -1,5 +1,13 @@
|
|||
<?xml version="1.0" encoding="utf-8" standalone="no"?>
|
||||
<resources>
|
||||
<string name="daynight_mode_day">Day</string>
|
||||
<string name="daynight_mode_night">Night</string>
|
||||
<string name="daynight_mode_auto">Sunrise/Sunset</string>
|
||||
<string name="daynight_mode_sensor">Light sensor</string>
|
||||
<string name="daynight_descr">Choose day/night mode switching rule</string>
|
||||
<string name="daynight_none_descr">Select renderer with night counterpart</string>
|
||||
<string name="daynight">Day/night mode</string>
|
||||
|
||||
<string name="download_files_question">Download {0} files ({1} MB)?</string>
|
||||
<string name="items_were_selected">{0} items were selected</string>
|
||||
<string name="filter_existing_indexes">Filter downloaded</string>
|
||||
|
|
|
@ -8,6 +8,7 @@
|
|||
<CheckBoxPreference android:summary="@string/use_english_names_descr" android:title="@string/use_english_names"
|
||||
android:key="use_english_names"></CheckBoxPreference>
|
||||
<ListPreference android:key="renderer" android:title="@string/renderers" android:summary="@string/renderers_descr"></ListPreference>
|
||||
<ListPreference android:key="daynight_mode" android:title="@string/daynight" android:summary="@string/daynight_descr"></ListPreference>
|
||||
<CheckBoxPreference android:summary="@string/continuous_rendering_descr" android:title="@string/continuous_rendering"
|
||||
android:key="use_step_by_step_rendering" />
|
||||
<CheckBoxPreference android:key="use_high_res_maps" android:title="@string/use_high_res_maps" android:summary="@string/use_high_res_maps_descr"></CheckBoxPreference>
|
||||
|
|
|
@ -20,6 +20,8 @@ import android.content.Context;
|
|||
import android.content.SharedPreferences;
|
||||
import android.content.SharedPreferences.Editor;
|
||||
import android.content.pm.ActivityInfo;
|
||||
import android.hardware.Sensor;
|
||||
import android.hardware.SensorManager;
|
||||
import android.location.LocationManager;
|
||||
import android.net.ConnectivityManager;
|
||||
import android.net.NetworkInfo;
|
||||
|
@ -49,6 +51,50 @@ public class OsmandSettings {
|
|||
|
||||
}
|
||||
|
||||
public enum DayNightMode {
|
||||
AUTO(R.string.daynight_mode_auto),
|
||||
DAY(R.string.daynight_mode_day),
|
||||
NIGHT(R.string.daynight_mode_night),
|
||||
SENSOR(R.string.daynight_mode_sensor);
|
||||
|
||||
private final int key;
|
||||
|
||||
DayNightMode(int key) {
|
||||
this.key = key;
|
||||
}
|
||||
|
||||
public String toHumanString(Context ctx){
|
||||
return ctx.getResources().getString(key);
|
||||
}
|
||||
|
||||
public boolean isSensor() {
|
||||
return this == SENSOR;
|
||||
}
|
||||
|
||||
public boolean isAuto() {
|
||||
return this == AUTO;
|
||||
}
|
||||
|
||||
public boolean isDay() {
|
||||
return this == DAY;
|
||||
}
|
||||
|
||||
public boolean isNight() {
|
||||
return this == NIGHT;
|
||||
}
|
||||
|
||||
public static DayNightMode[] possibleValues(Context context) {
|
||||
SensorManager mSensorManager = (SensorManager)context.getSystemService(Context.SENSOR_SERVICE);
|
||||
Sensor mLight = mSensorManager.getDefaultSensor(Sensor.TYPE_LIGHT);
|
||||
if (mLight != null) {
|
||||
return DayNightMode.values();
|
||||
} else {
|
||||
return new DayNightMode[] { AUTO, DAY, NIGHT };
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// These settings are stored in SharedPreferences
|
||||
public static final String SHARED_PREFERENCES_NAME = "net.osmand.settings"; //$NON-NLS-1$
|
||||
|
||||
|
@ -199,6 +245,23 @@ public class OsmandSettings {
|
|||
return prefs.edit().putString(APPLICATION_MODE, p.name()).commit();
|
||||
}
|
||||
|
||||
// this value string is synchronized with settings_pref.xml preference name
|
||||
public static final String DAYNIGHT_MODE = "daynight_mode"; //$NON-NLS-1$
|
||||
public static DayNightMode getDayNightMode(SharedPreferences prefs) {
|
||||
String s = prefs.getString(DAYNIGHT_MODE, DayNightMode.AUTO.name());
|
||||
try {
|
||||
return DayNightMode.valueOf(s);
|
||||
} catch (IllegalArgumentException e) {
|
||||
return DayNightMode.AUTO;
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean setDayNightMode(Context ctx, DayNightMode 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 ROUTER_SERVICE = "router_service"; //$NON-NLS-1$
|
||||
|
||||
|
@ -298,7 +361,7 @@ public class OsmandSettings {
|
|||
public static final String MAP_SCREEN_ORIENTATION = "map_screen_orientation"; //$NON-NLS-1$
|
||||
|
||||
public static int getMapOrientation(SharedPreferences prefs){
|
||||
return prefs.getInt(MAP_SCREEN_ORIENTATION, ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
|
||||
return prefs.getInt(MAP_SCREEN_ORIENTATION, ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);
|
||||
}
|
||||
|
||||
// this value string is synchronized with settings_pref.xml preference name
|
||||
|
|
150
OsmAnd/src/net/osmand/activities/DayNightHelper.java
Normal file
150
OsmAnd/src/net/osmand/activities/DayNightHelper.java
Normal file
|
@ -0,0 +1,150 @@
|
|||
package net.osmand.activities;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.TimeZone;
|
||||
|
||||
import net.osmand.LogUtil;
|
||||
import net.osmand.OsmandSettings;
|
||||
import net.osmand.OsmandSettings.DayNightMode;
|
||||
import net.osmand.SunriseSunset;
|
||||
import net.osmand.render.RendererRegistry;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
|
||||
import android.content.Context;
|
||||
import android.hardware.Sensor;
|
||||
import android.hardware.SensorEvent;
|
||||
import android.hardware.SensorEventListener;
|
||||
import android.hardware.SensorManager;
|
||||
import android.location.Location;
|
||||
import android.location.LocationManager;
|
||||
|
||||
/**
|
||||
* Class to help determine if we want to render day or night map
|
||||
* - it uses the DayNightMode enumeration for its behavior
|
||||
* - it uses the {@link RendererRegistry} to check if the night part is present
|
||||
* - it uses the LightSensor and needs calls from MapActivity on onPause and onResume to register/unregister
|
||||
* the sensor listener
|
||||
* - it uses the {@link SunriseSunset} and {@link LocationManager} to find out about sunset/sunrise and use it
|
||||
*
|
||||
* Note: the usage of SunriseSunset is not optimized in any way, it is recalculated on each demand. If this
|
||||
* way it would be resource consuming, some recalculation threshold could be specified to recalculate the sun-rise/set
|
||||
* only sometimes.
|
||||
* Note2: the light sensor threshold is hard coded to {@link SensorManager#LIGHT_CLOUDY} and could be made customizable
|
||||
*
|
||||
* @author pavol.zibrita
|
||||
*/
|
||||
public class DayNightHelper implements SensorEventListener {
|
||||
private static final Log log = LogUtil.getLog(DayNightHelper.class);
|
||||
|
||||
String currentRenderName = "";
|
||||
boolean daynightcheck = false;
|
||||
boolean sensorcheck = false;
|
||||
private final OsmandApplication osmandApplication;
|
||||
|
||||
public DayNightHelper(OsmandApplication osmandApplication) {
|
||||
this.osmandApplication = osmandApplication;
|
||||
setDayNightMode(OsmandSettings.getDayNightMode(OsmandSettings
|
||||
.getPrefs(osmandApplication)));
|
||||
}
|
||||
|
||||
DayNightMode dayNightMode = DayNightMode.AUTO;
|
||||
private DayNightHelper listener;
|
||||
private float lux = SensorManager.LIGHT_SUNLIGHT;
|
||||
|
||||
public void setDayNightMode(DayNightMode mode) {
|
||||
if (this.dayNightMode != mode) {
|
||||
this.dayNightMode = mode;
|
||||
this.currentRenderName = "";
|
||||
this.daynightcheck = false;
|
||||
this.sensorcheck = false;
|
||||
osmandApplication.getResourceManager().getRenderer().clearCache();
|
||||
}
|
||||
unregisterServiceListener();
|
||||
registerServiceListener();
|
||||
}
|
||||
|
||||
public boolean getDayNightRenderer() {
|
||||
RendererRegistry registry = RendererRegistry.getRegistry();
|
||||
String name = registry.getCurrentSelectedRenderer().name;
|
||||
boolean day = true;
|
||||
if (!currentRenderName.equals(name)) {
|
||||
currentRenderName = name;
|
||||
if (registry.hasDayNightRenderer(name)) {
|
||||
if (dayNightMode.isDay()) {
|
||||
day = true;
|
||||
} else if (dayNightMode.isNight()) {
|
||||
day = false;
|
||||
} else if (dayNightMode.isAuto()) {
|
||||
daynightcheck = true;
|
||||
} else if (dayNightMode.isSensor()) {
|
||||
sensorcheck = true;
|
||||
registerServiceListener();
|
||||
}
|
||||
}
|
||||
}
|
||||
// We are in auto mode!
|
||||
if (daynightcheck) {
|
||||
LocationManager locationProvider = (LocationManager) osmandApplication
|
||||
.getSystemService(Context.LOCATION_SERVICE); // Or use
|
||||
// LocationManager.GPS_PROVIDER
|
||||
Location lastKnownLocation = locationProvider
|
||||
.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);
|
||||
SunriseSunset daynightSwitch = new SunriseSunset(
|
||||
lastKnownLocation.getLatitude(),
|
||||
lastKnownLocation.getLongitude(), new Date(), TimeZone
|
||||
.getDefault().getRawOffset());
|
||||
day = daynightSwitch.isDaytime();
|
||||
log.debug("Sunrise/sunset setting to day: " + day);
|
||||
}
|
||||
if (sensorcheck) {
|
||||
day = lux > SensorManager.LIGHT_CLOUDY;
|
||||
log.debug("lux value:" + lux + " setting to day: " + day);
|
||||
}
|
||||
return day;
|
||||
}
|
||||
|
||||
public void onMapPause() {
|
||||
unregisterServiceListener();
|
||||
}
|
||||
|
||||
private void unregisterServiceListener() {
|
||||
if (listener != null) {
|
||||
SensorManager mSensorManager = (SensorManager) osmandApplication
|
||||
.getSystemService(Context.SENSOR_SERVICE);
|
||||
Sensor mLight = mSensorManager.getDefaultSensor(Sensor.TYPE_LIGHT);
|
||||
mSensorManager.unregisterListener(listener, mLight);
|
||||
listener = null;
|
||||
}
|
||||
}
|
||||
|
||||
public void onMapResume() {
|
||||
registerServiceListener();
|
||||
}
|
||||
|
||||
private void registerServiceListener() {
|
||||
if (dayNightMode.isSensor() && sensorcheck) {
|
||||
SensorManager mSensorManager = (SensorManager) osmandApplication
|
||||
.getSystemService(Context.SENSOR_SERVICE);
|
||||
Sensor mLight = mSensorManager.getDefaultSensor(Sensor.TYPE_LIGHT);
|
||||
List<Sensor> list = mSensorManager.getSensorList(Sensor.TYPE_LIGHT);
|
||||
log.info("Light sensors:" + list.size());
|
||||
mSensorManager.registerListener(this, mLight,
|
||||
SensorManager.SENSOR_DELAY_NORMAL);
|
||||
listener = this;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAccuracyChanged(Sensor sensor, int accuracy) {
|
||||
// nothing to do here
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSensorChanged(SensorEvent event) {
|
||||
if (event.values.length > 0) {
|
||||
lux = event.values[0];
|
||||
}
|
||||
}
|
||||
}
|
|
@ -700,6 +700,7 @@ public class MapActivity extends Activity implements IMapLocationListener, Senso
|
|||
currentLocationProvider = null;
|
||||
routingHelper.setUiActivity(null);
|
||||
|
||||
((OsmandApplication)getApplication()).getDaynightHelper().onMapPause();
|
||||
|
||||
OsmandSettings.setLastKnownMapLocation(this, (float) mapView.getLatitude(), (float) mapView.getLongitude());
|
||||
AnimateDraggingMapThread animatedThread = mapView.getAnimatedDraggingThread();
|
||||
|
@ -866,6 +867,8 @@ public class MapActivity extends Activity implements IMapLocationListener, Senso
|
|||
if(progress != null){
|
||||
((OsmandApplication) getApplication()).getResourceManager().setBusyIndicator(new BusyIndicator(this, progress));
|
||||
}
|
||||
|
||||
((OsmandApplication)getApplication()).getDaynightHelper().onMapResume();
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -40,6 +40,7 @@ public class OsmandApplication extends Application {
|
|||
private List<String> startingWarnings;
|
||||
private ProgressDialog progressDlg;
|
||||
private Handler uiHandler;
|
||||
private DayNightHelper daynightHelper;
|
||||
|
||||
|
||||
|
||||
|
@ -48,6 +49,7 @@ public class OsmandApplication extends Application {
|
|||
super.onCreate();
|
||||
routingHelper = new RoutingHelper(OsmandSettings.getApplicationMode(OsmandSettings.getPrefs(OsmandApplication.this)), OsmandApplication.this, player);
|
||||
manager = new ResourceManager(this);
|
||||
daynightHelper = new DayNightHelper(this);
|
||||
uiHandler = new Handler();
|
||||
startApplication();
|
||||
}
|
||||
|
@ -70,6 +72,10 @@ public class OsmandApplication extends Application {
|
|||
return manager;
|
||||
}
|
||||
|
||||
public DayNightHelper getDaynightHelper() {
|
||||
return daynightHelper;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLowMemory() {
|
||||
super.onLowMemory();
|
||||
|
|
|
@ -12,12 +12,13 @@ import java.util.Set;
|
|||
|
||||
import net.osmand.NavigationService;
|
||||
import net.osmand.OsmandSettings;
|
||||
import net.osmand.OsmandSettings.ApplicationMode;
|
||||
import net.osmand.OsmandSettings.DayNightMode;
|
||||
import net.osmand.PoiFiltersHelper;
|
||||
import net.osmand.ProgressDialogImplementation;
|
||||
import net.osmand.R;
|
||||
import net.osmand.ResourceManager;
|
||||
import net.osmand.SQLiteTileSource;
|
||||
import net.osmand.OsmandSettings.ApplicationMode;
|
||||
import net.osmand.activities.RouteProvider.RouteService;
|
||||
import net.osmand.map.TileSourceManager;
|
||||
import net.osmand.map.TileSourceManager.TileSourceTemplate;
|
||||
|
@ -40,10 +41,10 @@ import android.preference.CheckBoxPreference;
|
|||
import android.preference.EditTextPreference;
|
||||
import android.preference.ListPreference;
|
||||
import android.preference.Preference;
|
||||
import android.preference.PreferenceActivity;
|
||||
import android.preference.PreferenceScreen;
|
||||
import android.preference.Preference.OnPreferenceChangeListener;
|
||||
import android.preference.Preference.OnPreferenceClickListener;
|
||||
import android.preference.PreferenceActivity;
|
||||
import android.preference.PreferenceScreen;
|
||||
import android.widget.Toast;
|
||||
|
||||
public class SettingsActivity extends PreferenceActivity implements OnPreferenceChangeListener, OnPreferenceClickListener {
|
||||
|
@ -83,6 +84,7 @@ public class SettingsActivity extends PreferenceActivity implements OnPreference
|
|||
private Preference downloadIndexes;
|
||||
|
||||
private ListPreference applicationMode;
|
||||
private ListPreference daynightMode;
|
||||
private ListPreference saveTrackInterval;
|
||||
private ListPreference rotateMap;
|
||||
private ListPreference tileSourcePreference;
|
||||
|
@ -145,6 +147,8 @@ public class SettingsActivity extends PreferenceActivity implements OnPreference
|
|||
|
||||
applicationMode =(ListPreference) screen.findPreference(OsmandSettings.APPLICATION_MODE);
|
||||
applicationMode.setOnPreferenceChangeListener(this);
|
||||
daynightMode =(ListPreference) screen.findPreference(OsmandSettings.DAYNIGHT_MODE);
|
||||
daynightMode.setOnPreferenceChangeListener(this);
|
||||
rotateMap =(ListPreference) screen.findPreference(OsmandSettings.ROTATE_MAP);
|
||||
rotateMap.setOnPreferenceChangeListener(this);
|
||||
saveTrackInterval =(ListPreference) screen.findPreference(OsmandSettings.SAVE_TRACK_INTERVAL);
|
||||
|
@ -212,75 +216,77 @@ public class SettingsActivity extends PreferenceActivity implements OnPreference
|
|||
positionOnMap.setEntries(e);
|
||||
positionOnMap.setValueIndex(OsmandSettings.getPositionOnMap(prefs));
|
||||
|
||||
|
||||
saveTrackInterval.setEntries(new String[]{
|
||||
fill(saveTrackInterval, new String[]{
|
||||
resources.getString(R.string.interval_1_second),
|
||||
resources.getString(R.string.interval_2_seconds),
|
||||
resources.getString(R.string.interval_5_seconds),
|
||||
resources.getString(R.string.interval_15_seconds),
|
||||
resources.getString(R.string.interval_30_seconds),
|
||||
resources.getString(R.string.interval_1_minute),
|
||||
resources.getString(R.string.interval_5_minutes)});
|
||||
saveTrackInterval.setEntryValues(new String[]{"1", "2", "5", "15", "30", "60", "300"}); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$
|
||||
saveTrackInterval.setValue(OsmandSettings.getSavingTrackInterval(prefs)+""); //$NON-NLS-1$
|
||||
resources.getString(R.string.interval_5_minutes)}, //
|
||||
new String[]{"1", "2", "5", "15", "30", "60", "300"}, //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$
|
||||
OsmandSettings.getSavingTrackInterval(prefs)+""); //$NON-NLS-1$
|
||||
|
||||
String[] ints = new String[]{"0", "1", "2", "5", "8", "10", "15", "20", "25", "30", "40", "45", "60", "90" }; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$ //$NON-NLS-8$ //$NON-NLS-9$ //$NON-NLS-10$ //$NON-NLS-11$ //$NON-NLS-12$ //$NON-NLS-13$ //$NON-NLS-14$
|
||||
String[] intDescriptions = new String[ints.length];
|
||||
for(int i=0; i<intDescriptions.length; i++){
|
||||
intDescriptions[i] = ints[i] + " " + getString(R.string.int_min); //$NON-NLS-1$
|
||||
}
|
||||
routeServiceInterval.setEntries(intDescriptions);
|
||||
routeServiceInterval.setEntryValues(ints);
|
||||
routeServiceInterval.setValue(OsmandSettings.getServiceOffInterval(prefs)/60000+""); //$NON-NLS-1$
|
||||
fill(routeServiceInterval, intDescriptions, ints, OsmandSettings.getServiceOffInterval(prefs)/60000+""); //$NON-NLS-1$
|
||||
|
||||
ints = new String[]{"15", "30", "45", "60", "90", "120", "180", "300", "600"}; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$ //$NON-NLS-8$ //$NON-NLS-9$
|
||||
intDescriptions = new String[ints.length];
|
||||
for(int i=0; i<intDescriptions.length; i++){
|
||||
intDescriptions[i] = ints[i] + " " + getString(R.string.int_seconds); //$NON-NLS-1$
|
||||
}
|
||||
routeServiceWaitInterval.setEntries(intDescriptions);
|
||||
routeServiceWaitInterval.setEntryValues(ints);
|
||||
routeServiceWaitInterval.setValue(OsmandSettings.getServiceOffWaitInterval(prefs)/1000+""); //$NON-NLS-1$
|
||||
fill(routeServiceWaitInterval, intDescriptions, ints, OsmandSettings.getServiceOffWaitInterval(prefs)/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(prefs)+""); //$NON-NLS-1$
|
||||
fill(rotateMap, //
|
||||
new String[]{getString(R.string.rotate_map_none_opt), getString(R.string.rotate_map_bearing_opt), getString(R.string.rotate_map_compass_opt)}, //
|
||||
new String[]{OsmandSettings.ROTATE_MAP_NONE+"", OsmandSettings.ROTATE_MAP_BEARING+"", OsmandSettings.ROTATE_MAP_COMPASS+""}, //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
|
||||
OsmandSettings.getRotateMap(prefs)+""); //$NON-NLS-1$
|
||||
|
||||
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.setValue(OsmandSettings.getServiceOffProvider(prefs));
|
||||
fill(routeServiceProvider,//
|
||||
new String[]{getString(R.string.gps_provider), getString(R.string.network_provider)}, //
|
||||
new String[]{LocationManager.GPS_PROVIDER, LocationManager.NETWORK_PROVIDER}, //
|
||||
OsmandSettings.getServiceOffProvider(prefs));
|
||||
|
||||
routeServiceEnabled.setChecked(OsmandSettings.getServiceOffEnabled(prefs));
|
||||
|
||||
mapScreenOrientation.setEntries(new String[]{
|
||||
fill(mapScreenOrientation, //
|
||||
new String[] {
|
||||
resources.getString(R.string.map_orientation_portrait),
|
||||
resources.getString(R.string.map_orientation_landscape),
|
||||
resources.getString(R.string.map_orientation_default),
|
||||
});
|
||||
mapScreenOrientation.setEntryValues(new String[]{ActivityInfo.SCREEN_ORIENTATION_PORTRAIT+"", //$NON-NLS-1$
|
||||
ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE+"", ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED+""}); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
mapScreenOrientation.setValue(OsmandSettings.getMapOrientation(prefs)+""); //$NON-NLS-1$
|
||||
resources.getString(R.string.map_orientation_default), }, //
|
||||
new String[] {
|
||||
ActivityInfo.SCREEN_ORIENTATION_PORTRAIT + "", //$NON-NLS-1$
|
||||
ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE + "", ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED + "" }, //$NON-NLS-1$ //$NON-NLS-2$
|
||||
OsmandSettings.getMapOrientation(prefs) + ""); //$NON-NLS-1$
|
||||
|
||||
ApplicationMode[] presets = ApplicationMode.values();
|
||||
String[] names = new String[presets.length];
|
||||
String[] values = new String[presets.length];
|
||||
String[] valueEntries = new String[presets.length];
|
||||
for(int i=0; i<presets.length; i++){
|
||||
values[i] = ApplicationMode.toHumanString(presets[i], this);
|
||||
valueEntries[i] = presets[i].name();
|
||||
names[i] = ApplicationMode.toHumanString(presets[i], this);
|
||||
values[i] = presets[i].name();
|
||||
}
|
||||
applicationMode.setEntries(values);
|
||||
applicationMode.setEntryValues(valueEntries);
|
||||
applicationMode.setValue(OsmandSettings.getApplicationMode(prefs).name());
|
||||
fill(applicationMode, names, values, OsmandSettings.getApplicationMode(prefs).name());
|
||||
|
||||
DayNightMode[] dnpresets = DayNightMode.possibleValues(this);
|
||||
names = new String[dnpresets.length];
|
||||
values = new String[dnpresets.length];
|
||||
for(int i=0; i< dnpresets.length; i++){
|
||||
names[i] = dnpresets[i].toHumanString(this);
|
||||
values[i] = dnpresets[i].name();
|
||||
}
|
||||
fill(daynightMode, names, values, OsmandSettings.getDayNightMode(prefs).name());
|
||||
|
||||
String[] entries = new String[RouteService.values().length];
|
||||
String entry = OsmandSettings.getRouterService(prefs).getName();
|
||||
for(int i=0; i<entries.length; i++){
|
||||
entries[i] = RouteService.values()[i].getName();
|
||||
}
|
||||
routerPreference.setEntries(entries);
|
||||
routerPreference.setEntryValues(entries);
|
||||
routerPreference.setValue(entry);
|
||||
fill(routerPreference,entries,entries,entry);
|
||||
|
||||
// read available voice data
|
||||
File extStorage = new File(Environment.getExternalStorageDirectory(), ResourceManager.VOICE_PATH);
|
||||
|
@ -309,11 +315,7 @@ public class SettingsActivity extends PreferenceActivity implements OnPreference
|
|||
|
||||
String vectorRenderer = OsmandSettings.getVectorRenderer(prefs);
|
||||
Collection<String> rendererNames = RendererRegistry.getRegistry().getRendererNames();
|
||||
entries = new String[rendererNames.size()];
|
||||
k = 0;
|
||||
for(String s : rendererNames){
|
||||
entries[k++] = s;
|
||||
}
|
||||
entries = (String[]) rendererNames.toArray(new String[rendererNames.size()]);
|
||||
rendererPreference.setEntries(entries);
|
||||
rendererPreference.setEntryValues(entries);
|
||||
if(rendererNames.contains(vectorRenderer)){
|
||||
|
@ -321,6 +323,7 @@ public class SettingsActivity extends PreferenceActivity implements OnPreference
|
|||
} else {
|
||||
rendererPreference.setValueIndex(0);
|
||||
}
|
||||
updateDayNightAccess(vectorRenderer);
|
||||
|
||||
int startZoom = 12;
|
||||
int endZoom = 19;
|
||||
|
@ -328,29 +331,24 @@ public class SettingsActivity extends PreferenceActivity implements OnPreference
|
|||
for (int i = startZoom; i <= endZoom; i++) {
|
||||
entries[i - startZoom] = i + ""; //$NON-NLS-1$
|
||||
}
|
||||
maxLevelToDownload.setEntries(entries);
|
||||
maxLevelToDownload.setEntryValues(entries);
|
||||
maxLevelToDownload.setValue(OsmandSettings.getMaximumLevelToDownloadTile(prefs)+""); //$NON-NLS-1$
|
||||
|
||||
fill(maxLevelToDownload, entries, entries, OsmandSettings.getMaximumLevelToDownloadTile(prefs)+""); //$NON-NLS-1$
|
||||
|
||||
Map<String, String> entriesMap = getTileSourceEntries(this);
|
||||
entries = new String[entriesMap.size() + 1];
|
||||
valueEntries = new String[entriesMap.size() + 1];
|
||||
valueEntries[0] = VECTOR_MAP;
|
||||
values = new String[entriesMap.size() + 1];
|
||||
values[0] = VECTOR_MAP;
|
||||
entries[0] = getString(R.string.vector_data);
|
||||
int ki = 1;
|
||||
for(Map.Entry<String, String> es : entriesMap.entrySet()){
|
||||
entries[ki] = es.getValue();
|
||||
valueEntries[ki] = es.getKey();
|
||||
values[ki] = es.getKey();
|
||||
ki++;
|
||||
}
|
||||
|
||||
tileSourcePreference.setEntries(entries);
|
||||
tileSourcePreference.setEntryValues(valueEntries);
|
||||
String value = OsmandSettings.isUsingMapVectorData(prefs)? VECTOR_MAP : OsmandSettings.getMapTileSourceName(prefs);
|
||||
fill(tileSourcePreference, entries, values, value);
|
||||
|
||||
String mapName = " " + (OsmandSettings.isUsingMapVectorData(prefs) ? getString(R.string.vector_data) : //$NON-NLS-1$
|
||||
OsmandSettings.getMapTileSourceName(prefs));
|
||||
tileSourcePreference.setValue(value);
|
||||
String summary = tileSourcePreference.getSummary().toString();
|
||||
if (summary.lastIndexOf(':') != -1) {
|
||||
summary = summary.substring(0, summary.lastIndexOf(':') + 1);
|
||||
|
@ -358,6 +356,13 @@ public class SettingsActivity extends PreferenceActivity implements OnPreference
|
|||
tileSourcePreference.setSummary(summary + mapName);
|
||||
}
|
||||
|
||||
private void fill(ListPreference component, String[] list, String[] values, String selected)
|
||||
{
|
||||
component.setEntries(list);
|
||||
component.setEntryValues(values);
|
||||
component.setValue(selected);
|
||||
}
|
||||
|
||||
public static Map<String, String> getTileSourceEntries(Context ctx){
|
||||
Map<String, String> map = new LinkedHashMap<String, String>();
|
||||
File dir = new File(Environment.getExternalStorageDirectory(), ResourceManager.TILES_PATH);
|
||||
|
@ -420,6 +425,10 @@ public class SettingsActivity extends PreferenceActivity implements OnPreference
|
|||
setAppMode(ApplicationMode.valueOf(newValue.toString()), edit, (OsmandApplication) getApplication(), old);
|
||||
edit.commit();
|
||||
updateAllSettings();
|
||||
} else if(preference == daynightMode){
|
||||
edit.putString(OsmandSettings.DAYNIGHT_MODE, (String) newValue);
|
||||
((OsmandApplication)getApplication()).getDaynightHelper().setDayNightMode(DayNightMode.valueOf(newValue.toString()));
|
||||
edit.commit();
|
||||
} else if(preference == mapScreenOrientation){
|
||||
edit.putInt(OsmandSettings.MAP_SCREEN_ORIENTATION, Integer.parseInt(newValue.toString()));
|
||||
edit.commit();
|
||||
|
@ -483,6 +492,7 @@ public class SettingsActivity extends PreferenceActivity implements OnPreference
|
|||
Toast.makeText(this, R.string.renderer_load_exception, Toast.LENGTH_SHORT).show();
|
||||
} else {
|
||||
RendererRegistry.getRegistry().setCurrentSelectedRender(loaded);
|
||||
updateDayNightAccess(newValue);
|
||||
edit.putString(OsmandSettings.RENDERER, (String) newValue);
|
||||
Toast.makeText(this, R.string.renderer_load_sucess, Toast.LENGTH_SHORT).show();
|
||||
((OsmandApplication)getApplication()).getResourceManager().getRenderer().clearCache();
|
||||
|
@ -517,6 +527,16 @@ public class SettingsActivity extends PreferenceActivity implements OnPreference
|
|||
return true;
|
||||
}
|
||||
|
||||
private void updateDayNightAccess(Object newValue) {
|
||||
if (newValue != null && RendererRegistry.getRegistry().hasDayNightRenderer((String)newValue)) {
|
||||
daynightMode.setSummary(R.string.daynight_descr);
|
||||
daynightMode.setEnabled(true);
|
||||
} else {
|
||||
daynightMode.setSummary(R.string.daynight_none_descr);
|
||||
daynightMode.setEnabled(false);
|
||||
}
|
||||
}
|
||||
|
||||
public void reloadIndexes(){
|
||||
progressDlg = ProgressDialog.show(this, getString(R.string.loading_data), getString(R.string.reading_indexes), true);
|
||||
final ProgressDialogImplementation impl = new ProgressDialogImplementation(progressDlg);
|
||||
|
|
|
@ -45,6 +45,11 @@ public class BaseOsmandRender implements RenderingRuleVisitor {
|
|||
public BaseOsmandRender(){
|
||||
}
|
||||
|
||||
public boolean isDayRender()
|
||||
{
|
||||
return !name.endsWith(RendererRegistry.NIGHT_SUFFIX);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void rendering(String name, String depends, int defaultColor) {
|
||||
this.name = name;
|
||||
|
|
|
@ -13,6 +13,7 @@ import java.util.List;
|
|||
import java.util.Map;
|
||||
|
||||
import net.osmand.LogUtil;
|
||||
import net.osmand.activities.OsmandApplication;
|
||||
import net.osmand.binary.BinaryMapDataObject;
|
||||
import net.osmand.binary.BinaryMapIndexReader.TagValuePair;
|
||||
import net.osmand.data.preparation.MapTileDownloader.IMapDownloaderCallback;
|
||||
|
@ -272,7 +273,8 @@ public class OsmandRenderer {
|
|||
|
||||
public Bitmap generateNewBitmap(RenderingContext rc, List<BinaryMapDataObject> objects, Bitmap bmp, boolean useEnglishNames, List<IMapDownloaderCallback> notifyList) {
|
||||
long now = System.currentTimeMillis();
|
||||
render = RendererRegistry.getRegistry().getCurrentSelectedRenderer();
|
||||
boolean renderDay = ((OsmandApplication)context.getApplicationContext()).getDaynightHelper().getDayNightRenderer();
|
||||
render = RendererRegistry.getRegistry().getCurrentSelectedRendererForDayNight(renderDay);
|
||||
|
||||
// fill area
|
||||
Canvas cv = new Canvas(bmp);
|
||||
|
|
|
@ -74,16 +74,24 @@ public class RendererRegistry {
|
|||
return renderer;
|
||||
}
|
||||
|
||||
public boolean hasDayNightRenderer(String name){
|
||||
return hasRender(name) && hasRender(name + NIGHT_SUFFIX);
|
||||
}
|
||||
|
||||
public BaseOsmandRender getRenderer(String name){
|
||||
if(renderers.containsKey(name)){
|
||||
return renderers.get(name);
|
||||
}
|
||||
if(!externalRenderers.containsKey(name) && !internalRenderers.containsKey(name)){
|
||||
if(!hasRender(name)){
|
||||
return null;
|
||||
}
|
||||
return getRenderer(name, new LinkedHashSet<String>());
|
||||
}
|
||||
|
||||
private boolean hasRender(String name) {
|
||||
return externalRenderers.containsKey(name) || internalRenderers.containsKey(name);
|
||||
}
|
||||
|
||||
private BaseOsmandRender getRenderer(String name, Set<String> loadedRenderers) {
|
||||
try {
|
||||
return loadRenderer(name);
|
||||
|
@ -153,4 +161,14 @@ public class RendererRegistry {
|
|||
this.currentSelectedRender = currentSelectedRender;
|
||||
}
|
||||
|
||||
public BaseOsmandRender getCurrentSelectedRendererForDayNight(boolean forDay) {
|
||||
BaseOsmandRender local = getCurrentSelectedRenderer();
|
||||
if (forDay && local.isDayRender()) {
|
||||
return local;
|
||||
} else {
|
||||
BaseOsmandRender localNight = getRenderer(local.name + NIGHT_SUFFIX);
|
||||
return localNight != null ? localNight : local;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue