Ejemplo n.º 1
0
  public void updateApplicationModeSettings() {
    // update vector renderer
    RendererRegistry registry = app.getRendererRegistry();
    RenderingRulesStorage newRenderer = registry.getRenderer(settings.RENDERER.get());
    if (newRenderer == null) {
      newRenderer = registry.defaultRender();
    }
    if (registry.getCurrentSelectedRenderer() != newRenderer) {
      registry.setCurrentSelectedRender(newRenderer);
      app.getResourceManager().getRenderer().clearCache();
    }
    mapViewTrackingUtilities.updateSettings();
    app.getRoutingHelper().setAppMode(settings.getApplicationMode());
    if (mapLayers.getMapInfoLayer() != null) {
      mapLayers.getMapInfoLayer().recreateControls();
    }
    mapLayers.updateLayers(mapView);
    app.getDaynightHelper()
        .startSensorIfNeeded(
            new StateChangedListener<Boolean>() {

              @Override
              public void stateChanged(Boolean change) {
                getMapView().refreshMap(true);
              }
            });
    getMapView().refreshMap(true);
  }
Ejemplo n.º 2
0
    public boolean updateInfo(DrawSettings d) {
      String text = null;
      TurnType[] type = new TurnType[1];
      boolean showNextTurn = false;
      if (routingHelper != null && routingHelper.isRouteCalculated()) {
        if (routingHelper.isFollowingMode()) {
          if (settings.SHOW_STREET_NAME.get()) {
            text = routingHelper.getCurrentName(type);
            if (text == null) {
              text = "";
            }
          }
        } else {
          int di = MapRouteInfoMenu.getDirectionInfo();
          if (di >= 0
              && MapRouteInfoMenu.isControlVisible()
              && di < routingHelper.getRouteDirections().size()) {
            showNextTurn = true;
            RouteDirectionInfo next = routingHelper.getRouteDirections().get(di);
            type[0] = next.getTurnType();
            text =
                RoutingHelper.formatStreetName(
                    next.getStreetName(), next.getRef(), next.getDestinationName());
            //						if(next.distance > 0) {
            //							text += " " + OsmAndFormatter.getFormattedDistance(next.distance,
            // map.getMyApplication());
            //						}
            if (text == null) {
              text = "";
            }
          }
        }
      } else if (settings.getApplicationMode() != ApplicationMode.DEFAULT
          && map.getMapViewTrackingUtilities().isMapLinkedToLocation()
          && settings.SHOW_STREET_NAME.get()) {
        RouteDataObject rt = locationProvider.getLastKnownRouteSegment();
        if (rt != null) {
          text =
              RoutingHelper.formatStreetName(
                  rt.getName(settings.MAP_PREFERRED_LOCALE.get()),
                  rt.getRef(),
                  rt.getDestinationName(settings.MAP_PREFERRED_LOCALE.get()));
        }
        if (text == null) {
          text = "";
        }
      }
      if (!showNextTurn && updateWaypoint()) {
        updateVisibility(true);
        updateVisibility(addressText, false);
        updateVisibility(addressTextShadow, false);
      } else if (text == null) {
        updateVisibility(false);
      } else {
        updateVisibility(true);
        updateVisibility(waypointInfoBar, false);
        updateVisibility(addressText, true);
        updateVisibility(addressTextShadow, shadowRad > 0);
        boolean update = turnDrawable.setTurnType(type[0]);

        int h = addressText.getHeight() / 4 * 3;
        if (h != turnDrawable.getBounds().bottom) {
          turnDrawable.setBounds(0, 0, h, h);
        }
        if (update) {
          if (type[0] != null) {
            addressTextShadow.setCompoundDrawables(turnDrawable, null, null, null);
            addressTextShadow.setCompoundDrawablePadding(4);
            addressText.setCompoundDrawables(turnDrawable, null, null, null);
            addressText.setCompoundDrawablePadding(4);
          } else {
            addressTextShadow.setCompoundDrawables(null, null, null, null);
            addressText.setCompoundDrawables(null, null, null, null);
          }
        }
        if (!text.equals(addressText.getText().toString())) {
          if (!text.equals("")) {
            topBar.setContentDescription(text);
          } else {
            topBar.setContentDescription(
                map.getResources().getString(R.string.map_widget_top_text));
          }
          addressTextShadow.setText(text);
          addressText.setText(text);
          return true;
        }
      }
      return false;
    }
