Added share buttons to android

This commit is contained in:
Yousef Khadadeh 2026-05-31 18:35:57 +03:00
parent e2a62e852c
commit 7f94f65bea
16 changed files with 146 additions and 19 deletions

View file

@ -58,6 +58,28 @@ namespace AndroidJNICalls {
bool textChanged = false;
bool cursorChanged = false;
void shareInternalFile(const std::string& filePath, const std::string& mimeType) {
Logger::get().log(Logger::LogType::INFO, "[AndroidJNICalls::shareInternalFile] Share internal file " + filePath);
JNIEnv* env = static_cast<JNIEnv*>(SDL_GetAndroidJNIEnv());
jobject activity = (jobject)SDL_GetAndroidActivity();
jclass clazz = env->GetObjectClass(activity);
jmethodID method_id = env->GetStaticMethodID(clazz, "shareInternalFile", "(Ljava/lang/String;Ljava/lang/String;)V");
env->CallStaticVoidMethod(clazz, method_id, string2jstring(env, filePath), string2jstring(env, mimeType));
env->DeleteLocalRef(activity);
env->DeleteLocalRef(clazz);
}
void shareText(const std::string& str) {
Logger::get().log(Logger::LogType::INFO, "[AndroidJNICalls::shareText] Share text " + str);
JNIEnv* env = static_cast<JNIEnv*>(SDL_GetAndroidJNIEnv());
jobject activity = (jobject)SDL_GetAndroidActivity();
jclass clazz = env->GetObjectClass(activity);
jmethodID method_id = env->GetStaticMethodID(clazz, "shareText", "(Ljava/lang/String;)V");
env->CallStaticVoidMethod(clazz, method_id, string2jstring(env, str));
env->DeleteLocalRef(activity);
env->DeleteLocalRef(clazz);
}
int get_android_text_pos_from_cursor_pos(const std::shared_ptr<RichText::TextBox>& t, const RichText::TextPosition& p) {
return t->get_utf16_location_from_codepoint_location(t->get_codepoint_location_from_text_position(p));
}

View file

@ -26,6 +26,8 @@ struct InputManager;
namespace AndroidJNICalls {
extern InputManager* globalInputManager;
void shareInternalFile(const std::string& filePath, const std::string& mimeType);
void shareText(const std::string& str);
void startTextInput(CustomEvents::InputTextBoxID newTextboxID, const std::shared_ptr<RichText::TextBox>& newTextbox, const std::shared_ptr<RichText::TextBox::Cursor>& newCursor, const std::shared_ptr<RichText::TextStyleModifier::ModifierMap>& modMap, int inputType);
void startNetworkService();
void stopNetworkService();

View file

@ -29,10 +29,6 @@
#include "../../GUIStuff/ElementHelpers/CheckBoxHelpers.hpp"
#include <include/pathops/SkPathOps.h>
#define MINIMUM_DISTANCE_FROM_FIRST_POINT 3.0f
#define MINIMUM_DISTANCE_TO_NEXT_POINT 0.002f
#define DRAW_MINIMUM_LIMIT 1.0f
BrushTool::BrushTool(DrawingProgram& initDrawP):
DrawingProgramToolBase(initDrawP)
{}

View file

@ -427,6 +427,17 @@ void FileSelectScreen::move_selected_files(const std::filesystem::path& fromPath
}
}
void FileSelectScreen::share_selected_files() {
for(const FileInfo& f : fileList) {
if(f.selected) {
#ifdef __ANDROID__
AndroidJNICalls::shareInternalFile("saves/" + f.fileName + ".infpnt", "application/octet-stream");
#endif
break;
}
}
}
void FileSelectScreen::duplicate_selected_files(const std::filesystem::path& inPath) {
std::vector<std::string> toFolderListNames;
try {
@ -571,6 +582,15 @@ void FileSelectScreen::edit_action_bar() {
update_file_list(fileList, savePath, false);
editMode = false;
});
#ifdef __ANDROID__
if(numberOfSelectedEntries == 1) {
edit_action_bar_button("share", "data/icons/RemixIcon/share-line.svg", "Share", [&] {
share_selected_files();
update_file_list(fileList, savePath, false);
editMode = false;
});
}
#endif
}
else if(selectedMenu == SelectedMenu::TRASH) {
edit_action_bar_button("restore", "data/icons/RemixIcon/refresh-line.svg", "Restore", [&] {

View file

@ -112,6 +112,7 @@ class FileSelectScreen : public Screen {
};
void move_selected_files(const std::filesystem::path& fromPath, const std::filesystem::path& toPath, TrashMoveType trashMoveType);
void duplicate_selected_files(const std::filesystem::path& inPath);
void share_selected_files();
void delete_selected_files_in_trash();
enum class MoreOptionsMenu {

View file

@ -255,13 +255,25 @@ void PhoneDrawingProgramScreen::top_toolbar_settings_popup() {
input_text_field(gui, "lobby", "Lobby", &serverToConnectTo, {
.immutable = true
});
text_button(gui, "Host button", "Copy & Host", {
.wide = true,
.onClick = [&] {
main.input.set_clipboard_str(serverToConnectTo);
main.world->start_hosting(serverToConnectTo, serverLocalID);
topToolbarSettingsPopup = TopToolbarSettingsPopup::NONE;
}
left_to_right_line_layout(gui, [&] {
text_button(gui, "Host button", "Copy & Host", {
.wide = true,
.onClick = [&] {
main.input.set_clipboard_str(serverToConnectTo);
main.world->start_hosting(serverToConnectTo, serverLocalID);
topToolbarSettingsPopup = TopToolbarSettingsPopup::NONE;
}
});
#ifdef __ANDROID__
text_button(gui, "Share and host button", "Share & Host", {
.wide = true,
.onClick = [&] {
AndroidJNICalls::shareText(serverToConnectTo);
main.world->start_hosting(serverToConnectTo, serverLocalID);
topToolbarSettingsPopup = TopToolbarSettingsPopup::NONE;
}
});
#endif
});
}
});
@ -291,12 +303,23 @@ void PhoneDrawingProgramScreen::top_toolbar_settings_popup() {
input_text_field(gui, "lobby", "Lobby", &serverToConnectTo, {
.immutable = true
});
text_button(gui, "Copy button", "Copy", {
.wide = true,
.onClick = [&] {
main.input.set_clipboard_str(serverToConnectTo);
topToolbarSettingsPopup = TopToolbarSettingsPopup::NONE;
}
left_to_right_line_layout(gui, [&] {
text_button(gui, "Copy button", "Copy", {
.wide = true,
.onClick = [&] {
main.input.set_clipboard_str(serverToConnectTo);
topToolbarSettingsPopup = TopToolbarSettingsPopup::NONE;
}
});
#ifdef __ANDROID__
text_button(gui, "Share button", "Share", {
.wide = true,
.onClick = [&] {
AndroidJNICalls::shareText(serverToConnectTo);
topToolbarSettingsPopup = TopToolbarSettingsPopup::NONE;
}
});
#endif
});
}
});