Search in sources :

Example 1 with Paint

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

the class MarkerBitmap method getBitmapFromTitle.

public static Bitmap getBitmapFromTitle(final String title, final Paint paint) {
    final Context context = contextRef.get();
    if (!captionViews.containsKey(title) && context != null) {
        final var bubbleView = new TextView(context);
        bubbleView.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
        Utils.setBackground(bubbleView, ResourcesCompat.getDrawable(context.getResources(), R.drawable.caption_background, null));
        bubbleView.setGravity(Gravity.CENTER);
        bubbleView.setMaxEms(20);
        bubbleView.setTextSize(10);
        bubbleView.setPadding(5, -2, 5, -2);
        bubbleView.setTextColor(android.graphics.Color.BLACK);
        bubbleView.setText(title);
        // Measure the view at the exact dimensions (otherwise the text won't center correctly)
        final int widthSpec = View.MeasureSpec.makeMeasureSpec(paint.getTextWidth(title), View.MeasureSpec.EXACTLY);
        final int heightSpec = View.MeasureSpec.makeMeasureSpec(paint.getTextHeight(title), View.MeasureSpec.EXACTLY);
        bubbleView.measure(widthSpec, heightSpec);
        // Layout the view at the width and height
        bubbleView.layout(0, 0, paint.getTextWidth(title), paint.getTextHeight(title));
        captionViews.put(title, Utils.viewToBitmap(context, bubbleView));
        // FIXME: is never reduced!
        Objects.requireNonNull(captionViews.get(title)).incrementRefCount();
    }
    return captionViews.get(title);
}
Also used : Context(android.content.Context) ViewGroup(android.view.ViewGroup) TextView(android.widget.TextView) Point(org.mapsforge.core.model.Point) Paint(org.mapsforge.core.graphics.Paint)

Example 2 with Paint

use of org.mapsforge.core.graphics.Paint 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 3 with Paint

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

the class MapSectionFragment method onLocationProvidersChanged.

/**
 * Updates internal data structures when the user's selection of location providers has changed.
 * @param providers The new set of location providers
 */
