1 |
/**
|
2 |
* aagtl Advanced Geocaching Tool for Android
|
3 |
* loosely based on agtl by Daniel Fett <fett@danielfett.de>
|
4 |
* Copyright (C) 2010 - 2012 Zoff <aagtl@work.zoff.cc>
|
5 |
*
|
6 |
* This program is free software; you can redistribute it and/or
|
7 |
* modify it under the terms of the GNU General Public License
|
8 |
* version 2 as published by the Free Software Foundation.
|
9 |
*
|
10 |
* This program is distributed in the hope that it will be useful,
|
11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
13 |
* GNU General Public License for more details.
|
14 |
*
|
15 |
* You should have received a copy of the GNU General Public License
|
16 |
* along with this program; if not, write to the
|
17 |
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
18 |
* Boston, MA 02110-1301, USA.
|
19 |
*/
|
20 |
|
21 |
package com.zoffcc.applications.aagtl;
|
22 |
|
23 |
import android.content.Context;
|
24 |
import android.graphics.Canvas;
|
25 |
import android.graphics.Color;
|
26 |
import android.graphics.Paint;
|
27 |
import android.os.Bundle;
|
28 |
import android.os.Handler;
|
29 |
import android.os.Message;
|
30 |
import android.text.Html;
|
31 |
import android.view.View;
|
32 |
import android.widget.ImageView;
|
33 |
|
34 |
public class GCacheView extends ImageView
|
35 |
{
|
36 |
|
37 |
GeocacheCoordinate gc = null;
|
38 |
|
39 |
Paint box_paint = new Paint(0);
|
40 |
Paint text_paint = new Paint(0);
|
41 |
|
42 |
int details_loaded = 0;
|
43 |
String gc_name_current = "";
|
44 |
String gc_name_previous = "";
|
45 |
int get_gc_from_db = 0;
|
46 |
|
47 |
Boolean need_repaint = true;
|
48 |
Boolean override_download = false;
|
49 |
|
50 |
public Boolean download_details_thread_finished = false;
|
51 |
|
52 |
public static final int SHOW_DESC = 1;
|
53 |
public static final int SHOW_SHORT_DESC = 2;
|
54 |
public static final int SHOW_LOGS = 3;
|
55 |
public static final int SHOW_HINTS = 4;
|
56 |
public static final int SHOW_WAYPOINTS = 5;
|
57 |
|
58 |
public int show_field = SHOW_SHORT_DESC;
|
59 |
|
60 |
aagtl main_aagtl;
|
61 |
|
62 |
public GCacheView(Context context, aagtl main_aagtl)
|
63 |
{
|
64 |
super(context);
|
65 |
|
66 |
text_paint.setColor(Color.WHITE);
|
67 |
// text_paint.setStyle(Paint.Style.FILL);
|
68 |
text_paint.setTextSize(16 * aagtl.Global_dpi_factor);
|
69 |
// text_paint.setTypeface(Typeface.DEFAULT_BOLD);
|
70 |
text_paint.setAntiAlias(true);
|
71 |
|
72 |
this.main_aagtl = main_aagtl;
|
73 |
this.clear_stuff();
|
74 |
}
|
75 |
|
76 |
public void set_cache(GeocacheCoordinate co)
|
77 |
{
|
78 |
// System.out.println("in set_cache");
|
79 |
|
80 |
need_repaint = true;
|
81 |
|
82 |
try
|
83 |
{
|
84 |
this.gc_name_previous = gc.name;
|
85 |
// System.out.println("" + String.valueOf(this.gc.name));
|
86 |
}
|
87 |
catch (NullPointerException e)
|
88 |
{
|
89 |
this.gc_name_previous = "";
|
90 |
// System.out.println("null");
|
91 |
}
|
92 |
|
93 |
this.gc_name_current = co.name;
|
94 |
|
95 |
// System.out.println("cur=" + this.gc_name_current + " prev=" +
|
96 |
// this.gc_name_previous);
|
97 |
if (!this.gc_name_current.matches(this.gc_name_previous))
|
98 |
{
|
99 |
// System.out.println("details_loaded = 0");
|
100 |
this.details_loaded = 0;
|
101 |
// take new GC as cache-to-view
|
102 |
this.gc = co;
|
103 |
// set field back to shortdesc.
|
104 |
show_field = GCacheView.SHOW_SHORT_DESC;
|
105 |
}
|
106 |
|
107 |
// System.out.println("" + String.valueOf(this.gc.name));
|
108 |
}
|
109 |
|
110 |
public GeocacheCoordinate get_cache()
|
111 |
{
|
112 |
return this.gc;
|
113 |
}
|
114 |
|
115 |
private class Thread_gcv1 extends Thread
|
116 |
{
|
117 |
Handler mHandler;
|
118 |
Boolean do_close = false;
|
119 |
|
120 |
Thread_gcv1(Handler h)
|
121 |
{
|
122 |
mHandler = h;
|
123 |
}
|
124 |
|
125 |
public void close_dialog()
|
126 |
{
|
127 |
this.do_close = true;
|
128 |
}
|
129 |
|
130 |
public void run()
|
131 |
{
|
132 |
// System.out.println("thread xx started");
|
133 |
Message msg = mHandler.obtainMessage();
|
134 |
Bundle b = new Bundle();
|
135 |
b.putInt("command", 0);
|
136 |
msg.setData(b);
|
137 |
mHandler.sendMessage(msg);
|
138 |
while (!do_close)
|
139 |
{
|
140 |
try
|
141 |
{
|
142 |
Thread.sleep(100);
|
143 |
}
|
144 |
catch (InterruptedException e)
|
145 |
{
|
146 |
this.do_close = true;
|
147 |
}
|
148 |
}
|
149 |
// System.out.println("thread xx finished");
|
150 |
msg = mHandler.obtainMessage();
|
151 |
b = new Bundle();
|
152 |
b.putInt("command", 1);
|
153 |
msg.setData(b);
|
154 |
mHandler.sendMessage(msg);
|
155 |
}
|
156 |
}
|
157 |
|
158 |
private class Thread_gcv2 extends Thread
|
159 |
{
|
160 |
GCacheView main = null;
|
161 |
|
162 |
Thread_gcv2(GCacheView main_ref)
|
163 |
{
|
164 |
this.main = main_ref;
|
165 |
}
|
166 |
|
167 |
public void run()
|
168 |
{
|
169 |
Thread_gcv1 t1 = new Thread_gcv1(this.main.main_aagtl.dl_handler);
|
170 |
t1.start();
|
171 |
|
172 |
// System.out.println("thread yy started");
|
173 |
this.main.main_aagtl.cdol.update_coordinate(this.main.gc);
|
174 |
// System.out.println("thread yy finished");
|
175 |
this.main.download_details_thread_finished = true;
|
176 |
this.main.details_loaded = 2;
|
177 |
Message msg = this.main.main_aagtl.dl_handler.obtainMessage();
|
178 |
Bundle b = new Bundle();
|
179 |
b.putInt("command", 2);
|
180 |
msg.setData(b);
|
181 |
this.main.main_aagtl.dl_handler.sendMessage(msg);
|
182 |
|
183 |
t1.close_dialog();
|
184 |
}
|
185 |
}
|
186 |
|
187 |
public void onDraw(Canvas c)
|
188 |
{
|
189 |
// System.out.println("GCacheView: onDraw");
|
190 |
|
191 |
if (this.gc == null)
|
192 |
{
|
193 |
c.drawColor(Color.RED);
|
194 |
}
|
195 |
else
|
196 |
{
|
197 |
try
|
198 |
{
|
199 |
c.drawColor(Color.BLACK);
|
200 |
c.drawText(gc.name, 10 * aagtl.Global_dpi_factor, 50 * aagtl.Global_dpi_factor, text_paint);
|
201 |
c.drawText(gc.title, 10 * aagtl.Global_dpi_factor, 50 * aagtl.Global_dpi_factor + 30 * aagtl.Global_dpi_factor, text_paint);
|
202 |
c.drawText(gc.type, 10 * aagtl.Global_dpi_factor, 50 * aagtl.Global_dpi_factor + 2 * 30 * aagtl.Global_dpi_factor, text_paint);
|
203 |
c.drawText("size: " + String.valueOf(gc.size), 10 * aagtl.Global_dpi_factor, 50 * aagtl.Global_dpi_factor + 3 * 30 * aagtl.Global_dpi_factor, text_paint);
|
204 |
c.drawText("terrain: " + String.valueOf(gc.terrain), 10 * aagtl.Global_dpi_factor, 50 * aagtl.Global_dpi_factor + 4 * 30 * aagtl.Global_dpi_factor, text_paint);
|
205 |
|
206 |
if (this.get_gc_from_db == 1)
|
207 |
{
|
208 |
// check in db for cache details
|
209 |
c.drawText("checking database ...", 10 * aagtl.Global_dpi_factor, 50 * aagtl.Global_dpi_factor + 6 * 30 * aagtl.Global_dpi_factor, text_paint);
|
210 |
this.gc = this.main_aagtl.pv.get_point_full(this.gc.name);
|
211 |
System.out.println("checking database");
|
212 |
System.out.println("DESC=" + this.gc.desc);
|
213 |
if (this.gc.desc == null)
|
214 |
{
|
215 |
this.gc.desc = "please update details";
|
216 |
}
|
217 |
this.get_gc_from_db = 0;
|
218 |
}
|
219 |
|
220 |
if (this.details_loaded == 0)
|
221 |
{
|
222 |
if (!this.override_download)
|
223 |
{
|
224 |
// check in db for cache details
|
225 |
c.drawText("checking database ...", 10 * aagtl.Global_dpi_factor, 50 * aagtl.Global_dpi_factor + 6 * 30 * aagtl.Global_dpi_factor, text_paint);
|
226 |
this.gc = this.main_aagtl.pv.get_point_full(this.gc.name);
|
227 |
System.out.println("checking database");
|
228 |
System.out.println("DESC=" + this.gc.desc);
|
229 |
}
|
230 |
else
|
231 |
{
|
232 |
// ok override, and download from internet.
|
233 |
// set option back, this is a 1-shot option!
|
234 |
System.out.println("here 001");
|
235 |
this.override_download = false;
|
236 |
// make sure we download it!
|
237 |
this.gc.desc = null;
|
238 |
}
|
239 |
|
240 |
if (this.gc.desc == null)
|
241 |
{
|
242 |
// download from internet (in background thread)
|
243 |
c.drawColor(Color.BLACK);
|
244 |
|
245 |
c.drawText(gc.name, 10 * aagtl.Global_dpi_factor, 50 * aagtl.Global_dpi_factor, text_paint);
|
246 |
c.drawText(gc.title, 10 * aagtl.Global_dpi_factor, 50 * aagtl.Global_dpi_factor + 30 * aagtl.Global_dpi_factor, text_paint);
|
247 |
c.drawText(gc.type, 10 * aagtl.Global_dpi_factor, 50 * aagtl.Global_dpi_factor + 2 * 30 * aagtl.Global_dpi_factor, text_paint);
|
248 |
c.drawText("size: " + String.valueOf(gc.size), 10 * aagtl.Global_dpi_factor, 50 * aagtl.Global_dpi_factor + 3 * 30 * aagtl.Global_dpi_factor, text_paint);
|
249 |
c.drawText("terrain: " + String.valueOf(gc.terrain), 10 * aagtl.Global_dpi_factor, 50 * aagtl.Global_dpi_factor + 4 * 30 * aagtl.Global_dpi_factor, text_paint);
|
250 |
|
251 |
c.drawText("downloading ...", 10 * aagtl.Global_dpi_factor, 50 * aagtl.Global_dpi_factor + 6 * 30 * aagtl.Global_dpi_factor, text_paint);
|
252 |
|
253 |
// System.out.println("downloading from internet");
|
254 |
this.download_details_thread_finished = false;
|
255 |
this.details_loaded = 1;
|
256 |
Thread_gcv2 t2 = new Thread_gcv2(this);
|
257 |
t2.start();
|
258 |
|
259 |
need_repaint = true;
|
260 |
}
|
261 |
else
|
262 |
{
|
263 |
// ok found something in DB
|
264 |
this.download_details_thread_finished = true;
|
265 |
this.details_loaded = 2;
|
266 |
|
267 |
need_repaint = true;
|
268 |
}
|
269 |
|
270 |
}
|
271 |
else if (this.details_loaded == 1)
|
272 |
{
|
273 |
c.drawColor(Color.BLACK);
|
274 |
c.drawText(gc.name, 10 * aagtl.Global_dpi_factor, 50 * aagtl.Global_dpi_factor, text_paint);
|
275 |
c.drawText(gc.title, 10 * aagtl.Global_dpi_factor, 50 * aagtl.Global_dpi_factor + 30 * aagtl.Global_dpi_factor, text_paint);
|
276 |
c.drawText(gc.type, 10 * aagtl.Global_dpi_factor, 50 * aagtl.Global_dpi_factor + 2 * 30 * aagtl.Global_dpi_factor, text_paint);
|
277 |
c.drawText("size: " + String.valueOf(gc.size), 10 * aagtl.Global_dpi_factor, 50 * aagtl.Global_dpi_factor + 3 * 30 * aagtl.Global_dpi_factor, text_paint);
|
278 |
c.drawText("status: " + String.valueOf(GeocacheCoordinate.STATUS_HASH.get(gc.status)), 150, 50 + 3 * 30, text_paint);
|
279 |
c.drawText("diff: " + String.valueOf((float) gc.difficulty / 10f), 10 * aagtl.Global_dpi_factor, 50 * aagtl.Global_dpi_factor + 4 * 30 * aagtl.Global_dpi_factor, text_paint);
|
280 |
c.drawText("terrain: " + String.valueOf((float) gc.terrain / 10f), 10 * aagtl.Global_dpi_factor, 50 * aagtl.Global_dpi_factor + 5 * 30 * aagtl.Global_dpi_factor, text_paint);
|
281 |
|
282 |
c.drawText("downloading ...", 10 * aagtl.Global_dpi_factor, 50 * aagtl.Global_dpi_factor + 6 * 30 * aagtl.Global_dpi_factor, text_paint);
|
283 |
}
|
284 |
|
285 |
if (this.details_loaded == 2)
|
286 |
{
|
287 |
if (!need_repaint) // &&
|
288 |
// (this.gc_name_current.matches(this.gc_name_previous)))
|
289 |
{
|
290 |
// dont repaint all the time
|
291 |
return;
|
292 |
}
|
293 |
|
294 |
need_repaint = false;
|
295 |
c.drawColor(Color.BLACK);
|
296 |
c.drawText(gc.name, 10 * aagtl.Global_dpi_factor, 50 * aagtl.Global_dpi_factor, text_paint);
|
297 |
c.drawText(gc.title, 10 * aagtl.Global_dpi_factor, 50 * aagtl.Global_dpi_factor + 30 * aagtl.Global_dpi_factor, text_paint);
|
298 |
c.drawText(gc.type, 10 * aagtl.Global_dpi_factor, 50 * aagtl.Global_dpi_factor + 2 * 30 * aagtl.Global_dpi_factor, text_paint);
|
299 |
c.drawText("size: " + String.valueOf(gc.size), 10 * aagtl.Global_dpi_factor, 50 * aagtl.Global_dpi_factor + 3 * 30 * aagtl.Global_dpi_factor, text_paint);
|
300 |
c.drawText("status: " + String.valueOf(GeocacheCoordinate.STATUS_HASH.get(gc.status)), 150 * aagtl.Global_dpi_factor, 50 * aagtl.Global_dpi_factor + 3 * 30 * aagtl.Global_dpi_factor, text_paint);
|
301 |
c.drawText("diff: " + String.valueOf((float) gc.difficulty / 10f), 10 * aagtl.Global_dpi_factor, 50 * aagtl.Global_dpi_factor + 4 * 30 * aagtl.Global_dpi_factor, text_paint);
|
302 |
c.drawText("terrain: " + String.valueOf((float) gc.terrain / 10f), 10 * aagtl.Global_dpi_factor, 50 * aagtl.Global_dpi_factor + 5 * 30 * aagtl.Global_dpi_factor, text_paint);
|
303 |
|
304 |
// c.drawText("details loaded", 10, 50 + 6 * 30, text_paint);
|
305 |
c.drawText("", 10 * aagtl.Global_dpi_factor, 50 * aagtl.Global_dpi_factor + 6 * 30 * aagtl.Global_dpi_factor, text_paint);
|
306 |
|
307 |
String show_field_text = this.gc.shortdesc;
|
308 |
switch (this.show_field)
|
309 |
{
|
310 |
case GCacheView.SHOW_SHORT_DESC:
|
311 |
// already set above, as default. dont set again
|
312 |
// show_field_text = this.gc.shortdesc;
|
313 |
break;
|
314 |
case GCacheView.SHOW_DESC:
|
315 |
show_field_text = this.gc.desc;
|
316 |
break;
|
317 |
case GCacheView.SHOW_LOGS:
|
318 |
show_field_text = this.gc.logs;
|
319 |
break;
|
320 |
case GCacheView.SHOW_HINTS:
|
321 |
show_field_text = this.gc.hints;
|
322 |
break;
|
323 |
case GCacheView.SHOW_WAYPOINTS:
|
324 |
show_field_text = this.gc.waypoints;
|
325 |
break;
|
326 |
}
|
327 |
String nice_text = Html.fromHtml(show_field_text).toString().replaceAll("\n", "<br>");
|
328 |
// add white text color
|
329 |
nice_text = "<style> * { color: #FFFFFF; } </style> " + nice_text;
|
330 |
|
331 |
// load the text into the webview
|
332 |
this.main_aagtl.wv.loadDataWithBaseURL(null, nice_text, "text/html", "UTF-8", null);
|
333 |
|
334 |
// transparent bg-color
|
335 |
// this.main_aagtl.wv.setBackgroundColor(0);
|
336 |
this.main_aagtl.wv.setBackgroundColor(Color.BLACK);
|
337 |
// disable javascript
|
338 |
this.main_aagtl.wv.getSettings().setJavaScriptEnabled(false);
|
339 |
this.main_aagtl.wv.setVisibility(View.VISIBLE);
|
340 |
this.main_aagtl.wv.bringToFront();
|
341 |
}
|
342 |
}
|
343 |
catch (NullPointerException e)
|
344 |
{
|
345 |
|
346 |
}
|
347 |
}
|
348 |
}
|
349 |
|
350 |
public void clear_stuff()
|
351 |
{
|
352 |
}
|
353 |
|
354 |
public void onSizeChanged(int width, int height, int old_w, int old_h)
|
355 |
{
|
356 |
// System.out.println("GCacheView: onSizeChanged");
|
357 |
}
|
358 |
|
359 |
}
|