Ejemplo n.º 3
0
  private void updateControls(RotatedTileBox tileBox, DrawSettings nightMode) {
    boolean isNight = nightMode != null && nightMode.isNightMode();
    int shadw = isNight ? Color.TRANSPARENT : Color.WHITE;
    int textColor =
        isNight ? mapActivity.getResources().getColor(R.color.widgettext_night) : Color.BLACK;
    if (shadowColor != shadw) {
      shadowColor = shadw;
      // TODO
      // updatextColor(textColor, shadw, rulerControl, zoomControls, mapMenuControls);
    }
    boolean portrait = AndroidUiHelper.isOrientationPortrait(mapActivity);
    // default buttons
    boolean routePlanningMode = false;
    RoutingHelper rh = mapActivity.getRoutingHelper();
    if (rh.isRoutePlanningMode()) {
      routePlanningMode = true;
    } else if ((rh.isRouteCalculated() || rh.isRouteBeingCalculated()) && !rh.isFollowingMode()) {
      routePlanningMode = true;
    }
    boolean routeFollowingMode = !routePlanningMode && rh.isFollowingMode();
    boolean dialogOpened =
        optionsRouteControlDialog.isDialogVisible() || mapRouteInfoControlDialog.isDialogVisible();
    boolean showRouteCalculationControls =
        routePlanningMode
            || ((System.currentTimeMillis() - touchEvent < TIMEOUT_TO_SHOW_BUTTONS)
                && routeFollowingMode);
    boolean showMenuButton =
        (showRouteCalculationControls && portrait) || (!routeFollowingMode && !routePlanningMode);
    updateMyLocation(rh, dialogOpened);
    //		routePlanningBtn.setIconResId(routeFollowingMode ?	R.drawable.ic_action_gabout_dark :
    // R.drawable.map_directions	);
    //		routePlanningBtn.updateVisibility(showButtons && !routePlanningMode);
    routePlanningBtn.setIconResId(R.drawable.map_directions);
    routePlanningBtn.updateVisibility(!routeFollowingMode && !routePlanningMode);

    menuControl.updateVisibility(showMenuButton && !dialogOpened);
    mapZoomIn.updateVisibility(!dialogOpened);
    mapZoomOut.updateVisibility(!dialogOpened);
    compassHud.updateVisibility(!dialogOpened);
    layersHud.updateVisibility(!dialogOpened);

    if (routeFollowingMode || routePlanningMode) {
      mapAppModeShadow.setVisibility(View.GONE);
    } else {
      mapAppModeShadow.setVisibility(View.VISIBLE);
      if (!mapView.isZooming() || !OsmandPlugin.isDevelopment()) {
        zoomText.setVisibility(View.GONE);
        appModeIcon.setVisibility(View.VISIBLE);
        appModeIcon.setImageDrawable(
            app.getIconsCache()
                .getIcon(settings.getApplicationMode().getSmallIconDark(), !isNight));
      } else {
        zoomText.setVisibility(View.VISIBLE);
        appModeIcon.setVisibility(View.GONE);
        zoomText.setText(getZoomLevel(tileBox));
      }
    }
    int vis = showRouteCalculationControls ? View.VISIBLE : View.GONE;
    if (showRouteCalculationControls) {
      ((TextView) routeGoControl.iv).setTextColor(textColor);
      String text = portrait ? mapActivity.getString(R.string.shared_string_go) : "";
      if (startCounter > 0) {
        int get = (int) ((startCounter - System.currentTimeMillis()) / 1000l);
        text += " (" + get + ")";
      }
      ((TextView) routeGoControl.iv).setText(text);
    }

    if (routePreparationLayout.getVisibility() != vis) {
      routePreparationLayout.setVisibility(vis);
      mapDashControl.updateVisibility(showRouteCalculationControls && !portrait);
      mapRouteInfoControlDialog.setVisible(showRouteCalculationControls);
      if (showRouteCalculationControls) {
        if (!mapActivity.getRoutingHelper().isFollowingMode()
            && !mapActivity.getRoutingHelper().isPauseNavigation()) {
          startCounter();
        }
      } else {
        stopCounter();
      }
    }

    updateCompass(isNight);

    for (MapHudButton mc : controls) {
      mc.update(
          mapActivity.getMyApplication(), nightMode == null ? false : nightMode.isNightMode());
    }
  }
