From cf2eba88a8fbc72e3a573be2d3205f2fc48ddfdf Mon Sep 17 00:00:00 2001 From: Victor Shcherb Date: Thu, 2 Apr 2015 00:11:47 +0200 Subject: [PATCH] SUpport editing favorite --- OsmAnd/res/layout/favorite_edit_dialog.xml | 6 ++--- OsmAnd/res/values/strings.xml | 1 + .../activities/FavoritesTreeFragment.java | 26 ++++++++++++------- .../net/osmand/plus/views/FavoritesLayer.java | 23 +++++++++++++++- 4 files changed, 43 insertions(+), 13 deletions(-) diff --git a/OsmAnd/res/layout/favorite_edit_dialog.xml b/OsmAnd/res/layout/favorite_edit_dialog.xml index 16f1630b63..9f7304ad97 100644 --- a/OsmAnd/res/layout/favorite_edit_dialog.xml +++ b/OsmAnd/res/layout/favorite_edit_dialog.xml @@ -37,7 +37,6 @@ android:layout_width="fill_parent" android:layout_height="wrap_content" android:completionThreshold="1" - android:inputType="textCapWords" android:selectAllOnFocus="true"/> diff --git a/OsmAnd/res/values/strings.xml b/OsmAnd/res/values/strings.xml index 4690fe875e..bf66a5dec6 100644 --- a/OsmAnd/res/values/strings.xml +++ b/OsmAnd/res/values/strings.xml @@ -10,6 +10,7 @@ PLEASE: Have a look at http://code.google.com/p/osmand/wiki/UIConsistency, it may really improve your and our work :-) Thx - Hardy --> A-GPS info + Show description Message A-GPS data last downloaded: %1$s In many countries (Germany, France, Italy, and others) the use of speed camera warnings is not permitted by law. OsmAnd does assume any liability if you violate the law. Please click yes only if you are eligible to use this feature. diff --git a/OsmAnd/src/net/osmand/plus/activities/FavoritesTreeFragment.java b/OsmAnd/src/net/osmand/plus/activities/FavoritesTreeFragment.java index 2c647a0331..79a7ba17c5 100644 --- a/OsmAnd/src/net/osmand/plus/activities/FavoritesTreeFragment.java +++ b/OsmAnd/src/net/osmand/plus/activities/FavoritesTreeFragment.java @@ -3,6 +3,7 @@ package net.osmand.plus.activities; import android.app.Activity; import android.app.AlertDialog; import android.app.AlertDialog.Builder; +import android.content.Context; import android.content.DialogInterface; import android.content.Intent; import android.content.res.Resources; @@ -35,7 +36,6 @@ import android.widget.ImageView; import android.widget.Spinner; import android.widget.TextView; import android.widget.Toast; - import net.osmand.access.AccessibleToast; import net.osmand.data.FavouritePoint; import net.osmand.data.LatLon; @@ -47,6 +47,7 @@ import net.osmand.plus.GPXUtilities; import net.osmand.plus.GPXUtilities.GPXFile; import net.osmand.plus.IconsCache; import net.osmand.plus.OsmAndFormatter; +import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandSettings; import net.osmand.plus.R; import net.osmand.plus.TargetPointsHelper; @@ -199,7 +200,11 @@ public class FavoritesTreeFragment extends OsmandExpandableListFragment { item.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() { @Override public boolean onMenuItemClick(MenuItem item) { - editPoint(point); + editPoint(getActivity(), point, new Runnable() { + public void run() { + favouritesAdapter.synchronizeGroups(); + } + }); return true; } }); @@ -220,11 +225,12 @@ public class FavoritesTreeFragment extends OsmandExpandableListFragment { return true; } - private boolean editPoint(final FavouritePoint point) { - Builder builder = new AlertDialog.Builder(getActivity()); + public static boolean editPoint(Context ctx, final FavouritePoint point, final Runnable callback) { + OsmandApplication app = (OsmandApplication) ctx.getApplicationContext(); + Builder builder = new AlertDialog.Builder(ctx); builder.setTitle(R.string.favourites_context_menu_edit); - final View v = getActivity().getLayoutInflater().inflate(R.layout.favorite_edit_dialog, - getExpandableListView(), false); + final View v = LayoutInflater.from(ctx).inflate(R.layout.favorite_edit_dialog, + null, false); final AutoCompleteTextView cat = (AutoCompleteTextView) v.findViewById(R.id.Category); final EditText editText = (EditText) v.findViewById(R.id.Name); final EditText editDescr = (EditText) v.findViewById(R.id.descr); @@ -233,20 +239,22 @@ public class FavoritesTreeFragment extends OsmandExpandableListFragment { editDescr.setText(point.getDescription()); cat.setText(point.getCategory()); cat.setThreshold(1); + final FavouritesDbHelper helper = app.getFavorites(); List gs = helper.getFavoriteGroups(); String[] list = new String[gs.size()]; for(int i = 0; i < list.length; i++) { list[i] =gs.get(i).name; } - cat.setAdapter(new ArrayAdapter(getActivity(), R.layout.list_textview, list)); + cat.setAdapter(new ArrayAdapter(ctx, R.layout.list_textview, list)); builder.setNegativeButton(R.string.shared_string_cancel, null); builder.setPositiveButton(R.string.shared_string_apply, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { boolean edited = helper.editFavouriteName(point, editText.getText().toString().trim(), cat.getText() .toString(), editDescr.getText().toString()); - if (edited) { - favouritesAdapter.synchronizeGroups(); + if (edited && callback != null) { + callback.run(); + } } diff --git a/OsmAnd/src/net/osmand/plus/views/FavoritesLayer.java b/OsmAnd/src/net/osmand/plus/views/FavoritesLayer.java index 5f52898536..77e5bb35f7 100644 --- a/OsmAnd/src/net/osmand/plus/views/FavoritesLayer.java +++ b/OsmAnd/src/net/osmand/plus/views/FavoritesLayer.java @@ -4,6 +4,7 @@ import java.util.ArrayList; import java.util.List; import net.osmand.access.AccessibleToast; +import net.osmand.data.Amenity; import net.osmand.data.FavouritePoint; import net.osmand.data.LatLon; import net.osmand.data.LocationPoint; @@ -13,9 +14,12 @@ import net.osmand.data.RotatedTileBox; import net.osmand.plus.ContextMenuAdapter; import net.osmand.plus.ContextMenuAdapter.OnContextMenuClick; import net.osmand.plus.FavouritesDbHelper; +import net.osmand.plus.OsmAndFormatter; import net.osmand.plus.R; +import net.osmand.plus.activities.FavoritesTreeFragment; import net.osmand.plus.base.FavoriteImageDrawable; import net.osmand.plus.views.MapTextLayer.MapTextProvider; +import net.osmand.util.Algorithms; import android.app.AlertDialog; import android.app.AlertDialog.Builder; import android.content.DialogInterface; @@ -204,7 +208,11 @@ public class FavoritesLayer extends OsmandMapLayer implements ContextMenuLayer. OnContextMenuClick listener = new ContextMenuAdapter.OnContextMenuClick() { @Override public boolean onContextMenuClick(ArrayAdapter adapter, int itemId, int pos, boolean isChecked) { - if (itemId == R.string.favourites_context_menu_delete) { + if (itemId == R.string.favourites_context_menu_edit) { + FavoritesTreeFragment.editPoint(view.getContext(), a, null); + } else if (itemId == R.string.shared_string_show_description) { + showDescriptionDialog(a); + } else if (itemId == R.string.favourites_context_menu_delete) { final Resources resources = view.getContext().getResources(); Builder builder = new AlertDialog.Builder(view.getContext()); builder.setMessage(resources.getString(R.string.favourites_remove_dialog_msg, a.getName())); @@ -221,11 +229,24 @@ public class FavoritesLayer extends OsmandMapLayer implements ContextMenuLayer. return true; } }; + if (!Algorithms.isEmpty(a.getDescription())) { + adapter.item(R.string.shared_string_show_description).iconColor(R.drawable.ic_action_note_dark) + .listen(listener).reg(); + } + adapter.item(R.string.favourites_context_menu_edit).iconColor(R.drawable.ic_action_edit_dark) + .listen(listener).reg(); adapter.item(R.string.favourites_context_menu_delete) .iconColor(R.drawable.ic_action_delete_dark).listen(listener) .reg(); } } + + private void showDescriptionDialog(FavouritePoint a) { + Builder bs = new AlertDialog.Builder(view.getContext()); + bs.setTitle(a.getName(view.getContext())); + bs.setMessage(a.getDescription()); + bs.show(); + } @Override public LatLon getTextLocation(LocationPoint o) {