/[zanavi_public1]/navit/navit/android/src/com/zoffcc/applications/zanavi/NavitMapPreviewActivity.java
ZANavi

Contents of /navit/navit/android/src/com/zoffcc/applications/zanavi/NavitMapPreviewActivity.java

Parent Directory Parent Directory | Revision Log Revision Log


Revision 31 - (show annotations) (download)
Mon Feb 4 17:41:59 2013 UTC (11 years, 1 month ago) by zoff99
File size: 14643 byte(s)
new map version, lots of fixes and experimental new features
1 /**
2 * ZANavi, Zoff Android Navigation system.
3 * Copyright (C) 2011 Zoff <zoff@zoff.cc>
4 *
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * version 2 as published by the Free Software Foundation.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the
16 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
18 */
19
20 package com.zoffcc.applications.zanavi;
21
22 import android.app.Activity;
23 import android.content.Intent;
24 import android.graphics.Bitmap;
25 import android.graphics.Canvas;
26 import android.graphics.Color;
27 import android.graphics.Paint;
28 import android.graphics.Path;
29 import android.graphics.PorterDuff;
30 import android.os.Bundle;
31 import android.view.Display;
32 import android.view.Gravity;
33 import android.view.MotionEvent;
34 import android.view.View;
35 import android.view.WindowManager;
36 import android.widget.Button;
37 import android.widget.ImageView;
38 import android.widget.LinearLayout;
39 import android.widget.RelativeLayout.LayoutParams;
40 import android.widget.ScrollView;
41 import android.widget.TextView;
42
43 public class NavitMapPreviewActivity extends Activity
44 {
45 int selected_id;
46 private ImageView view = null;
47
48 public static Canvas view_canvas = null;
49 public static Bitmap view_bitmap = null;
50 public static Canvas view_canvas_upper = null;
51 public static Bitmap view_bitmap_upper = null;
52 public int my_height = 0;
53 public int my_width = 0;
54 private float my_lat = 0f;
55 private float my_lon = 0f;
56 private static int mp_overview = 0;
57 private static int MaxConfigs = 6;
58 private static Paint paint = new Paint();
59 private static int MaxStrokeConfigs = 3;
60
61 public static class MapPreviewConfig
62 {
63 int my_zoom;//= 14; // 14 -> detail || 7 -> overview || 5 -> o2 // show items like on this "order"-level
64 int my_scale;// = 16; // 16 -> detail || 1024 -> overview; || 8192 -> o2 // real zoom level
65 int my_font_size;// = 200; // 200 -> detail || 100 -> overview
66 int my_selection_range;// = 400; // 400 -> detail || 40.000 -> overview || 1.400.000 -> o2 // square around destination in which to show items
67 int[] my_strokewidth;
68 String[] my_color;
69 String my_bgcolor_1;
70 }
71
72 public static MapPreviewConfig[] mapconf = new MapPreviewConfig[MaxConfigs];
73
74 @Override
75 public void onCreate(Bundle savedInstanceState)
76 {
77 this.selected_id = -1;
78
79 super.onCreate(savedInstanceState);
80
81 int j;
82
83 j = 0;
84 mapconf[j] = new MapPreviewConfig();
85 mapconf[j].my_zoom = 15;
86 mapconf[j].my_scale = 16;
87 mapconf[j].my_font_size = 200;
88 mapconf[j].my_selection_range = 400;
89 mapconf[j].my_strokewidth = new int[MaxStrokeConfigs];
90 mapconf[j].my_strokewidth[0] = 16;
91 mapconf[j].my_strokewidth[2] = 16;
92 mapconf[j].my_color = new String[MaxStrokeConfigs];
93 mapconf[j].my_color[0] = "#FEFC8C";
94 mapconf[j].my_color[2] = "#9B1199";
95 mapconf[j].my_bgcolor_1 = "#FEFEFE";
96 j++;
97 mapconf[j] = new MapPreviewConfig();
98 mapconf[j].my_zoom = 15;
99 mapconf[j].my_scale = 16 * 2;
100 mapconf[j].my_font_size = 200;
101 mapconf[j].my_selection_range = 400;
102 mapconf[j].my_strokewidth = new int[MaxStrokeConfigs];
103 mapconf[j].my_strokewidth[0] = 16;
104 mapconf[j].my_strokewidth[2] = 16;
105 mapconf[j].my_color = new String[MaxStrokeConfigs];
106 mapconf[j].my_color[0] = "#FEFC8C";
107 mapconf[j].my_color[2] = "#9B1199";
108 mapconf[j].my_bgcolor_1 = "#FEFEFE";
109 j++;
110 mapconf[j] = new MapPreviewConfig();
111 mapconf[j].my_zoom = 7;
112 mapconf[j].my_scale = 1024;
113 mapconf[j].my_font_size = 100;
114 mapconf[j].my_selection_range = 50000;
115 mapconf[j].my_strokewidth = new int[MaxStrokeConfigs];
116 mapconf[j].my_strokewidth[0] = 6;
117 mapconf[j].my_strokewidth[2] = 6;
118 mapconf[j].my_color = new String[MaxStrokeConfigs];
119 mapconf[j].my_color[0] = "#CCCCCC";
120 mapconf[j].my_color[2] = "#9B1199";
121 mapconf[j].my_bgcolor_1 = "#FEF9EE";
122 j++;
123 mapconf[j] = new MapPreviewConfig();
124 mapconf[j].my_zoom = 5;
125 mapconf[j].my_scale = 8192;
126 mapconf[j].my_font_size = 65;
127 mapconf[j].my_selection_range = 100000;
128 mapconf[j].my_strokewidth = new int[MaxStrokeConfigs];
129 mapconf[j].my_strokewidth[0] = 3;
130 mapconf[j].my_strokewidth[2] = 3;
131 mapconf[j].my_color = new String[MaxStrokeConfigs];
132 mapconf[j].my_color[0] = "#CCCCCC";
133 mapconf[j].my_color[2] = "#9B1199";
134 mapconf[j].my_bgcolor_1 = "#FEF9EE";
135 j++;
136 mapconf[j] = new MapPreviewConfig();
137 mapconf[j].my_zoom = 3;
138 mapconf[j].my_scale = 8192 * 2 * 2 * 2;
139 mapconf[j].my_font_size = 65;
140 mapconf[j].my_selection_range = 710000;
141 mapconf[j].my_strokewidth = new int[MaxStrokeConfigs];
142 mapconf[j].my_strokewidth[0] = 3;
143 mapconf[j].my_strokewidth[2] = 3;
144 mapconf[j].my_color = new String[MaxStrokeConfigs];
145 mapconf[j].my_color[0] = "#CCCCCC";
146 mapconf[j].my_color[2] = "#9B1199";
147 mapconf[j].my_bgcolor_1 = "#FEF9EE";
148 j++;
149 mapconf[j] = new MapPreviewConfig();
150 mapconf[j].my_zoom = 3;
151 mapconf[j].my_scale = 8192 * 2 * 2 * 2 * 2;
152 mapconf[j].my_font_size = 65;
153 mapconf[j].my_selection_range = 1210000;
154 mapconf[j].my_strokewidth = new int[MaxStrokeConfigs];
155 mapconf[j].my_strokewidth[0] = 3;
156 mapconf[j].my_strokewidth[2] = 3;
157 mapconf[j].my_color = new String[MaxStrokeConfigs];
158 mapconf[j].my_color[0] = "#CCCCCC";
159 mapconf[j].my_color[2] = "#9B1199";
160 mapconf[j].my_bgcolor_1 = "#FEF9EE";
161
162 // set startup value
163 mp_overview = 0;
164
165 Display display = getWindowManager().getDefaultDisplay();
166 my_width = display.getWidth();
167 my_height = display.getHeight();
168
169 try
170 {
171 my_lat = getIntent().getExtras().getFloat("lat");
172 }
173 catch (Exception e)
174 {
175 }
176
177 try
178 {
179 my_lon = getIntent().getExtras().getFloat("lon");
180 }
181 catch (Exception e)
182 {
183 }
184
185 //System.out.println("my_lat=" + my_lat);
186 //System.out.println("my_lat=" + my_lon);
187
188 getWindow().setFlags(WindowManager.LayoutParams.FLAG_BLUR_BEHIND, WindowManager.LayoutParams.FLAG_BLUR_BEHIND);
189
190 // scrollview
191 ScrollView sv = new ScrollView(this);
192 sv.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
193
194 // panel linearlayout
195 LinearLayout relativelayout = new LinearLayout(this);
196 relativelayout.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));
197 relativelayout.setOrientation(LinearLayout.VERTICAL);
198 relativelayout.setPadding(5, 5, 5, 5);
199
200 Button btn_set_dest = new Button(this);
201 btn_set_dest.setText(Navit.get_text("Use as destination")); //TRANS
202 btn_set_dest.setOnClickListener(new View.OnClickListener()
203 {
204 public void onClick(View v)
205 {
206 //System.out.println("1111111");
207 selected_id = 1;
208 executeDone();
209 }
210 });
211 btn_set_dest.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT));
212 btn_set_dest.setGravity(Gravity.CENTER);
213
214 Button btn_cancel_dest = new Button(this);
215 btn_cancel_dest.setText(Navit.get_text("back")); //TRANS
216 btn_cancel_dest.setOnClickListener(new View.OnClickListener()
217 {
218 public void onClick(View v)
219 {
220 //System.out.println("2222222");
221 selected_id = 2;
222 executeDone();
223 }
224 });
225 btn_cancel_dest.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT));
226 btn_cancel_dest.setGravity(Gravity.CENTER);
227
228 Button btn_view_dest = new Button(this);
229 btn_view_dest.setText(Navit.get_text("show destination on map")); //TRANS
230 btn_view_dest.setOnClickListener(new View.OnClickListener()
231 {
232 public void onClick(View v)
233 {
234 //System.out.println("2222222");
235 selected_id = 3;
236 executeDone();
237 }
238 });
239 btn_view_dest.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT));
240 btn_view_dest.setGravity(Gravity.CENTER);
241
242 TextView header = new TextView(this);
243 try
244 {
245 String h = getIntent().getExtras().getString("q");
246 h = h + "\n" + Navit.get_text("touch map to zoom"); //TRANS
247 header.setText(h);
248 }
249 catch (Exception e)
250 {
251 header.setText("destination"); //TRANS
252 }
253 header.setTextSize(16);
254 if (this.my_height > this.my_width)
255 {
256 header.setLines(2);
257 }
258 else
259 {
260 header.setLines(1);
261 }
262 header.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
263 header.setGravity(Gravity.TOP);
264
265 view = new ImageView(this)
266 {
267 @Override
268 protected void onDraw(Canvas canvas)
269 {
270 if (view_bitmap != null)
271 {
272 // clear canvas with backgorund color
273 view_canvas.drawColor(Color.parseColor(mapconf[mp_overview].my_bgcolor_1));
274 view_canvas_upper.drawColor(Color.TRANSPARENT, PorterDuff.Mode.CLEAR);
275 DrawMapPreview(my_lat + "#" + my_lon + "#" + mapconf[mp_overview].my_zoom, this.getWidth(), this.getHeight(), mapconf[mp_overview].my_font_size, mapconf[mp_overview].my_scale, mapconf[mp_overview].my_selection_range);
276 canvas.drawBitmap(view_bitmap, 0, 0, null);
277 canvas.drawBitmap(view_bitmap_upper, 0, 0, null);
278 }
279 }
280 };
281
282 view.setOnTouchListener(new View.OnTouchListener()
283 {
284 public boolean onTouch(View v, MotionEvent event)
285 {
286 // System.out.println("xxxxxxxx222222");
287 mp_overview++;
288
289 // sanity check
290 if (mp_overview < 0)
291 {
292 mp_overview = 0;
293 }
294 // sanity check
295
296 if (mp_overview > MaxConfigs - 1)
297 {
298 mp_overview = 0;
299 }
300
301 view.postInvalidate();
302
303 return false;
304 }
305 });
306 view.setLayoutParams(new LayoutParams((int) (this.my_width * 0.8), (int) (this.my_height * 0.4)));
307
308 TextView dummy1 = new TextView(this);
309 dummy1.setText("");
310 // dummy1.setTextColor(color);
311 dummy1.setHeight(this.my_height * 15 / 800);
312
313 if (view_bitmap != null)
314 {
315 try
316 {
317 view_bitmap.recycle();
318 System.gc();
319 view_bitmap = null;
320 }
321 catch (Exception e)
322 {
323 e.printStackTrace();
324 }
325 }
326 view_bitmap = Bitmap.createBitmap((int) (this.my_width * 0.8), (int) (this.my_height * 0.4), Bitmap.Config.ARGB_8888);
327 view_canvas = new Canvas(view_bitmap);
328
329 if (view_bitmap_upper != null)
330 {
331 try
332 {
333 view_bitmap_upper.recycle();
334 System.gc();
335 view_bitmap_upper = null;
336 }
337 catch (Exception e)
338 {
339 e.printStackTrace();
340 }
341 }
342 view_bitmap_upper = Bitmap.createBitmap((int) (this.my_width * 0.8), (int) (this.my_height * 0.4), Bitmap.Config.ARGB_8888);
343 view_canvas_upper = new Canvas(view_bitmap_upper);
344
345 LinearLayout relativelayout2 = new LinearLayout(this);
346 relativelayout2.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT));
347 relativelayout2.setOrientation(LinearLayout.HORIZONTAL);
348 relativelayout2.setPadding(this.my_height * 20 / 800, this.my_height * 20 / 800, this.my_height * 20 / 800, this.my_height * 20 / 800);
349
350 relativelayout2.addView(view);
351 relativelayout2.setGravity(Gravity.CENTER_HORIZONTAL);
352
353 relativelayout.addView(header);
354 relativelayout.addView(relativelayout2);
355 // relativelayout.addView(btn_cancel_dest);
356 relativelayout.addView(btn_view_dest);
357 relativelayout.addView(dummy1);
358 relativelayout.addView(btn_set_dest);
359
360 sv.addView(relativelayout);
361
362 // set the main view
363 setContentView(sv);
364 }
365
366 @Override
367 public void onBackPressed()
368 {
369 selected_id = -1;
370 executeDone();
371 // super.onBackPressed();
372 }
373
374 private void executeDone()
375 {
376 Intent resultIntent = new Intent();
377 resultIntent.putExtra("selected_id", String.valueOf(this.selected_id));
378 setResult(Activity.RESULT_OK, resultIntent);
379
380 if (view_bitmap != null)
381 {
382 try
383 {
384 view_bitmap.recycle();
385 System.gc();
386 view_bitmap = null;
387 view_canvas = null;
388 }
389 catch (Exception e)
390 {
391 e.printStackTrace();
392 }
393 }
394
395 if (view_bitmap_upper != null)
396 {
397 try
398 {
399 view_bitmap_upper.recycle();
400 System.gc();
401 view_bitmap_upper = null;
402 }
403 catch (Exception e)
404 {
405 e.printStackTrace();
406 }
407 }
408
409 finish();
410 }
411
412 /**
413 * draw map preview
414 */
415 public static native void DrawMapPreview(String latlonzoom, int width, int height, int font_size, int scale, int sel_range);
416
417 public static void DrawMapPreview_text(int x, int y, String text, int size, int dx, int dy)
418 {
419 //System.out.println("DrawMapPreview_text: x=" + x + " y=" + y + " text=" + text);
420 //System.out.println("DrawMapPreview_text: dx=" + dx + " dy=" + dy);
421
422 if ((view_bitmap_upper != null) && (text != null))
423 {
424 // Paint paint = new Paint();
425 paint.setStrokeWidth(0);
426 paint.setTextSize(size / 15);
427 paint.setColor(Color.parseColor("#0A0A0A"));
428 paint.setStyle(Paint.Style.FILL);
429 paint.setAntiAlias(Navit.PREF_use_anti_aliasing);
430 if (dx == 0x10000 && dy == 0)
431 {
432 view_canvas_upper.drawText(text, x, y, paint);
433 }
434 else
435 {
436 Path path = new Path();
437 path.moveTo(x, y);
438 path.rLineTo(dx, dy);
439 paint.setTextAlign(Paint.Align.LEFT);
440 view_canvas_upper.drawTextOnPath(text, path, 0, 0, paint);
441 }
442 }
443 }
444
445 public static void DrawMapPreview_target(int x, int y)
446 {
447
448 if (view_bitmap != null)
449 {
450 //System.out.println("draw target x=" + x + " y=" + y);
451 // Paint paint = new Paint();
452 paint.setStrokeWidth(0);
453 paint.setAntiAlias(Navit.PREF_use_anti_aliasing);
454 paint.setStyle(Paint.Style.FILL);
455 paint.setColor(Color.parseColor("#FF0303"));
456 view_canvas.drawCircle(x, y, 10, paint);
457 paint.setStyle(Paint.Style.STROKE);
458 // paint.setColor(Color.parseColor("#FF0303"));
459 view_canvas.drawCircle(x, y, 16, paint);
460 }
461 }
462
463 public static void DrawMapPreview_polyline(int type, int c[])
464 {
465 if (view_bitmap != null)
466 {
467 // Paint paint = new Paint();
468 paint.setStyle(Paint.Style.STROKE);
469 paint.setAntiAlias(Navit.PREF_use_anti_aliasing);
470 paint.setStrokeWidth(mapconf[mp_overview].my_strokewidth[type]);
471 paint.setColor(Color.parseColor(mapconf[mp_overview].my_color[type]));
472 Path path = new Path();
473 path.moveTo(c[0], c[1]);
474 for (int i = 2; i < c.length; i += 2)
475 {
476 path.lineTo(c[i], c[i + 1]);
477 }
478 //global_path.close();
479 view_canvas.drawPath(path, paint);
480 }
481 }
482 }

   
Visit the ZANavi Wiki