Пример #1
0
 public void updateLoadedFiles() {
   Map<String, String> indexActivatedFileNames = app.getResourceManager().getIndexFileNames();
   DownloadIndexActivity.listWithAlternatives(
       app, app.getAppPath(""), IndexConstants.EXTRA_EXT, indexActivatedFileNames);
   Map<String, String> indexFileNames = app.getResourceManager().getIndexFileNames();
   DownloadIndexActivity.listWithAlternatives(
       app, app.getAppPath(""), IndexConstants.EXTRA_EXT, indexFileNames);
   DownloadIndexActivity.listWithAlternatives(
       app,
       app.getAppPath(IndexConstants.TILES_INDEX_DIR),
       IndexConstants.SQLITE_EXT,
       indexFileNames);
   app.getResourceManager().getBackupIndexes(indexFileNames);
   this.indexFileNames = indexFileNames;
   this.indexActivatedFileNames = indexActivatedFileNames;
 }
Пример #2
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);
  }
Пример #3
0
  // ///////////////////////////// INITIALIZING UI PART ///////////////////////////////////
  public void initView() {
    paintGrayFill = new Paint();
    paintGrayFill.setColor(Color.GRAY);
    paintGrayFill.setStyle(Style.FILL);
    // when map rotate
    paintGrayFill.setAntiAlias(true);

    paintBlackFill = new Paint();
    paintBlackFill.setColor(Color.BLACK);
    paintBlackFill.setStyle(Style.FILL);
    // when map rotate
    paintBlackFill.setAntiAlias(true);

    paintWhiteFill = new Paint();
    paintWhiteFill.setColor(Color.WHITE);
    paintWhiteFill.setStyle(Style.FILL);
    // when map rotate
    paintWhiteFill.setAntiAlias(true);

    paintCenter = new Paint();
    paintCenter.setStyle(Style.STROKE);
    paintCenter.setColor(Color.rgb(60, 60, 60));
    paintCenter.setStrokeWidth(2);
    paintCenter.setAntiAlias(true);

    paintImg = new Paint();
    //		paintImg.setFilterBitmap(true);
    //		paintImg.setDither(true);

    setClickable(true);
    setLongClickable(true);
    setFocusable(true);

    handler = new Handler();

    baseHandler =
        new Handler(application.getResourceManager().getRenderingBufferImageThread().getLooper());
    getHolder().addCallback(this);
    animatedDraggingThread = new AnimateDraggingMapThread(this);
    gestureDetector =
        new GestureDetector(
            getContext(), new MapExplorer(this, new MapTileViewOnGestureListener()));
    multiTouchSupport =
        new MultiTouchSupport(getContext(), new MapTileViewMultiTouchZoomListener());
    gestureDetector.setOnDoubleTapListener(new MapTileViewOnDoubleTapListener());

    WindowManager mgr = (WindowManager) getContext().getSystemService(Context.WINDOW_SERVICE);
    dm = new DisplayMetrics();
    mgr.getDefaultDisplay().getMetrics(dm);
    currentViewport =
        new RotatedTileBox.RotatedTileBoxBuilder()
            .setLocation(0, 0)
            .setZoomAndScale(3, 0)
            .setPixelDimensions(getWidth(), getHeight())
            .build();
    currentViewport.setDensity(dm.density);
  }
Пример #4
0
 @Override
 protected void onDestroy() {
   super.onDestroy();
   FailSafeFuntions.quitRouteRestoreDialog();
   OsmandPlugin.onMapActivityDestroy(this);
   mapViewTrackingUtilities.setMapView(null);
   cancelNotification();
   app.getResourceManager().getMapTileDownloader().removeDownloaderCallback(mapView);
 }
Пример #5
0
 public void updateDescription(LocalIndexInfo info) {
   File f = new File(info.getPathToData());
   if (info.getType() == LocalIndexType.MAP_DATA) {
     Map<String, String> ifns = app.getResourceManager().getIndexFileNames();
     if (ifns.containsKey(info.getFileName())) {
       try {
         Date dt = app.getResourceManager().getDateFormat().parse(ifns.get(info.getFileName()));
         info.setDescription(getInstalledDate(dt.getTime(), null));
       } catch (ParseException e) {
         e.printStackTrace();
       }
     } else {
       info.setDescription(getInstalledDate(f));
     }
   } else if (info.getType() == LocalIndexType.TILES_DATA) {
     ITileSource template;
     if (f.isDirectory() && TileSourceManager.isTileSourceMetaInfoExist(f)) {
       template = TileSourceManager.createTileSourceTemplate(new File(info.getPathToData()));
     } else if (f.isFile() && f.getName().endsWith(SQLiteTileSource.EXT)) {
       template = new SQLiteTileSource(app, f, TileSourceManager.getKnownSourceTemplates());
     } else {
       return;
     }
     String descr = "";
     descr += app.getString(R.string.local_index_tile_data_name, template.getName());
     if (template.getExpirationTimeMinutes() >= 0) {
       descr +=
           "\n"
               + app.getString(
                   R.string.local_index_tile_data_expire, template.getExpirationTimeMinutes());
     }
     info.setDescription(descr);
   } else if (info.getType() == LocalIndexType.SRTM_DATA) {
     info.setDescription(app.getString(R.string.download_srtm_maps));
   } else if (info.getType() == LocalIndexType.WIKI_DATA) {
     info.setDescription(getInstalledDate(f));
   } else if (info.getType() == LocalIndexType.TTS_VOICE_DATA) {
     info.setDescription(getInstalledDate(f));
   } else if (info.getType() == LocalIndexType.DEACTIVATED) {
     info.setDescription(getInstalledDate(f));
   } else if (info.getType() == LocalIndexType.VOICE_DATA) {
     info.setDescription(getInstalledDate(f));
   }
 }