Ejemplo n.º 4
0
  @Override
  public boolean onPreferenceTreeClick(PreferenceScreen preferenceScreen, Preference preference) {
    // customize the sub-preference title according the selected profile
    String title = "";
    if (preference.getKey() != null
        && preference instanceof PreferenceScreen
        && SettingsActivity.SCREEN_ID_NAVIGATION_SETTINGS.equals(preference.getKey())) {
      final ApplicationMode appMode = osmandSettings.getApplicationMode();
      PreferenceScreen scr = (PreferenceScreen) preference;
      title = scr.getTitle().toString();
      if (title.startsWith("-")) {
        title = title.substring(1);
      }
      Builder builder = new AlertDialog.Builder(this);
      View view = getLayoutInflater().inflate(R.layout.navigate_mode, null);
      builder.setView(view);
      final AlertDialog dlg = builder.show();

      final Button[] buttons = new Button[ApplicationMode.values().length];
      buttons[ApplicationMode.CAR.ordinal()] = (Button) view.findViewById(R.id.CarButton);
      buttons[ApplicationMode.BICYCLE.ordinal()] = (Button) view.findViewById(R.id.BicycleButton);
      buttons[ApplicationMode.PEDESTRIAN.ordinal()] =
          (Button) view.findViewById(R.id.PedestrianButton);
      final Dialog scrDialog = scr.getDialog();
      final String tlt = "   " + title;
      for (int i = 0; i < buttons.length; i++) {
        if (buttons[i] != null) {
          final int ind = i;
          final Button b = buttons[i];
          b.setOnClickListener(
              new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                  ApplicationMode selected = ApplicationMode.values()[ind];
                  osmandSettings.APPLICATION_MODE.set(selected);
                  updateAllSettings();
                  scrDialog.setTitle(
                      tlt + " [" + selected.toHumanString(SettingsActivity.this) + "]");
                  dlg.dismiss();
                }
              });
        }
      }
      scrDialog.setTitle(tlt + " [" + appMode + "] ");
      scr.getDialog()
          .setOnDismissListener(
              new OnDismissListener() {
                @Override
                public void onDismiss(DialogInterface dialog) {
                  osmandSettings.APPLICATION_MODE.set(appMode);
                  updateAllSettings();
                }
              });
    } else if (preference instanceof PreferenceScreen) {
      final PreferenceScreen scr = (PreferenceScreen) preference;
      title = scr.getTitle().toString();
      scr.getDialog().setTitle("   " + title);
    }
    if (preference instanceof PreferenceScreen) {
      final PreferenceScreen scr = (PreferenceScreen) preference;
      CustomTitleBarView titleBar =
          new CustomTitleBarView(title, R.drawable.tab_settings_screen_icon, null) {
            @Override
            public void backPressed() {
              scr.getDialog().dismiss();
            }
          };

      View titleView = getLayoutInflater().inflate(titleBar.getTitleBarLayout(), null);
      titleBar.init(titleView);
      // View decorView = scr.getDialog().getWindow().getDecorView();
      // LinearLayout ll = new LinearLayout(titleView.getContext());
      // scr.getDialog().getWindow().setContentView(ll);
      View dv = scr.getDialog().getWindow().getDecorView();
      ListView ls = (ListView) dv.findViewById(android.R.id.list);
      if (ls != null) {
        ls.addFooterView(titleView);
      }

      // LayoutParams lp = new ViewGroup.LayoutParams(LayoutParams.WRAP_CONTENT,
      // LayoutParams.WRAP_CONTENT);
      // scr.getDialog().addContentView(titleView, lp);

      // ll.setOrientation(LinearLayout.VERTICAL);
      // ll.addView(titleView);
      // ll.addView(decorView);

    }

    if (preference == applicationDir) {
      return true;
    }
    return super.onPreferenceTreeClick(preferenceScreen, preference);
  }
Ejemplo n.º 5
0
  private boolean updateCurrentRouteStatus(Location currentLocation, float posTolerance) {
    List<Location> routeNodes = route.getImmutableAllLocations();
    int currentRoute = route.currentRoute;
    // 1. Try to proceed to next point using orthogonal distance (finding minimum orthogonal dist)
    while (currentRoute + 1 < routeNodes.size()) {
      double dist = currentLocation.distanceTo(routeNodes.get(currentRoute));
      if (currentRoute > 0) {
        dist =
            getOrthogonalDistance(
                currentLocation, routeNodes.get(currentRoute - 1), routeNodes.get(currentRoute));
      }
      boolean processed = false;
      // if we are still too far try to proceed many points
      // if not then look ahead only 3 in order to catch sharp turns
      boolean longDistance = dist >= 250;
      int newCurrentRoute =
          lookAheadFindMinOrthogonalDistance(
              currentLocation, routeNodes, currentRoute, longDistance ? 15 : 8);
      double newDist =
          getOrthogonalDistance(
              currentLocation,
              routeNodes.get(newCurrentRoute),
              routeNodes.get(newCurrentRoute + 1));
      if (longDistance) {
        if (newDist < dist) {
          if (log.isDebugEnabled()) {
            log.debug(
                "Processed by distance : (new) "
                    + newDist
                    + " (old) "
                    + dist); //$NON-NLS-1$//$NON-NLS-2$
          }
          processed = true;
        }
      } else if (newDist < dist || newDist < 10) {
        // newDist < 10 (avoid distance 0 till next turn)
        if (dist > posTolerance) {
          processed = true;
          if (log.isDebugEnabled()) {
            log.debug(
                "Processed by distance : " + newDist + " " + dist); // $NON-NLS-1$//$NON-NLS-2$
          }
        } else {
          // case if you are getting close to the next point after turn
          // but you have not yet turned (could be checked bearing)
          if (currentLocation.hasBearing() || lastFixedLocation != null) {
            float bearingToRoute = currentLocation.bearingTo(routeNodes.get(currentRoute));
            float bearingRouteNext =
                routeNodes.get(newCurrentRoute).bearingTo(routeNodes.get(newCurrentRoute + 1));
            float bearingMotion =
                currentLocation.hasBearing()
                    ? currentLocation.getBearing()
                    : lastFixedLocation.bearingTo(currentLocation);
            double diff = Math.abs(MapUtils.degreesDiff(bearingMotion, bearingToRoute));
            double diffToNext = Math.abs(MapUtils.degreesDiff(bearingMotion, bearingRouteNext));
            if (diff > diffToNext) {
              if (log.isDebugEnabled()) {
                log.debug("Processed point bearing deltas : " + diff + " " + diffToNext);
              }
              processed = true;
            }
          }
        }
      }
      if (processed) {
        // that node already passed
        route.updateCurrentRoute(newCurrentRoute + 1);
        currentRoute = newCurrentRoute + 1;
      } else {
        break;
      }
    }

    // 2. check if intermediate found
    if (route.getIntermediatePointsToPass() > 0
        && route.getDistanceToNextIntermediate(lastFixedLocation) < POSITION_TOLERANCE * 2) {
      showMessage(app.getString(R.string.arrived_at_intermediate_point));
      route.passIntermediatePoint();

      TargetPointsHelper targets = app.getTargetPointsHelper();
      List<String> ns = targets.getIntermediatePointNames();
      int toDel = targets.getIntermediatePoints().size() - route.getIntermediatePointsToPass();
      int currentIndex = toDel - 1;
      String name =
          currentIndex < 0 || currentIndex >= ns.size() || ns.get(currentIndex) == null
              ? ""
              : ns.get(currentIndex);
      if (isFollowingMode) {
        voiceRouter.arrivedIntermediatePoint(name);
      }
      while (toDel > 0) {
        targets.removeWayPoint(false, 0);
        toDel--;
      }

      while (intermediatePoints != null
          && route.getIntermediatePointsToPass() < intermediatePoints.size()) {
        intermediatePoints.remove(0);
      }
    }

    // 3. check if destination found
    Location lastPoint = routeNodes.get(routeNodes.size() - 1);
    if (currentRoute > routeNodes.size() - 3
        && currentLocation.distanceTo(lastPoint)
            < (((float) settings.getApplicationMode().getArrivalDistance())
                * settings.ARRIVAL_DISTANCE_FACTOR.get())) {
      showMessage(app.getString(R.string.arrived_at_destination));
      TargetPointsHelper targets = app.getTargetPointsHelper();
      String description = targets.getPointNavigateDescription();
      if (isFollowingMode) {
        voiceRouter.arrivedDestinationPoint(description);
      }
      if (OsmandPlugin.onDestinationReached()) {
        clearCurrentRoute(null, null);
        setRoutePlanningMode(false);
        app.runInUIThread(
            new Runnable() {
              @Override
              public void run() {
                settings.APPLICATION_MODE.set(settings.DEFAULT_APPLICATION_MODE.get());
              }
            });
        // targets.clearPointToNavigate(false);
        return true;
      }
    }
    return false;
  }