1 | /**
|
1 | /**
|
2 | * ZANavi, Zoff Android Navigation system.
|
2 | * ZANavi, Zoff Android Navigation system.
|
3 | * Copyright (C) 2013 Zoff <zoff@zoff.cc>
|
3 | * Copyright (C) 2013 - 2015 Zoff <zoff@zoff.cc>
|
4 | *
|
4 | *
|
5 | * This program is free software; you can redistribute it and/or
|
5 | * This program is free software; you can redistribute it and/or
|
6 | * modify it under the terms of the GNU General Public License
|
6 | * modify it under the terms of the GNU General Public License
|
7 | * version 2 as published by the Free Software Foundation.
|
7 | * version 2 as published by the Free Software Foundation.
|
8 | *
|
8 | *
|
… | |
… | |
18 | */
|
18 | */
|
19 |
|
19 |
|
20 | package com.zoffcc.applications.zanavi;
|
20 | package com.zoffcc.applications.zanavi;
|
21 |
|
21 |
|
22 | import android.content.Context;
|
22 | import android.content.Context;
|
|
|
23 | import android.content.res.Resources;
|
|
|
24 | import android.graphics.Bitmap;
|
|
|
25 | import android.graphics.BitmapFactory;
|
23 | import android.graphics.Canvas;
|
26 | import android.graphics.Canvas;
|
24 | import android.graphics.Color;
|
|
|
25 | import android.graphics.Paint;
|
27 | import android.graphics.Paint;
|
26 | import android.graphics.RectF;
|
|
|
27 | import android.util.AttributeSet;
|
28 | import android.util.AttributeSet;
|
28 | import android.view.View;
|
29 | import android.widget.ImageView;
|
29 |
|
30 |
|
30 | public class ZANaviOSDCompass extends View
|
31 | public class ZANaviOSDCompass extends ImageView
|
31 | {
|
32 | {
|
32 |
|
33 | int w = 10;
|
|
|
34 | int h = 10;
|
|
|
35 | float w2 = w / 2;
|
|
|
36 | float h2 = h / 2;
|
|
|
37 | Bitmap bitmap_measure = null;
|
33 | private Paint paint = new Paint();
|
38 | Paint paint_2 = new Paint();
|
34 | private RectF f;
|
39 | Paint paint_3 = new Paint();
|
35 | int end_x;
|
40 | int cx = 0;
|
36 | int end_y;
|
41 | int cy = 0;
|
37 | float draw_factor = 1;
|
|
|
38 | int radius = 0;
|
|
|
39 | int compass_center_x = 0;
|
|
|
40 | int compass_center_y = 0;
|
|
|
41 |
|
42 |
|
42 | public ZANaviOSDCompass(Context context)
|
43 | public ZANaviOSDCompass(Context context)
|
43 | {
|
44 | {
|
44 | super(context);
|
45 | super(context);
|
45 | f = new RectF(0 + 3, 0 + 3, NavitOSDJava.compass_w - 3, NavitOSDJava.compass_h - 3);
|
46 |
|
|
|
47 | Resources res = getResources();
|
|
|
48 | bitmap_measure = BitmapFactory.decodeResource(res, R.drawable.zanavi_measure);
|
|
|
49 | paint_2.setDither(true);
|
|
|
50 | paint_2.setAntiAlias(true);
|
|
|
51 |
|
|
|
52 | paint_3.setColor(0xffcc0000);
|
|
|
53 | paint_3.setStyle(Paint.Style.FILL);
|
|
|
54 | // paint_3.setStrokeWidth(4);
|
46 | }
|
55 | }
|
47 |
|
56 |
|
48 | public ZANaviOSDCompass(Context context, AttributeSet attrs)
|
57 | public ZANaviOSDCompass(Context context, AttributeSet attrs)
|
49 | {
|
58 | {
|
50 | super(context, attrs);
|
59 | super(context, attrs);
|
51 | f = new RectF(0 + 3, 0 + 3, NavitOSDJava.compass_w - 3, NavitOSDJava.compass_h - 3);
|
60 |
|
|
|
61 | Resources res = getResources();
|
|
|
62 | bitmap_measure = BitmapFactory.decodeResource(res, R.drawable.zanavi_measure);
|
|
|
63 | paint_2.setDither(true);
|
|
|
64 | paint_2.setAntiAlias(true);
|
|
|
65 |
|
|
|
66 | paint_3.setColor(0xffcc0000);
|
|
|
67 | paint_3.setStyle(Paint.Style.FILL);
|
|
|
68 | // paint_3.setStrokeWidth(4);
|
52 | }
|
69 | }
|
53 |
|
70 |
|
54 | @Override
|
71 | @Override
|
55 | public void onSizeChanged(int w, int h, int oldw, int oldh)
|
72 | public void onSizeChanged(int w1, int h1, int oldw, int oldh)
|
56 | {
|
73 | {
|
57 | super.onSizeChanged(w, h, oldw, oldh);
|
74 | super.onSizeChanged(w1, h1, oldw, oldh);
|
58 | f = new RectF(0 + 12 * draw_factor, 0 + 12 * draw_factor, w - 12 * draw_factor, h - 12 * draw_factor);
|
75 | this.w = w1;
|
|
|
76 | this.h = h1;
|
|
|
77 | this.w2 = w / 2;
|
|
|
78 | this.h2 = h / 2;
|
59 |
|
79 |
|
60 | radius = (int) ((w / 2) - (13 * draw_factor));
|
80 | cx = (w - bitmap_measure.getWidth()) / 2;
|
61 | compass_center_x = w / 2;
|
81 | cy = (h - bitmap_measure.getHeight()) / 2;
|
62 | compass_center_y = h / 2;
|
|
|
63 |
|
|
|
64 | draw_factor = 1.0f;
|
|
|
65 | if (Navit.my_display_density.compareTo("mdpi") == 0)
|
|
|
66 | {
|
|
|
67 | draw_factor = 1.0f;
|
|
|
68 | }
|
|
|
69 | else if (Navit.my_display_density.compareTo("ldpi") == 0)
|
|
|
70 | {
|
|
|
71 | draw_factor = 0.7f;
|
|
|
72 | }
|
|
|
73 | else if (Navit.my_display_density.compareTo("hdpi") == 0)
|
|
|
74 | {
|
|
|
75 | draw_factor = 1.5f;
|
|
|
76 | }
|
|
|
77 |
|
|
|
78 | // correct for ultra high DPI
|
|
|
79 | if (Navit.metrics.densityDpi >= 320) //&& (Navit.PREF_shrink_on_high_dpi))
|
|
|
80 | {
|
|
|
81 | draw_factor = 1.8f * Navit.metrics.densityDpi / NavitGraphics.Global_want_dpi_other;
|
|
|
82 | }
|
|
|
83 |
|
|
|
84 | float real_factor = draw_factor / 1.5f;
|
|
|
85 | }
|
82 | }
|
86 |
|
|
|
87 | // private void resizeView(View view, int newWidth, int newHeight)
|
|
|
88 | // {
|
|
|
89 | // try
|
|
|
90 | // {
|
|
|
91 | // Constructor<? extends LayoutParams> ctor = view.getLayoutParams().getClass().getDeclaredConstructor(int.class, int.class);
|
|
|
92 | // view.setLayoutParams(ctor.newInstance(newWidth, newHeight));
|
|
|
93 | // }
|
|
|
94 | // catch (Exception e)
|
|
|
95 | // {
|
|
|
96 | // e.printStackTrace();
|
|
|
97 | // }
|
|
|
98 | // }
|
|
|
99 |
|
83 |
|
100 | public void onDraw(Canvas c)
|
84 | public void onDraw(Canvas c)
|
101 | {
|
85 | {
|
102 | super.onDraw(c);
|
86 | if (NavitAndroidOverlay.measure_mode)
|
103 | int dest_valid = NavitGraphics.CallbackDestinationValid2();
|
|
|
104 |
|
|
|
105 | boolean did_draw_circle = false;
|
|
|
106 | if (!NavitGraphics.MAP_DISPLAY_OFF)
|
|
|
107 | {
|
87 | {
|
108 | if ((Navit.OSD_compass.angle_north_valid) || ((Navit.OSD_compass.angle_target_valid) && (dest_valid > 0)))
|
88 | super.onDraw(c);
|
109 | {
|
89 | // c.drawColor(0xFFAAAAAA, PorterDuff.Mode.CLEAR);
|
110 | // compass_c.drawColor(Color.TRANSPARENT, PorterDuff.Mode.CLEAR);
|
90 | c.drawCircle(w2, h2, w2, paint_3);
|
111 | paint.setStyle(Paint.Style.FILL_AND_STROKE);
|
91 | c.drawBitmap(bitmap_measure, cx, cy, paint_2);
|
112 | paint.setStrokeWidth(2);
|
|
|
113 | paint.setAntiAlias(true);
|
|
|
114 | paint.setColor(NavitOSDJava.OSD_element_bg_001_compass);
|
|
|
115 | // c.drawRoundRect(f, 10, 10, paint);
|
|
|
116 | // c.drawCircle(compass_center_x, compass_center_y, radius, paint);
|
|
|
117 | c.drawOval(f, paint);
|
|
|
118 | }
|
92 | }
|
119 |
|
93 | else
|
120 | if (Navit.OSD_compass.angle_north_valid)
|
|
|
121 | {
|
94 | {
|
122 | paint.setColor(Color.BLACK);
|
95 | c.rotate(Navit.OSD_compass.angle_north, w2, h2);
|
123 | paint.setStyle(Paint.Style.STROKE);
|
96 | super.onDraw(c);
|
124 | paint.setStrokeWidth(3 * draw_factor);
|
|
|
125 | paint.setAntiAlias(true);
|
|
|
126 | //c.drawCircle(compass_center_x, compass_center_y, radius, paint);
|
|
|
127 | c.drawOval(f, paint);
|
|
|
128 | did_draw_circle = true;
|
|
|
129 | end_x = (int) ((float) Math.sin((float) Math.toRadians(Navit.OSD_compass.angle_north)) * radius);
|
|
|
130 | end_y = (int) ((float) Math.cos((float) Math.toRadians(Navit.OSD_compass.angle_north)) * radius);
|
|
|
131 | // System.out.println("x " + end_x + " y " + end_y);
|
|
|
132 | paint.setStrokeWidth(3 * draw_factor);
|
|
|
133 | if (Navit.metrics.densityDpi >= 320)
|
|
|
134 | {
|
|
|
135 | paint.setStrokeWidth(3 * draw_factor);
|
|
|
136 | }
|
|
|
137 | c.drawLine(compass_center_x - end_x, compass_center_y + end_y, compass_center_x, compass_center_y, paint);
|
|
|
138 | paint.setColor(Color.RED);
|
|
|
139 | paint.setStrokeWidth(3 * draw_factor);
|
|
|
140 | if (Navit.metrics.densityDpi >= 320)
|
|
|
141 | {
|
|
|
142 | paint.setStrokeWidth(3 * draw_factor);
|
|
|
143 | }
|
|
|
144 | c.drawLine(compass_center_x + end_x, compass_center_y - end_y, compass_center_x, compass_center_y, paint);
|
|
|
145 | }
|
|
|
146 |
|
|
|
147 | if ((Navit.OSD_compass.angle_target_valid) && (dest_valid > 0))
|
|
|
148 | {
|
|
|
149 | paint.setColor(Color.BLACK);
|
|
|
150 | paint.setStyle(Paint.Style.STROKE);
|
|
|
151 | paint.setStrokeWidth(2 * draw_factor);
|
|
|
152 | paint.setAntiAlias(true);
|
|
|
153 | if (!did_draw_circle)
|
|
|
154 | {
|
|
|
155 | // c.drawCircle(compass_center_x, compass_center_y, radius, paint);
|
|
|
156 | c.drawOval(f, paint);
|
|
|
157 | did_draw_circle = true;
|
|
|
158 | }
|
|
|
159 | end_x = (int) ((float) Math.sin((float) Math.toRadians(Navit.OSD_compass.angle_target)) * radius);
|
|
|
160 | end_y = (int) ((float) Math.cos((float) Math.toRadians(Navit.OSD_compass.angle_target)) * radius);
|
|
|
161 | // System.out.println("x " + end_x + " y " + end_y);
|
|
|
162 | paint.setStrokeWidth(3 * draw_factor);
|
|
|
163 | if (Navit.metrics.densityDpi >= 320)
|
|
|
164 | {
|
|
|
165 | paint.setStrokeWidth(3 * draw_factor);
|
|
|
166 | }
|
|
|
167 | paint.setColor(Color.GREEN);
|
|
|
168 | c.drawLine(compass_center_x, compass_center_y, compass_center_x + end_x, compass_center_y - end_y, paint);
|
|
|
169 | }
|
|
|
170 | }
|
97 | }
|
171 |
|
98 |
|
|
|
99 | // System.out.println("onDraw:OSDCompass");
|
172 | }
|
100 | }
|
173 | }
|
101 | }
|