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

   
Visit the ZANavi Wiki