From ec08c7dde813b4f0db93a6d56168bf6455e3fc59 Mon Sep 17 00:00:00 2001 From: zoff99 Date: Sun, 30 Jan 2011 14:52:19 +0000 Subject: [PATCH] Fix:Android:tweak paint routines, more density fixes git-svn-id: https://navit.svn.sourceforge.net/svnroot/navit/trunk@4069 ffa7fe5e-494d-0410-b361-a75ebd5db220 --- .../android/src/org/navitproject/navit/Navit.java | 3 +- .../navitproject/navit/NavitAndroidOverlay.java | 72 ++++--- .../src/org/navitproject/navit/NavitGraphics.java | 209 ++++++++++++++------- 3 files changed, 194 insertions(+), 90 deletions(-) diff --git a/navit/navit/android/src/org/navitproject/navit/Navit.java b/navit/navit/android/src/org/navitproject/navit/Navit.java index 51ba5e4..5ea37dc 100644 --- a/navit/navit/android/src/org/navitproject/navit/Navit.java +++ b/navit/navit/android/src/org/navitproject/navit/Navit.java @@ -55,6 +55,7 @@ public class Navit extends Activity implements Handler.Callback public static long time_pressed_menu_key = 0L; private static Intent startup_intent = null; private static long startup_intent_timestamp = 0L; + public static String my_display_density = "mdpi"; private boolean extractRes(String resname, String result) { @@ -199,7 +200,7 @@ public class Navit extends Activity implements Handler.Callback Log.e("Navit", "Failed to extract language resource " + langc); } - String my_display_density="mdpi"; + my_display_density="mdpi"; // hdpi display if (Navit.metrics.densityDpi == 240) { diff --git a/navit/navit/android/src/org/navitproject/navit/NavitAndroidOverlay.java b/navit/navit/android/src/org/navitproject/navit/NavitAndroidOverlay.java index 1abd944..e18d19b 100644 --- a/navit/navit/android/src/org/navitproject/navit/NavitAndroidOverlay.java +++ b/navit/navit/android/src/org/navitproject/navit/NavitAndroidOverlay.java @@ -27,7 +27,6 @@ import android.graphics.RectF; import android.graphics.Paint.Style; import android.os.Bundle; import android.os.Message; -import android.util.Log; import android.view.MotionEvent; import android.widget.ImageView; @@ -126,7 +125,7 @@ public class NavitAndroidOverlay extends ImageView { return this.draw_bubble; } - + public void hide_bubble() { this.draw_bubble = false; @@ -178,9 +177,20 @@ public class NavitAndroidOverlay extends ImageView { //Log.e("Navit", "NavitAndroidOverlay -> onDraw"); - Paint paint = new Paint(0); - paint.setAntiAlias(false); - paint.setColor(Color.GRAY); + float draw_factor = 1.0f; + if (Navit.my_display_density.compareTo("mdpi") == 0) + { + draw_factor = 1.0f; + } + else if (Navit.my_display_density.compareTo("ldpi") == 0) + { + draw_factor = 0.7f; + } + else if (Navit.my_display_density.compareTo("hdpi") == 0) + { + draw_factor = 1.5f; + } + if (this.draw_bubble) { @@ -235,31 +245,34 @@ public class NavitAndroidOverlay extends ImageView { //Log.e("Navit", "NavitAndroidOverlay -> onDraw -> bubble"); - int dx = 20; - int dy = -100; + int dx = (int) ((20 / 1.5f) * draw_factor); + int dy = (int) ((-100 / 1.5f) * draw_factor); Paint bubble_paint = new Paint(0); + int bubble_size_x = (int) ((150 / 1.5f) * draw_factor); + int bubble_size_y = (int) ((60 / 1.5f) * draw_factor); + // yellow-ish funny lines - int lx = 15; - int ly = 15; + int lx = (int) ((15 / 1.5f) * draw_factor); + int ly = (int) ((15 / 1.5f) * draw_factor); bubble_paint.setStyle(Style.FILL); bubble_paint.setAntiAlias(true); - bubble_paint.setStrokeWidth(8); + bubble_paint.setStrokeWidth(8 / 1.5f * draw_factor); bubble_paint.setColor(Color.parseColor("#FFF8C6")); - c.drawLine(this.bubble_001.x + dx, this.bubble_001.y + dy + 60 - ly, this.bubble_001.x, - this.bubble_001.y, bubble_paint); - c.drawLine(this.bubble_001.x + dx + lx, this.bubble_001.y + dy + 60, this.bubble_001.x, - this.bubble_001.y, bubble_paint); + c.drawLine(this.bubble_001.x + dx, this.bubble_001.y + dy + bubble_size_y - ly, + this.bubble_001.x, this.bubble_001.y, bubble_paint); + c.drawLine(this.bubble_001.x + dx + lx, this.bubble_001.y + dy + bubble_size_y, + this.bubble_001.x, this.bubble_001.y, bubble_paint); // draw black funny lines to target bubble_paint.setStyle(Style.STROKE); bubble_paint.setAntiAlias(true); bubble_paint.setStrokeWidth(3); bubble_paint.setColor(Color.parseColor("#000000")); - c.drawLine(this.bubble_001.x + dx, this.bubble_001.y + dy + 60 - ly, this.bubble_001.x, - this.bubble_001.y, bubble_paint); - c.drawLine(this.bubble_001.x + dx + lx, this.bubble_001.y + dy + 60, this.bubble_001.x, - this.bubble_001.y, bubble_paint); + c.drawLine(this.bubble_001.x + dx, this.bubble_001.y + dy + bubble_size_y - ly, + this.bubble_001.x, this.bubble_001.y, bubble_paint); + c.drawLine(this.bubble_001.x + dx + lx, this.bubble_001.y + dy + bubble_size_y, + this.bubble_001.x, this.bubble_001.y, bubble_paint); // filled rect yellow-ish @@ -268,9 +281,9 @@ public class NavitAndroidOverlay extends ImageView bubble_paint.setAntiAlias(false); bubble_paint.setColor(Color.parseColor("#FFF8C6")); RectF box_rect = new RectF(this.bubble_001.x + dx, this.bubble_001.y + dy, - this.bubble_001.x + 150 + dx, this.bubble_001.y + 60 + dy); - int rx = 20; - int ry = 20; + this.bubble_001.x + bubble_size_x + dx, this.bubble_001.y + bubble_size_y + dy); + int rx = (int) (20 / 1.5f * draw_factor); + int ry = (int) (20 / 1.5f * draw_factor); c.drawRoundRect(box_rect, rx, ry, bubble_paint); // black outlined rect @@ -280,18 +293,25 @@ public class NavitAndroidOverlay extends ImageView bubble_paint.setColor(Color.parseColor("#000000")); c.drawRoundRect(box_rect, rx, ry, bubble_paint); - int inner_dx = 30; - int inner_dy = 36; + int inner_dx = (int) (30 / 1.5f * draw_factor); + int inner_dy = (int) (36 / 1.5f * draw_factor); bubble_paint.setAntiAlias(true); bubble_paint.setStyle(Style.FILL); - bubble_paint.setTextSize(20); + bubble_paint.setTextSize((int) (20 / 1.5f * draw_factor)); bubble_paint.setStrokeWidth(3); bubble_paint.setColor(Color.parseColor("#3b3131")); c.drawText("drive here", this.bubble_001.x + dx + inner_dx, this.bubble_001.y + dy + inner_dy, bubble_paint); } - // test, draw a grey rectangle on top layer! - // c.drawRect(10, 10, 300, 200, paint); + // // test, draw rectangles on top layer! + // Paint paint = new Paint(0); + // paint.setAntiAlias(false); + // paint.setStyle(Style.STROKE); + // paint.setColor(Color.GREEN); + // c.drawRect(0 * draw_factor, 0 * draw_factor, 64 * draw_factor, 64 * draw_factor, paint); + // paint.setColor(Color.RED); + // c.drawRect(0 * draw_factor, (0 + 70) * draw_factor, 64 * draw_factor, + // (64 + 70) * draw_factor, paint); } } diff --git a/navit/navit/android/src/org/navitproject/navit/NavitGraphics.java b/navit/navit/android/src/org/navitproject/navit/NavitGraphics.java index a33c50e..833fca3 100644 --- a/navit/navit/android/src/org/navitproject/navit/NavitGraphics.java +++ b/navit/navit/android/src/org/navitproject/navit/NavitGraphics.java @@ -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) { -- 2.7.4