porting_android.h 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. /*
  2. Minetest
  3. Copyright (C) 2014 celeron55, Perttu Ahola <celeron55@gmail.com>
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU Lesser General Public License as published by
  6. the Free Software Foundation; either version 2.1 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU Lesser General Public License for more details.
  12. You should have received a copy of the GNU Lesser General Public License along
  13. with this program; if not, write to the Free Software Foundation, Inc.,
  14. 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  15. */
  16. #pragma once
  17. #ifndef __ANDROID__
  18. #error this include has to be included on android port only!
  19. #endif
  20. #include <jni.h>
  21. #include <android_native_app_glue.h>
  22. #include <android/log.h>
  23. #include <string>
  24. namespace porting {
  25. // java app
  26. extern android_app *app_global;
  27. // java <-> c++ interaction interface
  28. extern JNIEnv *jnienv;
  29. // do initialization required on android only
  30. void initAndroid();
  31. void cleanupAndroid();
  32. /**
  33. * Initializes path_* variables for Android
  34. * @param env Android JNI environment
  35. */
  36. void initializePathsAndroid();
  37. /**
  38. * show text input dialog in java
  39. * @param acceptButton text to display on accept button
  40. * @param hint hint to show
  41. * @param current initial value to display
  42. * @param editType type of texfield
  43. * (1==multiline text input; 2==single line text input; 3=password field)
  44. */
  45. void showInputDialog(const std::string &acceptButton,
  46. const std::string &hint, const std::string &current, int editType);
  47. void openURIAndroid(const std::string &url);
  48. /**
  49. * Opens a share intent to the file at path
  50. *
  51. * @param path
  52. */
  53. void shareFileAndroid(const std::string &path);
  54. /**
  55. * WORKAROUND for not working callbacks from java -> c++
  56. * get current state of input dialog
  57. */
  58. int getInputDialogState();
  59. /**
  60. * WORKAROUND for not working callbacks from java -> c++
  61. * get text in current input dialog
  62. */
  63. std::string getInputDialogValue();
  64. #ifndef SERVER
  65. float getDisplayDensity();
  66. v2u32 getDisplaySize();
  67. #endif
  68. }