Exemplo n.º 1
0
  private NextTurnInfoControl createNextInfoControl() {
    final RoutingHelper routingHelper = routeLayer.getHelper();
    final NextTurnInfoControl nextTurnInfo =
        new NextTurnInfoControl(map, paintText, paintSubText, false) {
          NextDirectionInfo calc1 = new NextDirectionInfo();
          TurnType straight = TurnType.valueOf(TurnType.C, true);

          @Override
          public boolean updateInfo() {
            boolean visible = false;
            if (routeLayer != null
                && routingHelper.isRouterEnabled()
                && routingHelper.isFollowingMode()) {
              makeUturnWhenPossible = routingHelper.makeUturnWhenPossible();
              if (makeUturnWhenPossible) {
                visible = true;
                turnImminent = 1;
                turnType =
                    TurnType.valueOf(TurnType.TU, view.getSettings().LEFT_SIDE_NAVIGATION.get());
                TurnPathHelper.calcTurnPath(pathForTurn, turnType, pathTransform);
                invalidate();
              } else {
                NextDirectionInfo r = routingHelper.getNextRouteDirectionInfo(calc1, false);
                boolean showStraight = false;
                if (r != null) {
                  RouteDirectionInfo toShowWithoutSpeak = r.directionInfo;
                  if (r.imminent >= 0 && r.imminent < 2) {
                    // next turn is very close (show it)
                  } else {
                    r = routingHelper.getNextRouteDirectionInfo(calc1, true);
                    if (calc1.directionInfo != toShowWithoutSpeak) {
                      // show straight and grey because it is not the closest turn
                      showStraight = r.imminent == -1;
                    }
                  }
                }
                if (r != null && r.distanceTo > 0) {
                  visible = true;
                  if (r.directionInfo == null) {
                    if (turnType != null) {
                      turnType = null;
                      invalidate();
                    }
                  } else if (!Algoritms.objectEquals(
                      turnType, showStraight ? straight : r.directionInfo.getTurnType())) {
                    turnType = showStraight ? straight : r.directionInfo.getTurnType();
                    TurnPathHelper.calcTurnPath(pathForTurn, turnType, pathTransform);
                    if (turnType.getExitOut() > 0) {
                      exitOut = turnType.getExitOut() + ""; // $NON-NLS-1$
                    } else {
                      exitOut = null;
                    }
                    invalidate();
                  }
                  if (distChanged(r.distanceTo, nextTurnDirection)) {
                    invalidate();
                    nextTurnDirection = r.distanceTo;
                  }
                  if (turnImminent != r.imminent) {
                    turnImminent = r.imminent;
                    invalidate();
                  }
                }
              }
            }
            updateVisibility(visible);
            return true;
          }
        };
    nextTurnInfo.setOnClickListener(
        new View.OnClickListener() {
          //			int i = 0;
          //			boolean leftSide = false;
          @Override
          public void onClick(View v) {
            // for test rendering purposes
            //				final int l = TurnType.predefinedTypes.length;
            //				final int exits = 5;
            //				i++;
            //				if (i % (l + exits) >= l ) {
            //					nextTurnInfo.turnType = TurnType.valueOf("EXIT" + (i % (l + exits) - l + 1),
            // leftSide);
            //					float a = leftSide?  -180 + (i % (l + exits) - l + 1) * 50:  180 - (i % (l +
            // exits) - l + 1) * 50;
            //					nextTurnInfo.turnType.setTurnAngle(a < 0 ? a + 360 : a);
            //					nextTurnInfo.exitOut = (i % (l + exits) - l + 1)+"";
            //				} else {
            //					nextTurnInfo.turnType = TurnType.valueOf(TurnType.predefinedTypes[i %
            // (TurnType.predefinedTypes.length + exits)], leftSide);
            //					nextTurnInfo.exitOut = "";
            //				}
            //				nextTurnInfo.turnImminent = (nextTurnInfo.turnImminent + 1) % 3;
            //				nextTurnInfo.nextTurnDirection = 580;
            //				TurnPathHelper.calcTurnPath(nextTurnInfo.pathForTurn,
            // nextTurnInfo.turnType,nextTurnInfo.pathTransform);
            //				showMiniMap = true;
            nextTurnInfo.requestLayout();
            view.refreshMap();
          }
        });
    // initial state
    nextTurnInfo.setVisibility(View.GONE);
    return nextTurnInfo;
  }
