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;
}
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));
}
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();
}
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;
}
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());
}
Aggregations