Fix:Android:tweak paint routines, more density fixes
authorzoff99 <zoff99@ffa7fe5e-494d-0410-b361-a75ebd5db220>
Sun, 30 Jan 2011 14:52:19 +0000 (14:52 +0000)
committerzoff99 <zoff99@ffa7fe5e-494d-0410-b361-a75ebd5db220>
Sun, 30 Jan 2011 14:52:19 +0000 (14:52 +0000)
git-svn-id: https://navit.svn.sourceforge.net/svnroot/navit/trunk@4069 ffa7fe5e-494d-0410-b361-a75ebd5db220

navit/navit/android/src/org/navitproject/navit/Navit.java
navit/navit/android/src/org/navitproject/navit/NavitAndroidOverlay.java
navit/navit/android/src/org/navitproject/navit/NavitGraphics.java

index 51ba5e4..5ea37dc 100644 (file)
@@ -55,6 +55,7 @@ public class Navit extends Activity implements Handler.Callback
        public static long                                      time_pressed_menu_key                           = 0L;\r
        private static Intent                           startup_intent                                                  = null;\r
        private static long                                     startup_intent_timestamp                        = 0L;\r
+       public static String                                    my_display_density                                      = "mdpi";\r
        \r
        private boolean extractRes(String resname, String result)\r
        {\r
@@ -199,7 +200,7 @@ public class Navit extends Activity implements Handler.Callback
                        Log.e("Navit", "Failed to extract language resource " + langc);\r
                }\r
 \r
