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

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

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

Revision 3 Revision 4
1/** 1/**
2 * aagtl Advanced Geocaching Tool for Android 2 * aagtl Advanced Geocaching Tool for Android
3 * loosely based on agtl by Daniel Fett <fett@danielfett.de> 3 * loosely based on agtl by Daniel Fett <fett@danielfett.de>
4 * Copyright (C) 2010 - 2012 Zoff <aagtl@work.zoff.cc> 4 * Copyright (C) 2010 - 2013 Zoff <aagtl@work.zoff.cc>
5 * 5 *
6 * This program is free software; you can redistribute it and/or 6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License 7 * modify it under the terms of the GNU General Public License
8 * version 2 as published by the Free Software Foundation. 8 * version 2 as published by the Free Software Foundation.
9 * 9 *
43import java.util.Iterator; 43import java.util.Iterator;
44import java.util.List; 44import java.util.List;
45import java.util.Locale; 45import java.util.Locale;
46import java.util.TimeZone; 46import java.util.TimeZone;
47 47
48import android.annotation.SuppressLint;
48import android.app.Activity; 49import android.app.Activity;
49import android.app.AlertDialog; 50import android.app.AlertDialog;
50import android.app.Dialog; 51import android.app.Dialog;
51import android.app.ProgressDialog; 52import android.app.ProgressDialog;
52import android.content.Context; 53import android.content.Context;
87import android.view.KeyEvent; 88import android.view.KeyEvent;
88import android.view.Menu; 89import android.view.Menu;
89import android.view.MenuItem; 90import android.view.MenuItem;
90import android.view.View; 91import android.view.View;
91import android.view.View.OnClickListener; 92import android.view.View.OnClickListener;
93import android.view.ViewConfiguration;
92import android.webkit.WebSettings; 94import android.webkit.WebSettings;
93import android.webkit.WebView; 95import android.webkit.WebView;
94import android.widget.Button; 96import android.widget.Button;
95import android.widget.RelativeLayout; 97import android.widget.RelativeLayout;
96import android.widget.TextView; 98import android.widget.TextView;
102public class aagtl extends Activity implements LocationListener, GpsStatus.Listener, SensorEventListener 104public class aagtl extends Activity implements LocationListener, GpsStatus.Listener, SensorEventListener
103// ,OnClickListener 105// ,OnClickListener
104{ 106{
105 107
106 static final boolean EMULATOR = false; 108 static final boolean EMULATOR = false;
109 static final boolean DEVELOPER_MODE = false;
107 110
108 static final boolean _RELEASE_ = true; 111 static final boolean _RELEASE_ = true;
109 boolean __ZOFF_PHONE__ = false; 112 boolean __ZOFF_PHONE__ = false;
113
114 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;
110 117
111 // OSD buttons/icons -------- START ----------- 118 // OSD buttons/icons -------- START -----------
112 public Bitmap follow_on = null; 119 public Bitmap follow_on = null;
113 public Bitmap follow_off = null; 120 public Bitmap follow_off = null;
114 public Bitmap follow_current = null; 121 public Bitmap follow_current = null;
115 public Boolean follow_mode = true; 122 public Boolean follow_mode = true;
116 public RectF follow_button_rect = new RectF(-100, 1, 1, 1); 123 public RectF follow_button_rect = new RectF(-100, 1, 1, 1);
117 124
118 public Bitmap arrow_button = null; 125 public Bitmap arrow_button = null;
119 public RectF arrow_button_rect = new RectF(-100, 1, 1, 1); 126 public RectF arrow_button_rect = new RectF(-100, 1, 1, 1);
127
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;
120 // OSD buttons/icons -------- END ----------- 133 // OSD buttons/icons -------- END -----------
121 134
122 Button btn_ok = null; 135 Button btn_ok = null;
123 Button btn_cancel = null; 136 Button btn_cancel = null;
124 ToggleButton orient_1_toggle = null; 137 ToggleButton orient_1_toggle = null;
131 private Handler global_messageHandler = new Handler(); 144 private Handler global_messageHandler = new Handler();
132 145
133 ProgressThread progressThread; 146 ProgressThread progressThread;
134 ProgressDialog pbarDialog; 147 ProgressDialog pbarDialog;
135 148
136 public String main_dir = "/sdcard/zoffcc/applications/aagtl"; 149 public String main_dir = "/tmp/";
137 public String main_data_dir = "/sdcard/external_sd/zoffcc/applications/aagtl"; 150 public String main_data_dir = "/tmp/";
138 151
139 public String status_text_string = ""; 152 public String status_text_string = "";
140 public String status_append_string = ""; 153 public String status_append_string = "";
141 154
142 Location mLastLocation = null; 155 Location mLastLocation = null;
162 static final int DISPLAY_VIEW_ARROW = 3; 175 static final int DISPLAY_VIEW_ARROW = 3;
163 176
164 private Boolean show_no_loc_warning = false; 177 private Boolean show_no_loc_warning = false;
165 178
166 public int current_display_view = DISPLAY_VIEW_MAP; 179 public int current_display_view = DISPLAY_VIEW_MAP;
167 static int TOUCH_CACHES_AFTER_THIS_ZOOM_LEVEL = 16; 180 static int TOUCH_CACHES_AFTER_THIS_ZOOM_LEVEL = 13;
168 181
169 public CharSequence[] route_file_items = null; 182 public CharSequence[] route_file_items = null;
170 public String current_routefile_name = null; 183 public String current_routefile_name = null;
171 public List<GeocacheCoordinate> route_file_caches = null; 184 public List<GeocacheCoordinate> route_file_caches = null;
172 public AlertDialog alert = null; 185 public AlertDialog alert = null;
173 186
187 public EmulatedMenuView emu_menu_view;
174 public Rose rose; 188 public Rose rose;
175 public CrossHair cross; 189 public CrossHair cross;
176 public GeocachesView gcview; 190 public GeocachesView gcview;
177 public ArrowView arrowview; 191 public ArrowView arrowview;
178 public GCacheView cacheview; 192 public GCacheView cacheview;
179 public RelativeLayout mainscreen_map_view; 193 public RelativeLayout mainscreen_map_view;
180 public int mainscreen_map_view_statusbar_height = 30; 194 public int mainscreen_map_view_statusbar_height = 30;
181 public RelativeLayout.LayoutParams layoutParams_mainscreen_map_view; 195 public RelativeLayout.LayoutParams layoutParams_mainscreen_map_view;
182 public TextView status_text; 196 public TextView status_text;
183 public WebView wv; 197 public WebView wv;
198 final int EmulatedMenuActivity_id = 997;
184 199
185 public double cur_lat_gps_save = -1; 200 public double cur_lat_gps_save = -1;
186 public double cur_lon_gps_save = -1; 201 public double cur_lon_gps_save = -1;
187 202
188 public String db_path; 203 public String db_path;
598 { 613 {
599 global_settings.map_position_lat = lat; 614 global_settings.map_position_lat = lat;
600 global_settings.map_position_lon = lon; 615 global_settings.map_position_lon = lon;
601 } 616 }
602 617
618 @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
603 @Override 672 @Override
604 protected void onCreate(Bundle savedInstanceState) 673 protected void onCreate(Bundle savedInstanceState)
605 { 674 {
675 wrap_strict_mode();
676
606 super.onCreate(savedInstanceState); 677 super.onCreate(savedInstanceState);
678
679 System.out.println("AAGTL:main:create");
607 680
608 // choose the correct volume to change (for TTS) 681 // choose the correct volume to change (for TTS)
609 // setVolumeControlStream(AudioManager.STREAM_SYSTEM); 682 // setVolumeControlStream(AudioManager.STREAM_SYSTEM);
610 // setVolumeControlStream(AudioManager.STREAM_NOTIFICATION); 683 // setVolumeControlStream(AudioManager.STREAM_NOTIFICATION);
611 setVolumeControlStream(AudioManager.STREAM_MUSIC); // --> this seems to 684 setVolumeControlStream(AudioManager.STREAM_MUSIC); // --> this seems to
614 687
615 String default_sdcard_dir = Environment.getExternalStorageDirectory().getAbsolutePath(); 688 String default_sdcard_dir = Environment.getExternalStorageDirectory().getAbsolutePath();
616 Log.e("aagtl", "sdcard dir=" + default_sdcard_dir); 689 Log.e("aagtl", "sdcard dir=" + default_sdcard_dir);
617 690
618 main_dir = default_sdcard_dir + "/zoffcc/applications/aagtl"; 691 main_dir = default_sdcard_dir + "/zoffcc/applications/aagtl";
619 main_data_dir = default_sdcard_dir + "/external_sd/zoffcc/applications/aagtl"; 692 main_data_dir = default_sdcard_dir + "/zoffcc/applications/aagtl";
693
694 // detect if device has a real menu button
695 detect_menu_button();
620 696
621 // get the local language ------------- 697 // get the local language -------------
622 Locale locale = java.util.Locale.getDefault(); 698 Locale locale = java.util.Locale.getDefault();
623 String lang = locale.getLanguage(); 699 String lang = locale.getLanguage();
624 String langu = lang; 700 String langu = lang;
731 { 807 {
732 // get location services 808 // get location services
733 // lm = LocationUtils.getLocationManager(ctx.getMyContext()); 809 // lm = LocationUtils.getLocationManager(ctx.getMyContext());
734 this.lm = (LocationManager) getSystemService(LOCATION_SERVICE); 810 this.lm = (LocationManager) getSystemService(LOCATION_SERVICE);
735 // get low accuracy provider 811 // get low accuracy provider
812 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 //
736 this.low = lm.getProvider(lm.getBestProvider(createCoarseCriteria(), true)); 819 this.low = lm.getProvider(lm.getBestProvider(lowCriteria, false));
820 System.out.println("AAGTL:fast location=" + this.low.getName());
737 821
738 // get high accuracy provider 822 // get high accuracy provider
739 this.high = lm.getProvider(lm.getBestProvider(createFineCriteria(), true)); 823 this.high = lm.getProvider(lm.getBestProvider(createFineCriteria(), false));
824 System.out.println("AAGTL:accurate location=" + this.high.getName());
740 // ++++++ lm.requestLocationUpdates(LocationManager.GPS_PROVIDER, 700L, 825 // ++++++ lm.requestLocationUpdates(LocationManager.GPS_PROVIDER, 700L,
741 // 1.0f, this); 826 // 1.0f, this);
742 827
743 if (!EMULATOR) 828 if (!EMULATOR)
744 { 829 {
804 display_.getMetrics(this.metrics); 889 display_.getMetrics(this.metrics);
805 Log.e("aagtl", "aagtl -> pixels x=" + width_ + " pixels y=" + height_); 890 Log.e("aagtl", "aagtl -> pixels x=" + width_ + " pixels y=" + height_);
806 Log.e("aagtl", "aagtl -> dpi=" + this.metrics.densityDpi); 891 Log.e("aagtl", "aagtl -> dpi=" + this.metrics.densityDpi);
807 Log.e("aagtl", "aagtl -> density=" + this.metrics.density); 892 Log.e("aagtl", "aagtl -> density=" + this.metrics.density);
808 Log.e("aagtl", "aagtl -> scaledDensity=" + this.metrics.scaledDensity); 893 Log.e("aagtl", "aagtl -> scaledDensity=" + this.metrics.scaledDensity);
894
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
809 // get display properties 900 // get display properties
810 901
811 System.out.println("Create: " + String.valueOf(savedInstanceState)); 902 System.out.println("Create: " + String.valueOf(savedInstanceState));
812 if (savedInstanceState != null) 903 if (savedInstanceState != null)
813 { 904 {
817 this.load_settings(); 908 this.load_settings();
818 909
819 // Set full screen view 910 // Set full screen view
820 // getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, 911 // getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
821 // WindowManager.LayoutParams.FLAG_FULLSCREEN); 912 // WindowManager.LayoutParams.FLAG_FULLSCREEN);
822 getWindow().setFlags(0, 0); 913 // ** getWindow().setFlags(0, 0);
823 // requestWindowFeature(Window.FEATURE_NO_TITLE); 914 // ** requestWindowFeature(Window.FEATURE_NO_TITLE);
824 requestWindowFeature(0); 915 //requestWindowFeature(0);
825 916
826 // System.out.println("CR map_position_lat:" + 917 // System.out.println("CR map_position_lat:" +
827 // String.valueOf(global_settings.map_position_lat)); 918 // String.valueOf(global_settings.map_position_lat));
828 // System.out.println("CR map_position_lon:" + 919 // System.out.println("CR map_position_lon:" +
829 // String.valueOf(global_settings.map_position_lon)); 920 // String.valueOf(global_settings.map_position_lon));
878 mainscreen_map_view.addView(status_text, tvlp); 969 mainscreen_map_view.addView(status_text, tvlp);
879 970
880 this.wv = new WebView(this); 971 this.wv = new WebView(this);
881 this.wv.getSettings().setSupportZoom(true); 972 this.wv.getSettings().setSupportZoom(true);
882 this.wv.getSettings().setBuiltInZoomControls(true); 973 this.wv.getSettings().setBuiltInZoomControls(true);
974 //this.wv.getSettings().setDefaultFontSize((int) (13f * aagtl.Global_dpi_factor));
883 this.wv.getSettings().setDefaultFontSize(13); 975 this.wv.getSettings().setDefaultFontSize((int) (13f * 1));
884 976
885 // zoom seems to be NULL on some systems (e.g. honeycomb) 977 // zoom seems to be NULL on some systems (e.g. honeycomb)
886 final View zoom = this.wv.getZoomControls(); 978 //final View zoom = this.wv.getZoomControls();
887 979
888 try 980 //try
889 { 981 //{
890 zoom.setVisibility(View.INVISIBLE); 982 // zoom.setVisibility(View.INVISIBLE);
891 } 983 //}
892 catch (Exception e) 984 //catch (Exception e)
893 { 985 //{
894 e.printStackTrace(); 986 // e.printStackTrace();
895 } 987 //}
896 988
897 this.wv.getSettings().setDefaultZoom(WebSettings.ZoomDensity.MEDIUM); 989 this.wv.getSettings().setDefaultZoom(WebSettings.ZoomDensity.MEDIUM);
898 RelativeLayout.LayoutParams wvlp = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.FILL_PARENT, RelativeLayout.LayoutParams.FILL_PARENT); 990 RelativeLayout.LayoutParams wvlp = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.FILL_PARENT, RelativeLayout.LayoutParams.FILL_PARENT);
899 mainscreen_map_view.addView(wv, wvlp); 991 mainscreen_map_view.addView(wv, wvlp);
900 992
908 RelativeLayout.LayoutParams avlp = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.FILL_PARENT, RelativeLayout.LayoutParams.FILL_PARENT); 1000 RelativeLayout.LayoutParams avlp = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.FILL_PARENT, RelativeLayout.LayoutParams.FILL_PARENT);
909 1001
910 cacheview = new GCacheView(this, this); 1002 cacheview = new GCacheView(this, this);
911 RelativeLayout.LayoutParams cvlp = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.FILL_PARENT, RelativeLayout.LayoutParams.FILL_PARENT); 1003 RelativeLayout.LayoutParams cvlp = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.FILL_PARENT, RelativeLayout.LayoutParams.FILL_PARENT);
912 1004
1005 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
913 // get the png's 1009 // get the png's
1010 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 {
914 this.follow_on = BitmapFactory.decodeResource(getResources(), R.drawable.follow); 1020 this.follow_on = BitmapFactory.decodeResource(getResources(), R.drawable.follow);
915 this.follow_off = BitmapFactory.decodeResource(getResources(), R.drawable.follow_off); 1021 this.follow_off = BitmapFactory.decodeResource(getResources(), R.drawable.follow_off);
916 this.follow_current = this.follow_on; 1022 this.follow_current = this.follow_on;
917 this.arrow_button = BitmapFactory.decodeResource(getResources(), R.drawable.arrow_off); 1023 this.arrow_button = BitmapFactory.decodeResource(getResources(), R.drawable.arrow_off);
1024 this.menu_button = BitmapFactory.decodeResource(getResources(), R.drawable.menu_001_small);
1025 }
918 1026
919 chlp.bottomMargin = mainscreen_map_view_statusbar_height; 1027 chlp.bottomMargin = mainscreen_map_view_statusbar_height;
920 gcwlp.bottomMargin = mainscreen_map_view_statusbar_height; 1028 gcwlp.bottomMargin = mainscreen_map_view_statusbar_height;
921 avlp.bottomMargin = mainscreen_map_view_statusbar_height; 1029 avlp.bottomMargin = mainscreen_map_view_statusbar_height;
922 cvlp.bottomMargin = mainscreen_map_view_statusbar_height; 1030 cvlp.bottomMargin = mainscreen_map_view_statusbar_height;
924 wvlp.topMargin = 80 + 4 * 40; 1032 wvlp.topMargin = 80 + 4 * 40;
925 mainscreen_map_view.addView(cross, chlp); 1033 mainscreen_map_view.addView(cross, chlp);
926 mainscreen_map_view.addView(gcview, gcwlp); 1034 mainscreen_map_view.addView(gcview, gcwlp);
927 mainscreen_map_view.addView(arrowview, avlp); 1035 mainscreen_map_view.addView(arrowview, avlp);
928 mainscreen_map_view.addView(cacheview, cvlp); 1036 mainscreen_map_view.addView(cacheview, cvlp);
1037 mainscreen_map_view.addView(emu_menu_view, emvlp);
929 // ------- MAP VIEW: CREATE ------- 1038 // ------- MAP VIEW: CREATE -------
930 1039
931 // ------- VIEWS ------- 1040 // ------- VIEWS -------
932 // make correct Z-order 1041 // make correct Z-order
933 rose.bringToFront(); 1042 rose.bringToFront();
936 status_text.bringToFront(); 1045 status_text.bringToFront();
937 wv.bringToFront(); 1046 wv.bringToFront();
938 arrowview.setVisibility(View.INVISIBLE); 1047 arrowview.setVisibility(View.INVISIBLE);
939 cacheview.setVisibility(View.INVISIBLE); 1048 cacheview.setVisibility(View.INVISIBLE);
940 wv.setVisibility(View.INVISIBLE); 1049 wv.setVisibility(View.INVISIBLE);
1050 emu_menu_view.bringToFront();
1051 emu_menu_view.setVisibility(View.INVISIBLE);
941 setContentView(mainscreen_map_view); 1052 setContentView(mainscreen_map_view);
942 // ------- VIEWS ------- 1053 // ------- VIEWS -------
943 1054
944 // ------- set default VIEW on display 1055 // ------- set default VIEW on display
945 this.set_display_screen(aagtl.DISPLAY_VIEW_MAP); 1056 this.set_display_screen(aagtl.DISPLAY_VIEW_MAP);
955 // get position on first startup 1066 // get position on first startup
956 turn_off_gps(); 1067 turn_off_gps();
957 try 1068 try
958 { 1069 {
959 // wait for gsm cell fix 1070 // wait for gsm cell fix
960 Thread.sleep(1000L); 1071 Thread.sleep(60L);
961 } 1072 }
962 catch (InterruptedException e) 1073 catch (InterruptedException e)
963 { 1074 {
964 e.printStackTrace(); 1075 e.printStackTrace();
965 } 1076 }
970 // this.wl = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK , 1081 // this.wl = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK ,
971 // "aagtlWakeLock"); // i think this is not working 1082 // "aagtlWakeLock"); // i think this is not working
972 this.wl = pm.newWakeLock(PowerManager.FULL_WAKE_LOCK | PowerManager.ON_AFTER_RELEASE, "aagtlWakeLock"); 1083 this.wl = pm.newWakeLock(PowerManager.FULL_WAKE_LOCK | PowerManager.ON_AFTER_RELEASE, "aagtlWakeLock");
973 } 1084 }
974 1085
975 @Override 1086 //@Override
976 public boolean onCreateOptionsMenu(Menu menu) 1087 //public boolean onCreateOptionsMenu(Menu menu)
977 { 1088 //{
978 super.onCreateOptionsMenu(menu); 1089 // super.onCreateOptionsMenu(menu);
979 // System.out.println("onCreateOptionsMenu"); 1090 // // System.out.println("onCreateOptionsMenu");
980 return true; 1091 // return true;
981 } 1092 //}
982 1093
983 @Override 1094 @Override
984 public boolean onPrepareOptionsMenu(Menu menu) 1095 public boolean onPrepareOptionsMenu(Menu menu)
985 { 1096 {
986 super.onPrepareOptionsMenu(menu); 1097 //super.onPrepareOptionsMenu(menu);
987 // this gets called every time the menu is opened!! 1098 // this gets called every time the menu is opened!!
988 // change menu items here! 1099 // change menu items here!
989 // System.out.println("onPrepareOptionsMenu"); 1100 // System.out.println("onPrepareOptionsMenu");
990 1101
991 switch (this.current_display_view) 1102 switch (this.current_display_view)
1170 // do something on back. 1281 // do something on back.
1171 // System.out.println("no back key!"); 1282 // System.out.println("no back key!");
1172 1283
1173 if (this.current_display_view == DISPLAY_VIEW_MAP) 1284 if (this.current_display_view == DISPLAY_VIEW_MAP)
1174 { 1285 {
1286 if (this.emu_menu_view.isShown())
1287 {
1288 this.emu_menu_view.setVisibility(View.INVISIBLE);
1289 }
1290 else
1291 {
1175 this.finish(); // -> this calls "onPause" 1292 this.finish(); // -> this calls "onPause"
1293 }
1176 } 1294 }
1177 else if (this.current_display_view == DISPLAY_VIEW_GC) 1295 else if (this.current_display_view == DISPLAY_VIEW_GC)
1178 { 1296 {
1179 this.set_display_screen(DISPLAY_VIEW_MAP); 1297 this.set_display_screen(DISPLAY_VIEW_MAP);
1180 } 1298 }
1240 } 1358 }
1241 1359
1242 @Override 1360 @Override
1243 public boolean onOptionsItemSelected(MenuItem item) 1361 public boolean onOptionsItemSelected(MenuItem item)
1244 { 1362 {
1363 return onOptionsItemSelected_wrapper(item.getItemId());
1364 }
1365
1366 public boolean onOptionsItemSelected_wrapper(int id)
1367 {
1245 // Handle item selection 1368 // Handle item selection
1246 switch (item.getItemId()) 1369 switch (id)
1247 { 1370 {
1248 case 1: 1371 case 1:
1249 // download caches (no full details) 1372 // download caches (no full details)
1250 this.download_caches_in_visible_view(false); 1373 this.download_caches_in_visible_view(false);
1251 return true; 1374 return true;
1433 this.cacheview.show_field = GCacheView.SHOW_WAYPOINTS; 1556 this.cacheview.show_field = GCacheView.SHOW_WAYPOINTS;
1434 this.cacheview.need_repaint = true; 1557 this.cacheview.need_repaint = true;
1435 this.cacheview.invalidate(); 1558 this.cacheview.invalidate();
1436 return true; 1559 return true;
1437 default: 1560 default:
1438 return super.onOptionsItemSelected(item); 1561 // return super.onOptionsItemSelected(item);
1562 return false;
1439 } 1563 }
1440 } 1564 }
1441 1565
1442 public void toast_me(String in_text, int duration) 1566 public void toast_me(String in_text, int duration)
1443 { 1567 {
1451 return ret; 1575 return ret;
1452 } 1576 }
1453 1577
1454 public void set_display_screen(int dt) 1578 public void set_display_screen(int dt)
1455 { 1579 {
1580 try
1581 {
1456 switch (dt) 1582 switch (dt)
1457 { 1583 {
1458 case DISPLAY_VIEW_MAP: 1584 case DISPLAY_VIEW_MAP:
1459 // main map view 1585 // main map view
1460 if (!this.global_settings.options_use_compass_heading) 1586 if (!this.global_settings.options_use_compass_heading)
1461 { 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
1596 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
1604 rose.bringToFront();
1605 gcview.bringToFront();
1606 cross.bringToFront();
1607 status_text.bringToFront();
1608 cross.invalidate();
1609 gcview.invalidate();
1610 status_text.invalidate();
1611
1612 break;
1613 case DISPLAY_VIEW_GC:
1614 // gc-view
1462 this.turn_off_compass(); 1615 this.turn_off_compass();
1463 } 1616 this.current_display_view = DISPLAY_VIEW_GC;
1464 else 1617
1465 { 1618 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
1626 // 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
1633 status_text.bringToFront();
1634 cacheview.bringToFront();
1635 cacheview.invalidate();
1636 status_text.invalidate();
1637
1638 break;
1639 case DISPLAY_VIEW_ARROW:
1640 // gc-view
1466 this.turn_on_compass(); 1641 this.turn_on_compass();
1467 }
1468 this.current_display_view = DISPLAY_VIEW_MAP;
1469
1470 arrowview.setVisibility(View.INVISIBLE);
1471 cacheview.setVisibility(View.INVISIBLE);
1472 rose.setVisibility(View.VISIBLE);
1473 gcview.setVisibility(View.VISIBLE);
1474 cross.setVisibility(View.VISIBLE);
1475 status_text.setVisibility(View.VISIBLE);
1476 wv.setVisibility(View.VISIBLE);
1477
1478 rose.bringToFront();
1479 gcview.bringToFront();
1480 cross.bringToFront();
1481 status_text.bringToFront();
1482 cross.invalidate();
1483 gcview.invalidate();
1484 status_text.invalidate();
1485
1486 break;
1487 case DISPLAY_VIEW_GC:
1488 // gc-view
1489 this.turn_off_compass();
1490 this.current_display_view = DISPLAY_VIEW_GC;
1491
1492 rose.setVisibility(View.INVISIBLE);
1493 gcview.setVisibility(View.INVISIBLE);
1494 cross.setVisibility(View.INVISIBLE);
1495 arrowview.setVisibility(View.INVISIBLE);
1496 wv.setVisibility(View.INVISIBLE);
1497 status_text.setVisibility(View.VISIBLE);
1498 cacheview.setVisibility(View.VISIBLE);
1499
1500 // make sure we dont start cachedownload immediately
1501 cacheview.override_download = true;
1502 cacheview.gc.desc = "please update details!!";
1503 cacheview.download_details_thread_finished = true;
1504 cacheview.details_loaded = 2;
1505 cacheview.get_gc_from_db = 1;
1506
1507 status_text.bringToFront();
1508 cacheview.bringToFront();
1509 cacheview.invalidate();
1510 status_text.invalidate();
1511
1512 break;
1513 case DISPLAY_VIEW_ARROW:
1514 // gc-view
1515 this.turn_on_compass();
1516 this.current_display_view = DISPLAY_VIEW_ARROW; 1642 this.current_display_view = DISPLAY_VIEW_ARROW;
1517 1643
1518 rose.setVisibility(View.INVISIBLE); 1644 rose.setVisibility(View.INVISIBLE);
1519 gcview.setVisibility(View.INVISIBLE); 1645 gcview.setVisibility(View.INVISIBLE);
1520 cross.setVisibility(View.INVISIBLE); 1646 cross.setVisibility(View.INVISIBLE);
1521 cacheview.setVisibility(View.INVISIBLE); 1647 cacheview.setVisibility(View.INVISIBLE);
1522 wv.setVisibility(View.INVISIBLE); 1648 wv.setVisibility(View.INVISIBLE);
1523 status_text.setVisibility(View.VISIBLE); 1649 status_text.setVisibility(View.VISIBLE);
1524 arrowview.setVisibility(View.VISIBLE); 1650 arrowview.setVisibility(View.VISIBLE);
1525 1651
1526 status_text.bringToFront(); 1652 status_text.bringToFront();
1527 arrowview.bringToFront(); 1653 arrowview.bringToFront();
1528 arrowview.invalidate(); 1654 arrowview.invalidate();
1529 status_text.invalidate(); 1655 status_text.invalidate();
1530 1656
1531 break; 1657 break;
1658 }
1659 }
1660 catch (Exception e)
1661 {
1662 // catch all
1532 } 1663 }
1533 } 1664 }
1534 1665
1535 public Coordinate[] get_visible_area() 1666 public Coordinate[] get_visible_area()
1536 { 1667 {
1981 2112
1982 @Override 2113 @Override
1983 public void onResume() 2114 public void onResume()
1984 { 2115 {
1985 super.onResume(); 2116 super.onResume();
1986 // System.out.println("main: resume"); 2117 System.out.println("AAGTL:main:resume");
1987 2118
1988 // mgpsl = new MyGPSListener(); 2119 // mgpsl = new MyGPSListener();
1989 2120
1990 this.load_settings(); 2121 this.load_settings();
1991 this.wdl.loadCookies(); 2122 this.wdl.loadCookies();
2034 // System.out.println("x2=" + this.cacheview.gc_name_previous); 2165 // System.out.println("x2=" + this.cacheview.gc_name_previous);
2035 // System.out.println("x3=" + this.cacheview.details_loaded); 2166 // System.out.println("x3=" + this.cacheview.details_loaded);
2036 // System.out.println("x4=" + String.valueOf(this.cacheview.gc)); 2167 // System.out.println("x4=" + String.valueOf(this.cacheview.gc));
2037 2168
2038 this.rose.load_caches_from_db(); 2169 this.rose.load_caches_from_db();
2170 //this.rose.redraw_like_zoom();
2039 } 2171 }
2040 2172
2041 protected void onActivityResult(int requestCode, int resultCode, Intent data) 2173 protected void onActivityResult(int requestCode, int resultCode, Intent data)
2042 { 2174 {
2043 switch (requestCode) 2175 switch (requestCode)
2044 { 2176 {
2177 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;
2045 case 7: 2201 case 7:
2046 try 2202 try
2047 { 2203 {
2048 String value = data.getStringExtra("username"); 2204 String value = data.getStringExtra("username");
2049 if (value != null && value.length() > 0) 2205 if (value != null && value.length() > 0)
2174 // System.out.println(lx.getHeight()); 2330 // System.out.println(lx.getHeight());
2175 // System.out.println(rose.getHeight()); 2331 // System.out.println(rose.getHeight());
2176 // System.out.println(cross.getHeight()); 2332 // System.out.println(cross.getHeight());
2177 // System.out.println(status_text.getHeight()); 2333 // System.out.println(status_text.getHeight());
2178 2334
2335 System.out.println("AAGTL:main:pause");
2179 // System.out.println("main: pause"); 2336 // System.out.println("main: pause");
2180 2337
2181 // stop listening for GPS 2338 // stop listening for GPS
2182 this.turn_off_locations(); 2339 this.turn_off_locations();
2183 // stop compass 2340 // stop compass
2203 } 2360 }
2204 2361
2205 // close sql db 2362 // close sql db
2206 pv.compact(); 2363 pv.compact();
2207 pv.close(); 2364 pv.close();
2365
2366 rose.free_stuff();
2208 2367
2209 super.onPause(); 2368 super.onPause();
2210 } 2369 }
2211 2370
2212 public void turn_off_locations() 2371 public void turn_off_locations()
2541 { 2700 {
2542 List<GeocacheCoordinate> caches = this.pv.get_new_fieldnotes(); 2701 List<GeocacheCoordinate> caches = this.pv.get_new_fieldnotes();
2543 if ((caches == null) || (caches.size() == 0)) 2702 if ((caches == null) || (caches.size() == 0))
2544 { 2703 {
2545 // no filednotes to upload 2704 // no filednotes to upload
2546 Toast.makeText(getApplicationContext(), "No Fieldnotes to upload", Toast.LENGTH_SHORT).show(); 2705 Message msg = this.toast_handler.obtainMessage();
2547 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);
2548 } 2712 }
2549 else 2713 else
2550 { 2714 {
2715 final Thread fn_uploader_thread = new Thread(new Runnable()
2716 {
2717 public void run()
2718 {
2719 List<GeocacheCoordinate> caches2 = pv.get_new_fieldnotes();
2551 FieldnotesUploader fu = new FieldnotesUploader(this.wdl, caches); 2720 FieldnotesUploader fu = new FieldnotesUploader(wdl, caches2);
2552 boolean ret = fu.upload(); 2721 boolean ret = fu.upload();
2553 if (ret) 2722 if (ret)
2554 { 2723 {
2555 Toast.makeText(getApplicationContext(), "" + caches.size() + " Fieldnotes uploaded", Toast.LENGTH_SHORT).show(); 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);
2556 } 2732 }
2557 else 2733 else
2558 { 2734 {
2559 Toast.makeText(getApplicationContext(), "Error while uploading Fieldnotes", Toast.LENGTH_SHORT).show(); 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 }
2560 } 2744 }
2745 });
2746 fn_uploader_thread.start();
2561 } 2747 }
2562 } 2748 }
2563 2749
2564 public void get_route_files() 2750 public void get_route_files()
2565 { 2751 {
3010 System.out.println("s: " + s); 3196 System.out.println("s: " + s);
3011 } 3197 }
3012 return true; 3198 return true;
3013 } 3199 }
3014 3200
3201 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 }
3015} 3354}

Legend:
Removed from v.3  
changed lines
  Added in v.4

   
Visit the aagtl Website