Search in sources :

Example 1 with RenderingRuleProperty

use of net.osmand.render.RenderingRuleProperty 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 RenderingRuleProperty

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

the class ConfigureMapMenu method createListAdapter.

public ContextMenuAdapter createListAdapter(final MapActivity ma) {
    ContextMenuAdapter adapter = new ContextMenuAdapter();
    adapter.setDefaultLayoutId(R.layout.list_item_icon_and_menu);
    adapter.addItem(new ContextMenuItem.ItemBuilder().setTitleId(R.string.app_modes_choose, ma).setLayout(R.layout.mode_toggles).createItem());
    adapter.setChangeAppModeListener(new OnClickListener() {

        @Override
        public void onClick() {
            ma.getDashboard().updateListAdapter(createListAdapter(ma));
        }
    });
    RenderingRulesStorage renderer = ma.getMyApplication().getRendererRegistry().getCurrentSelectedRenderer();
    List<RenderingRuleProperty> customRules = new ArrayList<>();
    boolean hasDepthContours = ma.getMyApplication().getResourceManager().hasDepthContours();
    if (renderer != null) {
        for (RenderingRuleProperty p : renderer.PROPS.getCustomRules()) {
            if (!RenderingRuleStorageProperties.UI_CATEGORY_HIDDEN.equals(p.getCategory()) && (hasDepthContours || !p.getAttrName().equals("depthContours"))) {
                customRules.add(p);
            }
        }
    }
    createLayersItems(customRules, adapter, ma);
    createRenderingAttributeItems(customRules, adapter, ma);
    return adapter;
}
Also used : ContextMenuAdapter(net.osmand.plus.ContextMenuAdapter) TIntArrayList(gnu.trove.list.array.TIntArrayList) ArrayList(java.util.ArrayList) RenderingRuleProperty(net.osmand.render.RenderingRuleProperty) RenderingRulesStorage(net.osmand.render.RenderingRulesStorage)

Example 3 with RenderingRuleProperty

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

the class ConfigureMapMenu method createProperties.

private ContextMenuItem createProperties(List<RenderingRuleProperty> customRules, final List<RenderingRuleProperty> customRulesIncluded, @StringRes final int strId, @DrawableRes final int icon, String category, final ListStringPreference defaultSettings, final ContextMenuAdapter adapter, final MapActivity activity, final boolean useDescription) {
    final List<RenderingRuleProperty> ps = new ArrayList<>();
    final List<OsmandSettings.CommonPreference<Boolean>> prefs = new ArrayList<>();
    Iterator<RenderingRuleProperty> it = customRules.iterator();
    while (it.hasNext()) {
        RenderingRuleProperty p = it.next();
        if (category.equals(p.getCategory()) && p.isBoolean()) {
            ps.add(p);
            final OsmandSettings.CommonPreference<Boolean> pref = activity.getMyApplication().getSettings().getCustomRenderBooleanProperty(p.getAttrName());
            prefs.add(pref);
            it.remove();
        }
    }
    if (prefs.size() > 0) {
        final List<OsmandSettings.CommonPreference<String>> includedPrefs = new ArrayList<>();
        if (customRulesIncluded != null) {
            for (RenderingRuleProperty p : customRulesIncluded) {
                if (!p.isBoolean()) {
                    final OsmandSettings.CommonPreference<String> pref = activity.getMyApplication().getSettings().getCustomRenderProperty(p.getAttrName());
                    includedPrefs.add(pref);
                }
            }
        }
        final ItemClickListener clickListener = new ContextMenuAdapter.ItemClickListener() {

            @Override
            public boolean onContextMenuClick(ArrayAdapter<ContextMenuItem> a, int itemId, int pos, boolean isChecked, int[] viewCoordinates) {
                if (!isChecked && !useDescription) {
                    if (defaultSettings != null) {
                        defaultSettings.set("");
                        for (int i = 0; i < prefs.size(); i++) {
                            if (prefs.get(i).get()) {
                                defaultSettings.addValue(prefs.get(i).getId());
                            }
                        }
                    }
                    for (int i = 0; i < prefs.size(); i++) {
                        prefs.get(i).set(false);
                    }
                    adapter.getItem(pos).setColorRes(ContextMenuItem.INVALID_ID);
                    a.notifyDataSetInvalidated();
                    refreshMapComplete(activity);
                    activity.getMapLayers().updateLayers(activity.getMapView());
                } else {
                    showPreferencesDialog(adapter, a, pos, activity, activity.getString(strId), ps, prefs, useDescription, defaultSettings, true, customRulesIncluded);
                }
                return false;
            }
        };
        ContextMenuItem.ItemBuilder builder = new ContextMenuItem.ItemBuilder().setTitleId(strId, activity).setIcon(icon).setListener(clickListener);
        boolean selected = false;
        for (OsmandSettings.CommonPreference<Boolean> p : prefs) {
            if (p.get()) {
                selected = true;
                break;
            }
        }
        if (!selected && includedPrefs.size() > 0) {
            for (OsmandSettings.CommonPreference<String> p : includedPrefs) {
                if (!Algorithms.isEmpty(p.get())) {
                    selected = true;
                    break;
                }
            }
        }
        builder.setColor(selected ? R.color.osmand_orange : ContextMenuItem.INVALID_ID);
        if (useDescription) {
            final String descr = getDescription(prefs, includedPrefs);
            builder.setDescription(descr);
            builder.setLayout(R.layout.list_item_single_line_descrition_narrow);
        } else {
            builder.setListener(new OnRowItemClick() {

                @Override
                public boolean onContextMenuClick(ArrayAdapter<ContextMenuItem> a, int itemId, int pos, boolean isChecked, int[] viewCoordinates) {
                    return clickListener.onContextMenuClick(a, itemId, pos, isChecked, null);
                }

                @Override
                public boolean onRowItemClick(ArrayAdapter<ContextMenuItem> a, View view, int itemId, int pos) {
                    showPreferencesDialog(adapter, a, pos, activity, activity.getString(strId), ps, prefs, useDescription, defaultSettings, false, customRulesIncluded);
                    return false;
                }
            });
            builder.setSecondaryIcon(R.drawable.ic_action_additional_option);
            builder.setSelected(selected);
        }
        return builder.createItem();
    // createCustomRenderingProperties(adapter, activity, ps);
    }
    return null;
}
Also used : ItemClickListener(net.osmand.plus.ContextMenuAdapter.ItemClickListener) CommonPreference(net.osmand.plus.OsmandSettings.CommonPreference) ContextMenuItem(net.osmand.plus.ContextMenuItem) TIntArrayList(gnu.trove.list.array.TIntArrayList) ArrayList(java.util.ArrayList) RenderingRuleProperty(net.osmand.render.RenderingRuleProperty) OnRowItemClick(net.osmand.plus.ContextMenuAdapter.OnRowItemClick) AppCompatCheckedTextView(android.support.v7.widget.AppCompatCheckedTextView) ImageView(android.widget.ImageView) View(android.view.View) AdapterView(android.widget.AdapterView) TextView(android.widget.TextView) ListView(android.widget.ListView) OsmandMapTileView(net.osmand.plus.views.OsmandMapTileView) OsmandSettings(net.osmand.plus.OsmandSettings) ArrayAdapter(android.widget.ArrayAdapter)

