/[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 41 - (show annotations) (download)
Tue Aug 11 18:50:37 2015 UTC (8 years, 8 months ago) by zoff99
File size: 11559 byte(s)
many fixes, and 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.ArrayList;
42 import java.util.Iterator;
43 import java.util.LinkedHashMap;
44 import java.util.List;
45 import java.util.Map;
46
47 import android.app.Activity;
48 import android.app.ExpandableListActivity;
49 import android.content.Intent;
50 import android.os.Build;
51 import android.os.Bundle;
52 import android.support.v7.widget.Toolbar;
53 import android.support.v7.widget.Toolbar.LayoutParams;
54 import android.util.Log;
55 import android.view.LayoutInflater;
56 import android.view.View;
57 import android.view.ViewGroup;
58 import android.widget.ExpandableListView;
59 import android.widget.LinearLayout;
60 import android.widget.ListView;
61
62 import com.zoffcc.applications.zanavi.NavitSearchResultListArrayAdapter.search_result_entry;
63
64 public class NavitAddressResultListActivity extends ExpandableListActivity
65 {
66 // public static NavitAddressResultListActivity self_ = null;
67 NavitSearchResultListArrayAdapter adapter_ = null;
68 private int selected_id = -1;
69 private int selected_id_passthru = -1;
70 // private Boolean is_empty = true;
71 // public ArrayList<HashMap<Integer, search_result_entry>> result_list;
72 public Map<Integer, List<search_result_entry>> result_list;
73
74 public static int mode = 1; // 0 .. hide towns if streets/housenumbers available
75 // 1 .. show towns and streets and housenumbers
76 // 2 .. show only towns
77
78 @Override
79 protected void onPostCreate(Bundle savedInstanceState)
80 {
81 super.onPostCreate(savedInstanceState);
82 Toolbar bar;
83
84 if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH)
85 {
86 ViewGroup root_view = (ViewGroup) findViewById(android.R.id.list).getParent().getParent();
87
88 bar = (Toolbar) LayoutInflater.from(this).inflate(R.layout.settings_toolbar, root_view, false);
89 bar.setTitle(Navit.get_text("Search results"));
90 root_view.addView(bar, 0); // insert at top
91 }
92 else
93 {
94 ViewGroup root_view = (ViewGroup) findViewById(android.R.id.content);
95 ListView content = (ListView) root_view.getChildAt(0);
96
97 root_view.removeAllViews();
98
99 LinearLayout ll = new LinearLayout(this);
100 ll.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
101 ll.setOrientation(LinearLayout.VERTICAL);
102
103 bar = (Toolbar) LayoutInflater.from(this).inflate(R.layout.settings_toolbar, root_view, false);
104 bar.setTitle(Navit.get_text("Search results"));
105 root_view.addView(ll);
106
107 ll.addView(bar);
108 ll.addView(content);
109 }
110
111 bar.setNavigationOnClickListener(new View.OnClickListener()
112 {
113 @Override
114 public void onClick(View v)
115 {
116 finish();
117 }
118 });
119 }
120
121 @Override
122 public void onCreate(Bundle savedInstanceState)
123 {
124 Navit.applySharedTheme(this, Navit.p.PREF_current_theme);
125
126 super.onCreate(savedInstanceState);
127
128 // Override how this activity is animated into view
129 // The new activity is pulled in from the left and the current activity is kept still
130 // This has to be called before onCreate
131 overridePendingTransition(R.anim.pull_in_from_right, R.anim.hold);
132
133 //Log.e("Navit", "all ok");
134
135 Navit.Navit_Address_Result_Struct tmp = new Navit.Navit_Address_Result_Struct();
136
137 Log.e("Navit", "########### full result count: " + Navit.NavitAddressResultList_foundItems.size());
138
139 // if (mode == 0)
140 // {
141 // // show "town names" as results only when we dont have any street names in resultlist
142 // if ((Navit.search_results_streets > 0) || (Navit.search_results_streets_hn > 0))
143 // {
144 // // clear out towns from result list
145 // for (Iterator<Navit.Navit_Address_Result_Struct> k = Navit.NavitAddressResultList_foundItems.iterator(); k.hasNext();)
146 // {
147 // tmp = k.next();
148 // if (tmp.result_type.equals("TWN"))
149 // {
150 // k.remove();
151 // }
152 // }
153 // }
154 // }
155 // else if (mode == 1)
156 // {
157 // // fine, show them all
158 // }
159 // else if (mode == 2)
160 // {
161 // // show only town names
162 // // clear out streets and housenumbers from result list
163 // for (Iterator<Navit.Navit_Address_Result_Struct> k = Navit.NavitAddressResultList_foundItems.iterator(); k.hasNext();)
164 // {
165 // tmp = k.next();
166 // if (tmp.result_type.equals("STR"))
167 // {
168 // k.remove();
169 // }
170 // else if (tmp.result_type.equals("SHN"))
171 // {
172 // k.remove();
173 // }
174 // }
175 // }
176
177 Log.e("Navit", "########### final result count: " + Navit.NavitAddressResultList_foundItems.size());
178
179 // this.result_list = new String[Navit.NavitAddressResultList_foundItems.size()];
180 this.result_list = new LinkedHashMap<Integer, List<search_result_entry>>();
181 ArrayList<search_result_entry> l1 = new ArrayList<search_result_entry>();
182 ArrayList<search_result_entry> l2 = new ArrayList<search_result_entry>();
183 ArrayList<search_result_entry> l3 = new ArrayList<search_result_entry>();
184
185 int j = 0;
186 for (Iterator<Navit.Navit_Address_Result_Struct> i = Navit.NavitAddressResultList_foundItems.iterator(); i.hasNext();)
187 {
188 tmp = i.next();
189 if (tmp.result_type.equals("TWN"))
190 {
191 l2.add(new search_result_entry(2, tmp.addr, j)); // town
192 }
193 else if (tmp.result_type.equals("POI"))
194 {
195 l3.add(new search_result_entry(3, tmp.addr, j)); // POI
196 }
197 else
198 {
199 l1.add(new search_result_entry(1, tmp.addr, j)); // street or housenumber
200 }
201 // [j] = tmp.addr;
202 j++;
203 }
204
205 this.result_list.put(1, l1);
206 this.result_list.put(2, l2);
207 this.result_list.put(3, l3);
208
209 //System.out.println("LL:in:l1=" + l1.size() + " l2=" + l2.size() + " l3=" + l3.size());
210
211 // self_ = this;
212
213 // adapter_ = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, result_list);
214 adapter_ = new NavitSearchResultListArrayAdapter(this, result_list);
215
216 setListAdapter(adapter_);
217 // this.getListView().setFastScrollEnabled(true);
218 // ** // is_empty = true;
219
220 // this.getExpandableListView().setBackgroundColor(Color.rgb(0, 0, 0));
221
222 // ListActivity has a ListView, which you can get with:
223 ExpandableListView lv = getExpandableListView();
224 lv.setOnChildClickListener(this);
225 // lv.setFastScrollEnabled(true);
226
227 // Then you can create a listener like so:
228 // lv.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener()
229 // {
230 // @Override
231 // public boolean onItemLongClick(AdapterView<?> av, View v, int pos, long id)
232 // {
233 // //onLongListItemClick(v, pos, id);
234 // //return true;
235 // }
236 //
237 // });
238
239 }
240
241 @Override
242 protected void onPause()
243 {
244 // Whenever this activity is paused (i.e. looses focus because another activity is started etc)
245 // Override how this activity is animated out of view
246 // The new activity is kept still and this activity is pushed out to the left
247 overridePendingTransition(R.anim.hold, R.anim.push_out_to_right);
248 super.onPause();
249 }
250
251 protected void onLongListItemClick(View v, int gpos, int pos2, long id)
252 {
253 // get the global resultposition from the result object
254 int pos = this.result_list.get(gpos + 1).get(pos2).getgpos();
255
256 Log.e("Navit", "long click id=" + id + " gpos=" + gpos + " pos=" + pos);
257 // remember what pos we clicked
258 this.selected_id_passthru = pos;
259
260 Intent search_intent = new Intent(this, NavitMapPreviewActivity.class);
261
262 if (Navit.use_index_search)
263 {
264 //Log.e("Navit", "long click lat=" + Navit.NavitAddressResultList_foundItems.get(pos).lat);
265 //Log.e("Navit", "long click lon=" + Navit.NavitAddressResultList_foundItems.get(pos).lon);
266 //Log.e("Navit", "long click lat=" + Navit.transform_to_geo_lat(Navit.NavitAddressResultList_foundItems.get(pos).lat));
267 //Log.e("Navit", "long click lon=" + Navit.transform_to_geo_lon(Navit.NavitAddressResultList_foundItems.get(pos).lon));
268 search_intent.putExtra("lat", (float) Navit.transform_to_geo_lat(Navit.NavitAddressResultList_foundItems.get(pos).lat));
269 search_intent.putExtra("lon", (float) Navit.transform_to_geo_lon(Navit.NavitAddressResultList_foundItems.get(pos).lon));
270 }
271 else
272 {
273 search_intent.putExtra("lat", Navit.NavitAddressResultList_foundItems.get(pos).lat);
274 search_intent.putExtra("lon", Navit.NavitAddressResultList_foundItems.get(pos).lon);
275 }
276 search_intent.putExtra("q", Navit.NavitAddressResultList_foundItems.get(pos).addr);
277 this.startActivityForResult(search_intent, Navit.NavitMapPreview_id);
278 }
279
280 protected void onActivityResult(int requestCode, int resultCode, Intent data)
281 {
282 switch (requestCode)
283 {
284 case Navit.NavitMapPreview_id:
285 try
286 {
287 if (resultCode == Activity.RESULT_OK)
288 {
289 Log.e("Navit", "*activity ready*");
290 int sel_id = Integer.parseInt(data.getStringExtra("selected_id"));
291 Log.e("Navit", "*activity ready* sel_id=" + sel_id);
292
293 if (sel_id == 1)
294 {
295 // user wants to set as destination
296 this.selected_id = this.selected_id_passthru;
297 // close this activity
298 executeDone("set");
299 }
300 else if (sel_id == 2)
301 {
302 // "back"
303 }
304 else if (sel_id == 3)
305 {
306 // show destination on map
307 this.selected_id = this.selected_id_passthru;
308 executeDone("view");
309 }
310 }
311 }
312 catch (Exception e)
313 {
314 e.printStackTrace();
315 }
316 }
317 }
318
319 @Override
320 public boolean onChildClick(ExpandableListView parent, View v, int groupPosition, int childPosition, long id)
321 {
322 // v.setBackgroundResource(R.color.background_material_dark);
323
324 onLongListItemClick(v, groupPosition, childPosition, id);
325 return true;
326 }
327
328 private void executeDone(String what)
329 {
330 Intent resultIntent = new Intent();
331 resultIntent.putExtra("selected_id", String.valueOf(this.selected_id));
332 if (what.equals("view"))
333 {
334 resultIntent.putExtra("what", "view");
335 }
336 else
337 {
338 resultIntent.putExtra("what", "-");
339 }
340 setResult(Activity.RESULT_OK, resultIntent);
341 finish();
342 }
343
344 }

   
Visit the ZANavi Wiki