Exemplo n.º 1
0
  /**
   * Sets ending point.
   *
   * <ul>
   *   <li>If {@code point} is the same as starting point &mdash; swap points if ending point is
   *       set, skip otherwise.
   *   <li>Set starting point to MyPosition if it was not set before.
   * </ul>
   *
   * Route starts to build if both points were set.
   *
   * @return {@code true} if the point was set.
   */
  @SuppressWarnings("Duplicates")
  public boolean setEndPoint(MapObject point) {
    mLogger.d("setEndPoint");

    if (MapObject.same(mEndPoint, point)) {
      if (mStartPoint == null) return setStartFromMyPosition();

      mLogger.d("setEndPoint: skip the same end point");
      return false;
    }

    if (point != null && point.sameAs(mStartPoint)) {
      if (mEndPoint == null) {
        mLogger.d("setEndPoint: skip because end point is empty");
        return false;
      }

      mLogger.d("setEndPoint: swap with starting point");
      mStartPoint = mEndPoint;
    }

    mEndPoint = point;

    if (mStartPoint == null) return setStartFromMyPosition();

    setPointsInternal();
    checkAndBuildRoute();
    return true;
  }
Exemplo n.º 2
0
  private boolean setStartFromMyPosition() {
    mLogger.d("setStartFromMyPosition");

    MapObject my = LocationHelper.INSTANCE.getMyPosition();
    if (my == null) {
      mLogger.d("setStartFromMyPosition: no my position - skip");

      if (mContainer != null) mContainer.updatePoints();

      setPointsInternal();
      return false;
    }

    return setStartPoint(my);
  }
Exemplo n.º 3
0
  public void start() {
    mLogger.d("start");

    if (!MapObject.isOfType(MapObject.MY_POSITION, mStartPoint)) {
      Statistics.INSTANCE.trackEvent(Statistics.EventName.ROUTING_START_SUGGEST_REBUILD);
      AlohaHelper.logClick(AlohaHelper.ROUTING_START_SUGGEST_REBUILD);
      suggestRebuildRoute();
      return;
    }

    MapObject my = LocationHelper.INSTANCE.getMyPosition();
    if (my == null) {
      mRoutingListener.onRoutingEvent(ResultCodesHelper.NO_POSITION, null);
      return;
    }

    mStartPoint = my;
    Statistics.INSTANCE.trackEvent(Statistics.EventName.ROUTING_START);
    AlohaHelper.logClick(AlohaHelper.ROUTING_START);
    setState(State.NAVIGATION);

    mContainer.showRoutePlan(false, null);
    mContainer.showNavigation(true);

    ThemeSwitcher.restart();

    Framework.nativeFollowRoute();
    LocationHelper.INSTANCE.restart();
  }
Exemplo n.º 4
0
  public void prepare(@Nullable MapObject startPoint, @Nullable MapObject endPoint) {
    mLogger.d("prepare (" + (endPoint == null ? "route)" : "p2p)"));

    if (!Config.isRoutingDisclaimerAccepted()) {
      showDisclaimer(startPoint, endPoint);
      return;
    }

    cancel();
    mStartPoint = startPoint;
    mEndPoint = endPoint;
    setState(State.PREPARE);

    if (mStartPoint != null && mEndPoint != null)
      mLastRouterType =
          Framework.nativeGetBestRouter(
              mStartPoint.getLat(), mStartPoint.getLon(),
              mEndPoint.getLat(), mEndPoint.getLon());
    Framework.nativeSetRouter(mLastRouterType);

    if (mContainer != null)
      mContainer.showRoutePlan(
          true,
          new Runnable() {
            @Override
            public void run() {
              if (mStartPoint == null || mEndPoint == null) updatePlan();
              else build();
            }
          });
  }
Exemplo n.º 5
0
  private void build() {
    mLogger.d("build");
    mUberRequestHandled = false;
    mLastBuildProgress = 0;
    mInternetConnected = ConnectionState.isConnected();

    if (mLastRouterType == Framework.ROUTER_TYPE_TAXI) {
      if (!mInternetConnected) {
        completeUberRequest();
        return;
      }
      requestUberInfo();
    }

    setBuildState(BuildState.BUILDING);
    updatePlan();

    Statistics.INSTANCE.trackRouteBuild(mLastRouterType, mStartPoint, mEndPoint);
    org.alohalytics.Statistics.logEvent(
        AlohaHelper.ROUTING_BUILD,
        new String[] {
          Statistics.EventParam.FROM, Statistics.getPointType(mStartPoint),
          Statistics.EventParam.TO, Statistics.getPointType(mEndPoint)
        });
    Framework.nativeBuildRoute(
        mStartPoint.getLat(), mStartPoint.getLon(), mEndPoint.getLat(), mEndPoint.getLon());
  }
