remove_detached_inventory: Fix segfault during mod load
[oweals/minetest.git] / src / porting_android.h
1 /*
2 Minetest
3 Copyright (C) 2014 celeron55, Perttu Ahola <celeron55@gmail.com>
4
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU Lesser General Public License as published by
7 the Free Software Foundation; either version 2.1 of the License, or
8 (at your option) any later version.
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 Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General Public License along
16 with this program; if not, write to the Free Software Foundation, Inc.,
17 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 */
19
20 #pragma once
21
22 #ifndef __ANDROID__
23 #error this include has to be included on android port only!
24 #endif
25
26 #include <jni.h>
27 #include <android_native_app_glue.h>
28 #include <android/log.h>
29
30 #include <string>
31
32 namespace porting {
33 /** java app **/
34 extern android_app *app_global;
35
36 /** java <-> c++ interaction interface **/
37 extern JNIEnv *jnienv;
38
39 /**
40  * do initialization required on android only
41  */
42 void initAndroid();
43 void cleanupAndroid();
44
45 /**
46  * Initializes path_* variables for Android
47  * @param env Android JNI environment
48  */
49 void initializePathsAndroid();
50
51 /**
52  * use java function to copy media from assets to external storage
53  */
54 void copyAssets();
55
56 /**
57  * show text input dialog in java
58  * @param acceptButton text to display on accept button
59  * @param hint hint to show
60  * @param current initial value to display
61  * @param editType type of texfield
62  * (1==multiline text input; 2==single line text input; 3=password field)
63  */
64 void showInputDialog(const std::string& acceptButton,
65                 const  std::string& hint, const std::string& current, int editType);
66
67 /**
68  * WORKAROUND for not working callbacks from java -> c++
69  * get current state of input dialog
70  */
71 int getInputDialogState();
72
73 /**
74  * WORKAROUND for not working callbacks from java -> c++
75  * get text in current input dialog
76  */
77 std::string getInputDialogValue();
78
79 #ifndef SERVER
80 float getDisplayDensity();
81 v2u32 getDisplaySize();
82 #endif
83
84 }