Java Code Examples for org.mapsforge.map.android.graphics.AndroidGraphicFactory#convertToBitmap()

The following examples show how to use org.mapsforge.map.android.graphics.AndroidGraphicFactory#convertToBitmap() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: HomeActivity.java    From EasyVPN-Free with GNU General Public License v3.0 7 votes vote down vote up
private void initDetailsServerOnMap() {
    if (markerList != null && markerList.size() > 0) {
        for (Marker marker : markerList) {
            layers.remove(marker);
        }
    }
    List<Server> serverList = dbHelper.getServersWithGPS();

    markerList = new ArrayList<Marker>();
    for (Server server : serverList) {
        LatLong position = new LatLong(server.getLat(), server.getLon());
        Bitmap bitmap = AndroidGraphicFactory.convertToBitmap(ContextCompat.getDrawable(this,
                getResources().getIdentifier(ConnectionQuality.getSimplePointIcon(server.getQuality()),
                        "drawable",
                        getPackageName())));
        Marker serverMarker = new Marker(position, bitmap, 0, 0);
        markerList.add(serverMarker);
        layers.add(serverMarker);
    }
}
 
Example 2
Source File: MapSectionFragment.java    From satstat with GNU General Public License v3.0 5 votes vote down vote up
/**
 * 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();
}
 
Example 3
Source File: HomeActivity.java    From EasyVPN-Free with GNU General Public License v3.0 4 votes vote down vote up
private void initServerOnMap(Layers layers) {
    Type listType = new TypeToken<ArrayList<Country>>(){}.getType();
    countryLatLonList =  new Gson().fromJson(LoadData.fromFile(COUNTRY_FILE_NAME, this), listType);

    for (Server server : countryList) {
        for (Country country : countryLatLonList) {
            if (server.getCountryShort().equals(country.getCountryCode())) {
                LatLong position = new LatLong(country.getCapitalLatitude(), country.getCapitalLongitude());
                Bitmap bitmap = AndroidGraphicFactory.convertToBitmap(ContextCompat.getDrawable(this,
                        getResources().getIdentifier(ConnectionQuality.getPointIcon(server.getQuality()),
                                "drawable",
                                getPackageName())));

                MyMarker countryMarker = new MyMarker(position, bitmap, 0, 0, server) {
                    @Override
                    public boolean onTap(LatLong geoPoint, Point viewPosition,
                                         Point tapPoint) {

                        if (contains(viewPosition, tapPoint)) {
                            onSelectCountry((Server)getRelationObject());
                            return true;
                        }
                        return false;
                    }
                };

                layers.add(countryMarker);


                String localeCountryName = localeCountries.get(country.getCountryCode()) != null ?
                        localeCountries.get(country.getCountryCode()) : country.getCountryName();

                Drawable drawable = new BitmapDrawable(getResources(), BitmapGenerator.getTextAsBitmap(localeCountryName, 20, ContextCompat.getColor(this,R.color.mapNameCountry)));
                Bitmap bitmapName = AndroidGraphicFactory.convertToBitmap(drawable);

                Marker countryNameMarker = new Marker(position, bitmapName, 0, bitmap.getHeight() / 2);

                layers.add(countryNameMarker);
            }
        }
    }
}