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