Search in sources :

Example 1 with RenderingRuleSearchRequest

use of net.osmand.render.RenderingRuleSearchRequest in project OsmAnd-tools by osmandapp.

the class NativeSwingRendering method renderImage.

public BufferedImage renderImage(RenderingImageContext ctx) throws IOException {
    long time = -System.currentTimeMillis();
    RenderingContext rctx = new RenderingContext() {

        @Override
        protected byte[] getIconRawData(String data) {
            return _R.getIconData(data);
        }
    };
    rctx.preferredLocale = renderingProps.get("lang") != null ? renderingProps.get("lang") : "";
    rctx.nightMode = "true".equals(renderingProps.get("nightMode"));
    RenderingRuleSearchRequest request = new RenderingRuleSearchRequest(storage);
    request.setBooleanFilter(request.ALL.R_NIGHT_MODE, rctx.nightMode);
    for (RenderingRuleProperty customProp : storage.PROPS.getCustomRules()) {
        String res = renderingProps.get(customProp.getAttrName());
        if (customProp.getAttrName().equals(RenderingRuleStorageProperties.A_ENGINE_V1)) {
            request.setBooleanFilter(customProp, true);
        } else if (!Algorithms.isEmpty(res)) {
            if (customProp.isString()) {
                request.setStringFilter(customProp, res);
            } else if (customProp.isBoolean()) {
                request.setBooleanFilter(customProp, "true".equalsIgnoreCase(res));
            } else {
                try {
                    request.setIntFilter(customProp, Integer.parseInt(res));
                } catch (NumberFormatException e) {
                    e.printStackTrace();
                }
            }
        } else {
            if (customProp.isString()) {
                request.setStringFilter(customProp, "");
            } else if (customProp.isBoolean()) {
                request.setBooleanFilter(customProp, false);
            } else {
                request.setIntFilter(customProp, -1);
            }
        }
    }
    request.setIntFilter(request.ALL.R_MINZOOM, ctx.zoom);
    request.saveState();
    NativeSearchResult res = searchObjectsForRendering(ctx.sleft, ctx.sright, ctx.stop, ctx.sbottom, ctx.zoom, request, true, rctx, "Nothing found");
    // ctx.zoomDelta =  1;
    // double scale = MapUtils.getPowZoom((float) ctx.zoomDelta);
    float scale = 1;
    if (renderingProps.get("density") != null) {
        scale *= Float.parseFloat(renderingProps.get("density"));
    }
    rctx.leftX = ctx.leftX * scale;
    rctx.topY = ctx.topY * scale;
    rctx.width = (int) (ctx.width * scale);
    rctx.height = (int) (ctx.height * scale);
    // map density scales corresponding to zoom delta
    // (so the distance between the road is the same)
    rctx.setDensityValue(scale);
    // rctx.textScale = 1f;//Text/icon scales according to mapDensity
    // Text/icon stays same for all sizes
    rctx.textScale = 1 / scale;
    if (renderingProps.get("textScale") != null) {
        rctx.textScale *= Float.parseFloat(renderingProps.get("textScale"));
    }
    rctx.screenDensityRatio = 1 / Math.max(1, 1f);
    final double tileDivisor = MapUtils.getPowZoom((float) (31 - ctx.zoom)) / scale;
    request.clearState();
    if (request.searchRenderingAttribute(RenderingRuleStorageProperties.A_DEFAULT_COLOR)) {
        rctx.defaultColor = request.getIntPropertyValue(request.ALL.R_ATTR_COLOR_VALUE);
    }
    request.clearState();
    request.setIntFilter(request.ALL.R_MINZOOM, ctx.zoom);
    if (request.searchRenderingAttribute(RenderingRuleStorageProperties.A_SHADOW_RENDERING)) {
        rctx.shadowRenderingMode = request.getIntPropertyValue(request.ALL.R_ATTR_INT_VALUE);
        rctx.shadowRenderingColor = request.getIntPropertyValue(request.ALL.R_SHADOW_COLOR);
    }
    rctx.zoom = ctx.zoom;
    rctx.tileDivisor = tileDivisor;
    long search = time + System.currentTimeMillis();
    final RenderingGenerationResult rres = NativeSwingRendering.generateRenderingIndirect(rctx, res.nativeHandler, false, request, true);
    long rendering = time + System.currentTimeMillis() - search;
    InputStream inputStream = new InputStream() {

        int nextInd = 0;

        @Override
        public int read() throws IOException {
            if (nextInd >= rres.bitmapBuffer.capacity()) {
                return -1;
            }
            byte b = rres.bitmapBuffer.get(nextInd++);
            if (b < 0) {
                return b + 256;
            } else {
                return b;
            }
        }
    };
    Iterator<ImageReader> readers = ImageIO.getImageReadersByFormatName("png");
    ImageReader reader = readers.next();
    reader.setInput(new MemoryCacheImageInputStream(inputStream), true);
    BufferedImage img = reader.read(0);
    ctx.searchTime = search;
    ctx.renderingTime = rendering;
    ctx.context = rctx;
    long last = time + System.currentTimeMillis() - rendering;
    System.out.println(" TIMES search - " + search + " rendering - " + rendering + " unpack - " + last);
    res.deleteNativeResult();
    return img;
}
Also used : RenderingContext(net.osmand.RenderingContext) MemoryCacheImageInputStream(javax.imageio.stream.MemoryCacheImageInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) MemoryCacheImageInputStream(javax.imageio.stream.MemoryCacheImageInputStream) RenderingRuleProperty(net.osmand.render.RenderingRuleProperty) BufferedImage(java.awt.image.BufferedImage) RenderingRuleSearchRequest(net.osmand.render.RenderingRuleSearchRequest) ImageReader(javax.imageio.ImageReader)

