/[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 27 - (show annotations) (download)
Mon Apr 9 21:27:36 2012 UTC (11 years, 11 months ago) by zoff99
File size: 14551 byte(s)
lots of new stuff, tranlsations, bug fixes ...
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 getWindow().setFlags(WindowManager.LayoutParams.FLAG_BLUR_BEHIND, WindowManager.LayoutParams.FLAG_BLUR_BEHIND);
186
187 // scrollview
188 ScrollView sv = new ScrollView(this);
189 sv.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
190
191 // panel linearlayout
192 LinearLayout relativelayout = new LinearLayout(this);
193 relativelayout.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));
194 relativelayout.setOrientation(LinearLayout.VERTICAL);
195 relativelayout.setPadding(5, 5, 5, 5);
196
197 Button btn_set_dest = new Button(this);
198 btn_set_dest.setText(Navit.get_text("Use as destination")); //TRANS
199 btn_set_dest.setOnClickListener(new View.OnClickListener()
200 {
201 public void onClick(View v)
202 {
203 //System.out.println("1111111");
204 selected_id = 1;
205 executeDone();
206 }
207 });
208 btn_set_dest.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT));
209 btn_set_dest.setGravity(Gravity.CENTER);
210
211 Button btn_cancel_dest = new Button(this);
212 btn_cancel_dest.setText(Navit.get_text("back")); //TRANS
213 btn_cancel_dest.setOnClickListener(new View.OnClickListener()
214 {
215 public void onClick(View v)
216 {
217 //System.out.println("2222222");
218 selected_id = 2;
219 executeDone();
220 }
221 });
222 btn_cancel_dest.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT));
223 btn_cancel_dest.setGravity(Gravity.CENTER);
224
225 Button btn_view_dest = new Button(this);
226 btn_view_dest.setText(Navit.get_text("show destination on map")); //TRANS
227 btn_view_dest.setOnClickListener(new View.OnClickListener()
228 {
229 public void onClick(View v)
230 {
231 //System.out.println("2222222");
232 selected_id = 3;
233 executeDone();
234 }
235 });
236 btn_view_dest.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT));
237 btn_view_dest.setGravity(Gravity.CENTER);
238
239 TextView header = new TextView(this);
240 try
241 {
242 String h = getIntent().getExtras().getString("q");
243 h = h + "\n" + Navit.get_text("touch map to zoom"); //TRANS
244 header.setText(h);
245 }
246 catch (Exception e)
247 {
248 header.setText("destination"); //TRANS
249 }
250 header.setTextSize(16);
251 if (this.my_height > this.my_width)
252 {
253 header.setLines(2);
254 }
255 else
256 {
257 header.setLines(1);
258 }
259 header.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
260 header.setGravity(Gravity.TOP);
261
262 view = new ImageView(this)
263 {
264 @Override
265 protected void onDraw(Canvas canvas)
266 {
267 if (view_bitmap != null)
268 {
269 // clear canvas with backgorund color
270 view_canvas.drawColor(Color.parseColor(mapconf[mp_overview].my_bgcolor_1));
271 view_canvas_upper.drawColor(Color.TRANSPARENT, PorterDuff.Mode.CLEAR);
272 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);
273 canvas.drawBitmap(view_bitmap, 0, 0, null);
274 canvas.drawBitmap(view_bitmap_upper, 0, 0, null);
275 }
276 }
277 };
278
279 view.setOnTouchListener(new View.OnTouchListener()
280 {
281 public boolean onTouch(View v, MotionEvent event)
282 {
283 // System.out.println("xxxxxxxx222222");
284 mp_overview++;
285
286 // sanity check
287 if (mp_overview < 0)
288 {
289 mp_overview = 0;
290 }
291 // sanity check
292
293 if (mp_overview > MaxConfigs - 1)
294 {
295 mp_overview = 0;
296 }
297
298 view.postInvalidate();
299
300 return false;
301 }
302 });
303 view.setLayoutParams(new LayoutParams((int) (this.my_width * 0.8), (int) (this.my_height * 0.4)));
304
305 TextView dummy1 = new TextView(this);
306 dummy1.setText("");
307 // dummy1.setTextColor(color);
308 dummy1.setHeight(this.my_height * 15 / 800);
309
310 if (view_bitmap != null)
311 {
312 try
313 {
314 view_bitmap.recycle();
315 System.gc();
316 view_bitmap = null;
317 }
318 catch (Exception e)
319 {
320 e.printStackTrace();
321 }
322 }
323 view_bitmap = Bitmap.createBitmap((int) (this.my_width * 0.8), (int) (this.my_height * 0.4), Bitmap.Config.ARGB_8888);
324 view_canvas = new Canvas(view_bitmap);
325
326 if (view_bitmap_upper != null)
327 {
328 try
329 {
330 view_bitmap_upper.recycle();
331 System.gc();
332 view_bitmap_upper = null;
333 }
334 catch (Exception e)
335 {
336 e.printStackTrace();
337 }
338 }
339 view_bitmap_upper = Bitmap.createBitmap((int) (this.my_width * 0.8), (int) (this.my_height * 0.4), Bitmap.Config.ARGB_8888);
340 view_canvas_upper = new Canvas(view_bitmap_upper);
341
342 LinearLayout relativelayout2 = new LinearLayout(this);
343 relativelayout2.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT));
344 relativelayout2.setOrientation(LinearLayout.HORIZONTAL);
345 relativelayout2.setPadding(this.my_height * 20 / 800, this.my_height * 20 / 800, this.my_height * 20 / 800, this.my_height * 20 / 800);
346
347 relativelayout2.addView(view);
348 relativelayout2.setGravity(Gravity.CENTER_HORIZONTAL);
349
350 relativelayout.addView(header);
351 relativelayout.addView(relativelayout2);
352 // relativelayout.addView(btn_cancel_dest);
353 relativelayout.addView(btn_view_dest);
354 relativelayout.addView(dummy1);
355 relativelayout.addView(btn_set_dest);
356
357 sv.addView(relativelayout);
358
359 // set the main view
360 setContentView(sv);
361 }
362
363 @Override
364 public void onBackPressed()
365 {
366 selected_id = -1;
367 executeDone();
368 // super.onBackPressed();
369 }
370
371 private void executeDone()
372 {
373 Intent resultIntent = new Intent();
374 resultIntent.putExtra("selected_id", String.valueOf(this.selected_id));
375 setResult(Activity.RESULT_OK, resultIntent);
376
377 if (view_bitmap != null)
378 {
379 try
380 {
381 view_bitmap.recycle();
382 System.gc();
383 view_bitmap = null;
384 view_canvas = null;
385 }
386 catch (Exception e)
387 {
388 e.printStackTrace();
389 }
390 }
391
392 if (view_bitmap_upper != null)
393 {
394 try
395 {
396 view_bitmap_upper.recycle();
397 System.gc();
398 view_bitmap_upper = null;
399 }
400 catch (Exception e)
401 {
402 e.printStackTrace();
403 }
404 }
405
406 finish();
407 }
408
409 /**
410 * draw map preview
411 */
412 public static native void DrawMapPreview(String latlonzoom, int width, int height, int font_size, int scale, int sel_range);
413
414 public static void DrawMapPreview_text(int x, int y, String text, int size, int dx, int dy)
415 {
416 //System.out.println("DrawMapPreview_text: x=" + x + " y=" + y + " text=" + text);
417 //System.out.println("DrawMapPreview_text: dx=" + dx + " dy=" + dy);
418
419 if ((view_bitmap_upper != null) && (text != null))
420 {
421 // Paint paint = new Paint();
422 paint.setStrokeWidth(0);
423 paint.setTextSize(size / 15);
424 paint.setColor(Color.parseColor("#0A0A0A"));
425 paint.setStyle(Paint.Style.FILL);
426 paint.setAntiAlias(Navit.PREF_use_anti_aliasing);
427 if (dx == 0x10000 && dy == 0)
428 {
429 view_canvas_upper.drawText(text, x, y, paint);
430 }
431 else
432 {
433 Path path = new Path();
434 path.moveTo(x, y);
435 path.rLineTo(dx, dy);
436 paint.setTextAlign(Paint.Align.LEFT);
437 view_canvas_upper.drawTextOnPath(text, path, 0, 0, paint);
438 }
439 }
440 }
441
442 public static void DrawMapPreview_target(int x, int y)
443 {
444
445 if (view_bitmap != null)
446 {
447 //System.out.println("draw target x=" + x + " y=" + y);
448 // Paint paint = new Paint();
449 paint.setStrokeWidth(0);
450 paint.setAntiAlias(Navit.PREF_use_anti_aliasing);
451 paint.setStyle(Paint.Style.FILL);
452 paint.setColor(Color.parseColor("#FF0303"));
453 view_canvas.drawCircle(x, y, 10, paint);
454 paint.setStyle(Paint.Style.STROKE);
455 // paint.setColor(Color.parseColor("#FF0303"));
456 view_canvas.drawCircle(x, y, 16, paint);
457 }
458 }
459
460 public static void DrawMapPreview_polyline(int type, int c[])
461 {
462 if (view_bitmap != null)
463 {
464 // Paint paint = new Paint();
465 paint.setStyle(Paint.Style.STROKE);
466 paint.setAntiAlias(Navit.PREF_use_anti_aliasing);
467 paint.setStrokeWidth(mapconf[mp_overview].my_strokewidth[type]);
468 paint.setColor(Color.parseColor(mapconf[mp_overview].my_color[type]));
469 Path path = new Path();
470 path.moveTo(c[0], c[1]);
471 for (int i = 2; i < c.length; i += 2)
472 {
473 path.lineTo(c[i], c[i + 1]);
474 }
475 //global_path.close();
476 view_canvas.drawPath(path, paint);
477 }
478 }
479 }

   
Visit the ZANavi Wiki