Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
godotengine
GitHub Repository: godotengine/godot
Path: blob/master/platform/android/java_godot_wrapper.h
20849 views
1
/**************************************************************************/
2
/* java_godot_wrapper.h */
3
/**************************************************************************/
4
/* This file is part of: */
5
/* GODOT ENGINE */
6
/* https://godotengine.org */
7
/**************************************************************************/
8
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
9
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
10
/* */
11
/* Permission is hereby granted, free of charge, to any person obtaining */
12
/* a copy of this software and associated documentation files (the */
13
/* "Software"), to deal in the Software without restriction, including */
14
/* without limitation the rights to use, copy, modify, merge, publish, */
15
/* distribute, sublicense, and/or sell copies of the Software, and to */
16
/* permit persons to whom the Software is furnished to do so, subject to */
17
/* the following conditions: */
18
/* */
19
/* The above copyright notice and this permission notice shall be */
20
/* included in all copies or substantial portions of the Software. */
21
/* */
22
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
23
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
24
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
25
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
26
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
27
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
28
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
29
/**************************************************************************/
30
31
#pragma once
32
33
#include "java_godot_view_wrapper.h"
34
35
#include "core/math/color.h"
36
#include "core/templates/list.h"
37
38
#include <android/log.h>
39
#include <jni.h>
40
41
// Class that makes functions in java/src/org/godotengine/godot/Godot.kt callable from C++
42
class GodotJavaWrapper {
43
private:
44
jobject godot_instance;
45
jclass godot_class;
46
47
GodotJavaViewWrapper *godot_view = nullptr;
48
49
jmethodID _restart = nullptr;
50
jmethodID _finish = nullptr;
51
jmethodID _set_keep_screen_on = nullptr;
52
jmethodID _alert = nullptr;
53
jmethodID _is_dark_mode_supported = nullptr;
54
jmethodID _is_dark_mode = nullptr;
55
jmethodID _get_accent_color = nullptr;
56
jmethodID _get_base_color = nullptr;
57
jmethodID _get_clipboard = nullptr;
58
jmethodID _set_clipboard = nullptr;
59
jmethodID _has_clipboard = nullptr;
60
jmethodID _show_dialog = nullptr;
61
jmethodID _show_input_dialog = nullptr;
62
jmethodID _show_file_picker = nullptr;
63
jmethodID _request_permission = nullptr;
64
jmethodID _request_permissions = nullptr;
65
jmethodID _get_granted_permissions = nullptr;
66
jmethodID _get_gdextension_list_config_file = nullptr;
67
jmethodID _get_ca_certificates = nullptr;
68
jmethodID _init_input_devices = nullptr;
69
jmethodID _vibrate = nullptr;
70
jmethodID _get_input_fallback_mapping = nullptr;
71
jmethodID _on_godot_setup_completed = nullptr;
72
jmethodID _on_godot_main_loop_started = nullptr;
73
jmethodID _on_godot_terminating = nullptr;
74
jmethodID _create_new_godot_instance = nullptr;
75
jmethodID _get_render_view = nullptr;
76
jmethodID _begin_benchmark_measure = nullptr;
77
jmethodID _end_benchmark_measure = nullptr;
78
jmethodID _dump_benchmark = nullptr;
79
jmethodID _check_internal_feature_support = nullptr;
80
jmethodID _sign_apk = nullptr;
81
jmethodID _verify_apk = nullptr;
82
jmethodID _enable_immersive_mode = nullptr;
83
jmethodID _is_in_immersive_mode = nullptr;
84
jmethodID _set_window_color = nullptr;
85
jmethodID _on_editor_workspace_selected = nullptr;
86
jmethodID _get_activity = nullptr;
87
jmethodID _build_env_connect = nullptr;
88
jmethodID _build_env_disconnect = nullptr;
89
jmethodID _build_env_execute = nullptr;
90
jmethodID _build_env_cancel = nullptr;
91
jmethodID _build_env_clean_project = nullptr;
92
93
public:
94
GodotJavaWrapper(JNIEnv *p_env, jobject p_godot_instance);
95
~GodotJavaWrapper();
96
97
jobject get_activity();
98
99
GodotJavaViewWrapper *get_godot_view();
100
101
void on_godot_setup_completed(JNIEnv *p_env = nullptr);
102
void on_godot_main_loop_started(JNIEnv *p_env = nullptr);
103
void on_godot_terminating(JNIEnv *p_env = nullptr);
104
void restart(JNIEnv *p_env = nullptr);
105
bool force_quit(JNIEnv *p_env = nullptr, int p_instance_id = 0);
106
void set_keep_screen_on(bool p_enabled);
107
void alert(const String &p_message, const String &p_title);
108
bool is_dark_mode_supported();
109
bool is_dark_mode();
110
Color get_accent_color();
111
Color get_base_color();
112
bool has_get_clipboard();
113
String get_clipboard();
114
bool has_set_clipboard();
115
void set_clipboard(const String &p_text);
116
bool has_has_clipboard();
117
bool has_clipboard();
118
Error show_dialog(const String &p_title, const String &p_description, const Vector<String> &p_buttons);
119
Error show_input_dialog(const String &p_title, const String &p_message, const String &p_existing_text);
120
Error show_file_picker(const String &p_current_directory, const String &p_filename, int p_mode, const Vector<String> &p_filters);
121
bool request_permission(const String &p_name);
122
bool request_permissions();
123
Vector<String> get_granted_permissions() const;
124
String get_ca_certificates() const;
125
void init_input_devices();
126
void vibrate(int p_duration_ms, float p_amplitude = -1.0);
127
String get_input_fallback_mapping();
128
int create_new_godot_instance(const List<String> &args);
129
void begin_benchmark_measure(const String &p_context, const String &p_label);
130
void end_benchmark_measure(const String &p_context, const String &p_label);
131
void dump_benchmark(const String &benchmark_file);
132
133
// Return the list of gdextensions config file.
134
Vector<String> get_gdextension_list_config_file() const;
135
136
// Return true if the given feature is supported.
137
bool check_internal_feature_support(const String &p_feature) const;
138
139
// Sign and verify apks
140
Error sign_apk(const String &p_input_path, const String &p_output_path, const String &p_keystore_path, const String &p_keystore_user, const String &p_keystore_password);
141
Error verify_apk(const String &p_apk_path);
142
143
void enable_immersive_mode(bool p_enabled);
144
bool is_in_immersive_mode();
145
146
void set_window_color(const Color &p_color);
147
148
void on_editor_workspace_selected(const String &p_workspace);
149
150
bool build_env_connect(const Callable &p_callback);
151
void build_env_disconnect();
152
int build_env_execute(const String &p_build_tool, const List<String> &p_arguments, const String &p_project_path, const String &p_gradle_build_directory, const Callable &p_output_callback, const Callable &p_result_callback);
153
void build_env_cancel(int p_job_id);
154
void build_env_clean_project(const String &p_project_path, const String &p_gradle_build_directory, const Callable &p_callback);
155
};
156
157