Ejemplo n.º 1
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();
            }
          });
  }
Ejemplo n.º 2
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;
  }
Ejemplo n.º 3
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());
  }
Ejemplo n.º 4
0
 @NonNull
 UberLinks getUberLink(@NonNull String productId) {
   return Uber.nativeGetUberLinks(
       productId,
       mStartPoint.getLat(),
       mStartPoint.getLon(),
       mEndPoint.getLat(),
       mEndPoint.getLon());
 }
Ejemplo n.º 5
0
  private void setPointsInternal() {
    if (mStartPoint == null) Framework.nativeSetRouteStartPoint(0.0, 0.0, false);
    else
      Framework.nativeSetRouteStartPoint(
          mStartPoint.getLat(),
          mStartPoint.getLon(),
          !MapObject.isOfType(MapObject.MY_POSITION, mStartPoint));

    if (mEndPoint == null) Framework.nativeSetRouteEndPoint(0.0, 0.0, false);
    else Framework.nativeSetRouteEndPoint(mEndPoint.getLat(), mEndPoint.getLon(), true);
  }
Ejemplo n.º 6
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();
  }
Ejemplo n.º 7
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();
  }
Ejemplo n.º 8
0
  private void suggestRebuildRoute() {
    final AlertDialog.Builder builder =
        new AlertDialog.Builder(mContainer.getActivity())
            .setMessage(R.string.p2p_reroute_from_current)
            .setCancelable(false)
            .setNegativeButton(R.string.cancel, null);

    TextView titleView =
        (TextView)
            View.inflate(mContainer.getActivity(), R.layout.dialog_suggest_reroute_title, null);
    titleView.setText(R.string.p2p_only_from_current);
    builder.setCustomTitle(titleView);

    if (MapObject.isOfType(MapObject.MY_POSITION, mEndPoint)) {
      builder.setPositiveButton(
          R.string.ok,
          new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
              swapPoints();
            }
          });
    } else {
      if (LocationHelper.INSTANCE.getMyPosition() == null)
        builder.setMessage(null).setNegativeButton(null, null);

      builder.setPositiveButton(
          R.string.ok,
          new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
              setStartFromMyPosition();
            }
          });
    }

    builder.show();
  }
Ejemplo n.º 9
0
 private void requestUberInfo() {
   mUberPlanning = true;
   Uber.nativeRequestUberProducts(
       mStartPoint.getLat(), mStartPoint.getLon(), mEndPoint.getLat(), mEndPoint.getLon());
   if (mContainer != null) mContainer.updateBuildProgress(0, mLastRouterType);
 }