Merge remote-tracking branch 'origin/master'

This commit is contained in:
Weblate 2015-03-26 22:25:57 +01:00
commit 4eab1fd6ec
6 changed files with 143 additions and 63 deletions

View file

@ -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)
@ -563,6 +579,21 @@ public class GeoPointParserUtil {
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 = {
"http://maps.yandex.ru/-/CVCw6M9g",
@ -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) {

View file

@ -6,6 +6,7 @@
<stroke android:width="@dimen/map_button_stroke" android:color="@color/map_widget_stroke" />
</shape></item>
<item><shape android:shape="rectangle">
<solid android:color="@color/color_transparent" />
<stroke android:width="@dimen/map_button_stroke" android:color="@color/map_widget_stroke" />
</shape></item>

View file

@ -7,6 +7,7 @@
<stroke android:color="@color/map_widget_stroke" android:width="@dimen/map_button_stroke"/>
</shape></item>
<item><shape android:shape="rectangle">
<solid android:color="@color/color_transparent" />
<corners
android:topRightRadius="@dimen/map_button_rect_rad"
android:bottomRightRadius="@dimen/map_button_rect_rad"

View file

@ -7,6 +7,7 @@
<stroke android:width="@dimen/map_button_stroke" android:color="@color/map_widget_stroke" />
</shape></item>
<item><shape android:shape="rectangle">
<solid android:color="@color/color_transparent" />
<corners android:radius="@dimen/map_button_rect_rad" />
<stroke android:width="@dimen/map_button_stroke" android:color="@color/map_widget_stroke" />
</shape></item>

View file

@ -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<TargetPoint> 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;
}
});

View file

@ -99,6 +99,7 @@ public class DashboardOnMap implements ObservableScrollViewCallbacks {
private View paddingView;
private int mFlexibleSpaceImageHeight;
private int mFlexibleBlurSpaceHeight;
private boolean portrait;
private WaypointDialogHelper waypointDialogHelper;
@ -135,9 +136,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);
@ -395,7 +397,9 @@ public class DashboardOnMap implements ObservableScrollViewCallbacks {
myLocation = mapActivity.getMyApplication().getLocationProvider().getLastKnownLocation();
mapActivity.getMapViewTrackingUtilities().setDashboard(this);
dashboardView.setVisibility(View.VISIBLE);
if(isActionButtonVisible()) {
actionButton.show();
}
updateDownloadBtn();
View listViewLayout = dashboardView.findViewById(R.id.dash_list_view_layout);
ScrollView scrollView = (ScrollView) dashboardView.findViewById(R.id.main_scroll);
@ -417,6 +421,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();
@ -759,36 +764,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));
}
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);
@ -804,12 +800,34 @@ 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() {