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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 15 - (show annotations) (download)
Mon Nov 21 20:54:48 2011 UTC (12 years, 5 months ago) by zoff99
File size: 8350 byte(s)
better search, make search interuptable, new translations
1 /**
2 * ZANavi, Zoff Android Navigation system.
3 * Copyright (C) 2011 Zoff <zoff@zoff.cc>
4 *
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * version 2 as published by the Free Software Foundation.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the
16 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
18 */
19
20 /**
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.Iterator;
42
43 import android.app.Activity;
44 import android.app.ListActivity;
45 import android.content.Intent;
46 import android.os.Bundle;
47 import android.util.Log;
48 import android.view.View;
49 import android.widget.AdapterView;
50 import android.widget.ArrayAdapter;
51 import android.widget.ListView;
52
53 public class NavitAddressResultListActivity extends ListActivity
54 {
55 // public static NavitAddressResultListActivity self_ = null;
56 ArrayAdapter<String> adapter_ = null;
57 private int selected_id = -1;
58 private int selected_id_passthru = -1;
59 private Boolean is_empty = true;
60 public String[] result_list = new String[] { "loading results ..." };
61 public static int mode = 1; // 0 .. hide towns if streets/housenumbers available
62 // 1 .. show towns and streets and housenumbers
63 // 2 .. show only towns
64
65 @Override
66 public void onCreate(Bundle savedInstanceState)
67 {
68 super.onCreate(savedInstanceState);
69 //Log.e("Navit", "all ok");
70
71 Navit.Navit_Address_Result_Struct tmp = new Navit.Navit_Address_Result_Struct();
72
73 Log.e("Navit", "########### full result count: " + Navit.NavitAddressResultList_foundItems.size());
74
75 if (mode == 0)
76 {
77 // show "town names" as results only when we dont have any street names in resultlist
78 if ((Navit.search_results_streets > 0) || (Navit.search_results_streets_hn > 0))
79 {
80 // clear out towns from result list
81 for (Iterator<Navit.Navit_Address_Result_Struct> k = Navit.NavitAddressResultList_foundItems.iterator(); k.hasNext();)
82 {
83 tmp = k.next();
84 if (tmp.result_type.equals("TWN"))
85 {
86 k.remove();
87 }
88 }
89 }
90 }
91 else if (mode == 1)
92 {
93 // fine, show them all
94 }
95 else if (mode == 2)
96 {
97 // show only town names
98 // clear out streets and housenumbers from result list
99 for (Iterator<Navit.Navit_Address_Result_Struct> k = Navit.NavitAddressResultList_foundItems.iterator(); k.hasNext();)
100 {
101 tmp = k.next();
102 if (tmp.result_type.equals("STR"))
103 {
104 k.remove();
105 }
106 else if (tmp.result_type.equals("SHN"))
107 {
108 k.remove();
109 }
110 }
111 }
112
113 Log.e("Navit", "########### final result count: " + Navit.NavitAddressResultList_foundItems.size());
114
115 this.result_list = new String[Navit.NavitAddressResultList_foundItems.size()];
116 int j = 0;
117 for (Iterator<Navit.Navit_Address_Result_Struct> i = Navit.NavitAddressResultList_foundItems.iterator(); i.hasNext();)
118 {
119 tmp = i.next();
120 this.result_list[j] = tmp.addr;
121 j++;
122 }
123
124 // self_ = this;
125
126 adapter_ = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, result_list);
127 setListAdapter(adapter_);
128 this.getListView().setFastScrollEnabled(true);
129 is_empty = true;
130
131 // ListActivity has a ListView, which you can get with:
132 ListView lv = getListView();
133
134 // Then you can create a listener like so:
135 lv.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener()
136 {
137 @Override
138 public boolean onItemLongClick(AdapterView<?> av, View v, int pos, long id)
139 {
140 onLongListItemClick(v, pos, id);
141 return true;
142 }
143
144 });
145
146 }
147
148 public void fillStringArray_later(String s)
149 {
150 System.out.println("fillStringArray_later: " + s);
151 }
152
153 public static void add_item_later(String item)
154 {
155 try
156 {
157 // self_.add_item_(item);
158 // adapter_.notifyDataSetChanged();
159 }
160 catch (Exception e)
161 {
162 e.printStackTrace();
163 }
164 }
165
166 public void add_item_(String item)
167 {
168 if (item == null)
169 {
170 // empty item?
171 return;
172 }
173
174 if (this.is_empty)
175 {
176 // clear dummy text, and add this item
177 this.result_list = new String[1];
178 this.result_list[0] = item;
179 }
180 else
181 {
182 // add the item to the end of the list
183 String[] tmp_list = this.result_list;
184 this.result_list = new String[tmp_list.length + 1];
185 for (int i = 0; i < tmp_list.length; i = i + 1)
186 {
187 this.result_list[i] = tmp_list[i];
188 }
189 this.result_list[tmp_list.length] = item;
190 }
191 ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, result_list);
192 setListAdapter(adapter);
193 this.is_empty = false;
194 }
195
196 protected void onLongListItemClick(View v, int pos, long id)
197 {
198 Log.e("Navit", "long click id=" + id + " pos=" + pos);
199 // remember what pos we clicked
200 this.selected_id_passthru = pos;
201
202 Intent search_intent = new Intent(this, NavitMapPreviewActivity.class);
203
204 search_intent.putExtra("lat", Navit.NavitAddressResultList_foundItems.get(pos).lat);
205 search_intent.putExtra("lon", Navit.NavitAddressResultList_foundItems.get(pos).lon);
206 search_intent.putExtra("q", Navit.NavitAddressResultList_foundItems.get(pos).addr);
207 this.startActivityForResult(search_intent, Navit.NavitMapPreview_id);
208 }
209
210 protected void onActivityResult(int requestCode, int resultCode, Intent data)
211 {
212 switch (requestCode)
213 {
214 case Navit.NavitMapPreview_id:
215 try
216 {
217 if (resultCode == Activity.RESULT_OK)
218 {
219 Log.e("Navit", "*activity ready*");
220 int sel_id = Integer.parseInt(data.getStringExtra("selected_id"));
221 Log.e("Navit", "*activity ready* sel_id=" + sel_id);
222
223 if (sel_id == 1)
224 {
225 // user wants to set as destination
226 this.selected_id = this.selected_id_passthru;
227 // close this activity
228 executeDone("set");
229 }
230 else if (sel_id == 2)
231 {
232 // "back"
233 }
234 else if (sel_id == 3)
235 {
236 // show destination on map
237 this.selected_id = this.selected_id_passthru;
238 executeDone("view");
239 }
240 }
241 }
242 catch (Exception e)
243 {
244 e.printStackTrace();
245 }
246 }
247 }
248
249 @Override
250 protected void onListItemClick(ListView l, View v, int position, long id)
251 {
252 super.onListItemClick(l, v, position, id);
253
254 // --- OLD --- set as target
255 // --- OLD --- set as target
256 // **this.selected_id = position;
257 // Log.e("Navit", "p:" + position);
258 // Log.e("Navit", "i:" + id);
259 // **executeDone();
260 // --- OLD --- set as target
261 // --- OLD --- set as target
262
263 // --- NEW --- preview map
264 // --- NEW --- preview map
265 onLongListItemClick(v, position, id);
266 // --- NEW --- preview map
267 // --- NEW --- preview map
268 }
269
270 // @Override
271 // public void onBackPressed()
272 // {
273 // executeDone();
274 // super.onBackPressed();
275 // }
276
277 private void executeDone(String what)
278 {
279 Intent resultIntent = new Intent();
280 resultIntent.putExtra("selected_id", String.valueOf(this.selected_id));
281 if (what.equals("view"))
282 {
283 resultIntent.putExtra("what", "view");
284 }
285 else
286 {
287 resultIntent.putExtra("what", "-");
288 }
289 setResult(Activity.RESULT_OK, resultIntent);
290 finish();
291 }
292
293 }

   
Visit the ZANavi Wiki