use of org.mapsforge.map.layer.download.tilesource.OnlineTileSource in project RSAndroidApp by RailwayStations.
the class MapsActivity method onCreateOptionsMenu.
@Override
public boolean onCreateOptionsMenu(final Menu menu) {
super.onCreateOptionsMenu(menu);
getMenuInflater().inflate(R.menu.maps, menu);
final MenuItem item = menu.findItem(R.id.menu_toggle_mypos);
myLocSwitch = new CheckBox(this);
myLocSwitch.setButtonDrawable(R.drawable.ic_gps_fix_selector);
myLocSwitch.setChecked(baseApplication.isLocationUpdates());
item.setActionView(myLocSwitch);
myLocSwitch.setOnCheckedChangeListener((buttonView, isChecked) -> {
baseApplication.setLocationUpdates(isChecked);
if (isChecked) {
askedForPermission = false;
registerLocationManager();
} else {
unregisterLocationManager();
}
});
final String map = baseApplication.getMap();
final MenuItem osmMapnick = menu.findItem(R.id.osm_mapnik);
osmMapnick.setChecked(map == null);
osmMapnick.setOnMenuItemClickListener(new MapMenuListener(this, baseApplication, null));
final SubMenu mapSubmenu = menu.findItem(R.id.maps_submenu).getSubMenu();
for (final OnlineTileSource tileSource : onlineTileSources.values()) {
final MenuItem mapItem = mapSubmenu.add(R.id.maps_group, NONE, NONE, tileSource.getName());
mapItem.setChecked(tileSource.getName().equals(map));
mapItem.setOnMenuItemClickListener(new MapMenuListener(this, baseApplication, tileSource.getName()));
}
final Uri mapDirectory = baseApplication.getMapDirectoryUri();
if (mapDirectory != null) {
final DocumentFile documentsTree = getDocumentFileFromTreeUri(mapDirectory);
if (documentsTree != null) {
for (final DocumentFile file : documentsTree.listFiles()) {
if (file.isFile() && file.getName().endsWith(".map")) {
final MenuItem mapItem = mapSubmenu.add(R.id.maps_group, NONE, NONE, file.getName());
mapItem.setChecked(file.getUri().equals(baseApplication.toUri(map)));
mapItem.setOnMenuItemClickListener(new MapMenuListener(this, baseApplication, file.getUri().toString()));
}
}
}
}
mapSubmenu.setGroupCheckable(R.id.maps_group, true, true);
final MenuItem mapFolder = mapSubmenu.add(R.string.map_folder);
mapFolder.setOnMenuItemClickListener(item1 -> {
openMapDirectoryChooser();
return false;
});
final Uri mapTheme = baseApplication.getMapThemeUri();
final Uri mapThemeDirectory = baseApplication.getMapThemeDirectoryUri();
final MenuItem defaultTheme = menu.findItem(R.id.default_theme);
defaultTheme.setChecked(mapTheme == null);
defaultTheme.setOnMenuItemClickListener(new MapThemeMenuListener(this, baseApplication, null));
final SubMenu themeSubmenu = menu.findItem(R.id.themes_submenu).getSubMenu();
if (mapThemeDirectory != null) {
final DocumentFile documentsTree = getDocumentFileFromTreeUri(mapThemeDirectory);
if (documentsTree != null) {
for (final DocumentFile file : documentsTree.listFiles()) {
if (file.isFile() && file.getName().endsWith(".xml")) {
final String themeName = file.getName();
final MenuItem themeItem = themeSubmenu.add(R.id.themes_group, NONE, NONE, themeName);
themeItem.setChecked(file.getUri().equals(mapTheme));
themeItem.setOnMenuItemClickListener(new MapThemeMenuListener(this, baseApplication, file.getUri()));
} else if (file.isDirectory()) {
final DocumentFile childFile = file.findFile(file.getName() + ".xml");
if (childFile != null) {
final String themeName = file.getName();
final MenuItem themeItem = themeSubmenu.add(R.id.themes_group, NONE, NONE, themeName);
themeItem.setChecked(childFile.getUri().equals(mapTheme));
themeItem.setOnMenuItemClickListener(new MapThemeMenuListener(this, baseApplication, childFile.getUri()));
}
}
}
}
}
themeSubmenu.setGroupCheckable(R.id.themes_group, true, true);
final MenuItem themeFolder = themeSubmenu.add(R.string.theme_folder);
themeFolder.setOnMenuItemClickListener(item12 -> {
openThemeDirectoryChooser();
return false;
});
return true;
}
use of org.mapsforge.map.layer.download.tilesource.OnlineTileSource in project satstat by mvglasow.
the class MapSectionFragment method onCreateView.
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
mainActivity = (MainActivity) this.getContext();
View rootView = inflater.inflate(R.layout.fragment_main_map, container, false);
float density = this.getContext().getResources().getDisplayMetrics().density;
String versionName;
try {
versionName = mainActivity.getPackageManager().getPackageInfo(mainActivity.getPackageName(), 0).versionName;
} catch (NameNotFoundException e) {
versionName = "unknown";
}
mapReattach = (ImageButton) rootView.findViewById(R.id.mapReattach);
mapAttribution = (TextView) rootView.findViewById(R.id.mapAttribution);
mapReattach.setVisibility(View.GONE);
isMapViewAttached = true;
OnClickListener clis = new OnClickListener() {
@Override
public void onClick(View v) {
if (v == mapReattach) {
isMapViewAttached = true;
mapReattach.setVisibility(View.GONE);
updateMap();
}
}
};
mapReattach.setOnClickListener(clis);
// Initialize controls
mapMap = new MapView(rootView.getContext());
((FrameLayout) rootView).addView(mapMap, 0);
mapMap.setClickable(true);
mapMap.getMapScaleBar().setVisible(true);
mapMap.getMapScaleBar().setMarginVertical((int) (density * 16));
mapMap.setBuiltInZoomControls(true);
mapMap.getMapZoomControls().setZoomLevelMin((byte) 10);
mapMap.getMapZoomControls().setZoomLevelMax((byte) 20);
mapMap.getMapZoomControls().setZoomControlsOrientation(Orientation.VERTICAL_IN_OUT);
mapMap.getMapZoomControls().setZoomInResource(R.drawable.zoom_control_in);
mapMap.getMapZoomControls().setZoomOutResource(R.drawable.zoom_control_out);
mapMap.getMapZoomControls().setMarginHorizontal((int) (density * 8));
mapMap.getMapZoomControls().setMarginVertical((int) (density * 16));
providerLocations = new HashMap<String, Location>();
mAvailableProviderStyles = new ArrayList<String>(Arrays.asList(Const.LOCATION_PROVIDER_STYLES));
providerStyles = new HashMap<String, String>();
providerAppliedStyles = new HashMap<String, String>();
providerInvalidationHandler = new Handler();
providerInvalidators = new HashMap<String, Runnable>();
onlineTileSource = new OnlineTileSource(Const.TILE_SERVER_OSM, 80);
onlineTileSource.setUserAgent(String.format("%s/%s (%s)", "SatStat", versionName, System.getProperty("http.agent")));
onlineTileSource.setName(Const.TILE_CACHE_OSM).setAlpha(false).setBaseUrl(Const.TILE_URL_OSM).setExtension(Const.TILE_EXTENSION_OSM).setParallelRequestsLimit(8).setProtocol("http").setTileSize(256).setZoomLevelMax((byte) 18).setZoomLevelMin((byte) 0);
GestureDetector gd = new GestureDetector(rootView.getContext(), new GestureDetector.SimpleOnGestureListener() {
public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) {
mapReattach.setVisibility(View.VISIBLE);
isMapViewAttached = false;
return false;
}
});
mapMap.setGestureDetector(gd);
mainActivity.mapSectionFragment = this;
float lat = mainActivity.mSharedPreferences.getFloat(Const.KEY_PREF_MAP_LAT, 360.0f);
float lon = mainActivity.mSharedPreferences.getFloat(Const.KEY_PREF_MAP_LON, 360.0f);
if ((lat < 360.0f) && (lon < 360.0f)) {
mapMap.getModel().mapViewPosition.setCenter(new LatLong(lat, lon));
}
int zoom = mainActivity.mSharedPreferences.getInt(Const.KEY_PREF_MAP_ZOOM, 16);
mapMap.getModel().mapViewPosition.setZoomLevel((byte) zoom);
createLayers(true);
return rootView;
}
Aggregations