Make map settings as plugin

This commit is contained in:
Victor Shcherb 2012-05-24 20:29:41 +02:00
parent 3e7ef38464
commit bc315a5161
10 changed files with 370 additions and 201 deletions

View file

@ -18,7 +18,7 @@
<uses-permission android:name="android.permission.WAKE_LOCK"></uses-permission>
<application android:icon="@drawable/icon" android:label="@string/app_name" android:theme="@style/OsmandTheme"
android:debuggable="true" android:name="net.osmand.plus.OsmandApplication"
android:debuggable="true" android:name=".OsmandApplication"
android:backupAgent="net.osmand.plus.OsmandBackupAgent" android:restoreAnyVersion="true">
<activity android:name="net.osmand.plus.activities.MainMenuActivity"
android:label="@string/app_name">
@ -68,7 +68,7 @@
<activity android:name="net.osmand.plus.activities.LocalIndexesActivity" android:label="@string/local_index_descr_title"></activity>
<activity android:name="net.osmand.plus.osmedit.LocalOpenstreetmapActivity" android:label="@string/local_openstreetmap_descr_title"></activity>
<service android:process="net.osmand.plus" android:label="@string/process_navigation_service" android:name="net.osmand.plus.NavigationService">
<service android:process="net.osmand.plus" android:label="@string/process_navigation_service" android:name=".NavigationService">
<intent-filter><action android:name="net.osmand.plus.NavigationService"></action></intent-filter>
</service>
<receiver android:name="net.osmand.plus.OnNavigationServiceAlarmReceiver"/>
@ -81,7 +81,7 @@
<action android:name="com.android.vending.INSTALL_REFERRER" />
</intent-filter>
</receiver>
<activity android:name="net.osmand.plus.activities.OsmandBidForFixActivity"></activity>
<activity android:name=".activities.OsmandBidForFixActivity"></activity>
</application>

View file