Exemplo n.º 2
0
  private NextTurnInfoControl createNextNextInfoControl() {
    final RoutingHelper routingHelper = routeLayer.getHelper();
    final NextTurnInfoControl nextTurnInfo =
        new NextTurnInfoControl(map, paintSmallText, paintSmallSubText, true) {
          NextDirectionInfo calc1 = new NextDirectionInfo();

          @Override
          public boolean updateInfo() {
            boolean visible = false;
            if (routeLayer != null
                && routingHelper.isRouterEnabled()
                && routingHelper.isFollowingMode()) {
              boolean uturnWhenPossible = routingHelper.makeUturnWhenPossible();
              NextDirectionInfo r = routingHelper.getNextRouteDirectionInfo(calc1, false);
              if (!uturnWhenPossible) {
                if (r != null) {
                  // next turn is very close (show next next with false to speak)
                  if (r.imminent >= 0 && r.imminent < 2) {
                    r = routingHelper.getNextRouteDirectionInfoAfter(r, calc1, false);
                  } else {
                    r = routingHelper.getNextRouteDirectionInfo(calc1, true);
                    if (r != null) {
                      r = routingHelper.getNextRouteDirectionInfoAfter(r, calc1, true);
                    }
                  }
                }
              }
              if (r != null && r.distanceTo > 0) {
                visible = true;
                if (r == null || r.directionInfo == null) {
                  if (turnType != null) {
                    turnType = null;
                    invalidate();
                  }
                } else if (!Algoritms.objectEquals(turnType, r.directionInfo.getTurnType())) {
                  turnType = r.directionInfo.getTurnType();
                  TurnPathHelper.calcTurnPath(pathForTurn, turnType, pathTransform);
                  invalidate();
                }
                if (distChanged(r.distanceTo, nextTurnDirection)) {
                  invalidate();
                  nextTurnDirection = r.distanceTo;
                }
                int imminent = r.imminent;
                if (turnImminent != imminent) {
                  turnImminent = imminent;
                  invalidate();
                }
              }
            }
            updateVisibility(visible);

            return true;
          }
        };
    nextTurnInfo.setOnClickListener(
        new View.OnClickListener() {
          //			int i = 0;
          @Override
          public void onClick(View v) {
            // uncomment to test turn info rendering
            //				final int l = TurnType.predefinedTypes.length;
            //				final int exits = 5;
            //				i++;
            //				if (i % (l + exits) >= l ) {
            //					nextTurnInfo.turnType = TurnType.valueOf("EXIT" + (i % (l + exits) - l + 1),
            // true);
            //					nextTurnInfo.exitOut = (i % (l + exits) - l + 1)+"";
            //					float a = 180 - (i % (l + exits) - l + 1) * 50;
            //					nextTurnInfo.turnType.setTurnAngle(a < 0 ? a + 360 : a);
            //				} else {
            //					nextTurnInfo.turnType = TurnType.valueOf(TurnType.predefinedTypes[i %
            // (TurnType.predefinedTypes.length + exits)], true);
            //					nextTurnInfo.exitOut = "";
            //				}
            //				nextTurnInfo.turnImminent = (nextTurnInfo.turnImminent + 1) % 3;
            //				nextTurnInfo.nextTurnDirection = 580;
            //				TurnPathHelper.calcTurnPath(nextTurnInfo.pathForTurn,
            // nexsweepAngletTurnInfo.turnType,nextTurnInfo.pathTransform);
            //				showMiniMap = true;
            view.refreshMap();
          }
        });
    // initial state
    //		nextTurnInfo.setVisibility(View.GONE);
    return nextTurnInfo;
  }