From 9cbfb9aba80c552a2c1a116f481478f26b43ae88 Mon Sep 17 00:00:00 2001 From: Victor Shcherb Date: Tue, 16 Jul 2013 23:52:54 +0200 Subject: [PATCH] Add selection dialog --- OsmAnd/res/layout/configuration_dialog.xml | 15 +++++++ .../plus/activities/MapActivityActions.java | 7 ++-- .../plus/activities/SettingsBaseActivity.java | 2 +- .../net/osmand/plus/views/MapInfoLayer.java | 42 ++++++++++++++----- 4 files changed, 52 insertions(+), 14 deletions(-) create mode 100644 OsmAnd/res/layout/configuration_dialog.xml diff --git a/OsmAnd/res/layout/configuration_dialog.xml b/OsmAnd/res/layout/configuration_dialog.xml new file mode 100644 index 0000000000..cc035cf5ac --- /dev/null +++ b/OsmAnd/res/layout/configuration_dialog.xml @@ -0,0 +1,15 @@ + + + + + + + \ No newline at end of file diff --git a/OsmAnd/src/net/osmand/plus/activities/MapActivityActions.java b/OsmAnd/src/net/osmand/plus/activities/MapActivityActions.java index 0555e38c3f..00a6319a28 100644 --- a/OsmAnd/src/net/osmand/plus/activities/MapActivityActions.java +++ b/OsmAnd/src/net/osmand/plus/activities/MapActivityActions.java @@ -67,6 +67,7 @@ import android.text.Html; import android.util.FloatMath; import android.view.View; import android.view.View.OnClickListener; +import android.view.ViewGroup; import android.widget.ArrayAdapter; import android.widget.AutoCompleteTextView; import android.widget.Button; @@ -465,9 +466,9 @@ public class MapActivityActions implements DialogProvider { } - public static View showActivityActionsDialog(Activity a, final Set selected, boolean showDefault, - final View.OnClickListener onClickListener) { - View view = a.getLayoutInflater().inflate(R.layout.mode_toggles, null); + public static View prepareAppModeView(Activity a, final Set selected, boolean showDefault, + ViewGroup parent, final View.OnClickListener onClickListener) { + View view = a.getLayoutInflater().inflate(R.layout.mode_toggles, parent); OsmandSettings settings = ((OsmandApplication) a.getApplication()).getSettings(); boolean lc = settings.isLightContentMenu(); final ToggleButton[] buttons = new ToggleButton[ApplicationMode.values().length]; diff --git a/OsmAnd/src/net/osmand/plus/activities/SettingsBaseActivity.java b/OsmAnd/src/net/osmand/plus/activities/SettingsBaseActivity.java index a60359b123..b4bf35dbd9 100644 --- a/OsmAnd/src/net/osmand/plus/activities/SettingsBaseActivity.java +++ b/OsmAnd/src/net/osmand/plus/activities/SettingsBaseActivity.java @@ -305,7 +305,7 @@ public abstract class SettingsBaseActivity extends SherlockPreferenceActivity im protected void profileDialog() { Builder b = new AlertDialog.Builder(this); final Set selected = new LinkedHashSet(); - View v = MapActivityActions.showActivityActionsDialog(this, selected, false, + View v = MapActivityActions.prepareAppModeView(this, selected, false, null, new View.OnClickListener() { @Override public void onClick(View v) { diff --git a/OsmAnd/src/net/osmand/plus/views/MapInfoLayer.java b/OsmAnd/src/net/osmand/plus/views/MapInfoLayer.java index 70e8a93a1e..e0c0fb1197 100644 --- a/OsmAnd/src/net/osmand/plus/views/MapInfoLayer.java +++ b/OsmAnd/src/net/osmand/plus/views/MapInfoLayer.java @@ -18,6 +18,7 @@ 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; @@ -53,9 +54,12 @@ import android.view.View; import android.view.View.MeasureSpec; import android.view.ViewGroup; import android.view.WindowManager; +import android.widget.AdapterView; +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; @@ -497,7 +501,7 @@ public class MapInfoLayer extends OsmandMapLayer { final ArrayList list = new ArrayList(); String appMode = settings.getApplicationMode().toHumanString(view.getApplication()); - list.add(map.getString(R.string.map_widget_reset) + " [" + appMode +"] "); + list.add(map.getString(R.string.map_widget_reset)); list.add(map.getString(R.string.map_widget_top_stack)); list.addAll(mapInfoControls.getTop()); list.add(map.getString(R.string.map_widget_right_stack)); @@ -516,11 +520,11 @@ public class MapInfoLayer extends OsmandMapLayer { // final LayerMenuListener listener = new LayerMenuListener(adapter, mapView, settings); - - final ApplicationMode mode = settings.getApplicationMode(); - ListAdapter listAdapter = new ArrayAdapter(map, R.layout.layers_list_activity_item, R.id.title, list) { + final Set selected = new LinkedHashSet(); + final ArrayAdapter listAdapter = new ArrayAdapter(map, R.layout.layers_list_activity_item, R.id.title, list) { @Override public View getView(final int position, View convertView, ViewGroup parent) { + final ApplicationMode mode = settings.getApplicationMode(); View v = convertView; if (v == null) { v = map.getLayoutInflater().inflate(R.layout.layers_list_activity_item, null); @@ -586,11 +590,27 @@ public class MapInfoLayer extends OsmandMapLayer { } }; Builder b = new AlertDialog.Builder(map); - b.setAdapter(listAdapter, new OnClickListener() { - + View confirmDialog = view.inflate(view.getContext(), R.layout.configuration_dialog, null); + final ListView lv = (ListView) confirmDialog.findViewById(android.R.id.list); + MapActivityActions.prepareAppModeView(map, selected, true, + (ViewGroup) confirmDialog.findViewById(R.id.TopBar), + new View.OnClickListener() { @Override - public void onClick(DialogInterface dialog, int which) { - Object o = list.get(which); + public void onClick(View v) { + if(selected.size() > 0) { + view.getSettings().APPLICATION_MODE.set(selected.iterator().next()); + listAdapter.notifyDataSetChanged(); + } + } + }); + + + lv.setOnItemClickListener(new OnItemClickListener() { + + @Override + public void onItemClick(AdapterView parent, View view, int position, long id) { + final ApplicationMode mode = settings.getApplicationMode(); + Object o = list.get(position); if (o instanceof MapWidgetRegInfo) { final MapWidgetRegInfo mi = (MapWidgetRegInfo) o; final boolean selecteable = mi.selecteable(); @@ -599,12 +619,14 @@ public class MapInfoLayer extends OsmandMapLayer { mapInfoControls.changeVisibility(mi); } recreateControls(); - } else if(which == 0) { + } else if(position == 0) { mapInfoControls.resetToDefault(); recreateControls(); - } + } } }); + lv.setAdapter(listAdapter); + b.setView(confirmDialog); final AlertDialog dlg = b.create(); // listener.setDialog(dlg); dlg.setCanceledOnTouchOutside(true);