Search in sources :

Example 1 with Bitmap

use of org.mapsforge.core.graphics.Bitmap in project RSAndroidApp by RailwayStations.

the class MapsActivity method loadBitmap.

private Bitmap loadBitmap(final int resourceId) {
    final Bitmap bitmap = AndroidGraphicFactory.convertToBitmap(ResourcesCompat.getDrawable(getResources(), resourceId, null));
    bitmap.incrementRefCount();
    return bitmap;
}
Also used : Bitmap(org.mapsforge.core.graphics.Bitmap) MarkerBitmap(de.bahnhoefe.deutschlands.bahnhofsfotos.mapsforge.MarkerBitmap)

Example 2 with Bitmap

use of org.mapsforge.core.graphics.Bitmap in project RSAndroidApp by RailwayStations.

the class MapsActivity method onLongPress.

private void onLongPress(final LatLong tapLatLong) {
    if (missingMarker == null) {
        // marker to show at the location
        final Drawable drawable = ContextCompat.getDrawable(this, R.drawable.marker_missing);
        assert drawable != null;
        final Bitmap bitmap = AndroidGraphicFactory.convertToBitmap(drawable);
        missingMarker = new Marker(tapLatLong, bitmap, -(bitmap.getWidth() / 2), -bitmap.getHeight()) {

            @Override
            public boolean onTap(final LatLong tapLatLong, final Point layerXY, final Point tapXY) {
                new SimpleDialogs().confirm(MapsActivity.this, R.string.add_missing_station, (dialogInterface, i) -> {
                    final Intent intent = new Intent(MapsActivity.this, DetailsActivity.class);
                    intent.putExtra(DetailsActivity.EXTRA_LATITUDE, getLatLong().latitude);
                    intent.putExtra(DetailsActivity.EXTRA_LONGITUDE, getLatLong().longitude);
                    startActivity(intent);
                });
                return false;
            }
        };
        binding.map.mapView.getLayerManager().getLayers().add(missingMarker);
    } else {
        missingMarker.setLatLong(tapLatLong);
        missingMarker.requestRedraw();
    }
    // feedback for long click
    ((Vibrator) getSystemService(VIBRATOR_SERVICE)).vibrate(VibrationEffect.createOneShot(150, VibrationEffect.DEFAULT_AMPLITUDE));
}
Also used : Bundle(android.os.Bundle) PackageManager(android.content.pm.PackageManager) NonNull(androidx.annotation.NonNull) StationFilter(de.bahnhoefe.deutschlands.bahnhofsfotos.util.StationFilter) Uri(android.net.Uri) WindowManager(android.view.WindowManager) LocationListener(android.location.LocationListener) Drawable(android.graphics.drawable.Drawable) AppCompatActivity(androidx.appcompat.app.AppCompatActivity) Align(org.mapsforge.core.graphics.Align) GeoItem(de.bahnhoefe.deutschlands.bahnhofsfotos.mapsforge.GeoItem) NONE(android.view.Menu.NONE) Manifest(android.Manifest) CheckBox(android.widget.CheckBox) Map(java.util.Map) AndroidGraphicFactory(org.mapsforge.map.android.graphics.AndroidGraphicFactory) TileRendererLayer(org.mapsforge.map.layer.renderer.TileRendererLayer) View(android.view.View) IMapViewPosition(org.mapsforge.map.model.IMapViewPosition) ContextCompat(androidx.core.content.ContextCompat) Log(android.util.Log) Station(de.bahnhoefe.deutschlands.bahnhofsfotos.model.Station) MapFile(org.mapsforge.map.reader.MapFile) DbAdapter(de.bahnhoefe.deutschlands.bahnhofsfotos.db.DbAdapter) Layer(org.mapsforge.map.layer.Layer) SubMenu(android.view.SubMenu) MapPosition(org.mapsforge.core.model.MapPosition) XmlRenderTheme(org.mapsforge.map.rendertheme.XmlRenderTheme) FileNotFoundException(java.io.FileNotFoundException) MapZoomControls(org.mapsforge.map.android.input.MapZoomControls) AbstractTileSource(org.mapsforge.map.layer.download.tilesource.AbstractTileSource) List(java.util.List) DocumentFile(androidx.documentfile.provider.DocumentFile) Marker(org.mapsforge.map.layer.overlay.Marker) ActivityResultContracts(androidx.activity.result.contract.ActivityResultContracts) TileCache(org.mapsforge.map.layer.cache.TileCache) Location(android.location.Location) LocationManager(android.location.LocationManager) Window(android.view.Window) Context(android.content.Context) ResourcesCompat(androidx.core.content.res.ResourcesCompat) Intent(android.content.Intent) FontStyle(org.mapsforge.core.graphics.FontStyle) HashMap(java.util.HashMap) TapHandler(de.bahnhoefe.deutschlands.bahnhofsfotos.mapsforge.TapHandler) Point(org.mapsforge.core.model.Point) MenuItem(android.view.MenuItem) ArrayList(java.util.ArrayList) VibrationEffect(android.os.VibrationEffect) Bitmap(org.mapsforge.core.graphics.Bitmap) InternalRenderTheme(org.mapsforge.map.rendertheme.InternalRenderTheme) Toast(android.widget.Toast) FontFamily(org.mapsforge.core.graphics.FontFamily) Menu(android.view.Menu) StreamRenderTheme(org.mapsforge.map.rendertheme.StreamRenderTheme) DbsTileSource(de.bahnhoefe.deutschlands.bahnhofsfotos.mapsforge.DbsTileSource) MarkerBitmap(de.bahnhoefe.deutschlands.bahnhofsfotos.mapsforge.MarkerBitmap) WeakReference(java.lang.ref.WeakReference) AndroidUtil(org.mapsforge.map.android.util.AndroidUtil) OnlineTileSource(org.mapsforge.map.layer.download.tilesource.OnlineTileSource) ActivityResultLauncher(androidx.activity.result.ActivityResultLauncher) ActivityCompat(androidx.core.app.ActivityCompat) TileDownloadLayer(org.mapsforge.map.layer.download.TileDownloadLayer) FileInputStream(java.io.FileInputStream) StationFilterBar(de.bahnhoefe.deutschlands.bahnhofsfotos.dialogs.StationFilterBar) LatLong(org.mapsforge.core.model.LatLong) ActivityMapsBinding(de.bahnhoefe.deutschlands.bahnhofsfotos.databinding.ActivityMapsBinding) MapDataStore(org.mapsforge.map.datastore.MapDataStore) ClusterManager(de.bahnhoefe.deutschlands.bahnhofsfotos.mapsforge.ClusterManager) MapInfoFragment(de.bahnhoefe.deutschlands.bahnhofsfotos.dialogs.MapInfoFragment) Color(android.graphics.Color) Paint(org.mapsforge.core.graphics.Paint) Upload(de.bahnhoefe.deutschlands.bahnhofsfotos.model.Upload) SimpleDialogs(de.bahnhoefe.deutschlands.bahnhofsfotos.dialogs.SimpleDialogs) Vibrator(android.os.Vibrator) Style(org.mapsforge.core.graphics.Style) OpenStreetMapMapnik(org.mapsforge.map.layer.download.tilesource.OpenStreetMapMapnik) Activity(android.app.Activity) Bitmap(org.mapsforge.core.graphics.Bitmap) MarkerBitmap(de.bahnhoefe.deutschlands.bahnhofsfotos.mapsforge.MarkerBitmap) SimpleDialogs(de.bahnhoefe.deutschlands.bahnhofsfotos.dialogs.SimpleDialogs) Drawable(android.graphics.drawable.Drawable) Intent(android.content.Intent) Marker(org.mapsforge.map.layer.overlay.Marker) Point(org.mapsforge.core.model.Point) Vibrator(android.os.Vibrator) LatLong(org.mapsforge.core.model.LatLong)