Example 2 with RenderingRuleSearchRequest

use of net.osmand.render.RenderingRuleSearchRequest in project Osmand by osmandapp.

the class MapRenderRepositories method loadMap.

public synchronized void loadMap(RotatedTileBox tileRect, MapTileDownloader mapTileDownloader) {
    boolean prevInterrupted = interrupted;
    interrupted = false;
    // added to avoid zoomAnimation != 0 which produces wrong map position on the screen
    tileRect.setZoomAndAnimation(tileRect.getZoom(), 0);
    // prevent editing
    requestedBox = new RotatedTileBox(tileRect);
    log.info("RENDER MAP: new request " + tileRect);
    if (currentRenderingContext != null) {
        currentRenderingContext = null;
    }
    try {
        // find selected rendering type
        OsmandApplication app = ((OsmandApplication) context.getApplicationContext());
        boolean nightMode = app.getDaynightHelper().isNightMode();
        // boolean moreDetail = prefs.SHOW_MORE_MAP_DETAIL.get();
        RenderingRulesStorage storage = app.getRendererRegistry().getCurrentSelectedRenderer();
        RenderingRuleSearchRequest renderingReq = new RenderingRuleSearchRequest(storage);
        renderingReq.setBooleanFilter(renderingReq.ALL.R_NIGHT_MODE, nightMode);
        for (RenderingRuleProperty customProp : storage.PROPS.getCustomRules()) {
            if (customProp.isBoolean()) {
                if (customProp.getAttrName().equals(RenderingRuleStorageProperties.A_ENGINE_V1)) {
                    renderingReq.setBooleanFilter(customProp, true);
                } else if (RenderingRuleStorageProperties.UI_CATEGORY_HIDDEN.equals(customProp.getCategory())) {
                    renderingReq.setBooleanFilter(customProp, false);
                } else {
                    CommonPreference<Boolean> pref = prefs.getCustomRenderBooleanProperty(customProp.getAttrName());
                    renderingReq.setBooleanFilter(customProp, pref.get());
                }
            } else if (RenderingRuleStorageProperties.UI_CATEGORY_HIDDEN.equals(customProp.getCategory())) {
                if (customProp.isString()) {
                    renderingReq.setStringFilter(customProp, "");
                } else {
                    renderingReq.setIntFilter(customProp, 0);
                }
            } else {
                CommonPreference<String> settings = prefs.getCustomRenderProperty(customProp.getAttrName());
                String res = settings.get();
                if (!Algorithms.isEmpty(res)) {
                    if (customProp.isString()) {
                        renderingReq.setStringFilter(customProp, res);
                    } else {
                        try {
                            renderingReq.setIntFilter(customProp, Integer.parseInt(res));
                        } catch (NumberFormatException e) {
                            e.printStackTrace();
                        }
                    }
                } else {
                    if (customProp.isString()) {
                        renderingReq.setStringFilter(customProp, "");
                    }
                }
            }
        }
        renderingReq.saveState();
        NativeOsmandLibrary nativeLib = !prefs.SAFE_MODE.get() ? NativeOsmandLibrary.getLibrary(storage, context) : null;
        // calculate data box
        QuadRect dataBox = requestedBox.getLatLonBounds();
        int dataBoxZoom = requestedBox.getZoom();
        long now = System.currentTimeMillis();
        if (cObjectsBox.left > dataBox.left || cObjectsBox.top < dataBox.top || cObjectsBox.right < dataBox.right || cObjectsBox.bottom > dataBox.bottom || (nativeLib != null) == (cNativeObjects == null) || dataBoxZoom != cObjectsZoom || prevInterrupted) {
            // increase data box in order for rotate
            if ((dataBox.right - dataBox.left) > (dataBox.top - dataBox.bottom)) {
                double wi = (dataBox.right - dataBox.left) * .05;
                dataBox.left -= wi;
                dataBox.right += wi;
            } else {
                double hi = (dataBox.top - dataBox.bottom) * .05;
                dataBox.top += hi;
                dataBox.bottom -= hi;
            }
            validateLatLonBox(dataBox);
            renderedState = 0;
            boolean loaded;
            if (nativeLib != null) {
                cObjects = new LinkedList<BinaryMapDataObject>();
                loaded = loadVectorDataNative(dataBox, requestedBox.getZoom(), renderingReq, nativeLib);
            } else {
                cNativeObjects = null;
                loaded = loadVectorData(dataBox, requestedBox.getZoom(), renderingReq);
            }
            if (!loaded || checkWhetherInterrupted()) {
                return;
            }
        }
        final long searchTime = System.currentTimeMillis() - now;
        currentRenderingContext = new OsmandRenderer.RenderingContext(context);
        renderingReq.clearState();
        renderingReq.setIntFilter(renderingReq.ALL.R_MINZOOM, requestedBox.getZoom());
        if (renderingReq.searchRenderingAttribute(RenderingRuleStorageProperties.A_DEFAULT_COLOR)) {
            currentRenderingContext.defaultColor = renderingReq.getIntPropertyValue(renderingReq.ALL.R_ATTR_COLOR_VALUE);
        }
        renderingReq.clearState();
        renderingReq.setIntFilter(renderingReq.ALL.R_MINZOOM, requestedBox.getZoom());
        if (renderingReq.searchRenderingAttribute(RenderingRuleStorageProperties.A_SHADOW_RENDERING)) {
            currentRenderingContext.shadowRenderingMode = renderingReq.getIntPropertyValue(renderingReq.ALL.R_ATTR_INT_VALUE);
            currentRenderingContext.shadowRenderingColor = renderingReq.getIntPropertyValue(renderingReq.ALL.R_SHADOW_COLOR);
        }
        if (renderingReq.searchRenderingAttribute("polygonMinSizeToDisplay")) {
            currentRenderingContext.polygonMinSizeToDisplay = renderingReq.getIntPropertyValue(renderingReq.ALL.R_ATTR_INT_VALUE);
        }
        final QuadPointDouble lt = requestedBox.getLeftTopTile(requestedBox.getZoom());
        double cfd = MapUtils.getPowZoom(requestedBox.getZoomFloatPart()) * requestedBox.getMapDensity();
        lt.x *= cfd;
        lt.y *= cfd;
        // LatLon ltn = requestedBox.getLeftTopLatLon();
        final double tileDivisor = MapUtils.getPowZoom(31 - requestedBox.getZoom()) / cfd;
        currentRenderingContext.leftX = lt.x;
        currentRenderingContext.topY = lt.y;
        currentRenderingContext.zoom = requestedBox.getZoom();
        currentRenderingContext.rotate = requestedBox.getRotate();
        currentRenderingContext.width = requestedBox.getPixWidth();
        currentRenderingContext.height = requestedBox.getPixHeight();
        currentRenderingContext.nightMode = nightMode;
        if (requestedBox.getZoom() <= zoomOnlyForBasemaps && "".equals(prefs.MAP_PREFERRED_LOCALE.get())) {
            currentRenderingContext.preferredLocale = app.getLanguage();
            currentRenderingContext.transliterate = !"ru".equals(app.getLanguage()) && !"uk".equals(app.getLanguage()) && !"be".equals(app.getLanguage()) && !"bg".equals(app.getLanguage()) && !"mk".equals(app.getLanguage()) && !"sr".equals(app.getLanguage());
        } else {
            currentRenderingContext.preferredLocale = prefs.MAP_PREFERRED_LOCALE.get();
            currentRenderingContext.transliterate = prefs.MAP_TRANSLITERATE_NAMES.get();
            if (currentRenderingContext.preferredLocale.equals("en")) {
                currentRenderingContext.transliterate = true;
            }
        }
        final float mapDensity = (float) requestedBox.getMapDensity();
        currentRenderingContext.setDensityValue(mapDensity);
        // Text/icon scales according to mapDensity (so text is size of road)
        // currentRenderingContext.textScale = (requestedBox.getDensity()*app.getSettings().TEXT_SCALE.get());
        // Text/icon stays same for all sizes
        currentRenderingContext.textScale = (requestedBox.getDensity() * app.getSettings().TEXT_SCALE.get()) / mapDensity;
        currentRenderingContext.screenDensityRatio = 1 / Math.max(1, requestedBox.getDensity());
        // init rendering context
        currentRenderingContext.tileDivisor = tileDivisor;
        if (checkWhetherInterrupted()) {
            return;
        }
        now = System.currentTimeMillis();
        Bitmap bmp;
        boolean transparent = false;
        RenderingRuleProperty rr = storage.PROPS.get("noPolygons");
        if (rr != null) {
            transparent = renderingReq.getIntPropertyValue(rr) > 0;
        }
        // 1. generate image step by step
        Bitmap reuse = prevBmp;
        this.prevBmp = this.bmp;
        this.prevBmpLocation = this.bmpLocation;
        // necessary for transparent, otherwise 2 times smaller
        Config cfg = transparent ? Config.ARGB_8888 : Config.RGB_565;
        if (reuse != null && reuse.getWidth() == currentRenderingContext.width && reuse.getHeight() == currentRenderingContext.height && cfg == reuse.getConfig()) {
            bmp = reuse;
            bmp.eraseColor(currentRenderingContext.defaultColor);
        } else {
            if (reuse != null) {
                log.warn(String.format("Create new image ? %d != %d (w) %d != %d (h) ", currentRenderingContext.width, reuse.getWidth(), currentRenderingContext.height, reuse.getHeight()));
            }
            bmp = Bitmap.createBitmap(currentRenderingContext.width, currentRenderingContext.height, cfg);
            if (reuse != null) {
                reuse.recycle();
            }
        }
        this.bmp = bmp;
        this.bmpLocation = tileRect;
        if (nativeLib != null) {
            renderer.generateNewBitmapNative(currentRenderingContext, nativeLib, cNativeObjects, bmp, renderingReq, mapTileDownloader);
        } else {
            renderer.generateNewBitmap(currentRenderingContext, cObjects, bmp, renderingReq, mapTileDownloader);
        }
        // Force to use rendering request in order to prevent Garbage Collector when it is used in C++
        if (renderingReq != null) {
            log.info("Debug :" + renderingReq != null);
        }
        String renderingDebugInfo = currentRenderingContext.renderingDebugInfo;
        currentRenderingContext.ended = true;
        if (checkWhetherInterrupted()) {
            // (be smart a bit do not revert if road already drawn)
            if (currentRenderingContext.lastRenderedKey < OsmandRenderer.DEFAULT_LINE_MAX) {
                reuse = this.bmp;
                this.bmp = this.prevBmp;
                this.bmpLocation = this.prevBmpLocation;
                this.prevBmp = reuse;
                this.prevBmpLocation = null;
            }
            currentRenderingContext = null;
            return;
        } else {
            visibleRenderingContext = currentRenderingContext;
            this.checkedRenderedState = renderedState;
            this.checkedBox = this.bmpLocation;
        }
        currentRenderingContext = null;
        // 2. replace whole image
        // keep cache
        // this.prevBmp = null;
        this.prevBmpLocation = null;
        if (prefs.DEBUG_RENDERING_INFO.get() && OsmandPlugin.getEnabledPlugin(OsmandDevelopmentPlugin.class) != null) {
            // $NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$
            String timeInfo = "Searching: " + searchTime + " ms";
            if (renderingDebugInfo != null) {
                timeInfo += "\n" + renderingDebugInfo;
            }
            final String msg = timeInfo;
            log.info(msg);
            handler.post(new Runnable() {

                @Override
                public void run() {
                    Toast.makeText(context, msg, Toast.LENGTH_LONG).show();
                }
            });
        }
    } catch (RuntimeException e) {
        // $NON-NLS-1$
        log.error("Runtime memory exception", e);
        handler.post(new Runnable() {

            @Override
            public void run() {
                Toast.makeText(context, R.string.rendering_exception, Toast.LENGTH_SHORT).show();
            }
        });
    } catch (OutOfMemoryError e) {
        // $NON-NLS-1$
        log.error("Out of memory error", e);
        cObjects = new ArrayList<BinaryMapDataObject>();
        cObjectsBox = new QuadRect();
        handler.post(new Runnable() {

            @Override
            public void run() {
                // ActivityManager activityManager = (ActivityManager)context.getSystemService(Context.ACTIVITY_SERVICE);
                // ActivityManager.MemoryInfo memoryInfo = new ActivityManager.MemoryInfo();
                // activityManager.getMemoryInfo(memoryInfo);
                // int avl = (int) (memoryInfo.availMem / (1 << 20));
                int max = (int) (Runtime.getRuntime().maxMemory() / (1 << 20));
                int avl = (int) (Runtime.getRuntime().freeMemory() / (1 << 20));
                String s = " (" + avl + " MB available of " + max + ") ";
                Toast.makeText(context, context.getString(R.string.rendering_out_of_memory) + s, Toast.LENGTH_SHORT).show();
            }
        });
    } finally {
        if (currentRenderingContext != null) {
            currentRenderingContext.ended = true;
        }
    }
}
Also used : OsmandApplication(net.osmand.plus.OsmandApplication) Config(android.graphics.Bitmap.Config) TIntArrayList(gnu.trove.list.array.TIntArrayList) ArrayList(java.util.ArrayList) TLongArrayList(gnu.trove.list.array.TLongArrayList) QuadRect(net.osmand.data.QuadRect) Bitmap(android.graphics.Bitmap) BinaryMapDataObject(net.osmand.binary.BinaryMapDataObject) RenderingContext(net.osmand.plus.render.OsmandRenderer.RenderingContext) RotatedTileBox(net.osmand.data.RotatedTileBox) CommonPreference(net.osmand.plus.OsmandSettings.CommonPreference) RenderingRuleProperty(net.osmand.render.RenderingRuleProperty) RenderingRulesStorage(net.osmand.render.RenderingRulesStorage) RenderingRuleSearchRequest(net.osmand.render.RenderingRuleSearchRequest) QuadPointDouble(net.osmand.data.QuadPointDouble)