public void onLocationProvidersChanged(Set<String> providers) {
    Context context = this.getContext();
    List<String> allProviders = mainActivity.locationManager.getAllProviders();
    ArrayList<String> removedProviders = new ArrayList<String>();
    for (String pr : providerLocations.keySet()) if (!providers.contains(pr))
        removedProviders.add(pr);
    // remove cached locations and invalidators for providers which are no longer selected
    for (String pr : removedProviders) {
        providerLocations.remove(pr);
        providerInvalidators.remove(pr);
    }
    // ensure there is a cached location for each chosen provider (can be null)
    for (String pr : providers) {
        if ((allProviders.indexOf(pr) >= 0) && !providerLocations.containsKey(pr)) {
            Location location = new Location("");
            providerLocations.put(pr, location);
        }
    }
    // add overlays
    updateLocationProviderStyles();
    mapCircles = new HashMap<String, Circle>();
    mapMarkers = new HashMap<String, Marker>();
    Log.d(TAG, "Provider location cache: " + providerLocations.keySet().toString());
    Layers layers = mapMap.getLayerManager().getLayers();
    // remove all layers other than tile render layer from map
    for (Layer layer : layers) if (!(layer instanceof TileRendererLayer) && !(layer instanceof TileDownloadLayer)) {
        layer.onDestroy();
        layers.remove(layer);
    }
    for (String pr : providers) {
        // no invalidator for GPS, which is invalidated through GPS status
        if ((!pr.equals(LocationManager.GPS_PROVIDER)) && (providerInvalidators.get(pr)) == null) {
            final String provider = pr;
            final Context ctx = context;
            providerInvalidators.put(pr, new Runnable() {

                private String mProvider = provider;

                @Override
                public void run() {
                    Location location = providerLocations.get(mProvider);
                    if (location != null)
                        markLocationAsStale(location);
                    applyLocationProviderStyle(ctx, mProvider, Const.LOCATION_PROVIDER_GRAY);
                }
            });
        }
        String styleName = assignLocationProviderStyle(pr);
        LatLong latLong;
        float acc;
        boolean visible;
        if ((providerLocations.get(pr) != null) && (providerLocations.get(pr).getProvider() != "")) {
            latLong = new LatLong(providerLocations.get(pr).getLatitude(), providerLocations.get(pr).getLongitude());
            if (providerLocations.get(pr).hasAccuracy())
                acc = providerLocations.get(pr).getAccuracy();
            else
                acc = 0;
            visible = true;
            if (isLocationStale(providerLocations.get(pr)))
                styleName = Const.LOCATION_PROVIDER_GRAY;
            Log.d("MainActivity", pr + " has " + latLong.toString());
        } else {
            latLong = new LatLong(0, 0);
            acc = 0;
            visible = false;
            Log.d("MainActivity", pr + " has no location, hiding");
        }
        // Circle layer
        Resources res = context.getResources();
        TypedArray style = res.obtainTypedArray(res.getIdentifier(styleName, "array", context.getPackageName()));
        Paint fill = AndroidGraphicFactory.INSTANCE.createPaint();
        float density = context.getResources().getDisplayMetrics().density;
        fill.setColor(style.getColor(Const.STYLE_FILL, R.color.circle_gray_fill));
        fill.setStyle(Style.FILL);
        Paint stroke = AndroidGraphicFactory.INSTANCE.createPaint();
        stroke.setColor(style.getColor(Const.STYLE_STROKE, R.color.circle_gray_stroke));
        stroke.setStrokeWidth(Math.max(1.5f * density, 1));
        stroke.setStyle(Style.STROKE);
        Circle circle = new Circle(latLong, acc, fill, stroke);
        mapCircles.put(pr, circle);
        layers.add(circle);
        circle.setVisible(visible);
        // Marker layer
        Drawable drawable = style.getDrawable(Const.STYLE_MARKER);
        Bitmap bitmap = AndroidGraphicFactory.convertToBitmap(drawable);
        Marker marker = new Marker(latLong, bitmap, 0, -bitmap.getHeight() * 10 / 24);
        mapMarkers.put(pr, marker);
        layers.add(marker);
        marker.setVisible(visible);
        style.recycle();
    }
    // move layers into view
    updateMap();
}
Also used : Context(android.content.Context) Circle(org.mapsforge.map.layer.overlay.Circle) TileRendererLayer(org.mapsforge.map.layer.renderer.TileRendererLayer) ArrayList(java.util.ArrayList) TileDownloadLayer(org.mapsforge.map.layer.download.TileDownloadLayer) Drawable(android.graphics.drawable.Drawable) Marker(org.mapsforge.map.layer.overlay.Marker) Paint(org.mapsforge.core.graphics.Paint) TileRendererLayer(org.mapsforge.map.layer.renderer.TileRendererLayer) Layer(org.mapsforge.map.layer.Layer) TileDownloadLayer(org.mapsforge.map.layer.download.TileDownloadLayer) Bitmap(org.mapsforge.core.graphics.Bitmap) TypedArray(android.content.res.TypedArray) Resources(android.content.res.Resources) Layers(org.mapsforge.map.layer.Layers) LatLong(org.mapsforge.core.model.LatLong) Location(android.location.Location)

Aggregations

Paint (org.mapsforge.core.graphics.Paint)3 Context (android.content.Context)2 ArrayList (java.util.ArrayList)2 Bitmap (org.mapsforge.core.graphics.Bitmap)2 Point (org.mapsforge.core.model.Point)2 Resources (android.content.res.Resources)1 TypedArray (android.content.res.TypedArray)1 Drawable (android.graphics.drawable.Drawable)1 Location (android.location.Location)1 ViewGroup (android.view.ViewGroup)1 TextView (android.widget.TextView)1 MarkerBitmap (de.bahnhoefe.deutschlands.bahnhofsfotos.mapsforge.MarkerBitmap)1 FontFamily (org.mapsforge.core.graphics.FontFamily)1 FontStyle (org.mapsforge.core.graphics.FontStyle)1 LatLong (org.mapsforge.core.model.LatLong)1 Layer (org.mapsforge.map.layer.Layer)1 Layers (org.mapsforge.map.layer.Layers)1 TileDownloadLayer (org.mapsforge.map.layer.download.TileDownloadLayer)1 Circle (org.mapsforge.map.layer.overlay.Circle)1 Marker (org.mapsforge.map.layer.overlay.Marker)1