diff --git a/OsmAnd/res/layout/quick_action_widget_item.xml b/OsmAnd/res/layout/quick_action_widget_item.xml
index 73e0f27bc5..93b4183f96 100644
--- a/OsmAnd/res/layout/quick_action_widget_item.xml
+++ b/OsmAnd/res/layout/quick_action_widget_item.xml
@@ -15,14 +15,26 @@
android:gravity="center_horizontal"
android:orientation="vertical">
-
+
+
+
+
+
+
Add marker
Add POI
Change map style
+ Map style has been changed to the \"%s\".
Take audio note
Take video note
Take photo note
Add OSM bug
Voice On/Off
+ Voice Off
+ Voice On
Add GPX waypoint
Add Parking place
Add action
@@ -2507,8 +2510,12 @@ If you need help with OsmAnd application, please contact our support team: suppo
Quick action name duplicate
Tap on action will Show or Hide favorites points on map.
Tap on action will Show or Hide POI points on map.
- Show/Hide Favorites
- Show/Hide POI
+ Show/Hide Favorites
+ Show Favorites
+ Hide Favorites
+ Show/Hide POI
+ Show %1$s
+ Hide %1$s
Add category
Create items
Configure map
diff --git a/OsmAnd/src/net/osmand/plus/quickaction/AddQuickActionDialog.java b/OsmAnd/src/net/osmand/plus/quickaction/AddQuickActionDialog.java
index 36c1d3f54c..0d82df4534 100644
--- a/OsmAnd/src/net/osmand/plus/quickaction/AddQuickActionDialog.java
+++ b/OsmAnd/src/net/osmand/plus/quickaction/AddQuickActionDialog.java
@@ -41,8 +41,13 @@ public class AddQuickActionDialog extends DialogFragment {
getDialog().getWindow().requestFeature(Window.FEATURE_NO_TITLE);
+ List active = ((MapActivity) getActivity())
+ .getMapLayers()
+ .getQuickActionRegistry()
+ .getQuickActions();
+
View root = inflater.inflate(R.layout.quick_action_add_dialog, container, false);
- Adapter adapter = new Adapter(QuickActionFactory.produceTypeActionsListWithHeaders());
+ Adapter adapter = new Adapter(QuickActionFactory.produceTypeActionsListWithHeaders(active));
RecyclerView recyclerView = (RecyclerView) root.findViewById(R.id.recycler_view);
Button btnDismiss = (Button) root.findViewById(R.id.btnDismiss);
diff --git a/OsmAnd/src/net/osmand/plus/quickaction/CreateEditActionDialog.java b/OsmAnd/src/net/osmand/plus/quickaction/CreateEditActionDialog.java
index 996de505fd..f81f6ef021 100644
--- a/OsmAnd/src/net/osmand/plus/quickaction/CreateEditActionDialog.java
+++ b/OsmAnd/src/net/osmand/plus/quickaction/CreateEditActionDialog.java
@@ -180,6 +180,9 @@ public class CreateEditActionDialog extends DialogFragment {
}
});
+ name.setEnabled(!action.isSingle() && !action.toggle);
+ action.setAutoGeneratedTitle(name);
+
if (savedInstanceState == null) name.setText(action.getName(getContext()));
else action.setName(name.getText().toString());
diff --git a/OsmAnd/src/net/osmand/plus/quickaction/QuickAction.java b/OsmAnd/src/net/osmand/plus/quickaction/QuickAction.java
index 2543ff0403..d4138fd643 100644
--- a/OsmAnd/src/net/osmand/plus/quickaction/QuickAction.java
+++ b/OsmAnd/src/net/osmand/plus/quickaction/QuickAction.java
@@ -2,21 +2,25 @@ package net.osmand.plus.quickaction;
import android.content.Context;
+import android.graphics.drawable.Drawable;
import android.os.Parcel;
import android.os.Parcelable;
import android.support.annotation.DrawableRes;
import android.support.annotation.StringRes;
import android.view.View;
import android.view.ViewGroup;
+import android.widget.EditText;
import com.google.gson.Gson;
import com.google.gson.annotations.Expose;
import com.google.gson.reflect.TypeToken;
+import net.osmand.plus.OsmandApplication;
import net.osmand.plus.activities.MapActivity;
import java.lang.reflect.Type;
import java.util.HashMap;
+import java.util.List;
import java.util.Map;
public class QuickAction {
@@ -58,6 +62,8 @@ public class QuickAction {
this.iconRes = quickAction.iconRes;
this.name = quickAction.name;
this.params = quickAction.params;
+ this.single = quickAction.single;
+ this.toggle = quickAction.toggle;
}
public int getNameRes() {
@@ -76,6 +82,10 @@ public class QuickAction {
return name == null || name.isEmpty() ? nameRes > 0 ? context.getString(nameRes) : "" : name;
}
+ public boolean isSingle() {
+ return single;
+ }
+
public HashMap getParams() {
if (params == null) params = new HashMap<>();
@@ -91,10 +101,30 @@ public class QuickAction {
this.params = params;
}
+ public boolean isActionWithSlash(OsmandApplication application){
+ return false;
+ }
+
+ public String getActionText(OsmandApplication application){
+ return getName(application);
+ }
+
+ public void setAutoGeneratedTitle(EditText title){
+ }
+
public void execute(MapActivity activity){};
public void drawUI(ViewGroup parent, MapActivity activity){};
public boolean fillParams(View root, MapActivity activity){ return true; };
+ public boolean hasInstanceInList(List active){
+
+ for (QuickAction action: active){
+ if (action.type == type) return true;
+ }
+
+ return false;
+ }
+
@Override
public boolean equals(Object o) {
if (this == o) return true;
diff --git a/OsmAnd/src/net/osmand/plus/quickaction/QuickActionFactory.java b/OsmAnd/src/net/osmand/plus/quickaction/QuickActionFactory.java
index 95dcaa60dc..92b82454cf 100644
--- a/OsmAnd/src/net/osmand/plus/quickaction/QuickActionFactory.java
+++ b/OsmAnd/src/net/osmand/plus/quickaction/QuickActionFactory.java
@@ -34,6 +34,7 @@ import net.osmand.data.LatLon;
import net.osmand.data.PointDescription;
import net.osmand.osm.AbstractPoiType;
import net.osmand.osm.MapPoiTypes;
+import net.osmand.osm.PoiFilter;
import net.osmand.osm.PoiType;
import net.osmand.osm.edit.Node;
import net.osmand.osm.edit.OSMSettings;
@@ -71,6 +72,7 @@ import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
+import java.util.Set;
import static net.osmand.plus.osmedit.AdvancedEditPoiFragment.addPoiToStringSet;
@@ -100,19 +102,6 @@ public class QuickActionFactory {
return quickActions != null ? quickActions : new ArrayList();
}
-// public static List produceTypeActionsList() {
-//
-// ArrayList quickActions = new ArrayList<>();
-//
-// quickActions.add(new MarkerAction());
-// quickActions.add(new FavoriteAction());
-// quickActions.add(new ShowHideFavoritesAction());
-// quickActions.add(new ShowHidePoiAction());
-// quickActions.add(new GPXAction());
-//
-// return quickActions;
-// }
-
public static List produceTypeActionsListWithHeaders() {
ArrayList quickActions = new ArrayList<>();
@@ -151,6 +140,76 @@ public class QuickActionFactory {
return quickActions;
}
+ public static List produceTypeActionsListWithHeaders(List active) {
+
+ ArrayList quickActions = new ArrayList<>();
+
+ quickActions.add(new QuickAction(0, R.string.quick_action_add_create_items));
+ quickActions.add(new FavoriteAction());
+ quickActions.add(new GPXAction());
+
+ QuickAction marker = new MarkerAction();
+
+ if (!marker.hasInstanceInList(active)) {
+ quickActions.add(marker);
+ }
+
+ if (OsmandPlugin.getEnabledPlugin(AudioVideoNotesPlugin.class) != null) {
+
+ QuickAction audio = new TakeAudioNoteAction();
+ QuickAction photo = new TakePhotoNoteAction();
+ QuickAction vedio = new TakeVideoNoteAction();
+
+ if (!audio.hasInstanceInList(active)) {
+ quickActions.add(audio);
+ }
+
+ if (!photo.hasInstanceInList(active)) {
+ quickActions.add(photo);
+ }
+
+ if (!vedio.hasInstanceInList(active)) {
+ quickActions.add(vedio);
+ }
+ }
+
+ if (OsmandPlugin.getEnabledPlugin(OsmEditingPlugin.class) != null) {
+
+ quickActions.add(new AddPOIAction());
+ quickActions.add(new AddOSMBugAction());
+ }
+
+ if (OsmandPlugin.getEnabledPlugin(ParkingPositionPlugin.class) != null) {
+
+ QuickAction parking = new ParkingAction();
+
+ if (!parking.hasInstanceInList(active)) {
+ quickActions.add(parking);
+ }
+ }
+
+ quickActions.add(new QuickAction(0, R.string.quick_action_add_configure_map));
+ quickActions.add(new MapStyleAction());
+
+ QuickAction favorites = new ShowHideFavoritesAction();
+
+ if (!favorites.hasInstanceInList(active)) {
+ quickActions.add(favorites);
+ }
+
+ quickActions.add(new ShowHidePoiAction());
+
+ QuickAction voice = new NavigationVoiceAction();
+
+ if (!voice.hasInstanceInList(active)) {
+
+ quickActions.add(new QuickAction(0, R.string.quick_action_add_navigation));
+ quickActions.add(voice);
+ }
+
+ return quickActions;
+ }
+
public static QuickAction newActionByType(int type) {
switch (type) {
@@ -412,7 +471,7 @@ public class QuickActionFactory {
name.setText(getParams().get(KEY_NAME));
categoryEdit.setText(getParams().get(KEY_CATEGORY_NAME));
- if (getParams().get(KEY_NAME).isEmpty() && Integer.valueOf(getParams().get(KEY_CATEGORY_NAME)) == 0) {
+ if (getParams().get(KEY_NAME).isEmpty() && Integer.valueOf(getParams().get(KEY_CATEGORY_COLOR)) == 0) {
categoryEdit.setText(activity.getString(R.string.shared_string_favorites));
categoryImage.setColorFilter(activity.getResources().getColor(R.color.color_favorite));
@@ -526,7 +585,7 @@ public class QuickActionFactory {
protected ShowHideFavoritesAction() {
id = System.currentTimeMillis();
type = TYPE;
- nameRes = R.string.quic_action_showhide_favorites_title;
+ nameRes = R.string.quick_action_showhide_favorites_title;
iconRes = R.drawable.ic_action_fav_dark;
single = true;
toggle = true;
@@ -556,6 +615,20 @@ public class QuickActionFactory {
parent.addView(view);
}
+
+ @Override
+ public String getActionText(OsmandApplication application) {
+
+ return application.getSettings().SHOW_FAVORITES.get()
+ ? application.getString(R.string.quick_action_favorites_hide)
+ : application.getString(R.string.quick_action_favorites_show);
+ }
+
+ @Override
+ public boolean isActionWithSlash(OsmandApplication application) {
+
+ return application.getSettings().SHOW_FAVORITES.get();
+ }
}
public static class ShowHidePoiAction extends QuickAction {
@@ -564,10 +637,12 @@ public class QuickActionFactory {
public static final String KEY_FILTERS = "filters";
+ private transient EditText title;
+
protected ShowHidePoiAction() {
id = System.currentTimeMillis();
type = TYPE;
- nameRes = R.string.quic_action_showhide_poi_title;
+ nameRes = R.string.quick_action_showhide_poi_title;
iconRes = R.drawable.ic_action_gabout_dark;
toggle = true;
}
@@ -576,14 +651,34 @@ public class QuickActionFactory {
super(quickAction);
}
+ @Override
+ public String getActionText(OsmandApplication application) {
+
+ return !isCurrentFilters(application)
+ ? application.getString(R.string.quick_action_poi_show, getName(application))
+ : application.getString(R.string.quick_action_poi_hide, getName(application));
+ }
+
+ @Override
+ public boolean isActionWithSlash(OsmandApplication application) {
+
+ return isCurrentFilters(application);
+ }
+
+ @Override
+ public void setAutoGeneratedTitle(EditText title) {
+ this.title = title;
+ }
+
@Override
public void execute(MapActivity activity) {
PoiFiltersHelper pf = activity.getMyApplication().getPoiFilters();
+ List poiFilters = loadPoiFilters(activity.getMyApplication().getPoiFilters());
- if (pf.getSelectedPoiFilters().isEmpty()) {
+ if (!isCurrentFilters(pf.getSelectedPoiFilters(), poiFilters)){
- List poiFilters = loadPoiFilters(activity.getMyApplication().getPoiFilters());
+ pf.clearSelectedPoiFilters();
for (PoiUIFilter filter : poiFilters) {
pf.addSelectedPoiFilter(filter);
@@ -591,9 +686,26 @@ public class QuickActionFactory {
} else pf.clearSelectedPoiFilters();
+
+
activity.getMapLayers().updateLayers(activity.getMapView());
}
+ private boolean isCurrentFilters(OsmandApplication application) {
+
+ PoiFiltersHelper pf = application.getPoiFilters();
+ List poiFilters = loadPoiFilters(application.getPoiFilters());
+
+ return isCurrentFilters(pf.getSelectedPoiFilters(), poiFilters);
+ }
+
+ private boolean isCurrentFilters(Set currentPoiFilters, List poiFilters){
+
+ if (currentPoiFilters.size() != poiFilters.size()) return false;
+
+ return currentPoiFilters.containsAll(poiFilters);
+ }
+
@Override
public void drawUI(ViewGroup parent, final MapActivity activity) {
@@ -646,7 +758,7 @@ public class QuickActionFactory {
}
@Override
- public void onBindViewHolder(Holder holder, final int position) {
+ public void onBindViewHolder(final Holder holder, final int position) {
final PoiUIFilter filter = filters.get(position);
@@ -663,10 +775,18 @@ public class QuickActionFactory {
@Override
public void onClick(View view) {
+ String oldTitle = getTitle(filters);
+
filters.remove(position);
savePoiFilters(filters);
notifyDataSetChanged();
+
+ if (oldTitle.equals(title.getText().toString()) || title.getText().toString().equals(getName(holder.title.getContext()))) {
+
+ String newTitle = getTitle(filters);
+ title.setText(newTitle);
+ }
}
});
}
@@ -727,7 +847,7 @@ public class QuickActionFactory {
return poiFilters;
}
- private void showSingleChoicePoiFilterDialog(final OsmandApplication app, MapActivity activity, final Adapter filtersAdapter) {
+ private void showSingleChoicePoiFilterDialog(final OsmandApplication app, final MapActivity activity, final Adapter filtersAdapter) {
final PoiFiltersHelper poiFilters = app.getPoiFilters();
final ContextMenuAdapter adapter = new ContextMenuAdapter();
@@ -752,7 +872,16 @@ public class QuickActionFactory {
builder.setAdapter(listAdapter, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
+
+ String oldTitle = getTitle(filtersAdapter.filters);
+
filtersAdapter.addItem(list.get(which));
+
+ if (oldTitle.equals(title.getText().toString()) || title.getText().toString().equals(getName(activity))) {
+
+ String newTitle = getTitle(filtersAdapter.filters);
+ title.setText(newTitle);
+ }
}
});
@@ -773,6 +902,15 @@ public class QuickActionFactory {
alertDialog.show();
}
+ private String getTitle(List filters) {
+
+ if (filters.isEmpty()) return "";
+
+ return filters.size() > 1
+ ? filters.get(0).getName() + " +" + (filters.size() - 1)
+ : filters.get(0).getName();
+ }
+
private void addFilterToList(final ContextMenuAdapter adapter,
final List list,
final PoiUIFilter f) {
@@ -878,7 +1016,7 @@ public class QuickActionFactory {
name.setText(getParams().get(KEY_NAME));
categoryEdit.setText(getParams().get(KEY_CATEGORY_NAME));
- if (getParams().get(KEY_NAME).isEmpty() && Integer.valueOf(getParams().get(KEY_CATEGORY_NAME)) == 0) {
+ if (getParams().get(KEY_NAME).isEmpty() && Integer.valueOf(getParams().get(KEY_CATEGORY_COLOR)) == 0) {
categoryEdit.setText("");
categoryImage.setColorFilter(activity.getResources().getColor(R.color.icon_color));
@@ -1161,6 +1299,20 @@ public class QuickActionFactory {
parent.addView(view);
}
+
+ @Override
+ public String getActionText(OsmandApplication application) {
+
+ return application.getSettings().VOICE_MUTE.get()
+ ? application.getString(R.string.quick_action_navigation_voice_off)
+ : application.getString(R.string.quick_action_navigation_voice_on);
+ }
+
+ @Override
+ public boolean isActionWithSlash(OsmandApplication application) {
+
+ return application.getSettings().VOICE_MUTE.get();
+ }
}
public static class AddOSMBugAction extends QuickAction {
@@ -1422,6 +1574,8 @@ public class QuickActionFactory {
private static String KEY_STYLES = "styles";
+ private transient EditText title;
+
protected MapStyleAction() {
id = System.currentTimeMillis();
type = TYPE;
@@ -1437,7 +1591,7 @@ public class QuickActionFactory {
@Override
public void execute(MapActivity activity) {
- List mapStyles = getFilteredStyles(activity.getMyApplication());
+ List mapStyles = getFilteredStyles();
String curStyle = activity.getMyApplication().getSettings().RENDERER.get();
int index = mapStyles.indexOf(curStyle);
@@ -1458,13 +1612,15 @@ public class QuickActionFactory {
activity.getMyApplication().getRendererRegistry().setCurrentSelectedRender(loaded);
ConfigureMapMenu.refreshMapComplete(activity);
+ Toast.makeText(activity, activity.getString(R.string.quick_action_map_style_switch, nextStyle), Toast.LENGTH_SHORT).show();
+
} else {
Toast.makeText(activity, R.string.renderer_load_exception, Toast.LENGTH_SHORT).show();
}
}
- protected List getFilteredStyles(OsmandApplication application){
+ protected List getFilteredStyles(){
List filtered = new ArrayList<>();
boolean enabled = OsmandPlugin.getEnabledPlugin(NauticalMapsPlugin.class) != null;
@@ -1483,6 +1639,21 @@ public class QuickActionFactory {
return filtered;
}
+ @Override
+ public void setAutoGeneratedTitle(EditText title) {
+ this.title = title;
+ }
+
+ private String getTitle(List filters) {
+
+ if (filters.isEmpty()) return "";
+
+ return filters.size() > 1
+ ? filters.get(0) + " +" + (filters.size() - 1)
+ : filters.get(0);
+ }
+
+
@Override
public void drawUI(ViewGroup parent, final MapActivity activity) {
@@ -1542,7 +1713,18 @@ public class QuickActionFactory {
String renderer = visibleNamesList.get(i);
RenderingRulesStorage loaded = app.getRendererRegistry().getRenderer(renderer);
- if (loaded != null) adapter.addItem(renderer);
+ if (loaded != null) {
+
+ String oldTitle = getTitle(adapter.itemsList);
+
+ adapter.addItem(renderer);
+
+ if (oldTitle.equals(title.getText().toString()) || title.getText().toString().equals(getName(activity))) {
+
+ String newTitle = getTitle(adapter.itemsList);
+ title.setText(newTitle);
+ }
+ }
dialogInterface.dismiss();
}
@@ -1591,7 +1773,16 @@ public class QuickActionFactory {
holder.closeBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
+
+ String oldTitle = getTitle(itemsList);
+
deleteItem(position);
+
+ if (oldTitle.equals(title.getText().toString()) || title.getText().toString().equals(getName(holder.handleView.getContext()))) {
+
+ String newTitle = getTitle(itemsList);
+ title.setText(newTitle);
+ }
}
});
}
@@ -1644,6 +1835,8 @@ public class QuickActionFactory {
if (selectedPosition < 0 || targetPosition < 0)
return false;
+ String oldTitle = getTitle(itemsList);
+
Collections.swap(itemsList, selectedPosition, targetPosition);
if (selectedPosition - targetPosition < -1) {
notifyItemMoved(selectedPosition, targetPosition);
@@ -1657,6 +1850,12 @@ public class QuickActionFactory {
notifyItemChanged(selectedPosition);
notifyItemChanged(targetPosition);
+ if (oldTitle.equals(title.getText().toString()) || title.getText().toString().equals(getName(recyclerView.getContext()))) {
+
+ String newTitle = getTitle(itemsList);
+ title.setText(newTitle);
+ }
+
return true;
}
diff --git a/OsmAnd/src/net/osmand/plus/quickaction/QuickActionRegistry.java b/OsmAnd/src/net/osmand/plus/quickaction/QuickActionRegistry.java
index d6f4ed3356..734d91c7c3 100644
--- a/OsmAnd/src/net/osmand/plus/quickaction/QuickActionRegistry.java
+++ b/OsmAnd/src/net/osmand/plus/quickaction/QuickActionRegistry.java
@@ -92,7 +92,7 @@ public class QuickActionRegistry {
if (action.type == QuickActionFactory.MapStyleAction.TYPE) {
if (((QuickActionFactory.MapStyleAction) QuickActionFactory.produceAction(action))
- .getFilteredStyles(settings.getContext()).isEmpty()){
+ .getFilteredStyles().isEmpty()){
skip = true;
}
diff --git a/OsmAnd/src/net/osmand/plus/quickaction/QuickActionsWidget.java b/OsmAnd/src/net/osmand/plus/quickaction/QuickActionsWidget.java
index a60e592914..1030a6e0d2 100644
--- a/OsmAnd/src/net/osmand/plus/quickaction/QuickActionsWidget.java
+++ b/OsmAnd/src/net/osmand/plus/quickaction/QuickActionsWidget.java
@@ -71,7 +71,8 @@ public class QuickActionsWidget extends LinearLayout {
private void setupLayout(Context context, int pageCount){
- boolean light = ((OsmandApplication) context.getApplicationContext()).getSettings().isLightContent();
+ OsmandApplication application = ((OsmandApplication) getContext().getApplicationContext());
+ boolean light = application.getSettings().isLightContent() && !application.getDaynightHelper().isNightMode();
inflate(new ContextThemeWrapper(context, light
? R.style.OsmandLightTheme
@@ -159,7 +160,8 @@ public class QuickActionsWidget extends LinearLayout {
private void updateControls(int position) {
- boolean light = ((OsmandApplication) getContext().getApplicationContext()).getSettings().isLightContent();
+ OsmandApplication application = ((OsmandApplication) getContext().getApplicationContext());
+ boolean light = application.getSettings().isLightContent() && !application.getDaynightHelper().isNightMode();
int colorEnabled = light ? R.color.icon_color : R.color.color_white;
int colorDisabled = light ? R.color.icon_color_light : R.color.white_50_transparent;
@@ -184,7 +186,8 @@ public class QuickActionsWidget extends LinearLayout {
private View createPageView(ViewGroup container, int position){
- boolean light = ((OsmandApplication) getContext().getApplicationContext()).getSettings().isLightContent();
+ OsmandApplication application = ((OsmandApplication) getContext().getApplicationContext());
+ boolean light = application.getSettings().isLightContent() && !application.getDaynightHelper().isNightMode();
LayoutInflater li = getLayoutInflater(light
? R.style.OsmandLightTheme
@@ -202,13 +205,22 @@ public class QuickActionsWidget extends LinearLayout {
if (i + (position * ELEMENT_PER_PAGE) < actions.size()) {
- final QuickAction action = actions.get(i + (position * ELEMENT_PER_PAGE));
+ final QuickAction action = QuickActionFactory.produceAction(
+ actions.get(i + (position * ELEMENT_PER_PAGE)));
((ImageView) view.findViewById(R.id.imageView))
.setImageResource(action.getIconRes());
((TextView) view.findViewById(R.id.title))
- .setText(action.getName(getContext()));
+ .setText(action.getActionText(application));
+
+ if (action.isActionWithSlash(application)) {
+
+ ((ImageView) view.findViewById(R.id.imageSlash))
+ .setImageResource(light
+ ? R.drawable.ic_action_icon_hide_white
+ : R.drawable.ic_action_icon_hide_dark);
+ }
view.setOnClickListener(new OnClickListener() {
@Override