Example 3 with RenderingRuleSearchRequest

use of net.osmand.render.RenderingRuleSearchRequest in project Osmand by osmandapp.

the class OsmandMapTileView method updateCanvasColors.

private CanvasColors updateCanvasColors() {
    CanvasColors canvasColors = null;
    RenderingRulesStorage rrs = application.getRendererRegistry().getCurrentSelectedRenderer();
    if (rrs != null) {
        canvasColors = new CanvasColors();
        RenderingRuleSearchRequest req = new RenderingRuleSearchRequest(rrs);
        req.setBooleanFilter(rrs.PROPS.R_NIGHT_MODE, false);
        if (req.searchRenderingAttribute(RenderingRuleStorageProperties.A_DEFAULT_COLOR)) {
            canvasColors.colorDay = req.getIntPropertyValue(req.ALL.R_ATTR_COLOR_VALUE);
        }
        req = new RenderingRuleSearchRequest(rrs);
        req.setBooleanFilter(rrs.PROPS.R_NIGHT_MODE, true);
        if (req.searchRenderingAttribute(RenderingRuleStorageProperties.A_DEFAULT_COLOR)) {
            canvasColors.colorNight = req.getIntPropertyValue(req.ALL.R_ATTR_COLOR_VALUE);
        }
    }
    return canvasColors;
}
Also used : RenderingRuleSearchRequest(net.osmand.render.RenderingRuleSearchRequest) RenderingRulesStorage(net.osmand.render.RenderingRulesStorage)

