porting_android.h 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  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 header 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 "irrlichttypes_bloated.h"
  24. #include <string>
  25. namespace porting {
  26. // Java app
  27. extern android_app *app_global;
  28. // Java <-> C++ interaction interface
  29. extern JNIEnv *jnienv;
  30. /**
  31. * Show a text input dialog in Java
  32. * @param hint Hint to be shown
  33. * @param current Initial value to be displayed
  34. * @param editType Type of the text field
  35. * (1 = multi-line text input; 2 = single-line text input; 3 = password field)
  36. */
  37. void showTextInputDialog(const std::string &hint, const std::string &current, int editType);
  38. /**
  39. * Show a selection dialog in Java
  40. * @param optionList The list of options
  41. * @param listSize Size of the list
  42. * @param selectedIdx Selected index
  43. */
  44. void showComboBoxDialog(const std::string optionList[], s32 listSize, s32 selectedIdx);
  45. /**
  46. * Opens a share intent to the file at path
  47. *
  48. * @param path
  49. */
  50. void shareFileAndroid(const std::string &path);
  51. /*
  52. * Types of Android input dialog:
  53. * 1. Text input (single/multi-line text and password field)
  54. * 2. Selection input (combo box)
  55. */
  56. enum AndroidDialogType { TEXT_INPUT, SELECTION_INPUT };
  57. /*
  58. * WORKAROUND for not working callbacks from Java -> C++
  59. * Get the type of the last input dialog
  60. */
  61. AndroidDialogType getLastInputDialogType();
  62. /*
  63. * States of Android input dialog:
  64. * 1. The dialog is currently shown.
  65. * 2. The dialog has its input sent.
  66. * 3. The dialog is canceled/dismissed.
  67. */
  68. enum AndroidDialogState { DIALOG_SHOWN, DIALOG_INPUTTED, DIALOG_CANCELED };
  69. /*
  70. * WORKAROUND for not working callbacks from Java -> C++
  71. * Get the state of the input dialog
  72. */
  73. AndroidDialogState getInputDialogState();
  74. /*
  75. * WORKAROUND for not working callbacks from Java -> C++
  76. * Get the text in the current/last input dialog
  77. * This function clears the dialog state (set to canceled). Make sure to save
  78. * the dialog state before calling this function.
  79. */
  80. std::string getInputDialogMessage();
  81. /*
  82. * WORKAROUND for not working callbacks from Java -> C++
  83. * Get the selection in the current/last input dialog
  84. * This function clears the dialog state (set to canceled). Make sure to save
  85. * the dialog state before calling this function.
  86. */
  87. int getInputDialogSelection();
  88. #ifndef SERVER
  89. float getDisplayDensity();
  90. v2u32 getDisplaySize();
  91. #endif
  92. }