Example 3 with Bitmap

use of org.mapsforge.core.graphics.Bitmap in project satstat by mvglasow.

the class MapSectionFragment method applyLocationProviderStyle.

/**
 * Applies a style to the map overlays associated with a given location provider.
 *
 * This method changes the style (effectively, the color) of the circle and
 * marker overlays. Its main purpose is to switch the color of the overlays
 * between gray and the provider color.
 *
 * @param context The context of the caller
 * @param provider The name of the location provider, as returned by
 * {@link LocationProvider.getName()}.
 * @param styleName The name of the style to apply. If it is null, the
 * default style for the provider as returned by
 * assignLocationProviderStyle() is applied.
 */
protected void applyLocationProviderStyle(Context context, String provider, String styleName) {
    String sn = (styleName != null) ? styleName : assignLocationProviderStyle(provider);
    Boolean isStyleChanged = !sn.equals(providerAppliedStyles.get(provider));
    Boolean needsRedraw = false;
    Resources res = context.getResources();
    TypedArray style = res.obtainTypedArray(res.getIdentifier(sn, "array", context.getPackageName()));
    // Circle layer
    Circle circle = mapCircles.get(provider);
    if (circle != null) {
        circle.getPaintFill().setColor(style.getColor(Const.STYLE_FILL, R.color.circle_gray_fill));
        circle.getPaintStroke().setColor(style.getColor(Const.STYLE_STROKE, R.color.circle_gray_stroke));
        needsRedraw = isStyleChanged && circle.isVisible();
    }
    // Marker layer
    Marker marker = mapMarkers.get(provider);
    if (marker != null) {
        Drawable drawable = style.getDrawable(Const.STYLE_MARKER);
        Bitmap bitmap = AndroidGraphicFactory.convertToBitmap(drawable);
        marker.setBitmap(bitmap);
        needsRedraw = needsRedraw || (isStyleChanged && marker.isVisible());
    }
    if (needsRedraw) {
        LayerManager manager = mapMap.getLayerManager();
        if (manager != null)
            manager.redrawLayers();
    }
    providerAppliedStyles.put(provider, sn);
    style.recycle();
}
Also used : Circle(org.mapsforge.map.layer.overlay.Circle) Bitmap(org.mapsforge.core.graphics.Bitmap) TypedArray(android.content.res.TypedArray) Drawable(android.graphics.drawable.Drawable) Resources(android.content.res.Resources) Marker(org.mapsforge.map.layer.overlay.Marker) LayerManager(org.mapsforge.map.layer.LayerManager)