Example 4 with RenderingRuleSearchRequest

use of net.osmand.render.RenderingRuleSearchRequest in project Osmand by osmandapp.

the class GPXLayer method updatePaints.

private int updatePaints(int color, boolean routePoints, boolean currentTrack, DrawSettings nightMode, RotatedTileBox tileBox) {
    RenderingRulesStorage rrs = view.getApplication().getRendererRegistry().getCurrentSelectedRenderer();
    final boolean isNight = nightMode != null && nightMode.isNightMode();
    int hsh = calculateHash(rrs, routePoints, isNight, tileBox.getMapDensity(), tileBox.getZoom());
    if (hsh != cachedHash) {
        cachedHash = hsh;
        cachedColor = ContextCompat.getColor(view.getApplication(), R.color.gpx_track);
        if (rrs != null) {
            RenderingRuleSearchRequest req = new RenderingRuleSearchRequest(rrs);
            req.setBooleanFilter(rrs.PROPS.R_NIGHT_MODE, isNight);
            CommonPreference<String> p = view.getSettings().getCustomRenderProperty("currentTrackColor");
            if (p != null && p.isSet()) {
                RenderingRuleProperty ctColor = rrs.PROPS.get("currentTrackColor");
                if (ctColor != null) {
                    req.setStringFilter(ctColor, p.get());
                }
            }
            CommonPreference<String> p2 = view.getSettings().getCustomRenderProperty("currentTrackWidth");
            if (p2 != null && p2.isSet()) {
                RenderingRuleProperty ctWidth = rrs.PROPS.get("currentTrackWidth");
                if (ctWidth != null) {
                    req.setStringFilter(ctWidth, p2.get());
                }
            }
            String additional = "";
            if (routePoints) {
                additional = "routePoints=true";
            }
            if (currentTrack) {
                additional = (additional.length() == 0 ? "" : ";") + "currentTrack=true";
            }
            req.setIntFilter(rrs.PROPS.R_MINZOOM, tileBox.getZoom());
            req.setIntFilter(rrs.PROPS.R_MAXZOOM, tileBox.getZoom());
            if (additional.length() > 0) {
                req.setStringFilter(rrs.PROPS.R_ADDITIONAL, additional);
            }
            if (req.searchRenderingAttribute("gpx")) {
                RenderingContext rc = new OsmandRenderer.RenderingContext(view.getContext());
                rc.setDensityValue((float) tileBox.getMapDensity());
                cachedColor = req.getIntPropertyValue(rrs.PROPS.R_COLOR);
                osmandRenderer.updatePaint(req, paint, 0, false, rc);
                isPaint2 = osmandRenderer.updatePaint(req, paint2, 1, false, rc);
                isPaint_1 = osmandRenderer.updatePaint(req, paint_1, -1, false, rc);
                isShadowPaint = req.isSpecified(rrs.PROPS.R_SHADOW_RADIUS);
                if (isShadowPaint) {
                    ColorFilter cf = new PorterDuffColorFilter(req.getIntPropertyValue(rrs.PROPS.R_SHADOW_COLOR), Mode.SRC_IN);
                    shadowPaint.setColorFilter(cf);
                    shadowPaint.setStrokeWidth(paint.getStrokeWidth() + 2 * rc.getComplexValue(req, rrs.PROPS.R_SHADOW_RADIUS));
                }
            } else {
                System.err.println("Rendering attribute gpx is not found !");
                paint.setStrokeWidth(7 * view.getDensity());
            }
        }
    }
    paint.setColor(color == 0 ? cachedColor : color);
    return cachedColor;
}
Also used : RenderingContext(net.osmand.plus.render.OsmandRenderer.RenderingContext) PorterDuffColorFilter(android.graphics.PorterDuffColorFilter) ColorFilter(android.graphics.ColorFilter) RenderingRuleSearchRequest(net.osmand.render.RenderingRuleSearchRequest) RenderingRuleProperty(net.osmand.render.RenderingRuleProperty) PorterDuffColorFilter(android.graphics.PorterDuffColorFilter) RenderingRulesStorage(net.osmand.render.RenderingRulesStorage) Paint(android.graphics.Paint)

