Merge pull request #3409 from brainbeanapps/master

quick action part 2
This commit is contained in:
vshcherb 2017-01-10 18:43:38 +01:00 committed by GitHub
commit 63e21f9940
6 changed files with 209 additions and 40 deletions

View file

@ -1,13 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:installLocation="auto"
android:versionName="@string/app_version"
android:installLocation="auto"
android:versionName="@string/app_version"
android:versionCode="240"
package="net.osmand.plus">
<uses-sdk android:minSdkVersion="14" android:targetSdkVersion="21" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_LOCATION_EXTRA_COMMANDS" />
@ -42,8 +40,9 @@
<uses-feature android:name="android.hardware.touchscreen" android:required="false" />
<uses-feature android:name="android.hardware.bluetooth" android:required="false" />
<uses-feature android:name="com.sec.feature.spen_usp" android:required="false"/>
<uses-sdk android:targetSdkVersion="21" android:minSdkVersion="9"
tools:overrideLibrary="com.getkeepsafe.taptargetview"/>
<supports-screens android:resizeable="true" android:smallScreens="true" android:normalScreens="true" android:largeScreens="true"
android:xlargeScreens="true" android:anyDensity="true" />

View file

@ -19,12 +19,12 @@
android:layout_width="match_parent"
android:layout_height="200dp" />
<!-- android:background="@drawable/quick_action_controls_background" -->
<LinearLayout
android:id="@+id/controls"
android:layout_width="match_parent"
android:layout_height="24dp"
android:orientation="horizontal">
android:orientation="horizontal"
android:background="@drawable/quick_action_controls_background">
<ImageButton
android:id="@+id/btnPrev"

View file

@ -19,12 +19,12 @@
android:layout_width="match_parent"
android:layout_height="200dp" />
<!-- android:background="@drawable/quick_action_controls_background" -->
<LinearLayout
android:id="@+id/controls"
android:layout_width="match_parent"
android:layout_height="48dp"
android:orientation="horizontal">
android:orientation="horizontal"
android:background="@drawable/quick_action_controls_background">
<ImageButton
android:id="@+id/btnPrev"

View file

@ -2528,6 +2528,8 @@ If you need help with OsmAnd application, please contact our support team: suppo
<string name="quick_action_map_overlay_title">Map overlays</string>
<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>

View file

