Search in sources :

Example 1 with OnlineTileSource

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;
}
Also used : OnlineTileSource(org.mapsforge.map.layer.download.tilesource.OnlineTileSource) DocumentFile(androidx.documentfile.provider.DocumentFile) CheckBox(android.widget.CheckBox) MenuItem(android.view.MenuItem) SubMenu(android.view.SubMenu) Uri(android.net.Uri)

Example 2 with OnlineTileSource

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;
}
Also used : OnlineTileSource(org.mapsforge.map.layer.download.tilesource.OnlineTileSource) NameNotFoundException(android.content.pm.PackageManager.NameNotFoundException) Handler(android.os.Handler) GestureDetector(android.view.GestureDetector) View(android.view.View) TextView(android.widget.TextView) MapView(org.mapsforge.map.android.view.MapView) Point(org.mapsforge.core.model.Point) Paint(org.mapsforge.core.graphics.Paint) MotionEvent(android.view.MotionEvent) FrameLayout(android.widget.FrameLayout) OnClickListener(android.view.View.OnClickListener) MapView(org.mapsforge.map.android.view.MapView) LatLong(org.mapsforge.core.model.LatLong) Location(android.location.Location)

Aggregations

OnlineTileSource (org.mapsforge.map.layer.download.tilesource.OnlineTileSource)2 NameNotFoundException (android.content.pm.PackageManager.NameNotFoundException)1 Location (android.location.Location)1 Uri (android.net.Uri)1 Handler (android.os.Handler)1 GestureDetector (android.view.GestureDetector)1 MenuItem (android.view.MenuItem)1 MotionEvent (android.view.MotionEvent)1 SubMenu (android.view.SubMenu)1 View (android.view.View)1 OnClickListener (android.view.View.OnClickListener)1 CheckBox (android.widget.CheckBox)1 FrameLayout (android.widget.FrameLayout)1 TextView (android.widget.TextView)1 DocumentFile (androidx.documentfile.provider.DocumentFile)1 Paint (org.mapsforge.core.graphics.Paint)1 LatLong (org.mapsforge.core.model.LatLong)1 Point (org.mapsforge.core.model.Point)1 MapView (org.mapsforge.map.android.view.MapView)1