From f4b65ef81ab437bd99c09f75b626f82b0a95035f Mon Sep 17 00:00:00 2001 From: vshcherb Date: Fri, 23 Aug 2013 10:42:24 +0200 Subject: [PATCH] Remove extra settings plugin --- OsmAnd/OsmAnd.iml | 2 +- OsmAnd/src/net/osmand/plus/OsmandPlugin.java | 18 +- .../plus/activities/LocalIndexesActivity.java | 2 - .../extrasettings/OsmandExtraSettings.java | 81 +----- .../net/osmand/plus/views/MapInfoLayer.java | 222 ++------------- .../mapwidgets/AppearanceWidgetsFactory.java | 261 ++++++++++++++++++ 6 files changed, 293 insertions(+), 293 deletions(-) create mode 100644 OsmAnd/src/net/osmand/plus/views/mapwidgets/AppearanceWidgetsFactory.java diff --git a/OsmAnd/OsmAnd.iml b/OsmAnd/OsmAnd.iml index 4b2429a0e9..f65424b6ed 100644 --- a/OsmAnd/OsmAnd.iml +++ b/OsmAnd/OsmAnd.iml @@ -1,7 +1,7 @@ - + diff --git a/OsmAnd/src/net/osmand/plus/OsmandPlugin.java b/OsmAnd/src/net/osmand/plus/OsmandPlugin.java index d0f608013f..beea75ca2e 100644 --- a/OsmAnd/src/net/osmand/plus/OsmandPlugin.java +++ b/OsmAnd/src/net/osmand/plus/OsmandPlugin.java @@ -1,11 +1,9 @@ package net.osmand.plus; - -import java.util.ArrayList; -import java.util.List; -import java.util.Set; - +import android.content.Intent; +import android.content.pm.PackageManager.NameNotFoundException; +import android.preference.PreferenceScreen; import net.osmand.IProgress; import net.osmand.PlatformUtil; import net.osmand.access.AccessibilityPlugin; @@ -17,7 +15,6 @@ import net.osmand.plus.activities.SettingsActivity; import net.osmand.plus.audionotes.AudioVideoNotesPlugin; import net.osmand.plus.development.OsmandDevelopmentPlugin; import net.osmand.plus.distancecalculator.DistanceCalculatorPlugin; -import net.osmand.plus.extrasettings.OsmandExtraSettings; import net.osmand.plus.monitoring.OsmandMonitoringPlugin; import net.osmand.plus.osmedit.OsmEditingPlugin; import net.osmand.plus.osmodroid.OsMoDroidPlugin; @@ -25,12 +22,11 @@ import net.osmand.plus.parkingpoint.ParkingPositionPlugin; import net.osmand.plus.rastermaps.OsmandRasterMapsPlugin; import net.osmand.plus.srtmplugin.SRTMPlugin; import net.osmand.plus.views.OsmandMapTileView; - import org.apache.commons.logging.Log; -import android.content.Intent; -import android.content.pm.PackageManager.NameNotFoundException; -import android.preference.PreferenceScreen; +import java.util.ArrayList; +import java.util.List; +import java.util.Set; public abstract class OsmandPlugin { @@ -68,7 +64,7 @@ public abstract class OsmandPlugin { OsmandRasterMapsPlugin rasterMapsPlugin = new OsmandRasterMapsPlugin(app); installedPlugins.add(rasterMapsPlugin); installedPlugins.add(new OsmandMonitoringPlugin(app)); - installedPlugins.add(new OsmandExtraSettings(app)); +// installedPlugins.add(new OsmandExtraSettings(app)); installedPlugins.add(new AccessibilityPlugin(app)); if(!installPlugin(SRTM_PLUGIN_COMPONENT_PAID, SRTMPlugin.ID, app, new SRTMPlugin(app, true))) { diff --git a/OsmAnd/src/net/osmand/plus/activities/LocalIndexesActivity.java b/OsmAnd/src/net/osmand/plus/activities/LocalIndexesActivity.java index ba7b835fc0..bc119d9e0b 100644 --- a/OsmAnd/src/net/osmand/plus/activities/LocalIndexesActivity.java +++ b/OsmAnd/src/net/osmand/plus/activities/LocalIndexesActivity.java @@ -77,8 +77,6 @@ public class LocalIndexesActivity extends OsmandExpandableListActivity { private ContextMenuAdapter optionsMenuAdapter; private ActionMode actionMode; - - @SuppressWarnings("unchecked") @Override protected void onCreate(Bundle savedInstanceState) { diff --git a/OsmAnd/src/net/osmand/plus/extrasettings/OsmandExtraSettings.java b/OsmAnd/src/net/osmand/plus/extrasettings/OsmandExtraSettings.java index bb16c85a00..137ddd4f94 100644 --- a/OsmAnd/src/net/osmand/plus/extrasettings/OsmandExtraSettings.java +++ b/OsmAnd/src/net/osmand/plus/extrasettings/OsmandExtraSettings.java @@ -5,6 +5,7 @@ import java.util.Arrays; import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandPlugin; +import net.osmand.plus.OsmandSettings; import net.osmand.plus.OsmandSettings.OsmandPreference; import net.osmand.plus.R; import net.osmand.plus.activities.MapActivity; @@ -43,91 +44,13 @@ public class OsmandExtraSettings extends OsmandPlugin { public String getName() { return app.getString(R.string.extra_settings); } + @Override public void registerLayers(final MapActivity activity) { registerControls = true; final OsmandMapTileView view = activity.getMapView(); final MapInfoLayer mapInfoLayer = activity.getMapLayers().getMapInfoLayer(); final MapWidgetRegistry mapInfoControls = mapInfoLayer.getMapInfoControls(); - - final OsmandPreference textSizePref = view.getSettings().MAP_TEXT_SIZE; - final MapWidgetRegInfo textSize = mapInfoControls.registerAppearanceWidget(R.drawable.widget_text_size, R.string.map_text_size, - "text_size", textSizePref); - textSize.setStateChangeListener(new Runnable() { - @Override - public void run() { - final Float[] floatValues = new Float[] {0.6f, 0.8f, 1.0f, 1.2f, 1.5f, 1.75f, 2f}; - String[] entries = new String[floatValues.length]; - for (int i = 0; i < floatValues.length; i++) { - entries[i] = (int) (floatValues[i] * 100) +" %"; - } - Builder b = new AlertDialog.Builder(view.getContext()); - b.setTitle(R.string.map_text_size); - int i = Arrays.binarySearch(floatValues, textSizePref.get()); - b.setSingleChoiceItems(entries, i, new OnClickListener() { - @Override - public void onClick(DialogInterface dialog, int which) { - textSizePref.set(floatValues[which]); - app.getResourceManager().getRenderer().clearCache(); - view.refreshMap(true); - dialog.dismiss(); - } - }); - b.show(); - } - }); - - final MapWidgetRegInfo showRuler = mapInfoControls.registerAppearanceWidget(R.drawable.widget_ruler, R.string.map_widget_show_ruler, - "showRuler", view.getSettings().SHOW_RULER); - showRuler.setStateChangeListener(new Runnable() { - @Override - public void run() { - view.getSettings().SHOW_RULER.set(!view.getSettings().SHOW_RULER.get()); - view.refreshMap(); - } - }); - - final MapWidgetRegInfo showDestinationArrow = mapInfoControls.registerAppearanceWidget(R.drawable.widget_show_destination_arrow, R.string.map_widget_show_destination_arrow, - "show_destination_arrow", view.getSettings().SHOW_DESTINATION_ARROW); - showDestinationArrow.setStateChangeListener(new Runnable() { - @Override - public void run() { - view.getSettings().SHOW_DESTINATION_ARROW.set(!view.getSettings().SHOW_DESTINATION_ARROW.get()); - mapInfoLayer.recreateControls(); - } - }); - - final MapWidgetRegInfo transparent = mapInfoControls.registerAppearanceWidget(R.drawable.widget_transparent_skin, R.string.map_widget_transparent, - "transparent", view.getSettings().TRANSPARENT_MAP_THEME); - transparent.setStateChangeListener(new Runnable() { - @Override - public void run() { - view.getSettings().TRANSPARENT_MAP_THEME.set(!view.getSettings().TRANSPARENT_MAP_THEME.get()); - mapInfoLayer.recreateControls(); - } - }); - -// final MapInfoControlRegInfo posMap = mapInfoControls.registerAppearanceWidget(R.drawable.widget_position_marker, R.string.position_on_map, -// "position_on_map", textSizePref); -// posMap.setStateChangeListener(new Runnable() { -// @Override -// public void run() { -// String[] entries = new String[] { activity.getString(R.string.position_on_map_center), activity.getString(R.string.position_on_map_bottom) }; -// final Integer[] vals = new Integer[] { OsmandSettings.CENTER_CONSTANT, OsmandSettings.BOTTOM_CONSTANT }; -// Builder b = new AlertDialog.Builder(view.getContext()); -// int i = Arrays.binarySearch(vals, posPref.get()); -// b.setSingleChoiceItems(entries, i, new OnClickListener() { -// @Override -// public void onClick(DialogInterface dialog, int which) { -// posPref.set(vals[which]); -// activity.updateApplicationModeSettings(); -// view.refreshMap(true); -// dialog.dismiss(); -// } -// }); -// b.show(); -// } -// }); } @Override diff --git a/OsmAnd/src/net/osmand/plus/views/MapInfoLayer.java b/OsmAnd/src/net/osmand/plus/views/MapInfoLayer.java index b248a7b2db..54dd9232da 100644 --- a/OsmAnd/src/net/osmand/plus/views/MapInfoLayer.java +++ b/OsmAnd/src/net/osmand/plus/views/MapInfoLayer.java @@ -1,52 +1,11 @@ package net.osmand.plus.views; -import java.lang.reflect.Field; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collection; -import java.util.EnumSet; -import java.util.LinkedHashSet; -import java.util.List; -import java.util.Set; - -import net.osmand.access.AccessibleToast; -import net.osmand.plus.ApplicationMode; -import net.osmand.plus.OsmandApplication; -import net.osmand.plus.OsmandPlugin; -import net.osmand.plus.OsmandSettings; -import net.osmand.plus.OsmandSettings.CommonPreference; -import net.osmand.plus.R; -import net.osmand.plus.activities.MapActivity; -import net.osmand.plus.activities.MapActivityActions; -import net.osmand.plus.activities.SettingsActivity; -import net.osmand.plus.extrasettings.OsmandExtraSettings; -import net.osmand.plus.routing.RoutingHelper; -import net.osmand.plus.views.mapwidgets.BaseMapWidget; -import net.osmand.plus.views.mapwidgets.ImageViewWidget; -import net.osmand.plus.views.mapwidgets.MapInfoWidgetsFactory; -import net.osmand.plus.views.mapwidgets.MapInfoWidgetsFactory.TopTextView; -import net.osmand.plus.views.mapwidgets.MapWidgetRegistry; -import net.osmand.plus.views.mapwidgets.MapWidgetRegistry.MapWidgetRegInfo; -import net.osmand.plus.views.mapwidgets.NextTurnInfoWidget; -import net.osmand.plus.views.mapwidgets.RouteInfoWidgetsFactory; -import net.osmand.plus.views.mapwidgets.StackWidgetView; -import net.osmand.plus.views.mapwidgets.TextInfoWidget; -import net.osmand.plus.views.mapwidgets.UpdateableWidget; -import net.osmand.render.RenderingRuleProperty; -import net.osmand.render.RenderingRulesStorage; -import net.osmand.util.Algorithms; import android.app.AlertDialog; import android.app.AlertDialog.Builder; import android.content.Context; -import android.content.DialogInterface; -import android.content.DialogInterface.OnClickListener; -import android.graphics.Canvas; -import android.graphics.Color; -import android.graphics.Paint; +import android.graphics.*; import android.graphics.Paint.Style; -import android.graphics.Rect; -import android.graphics.RectF; import android.graphics.drawable.Drawable; import android.util.DisplayMetrics; import android.view.Gravity; @@ -54,20 +13,27 @@ import android.view.View; import android.view.View.MeasureSpec; import android.view.ViewGroup; import android.view.WindowManager; -import android.widget.AdapterView; +import android.widget.*; import android.widget.AdapterView.OnItemClickListener; -import android.widget.ArrayAdapter; -import android.widget.CheckBox; -import android.widget.CompoundButton; -import android.widget.ListView; import android.widget.CompoundButton.OnCheckedChangeListener; -import android.widget.FrameLayout; -import android.widget.ImageView; -import android.widget.LinearLayout; import android.widget.LinearLayout.LayoutParams; -import android.widget.ListAdapter; -import android.widget.TextView; -import android.widget.Toast; +import net.osmand.plus.ApplicationMode; +import net.osmand.plus.OsmandApplication; +import net.osmand.plus.OsmandSettings; +import net.osmand.plus.R; +import net.osmand.plus.activities.MapActivity; +import net.osmand.plus.activities.MapActivityActions; +import net.osmand.plus.routing.RoutingHelper; +import net.osmand.plus.views.mapwidgets.*; +import net.osmand.plus.views.mapwidgets.MapInfoWidgetsFactory.TopTextView; +import net.osmand.plus.views.mapwidgets.MapWidgetRegistry.MapWidgetRegInfo; +import net.osmand.util.Algorithms; + +import java.lang.reflect.Field; +import java.util.ArrayList; +import java.util.EnumSet; +import java.util.LinkedHashSet; +import java.util.Set; public class MapInfoLayer extends OsmandMapLayer { @@ -100,7 +66,7 @@ public class MapInfoLayer extends OsmandMapLayer { private MonitoringInfoControl monitoringServices; - private String ADDITIONAL_VECTOR_RENDERING_CATEGORY; + @@ -117,7 +83,6 @@ public class MapInfoLayer extends OsmandMapLayer { scaleCoefficient *= 1.5f; } - ADDITIONAL_VECTOR_RENDERING_CATEGORY = map.getString(R.string.map_widget_vector_attributes); paintText = new Paint(); paintText.setStyle(Style.FILL_AND_STROKE); paintText.setColor(Color.BLACK); @@ -250,150 +215,10 @@ public class MapInfoLayer extends OsmandMapLayer { "street_name", MapWidgetRegistry.MAIN_CONTROL, all, 100); // Register appearance widgets - registerAppearanceWidgets(); + AppearanceWidgetsFactory.INSTANCE.registerAppearanceWidgets(map, this, mapInfoControls); } - private void registerAppearanceWidgets() { - final MapWidgetRegInfo vectorRenderer = mapInfoControls.registerAppearanceWidget(R.drawable.widget_rendering_style, R.string.map_widget_renderer, - "renderer", view.getSettings().RENDERER); - final OsmandApplication app = view.getApplication(); - vectorRenderer.setStateChangeListener(new Runnable() { - @Override - public void run() { - Builder bld = new AlertDialog.Builder(view.getContext()); - bld.setTitle(R.string.renderers); - Collection rendererNames = app.getRendererRegistry().getRendererNames(); - final String[] items = rendererNames.toArray(new String[rendererNames.size()]); - int i = -1; - for(int j = 0; j< items.length; j++) { - if(items[j].equals(app.getRendererRegistry().getCurrentSelectedRenderer().getName())) { - i = j; - break; - } - } - bld.setSingleChoiceItems(items, i, new OnClickListener() { - - @Override - public void onClick(DialogInterface dialog, int which) { - String renderer = items[which]; - RenderingRulesStorage loaded = app.getRendererRegistry().getRenderer(renderer); - if (loaded != null) { - view.getSettings().RENDERER.set(renderer); - app.getRendererRegistry().setCurrentSelectedRender(loaded); - app.getResourceManager().getRenderer().clearCache(); - view.refreshMap(true); - } else { - AccessibleToast.makeText(app, R.string.renderer_load_exception, Toast.LENGTH_SHORT).show(); - } - createCustomRenderingProperties(loaded); - dialog.dismiss(); - } - }); - bld.show(); - } - }); - - final MapWidgetRegInfo dayNight = mapInfoControls.registerAppearanceWidget(R.drawable.widget_day_night_mode, R.string.map_widget_day_night, - "dayNight", view.getSettings().DAYNIGHT_MODE); - dayNight.setStateChangeListener(new Runnable() { - @Override - public void run() { - Builder bld = new AlertDialog.Builder(view.getContext()); - 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(map.getMyApplication()); - } - int i = view.getSettings().DAYNIGHT_MODE.get().ordinal(); - bld.setSingleChoiceItems(items, i, new OnClickListener() { - @Override - public void onClick(DialogInterface dialog, int which) { - view.getSettings().DAYNIGHT_MODE.set(OsmandSettings.DayNightMode.values()[which]); - app.getResourceManager().getRenderer().clearCache(); - view.refreshMap(true); - dialog.dismiss(); - } - }); - bld.show(); - } - }); - - final MapWidgetRegInfo displayViewDirections = mapInfoControls.registerAppearanceWidget(R.drawable.widget_viewing_direction, R.string.map_widget_view_direction, - "viewDirection", view.getSettings().SHOW_VIEW_ANGLE); - displayViewDirections.setStateChangeListener(new Runnable() { - @Override - public void run() { - view.getSettings().SHOW_VIEW_ANGLE.set(!view.getSettings().SHOW_VIEW_ANGLE.get()); - map.getMapViewTrackingUtilities().updateSettings(); - } - }); - - RenderingRulesStorage renderer = app.getRendererRegistry().getCurrentSelectedRenderer(); - if(renderer != null) { - createCustomRenderingProperties(renderer); - } - } - - private void createCustomRenderingProperties(RenderingRulesStorage renderer) { - String categoryName = ADDITIONAL_VECTOR_RENDERING_CATEGORY; - mapInfoControls.removeApperanceWidgets(categoryName); - final OsmandApplication app = view.getApplication(); - List customRules = renderer.PROPS.getCustomRules(); - for (final RenderingRuleProperty p : customRules) { - String propertyName = SettingsActivity.getStringPropertyName(view.getContext(), p.getAttrName(), p.getName()); - //test old descr as title - final String propertyDescr = SettingsActivity.getStringPropertyDescription(view.getContext(), p.getAttrName(), p.getName()); - if(p.isBoolean()) { - final CommonPreference pref = view.getApplication().getSettings().getCustomRenderBooleanProperty(p.getAttrName()); - int icon = 0; - try { - Field f = R.drawable.class.getField("widget_" + p.getAttrName().toLowerCase()); - icon = f.getInt(null); - } catch(Exception e){ - } - MapWidgetRegInfo w = mapInfoControls.registerAppearanceWidget(icon, propertyName, "rend_"+p.getAttrName(), pref, categoryName); - w.setStateChangeListener(new Runnable() { - @Override - public void run() { - pref.set(!pref.get()); - app.getResourceManager().getRenderer().clearCache(); - view.refreshMap(true); - } - }); - - } else { - final CommonPreference pref = view.getApplication().getSettings().getCustomRenderProperty(p.getAttrName()); - int icon = 0; - try { - Field f = R.drawable.class.getField("widget_" + p.getAttrName().toLowerCase()); - icon = f.getInt(null); - } catch(Exception e){ - } - MapWidgetRegInfo w = mapInfoControls.registerAppearanceWidget(icon, propertyName, "rend_"+p.getAttrName(), pref, categoryName); - w.setStateChangeListener(new Runnable() { - @Override - public void run() { - Builder b = new AlertDialog.Builder(view.getContext()); - //test old descr as title - b.setTitle(propertyDescr); - int i = Arrays.asList(p.getPossibleValues()).indexOf(pref.get()); - b.setSingleChoiceItems(p.getPossibleValues(), i, new 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(); - } - }); - } - } - } - public void recreateControls(){ rightStack.clearAllViews(); @@ -408,7 +233,7 @@ public class MapInfoLayer extends OsmandMapLayer { mapInfoControls.populateStatusBar(statusBar); updateColorShadowsOfText(null); } - + public void createControls() { // 1. Create view groups and controls statusBar.setBackgroundDrawable(view.getResources().getDrawable(R.drawable.box_top)); @@ -482,9 +307,6 @@ public class MapInfoLayer extends OsmandMapLayer { s.add(ms.getCategory()); } } - if(OsmandPlugin.getEnabledPlugin(OsmandExtraSettings.class) == null){ - s.remove(ADDITIONAL_VECTOR_RENDERING_CATEGORY); - } return s; } diff --git a/OsmAnd/src/net/osmand/plus/views/mapwidgets/AppearanceWidgetsFactory.java b/OsmAnd/src/net/osmand/plus/views/mapwidgets/AppearanceWidgetsFactory.java new file mode 100644 index 0000000000..f88de1d92a --- /dev/null +++ b/OsmAnd/src/net/osmand/plus/views/mapwidgets/AppearanceWidgetsFactory.java @@ -0,0 +1,261 @@ +package net.osmand.plus.views.mapwidgets; + +import android.app.AlertDialog; +import android.content.DialogInterface; +import android.widget.Toast; +import net.osmand.access.AccessibleToast; +import net.osmand.plus.OsmandApplication; +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.MapInfoLayer; +import net.osmand.plus.views.OsmandMapTileView; +import net.osmand.render.RenderingRuleProperty; +import net.osmand.render.RenderingRulesStorage; + +import java.lang.reflect.Field; +import java.util.Arrays; +import java.util.Collection; +import java.util.List; + +public class AppearanceWidgetsFactory { + + public static AppearanceWidgetsFactory INSTANCE = new AppearanceWidgetsFactory(); + private String ADDITIONAL_VECTOR_RENDERING_CATEGORY; + public static boolean EXTRA_SETTINGS = true; + + + public void registerAppearanceWidgets(final MapActivity map, final MapInfoLayer mapInfoLayer, + final MapWidgetRegistry mapInfoControls) { + final OsmandMapTileView view = map.getMapView(); + final MapWidgetRegistry.MapWidgetRegInfo vectorRenderer = mapInfoControls.registerAppearanceWidget(R.drawable.widget_rendering_style, R.string.map_widget_renderer, + "renderer", view.getSettings().RENDERER); + final OsmandApplication app = view.getApplication(); + vectorRenderer.setStateChangeListener(new Runnable() { + @Override + public void run() { + AlertDialog.Builder bld = new AlertDialog.Builder(view.getContext()); + bld.setTitle(R.string.renderers); + Collection rendererNames = app.getRendererRegistry().getRendererNames(); + final String[] items = rendererNames.toArray(new String[rendererNames.size()]); + int i = -1; + for(int j = 0; j< items.length; j++) { + if(items[j].equals(app.getRendererRegistry().getCurrentSelectedRenderer().getName())) { + i = j; + break; + } + } + bld.setSingleChoiceItems(items, i, new DialogInterface.OnClickListener() { + + @Override + public void onClick(DialogInterface dialog, int which) { + String renderer = items[which]; + RenderingRulesStorage loaded = app.getRendererRegistry().getRenderer(renderer); + if (loaded != null) { + view.getSettings().RENDERER.set(renderer); + app.getRendererRegistry().setCurrentSelectedRender(loaded); + app.getResourceManager().getRenderer().clearCache(); + view.refreshMap(true); + } else { + AccessibleToast.makeText(app, R.string.renderer_load_exception, Toast.LENGTH_SHORT).show(); + } + if(EXTRA_SETTINGS) { + createCustomRenderingProperties(loaded, map, mapInfoLayer, mapInfoControls); + } + dialog.dismiss(); + } + }); + bld.show(); + } + }); + + final MapWidgetRegistry.MapWidgetRegInfo dayNight = mapInfoControls.registerAppearanceWidget(R.drawable.widget_day_night_mode, R.string.map_widget_day_night, + "dayNight", view.getSettings().DAYNIGHT_MODE); + dayNight.setStateChangeListener(new Runnable() { + @Override + public void run() { + AlertDialog.Builder bld = new AlertDialog.Builder(view.getContext()); + 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(map.getMyApplication()); + } + int i = view.getSettings().DAYNIGHT_MODE.get().ordinal(); + bld.setSingleChoiceItems(items, i, new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int which) { + view.getSettings().DAYNIGHT_MODE.set(OsmandSettings.DayNightMode.values()[which]); + app.getResourceManager().getRenderer().clearCache(); + view.refreshMap(true); + dialog.dismiss(); + } + }); + bld.show(); + } + }); + + final MapWidgetRegistry.MapWidgetRegInfo displayViewDirections = mapInfoControls.registerAppearanceWidget(R.drawable.widget_viewing_direction, R.string.map_widget_view_direction, + "viewDirection", view.getSettings().SHOW_VIEW_ANGLE); + displayViewDirections.setStateChangeListener(new Runnable() { + @Override + public void run() { + view.getSettings().SHOW_VIEW_ANGLE.set(!view.getSettings().SHOW_VIEW_ANGLE.get()); + map.getMapViewTrackingUtilities().updateSettings(); + } + }); + + if (EXTRA_SETTINGS) { + // previous extra settings + final OsmandSettings.OsmandPreference textSizePref = view.getSettings().MAP_TEXT_SIZE; + final MapWidgetRegistry.MapWidgetRegInfo textSize = mapInfoControls.registerAppearanceWidget(R.drawable.widget_text_size, R.string.map_text_size, + "text_size", textSizePref); + textSize.setStateChangeListener(new Runnable() { + @Override + public void run() { + final Float[] floatValues = new Float[] {0.6f, 0.8f, 1.0f, 1.2f, 1.5f, 1.75f, 2f}; + String[] entries = new String[floatValues.length]; + for (int i = 0; i < floatValues.length; i++) { + entries[i] = (int) (floatValues[i] * 100) +" %"; + } + AlertDialog.Builder b = new AlertDialog.Builder(view.getContext()); + b.setTitle(R.string.map_text_size); + int i = Arrays.binarySearch(floatValues, textSizePref.get()); + b.setSingleChoiceItems(entries, i, new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int which) { + textSizePref.set(floatValues[which]); + app.getResourceManager().getRenderer().clearCache(); + view.refreshMap(true); + dialog.dismiss(); + } + }); + b.show(); + } + }); + + final MapWidgetRegistry.MapWidgetRegInfo showRuler = mapInfoControls.registerAppearanceWidget(R.drawable.widget_ruler, R.string.map_widget_show_ruler, + "showRuler", view.getSettings().SHOW_RULER); + showRuler.setStateChangeListener(new Runnable() { + @Override + public void run() { + view.getSettings().SHOW_RULER.set(!view.getSettings().SHOW_RULER.get()); + view.refreshMap(); + } + }); + + final MapWidgetRegistry.MapWidgetRegInfo showDestinationArrow = mapInfoControls.registerAppearanceWidget(R.drawable.widget_show_destination_arrow, R.string.map_widget_show_destination_arrow, + "show_destination_arrow", view.getSettings().SHOW_DESTINATION_ARROW); + showDestinationArrow.setStateChangeListener(new Runnable() { + @Override + public void run() { + view.getSettings().SHOW_DESTINATION_ARROW.set(!view.getSettings().SHOW_DESTINATION_ARROW.get()); + mapInfoLayer.recreateControls(); + } + }); + + final MapWidgetRegistry.MapWidgetRegInfo transparent = mapInfoControls.registerAppearanceWidget(R.drawable.widget_transparent_skin, R.string.map_widget_transparent, + "transparent", view.getSettings().TRANSPARENT_MAP_THEME); + transparent.setStateChangeListener(new Runnable() { + @Override + public void run() { + view.getSettings().TRANSPARENT_MAP_THEME.set(!view.getSettings().TRANSPARENT_MAP_THEME.get()); + mapInfoLayer.recreateControls(); + } + }); + +// final OsmandSettings.OsmandPreference posPref = view.getSettings().POSITION_ON_MAP; +// final MapWidgetRegistry.MapWidgetRegInfo posMap = mapInfoControls.registerAppearanceWidget(R.drawable.widget_position_marker, R.string.position_on_map, +// "position_on_map", textSizePref); +// posMap.setStateChangeListener(new Runnable() { +// @Override +// public void run() { +// String[] entries = new String[] {map.getString(R.string.position_on_map_center), map.getString(R.string.position_on_map_bottom) }; +// final Integer[] vals = new Integer[] { OsmandSettings.CENTER_CONSTANT, OsmandSettings.BOTTOM_CONSTANT }; +// AlertDialog.Builder b = new AlertDialog.Builder(view.getContext()); +// int i = Arrays.binarySearch(vals, posPref.get()); +// b.setSingleChoiceItems(entries, i, new DialogInterface.OnClickListener() { +// @Override +// public void onClick(DialogInterface dialog, int which) { +// posPref.set(vals[which]); +// map.updateApplicationModeSettings(); +// view.refreshMap(true); +// dialog.dismiss(); +// } +// }); +// b.show(); +// } +// }); + + } + + RenderingRulesStorage renderer = app.getRendererRegistry().getCurrentSelectedRenderer(); + if(renderer != null && EXTRA_SETTINGS) { + createCustomRenderingProperties(renderer, map, mapInfoLayer, mapInfoControls); + } + } + + private void createCustomRenderingProperties(RenderingRulesStorage renderer, final MapActivity map, + final MapInfoLayer mapInfoLayer, final MapWidgetRegistry mapInfoControls) { + final OsmandMapTileView view = map.getMapView(); + if(ADDITIONAL_VECTOR_RENDERING_CATEGORY == null) { + ADDITIONAL_VECTOR_RENDERING_CATEGORY = map.getString(R.string.map_widget_vector_attributes); + } + String categoryName = ADDITIONAL_VECTOR_RENDERING_CATEGORY; + mapInfoControls.removeApperanceWidgets(categoryName); + final OsmandApplication app = view.getApplication(); + List customRules = renderer.PROPS.getCustomRules(); + for (final RenderingRuleProperty p : customRules) { + String propertyName = SettingsActivity.getStringPropertyName(view.getContext(), p.getAttrName(), p.getName()); + //test old descr as title + final String propertyDescr = SettingsActivity.getStringPropertyDescription(view.getContext(), p.getAttrName(), p.getName()); + if(p.isBoolean()) { + final OsmandSettings.CommonPreference pref = view.getApplication().getSettings().getCustomRenderBooleanProperty(p.getAttrName()); + int icon = 0; + try { + Field f = R.drawable.class.getField("widget_" + p.getAttrName().toLowerCase()); + icon = f.getInt(null); + } catch(Exception e){ + } + MapWidgetRegistry.MapWidgetRegInfo w = mapInfoControls.registerAppearanceWidget(icon, propertyName, "rend_"+p.getAttrName(), pref, categoryName); + w.setStateChangeListener(new Runnable() { + @Override + public void run() { + pref.set(!pref.get()); + app.getResourceManager().getRenderer().clearCache(); + view.refreshMap(true); + } + }); + + } else { + final OsmandSettings.CommonPreference pref = view.getApplication().getSettings().getCustomRenderProperty(p.getAttrName()); + int icon = 0; + try { + Field f = R.drawable.class.getField("widget_" + p.getAttrName().toLowerCase()); + icon = f.getInt(null); + } catch(Exception e){ + } + MapWidgetRegistry.MapWidgetRegInfo w = mapInfoControls.registerAppearanceWidget(icon, propertyName, "rend_"+p.getAttrName(), pref, categoryName); + w.setStateChangeListener(new Runnable() { + @Override + public void run() { + AlertDialog.Builder b = new AlertDialog.Builder(view.getContext()); + //test old descr as title + b.setTitle(propertyDescr); + int i = Arrays.asList(p.getPossibleValues()).indexOf(pref.get()); + b.setSingleChoiceItems(p.getPossibleValues(), 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(); + } + }); + } + } + } +}