-               String my_display_density="mdpi";\r
+               my_display_density="mdpi";\r
                // hdpi display\r
                if (Navit.metrics.densityDpi == 240)\r
                {\r
index 1abd944..e18d19b 100644 (file)
@@ -27,7 +27,6 @@ import android.graphics.RectF;
 import android.graphics.Paint.Style;\r
 import android.os.Bundle;\r
 import android.os.Message;\r
-import android.util.Log;\r
 import android.view.MotionEvent;\r
 import android.widget.ImageView;\r
 \r
@@ -126,7 +125,7 @@ public class NavitAndroidOverlay extends ImageView
        {\r
                return this.draw_bubble;\r
        }\r
-       \r
+\r
        public void hide_bubble()\r
        {\r
                this.draw_bubble = false;\r
@@ -178,9 +177,20 @@ public class NavitAndroidOverlay extends ImageView
        {\r
                //Log.e("Navit", "NavitAndroidOverlay -> onDraw");\r
 \r
-               Paint paint = new Paint(0);\r
-               paint.setAntiAlias(false);\r
-               paint.setColor(Color.GRAY);\r
+               float draw_factor = 1.0f;\r
+               if (Navit.my_display_density.compareTo("mdpi") == 0)\r
+               {\r
+                       draw_factor = 1.0f;\r
+               }\r
+               else if (Navit.my_display_density.compareTo("ldpi") == 0)\r
+               {\r
+                       draw_factor = 0.7f;\r
+               }\r
+               else if (Navit.my_display_density.compareTo("hdpi") == 0)\r
+               {\r
+                       draw_factor = 1.5f;\r
+               }\r
+\r
 \r
                if (this.draw_bubble)\r
                {\r
@@ -235,31 +245,34 @@ public class NavitAndroidOverlay extends ImageView
                {\r
                        //Log.e("Navit", "NavitAndroidOverlay -> onDraw -> bubble");\r
 \r
-                       int dx = 20;\r
-                       int dy = -100;\r
+                       int dx = (int) ((20 / 1.5f) * draw_factor);\r
+                       int dy = (int) ((-100 / 1.5f) * draw_factor);\r
                        Paint bubble_paint = new Paint(0);\r
 \r
+                       int bubble_size_x = (int) ((150 / 1.5f) * draw_factor);\r
+                       int bubble_size_y = (int) ((60 / 1.5f) * draw_factor);\r
+\r
                        // yellow-ish funny lines\r
-                       int lx = 15;\r
-                       int ly = 15;\r
+                       int lx = (int) ((15 / 1.5f) * draw_factor);\r
+                       int ly = (int) ((15 / 1.5f) * draw_factor);\r
                        bubble_paint.setStyle(Style.FILL);\r
                        bubble_paint.setAntiAlias(true);\r
-                       bubble_paint.setStrokeWidth(8);\r
+                       bubble_paint.setStrokeWidth(8 / 1.5f * draw_factor);\r
                        bubble_paint.setColor(Color.parseColor("#FFF8C6"));\r
-                       c.drawLine(this.bubble_001.x + dx, this.bubble_001.y + dy + 60 - ly, this.bubble_001.x,\r
-                                       this.bubble_001.y, bubble_paint);\r
-                       c.drawLine(this.bubble_001.x + dx + lx, this.bubble_001.y + dy + 60, this.bubble_001.x,\r
-                                       this.bubble_001.y, bubble_paint);\r
+                       c.drawLine(this.bubble_001.x + dx, this.bubble_001.y + dy + bubble_size_y - ly,\r
+                                       this.bubble_001.x, this.bubble_001.y, bubble_paint);\r
+                       c.drawLine(this.bubble_001.x + dx + lx, this.bubble_001.y + dy + bubble_size_y,\r
+                                       this.bubble_001.x, this.bubble_001.y, bubble_paint);\r
 \r
                        // draw black funny lines to target\r
                        bubble_paint.setStyle(Style.STROKE);\r
                        bubble_paint.setAntiAlias(true);\r
                        bubble_paint.setStrokeWidth(3);\r
                        bubble_paint.setColor(Color.parseColor("#000000"));\r
-                       c.drawLine(this.bubble_001.x + dx, this.bubble_001.y + dy + 60 - ly, this.bubble_001.x,\r
-                                       this.bubble_001.y, bubble_paint);\r
-                       c.drawLine(this.bubble_001.x + dx + lx, this.bubble_001.y + dy + 60, this.bubble_001.x,\r
-                                       this.bubble_001.y, bubble_paint);\r
+                       c.drawLine(this.bubble_001.x + dx, this.bubble_001.y + dy + bubble_size_y - ly,\r
+                                       this.bubble_001.x, this.bubble_001.y, bubble_paint);\r
+                       c.drawLine(this.bubble_001.x + dx + lx, this.bubble_001.y + dy + bubble_size_y,\r
+                                       this.bubble_001.x, this.bubble_001.y, bubble_paint);\r
 \r
 \r
                        // filled rect yellow-ish\r
@@ -268,9 +281,9 @@ public class NavitAndroidOverlay extends ImageView
                        bubble_paint.setAntiAlias(false);\r
                        bubble_paint.setColor(Color.parseColor("#FFF8C6"));\r
                        RectF box_rect = new RectF(this.bubble_001.x + dx, this.bubble_001.y + dy,\r
-                                       this.bubble_001.x + 150 + dx, this.bubble_001.y + 60 + dy);\r
-                       int rx = 20;\r
-                       int ry = 20;\r
+                                       this.bubble_001.x + bubble_size_x + dx, this.bubble_001.y + bubble_size_y + dy);\r
+                       int rx = (int) (20 / 1.5f * draw_factor);\r
+                       int ry = (int) (20 / 1.5f * draw_factor);\r
                        c.drawRoundRect(box_rect, rx, ry, bubble_paint);\r
 \r
                        // black outlined rect\r
@@ -280,18 +293,25 @@ public class NavitAndroidOverlay extends ImageView
                        bubble_paint.setColor(Color.parseColor("#000000"));\r
                        c.drawRoundRect(box_rect, rx, ry, bubble_paint);\r
 \r
-                       int inner_dx = 30;\r
-                       int inner_dy = 36;\r
+                       int inner_dx = (int) (30 / 1.5f * draw_factor);\r
+                       int inner_dy = (int) (36 / 1.5f * draw_factor);\r
                        bubble_paint.setAntiAlias(true);\r
                        bubble_paint.setStyle(Style.FILL);\r
-                       bubble_paint.setTextSize(20);\r
+                       bubble_paint.setTextSize((int) (20 / 1.5f * draw_factor));\r
                        bubble_paint.setStrokeWidth(3);\r
                        bubble_paint.setColor(Color.parseColor("#3b3131"));\r
                        c.drawText("drive here", this.bubble_001.x + dx + inner_dx, this.bubble_001.y + dy\r
                                        + inner_dy, bubble_paint);\r
                }\r
 \r
-               // test, draw a grey rectangle on top layer!\r
-               // c.drawRect(10, 10, 300, 200, paint);\r
+               //              // test, draw rectangles on top layer!\r
+               //              Paint paint = new Paint(0);\r
+               //              paint.setAntiAlias(false);\r
+               //              paint.setStyle(Style.STROKE);\r
+               //              paint.setColor(Color.GREEN);\r
+               //              c.drawRect(0 * draw_factor, 0 * draw_factor, 64 * draw_factor, 64 * draw_factor, paint);\r
+               //              paint.setColor(Color.RED);\r
+               //              c.drawRect(0 * draw_factor, (0 + 70) * draw_factor, 64 * draw_factor,\r
+               //                              (64 + 70) * draw_factor, paint);\r
        }\r
 }\r
index a33c50e..833fca3 100644 (file)
@@ -34,7 +34,6 @@ import android.graphics.PointF;
 import android.graphics.Rect;
 import android.os.Handler;
 import android.os.Message;
-import android.util.DisplayMetrics;
 import android.util.FloatMath;
 import android.util.Log;
 import android.view.KeyEvent;
@@ -46,30 +45,30 @@ import android.widget.RelativeLayout;
 
 public class NavitGraphics
 {
-       private NavitGraphics                   parent_graphics;
-       private ArrayList                                       overlays                                                                                = new ArrayList();
-       int                                                                     bitmap_w;
-       int                                                                     bitmap_h;
-       int                                                                     pos_x;
-       int                                                                     pos_y;
-       int                                                                     pos_wraparound;
-       int                                                                     overlay_disabled;
-       float                                                                   trackball_x, trackball_y;
-       View                                                                    view;
-       RelativeLayout                                          relativelayout;
-       NavitCamera                                                     camera;
-       Activity                                                                activity;
-
-       public static Boolean                   in_map                                                                          = false;
+       private NavitGraphics           parent_graphics;
+       private ArrayList                               overlays                                                                                = new ArrayList();
+       int                                                             bitmap_w;
+       int                                                             bitmap_h;
+       int                                                             pos_x;
+       int                                                             pos_y;
+       int                                                             pos_wraparound;
+       int                                                             overlay_disabled;
+       float                                                           trackball_x, trackball_y;
+       View                                                            view;
+       RelativeLayout                                  relativelayout;
+       NavitCamera                                             camera;
+       Activity                                                        activity;
+
+       public static Boolean           in_map                                                                          = false;
 
        // for menu key
-       private static long                             time_for_long_press                                             = 300L;
-       private static long                             interval_for_long_press                                 = 200L;
+       private static long                     time_for_long_press                                             = 300L;
+       private static long                     interval_for_long_press                                 = 200L;
 
        // for touch screen
-       private long                                            last_touch_on_screen                                            = 0L;
-       private static long                             long_press_on_screen_interval                   = 1500L;
-       private static float                            long_press_on_screen_max_distance       = 8f;
+       private long                                    last_touch_on_screen                                            = 0L;
+       private static long                     long_press_on_screen_interval                   = 1500L;
+       private static float                    long_press_on_screen_max_distance       = 8f;
 
        // Overlay View for Android
        //
@@ -77,7 +76,6 @@ public class NavitGraphics
        // and get touch events for it (without touching C-code)
        public NavitAndroidOverlay      NavitAOverlay                                                           = null;
 
-
        public void SetCamera(int use_camera)
        {
                if (use_camera != 0 && camera == null)
@@ -116,7 +114,7 @@ public class NavitGraphics
                        last_down_action = System.currentTimeMillis();
                        Log.e("NavitGraphics", "SensorThread created");
                }
-               
+
                public void down()
                {
                        this.is_still_pressing = true;
@@ -257,9 +255,10 @@ public class NavitGraphics
                                protected void onSizeChanged(int w, int h, int oldw, int oldh)
                                {
                                        Log.e("Navit", "NavitGraphics -> onSizeChanged pixels x=" + w + " pixels y=" + h);
-                                       Log.e("Navit", "NavitGraphics -> onSizeChanged dpi="+Navit.metrics.densityDpi);
-                                       Log.e("Navit", "NavitGraphics -> onSizeChanged density="+Navit.metrics.density);
-                                       Log.e("Navit", "NavitGraphics -> onSizeChanged scaledDensity="+Navit.metrics.scaledDensity);
+                                       Log.e("Navit", "NavitGraphics -> onSizeChanged dpi=" + Navit.metrics.densityDpi);
+                                       Log.e("Navit", "NavitGraphics -> onSizeChanged density=" + Navit.metrics.density);
+                                       Log.e("Navit", "NavitGraphics -> onSizeChanged scaledDensity="
+                                                       + Navit.metrics.scaledDensity);
                                        super.onSizeChanged(w, h, oldw, oldh);
                                        draw_bitmap = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888);
                                        draw_canvas = new Canvas(draw_bitmap);
@@ -429,7 +428,7 @@ public class NavitGraphics
                                                        {
 
                                                        }
-                                                       
+
                                                        // was is a long press? or normal quick touch?
                                                        if ((in_map)
                                                                        && ((System.currentTimeMillis() - last_touch_on_screen) > long_press_on_screen_interval))
@@ -466,7 +465,7 @@ public class NavitGraphics
 
                                                                // if we drag, hide the bubble
                                                                NavitAOverlay.hide_bubble();
-                                                               
+
                                                                MotionCallback(MotionCallbackID, x, y);
                                                                ButtonCallback(ButtonCallbackID, 0, 1, x, y); // up
 
@@ -491,11 +490,11 @@ public class NavitGraphics
                                                                        {
                                                                                // zoom in
                                                                                CallbackMessageChannel(1, "");
-                                                                               
+
                                                                                // next lines are a hack, without it screen will not get updated anymore!
                                                                                ButtonCallback(ButtonCallbackID, 1, 1, x, y); // down
-                                                                               MotionCallback(MotionCallbackID, x+15, y);
-                                                                               MotionCallback(MotionCallbackID, x-15, y);
+                                                                               MotionCallback(MotionCallbackID, x + 15, y);
+                                                                               MotionCallback(MotionCallbackID, x - 15, y);
                                                                                ButtonCallback(ButtonCallbackID, 0, 1, x, y); // up
                                                                                this.postInvalidate();
 
@@ -508,8 +507,8 @@ public class NavitGraphics
 
                                                                                // next lines are a hack, without it screen will not get updated anymore!
                                                                                ButtonCallback(ButtonCallbackID, 1, 1, x, y); // down
-                                                                               MotionCallback(MotionCallbackID, x+15, y);
-                                                                               MotionCallback(MotionCallbackID, x-15, y);
+                                                                               MotionCallback(MotionCallbackID, x + 15, y);
+                                                                               MotionCallback(MotionCallbackID, x - 15, y);
                                                                                ButtonCallback(ButtonCallbackID, 0, 1, x, y); // up
                                                                                this.postInvalidate();
 
@@ -1097,53 +1096,138 @@ public class NavitGraphics
        }
 
 
-       protected void draw_polyline(Paint paint, int c[])
+       Path                                                    global_path             = new Path();
+       Rect                                                    global_r                        = new Rect();
+       public static Boolean   power_device    = false;
+
+
+
+       private class t_draw_polyline extends Thread
        {
-               paint.setStyle(Paint.Style.STROKE);
-               Path path = new Path();
-               path.moveTo(c[0], c[1]);
-               for (int i = 2; i < c.length; i += 2)
+               private Boolean running;
+               private Paint           p               = null;
+               private int                     c[]     = null;
+               private Path            pf              = new Path();
+
+               t_draw_polyline(Paint paint, int cc[])
+               {
+                       this.p = paint;
+                       this.c = cc;
+                       this.running = true;
+                       //Log.e("Navit", "t_draw_polyline created");
+               }
+
+               public void run()
                {
-                       path.lineTo(c[i], c[i + 1]);
+                       //Log.e("Navit", "t_draw_polyline started");
+                       p.setStyle(Paint.Style.STROKE);
+                       //pf.reset();
+                       pf.moveTo(c[0], c[1]);
+                       for (int i = 2; i < c.length; i += 2)
+                       {
+                               pf.lineTo(c[i], c[i + 1]);
+                       }
+                       draw_canvas.drawPath(pf, p);
+                       //Log.e("Navit", "t_draw_polyline ended");
                }
-               draw_canvas.drawPath(path, paint);
        }
 
-       protected void draw_polygon(Paint paint, int c[])
+       private class t_draw_polygon extends Thread
        {
-               paint.setStyle(Paint.Style.FILL);
-               Path path = new Path();
-               path.moveTo(c[0], c[1]);
-               for (int i = 2; i < c.length; i += 2)
+               private Boolean running;
+               private Paint           p               = null;
+               private int                     c[]     = null;
+               private Path            pf              = new Path();
+
+               t_draw_polygon(Paint paint, int cc[])
                {
-                       path.lineTo(c[i], c[i + 1]);
+                       this.p = paint;
+                       this.c = cc;
+                       this.running = true;
+               }
+
+               public void run()
+               {
+                       p.setStyle(Paint.Style.FILL);
+                       //pf.reset();
+                       pf.moveTo(c[0], c[1]);
+                       for (int i = 2; i < c.length; i += 2)
+                       {
+                               pf.lineTo(c[i], c[i + 1]);
+                       }
+                       draw_canvas.drawPath(pf, p);
+               }
+       }
+
+       void draw_polyline(Paint paint, int c[])
+       {
+               if (NavitGraphics.power_device)
+               {
+                       t_draw_polyline t = new t_draw_polyline(paint, c);
+                       t.start();
+               }
+               else
+               {
+//                     //Log.e("NavitGraphics","draw_polyline");
+                       paint.setStyle(Paint.Style.STROKE);
+                       global_path.reset();
+                       global_path.moveTo(c[0], c[1]);
+                       for (int i = 2; i < c.length; i += 2)
+                       {
+                               global_path.lineTo(c[i], c[i + 1]);
+                       }
+                       global_path.close();
+                       draw_canvas.drawPath(global_path, paint);
+               }
+       }
+
+       void draw_polygon(Paint paint, int c[])
+       {
+               if (NavitGraphics.power_device)
+               {
+                       t_draw_polygon t = new t_draw_polygon(paint, c);
+                       t.start();
+               }
+               else
+               {
+                       //Log.e("NavitGraphics","draw_polygon");
+                       paint.setStyle(Paint.Style.FILL);
+                       global_path.reset();
+                       global_path.moveTo(c[0], c[1]);
+                       for (int i = 2; i < c.length; i += 2)
+                       {
+                               global_path.lineTo(c[i], c[i + 1]);
+                       }
+                       global_path.close();
+                       draw_canvas.drawPath(global_path, paint);
                }
-               draw_canvas.drawPath(path, paint);
        }
        protected void draw_rectangle(Paint paint, int x, int y, int w, int h)
        {
-               Rect r = new Rect(x, y, x + w, y + h);
+               //Log.e("NavitGraphics","draw_rectangle");
+               global_r.set(x, y, x + w, y + h);
                paint.setStyle(Paint.Style.FILL);
-               draw_canvas.drawRect(r, paint);
+               draw_canvas.drawRect(global_r, paint);
        }
        protected void draw_circle(Paint paint, int x, int y, int r)
        {
-               float fx = x;
-               float fy = y;
-               float fr = r / 2;
+               //Log.e("NavitGraphics","draw_circle");
+               //              float fx = x;
+               //              float fy = y;
+               //              float fr = r / 2;
                paint.setStyle(Paint.Style.STROKE);
-               draw_canvas.drawCircle(fx, fy, fr, paint);
+               draw_canvas.drawCircle(x, y, r / 2, paint);
        }
        protected void draw_text(Paint paint, int x, int y, String text, int size, int dx, int dy)
        {
-               float fx = x;
-               float fy = y;
-               // Log.e("NavitGraphics","Text size "+size + " vs " + paint.getTextSize());
-               paint.setTextSize((float) size / 15);
+               //              float fx = x;
+               //              float fy = y;
+               //Log.e("NavitGraphics","Text size "+size + " vs " + paint.getTextSize());
+               paint.setTextSize(size / 15);
                paint.setStyle(Paint.Style.FILL);
                if (dx == 0x10000 && dy == 0)
                {
-                       draw_canvas.drawText(text, fx, fy, paint);
+                       draw_canvas.drawText(text, x, y, paint);
                }
                else
                {
@@ -1156,11 +1240,10 @@ public class NavitGraphics
        }
        protected void draw_image(Paint paint, int x, int y, Bitmap bitmap)
        {
-               // Log.e("NavitGraphics","draw_image");
-
-               float fx = x;
-               float fy = y;
-               draw_canvas.drawBitmap(bitmap, fx, fy, paint);
+               //Log.e("NavitGraphics","draw_image");
+               //              float fx = x;
+               //              float fy = y;
+               draw_canvas.drawBitmap(bitmap, x, y, paint);
        }
        protected void draw_mode(int mode)
        {