… | |
… | |
48 | static int t_position = -1;
|
48 | static int t_position = -1;
|
49 | static int t_size = -1;
|
49 | static int t_size = -1;
|
50 | static Boolean refresh_items = false;
|
50 | static Boolean refresh_items = false;
|
51 | static NavitRecentDestinationActivity my = null;
|
51 | static NavitRecentDestinationActivity my = null;
|
52 | private static ArrayList<String> listview_items = new ArrayList<String>();
|
52 | private static ArrayList<String> listview_items = new ArrayList<String>();
|
|
|
53 | private static ArrayList<String> listview_addons = new ArrayList<String>();
|
53 |
|
54 |
|
54 | @Override
|
55 | @Override
|
55 | public void onCreate(Bundle savedInstanceState)
|
56 | public void onCreate(Bundle savedInstanceState)
|
56 | {
|
57 | {
|
57 | super.onCreate(savedInstanceState);
|
58 | super.onCreate(savedInstanceState);
|
58 | my = this;
|
59 | my = this;
|
59 |
|
60 |
|
60 | context_items = new String[] { Navit.get_text("delete Destination"), Navit.get_text("rename Destination") }; // TRANS
|
61 | context_items = new String[] { Navit.get_text("delete Destination"), Navit.get_text("rename Destination"), Navit.get_text("set as Home Location") }; // TRANS
|
61 |
|
62 |
|
62 | listview_items.clear();
|
63 | listview_items.clear();
|
|
|
64 | listview_addons.clear();
|
63 |
|
65 |
|
64 | // crash reported on google play store
|
66 | // crash reported on google play store
|
65 | // gueard against nullpointer
|
67 | // gueard against nullpointer
|
66 | if (Navit.map_points == null)
|
68 | if (Navit.map_points == null)
|
67 | {
|
69 | {
|
68 | Navit.map_points = new ArrayList<Navit_Point_on_Map>();
|
70 | Navit.map_points = new ArrayList<Navit_Point_on_Map>();
|
69 | }
|
71 | }
|
70 | // crash reported on google play store
|
72 | // crash reported on google play store
|
71 | // gueard against nullpointer
|
73 | // guard against nullpointer
|
72 |
|
74 |
|
73 | String[] t = new String[Navit.map_points.size()];
|
75 | String[] t = new String[Navit.map_points.size()];
|
|
|
76 | String[] t_addons = new String[Navit.map_points.size()];
|
74 | try
|
77 | try
|
75 | {
|
78 | {
|
76 | int j = 0;
|
79 | int j = 0;
|
77 | for (j = Navit.map_points.size() - 1; j >= 0; j--)
|
80 | for (j = Navit.map_points.size() - 1; j >= 0; j--)
|
78 | {
|
81 | {
|
79 | t[Navit.map_points.size() - j - 1] = Navit.map_points.get(j).point_name;
|
82 | t[Navit.map_points.size() - j - 1] = Navit.map_points.get(j).point_name;
|
|
|
83 | t_addons[Navit.map_points.size() - j - 1] = Navit.map_points.get(j).addon;
|
80 | }
|
84 | }
|
|
|
85 |
|
81 | for (j = 0; j < t.length; j++)
|
86 | for (j = 0; j < t.length; j++)
|
82 | {
|
87 | {
|
83 | listview_items.add(t[j]);
|
88 | listview_items.add(t[j]);
|
|
|
89 | listview_addons.add(t_addons[j]);
|
84 | }
|
90 | }
|
85 | }
|
91 | }
|
86 | catch (Exception e)
|
92 | catch (Exception e)
|
87 | {
|
93 | {
|
88 | e.printStackTrace();
|
94 | e.printStackTrace();
|
89 | t = new String[1];
|
95 | t = new String[1];
|
90 | t[0] = "* Error *";
|
96 | t[0] = "* Error *";
|
91 | listview_items.add(t[0]);
|
97 | listview_items.add(t[0]);
|
|
|
98 | listview_addons.add(null);
|
92 | }
|
99 | }
|
93 | NavitArrayAdapter adapter = new NavitArrayAdapter(this, listview_items);
|
100 | NavitArrayAdapter adapter = new NavitArrayAdapter(this, listview_items, listview_addons);
|
94 |
|
101 |
|
95 | //if (convertView == null)
|
102 | //if (convertView == null)
|
96 | //{
|
103 | //{
|
97 | // LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
|
104 | // LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
|
98 | // convertView = inflater.inflate(R.layout.search_result_list_header, null);
|
105 | // convertView = inflater.inflate(R.layout.search_result_list_header, null);
|
… | |
… | |
108 | {
|
115 | {
|
109 | public void handleMessage(Message msg)
|
116 | public void handleMessage(Message msg)
|
110 | {
|
117 | {
|
111 | if (msg.getData().getInt("what") == 1)
|
118 | if (msg.getData().getInt("what") == 1)
|
112 | {
|
119 | {
|
|
|
120 | int i = msg.getData().getInt("i");
|
113 | refresh_items_real();
|
121 | refresh_items_real(i);
|
114 | }
|
122 | }
|
115 | }
|
123 | }
|
116 | };
|
124 | };
|
117 |
|
125 |
|
118 | public static void refresh_items()
|
126 | public static void refresh_items(int i)
|
119 | {
|
127 | {
|
120 | Message msg = new Message();
|
128 | Message msg = new Message();
|
121 | Bundle b = new Bundle();
|
129 | Bundle b = new Bundle();
|
122 | b.putInt("what", 1);
|
130 | b.putInt("what", 1);
|
|
|
131 | b.putInt("i", i);
|
123 | msg.setData(b);
|
132 | msg.setData(b);
|
124 | handler1.sendMessage(msg);
|
133 | handler1.sendMessage(msg);
|
125 | }
|
134 | }
|
126 |
|
135 |
|
127 | public static void refresh_items_real()
|
136 | public static void refresh_items_real(int i)
|
128 | {
|
137 | {
|
129 | String[] t = new String[Navit.map_points.size()];
|
138 | String[] t = new String[Navit.map_points.size()];
|
|
|
139 | String[] t_addons = new String[Navit.map_points.size()];
|
130 | NavitArrayAdapter adapter = (NavitArrayAdapter) my.getListAdapter();
|
140 | NavitArrayAdapter adapter = (NavitArrayAdapter) my.getListAdapter();
|
131 | listview_items.clear();
|
141 | listview_items.clear();
|
|
|
142 | listview_addons.clear();
|
132 | adapter.notifyDataSetChanged();
|
143 | adapter.notifyDataSetChanged();
|
133 | try
|
144 | try
|
134 | {
|
145 | {
|
135 | int j = 0;
|
146 | int j = 0;
|
136 | for (j = Navit.map_points.size() - 1; j >= 0; j--)
|
147 | for (j = Navit.map_points.size() - 1; j >= 0; j--)
|
137 | {
|
148 | {
|
138 | t[Navit.map_points.size() - j - 1] = Navit.map_points.get(j).point_name;
|
149 | t[Navit.map_points.size() - j - 1] = Navit.map_points.get(j).point_name;
|
|
|
150 | t_addons[Navit.map_points.size() - j - 1] = Navit.map_points.get(j).addon;
|
|
|
151 | // System.out.println("name=" + Navit.map_points.get(j).point_name + " addon=" + Navit.map_points.get(j).addon);
|
139 | }
|
152 | }
|
140 | for (j = 0; j < t.length; j++)
|
153 | for (j = 0; j < t.length; j++)
|
141 | {
|
154 | {
|
142 | listview_items.add(t[j]);
|
155 | listview_items.add(t[j]);
|
|
|
156 | listview_addons.add(t_addons[j]);
|
143 | }
|
157 | }
|
144 | }
|
158 | }
|
145 | catch (Exception e)
|
159 | catch (Exception e)
|
146 | {
|
160 | {
|
147 | e.printStackTrace();
|
161 | e.printStackTrace();
|
148 | t = new String[1];
|
162 | t = new String[1];
|
149 | t[0] = "* Error *";
|
163 | t[0] = "* Error *";
|
150 | listview_items.add(t[0]);
|
164 | listview_items.add(t[0]);
|
|
|
165 | listview_addons.add(null);
|
151 | }
|
166 | }
|
152 | adapter.notifyDataSetChanged();
|
167 | adapter.notifyDataSetChanged();
|
153 | refresh_items = false;
|
168 | refresh_items = false;
|
154 | }
|
169 | }
|
155 |
|
170 |
|
… | |
… | |
188 | Navit.map_points.remove(t_size - t_position - 1);
|
203 | Navit.map_points.remove(t_size - t_position - 1);
|
189 | // save it
|
204 | // save it
|
190 | Navit.write_map_points();
|
205 | Navit.write_map_points();
|
191 | // refresh
|
206 | // refresh
|
192 | refresh_items = true;
|
207 | refresh_items = true;
|
193 | refresh_items();
|
208 | refresh_items(1);
|
194 | break;
|
209 | break;
|
195 | case 1:
|
210 | case 1:
|
196 | // rename item
|
211 | // rename item
|
197 | NavitRecentDestinationActivity.t = Navit.map_points.get(t_size - t_position - 1);
|
212 | NavitRecentDestinationActivity.t = Navit.map_points.get(t_size - t_position - 1);
|
198 | String title = Navit.get_text("Rename Destination"); //TRANS
|
213 | String title = Navit.get_text("Rename Destination"); //TRANS
|
… | |
… | |
206 | System.out.println("new=" + newname);
|
221 | System.out.println("new=" + newname);
|
207 | // save it
|
222 | // save it
|
208 | Navit.write_map_points();
|
223 | Navit.write_map_points();
|
209 | // refresh
|
224 | // refresh
|
210 | refresh_items = true;
|
225 | refresh_items = true;
|
211 | refresh_items();
|
226 | refresh_items(0);
|
212 | }
|
227 | }
|
213 | }
|
228 | }
|
214 |
|
229 |
|
215 | );
|
230 | );
|
216 | rd.show();
|
231 | rd.show();
|
|
|
232 | break;
|
|
|
233 | case 2:
|
|
|
234 | // find old HOME item
|
|
|
235 | int old_home_id = Navit.find_home_point();
|
|
|
236 | if (old_home_id != -1)
|
|
|
237 | {
|
|
|
238 | NavitRecentDestinationActivity.t = Navit.map_points.get(old_home_id);
|
|
|
239 | NavitRecentDestinationActivity.t.addon = null;
|
|
|
240 | Navit.map_points.set(old_home_id, NavitRecentDestinationActivity.t);
|
|
|
241 | }
|
|
|
242 | // in case of double home, because of some strange error
|
|
|
243 | old_home_id = Navit.find_home_point();
|
|
|
244 | if (old_home_id != -1)
|
|
|
245 | {
|
|
|
246 | NavitRecentDestinationActivity.t = Navit.map_points.get(old_home_id);
|
|
|
247 | NavitRecentDestinationActivity.t.addon = null;
|
|
|
248 | Navit.map_points.set(old_home_id, NavitRecentDestinationActivity.t);
|
|
|
249 | }
|
|
|
250 | // in case of double home, because of some strange error
|
|
|
251 | old_home_id = Navit.find_home_point();
|
|
|
252 | if (old_home_id != -1)
|
|
|
253 | {
|
|
|
254 | NavitRecentDestinationActivity.t = Navit.map_points.get(old_home_id);
|
|
|
255 | NavitRecentDestinationActivity.t.addon = null;
|
|
|
256 | Navit.map_points.set(old_home_id, NavitRecentDestinationActivity.t);
|
|
|
257 | }
|
|
|
258 |
|
|
|
259 | // set HOME item
|
|
|
260 | NavitRecentDestinationActivity.t = Navit.map_points.get(t_size - t_position - 1);
|
|
|
261 | NavitRecentDestinationActivity.t.addon = "1";
|
|
|
262 | // delete item
|
|
|
263 | Navit.map_points.remove(t_size - t_position - 1);
|
|
|
264 | // add it to the first position
|
|
|
265 | Navit.map_points.add(NavitRecentDestinationActivity.t);
|
|
|
266 | // save it
|
|
|
267 | Navit.write_map_points();
|
|
|
268 | // refresh
|
|
|
269 | refresh_items = true;
|
|
|
270 | refresh_items(0);
|
217 | break;
|
271 | break;
|
218 | }
|
272 | }
|
219 | return true;
|
273 | return true;
|
220 | }
|
274 | }
|
221 |
|
275 |
|