/[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 31 - (show annotations) (download)
Mon Feb 4 17:41:59 2013 UTC (11 years, 1 month ago) by zoff99
File size: 9101 byte(s)
new map version, lots of fixes and experimental new features
1 /**
2 * ZANavi, Zoff Android Navigation system.
3 * Copyright (C) 2011 Zoff <zoff@zoff.cc>
4 *
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * version 2 as published by the Free Software Foundation.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the
16 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
18 */
19
20 /**
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 if (Navit.use_index_search)
205 {
206 //Log.e("Navit", "long click lat=" + Navit.NavitAddressResultList_foundItems.get(pos).lat);
207 //Log.e("Navit", "long click lon=" + Navit.NavitAddressResultList_foundItems.get(pos).lon);
208 //Log.e("Navit", "long click lat=" + Navit.transform_to_geo_lat(Navit.NavitAddressResultList_foundItems.get(pos).lat));
209 //Log.e("Navit", "long click lon=" + Navit.transform_to_geo_lon(Navit.NavitAddressResultList_foundItems.get(pos).lon));
210 search_intent.putExtra("lat", (float) Navit.transform_to_geo_lat(Navit.NavitAddressResultList_foundItems.get(pos).lat));
211 search_intent.putExtra("lon", (float) Navit.transform_to_geo_lon(Navit.NavitAddressResultList_foundItems.get(pos).lon));
212 }
213 else
214 {
215 search_intent.putExtra("lat", Navit.NavitAddressResultList_foundItems.get(pos).lat);
216 search_intent.putExtra("lon", Navit.NavitAddressResultList_foundItems.get(pos).lon);
217 }
218 search_intent.putExtra("q", Navit.NavitAddressResultList_foundItems.get(pos).addr);
219 this.startActivityForResult(search_intent, Navit.NavitMapPreview_id);
220 }
221
222 protected void onActivityResult(int requestCode, int resultCode, Intent data)
223 {
224 switch (requestCode)
225 {
226 case Navit.NavitMapPreview_id:
227 try
228 {
229 if (resultCode == Activity.RESULT_OK)
230 {
231 Log.e("Navit", "*activity ready*");
232 int sel_id = Integer.parseInt(data.getStringExtra("selected_id"));
233 Log.e("Navit", "*activity ready* sel_id=" + sel_id);
234
235 if (sel_id == 1)
236 {
237 // user wants to set as destination
238 this.selected_id = this.selected_id_passthru;
239 // close this activity
240 executeDone("set");
241 }
242 else if (sel_id == 2)
243 {
244 // "back"
245 }
246 else if (sel_id == 3)
247 {
248 // show destination on map
249 this.selected_id = this.selected_id_passthru;
250 executeDone("view");
251 }
252 }
253 }
254 catch (Exception e)
255 {
256 e.printStackTrace();
257 }
258 }
259 }
260
261 @Override
262 protected void onListItemClick(ListView l, View v, int position, long id)
263 {
264 super.onListItemClick(l, v, position, id);
265
266 // --- OLD --- set as target
267 // --- OLD --- set as target
268 // **this.selected_id = position;
269 // Log.e("Navit", "p:" + position);
270 // Log.e("Navit", "i:" + id);
271 // **executeDone();
272 // --- OLD --- set as target
273 // --- OLD --- set as target
274
275 // --- NEW --- preview map
276 // --- NEW --- preview map
277 onLongListItemClick(v, position, id);
278 // --- NEW --- preview map
279 // --- NEW --- preview map
280 }
281
282 // @Override
283 // public void onBackPressed()
284 // {
285 // executeDone();
286 // super.onBackPressed();
287 // }
288
289 private void executeDone(String what)
290 {
291 Intent resultIntent = new Intent();
292 resultIntent.putExtra("selected_id", String.valueOf(this.selected_id));
293 if (what.equals("view"))
294 {
295 resultIntent.putExtra("what", "view");
296 }
297 else
298 {
299 resultIntent.putExtra("what", "-");
300 }
301 setResult(Activity.RESULT_OK, resultIntent);
302 finish();
303 }
304
305 }

   
Visit the ZANavi Wiki