/[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 51 - (show annotations) (download)
Mon Jul 25 19:29:08 2016 UTC (7 years, 9 months ago) by zoff99
File size: 35874 byte(s)
v2.0.52
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
669 if (!Navit.use_index_search)
670 {
671 ff_checkbox.setText(Navit.get_text("search full mapfile [BETA]")); //TRANS
672 ff_checkbox.setChecked(false);
673 ff_checkbox.setOnCheckedChangeListener(new OnCheckedChangeListener()
674 {
675 public void onCheckedChanged(CompoundButton buttonView, boolean isChecked)
676 {
677 if (isChecked)
678 {
679 try
680 {
681 search_country_select.setVisibility(View.INVISIBLE);
682 hdup_checkbox.setVisibility(View.INVISIBLE);
683 }
684 catch (Exception e)
685 {
686
687 }
688 }
689 else
690 {
691 try
692 {
693 search_country_select.setVisibility(View.VISIBLE);
694 hdup_checkbox.setVisibility(View.VISIBLE);
695 }
696 catch (Exception e)
697 {
698
699 }
700 }
701 }
702 });
703 }
704
705 // search button
706 final Button btnSearch = (Button) findViewById(R.id.bt_search);
707 btnSearch.setText(Navit.get_text("Search")); //TRANS
708 btnSearch.setOnClickListener(new OnClickListener()
709 {
710 public void onClick(View v)
711 {
712 executeDone("x");
713 }
714 });
715
716 this.search_type = getIntent().getExtras().getString("type");
717 if (this.search_type.endsWith("offline"))
718 {
719 this.search_country_id = getIntent().getExtras().getInt("search_country_id");
720 }
721
722 // select country button
723 search_country_select = (Button) findViewById(R.id.bt_country_select);
724 if (!Navit.use_index_search)
725 {
726
727 search_country_select.setText(NavitAddressSearchCountrySelectActivity.CountryList_Human[search_country_id][2]);
728 search_country_select.setOnClickListener(new View.OnClickListener()
729 {
730 public void onClick(View v)
731 {
732 start_country_select_form();
733 }
734 });
735 }
736
737 // title
738 try
739 {
740 String s = getIntent().getExtras().getString("title");
741 if (s.length() > 0)
742 {
743 this.setTitle(s);
744 }
745 }
746 catch (Exception e)
747 {
748 }
749
750 // partial match
751 try
752 {
753 String s = getIntent().getExtras().getString("partial_match");
754 if (s.length() > 0)
755 {
756 if (s.equals("1"))
757 {
758 pm_checkbox.setChecked(true);
759 }
760 else
761 {
762 pm_checkbox.setChecked(false);
763 }
764 }
765 }
766 catch (Exception e)
767 {
768 }
769
770 hn_string = (EditText) findViewById(R.id.et_house_number_string);
771
772 if (Navit.use_index_search)
773 {
774
775 // hide duplicates
776 hdup_checkbox.setOnClickListener(new OnClickListener()
777 {
778
779 @Override
780 public void onClick(View v)
781 {
782 if (((CheckBox) v).isChecked())
783 {
784 Navit.search_hide_duplicates = true;
785 }
786 else
787 {
788 Navit.search_hide_duplicates = false;
789 }
790
791 // checkbox has changed state
792 try
793 {
794 if (searchresultsThreadNew_offline == null)
795 {
796 Log.e("Navit", "SearchResults NEW:001:HN");
797
798 searchresultsThreadNew_offline = new SearchResultsThreadNew();
799 searchresultsThreadNew_offline.start();
800 }
801 else
802 {
803 Log.e("Navit", "SearchResults NEW:002:HN");
804
805 searchresultsThreadNew_offline.change_search();
806 }
807 }
808 catch (Exception e)
809 {
810 e.printStackTrace();
811 }
812
813 }
814 });
815
816 // house number string
817 try
818 {
819 hn_string.setSingleLine();
820 hn_string.setHint(Navit.get_text("Housenumber")); // TRANS
821 // hn_string.setInputType(InputType.TYPE_CLASS_NUMBER);
822 hn_string.setImeOptions(EditorInfo.IME_ACTION_SEARCH);
823 hn_string.setText(getIntent().getExtras().getString("hn_string"));
824
825 hn_string.addTextChangedListener(new TextWatcher()
826 {
827 @Override
828 public void onTextChanged(CharSequence s, int start, int before, int count)
829 {
830 }
831
832 @Override
833 public void afterTextChanged(Editable arg0)
834 {
835 // address text has changed
836 try
837 {
838 if (searchresultsThreadNew_offline == null)
839 {
840 Log.e("Navit", "SearchResults NEW:001:HN");
841
842 searchresultsThreadNew_offline = new SearchResultsThreadNew();
843 Navit.Navit_last_address_hn_string = arg0.toString();
844 searchresultsThreadNew_offline.start();
845 }
846 else
847 {
848 Log.e("Navit", "SearchResults NEW:002:HN");
849
850 searchresultsThreadNew_offline.set_search_strings(Navit.Navit_last_address_search_string, arg0.toString());
851 searchresultsThreadNew_offline.change_search();
852 }
853 }
854 catch (Exception e)
855 {
856 e.printStackTrace();
857 }
858 }
859
860 @Override
861 public void beforeTextChanged(CharSequence s, int start, int count, int after)
862 {
863 }
864 });
865
866 hn_string.setOnEditorActionListener(new TextView.OnEditorActionListener()
867 {
868 @Override
869 public boolean onEditorAction(TextView v, int actionId, KeyEvent event)
870 {
871 if (actionId == EditorInfo.IME_ACTION_SEARCH)
872 {
873 executeDone("x");
874 return true;
875 }
876 return false;
877 }
878 });
879 }
880 catch (Exception e)
881 {
882 }
883 }
884
885 // address string
886 try
887 {
888
889 // address: text field -> with autocomplete dropdown
890 address_string = (ZANaviAutoCompleteTextViewSearchLocation) findViewById(R.id.et_address_string);
891 ArrayAdapter addr_view_autocomplete_adapter = new ArrayAdapter(this, android.R.layout.simple_dropdown_item_1line, Navit.p.PREF_StreetSearchStrings);
892 address_string.setCompletionHint(Navit.get_text("last searches")); // TRANS
893 if (this.search_type.equals("offline"))
894 {
895 if (Navit.use_index_search)
896 {
897 address_string.setHint(Navit.get_text("Streetname") + " " + Navit.get_text("Town")); // TRANS
898 }
899 else
900 {
901 address_string.setHint(Navit.get_text("Town") + " " + Navit.get_text("Streetname")); // TRANS
902 }
903 }
904 else
905 {
906 address_string.setHint(Navit.get_text("Address or POI-Name")); // TRANS
907 }
908
909 address_string.addTextChangedListener(new TextWatcher()
910 {
911 @Override
912 public void onTextChanged(CharSequence s, int start, int before, int count)
913 {
914 }
915
916 @Override
917 public void afterTextChanged(Editable arg0)
918 {
919 try
920 {
921 if (arg0.length() > 2)
922 {
923 // address text has changed
924 if (searchresultsThreadNew_offline == null)
925 {
926 Log.e("Navit", "SearchResults NEW:001");
927
928 searchresultsThreadNew_offline = new SearchResultsThreadNew();
929 Navit.Navit_last_address_search_string = arg0.toString();
930 searchresultsThreadNew_offline.start();
931 }
932 else
933 {
934 Log.e("Navit", "SearchResults NEW:002");
935
936 searchresultsThreadNew_offline.set_search_strings(arg0.toString(), Navit.Navit_last_address_hn_string);
937 searchresultsThreadNew_offline.change_search();
938 }
939 }
940 else
941 {
942 if (searchresultsThreadNew_offline != null)
943 {
944 Log.e("Navit", "SearchResults NEW:003");
945 searchresultsThreadNew_offline.cancel_search();
946 }
947 }
948 }
949 catch (Exception e)
950 {
951 e.printStackTrace();
952 }
953 }
954
955 @Override
956 public void beforeTextChanged(CharSequence s, int start, int count, int after)
957 {
958 }
959 });
960
961 address_string.setOnEditorActionListener(new TextView.OnEditorActionListener()
962 {
963 @Override
964 public boolean onEditorAction(TextView v, int actionId, KeyEvent event)
965 {
966 if (actionId == EditorInfo.IME_ACTION_SEARCH)
967 {
968 executeDone("x");
969 return true;
970 }
971 return false;
972 }
973 });
974
975 address_string.setImeOptions(EditorInfo.IME_ACTION_SEARCH);
976 address_string.setSingleLine();
977 address_string.setThreshold(1);
978 address_string.setAdapter(addr_view_autocomplete_adapter);
979 address_string.setText(getIntent().getExtras().getString("address_string"));
980 }
981 catch (Exception e)
982 {
983 }
984
985 if (this.search_type.equals("offline"))
986 {
987 if (Navit.use_index_search)
988 {
989 ff_checkbox.setVisibility(View.GONE);
990 search_country_select.setVisibility(View.GONE);
991
992 // deactivate some stuff for realtime-searchresults
993 Button b = (Button) findViewById(R.id.bt_search);
994 b.setVisibility(View.GONE);
995
996 pm_checkbox.setPadding(0, 0, 0, 0);
997 pm_checkbox.setTextSize(NavitGraphics.dp_to_px(5));
998 pm_checkbox.setVisibility(View.GONE);
999
1000 pm_checkbox.setChecked(true);
1001
1002 // hdup_checkbox.setPadding(0, 0, 0, 0);
1003 hdup_checkbox.setTextSize(TypedValue.COMPLEX_UNIT_SP, 10);
1004
1005 TextView v1 = (TextView) findViewById(R.id.enter_dest);
1006 v1.setVisibility(View.GONE);
1007 TextView v2 = (TextView) findViewById(R.id.house_number);
1008 v2.setVisibility(View.GONE);
1009
1010 result_count_text = "" + Navit.NavitAddressResultList_foundItems.size();
1011 result_count_number.setText(result_count_text);
1012
1013 // index_container.setVisibility(View.GONE);
1014
1015 listview = (ListView) findViewById(R.id.search_realtime_result_container);
1016 ArrayList<search_result_entry> l2 = new ArrayList<search_result_entry>();
1017 // search_result_entry a = new search_result_entry(1, "eoprk woroewk r3k0", 0);
1018 // l2.add(a);
1019 adapter = new SearchResultListNewArrayAdapter(this, l2);
1020
1021 final Context c = this.getBaseContext();
1022
1023 listview.setOnItemClickListener(new OnItemClickListener()
1024 {
1025 @Override
1026 public void onItemClick(AdapterView parent, View v, int position, long id)
1027 {
1028 selected_id_passthru = position;
1029
1030 Intent search_intent = new Intent(c, NavitMapPreviewActivity.class);
1031 search_intent.putExtra("lat", (float) Navit.transform_to_geo_lat(Navit.NavitAddressResultList_foundItems.get(position).lat));
1032 search_intent.putExtra("lon", (float) Navit.transform_to_geo_lon(Navit.NavitAddressResultList_foundItems.get(position).lon));
1033
1034 search_intent.putExtra("q", Navit.NavitAddressResultList_foundItems.get(position).addr);
1035 startActivityForResult(search_intent, Navit.NavitMapPreview_id);
1036 }
1037 }
1038
1039 );
1040
1041 listview.setAdapter(adapter);
1042 }
1043 else
1044 // no index search
1045 {
1046 result_count_number.setVisibility(View.GONE);
1047 }
1048 }
1049 else
1050 {
1051 ff_checkbox.setVisibility(View.GONE);
1052 search_country_select.setVisibility(View.GONE);
1053 pm_checkbox.setVisibility(View.GONE);
1054 hdup_checkbox.setVisibility(View.GONE);
1055 index_container.setVisibility(View.GONE);
1056 result_count_number.setVisibility(View.GONE);
1057 hn_string.setVisibility(View.GONE);
1058 addrhn_view.setVisibility(View.GONE);
1059 }
1060 }
1061
1062 public void start_country_select_form()
1063 {
1064 Intent search_intent = new Intent(this, NavitAddressSearchCountrySelectActivity.class);
1065 this.startActivityForResult(search_intent, Navit.NavitAddressSearchCountry_id);
1066 }
1067
1068 protected void onActivityResult(int requestCode, int resultCode, Intent data)
1069 {
1070 switch (requestCode)
1071 {
1072 case Navit.NavitAddressSearchCountry_id:
1073 try
1074 {
1075 if (resultCode == ActionBarActivity.RESULT_OK)
1076 {
1077 search_country_id = Integer.parseInt(data.getStringExtra("selected_id"));
1078 // System.out.println("search_country_id=" + search_country_id);
1079 search_country_select.setText(NavitAddressSearchCountrySelectActivity.CountryList_Human[search_country_id][2]);
1080 }
1081 }
1082 catch (Exception e)
1083 {
1084
1085 }
1086 break;
1087
1088 case Navit.NavitMapPreview_id:
1089 try
1090 {
1091 if (resultCode == Activity.RESULT_OK)
1092 {
1093 Log.e("Navit", "*activity ready*");
1094 int sel_id = Integer.parseInt(data.getStringExtra("selected_id"));
1095 Log.e("Navit", "*activity ready* sel_id=" + sel_id);
1096
1097 if (sel_id == 1)
1098 {
1099 // user wants to set as destination
1100 this.selected_id = this.selected_id_passthru;
1101 // close this activity
1102 executeDone("set");
1103 }
1104 else if (sel_id == 2)
1105 {
1106 // "back"
1107 }
1108 else if (sel_id == 3)
1109 {
1110 // show destination on map
1111 this.selected_id = this.selected_id_passthru;
1112 executeDone("view");
1113 }
1114 }
1115 }
1116 catch (Exception e)
1117 {
1118 e.printStackTrace();
1119 }
1120 break;
1121 }
1122
1123 }
1124
1125 static void force_done()
1126 {
1127 try
1128 {
1129 if (searchresultsThreadNew_offline != null)
1130 {
1131 searchresultsThreadNew_offline.stop_me();
1132 }
1133 }
1134 catch (Exception e)
1135 {
1136 }
1137
1138 Intent resultIntent = new Intent();
1139
1140 NavitAddressSearchActivity_s.setResult(ActionBarActivity.RESULT_OK, resultIntent);
1141 resultIntent.putExtra("address_string", NavitAddressSearchActivity.address_string.getText().toString());
1142 resultIntent.putExtra("what", "-");
1143
1144 NavitAddressSearchActivity_s.finish();
1145 }
1146
1147 private void executeDone(String what)
1148 {
1149 try
1150 {
1151 if (searchresultsThreadNew_offline != null)
1152 {
1153 searchresultsThreadNew_offline.stop_me();
1154 }
1155 }
1156 catch (Exception e)
1157 {
1158 }
1159
1160 Intent resultIntent = new Intent();
1161 resultIntent.putExtra("address_string", NavitAddressSearchActivity.address_string.getText().toString());
1162
1163 if (this.search_type.endsWith("offline"))
1164 {
1165 if (Navit.use_index_search)
1166 {
1167 resultIntent.putExtra("hn_string", NavitAddressSearchActivity.this.hn_string.getText().toString());
1168 }
1169
1170 if (NavitAddressSearchActivity.pm_checkbox.isChecked())
1171 {
1172 resultIntent.putExtra("partial_match", "1");
1173 }
1174 else
1175 {
1176 resultIntent.putExtra("partial_match", "0");
1177 }
1178
1179 if (NavitAddressSearchActivity.hdup_checkbox.isChecked())
1180 {
1181 resultIntent.putExtra("hide_dup", "1");
1182 }
1183 else
1184 {
1185 resultIntent.putExtra("hide_dup", "0");
1186 }
1187
1188 try
1189 {
1190 if (NavitAddressSearchActivity.this.ff_checkbox.isChecked())
1191 {
1192 resultIntent.putExtra("full_file_search", "1");
1193 }
1194 else
1195 {
1196 resultIntent.putExtra("full_file_search", "0");
1197 }
1198 }
1199 catch (Exception e)
1200 {
1201 // on error assume its turned off
1202 resultIntent.putExtra("full_file_search", "0");
1203 }
1204
1205 try
1206 {
1207 resultIntent.putExtra("address_country_iso2", NavitAddressSearchCountrySelectActivity.CountryList_Human[search_country_id][0]);
1208 resultIntent.putExtra("search_country_id", search_country_id);
1209 if (NavitAddressSearchCountrySelectActivity.CountryList_Human[search_country_id][0].equals("*D"))
1210 {
1211 resultIntent.putExtra("address_country_flags", 1);
1212 }
1213 else if (NavitAddressSearchCountrySelectActivity.CountryList_Human[search_country_id][0].equals("*A"))
1214 {
1215 resultIntent.putExtra("address_country_flags", 3);
1216 }
1217 else
1218 {
1219 resultIntent.putExtra("address_country_flags", 2);
1220 }
1221 }
1222 catch (Exception e)
1223 {
1224 // index search
1225 resultIntent.putExtra("address_country_iso2", "X");
1226 resultIntent.putExtra("search_country_id", 0);
1227 resultIntent.putExtra("address_country_flags", 2);
1228 }
1229 }
1230
1231 try
1232 {
1233 // now hide the keyboard before we switch back to the mapscreen (bitmaps wont be recreated because now the size stays the same!)
1234 InputMethodManager inputManager = (InputMethodManager) this.getSystemService(Context.INPUT_METHOD_SERVICE);
1235 inputManager.hideSoftInputFromWindow(this.getCurrentFocus().getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);
1236 }
1237 catch (Exception e)
1238 {
1239
1240 }
1241
1242 resultIntent.putExtra("selected_id", String.valueOf(this.selected_id));
1243 if (what.equals("view"))
1244 {
1245 resultIntent.putExtra("what", "view");
1246 }
1247 else if (what.equals("set"))
1248 {
1249 resultIntent.putExtra("what", "set");
1250 }
1251 else
1252 {
1253 resultIntent.putExtra("what", "-");
1254 }
1255
1256 setResult(ActionBarActivity.RESULT_OK, resultIntent);
1257 finish();
1258 }
1259 }

   
Visit the ZANavi Wiki