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 android.app.Activity;
|
42 |
import android.content.Intent;
|
43 |
import android.os.Bundle;
|
44 |
import android.util.TypedValue;
|
45 |
import android.view.Gravity;
|
46 |
import android.view.View;
|
47 |
import android.view.View.OnClickListener;
|
48 |
import android.view.WindowManager;
|
49 |
import android.widget.Button;
|
50 |
import android.widget.CheckBox;
|
51 |
import android.widget.CompoundButton;
|
52 |
import android.widget.CompoundButton.OnCheckedChangeListener;
|
53 |
import android.widget.EditText;
|
54 |
import android.widget.LinearLayout;
|
55 |
import android.widget.RelativeLayout.LayoutParams;
|
56 |
import android.widget.ScrollView;
|
57 |
import android.widget.TextView;
|
58 |
|
59 |
public class NavitAddressSearchActivity extends Activity
|
60 |
{
|
61 |
private EditText address_string;
|
62 |
private EditText hn_string;
|
63 |
private CheckBox pm_checkbox;
|
64 |
private CheckBox hdup_checkbox;
|
65 |
private CheckBox ff_checkbox;
|
66 |
private String search_type;
|
67 |
private int search_country_id = 0;
|
68 |
private Button search_country_select;
|
69 |
|
70 |
// public RelativeLayout NavitAddressSearchActivity_layout;
|
71 |
|
72 |
@Override
|
73 |
protected void onCreate(Bundle savedInstanceState)
|
74 |
{
|
75 |
super.onCreate(savedInstanceState);
|
76 |
|
77 |
getWindow().setFlags(WindowManager.LayoutParams.FLAG_BLUR_BEHIND, WindowManager.LayoutParams.FLAG_BLUR_BEHIND);
|
78 |
|
79 |
// scrollview
|
80 |
ScrollView sv = new ScrollView(this);
|
81 |
sv.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
|
82 |
|
83 |
// panel linearlayout
|
84 |
LinearLayout panel = new LinearLayout(this);
|
85 |
panel.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));
|
86 |
panel.setOrientation(LinearLayout.VERTICAL);
|
87 |
|
88 |
// address: label and text field
|
89 |
TextView addr_view = new TextView(this);
|
90 |
addr_view.setText(Navit.get_text("Enter Destination")); //TRANS
|
91 |
addr_view.setTextSize(TypedValue.COMPLEX_UNIT_SP, 20f);
|
92 |
addr_view.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
|
93 |
addr_view.setPadding(4, 4, 4, 4);
|
94 |
|
95 |
// address: label and text field
|
96 |
TextView addrhn_view = new TextView(this);
|
97 |
addrhn_view.setText(Navit.get_text("Housenumber")); //TRANS
|
98 |
addrhn_view.setTextSize(TypedValue.COMPLEX_UNIT_SP, 20f);
|
99 |
addrhn_view.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
|
100 |
addrhn_view.setPadding(4, 4, 4, 4);
|
101 |
|
102 |
// partial match checkbox
|
103 |
pm_checkbox = new CheckBox(this);
|
104 |
pm_checkbox.setText(Navit.get_text("partial match")); //TRANS
|
105 |
pm_checkbox.setChecked(false);
|
106 |
pm_checkbox.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT));
|
107 |
pm_checkbox.setGravity(Gravity.CENTER);
|
108 |
|
109 |
// partial match checkbox
|
110 |
hdup_checkbox = new CheckBox(this);
|
111 |
hdup_checkbox.setText(Navit.get_text("hide duplicates")); //TRANS
|
112 |
hdup_checkbox.setChecked(true);
|
113 |
hdup_checkbox.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT));
|
114 |
hdup_checkbox.setGravity(Gravity.CENTER);
|
115 |
|
116 |
// full file checkbox
|
117 |
ff_checkbox = new CheckBox(this);
|
118 |
if (!Navit.use_index_search)
|
119 |
{
|
120 |
ff_checkbox.setText(Navit.get_text("search full mapfile [BETA]")); //TRANS
|
121 |
ff_checkbox.setChecked(false);
|
122 |
ff_checkbox.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT));
|
123 |
ff_checkbox.setGravity(Gravity.CENTER);
|
124 |
|
125 |
ff_checkbox.setOnCheckedChangeListener(new OnCheckedChangeListener()
|
126 |
{
|
127 |
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked)
|
128 |
{
|
129 |
if (isChecked)
|
130 |
{
|
131 |
try
|
132 |
{
|
133 |
search_country_select.setVisibility(View.INVISIBLE);
|
134 |
hdup_checkbox.setVisibility(View.INVISIBLE);
|
135 |
}
|
136 |
catch (Exception e)
|
137 |
{
|
138 |
|
139 |
}
|
140 |
}
|
141 |
else
|
142 |
{
|
143 |
try
|
144 |
{
|
145 |
search_country_select.setVisibility(View.VISIBLE);
|
146 |
hdup_checkbox.setVisibility(View.VISIBLE);
|
147 |
}
|
148 |
catch (Exception e)
|
149 |
{
|
150 |
|
151 |
}
|
152 |
}
|
153 |
}
|
154 |
});
|
155 |
}
|
156 |
// search button
|
157 |
final Button btnSearch = new Button(this);
|
158 |
btnSearch.setText(Navit.get_text("Search")); //TRANS
|
159 |
btnSearch.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT));
|
160 |
btnSearch.setGravity(Gravity.CENTER);
|
161 |
btnSearch.setOnClickListener(new OnClickListener()
|
162 |
{
|
163 |
public void onClick(View v)
|
164 |
{
|
165 |
executeDone();
|
166 |
}
|
167 |
});
|
168 |
|
169 |
this.search_type = getIntent().getExtras().getString("type");
|
170 |
if (this.search_type.endsWith("offline"))
|
171 |
{
|
172 |
this.search_country_id = getIntent().getExtras().getInt("search_country_id");
|
173 |
}
|
174 |
|
175 |
// select country button
|
176 |
search_country_select = new Button(this);
|
177 |
if (!Navit.use_index_search)
|
178 |
{
|
179 |
|
180 |
search_country_select.setText(NavitAddressSearchCountrySelectActivity.CountryList_Human[search_country_id][2]);
|
181 |
search_country_select.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT));
|
182 |
search_country_select.setGravity(Gravity.CENTER);
|
183 |
search_country_select.setOnClickListener(new View.OnClickListener()
|
184 |
{
|
185 |
public void onClick(View v)
|
186 |
{
|
187 |
start_country_select_form();
|
188 |
}
|
189 |
});
|
190 |
}
|
191 |
|
192 |
// title
|
193 |
try
|
194 |
{
|
195 |
String s = getIntent().getExtras().getString("title");
|
196 |
if (s.length() > 0)
|
197 |
{
|
198 |
this.setTitle(s);
|
199 |
}
|
200 |
}
|
201 |
catch (Exception e)
|
202 |
{
|
203 |
}
|
204 |
|
205 |
// partial match
|
206 |
try
|
207 |
{
|
208 |
String s = getIntent().getExtras().getString("partial_match");
|
209 |
if (s.length() > 0)
|
210 |
{
|
211 |
if (s.equals("1"))
|
212 |
{
|
213 |
pm_checkbox.setChecked(true);
|
214 |
}
|
215 |
else
|
216 |
{
|
217 |
pm_checkbox.setChecked(false);
|
218 |
}
|
219 |
}
|
220 |
}
|
221 |
catch (Exception e)
|
222 |
{
|
223 |
}
|
224 |
|
225 |
if (Navit.use_index_search)
|
226 |
{
|
227 |
|
228 |
// house number string
|
229 |
try
|
230 |
{
|
231 |
hn_string = new EditText(this);
|
232 |
hn_string.setText(getIntent().getExtras().getString("hn_string"));
|
233 |
}
|
234 |
catch (Exception e)
|
235 |
{
|
236 |
}
|
237 |
}
|
238 |
|
239 |
// address string
|
240 |
try
|
241 |
{
|
242 |
address_string = new EditText(this);
|
243 |
address_string.setText(getIntent().getExtras().getString("address_string"));
|
244 |
}
|
245 |
catch (Exception e)
|
246 |
{
|
247 |
}
|
248 |
|
249 |
// actually adding the views (that have layout set on them) to the panel
|
250 |
panel.addView(addr_view);
|
251 |
panel.addView(address_string);
|
252 |
if (this.search_type.equals("offline"))
|
253 |
{
|
254 |
if (Navit.use_index_search)
|
255 |
{
|
256 |
panel.addView(addrhn_view);
|
257 |
panel.addView(hn_string);
|
258 |
}
|
259 |
if (!Navit.use_index_search)
|
260 |
{
|
261 |
panel.addView(search_country_select);
|
262 |
}
|
263 |
panel.addView(pm_checkbox);
|
264 |
panel.addView(hdup_checkbox);
|
265 |
if (!Navit.use_index_search)
|
266 |
{
|
267 |
panel.addView(ff_checkbox);
|
268 |
}
|
269 |
}
|
270 |
panel.addView(btnSearch);
|
271 |
|
272 |
sv.addView(panel);
|
273 |
|
274 |
// set the main view
|
275 |
setContentView(sv);
|
276 |
}
|
277 |
|
278 |
public void start_country_select_form()
|
279 |
{
|
280 |
Intent search_intent = new Intent(this, NavitAddressSearchCountrySelectActivity.class);
|
281 |
this.startActivityForResult(search_intent, Navit.NavitAddressSearchCountry_id);
|
282 |
}
|
283 |
|
284 |
protected void onActivityResult(int requestCode, int resultCode, Intent data)
|
285 |
{
|
286 |
switch (requestCode)
|
287 |
{
|
288 |
case Navit.NavitAddressSearchCountry_id:
|
289 |
try
|
290 |
{
|
291 |
if (resultCode == Activity.RESULT_OK)
|
292 |
{
|
293 |
search_country_id = Integer.parseInt(data.getStringExtra("selected_id"));
|
294 |
// System.out.println("search_country_id=" + search_country_id);
|
295 |
search_country_select.setText(NavitAddressSearchCountrySelectActivity.CountryList_Human[search_country_id][2]);
|
296 |
}
|
297 |
}
|
298 |
catch (Exception e)
|
299 |
{
|
300 |
|
301 |
}
|
302 |
}
|
303 |
}
|
304 |
|
305 |
private void executeDone()
|
306 |
{
|
307 |
Intent resultIntent = new Intent();
|
308 |
resultIntent.putExtra("address_string", NavitAddressSearchActivity.this.address_string.getText().toString());
|
309 |
|
310 |
if (this.search_type.endsWith("offline"))
|
311 |
{
|
312 |
if (Navit.use_index_search)
|
313 |
{
|
314 |
resultIntent.putExtra("hn_string", NavitAddressSearchActivity.this.hn_string.getText().toString());
|
315 |
}
|
316 |
|
317 |
if (NavitAddressSearchActivity.this.pm_checkbox.isChecked())
|
318 |
{
|
319 |
resultIntent.putExtra("partial_match", "1");
|
320 |
}
|
321 |
else
|
322 |
{
|
323 |
resultIntent.putExtra("partial_match", "0");
|
324 |
}
|
325 |
|
326 |
if (NavitAddressSearchActivity.this.hdup_checkbox.isChecked())
|
327 |
{
|
328 |
resultIntent.putExtra("hide_dup", "1");
|
329 |
}
|
330 |
else
|
331 |
{
|
332 |
resultIntent.putExtra("hide_dup", "0");
|
333 |
}
|
334 |
|
335 |
try
|
336 |
{
|
337 |
if (NavitAddressSearchActivity.this.ff_checkbox.isChecked())
|
338 |
{
|
339 |
resultIntent.putExtra("full_file_search", "1");
|
340 |
}
|
341 |
else
|
342 |
{
|
343 |
resultIntent.putExtra("full_file_search", "0");
|
344 |
}
|
345 |
}
|
346 |
catch (Exception e)
|
347 |
{
|
348 |
// on error assume its turned off
|
349 |
resultIntent.putExtra("full_file_search", "0");
|
350 |
}
|
351 |
|
352 |
try
|
353 |
{
|
354 |
resultIntent.putExtra("address_country_iso2", NavitAddressSearchCountrySelectActivity.CountryList_Human[search_country_id][0]);
|
355 |
resultIntent.putExtra("search_country_id", search_country_id);
|
356 |
if (NavitAddressSearchCountrySelectActivity.CountryList_Human[search_country_id][0].equals("*D"))
|
357 |
{
|
358 |
resultIntent.putExtra("address_country_flags", 1);
|
359 |
}
|
360 |
else if (NavitAddressSearchCountrySelectActivity.CountryList_Human[search_country_id][0].equals("*A"))
|
361 |
{
|
362 |
resultIntent.putExtra("address_country_flags", 3);
|
363 |
}
|
364 |
else
|
365 |
{
|
366 |
resultIntent.putExtra("address_country_flags", 2);
|
367 |
}
|
368 |
}
|
369 |
catch (Exception e)
|
370 |
{
|
371 |
// index search
|
372 |
resultIntent.putExtra("address_country_iso2", "X");
|
373 |
resultIntent.putExtra("search_country_id", 0);
|
374 |
resultIntent.putExtra("address_country_flags", 2);
|
375 |
}
|
376 |
}
|
377 |
|
378 |
setResult(Activity.RESULT_OK, resultIntent);
|
379 |
finish();
|
380 |
}
|
381 |
}
|