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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 41 - (show annotations) (download)
Tue Aug 11 18:50:37 2015 UTC (8 years, 7 months ago) by zoff99
File size: 33933 byte(s)
many fixes, and new features
1 /**
2 * ZANavi, Zoff Android Navigation system.
3 * Copyright (C) 2011 - 2015 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 /**
21 * Navit, a modular navigation system.
22 * Copyright (C) 2005-2008 Navit Team
23 *
24 * This program is free software; you can redistribute it and/or
25 * modify it under the terms of the GNU General Public License
26 * version 2 as published by the Free Software Foundation.
27 *
28 * This program is distributed in the hope that it will be useful,
29 * but WITHOUT ANY WARRANTY; without even the implied warranty of
30 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
31 * GNU General Public License for more details.
32 *
33 * You should have received a copy of the GNU General Public License
34 * along with this program; if not, write to the
35 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
36 * Boston, MA 02110-1301, USA.
37 */
38
39 package com.zoffcc.applications.zanavi;
40
41 import java.util.ArrayList;
42
43 import android.app.Activity;
44 import android.content.Context;
45 import android.content.Intent;
46 import android.graphics.ColorFilter;
47 import android.graphics.ColorMatrixColorFilter;
48 import android.graphics.drawable.Drawable;
49 import android.os.Bundle;
50 import android.os.Message;
51 import android.support.v7.app.ActionBarActivity;
52 import android.text.Editable;
53 import android.text.TextWatcher;
54 import android.util.Log;
55 import android.util.TypedValue;
56 import android.view.KeyEvent;
57 import android.view.LayoutInflater;
58 import android.view.MotionEvent;
59 import android.view.View;
60 import android.view.View.OnClickListener;
61 import android.view.ViewGroup;
62 import android.view.inputmethod.EditorInfo;
63 import android.view.inputmethod.InputMethodManager;
64 import android.widget.AdapterView;
65 import android.widget.AdapterView.OnItemClickListener;
66 import android.widget.ArrayAdapter;
67 import android.widget.Button;
68 import android.widget.CheckBox;
69 import android.widget.CompoundButton;
70 import android.widget.CompoundButton.OnCheckedChangeListener;
71 import android.widget.EditText;
72 import android.widget.ImageView;
73 import android.widget.LinearLayout;
74 import android.widget.ListView;
75 import android.widget.RelativeLayout;
76 import android.widget.ScrollView;
77 import android.widget.TextView;
78
79 import com.zoffcc.applications.zanavi.Navit.Navit_Address_Result_Struct;
80 import com.zoffcc.applications.zanavi.NavitSearchResultListArrayAdapter.search_result_entry;
81
82 public class NavitAddressSearchActivity extends ActionBarActivity
83 {
84 private ZANaviAutoCompleteTextViewSearchLocation address_string;
85 private EditText hn_string;
86 private TextView addrhn_view;
87 private static CheckBox pm_checkbox;
88 private static CheckBox hdup_checkbox;
89 static TextView result_count_number;
90 static String result_count_text = "0";
91 private CheckBox ff_checkbox;
92 private String search_type;
93 private int search_country_id = 0;
94 private Button search_country_select;
95 private ScrollView sv;
96 private LinearLayout ll;
97 static ListView listview;
98 static SearchResultListNewArrayAdapter adapter;
99 private ImageView index_light;
100 private RelativeLayout index_container;
101 private TextView index_light_noindex_text;
102 static SearchResultsThreadNew searchresultsThreadNew_offline = null;
103 private static int res_counter_ = 0;
104 private int selected_id = -1;
105 private int selected_id_passthru = -1;
106
107 public class SearchResultListNewArrayAdapter extends ArrayAdapter<search_result_entry>
108 {
109 private final Context context;
110 ArrayList<search_result_entry> l = null;
111
112 public SearchResultListNewArrayAdapter(Context context, ArrayList<search_result_entry> values)
113 {
114 super(context, -1, values);
115 this.l = values;
116 this.context = context;
117 }
118
119 @Override
120 public void add(search_result_entry e)
121 {
122 this.l.add(e);
123 }
124
125 @Override
126 public View getView(int position, View convertView, ViewGroup parent)
127 {
128 search_result_entry entry = l.get(position);
129 LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
130 if (entry.gettype() == 1)
131 {
132 convertView = inflater.inflate(R.layout.search_result_item_street, null);
133
134 ImageView icon_view = (ImageView) convertView.findViewById(R.id.icon);
135 if (Navit.p.PREF_current_theme == Navit.DEFAULT_THEME_OLD_LIGHT)
136 {
137 // leave it as it is
138 }
139 else
140 {
141 // thanks to: http://stackoverflow.com/questions/17841787/invert-colors-of-drawable-android
142 Drawable drawable_homeicon = icon_view.getResources().getDrawable(R.drawable.roadicon);
143 float[] colorMatrix_Negative = { -1.0f, 0, 0, 0, 255, //red
144 0, -1.0f, 0, 0, 255, //green
145 0, 0, -1.0f, 0, 255, //blue
146 0, 0, 0, 1.0f, 0 //alpha
147 };
148
149 ColorFilter colorFilter_Negative = new ColorMatrixColorFilter(colorMatrix_Negative);
150 drawable_homeicon.setColorFilter(colorFilter_Negative);
151 icon_view.setImageDrawable(drawable_homeicon);
152 }
153 }
154 else if (entry.gettype() == 3)
155 {
156 convertView = inflater.inflate(R.layout.search_result_item_poi, null);
157
158 ImageView icon_view = (ImageView) convertView.findViewById(R.id.icon);
159 if (Navit.p.PREF_current_theme == Navit.DEFAULT_THEME_OLD_LIGHT)
160 {
161 // leave it as it is
162 }
163 else
164 {
165 Drawable drawable_homeicon = icon_view.getResources().getDrawable(R.drawable.poiicon);
166 float[] colorMatrix_Negative = { -1.0f, 0, 0, 0, 255, //red
167 0, -1.0f, 0, 0, 255, //green
168 0, 0, -1.0f, 0, 255, //blue
169 0, 0, 0, 1.0f, 0 //alpha
170 };
171
172 ColorFilter colorFilter_Negative = new ColorMatrixColorFilter(colorMatrix_Negative);
173 drawable_homeicon.setColorFilter(colorFilter_Negative);
174 icon_view.setImageDrawable(drawable_homeicon);
175 }
176 }
177 else
178 {
179 convertView = inflater.inflate(R.layout.search_result_item_town, null);
180
181 ImageView icon_view = (ImageView) convertView.findViewById(R.id.icon);
182 if (Navit.p.PREF_current_theme == Navit.DEFAULT_THEME_OLD_LIGHT)
183 {
184 // leave it as it is
185 }
186 else
187 {
188 Drawable drawable_homeicon = icon_view.getResources().getDrawable(R.drawable.townicon);
189 float[] colorMatrix_Negative = { -1.0f, 0, 0, 0, 255, //red
190 0, -1.0f, 0, 0, 255, //green
191 0, 0, -1.0f, 0, 255, //blue
192 0, 0, 0, 1.0f, 0 //alpha
193 };
194
195 ColorFilter colorFilter_Negative = new ColorMatrixColorFilter(colorMatrix_Negative);
196 drawable_homeicon.setColorFilter(colorFilter_Negative);
197 icon_view.setImageDrawable(drawable_homeicon);
198 }
199 }
200
201 // R.layout.search_result_item_poi --> for POI result
202 //}
203
204 TextView text = (TextView) convertView.findViewById(R.id.toptext);
205 text.setText(entry.getName());
206
207 return convertView;
208 }
209 }
210
211 public static void fillStringArrayNew(String s)
212 {
213 if (s.equals("D:D"))
214 {
215 // ok its a dummy
216 }
217 else
218 {
219 try
220 {
221 // we hope its a real result value
222 Navit.Navit_Address_Result_Struct tmp_addr = new Navit_Address_Result_Struct();
223 String[] tmp_s = s.split(":");
224 tmp_addr.result_type = tmp_s[0];
225 tmp_addr.item_id = tmp_s[1];
226
227 tmp_addr.lat = Integer.parseInt(tmp_s[2]);
228 tmp_addr.lon = Integer.parseInt(tmp_s[3]);
229 // the rest ist address
230 tmp_addr.addr = s.substring(4 + tmp_s[0].length() + tmp_s[1].length() + tmp_s[2].length() + tmp_s[3].length(), s.length());
231
232 // String hash_id = tmp_addr.result_type + ":" + tmp_addr.lat + ":" + tmp_addr.lon + ":" + tmp_addr.addr;
233 String hash_id = tmp_addr.result_type + ":" + tmp_addr.addr;
234 //System.out.println("hash_id=" + hash_id);
235 if ((!Navit.search_hide_duplicates) || (!Navit.Navit_Address_Result_double_index.contains(hash_id)))
236 {
237 Navit.NavitAddressResultList_foundItems.add(tmp_addr);
238 Navit.Navit_Address_Result_double_index.add(hash_id);
239 //System.out.println("*add*=" + hash_id);
240
241 if (tmp_addr.result_type.equals("TWN"))
242 {
243 Navit.search_results_towns++;
244 }
245 else if (tmp_addr.result_type.equals("STR"))
246 {
247 Navit.search_results_streets++;
248 }
249 else if (tmp_addr.result_type.equals("SHN"))
250 {
251 Navit.search_results_streets_hn++;
252 }
253 else if (tmp_addr.result_type.equals("POI"))
254 {
255 Navit.search_results_poi++;
256 }
257
258 result_count_text = "" + Navit.NavitAddressResultList_foundItems.size();
259
260 //
261 //
262 // System.out.println("RES=" + s);
263 //
264 //
265
266 try
267 {
268 if (tmp_addr.result_type.equals("TWN"))
269 {
270 final search_result_entry res_entry = new search_result_entry(2, tmp_addr.addr, res_counter_);
271
272 Navit.runOnUI(new Runnable()
273 {
274 @Override
275 public void run()
276 {
277 adapter.add(res_entry);
278 result_count_number.setText(result_count_text);
279 }
280 });
281
282 }
283 else if (tmp_addr.result_type.equals("POI"))
284 {
285 final search_result_entry res_entry = new search_result_entry(3, tmp_addr.addr, res_counter_);
286 Navit.runOnUI(new Runnable()
287 {
288 @Override
289 public void run()
290 {
291 adapter.add(res_entry);
292 result_count_number.setText(result_count_text);
293 }
294 });
295 }
296 else
297 {
298 final search_result_entry res_entry = new search_result_entry(1, tmp_addr.addr, res_counter_);
299 Navit.runOnUI(new Runnable()
300 {
301 @Override
302 public void run()
303 {
304 adapter.add(res_entry);
305 result_count_number.setText(result_count_text);
306 }
307 });
308 }
309 res_counter_++;
310 // listview.postInvalidate();
311 }
312 catch (Exception e4)
313 {
314 System.out.println("AAEE:077:" + e4.getMessage());
315 }
316
317 try
318 {
319 Message msg = Navit.Navit_progress_h.obtainMessage();
320 Bundle b = new Bundle();
321 msg.what = 39;
322 msg.setData(b);
323 Navit.Navit_progress_h.sendMessage(msg);
324 }
325 catch (Exception e)
326 {
327 System.out.println("AAEE:011:" + e.getMessage());
328 e.printStackTrace();
329 }
330
331 // Navit.NavitSearchresultBar_title = Navit.get_text("loading search results");
332 // Navit.NavitSearchresultBar_text = Navit.get_text("towns") + ":" + Navit.search_results_towns + " " + Navit.get_text("Streets") + ":" + Navit.search_results_streets + "/" + Navit.search_results_streets_hn + " " + Navit.get_text("POI") + ":" + Navit.search_results_poi;
333 }
334 }
335 catch (Exception e)
336 {
337 }
338 }
339 }
340
341 protected void onPause()
342 {
343 super.onPause();
344
345 try
346 {
347 if (searchresultsThreadNew_offline != null)
348 {
349 searchresultsThreadNew_offline.stop_me();
350 }
351 }
352 catch (Exception e)
353 {
354 }
355 }
356
357 public class SearchResultsThreadNew extends Thread
358 {
359 private Boolean running;
360 private Boolean changed = false;
361 private Boolean is_searching = false;
362
363 SearchResultsThreadNew()
364 {
365 this.running = true;
366 Log.e("Navit", "SearchResultsThreadNew created");
367
368 Navit.NavitAddressResultList_foundItems.clear();
369 Navit.Navit_Address_Result_double_index.clear();
370
371 Navit.runOnUI(new Runnable()
372 {
373 @Override
374 public void run()
375 {
376 result_count_text = "" + Navit.NavitAddressResultList_foundItems.size();
377 result_count_number.setText(result_count_text);
378 }
379 });
380
381 try
382 {
383 Message msg = Navit.Navit_progress_h.obtainMessage();
384 Bundle b = new Bundle();
385 msg.what = 38;
386 msg.setData(b);
387 Navit.Navit_progress_h.sendMessage(msg);
388 }
389 catch (Exception e)
390 {
391 System.out.println("AAEE:003");
392 e.printStackTrace();
393 }
394 res_counter_ = 0;
395 }
396
397 public void set_search_strings(String addr, String hn)
398 {
399 Navit.Navit_last_address_search_string = addr;
400 Navit.Navit_last_address_hn_string = hn;
401 }
402
403 public void change_search()
404 {
405 if (is_searching)
406 {
407 Message msg = new Message();
408 Bundle b = new Bundle();
409 b.putInt("Callback", 46);
410 msg.setData(b);
411 try
412 {
413 NavitGraphics.callback_handler.sendMessage(msg);
414 }
415 catch (Exception e)
416 {
417 }
418 Log.e("Navit", "SearchResultsThreadNew -> Cancel");
419
420 changed = true;
421 this.interrupt();
422 }
423 else
424 {
425 changed = true;
426 this.interrupt();
427 }
428 }
429
430 public void cancel_search()
431 {
432 }
433
434 public void stop_me()
435 {
436 Message msg = new Message();
437 Bundle b = new Bundle();
438 b.putInt("Callback", 46);
439 msg.setData(b);
440 try
441 {
442 NavitGraphics.callback_handler.sendMessage(msg);
443 }
444 catch (Exception e)
445 {
446 }
447 Log.e("Navit", "SearchResultsThreadNew -> stop_me");
448
449 this.running = false;
450 this.interrupt();
451 }
452
453 public void run()
454 {
455 Log.e("Navit", "SearchResultsThreadNew started");
456
457 Navit.index_search_realtime = true;
458
459 System.out.println("Global_Location_update_not_allowed = 1");
460 Navit.Global_Location_update_not_allowed = 1; // dont allow location updates now!
461
462 if (Navit.use_index_search)
463 {
464 while (running) // loop until we leave
465 {
466 // start the search, this could take a long time!!
467
468 Navit.NavitAddressResultList_foundItems.clear();
469 Navit.Navit_Address_Result_double_index.clear();
470
471 Navit.runOnUI(new Runnable()
472 {
473 @Override
474 public void run()
475 {
476 result_count_text = "" + Navit.NavitAddressResultList_foundItems.size();
477 result_count_number.setText(result_count_text);
478 }
479 });
480
481 try
482 {
483 Message msg = Navit.Navit_progress_h.obtainMessage();
484 Bundle b = new Bundle();
485 msg.what = 38;
486 msg.setData(b);
487 Navit.Navit_progress_h.sendMessage(msg);
488
489 Thread.sleep(20);
490 }
491 catch (Exception e)
492 {
493 System.out.println("AAEE:002");
494 e.printStackTrace();
495 }
496 res_counter_ = 0;
497
498 if (NavitAddressSearchActivity.pm_checkbox.isChecked())
499 {
500 Navit.Navit_last_address_partial_match = true;
501 }
502 else
503 {
504 Navit.Navit_last_address_partial_match = false;
505 }
506
507 if (NavitAddressSearchActivity.hdup_checkbox.isChecked())
508 {
509 Navit.search_hide_duplicates = true;
510 }
511 else
512 {
513 Navit.search_hide_duplicates = false;
514 }
515
516 int partial_match_i = 0;
517 if (Navit.Navit_last_address_partial_match)
518 {
519 partial_match_i = 1;
520 }
521
522 // Log.e("Navit", "SearchResultsThread run1");
523 // need lowercase to find stuff !!
524 Navit.Navit_last_address_search_string = Navit.filter_bad_chars(Navit.Navit_last_address_search_string).toLowerCase();
525 if ((Navit.Navit_last_address_hn_string != null) && (Navit.Navit_last_address_hn_string.equals("")))
526 {
527 Navit.Navit_last_address_hn_string = Navit.filter_bad_chars(Navit.Navit_last_address_hn_string).toLowerCase();
528 }
529
530 // new method with index search
531 // -----------------
532 //Navit_last_address_search_string
533 String street_ = "";
534 String town_ = "";
535 String hn_ = Navit.Navit_last_address_hn_string;
536
537 int last_space = Navit.Navit_last_address_search_string.lastIndexOf(" ");
538 if (last_space != -1)
539 {
540 street_ = Navit.Navit_last_address_search_string.substring(0, last_space);
541 town_ = Navit.Navit_last_address_search_string.substring(last_space + 1);
542 // System.out.println("XX" + street_ + "YY" + town_ + "ZZ");
543 }
544 else
545 {
546 street_ = Navit.Navit_last_address_search_string;
547 town_ = "";
548 }
549
550 is_searching = true;
551
552 Log.e("Navit", "SearchResultsThread args:pm=" + partial_match_i + " str=" + street_ + " town=" + town_ + " hn=" + hn_ + " cfl=" + Navit.Navit_last_address_search_country_flags + " iso=" + Navit.Navit_last_address_search_country_iso2_string);
553 Navit.N_NavitGraphics.SearchResultList(2, partial_match_i, street_, town_, hn_, Navit.Navit_last_address_search_country_flags, Navit.Navit_last_address_search_country_iso2_string, "0#0", 0);
554
555 is_searching = false;
556
557 while ((!changed) && (running))
558 {
559 try
560 {
561 Log.e("Navit", "SearchResultsThread SLEEP");
562 Thread.sleep(10000);
563 }
564 catch (Exception e2)
565 {
566 }
567 }
568
569 changed = false;
570
571 // sort result list
572 // Collections.sort(Navit.NavitAddressResultList_foundItems);
573 }
574 }
575
576 Log.e("Navit", "SearchResultsThreadNew run2");
577
578 Navit.NavitAddressSearchSpinnerActive = false;
579
580 // reset the startup-search flag
581 Navit.NavitStartupAlreadySearching = false;
582
583 System.out.println("Global_Location_update_not_allowed = 0");
584 Navit.Global_Location_update_not_allowed = 0; // DO allow location updates now!
585
586 Navit.index_search_realtime = false;
587 searchresultsThreadNew_offline = null;
588
589 Log.e("Navit", "SearchResultsThreadNew ended");
590 }
591 }
592
593 @Override
594 protected void onCreate(Bundle savedInstanceState)
595 {
596 Navit.applySharedTheme(this, Navit.p.PREF_current_theme);
597
598 super.onCreate(savedInstanceState);
599
600 setContentView(R.layout.activity_search_form);
601
602 android.support.v7.widget.Toolbar bar = (android.support.v7.widget.Toolbar) findViewById(R.id.toolbar2nd);
603 bar.setTitle(Navit.get_text("address search"));
604 bar.setNavigationOnClickListener(new View.OnClickListener()
605 {
606 @Override
607 public void onClick(View v)
608 {
609 finish();
610 }
611 });
612
613 // address: label
614 TextView addr_view = (TextView) findViewById(R.id.enter_dest);
615 addr_view.setText(Navit.get_text("Enter Destination")); //TRANS
616
617 // housenumber: label
618 addrhn_view = (TextView) findViewById(R.id.house_number);
619 addrhn_view.setText(Navit.get_text("Housenumber")); //TRANS
620
621 // partial match checkbox
622 pm_checkbox = (CheckBox) findViewById(R.id.cb_partial_match);
623 pm_checkbox.setText(Navit.get_text("partial match")); //TRANS
624 pm_checkbox.setChecked(true);
625
626 // hide duplicates checkbox
627 hdup_checkbox = (CheckBox) findViewById(R.id.cb_hide_dup);
628 hdup_checkbox.setText(Navit.get_text("hide duplicates")); //TRANS
629 hdup_checkbox.setChecked(true);
630
631 result_count_number = (TextView) findViewById(R.id.result_count_number);
632
633 index_light = (ImageView) findViewById(R.id.index_light_img);
634 index_light_noindex_text = (TextView) findViewById(R.id.index_light_noindex_text);
635 index_light_noindex_text.setText(Navit.get_text("click to activate Index Search"));
636 final Intent donate_intent = new Intent(this, ZANaviNormalDonateActivity.class);
637 index_light_noindex_text.setOnTouchListener(new View.OnTouchListener()
638 {
639 @Override
640 public boolean onTouch(View v, MotionEvent m)
641 {
642 startActivityForResult(donate_intent, Navit.NavitDonateFromSearch_id);
643 return false;
644 }
645 });
646
647 if (Navit.use_index_search)
648 {
649 index_light.setImageResource(R.drawable.round_light_green);
650 index_light_noindex_text.setVisibility(View.GONE);
651 }
652 else
653 {
654 index_light.setImageResource(R.drawable.round_light_red);
655 }
656
657 index_container = (RelativeLayout) findViewById(R.id.index_light_container);
658
659 // full file checkbox
660 ff_checkbox = (CheckBox) findViewById(R.id.cb_full_file);
661 if (!Navit.use_index_search)
662 {
663 ff_checkbox.setText(Navit.get_text("search full mapfile [BETA]")); //TRANS
664 ff_checkbox.setChecked(false);
665 ff_checkbox.setOnCheckedChangeListener(new OnCheckedChangeListener()
666 {
667 public void onCheckedChanged(CompoundButton buttonView, boolean isChecked)
668 {
669 if (isChecked)
670 {
671 try
672 {
673 search_country_select.setVisibility(View.INVISIBLE);
674 hdup_checkbox.setVisibility(View.INVISIBLE);
675 }
676 catch (Exception e)
677 {
678
679 }
680 }
681 else
682 {
683 try
684 {
685 search_country_select.setVisibility(View.VISIBLE);
686 hdup_checkbox.setVisibility(View.VISIBLE);
687 }
688 catch (Exception e)
689 {
690
691 }
692 }
693 }
694 });
695 }
696
697 // search button
698 final Button btnSearch = (Button) findViewById(R.id.bt_search);
699 btnSearch.setText(Navit.get_text("Search")); //TRANS
700 btnSearch.setOnClickListener(new OnClickListener()
701 {
702 public void onClick(View v)
703 {
704 executeDone("x");
705 }
706 });
707
708 this.search_type = getIntent().getExtras().getString("type");
709 if (this.search_type.endsWith("offline"))
710 {
711 this.search_country_id = getIntent().getExtras().getInt("search_country_id");
712 }
713
714 // select country button
715 search_country_select = (Button) findViewById(R.id.bt_country_select);
716 if (!Navit.use_index_search)
717 {
718
719 search_country_select.setText(NavitAddressSearchCountrySelectActivity.CountryList_Human[search_country_id][2]);
720 search_country_select.setOnClickListener(new View.OnClickListener()
721 {
722 public void onClick(View v)
723 {
724 start_country_select_form();
725 }
726 });
727 }
728
729 // title
730 try
731 {
732 String s = getIntent().getExtras().getString("title");
733 if (s.length() > 0)
734 {
735 this.setTitle(s);
736 }
737 }
738 catch (Exception e)
739 {
740 }
741
742 // partial match
743 try
744 {
745 String s = getIntent().getExtras().getString("partial_match");
746 if (s.length() > 0)
747 {
748 if (s.equals("1"))
749 {
750 pm_checkbox.setChecked(true);
751 }
752 else
753 {
754 pm_checkbox.setChecked(false);
755 }
756 }
757 }
758 catch (Exception e)
759 {
760 }
761
762 hn_string = (EditText) findViewById(R.id.et_house_number_string);
763
764 if (Navit.use_index_search)
765 {
766
767 // house number string
768 try
769 {
770 hn_string.setSingleLine();
771 hn_string.setHint(Navit.get_text("Housenumber")); // TRANS
772 // hn_string.setInputType(InputType.TYPE_CLASS_NUMBER);
773 hn_string.setImeOptions(EditorInfo.IME_ACTION_SEARCH);
774 hn_string.setText(getIntent().getExtras().getString("hn_string"));
775
776 hn_string.addTextChangedListener(new TextWatcher()
777 {
778 @Override
779 public void onTextChanged(CharSequence s, int start, int before, int count)
780 {
781 }
782
783 @Override
784 public void afterTextChanged(Editable arg0)
785 {
786 // address text has changed
787 if (searchresultsThreadNew_offline == null)
788 {
789 Log.e("Navit", "SearchResults NEW:001:HN");
790
791 searchresultsThreadNew_offline = new SearchResultsThreadNew();
792 Navit.Navit_last_address_hn_string = arg0.toString();
793 searchresultsThreadNew_offline.start();
794 }
795 else
796 {
797 Log.e("Navit", "SearchResults NEW:002:HN");
798
799 searchresultsThreadNew_offline.set_search_strings(Navit.Navit_last_address_search_string, arg0.toString());
800 searchresultsThreadNew_offline.change_search();
801 }
802 }
803
804 @Override
805 public void beforeTextChanged(CharSequence s, int start, int count, int after)
806 {
807 }
808 });
809
810 hn_string.setOnEditorActionListener(new TextView.OnEditorActionListener()
811 {
812 @Override
813 public boolean onEditorAction(TextView v, int actionId, KeyEvent event)
814 {
815 if (actionId == EditorInfo.IME_ACTION_SEARCH)
816 {
817 executeDone("x");
818 return true;
819 }
820 return false;
821 }
822 });
823 }
824 catch (Exception e)
825 {
826 }
827 }
828
829 // address string
830 try
831 {
832
833 // address: text field -> with autocomplete dropdown
834 address_string = (ZANaviAutoCompleteTextViewSearchLocation) findViewById(R.id.et_address_string);
835 ArrayAdapter addr_view_autocomplete_adapter = new ArrayAdapter(this, android.R.layout.simple_dropdown_item_1line, Navit.p.PREF_StreetSearchStrings);
836 address_string.setCompletionHint(Navit.get_text("last searches")); // TRANS
837 if (this.search_type.equals("offline"))
838 {
839 if (Navit.use_index_search)
840 {
841 address_string.setHint(Navit.get_text("Streetname") + " " + Navit.get_text("Town")); // TRANS
842 }
843 else
844 {
845 address_string.setHint(Navit.get_text("Town") + " " + Navit.get_text("Streetname")); // TRANS
846 }
847 }
848 else
849 {
850 address_string.setHint(Navit.get_text("Address or POI-Name")); // TRANS
851 }
852
853 address_string.addTextChangedListener(new TextWatcher()
854 {
855 @Override
856 public void onTextChanged(CharSequence s, int start, int before, int count)
857 {
858 }
859
860 @Override
861 public void afterTextChanged(Editable arg0)
862 {
863 if (arg0.length() > 2)
864 {
865 // address text has changed
866 if (searchresultsThreadNew_offline == null)
867 {
868 Log.e("Navit", "SearchResults NEW:001");
869
870 searchresultsThreadNew_offline = new SearchResultsThreadNew();
871 Navit.Navit_last_address_search_string = arg0.toString();
872 searchresultsThreadNew_offline.start();
873 }
874 else
875 {
876 Log.e("Navit", "SearchResults NEW:002");
877
878 searchresultsThreadNew_offline.set_search_strings(arg0.toString(), Navit.Navit_last_address_hn_string);
879 searchresultsThreadNew_offline.change_search();
880 }
881 }
882 else
883 {
884 if (searchresultsThreadNew_offline != null)
885 {
886 Log.e("Navit", "SearchResults NEW:003");
887 searchresultsThreadNew_offline.cancel_search();
888 }
889 }
890 }
891
892 @Override
893 public void beforeTextChanged(CharSequence s, int start, int count, int after)
894 {
895 }
896 });
897
898 address_string.setOnEditorActionListener(new TextView.OnEditorActionListener()
899 {
900 @Override
901 public boolean onEditorAction(TextView v, int actionId, KeyEvent event)
902 {
903 if (actionId == EditorInfo.IME_ACTION_SEARCH)
904 {
905 executeDone("x");
906 return true;
907 }
908 return false;
909 }
910 });
911
912 address_string.setImeOptions(EditorInfo.IME_ACTION_SEARCH);
913 address_string.setSingleLine();
914 address_string.setThreshold(1);
915 address_string.setAdapter(addr_view_autocomplete_adapter);
916 address_string.setText(getIntent().getExtras().getString("address_string"));
917 }
918 catch (Exception e)
919 {
920 }
921
922 if (this.search_type.equals("offline"))
923 {
924 if (Navit.use_index_search)
925 {
926 ff_checkbox.setVisibility(View.GONE);
927 search_country_select.setVisibility(View.GONE);
928
929 // deactivate some stuff for realtime-searchresults
930 Button b = (Button) findViewById(R.id.bt_search);
931 b.setVisibility(View.GONE);
932
933 pm_checkbox.setPadding(0, 0, 0, 0);
934 pm_checkbox.setTextSize(NavitGraphics.dp_to_px(5));
935 pm_checkbox.setVisibility(View.GONE);
936
937 pm_checkbox.setChecked(true);
938
939 // hdup_checkbox.setPadding(0, 0, 0, 0);
940 hdup_checkbox.setTextSize(TypedValue.COMPLEX_UNIT_SP, 10);
941
942 TextView v1 = (TextView) findViewById(R.id.enter_dest);
943 v1.setVisibility(View.GONE);
944 TextView v2 = (TextView) findViewById(R.id.house_number);
945 v2.setVisibility(View.GONE);
946
947 result_count_text = "" + Navit.NavitAddressResultList_foundItems.size();
948 result_count_number.setText(result_count_text);
949
950 // index_container.setVisibility(View.GONE);
951
952 listview = (ListView) findViewById(R.id.search_realtime_result_container);
953 ArrayList<search_result_entry> l2 = new ArrayList<search_result_entry>();
954 // search_result_entry a = new search_result_entry(1, "eoprk woroewk r3k0", 0);
955 // l2.add(a);
956 adapter = new SearchResultListNewArrayAdapter(this, l2);
957
958 final Context c = this.getBaseContext();
959
960 listview.setOnItemClickListener(new OnItemClickListener()
961 {
962 @Override
963 public void onItemClick(AdapterView parent, View v, int position, long id)
964 {
965 selected_id_passthru = position;
966
967 Intent search_intent = new Intent(c, NavitMapPreviewActivity.class);
968 search_intent.putExtra("lat", (float) Navit.transform_to_geo_lat(Navit.NavitAddressResultList_foundItems.get(position).lat));
969 search_intent.putExtra("lon", (float) Navit.transform_to_geo_lon(Navit.NavitAddressResultList_foundItems.get(position).lon));
970
971 search_intent.putExtra("q", Navit.NavitAddressResultList_foundItems.get(position).addr);
972 startActivityForResult(search_intent, Navit.NavitMapPreview_id);
973 }
974 }
975
976 );
977
978 listview.setAdapter(adapter);
979 }
980 else
981 // no index search
982 {
983 result_count_number.setVisibility(View.GONE);
984 }
985 }
986 else
987 {
988 ff_checkbox.setVisibility(View.GONE);
989 search_country_select.setVisibility(View.GONE);
990 pm_checkbox.setVisibility(View.GONE);
991 hdup_checkbox.setVisibility(View.GONE);
992 index_container.setVisibility(View.GONE);
993 result_count_number.setVisibility(View.GONE);
994 hn_string.setVisibility(View.GONE);
995 addrhn_view.setVisibility(View.GONE);
996 }
997 }
998
999 public void start_country_select_form()
1000 {
1001 Intent search_intent = new Intent(this, NavitAddressSearchCountrySelectActivity.class);
1002 this.startActivityForResult(search_intent, Navit.NavitAddressSearchCountry_id);
1003 }
1004
1005 protected void onActivityResult(int requestCode, int resultCode, Intent data)
1006 {
1007 switch (requestCode)
1008 {
1009 case Navit.NavitAddressSearchCountry_id:
1010 try
1011 {
1012 if (resultCode == ActionBarActivity.RESULT_OK)
1013 {
1014 search_country_id = Integer.parseInt(data.getStringExtra("selected_id"));
1015 // System.out.println("search_country_id=" + search_country_id);
1016 search_country_select.setText(NavitAddressSearchCountrySelectActivity.CountryList_Human[search_country_id][2]);
1017 }
1018 }
1019 catch (Exception e)
1020 {
1021
1022 }
1023 break;
1024
1025 case Navit.NavitMapPreview_id:
1026 try
1027 {
1028 if (resultCode == Activity.RESULT_OK)
1029 {
1030 Log.e("Navit", "*activity ready*");
1031 int sel_id = Integer.parseInt(data.getStringExtra("selected_id"));
1032 Log.e("Navit", "*activity ready* sel_id=" + sel_id);
1033
1034 if (sel_id == 1)
1035 {
1036 // user wants to set as destination
1037 this.selected_id = this.selected_id_passthru;
1038 // close this activity
1039 executeDone("set");
1040 }
1041 else if (sel_id == 2)
1042 {
1043 // "back"
1044 }
1045 else if (sel_id == 3)
1046 {
1047 // show destination on map
1048 this.selected_id = this.selected_id_passthru;
1049 executeDone("view");
1050 }
1051 }
1052 }
1053 catch (Exception e)
1054 {
1055 e.printStackTrace();
1056 }
1057 break;
1058 }
1059
1060 }
1061
1062 private void executeDone(String what)
1063 {
1064 try
1065 {
1066 if (searchresultsThreadNew_offline != null)
1067 {
1068 searchresultsThreadNew_offline.stop_me();
1069 }
1070 }
1071 catch (Exception e)
1072 {
1073 }
1074
1075 Intent resultIntent = new Intent();
1076 resultIntent.putExtra("address_string", NavitAddressSearchActivity.this.address_string.getText().toString());
1077
1078 if (this.search_type.endsWith("offline"))
1079 {
1080 if (Navit.use_index_search)
1081 {
1082 resultIntent.putExtra("hn_string", NavitAddressSearchActivity.this.hn_string.getText().toString());
1083 }
1084
1085 if (NavitAddressSearchActivity.this.pm_checkbox.isChecked())
1086 {
1087 resultIntent.putExtra("partial_match", "1");
1088 }
1089 else
1090 {
1091 resultIntent.putExtra("partial_match", "0");
1092 }
1093
1094 if (NavitAddressSearchActivity.this.hdup_checkbox.isChecked())
1095 {
1096 resultIntent.putExtra("hide_dup", "1");
1097 }
1098 else
1099 {
1100 resultIntent.putExtra("hide_dup", "0");
1101 }
1102
1103 try
1104 {
1105 if (NavitAddressSearchActivity.this.ff_checkbox.isChecked())
1106 {
1107 resultIntent.putExtra("full_file_search", "1");
1108 }
1109 else
1110 {
1111 resultIntent.putExtra("full_file_search", "0");
1112 }
1113 }
1114 catch (Exception e)
1115 {
1116 // on error assume its turned off
1117 resultIntent.putExtra("full_file_search", "0");
1118 }
1119
1120 try
1121 {
1122 resultIntent.putExtra("address_country_iso2", NavitAddressSearchCountrySelectActivity.CountryList_Human[search_country_id][0]);
1123 resultIntent.putExtra("search_country_id", search_country_id);
1124 if (NavitAddressSearchCountrySelectActivity.CountryList_Human[search_country_id][0].equals("*D"))
1125 {
1126 resultIntent.putExtra("address_country_flags", 1);
1127 }
1128 else if (NavitAddressSearchCountrySelectActivity.CountryList_Human[search_country_id][0].equals("*A"))
1129 {
1130 resultIntent.putExtra("address_country_flags", 3);
1131 }
1132 else
1133 {
1134 resultIntent.putExtra("address_country_flags", 2);
1135 }
1136 }
1137 catch (Exception e)
1138 {
1139 // index search
1140 resultIntent.putExtra("address_country_iso2", "X");
1141 resultIntent.putExtra("search_country_id", 0);
1142 resultIntent.putExtra("address_country_flags", 2);
1143 }
1144 }
1145
1146 try
1147 {
1148 // now hide the keyboard before we switch back to the mapscreen (bitmaps wont be recreated because now the size stays the same!)
1149 InputMethodManager inputManager = (InputMethodManager) this.getSystemService(Context.INPUT_METHOD_SERVICE);
1150 inputManager.hideSoftInputFromWindow(this.getCurrentFocus().getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);
1151 }
1152 catch (Exception e)
1153 {
1154
1155 }
1156
1157 resultIntent.putExtra("selected_id", String.valueOf(this.selected_id));
1158 if (what.equals("view"))
1159 {
1160 resultIntent.putExtra("what", "view");
1161 }
1162 else if (what.equals("set"))
1163 {
1164 resultIntent.putExtra("what", "set");
1165 }
1166 else
1167 {
1168 resultIntent.putExtra("what", "-");
1169 }
1170
1171 setResult(ActionBarActivity.RESULT_OK, resultIntent);
1172 finish();
1173 }
1174 }

   
Visit the ZANavi Wiki