@ -168,6 +168,8 @@ public class QuickActionFactory {
if (OsmandPlugin.getEnabledPlugin(OsmandRasterMapsPlugin.class) != null) {
quickActions.add(new MapSourceAction());
quickActions.add(new MapOverlayAction());
quickActions.add(new MapUnderlayAction());
}
QuickAction favorites = new ShowHideFavoritesAction();
@ -238,6 +240,12 @@ public class QuickActionFactory {
case MapSourceAction.TYPE:
return new MapSourceAction();
case MapOverlayAction.TYPE:
return new MapOverlayAction();
case MapUnderlayAction.TYPE:
return new MapUnderlayAction();
default:
return new QuickAction();
}
@ -292,6 +300,12 @@ public class QuickActionFactory {
case MapSourceAction.TYPE:
return new MapSourceAction(quickAction);
case MapOverlayAction.TYPE:
return new MapOverlayAction(quickAction);
case MapUnderlayAction.TYPE:
return new MapUnderlayAction(quickAction);
default:
return quickAction;
}
@ -544,11 +558,15 @@ public class QuickActionFactory {
@Override
public void geocodingDone(String address) {
progressDialog.dismiss();
activity.getContextMenu().getFavoritePointEditor().add(latLon, address, "",
getParams().get(KEY_CATEGORY_NAME),
Integer.valueOf(getParams().get(KEY_CATEGORY_COLOR)),
!Boolean.valueOf(getParams().get(KEY_DIALOG)));
if (progressDialog != null) progressDialog.dismiss();
if (activity != null) {
activity.getContextMenu().getFavoritePointEditor().add(latLon, address, "",
getParams().get(KEY_CATEGORY_NAME),
Integer.valueOf(getParams().get(KEY_CATEGORY_COLOR)),
!Boolean.valueOf(getParams().get(KEY_DIALOG)));
}
}
}, null);
@ -788,12 +806,14 @@ public class QuickActionFactory {
String filtersId = getParams().get(KEY_FILTERS);
Collections.addAll(filters, filtersId.split(","));
if (app.getPoiFilters() == null) return super.getIconRes();
PoiUIFilter filter = app.getPoiFilters().getFilterById(filters.get(0));
Object res = filter.getIconResource();
if (filter == null) return super.getIconRes();
Object res = filter.getIconResource();
if (res instanceof String && RenderingIcons.containsBigIcon(res.toString())) {
return RenderingIcons.getBigIconResourceId(res.toString());
@ -818,8 +838,6 @@ public class QuickActionFactory {
} else pf.clearSelectedPoiFilters();
activity.getMapLayers().updateLayers(activity.getMapView());
}
@ -2167,27 +2185,64 @@ 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_OVERLAY.get(),
settings.MAP_OVERLAY.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_OVERLAY.set(nextSource.first);
settings.MAP_OVERLAY_PREVIOUS.set(nextSource.first);
plugin.updateMapLayers(activity.getMapView(), settings.MAP_OVERLAY, activity.getMapLayers());
Toast.makeText(activity, activity.getString(R.string.quick_action_map_overlay_switch, nextSource.second), Toast.LENGTH_SHORT).show();
}
}
@Override
@ -2216,12 +2271,39 @@ 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();
}
};
}
}
public static class MapUnderlayAction extends SwitchableAction<Pair<String, String>> {
public static final int TYPE = 16;
@ -2238,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
@ -2287,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();
}
};
}
@ -2500,7 +2646,15 @@ public class QuickActionFactory {
@Override
public boolean fillParams(View root, MapActivity activity) {
return !getParams().isEmpty() && (getParams().get(getListKey()) != null || !getParams().get(getListKey()).isEmpty());
final RecyclerView list = (RecyclerView) root.findViewById(R.id.list);
final Adapter adapter = (Adapter) list.getAdapter();
boolean hasParams = adapter.itemsList != null && !adapter.itemsList.isEmpty();
if (hasParams) saveListToParams(adapter.itemsList);
return hasParams;
}
protected class Adapter extends RecyclerView.Adapter<Adapter.ItemHolder> implements QuickActionItemTouchHelperCallback.OnItemMoveCallback {
@ -2543,7 +2697,7 @@ public class QuickActionFactory {
String oldTitle = getTitle(itemsList);
String defaultName = holder.handleView.getContext().getString(getNameRes());
deleteItem(position);
deleteItem(holder.getAdapterPosition());
if (oldTitle.equals(title.getText().toString()) || title.getText().toString().equals(defaultName)) {
@ -2561,12 +2715,11 @@ public class QuickActionFactory {
public void deleteItem(int position) {
if (position == -1)
if (position == -1) {
return;
}
itemsList.remove(position);
saveListToParams(itemsList);
notifyItemRemoved(position);
}
@ -2575,8 +2728,6 @@ public class QuickActionFactory {
if (!itemsList.containsAll(data)) {
itemsList.addAll(data);
saveListToParams(itemsList);
notifyDataSetChanged();
}
}
@ -2591,7 +2742,6 @@ public class QuickActionFactory {
int oldSize = itemsList.size();
itemsList.add(item);
saveListToParams(itemsList);
notifyItemRangeInserted(oldSize, itemsList.size() - oldSize);
if (oldTitle.equals(title.getText().toString()) || title.getText().toString().equals(defaultName)) {
@ -2645,7 +2795,6 @@ public class QuickActionFactory {
@Override
public void onViewDropped(RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder) {
saveListToParams(itemsList);
}
public class ItemHolder extends RecyclerView.ViewHolder {

View file

@ -18,6 +18,7 @@ import com.getkeepsafe.taptargetview.TapTargetView;
import net.osmand.data.LatLon;
import net.osmand.data.RotatedTileBox;
import net.osmand.plus.OsmAndLocationProvider;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.OsmandSettings;
import net.osmand.plus.R;
@ -113,7 +114,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 +122,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,13 +200,17 @@ public class MapQuickActionLayer extends OsmandMapLayer implements QuickActionRe
previousMapPosition = view.getMapPosition();
view.setMapPosition(OsmandSettings.BOTTOM_CONSTANT);
MapContextMenu menu = mapActivity.getContextMenu();
LatLon ll = menu.isActive() && tileBox.containsLatLon(menu.getLatLon()) ? menu.getLatLon() : tileBox.getCenterLatLon();
Boolean isFollowPoint = isFolowPoint(tileBox, menu);
menu.updateMapCenter(null);
menu.close();
RotatedTileBox rb = new RotatedTileBox(tileBox);
// tileBox.setCenterLocation(0.5f, 0.75f);
if (!isFollowPoint && previousMapPosition != OsmandSettings.BOTTOM_CONSTANT)
rb.setCenterLocation(0.5f, 0.15f);
rb.setLatLonCenter(ll.getLatitude(), ll.getLongitude());
double lat = rb.getLatFromPixel(tileBox.getCenterPixelX(), tileBox.getCenterPixelY());
double lon = rb.getLonFromPixel(tileBox.getCenterPixelX(), tileBox.getCenterPixelY());
@ -230,8 +231,26 @@ public class MapQuickActionLayer extends OsmandMapLayer implements QuickActionRe
view.refreshMap();
}
private boolean isFolowPoint(RotatedTileBox tileBox, MapContextMenu menu) {
return OsmAndLocationProvider.isLocationPermissionAvailable(mapActivity) &&
mapActivity.getMapViewTrackingUtilities().isMapLinkedToLocation() ||
menu.isActive() && tileBox.containsLatLon(menu.getLatLon()); // remove if not to folow if there is selected point on map
}
private void quitMovingMarker() {
RotatedTileBox tileBox = mapActivity.getMapView().getCurrentRotatedTileBox();
if (!isFolowPoint(tileBox, mapActivity.getContextMenu()) && previousMapPosition != OsmandSettings.BOTTOM_CONSTANT){
RotatedTileBox rb = tileBox.copy();
rb.setCenterLocation(0.5f, 0.5f);
LatLon ll = tileBox.getCenterLatLon();
rb.setLatLonCenter(ll.getLatitude(), ll.getLongitude());
double lat = tileBox.getLatFromPixel(rb.getCenterPixelX(), rb.getCenterPixelY());
double lon = tileBox.getLonFromPixel(rb.getCenterPixelX(), rb.getCenterPixelY());
view.setLatLon(lat, lon);
}
view.setMapPosition(previousMapPosition);
inChangeMarkerPositionMode = false;
mark(View.VISIBLE, R.id.map_ruler_layout,
R.id.map_left_widgets_panel, R.id.map_right_widgets_panel, R.id.map_center_info);