From 0598389eb55b770f50c429d2c9e706f810b41cc3 Mon Sep 17 00:00:00 2001 From: Victor Shcherb Date: Sat, 3 Aug 2013 20:03:46 +0200 Subject: [PATCH] Do not close Define view dialog --- .../net/osmand/plus/ContextMenuAdapter.java | 4 +++ .../plus/activities/MapActivityLayers.java | 28 +++++++++++++------ .../osmand/plus/srtmplugin/SRTMPlugin.java | 1 - 3 files changed, 24 insertions(+), 9 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/ContextMenuAdapter.java b/OsmAnd/src/net/osmand/plus/ContextMenuAdapter.java index 02e773af2e..36b1d3ae49 100644 --- a/OsmAnd/src/net/osmand/plus/ContextMenuAdapter.java +++ b/OsmAnd/src/net/osmand/plus/ContextMenuAdapter.java @@ -53,6 +53,10 @@ public class ContextMenuAdapter { return selectedList.get(pos); } + public void setSelection(int pos, int s) { + selectedList.set(pos, s); + } + public int getImageId(int pos, boolean light) { if(!light || iconListLight.get(pos) == 0) { return iconList.get(pos); diff --git a/OsmAnd/src/net/osmand/plus/activities/MapActivityLayers.java b/OsmAnd/src/net/osmand/plus/activities/MapActivityLayers.java index af4d7160ec..c76325fd38 100644 --- a/OsmAnd/src/net/osmand/plus/activities/MapActivityLayers.java +++ b/OsmAnd/src/net/osmand/plus/activities/MapActivityLayers.java @@ -60,6 +60,8 @@ import android.content.Intent; import android.os.Build; 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.CompoundButton; @@ -310,7 +312,7 @@ public class MapActivityLayers { layout = R.layout.list_menu_item_native; } - ListAdapter listAdapter = new ArrayAdapter( + final ArrayAdapter listAdapter = new ArrayAdapter( activity, layout, R.id.title, adapter.getItemNames()){ @Override public View getView(final int position, View convertView, ViewGroup parent) { @@ -344,20 +346,30 @@ public class MapActivityLayers { } }; - b.setAdapter(listAdapter, new OnClickListener() { + OnClickListener onClickListener = new OnClickListener() { @Override public void onClick(DialogInterface dialog, int position) { - if(adapter.getSelection(position) >= 0) { - listener.onClick(position, !(adapter.getSelection(position) > 0)); - } else { - listener.onClick(position, adapter.getSelection(position) > 0); - } } - }); + }; + b.setAdapter(listAdapter, onClickListener); + b.setPositiveButton(R.string.default_buttons_ok, null); final AlertDialog dlg = b.create(); listener.setDialog(dlg); dlg.setCanceledOnTouchOutside(true); + dlg.getListView().setOnItemClickListener(new OnItemClickListener() { + + @Override + public void onItemClick(AdapterView parent, View view, int position, long id) { + if(adapter.getSelection(position) >= 0) { + listener.onClick(position, !(adapter.getSelection(position) > 0)); + adapter.setSelection(position, adapter.getSelection(position) > 0 ? 0 : 1); + listAdapter.notifyDataSetInvalidated(); + } else { + listener.onClick(position, adapter.getSelection(position) > 0); + } + } + }); dlg.show(); } diff --git a/OsmAnd/src/net/osmand/plus/srtmplugin/SRTMPlugin.java b/OsmAnd/src/net/osmand/plus/srtmplugin/SRTMPlugin.java index 697facf5f8..9eb5b6ead2 100644 --- a/OsmAnd/src/net/osmand/plus/srtmplugin/SRTMPlugin.java +++ b/OsmAnd/src/net/osmand/plus/srtmplugin/SRTMPlugin.java @@ -96,7 +96,6 @@ public class SRTMPlugin extends OsmandPlugin { @Override public void onContextMenuClick(int itemId, int pos, boolean isChecked, DialogInterface dialog) { if (itemId == R.string.layer_hillshade) { - dialog.dismiss(); HILLSHADE.set(!HILLSHADE.get()); updateLayers(mapView, mapActivity); }