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