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

   
Visit the ZANavi Wiki