/[aagtl_public1]/src/com/zoffcc/applications/aagtl/aagtl.java
aagtl

Contents of /src/com/zoffcc/applications/aagtl/aagtl.java

Parent Directory Parent Directory | Revision Log Revision Log


Revision 4 - (hide annotations) (download)
Sat Aug 1 08:47:10 2015 UTC (8 years, 7 months ago) by zoffadmin
File size: 95673 byte(s)
1.0.35
1 zoffadmin 2 /**
2     * aagtl Advanced Geocaching Tool for Android
3     * loosely based on agtl by Daniel Fett <fett@danielfett.de>
4 zoffadmin 4 * Copyright (C) 2010 - 2013 Zoff <aagtl@work.zoff.cc>
5 zoffadmin 2 *
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 java.io.BufferedInputStream;
24     import java.io.BufferedOutputStream;
25     import java.io.BufferedReader;
26     import java.io.ByteArrayInputStream;
27     import java.io.ByteArrayOutputStream;
28     import java.io.DataInputStream;
29     import java.io.File;
30     import java.io.FileInputStream;
31     import java.io.FileNotFoundException;
32     import java.io.FileOutputStream;
33     import java.io.IOException;
34     import java.io.InputStreamReader;
35     import java.io.ObjectInputStream;
36     import java.io.ObjectOutputStream;
37     import java.io.OptionalDataException;
38     import java.io.Serializable;
39     import java.io.StreamCorruptedException;
40     import java.text.SimpleDateFormat;
41     import java.util.ArrayList;
42     import java.util.Calendar;
43     import java.util.Iterator;
44     import java.util.List;
45     import java.util.Locale;
46     import java.util.TimeZone;
47    
48 zoffadmin 4 import android.annotation.SuppressLint;
49 zoffadmin 2 import android.app.Activity;
50     import android.app.AlertDialog;
51     import android.app.Dialog;
52     import android.app.ProgressDialog;
53     import android.content.Context;
54     import android.content.DialogInterface;
55     import android.content.Intent;
56     import android.content.pm.ActivityInfo;
57     import android.content.res.Configuration;
58     import android.graphics.Bitmap;
59     import android.graphics.BitmapFactory;
60     import android.graphics.Color;
61     import android.graphics.RectF;
62     import android.hardware.Sensor;
63     import android.hardware.SensorEvent;
64     import android.hardware.SensorEventListener;
65     import android.hardware.SensorManager;
66     import android.location.Criteria;
67     import android.location.GpsSatellite;
68     import android.location.GpsStatus;
69     import android.location.Location;
70     import android.location.LocationListener;
71     import android.location.LocationManager;
72     import android.location.LocationProvider;
73     import android.media.AudioManager;
74     import android.net.Uri;
75     import android.os.Bundle;
76     import android.os.Environment;
77     import android.os.Handler;
78     import android.os.Message;
79     import android.os.PowerManager;
80     import android.os.PowerManager.WakeLock;
81     import android.os.SystemClock;
82     import android.text.SpannableString;
83     import android.text.method.LinkMovementMethod;
84     import android.text.util.Linkify;
85     import android.util.DisplayMetrics;
86     import android.util.Log;
87     import android.view.Display;
88     import android.view.KeyEvent;
89     import android.view.Menu;
90     import android.view.MenuItem;
91     import android.view.View;
92     import android.view.View.OnClickListener;
93 zoffadmin 4 import android.view.ViewConfiguration;
94 zoffadmin 2 import android.webkit.WebSettings;
95     import android.webkit.WebView;
96     import android.widget.Button;
97     import android.widget.RelativeLayout;
98     import android.widget.TextView;
99     import android.widget.Toast;
100     import android.widget.ToggleButton;
101    
102     import com.example.widget.NumberPicker;
103    
104     public class aagtl extends Activity implements LocationListener, GpsStatus.Listener, SensorEventListener
105     // ,OnClickListener
106     {
107    
108     static final boolean EMULATOR = false;
109 zoffadmin 4 static final boolean DEVELOPER_MODE = false;
110 zoffadmin 2
111     static final boolean _RELEASE_ = true;
112     boolean __ZOFF_PHONE__ = false;
113    
114 zoffadmin 4 static int Global_want_dpi = 240;
115     static int Global_real_dpi = 120; // this will be set in onCreate() method
116     static float Global_dpi_factor = 1.0f;
117    
118 zoffadmin 2 // OSD buttons/icons -------- START -----------
119     public Bitmap follow_on = null;
120     public Bitmap follow_off = null;
121     public Bitmap follow_current = null;
122     public Boolean follow_mode = true;
123     public RectF follow_button_rect = new RectF(-100, 1, 1, 1);
124    
125     public Bitmap arrow_button = null;
126     public RectF arrow_button_rect = new RectF(-100, 1, 1, 1);
127 zoffadmin 4
128     public Bitmap menu_button = null;
129     public RectF menu_button_rect = new RectF(-100, 1, 1, 1);
130     public RectF menu_button_rect_touch = new RectF(-100, 1, 1, 1);
131    
132     public boolean has_hw_menu_button = false;
133 zoffadmin 2 // OSD buttons/icons -------- END -----------
134    
135     Button btn_ok = null;
136     Button btn_cancel = null;
137     ToggleButton orient_1_toggle = null;
138     NumberPicker xx1 = null;
139     NumberPicker xx2 = null;
140     NumberPicker xx3 = null;
141     Boolean is_lat_current_change_target_coords = true;
142    
143     // Instantiating the Handler associated with the main thread.
144     private Handler global_messageHandler = new Handler();
145    
146     ProgressThread progressThread;
147     ProgressDialog pbarDialog;
148    
149 zoffadmin 4 public String main_dir = "/tmp/";
150     public String main_data_dir = "/tmp/";
151 zoffadmin 2
152     public String status_text_string = "";
153     public String status_append_string = "";
154    
155     Location mLastLocation = null;
156     long mLastLocationMillis = -1;
157     Boolean isGPSFix = false;
158     int used_sats = 0;
159    
160     String main_language = null;
161     String sub_language = null;
162     DisplayMetrics metrics;
163     WakeLock wl = null;
164    
165     List<GeocacheCoordinate> downloaded_caches = null;
166    
167     public LocationManager lm = null;
168     public LocationProvider low = null;
169     public LocationProvider high = null;
170     public SensorManager sensorManager = null;
171     public long last_heading_update = 0L;
172    
173     static final int DISPLAY_VIEW_MAP = 1;
174     static final int DISPLAY_VIEW_GC = 2;
175     static final int DISPLAY_VIEW_ARROW = 3;
176    
177     private Boolean show_no_loc_warning = false;
178    
179     public int current_display_view = DISPLAY_VIEW_MAP;
180 zoffadmin 4 static int TOUCH_CACHES_AFTER_THIS_ZOOM_LEVEL = 13;
181 zoffadmin 2
182     public CharSequence[] route_file_items = null;
183     public String current_routefile_name = null;
184     public List<GeocacheCoordinate> route_file_caches = null;
185     public AlertDialog alert = null;
186    
187 zoffadmin 4 public EmulatedMenuView emu_menu_view;
188 zoffadmin 2 public Rose rose;
189     public CrossHair cross;
190     public GeocachesView gcview;
191     public ArrowView arrowview;
192     public GCacheView cacheview;
193     public RelativeLayout mainscreen_map_view;
194     public int mainscreen_map_view_statusbar_height = 30;
195     public RelativeLayout.LayoutParams layoutParams_mainscreen_map_view;
196     public TextView status_text;
197     public WebView wv;
198 zoffadmin 4 final int EmulatedMenuActivity_id = 997;
199 zoffadmin 2
200     public double cur_lat_gps_save = -1;
201     public double cur_lon_gps_save = -1;
202    
203     public String db_path;
204    
205     MapDownloader mdl;
206     HTMLDownloader wdl;
207     PointProvider pv;
208     CacheDownloader cdol;
209    
210     public static class settings implements Serializable
211     {
212     private static final long serialVersionUID = 171513126339437464L;
213     public Boolean download_visible = true;
214     public Boolean download_notfound = true;
215     public Boolean download_new = true;
216     public Boolean download_nothing = false;
217     public Boolean download_create_index = true;
218     public Boolean download_run_after = false;
219     // download_run_after_string --> is now used as a generic config
220     // container!!
221     public String download_run_after_string = "CFG:v2.0:";
222     //
223     public String download_output_dir = "/sdcard/external_sd/zoffcc/applications/aagtl";
224     public double map_position_lat = 48.23428;
225     public double map_position_lon = 16.391514;
226     public int map_zoom = 15;
227     public int map_type = MapDownloader.MAP_OSM;
228     public Boolean download_resize = true;
229     public int download_resize_pixel = 400;
230     public Boolean options_show_name = true;
231     public String options_username = "Username";
232     public String options_password = "Password";
233     public double last_target_lat = 50.0;
234     public double last_target_lon = 10.0;
235     public String last_target_name = "default";
236     // "default" -> no target set
237     // "GC:GCXXXX" -> gc cache GC-Code
238     // "M:GCXXXX" -> manually entered coord (for GC-Code cache)
239     // "M:manual" -> manually entered coords
240     public Boolean download_noimages = false;
241     public String download_map_path = "/sdcard/external_sd/zoffcc/applications/aagtl";
242     public Boolean options_hide_found = false;
243     public Boolean options_use_compass_heading = false;
244     public String options_gc_filter__type = "";
245     public Boolean options_turn_map_on_heading = false;
246     }
247    
248     public settings global_settings = new settings();
249    
250     /** this criteria will settle for less accuracy, high power, and cost */
251     public static Criteria createCoarseCriteria()
252     {
253    
254     Criteria c = new Criteria();
255     c.setAccuracy(Criteria.ACCURACY_COARSE);
256     c.setAltitudeRequired(false);
257     c.setBearingRequired(false);
258     c.setSpeedRequired(false);
259     c.setCostAllowed(true);
260     c.setPowerRequirement(Criteria.POWER_HIGH);
261     return c;
262    
263     }
264    
265     /** this criteria needs high accuracy, high power, and cost */
266     public static Criteria createFineCriteria()
267     {
268    
269     Criteria c = new Criteria();
270     c.setAccuracy(Criteria.ACCURACY_FINE);
271     c.setAltitudeRequired(false);
272     c.setBearingRequired(false);
273     c.setSpeedRequired(false);
274     c.setCostAllowed(true);
275     c.setPowerRequirement(Criteria.POWER_HIGH);
276     return c;
277    
278     }
279    
280     public void load_settings()
281     {
282     System.out.println("load settings");
283    
284     // O P E N
285     FileInputStream fis = null;
286     try
287     {
288     fis = new FileInputStream(this.main_dir + "/config/settings.cfg");
289     }
290     catch (FileNotFoundException e)
291     {
292     if (CacheDownloader.DEBUG_)
293     {
294     System.out.println("FileNotFoundException");
295     }
296     global_settings = new settings();
297     return;
298     }
299    
300     BufferedInputStream bis = new BufferedInputStream(fis, 65536 /* 64K bytes */);
301     ObjectInputStream ois = null;
302     try
303     {
304     ois = new ObjectInputStream(bis);
305     }
306     catch (StreamCorruptedException e)
307     {
308     if (CacheDownloader.DEBUG_)
309     {
310     System.out.println("StreamCorruptedException");
311     }
312     global_settings = new settings();
313     return;
314     }
315     catch (IOException e)
316     {
317     if (CacheDownloader.DEBUG_)
318     {
319     System.out.println("IOException");
320     }
321     global_settings = new settings();
322     return;
323     }
324    
325     // R E A D
326     try
327     {
328     this.global_settings = (aagtl.settings) ois.readObject();
329     // check for encrypted password
330     if (this.global_settings.download_run_after_string.startsWith("CFG:v2.0:"))
331     {
332     // ok v2.0 so password is already encrypted
333     String inputString = this.global_settings.options_password;
334     if (CacheDownloader.DEBUG_)
335     {
336     System.out.println(this.global_settings.download_run_after_string);
337     }
338     String salt = this.global_settings.download_run_after_string.split(":")[2];
339     String cryptword = salt + "aagtl-" + "52-" + "Crypt";
340    
341     // Create encrypter/decrypter class
342     StringEnc desEncrypter = new StringEnc(cryptword);
343    
344     // Decrypt the string
345     String desDecrypted = desEncrypter.decrypt(inputString);
346    
347     // Print out values
348     if (CacheDownloader.DEBUG_)
349     {
350     System.out.println(" Original String : " + inputString);
351     System.out.println(" Salt (read) : " + salt);
352     System.out.println(" Decrypted String : " + desDecrypted);
353     System.out.println();
354     }
355    
356     this.global_settings.options_password = desDecrypted;
357     }
358     else
359     {
360     // old config so password is clear text
361     // now generate a salt value
362     String inputString = this.global_settings.options_password;
363     String salt = String.valueOf((int) (1000f * Math.random()));
364     if (CacheDownloader.DEBUG_)
365     {
366     System.out.println(" Original String : " + inputString);
367     System.out.println(" Salt (new) : " + salt);
368     }
369     this.global_settings.download_run_after_string = "CFG:v2.0:" + salt + ":";
370     }
371     }
372     catch (OptionalDataException e)
373     {
374     global_settings = new settings();
375     return;
376     }
377     catch (ClassNotFoundException e)
378     {
379     global_settings = new settings();
380     return;
381     }
382     catch (IOException e)
383     {
384     global_settings = new settings();
385     return;
386     }
387     catch (Exception e)
388     {
389     // fail safe, catch all!
390     global_settings = new settings();
391     return;
392     }
393    
394     // C L O S E
395     try
396     {
397     ois.close();
398     }
399     catch (IOException e)
400     {
401     global_settings = new settings();
402     return;
403     }
404    
405     // check if currently viewed cache exists, if not set it to something
406     // sane
407     if ((this.cacheview == null) || (this.cacheview.gc == null))
408     {
409     this.set_init_target_cache();
410     }
411    
412     if (CacheDownloader.DEBUG_)
413     {
414     System.out.println("settings:" + this.global_settings.options_username);
415     System.out.println("settings:" + this.global_settings.options_password);
416     }
417     }
418    
419     public void save_settings()
420     {
421     System.out.println("save settings");
422    
423     // make dirs
424     File dir1 = new File(this.main_dir + "/config/settings.cfg");
425     File dir2 = new File(dir1.getParent());
426     dir2.mkdirs();
427    
428     // O P E N
429     FileOutputStream fos = null;
430     try
431     {
432     fos = new FileOutputStream(this.main_dir + "/config/settings.cfg", false /* append */);
433     }
434     catch (FileNotFoundException e)
435     {
436     if (CacheDownloader.DEBUG_)
437     {
438     System.out.println("FileNotFoundException");
439     }
440     return;
441     }
442    
443     BufferedOutputStream bos = new BufferedOutputStream(fos, 65536 /*
444     * 64K
445     * bytes
446     */);
447     ObjectOutputStream oos = null;
448    
449     try
450     {
451     oos = new ObjectOutputStream(bos);
452     }
453     catch (IOException e)
454     {
455     if (CacheDownloader.DEBUG_)
456     {
457     System.out.println("IOException");
458     }
459     return;
460     }
461    
462     // W R I T E
463     // object to write, and objects it points to must implement
464     // java.io.Serializable
465     // Ideally such objects should also have have a field:
466     // static final long serialVersionUID = 1L;
467     // to prevent spurious InvalidClassExceptions.
468    
469     try
470     {
471     // +++++++++++++++++++++++++
472     // copy the settings object
473     // +++++++++++++++++++++++++
474     // Serialize to a byte array
475     ByteArrayOutputStream bos_save = new ByteArrayOutputStream();
476     ObjectOutputStream out_save = new ObjectOutputStream(bos_save);
477     out_save.writeObject(this.global_settings);
478     out_save.close();
479     // Get the bytes of the serialized object
480     byte[] buf_save = bos_save.toByteArray();
481     // Deserialize from a byte array
482     ObjectInputStream in_save = new ObjectInputStream(new ByteArrayInputStream(buf_save));
483     settings save_settings = (settings) in_save.readObject();
484     in_save.close();
485     // +++++++++++++++++++++++++
486     // copy the settings object
487     // +++++++++++++++++++++++++
488    
489     if (save_settings.download_run_after_string.startsWith("CFG:v2.0:"))
490     {
491     // ok v2.0 so password is clear text new, encrypt it
492     String inputString = save_settings.options_password;
493     String salt = "";
494     try
495     {
496     salt = save_settings.download_run_after_string.split(":")[2];
497     if (CacheDownloader.DEBUG_)
498     {
499     System.out.println("using salt: " + salt);
500     }
501     }
502     catch (Exception e)
503     {
504     // now generate a salt value
505     salt = String.valueOf((int) (1000f * Math.random()));
506     this.global_settings.download_run_after_string = "CFG:v2.0:" + salt + ":";
507     save_settings.download_run_after_string = this.global_settings.download_run_after_string;
508     if (CacheDownloader.DEBUG_)
509     {
510     System.out.println("generated salt: " + salt);
511     }
512     }
513     String cryptword = salt + "aagtl-" + "52-" + "Crypt";
514    
515     // Create encrypter/decrypter class
516     StringEnc desEncrypter = new StringEnc(cryptword);
517    
518     // Encrypt the string
519     String desEncrypted = desEncrypter.encrypt(inputString);
520    
521     if (CacheDownloader.DEBUG_)
522     {
523     // Print out values
524     System.out.println(" Original String : " + inputString);
525     System.out.println(" Salt (read) : " + salt);
526     System.out.println(" Encrypted String : " + desEncrypted);
527     System.out.println();
528     }
529    
530     save_settings.options_password = desEncrypted;
531     }
532    
533     oos.writeObject(save_settings);
534     oos.flush();
535     // C L O S E
536     oos.close();
537    
538     // free some memory
539     save_settings = null;
540     }
541     catch (IOException e)
542     {
543     if (CacheDownloader.DEBUG_)
544     {
545     System.out.println("IOException 2");
546     }
547     return;
548     }
549     catch (Exception e)
550     {
551     if (CacheDownloader.DEBUG_)
552     {
553     System.out.println("**Exception**");
554     }
555     // fail safe, catch all!
556     return;
557     }
558    
559     }
560    
561     @Override
562     public void onSaveInstanceState(Bundle savedInstanceState)
563     {
564     // Save UI state changes to the savedInstanceState.
565     // This bundle will be passed to onCreate if the process is
566     // killed and restarted.
567     savedInstanceState.putDouble("global_settings.map_position_lat", global_settings.map_position_lat);
568     savedInstanceState.putDouble("global_settings.map_position_lon", global_settings.map_position_lon);
569     System.out.println(String.valueOf(this.cacheview.gc));
570     savedInstanceState.putSerializable("cacheview.gc", this.cacheview.gc);
571     savedInstanceState.putSerializable("rose.current_target", this.rose.current_target);
572     this.save_settings();
573    
574     super.onSaveInstanceState(savedInstanceState);
575     System.out.println("save bundle");
576     }
577    
578     @Override
579     public void onRestoreInstanceState(Bundle savedInstanceState)
580     {
581     super.onRestoreInstanceState(savedInstanceState);
582    
583     if (!savedInstanceState.isEmpty())
584     {
585     global_settings.map_position_lat = savedInstanceState.getDouble("global_settings.map_position_lat");
586     global_settings.map_position_lon = savedInstanceState.getDouble("global_settings.map_position_lon");
587    
588     // try
589     // {
590     // System.out.println(String.valueOf(this.cacheview.gc));
591     // this.cacheview.gc = (GeocacheCoordinate) savedInstanceState
592     // .getSerializable("cacheview.gc");
593     // System.out.println(String.valueOf(this.cacheview.gc));
594     // this.rose.current_target = (GeocacheCoordinate)
595     // savedInstanceState
596     // .getSerializable("rose.current_target");
597     // }
598     // catch (Exception e)
599     // {
600     // System.out.println("error in restoring values");
601     // }
602     }
603    
604     System.out.println("restore bundle");
605    
606     // System.out.println("map_position_lat:" +
607     // String.valueOf(global_settings.map_position_lat));
608     // System.out.println("map_position_lon:" +
609     // String.valueOf(global_settings.map_position_lon));
610     }
611    
612     public void set_center(double lat, double lon)
613     {
614     global_settings.map_position_lat = lat;
615     global_settings.map_position_lon = lon;
616     }
617    
618 zoffadmin 4 @SuppressLint("NewApi")
619     void detect_menu_button()
620     {
621     // default: we dont have a real menu button
622     has_hw_menu_button = false;
623    
624     try
625     {
626     if (Integer.parseInt(android.os.Build.VERSION.SDK) >= 14)
627     {
628     if (ViewConfiguration.get(getApplicationContext()).hasPermanentMenuKey())
629     {
630     has_hw_menu_button = true;
631     }
632     else
633     {
634     has_hw_menu_button = false;
635     }
636     }
637     }
638     catch (Exception e)
639     {
640     // on error we must be on android API < 14 and therfore we have a menu button (that is what we assume)
641     has_hw_menu_button = true;
642     }
643    
644     // ------ for debug ---------
645     // ------ for debug ---------
646     // ------ for debug ---------
647     has_hw_menu_button = false; // now always show the manu button icon
648     // ------ for debug ---------
649     // ------ for debug ---------
650     // ------ for debug ---------
651    
652     }
653    
654     @SuppressLint("NewApi")
655     void wrap_strict_mode()
656     {
657     if (DEVELOPER_MODE)
658     {
659     // try
660     // {
661     // StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder().detectDiskReads().detectDiskWrites().detectNetwork() // or .detectAll() for all detectable problems
662     // .penaltyLog().build());
663     // StrictMode.setVmPolicy(new StrictMode.VmPolicy.Builder().detectLeakedSqlLiteObjects().detectLeakedClosableObjects().penaltyLog().penaltyDeath().build());
664     // }
665     // catch (Exception e)
666     // {
667     //
668     // }
669     }
670     }
671    
672 zoffadmin 2 @Override
673     protected void onCreate(Bundle savedInstanceState)
674     {
675 zoffadmin 4 wrap_strict_mode();
676    
677 zoffadmin 2 super.onCreate(savedInstanceState);
678    
679 zoffadmin 4 System.out.println("AAGTL:main:create");
680    
681 zoffadmin 2 // choose the correct volume to change (for TTS)
682     // setVolumeControlStream(AudioManager.STREAM_SYSTEM);
683     // setVolumeControlStream(AudioManager.STREAM_NOTIFICATION);
684     setVolumeControlStream(AudioManager.STREAM_MUSIC); // --> this seems to
685     // be used for TTS
686     // setVolumeControlStream(AudioManager.STREAM_DTMF);
687    
688     String default_sdcard_dir = Environment.getExternalStorageDirectory().getAbsolutePath();
689     Log.e("aagtl", "sdcard dir=" + default_sdcard_dir);
690    
691     main_dir = default_sdcard_dir + "/zoffcc/applications/aagtl";
692 zoffadmin 4 main_data_dir = default_sdcard_dir + "/zoffcc/applications/aagtl";
693 zoffadmin 2
694 zoffadmin 4 // detect if device has a real menu button
695     detect_menu_button();
696    
697 zoffadmin 2 // get the local language -------------
698     Locale locale = java.util.Locale.getDefault();
699     String lang = locale.getLanguage();
700     String langu = lang;
701     String langc = lang;
702     Log.e("aagtl", "lang=" + lang);
703     int pos = langu.indexOf('_');
704     if (pos != -1)
705     {
706     langc = langu.substring(0, pos);
707     langu = langc + langu.substring(pos).toUpperCase(locale);
708     Log.e("aagtl", "substring lang " + langu.substring(pos).toUpperCase(locale));
709     // set lang. for translation
710     main_language = langc;
711     sub_language = langu.substring(pos).toUpperCase(locale);
712     }
713     else
714     {
715     String country = locale.getCountry();
716     Log.e("aagtl", "Country1 " + country);
717     Log.e("aagtl", "Country2 " + country.toUpperCase(locale));
718     langu = langc + "_" + country.toUpperCase(locale);
719     // set lang. for translation
720     main_language = langc;
721     sub_language = country.toUpperCase(locale);
722     }
723     Log.e("aagtl", "Language " + lang);
724     // get the local language -------------
725    
726     // make dirs
727     File dir11 = new File(this.main_dir);
728     dir11.mkdirs();
729     File dir22 = new File(this.main_data_dir);
730     dir22.mkdirs();
731     // create nomedia files
732     File nomedia_file = new File(this.main_dir + "/.nomedia");
733     try
734     {
735     nomedia_file.createNewFile();
736     }
737     catch (IOException e1)
738     {
739     e1.printStackTrace();
740     }
741     nomedia_file = new File(this.main_data_dir + "/.nomedia");
742     try
743     {
744     nomedia_file.createNewFile();
745     }
746     catch (IOException e1)
747     {
748     e1.printStackTrace();
749     }
750     // create nomedia files
751    
752     // make dirs (for "route" files, you can select a file, and only those
753     // GC will be shown)
754     File dir71 = new File(this.main_dir + "/routes/");
755     dir71.mkdirs();
756    
757     /*
758     * show info box for first time users
759     */
760     AlertDialog.Builder infobox = new AlertDialog.Builder(this);
761     infobox.setTitle(aagtlTextTranslations.INFO_BOX_TITLE); // TRANS
762     infobox.setCancelable(false);
763     final TextView message = new TextView(this);
764     message.setFadingEdgeLength(20);
765     message.setVerticalFadingEdgeEnabled(true);
766     message.setVerticalScrollBarEnabled(true);
767     RelativeLayout.LayoutParams rlpib = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.FILL_PARENT, RelativeLayout.LayoutParams.FILL_PARENT);
768    
769     // margins seem not to work, hmm strange
770     // so add a " " at start of every line. well whadda you gonna do ...
771     // rlp.leftMargin = 8; -> we use "m" string
772    
773     message.setLayoutParams(rlpib);
774     final SpannableString s = new SpannableString(aagtlTextTranslations.INFO_BOX_TEXT); // TRANS
775     Linkify.addLinks(s, Linkify.WEB_URLS);
776     message.setText(s);
777     message.setMovementMethod(LinkMovementMethod.getInstance());
778     infobox.setView(message);
779    
780     // TRANS
781     infobox.setPositiveButton("Ok", new DialogInterface.OnClickListener()
782     {
783     public void onClick(DialogInterface arg0, int arg1)
784     {
785     Log.e("aagtl", "Ok, user saw the infobox");
786     }
787     });
788    
789     // TRANS
790     infobox.setNeutralButton(aagtlTextTranslations.JAVA_MENU_MOREINFO, new DialogInterface.OnClickListener()
791     {
792     public void onClick(DialogInterface arg0, int arg1)
793     {
794     Log.e("aagtl", "user wants more info, show the website");
795     String url = "http://aagtl.work.zoff.cc/";
796     Intent i = new Intent(Intent.ACTION_VIEW);
797     i.setData(Uri.parse(url));
798     startActivity(i);
799     }
800     });
801    
802     //
803     //
804     //
805     show_no_loc_warning = false;
806     try
807     {
808     // get location services
809     // lm = LocationUtils.getLocationManager(ctx.getMyContext());
810     this.lm = (LocationManager) getSystemService(LOCATION_SERVICE);
811     // get low accuracy provider
812 zoffadmin 4 Criteria lowCriteria = new Criteria();
813     lowCriteria.setAccuracy(Criteria.ACCURACY_COARSE);
814     lowCriteria.setAltitudeRequired(false);
815     lowCriteria.setBearingRequired(false);
816     lowCriteria.setCostAllowed(true);
817     lowCriteria.setPowerRequirement(Criteria.POWER_LOW);
818     //
819     this.low = lm.getProvider(lm.getBestProvider(lowCriteria, false));
820     System.out.println("AAGTL:fast location=" + this.low.getName());
821 zoffadmin 2
822 zoffadmin 4 // get high accuracy provider
823     this.high = lm.getProvider(lm.getBestProvider(createFineCriteria(), false));
824     System.out.println("AAGTL:accurate location=" + this.high.getName());
825 zoffadmin 2 // ++++++ lm.requestLocationUpdates(LocationManager.GPS_PROVIDER, 700L,
826     // 1.0f, this);
827    
828     if (!EMULATOR)
829     {
830     sensorManager = (SensorManager) getSystemService(SENSOR_SERVICE);
831     }
832     }
833     catch (Exception e)
834     {
835     e.printStackTrace();
836     // Toast.makeText(getApplicationContext(), "You dont have any Location providers!\nthis program will not work on your device!", Toast.LENGTH_LONG).show();
837     // set the infobox text to this error message, to tell the user it wont work correctly
838     message.setText("\n You don't have any Location providers!\n This program will not work fully!\n");
839     show_no_loc_warning = true;
840     }
841    
842     //
843     //
844     //
845     //
846    
847     String FIRST_STARTUP_FILE = main_dir + "/infobox_seen.txt";
848     File aagtl_first_startup = new File(FIRST_STARTUP_FILE);
849     // if file does NOT exist, show the info box
850     // or if "no location providers", show info box
851     if ((!aagtl_first_startup.exists()) || (show_no_loc_warning))
852     {
853     // if "no location providers" text, then dont show/save info box file
854     if (!show_no_loc_warning)
855     {
856     FileOutputStream fos_temp;
857     try
858     {
859     fos_temp = new FileOutputStream(aagtl_first_startup);
860     fos_temp.write((int) 65); // just write an "A" to the file, but
861     // really doesnt matter
862     fos_temp.flush();
863     fos_temp.close();
864     }
865     catch (Exception e)
866     {
867     e.printStackTrace();
868     }
869     }
870    
871     try
872     {
873     infobox.show();
874     }
875     catch (Exception e)
876     {
877     e.printStackTrace();
878     }
879     }
880     /*
881     * show info box for first time users
882     */
883    
884     // get display properties
885     Display display_ = getWindowManager().getDefaultDisplay();
886     int width_ = display_.getWidth();
887     int height_ = display_.getHeight();
888     this.metrics = new DisplayMetrics();
889     display_.getMetrics(this.metrics);
890     Log.e("aagtl", "aagtl -> pixels x=" + width_ + " pixels y=" + height_);
891     Log.e("aagtl", "aagtl -> dpi=" + this.metrics.densityDpi);
892     Log.e("aagtl", "aagtl -> density=" + this.metrics.density);
893     Log.e("aagtl", "aagtl -> scaledDensity=" + this.metrics.scaledDensity);
894 zoffadmin 4
895     Global_real_dpi = this.metrics.densityDpi;
896     Global_dpi_factor = (float) aagtl.Global_real_dpi / (float) aagtl.Global_want_dpi;
897    
898     mainscreen_map_view_statusbar_height = (int) ((float) mainscreen_map_view_statusbar_height * Global_dpi_factor);
899    
900 zoffadmin 2 // get display properties
901    
902     System.out.println("Create: " + String.valueOf(savedInstanceState));
903     if (savedInstanceState != null)
904     {
905     this.onRestoreInstanceState(savedInstanceState);
906     }
907    
908     this.load_settings();
909    
910     // Set full screen view
911     // getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
912     // WindowManager.LayoutParams.FLAG_FULLSCREEN);
913 zoffadmin 4 // ** getWindow().setFlags(0, 0);
914     // ** requestWindowFeature(Window.FEATURE_NO_TITLE);
915     //requestWindowFeature(0);
916 zoffadmin 2
917     // System.out.println("CR map_position_lat:" +
918     // String.valueOf(global_settings.map_position_lat));
919     // System.out.println("CR map_position_lon:" +
920     // String.valueOf(global_settings.map_position_lon));
921    
922     // setContentView(R.layout.main);
923    
924     Boolean sensors_fullblown = false;
925     if (sensors_fullblown)
926     {
927     List<Sensor> sensors = sensorManager.getSensorList(Sensor.TYPE_ALL);
928     Sensor ourSensor = null;
929     for (int i = 0; i < sensors.size(); ++i)
930     {
931     ourSensor = sensors.get(i);
932     // System.out.println(ourSensor.getName());
933     if (ourSensor != null)
934     {
935     sensorManager.registerListener(this, ourSensor, SensorManager.SENSOR_DELAY_NORMAL);
936     }
937     }
938     }
939    
940     // System.out.println("main: create");
941     this.mdl = new MapDownloader(global_messageHandler, this);
942     this.mdl.start();
943    
944     this.wdl = new HTMLDownloader(this);
945    
946     this.cdol = new CacheDownloader(this, wdl);
947    
948     // ------- MAP VIEW: CREATE -------
949     layoutParams_mainscreen_map_view = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.FILL_PARENT, RelativeLayout.LayoutParams.FILL_PARENT);
950     mainscreen_map_view = new RelativeLayout(this);
951     mainscreen_map_view.setLayoutParams(layoutParams_mainscreen_map_view);
952    
953     status_text = new TextView(this);
954     status_text.setBackgroundColor(Color.BLACK);
955     status_text.setTextColor(Color.WHITE);
956     status_text.setMaxLines(1);
957     status_text.setTextSize(12);
958     status_text.setText("--- --- --- --- ---");
959     status_text.setVisibility(0); // set to visible
960    
961     rose = new Rose(this, this);
962     RelativeLayout.LayoutParams rlp = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.FILL_PARENT, RelativeLayout.LayoutParams.FILL_PARENT);
963     rlp.bottomMargin = mainscreen_map_view_statusbar_height;
964     rlp.addRule(RelativeLayout.ALIGN_PARENT_TOP);
965     mainscreen_map_view.addView(rose, rlp);
966    
967     RelativeLayout.LayoutParams tvlp = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.FILL_PARENT, mainscreen_map_view_statusbar_height);
968     tvlp.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
969     mainscreen_map_view.addView(status_text, tvlp);
970    
971     this.wv = new WebView(this);
972     this.wv.getSettings().setSupportZoom(true);
973     this.wv.getSettings().setBuiltInZoomControls(true);
974 zoffadmin 4 //this.wv.getSettings().setDefaultFontSize((int) (13f * aagtl.Global_dpi_factor));
975     this.wv.getSettings().setDefaultFontSize((int) (13f * 1));
976 zoffadmin 2
977     // zoom seems to be NULL on some systems (e.g. honeycomb)
978 zoffadmin 4 //final View zoom = this.wv.getZoomControls();
979 zoffadmin 2
980 zoffadmin 4 //try
981     //{
982     // zoom.setVisibility(View.INVISIBLE);
983     //}
984     //catch (Exception e)
985     //{
986     // e.printStackTrace();
987     //}
988 zoffadmin 2
989     this.wv.getSettings().setDefaultZoom(WebSettings.ZoomDensity.MEDIUM);
990     RelativeLayout.LayoutParams wvlp = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.FILL_PARENT, RelativeLayout.LayoutParams.FILL_PARENT);
991     mainscreen_map_view.addView(wv, wvlp);
992    
993     cross = new CrossHair(this, this);
994     RelativeLayout.LayoutParams chlp = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.FILL_PARENT, RelativeLayout.LayoutParams.FILL_PARENT);
995    
996     gcview = new GeocachesView(this, this);
997     RelativeLayout.LayoutParams gcwlp = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.FILL_PARENT, RelativeLayout.LayoutParams.FILL_PARENT);
998    
999     arrowview = new ArrowView(this, this);
1000     RelativeLayout.LayoutParams avlp = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.FILL_PARENT, RelativeLayout.LayoutParams.FILL_PARENT);
1001    
1002     cacheview = new GCacheView(this, this);
1003     RelativeLayout.LayoutParams cvlp = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.FILL_PARENT, RelativeLayout.LayoutParams.FILL_PARENT);
1004    
1005 zoffadmin 4 emu_menu_view = new EmulatedMenuView(this, this);
1006     RelativeLayout.LayoutParams emvlp = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.FILL_PARENT, RelativeLayout.LayoutParams.FILL_PARENT);
1007     emvlp.setMargins(dp_to_px(40), dp_to_px(30), dp_to_px(40), dp_to_px(30));
1008    
1009 zoffadmin 2 // get the png's
1010 zoffadmin 4 if (Global_real_dpi > 320)
1011     {
1012     this.follow_on = BitmapFactory.decodeResource(getResources(), R.drawable.follow_large);
1013     this.follow_off = BitmapFactory.decodeResource(getResources(), R.drawable.follow_off_large);
1014     this.follow_current = this.follow_on;
1015     this.arrow_button = BitmapFactory.decodeResource(getResources(), R.drawable.arrow_off_large);
1016     this.menu_button = BitmapFactory.decodeResource(getResources(), R.drawable.menu_001);
1017     }
1018     else
1019     {
1020     this.follow_on = BitmapFactory.decodeResource(getResources(), R.drawable.follow);
1021     this.follow_off = BitmapFactory.decodeResource(getResources(), R.drawable.follow_off);
1022     this.follow_current = this.follow_on;
1023     this.arrow_button = BitmapFactory.decodeResource(getResources(), R.drawable.arrow_off);
1024     this.menu_button = BitmapFactory.decodeResource(getResources(), R.drawable.menu_001_small);
1025     }
1026 zoffadmin 2
1027     chlp.bottomMargin = mainscreen_map_view_statusbar_height;
1028     gcwlp.bottomMargin = mainscreen_map_view_statusbar_height;
1029     avlp.bottomMargin = mainscreen_map_view_statusbar_height;
1030     cvlp.bottomMargin = mainscreen_map_view_statusbar_height;
1031     wvlp.bottomMargin = mainscreen_map_view_statusbar_height;
1032     wvlp.topMargin = 80 + 4 * 40;
1033     mainscreen_map_view.addView(cross, chlp);
1034     mainscreen_map_view.addView(gcview, gcwlp);
1035     mainscreen_map_view.addView(arrowview, avlp);
1036     mainscreen_map_view.addView(cacheview, cvlp);
1037 zoffadmin 4 mainscreen_map_view.addView(emu_menu_view, emvlp);
1038 zoffadmin 2 // ------- MAP VIEW: CREATE -------
1039    
1040     // ------- VIEWS -------
1041     // make correct Z-order
1042     rose.bringToFront();
1043     gcview.bringToFront();
1044     cross.bringToFront();
1045     status_text.bringToFront();
1046     wv.bringToFront();
1047     arrowview.setVisibility(View.INVISIBLE);
1048     cacheview.setVisibility(View.INVISIBLE);
1049     wv.setVisibility(View.INVISIBLE);
1050 zoffadmin 4 emu_menu_view.bringToFront();
1051     emu_menu_view.setVisibility(View.INVISIBLE);
1052 zoffadmin 2 setContentView(mainscreen_map_view);
1053     // ------- VIEWS -------
1054    
1055     // ------- set default VIEW on display
1056     this.set_display_screen(aagtl.DISPLAY_VIEW_MAP);
1057     // ------- set default VIEW on display
1058    
1059     db_path = this.main_data_dir + "/config/caches.db";
1060     File dir1 = new File(db_path);
1061     File dir2 = new File(dir1.getParent());
1062     dir2.mkdirs();
1063     // pv = new PointProvider(db_path, this.mdl, "", "geocaches");
1064     // *** DANGER *** pv._clear_database_();
1065    
1066     // get position on first startup
1067     turn_off_gps();
1068     try
1069     {
1070     // wait for gsm cell fix
1071 zoffadmin 4 Thread.sleep(60L);
1072 zoffadmin 2 }
1073     catch (InterruptedException e)
1074     {
1075     e.printStackTrace();
1076     }
1077     // ok, now switch to real gps
1078     turn_on_gps();
1079    
1080     PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
1081     // this.wl = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK ,
1082     // "aagtlWakeLock"); // i think this is not working
1083     this.wl = pm.newWakeLock(PowerManager.FULL_WAKE_LOCK | PowerManager.ON_AFTER_RELEASE, "aagtlWakeLock");
1084     }
1085    
1086 zoffadmin 4 //@Override
1087     //public boolean onCreateOptionsMenu(Menu menu)
1088     //{
1089     // super.onCreateOptionsMenu(menu);
1090     // // System.out.println("onCreateOptionsMenu");
1091     // return true;
1092     //}
1093 zoffadmin 2
1094     @Override
1095     public boolean onPrepareOptionsMenu(Menu menu)
1096     {
1097 zoffadmin 4 //super.onPrepareOptionsMenu(menu);
1098 zoffadmin 2 // this gets called every time the menu is opened!!
1099     // change menu items here!
1100     // System.out.println("onPrepareOptionsMenu");
1101    
1102     switch (this.current_display_view)
1103     {
1104     case DISPLAY_VIEW_MAP:
1105     // main map view
1106    
1107     menu.clear();
1108     // g-id,i-id,order
1109     menu.add(1, 2, 20, "zoom in");
1110     menu.add(1, 3, 22, "zoom out");
1111    
1112     menu.add(1, 4, 30, "maptype: OSM");
1113     if (__ZOFF_PHONE__)
1114     {
1115     menu.add(1, 5, 32, "maptype: Sat");
1116     }
1117     else
1118     {
1119     menu.add(1, 29, 33, "maptype: OCM");
1120     }
1121    
1122     menu.add(1, 1, 40, "get caches in view");
1123     menu.add(1, 20, 41, "get details in view");
1124    
1125     menu.add(1, 21, 42, "turn on GPS");
1126     menu.add(1, 22, 43, "turn off GPS");
1127     menu.add(1, 25, 44, "show arrow view");
1128    
1129     menu.add(1, 30, 45, "navigate to target");
1130     menu.add(1, 32, 46, "change target lat.");
1131     menu.add(1, 33, 47, "change target lon.");
1132    
1133     menu.add(1, 27, 49, "select routefile");
1134     menu.add(1, 28, 50, "get caches from routefile");
1135     menu.add(1, 23, 51, "upload fieldnotes");
1136     if (this.global_settings.options_turn_map_on_heading)
1137     {
1138     menu.add(1, 26, 52, "turn off rotating map");
1139     }
1140     else
1141     {
1142     menu.add(1, 26, 52, "turn on rotating map");
1143     }
1144    
1145     menu.add(1, 6, 78, "-");
1146     menu.add(1, 19, 79, "set username/password");
1147     menu.add(1, 6, 80, "-");
1148     menu.add(1, 7, 82, "empty database");
1149    
1150     break;
1151     case DISPLAY_VIEW_GC:
1152     // gc-view
1153     menu.clear();
1154     // g-id,i-id,order
1155     menu.add(1, 8, 20, "map view");
1156     menu.add(1, 14, 22, "update details");
1157     menu.add(1, 9, 24, "set as target -> map");
1158     menu.add(1, 10, 26, "set as target -> arrow");
1159     menu.add(1, 15, 28, "description");
1160     menu.add(1, 16, 30, "hints");
1161     menu.add(1, 17, 32, "logs");
1162     menu.add(1, 34, 33, "waypoints");
1163     menu.add(1, 18, 34, "shorttext");
1164     menu.add(1, 31, 35, "show Cache website");
1165     // seems to be buggy, so for the moment remove it
1166     // if (this.rose.current_target != null)
1167     // {
1168     // menu.add(1, 24, 36, "post fieldnote");
1169     // }
1170     break;
1171     case DISPLAY_VIEW_ARROW:
1172     // arrow view
1173     menu.clear();
1174     // g-id,i-id,order
1175     menu.add(1, 11, 20, "cache view");
1176     menu.add(1, 12, 22, "map view");
1177     String st_compass = "use compass heading";
1178     if (this.global_settings.options_use_compass_heading)
1179     {
1180     st_compass = "use gps heading";
1181    
1182     }
1183     menu.add(1, 13, 24, st_compass);
1184     if (this.rose.current_target != null)
1185     {
1186     menu.add(1, 24, 26, "post fieldnote");
1187     }
1188     break;
1189     }
1190    
1191     return true;
1192     }
1193    
1194     public void onSensorChanged(SensorEvent event)
1195     {
1196     if (event.sensor.getType() == Sensor.TYPE_MAGNETIC_FIELD)
1197     {
1198     // System.out.println("Sensor.TYPE_MAGNETIC_FIELD");
1199     return;
1200     }
1201    
1202     if (event.sensor.getType() == Sensor.TYPE_ORIENTATION)
1203     {
1204     // System.out.println("Sensor.TYPE_ORIENTATION");
1205    
1206     Boolean set_c_heading = false;
1207     if (this.global_settings.options_use_compass_heading)
1208     {
1209     // if "options_use_compass_heading" is set the use compass
1210     // always
1211     set_c_heading = true;
1212     // System.out.println("true 1");
1213     }
1214     else
1215     {
1216     if (!this.isGPSFix)
1217     {
1218     // if no gps-fix then use compass until gps fix found
1219     set_c_heading = true;
1220     // System.out.println("true 2");
1221     }
1222     }
1223    
1224     if (set_c_heading)
1225     {
1226     // compass
1227     double myAzimuth = event.values[0];
1228     // double myPitch = event.values[1];
1229     // double myRoll = event.values[2];
1230    
1231     // String out = String.format("Azimuth: %.2f", myAzimuth);
1232     // System.out.println("compass: " + out);
1233    
1234     if (this.current_display_view == DISPLAY_VIEW_MAP)
1235     {
1236     long normal_delay = 1000L; // update every 1.0 seconds
1237     if (this.global_settings.options_turn_map_on_heading)
1238     {
1239     normal_delay = 400L; // update every 0.4 seconds with
1240     // turning map!
1241     }
1242     if (System.currentTimeMillis() - last_heading_update < normal_delay)
1243     {
1244     // System.out.println("-> compass heading: update to fast, skipped");
1245     }
1246     else
1247     {
1248     // System.out.println("-> compass heading (slow)");
1249     last_heading_update = System.currentTimeMillis();
1250     this.cross.set_gps_heading(myAzimuth);
1251     this.cross.invalidate();
1252     this.arrowview.invalidate();
1253     }
1254     }
1255     else
1256     {
1257     // System.out.println("-> compass heading (fast)");
1258     last_heading_update = System.currentTimeMillis();
1259     this.cross.set_gps_heading(myAzimuth);
1260     this.cross.invalidate();
1261     this.arrowview.invalidate();
1262     }
1263     }
1264    
1265     // String out =
1266     // String.format("Azimuth: %.2f\n\nPitch:%.2f\n\nRoll:%.2f\n\n",
1267     // myAzimuth,
1268     // myPitch, myRoll);
1269     // System.out.println("compass: " + out);
1270     }
1271     }
1272    
1273     public void onAccuracyChanged(Sensor sensor, int accuracy)
1274     {
1275     // compass
1276     }
1277    
1278     @Override
1279     public void onBackPressed()
1280     {
1281     // do something on back.
1282     // System.out.println("no back key!");
1283    
1284     if (this.current_display_view == DISPLAY_VIEW_MAP)
1285     {
1286 zoffadmin 4 if (this.emu_menu_view.isShown())
1287     {
1288     this.emu_menu_view.setVisibility(View.INVISIBLE);
1289     }
1290     else
1291     {
1292     this.finish(); // -> this calls "onPause"
1293     }
1294 zoffadmin 2 }
1295     else if (this.current_display_view == DISPLAY_VIEW_GC)
1296     {
1297     this.set_display_screen(DISPLAY_VIEW_MAP);
1298     }
1299     else if (this.current_display_view == DISPLAY_VIEW_ARROW)
1300     {
1301     if (this.rose.current_target != null)
1302     {
1303     // show gc view, if we have a target
1304     this.set_display_screen(DISPLAY_VIEW_GC);
1305     }
1306     else
1307     {
1308     // no target -> show map view
1309     this.set_display_screen(DISPLAY_VIEW_MAP);
1310     }
1311     }
1312    
1313     return;
1314     }
1315    
1316     public void set_init_target_cache()
1317     {
1318     if (this.global_settings.last_target_name.compareTo("default") == 0)
1319     {
1320     // no target set!!
1321     }
1322     else
1323     {
1324     String my_tmp_name = "last target";
1325     GeocacheCoordinate tmp_gc = new GeocacheCoordinate(this.global_settings.last_target_lat, this.global_settings.last_target_lon, my_tmp_name);
1326     if (this.cacheview != null)
1327     {
1328     System.out.println("xxxxx1");
1329     this.cacheview.set_cache(tmp_gc);
1330     // this.set_display_screen(aagtl.DISPLAY_VIEW_GC);
1331     // this.set_display_screen(aagtl.DISPLAY_VIEW_MAP);
1332     }
1333     if (this.rose != null)
1334     {
1335     System.out.println("xxxxx2");
1336     if (this.global_settings != null)
1337     {
1338     System.out.println("xxxxx3");
1339     System.out.println("" + this.global_settings.last_target_name);
1340     System.out.println("" + this.global_settings.last_target_lat);
1341     System.out.println("" + this.global_settings.last_target_lon);
1342     this.rose.current_target = tmp_gc;
1343     }
1344     }
1345     }
1346     }
1347    
1348     public void set_target()
1349     {
1350     this.rose.current_target = this.cacheview.get_cache();
1351     this.global_settings.last_target_lat = this.rose.current_target.lat;
1352     this.global_settings.last_target_lon = this.rose.current_target.lon;
1353     this.global_settings.last_target_name = "GC:" + this.rose.current_target.name;
1354     // "default" -> no target set
1355     // "GC:GCXXXX" -> gc cache GC-Code
1356     // "M:GCXXXX" -> manually entered coord (for GC-Code cache)
1357     // "M:manual" -> manually entered coords
1358     }
1359    
1360     @Override
1361     public boolean onOptionsItemSelected(MenuItem item)
1362     {
1363 zoffadmin 4 return onOptionsItemSelected_wrapper(item.getItemId());
1364     }
1365    
1366     public boolean onOptionsItemSelected_wrapper(int id)
1367     {
1368 zoffadmin 2 // Handle item selection
1369 zoffadmin 4 switch (id)
1370 zoffadmin 2 {
1371     case 1:
1372     // download caches (no full details)
1373     this.download_caches_in_visible_view(false);
1374     return true;
1375     case 2:
1376     this.rose.zoom_in();
1377     return true;
1378     case 3:
1379     this.rose.zoom_out();
1380     return true;
1381     case 4:
1382     this.rose.change_map_type(MapDownloader.MAP_OSM);
1383     return true;
1384     case 5:
1385     this.rose.change_map_type(MapDownloader.MAP_BIM);
1386     return true;
1387     case 6:
1388     // dummy, do nothing!!
1389     // dummy, do nothing!!
1390     // dummy, do nothing!!
1391     // dummy, do nothing!!
1392     // dummy, do nothing!!
1393     return true;
1394     case 7:
1395     // drop table, and create new -> in DB
1396     this.pv._clear_database_();
1397     return true;
1398     case 8:
1399     this.set_display_screen(DISPLAY_VIEW_MAP);
1400     return true;
1401     case 9:
1402     // set as target -> map
1403     this.set_target();
1404     this.set_display_screen(DISPLAY_VIEW_MAP);
1405     return true;
1406     case 10:
1407     // set as target -> arrow
1408     this.set_target();
1409     this.set_display_screen(DISPLAY_VIEW_ARROW);
1410     return true;
1411     case 11:
1412     // cache view
1413     this.set_display_screen(DISPLAY_VIEW_GC);
1414     return true;
1415     case 12:
1416     // map view
1417     this.set_display_screen(DISPLAY_VIEW_MAP);
1418     return true;
1419     case 13:
1420     // toggle compass/gps heading
1421     this.global_settings.options_use_compass_heading = !this.global_settings.options_use_compass_heading;
1422     return true;
1423     case 14:
1424     // download gc-details again
1425     this.cacheview.details_loaded = 0;
1426     this.cacheview.download_details_thread_finished = false;
1427     this.cacheview.gc_name_previous = "";
1428     this.cacheview.need_repaint = true;
1429     this.cacheview.override_download = true;
1430     this.cacheview.invalidate();
1431     return true;
1432     case 15:
1433     // show description
1434     this.cacheview.show_field = GCacheView.SHOW_DESC;
1435     this.cacheview.need_repaint = true;
1436     this.cacheview.invalidate();
1437     return true;
1438     case 16:
1439     // show hints
1440     this.cacheview.show_field = GCacheView.SHOW_HINTS;
1441     this.cacheview.need_repaint = true;
1442     this.cacheview.invalidate();
1443     return true;
1444     case 17:
1445     // show logs
1446     this.cacheview.show_field = GCacheView.SHOW_LOGS;
1447     this.cacheview.need_repaint = true;
1448     this.cacheview.invalidate();
1449     return true;
1450     case 18:
1451     // show shortdesc
1452     this.cacheview.show_field = GCacheView.SHOW_SHORT_DESC;
1453     this.cacheview.need_repaint = true;
1454     this.cacheview.invalidate();
1455     return true;
1456     case 19:
1457     // set gc.com user/pass
1458     // save setting before we leave this activity!!
1459     this.save_settings();
1460     // ok startup the user/pass activity
1461     Intent foo = new Intent(this, TextEntryActivity.class);
1462     foo.putExtra("title", "Enter geocaching.com userdetails");
1463     foo.putExtra("username", this.global_settings.options_username);
1464     foo.putExtra("password", this.global_settings.options_password);
1465     this.startActivityForResult(foo, 7);
1466     return true;
1467     case 20:
1468     // download caches (with full details!)
1469     this.download_caches_in_visible_view(true);
1470     return true;
1471     case 21:
1472     // turn gps on
1473     this.turn_on_gps();
1474     this.cross.invalidate();
1475     this.arrowview.invalidate();
1476     return true;
1477     case 22:
1478     // turn gps off
1479     this.turn_off_gps();
1480     this.cross.invalidate();
1481     this.arrowview.invalidate();
1482     return true;
1483     case 23:
1484     // upload fieldnotes
1485     this.upload_fieldnotes();
1486     return true;
1487     case 24:
1488     // open fieldnote entry form
1489     // ok startup the activity
1490     Intent foo2 = new Intent(this, PostLogEntryActivity.class);
1491     foo2.putExtra("title", "Fieldnote for " + this.rose.current_target.name);
1492     Calendar cal = Calendar.getInstance();
1493     SimpleDateFormat sdf2 = new SimpleDateFormat("yyyy-MM-dd HH:mm");
1494     foo2.putExtra("msg", "\nTFTC\n" + sdf2.format(cal.getTime()) + "");
1495     this.startActivityForResult(foo2, 8);
1496     return true;
1497     case 25:
1498     // set "arrow" as current view
1499     this.set_display_screen(DISPLAY_VIEW_ARROW);
1500     return true;
1501     case 26:
1502     // toggle "turn map with heading"
1503     this.global_settings.options_turn_map_on_heading = !this.global_settings.options_turn_map_on_heading;
1504     return true;
1505     case 27:
1506     // select routefile
1507     this.get_route_files();
1508     return true;
1509     case 28:
1510     // download caches from route file
1511     if ((this.route_file_caches != null) && (this.route_file_caches.size() > 0))
1512     {
1513     showDialog(3);
1514     }
1515     else
1516     {
1517     Toast.makeText(getApplicationContext(), "No caches in Route!", Toast.LENGTH_SHORT).show();
1518     }
1519     return true;
1520     case 29:
1521     // map type open cycle maps
1522     this.rose.change_map_type(MapDownloader.MAP_OCM);
1523     return true;
1524     case 30:
1525     // call navigation intent to drive to target
1526     this.navigate_to_target();
1527     return true;
1528     case 31:
1529     // show gc cache page in browser
1530     this.show_cache_page_in_browser();
1531     return true;
1532     case 32:
1533     // change target coords lat
1534     if (this.rose.current_target != null)
1535     {
1536     this.change_target_coords_lat();
1537     }
1538     else
1539     {
1540     Toast.makeText(getApplicationContext(), "No target selected", Toast.LENGTH_SHORT).show();
1541     }
1542     return true;
1543     case 33:
1544     // change target coords lon
1545     if (this.rose.current_target != null)
1546     {
1547     this.change_target_coords_lon();
1548     }
1549     else
1550     {
1551     Toast.makeText(getApplicationContext(), "No target selected", Toast.LENGTH_SHORT).show();
1552     }
1553     return true;
1554     case 34:
1555     // show waypoints
1556     this.cacheview.show_field = GCacheView.SHOW_WAYPOINTS;
1557     this.cacheview.need_repaint = true;
1558     this.cacheview.invalidate();
1559     return true;
1560     default:
1561 zoffadmin 4 // return super.onOptionsItemSelected(item);
1562     return false;
1563 zoffadmin 2 }
1564     }
1565    
1566     public void toast_me(String in_text, int duration)
1567     {
1568     Toast.makeText(getApplicationContext(), in_text, duration).show();
1569     }
1570    
1571     public Coordinate pixmappoint2coord(int[] point)
1572     {
1573     Coordinate ret = null;
1574     ret = this.rose.num2deg(((double) point[0] + (double) (this.rose.map_center_x * this.rose.tile_size_x) - (double) (this.rose.mCanvasWidth / 2)) / (double) this.rose.tile_size_x, ((double) point[1] + (double) (this.rose.map_center_y * this.rose.tile_size_y) - (double) (this.rose.mCanvasHeight / 2)) / (double) this.rose.tile_size_y);
1575     return ret;
1576     }
1577    
1578     public void set_display_screen(int dt)
1579     {
1580 zoffadmin 4 try
1581 zoffadmin 2 {
1582 zoffadmin 4 switch (dt)
1583 zoffadmin 2 {
1584 zoffadmin 4 case DISPLAY_VIEW_MAP:
1585     // main map view
1586     if (!this.global_settings.options_use_compass_heading)
1587     {
1588     this.turn_off_compass();
1589     }
1590     else
1591     {
1592     this.turn_on_compass();
1593     }
1594     this.current_display_view = DISPLAY_VIEW_MAP;
1595 zoffadmin 2
1596 zoffadmin 4 arrowview.setVisibility(View.INVISIBLE);
1597     cacheview.setVisibility(View.INVISIBLE);
1598     rose.setVisibility(View.VISIBLE);
1599     gcview.setVisibility(View.VISIBLE);
1600     cross.setVisibility(View.VISIBLE);
1601     status_text.setVisibility(View.VISIBLE);
1602     wv.setVisibility(View.VISIBLE);
1603 zoffadmin 2
1604 zoffadmin 4 rose.bringToFront();
1605     gcview.bringToFront();
1606     cross.bringToFront();
1607     status_text.bringToFront();
1608     cross.invalidate();
1609     gcview.invalidate();
1610     status_text.invalidate();
1611 zoffadmin 2
1612 zoffadmin 4 break;
1613     case DISPLAY_VIEW_GC:
1614     // gc-view
1615     this.turn_off_compass();
1616     this.current_display_view = DISPLAY_VIEW_GC;
1617 zoffadmin 2
1618 zoffadmin 4 rose.setVisibility(View.INVISIBLE);
1619     gcview.setVisibility(View.INVISIBLE);
1620     cross.setVisibility(View.INVISIBLE);
1621     arrowview.setVisibility(View.INVISIBLE);
1622     wv.setVisibility(View.INVISIBLE);
1623     status_text.setVisibility(View.VISIBLE);
1624     cacheview.setVisibility(View.VISIBLE);
1625 zoffadmin 2
1626 zoffadmin 4 // make sure we dont start cachedownload immediately
1627     cacheview.override_download = true;
1628     cacheview.gc.desc = "please update details!!";
1629     cacheview.download_details_thread_finished = true;
1630     cacheview.details_loaded = 2;
1631     cacheview.get_gc_from_db = 1;
1632 zoffadmin 2
1633 zoffadmin 4 status_text.bringToFront();
1634     cacheview.bringToFront();
1635     cacheview.invalidate();
1636     status_text.invalidate();
1637 zoffadmin 2
1638 zoffadmin 4 break;
1639     case DISPLAY_VIEW_ARROW:
1640     // gc-view
1641     this.turn_on_compass();
1642     this.current_display_view = DISPLAY_VIEW_ARROW;
1643 zoffadmin 2
1644 zoffadmin 4 rose.setVisibility(View.INVISIBLE);
1645     gcview.setVisibility(View.INVISIBLE);
1646     cross.setVisibility(View.INVISIBLE);
1647     cacheview.setVisibility(View.INVISIBLE);
1648     wv.setVisibility(View.INVISIBLE);
1649     status_text.setVisibility(View.VISIBLE);
1650     arrowview.setVisibility(View.VISIBLE);
1651 zoffadmin 2
1652 zoffadmin 4 status_text.bringToFront();
1653     arrowview.bringToFront();
1654     arrowview.invalidate();
1655     status_text.invalidate();
1656 zoffadmin 2
1657 zoffadmin 4 break;
1658     }
1659 zoffadmin 2 }
1660 zoffadmin 4 catch (Exception e)
1661     {
1662     // catch all
1663     }
1664 zoffadmin 2 }
1665    
1666     public Coordinate[] get_visible_area()
1667     {
1668     Coordinate[] ret = new Coordinate[2];
1669     int[] ii = new int[2];
1670     ii[0] = -10;
1671     ii[1] = -10;
1672     // System.out.println(" " + ii[0] + " " + ii[1]);
1673     ret[0] = this.pixmappoint2coord(ii);
1674     // System.out.println(" " + ret[0]);
1675    
1676     ii[0] = this.rose.mCanvasWidth + 10;
1677     ii[1] = this.rose.mCanvasHeight + 10;
1678     // System.out.println(" " + ii[0] + " " + ii[1]);
1679     ret[1] = this.pixmappoint2coord(ii);
1680     // System.out.println(" " + ret[1]);
1681    
1682     return ret;
1683     }
1684    
1685     public Coordinate[] get_visible_area_large()
1686     {
1687     Coordinate[] ret = new Coordinate[2];
1688     int[] ii = new int[2];
1689     ii[0] = -60;
1690     ii[1] = -60;
1691     // System.out.println(" " + ii[0] + " " + ii[1]);
1692     ret[0] = this.pixmappoint2coord(ii);
1693     // System.out.println(" " + ret[0]);
1694    
1695     ii[0] = this.rose.mCanvasWidth + 60;
1696     ii[1] = this.rose.mCanvasHeight + 60;
1697     // System.out.println(" " + ii[0] + " " + ii[1]);
1698     ret[1] = this.pixmappoint2coord(ii);
1699     // System.out.println(" " + ret[1]);
1700    
1701     return ret;
1702     }
1703    
1704     // Sets screen rotation as fixed to current rotation setting
1705     public void mLockScreenRotation()
1706     {
1707     // Stop the screen orientation changing during an event
1708     switch (this.getResources().getConfiguration().orientation)
1709     {
1710     case Configuration.ORIENTATION_PORTRAIT:
1711     this.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
1712     break;
1713     case Configuration.ORIENTATION_LANDSCAPE:
1714     this.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
1715     break;
1716     }
1717     }
1718    
1719     // allow screen rotations again
1720     public void mUnlockScreenRotation()
1721     {
1722     this.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);
1723     }
1724    
1725     public void download_caches_in_visible_view(Boolean download_details)
1726     {
1727     if (download_details)
1728     {
1729     this.downloaded_caches = null;
1730     showDialog(2);
1731     }
1732     else
1733     {
1734     this.downloaded_caches = null;
1735     showDialog(0);
1736     }
1737     }
1738    
1739     public void set_bar(Handler h, String title, String text, int cur, int max, Boolean show)
1740     {
1741     Message msg = h.obtainMessage();
1742     Bundle b = new Bundle();
1743     b.putInt("max", max);
1744     b.putInt("cur", cur);
1745     b.putString("title", title);
1746     b.putString("text", text);
1747     b.putBoolean("show", true);
1748     msg.setData(b);
1749     h.sendMessage(msg);
1750     SystemClock.sleep(1);
1751     }
1752    
1753     public void set_bar_slow(Handler h, String title, String text, int cur, int max, Boolean show)
1754     {
1755     Message msg = h.obtainMessage();
1756     Bundle b = new Bundle();
1757     b.putInt("max", max);
1758     b.putInt("cur", cur);
1759     b.putString("title", title);
1760     b.putString("text", text);
1761     b.putBoolean("show", true);
1762     msg.setData(b);
1763     h.sendMessage(msg);
1764     SystemClock.sleep(50);
1765     }
1766    
1767     public void download_caches_from_route_file(Handler h)
1768     {
1769     if (this.route_file_caches == null)
1770     {
1771     return;
1772     }
1773    
1774     // dont go to sleep
1775     this.wl.acquire();
1776    
1777     int count_p = 0;
1778     int max_p = this.route_file_caches.size();
1779     this.mLockScreenRotation();
1780     set_bar(h, "get geocaches", "downloading caches from route file", 0, max_p, true);
1781    
1782     GeocacheCoordinate this_gc = null;
1783     int reopen_after = 30;
1784     int cur = 0;
1785    
1786     this.pv.begin_trans();
1787     try
1788     {
1789    
1790     for (int _cache = 0; _cache < this.route_file_caches.size(); _cache++)
1791     {
1792     this_gc = this.route_file_caches.get(_cache);
1793     set_bar(h, "get geocaches", "downloading caches from route file", _cache, max_p, true);
1794     this.pv.add_point(this_gc);
1795     this.cdol.update_coordinate(this_gc);
1796    
1797     cur++;
1798     if (cur > reopen_after)
1799     {
1800     this.pv.commit();
1801     this.pv.end_trans();
1802     this.pv.reopen_db();
1803     this.pv.begin_trans();
1804     cur = 0;
1805     }
1806    
1807     }
1808     this.pv.commit();
1809     }
1810     finally
1811     {
1812     this.pv.end_trans();
1813     }
1814     set_bar(h, "get geocaches", "finished", max_p, max_p, true);
1815     }
1816    
1817     public void download_caches_in_visible_view_wrapper(Handler h, Boolean download_details)
1818     {
1819     Coordinate[] location = this.get_visible_area();
1820     int count_p = 0;
1821     int max_p;
1822     if (this.rose.zoom > 11)
1823     {
1824     // this is just an estimate!! so that progressbar looks better
1825     max_p = (1 * 4) + (4 * 4);
1826     }
1827     else
1828     {
1829     max_p = (1 * 4) + (4 * 4) + (4 * 4 * 4);
1830     }
1831    
1832     // dont go to sleep
1833     this.wl.acquire();
1834     this.mLockScreenRotation();
1835    
1836     set_bar(h, "get geocaches", "downloading ...", 0, max_p, true);
1837    
1838     HTMLDownloader.get_geocaches_ret ps = null;
1839     ps = wdl.get_geocaches(location, count_p, max_p, 0, h, this.rose.zoom);
1840    
1841     set_bar(h, "get geocaches", "downloading ...", max_p, max_p, true);
1842    
1843     if (ps.points != null)
1844     {
1845    
1846     set_bar(h, "get geocaches", "inserting into DB ...", 0, ps.points.length, true);
1847    
1848     GeocacheCoordinate this_gc = null;
1849    
1850     int reopen_after = 30;
1851     int cur = 0;
1852    
1853     this.pv.begin_trans();
1854     try
1855     {
1856     for (int _cache = 0; _cache < ps.points.length; _cache++)
1857     {
1858     this_gc = ps.points[_cache];
1859     this.pv.add_point(this_gc);
1860     set_bar(h, "get geocaches", "inserting into DB ...", (_cache + 1), ps.points.length, true);
1861    
1862     cur++;
1863     if (cur > reopen_after)
1864     {
1865     this.pv.commit();
1866     this.pv.end_trans();
1867     this.pv.reopen_db();
1868     this.pv.begin_trans();
1869     cur = 0;
1870     }
1871    
1872     }
1873     this.pv.commit();
1874     }
1875     finally
1876     {
1877     this.pv.end_trans();
1878     }
1879    
1880     set_bar(h, "get geocaches", "inserting into DB ...", ps.points.length, ps.points.length, true);
1881    
1882     set_bar(h, "get geocaches", "parsing ...", 0, ps.points.length, true);
1883    
1884     this.downloaded_caches = new ArrayList<GeocacheCoordinate>();
1885     for (int _cache = 0; _cache < ps.points.length; _cache++)
1886     {
1887     this_gc = ps.points[_cache];
1888     this.downloaded_caches.add(this_gc);
1889     set_bar(h, "get geocaches", "parsing ...", (_cache + 1), ps.points.length, true);
1890     }
1891    
1892     if (download_details)
1893     {
1894     // now download cache details 1-by-1
1895     // this is going to be slow!!!!! so watch out!
1896    
1897     reopen_after = 15;
1898     cur = 0;
1899    
1900     long timestamp1 = 0;
1901     long timestamp2 = 0;
1902     float remain = 0;
1903     float timestamp3 = 0;
1904    
1905     timestamp1 = SystemClock.elapsedRealtime();
1906     this.pv.compact();
1907     set_bar(h, "get geocaches", "downloading details ...", 0, this.downloaded_caches.size(), true);
1908     this.pv.begin_trans();
1909     try
1910     {
1911    
1912     for (int _cache = 0; _cache < this.downloaded_caches.size(); _cache++)
1913     {
1914     timestamp2 = SystemClock.elapsedRealtime();
1915     this_gc = this.downloaded_caches.get(_cache);
1916     this.cdol.update_coordinate(this_gc);
1917    
1918     cur++;
1919     if (cur > reopen_after)
1920     {
1921     this.pv.commit();
1922     this.pv.end_trans();
1923     this.pv.reopen_db();
1924     this.pv.begin_trans();
1925     cur = 0;
1926     }
1927     timestamp3 = ((float) SystemClock.elapsedRealtime() - (float) timestamp2) / 1000f;
1928     remain = ((SystemClock.elapsedRealtime() - timestamp1) / (_cache + 1)) * (this.downloaded_caches.size() - (_cache + 1)) / 1000;
1929     set_bar(h, "get geocaches", String.format("this: %.1f s, remaining: %.0f s", timestamp3, remain), (_cache + 1), this.downloaded_caches.size(), true);
1930     }
1931     this.pv.commit();
1932     }
1933     finally
1934     {
1935     this.pv.end_trans();
1936     }
1937     set_bar(h, "get geocaches", "finished", this.downloaded_caches.size(), this.downloaded_caches.size(), true);
1938     }
1939     else
1940     {
1941     set_bar(h, "get geocaches", "finished", ps.points.length, ps.points.length, true);
1942     }
1943     }
1944     }
1945    
1946     public Handler toast_handler = new Handler()
1947     {
1948     @Override
1949     public void handleMessage(Message msg44)
1950     {
1951     if (msg44.getData().getInt("command") == 1)
1952     {
1953     toast_me(msg44.getData().getString("text"), msg44.getData().getInt("duration"));
1954     }
1955     }
1956     };
1957    
1958     public Handler dl_handler = new Handler()
1959     {
1960     @Override
1961     public void handleMessage(Message msg33)
1962     {
1963     // System.out.println("msg33");
1964     if (msg33.getData().getInt("command") == 1)
1965     {
1966     removeDialog(1);
1967     }
1968     else if (msg33.getData().getInt("command") == 2)
1969     {
1970     cacheview.invalidate();
1971     }
1972     else
1973     {
1974     showDialog(1);
1975     }
1976     }
1977     };
1978    
1979     private Handler progress_handler = new Handler()
1980     {
1981     public void handleMessage(Message msg22)
1982     {
1983     pbarDialog.setMax(msg22.getData().getInt("max"));
1984     pbarDialog.setProgress(msg22.getData().getInt("cur"));
1985     pbarDialog.setTitle(msg22.getData().getString("title"));
1986     pbarDialog.setMessage(msg22.getData().getString("text"));
1987     // System.out.println("msg: "
1988     // + msg22.getData().getInt("cur") + " "
1989     // + msg22.getData().getInt("max") + " "
1990     // + msg22.getData().getString("text"));
1991     // if (!msg22.getData().getBoolean("show"))
1992     // {
1993     // dismissDialog(0);
1994     // }
1995     }
1996     };
1997    
1998     Handler gcv_Refresh = new Handler()
1999     {
2000     @Override
2001     public void handleMessage(Message msg)
2002     {
2003     switch (msg.what)
2004     {
2005     case 0:
2006     // gcview.set_loaded_caches(downloaded_caches);
2007     rose.load_caches_from_db();
2008     break;
2009     }
2010     }
2011     };
2012    
2013     protected Dialog onCreateDialog(int id)
2014     {
2015     switch (id)
2016     {
2017     case 0:
2018     pbarDialog = new ProgressDialog(this);
2019     pbarDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
2020     pbarDialog.setTitle("--");
2021     pbarDialog.setMessage("--");
2022     pbarDialog.setCancelable(true);
2023     pbarDialog.setProgress(0);
2024     pbarDialog.setMax(200);
2025     progressThread = new ProgressThread(progress_handler, 0);
2026     progressThread.start();
2027     return pbarDialog;
2028     case 1:
2029     ProgressDialog xDialog = new ProgressDialog(this);
2030     // xDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
2031     xDialog.setTitle("Geocache");
2032     xDialog.setMessage("downloading details from internet");
2033     xDialog.setCancelable(false);
2034     xDialog.setIndeterminate(true);
2035     // xDialog.setProgress(0);
2036     // xDialog.setMax(1);
2037     return xDialog;
2038     case 2:
2039     pbarDialog = new ProgressDialog(this);
2040     pbarDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
2041     pbarDialog.setTitle("--");
2042     pbarDialog.setMessage("--");
2043     pbarDialog.setCancelable(true);
2044     pbarDialog.setProgress(0);
2045     pbarDialog.setMax(200);
2046     progressThread = new ProgressThread(progress_handler, 1);
2047     progressThread.start();
2048     return pbarDialog;
2049     case 3:
2050     pbarDialog = new ProgressDialog(this);
2051     pbarDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
2052     pbarDialog.setTitle("--");
2053     pbarDialog.setMessage("--");
2054     pbarDialog.setCancelable(true);
2055     pbarDialog.setProgress(0);
2056     pbarDialog.setMax(200);
2057     progressThread = new ProgressThread(progress_handler, 3);
2058     progressThread.start();
2059     return pbarDialog;
2060     default:
2061     return null;
2062     }
2063     }
2064    
2065     private class ProgressThread extends Thread
2066     {
2067     Handler mHandler;
2068     int with_details = 0;
2069    
2070     ProgressThread(Handler h, int with_details)
2071     {
2072     this.mHandler = h;
2073     this.with_details = with_details;
2074     }
2075    
2076     public void run()
2077     {
2078     try
2079     {
2080     pv.compact();
2081     }
2082     catch (Exception e)
2083     {
2084     e.printStackTrace();
2085     }
2086    
2087     if (with_details == 0)
2088     {
2089     download_caches_in_visible_view_wrapper(mHandler, false);
2090     dismissDialog(0);
2091     removeDialog(0);
2092     }
2093     else if (with_details == 1)
2094     {
2095     download_caches_in_visible_view_wrapper(mHandler, true);
2096     dismissDialog(2);
2097     removeDialog(2);
2098     }
2099     else if (with_details == 3)
2100     {
2101     download_caches_from_route_file(mHandler);
2102     dismissDialog(3);
2103     removeDialog(3);
2104     }
2105     // put the caches into the correct List
2106     gcv_Refresh.sendEmptyMessage(0);
2107     mUnlockScreenRotation();
2108     // allow sleep again
2109     wl.release();
2110     }
2111     }
2112    
2113     @Override
2114     public void onResume()
2115     {
2116     super.onResume();
2117 zoffadmin 4 System.out.println("AAGTL:main:resume");
2118 zoffadmin 2
2119     // mgpsl = new MyGPSListener();
2120    
2121     this.load_settings();
2122     this.wdl.loadCookies();
2123    
2124     if (mdl.running != true)
2125     {
2126     // System.out.println(mdl.getState());
2127     if (mdl.getState() == Thread.State.TERMINATED)
2128     {
2129     this.mdl = null;
2130     this.mdl = new MapDownloader(global_messageHandler, this);
2131     this.mdl.start();
2132     // System.out.println(mdl.getState());
2133     }
2134     }
2135    
2136     // assume we have no gps fix after resume
2137     isGPSFix = false;
2138    
2139     File dir1 = new File(this.db_path);
2140     File dir2 = new File(dir1.getParent());
2141     dir2.mkdirs();
2142     this.pv = null;
2143     this.pv = new PointProvider(this.db_path, this.mdl, "", "geocaches");
2144     // this.pv.set_filter("type='" + GeocacheCoordinate.TYPE_REGULAR + "'");
2145    
2146     // !!!!!!!!!!! DEVELOPMENT !!!!!!!!!!
2147     // !!!!!!!!!!! DEVELOPMENT !!!!!!!!!!
2148     // !!!!!!!!!!! DEVELOPMENT !!!!!!!!!!
2149     File dir3 = new File(dir2.toString() + "/zoff.txt");
2150     if (dir3.exists())
2151     {
2152     this.__ZOFF_PHONE__ = true;
2153     }
2154     // !!!!!!!!!!! DEVELOPMENT !!!!!!!!!!
2155     // !!!!!!!!!!! DEVELOPMENT !!!!!!!!!!
2156     // !!!!!!!!!!! DEVELOPMENT !!!!!!!!!!
2157    
2158     // start listening for GPS
2159     this.turn_on_locations();
2160    
2161     // start compass
2162     this.turn_on_compass();
2163    
2164     // System.out.println("x1=" + this.cacheview.gc_name_current);
2165     // System.out.println("x2=" + this.cacheview.gc_name_previous);
2166     // System.out.println("x3=" + this.cacheview.details_loaded);
2167     // System.out.println("x4=" + String.valueOf(this.cacheview.gc));
2168    
2169     this.rose.load_caches_from_db();
2170 zoffadmin 4 //this.rose.redraw_like_zoom();
2171 zoffadmin 2 }
2172    
2173     protected void onActivityResult(int requestCode, int resultCode, Intent data)
2174     {
2175     switch (requestCode)
2176     {
2177 zoffadmin 4 case EmulatedMenuActivity_id:
2178     try
2179     {
2180     if (resultCode == Activity.RESULT_OK)
2181     {
2182     int res_id = data.getIntExtra("selected_id", -1);
2183     if (res_id > -1)
2184     {
2185     try
2186     {
2187     Thread.sleep(200);
2188     }
2189     catch (Exception e2)
2190     {
2191    
2192     }
2193     onOptionsItemSelected_wrapper(res_id);
2194     }
2195     }
2196     }
2197     catch (Exception e)
2198     {
2199     }
2200     break;
2201 zoffadmin 2 case 7:
2202     try
2203     {
2204     String value = data.getStringExtra("username");
2205     if (value != null && value.length() > 0)
2206     {
2207     this.global_settings.options_username = value;
2208     // System.out.println("u=" + String.valueOf(value));
2209     }
2210    
2211     value = data.getStringExtra("password");
2212     if (value != null && value.length() > 0)
2213     {
2214     this.global_settings.options_password = value;
2215     // System.out.println("p=" + String.valueOf(value));
2216     }
2217     }
2218     catch (Exception e)
2219     {
2220     }
2221    
2222     this.save_settings();
2223    
2224     break;
2225     case 8:
2226     try
2227     {
2228     String value2 = data.getStringExtra("msg");
2229     int value3 = data.getIntExtra("logtype", GeocacheCoordinate.LOG_AS_FOUND);
2230    
2231     if (value2 != null && value2.length() > 0)
2232     {
2233     System.out.println("fieldnote=" + String.valueOf(value2));
2234     Calendar cal = Calendar.getInstance();
2235     SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm'Z'");
2236     sdf.setTimeZone(TimeZone.getTimeZone("UTC"));
2237     GeocacheCoordinate temp_gc = this.rose.current_target;
2238     System.out.println("temp_gc=" + String.valueOf(temp_gc));
2239     temp_gc.fieldnotes = value2;
2240     temp_gc.log_date = sdf.format(cal.getTime());
2241    
2242     // set according to selected value!!
2243     if (value3 == GeocacheCoordinate.LOG_AS_FOUND)
2244     {
2245     temp_gc.aagtl_status = GeocacheCoordinate.AAGTL_STATUS_FOUND;
2246     temp_gc.found = true;
2247     temp_gc.log_as = value3;
2248     }
2249     else if (value3 == GeocacheCoordinate.LOG_AS_NOTFOUND)
2250     {
2251     temp_gc.aagtl_status = GeocacheCoordinate.AAGTL_STATUS_NORMAL;
2252     temp_gc.found = false;
2253     temp_gc.log_as = value3;
2254     }
2255     else if (value3 == GeocacheCoordinate.LOG_AS_NOTE)
2256     {
2257     temp_gc.aagtl_status = GeocacheCoordinate.AAGTL_STATUS_NORMAL;
2258     temp_gc.found = false;
2259     temp_gc.log_as = value3;
2260     }
2261     // set according to selected value!!
2262    
2263     // System.out.println("v3=" + value3 + " f=" + temp_gc.found
2264     // + " as="
2265     // + temp_gc.aagtl_status);
2266    
2267     this.pv.reopen_db();
2268     this.pv.compact();
2269     this.pv.begin_trans();
2270     try
2271     {
2272     this.pv.add_point_fn(temp_gc);
2273     this.pv.commit();
2274     }
2275     finally
2276     {
2277     this.pv.end_trans();
2278     }
2279     this.pv.close();
2280     }
2281    
2282     }
2283     catch (Exception e)
2284     {
2285     System.out.println("Error saving fieldnote!");
2286     e.printStackTrace();
2287     }
2288    
2289     break;
2290     default:
2291     break;
2292     }
2293     }
2294    
2295     public void onClickXXX(DialogInterface d, int i)
2296     {
2297     // Perform action on clicks
2298     // Toast.makeText(HelloFormStuff.this, "Beep Bop",
2299     // Toast.LENGTH_SHORT).show();
2300     System.out.println("button pressed");
2301     }
2302    
2303     public void turn_on_compass()
2304     {
2305     try
2306     {
2307     sensorManager.registerListener(this, sensorManager.getDefaultSensor(Sensor.TYPE_ORIENTATION), SensorManager.SENSOR_DELAY_NORMAL);
2308     }
2309     catch (Exception e)
2310     {
2311     e.printStackTrace();
2312     }
2313     }
2314    
2315     public void turn_off_compass()
2316     {
2317     try
2318     {
2319     sensorManager.unregisterListener(this);
2320     }
2321     catch (Exception e)
2322     {
2323     e.printStackTrace();
2324     }
2325     }
2326    
2327     @Override
2328     protected void onPause()
2329     {
2330     // System.out.println(lx.getHeight());
2331     // System.out.println(rose.getHeight());
2332     // System.out.println(cross.getHeight());
2333     // System.out.println(status_text.getHeight());
2334    
2335 zoffadmin 4 System.out.println("AAGTL:main:pause");
2336 zoffadmin 2 // System.out.println("main: pause");
2337    
2338     // stop listening for GPS
2339     this.turn_off_locations();
2340     // stop compass
2341     this.turn_off_compass();
2342    
2343     this.save_settings();
2344     this.wdl.saveCookies();
2345    
2346     if (mdl != null)
2347     {
2348     mdl.interrupt();
2349     mdl.request_stop();
2350     try
2351     {
2352     mdl.join();
2353     // System.out.println(mdl.getState());
2354     // System.out.println("join mdl");
2355     }
2356     catch (InterruptedException e)
2357     {
2358     e.printStackTrace();
2359     }
2360     }
2361    
2362     // close sql db
2363     pv.compact();
2364     pv.close();
2365    
2366 zoffadmin 4 rose.free_stuff();
2367    
2368 zoffadmin 2 super.onPause();
2369     }
2370    
2371     public void turn_off_locations()
2372     {
2373     try
2374     {
2375     // stop listening (for any type of location)
2376     lm.removeUpdates(this);
2377     lm.removeGpsStatusListener(this);
2378     // we cant have a fix now
2379     isGPSFix = false;
2380     }
2381     catch (Exception e)
2382     {
2383     e.printStackTrace();
2384     }
2385     }
2386    
2387     public void turn_on_locations()
2388     {
2389     // start with GPS
2390     this.turn_on_gps();
2391     }
2392    
2393     public void turn_on_follow_mode()
2394     {
2395     this.follow_mode = true;
2396     this.follow_current = this.follow_on;
2397     }
2398    
2399     public void turn_off_follow_mode()
2400     {
2401     this.follow_mode = false;
2402     this.follow_current = this.follow_off;
2403     }
2404    
2405     public void turn_off_gps()
2406     {
2407     try
2408     {
2409    
2410     // stop listening for GPS
2411     lm.removeUpdates(this);
2412     lm.removeGpsStatusListener(this);
2413     // we cant have a fix now
2414     isGPSFix = false;
2415    
2416     // start listening for network location
2417     lm.requestLocationUpdates(this.low.getName(), 0L, 0f, this);
2418     }
2419     catch (Exception e)
2420     {
2421     e.printStackTrace();
2422     }
2423     }
2424    
2425     public void turn_on_gps()
2426     {
2427     try
2428     {
2429     // stop listening for network location
2430     lm.removeUpdates(this);
2431     // assume we have no gps fix after turing on gps
2432     isGPSFix = false;
2433    
2434     // start listening for GPS
2435     lm.requestLocationUpdates(this.high.getName(), 0L, 0f, this);
2436     lm.addGpsStatusListener(this);
2437     }
2438     catch (Exception e)
2439     {
2440     e.printStackTrace();
2441     }
2442     }
2443    
2444     public void onLocationChanged(Location location)
2445     {
2446     Boolean must_reload_caches_from_db = false;
2447    
2448     if (location == null) return;
2449    
2450     if (!follow_mode) return;
2451    
2452     // for external bluetooth GPS -----------------
2453     Boolean old_fix_status = isGPSFix;
2454     if (mLastLocation != null) isGPSFix = (SystemClock.elapsedRealtime() - mLastLocationMillis) < 3000;
2455     if (isGPSFix.compareTo(old_fix_status) != 0)
2456     {
2457     cross.invalidate();
2458     }
2459     mLastLocationMillis = SystemClock.elapsedRealtime();
2460     // for external bluetooth GPS -----------------
2461    
2462     mLastLocation = location;
2463     // check distance that we moved
2464     if ((cur_lat_gps_save == -1) || (cur_lon_gps_save == -1))
2465     {
2466     // System.out.println("gps 1");
2467     // first fix
2468     cur_lat_gps_save = location.getLatitude();
2469     cur_lon_gps_save = location.getLongitude();
2470     }
2471     else
2472     {
2473     // System.out.println("gps 2");
2474    
2475     // lat (48.2200 -> 48.2201) 0.0001 =~ 11.12m
2476     // lon (16.4000 -> 16.4002) 0.0002 =~ 14.82m
2477    
2478     double my_pos_delta_lat;
2479     double my_pos_delta_lon;
2480    
2481     my_pos_delta_lat = (double) (0.0001 * 4 * (20 - this.rose.zoom));
2482     my_pos_delta_lon = (double) (0.0002 * 4 * (20 - this.rose.zoom));
2483    
2484     // // lat,lon 1
2485     // Coordinate a = this.rose.num2deg(this.rose.map_center_x,
2486     // this.rose.map_center_y);
2487     // // lat,lon 2
2488     // Coordinate b = this.rose.num2deg(this.rose.map_center_x +
2489     // (this.rose.tile_size_x * 0.04),
2490     // this.rose.map_center_y + (this.rose.tile_size_y * 0.04));
2491     // // distance lat for 1 maptile (from pixel -> lat)
2492     // my_pos_delta_lat = Math.abs(b.lat - a.lat);
2493     // // distance lon for 1 maptile (from pixel -> lon)
2494     // my_pos_delta_lon = Math.abs(b.lon - a.lon);
2495     // // System.out.println("" + my_pos_delta_lat + " " +
2496     // my_pos_delta_lon);
2497    
2498     if (Math.abs(cur_lat_gps_save - location.getLatitude()) > my_pos_delta_lat)
2499     {
2500     // System.out.println("gps 3");
2501    
2502     must_reload_caches_from_db = true;
2503     // remember this location
2504     cur_lat_gps_save = location.getLatitude();
2505     cur_lon_gps_save = location.getLongitude();
2506     }
2507     else if (Math.abs(cur_lon_gps_save - location.getLongitude()) > my_pos_delta_lon)
2508     {
2509     // System.out.println("gps 4");
2510    
2511     must_reload_caches_from_db = true;
2512     // remember this location
2513     cur_lat_gps_save = location.getLatitude();
2514     cur_lon_gps_save = location.getLongitude();
2515     }
2516     }
2517    
2518     // update mapview
2519     this.rose.set_center(new Coordinate(location.getLatitude(), location.getLongitude()));
2520     this.rose.__calc_tiles_on_display();
2521     if (must_reload_caches_from_db)
2522     {
2523     // System.out.println("gps: reload caches from db");
2524     this.rose.load_caches_from_db();
2525     }
2526     if (this.current_display_view == DISPLAY_VIEW_MAP)
2527     {
2528     // System.out.println("iigc1");
2529     this.rose.main_object.gcview.invalidate();
2530     }
2531     this.rose.draw_me();
2532     // update mapview
2533    
2534     if (!this.global_settings.options_use_compass_heading)
2535     {
2536     // System.out.println("-> gps heading");
2537     this.cross.set_gps_heading(location.getBearing());
2538     }
2539    
2540     this.cross.set_gps_acc(location.getAccuracy());
2541     this.cross.invalidate();
2542    
2543     if (this.current_display_view == DISPLAY_VIEW_ARROW)
2544     {
2545     // now redraw arrow (if visible)
2546     this.arrowview.invalidate();
2547     }
2548    
2549     // status_text.setText(String.format("lat %.5f", location.getLatitude())
2550     // + " "
2551     // + String.format("lon %.5f", location.getLongitude()));
2552     this.change_status_text(String.format("lat %.5f", location.getLatitude()) + " " + String.format("lon %.5f", location.getLongitude()));
2553     // status_text.append(" " + String.format("%.1f",
2554     // this.rose.map_center_x) + " "
2555     // + String.format("%.1f", this.rose.map_center_y));
2556    
2557     // sb.append("Timestamp: ");
2558     // sb.append(location.getTime());
2559     // sb.append('\n');
2560    
2561     // System.out.println(sb.toString());
2562    
2563     }
2564    
2565     private Handler handle_status_text = new Handler()
2566     {
2567     public void handleMessage(Message msg)
2568     {
2569     Bundle b = msg.getData();
2570     int id = b.getInt("id");
2571     if (id == 0)
2572     {
2573     change_status_text_real(b.getString("text"));
2574     }
2575     else if (id == 1)
2576     {
2577     append_status_text_real(b.getString("text"));
2578     }
2579     }
2580     };
2581    
2582     public void change_status_text(String new_text)
2583     {
2584     Message msg = handle_status_text.obtainMessage();
2585     Bundle b = new Bundle();
2586     b.putString("text", new_text);
2587     b.putInt("id", 0);
2588     msg.setData(b);
2589     handle_status_text.sendMessage(msg);
2590     }
2591    
2592     public void change_status_text_real(String new_text)
2593     {
2594     this.status_text_string = new_text;
2595     status_text.setText(this.status_text_string + " " + this.status_append_string);
2596     this.status_text.postInvalidate();
2597     }
2598    
2599     public void append_status_text(String new_text)
2600     {
2601     Message msg = handle_status_text.obtainMessage();
2602     Bundle b = new Bundle();
2603     b.putString("text", new_text);
2604     b.putInt("id", 1);
2605     msg.setData(b);
2606     handle_status_text.sendMessage(msg);
2607     }
2608    
2609     public void append_status_text_real(String new_text)
2610     {
2611     this.status_append_string = new_text;
2612     status_text.setText(this.status_text_string + " " + this.status_append_string);
2613     this.status_text.postInvalidate();
2614     }
2615    
2616     public void onProviderDisabled(String provider)
2617     {
2618     // status_text.setText("onProviderDisabled");
2619     // System.out.println("onProviderDisabled");
2620     }
2621    
2622     public void onProviderEnabled(String provider)
2623     {
2624     // status_text.setText("onProviderEnabled");
2625     // System.out.println("onProviderEnabled");
2626     }
2627    
2628     public void onStatusChanged(String provider, int status, Bundle extras)
2629     {
2630     // status_text.setText("onStatusChanged " + String.valueOf(status) + " "
2631     // + extras.toString());
2632     // ** good ** // System.out.println("onStatusChanged " +
2633     // String.valueOf(status) + " " + extras.toString());
2634     // System.out.println(extras.toString());
2635     // GpsStatus.GPS_EVENT_SATELLITE_STATUS -> 4
2636     // GpsStatus.GPS_EVENT_STARTED -> 1
2637     // GpsStatus.GPS_EVENT_STOPPED; -> 2
2638     }
2639    
2640     public void onGpsStatusChanged(int event)
2641     {
2642     GpsStatus stat = lm.getGpsStatus(null);
2643     Iterable<GpsSatellite> iSatellites = stat.getSatellites();
2644     // System.out.println("" + String.valueOf(iSatellites.toString()));
2645     Iterator<GpsSatellite> it = iSatellites.iterator();
2646    
2647     int used_sats_new = 0;
2648     while (it.hasNext())
2649     {
2650     GpsSatellite oSat = (GpsSatellite) it.next();
2651     if (oSat.usedInFix())
2652     {
2653     used_sats_new++;
2654     }
2655     // System.out.println("SAT-info: " + oSat.toString());
2656     }
2657     if (this.used_sats != used_sats_new)
2658     {
2659     this.used_sats = used_sats_new;
2660     cross.set_used_sats(used_sats);
2661     cross.invalidate();
2662     }
2663    
2664     // for INTERNAL GPS -----------------
2665     Boolean old_fix_status = isGPSFix;
2666     switch (event)
2667     {
2668     case GpsStatus.GPS_EVENT_SATELLITE_STATUS:
2669     if (mLastLocation != null) isGPSFix = (SystemClock.elapsedRealtime() - mLastLocationMillis) < 3000;
2670    
2671     if (isGPSFix.compareTo(old_fix_status) != 0)
2672     {
2673     cross.invalidate();
2674     }
2675     old_fix_status = isGPSFix;
2676    
2677     if (isGPSFix)
2678     { // A fix has been acquired.
2679     // Do something.
2680     // System.out.println("FIX found ##");
2681     }
2682     else
2683     { // The fix has been lost.
2684     // Do something.
2685     // System.out.println("lost FIX ==");
2686     }
2687    
2688     break;
2689     case GpsStatus.GPS_EVENT_FIRST_FIX:
2690     // Do something.
2691     isGPSFix = true;
2692     // System.out.println("first FIX **");
2693    
2694     break;
2695     }
2696     // for INTERNAL GPS -----------------
2697     }
2698    
2699     public void upload_fieldnotes()
2700     {
2701     List<GeocacheCoordinate> caches = this.pv.get_new_fieldnotes();
2702     if ((caches == null) || (caches.size() == 0))
2703     {
2704     // no filednotes to upload
2705 zoffadmin 4 Message msg = this.toast_handler.obtainMessage();
2706     Bundle b = new Bundle();
2707     b.putInt("command", 1);
2708     b.putInt("duration", Toast.LENGTH_LONG);
2709     b.putString("text", "No Fieldnotes to upload");
2710     msg.setData(b);
2711     this.toast_handler.sendMessage(msg);
2712 zoffadmin 2 }
2713     else
2714     {
2715 zoffadmin 4 final Thread fn_uploader_thread = new Thread(new Runnable()
2716 zoffadmin 2 {
2717 zoffadmin 4 public void run()
2718     {
2719     List<GeocacheCoordinate> caches2 = pv.get_new_fieldnotes();
2720     FieldnotesUploader fu = new FieldnotesUploader(wdl, caches2);
2721     boolean ret = fu.upload();
2722     if (ret)
2723     {
2724     //Toast.makeText(getApplicationContext(), "" + caches2.size() + " Fieldnotes uploaded", Toast.LENGTH_SHORT).show();
2725     Message msg = toast_handler.obtainMessage();
2726     Bundle b = new Bundle();
2727     b.putInt("command", 1);
2728     b.putInt("duration", Toast.LENGTH_LONG);
2729     b.putString("text", "" + caches2.size() + " Fieldnotes uploaded");
2730     msg.setData(b);
2731     toast_handler.sendMessage(msg);
2732     }
2733     else
2734     {
2735     //Toast.makeText(getApplicationContext(), "Error while uploading Fieldnotes", Toast.LENGTH_SHORT).show();
2736     Message msg = toast_handler.obtainMessage();
2737     Bundle b = new Bundle();
2738     b.putInt("command", 1);
2739     b.putInt("duration", Toast.LENGTH_LONG);
2740     b.putString("text", "Error while uploading Fieldnotes");
2741     msg.setData(b);
2742     toast_handler.sendMessage(msg);
2743     }
2744     }
2745     });
2746     fn_uploader_thread.start();
2747 zoffadmin 2 }
2748     }
2749    
2750     public void get_route_files()
2751     {
2752     File folder = new File(this.main_dir + "/routes/");
2753     File[] listOfFiles = folder.listFiles();
2754     this.current_routefile_name = null;
2755     this.route_file_items = new CharSequence[listOfFiles.length + 1];
2756    
2757     for (int i = 0; i < listOfFiles.length; i++)
2758     {
2759     if (listOfFiles[i].isFile())
2760     {
2761     System.out.println("File " + listOfFiles[i].getName());
2762     // current_routefile_name = listOfFiles[i].getName();
2763     this.route_file_items[i] = listOfFiles[i].getName();
2764     }
2765     else if (listOfFiles[i].isDirectory())
2766     {
2767     // System.out.println("Directory " +
2768     // listOfFiles[i].getName());
2769     }
2770     }
2771     // this on to clear "routes"
2772     this.route_file_items[listOfFiles.length] = "--None--";
2773    
2774     AlertDialog.Builder builder = new AlertDialog.Builder(this);
2775     builder.setTitle("Pick a Routefile");
2776     builder.setItems(route_file_items, new DialogInterface.OnClickListener()
2777     {
2778     public void onClick(DialogInterface dialog, int j)
2779     {
2780     current_routefile_name = route_file_items[j].toString();
2781     System.out.println("crfn1=" + current_routefile_name);
2782     Toast.makeText(getApplicationContext(), "Routefile selected: " + route_file_items[j].toString(), Toast.LENGTH_SHORT).show();
2783    
2784     if (route_file_items[j].toString().equals("--None--"))
2785     {
2786     route_file_caches = null;
2787     pv.clear_filter();
2788     // load caches from DB, so that filter will be cleared
2789     rose.load_caches_from_db();
2790     return;
2791     }
2792    
2793     try
2794     {
2795     // Open the file
2796     FileInputStream fstream = new FileInputStream(main_dir + "/routes/" + current_routefile_name);
2797     // Get the object of DataInputStream
2798     DataInputStream in = new DataInputStream(fstream);
2799     BufferedReader br = new BufferedReader(new InputStreamReader(in));
2800     String strLine;
2801     route_file_caches = new ArrayList<GeocacheCoordinate>();
2802     route_file_caches.clear();
2803     String new_pv_filter = "";
2804     String sep = "";
2805     // Read File Line By Line
2806     while ((strLine = br.readLine()) != null)
2807     {
2808     strLine = strLine.trim();
2809     if (!strLine.equals(""))
2810     {
2811     // Print the content on the console
2812     // System.out.println(strLine);
2813     // add GC to global list for route caches
2814     route_file_caches.add(new GeocacheCoordinate(0.0, 0.0, strLine));
2815     new_pv_filter = new_pv_filter + sep + " name='" + strLine + "' ";
2816     if (sep.equals(""))
2817     {
2818     sep = " or ";
2819     }
2820     }
2821     }
2822     // Close the input stream
2823     in.close();
2824    
2825     // System.out.println("new filter=" + new_pv_filter);
2826     pv.set_filter(new_pv_filter);
2827     // load caches from DB, so that filter will be active
2828     rose.load_caches_from_db();
2829     }
2830     catch (Exception e)
2831     {
2832     // System.err.println("Error: " + e.getMessage());
2833     route_file_caches = null;
2834     pv.clear_filter();
2835     // load caches from DB, so that filter will be cleared
2836     rose.load_caches_from_db();
2837     }
2838     alert.dismiss();
2839     }
2840     });
2841     this.alert = builder.create();
2842     this.alert.show(); // this will return immediately!!
2843     }
2844    
2845     public void change_target_coords_lat()
2846     {
2847     int num1 = 0;
2848     int num2 = 0;
2849     int num3 = 0;
2850     Boolean ns_ew_toggle = true;
2851     String toggle_text_on = "N";
2852     String toggle_text_off = "S";
2853    
2854     Coordinate.coords_d_m_m conv = this.rose.current_target.d_to_dm_m();
2855     // Coordinate.dm_m_to_d(conv);
2856    
2857     num1 = conv.lat_deg;
2858     num2 = conv.lat_min;
2859     num3 = conv.lat_min_fractions;
2860     ns_ew_toggle = true;
2861     if (!conv.lat_plus_minus)
2862     {
2863     ns_ew_toggle = false;
2864    
2865     }
2866    
2867     this.show_geocoord_picker(true, num1, num2, num3, ns_ew_toggle, toggle_text_on, toggle_text_off);
2868     }
2869    
2870     public void change_target_coords_lon()
2871     {
2872     int num1 = 0;
2873     int num2 = 0;
2874     int num3 = 0;
2875     Boolean ns_ew_toggle = true;
2876     String toggle_text_on = "E";
2877     String toggle_text_off = "W";
2878    
2879     Coordinate.coords_d_m_m conv = this.rose.current_target.d_to_dm_m();
2880     // Coordinate.dm_m_to_d(conv);
2881    
2882     num1 = conv.lon_deg;
2883     num2 = conv.lon_min;
2884     num3 = conv.lon_min_fractions;
2885     ns_ew_toggle = true;
2886     if (!conv.lon_plus_minus)
2887     {
2888     ns_ew_toggle = false;
2889    
2890     }
2891    
2892     this.show_geocoord_picker(false, num1, num2, num3, ns_ew_toggle, toggle_text_on, toggle_text_off);
2893     }
2894    
2895     public void show_geocoord_picker(Boolean is_lat, int num1, int num2, int num3, Boolean toggle, String t_on, String t_off)
2896     {
2897     this.is_lat_current_change_target_coords = is_lat;
2898    
2899     xx1 = new NumberPicker(this);
2900     xx1.setFormatter(NumberPicker.THREE_DIGIT_FORMATTER);
2901     xx1.setRange(0, 999);
2902     xx1.setCurrent(num1);
2903     RelativeLayout.LayoutParams lp1 = new RelativeLayout.LayoutParams(150, RelativeLayout.LayoutParams.FILL_PARENT);
2904     lp1.topMargin = 20;
2905     lp1.leftMargin = 5;
2906     lp1.height = 200;
2907     lp1.width = (int) (this.rose.mCanvasWidth * 0.3); // calc width
2908     lp1.addRule(RelativeLayout.ALIGN_PARENT_TOP);
2909     mainscreen_map_view.addView(xx1, lp1);
2910    
2911     orient_1_toggle = new ToggleButton(this);
2912     RelativeLayout.LayoutParams otb_1 = new RelativeLayout.LayoutParams(150, RelativeLayout.LayoutParams.FILL_PARENT);
2913     orient_1_toggle.setChecked(toggle);
2914     if (toggle)
2915     {
2916     orient_1_toggle.setText(t_on);
2917     }
2918     else
2919     {
2920     orient_1_toggle.setText(t_off);
2921     }
2922     orient_1_toggle.setTextOff(t_off);
2923     orient_1_toggle.setTextOn(t_on);
2924     otb_1.topMargin = 20 + 2;
2925     otb_1.rightMargin = 1;
2926     otb_1.leftMargin = 4 + lp1.width;
2927     otb_1.height = 200 - 10;
2928     otb_1.width = 55;
2929     otb_1.addRule(RelativeLayout.ALIGN_PARENT_TOP);
2930     mainscreen_map_view.addView(orient_1_toggle, otb_1);
2931    
2932     // ToggleButton orient_2_toggle = new ToggleButton(this);
2933     // RelativeLayout.LayoutParams otb_2 = new
2934     // RelativeLayout.LayoutParams(150,
2935     // RelativeLayout.LayoutParams.FILL_PARENT);
2936     // orient_2_toggle.setChecked(false);
2937     // orient_2_toggle.setText("S");
2938     // orient_2_toggle.setTextOff("S");
2939     // orient_2_toggle.setTextOn("S");
2940     // otb_2.topMargin = 20 + 100;
2941     // otb_2.leftMargin = 5 + lp1.width;
2942     // otb_2.height = 100;
2943     // otb_2.width = 45;
2944     // otb_2.addRule(RelativeLayout.ALIGN_PARENT_TOP);
2945     // mainscreen_map_view.addView(orient_2_toggle, otb_2);
2946    
2947     xx2 = new NumberPicker(this);
2948     xx2.setFormatter(NumberPicker.TWO_DIGIT_FORMATTER);
2949     xx2.setRange(0, 99);
2950     xx2.setCurrent(num2);
2951     RelativeLayout.LayoutParams lp2 = new RelativeLayout.LayoutParams(150, RelativeLayout.LayoutParams.FILL_PARENT);
2952     lp2.rightMargin = 5;
2953     lp2.topMargin = 20;
2954     lp2.height = 200;
2955     lp2.leftMargin = lp1.width + 2 + 55; // width of other number picker
2956     lp2.width = 110;
2957     lp2.addRule(RelativeLayout.ALIGN_PARENT_TOP);
2958     mainscreen_map_view.addView(xx2, lp2);
2959    
2960     xx3 = new NumberPicker(this);
2961     xx3.setFormatter(NumberPicker.THREE_DIGIT_FORMATTER);
2962     xx3.setRange(0, 999);
2963     xx3.setCurrent(num3);
2964     RelativeLayout.LayoutParams lp3 = new RelativeLayout.LayoutParams(150, RelativeLayout.LayoutParams.FILL_PARENT);
2965     lp3.rightMargin = 5;
2966     lp3.topMargin = 20;
2967     lp3.height = 200;
2968     lp3.leftMargin = lp1.width + lp2.width + 2 + 55; // width of other
2969     // number picker
2970     lp3.width = this.rose.mCanvasWidth - lp1.width - lp2.width - 5 - 55; // take
2971     // rest
2972     // of
2973     // width
2974     lp3.addRule(RelativeLayout.ALIGN_PARENT_TOP);
2975     mainscreen_map_view.addView(xx3, lp3);
2976    
2977     RelativeLayout.LayoutParams bt_ok = new RelativeLayout.LayoutParams(150, RelativeLayout.LayoutParams.FILL_PARENT);
2978     btn_ok = new Button(this);
2979     bt_ok.width = ((int) (this.rose.mCanvasWidth * 0.4));
2980     bt_ok.height = 70;
2981     bt_ok.leftMargin = 5;
2982     bt_ok.topMargin = 20 + 3 + lp2.height;
2983     btn_ok.setText("OK");
2984     bt_ok.addRule(RelativeLayout.ALIGN_PARENT_TOP);
2985     this.btn_ok.setOnClickListener(new OnClickListener()
2986     {
2987     public void onClick(View v)
2988     {
2989     System.out.println("toggle=" + orient_1_toggle.isChecked());
2990     System.out.println("xx1=" + xx1.getCurrent());
2991     System.out.println("xx2=" + xx2.getCurrent());
2992     System.out.println("xx3=" + xx3.getCurrent());
2993    
2994     Coordinate ccc = new Coordinate(2, 2);
2995     Coordinate.coords_d_m_m conv2 = new Coordinate.coords_d_m_m();
2996     if (is_lat_current_change_target_coords)
2997     {
2998     conv2.lat_deg = xx1.getCurrent();
2999     conv2.lat_min = xx2.getCurrent();
3000     conv2.lat_min_fractions = xx3.getCurrent();
3001     if (orient_1_toggle.isChecked())
3002     {
3003     conv2.lat_plus_minus = true;
3004     conv2.lat_sign = "+";
3005     }
3006     else
3007     {
3008     conv2.lat_plus_minus = false;
3009     conv2.lat_sign = "-";
3010     }
3011     ccc = Coordinate.dm_m_to_d(conv2);
3012     ccc.lon = rose.current_target.lon;
3013     }
3014     else
3015     {
3016     conv2.lon_deg = xx1.getCurrent();
3017     conv2.lon_min = xx2.getCurrent();
3018     conv2.lon_min_fractions = xx3.getCurrent();
3019     if (orient_1_toggle.isChecked())
3020     {
3021     conv2.lon_plus_minus = true;
3022     conv2.lon_sign = "+";
3023     }
3024     else
3025     {
3026     conv2.lon_plus_minus = false;
3027     conv2.lon_sign = "-";
3028     }
3029     ccc = Coordinate.dm_m_to_d(conv2);
3030     ccc.lat = rose.current_target.lat;
3031     }
3032     System.out.println("ccc lat=" + ccc.lat);
3033     System.out.println("ccc lon=" + ccc.lon);
3034     // now set new target coords
3035     GeocacheCoordinate tmp_gc2 = new GeocacheCoordinate(ccc.lat, ccc.lon, "*GCmanual*");
3036     tmp_gc2.title = "*manual target";
3037     rose.current_target = tmp_gc2;
3038    
3039     mainscreen_map_view.removeView(btn_cancel);
3040     mainscreen_map_view.removeView(btn_ok);
3041     mainscreen_map_view.removeView(orient_1_toggle);
3042     mainscreen_map_view.removeView(xx1);
3043     mainscreen_map_view.removeView(xx2);
3044     mainscreen_map_view.removeView(xx3);
3045     }
3046     });
3047     mainscreen_map_view.addView(btn_ok, bt_ok);
3048    
3049     RelativeLayout.LayoutParams bt_cl = new RelativeLayout.LayoutParams(150, RelativeLayout.LayoutParams.FILL_PARENT);
3050     btn_cancel = new Button(this);
3051     bt_cl.width = ((int) (this.rose.mCanvasWidth * 0.4));
3052     bt_cl.height = 70;
3053     bt_cl.topMargin = 20 + 3 + lp2.height;
3054     bt_cl.leftMargin = this.rose.mCanvasWidth - 5 - bt_cl.width;
3055     bt_cl.rightMargin = 5;
3056     btn_cancel.setText("Cancel");
3057     bt_cl.addRule(RelativeLayout.ALIGN_PARENT_TOP);
3058     this.btn_cancel.setOnClickListener(new OnClickListener()
3059     {
3060     public void onClick(View v)
3061     {
3062     mainscreen_map_view.removeView(btn_cancel);
3063     mainscreen_map_view.removeView(btn_ok);
3064     mainscreen_map_view.removeView(orient_1_toggle);
3065     mainscreen_map_view.removeView(xx1);
3066     mainscreen_map_view.removeView(xx2);
3067     mainscreen_map_view.removeView(xx3);
3068     }
3069     });
3070     mainscreen_map_view.addView(btn_cancel, bt_cl);
3071     // mainscreen_map_view.removeView(btn_cancel);
3072     }
3073    
3074     public void navigate_to_target()
3075     {
3076     // save before starting new activity!!
3077     this.save_settings();
3078     try
3079     {
3080     // try to start navi. activity
3081     startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("google.navigation:q=" + this.rose.current_target.lat + "," + this.rose.current_target.lon)));
3082     }
3083     catch (Exception e)
3084     {
3085     // System.out.println("Error starting navigation");
3086     Toast.makeText(getApplicationContext(), "Error starting navigation!", Toast.LENGTH_SHORT).show();
3087     e.printStackTrace();
3088     }
3089     }
3090    
3091     public void show_cache_page_in_browser()
3092     {
3093     // save before starting new activity!!
3094    
3095     // http://www.geocaching.com/seek/cache_details.aspx?guid=b89040ae-5bca-4a14-960b-d9dcbe645d8a
3096     // or
3097     // http://www.geocaching.com/seek/cache_details.aspx?wp=GC2EVEY
3098    
3099     // System.out.println("1=" + this.cacheview.gc_name_current);
3100     // System.out.println("2=" + this.cacheview.gc_name_previous);
3101     // System.out.println("3=" + this.cacheview.details_loaded);
3102     // System.out.println("4=" + String.valueOf(this.cacheview.gc));
3103    
3104     this.save_settings();
3105     try
3106     {
3107     // try to start browser activity
3108     // old form, no more supported // startActivity(new
3109     // Intent(Intent.ACTION_VIEW,
3110     // ContentURI.create("http://www.myurl.com")));
3111     startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.geocaching.com/seek/cache_details.aspx?wp=" + cacheview.gc.name)));
3112     }
3113     catch (Exception e)
3114     {
3115     // System.out.println("Error starting navigation");
3116     Toast.makeText(getApplicationContext(), "Error starting Browser!", Toast.LENGTH_SHORT).show();
3117     e.printStackTrace();
3118     }
3119     }
3120    
3121     // @Override
3122     public boolean XXXXXXXXXXXXXXonKeyDown(int keyCode, KeyEvent event)
3123     {
3124     int i;
3125     String s = null;
3126     i = event.getUnicodeChar();
3127     System.out.println("onKeyDown " + keyCode + " " + i);
3128     if (i == 0)
3129     {
3130     if (keyCode == android.view.KeyEvent.KEYCODE_DEL)
3131     {
3132     s = java.lang.String.valueOf((char) 8);
3133     }
3134     else if (keyCode == android.view.KeyEvent.KEYCODE_MENU)
3135     {
3136     s = java.lang.String.valueOf((char) 1);
3137     return false;
3138     }
3139     else if (keyCode == android.view.KeyEvent.KEYCODE_SEARCH)
3140     {
3141     s = java.lang.String.valueOf((char) 19);
3142     }
3143     else if (keyCode == android.view.KeyEvent.KEYCODE_BACK)
3144     {
3145     s = java.lang.String.valueOf((char) 27);
3146     return false;
3147     }
3148     else if (keyCode == android.view.KeyEvent.KEYCODE_CALL)
3149     {
3150     s = java.lang.String.valueOf((char) 3);
3151     }
3152     else if (keyCode == android.view.KeyEvent.KEYCODE_VOLUME_UP)
3153     {
3154     s = java.lang.String.valueOf((char) 21);
3155     System.out.println("ss " + s);
3156     return false;
3157     }
3158     else if (keyCode == android.view.KeyEvent.KEYCODE_VOLUME_DOWN)
3159     {
3160     s = java.lang.String.valueOf((char) 4);
3161     System.out.println("ss " + s);
3162     return false;
3163     }
3164     else if (keyCode == android.view.KeyEvent.KEYCODE_DPAD_CENTER)
3165     {
3166     s = java.lang.String.valueOf((char) 13);
3167     }
3168     else if (keyCode == android.view.KeyEvent.KEYCODE_DPAD_DOWN)
3169     {
3170     s = java.lang.String.valueOf((char) 16);
3171     }
3172     else if (keyCode == android.view.KeyEvent.KEYCODE_DPAD_LEFT)
3173     {
3174     s = java.lang.String.valueOf((char) 2);
3175     }
3176     else if (keyCode == android.view.KeyEvent.KEYCODE_DPAD_RIGHT)
3177     {
3178     s = java.lang.String.valueOf((char) 6);
3179     }
3180     else if (keyCode == android.view.KeyEvent.KEYCODE_DPAD_UP)
3181     {
3182     s = java.lang.String.valueOf((char) 14);
3183     }
3184     }
3185     else if (i == 10)
3186     {
3187     s = java.lang.String.valueOf((char) 13);
3188     }
3189     else
3190     {
3191     s = java.lang.String.valueOf((char) i);
3192     }
3193     if (s != null)
3194     {
3195     // KeypressCallback(KeypressCallbackID, s);
3196     System.out.println("s: " + s);
3197     }
3198     return true;
3199     }
3200    
3201 zoffadmin 4 public static void logHeap(Class clazz)
3202     {
3203     // Double allocated = Double.valueOf(Debug.getNativeHeapAllocatedSize()) / Double.valueOf((1048576));
3204     // Double available = Double.valueOf(Debug.getNativeHeapSize() / 1048576.0);
3205     // Double free = Double.valueOf(Debug.getNativeHeapFreeSize() / 1048576.0);
3206     // DecimalFormat df = new DecimalFormat();
3207     // df.setMaximumFractionDigits(2);
3208     // df.setMinimumFractionDigits(2);
3209     //
3210     // Log.d("aagtl", "AAGTL:DEBUG: =================================");
3211     // Log.d("aagtl", "AAGTL:DEBUG:heap native: allocated " + df.format(allocated) + "MB of " + df.format(available) + "MB (" + df.format(free) + "MB free) in [" + clazz.getName().replaceAll("com.myapp.android.", "") + "]");
3212     // Log.d("aagtl", "AAGTL:DEBUG:memory: allocated: " + df.format(Double.valueOf(Runtime.getRuntime().totalMemory() / 1048576)) + "MB of " + df.format(Double.valueOf(Runtime.getRuntime().maxMemory() / 1048576)) + "MB (" + df.format(Double.valueOf(Runtime.getRuntime().freeMemory() / 1048576)) + "MB free)");
3213     }
3214    
3215     void add_to_emu_menu(int dummy, int id, int pos, String name)
3216     {
3217     EmulatedMenuActivity.MenuItemsList[pos] = name;
3218     EmulatedMenuActivity.MenuItemsIdMapping[pos] = id;
3219     }
3220    
3221     public void prepare_emu_options_menu()
3222     {
3223     switch (this.current_display_view)
3224     {
3225     case DISPLAY_VIEW_MAP:
3226     // main map view
3227    
3228     EmulatedMenuActivity.MenuItemsList = null;
3229     EmulatedMenuActivity.MenuItemsIdMapping = null;
3230     EmulatedMenuActivity.MenuItemsList = new String[20];
3231     EmulatedMenuActivity.MenuItemsIdMapping = new int[20];
3232    
3233     // g-id,i-id,order
3234     add_to_emu_menu(1, 2, 0, "zoom in");
3235     add_to_emu_menu(1, 3, 1, "zoom out");
3236    
3237     add_to_emu_menu(1, 4, 2, "maptype: OSM");
3238     if (__ZOFF_PHONE__)
3239     {
3240     add_to_emu_menu(1, 5, 3, "maptype: Sat");
3241     }
3242     else
3243     {
3244     add_to_emu_menu(1, 29, 3, "maptype: OCM");
3245     }
3246    
3247     add_to_emu_menu(1, 1, 4, "get caches in view");
3248     add_to_emu_menu(1, 20, 5, "get details in view");
3249    
3250     add_to_emu_menu(1, 21, 6, "turn on GPS");
3251     add_to_emu_menu(1, 22, 7, "turn off GPS");
3252     add_to_emu_menu(1, 25, 8, "show arrow view");
3253    
3254     add_to_emu_menu(1, 30, 9, "navigate to target");
3255     add_to_emu_menu(1, 32, 10, "change target lat.");
3256     add_to_emu_menu(1, 33, 11, "change target lon.");
3257    
3258     add_to_emu_menu(1, 27, 12, "select routefile");
3259     add_to_emu_menu(1, 28, 13, "get caches from routefile");
3260     add_to_emu_menu(1, 23, 14, "upload fieldnotes");
3261     if (this.global_settings.options_turn_map_on_heading)
3262     {
3263     add_to_emu_menu(1, 26, 15, "turn off rotating map");
3264     }
3265     else
3266     {
3267     add_to_emu_menu(1, 26, 15, "turn on rotating map");
3268     }
3269    
3270     add_to_emu_menu(1, 6, 16, "-");
3271     add_to_emu_menu(1, 19, 17, "set username/password");
3272     add_to_emu_menu(1, 6, 18, "-");
3273     add_to_emu_menu(1, 7, 19, "empty database");
3274    
3275     break;
3276     case DISPLAY_VIEW_GC:
3277     // gc-view
3278     EmulatedMenuActivity.MenuItemsList = null;
3279     EmulatedMenuActivity.MenuItemsIdMapping = null;
3280     EmulatedMenuActivity.MenuItemsList = new String[10];
3281     EmulatedMenuActivity.MenuItemsIdMapping = new int[10];
3282    
3283     // g-id,i-id,order
3284     add_to_emu_menu(1, 8, 0, "map view");
3285     add_to_emu_menu(1, 14, 1, "update details");
3286     add_to_emu_menu(1, 9, 2, "set as target -> map");
3287     add_to_emu_menu(1, 10, 3, "set as target -> arrow");
3288     add_to_emu_menu(1, 15, 4, "description");
3289     add_to_emu_menu(1, 16, 5, "hints");
3290     add_to_emu_menu(1, 17, 6, "logs");
3291     add_to_emu_menu(1, 34, 7, "waypoints");
3292     add_to_emu_menu(1, 18, 8, "shorttext");
3293     add_to_emu_menu(1, 31, 9, "show Cache website");
3294     // seems to be buggy, so for the moment remove it
3295     // if (this.rose.current_target != null)
3296     // {
3297     // add_to_emu_menu(1, 24, 36, "post fieldnote");
3298     // }
3299     break;
3300     case DISPLAY_VIEW_ARROW:
3301     // arrow view
3302     EmulatedMenuActivity.MenuItemsList = null;
3303     EmulatedMenuActivity.MenuItemsIdMapping = null;
3304     int num = 3;
3305     if (this.rose.current_target != null)
3306     {
3307     num = 4;
3308     }
3309     EmulatedMenuActivity.MenuItemsList = new String[num];
3310     EmulatedMenuActivity.MenuItemsIdMapping = new int[num];
3311    
3312     // g-id,i-id,order
3313     add_to_emu_menu(1, 11, 0, "cache view");
3314     add_to_emu_menu(1, 12, 1, "map view");
3315     String st_compass = "use compass heading";
3316     if (this.global_settings.options_use_compass_heading)
3317     {
3318     st_compass = "use gps heading";
3319    
3320     }
3321     add_to_emu_menu(1, 13, 2, st_compass);
3322     if (this.rose.current_target != null)
3323     {
3324     add_to_emu_menu(1, 24, 3, "post fieldnote");
3325     }
3326     break;
3327     }
3328    
3329     }
3330    
3331     public void openOptionsMenu_wrapper()
3332     {
3333     // ------ old ---------
3334     //openOptionsMenu();
3335     // ------ old ---------
3336    
3337     //Intent emualted_menu_activity = new Intent(this, EmulatedMenuActivity.class);
3338     //this.startActivityForResult(emualted_menu_activity, EmulatedMenuActivity_id);
3339     prepare_emu_options_menu();
3340     emu_menu_view.set_adapter(EmulatedMenuActivity.MenuItemsList, EmulatedMenuActivity.MenuItemsIdMapping);
3341     emu_menu_view.bringToFront();
3342     emu_menu_view.setVisibility(View.VISIBLE);
3343     }
3344    
3345     public static int dp_to_px(int dp)
3346     {
3347     return (int) (((float) dp * Global_dpi_factor) + 0.5);
3348     }
3349    
3350     public static int px_to_dp(int px)
3351     {
3352     return (int) (((float) px / Global_dpi_factor) + 0.5);
3353     }
3354 zoffadmin 2 }

   
Visit the aagtl Website