@ -1,5 +1,16 @@
<?xml version="1.0" encoding="utf-8" standalone="no"?>
<resources>
<!--
Disclaimer :
If you are going to translate strings, please make sure :
1. There is no duplicate strings by name
2. Every apostrophe is started with quote (look others).
If you are making/correcting english translations make sure :
1. All your modified/created strings are in the top of the file (to make easier find what's translated).
-->
<string name="osmand_rastermaps_plugin_description">This plugin allows to use large variety of online tile maps such as an overlay or as a base map. The maps could be prepared offline and copied to osmand folder.</string>
<string name="osmand_rastermaps_plugin_name">Online maps</string>
<string name="osmand_background_plugin_description">This plugin allows to use routing and tracking in energy safe mode with screen off. It runs background service which wakes GPS up in a certain interval and records GPX or does routing instructions.</string>
<string name="osmand_background_plugin_name">Screen Off features</string>
<string name="osmand_accessibility_description">This plugin enables special accessibility features.</string>

View file

@ -2,45 +2,18 @@
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
<PreferenceCategory android:title="@string/profile_settings" android:key="profile_dep_cat">
<ListPreference android:summary="@string/settings_preset_descr" android:title="@string/settings_preset" android:key="application_mode"></ListPreference>
<PreferenceScreen android:key="map_settings" android:title="@string/rendering_settings" android:summary="@string/rendering_settings_descr">
<PreferenceCategory android:title="@string/pref_raster_map">
<CheckBoxPreference android:summary="@string/map_vector_data_descr" android:title="@string/map_vector_data"
android:key="map_vector_data"></CheckBoxPreference>
<ListPreference android:title="@string/map_tile_source" android:summary="@string/map_tile_source_descr" android:key="map_tile_sources"></ListPreference>
<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/level_to_switch_vector_raster" android:summary="@string/level_to_switch_vector_raster_descr"
android:key="level_to_switch_vector_raster"></ListPreference>
</PreferenceCategory>
<PreferenceCategory android:title="@string/pref_overlay">
<ListPreference android:title="@string/map_overlay" android:summary="@string/map_overlay_descr" android:key="map_overlay"></ListPreference>
<ListPreference android:title="@string/map_underlay" android:summary="@string/map_underlay_descr" android:key="map_underlay"></ListPreference>
<net.osmand.plus.views.SeekBarPreference android:key="overlay_transparency" android:defaultValue="0" android:max="255"
android:dialogMessage="@string/modify_transparency" android:title="@string/overlay_transparency" android:summary="@string/overlay_transparency_descr"/>
<net.osmand.plus.views.SeekBarPreference android:key="map_transparency" android:defaultValue="0" android:max="255"
android:dialogMessage="@string/modify_transparency" android:title="@string/map_transparency" android:summary="@string/map_transparency_descr"/>
</PreferenceCategory>
<PreferenceScreen android:key="appearance_settings" android:title="@string/appearance_settings" android:summary="@string/appearance_settings_descr">
<ListPreference android:key="rotate_map" android:title="@string/rotate_map_to_bearing" android:summary="@string/rotate_map_to_bearing_descr"></ListPreference>
<ListPreference android:key="daynight_mode" android:title="@string/daynight" android:summary="@string/daynight_descr"></ListPreference>
<CheckBoxPreference android:key="show_view_angle" android:title="@string/show_view_angle" android:summary="@string/show_view_angle_descr"></CheckBoxPreference>
<CheckBoxPreference android:title="@string/auto_zoom_map" android:summary="@string/auto_zoom_map_descr" android:key="auto_zoom_map"></CheckBoxPreference>
<CheckBoxPreference android:summary="@string/use_english_names_descr" android:title="@string/use_english_names"
android:key="use_english_names"></CheckBoxPreference>
<CheckBoxPreference android:key="show_altitude_info" android:title="@string/show_altitude_info" android:summary="@string/show_altitude_info_descr"/>
<PreferenceCategory android:title="@string/pref_vector_map">
<ListPreference android:key="renderer" android:title="@string/renderers" android:summary="@string/renderers_descr"></ListPreference>
<ListPreference android:key="map_text_size" android:title="@string/map_text_size" android:summary="@string/map_text_size_descr"/>
</PreferenceCategory>
<PreferenceCategory android:title="@string/pref_vector_rendering" android:key="custom_vector_rendering">
</PreferenceCategory>
</PreferenceScreen>
<PreferenceScreen android:key="appearance_settings" android:title="@string/appearance_settings" android:summary="@string/appearance_settings_descr">
<ListPreference android:key="daynight_mode" android:title="@string/daynight" android:summary="@string/daynight_descr"></ListPreference>
<ListPreference android:key="rotate_map" android:title="@string/rotate_map_to_bearing" android:summary="@string/rotate_map_to_bearing_descr"></ListPreference>
<CheckBoxPreference android:title="@string/auto_zoom_map" android:summary="@string/auto_zoom_map_descr" android:key="auto_zoom_map"></CheckBoxPreference>
<ListPreference android:key="position_on_map" android:title="@string/position_on_map" android:summary="@string/position_on_map_descr"></ListPreference>
<CheckBoxPreference android:key="show_view_angle" android:title="@string/show_view_angle" android:summary="@string/show_view_angle_descr"></CheckBoxPreference>
<CheckBoxPreference android:summary="@string/use_english_names_descr" android:title="@string/use_english_names"
android:key="use_english_names"></CheckBoxPreference>
<CheckBoxPreference android:key="show_altitude_info" android:title="@string/show_altitude_info" android:summary="@string/show_altitude_info_descr"/>
<CheckBoxPreference android:key="transparent_map_theme" android:title="@string/use_transparent_map_theme" android:summary="@string/use_transparent_map_theme_descr"/>
<CheckBoxPreference android:key="fluorescent_overlays" android:title="@string/use_fluorescent_overlays" android:summary="@string/use_fluorescent_overlays_descr"/>
<CheckBoxPreference android:key="show_ruler" android:title="@string/show_ruler_level" android:summary="@string/show_ruler_level_descr"/>
</PreferenceScreen>
<PreferenceScreen android:key="routing_settings" android:title="@string/routing_settings" android:summary="@string/routing_settings_descr">

View file

@ -18,6 +18,7 @@ import net.osmand.plus.development.OsmandDevelopmentPlugin;
import net.osmand.plus.extrasettings.OsmandExtraSettings;
import net.osmand.plus.monitoring.OsmandMonitoringPlugin;
import net.osmand.plus.osmedit.OsmEditingPlugin;
import net.osmand.plus.rastermaps.OsmandRasterMapsPlugin;
import net.osmand.plus.views.OsmandMapTileView;
public abstract class OsmandPlugin {
@ -42,9 +43,13 @@ public abstract class OsmandPlugin {
*/
public abstract boolean init(OsmandApplication app);
public void disable(OsmandApplication app) {};
public static void initPlugins(OsmandApplication app) {
OsmandSettings settings = app.getSettings();
OsmandRasterMapsPlugin rasterMapsPlugin = new OsmandRasterMapsPlugin(app);
installedPlugins.add(rasterMapsPlugin);
installedPlugins.add(new OsmandMonitoringPlugin(app));
installedPlugins.add(new OsmEditingPlugin(app));
installedPlugins.add(new OsmandBackgroundServicePlugin(app));
@ -53,6 +58,22 @@ public abstract class OsmandPlugin {
installedPlugins.add(new OsmandDevelopmentPlugin(app));
Set<String> enabledPlugins = settings.getEnabledPlugins();
// update special plugin state
if (!enabledPlugins.contains(rasterMapsPlugin.getId())) {
if (settings.MAP_VECTOR_DATA.get()) {
if(settings.MAP_OVERLAY.get() != null) {
settings.MAP_OVERLAY.set(null);
}
if(settings.MAP_UNDERLAY.get() != null) {
settings.MAP_UNDERLAY.set(null);
}
} else {
settings.enablePlugin(rasterMapsPlugin.getId(), true);
enabledPlugins = settings.getEnabledPlugins();
}
}
for (OsmandPlugin plugin : installedPlugins) {
if (enabledPlugins.contains(plugin.getId())) {
try {
@ -73,6 +94,7 @@ public abstract class OsmandPlugin {
}
activePlugins.add(plugin);
} else {
plugin.disable(app);
activePlugins.remove(plugin);
}
app.getSettings().enablePlugin(plugin.getId(), enable);

View file

@ -685,7 +685,7 @@ public class OsmandSettings {
// this value string is synchronized with settings_pref.xml preference name
public final CommonPreference<Boolean> MAP_VECTOR_DATA = new BooleanPreference("map_vector_data",
false, false);
true, false);
// this value string is synchronized with settings_pref.xml preference name
public final CommonPreference<String> MAP_OVERLAY = new StringPreference("map_overlay",

View file

@ -14,11 +14,13 @@ import net.osmand.Algoritms;
import net.osmand.GPXUtilities.WptPt;
import net.osmand.IProgress;
import net.osmand.access.AccessibleToast;
import net.osmand.plus.OsmandPlugin;
import net.osmand.plus.OsmandSettings;
import net.osmand.plus.R;
import net.osmand.plus.ResourceManager;
import net.osmand.plus.activities.LocalIndexHelper.LocalIndexInfo;
import net.osmand.plus.activities.LocalIndexHelper.LocalIndexType;
import net.osmand.plus.development.OsmandDevelopmentPlugin;
import net.osmand.plus.osmedit.OpenstreetmapRemoteUtil;
import android.app.Activity;
import android.app.AlertDialog;
@ -166,7 +168,9 @@ public class LocalIndexesActivity extends OsmandExpandableListActivity {
final List<Integer> menu = new ArrayList<Integer>();
if(info.getType() == LocalIndexType.GPX_DATA){
menu.add(R.string.show_gpx_route);
menu.add(R.string.local_index_mi_upload_gpx);
if(OsmandPlugin.getEnabledPlugin(OsmandDevelopmentPlugin.class) instanceof OsmandDevelopmentPlugin) {
menu.add(R.string.local_index_mi_upload_gpx);
}
descriptionLoader = new LoadLocalIndexDescriptionTask();
descriptionLoader.execute(info);
}
@ -558,7 +562,9 @@ public class LocalIndexesActivity extends OsmandExpandableListActivity {
menu.add(0, R.string.local_index_mi_restore, 1, getString(R.string.local_index_mi_restore)+"...");
menu.add(0, R.string.local_index_mi_delete, 2, getString(R.string.local_index_mi_delete)+"...");
menu.add(0, R.string.local_index_mi_reload, 3, R.string.local_index_mi_reload);
menu.add(0, R.string.local_index_mi_upload_gpx, 4, getString(R.string.local_index_mi_upload_gpx)+"...");
if(OsmandPlugin.getEnabledPlugin(OsmandDevelopmentPlugin.class) instanceof OsmandDevelopmentPlugin) {
menu.add(0, R.string.local_index_mi_upload_gpx, 4, getString(R.string.local_index_mi_upload_gpx)+"...");
}
return true;
}

View file

@ -25,7 +25,6 @@ import net.osmand.plus.OsmandSettings.OsmandPreference;
import net.osmand.plus.ProgressDialogImplementation;
import net.osmand.plus.R;
import net.osmand.plus.ResourceManager;
import net.osmand.plus.render.MapRenderRepositories;
import net.osmand.plus.render.NativeOsmandLibrary;
import net.osmand.plus.routing.RouteProvider.RouteService;
import net.osmand.plus.views.SeekBarPreference;
@ -62,17 +61,13 @@ public class SettingsActivity extends PreferenceActivity implements OnPreference
public static final String SCREEN_ID_GENERAL_SETTINGS = "general_settings";
public static final String SCREEN_ID_NAVIGATION_SETTINGS = "routing_settings";
public static final String SCREEN_ID_MONITORING_SETTINGS = "monitor_settings";
private static final String MORE_VALUE = "MORE_VALUE";
public static final String MORE_VALUE = "MORE_VALUE";
private Preference bidforfix;
private Preference plugins;
private EditTextPreference applicationDir;
private ListPreference applicationModePreference;
private ListPreference tileSourcePreference;
private ListPreference overlayPreference;
private ListPreference underlayPreference;
private ListPreference dayNightModePreference;
private ListPreference routerServicePreference;
@ -114,6 +109,17 @@ public class SettingsActivity extends PreferenceActivity implements OnPreference
seekBarPreferences.put(b.getId(), b);
}
public SeekBarPreference createSeekBarPreference(OsmandPreference<Integer> b, int title, int summary, int dialogTextId,
int defValue, int maxValue){
SeekBarPreference p = new SeekBarPreference(this, dialogTextId, defValue, maxValue);
p.setTitle(title);
p.setSummary(summary);
p.setOnPreferenceChangeListener(this);
screenPreferences.put(b.getId(), p);
seekBarPreferences.put(b.getId(), b);
return p;
}
public <T> void registerListPreference(OsmandPreference<T> b, PreferenceScreen screen, String[] names, T[] values){
ListPreference p = (ListPreference) screen.findPreference(b.getId());
prepareListPreference(b, names, values, p);
@ -226,22 +232,16 @@ public class SettingsActivity extends PreferenceActivity implements OnPreference
registerBooleanPreference(osmandSettings.AUTO_ZOOM_MAP,screen);
registerBooleanPreference(osmandSettings.FAST_ROUTE_MODE,screen);
registerBooleanPreference(osmandSettings.USE_OSMAND_ROUTING_SERVICE_ALWAYS,screen);
registerBooleanPreference(osmandSettings.USE_INTERNET_TO_DOWNLOAD_TILES,screen);
registerBooleanPreference(osmandSettings.MAP_VECTOR_DATA,screen);
registerBooleanPreference(osmandSettings.TRANSPARENT_MAP_THEME,screen);
registerBooleanPreference(osmandSettings.SHOW_ALTITUDE_INFO,screen);
registerBooleanPreference(osmandSettings.FLUORESCENT_OVERLAYS,screen);
registerBooleanPreference(osmandSettings.SHOW_RULER,screen);
CheckBoxPreference nativeCheckbox = registerBooleanPreference(osmandSettings.NATIVE_RENDERING,screen);
//disable the checkbox if the library cannot be used
if ((NativeOsmandLibrary.isLoaded() && !NativeOsmandLibrary.isSupported()) ||
osmandSettings.NATIVE_RENDERING_FAILED.get()) {
nativeCheckbox.setEnabled(false);
}
registerSeekBarPreference(osmandSettings.MAP_OVERLAY_TRANSPARENCY, screen);
registerSeekBarPreference(osmandSettings.MAP_TRANSPARENCY, screen);
// List preferences
registerListPreference(osmandSettings.ROTATE_MAP, screen,
@ -252,10 +252,6 @@ public class SettingsActivity extends PreferenceActivity implements OnPreference
new String[] {getString(R.string.map_orientation_portrait), getString(R.string.map_orientation_landscape), getString(R.string.map_orientation_default)},
new Integer[] {ActivityInfo.SCREEN_ORIENTATION_PORTRAIT, ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE, ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED});
registerListPreference(osmandSettings.POSITION_ON_MAP, screen,
new String[] {getString(R.string.position_on_map_center), getString(R.string.position_on_map_bottom)},
new Integer[] {OsmandSettings.CENTER_CONSTANT, OsmandSettings.BOTTOM_CONSTANT});
entries = new String[DayNightMode.values().length];
for(int i=0; i<entries.length; i++){
@ -276,20 +272,11 @@ public class SettingsActivity extends PreferenceActivity implements OnPreference
entries = new String[] { getString(R.string.system_locale),
"English", "Czech", "German", "Spanish", "French", "Hungarian", "Italian", "Japanese", "Dutch", "Polish", "Portuguese", "Russian", "Slovak", "Vietnamese" };;
registerListPreference(osmandSettings.PREFERRED_LOCALE, screen, entries, entrieValues);
int startZoom = 12;
int endZoom = 19;
entries = new String[endZoom - startZoom + 1];
Integer[] intValues = new Integer[endZoom - startZoom + 1];
for (int i = startZoom; i <= endZoom; i++) {
entries[i - startZoom] = i + ""; //$NON-NLS-1$
intValues[i - startZoom] = i ;
}
// try without, Issue 823:
// registerListPreference(osmandSettings.MAX_LEVEL_TO_DOWNLOAD_TILE, screen, entries, intValues);
intValues = new Integer[] { 0, 5, 10, 15, 20, 25, 30, 45, 60, 90};
Integer[] intValues = new Integer[] { 0, 5, 10, 15, 20, 25, 30, 45, 60, 90};
entries = new String[intValues.length];
entries[0] = getString(R.string.auto_follow_route_never);
for (int i = 1; i < intValues.length; i++) {
@ -304,16 +291,6 @@ public class SettingsActivity extends PreferenceActivity implements OnPreference
}
registerListPreference(osmandSettings.MAP_TEXT_SIZE, screen, entries, floatValues);
startZoom = 1;
endZoom = 18;
entries = new String[endZoom - startZoom + 1];
intValues = new Integer[endZoom - startZoom + 1];
for (int i = startZoom; i <= endZoom; i++) {
entries[i - startZoom] = i + ""; //$NON-NLS-1$
intValues[i - startZoom] = i ;
}
registerListPreference(osmandSettings.LEVEL_TO_SWITCH_VECTOR_RASTER, screen, entries, intValues);
entries = new String[RouteService.values().length];
for(int i=0; i<entries.length; i++){
entries[i] = RouteService.values()[i].getName();
@ -337,20 +314,11 @@ public class SettingsActivity extends PreferenceActivity implements OnPreference
applicationModePreference = (ListPreference) screen.findPreference(osmandSettings.APPLICATION_MODE.getId());
applicationModePreference.setOnPreferenceChangeListener(this);
tileSourcePreference = (ListPreference) screen.findPreference(osmandSettings.MAP_TILE_SOURCES.getId());
tileSourcePreference.setOnPreferenceChangeListener(this);
overlayPreference = (ListPreference) screen.findPreference(osmandSettings.MAP_OVERLAY.getId());
overlayPreference.setOnPreferenceChangeListener(this);
underlayPreference = (ListPreference) screen.findPreference(osmandSettings.MAP_UNDERLAY.getId());
underlayPreference.setOnPreferenceChangeListener(this);
dayNightModePreference = (ListPreference) screen.findPreference(osmandSettings.DAYNIGHT_MODE.getId());
dayNightModePreference.setOnPreferenceChangeListener(this);
routerServicePreference = (ListPreference) screen.findPreference(osmandSettings.ROUTER_SERVICE.getId());
routerServicePreference.setOnPreferenceChangeListener(this);
Preference localIndexes =(Preference) screen.findPreference(OsmandSettings.LOCAL_INDEXES);
localIndexes.setOnPreferenceClickListener(this);
applicationDir = (EditTextPreference) screen.findPreference(OsmandSettings.EXTERNAL_STORAGE_DIR);
@ -386,29 +354,31 @@ public class SettingsActivity extends PreferenceActivity implements OnPreference
private void createCustomRenderingProperties(boolean update) {
RenderingRulesStorage renderer = getMyApplication().getRendererRegistry().getCurrentSelectedRenderer();
PreferenceCategory cat = (PreferenceCategory) findPreference("custom_vector_rendering");
cat.removeAll();
if(renderer != null){
for(RenderingRuleProperty p : renderer.PROPS.getCustomRules()){
CommonPreference<String> custom = getMyApplication().getSettings().getCustomRenderProperty(p.getAttrName());
ListPreference lp = new ListPreference(this);
lp.setOnPreferenceChangeListener(this);
lp.setKey(custom.getId());
lp.setTitle(p.getName());
lp.setSummary(p.getDescription());
cat.addPreference(lp);
LinkedHashMap<String, Object> vals = new LinkedHashMap<String, Object>();
screenPreferences.put(custom.getId(), lp);
listPreferences.put(custom.getId(), custom);
listPrefValues.put(custom.getId(), vals);
String[] names = p.getPossibleValues();
for(int i=0; i<names.length; i++){
vals.put(names[i], names[i]);
if (cat != null) {
cat.removeAll();
if (renderer != null) {
for (RenderingRuleProperty p : renderer.PROPS.getCustomRules()) {
CommonPreference<String> custom = getMyApplication().getSettings().getCustomRenderProperty(p.getAttrName());
ListPreference lp = new ListPreference(this);
lp.setOnPreferenceChangeListener(this);
lp.setKey(custom.getId());
lp.setTitle(p.getName());
lp.setSummary(p.getDescription());
cat.addPreference(lp);
LinkedHashMap<String, Object> vals = new LinkedHashMap<String, Object>();
screenPreferences.put(custom.getId(), lp);
listPreferences.put(custom.getId(), custom);
listPrefValues.put(custom.getId(), vals);
String[] names = p.getPossibleValues();
for (int i = 0; i < names.length; i++) {
vals.put(names[i], names[i]);
}
}
if (update) {
updateAllSettings();
}
}
if(update) {
updateAllSettings();
}
}
@ -487,65 +457,15 @@ public class SettingsActivity extends PreferenceActivity implements OnPreference
}
OsmandPlugin.onSettingsActivityUpdate(this);
// Specific properties
updateTileSourceSummary();
updateApplicationDirTextAndSummary();
applicationModePreference.setTitle(getString(R.string.settings_preset) + " [" + osmandSettings.APPLICATION_MODE.get().toHumanString(this) + "]");
dayNightModePreference.setSummary(getString(R.string.daynight_descr) + " [" + osmandSettings.DAYNIGHT_MODE.get().toHumanString(this) + "]");
routerServicePreference.setSummary(getString(R.string.router_service_descr) + " [" + osmandSettings.ROUTER_SERVICE.get() + "]");
}
private void updateTileSourceSummary() {
fillTileSourcesToPreference(tileSourcePreference, osmandSettings.MAP_TILE_SOURCES.get(), false);
fillTileSourcesToPreference(overlayPreference, osmandSettings.MAP_OVERLAY.get(), true);
fillTileSourcesToPreference(underlayPreference, osmandSettings.MAP_UNDERLAY.get(), true);
// String mapName = " " + osmandSettings.MAP_TILE_SOURCES.get(); //$NON-NLS-1$
// String summary = tileSourcePreference.getSummary().toString();
// if (summary.lastIndexOf(':') != -1) {
// summary = summary.substring(0, summary.lastIndexOf(':') + 1);
// }
// tileSourcePreference.setSummary(summary + mapName);
tileSourcePreference.setSummary(getString(R.string.map_tile_source_descr) + " [" + osmandSettings.MAP_TILE_SOURCES.get() + "]");
overlayPreference.setSummary(getString(R.string.map_overlay_descr) + " [" + osmandSettings.MAP_OVERLAY.get() + "]");
underlayPreference.setSummary(getString(R.string.map_underlay_descr) + " [" + osmandSettings.MAP_UNDERLAY.get() + "]");
}
private void fillTileSourcesToPreference(ListPreference tileSourcePreference, String value, boolean addNone) {
Map<String, String> entriesMap = osmandSettings.getTileSourceEntries();
int add = addNone ? 1 : 0;
String[] entries = new String[entriesMap.size() + 1 + add];
String[] values = new String[entriesMap.size() + 1 + add];
int ki = 0;
if(addNone){
entries[ki] = getString(R.string.default_none);
values[ki] = "";
ki++;
}
if (value == null) {
value = "";
}
for(Map.Entry<String, String> es : entriesMap.entrySet()){
entries[ki] = es.getValue();
values[ki] = es.getKey();
ki++;
}
entries[ki] = getString(R.string.install_more);
values[ki] = MORE_VALUE;
fill(tileSourcePreference, entries, values, value);
}
private void fill(ListPreference component, String[] list, String[] values, String selected) {
component.setEntries(list);
component.setEntryValues(values);
component.setValue(selected);
}
@SuppressWarnings("unchecked")
@Override
@ -557,13 +477,6 @@ public class SettingsActivity extends PreferenceActivity implements OnPreference
OsmandPreference<String> editPref = editTextPreferences.get(preference.getKey());
if(boolPref != null){
boolPref.set((Boolean)newValue);
if (boolPref.getId().equals(osmandSettings.MAP_VECTOR_DATA.getId())) {
MapRenderRepositories r = ((OsmandApplication)getApplication()).getResourceManager().getRenderer();
if(r.isEmpty()){
AccessibleToast.makeText(this, getString(R.string.no_vector_map_loaded), Toast.LENGTH_LONG).show();
return false;
}
}
if (boolPref.getId().equals(osmandSettings.NATIVE_RENDERING.getId())) {
if(((Boolean)newValue).booleanValue()) {
loadNativeLibrary();
@ -617,36 +530,6 @@ public class SettingsActivity extends PreferenceActivity implements OnPreference
} else if(preference == applicationDir){
warnAboutChangingStorage((String) newValue);
return false;
} else if (preference == tileSourcePreference || preference == overlayPreference
|| preference == underlayPreference) {
if(MORE_VALUE.equals(newValue)){
SettingsActivity.installMapLayers(this, new ResultMatcher<TileSourceTemplate>() {
@Override
public boolean isCancelled() { return false;}
@Override
public boolean publish(TileSourceTemplate object) {
if(object == null){
updateTileSourceSummary();
}
return true;
}
});
} else if(preference == tileSourcePreference){
osmandSettings.MAP_TILE_SOURCES.set((String) newValue);
updateTileSourceSummary();
} else {
if(((String) newValue).length() == 0){
newValue = null;
}
if(preference == underlayPreference){
osmandSettings.MAP_UNDERLAY.set(((String) newValue));
underlayPreference.setSummary(getString(R.string.map_underlay_descr) + " [" + osmandSettings.MAP_UNDERLAY.get() + "]");
} else if(preference == overlayPreference){
osmandSettings.MAP_OVERLAY.set(((String) newValue));
overlayPreference.setSummary(getString(R.string.map_overlay_descr) + " [" + osmandSettings.MAP_OVERLAY.get() + "]");
}
}
}
return true;
}

View file

@ -62,5 +62,27 @@ public class OsmandExtraSettings extends OsmandPlugin {
new Integer[] {AudioManager.STREAM_MUSIC, AudioManager.STREAM_NOTIFICATION, AudioManager.STREAM_VOICE_CALL},
R.string.choose_audio_stream, R.string.choose_audio_stream_descr);
cat.addPreference(lp);
PreferenceScreen appearance = (PreferenceScreen) screen.findPreference("appearance_settings");
cat = new PreferenceCategory(app);
cat.setTitle(R.string.extra_settings);
appearance.addPreference(cat);
cat.addPreference(activity.createCheckBoxPreference(settings.TRANSPARENT_MAP_THEME,
R.string.use_transparent_map_theme, R.string.use_transparent_map_theme_descr));
cat.addPreference(activity.createCheckBoxPreference(settings.SHOW_RULER,
R.string.show_ruler_level, R.string.show_ruler_level_descr));
cat.addPreference(activity.createCheckBoxPreference(settings.FLUORESCENT_OVERLAYS,
R.string.use_fluorescent_overlays, R.string.use_fluorescent_overlays_descr));
cat.addPreference(activity.createListPreference(settings.POSITION_ON_MAP,
new String[] { activity.getString(R.string.position_on_map_center), activity.getString(R.string.position_on_map_bottom) },
new Integer[] { OsmandSettings.CENTER_CONSTANT, OsmandSettings.BOTTOM_CONSTANT }, R.string.position_on_map,
R.string.position_on_map_descr));
PreferenceCategory vectorSettings = new PreferenceCategory(app);
vectorSettings.setTitle(R.string.pref_vector_rendering);
appearance.addPreference(vectorSettings);
}
}

View file

@ -0,0 +1,233 @@
package net.osmand.plus.rastermaps;
import java.util.Map;
import net.osmand.ResultMatcher;
import net.osmand.map.TileSourceManager.TileSourceTemplate;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.OsmandPlugin;
import net.osmand.plus.OsmandSettings;
import net.osmand.plus.R;
import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.activities.SettingsActivity;
import net.osmand.plus.views.SeekBarPreference;
import android.preference.CheckBoxPreference;
import android.preference.ListPreference;
import android.preference.Preference;
import android.preference.Preference.OnPreferenceChangeListener;
import android.preference.PreferenceCategory;
import android.preference.PreferenceGroup;
import android.preference.PreferenceScreen;
public class OsmandRasterMapsPlugin extends OsmandPlugin {
private static final String ID = "osmand.rastermaps";
private OsmandSettings settings;
private OsmandApplication app;
private ListPreference tileSourcePreference;
private ListPreference overlayPreference;
private ListPreference underlayPreference;
public OsmandRasterMapsPlugin(OsmandApplication app) {
this.app = app;
}
@Override
public boolean init(OsmandApplication app) {
settings = app.getSettings();
return true;
}
@Override
public String getId() {
return ID;
}
@Override
public String getDescription() {
return app.getString(R.string.osmand_rastermaps_plugin_description);
}
@Override
public String getName() {
return app.getString(R.string.osmand_rastermaps_plugin_name);
}
@Override
public void registerLayers(MapActivity activity) {
}
@Override
public void settingsActivityUpdate(SettingsActivity activity) {
updateTileSourceSummary();
}
@Override
public void settingsActivityCreate(final SettingsActivity activity, PreferenceScreen screen) {
PreferenceGroup general = (PreferenceGroup) screen.findPreference("global_settings");
PreferenceGroup grp = screen.getPreferenceManager().createPreferenceScreen(activity);
grp.setSummary(R.string.rendering_settings_descr);
grp.setTitle(R.string.rendering_settings);
grp.setKey("map_settings");
grp.setOrder(0);
general.addPreference(grp);
OnPreferenceChangeListener listener = createPreferenceListener(activity);
PreferenceCategory cat = new PreferenceCategory(activity);
cat.setTitle(R.string.pref_raster_map);
grp.addPreference(cat);
CheckBoxPreference mapVectorData = activity.createCheckBoxPreference(settings.MAP_VECTOR_DATA,
R.string.map_vector_data, R.string.map_vector_data_descr);
// final OnPreferenceChangeListener parent = mapVectorData.getOnPreferenceChangeListener();
// MapRenderRepositories r = app.getResourceManager().getRenderer();
// if(r.isEmpty()){
// AccessibleToast.makeText(this, app.getString(R.string.no_vector_map_loaded), Toast.LENGTH_LONG).show();
// return false;
// }
cat.addPreference(mapVectorData);
tileSourcePreference = new ListPreference(activity);
tileSourcePreference.setSummary(R.string.map_tile_source_descr);
tileSourcePreference.setTitle(R.string.map_tile_source);
tileSourcePreference.setOnPreferenceChangeListener(listener);
cat.addPreference(tileSourcePreference);
cat.addPreference(activity.createCheckBoxPreference(settings.USE_INTERNET_TO_DOWNLOAD_TILES,
R.string.use_internet, R.string.use_internet_to_download_tile));
int startZoom = 1;
int endZoom = 18;
String[] entries = new String[endZoom - startZoom + 1];
Integer[] intValues = new Integer[endZoom - startZoom + 1];
for (int i = startZoom; i <= endZoom; i++) {
entries[i - startZoom] = i + ""; //$NON-NLS-1$
intValues[i - startZoom] = i ;
}
ListPreference lp = activity.createListPreference(settings.LEVEL_TO_SWITCH_VECTOR_RASTER,
entries, intValues, R.string.level_to_switch_vector_raster, R.string.level_to_switch_vector_raster_descr);
cat.addPreference(lp);
// try without, Issue 823:
// int startZoom = 12;
// int endZoom = 19;
// entries = new String[endZoom - startZoom + 1];
// Integer[] intValues = new Integer[endZoom - startZoom + 1];
// for (int i = startZoom; i <= endZoom; i++) {
// entries[i - startZoom] = i + ""; //$NON-NLS-1$
// intValues[i - startZoom] = i ;
// }
// registerListPreference(osmandSettings.MAX_LEVEL_TO_DOWNLOAD_TILE, screen, entries, intValues);
cat = new PreferenceCategory(activity);
cat.setTitle(R.string.pref_overlay);
grp.addPreference(cat);
overlayPreference = new ListPreference(activity);
overlayPreference.setSummary(R.string.map_overlay_descr);
overlayPreference.setTitle(R.string.map_overlay);
overlayPreference.setOnPreferenceChangeListener(listener);
cat.addPreference(overlayPreference);
underlayPreference = new ListPreference(activity);
underlayPreference.setSummary(R.string.map_underlay_descr);
underlayPreference.setTitle(R.string.map_underlay);
underlayPreference.setOnPreferenceChangeListener(listener);
cat.addPreference(underlayPreference);
SeekBarPreference sp = activity.createSeekBarPreference(settings.MAP_OVERLAY_TRANSPARENCY, R.string.overlay_transparency, R.string.overlay_transparency_descr,
R.string.modify_transparency, 0, 255);
cat.addPreference(sp);
sp = activity.createSeekBarPreference(settings.MAP_TRANSPARENCY, R.string.map_transparency, R.string.map_transparency_descr,
R.string.modify_transparency, 0, 255);
cat.addPreference(sp);
}
private OnPreferenceChangeListener createPreferenceListener(final SettingsActivity activity) {
return new OnPreferenceChangeListener() {
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
if (preference == tileSourcePreference || preference == overlayPreference
|| preference == underlayPreference) {
if(SettingsActivity.MORE_VALUE.equals(newValue)){
SettingsActivity.installMapLayers(activity, new ResultMatcher<TileSourceTemplate>() {
@Override
public boolean isCancelled() { return false;}
@Override
public boolean publish(TileSourceTemplate object) {
if(object == null){
updateTileSourceSummary();
}
return true;
}
});
} else if(preference == tileSourcePreference){
settings.MAP_TILE_SOURCES.set((String) newValue);
updateTileSourceSummary();
} else {
if(((String) newValue).length() == 0){
newValue = null;
}
if(preference == underlayPreference){
settings.MAP_UNDERLAY.set(((String) newValue));
underlayPreference.setSummary(app.getString(R.string.map_underlay_descr) + " [" + settings.MAP_UNDERLAY.get() + "]");
} else if(preference == overlayPreference){
settings.MAP_OVERLAY.set(((String) newValue));
overlayPreference.setSummary(app.getString(R.string.map_overlay_descr) + " [" + settings.MAP_OVERLAY.get() + "]");
}
}
}
return true;
}
};
}
private void updateTileSourceSummary() {
if (tileSourcePreference != null) {
fillTileSourcesToPreference(tileSourcePreference, settings.MAP_TILE_SOURCES.get(), false);
fillTileSourcesToPreference(overlayPreference, settings.MAP_OVERLAY.get(), true);
fillTileSourcesToPreference(underlayPreference, settings.MAP_UNDERLAY.get(), true);
// String mapName = " " + settings.MAP_TILE_SOURCES.get(); //$NON-NLS-1$
// String summary = tileSourcePreference.getSummary().toString();
// if (summary.lastIndexOf(':') != -1) {
// summary = summary.substring(0, summary.lastIndexOf(':') + 1);
// }
// tileSourcePreference.setSummary(summary + mapName);
tileSourcePreference.setSummary(app.getString(R.string.map_tile_source_descr) + " [" + settings.MAP_TILE_SOURCES.get() + "]");
overlayPreference.setSummary(app.getString(R.string.map_overlay_descr) + " [" + settings.MAP_OVERLAY.get() + "]");
underlayPreference.setSummary(app.getString(R.string.map_underlay_descr) + " [" + settings.MAP_UNDERLAY.get() + "]");
}
}
private void fillTileSourcesToPreference(ListPreference tileSourcePreference, String value, boolean addNone) {
Map<String, String> entriesMap = settings.getTileSourceEntries();
int add = addNone ? 1 : 0;
String[] entries = new String[entriesMap.size() + 1 + add];
String[] values = new String[entriesMap.size() + 1 + add];
int ki = 0;
if (addNone) {
entries[ki] = app.getString(R.string.default_none);
values[ki] = "";
ki++;
}
if (value == null) {
value = "";
}
for (Map.Entry<String, String> es : entriesMap.entrySet()) {
entries[ki] = es.getValue();
values[ki] = es.getKey();
ki++;
}
entries[ki] = app.getString(R.string.install_more);
values[ki] = SettingsActivity.MORE_VALUE;
fill(tileSourcePreference, entries, values, value);
}
private void fill(ListPreference component, String[] list, String[] values, String selected) {
component.setEntries(list);
component.setEntryValues(values);
component.setValue(selected);
}
}

View file

@ -61,6 +61,25 @@ public class SeekBarPreference extends DialogPreference implements
maxValue = attrs.getAttributeIntValue(ANDROID_NS, MAX_VALUE_ID, 100);
}
/**
* Default constructor.
*
* @param context
* The application context.
* @param attrs
* The attribute set, containing the text, title, values, and
* range for the slider dialog.
*/
public SeekBarPreference(final Context context, int dialogTextId, int defValue, int maxValue) {
super(context, null);
this.context = context;
dialogText = context.getResources().getString(dialogTextId);
valueText = null;
this.defaultValue = defValue;
this.maxValue = maxValue;
}
public int getMax() {
return maxValue;
@ -120,7 +139,7 @@ public class SeekBarPreference extends DialogPreference implements
if (shouldPersist()) {
persistInt(valueToSave);
}
callChangeListener(new Integer(valueToSave));
callChangeListener(Integer.valueOf(valueToSave));
} else {
this.valueToSave = value;
}