You've already forked android_translation_layer
mirror of
https://gitlab.com/android_translation_layer/android_translation_layer.git
synced 2025-10-27 11:48:10 -07:00
implement EditText.setOnEditorActionListener()
This makes the NewPipe search work again
This commit is contained in:
@@ -223,6 +223,14 @@ JNIEXPORT jstring JNICALL Java_android_widget_EditText_native_1getText
|
||||
JNIEXPORT void JNICALL Java_android_widget_EditText_native_1addTextChangedListener
|
||||
(JNIEnv *, jobject, jlong, jobject);
|
||||
|
||||
/*
|
||||
* Class: android_widget_EditText
|
||||
* Method: native_setOnEditorActionListener
|
||||
* Signature: (JLandroid/widget/TextView/OnEditorActionListener;)V
|
||||
*/
|
||||
JNIEXPORT void JNICALL Java_android_widget_EditText_native_1setOnEditorActionListener
|
||||
(JNIEnv *, jobject, jlong, jobject);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -136,6 +136,9 @@ void set_up_handle_cache(JNIEnv *env)
|
||||
handle_cache.looper.class = _REF((*env)->FindClass(env, "android/os/Looper"));
|
||||
handle_cache.looper.loop = _STATIC_METHOD(handle_cache.looper.class, "loop", "()V");
|
||||
handle_cache.looper.prepareMainLooper = _STATIC_METHOD(handle_cache.looper.class, "prepareMainLooper", "()V");
|
||||
|
||||
handle_cache.key_event.class = _REF((*env)->FindClass(env, "android/view/KeyEvent"));
|
||||
handle_cache.key_event.constructor = _METHOD(handle_cache.key_event.class, "<init>", "(II)V");
|
||||
}
|
||||
|
||||
void extract_from_apk(const char *path, const char *target) {
|
||||
|
||||
@@ -91,6 +91,10 @@ struct handle_cache {
|
||||
jmethodID loop;
|
||||
jmethodID prepareMainLooper;
|
||||
} looper;
|
||||
struct {
|
||||
jclass class;
|
||||
jmethodID constructor;
|
||||
} key_event;
|
||||
};
|
||||
|
||||
extern struct handle_cache handle_cache;
|
||||
|
||||
@@ -49,3 +49,31 @@ JNIEXPORT void JNICALL Java_android_widget_EditText_native_1addTextChangedListen
|
||||
|
||||
g_signal_connect(GTK_EDITABLE(entry), "changed", G_CALLBACK(changed_cb), callback_data);
|
||||
}
|
||||
|
||||
#define IME_ACTION_SEARCH 3
|
||||
#define KEYCODE_ENTER 66
|
||||
|
||||
static void on_activate(GtkEntry *entry, struct changed_callback_data *d)
|
||||
{
|
||||
JNIEnv *env = get_jni_env();
|
||||
|
||||
jobject key_event = (*env)->NewObject(env, handle_cache.key_event.class, handle_cache.key_event.constructor, IME_ACTION_SEARCH, KEYCODE_ENTER);
|
||||
(*env)->CallBooleanMethod(env, d->listener, d->listener_method, d->this, 0, key_event);
|
||||
if((*env)->ExceptionCheck(env))
|
||||
(*env)->ExceptionDescribe(env);
|
||||
}
|
||||
|
||||
JNIEXPORT void JNICALL Java_android_widget_EditText_native_1setOnEditorActionListener(JNIEnv *env, jobject this, jlong widget_ptr, jobject listener)
|
||||
{
|
||||
GtkEntry *entry = GTK_ENTRY(_PTR(widget_ptr));
|
||||
|
||||
if (!listener)
|
||||
return;
|
||||
|
||||
struct changed_callback_data *callback_data = malloc(sizeof(struct changed_callback_data));
|
||||
callback_data->this = _REF(this);
|
||||
callback_data->listener = _REF(listener);
|
||||
callback_data->listener_method = _METHOD(_CLASS(listener), "onEditorAction", "(Landroid/widget/TextView;ILandroid/view/KeyEvent;)Z");
|
||||
|
||||
g_signal_connect(entry, "activate", G_CALLBACK(on_activate), callback_data);
|
||||
}
|
||||
|
||||
@@ -19,6 +19,7 @@ public class EditText extends TextView {
|
||||
protected native long native_constructor(Context context, AttributeSet attrs);
|
||||
protected native String native_getText(long widget);
|
||||
protected native void native_addTextChangedListener(long widget, TextWatcher watcher);
|
||||
protected native void native_setOnEditorActionListener(long widget, OnEditorActionListener l);
|
||||
|
||||
public Editable getText() {
|
||||
return new SpannableStringBuilder(native_getText(widget));
|
||||
@@ -37,4 +38,9 @@ public class EditText extends TextView {
|
||||
public void addTextChangedListener(TextWatcher watcher) {
|
||||
native_addTextChangedListener(widget, watcher);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setOnEditorActionListener(OnEditorActionListener l) {
|
||||
native_setOnEditorActionListener(widget, l);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,6 +16,7 @@ import android.text.method.TransformationMethod;
|
||||
import android.text.style.URLSpan;
|
||||
import android.util.AttributeSet;
|
||||
import android.view.Gravity;
|
||||
import android.view.KeyEvent;
|
||||
import android.view.View;
|
||||
|
||||
public class TextView extends View {
|
||||
@@ -186,6 +187,7 @@ public class TextView extends View {
|
||||
public CharSequence getHint() {return "HINT";}
|
||||
|
||||
public static interface OnEditorActionListener {
|
||||
public abstract boolean onEditorAction(TextView v, int actionId, KeyEvent event);
|
||||
}
|
||||
|
||||
public static enum BufferType {
|
||||
|
||||
Reference in New Issue
Block a user