Example 4 with RenderingRuleProperty

use of net.osmand.render.RenderingRuleProperty 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 5 with RenderingRuleProperty

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

the class OsmandRenderer method updatePaint.

public boolean updatePaint(RenderingRuleSearchRequest req, Paint p, int ind, boolean area, RenderingContext rc) {
    RenderingRuleProperty rColor;
    RenderingRuleProperty rStrokeW;
    RenderingRuleProperty rCap;
    RenderingRuleProperty rPathEff;
    if (ind == 0) {
        rColor = req.ALL.R_COLOR;
        rStrokeW = req.ALL.R_STROKE_WIDTH;
        rCap = req.ALL.R_CAP;
        rPathEff = req.ALL.R_PATH_EFFECT;
    } else if (ind == 1) {
        rColor = req.ALL.R_COLOR_2;
        rStrokeW = req.ALL.R_STROKE_WIDTH_2;
        rCap = req.ALL.R_CAP_2;
        rPathEff = req.ALL.R_PATH_EFFECT_2;
    } else if (ind == -1) {
        rColor = req.ALL.R_COLOR_0;
        rStrokeW = req.ALL.R_STROKE_WIDTH_0;
        rCap = req.ALL.R_CAP_0;
        rPathEff = req.ALL.R_PATH_EFFECT_0;
    } else if (ind == -2) {
        rColor = req.ALL.R_COLOR__1;
        rStrokeW = req.ALL.R_STROKE_WIDTH__1;
        rCap = req.ALL.R_CAP__1;
        rPathEff = req.ALL.R_PATH_EFFECT__1;
    } else if (ind == 2) {
        rColor = req.ALL.R_COLOR_3;
        rStrokeW = req.ALL.R_STROKE_WIDTH_3;
        rCap = req.ALL.R_CAP_3;
        rPathEff = req.ALL.R_PATH_EFFECT_3;
    } else if (ind == -3) {
        rColor = req.ALL.R_COLOR__2;
        rStrokeW = req.ALL.R_STROKE_WIDTH__2;
        rCap = req.ALL.R_CAP__2;
        rPathEff = req.ALL.R_PATH_EFFECT__2;
    } else if (ind == 3) {
        rColor = req.ALL.R_COLOR_4;
        rStrokeW = req.ALL.R_STROKE_WIDTH_4;
        rCap = req.ALL.R_CAP_4;
        rPathEff = req.ALL.R_PATH_EFFECT_4;
    } else {
        rColor = req.ALL.R_COLOR_5;
        rStrokeW = req.ALL.R_STROKE_WIDTH_5;
        rCap = req.ALL.R_CAP_5;
        rPathEff = req.ALL.R_PATH_EFFECT_5;
    }
    if (area) {
        if (!req.isSpecified(rColor) && !req.isSpecified(req.ALL.R_SHADER)) {
            return false;
        }
        p.setShader(null);
        p.setColorFilter(null);
        p.clearShadowLayer();
        p.setStyle(Style.FILL_AND_STROKE);
        p.setStrokeWidth(0);
    } else {
        if (!req.isSpecified(rStrokeW)) {
            return false;
        }
        p.setShader(null);
        p.setColorFilter(null);
        p.clearShadowLayer();
        p.setStyle(Style.STROKE);
        p.setStrokeWidth(rc.getComplexValue(req, rStrokeW));
        String cap = req.getStringPropertyValue(rCap);
        if (!Algorithms.isEmpty(cap)) {
            p.setStrokeCap(Cap.valueOf(cap.toUpperCase()));
        } else {
            p.setStrokeCap(Cap.BUTT);
        }
        String pathEffect = req.getStringPropertyValue(rPathEff);
        if (!Algorithms.isEmpty(pathEffect)) {
            if (!parsedDashEffects.containsKey(pathEffect)) {
                String[] vls = pathEffect.split("_");
                float[] vs = new float[vls.length * 2];
                for (int i = 0; i < vls.length; i++) {
                    int s = vls[i].indexOf(':');
                    String pre = vls[i];
                    String post = "";
                    if (s != -1) {
                        pre = vls[i].substring(0, i);
                        post = vls[i].substring(i + 1);
                    }
                    if (pre.length() > 0) {
                        vs[i * 2] = Float.parseFloat(pre);
                    }
                    if (post.length() > 0) {
                        vs[i * 2 + 1] = Float.parseFloat(post);
                    }
                }
                parsedDashEffects.put(pathEffect, vs);
            }
            float[] cachedValues = parsedDashEffects.get(pathEffect);
            p.setPathEffect(getDashEffect(rc, cachedValues, 0));
        } else {
            p.setPathEffect(null);
        }
    }
    p.setColor(req.getIntPropertyValue(rColor));
    if (ind == 0) {
        String resId = req.getStringPropertyValue(req.ALL.R_SHADER);
        if (resId != null) {
            if (req.getIntPropertyValue(rColor) == 0) {
                // set color required by skia
                p.setColor(Color.WHITE);
            }
            p.setShader(getShader(resId));
        }
        // do not check shadow color here
        if (rc.shadowRenderingMode == ShadowRenderingMode.ONE_STEP.value) {
            int shadowColor = req.getIntPropertyValue(req.ALL.R_SHADOW_COLOR);
            if (shadowColor == 0) {
                shadowColor = rc.shadowRenderingColor;
            }
            int shadowRadius = (int) rc.getComplexValue(req, req.ALL.R_SHADOW_RADIUS);
            if (shadowColor == 0) {
                shadowRadius = 0;
            }
            p.setShadowLayer(shadowRadius, 0, 0, shadowColor);
        }
    }
    return true;
}
Also used : RenderingRuleProperty(net.osmand.render.RenderingRuleProperty) Paint(android.graphics.Paint)

Aggregations

RenderingRuleProperty (net.osmand.render.RenderingRuleProperty)14 OsmandSettings (net.osmand.plus.OsmandSettings)8 View (android.view.View)7 ArrayList (java.util.ArrayList)7 ArrayAdapter (android.widget.ArrayAdapter)6 TIntArrayList (gnu.trove.list.array.TIntArrayList)6 ContextMenuItem (net.osmand.plus.ContextMenuItem)6 CommonPreference (net.osmand.plus.OsmandSettings.CommonPreference)6 RenderingRulesStorage (net.osmand.render.RenderingRulesStorage)6 AdapterView (android.widget.AdapterView)5 ImageView (android.widget.ImageView)5 TextView (android.widget.TextView)5 OsmandApplication (net.osmand.plus.OsmandApplication)5 DialogInterface (android.content.DialogInterface)4 AlertDialog (android.support.v7.app.AlertDialog)4 AppCompatCheckedTextView (android.support.v7.widget.AppCompatCheckedTextView)4 ListView (android.widget.ListView)4 ContextMenuAdapter (net.osmand.plus.ContextMenuAdapter)4 OsmandMapTileView (net.osmand.plus.views.OsmandMapTileView)4 SwitchCompat (android.support.v7.widget.SwitchCompat)3