diff --git a/OsmAnd-java/src/net/osmand/util/GeoPointParserUtil.java b/OsmAnd-java/src/net/osmand/util/GeoPointParserUtil.java index 0a04e42028..545fd5c1c3 100644 --- a/OsmAnd-java/src/net/osmand/util/GeoPointParserUtil.java +++ b/OsmAnd-java/src/net/osmand/util/GeoPointParserUtil.java @@ -60,6 +60,8 @@ public class GeoPointParserUtil { String twoQueryParameters[] = { "geo:0,0?z=11&q=Lots+Of+Stuff", + "http://osmand.net/go?lat=34.99393&lon=-110.12345", + "http://www.osmand.net/go.html?lat=34.99393&lon=-110.12345", "http://download.osmand.net/go?lat=34.99393&lon=-110.12345", "http://download.osmand.net/go?lat=34.99393&lon=-110.12345#this+should+be+ignored", }; @@ -205,6 +207,31 @@ public class GeoPointParserUtil { actual = GeoPointParserUtil.parse(url); assertGeoPoint(actual, new GeoParsedPoint(dlat, dlon, z)); + // http://osmand.net/go?lat=34&lon=-106&z=11 + url = "http://www.osmand.net/go.html?lat=" + ilat + "&lon=" + ilon + "&z=" + z; + System.out.println("url: " + url); + actual = GeoPointParserUtil.parse(url); + assertGeoPoint(actual, new GeoParsedPoint(ilat, ilon, z)); + + // http://www.osmand.net/go?lat=34.99393&lon=-106.61568&z=11 + url = "http://www.osmand.net/go.html?lat=" + dlat + "&lon=" + dlon + "&z=" + z; + System.out.println("url: " + url); + actual = GeoPointParserUtil.parse(url); + assertGeoPoint(actual, new GeoParsedPoint(dlat, dlon, z)); + + // http://osmand.net/go?lat=34&lon=-106&z=11 + url = "http://osmand.net/go?lat=" + ilat + "&lon=" + ilon + "&z=" + z; + System.out.println("url: " + url); + actual = GeoPointParserUtil.parse(url); + assertGeoPoint(actual, new GeoParsedPoint(ilat, ilon, z)); + + // http://osmand.net/go?lat=34.99393&lon=-106.61568&z=11 + url = "http://osmand.net/go?lat=" + dlat + "&lon=" + dlon + "&z=" + z; + System.out.println("url: " + url); + actual = GeoPointParserUtil.parse(url); + assertGeoPoint(actual, new GeoParsedPoint(dlat, dlon, z)); + + // http://openstreetmap.org/#map=11/34/-106 z = 11; url = "http://openstreetmap.org/#map=" + z + "/" + ilat + "/" + ilon; @@ -326,17 +353,6 @@ public class GeoPointParserUtil { actual = GeoPointParserUtil.parse(url); assertGeoPoint(actual, new GeoParsedPoint(dlat, dlon, z)); - // http://www.google.com/maps/?q=loc:34,-106&z=11 - url = "http://www.google.com/maps/?q=loc:" + ilat + "," + ilon + "&z=" + z; - System.out.println("url: " + url); - actual = GeoPointParserUtil.parse(url); - assertGeoPoint(actual, new GeoParsedPoint(ilat, ilon, z)); - - // http://www.google.com/maps/?q=loc:34.99393,-106.61568&z=11 - url = "http://www.google.com/maps/?q=loc:" + dlat + "," + dlon + "&z=" + z; - System.out.println("url: " + url); - actual = GeoPointParserUtil.parse(url); - assertGeoPoint(actual, new GeoParsedPoint(dlat, dlon, z)); // whatsapp // http://maps.google.com/maps/q=loc:34,-106 (You) @@ -562,6 +578,21 @@ public class GeoPointParserUtil { throw new RuntimeException(u + " not parsable!"); System.out.println("Properly parsed as: " + actual.getGeoUriString()); } + + // http://www.google.com/maps/?q=loc:34,-106&z=11 + url = "http://www.google.com/maps/?q=loc:" + ilat + "," + ilon + "&z=" + z; + System.out.println("url: " + url); + actual = GeoPointParserUtil.parse(url); + // FIXME FAIL + assertGeoPoint(actual, new GeoParsedPoint(ilat, ilon, z)); + + // http://www.google.com/maps/?q=loc:34.99393,-106.61568&z=11 + url = "http://www.google.com/maps/?q=loc:" + dlat + "," + dlon + "&z=" + z; + System.out.println("url: " + url); + actual = GeoPointParserUtil.parse(url); + // FIXME FAIL + assertGeoPoint(actual, new GeoParsedPoint(dlat, dlon, z)); + // these URLs are not parsable, but should not crash or cause problems String[] unparsableUrls = { @@ -582,6 +613,8 @@ public class GeoPointParserUtil { throw new RuntimeException(u + " not parsable, but parse did not return null!"); System.out.println("Handled URL"); } + + } private static boolean areCloseEnough(double a, double b, long howClose) { diff --git a/OsmAnd/src/net/osmand/plus/dashboard/DashWaypointsFragment.java b/OsmAnd/src/net/osmand/plus/dashboard/DashWaypointsFragment.java index 015fda57d0..d4fc66e2e1 100644 --- a/OsmAnd/src/net/osmand/plus/dashboard/DashWaypointsFragment.java +++ b/OsmAnd/src/net/osmand/plus/dashboard/DashWaypointsFragment.java @@ -13,7 +13,10 @@ import net.osmand.plus.TargetPointsHelper.TargetPoint; import net.osmand.plus.activities.MapActivity; import net.osmand.plus.dialogs.DirectionsDialogs; import net.osmand.plus.dialogs.FavoriteDialogs; +import android.app.AlertDialog; import android.app.Dialog; +import android.app.AlertDialog.Builder; +import android.content.DialogInterface; import android.os.Bundle; import android.support.annotation.Nullable; import android.support.v7.widget.PopupMenu; @@ -95,12 +98,19 @@ public class DashWaypointsFragment extends DashLocationFragment { name.setText(PointDescription.getSimpleName(point, getActivity())); ImageButton options = ((ImageButton)view.findViewById(R.id.options)); options.setVisibility(View.VISIBLE); + final boolean optionsVisible = (SHOW_ALL && getMyApplication().getTargetPointsHelper().getIntermediatePoints().size() > 0); + options.setImageDrawable(getMyApplication().getIconsCache(). - getContentIcon(R.drawable.ic_overflow_menu_white)); + getContentIcon(optionsVisible? R.drawable.ic_overflow_menu_white : + R.drawable.ic_action_remove_dark)); options.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { - selectModel(point, view); + if(optionsVisible) { + selectTargetModel(point, view); + } else { + deletePointConfirm(point, view); + } } }); @@ -128,30 +138,47 @@ public class DashWaypointsFragment extends DashLocationFragment { } this.distances = distances; } - private void selectModel(final TargetPoint model, View v) { - boolean light = ((OsmandApplication) getActivity().getApplication()).getSettings().isLightContent(); - final PopupMenu optionsMenu = new PopupMenu(getActivity(), v); - DirectionsDialogs.setupPopUpMenuIcon(optionsMenu); - MenuItem - item = optionsMenu.getMenu().add( - R.string.shared_string_add_to_favorites).setIcon(getMyApplication().getIconsCache(). - getContentIcon(R.drawable.ic_action_fav_dark)); - item.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() { + + protected void deletePointConfirm(final TargetPoint point, View view) { + final boolean target = point == getMyApplication().getTargetPointsHelper().getPointToNavigate(); + Builder builder = new AlertDialog.Builder(view.getContext()); + // Stop the navigation + builder.setTitle(getString(R.string.clear_destination)); + builder.setMessage(getString(R.string.delete_target_point)); + builder.setPositiveButton(R.string.shared_string_yes, new DialogInterface.OnClickListener() { @Override - public boolean onMenuItemClick(MenuItem item) { - Bundle args = new Bundle(); - Dialog dlg = FavoriteDialogs.createAddFavouriteDialog(getActivity(), args); - dlg.show(); - FavoriteDialogs.prepareAddFavouriteDialog(getActivity(), dlg, args, model.getLatitude(), model.getLongitude(), - model.getOriginalPointDescription()); - return true; + public void onClick(DialogInterface dialog, int which) { + getMyApplication().getTargetPointsHelper().removeWayPoint(true, target ? -1 : point.index); + setupTargets(); } }); - final boolean target = model == getMyApplication().getTargetPointsHelper().getPointToNavigate(); + builder.setNegativeButton(R.string.shared_string_no, null); + builder.show(); + } + + private void selectTargetModel(final TargetPoint point, final View view) { + final PopupMenu optionsMenu = new PopupMenu(getActivity(), view); + DirectionsDialogs.setupPopUpMenuIcon(optionsMenu); + MenuItem item; +// item = optionsMenu.getMenu().add( +// R.string.shared_string_add_to_favorites).setIcon(getMyApplication().getIconsCache(). +// getContentIcon(R.drawable.ic_action_fav_dark)); +// item.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() { +// @Override +// public boolean onMenuItemClick(MenuItem item) { +// Bundle args = new Bundle(); +// Dialog dlg = FavoriteDialogs.createAddFavouriteDialog(getActivity(), args); +// dlg.show(); +// FavoriteDialogs.prepareAddFavouriteDialog(getActivity(), dlg, args, model.getLatitude(), model.getLongitude(), +// model.getOriginalPointDescription()); +// return true; +// } +// }); + final boolean target = point == getMyApplication().getTargetPointsHelper().getPointToNavigate(); if(SHOW_ALL && getMyApplication().getTargetPointsHelper().getIntermediatePoints().size() > 0) { final List allTargets = getMyApplication().getTargetPointsHelper().getIntermediatePointsWithTarget(); - if (model.index > 0 || target) { - final int ind = target ? allTargets.size() - 1 : model.index; + if (point.index > 0 || target) { + final int ind = target ? allTargets.size() - 1 : point.index; item = optionsMenu.getMenu().add(R.string.waypoint_visit_before) .setIcon(getMyApplication().getIconsCache(). getContentIcon(R.drawable.ic_action_up_dark)); @@ -173,8 +200,8 @@ public class DashWaypointsFragment extends DashLocationFragment { item.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() { @Override public boolean onMenuItemClick(MenuItem item) { - TargetPoint remove = allTargets.remove(model.index + 1); - allTargets.add(model.index, remove); + TargetPoint remove = allTargets.remove(point.index + 1); + allTargets.add(point.index, remove); getMyApplication().getTargetPointsHelper().reorderAllTargetPoints(allTargets, true); setupTargets(); return true; @@ -184,12 +211,11 @@ public class DashWaypointsFragment extends DashLocationFragment { } item = optionsMenu.getMenu().add( R.string.shared_string_delete).setIcon(getMyApplication().getIconsCache(). - getContentIcon(R.drawable.ic_action_delete_dark)); + getContentIcon(R.drawable.ic_action_remove_dark)); item.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() { @Override public boolean onMenuItemClick(MenuItem item) { - getMyApplication().getTargetPointsHelper().removeWayPoint(true, target ? -1 : model.index); - setupTargets(); + deletePointConfirm(point, view); return true; } }); diff --git a/OsmAnd/src/net/osmand/plus/dashboard/DashboardOnMap.java b/OsmAnd/src/net/osmand/plus/dashboard/DashboardOnMap.java index 57b3d8ab95..b1ba7082c5 100644 --- a/OsmAnd/src/net/osmand/plus/dashboard/DashboardOnMap.java +++ b/OsmAnd/src/net/osmand/plus/dashboard/DashboardOnMap.java @@ -35,7 +35,6 @@ import android.annotation.SuppressLint; import android.app.Activity; import android.content.Context; import android.content.Intent; -import android.graphics.Color; import android.graphics.drawable.Drawable; import android.os.Build; import android.support.v4.app.Fragment; @@ -99,6 +98,7 @@ public class DashboardOnMap implements ObservableScrollViewCallbacks { private View paddingView; private int mFlexibleSpaceImageHeight; private int mFlexibleBlurSpaceHeight; + private boolean portrait; private WaypointDialogHelper waypointDialogHelper; @@ -135,9 +135,10 @@ public class DashboardOnMap implements ObservableScrollViewCallbacks { toolbar = ((Toolbar) dashboardView.findViewById(R.id.toolbar)); ObservableScrollView scrollView = ((ObservableScrollView) dashboardView.findViewById(R.id.main_scroll)); listView = (ListView) dashboardView.findViewById(R.id.dash_list_view); - scrollView.setScrollViewCallbacks(this); gradientToolbar = mapActivity.getResources().getDrawable(R.drawable.gradient_toolbar).mutate(); if (ScreenOrientationHelper.isOrientationPortrait(mapActivity)) { + this.portrait = true; + scrollView.setScrollViewCallbacks(this); ((ObservableListView) listView).setScrollViewCallbacks(this); mFlexibleSpaceImageHeight = mapActivity.getResources().getDimensionPixelSize( R.dimen.dashboard_map_top_padding); @@ -390,7 +391,9 @@ public class DashboardOnMap implements ObservableScrollViewCallbacks { myLocation = mapActivity.getMyApplication().getLocationProvider().getLastKnownLocation(); mapActivity.getMapViewTrackingUtilities().setDashboard(this); dashboardView.setVisibility(View.VISIBLE); - actionButton.show(); + if(isActionButtonVisible()) { + actionButton.show(); + } updateDownloadBtn(); View listViewLayout = dashboardView.findViewById(R.id.dash_list_view_layout); ScrollView scrollView = (ScrollView) dashboardView.findViewById(R.id.main_scroll); @@ -412,6 +415,7 @@ public class DashboardOnMap implements ObservableScrollViewCallbacks { updateListBackgroundHeight(); } } + mapActivity.findViewById(R.id.toolbar_back).setVisibility(isBackButtonVisible() ? View.VISIBLE : View.GONE); mapActivity.findViewById(R.id.MapHudButtonsOverlay).setVisibility(View.INVISIBLE); updateToolbarActions(); @@ -754,36 +758,27 @@ public class DashboardOnMap implements ObservableScrollViewCallbacks { @Override public void onScrollChanged(int scrollY, boolean firstScroll, boolean dragging) { // Translate list background - if (listBackgroundView != null) { + if (portrait) { setTranslationY(listBackgroundView, Math.max(0, -scrollY + mFlexibleSpaceImageHeight)); } - setTranslationY(toolbar, Math.min(0, -scrollY + mFlexibleSpaceImageHeight - mFlexibleBlurSpaceHeight)); + if (portrait) { + setTranslationY(toolbar, Math.min(0, -scrollY + mFlexibleSpaceImageHeight - mFlexibleBlurSpaceHeight)); + } + updateColorOfToolbar(scrollY); updateTopButton(scrollY); } + private boolean isActionButtonVisible() { + return visibleType == DashboardType.DASHBOARD || visibleType == DashboardType.LIST_MENU; + } + + private boolean isBackButtonVisible() { + return !(visibleType == DashboardType.DASHBOARD || visibleType == DashboardType.LIST_MENU); + } private void updateTopButton(int scrollY) { - if (listBackgroundView != null) { - float sh = mFlexibleSpaceImageHeight - mFlexibleBlurSpaceHeight; - float t = sh == 0 ? 1 : (1 - Math.max(0, -scrollY + sh) / sh); - t = Math.max(0, t); - int baseColor = 0xff8f00; - int alpha = (int) (t * 255); - // in order to have proper fast scroll down - int malpha = t == 1 ? alpha = 0 : alpha; - setAlpha(paddingView, malpha, baseColor); - if (listBackgroundView != null) { - setAlpha(dashboardView.findViewById(R.id.map_part_dashboard), malpha, baseColor); - } - gradientToolbar.setAlpha((int) ((1 - t) * 255)); - setAlpha(dashboardView, (int) (t * 128), 0); - if (t < 1) { - ((Toolbar) dashboardView.findViewById(R.id.toolbar)).setBackgroundDrawable(gradientToolbar); - } else { - ((Toolbar) dashboardView.findViewById(R.id.toolbar)).setBackgroundColor(0xff000000 | baseColor); - } - } - if (actionButton != null) { + + if (actionButton != null && portrait && isActionButtonVisible()) { double scale = mapActivity.getResources().getDisplayMetrics().density; int originalPosition = (int) (160 * scale); int minTop = (int) (65 * scale); @@ -798,13 +793,35 @@ public class DashboardOnMap implements ObservableScrollViewCallbacks { } } + + + private void updateColorOfToolbar(int scrollY) { + if (portrait) { + float sh = mFlexibleSpaceImageHeight - mFlexibleBlurSpaceHeight; + float t = sh == 0 ? 1 : (1 - Math.max(0, -scrollY + sh) / sh); + t = Math.max(0, t); + int baseColor = 0xff8f00; + int alpha = (int) (t * 255); + // in order to have proper fast scroll down + int malpha = t == 1 ? alpha = 0 : alpha; + setAlpha(paddingView, malpha, baseColor); + setAlpha(dashboardView.findViewById(R.id.map_part_dashboard), malpha, baseColor); + gradientToolbar.setAlpha((int) ((1 - t) * 255)); + setAlpha(dashboardView, (int) (t * 128), 0); + if (t < 1) { + ((Toolbar) dashboardView.findViewById(R.id.toolbar)).setBackgroundDrawable(gradientToolbar); + } else { + ((Toolbar) dashboardView.findViewById(R.id.toolbar)).setBackgroundColor(0xff000000 | baseColor); + } + } + } private void updateListAdapter(ArrayAdapter listAdapter, OnItemClickListener listener) { this.listAdapter = listAdapter; this.listAdapterOnClickListener = listener; if(this.listView != null) { listView.setAdapter(listAdapter); - if(listBackgroundView == null) { + if(!portrait) { listView.setOnItemClickListener(this.listAdapterOnClickListener); } else if (this.listAdapterOnClickListener != null) { listView.setOnItemClickListener(new OnItemClickListener() {