Example 4 with Bitmap

use of org.mapsforge.core.graphics.Bitmap in project RSAndroidApp by RailwayStations.

the class MapsActivity method getMarkerBitmap.

private List<MarkerBitmap> getMarkerBitmap() {
    final List<MarkerBitmap> markerBitmaps = new ArrayList<>();
    // prepare for marker icons.
    // small icon for maximum single item
    final Bitmap bitmapWithPhoto = loadBitmap(R.drawable.marker_green);
    final Bitmap markerWithoutPhoto = loadBitmap(R.drawable.marker_red);
    final Bitmap markerOwnPhoto = loadBitmap(R.drawable.marker_violet);
    final Bitmap markerPendingUpload = loadBitmap(R.drawable.marker_yellow);
    final Bitmap markerWithPhotoInactive = loadBitmap(R.drawable.marker_green_inactive);
    final Bitmap markerWithoutPhotoInactive = loadBitmap(R.drawable.marker_red_inactive);
    final Bitmap markerOwnPhotoInactive = loadBitmap(R.drawable.marker_violet_inactive);
    final Paint paint1 = AndroidGraphicFactory.INSTANCE.createPaint();
    paint1.setStyle(Style.FILL);
    paint1.setTextAlign(Align.CENTER);
    FontFamily fontFamily = FontFamily.DEFAULT;
    FontStyle fontStyle = FontStyle.BOLD;
    paint1.setTypeface(fontFamily, fontStyle);
    paint1.setColor(Color.RED);
    markerBitmaps.add(new MarkerBitmap(this.getApplicationContext(), markerWithoutPhoto, bitmapWithPhoto, markerOwnPhoto, markerWithoutPhotoInactive, markerWithPhotoInactive, markerOwnPhotoInactive, markerPendingUpload, new Point(0, -(markerWithoutPhoto.getHeight() / 2.0)), 10f, 1, paint1));
    // small cluster icon. for 10 or less items.
    final Bitmap bitmapBalloonSN = loadBitmap(R.drawable.balloon_s_n);
    final Paint paint2 = AndroidGraphicFactory.INSTANCE.createPaint();
    paint2.setStyle(Style.FILL);
    paint2.setTextAlign(Align.CENTER);
    fontFamily = FontFamily.DEFAULT;
    fontStyle = FontStyle.BOLD;
    paint2.setTypeface(fontFamily, fontStyle);
    paint2.setColor(Color.BLACK);
    markerBitmaps.add(new MarkerBitmap(this.getApplicationContext(), bitmapBalloonSN, new Point(0, 0), 9f, 10, paint2));
    // large cluster icon. 100 will be ignored.
    final Bitmap bitmapBalloonMN = loadBitmap(R.drawable.balloon_m_n);
    final Paint paint3 = AndroidGraphicFactory.INSTANCE.createPaint();
    paint3.setStyle(Style.FILL);
    paint3.setTextAlign(Align.CENTER);
    fontFamily = FontFamily.DEFAULT;
    fontStyle = FontStyle.BOLD;
    paint3.setTypeface(fontFamily, fontStyle);
    paint3.setColor(Color.BLACK);
    markerBitmaps.add(new MarkerBitmap(this.getApplicationContext(), bitmapBalloonMN, new Point(0, 0), 11f, 100, paint3));
    return markerBitmaps;
}
Also used : FontFamily(org.mapsforge.core.graphics.FontFamily) Bitmap(org.mapsforge.core.graphics.Bitmap) MarkerBitmap(de.bahnhoefe.deutschlands.bahnhofsfotos.mapsforge.MarkerBitmap) FontStyle(org.mapsforge.core.graphics.FontStyle) ArrayList(java.util.ArrayList) MarkerBitmap(de.bahnhoefe.deutschlands.bahnhofsfotos.mapsforge.MarkerBitmap) Paint(org.mapsforge.core.graphics.Paint) Point(org.mapsforge.core.model.Point)

