From 8554edd9ac61a447db206adfc9de3cb67712ea5e Mon Sep 17 00:00:00 2001 From: Denis Date: Fri, 17 Oct 2014 14:51:05 +0300 Subject: [PATCH] Updated configure settings screen --- OsmAnd/res/layout/map_settings_item.xml | 43 ++ OsmAnd/res/values/strings.xml | 1 + .../osmand/plus/activities/MapActivity.java | 6 +- .../plus/activities/MapActivityActions.java | 7 +- .../ConfigureSettingsMenuHelper.java | 544 ++++++++++-------- 5 files changed, 363 insertions(+), 238 deletions(-) create mode 100644 OsmAnd/res/layout/map_settings_item.xml diff --git a/OsmAnd/res/layout/map_settings_item.xml b/OsmAnd/res/layout/map_settings_item.xml new file mode 100644 index 0000000000..ee3ac30056 --- /dev/null +++ b/OsmAnd/res/layout/map_settings_item.xml @@ -0,0 +1,43 @@ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/OsmAnd/res/values/strings.xml b/OsmAnd/res/values/strings.xml index abca04b331..d760bc77ff 100644 --- a/OsmAnd/res/values/strings.xml +++ b/OsmAnd/res/values/strings.xml @@ -9,6 +9,7 @@ 3. All your modified/created strings are in the top of the file (to make easier find what\'s translated). PLEASE: Have a look at http://code.google.com/p/osmand/wiki/UIConsistency, it may really improve your and our work :-) Thx - Hardy --> + Configure map Search radius Device not found OsMo service is not available:\n- check the connection;\n- check the settings;\n- check out our Twitter: https://twitter.com/OsMomobi diff --git a/OsmAnd/src/net/osmand/plus/activities/MapActivity.java b/OsmAnd/src/net/osmand/plus/activities/MapActivity.java index 6b03f75220..71abb48240 100644 --- a/OsmAnd/src/net/osmand/plus/activities/MapActivity.java +++ b/OsmAnd/src/net/osmand/plus/activities/MapActivity.java @@ -124,11 +124,11 @@ public class MapActivity extends AccessibleActivity { settings = app.getSettings(); app.applyTheme(this); super.onCreate(savedInstanceState); - - + requestWindowFeature(Window.FEATURE_NO_TITLE); + + mapActions = new MapActivityActions(this); mapLayers = new MapActivityLayers(this); - requestWindowFeature(Window.FEATURE_NO_TITLE); // Full screen is not used here //getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN); setContentView(R.layout.main); diff --git a/OsmAnd/src/net/osmand/plus/activities/MapActivityActions.java b/OsmAnd/src/net/osmand/plus/activities/MapActivityActions.java index 231b64a469..053329b4fe 100644 --- a/OsmAnd/src/net/osmand/plus/activities/MapActivityActions.java +++ b/OsmAnd/src/net/osmand/plus/activities/MapActivityActions.java @@ -98,6 +98,7 @@ public class MapActivityActions implements DialogProvider { DrawerLayout mDrawerLayout; ListView mDrawerList; private WaypointDialogHelper waypointDialogHelper; + private ConfigureSettingsMenuHelper configureSettingsMenuHelper; public MapActivityActions(MapActivity mapActivity){ @@ -105,6 +106,7 @@ public class MapActivityActions implements DialogProvider { settings = mapActivity.getMyApplication().getSettings(); routingHelper = mapActivity.getMyApplication().getRoutingHelper(); waypointDialogHelper = new WaypointDialogHelper(mapActivity); + configureSettingsMenuHelper = new ConfigureSettingsMenuHelper(mapActivity.getMyApplication()); waypointDialogHelper.init(); } @@ -906,7 +908,6 @@ public class MapActivityActions implements DialogProvider { final List deletedPoints = new ArrayList(); ArrayAdapter adapter = waypointDialogHelper.getWaypointsAdapter(app.getMapActivity(), deletedPoints); - mDrawerList = (ListView) mapActivity.findViewById(R.id.left_drawer); mDrawerList.setAdapter(adapter); return false; } else { @@ -922,8 +923,8 @@ public class MapActivityActions implements DialogProvider { .listen(new OnContextMenuClick() { @Override public boolean onContextMenuClick(int itemId, int pos, boolean isChecked, DialogInterface dialog) { - mapActivity.startActivity(new Intent(mapActivity, ConfigureSettingsMenuHelper.class)); - return true; + configureSettingsMenuHelper.setListView(mDrawerList); + return false; //mapActivity.getMapLayers().openLayerSelectionDialog(mapView); } }).reg(); diff --git a/OsmAnd/src/net/osmand/plus/configuremap/ConfigureSettingsMenuHelper.java b/OsmAnd/src/net/osmand/plus/configuremap/ConfigureSettingsMenuHelper.java index 992046e8ec..9afab4d621 100644 --- a/OsmAnd/src/net/osmand/plus/configuremap/ConfigureSettingsMenuHelper.java +++ b/OsmAnd/src/net/osmand/plus/configuremap/ConfigureSettingsMenuHelper.java @@ -1,15 +1,16 @@ package net.osmand.plus.configuremap; -import android.app.Activity; import android.app.AlertDialog; import android.content.DialogInterface; import android.content.Intent; +import android.graphics.Typeface; import android.os.Build; import android.preference.*; +import android.util.TypedValue; import android.view.KeyEvent; -import android.widget.ArrayAdapter; -import android.widget.ListAdapter; -import android.widget.Toast; +import android.view.View; +import android.view.ViewGroup; +import android.widget.*; import net.osmand.CallbackWithObject; import net.osmand.access.AccessibleToast; import net.osmand.data.AmenityType; @@ -18,9 +19,11 @@ import net.osmand.plus.activities.*; import net.osmand.plus.helpers.GpxUiHelper; import net.osmand.plus.render.RenderingIcons; import net.osmand.plus.views.mapwidgets.AppearanceWidgetsFactory; +import net.osmand.plus.views.mapwidgets.MapWidgetRegistry; import net.osmand.render.RenderingRuleProperty; import net.osmand.render.RenderingRulesStorage; +import java.lang.reflect.Field; import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; @@ -29,255 +32,336 @@ import java.util.List; /** * Created by Denis on 14.10.2014. */ -public class ConfigureSettingsMenuHelper{ +public class ConfigureSettingsMenuHelper { - 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; + public static final int BACK_HEADER = 0; + public static final int HEADER = 1; + public static final int LAYER = 2; + public static final int MAP_REDNDER = 3; + public static final int RENDERING_PROPERTY = 4; + + private ListView listView; private OsmandApplication app; - public class ConfigureMapMenuItem{ + public class ConfigureMapMenuItem { + int nameId; int type; int darkIcon = -1; - int whiteIcon = -1; + int lightIcon = -1; Object preference; - ConfigureMapMenuItem(int type, int darkIcon, int whiteIcon, Object preference){ + + ConfigureMapMenuItem(int type, int name, int darkIcon, int whiteIcon, Object preference) { this.type = type; + this.nameId = name; this.darkIcon = darkIcon; - this.whiteIcon = whiteIcon; + this.lightIcon = whiteIcon; this.preference = preference; } } - public ConfigureSettingsMenuHelper(OsmandApplication app){ + public ConfigureSettingsMenuHelper(OsmandApplication app) { this.app = app; } - private ArrayAdapter createAllCategories() { + public void setListView(ListView listView){ + this.listView = listView; + listView.setAdapter(createSettingsAdapter()); + } + + + private ArrayAdapter createSettingsAdapter() { List items = new ArrayList(); + items.add(new ConfigureMapMenuItem(BACK_HEADER, R.string.configure_map, R.drawable.ic_action_undo_dark, R.drawable.ic_action_undo_light, null)); createLayersItems(items); - createRenderingAttributePreferences(); - } - - private void createRenderingAttributePreferences() { - PreferenceCategory renderingCategory = new PreferenceCategory(this); - - grp.addPreference(renderingCategory); - Preference p = new Preference(this); - p.setTitle(R.string.map_widget_renderer); - p.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() { + createRenderingAttributeItems(items); + return new ArrayAdapter(app, R.layout.map_settings_item, items) { @Override - public boolean onPreferenceClick(Preference preference) { - AlertDialog.Builder bld = new AlertDialog.Builder(getActivity()); - bld.setTitle(R.string.renderers); - Collection rendererNames = app.getRendererRegistry().getRendererNames(); - final String[] items = rendererNames.toArray(new String[rendererNames.size()]); - final String[] visibleNames = new String[items.length]; - int selected = -1; - final String selectedName = app.getRendererRegistry().getCurrentSelectedRenderer().getName(); - for (int j = 0; j < items.length; j++) { - if (items[j].equals(selectedName)) { - selected = j; - } - visibleNames[j] = items[j].replace('_', ' ').replace( - '-', ' '); + public View getView(int position, View convertView, ViewGroup parent) { + if (convertView == null) { + convertView = app.getMapActivity().getLayoutInflater().inflate(R.layout.map_settings_item, null); } - bld.setSingleChoiceItems(visibleNames, selected, new DialogInterface.OnClickListener() { - - @Override - public void onClick(DialogInterface dialog, int which) { - String renderer = items[which]; - RenderingRulesStorage loaded = app.getRendererRegistry().getRenderer(renderer); - if (loaded != null) { - app.getSettings().RENDERER.set(renderer); - app.getRendererRegistry().setCurrentSelectedRender(loaded); - app.getResourceManager().getRenderer().clearCache(); - } else { - AccessibleToast.makeText(app, R.string.renderer_load_exception, Toast.LENGTH_SHORT).show(); - } - dialog.dismiss(); - createAllCategories(); - } - }); - bld.show(); - return true; - } - }); - - p = new Preference(this); - p.setTitle(R.string.map_widget_day_night); - p.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() { - @Override - public boolean onPreferenceClick(Preference preference) { - AlertDialog.Builder bld = new AlertDialog.Builder(getActivity()); - bld.setTitle(R.string.daynight); - final String[] items = new String[OsmandSettings.DayNightMode.values().length]; - for (int i = 0; i < items.length; i++) { - items[i] = OsmandSettings.DayNightMode.values()[i].toHumanString(getMyApplication()); - } - int i = getMyApplication().getSettings().DAYNIGHT_MODE.get().ordinal(); - bld.setSingleChoiceItems(items, i, new DialogInterface.OnClickListener() { - @Override - public void onClick(DialogInterface dialog, int which) { - getMyApplication().getSettings().DAYNIGHT_MODE.set(OsmandSettings.DayNightMode.values()[which]); - getMyApplication().getResourceManager().getRenderer().clearCache(); - dialog.dismiss(); - } - }); - bld.show(); - return true; - } - }); - grp.addPreference(p); - - RenderingRulesStorage renderer = getMyApplication().getRendererRegistry().getCurrentSelectedRenderer(); - if(renderer != null && AppearanceWidgetsFactory.EXTRA_SETTINGS) { - createMapRenderingPreferences(); - } - } - - - private void createMapRenderingPreferences() { - - RenderingRulesStorage renderer = app.getRendererRegistry().getCurrentSelectedRenderer(); - List customRules = renderer.PROPS.getCustomRules(); - for (final RenderingRuleProperty p : customRules) { - String propertyName = SettingsActivity.getStringPropertyName(getActivity(), p.getAttrName(), p.getName()); - //test old descr as title - final String propertyDescr = SettingsActivity.getStringPropertyDescription(getActivity(), p.getAttrName(), p.getName()); - if(p.isBoolean()) { - final OsmandSettings.CommonPreference pref = app.getSettings().getCustomRenderBooleanProperty(p.getAttrName()); - preference.setTitle(propertyName); - - preference.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() { - @Override - public boolean onPreferenceClick(Preference preference) { - pref.set(!pref.get()); - app.getResourceManager().getRenderer().clearCache(); - return true; - } - }); - - } else { - final OsmandSettings.CommonPreference pref = getMyApplication().getSettings().getCustomRenderProperty(p.getAttrName()); - Preference preference = new Preference(getActivity()); - preference.setTitle(propertyName); - renderingCategory.addPreference(preference); - preference.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() { - @Override - public boolean onPreferenceClick(Preference preference) { - AlertDialog.Builder b = new AlertDialog.Builder(getActivity()); - //test old descr as title - b.setTitle(propertyDescr); - - int i = Arrays.asList(p.getPossibleValues()).indexOf(pref.get()); - - String[] possibleValuesString = new String[p.getPossibleValues().length]; - - for (int j = 0; j < p.getPossibleValues().length; j++) { - possibleValuesString[j] = SettingsActivity.getStringPropertyValue(getApplication(), p.getPossibleValues()[j]); - } - - b.setSingleChoiceItems(possibleValuesString, i, new DialogInterface.OnClickListener() { + ConfigureMapMenuItem item = getItem(position); + prepareView(convertView, item); + if (item.type == BACK_HEADER){ + ((TextView) convertView.findViewById(R.id.name)).setText(item.nameId); + ImageButton button = (ImageButton) convertView.findViewById(R.id.back); + button.setImageResource(getIcon(item)); + } else if (item.type == HEADER) { + ((TextView) convertView.findViewById(R.id.name)).setText((String) item.preference); + } else if (item.type == LAYER) { + ((TextView) convertView.findViewById(R.id.name)).setText(item.nameId); + setLayersCheckBox(item, (CheckBox) convertView.findViewById(R.id.check)); + } else if (item.type == MAP_REDNDER) { + ((TextView) convertView.findViewById(R.id.name)).setText(item.nameId); + if (item.nameId == R.string.map_widget_renderer) { + convertView.setOnClickListener(new View.OnClickListener() { @Override - public void onClick(DialogInterface dialog, int which) { - pref.set(p.getPossibleValues()[which]); - app.getResourceManager().getRenderer().clearCache(); - dialog.dismiss(); + public void onClick(View view) { + AlertDialog.Builder bld = new AlertDialog.Builder(app.getMapActivity()); + bld.setTitle(R.string.renderers); + Collection rendererNames = app.getRendererRegistry().getRendererNames(); + final String[] items = rendererNames.toArray(new String[rendererNames.size()]); + final String[] visibleNames = new String[items.length]; + int selected = -1; + final String selectedName = app.getRendererRegistry().getCurrentSelectedRenderer().getName(); + for (int j = 0; j < items.length; j++) { + if (items[j].equals(selectedName)) { + selected = j; + } + visibleNames[j] = items[j].replace('_', ' ').replace( + '-', ' '); + } + bld.setSingleChoiceItems(visibleNames, selected, new DialogInterface.OnClickListener() { + + @Override + public void onClick(DialogInterface dialog, int which) { + String renderer = items[which]; + RenderingRulesStorage loaded = app.getRendererRegistry().getRenderer(renderer); + if (loaded != null) { + app.getSettings().RENDERER.set(renderer); + app.getRendererRegistry().setCurrentSelectedRender(loaded); + app.getResourceManager().getRenderer().clearCache(); + } else { + AccessibleToast.makeText(app, R.string.renderer_load_exception, Toast.LENGTH_SHORT).show(); + } + dialog.dismiss(); + createSettingsAdapter(); + } + }); + bld.show(); + } + }); + } else if (item.nameId == R.string.map_widget_day_night) { + convertView.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + AlertDialog.Builder bld = new AlertDialog.Builder(app.getMapActivity()); + bld.setTitle(R.string.daynight); + final String[] items = new String[OsmandSettings.DayNightMode.values().length]; + for (int i = 0; i < items.length; i++) { + items[i] = OsmandSettings.DayNightMode.values()[i].toHumanString(app); + } + int i = app.getSettings().DAYNIGHT_MODE.get().ordinal(); + bld.setSingleChoiceItems(items, i, new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int which) { + app.getSettings().DAYNIGHT_MODE.set(OsmandSettings.DayNightMode.values()[which]); + app.getResourceManager().getRenderer().clearCache(); + dialog.dismiss(); + } + }); + bld.show(); } }); - b.show(); - return true; } - }); + } else if (item.type == RENDERING_PROPERTY) { + convertView.findViewById(R.id.icon).setVisibility(View.GONE); + final RenderingRuleProperty p = (RenderingRuleProperty) item.preference; + String propertyName = SettingsActivity.getStringPropertyName(app, p.getAttrName(), p.getName()); + TextView header = (TextView) convertView.findViewById(R.id.name); + header.setText(propertyName); + header.setTextSize(TypedValue.COMPLEX_UNIT_SP, 16); + convertView.findViewById(R.id.icon).setVisibility(View.GONE); + final String propertyDescription = SettingsActivity.getStringPropertyDescription(app, p.getAttrName(), p.getName()); + if (p.isBoolean()) { + final OsmandSettings.CommonPreference pref = app.getSettings().getCustomRenderBooleanProperty(p.getAttrName()); + CheckBox ch = (CheckBox) convertView.findViewById(R.id.check); + ch.setChecked(pref.get()); + ch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { + @Override + public void onCheckedChanged(CompoundButton compoundButton, boolean b) { + pref.set(!pref.get()); + app.getResourceManager().getRenderer().clearCache(); + //view.refreshMap(true); + } + }); + } else { + final OsmandSettings.CommonPreference pref = app.getSettings().getCustomRenderProperty(p.getAttrName()); + convertView.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + AlertDialog.Builder b = new AlertDialog.Builder(app.getMapActivity()); + //test old descr as title + b.setTitle(propertyDescription); + int i = Arrays.asList(p.getPossibleValues()).indexOf(pref.get()); + + String[] possibleValuesString = new String[p.getPossibleValues().length]; + + for (int j = 0; j < p.getPossibleValues().length; j++) { + possibleValuesString[j] = SettingsActivity.getStringPropertyValue(app, p.getPossibleValues()[j]); + } + + b.setSingleChoiceItems(possibleValuesString, i, new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int which) { + pref.set(p.getPossibleValues()[which]); + app.getResourceManager().getRenderer().clearCache(); + //view.refreshMap(true); + dialog.dismiss(); + } + }); + b.show(); + } + }); + } + } + return convertView; } - } - } + //Hiding and showing items based on current item + //setting proper visual property + private void prepareView(View convertView, ConfigureMapMenuItem item) { + int type = item.type; + //setting name textview + if (type == BACK_HEADER) { + TextView header = (TextView) convertView.findViewById(R.id.name); + header.setTextSize(TypedValue.COMPLEX_UNIT_SP, 22); + header.setTypeface(Typeface.DEFAULT_BOLD); + } else if (type == HEADER) { + TextView header = (TextView) convertView.findViewById(R.id.name); + header.setTextSize(TypedValue.COMPLEX_UNIT_SP, 20); + header.setTypeface(Typeface.DEFAULT_BOLD); + } else { + ((TextView) convertView.findViewById(R.id.name)).setTextSize(TypedValue.COMPLEX_UNIT_SP, 16); + } + + //setting backbutton + if (type == BACK_HEADER) { + convertView.findViewById(R.id.back).setVisibility(View.VISIBLE); + } else { + convertView.findViewById(R.id.back).setVisibility(View.GONE); + } + + //other elements + if (type == BACK_HEADER) { + convertView.findViewById(R.id.check).setVisibility(View.GONE); + convertView.findViewById(R.id.descr).setVisibility(View.GONE); + convertView.findViewById(R.id.icon).setVisibility(View.GONE); + } else if (type == HEADER) { + convertView.findViewById(R.id.icon).setVisibility(View.GONE); + convertView.findViewById(R.id.check).setVisibility(View.GONE); + convertView.findViewById(R.id.descr).setVisibility(View.GONE); + } else if (type == LAYER) { + ((ImageView) convertView.findViewById(R.id.icon)).setImageResource(getIcon(item)); + convertView.findViewById(R.id.icon).setVisibility(View.VISIBLE); + } else if (type == MAP_REDNDER) { + convertView.findViewById(R.id.icon).setVisibility(View.GONE); + convertView.findViewById(R.id.check).setVisibility(View.GONE); + } else if (type == RENDERING_PROPERTY) { + final RenderingRuleProperty p = (RenderingRuleProperty) item.preference; + if (p.isBoolean()) { + convertView.findViewById(R.id.check).setVisibility(View.VISIBLE); + } else { + convertView.findViewById(R.id.check).setVisibility(View.GONE); + } + + } + } + + private int getIcon(ConfigureMapMenuItem item) { + if (app.getSettings().isLightContent()) { + return item.lightIcon; + } else { + return item.darkIcon; + } + } + + private void setLayersCheckBox(ConfigureMapMenuItem item, CheckBox check) { + check.setVisibility(View.VISIBLE); + if (item.nameId == R.string.layer_poi) { + final OsmandSettings.OsmandPreference pref = (OsmandSettings.OsmandPreference) item.preference; + check.setChecked(pref.get()); + check.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { + @Override + public void onCheckedChanged(CompoundButton compoundButton, boolean b) { + if (b) { + selectPOIFilterLayer(null); + } else { + pref.set(b); + } + } + }); + } else if (item.nameId == R.string.layer_gpx_layer) { + check.setChecked(app.getSelectedGpxHelper().isShowingAnyGpxFiles()); + check.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { + @Override + public void onCheckedChanged(CompoundButton compoundButton, boolean b) { + if (b) { + showGPXFileDialog(null); + } + } + }); + } else if (item.nameId == R.string.layer_transport && TransportRouteHelper.getInstance().routeIsCalculated()) { + check.setChecked(true); + } else { + final OsmandSettings.OsmandPreference pref = (OsmandSettings.OsmandPreference) item.preference; + check.setChecked(pref.get()); + check.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { + @Override + public void onCheckedChanged(CompoundButton compoundButton, boolean b) { + pref.set(b); + } + }); + } + } + + + }; + } private void createLayersItems(List items) { - items.add(new ConfigureMapMenuItem(HEADER,-1,-1,R.string.show)); - grp.addPreference(mapLayersCategory); - final CheckBoxPreference poi = new CheckBoxPreference(this); - poi.setTitle(R.string.layer_poi); - poi.setChecked(settings.SHOW_POI_OVER_MAP.get()); - addIcon(poi, R.drawable.ic_action_info_light, R.drawable.ic_action_info_dark); - poi.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() { - @Override - public boolean onPreferenceClick(Preference preference) { - settings.SHOW_POI_OVER_MAP.set(!settings.SHOW_POI_OVER_MAP.get()); - if (settings.SHOW_POI_OVER_MAP.get()) { - selectPOIFilterLayer(null); - } else { - poi.setSummary(""); - } - return true; - } - }); - if (settings.SHOW_POI_OVER_MAP.get()) { - poi.setSummary(settings.getPoiFilterForMap()); - } - mapLayersCategory.addPreference(poi); - CheckBoxPreference p = createCheckBoxPreference(settings.SHOW_POI_LABEL, R.string.layer_amenity_label, - R.drawable.ic_action_text_dark, R.drawable.ic_action_text_light); - mapLayersCategory.addPreference(p); - - p = createCheckBoxPreference(settings.SHOW_FAVORITES, R.string.layer_favorites, - R.drawable.ic_action_fav_dark, R.drawable.ic_action_fav_light); - mapLayersCategory.addPreference(p); - final CheckBoxPreference gpx = new CheckBoxPreference(this); - gpx.setTitle(R.string.layer_gpx_layer); - addIcon(gpx, R.drawable.ic_action_polygom_light, R.drawable.ic_action_polygom_dark); - gpx.setChecked(getMyApplication().getSelectedGpxHelper().isShowingAnyGpxFiles()); - gpx.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() { - @Override - public boolean onPreferenceClick(Preference preference) { - if (gpx.isChecked()){ - showGPXFileDialog(getAlreadySelectedGpx()); - } - return true; - } - }); - - mapLayersCategory.addPreference(gpx); - p = createCheckBoxPreference(settings.SHOW_TRANSPORT_OVER_MAP, R.string.layer_transport, - R.drawable.ic_action_bus_dark, R.drawable.ic_action_bus_light); - mapLayersCategory.addPreference(p); + items.add(new ConfigureMapMenuItem(HEADER, -1, -1, -1, "Show:")); + items.add(new ConfigureMapMenuItem(LAYER, R.string.layer_poi, R.drawable.ic_action_info_dark, + R.drawable.ic_action_info_light, app.getSettings().SHOW_POI_OVER_MAP)); + items.add(new ConfigureMapMenuItem(LAYER, R.string.layer_amenity_label, R.drawable.ic_action_text_dark, + R.drawable.ic_action_text_light, app.getSettings().SHOW_POI_LABEL)); + items.add(new ConfigureMapMenuItem(LAYER, R.string.layer_favorites, R.drawable.ic_action_fav_dark, + R.drawable.ic_action_fav_light, app.getSettings().SHOW_FAVORITES)); + items.add(new ConfigureMapMenuItem(LAYER, R.string.layer_gpx_layer, R.drawable.ic_action_polygom_dark, + R.drawable.ic_action_polygom_light, null)); + items.add(new ConfigureMapMenuItem(LAYER, R.string.layer_transport, R.drawable.ic_action_bus_dark, + R.drawable.ic_action_bus_light, app.getSettings().SHOW_TRANSPORT_OVER_MAP)); if (TransportRouteHelper.getInstance().routeIsCalculated()) { - p = new CheckBoxPreference(this); - p.setChecked(true); - addIcon(p, R.drawable.ic_action_bus_light, R.drawable.ic_action_bus_dark); - mapLayersCategory.addPreference(p); + items.add(new ConfigureMapMenuItem(R.string.layer_transport, LAYER, + R.drawable.ic_action_bus_dark, R.drawable.ic_action_bus_light, 1)); } } - public void addIcon(CheckBoxPreference p, int lightIcon, int darkIcon) { - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) { - if (getMyApplication().getSettings().isLightContent()) { - p.setIcon(lightIcon); - } else { - p.setIcon(darkIcon); - } + private void createRenderingAttributeItems(List items) { + items.add(new ConfigureMapMenuItem(HEADER, -1, -1, -1, app.getString(R.string.map_widget_map_rendering))); + items.add(new ConfigureMapMenuItem(MAP_REDNDER, R.string.map_widget_renderer, -1, -1, null)); + items.add(new ConfigureMapMenuItem(MAP_REDNDER, R.string.map_widget_day_night, -1, -1, null)); + + RenderingRulesStorage renderer = app.getRendererRegistry().getCurrentSelectedRenderer(); + if (renderer != null && AppearanceWidgetsFactory.EXTRA_SETTINGS) { + createMapRenderingPreferences(items); + } + } + + private void createMapRenderingPreferences(List items) { + items.add(new ConfigureMapMenuItem(HEADER, -1, -1, -1, app.getString(R.string.map_widget_vector_attributes))); + RenderingRulesStorage renderer = app.getRendererRegistry().getCurrentSelectedRenderer(); + List customRules = renderer.PROPS.getCustomRules(); + for (RenderingRuleProperty p : customRules) { + items.add(new ConfigureMapMenuItem(RENDERING_PROPERTY, -1, -1, -1, p)); } } public AlertDialog selectPOIFilterLayer(final PoiFilter[] selected) { final List userDefined = new ArrayList(); - OsmandApplication app = (OsmandApplication) getApplication(); final PoiFiltersHelper poiFilters = app.getPoiFilters(); - final ContextMenuAdapter adapter = new ContextMenuAdapter(this); + final ContextMenuAdapter adapter = new ContextMenuAdapter(app.getMapActivity()); - ContextMenuAdapter.Item is = adapter.item(getString(R.string.any_poi)); + ContextMenuAdapter.Item is = adapter.item(app.getString(R.string.any_poi)); if (RenderingIcons.containsBigIcon("null")) { is.icon(RenderingIcons.getBigIconResourceId("null")); } is.reg(); // 2nd custom - adapter.item(getString(R.string.poi_filter_custom_filter)).icon(RenderingIcons.getBigIconResourceId("user_defined")).reg(); + adapter.item(app.getString(R.string.poi_filter_custom_filter)).icon(RenderingIcons.getBigIconResourceId("user_defined")).reg(); for (PoiFilter f : poiFilters.getUserDefinedPoiFilters()) { ContextMenuAdapter.Item it = adapter.item(f.getName()); @@ -291,20 +375,20 @@ public class ConfigureSettingsMenuHelper{ } final AmenityType[] categories = AmenityType.getCategories(); for (AmenityType t : categories) { - ContextMenuAdapter.Item it = adapter.item(OsmAndFormatter.toPublicString(t, getMyApplication())); + ContextMenuAdapter.Item it = adapter.item(OsmAndFormatter.toPublicString(t, app)); if (RenderingIcons.containsBigIcon(t.toString().toLowerCase())) { it.icon(RenderingIcons.getBigIconResourceId(t.toString().toLowerCase())); } it.reg(); } - final AlertDialog.Builder builder = new AlertDialog.Builder(this); + final AlertDialog.Builder builder = new AlertDialog.Builder(app.getMapActivity()); ListAdapter listAdapter; if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB) { listAdapter = - adapter.createListAdapter(this, R.layout.list_menu_item, app.getSettings().isLightContentMenu()); + adapter.createListAdapter(app.getMapActivity(), R.layout.list_menu_item, app.getSettings().isLightContentMenu()); } else { listAdapter = - adapter.createListAdapter(this, R.layout.list_menu_item_native, app.getSettings().isLightContentMenu()); + adapter.createListAdapter(app.getMapActivity(), R.layout.list_menu_item_native, app.getSettings().isLightContentMenu()); } builder.setAdapter(listAdapter, new DialogInterface.OnClickListener() { @@ -312,12 +396,12 @@ public class ConfigureSettingsMenuHelper{ public void onClick(DialogInterface dialog, int which) { if (which == 1) { String filterId = PoiFilter.CUSTOM_FILTER_ID; - getMyApplication().getSettings().setPoiFilterForMap(filterId); - Intent newIntent = new Intent(getApplication(), EditPOIFilterActivity.class); + app.getSettings().setPoiFilterForMap(filterId); + Intent newIntent = new Intent(app, EditPOIFilterActivity.class); newIntent.putExtra(EditPOIFilterActivity.AMENITY_FILTER, filterId); //newIntent.putExtra(EditPOIFilterActivity.SEARCH_LAT, getMyApplication().getMapActivity().getMapView().getLatitude()); //newIntent.putExtra(EditPOIFilterActivity.SEARCH_LON, getMyApplication().getMapActivity().getMapView().getLongitude()); - getActivity().startActivity(newIntent); + app.getMapActivity().startActivity(newIntent); } else { String filterId; if (which == 0) { @@ -327,7 +411,7 @@ public class ConfigureSettingsMenuHelper{ } else { filterId = PoiFiltersHelper.getOsmDefinedFilterId(categories[which - userDefined.size() - 2]); } - getMyApplication().getSettings().setPoiFilterForMap(filterId); + app.getSettings().setPoiFilterForMap(filterId); PoiFilter f = poiFilters.getFilterById(filterId); if (f != null) { f.clearNameFilter(); @@ -335,7 +419,7 @@ public class ConfigureSettingsMenuHelper{ if (selected != null && selected.length > 0) { selected[0] = f; } - createAllCategories(); + createSettingsAdapter(); } } @@ -347,8 +431,8 @@ public class ConfigureSettingsMenuHelper{ event.getAction() == KeyEvent.ACTION_UP && !event.isCanceled()) { dialogInterface.cancel(); - settings.SHOW_POI_OVER_MAP.set(false); - createAllCategories(); + app.getSettings().SHOW_POI_OVER_MAP.set(false); + createSettingsAdapter(); return true; } return false; @@ -357,10 +441,6 @@ public class ConfigureSettingsMenuHelper{ return builder.show(); } - private Activity getActivity() { - return this; - } - public void showGPXFileDialog(List files) { CallbackWithObject callbackWithObject = new CallbackWithObject() { @Override @@ -368,9 +448,9 @@ public class ConfigureSettingsMenuHelper{ GPXUtilities.WptPt locToShow = null; for (GPXUtilities.GPXFile g : result) { if (g.showCurrentTrack) { - if (!settings.SAVE_TRACK_TO_GPX.get() && ! - settings.SAVE_GLOBAL_TRACK_TO_GPX.get()) { - AccessibleToast.makeText(getActivity(), R.string.gpx_monitoring_disabled_warn, Toast.LENGTH_SHORT).show(); + if (!app.getSettings().SAVE_TRACK_TO_GPX.get() && ! + app.getSettings().SAVE_GLOBAL_TRACK_TO_GPX.get()) { + AccessibleToast.makeText(app.getMapActivity(), R.string.gpx_monitoring_disabled_warn, Toast.LENGTH_SHORT).show(); } break; } @@ -378,22 +458,22 @@ public class ConfigureSettingsMenuHelper{ locToShow = g.findPointToShow(); } } - getMyApplication().getSelectedGpxHelper().setGpxFileToDisplay(result); - createAllCategories(); + app.getSelectedGpxHelper().setGpxFileToDisplay(result); + createSettingsAdapter(); return true; } }; if (files == null) { - GpxUiHelper.selectGPXFile(getActivity(), true, true, callbackWithObject); + GpxUiHelper.selectGPXFile(app.getMapActivity(), true, true, callbackWithObject); } else { - GpxUiHelper.selectGPXFile(files, getActivity(), true, true, callbackWithObject); + GpxUiHelper.selectGPXFile(files, app.getMapActivity(), true, true, callbackWithObject); } } - private List getAlreadySelectedGpx(){ - GpxSelectionHelper gpxSelectionHelper = getMyApplication().getSelectedGpxHelper(); - if (gpxSelectionHelper == null){ + private List getAlreadySelectedGpx() { + GpxSelectionHelper gpxSelectionHelper = app.getSelectedGpxHelper(); + if (gpxSelectionHelper == null) { return null; } List selectedGpxFiles = gpxSelectionHelper.getSelectedGPXFiles();