androidUTIL.h 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285
  1. /***************************************************************************
  2. *
  3. * Project: OpenCPN
  4. * Purpose: OpenCPN Android support utilities
  5. * Author: David Register
  6. *
  7. ***************************************************************************
  8. * Copyright (C) 2015 by David S. Register *
  9. * *
  10. * This program is free software; you can redistribute it and/or modify *
  11. * it under the terms of the GNU General Public License as published by *
  12. * the Free Software Foundation; either version 2 of the License, or *
  13. * (at your option) any later version. *
  14. * *
  15. * This program is distributed in the hope that it will be useful, *
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of *
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
  18. * GNU General Public License for more details. *
  19. * *
  20. * You should have received a copy of the GNU General Public License *
  21. * along with this program; if not, write to the *
  22. * Free Software Foundation, Inc., *
  23. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
  24. **************************************************************************/
  25. #ifndef ANDROIDUTIL_H
  26. #define ANDROIDUTIL_H
  27. #include "wx/wxprec.h"
  28. #ifndef WX_PRECOMP
  29. #include "wx/wx.h"
  30. #endif // precompiled headers
  31. #include <QString>
  32. #include <string>
  33. #include "OCPN_Sound.h"
  34. #include "android_jvm.h"
  35. class ArrayOfCDI;
  36. // Enumerators for OCPN menu actions requested by Android UI
  37. #define OCPN_ACTION_FOLLOW 0x1000
  38. #define OCPN_ACTION_ROUTE 0x1001
  39. #define OCPN_ACTION_RMD 0x1002
  40. #define OCPN_ACTION_SETTINGS_BASIC 0x1003
  41. #define OCPN_ACTION_SETTINGS_EXPERT 0x1004
  42. #define OCPN_ACTION_TRACK_TOGGLE 0x1005
  43. #define OCPN_ACTION_MOB 0x1006
  44. #define OCPN_ACTION_TIDES_TOGGLE 0x1007
  45. #define OCPN_ACTION_CURRENTS_TOGGLE 0x1008
  46. #define OCPN_ACTION_ENCTEXT_TOGGLE 0x1009
  47. #define OCPN_ACTION_TRACK_ON 0x100a
  48. #define OCPN_ACTION_TRACK_OFF 0x100b
  49. #define OCPN_ACTION_ENCSOUNDINGS_TOGGLE 0x100c
  50. #define OCPN_ACTION_ENCLIGHTS_TOGGLE 0x100d
  51. #define OCPN_ACTION_DOWNLOAD_VALID 0x100e
  52. #define GPS_OFF 0
  53. #define GPS_ON 1
  54. #define GPS_PROVIDER_AVAILABLE 2
  55. #define GPS_SHOWPREFERENCES 3
  56. extern bool androidUtilInit(void);
  57. extern wxString androidGetDeviceInfo();
  58. extern void CheckMigrateCharts();
  59. extern bool androidGetMemoryStatus(int *mem_total, int *mem_used);
  60. extern double GetAndroidDisplaySize();
  61. extern double getAndroidDPmm();
  62. extern wxSize getAndroidDisplayDimensions(void);
  63. extern double getAndroidDisplayDensity();
  64. extern int getAndroidActionBarHeight();
  65. extern void androidConfirmSizeCorrection();
  66. extern void androidForceFullRepaint(bool bskipConfirm = false);
  67. extern int androidGetVersionCode();
  68. extern wxString androidGetVersionName();
  69. extern bool LoadQtStyleSheet(wxString &sheet_file);
  70. extern QString getQtStyleSheet(void);
  71. extern void androidShowBusyIcon();
  72. extern void androidHideBusyIcon();
  73. extern void androidEnableBackButton(bool benable);
  74. extern void androidEnableBackButtonCheck(bool benable);
  75. extern void androidEnableOptionItems(bool benable);
  76. extern wxString androidGetSupplementalLicense(void);
  77. extern bool androidStartGPS(wxEvtHandler *consumer);
  78. extern bool androidStopGPS();
  79. extern wxString androidGPSService(int parm);
  80. extern bool androidDeviceHasGPS();
  81. extern bool androidDeviceHasBlueTooth();
  82. extern bool androidStartBluetoothScan();
  83. extern bool androidStopBluetoothScan();
  84. extern wxArrayString androidGetBluetoothScanResults();
  85. extern bool androidStartBT(wxEvtHandler *consumer, wxString mac_address);
  86. extern bool androidStopBT();
  87. extern bool androidSendBTMessage(wxString &payload);
  88. extern wxArrayString *androidGetSerialPortsArray(void);
  89. extern bool androidStartUSBSerial(wxString &portname, wxString baudRate,
  90. wxEvtHandler *consumer);
  91. extern bool androidStopUSBSerial(wxString &portname);
  92. extern bool androidWriteSerial(wxString &portname, wxString &message);
  93. extern bool DoAndroidPreferences(void);
  94. extern int androidFileChooser(wxString *result, const wxString &initDir,
  95. const wxString &title, const wxString &suggestion,
  96. const wxString &wildcard, bool dirOnly = false,
  97. bool addFiles = false);
  98. extern void androidSetChartTypeMaskSel(int mask, wxString &indicator);
  99. extern void androidSetRouteAnnunciator(bool viz);
  100. extern void androidSetFollowTool(int state, bool forceUpdate = false);
  101. extern void androidSetTrackTool(bool bactive);
  102. extern wxString androidGetHomeDir();
  103. extern wxString
  104. androidGetPrivateDir(); // Used for logfile, config file, and the like
  105. extern wxString
  106. androidGetSharedDir(); // Used for assets like uidata, s57data, etc
  107. extern wxString
  108. androidGetCacheDir(); // Used for raster_texture_cache, mmsitoname.csv, etc
  109. extern wxString androidGetExtStorageDir(); // Used for Chart storage, typically
  110. extern wxString androidGetDownloadDirectory();
  111. extern int startAndroidFileDownload(const wxString &url,
  112. const wxString &destination,
  113. wxEvtHandler *evh, long *dl_ID);
  114. extern int queryAndroidFileDownload(long dl_ID, wxString *result);
  115. extern void finishAndroidFileDownload();
  116. extern void cancelAndroidFileDownload(long dl_ID);
  117. extern int validateAndroidWriteLocation(const wxString &destination);
  118. extern wxString doAndroidPOST(const wxString &url, wxString &parms,
  119. int timeoutMsec);
  120. extern wxString getFontQtStylesheet(wxFont *font);
  121. extern wxSize getAndroidConfigSize();
  122. void resizeAndroidPersistents();
  123. bool AndroidSecureCopyFile(wxString in, wxString out);
  124. class AndroidSound;
  125. bool androidPlaySound(const wxString soundfile, AndroidSound* sound);
  126. bool androidGetFullscreen();
  127. bool androidSetFullscreen(bool bFull);
  128. void androidDisableFullScreen();
  129. void androidRestoreFullScreen();
  130. void androidLaunchHelpView();
  131. void androidTestCPP();
  132. int androidGetTZOffsetMins();
  133. int androidApplySettingsString(wxString settings, ArrayOfCDI *pACDI);
  134. bool androidShowDisclaimer(wxString title, wxString msg);
  135. bool androidShowSimpleOKDialog(std::string title, std::string msg);
  136. bool androidShowSimpleYesNoDialog(wxString title, wxString msg);
  137. bool androidInstallPlaystoreHelp();
  138. void androidLaunchBrowser(wxString URL);
  139. bool androidCheckOnline();
  140. unsigned int androidColorPicker(unsigned int initialColor);
  141. wxArrayString androidTraverseDir(wxString dir, wxString filespec);
  142. void androidEnableOptionsMenu(bool bEnable);
  143. void prepareAndroidStyleSheets();
  144. QString getAdjustedDialogStyleSheet();
  145. QString getListBookStyleSheet();
  146. QString getScrollBarsStyleSheet();
  147. QString getWideScrollBarsStyleSheet();
  148. void setChoiceStyleSheet(wxChoice *win, int refDim);
  149. void setMenuStyleSheet(wxMenu *win, const wxFont &font);
  150. QString prepareAndroidSliderStyleSheet(int sliderWidth);
  151. void androidDisplayTimedToast(wxString message, int timeMillisec);
  152. void androidCancelTimedToast();
  153. void androidDisplayToast(wxString message);
  154. void androidEnableRotation(void);
  155. void androidDisableRotation(void);
  156. int androidGetScreenOrientation();
  157. void androidEnableMulticast(bool benable);
  158. void androidLastCall();
  159. wxString androidGetIpV4Address(void);
  160. // SVG Support
  161. wxBitmap loadAndroidSVG(const wxString filename, unsigned int width,
  162. unsigned int height);
  163. wxString androidGetAndroidSystemLocale();
  164. bool androidIsDirWritable( wxString dir );
  165. wxArrayString GetConfigChartDirectories();
  166. class InProgressIndicator: public wxGauge
  167. {
  168. DECLARE_EVENT_TABLE()
  169. public:
  170. InProgressIndicator();
  171. InProgressIndicator(wxWindow* parent, wxWindowID id, int range,
  172. const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize,
  173. long style = wxGA_HORIZONTAL, const wxValidator& validator = wxDefaultValidator, const wxString& name = "inprogress");
  174. ~InProgressIndicator();
  175. void OnTimer(wxTimerEvent &evt);
  176. void Start();
  177. void Stop();
  178. wxTimer m_timer;
  179. int msec;
  180. bool m_bAlive;
  181. };
  182. ///////////////////////////////////////////////////////////////////////////////
  183. /// Class MigrateAssistantDialog
  184. ///////////////////////////////////////////////////////////////////////////////
  185. #define ID_MIGRATE_OK 8791
  186. #define ID_MIGRATE_CANCEL 8792
  187. #define ID_MIGRATE_START 8793
  188. #define ID_MIGRATE_CONTINUE 8794
  189. #define MIGRATION_STATUS_TIMER 8795
  190. class MigrateAssistantDialog : public wxDialog {
  191. public:
  192. explicit MigrateAssistantDialog(wxWindow *parent,
  193. bool bskipScan,
  194. wxWindowID id = wxID_ANY,
  195. const wxString &caption = wxEmptyString,
  196. const wxPoint &pos = wxDefaultPosition,
  197. const wxSize &size = wxDefaultSize, long style = 0);
  198. ~MigrateAssistantDialog(void);
  199. void CreateControls(void);
  200. void OnMigrateCancelClick(wxCommandEvent &event);
  201. void OnMigrateOKClick(wxCommandEvent &event);
  202. void OnMigrateClick(wxCommandEvent &event);
  203. void OnMigrate1Click(wxCommandEvent &event);
  204. void OnCtlUpdated(wxCommandEvent &event);
  205. void onPermissionGranted(wxString);
  206. void setStatus( wxString s ){ m_statusText->SetLabel(s); }
  207. void onTimerEvent(wxTimerEvent &event);
  208. void FinishMigration();
  209. wxButton *m_CancelButton, *m_OKButton;
  210. wxButton *m_migrateButton, *m_migrateButton1;
  211. wxStaticText *m_infoText, *m_infoDirs, *m_migrateStep1, *m_statusText;;
  212. wxRadioButton *m_radioSDCard, *m_radioInternal;
  213. InProgressIndicator *m_ipGauge;
  214. wxStaticBoxSizer *statusSizer;
  215. wxArrayString m_migrateDirs;
  216. wxString m_Status;
  217. wxString m_permissionResult;
  218. wxTimer m_statusTimer;
  219. wxString m_migrateSourceFolder;
  220. wxString m_migrateDestinationFolder; // something like "/storage/emulated/0/Android/data/org.opencpn.opencpn/files/Charts
  221. // or "/storage/xxx-yyyy/Android/data/org.opencpn.opencpn/files/Charts
  222. bool m_bsdcard;
  223. bool m_bskipScan;
  224. private:
  225. DECLARE_EVENT_TABLE()
  226. };
  227. #endif // guard