Exemplo n.º 6
0
 void searchPoi(int slotId) {
   mLogger.d("searchPoi: " + slotId);
   Statistics.INSTANCE.trackEvent(Statistics.EventName.ROUTING_SEARCH_POINT);
   AlohaHelper.logClick(AlohaHelper.ROUTING_SEARCH_POINT);
   mWaitingPoiPickSlot = slotId;
   mContainer.showSearch();
   mContainer.updateMenu();
 }
Exemplo n.º 7
0
 /**
  * Called from the native code
  *
  * @param info this object contains information about Uber products
  */
 @MainThread
 private void onUberInfoReceived(@NonNull UberInfo info) {
   mUberPlanning = false;
   mLogger.d("onUberInfoReceived uberInfo = " + info);
   if (mLastRouterType == Framework.ROUTER_TYPE_TAXI && mContainer != null) {
     mContainer.onUberInfoReceived(info);
     completeUberRequest();
   }
 }
Exemplo n.º 8
0
  private void setBuildState(BuildState newState) {
    mLogger.d("[B] State: " + mState + ", BuildState: " + mBuildState + " -> " + newState);
    mBuildState = newState;

    if (mBuildState == BuildState.BUILT && !MapObject.isOfType(MapObject.MY_POSITION, mStartPoint))
      Framework.nativeDisableFollowing();

    if (mContainer != null) mContainer.updateMenu();
  }
Exemplo n.º 9
0
 /**
  * Called from the native code
  *
  * @param errorCode must match the one of the values in {@link
  *     com.mapswithme.maps.uber.Uber.ErrorCode}
  */
 @MainThread
 private void onUberError(@NonNull String errorCode) {
   mUberPlanning = false;
   Uber.ErrorCode code = Uber.ErrorCode.valueOf(errorCode);
   mLogger.e("onUberError error = " + code);
   if (mLastRouterType == Framework.ROUTER_TYPE_TAXI && mContainer != null) {
     mContainer.onUberError(code);
     completeUberRequest();
   }
 }
Exemplo n.º 10
0
  public boolean cancelPlanning() {
    mLogger.d("cancelPlanning");

    if (isPlanning()) {
      cancel();
      return true;
    }

    return false;
  }
Exemplo n.º 11
0
  public void setRouterType(@Framework.RouterType int router) {
    mLogger.d("setRouterType: " + mLastRouterType + " -> " + router);

    // Repeating tap on Uber icon should trigger the route building always,
    // because it may be "No internet connection, try later" case
    if (router == mLastRouterType && router != Framework.ROUTER_TYPE_TAXI) return;

    mLastRouterType = router;
    Framework.nativeSetRouter(router);

    if (mStartPoint != null && mEndPoint != null) build();
  }
Exemplo n.º 12
0
  void swapPoints() {
    mLogger.d("swapPoints");

    MapObject point = mStartPoint;
    mStartPoint = mEndPoint;
    mEndPoint = point;

    Statistics.INSTANCE.trackEvent(Statistics.EventName.ROUTING_SWAP_POINTS);
    AlohaHelper.logClick(AlohaHelper.ROUTING_SWAP_POINTS);

    setPointsInternal();
    checkAndBuildRoute();
  }
Exemplo n.º 13
0
  public boolean cancel() {
    if (isPlanning()) {
      mLogger.d("cancel: planning");

      cancelInternal();
      if (mContainer != null) mContainer.showRoutePlan(false, null);
      return true;
    }

    if (isNavigating()) {
      mLogger.d("cancel: navigating");

      cancelInternal();
      if (mContainer != null) {
        mContainer.showNavigation(false);
        mContainer.updateMenu();
      }
      return true;
    }

    mLogger.d("cancel: none");
    return false;
  }
Exemplo n.º 14
0
  private void cancelInternal() {
    mLogger.d("cancelInternal");

    mStartPoint = null;
    mEndPoint = null;
    setPointsInternal();
    mWaitingPoiPickSlot = NO_SLOT;
    mUberRequestHandled = false;

    setBuildState(BuildState.NONE);
    setState(State.NONE);

    ThemeSwitcher.restart();
    Framework.nativeCloseRouting();
    LocationHelper.INSTANCE.restart();
  }
Exemplo n.º 15
0
        @Override
        public void onRoutingEvent(final int resultCode, @Nullable final String[] missingMaps) {
          mLogger.d("onRoutingEvent(resultCode: " + resultCode + ")");

          UiThread.run(
              new Runnable() {
                @Override
                public void run() {
                  mLastResultCode = resultCode;
                  mLastMissingMaps = missingMaps;
                  mContainsCachedResult = true;

                  if (mLastResultCode == ResultCodesHelper.NO_ERROR) {
                    mCachedRoutingInfo = Framework.nativeGetRouteFollowingInfo();
                    setBuildState(BuildState.BUILT);
                    mLastBuildProgress = 100;
                  }

                  processRoutingEvent();
                }
              });
        }
Exemplo n.º 16
0
  private void setState(State newState) {
    mLogger.d("[S] State: " + mState + " -> " + newState + ", BuildState: " + mBuildState);
    mState = newState;

    if (mContainer != null) mContainer.updateMenu();
  }