diff --git a/android/src/com/mapswithme/maps/bookmarks/data/MapObject.java b/android/src/com/mapswithme/maps/bookmarks/data/MapObject.java index 15c0e7ef30..04ea86924f 100644 --- a/android/src/com/mapswithme/maps/bookmarks/data/MapObject.java +++ b/android/src/com/mapswithme/maps/bookmarks/data/MapObject.java @@ -180,6 +180,11 @@ public class MapObject implements Parcelable addMetadata(types[i], values[i]); } + public boolean hasPhoneNumber() + { + return !TextUtils.isEmpty(getMetadata(Metadata.MetadataType.FMD_PHONE_NUMBER)); + } + public static boolean isOfType(@MapObjectType int type, MapObject object) { return object != null && object.getMapObjectType() == type; diff --git a/android/src/com/mapswithme/maps/routing/RoutingController.java b/android/src/com/mapswithme/maps/routing/RoutingController.java index dd96affceb..6856dc837f 100644 --- a/android/src/com/mapswithme/maps/routing/RoutingController.java +++ b/android/src/com/mapswithme/maps/routing/RoutingController.java @@ -358,6 +358,9 @@ public class RoutingController mLastRouterType = routerType; Framework.nativeSetRouter(mLastRouterType); + if (mStartPoint != null || mEndPoint != null) + setPointsInternal(); + if (mContainer != null) mContainer.showRoutePlan(true, new Runnable() { diff --git a/android/src/com/mapswithme/maps/widget/placepage/PlacePageButtons.java b/android/src/com/mapswithme/maps/widget/placepage/PlacePageButtons.java index 2ad4d585fb..2c1be0cbdd 100644 --- a/android/src/com/mapswithme/maps/widget/placepage/PlacePageButtons.java +++ b/android/src/com/mapswithme/maps/widget/placepage/PlacePageButtons.java @@ -17,6 +17,7 @@ import java.util.List; import com.mapswithme.maps.MwmApplication; import com.mapswithme.maps.R; +import com.mapswithme.maps.routing.RoutingController; import com.mapswithme.util.BottomSheetHelper; import com.mapswithme.util.ThemeUtils; @@ -151,6 +152,20 @@ final class PlacePageButtons { return R.drawable.bs_ic_more; } + }, + CALL + { + @Override + int getTitle() + { + return R.string.placepage_call_button; + } + + @Override + int getIcon() + { + return R.drawable.ic_phone; + } }; abstract @StringRes int getTitle(); @@ -185,11 +200,30 @@ final class PlacePageButtons int to = res.indexOf(Item.ROUTE_TO); if (to > from && to >= MAX_BUTTONS) Collections.swap(res, from, to); + + preserveRoutingButtons(res, Item.CALL); + preserveRoutingButtons(res, Item.BOOKING); } return res; } + private void preserveRoutingButtons(@NonNull List items, @NonNull Item itemToShift) + { + if (!RoutingController.get().isNavigating() && !RoutingController.get().isPlanning()) + return; + + int pos = items.indexOf(itemToShift); + if (pos > -1) + { + items.remove(pos); + items.add(MAX_BUTTONS, itemToShift); + int to = items.indexOf(Item.ROUTE_TO); + items.remove(Item.ROUTE_FROM); + items.add(to + 1, Item.ROUTE_FROM); + } + } + private void showPopup(final List buttons) { BottomSheetHelper.Builder bs = new BottomSheetHelper.Builder(mPlacePage.getActivity()); diff --git a/android/src/com/mapswithme/maps/widget/placepage/PlacePageView.java b/android/src/com/mapswithme/maps/widget/placepage/PlacePageView.java index c91d9fdc10..89f2b99ded 100644 --- a/android/src/com/mapswithme/maps/widget/placepage/PlacePageView.java +++ b/android/src/com/mapswithme/maps/widget/placepage/PlacePageView.java @@ -416,26 +416,38 @@ public class PlacePageView extends RelativeLayout break; case ROUTE_FROM: - if (RoutingController.get().setStartPoint(mMapObject)) + RoutingController controller = RoutingController.get(); + if (!controller.isPlanning()) + { + controller.prepare(mMapObject, null); hide(); + } + else if (controller.setStartPoint(mMapObject)) + { + hide(); + } break; - case ROUTE_TO: - if (RoutingController.get().isPlanning()) - { - if (RoutingController.get().setEndPoint(mMapObject)) - hide(); - } - else - { - getActivity().startLocationToPoint(Statistics.EventName.PP_ROUTE, AlohaHelper.PP_ROUTE, getMapObject()); - } - break; + case ROUTE_TO: + if (RoutingController.get().isPlanning()) + { + if (RoutingController.get().setEndPoint(mMapObject)) + hide(); + } + else + { + getActivity().startLocationToPoint(Statistics.EventName.PP_ROUTE, AlohaHelper.PP_ROUTE, getMapObject()); + } + break; - case BOOKING: - case OPENTABLE: - onSponsoredClick(true /* book */); - break; + case BOOKING: + case OPENTABLE: + onSponsoredClick(true /* book */); + break; + + case CALL: + Utils.callPhone(getContext(), mTvPhone.getText().toString()); + break; } } }); @@ -1147,18 +1159,16 @@ public class PlacePageView extends RelativeLayout } } + if (mMapObject.hasPhoneNumber()) + buttons.add(PlacePageButtons.Item.CALL); + buttons.add(PlacePageButtons.Item.BOOKMARK); - if (RoutingController.get().isPlanning()) + if (RoutingController.get().isPlanning() || showRoutingButton) { buttons.add(PlacePageButtons.Item.ROUTE_FROM); buttons.add(PlacePageButtons.Item.ROUTE_TO); } - else - { - if (showRoutingButton) - buttons.add(PlacePageButtons.Item.ROUTE_TO); - } buttons.add(PlacePageButtons.Item.SHARE); @@ -1307,15 +1317,7 @@ public class PlacePageView extends RelativeLayout refreshLatLon(); break; case R.id.ll__place_phone: - Intent intent = new Intent(Intent.ACTION_DIAL); - intent.setData(Uri.parse("tel:" + mTvPhone.getText())); - try - { - getContext().startActivity(intent); - } catch (ActivityNotFoundException e) - { - AlohaHelper.logException(e); - } + Utils.callPhone(getContext(), mTvPhone.getText().toString()); break; case R.id.ll__place_website: followUrl(mTvWebsite.getText().toString()); @@ -1330,9 +1332,7 @@ public class PlacePageView extends RelativeLayout showBigDirection(); break; case R.id.ll__place_email: - intent = new Intent(Intent.ACTION_SENDTO); - intent.setData(Utils.buildMailUri(mTvEmail.getText().toString(), "", "")); - getContext().startActivity(intent); + Utils.sendTo(getContext(), mTvEmail.getText().toString()); break; case R.id.tv__bookmark_edit: Bookmark bookmark = (Bookmark) mMapObject; diff --git a/android/src/com/mapswithme/util/Utils.java b/android/src/com/mapswithme/util/Utils.java index d6d3bed076..f39903d987 100644 --- a/android/src/com/mapswithme/util/Utils.java +++ b/android/src/com/mapswithme/util/Utils.java @@ -429,4 +429,25 @@ public class Utils } context.startActivity(intent); } + + public static void sendTo(@NonNull Context context, @NonNull String email) + { + Intent intent = new Intent(Intent.ACTION_SENDTO); + intent.setData(Utils.buildMailUri(email, "", "")); + context.startActivity(intent); + } + + public static void callPhone(@NonNull Context context, @NonNull String phone) + { + Intent intent = new Intent(Intent.ACTION_DIAL); + intent.setData(Uri.parse("tel:" + phone)); + try + { + context.startActivity(intent); + } + catch (ActivityNotFoundException e) + { + AlohaHelper.logException(e); + } + } }