diff --git a/OsmAnd/res/layout/editing_tile_source.xml b/OsmAnd/res/layout/editing_tile_source.xml index 139843555c..e6fd637705 100644 --- a/OsmAnd/res/layout/editing_tile_source.xml +++ b/OsmAnd/res/layout/editing_tile_source.xml @@ -6,46 +6,57 @@ + android:layout_marginLeft="@dimen/text_margin_small" + android:layout_marginRight="@dimen/text_margin_small"/> - diff --git a/OsmAnd/src/net/osmand/plus/DialogListItemAdapter.java b/OsmAnd/src/net/osmand/plus/DialogListItemAdapter.java index 5decad066f..dd45f6ba67 100644 --- a/OsmAnd/src/net/osmand/plus/DialogListItemAdapter.java +++ b/OsmAnd/src/net/osmand/plus/DialogListItemAdapter.java @@ -27,14 +27,14 @@ public class DialogListItemAdapter extends BaseAdapter { public static DialogListItemAdapter createSingleChoiceAdapter(String[] mData, boolean nightMode, int selected, OsmandApplication app, @ColorInt int compoundButtonColor, int themeRes, final View.OnClickListener listener) { - return new DialogListItemAdapter(mData, selected, null, nightMode, app, - compoundButtonColor, themeRes, listener, false); + + return new DialogListItemAdapter(mData, selected, null, nightMode, app, compoundButtonColor, themeRes, listener, false); } public static DialogListItemAdapter createMultiChoiceAdapter(String[] mData, boolean nightMode, boolean checkedItems[], OsmandApplication app, @ColorInt int compoundButtonColor, int themeRes, final View.OnClickListener listener) { - return new DialogListItemAdapter(mData, INVALID_ID, checkedItems, nightMode, app, - compoundButtonColor, themeRes, listener, true); + + return new DialogListItemAdapter(mData, INVALID_ID, checkedItems, nightMode, app, compoundButtonColor, themeRes, listener, true); } private DialogListItemAdapter(String[] mData, int selected, boolean[] checkedItems, boolean nightMode, OsmandApplication app, diff --git a/OsmAnd/src/net/osmand/plus/activities/MapActivityLayers.java b/OsmAnd/src/net/osmand/plus/activities/MapActivityLayers.java index 6bddb925f2..2964149738 100644 --- a/OsmAnd/src/net/osmand/plus/activities/MapActivityLayers.java +++ b/OsmAnd/src/net/osmand/plus/activities/MapActivityLayers.java @@ -4,6 +4,7 @@ package net.osmand.plus.activities; import android.content.DialogInterface; import android.graphics.drawable.Drawable; import android.support.annotation.Nullable; +import android.support.v4.content.ContextCompat; import android.support.v7.app.AlertDialog; import android.support.v7.view.ContextThemeWrapper; import android.view.View; @@ -22,6 +23,7 @@ import net.osmand.plus.ContextMenuAdapter; import net.osmand.plus.ContextMenuItem; import net.osmand.GPXUtilities.GPXFile; import net.osmand.GPXUtilities.WptPt; +import net.osmand.plus.DialogListItemAdapter; import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandPlugin; import net.osmand.plus.OsmandSettings; @@ -493,80 +495,85 @@ public class MapActivityLayers { items[i++] = entry.getValue(); } - builder.setSingleChoiceItems(items, selectedItem, new DialogInterface.OnClickListener() { - @Override - public void onClick(DialogInterface dialog, int which) { - String layerKey = entriesMapList.get(which).getKey(); - switch (layerKey) { - case layerOsmVector: - settings.MAP_ONLINE_DATA.set(false); - updateMapSource(mapView, null); - updateItem(it, adapter, null); - break; - case layerEditInstall: - OsmandRasterMapsPlugin.defineNewEditLayer(activity, new ResultMatcher() { + OsmandApplication app = getApplication(); + boolean nightMode = isNightMode(app); + int themeRes = getThemeRes(app); + int selectedModeColor = ContextCompat.getColor(app, settings.getApplicationMode().getIconColorInfo().getColor(nightMode)); + DialogListItemAdapter dialogAdapter = DialogListItemAdapter.createSingleChoiceAdapter( + items, nightMode, selectedItem, app, selectedModeColor, themeRes, new View.OnClickListener() { + @Override + public void onClick(View v) { + int which = (int) v.getTag(); + String layerKey = entriesMapList.get(which).getKey(); + switch (layerKey) { + case layerOsmVector: + settings.MAP_ONLINE_DATA.set(false); + updateMapSource(mapView, null); + updateItem(it, adapter, null); + break; + case layerEditInstall: + OsmandRasterMapsPlugin.defineNewEditLayer(activity, new ResultMatcher() { - @Override - public boolean publish(TileSourceTemplate object) { - settings.MAP_TILE_SOURCES.set(object.getName()); - settings.MAP_ONLINE_DATA.set(true); - if(it != null) { - it.setDescription(object.getName()); - } - updateMapSource(mapView, settings.MAP_TILE_SOURCES); - return true; - } - - @Override - public boolean isCancelled() { - return false; - } - - }); - break; - case layerInstallMore: - OsmandRasterMapsPlugin.installMapLayers(activity, new ResultMatcher() { - TileSourceTemplate template = null; - int count = 0; - - @Override - public boolean publish(TileSourceTemplate object) { - if (object == null) { - if (count == 1) { - settings.MAP_TILE_SOURCES.set(template.getName()); + @Override + public boolean publish(TileSourceTemplate object) { + settings.MAP_TILE_SOURCES.set(object.getName()); settings.MAP_ONLINE_DATA.set(true); - updateItem(it, adapter, template.getName()); + if(it != null) { + it.setDescription(object.getName()); + } updateMapSource(mapView, settings.MAP_TILE_SOURCES); - } else { - selectMapLayer(mapView, it, adapter); + return true; } - } else { - count++; - template = object; - } - return false; - } - @Override - public boolean isCancelled() { - return false; - } - }); - break; - default: - settings.MAP_TILE_SOURCES.set(layerKey); - settings.MAP_ONLINE_DATA.set(true); - updateItem(it, adapter, layerKey); - updateMapSource(mapView, settings.MAP_TILE_SOURCES); - break; + @Override + public boolean isCancelled() { + return false; + } + + }); + break; + case layerInstallMore: + OsmandRasterMapsPlugin.installMapLayers(activity, new ResultMatcher() { + TileSourceTemplate template = null; + int count = 0; + + @Override + public boolean publish(TileSourceTemplate object) { + if (object == null) { + if (count == 1) { + settings.MAP_TILE_SOURCES.set(template.getName()); + settings.MAP_ONLINE_DATA.set(true); + updateItem(it, adapter, template.getName()); + updateMapSource(mapView, settings.MAP_TILE_SOURCES); + } else { + selectMapLayer(mapView, it, adapter); + } + } else { + count++; + template = object; + } + return false; + } + + @Override + public boolean isCancelled() { + return false; + } + }); + break; + default: + settings.MAP_TILE_SOURCES.set(layerKey); + settings.MAP_ONLINE_DATA.set(true); + updateItem(it, adapter, layerKey); + updateMapSource(mapView, settings.MAP_TILE_SOURCES); + break; + } + } } - - dialog.dismiss(); - } - - }); + ); + builder.setAdapter(dialogAdapter, null); builder.setNegativeButton(R.string.shared_string_dismiss, null); - builder.show(); + dialogAdapter.setDialog(builder.show()); } private void updateItem(@Nullable ContextMenuItem item, diff --git a/OsmAnd/src/net/osmand/plus/activities/actions/OsmAndAction.java b/OsmAnd/src/net/osmand/plus/activities/actions/OsmAndAction.java index b0d4381b33..4f968c28f8 100644 --- a/OsmAnd/src/net/osmand/plus/activities/actions/OsmAndAction.java +++ b/OsmAnd/src/net/osmand/plus/activities/actions/OsmAndAction.java @@ -2,6 +2,7 @@ package net.osmand.plus.activities.actions; 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.views.OsmandMapTileView; import android.app.Activity; @@ -55,4 +56,12 @@ public class OsmAndAction { public void showDialog() { mapActivity.showDialog(getDialogID()); } + + public boolean isNightMode() { + return mapActivity.getMyApplication().getDaynightHelper().isNightModeForMapControls(); + } + + public int getThemeRes() { + return isNightMode() ? R.style.OsmandDarkTheme : R.style.OsmandLightTheme; + } } diff --git a/OsmAnd/src/net/osmand/plus/activities/actions/StartGPSStatus.java b/OsmAnd/src/net/osmand/plus/activities/actions/StartGPSStatus.java index 55f3ae0cf8..ab67ad0fbc 100644 --- a/OsmAnd/src/net/osmand/plus/activities/actions/StartGPSStatus.java +++ b/OsmAnd/src/net/osmand/plus/activities/actions/StartGPSStatus.java @@ -9,13 +9,14 @@ import android.content.pm.PackageManager; import android.content.pm.PackageManager.NameNotFoundException; import android.net.Uri; import android.os.Bundle; +import android.support.v4.content.ContextCompat; import android.support.v7.app.AlertDialog; +import android.support.v7.widget.AppCompatCheckBox; import android.view.View; import android.view.ViewGroup; import android.widget.AdapterView; import android.widget.AdapterView.OnItemClickListener; import android.widget.ArrayAdapter; -import android.widget.CheckBox; import android.widget.LinearLayout; import android.widget.LinearLayout.LayoutParams; import android.widget.ListView; @@ -24,6 +25,7 @@ import android.widget.Toast; import net.osmand.AndroidUtils; import net.osmand.plus.R; +import net.osmand.plus.UiUtilities; import net.osmand.plus.Version; import net.osmand.plus.activities.MapActivity; @@ -111,11 +113,16 @@ public class StartGPSStatus extends OsmAndAction { final int dp12 = AndroidUtils.dpToPx(mapActivity, 12f); final int dp8 = AndroidUtils.dpToPx(mapActivity, 8f); lv.setPadding(0, dp8, 0, dp8); - final CheckBox cb = new CheckBox(activity); + final AppCompatCheckBox cb = new AppCompatCheckBox(activity); cb.setText(R.string.shared_string_remember_my_choice); LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT); lp.setMargins(dp24, dp8, dp8, dp24); cb.setLayoutParams(lp); + cb.setPadding(dp8, 0, 0, 0); + int textColorPrimary = ContextCompat.getColor(activity, isNightMode() ? R.color.text_color_primary_dark : R.color.text_color_primary_light); + int selectedModeColor = ContextCompat.getColor(activity, getSettings().getApplicationMode().getIconColorInfo().getColor(isNightMode())); + cb.setTextColor(textColorPrimary); + UiUtilities.setupCompoundButton(isNightMode(), selectedModeColor, cb); final int layout = R.layout.list_menu_item_native; final ArrayAdapter adapter = new ArrayAdapter(mapActivity, layout, GpsStatusApps.values()) { diff --git a/OsmAnd/src/net/osmand/plus/osmedit/OsmNotesMenu.java b/OsmAnd/src/net/osmand/plus/osmedit/OsmNotesMenu.java index 80f00f943d..5493d78ab4 100644 --- a/OsmAnd/src/net/osmand/plus/osmedit/OsmNotesMenu.java +++ b/OsmAnd/src/net/osmand/plus/osmedit/OsmNotesMenu.java @@ -1,12 +1,16 @@ package net.osmand.plus.osmedit; -import android.app.AlertDialog; import android.content.Context; -import android.content.DialogInterface; +import android.support.v4.content.ContextCompat; +import android.support.v7.app.AlertDialog; +import android.view.ContextThemeWrapper; +import android.view.View; import android.widget.ArrayAdapter; import net.osmand.plus.ContextMenuAdapter; import net.osmand.plus.ContextMenuItem; +import net.osmand.plus.DialogListItemAdapter; +import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandPlugin; import net.osmand.plus.OsmandSettings; import net.osmand.plus.OsmandSettings.CommonPreference; @@ -31,13 +35,18 @@ public class OsmNotesMenu { } private static void createLayersItems(final ContextMenuAdapter adapter, final MapActivity mapActivity) { - final OsmandSettings settings = mapActivity.getMyApplication().getSettings(); + final OsmandApplication app = mapActivity.getMyApplication(); + final OsmandSettings settings = app.getSettings(); final OsmEditingPlugin plugin = OsmandPlugin.getPlugin(OsmEditingPlugin.class); if (plugin == null) { return; } + final boolean nightMode = isNightMode(app); + final int themeRes = getThemeRes(app); + final int selectedModeColor = ContextCompat.getColor(app, settings.getApplicationMode().getIconColorInfo().getColor(nightMode)); + final int osmNotesStringId = R.string.layer_osm_bugs; final int showZoomLevelStringId = R.string.show_from_zoom_level; final int showClosedNotesStringId = R.string.show_closed_notes; @@ -60,11 +69,11 @@ public class OsmNotesMenu { } else if (itemId == showZoomLevelStringId) { int checked = Arrays.asList(zoomIntValues).indexOf(showOsmBugsZoomPref.get()); - new AlertDialog.Builder(mapActivity) - .setTitle(R.string.show_from_zoom_level) - .setSingleChoiceItems(zoomStrings, checked, new DialogInterface.OnClickListener() { + DialogListItemAdapter dialogAdapter = DialogListItemAdapter.createSingleChoiceAdapter( + zoomStrings, nightMode, checked, app, selectedModeColor, themeRes, new View.OnClickListener() { @Override - public void onClick(DialogInterface dialog, int which) { + public void onClick(View v) { + int which = (int) v.getTag(); showOsmBugsZoomPref.set(zoomIntValues[which]); ContextMenuItem item = adapter.getItem(position); if (item != null) { @@ -72,11 +81,14 @@ public class OsmNotesMenu { adapter.notifyDataSetChanged(); } mapActivity.refreshMap(); - dialog.dismiss(); } - }) - .setNegativeButton(R.string.shared_string_dismiss, null) - .show(); + } + ); + AlertDialog.Builder b = new AlertDialog.Builder(new ContextThemeWrapper(mapActivity, themeRes)) + .setTitle(R.string.show_from_zoom_level) + .setAdapter(dialogAdapter, null) + .setNegativeButton(R.string.shared_string_dismiss, null); + dialogAdapter.setDialog(b.show()); } else if (itemId == showClosedNotesStringId) { showClosedOsmBugsPref.set(isChecked); mapActivity.refreshMap(); @@ -86,7 +98,6 @@ public class OsmNotesMenu { }; boolean showOsmBugs = showOsmBugsPref.get(); - boolean nightMode = mapActivity.getMyApplication().getDaynightHelper().isNightModeForMapControls(); int toggleIconColorId; if (showOsmBugs) { toggleIconColorId = nightMode ? R.color.active_color_primary_dark : R.color.active_color_primary_light; @@ -135,4 +146,15 @@ public class OsmNotesMenu { } return res; } + + public static boolean isNightMode(OsmandApplication app) { + if (app == null) { + return false; + } + return app.getDaynightHelper().isNightModeForMapControls(); + } + + public static int getThemeRes(OsmandApplication app) { + return isNightMode(app) ? R.style.OsmandDarkTheme : R.style.OsmandLightTheme; + } } diff --git a/OsmAnd/src/net/osmand/plus/rastermaps/OsmandRasterMapsPlugin.java b/OsmAnd/src/net/osmand/plus/rastermaps/OsmandRasterMapsPlugin.java index 6059350314..2cff5222d4 100644 --- a/OsmAnd/src/net/osmand/plus/rastermaps/OsmandRasterMapsPlugin.java +++ b/OsmAnd/src/net/osmand/plus/rastermaps/OsmandRasterMapsPlugin.java @@ -5,7 +5,9 @@ import android.content.DialogInterface; import android.os.AsyncTask; import android.support.annotation.NonNull; import android.support.annotation.Nullable; +import android.support.v4.content.ContextCompat; import android.support.v7.app.AlertDialog; +import android.support.v7.widget.AppCompatCheckBox; import android.view.ContextThemeWrapper; import android.view.View; import android.widget.AdapterView; @@ -26,6 +28,7 @@ import net.osmand.map.TileSourceManager.TileSourceTemplate; import net.osmand.plus.ContextMenuAdapter; import net.osmand.plus.ContextMenuAdapter.ItemClickListener; import net.osmand.plus.ContextMenuItem; +import net.osmand.plus.DialogListItemAdapter; import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandPlugin; import net.osmand.plus.OsmandSettings; @@ -433,16 +436,22 @@ public class OsmandRasterMapsPlugin extends OsmandPlugin { names[i] = downloaded.get(i).getName(); } final boolean[] selected = new boolean[downloaded.size()]; - builder.setMultiChoiceItems(names, selected, new DialogInterface.OnMultiChoiceClickListener() { - - @Override - public void onClick(DialogInterface dialog, int which, boolean isChecked) { - selected[which] = isChecked; - if (entriesMap.containsKey(downloaded.get(which).getName()) && isChecked) { - Toast.makeText(activity, R.string.tile_source_already_installed, Toast.LENGTH_SHORT).show(); + boolean nightMode = isNightMode(activity, app); + int themeResId = getThemeRes(activity, app); + int selectedProfileColor = ContextCompat.getColor(app, app.getSettings().getApplicationMode().getIconColorInfo().getColor(nightMode)); + DialogListItemAdapter dialogAdapter = DialogListItemAdapter.createMultiChoiceAdapter(names, nightMode, selected, app, + selectedProfileColor, themeResId, new View.OnClickListener() { + @Override + public void onClick(View v) { + int which = (int) v.getTag(); + selected[which] = !selected[which]; + if (entriesMap.containsKey(downloaded.get(which).getName()) && selected[which]) { + Toast.makeText(activity, R.string.tile_source_already_installed, Toast.LENGTH_SHORT).show(); + } + } } - } - }); + ); + builder.setAdapter(dialogAdapter, null); builder.setNegativeButton(R.string.shared_string_cancel, null); builder.setTitle(R.string.select_tile_source_to_install); builder.setPositiveButton(R.string.shared_string_apply, new DialogInterface.OnClickListener() { @@ -467,8 +476,7 @@ public class OsmandRasterMapsPlugin extends OsmandPlugin { } } }); - - builder.show(); + dialogAdapter.setDialog(builder.show()); } }; t.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); @@ -478,6 +486,9 @@ public class OsmandRasterMapsPlugin extends OsmandPlugin { final OsmandApplication app = (OsmandApplication) activity.getApplication(); final OsmandSettings settings = app.getSettings(); final Map entriesMap = settings.getTileSourceEntries(false); + boolean nightMode = isNightMode(activity, app); + final int dp8 = AndroidUtils.dpToPx(app, 8f); + int textColorPrimary = ContextCompat.getColor(app, nightMode ? R.color.text_color_primary_dark : R.color.text_color_primary_light); TileSourceTemplate ts = new TileSourceTemplate("NewMapnik", "http://mapnik.osmand.net/{0}/{1}/{2}.png", "png", 17, 5, 256, 16, 32000); final TileSourceTemplate[] result = new TileSourceTemplate[]{ts}; @@ -489,7 +500,10 @@ public class OsmandRasterMapsPlugin extends OsmandPlugin { final EditText minZoom = (EditText) view.findViewById(R.id.MinZoom); final EditText maxZoom = (EditText) view.findViewById(R.id.MaxZoom); final EditText expire = (EditText) view.findViewById(R.id.ExpirationTime); - final CheckBox elliptic = (CheckBox) view.findViewById(R.id.EllipticMercator); + final AppCompatCheckBox elliptic = (AppCompatCheckBox) view.findViewById(R.id.EllipticMercator); + elliptic.setTextColor(textColorPrimary); + elliptic.setPadding(dp8, 0, 0, 0); + UiUtilities.setupCompoundButton(app, elliptic, nightMode, true); updateTileSourceEditView(ts, name, urlToLoad, minZoom, maxZoom, expire, elliptic); final ArrayList templates = new ArrayList<>(entriesMap.keySet()); diff --git a/OsmAnd/src/net/osmand/plus/routepreparationmenu/RoutingOptionsHelper.java b/OsmAnd/src/net/osmand/plus/routepreparationmenu/RoutingOptionsHelper.java index 5c90b98de2..9dad48bad4 100644 --- a/OsmAnd/src/net/osmand/plus/routepreparationmenu/RoutingOptionsHelper.java +++ b/OsmAnd/src/net/osmand/plus/routepreparationmenu/RoutingOptionsHelper.java @@ -4,14 +4,16 @@ import android.app.Activity; import android.content.Context; import android.content.DialogInterface; import android.content.Intent; +import android.os.Build; import android.support.annotation.DrawableRes; import android.support.annotation.NonNull; +import android.support.v4.content.ContextCompat; import android.support.v7.app.AlertDialog; +import android.support.v7.widget.AppCompatCheckedTextView; import android.util.TypedValue; import android.view.View; import android.view.ViewGroup; import android.widget.ArrayAdapter; -import android.widget.TextView; import net.osmand.CallbackWithObject; import net.osmand.GPXUtilities; @@ -21,6 +23,7 @@ import net.osmand.data.LatLon; import net.osmand.plus.ApplicationMode; import net.osmand.plus.ContextMenuAdapter; import net.osmand.plus.ContextMenuItem; +import net.osmand.plus.DialogListItemAdapter; import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandSettings; import net.osmand.plus.R; @@ -144,26 +147,33 @@ public class RoutingOptionsHelper { entries[k] = mapActivity.getResources().getString(R.string.install_more); adapter.addItem(itemBuilder.setTitle(entries[k]).createItem()); - AlertDialog.Builder bld = new AlertDialog.Builder(mapActivity); - bld.setSingleChoiceItems(entries, selected, new DialogInterface.OnClickListener() { - - @Override - public void onClick(DialogInterface dialog, int which) { - String value = entrieValues[which]; - if (MORE_VALUE.equals(value)) { - final Intent intent = new Intent(mapActivity, DownloadActivity.class); - intent.putExtra(DownloadActivity.TAB_TO_OPEN, DownloadActivity.DOWNLOAD_TAB); - intent.putExtra(DownloadActivity.FILTER_CAT, DownloadActivityType.VOICE_FILE.getTag()); - mapActivity.startActivity(intent); - } else { - if (callback != null) { - callback.processResult(value); + boolean nightMode = isNightMode(app); + Context themedContext = UiUtilities.getThemedContext(mapActivity, nightMode); + int themeRes = getThemeRes(app); + ApplicationMode selectedAppMode = app.getRoutingHelper().getAppMode(); + int selectedModeColor = ContextCompat.getColor(app, selectedAppMode.getIconColorInfo().getColor(nightMode)); + DialogListItemAdapter dialogAdapter = DialogListItemAdapter.createSingleChoiceAdapter( + entries, nightMode, selected, app, selectedModeColor, themeRes, new View.OnClickListener() { + @Override + public void onClick(View v) { + int which = (int) v.getTag(); + String value = entrieValues[which]; + if (MORE_VALUE.equals(value)) { + final Intent intent = new Intent(mapActivity, DownloadActivity.class); + intent.putExtra(DownloadActivity.TAB_TO_OPEN, DownloadActivity.DOWNLOAD_TAB); + intent.putExtra(DownloadActivity.FILTER_CAT, DownloadActivityType.VOICE_FILE.getTag()); + mapActivity.startActivity(intent); + } else { + if (callback != null) { + callback.processResult(value); + } + } } } - dialog.dismiss(); - } - }); - bld.show(); + ); + AlertDialog.Builder bld = new AlertDialog.Builder(themedContext); + bld.setAdapter(dialogAdapter, null); + dialogAdapter.setDialog(bld.show()); } public String getVoiceProviderName(Context ctx, String value) { @@ -315,8 +325,10 @@ public class RoutingOptionsHelper { selectedIndex = 0; } - final boolean nightMode = app.getDaynightHelper().isNightModeForMapControls(); + final boolean nightMode = isNightMode(app); Context themedContext = UiUtilities.getThemedContext(mapActivity, nightMode); + ApplicationMode selectedAppMode = app.getRoutingHelper().getAppMode(); + final int selectedModeColor = ContextCompat.getColor(app, selectedAppMode.getIconColorInfo().getColor(nightMode)); AlertDialog.Builder builder = new AlertDialog.Builder(themedContext); final int layout = R.layout.list_menu_item_native_singlechoice; @@ -330,9 +342,12 @@ public class RoutingOptionsHelper { v = UiUtilities.getInflater(mapActivity, nightMode).inflate(layout, parent, false); } final ContextMenuItem item = adapter.getItem(position); - TextView tv = (TextView) v.findViewById(R.id.text1); + AppCompatCheckedTextView tv = (AppCompatCheckedTextView) v.findViewById(R.id.text1); tv.setText(item.getTitle()); tv.setTextSize(TypedValue.COMPLEX_UNIT_SP, 16f); + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { + UiUtilities.setupCompoundButtonDrawable(app, nightMode, selectedModeColor, tv.getCheckMarkDrawable()); + } return v; } @@ -590,6 +605,17 @@ public class RoutingOptionsHelper { return parameter; } + + public boolean isNightMode(OsmandApplication app) { + if (app == null) { + return false; + } + return app.getDaynightHelper().isNightModeForMapControls(); + } + + public int getThemeRes(OsmandApplication app) { + return isNightMode(app) ? R.style.OsmandDarkTheme : R.style.OsmandLightTheme; + } public static class LocalRoutingParameter { diff --git a/OsmAnd/src/net/osmand/plus/srtmplugin/ContourLinesMenu.java b/OsmAnd/src/net/osmand/plus/srtmplugin/ContourLinesMenu.java index 35b5e34026..0b43b26b20 100644 --- a/OsmAnd/src/net/osmand/plus/srtmplugin/ContourLinesMenu.java +++ b/OsmAnd/src/net/osmand/plus/srtmplugin/ContourLinesMenu.java @@ -37,7 +37,7 @@ public class ContourLinesMenu { if (plugin != null && !plugin.isActive() && !plugin.needsInstallation()) { OsmandPlugin.enablePlugin(mapActivity, mapActivity.getMyApplication(), plugin, true); } - boolean nightMode = mapActivity.getMyApplication().getDaynightHelper().isNightModeForMapControls(); + boolean nightMode = isNightMode(mapActivity.getMyApplication()); ContextMenuAdapter adapter = new ContextMenuAdapter(); adapter.setDefaultLayoutId(R.layout.list_item_icon_and_menu); adapter.setProfileDependent(true); @@ -329,6 +329,13 @@ public class ContourLinesMenu { } } } + + public static boolean isNightMode(OsmandApplication app) { + if (app == null) { + return false; + } + return app.getDaynightHelper().isNightModeForMapControls(); + } public static void closeDashboard(MapActivity mapActivity) { mapActivity.getDashboard().hideDashboard(false); diff --git a/OsmAnd/src/net/osmand/plus/srtmplugin/SRTMPlugin.java b/OsmAnd/src/net/osmand/plus/srtmplugin/SRTMPlugin.java index 342182f813..5998417267 100644 --- a/OsmAnd/src/net/osmand/plus/srtmplugin/SRTMPlugin.java +++ b/OsmAnd/src/net/osmand/plus/srtmplugin/SRTMPlugin.java @@ -4,7 +4,9 @@ import android.app.Activity; import android.content.Context; import android.content.DialogInterface; import android.support.annotation.NonNull; +import android.support.v4.content.ContextCompat; import android.support.v7.app.AlertDialog; +import android.view.ContextThemeWrapper; import android.view.View; import android.widget.ArrayAdapter; @@ -13,6 +15,7 @@ import net.osmand.data.LatLon; import net.osmand.plus.ApplicationMode; import net.osmand.plus.ContextMenuAdapter; import net.osmand.plus.ContextMenuItem; +import net.osmand.plus.DialogListItemAdapter; import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandPlugin; import net.osmand.plus.OsmandSettings; @@ -359,7 +362,9 @@ public class SRTMPlugin extends OsmandPlugin { final Runnable callback) { final String propertyDescr = SettingsActivity.getStringPropertyDescription(activity, p.getAttrName(), p.getName()); - AlertDialog.Builder b = new AlertDialog.Builder(activity); + boolean nightMode = isNightMode(activity, app); + int themeRes = getThemeRes(activity, app); + AlertDialog.Builder b = new AlertDialog.Builder(new ContextThemeWrapper(activity, themeRes)); b.setTitle(propertyDescr); List possibleValuesList = new ArrayList<>(Arrays.asList(p.getPossibleValues())); @@ -382,18 +387,22 @@ public class SRTMPlugin extends OsmandPlugin { possibleValues[j]); } - b.setSingleChoiceItems(possibleValuesString, i, new DialogInterface.OnClickListener() { - @Override - public void onClick(DialogInterface dialog, int which) { - if (which == 0) { - pref.set(""); - } else { - pref.set(possibleValues[which - 1]); + int selectedModeColor = ContextCompat.getColor(app, settings.getApplicationMode().getIconColorInfo().getColor(nightMode)); + DialogListItemAdapter dialogAdapter = DialogListItemAdapter.createSingleChoiceAdapter( + possibleValuesString, nightMode, i, app, selectedModeColor, themeRes, new View.OnClickListener() { + + @Override + public void onClick(View v) { + int which = (int) v.getTag(); + if (which == 0) { + pref.set(""); + } else { + pref.set(possibleValues[which - 1]); + } + refreshMapComplete(activity); + } } - refreshMapComplete(activity); - dialog.dismiss(); - } - }); + ); b.setNegativeButton(R.string.shared_string_dismiss, null); b.setOnDismissListener(new DialogInterface.OnDismissListener() { @Override @@ -403,7 +412,8 @@ public class SRTMPlugin extends OsmandPlugin { } } }); - b.show(); + b.setAdapter(dialogAdapter, null); + dialogAdapter.setDialog(b.show()); } @Override @@ -420,4 +430,15 @@ public class SRTMPlugin extends OsmandPlugin { activity.updateMapSettings(); activity.getMapView().refreshMap(true); } + + private static boolean isNightMode(Activity activity, OsmandApplication app) { + if (activity == null || app == null) { + return false; + } + return activity instanceof MapActivity ? app.getDaynightHelper().isNightModeForMapControls() : !app.getSettings().isLightContent(); + } + + private static int getThemeRes(Activity activity, OsmandApplication app) { + return isNightMode(activity, app) ? R.style.OsmandDarkTheme : R.style.OsmandLightTheme; + } }