Refactoring map settings
This commit is contained in:
parent
7fbda80bc5
commit
b7670d168d
3 changed files with 38 additions and 73 deletions
|
@ -130,7 +130,7 @@
|
||||||
<activity android:name="net.osmand.plus.development.SettingsDevelopmentActivity" android:configChanges="keyboardHidden|orientation" />
|
<activity android:name="net.osmand.plus.development.SettingsDevelopmentActivity" android:configChanges="keyboardHidden|orientation" />
|
||||||
<activity android:name="net.osmand.plus.audionotes.SettingsAudioVideoActivity" android:configChanges="keyboardHidden|orientation" />
|
<activity android:name="net.osmand.plus.audionotes.SettingsAudioVideoActivity" android:configChanges="keyboardHidden|orientation" />
|
||||||
<activity android:name="net.osmand.access.SettingsAccessibilityActivity" android:configChanges="keyboardHidden|orientation" />
|
<activity android:name="net.osmand.access.SettingsAccessibilityActivity" android:configChanges="keyboardHidden|orientation" />
|
||||||
<activity android:name=".configuremap.ConfigureScreenSettingsActivity" android:configChanges="keyboardHidden|orientation" />
|
<activity android:name=".configuremap.ConfigureSettingsMenuHelper" android:configChanges="keyboardHidden|orientation" />
|
||||||
|
|
||||||
<activity android:name="net.osmand.plus.activities.search.SearchActivity" android:label="@string/search_activity" />
|
<activity android:name="net.osmand.plus.activities.search.SearchActivity" android:label="@string/search_activity" />
|
||||||
<activity android:name="net.osmand.plus.activities.ShowRouteInfoActivity" android:label="@string/show_route" />
|
<activity android:name="net.osmand.plus.activities.ShowRouteInfoActivity" android:label="@string/show_route" />
|
||||||
|
|
|
@ -47,7 +47,7 @@ import net.osmand.plus.activities.actions.ShareLocation;
|
||||||
import net.osmand.plus.activities.actions.StartGPSStatus;
|
import net.osmand.plus.activities.actions.StartGPSStatus;
|
||||||
import net.osmand.plus.activities.search.SearchActivity;
|
import net.osmand.plus.activities.search.SearchActivity;
|
||||||
import net.osmand.plus.base.FavoriteImageDrawable;
|
import net.osmand.plus.base.FavoriteImageDrawable;
|
||||||
import net.osmand.plus.configuremap.ConfigureScreenSettingsActivity;
|
import net.osmand.plus.configuremap.ConfigureSettingsMenuHelper;
|
||||||
import net.osmand.plus.development.OsmandDevelopmentPlugin;
|
import net.osmand.plus.development.OsmandDevelopmentPlugin;
|
||||||
import net.osmand.plus.helpers.WaypointDialogHelper;
|
import net.osmand.plus.helpers.WaypointDialogHelper;
|
||||||
import net.osmand.plus.osmo.OsMoPositionLayer;
|
import net.osmand.plus.osmo.OsMoPositionLayer;
|
||||||
|
@ -922,7 +922,7 @@ public class MapActivityActions implements DialogProvider {
|
||||||
.listen(new OnContextMenuClick() {
|
.listen(new OnContextMenuClick() {
|
||||||
@Override
|
@Override
|
||||||
public boolean onContextMenuClick(int itemId, int pos, boolean isChecked, DialogInterface dialog) {
|
public boolean onContextMenuClick(int itemId, int pos, boolean isChecked, DialogInterface dialog) {
|
||||||
mapActivity.startActivity(new Intent(mapActivity, ConfigureScreenSettingsActivity.class));
|
mapActivity.startActivity(new Intent(mapActivity, ConfigureSettingsMenuHelper.class));
|
||||||
return true;
|
return true;
|
||||||
//mapActivity.getMapLayers().openLayerSelectionDialog(mapView);
|
//mapActivity.getMapLayers().openLayerSelectionDialog(mapView);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,12 +1,10 @@
|
||||||
package net.osmand.plus.configuremap;
|
package net.osmand.plus.configuremap;
|
||||||
|
|
||||||
import android.app.ActionBar;
|
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
import android.app.AlertDialog;
|
import android.app.AlertDialog;
|
||||||
import android.content.DialogInterface;
|
import android.content.DialogInterface;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
import android.os.Bundle;
|
|
||||||
import android.preference.*;
|
import android.preference.*;
|
||||||
import android.view.KeyEvent;
|
import android.view.KeyEvent;
|
||||||
import android.widget.ArrayAdapter;
|
import android.widget.ArrayAdapter;
|
||||||
|
@ -31,66 +29,42 @@ import java.util.List;
|
||||||
/**
|
/**
|
||||||
* Created by Denis on 14.10.2014.
|
* Created by Denis on 14.10.2014.
|
||||||
*/
|
*/
|
||||||
public class ConfigureScreenSettingsActivity extends SettingsBaseActivity {
|
public class ConfigureSettingsMenuHelper{
|
||||||
|
|
||||||
private ApplicationMode previousMode;
|
public static final int HEADER = 0;
|
||||||
|
public static final int LAYER = 1;
|
||||||
|
public static final int MAP_REDNDER = 2;
|
||||||
|
public static final int RENDERING_ATTR = 3;
|
||||||
|
|
||||||
@Override
|
private OsmandApplication app;
|
||||||
public void onCreate(Bundle savedInstanceState) {
|
|
||||||
super.onCreate(savedInstanceState);
|
|
||||||
|
|
||||||
for (ApplicationMode a : ApplicationMode.values(settings)) {
|
public class ConfigureMapMenuItem{
|
||||||
modes.add(a);
|
int type;
|
||||||
|
int darkIcon = -1;
|
||||||
|
int whiteIcon = -1;
|
||||||
|
Object preference;
|
||||||
|
|
||||||
|
ConfigureMapMenuItem(int type, int darkIcon, int whiteIcon, Object preference){
|
||||||
|
this.type = type;
|
||||||
|
this.darkIcon = darkIcon;
|
||||||
|
this.whiteIcon = whiteIcon;
|
||||||
|
this.preference = preference;
|
||||||
}
|
}
|
||||||
getSupportActionBar().setNavigationMode(ActionBar.NAVIGATION_MODE_LIST);
|
|
||||||
List<String> s = new ArrayList<String>();
|
|
||||||
for (ApplicationMode a : modes) {
|
|
||||||
s.add(a.toHumanString(getMyApplication()));
|
|
||||||
}
|
|
||||||
|
|
||||||
ArrayAdapter<String> spinnerAdapter = new ArrayAdapter<String>(getSupportActionBar().getThemedContext(),
|
|
||||||
R.layout.sherlock_spinner_item, s);
|
|
||||||
spinnerAdapter.setDropDownViewResource(R.layout.sherlock_spinner_dropdown_item);
|
|
||||||
getSupportActionBar().setListNavigationCallbacks(spinnerAdapter, new com.actionbarsherlock.app.ActionBar.OnNavigationListener() {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean onNavigationItemSelected(int itemPosition, long itemId) {
|
|
||||||
settings.APPLICATION_MODE.set(modes.get(itemPosition));
|
|
||||||
createAllCategories();
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
public ConfigureSettingsMenuHelper(OsmandApplication app){
|
||||||
protected void onResume() {
|
this.app = app;
|
||||||
super.onResume();
|
|
||||||
previousMode = settings.getApplicationMode();
|
|
||||||
boolean found = setSelectedAppMode(previousMode);
|
|
||||||
if (!found) {
|
|
||||||
getSupportActionBar().setSelectedNavigationItem(0);
|
|
||||||
}
|
|
||||||
createAllCategories();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private ArrayAdapter<ConfigureMapMenuItem> createAllCategories() {
|
||||||
@Override
|
List<ConfigureMapMenuItem> items = new ArrayList<ConfigureMapMenuItem>();
|
||||||
protected void onPause() {
|
createLayersItems(items);
|
||||||
super.onPause();
|
|
||||||
settings.APPLICATION_MODE.set(previousMode);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void createAllCategories() {
|
|
||||||
getPreferenceScreen().removeAll();
|
|
||||||
createLayersPreferences();
|
|
||||||
createRenderingAttributePreferences();
|
createRenderingAttributePreferences();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void createRenderingAttributePreferences() {
|
private void createRenderingAttributePreferences() {
|
||||||
PreferenceCategory renderingCategory = new PreferenceCategory(this);
|
PreferenceCategory renderingCategory = new PreferenceCategory(this);
|
||||||
renderingCategory.setTitle(R.string.map_widget_map_rendering);
|
|
||||||
PreferenceScreen grp = getPreferenceScreen();
|
|
||||||
grp.addPreference(renderingCategory);
|
grp.addPreference(renderingCategory);
|
||||||
Preference p = new Preference(this);
|
Preference p = new Preference(this);
|
||||||
p.setTitle(R.string.map_widget_renderer);
|
p.setTitle(R.string.map_widget_renderer);
|
||||||
|
@ -99,11 +73,11 @@ public class ConfigureScreenSettingsActivity extends SettingsBaseActivity {
|
||||||
public boolean onPreferenceClick(Preference preference) {
|
public boolean onPreferenceClick(Preference preference) {
|
||||||
AlertDialog.Builder bld = new AlertDialog.Builder(getActivity());
|
AlertDialog.Builder bld = new AlertDialog.Builder(getActivity());
|
||||||
bld.setTitle(R.string.renderers);
|
bld.setTitle(R.string.renderers);
|
||||||
Collection<String> rendererNames = getMyApplication().getRendererRegistry().getRendererNames();
|
Collection<String> rendererNames = app.getRendererRegistry().getRendererNames();
|
||||||
final String[] items = rendererNames.toArray(new String[rendererNames.size()]);
|
final String[] items = rendererNames.toArray(new String[rendererNames.size()]);
|
||||||
final String[] visibleNames = new String[items.length];
|
final String[] visibleNames = new String[items.length];
|
||||||
int selected = -1;
|
int selected = -1;
|
||||||
final String selectedName = getMyApplication().getRendererRegistry().getCurrentSelectedRenderer().getName();
|
final String selectedName = app.getRendererRegistry().getCurrentSelectedRenderer().getName();
|
||||||
for (int j = 0; j < items.length; j++) {
|
for (int j = 0; j < items.length; j++) {
|
||||||
if (items[j].equals(selectedName)) {
|
if (items[j].equals(selectedName)) {
|
||||||
selected = j;
|
selected = j;
|
||||||
|
@ -116,13 +90,13 @@ public class ConfigureScreenSettingsActivity extends SettingsBaseActivity {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(DialogInterface dialog, int which) {
|
public void onClick(DialogInterface dialog, int which) {
|
||||||
String renderer = items[which];
|
String renderer = items[which];
|
||||||
RenderingRulesStorage loaded = getMyApplication().getRendererRegistry().getRenderer(renderer);
|
RenderingRulesStorage loaded = app.getRendererRegistry().getRenderer(renderer);
|
||||||
if (loaded != null) {
|
if (loaded != null) {
|
||||||
getMyApplication().getSettings().RENDERER.set(renderer);
|
app.getSettings().RENDERER.set(renderer);
|
||||||
getMyApplication().getRendererRegistry().setCurrentSelectedRender(loaded);
|
app.getRendererRegistry().setCurrentSelectedRender(loaded);
|
||||||
getMyApplication().getResourceManager().getRenderer().clearCache();
|
app.getResourceManager().getRenderer().clearCache();
|
||||||
} else {
|
} else {
|
||||||
AccessibleToast.makeText(getMyApplication(), R.string.renderer_load_exception, Toast.LENGTH_SHORT).show();
|
AccessibleToast.makeText(app, R.string.renderer_load_exception, Toast.LENGTH_SHORT).show();
|
||||||
}
|
}
|
||||||
dialog.dismiss();
|
dialog.dismiss();
|
||||||
createAllCategories();
|
createAllCategories();
|
||||||
|
@ -132,7 +106,6 @@ public class ConfigureScreenSettingsActivity extends SettingsBaseActivity {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
grp.addPreference(p);
|
|
||||||
|
|
||||||
p = new Preference(this);
|
p = new Preference(this);
|
||||||
p.setTitle(R.string.map_widget_day_night);
|
p.setTitle(R.string.map_widget_day_night);
|
||||||
|
@ -168,23 +141,17 @@ public class ConfigureScreenSettingsActivity extends SettingsBaseActivity {
|
||||||
|
|
||||||
|
|
||||||
private void createMapRenderingPreferences() {
|
private void createMapRenderingPreferences() {
|
||||||
PreferenceCategory renderingCategory = new PreferenceCategory(this);
|
|
||||||
renderingCategory.setTitle(R.string.map_widget_vector_attributes);
|
|
||||||
PreferenceScreen grp = getPreferenceScreen();
|
|
||||||
grp.addPreference(renderingCategory);
|
|
||||||
|
|
||||||
RenderingRulesStorage renderer = getMyApplication().getRendererRegistry().getCurrentSelectedRenderer();
|
RenderingRulesStorage renderer = app.getRendererRegistry().getCurrentSelectedRenderer();
|
||||||
final OsmandApplication app = getMyApplication();
|
|
||||||
List<RenderingRuleProperty> customRules = renderer.PROPS.getCustomRules();
|
List<RenderingRuleProperty> customRules = renderer.PROPS.getCustomRules();
|
||||||
for (final RenderingRuleProperty p : customRules) {
|
for (final RenderingRuleProperty p : customRules) {
|
||||||
String propertyName = SettingsActivity.getStringPropertyName(getActivity(), p.getAttrName(), p.getName());
|
String propertyName = SettingsActivity.getStringPropertyName(getActivity(), p.getAttrName(), p.getName());
|
||||||
//test old descr as title
|
//test old descr as title
|
||||||
final String propertyDescr = SettingsActivity.getStringPropertyDescription(getActivity(), p.getAttrName(), p.getName());
|
final String propertyDescr = SettingsActivity.getStringPropertyDescription(getActivity(), p.getAttrName(), p.getName());
|
||||||
if(p.isBoolean()) {
|
if(p.isBoolean()) {
|
||||||
final OsmandSettings.CommonPreference<Boolean> pref = getMyApplication().getSettings().getCustomRenderBooleanProperty(p.getAttrName());
|
final OsmandSettings.CommonPreference<Boolean> pref = app.getSettings().getCustomRenderBooleanProperty(p.getAttrName());
|
||||||
CheckBoxPreference preference = createCheckBoxPreference(pref);
|
|
||||||
preference.setTitle(propertyName);
|
preference.setTitle(propertyName);
|
||||||
renderingCategory.addPreference(preference);
|
|
||||||
preference.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
|
preference.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public boolean onPreferenceClick(Preference preference) {
|
public boolean onPreferenceClick(Preference preference) {
|
||||||
|
@ -232,10 +199,8 @@ public class ConfigureScreenSettingsActivity extends SettingsBaseActivity {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private void createLayersPreferences() {
|
private void createLayersItems(List<ConfigureMapMenuItem> items) {
|
||||||
PreferenceCategory mapLayersCategory = new PreferenceCategory(this);
|
items.add(new ConfigureMapMenuItem(HEADER,-1,-1,R.string.show));
|
||||||
mapLayersCategory.setTitle(R.string.menu_layers);
|
|
||||||
PreferenceScreen grp = getPreferenceScreen();
|
|
||||||
grp.addPreference(mapLayersCategory);
|
grp.addPreference(mapLayersCategory);
|
||||||
final CheckBoxPreference poi = new CheckBoxPreference(this);
|
final CheckBoxPreference poi = new CheckBoxPreference(this);
|
||||||
poi.setTitle(R.string.layer_poi);
|
poi.setTitle(R.string.layer_poi);
|
Loading…
Reference in a new issue