Example 5 with Bitmap

use of org.mapsforge.core.graphics.Bitmap in project RSAndroidApp by RailwayStations.

the class MapsActivity method createBitmapMarker.

private Marker createBitmapMarker(final LatLong latLong, final int markerRes) {
    final Drawable drawable = ContextCompat.getDrawable(this, markerRes);
    assert drawable != null;
    final Bitmap bitmap = AndroidGraphicFactory.convertToBitmap(drawable);
    return new Marker(latLong, bitmap, -(bitmap.getWidth() / 2), -bitmap.getHeight());
}
Also used : Bitmap(org.mapsforge.core.graphics.Bitmap) MarkerBitmap(de.bahnhoefe.deutschlands.bahnhofsfotos.mapsforge.MarkerBitmap) Drawable(android.graphics.drawable.Drawable) Marker(org.mapsforge.map.layer.overlay.Marker)

Aggregations

Bitmap (org.mapsforge.core.graphics.Bitmap)6 Drawable (android.graphics.drawable.Drawable)4 MarkerBitmap (de.bahnhoefe.deutschlands.bahnhofsfotos.mapsforge.MarkerBitmap)4 Marker (org.mapsforge.map.layer.overlay.Marker)4 Context (android.content.Context)2 Resources (android.content.res.Resources)2 TypedArray (android.content.res.TypedArray)2 Location (android.location.Location)2 ArrayList (java.util.ArrayList)2 Paint (org.mapsforge.core.graphics.Paint)2 Manifest (android.Manifest)1 Activity (android.app.Activity)1 Intent (android.content.Intent)1 PackageManager (android.content.pm.PackageManager)1 Color (android.graphics.Color)1 LocationListener (android.location.LocationListener)1 LocationManager (android.location.LocationManager)1 Uri (android.net.Uri)1 Bundle (android.os.Bundle)1 VibrationEffect (android.os.VibrationEffect)1