Пример #6
0
  public List<LocalIndexInfo> getLocalIndexData(LoadLocalIndexTask loadTask) {
    Map<String, String> loadedMaps = app.getResourceManager().getIndexFileNames();
    List<LocalIndexInfo> result = new ArrayList<>();

    loadObfData(app.getAppPath(IndexConstants.MAPS_PATH), result, false, loadTask, loadedMaps);
    loadObfData(
        app.getAppPath(IndexConstants.ROADS_INDEX_DIR), result, false, loadTask, loadedMaps);
    loadTilesData(app.getAppPath(IndexConstants.TILES_INDEX_DIR), result, false, loadTask);
    loadSrtmData(app.getAppPath(IndexConstants.SRTM_INDEX_DIR), result, loadTask);
    loadWikiData(app.getAppPath(IndexConstants.WIKI_INDEX_DIR), result, loadTask);
    // loadVoiceData(app.getAppPath(IndexConstants.TTSVOICE_INDEX_EXT_ZIP), result, true, loadTask);
    loadVoiceData(app.getAppPath(IndexConstants.VOICE_INDEX_DIR), result, false, loadTask);
    loadObfData(
        app.getAppPath(IndexConstants.BACKUP_INDEX_DIR), result, true, loadTask, loadedMaps);

    return result;
  }
Пример #7
0
  @Override
  protected void onPause() {
    super.onPause();
    app.getLocationProvider().pauseAllUpdates();
    app.getDaynightHelper().stopSensorIfNeeded();
    settings.APPLICATION_MODE.removeListener(applicationModeListener);

    settings.setLastKnownMapLocation((float) mapView.getLatitude(), (float) mapView.getLongitude());
    AnimateDraggingMapThread animatedThread = mapView.getAnimatedDraggingThread();
    if (animatedThread.isAnimating() && animatedThread.getTargetZoom() != 0) {
      settings.setMapLocationToShow(
          animatedThread.getTargetLatitude(),
          animatedThread.getTargetLongitude(),
          (int) animatedThread.getTargetZoom());
    }

    settings.setLastKnownMapZoom(mapView.getZoom());
    settings.MAP_ACTIVITY_ENABLED.set(false);
    app.getResourceManager().interruptRendering();
    app.getResourceManager().setBusyIndicator(null);
    OsmandPlugin.onMapActivityPause(this);
  }
Пример #8
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);
  }
Пример #9
0
  @Override
  public void onCreate(Bundle savedInstanceState) {
    app = getMyApplication();
    settings = app.getSettings();
    app.applyTheme(this);
    super.onCreate(savedInstanceState);

    mapActions = new MapActivityActions(this);
    mapLayers = new MapActivityLayers(this);
    requestWindowFeature(Window.FEATURE_NO_TITLE);
    // Full screen is not used here
    // getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
    // WindowManager.LayoutParams.FLAG_FULLSCREEN);
    setContentView(R.layout.main);
    startProgressDialog = new ProgressDialog(this);
    startProgressDialog.setCancelable(true);
    app.checkApplicationIsBeingInitialized(this, startProgressDialog);
    parseLaunchIntentLocation();

    mapView = (OsmandMapTileView) findViewById(R.id.MapView);
    mapView.setTrackBallDelegate(
        new OsmandMapTileView.OnTrackBallListener() {
          @Override
          public boolean onTrackBallEvent(MotionEvent e) {
            showAndHideMapPosition();
            return MapActivity.this.onTrackballEvent(e);
          }
        });
    mapView.setAccessibilityActions(new MapAccessibilityActions(this));
    if (mapViewTrackingUtilities == null) {
      mapViewTrackingUtilities = new MapViewTrackingUtilities(app);
    }
    mapViewTrackingUtilities.setMapView(mapView);

    // Do some action on close
    startProgressDialog.setOnDismissListener(
        new DialogInterface.OnDismissListener() {
          @Override
          public void onDismiss(DialogInterface dialog) {
            app.getResourceManager().getRenderer().clearCache();
            mapView.refreshMap(true);
          }
        });

    app.getResourceManager()
        .getMapTileDownloader()
        .addDownloaderCallback(
            new IMapDownloaderCallback() {
              @Override
              public void tileDownloaded(DownloadRequest request) {
                if (request != null && !request.error && request.fileToSave != null) {
                  ResourceManager mgr = app.getResourceManager();
                  mgr.tileDownloaded(request);
                }
                if (request == null || !request.error) {
                  mapView.tileDownloaded(request);
                }
              }
            });
    createProgressBarForRouting();
    // This situtation could be when navigation suddenly crashed and after restarting
    // it tries to continue the last route
    if (settings.FOLLOW_THE_ROUTE.get()
        && !app.getRoutingHelper().isRouteCalculated()
        && !app.getRoutingHelper().isRouteBeingCalculated()) {
      FailSafeFuntions.restoreRoutingMode(this);
    }

    mapLayers.createLayers(mapView);

    if (!settings.isLastKnownMapLocation()) {
      // show first time when application ran
      net.osmand.Location location = app.getLocationProvider().getFirstTimeRunDefaultLocation();
      if (location != null) {
        mapView.setLatLon(location.getLatitude(), location.getLongitude());
        mapView.setZoom(14);
      }
    }
    addDialogProvider(mapActions);
    OsmandPlugin.onMapActivityCreate(this);
    if (lockView != null) {
      ((FrameLayout) mapView.getParent()).addView(lockView);
    }
  }
 @Override
 protected IncrementalChangesManager.IncrementalUpdateList doInBackground(String... params) {
   final OsmandApplication myApplication = getMyApplication();
   IncrementalChangesManager cm = myApplication.getResourceManager().getChangesManager();
   return cm.getUpdatesByMonth(params[0]);
 }