underlay quick action
This commit is contained in:
parent
5af7d6fb13
commit
ac2a48cd31
3 changed files with 92 additions and 11 deletions
|
@ -2529,6 +2529,7 @@ If you need help with OsmAnd application, please contact our support team: suppo
|
|||
<string name="quick_action_map_overlay_descr">Tapping the action button will page the map overlay through the list below.</string>
|
||||
<string name="quick_action_map_overlay_action">Add overlay</string>
|
||||
<string name="quick_action_map_overlay_switch">The map overlay has been changed to \"%s\".</string>
|
||||
<string name="quick_action_map_underlay_switch">The map underlay has been changed to \"%s\".</string>
|
||||
<string name="quick_action_map_underlay">Change map underlay</string>
|
||||
<string name="quick_action_map_underlay_title">Map underlays</string>
|
||||
<string name="quick_action_map_underlay_descr">Tapping the action button will page the map underlay through the list below.</string>
|
||||
|
|
|
@ -42,10 +42,8 @@ import com.google.gson.Gson;
|
|||
import com.google.gson.reflect.TypeToken;
|
||||
|
||||
import net.osmand.CallbackWithObject;
|
||||
import net.osmand.ResultMatcher;
|
||||
import net.osmand.data.LatLon;
|
||||
import net.osmand.data.PointDescription;
|
||||
import net.osmand.map.TileSourceManager;
|
||||
import net.osmand.osm.AbstractPoiType;
|
||||
import net.osmand.osm.MapPoiTypes;
|
||||
import net.osmand.osm.PoiCategory;
|
||||
|
@ -60,7 +58,6 @@ import net.osmand.plus.OsmandPlugin;
|
|||
import net.osmand.plus.OsmandSettings;
|
||||
import net.osmand.plus.R;
|
||||
import net.osmand.plus.activities.MapActivity;
|
||||
import net.osmand.plus.activities.MapActivityLayers;
|
||||
import net.osmand.plus.audionotes.AudioVideoNotesPlugin;
|
||||
import net.osmand.plus.dialogs.ConfigureMapMenu;
|
||||
import net.osmand.plus.mapcontextmenu.editors.EditCategoryDialogFragment;
|
||||
|
@ -172,6 +169,7 @@ public class QuickActionFactory {
|
|||
|
||||
quickActions.add(new MapSourceAction());
|
||||
quickActions.add(new MapOverlayAction());
|
||||
quickActions.add(new MapUnderlayAction());
|
||||
}
|
||||
|
||||
QuickAction favorites = new ShowHideFavoritesAction();
|
||||
|
@ -245,6 +243,9 @@ public class QuickActionFactory {
|
|||
case MapOverlayAction.TYPE:
|
||||
return new MapOverlayAction();
|
||||
|
||||
case MapUnderlayAction.TYPE:
|
||||
return new MapUnderlayAction();
|
||||
|
||||
default:
|
||||
return new QuickAction();
|
||||
}
|
||||
|
@ -302,6 +303,9 @@ public class QuickActionFactory {
|
|||
case MapOverlayAction.TYPE:
|
||||
return new MapOverlayAction(quickAction);
|
||||
|
||||
case MapUnderlayAction.TYPE:
|
||||
return new MapUnderlayAction(quickAction);
|
||||
|
||||
default:
|
||||
return quickAction;
|
||||
}
|
||||
|
@ -2316,27 +2320,63 @@ public class QuickActionFactory {
|
|||
|
||||
@Override
|
||||
protected String getTitle(List<Pair<String, String>> filters) {
|
||||
return null;
|
||||
|
||||
if (filters.isEmpty()) return "";
|
||||
|
||||
return filters.size() > 1
|
||||
? filters.get(0).second + " +" + (filters.size() - 1)
|
||||
: filters.get(0).second;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void saveListToParams(List<Pair<String, String>> list) {
|
||||
|
||||
getParams().put(getListKey(), new Gson().toJson(list));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<Pair<String, String>> loadListFromParams() {
|
||||
return null;
|
||||
|
||||
String json = getParams().get(getListKey());
|
||||
|
||||
if (json == null || json.isEmpty()) return new ArrayList<>();
|
||||
|
||||
Type listType = new TypeToken<ArrayList<Pair<String, String>>>(){}.getType();
|
||||
|
||||
return new Gson().fromJson(json, listType);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getItemName(Pair<String, String> item) {
|
||||
return null;
|
||||
return item.second;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(MapActivity activity) {
|
||||
OsmandRasterMapsPlugin plugin = OsmandPlugin.getEnabledPlugin(OsmandRasterMapsPlugin.class);
|
||||
|
||||
if (plugin != null) {
|
||||
|
||||
OsmandSettings settings = activity.getMyApplication().getSettings();
|
||||
List<Pair<String, String>> sources = loadListFromParams();
|
||||
|
||||
Pair<String, String> currentSource = new Pair<>(
|
||||
settings.MAP_UNDERLAY.get(),
|
||||
settings.MAP_UNDERLAY.get());
|
||||
|
||||
Pair<String, String> nextSource = sources.get(0);
|
||||
int index = sources.indexOf(currentSource);
|
||||
|
||||
if (index >= 0 && index + 1 < sources.size()) {
|
||||
nextSource = sources.get(index + 1);
|
||||
}
|
||||
|
||||
settings.MAP_UNDERLAY.set(nextSource.first);
|
||||
settings.MAP_UNDERLAY_PREVIOUS.set(nextSource.first);
|
||||
|
||||
plugin.updateMapLayers(activity.getMapView(), settings.MAP_UNDERLAY, activity.getMapLayers());
|
||||
Toast.makeText(activity, activity.getString(R.string.quick_action_map_underlay_switch, nextSource.second), Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -2365,6 +2405,34 @@ public class QuickActionFactory {
|
|||
@Override
|
||||
public void onClick(View view) {
|
||||
|
||||
final OsmandSettings settings = activity.getMyApplication().getSettings();
|
||||
Map<String, String> entriesMap = settings.getTileSourceEntries();
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(activity);
|
||||
final ArrayList<String> keys = new ArrayList<>(entriesMap.keySet());
|
||||
final String[] items = new String[entriesMap.size()];
|
||||
int i = 0;
|
||||
|
||||
for (String it : entriesMap.values()) {
|
||||
items[i++] = it;
|
||||
}
|
||||
|
||||
final ArrayAdapter<String> arrayAdapter = new ArrayAdapter<>(activity, R.layout.dialog_text_item);
|
||||
arrayAdapter.addAll(items);
|
||||
builder.setAdapter(arrayAdapter, new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int i) {
|
||||
|
||||
Pair<String, String> layer = new Pair<>(
|
||||
keys.get(i), items[i]);
|
||||
|
||||
adapter.addItem(layer, activity);
|
||||
|
||||
dialog.dismiss();
|
||||
|
||||
}
|
||||
}).setNegativeButton(R.string.shared_string_cancel, null);
|
||||
|
||||
builder.show();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
|
|
@ -113,7 +113,7 @@ public class MapQuickActionLayer extends OsmandMapLayer implements QuickActionRe
|
|||
}
|
||||
|
||||
private boolean showTutorialIfNeeded() {
|
||||
if (isLayerOn && !settings.IS_QUICK_ACTION_TUTORIAL_SHOWN.get()) {
|
||||
if (isLayerOn && !settings.IS_QUICK_ACTION_TUTORIAL_SHOWN.get() && android.os.Build.VERSION.SDK_INT >= 14) {
|
||||
TapTargetView.showFor(mapActivity, // `this` is an Activity
|
||||
TapTarget.forView(quickActionButton, mapActivity.getString(R.string.quick_action_btn_tutorial_title), mapActivity.getString(R.string.quick_action_btn_tutorial_descr))
|
||||
// All options below are optional
|
||||
|
@ -121,16 +121,12 @@ public class MapQuickActionLayer extends OsmandMapLayer implements QuickActionRe
|
|||
.targetCircleColor(R.color.color_white) // Specify a color for the target circle
|
||||
.titleTextSize(20) // Specify the size (in sp) of the title text
|
||||
.descriptionTextSize(16) // Specify the size (in sp) of the description text
|
||||
// .textColor(R.color.color_white) // Specify a color for both the title and description text
|
||||
.descriptionTextColor(R.color.color_white) // Specify a color for both the title and description text
|
||||
.titleTextColor(R.color.color_white) // Specify a color for both the title and description text
|
||||
// .textTypeface(Typeface.SANS_SERIF) // Specify a typeface for the text
|
||||
// .dimColor(R.color.black) // If set, will dim behind the view with 30% opacity of the given color
|
||||
.drawShadow(true) // Whether to draw a drop shadow or not
|
||||
.cancelable(false) // Whether tapping outside the outer circle dismisses the view
|
||||
.tintTarget(false) // Whether to tint the target view's color
|
||||
.transparentTarget(false) // Specify whether the target is transparent (displays the content underneath)
|
||||
// .icon(Drawable) // Specify a custom drawable to draw as the target
|
||||
.targetRadius(50), // Specify the target radius (in dp)
|
||||
new TapTargetView.Listener() { // The listener can listen for regular clicks, long clicks or cancels
|
||||
@Override
|
||||
|
@ -203,6 +199,22 @@ public class MapQuickActionLayer extends OsmandMapLayer implements QuickActionRe
|
|||
previousMapPosition = view.getMapPosition();
|
||||
view.setMapPosition(OsmandSettings.BOTTOM_CONSTANT);
|
||||
MapContextMenu menu = mapActivity.getContextMenu();
|
||||
|
||||
// LatLon ll;
|
||||
// if (menu.isActive() && tileBox.containsLatLon(menu.getLatLon())) {
|
||||
// ll = menu.getLatLon();
|
||||
// view.setMapPosition(OsmandSettings.BOTTOM_CONSTANT);
|
||||
// } else {
|
||||
// if (false){
|
||||
// //TODO check if we are tracking
|
||||
// view.setMapPosition(OsmandSettings.BOTTOM_CONSTANT);
|
||||
// ll = tileBox.getCenterLatLon();
|
||||
// } else {
|
||||
// ll = tileBox.getCenterLatLon();
|
||||
// view.setMapPosition(OsmandSettings.BOTTOM_CONSTANT);
|
||||
// }
|
||||
// }
|
||||
|
||||
LatLon ll = menu.isActive() && tileBox.containsLatLon(menu.getLatLon()) ? menu.getLatLon() : tileBox.getCenterLatLon();
|
||||
|
||||
menu.updateMapCenter(null);
|
||||
|
|
Loading…
Reference in a new issue