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