public void select(int mode) { try { double lat = convert(((TextView) view.findViewById(R.id.LatitudeEdit)).getText().toString()); double lon = convert(((TextView) view.findViewById(R.id.LongitudeEdit)).getText().toString()); if (mode == ADD_TO_FAVORITE) { Bundle b = new Bundle(); Dialog dlg = MapActivityActions.createAddFavouriteDialog(getActivity(), b); dlg.show(); MapActivityActions.prepareAddFavouriteDialog( getActivity(), dlg, b, lat, lon, getString(R.string.point_on_map, lat, lon)); } else if (mode == NAVIGATE_TO) { MapActivityActions.directionsToDialogAndLaunchMap( getActivity(), lat, lon, getString(R.string.point_on_map, lat, lon)); } else if (mode == ADD_WAYPOINT) { MapActivityActions.addWaypointDialogAndLaunchMap( getActivity(), lat, lon, getString(R.string.point_on_map, lat, lon)); } else if (mode == SHOW_ON_MAP) { OsmandApplication app = (OsmandApplication) getActivity().getApplication(); app.getSettings() .setMapLocationToShow( lat, lon, Math.max(12, app.getSettings().getLastKnownMapZoom()), getString(R.string.point_on_map, lat, lon)); MapActivity.launchMapActivityMoveToTop(getActivity()); } } catch (RuntimeException e) { ((TextView) view.findViewById(R.id.ValidateTextView)).setVisibility(View.VISIBLE); ((TextView) view.findViewById(R.id.ValidateTextView)).setText(R.string.invalid_locations); Log.w(PlatformUtil.TAG, "Convertion failed", e); // $NON-NLS-1$ } }
@Override protected void onListItemClick(ListView l, View v, int position, long id) { if (!isSelectFavoriteMode()) { QuickAction qa = new QuickAction(v); FavouritePoint point = favouritesAdapter.getItem(position); String name = getString(R.string.favorite) + ": " + point.getName(); LatLon location = new LatLon(point.getLatitude(), point.getLongitude()); View.OnClickListener onshow = new View.OnClickListener() { @Override public void onClick(View v) { settings.SHOW_FAVORITES.set(true); } }; MapActivityActions.createDirectionsActions( qa, location, point, name, settings.getLastKnownMapZoom(), this, true, onshow); qa.show(); } else { Intent intent = getIntent(); intent.putExtra(SELECT_FAVORITE_POINT_INTENT_KEY, favouritesAdapter.getItem(position)); setResult(SELECT_FAVORITE_POINT_RESULT_OK, intent); finish(); } }
@Override public boolean onKeyUp(int keyCode, KeyEvent event) { if (keyCode == KeyEvent.KEYCODE_DPAD_CENTER) { if (!app.getInternalAPI().accessibilityEnabled()) { mapActions.contextMenuPoint(mapView.getLatitude(), mapView.getLongitude()); } else if (uiHandler.hasMessages(LONG_KEYPRESS_MSG_ID)) { uiHandler.removeMessages(LONG_KEYPRESS_MSG_ID); mapActions.contextMenuPoint(mapView.getLatitude(), mapView.getLongitude()); } return true; } else if (settings.ZOOM_BY_TRACKBALL.get()) { // Parrot device has only dpad left and right if (keyCode == KeyEvent.KEYCODE_DPAD_LEFT) { changeZoom(mapView.getZoom() - 1); return true; } else if (keyCode == KeyEvent.KEYCODE_DPAD_RIGHT) { changeZoom(mapView.getZoom() + 1); return true; } } else if (keyCode == KeyEvent.KEYCODE_DPAD_LEFT || keyCode == KeyEvent.KEYCODE_DPAD_RIGHT || keyCode == KeyEvent.KEYCODE_DPAD_DOWN || keyCode == KeyEvent.KEYCODE_DPAD_UP) { int dx = keyCode == KeyEvent.KEYCODE_DPAD_RIGHT ? 15 : (keyCode == KeyEvent.KEYCODE_DPAD_LEFT ? -15 : 0); int dy = keyCode == KeyEvent.KEYCODE_DPAD_DOWN ? 15 : (keyCode == KeyEvent.KEYCODE_DPAD_UP ? -15 : 0); LatLon l = mapView.getLatLonFromScreenPoint( mapView.getCenterPointX() + dx, mapView.getCenterPointY() + dy); setMapLocation(l.getLatitude(), l.getLongitude()); return true; } else if (OsmandPlugin.onMapActivityKeyUp(this, keyCode)) { return true; } return super.onKeyUp(keyCode, event); }
@Override public boolean onKeyDown(int keyCode, KeyEvent event) { if (keyCode == KeyEvent.KEYCODE_DPAD_CENTER && app.getInternalAPI().accessibilityEnabled()) { if (!uiHandler.hasMessages(LONG_KEYPRESS_MSG_ID)) { Message msg = Message.obtain( uiHandler, new Runnable() { @Override public void run() { app.getLocationProvider().emitNavigationHint(); } }); msg.what = LONG_KEYPRESS_MSG_ID; uiHandler.sendMessageDelayed(msg, LONG_KEYPRESS_DELAY); } return true; } else if (keyCode == KeyEvent.KEYCODE_MENU && event.getRepeatCount() == 0) { mapActions.openOptionsMenuAsList(); return true; } else if (keyCode == KeyEvent.KEYCODE_SEARCH && event.getRepeatCount() == 0) { Intent newIntent = new Intent(MapActivity.this, OsmandIntents.getSearchActivity()); // causes wrong position caching: newIntent.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT); LatLon loc = getMapLocation(); newIntent.putExtra(SearchActivity.SEARCH_LAT, loc.getLatitude()); newIntent.putExtra(SearchActivity.SEARCH_LON, loc.getLongitude()); startActivity(newIntent); newIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); return true; } else if (!app.getRoutingHelper().isFollowingMode() && OsmandPlugin.getEnabledPlugin(AccessibilityPlugin.class) != null) { // Find more appropriate plugin for it? if (keyCode == KeyEvent.KEYCODE_VOLUME_UP && event.getRepeatCount() == 0) { if (mapView.isZooming()) { changeZoom(mapView.getZoom() + 2); } else { changeZoom(mapView.getZoom() + 1); } return true; } else if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN && event.getRepeatCount() == 0) { changeZoom(mapView.getZoom() - 1); return true; } } return super.onKeyDown(keyCode, event); }
@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); }