From b421c7432b94da29d7bff264bc7489cdb968aa42 Mon Sep 17 00:00:00 2001 From: Roman Romanov Date: Mon, 12 Dec 2016 13:44:51 +0400 Subject: [PATCH 1/4] [android] PP Action Bar buttons. --- .../maps/routing/RoutingController.java | 3 ++ .../maps/widget/placepage/PlacePageView.java | 47 ++++++++++--------- 2 files changed, 28 insertions(+), 22 deletions(-) diff --git a/android/src/com/mapswithme/maps/routing/RoutingController.java b/android/src/com/mapswithme/maps/routing/RoutingController.java index 83d0ecc16c..4c15241619 100644 --- a/android/src/com/mapswithme/maps/routing/RoutingController.java +++ b/android/src/com/mapswithme/maps/routing/RoutingController.java @@ -357,6 +357,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/PlacePageView.java b/android/src/com/mapswithme/maps/widget/placepage/PlacePageView.java index c91d9fdc10..992a0e331e 100644 --- a/android/src/com/mapswithme/maps/widget/placepage/PlacePageView.java +++ b/android/src/com/mapswithme/maps/widget/placepage/PlacePageView.java @@ -416,26 +416,34 @@ 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; } } }); @@ -1149,16 +1157,11 @@ public class PlacePageView extends RelativeLayout 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); From 6078611b4d87911b9a3d9cb6af9bd8b6c0f6a07b Mon Sep 17 00:00:00 2001 From: Roman Romanov Date: Thu, 29 Dec 2016 09:30:32 +0400 Subject: [PATCH 2/4] [android] Added call button. --- .../widget/placepage/PlacePageButtons.java | 14 +++++++++ .../maps/widget/placepage/PlacePageView.java | 31 +++++++++++++------ 2 files changed, 36 insertions(+), 9 deletions(-) diff --git a/android/src/com/mapswithme/maps/widget/placepage/PlacePageButtons.java b/android/src/com/mapswithme/maps/widget/placepage/PlacePageButtons.java index 2ad4d585fb..d6ee8600c4 100644 --- a/android/src/com/mapswithme/maps/widget/placepage/PlacePageButtons.java +++ b/android/src/com/mapswithme/maps/widget/placepage/PlacePageButtons.java @@ -151,6 +151,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(); diff --git a/android/src/com/mapswithme/maps/widget/placepage/PlacePageView.java b/android/src/com/mapswithme/maps/widget/placepage/PlacePageView.java index 992a0e331e..63927ef9be 100644 --- a/android/src/com/mapswithme/maps/widget/placepage/PlacePageView.java +++ b/android/src/com/mapswithme/maps/widget/placepage/PlacePageView.java @@ -444,6 +444,10 @@ public class PlacePageView extends RelativeLayout case OPENTABLE: onSponsoredClick(true /* book */); break; + + case CALL: + callPhone(); + break; } } }); @@ -1155,6 +1159,9 @@ public class PlacePageView extends RelativeLayout } } + if (!TextUtils.isEmpty(mMapObject.getMetadata(Metadata.MetadataType.FMD_PHONE_NUMBER))) + buttons.add(PlacePageButtons.Item.CALL); + buttons.add(PlacePageButtons.Item.BOOKMARK); if (RoutingController.get().isPlanning() || showRoutingButton) @@ -1310,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); - } + callPhone(); break; case R.id.ll__place_website: followUrl(mTvWebsite.getText().toString()); @@ -1333,6 +1332,7 @@ public class PlacePageView extends RelativeLayout showBigDirection(); break; case R.id.ll__place_email: + Intent intent; intent = new Intent(Intent.ACTION_SENDTO); intent.setData(Utils.buildMailUri(mTvEmail.getText().toString(), "", "")); getContext().startActivity(intent); @@ -1364,6 +1364,19 @@ public class PlacePageView extends RelativeLayout } } + private void callPhone() + { + Intent intent = new Intent(Intent.ACTION_DIAL); + intent.setData(Uri.parse("tel:" + mTvPhone.getText())); + try + { + getContext().startActivity(intent); + } catch (ActivityNotFoundException e) + { + AlohaHelper.logException(e); + } + } + private void followUrl(String url) { final Intent intent = new Intent(Intent.ACTION_VIEW); From 1b68b78ab3234a8f03c2a690364359ff34bc684b Mon Sep 17 00:00:00 2001 From: Roman Romanov Date: Fri, 30 Dec 2016 11:39:40 +0400 Subject: [PATCH 3/4] [android] Review fixes --- .../maps/bookmarks/data/MapObject.java | 5 ++++ .../widget/placepage/PlacePageButtons.java | 20 ++++++++++++++++ .../maps/widget/placepage/PlacePageView.java | 24 ++++--------------- android/src/com/mapswithme/util/Utils.java | 21 ++++++++++++++++ 4 files changed, 50 insertions(+), 20 deletions(-) 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/widget/placepage/PlacePageButtons.java b/android/src/com/mapswithme/maps/widget/placepage/PlacePageButtons.java index d6ee8600c4..8ab5faa618 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; @@ -199,11 +200,30 @@ final class PlacePageButtons int to = res.indexOf(Item.ROUTE_TO); if (to > from && to >= MAX_BUTTONS) Collections.swap(res, from, to); + + preserveNavigationButtons(res, Item.CALL); + preserveNavigationButtons(res, Item.BOOKING); } return res; } + private void preserveNavigationButtons(@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 63927ef9be..89f2b99ded 100644 --- a/android/src/com/mapswithme/maps/widget/placepage/PlacePageView.java +++ b/android/src/com/mapswithme/maps/widget/placepage/PlacePageView.java @@ -446,7 +446,7 @@ public class PlacePageView extends RelativeLayout break; case CALL: - callPhone(); + Utils.callPhone(getContext(), mTvPhone.getText().toString()); break; } } @@ -1159,7 +1159,7 @@ public class PlacePageView extends RelativeLayout } } - if (!TextUtils.isEmpty(mMapObject.getMetadata(Metadata.MetadataType.FMD_PHONE_NUMBER))) + if (mMapObject.hasPhoneNumber()) buttons.add(PlacePageButtons.Item.CALL); buttons.add(PlacePageButtons.Item.BOOKMARK); @@ -1317,7 +1317,7 @@ public class PlacePageView extends RelativeLayout refreshLatLon(); break; case R.id.ll__place_phone: - callPhone(); + Utils.callPhone(getContext(), mTvPhone.getText().toString()); break; case R.id.ll__place_website: followUrl(mTvWebsite.getText().toString()); @@ -1332,10 +1332,7 @@ public class PlacePageView extends RelativeLayout showBigDirection(); break; case R.id.ll__place_email: - Intent intent; - 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; @@ -1364,19 +1361,6 @@ public class PlacePageView extends RelativeLayout } } - private void callPhone() - { - Intent intent = new Intent(Intent.ACTION_DIAL); - intent.setData(Uri.parse("tel:" + mTvPhone.getText())); - try - { - getContext().startActivity(intent); - } catch (ActivityNotFoundException e) - { - AlohaHelper.logException(e); - } - } - private void followUrl(String url) { final Intent intent = new Intent(Intent.ACTION_VIEW); 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); + } + } } From b4191858e17c4b7a900b5d3ecfa6f618afe4bce8 Mon Sep 17 00:00:00 2001 From: Roman Romanov Date: Fri, 30 Dec 2016 14:15:11 +0400 Subject: [PATCH 4/4] [android] Review fixes --- .../mapswithme/maps/widget/placepage/PlacePageButtons.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/android/src/com/mapswithme/maps/widget/placepage/PlacePageButtons.java b/android/src/com/mapswithme/maps/widget/placepage/PlacePageButtons.java index 8ab5faa618..2c1be0cbdd 100644 --- a/android/src/com/mapswithme/maps/widget/placepage/PlacePageButtons.java +++ b/android/src/com/mapswithme/maps/widget/placepage/PlacePageButtons.java @@ -201,14 +201,14 @@ final class PlacePageButtons if (to > from && to >= MAX_BUTTONS) Collections.swap(res, from, to); - preserveNavigationButtons(res, Item.CALL); - preserveNavigationButtons(res, Item.BOOKING); + preserveRoutingButtons(res, Item.CALL); + preserveRoutingButtons(res, Item.BOOKING); } return res; } - private void preserveNavigationButtons(@NonNull List items, @NonNull Item itemToShift) + private void preserveRoutingButtons(@NonNull List items, @NonNull Item itemToShift) { if (!RoutingController.get().isNavigating() && !RoutingController.get().isPlanning()) return;