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

   
Visit the ZANavi Wiki