Debian Codegraph @

src/android/android_clipboard.c

raw
1 /* ______ ___ ___
2 * /\ _ \ /\_ \ /\_ \
3 * \ \ \L\ \\//\ \ \//\ \ __ __ _ __ ___
4 * \ \ __ \ \ \ \ \ \ \ /'__`\ /'_ `\/\`'__\/ __`\
5 * \ \ \/\ \ \_\ \_ \_\ \_/\ __//\ \L\ \ \ \//\ \L\ \
6 * \ \_\ \_\/\____\/\____\ \____\ \____ \ \_\\ \____/
7 * \/_//_/\/____/\/____/\/____/\/___L\ \/_/ \/___/
8 * /\____/
9 * \_/__/
10 *
11 * Android clipboard handling.
12 *
13 * By Beoran.
14 *
15 * See readme.txt for copyright information.
16 */
17
18
19
20 #include "allegro5/allegro.h"
21 #include "allegro5/allegro_android.h"
22 #include "allegro5/internal/aintern.h"
23 #include "allegro5/internal/aintern_android.h"
24 #include "allegro5/internal/aintern_bitmap.h"
25
26 #include <jni.h>
27
28 ALLEGRO_DEBUG_CHANNEL("clipboard")
29
30 static bool android_set_clipboard_text(ALLEGRO_DISPLAY *display, const char *text)
31 {
32 JNIEnv * env = (JNIEnv *)_al_android_get_jnienv();
33 jstring jtext= _jni_call(env, jstring, NewStringUTF, text);
34 (void) display;
35 return _jni_callBooleanMethodV(env, _al_android_activity_object(),
36 "setClipboardText", "(Ljava/lang/String;)Z", jtext);
37 }
38
39 static char *android_get_clipboard_text(ALLEGRO_DISPLAY *display)
40 {
41 JNIEnv * env = (JNIEnv *)_al_android_get_jnienv();
42 jobject jtext = _jni_callObjectMethod(env, _al_android_activity_object(), "getClipboardText", "()Ljava/lang/String;");
43 jsize len = _jni_call(env, jsize, GetStringUTFLength, jtext);
44 const char *str = _jni_call(env, const char *, GetStringUTFChars, jtext, NULL);
45 char * text = al_malloc(len+1);
46 (void) display;
47
48 text = _al_sane_strncpy(text, str, len);
49 _jni_callv(env, ReleaseStringUTFChars, jtext, str);
50 _jni_callv(env, DeleteLocalRef, jtext);
51
52 return text;
53 }
54
55 static bool android_has_clipboard_text(ALLEGRO_DISPLAY *display)
56 {
57 JNIEnv * env = (JNIEnv *)_al_android_get_jnienv();
58 (void) display;
59 return _jni_callBooleanMethodV(env, _al_android_activity_object(),
60 "hasClipboardText", "()Z");
61 }
62
63
64 void _al_android_add_clipboard_functions(ALLEGRO_DISPLAY_INTERFACE *vt)
65 {
66 vt->set_clipboard_text = android_set_clipboard_text;
67 vt->get_clipboard_text = android_get_clipboard_text;
68 vt->has_clipboard_text = android_has_clipboard_text;
69 }
70
71 /* vi: set ts=8 sts=3 sw=3 et: */