Exemplo n.º 1
0
  @Override
  protected void onResume() {
    super.onResume();
    cancelNotification();
    if (settings.MAP_SCREEN_ORIENTATION.get() != getRequestedOrientation()) {
      setRequestedOrientation(settings.MAP_SCREEN_ORIENTATION.get());
      // can't return from this method we are not sure if activity will be recreated or not
    }

    app.getLocationProvider().checkIfLastKnownLocationIsValid();
    // for voice navigation
    if (settings.AUDIO_STREAM_GUIDANCE.get() != null) {
      setVolumeControlStream(settings.AUDIO_STREAM_GUIDANCE.get());
    } else {
      setVolumeControlStream(AudioManager.STREAM_MUSIC);
    }

    applicationModeListener =
        new StateChangedListener<ApplicationMode>() {
          @Override
          public void stateChanged(ApplicationMode change) {
            updateApplicationModeSettings();
          }
        };
    settings.APPLICATION_MODE.addListener(applicationModeListener);
    updateApplicationModeSettings();

    String filterId = settings.getPoiFilterForMap();
    PoiFilter poiFilter = app.getPoiFilters().getFilterById(filterId);
    if (poiFilter == null) {
      poiFilter = new PoiFilter(null, app);
    }

    mapLayers.getPoiMapLayer().setFilter(poiFilter);

    // if destination point was changed try to recalculate route
    TargetPointsHelper targets = app.getTargetPointsHelper();
    RoutingHelper routingHelper = app.getRoutingHelper();
    if (routingHelper.isFollowingMode()
        && (!Algorithms.objectEquals(targets.getPointToNavigate(), routingHelper.getFinalLocation())
            || !Algorithms.objectEquals(
                targets.getIntermediatePoints(), routingHelper.getIntermediatePoints()))) {
      routingHelper.setFinalAndCurrentLocation(
          targets.getPointToNavigate(),
          targets.getIntermediatePoints(),
          app.getLocationProvider().getLastKnownLocation(),
          routingHelper.getCurrentGPXRoute());
    }
    app.getLocationProvider().resumeAllUpdates();

    if (settings != null && settings.isLastKnownMapLocation()) {
      LatLon l = settings.getLastKnownMapLocation();
      mapView.setLatLon(l.getLatitude(), l.getLongitude());
      mapView.setZoom(settings.getLastKnownMapZoom());
    }

    settings.MAP_ACTIVITY_ENABLED.set(true);
    checkExternalStorage();
    showAndHideMapPosition();

    LatLon cur = new LatLon(mapView.getLatitude(), mapView.getLongitude());
    LatLon latLonToShow = settings.getAndClearMapLocationToShow();
    String mapLabelToShow = settings.getAndClearMapLabelToShow();
    Object toShow = settings.getAndClearObjectToShow();
    if (settings.isRouteToPointNavigateAndClear()) {
      // always enable and follow and let calculate it (GPS is not accessible in garage)
      mapActions.getDirections(null, null, false);
    }
    if (mapLabelToShow != null && latLonToShow != null) {
      mapLayers.getContextMenuLayer().setSelectedObject(toShow);
      mapLayers.getContextMenuLayer().setLocation(latLonToShow, mapLabelToShow);
    }
    if (latLonToShow != null && !latLonToShow.equals(cur)) {
      mapView
          .getAnimatedDraggingThread()
          .startMoving(
              latLonToShow.getLatitude(),
              latLonToShow.getLongitude(),
              settings.getMapZoomToShow(),
              true);
    }
    if (latLonToShow != null) {
      // remember if map should come back to isMapLinkedToLocation=true
      mapViewTrackingUtilities.setMapLinkedToLocation(false);
    }

    View progress = mapLayers.getMapInfoLayer().getProgressBar();
    if (progress != null) {
      app.getResourceManager().setBusyIndicator(new BusyIndicator(this, progress));
    }

    OsmandPlugin.onMapActivityResume(this);
    mapView.refreshMap(true);
  }
Exemplo n.º 2
0
  @Override
  public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
    OsmandApplication app = (OsmandApplication) getActivity().getApplication();
    boolean light = app.getSettings().isLightActionBar();
    com.actionbarsherlock.view.MenuItem menuItem =
        menu.add(0, NAVIGATE_TO, 0, R.string.get_directions)
            .setShowAsActionFlags(
                MenuItem.SHOW_AS_ACTION_ALWAYS | MenuItem.SHOW_AS_ACTION_WITH_TEXT);
    menuItem =
        menuItem.setIcon(
            light ? R.drawable.ic_action_gdirections_light : R.drawable.ic_action_gdirections_dark);
    menuItem.setOnMenuItemClickListener(
        new OnMenuItemClickListener() {
          @Override
          public boolean onMenuItemClick(com.actionbarsherlock.view.MenuItem item) {
            select(NAVIGATE_TO);
            return true;
          }
        });
    TargetPointsHelper targets = app.getTargetPointsHelper();
    if (targets.getPointToNavigate() != null) {
      menuItem =
          menu.add(0, ADD_WAYPOINT, 0, R.string.context_menu_item_intermediate_point)
              .setShowAsActionFlags(
                  MenuItem.SHOW_AS_ACTION_ALWAYS | MenuItem.SHOW_AS_ACTION_WITH_TEXT);
      menuItem =
          menuItem.setIcon(
              light ? R.drawable.ic_action_flage_light : R.drawable.ic_action_flage_dark);
    } else {
      menuItem =
          menu.add(0, ADD_WAYPOINT, 0, R.string.context_menu_item_destination_point)
              .setShowAsActionFlags(
                  MenuItem.SHOW_AS_ACTION_ALWAYS | MenuItem.SHOW_AS_ACTION_WITH_TEXT);
      menuItem =
          menuItem.setIcon(
              light ? R.drawable.ic_action_flag_light : R.drawable.ic_action_flag_dark);
    }
    menuItem.setOnMenuItemClickListener(
        new OnMenuItemClickListener() {
          @Override
          public boolean onMenuItemClick(com.actionbarsherlock.view.MenuItem item) {
            select(ADD_WAYPOINT);
            return true;
          }
        });
    // }
    menuItem =
        menu.add(0, SHOW_ON_MAP, 0, R.string.search_shown_on_map)
            .setShowAsActionFlags(
                MenuItem.SHOW_AS_ACTION_ALWAYS | MenuItem.SHOW_AS_ACTION_WITH_TEXT);
    menuItem =
        menuItem.setIcon(
            light ? R.drawable.ic_action_marker_light : R.drawable.ic_action_marker_dark);

    menuItem.setOnMenuItemClickListener(
        new OnMenuItemClickListener() {
          @Override
          public boolean onMenuItemClick(com.actionbarsherlock.view.MenuItem item) {
            select(SHOW_ON_MAP);
            return true;
          }
        });

    menuItem =
        menu.add(0, ADD_TO_FAVORITE, 0, R.string.add_to_favourite)
            .setShowAsActionFlags(
                MenuItem.SHOW_AS_ACTION_ALWAYS | MenuItem.SHOW_AS_ACTION_WITH_TEXT);
    menuItem =
        menuItem.setIcon(light ? R.drawable.ic_action_fav_light : R.drawable.ic_action_fav_dark);

    menuItem.setOnMenuItemClickListener(
        new OnMenuItemClickListener() {
          @Override
          public boolean onMenuItemClick(com.actionbarsherlock.view.MenuItem item) {
            select(ADD_TO_FAVORITE);
            return true;
          }
        });
  }