Example 5 with RenderingRuleSearchRequest

use of net.osmand.render.RenderingRuleSearchRequest in project Osmand by osmandapp.

the class TransportStopRoute method getColor.

public int getColor(OsmandApplication ctx, boolean nightMode) {
    if (cachedColor == 0 || cachedNight != nightMode) {
        cachedColor = ctx.getResources().getColor(R.color.transport_route_line);
        cachedNight = nightMode;
        if (type != null) {
            RenderingRulesStorage rrs = ctx.getRendererRegistry().getCurrentSelectedRenderer();
            RenderingRuleSearchRequest req = new RenderingRuleSearchRequest(rrs);
            req.setBooleanFilter(rrs.PROPS.R_NIGHT_MODE, nightMode);
            String color = route.getColor();
            String typeStr = color == null || color.isEmpty() ? type.getRendeAttr() : color;
            if (req.searchRenderingAttribute(typeStr)) {
                cachedColor = req.getIntPropertyValue(rrs.PROPS.R_ATTR_COLOR_VALUE);
            }
        }
    }
    return cachedColor;
}
Also used : RenderingRuleSearchRequest(net.osmand.render.RenderingRuleSearchRequest) RenderingRulesStorage(net.osmand.render.RenderingRulesStorage)

Aggregations

RenderingRuleSearchRequest (net.osmand.render.RenderingRuleSearchRequest)5 RenderingRulesStorage (net.osmand.render.RenderingRulesStorage)4 RenderingRuleProperty (net.osmand.render.RenderingRuleProperty)3 RenderingContext (net.osmand.plus.render.OsmandRenderer.RenderingContext)2 Bitmap (android.graphics.Bitmap)1 Config (android.graphics.Bitmap.Config)1 ColorFilter (android.graphics.ColorFilter)1 Paint (android.graphics.Paint)1 PorterDuffColorFilter (android.graphics.PorterDuffColorFilter)1 TIntArrayList (gnu.trove.list.array.TIntArrayList)1 TLongArrayList (gnu.trove.list.array.TLongArrayList)1 BufferedImage (java.awt.image.BufferedImage)1 FileInputStream (java.io.FileInputStream)1 InputStream (java.io.InputStream)1 ArrayList (java.util.ArrayList)1 ImageReader (javax.imageio.ImageReader)1 MemoryCacheImageInputStream (javax.imageio.stream.MemoryCacheImageInputStream)1 RenderingContext (net.osmand.RenderingContext)1 BinaryMapDataObject (net.osmand.binary.BinaryMapDataObject)1 QuadPointDouble (net.osmand.data.QuadPointDouble)1