Ticket #1285: AndroidRastermaps1.diff

File AndroidRastermaps1.diff, 8.7 KB (added by jandegr, 6 years ago)
  • android/src/org/navitproject/navit/NavitGraphics.java

     
    2020package org.navitproject.navit;
    2121
    2222import java.io.File;
     23import java.io.FileInputStream;
     24import java.io.IOException;
    2325import java.lang.reflect.Method;
    2426import java.util.ArrayList;
    2527
     
    2628import android.app.Activity;
    2729import android.content.Context;
    2830import android.graphics.Bitmap;
     31import android.graphics.BitmapFactory;
    2932import android.graphics.Canvas;
     33import android.graphics.Matrix;
     34import android.os.Environment;
    3035import android.graphics.Paint;
    3136import android.graphics.Path;
    3237import android.graphics.PointF;
     
    931942                draw_canvas.drawBitmap(bitmap, x, y, paint);
    932943        }
    933944
     945       
     946       
     947        /* takes an image and draws it on the screen as a prerendered maptile
     948         *
     949         *
     950         *
     951         * @param imagepath             a string representing an absolute or relative path
     952         *                                              to the image file
     953         * @param count                 the number of points specified
     954         * @param p0x and p0y   specifying the top left point
     955         * @param p1x and p1y   specifying the top right point
     956         * @param p2x and p2y   specifying the bottom left point, not yet used but kept
     957         *                                              for compatibility with the linux port
     958         *
     959         * TODO make it work with 4 points specified to make it work for 3D mapview, so it can be used
     960         *              for small but very detailed maps as well as for large maps with very little detail but large
     961         *              coverage.
     962         * TODO make it work with rectangular tiles as well ?
     963         */
     964        protected void draw_image_warp(String imagepath, int count, int p0x, int p0y, int p1x, int p1y, int p2x, int p2y)
     965        {
     966       
     967                float width;
     968                float scale;
     969                float deltaY;
     970                float deltaX;
     971                float angle;
     972                Bitmap bitmap = null;
     973                FileInputStream infile;
     974                Matrix matrix; 
     975       
     976                if (count == 3)
     977                {                       
     978                        if (!imagepath.startsWith("/"))
     979                                imagepath = Environment.getExternalStorageDirectory().getPath()+"/navit/"+imagepath;                           
     980                        try
     981                        {
     982                                infile = new FileInputStream(imagepath);
     983                                bitmap = BitmapFactory.decodeStream(infile);
     984                                infile.close();
     985                        }
     986                        catch (IOException e)
     987                        {
     988                                Log.e("NavitGraphics","could not open "+imagepath);
     989                        }
     990                        if (bitmap != null)             
     991                        {
     992                                matrix = new Matrix();
     993                                deltaX = p1x - p0x;
     994                                deltaY = p1y - p0y;
     995                                width = (float) (Math.sqrt((deltaX * deltaX) + (deltaY * deltaY)));                     
     996                                angle = (float) (Math.atan2(deltaY, deltaX) * 180d / Math.PI);
     997                                scale = width / bitmap.getWidth();
     998                                matrix.preScale(scale, scale);
     999                                matrix.postTranslate(p0x, p0y);                 
     1000                                matrix.postRotate(angle, p0x, p0y);
     1001                                draw_canvas.drawBitmap(bitmap, matrix, null);
     1002                        }
     1003                }
     1004        }
     1005       
    9341006        /* These constants must be synchronized with enum draw_mode_num in graphics.h. */
    9351007        public static final int draw_mode_begin = 0;
    9361008        public static final int draw_mode_end = 1;
     
    10001072        public static native String CallbackLocalizedString(String s);
    10011073
    10021074}
     1075
     1076
  • graphics/android/graphics_android.c

     
    3636
    3737struct graphics_priv {
    3838        jclass NavitGraphicsClass;
    39         jmethodID NavitGraphics_draw_polyline, NavitGraphics_draw_polygon, NavitGraphics_draw_rectangle, NavitGraphics_draw_circle, NavitGraphics_draw_text, NavitGraphics_draw_image, NavitGraphics_draw_mode, NavitGraphics_draw_drag, NavitGraphics_overlay_disable, NavitGraphics_overlay_resize, NavitGraphics_SetCamera;
     39        jmethodID NavitGraphics_draw_polyline, NavitGraphics_draw_polygon, NavitGraphics_draw_rectangle, NavitGraphics_draw_circle, NavitGraphics_draw_text, NavitGraphics_draw_image, NavitGraphics_draw_image_warp, NavitGraphics_draw_mode, NavitGraphics_draw_drag, NavitGraphics_overlay_disable, NavitGraphics_overlay_resize, NavitGraphics_SetCamera;
    4040
    4141        jclass PaintClass;
    4242        jmethodID Paint_init,Paint_setStrokeWidth,Paint_setARGB;
     
    364364        (*jnienv)->DeleteLocalRef(jnienv, string);
    365365}
    366366
     367
    367368static void
    368369draw_image(struct graphics_priv *gra, struct graphics_gc_priv *fg, struct point *p, struct graphics_image_priv *img)
    369370{
     
    373374       
    374375}
    375376
     377static void
     378draw_image_warp (struct graphics_priv *gr, struct graphics_gc_priv *fg, struct point *p, int count, char *label)
     379{
     380
     381        /*
     382         *
     383         *
     384         * if coord count==3 then top.left top.right bottom.left
     385         *
     386         */
     387
     388        if (count==3)
     389        {
     390                jstring string = (*jnienv)->NewStringUTF(jnienv, label);
     391                (*jnienv)->CallVoidMethod(jnienv, gr->NavitGraphics, gr->NavitGraphics_draw_image_warp, string, count,  p[0].x, p[0].y,p[1].x, p[1].y, p[2].x, p[2].y);
     392                (*jnienv)->DeleteLocalRef(jnienv, string);
     393        }
     394}
     395
     396
    376397static void draw_drag(struct graphics_priv *gra, struct point *p)
    377398{
    378399        (*jnienv)->CallVoidMethod(jnienv, gra->NavitGraphics, gra->NavitGraphics_draw_drag, p ? p->x : 0, p ? p->y : 0);
     
    452473        draw_circle,
    453474        draw_text,
    454475        draw_image,
    455         NULL,
     476        draw_image_warp,
    456477        draw_drag,
    457478        font_new,
    458479        gc_new,
     
    642663                return 0;
    643664        if (!find_method(ret->NavitGraphicsClass, "draw_image", "(Landroid/graphics/Paint;IILandroid/graphics/Bitmap;)V", &ret->NavitGraphics_draw_image))
    644665                return 0;
     666        if (!find_method(ret->NavitGraphicsClass, "draw_image_warp", "(Ljava/lang/String;IIIIIII)V", &ret->NavitGraphics_draw_image_warp))
     667                return 0;
    645668        if (!find_method(ret->NavitGraphicsClass, "draw_mode", "(I)V", &ret->NavitGraphics_draw_mode))
    646669                return 0;
    647670        if (!find_method(ret->NavitGraphicsClass, "draw_drag", "(II)V", &ret->NavitGraphics_draw_drag))
     
    955978        plugin_register_graphics_type("android", graphics_android_new);
    956979        plugin_register_event_type("android", event_android_new);
    957980}
     981
  • graphics.c

     
    727727{
    728728        struct graphics_image *this_;
    729729        char* hash_key = g_strdup_printf("%s*%d*%d*%d",path,w,h,rotate);
    730 
     730//      dbg(0," image %s, w=%d, h=%d, rotate=%d\n",path,w,h,rotate);
    731731        if ( g_hash_table_lookup_extended( gra->image_cache_hash, hash_key, NULL, (gpointer)&this_) ) {
    732732                g_free(hash_key);
    733733                dbg(lvl_debug,"Found cached image%sfor '%s'\n",this_?" ":" miss ",path);
     
    21482148                }
    21492149                break;
    21502150        case element_image:
    2151                 dbg(lvl_debug,"image: '%s'\n", di->label);
    2152                 if (gra->meth.draw_image_warp) {
     2151        //      dbg(0,"image: '%s'\n", di->label);
     2152                if (gra->meth.draw_image_warp)
     2153
     2154#ifdef HAVE_API_ANDROID
     2155
     2156                        gra->meth.draw_image_warp(gra->priv, gra->gc[0]->priv, pa, count, di->label);
     2157#else
     2158                {
    21532159                        img=graphics_image_new_scaled_rotated(gra, di->label, -1, -1, 0);
    21542160                        if (img)
    21552161                                gra->meth.draw_image_warp(gra->priv, gra->gc[0]->priv, pa, count, img->priv);
    2156                 } else
     2162                }
     2163                else
    21572164                        dbg(lvl_error,"draw_image_warp not supported by graphics driver drawing '%s'\n", di->label);
     2165#endif
    21582166                break;
    21592167        case element_arrows:
    21602168                display_draw_arrows(gra,gc,pa,count);
     
    29692977                curr=g_list_next(curr);
    29702978        }
    29712979}
     2980
  • graphics.h

     
    6868        void (*draw_circle)(struct graphics_priv *gr, struct graphics_gc_priv *gc, struct point *p, int r);
    6969        void (*draw_text)(struct graphics_priv *gr, struct graphics_gc_priv *fg, struct graphics_gc_priv *bg, struct graphics_font_priv *font, char *text, struct point *p, int dx, int dy);
    7070        void (*draw_image)(struct graphics_priv *gr, struct graphics_gc_priv *fg, struct point *p, struct graphics_image_priv *img);
     71#ifdef HAVE_API_ANDROID
     72        void (*draw_image_warp)(struct graphics_priv *gr, struct graphics_gc_priv *fg, struct point *p, int count, char *label);
     73#else
    7174        void (*draw_image_warp)(struct graphics_priv *gr, struct graphics_gc_priv *fg, struct point *p, int count, struct graphics_image_priv *img);
     75#endif
    7276        void (*draw_drag)(struct graphics_priv *gr, struct point *p);
    7377        struct graphics_font_priv *(*font_new)(struct graphics_priv *gr, struct graphics_font_methods *meth, char *font,  int size, int flags);
    7478        struct graphics_gc_priv *(*gc_new)(struct graphics_priv *gr, struct graphics_gc_methods *meth);
  • xslt/map_sdcard_navitmap_bin.xslt

     
    22<xsl:transform version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xi="http://www.w3.org/2001/XInclude">
    33        <xsl:template match="/config/navit/mapset/xi:include">
    44                <maps type="binfile" data="/sdcard/navit/*.bin" />
     5                <maps type="textfile" data="/sdcard/navit/*.txt" />
    56        </xsl:template>
    67</xsl:transform>