mirror of
git://git.sv.gnu.org/emacs.git
synced 2025-12-15 10:30:25 -08:00
Housekeeping around androidselect.c
* java/org/gnu/emacs/EmacsClipboard.java (setClipboard) (getClipboard): * java/org/gnu/emacs/EmacsSdk11Clipboard.java (setClipboard) (getClipboard): * java/org/gnu/emacs/EmacsSdk8Clipboard.java (setClipboard) (getClipboard): Save and return Strings rather than byte arrays. * src/androidselect.c (android_init_emacs_clipboard) (Fandroid_set_clipboard, Fandroid_get_clipboard): Adjust to match.
This commit is contained in:
parent
5ec4c1a7d3
commit
8dc00dc222
4 changed files with 48 additions and 86 deletions
|
|
@ -27,10 +27,10 @@ import android.os.Build;
|
||||||
|
|
||||||
public abstract class EmacsClipboard
|
public abstract class EmacsClipboard
|
||||||
{
|
{
|
||||||
public abstract void setClipboard (byte[] bytes);
|
public abstract void setClipboard (String string);
|
||||||
public abstract int ownsClipboard ();
|
public abstract int ownsClipboard ();
|
||||||
public abstract boolean clipboardExists ();
|
public abstract boolean clipboardExists ();
|
||||||
public abstract byte[] getClipboard ();
|
public abstract String getClipboard ();
|
||||||
|
|
||||||
public abstract String[] getClipboardTargets ();
|
public abstract String[] getClipboardTargets ();
|
||||||
public abstract AssetFileDescriptor getClipboardData (String target);
|
public abstract AssetFileDescriptor getClipboardData (String target);
|
||||||
|
|
|
||||||
|
|
@ -86,19 +86,15 @@ public final class EmacsSdk11Clipboard extends EmacsClipboard
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Set the clipboard text to CLIPBOARD, a string in UTF-8
|
/* Save the STRING into the clipboard by way of text copied by the
|
||||||
encoding. */
|
user. */
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public synchronized void
|
public synchronized void
|
||||||
setClipboard (byte[] bytes)
|
setClipboard (String string)
|
||||||
{
|
{
|
||||||
ClipData data;
|
ClipData data;
|
||||||
String string;
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
string = new String (bytes, "UTF-8");
|
|
||||||
data = ClipData.newPlainText ("Emacs", string);
|
data = ClipData.newPlainText ("Emacs", string);
|
||||||
manager.setPrimaryClip (data);
|
manager.setPrimaryClip (data);
|
||||||
ownsClipboard = true;
|
ownsClipboard = true;
|
||||||
|
|
@ -108,11 +104,6 @@ public final class EmacsSdk11Clipboard extends EmacsClipboard
|
||||||
been changed. */
|
been changed. */
|
||||||
++clipboardChangedCount;
|
++clipboardChangedCount;
|
||||||
}
|
}
|
||||||
catch (UnsupportedEncodingException exception)
|
|
||||||
{
|
|
||||||
Log.w (TAG, "setClipboard: " + exception);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Return whether or not Emacs owns the clipboard. Value is 1 if
|
/* Return whether or not Emacs owns the clipboard. Value is 1 if
|
||||||
Emacs does, 0 if Emacs does not, and -1 if that information is
|
Emacs does, 0 if Emacs does not, and -1 if that information is
|
||||||
|
|
@ -141,7 +132,7 @@ public final class EmacsSdk11Clipboard extends EmacsClipboard
|
||||||
NULL if no content is available. */
|
NULL if no content is available. */
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public byte[]
|
public String
|
||||||
getClipboard ()
|
getClipboard ()
|
||||||
{
|
{
|
||||||
ClipData clip;
|
ClipData clip;
|
||||||
|
|
@ -154,18 +145,8 @@ public final class EmacsSdk11Clipboard extends EmacsClipboard
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
context = EmacsService.SERVICE;
|
context = EmacsService.SERVICE;
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
text = clip.getItemAt (0).coerceToText (context);
|
text = clip.getItemAt (0).coerceToText (context);
|
||||||
return text.toString ().getBytes ("UTF-8");
|
return text.toString ();
|
||||||
}
|
|
||||||
catch (UnsupportedEncodingException exception)
|
|
||||||
{
|
|
||||||
Log.w (TAG, "getClipboard: " + exception);
|
|
||||||
}
|
|
||||||
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Return an array of targets currently provided by the
|
/* Return an array of targets currently provided by the
|
||||||
|
|
|
||||||
|
|
@ -52,21 +52,14 @@ public final class EmacsSdk8Clipboard extends EmacsClipboard
|
||||||
= (ClipboardManager) context.getSystemService (what);
|
= (ClipboardManager) context.getSystemService (what);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Set the clipboard text to CLIPBOARD, a string in UTF-8
|
/* Save the STRING into the clipboard by way of text copied by the
|
||||||
encoding. */
|
user. */
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void
|
public void
|
||||||
setClipboard (byte[] bytes)
|
setClipboard (String string)
|
||||||
{
|
{
|
||||||
try
|
manager.setText (string);
|
||||||
{
|
|
||||||
manager.setText (new String (bytes, "UTF-8"));
|
|
||||||
}
|
|
||||||
catch (UnsupportedEncodingException exception)
|
|
||||||
{
|
|
||||||
Log.w (TAG, "setClipboard: " + exception);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Return whether or not Emacs owns the clipboard. Value is 1 if
|
/* Return whether or not Emacs owns the clipboard. Value is 1 if
|
||||||
|
|
@ -93,7 +86,7 @@ public final class EmacsSdk8Clipboard extends EmacsClipboard
|
||||||
NULL if no content is available. */
|
NULL if no content is available. */
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public byte[]
|
public String
|
||||||
getClipboard ()
|
getClipboard ()
|
||||||
{
|
{
|
||||||
String string;
|
String string;
|
||||||
|
|
@ -105,17 +98,7 @@ public final class EmacsSdk8Clipboard extends EmacsClipboard
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
string = text.toString ();
|
string = text.toString ();
|
||||||
|
return string;
|
||||||
try
|
|
||||||
{
|
|
||||||
return string.getBytes ("UTF-8");
|
|
||||||
}
|
|
||||||
catch (UnsupportedEncodingException exception)
|
|
||||||
{
|
|
||||||
Log.w (TAG, "getClipboard: " + exception);
|
|
||||||
}
|
|
||||||
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Return an array of targets currently provided by the
|
/* Return an array of targets currently provided by the
|
||||||
|
|
|
||||||
|
|
@ -94,10 +94,10 @@ android_init_emacs_clipboard (void)
|
||||||
name, signature); \
|
name, signature); \
|
||||||
eassert (clipboard_class.c_name);
|
eassert (clipboard_class.c_name);
|
||||||
|
|
||||||
FIND_METHOD (set_clipboard, "setClipboard", "([B)V");
|
FIND_METHOD (set_clipboard, "setClipboard", "(Ljava/lang/String;)V");
|
||||||
FIND_METHOD (owns_clipboard, "ownsClipboard", "()I");
|
FIND_METHOD (owns_clipboard, "ownsClipboard", "()I");
|
||||||
FIND_METHOD (clipboard_exists, "clipboardExists", "()Z");
|
FIND_METHOD (clipboard_exists, "clipboardExists", "()Z");
|
||||||
FIND_METHOD (get_clipboard, "getClipboard", "()[B");
|
FIND_METHOD (get_clipboard, "getClipboard", "()Ljava/lang/String;");
|
||||||
FIND_METHOD (get_clipboard_targets, "getClipboardTargets",
|
FIND_METHOD (get_clipboard_targets, "getClipboardTargets",
|
||||||
"()[Ljava/lang/String;");
|
"()[Ljava/lang/String;");
|
||||||
FIND_METHOD (get_clipboard_data, "getClipboardData",
|
FIND_METHOD (get_clipboard_data, "getClipboardData",
|
||||||
|
|
@ -151,28 +151,26 @@ DEFUN ("android-set-clipboard", Fandroid_set_clipboard,
|
||||||
doc: /* Set the clipboard text to STRING. */)
|
doc: /* Set the clipboard text to STRING. */)
|
||||||
(Lisp_Object string)
|
(Lisp_Object string)
|
||||||
{
|
{
|
||||||
jarray bytes;
|
jstring text;
|
||||||
|
|
||||||
if (!android_init_gui)
|
if (!android_init_gui)
|
||||||
error ("Accessing clipboard without display connection");
|
error ("Accessing clipboard without display connection");
|
||||||
|
|
||||||
CHECK_STRING (string);
|
CHECK_STRING (string);
|
||||||
string = ENCODE_UTF_8 (string);
|
string = code_convert_string_norecord (string, Qandroid_jni,
|
||||||
|
true);
|
||||||
|
|
||||||
bytes = (*android_java_env)->NewByteArray (android_java_env,
|
text = (*android_java_env)->NewStringUTF (android_java_env,
|
||||||
SBYTES (string));
|
SSDATA (string));
|
||||||
android_exception_check ();
|
android_exception_check ();
|
||||||
|
|
||||||
(*android_java_env)->SetByteArrayRegion (android_java_env, bytes,
|
|
||||||
0, SBYTES (string),
|
|
||||||
(jbyte *) SDATA (string));
|
|
||||||
(*android_java_env)->CallVoidMethod (android_java_env,
|
(*android_java_env)->CallVoidMethod (android_java_env,
|
||||||
clipboard,
|
clipboard,
|
||||||
clipboard_class.set_clipboard,
|
clipboard_class.set_clipboard,
|
||||||
bytes);
|
text);
|
||||||
android_exception_check_1 (bytes);
|
android_exception_check_1 (text);
|
||||||
|
ANDROID_DELETE_LOCAL_REF (text);
|
||||||
|
|
||||||
ANDROID_DELETE_LOCAL_REF (bytes);
|
|
||||||
return Qnil;
|
return Qnil;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -185,39 +183,39 @@ Alternatively, return nil if the clipboard is empty. */)
|
||||||
(void)
|
(void)
|
||||||
{
|
{
|
||||||
Lisp_Object string;
|
Lisp_Object string;
|
||||||
jarray bytes;
|
jstring text;
|
||||||
jmethodID method;
|
jmethodID method;
|
||||||
size_t length;
|
jsize length;
|
||||||
jbyte *data;
|
const char *data;
|
||||||
|
|
||||||
if (!android_init_gui)
|
if (!android_init_gui)
|
||||||
error ("No Android display connection!");
|
error ("No Android display connection!");
|
||||||
|
|
||||||
method = clipboard_class.get_clipboard;
|
method = clipboard_class.get_clipboard;
|
||||||
bytes
|
text
|
||||||
= (*android_java_env)->CallObjectMethod (android_java_env,
|
= (*android_java_env)->CallObjectMethod (android_java_env,
|
||||||
clipboard,
|
clipboard,
|
||||||
method);
|
method);
|
||||||
android_exception_check ();
|
android_exception_check ();
|
||||||
|
|
||||||
if (!bytes)
|
if (!text)
|
||||||
return Qnil;
|
return Qnil;
|
||||||
|
|
||||||
length = (*android_java_env)->GetArrayLength (android_java_env,
|
/* Retrieve a pointer to the raw JNI-encoded bytes of the string. */
|
||||||
bytes);
|
length = (*android_java_env)->GetStringUTFLength (android_java_env,
|
||||||
data = (*android_java_env)->GetByteArrayElements (android_java_env,
|
text);
|
||||||
bytes, NULL);
|
data = (*android_java_env)->GetStringUTFChars (android_java_env, text,
|
||||||
android_exception_check_nonnull (data, bytes);
|
NULL);
|
||||||
|
android_exception_check_nonnull ((void *) data, text);
|
||||||
|
|
||||||
string = make_unibyte_string ((char *) data, length);
|
/* Copy them into a unibyte string for decoding. */
|
||||||
|
string = make_unibyte_string (data, length);
|
||||||
(*android_java_env)->ReleaseByteArrayElements (android_java_env,
|
(*android_java_env)->ReleaseStringUTFChars (android_java_env, text,
|
||||||
bytes, data,
|
data);
|
||||||
JNI_ABORT);
|
ANDROID_DELETE_LOCAL_REF (text);
|
||||||
ANDROID_DELETE_LOCAL_REF (bytes);
|
|
||||||
|
|
||||||
/* Now decode the resulting string. */
|
/* Now decode the resulting string. */
|
||||||
return code_convert_string_norecord (string, Qutf_8, false);
|
return code_convert_string_norecord (string, Qandroid_jni, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
DEFUN ("android-clipboard-exists-p", Fandroid_clipboard_exists_p,
|
DEFUN ("android-clipboard-exists-p", Fandroid_clipboard_exists_p,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue