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

   
Visit the ZANavi Wiki