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
EditText: implement addTextChangedListener()
This commit is contained in:
@@ -215,6 +215,14 @@ JNIEXPORT jlong JNICALL Java_android_widget_EditText_native_1constructor
|
|||||||
JNIEXPORT jstring JNICALL Java_android_widget_EditText_native_1getText
|
JNIEXPORT jstring JNICALL Java_android_widget_EditText_native_1getText
|
||||||
(JNIEnv *, jobject, jlong);
|
(JNIEnv *, jobject, jlong);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Class: android_widget_EditText
|
||||||
|
* Method: native_addTextChangedListener
|
||||||
|
* Signature: (JLandroid/text/TextWatcher;)V
|
||||||
|
*/
|
||||||
|
JNIEXPORT void JNICALL Java_android_widget_EditText_native_1addTextChangedListener
|
||||||
|
(JNIEnv *, jobject, jlong, jobject);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -21,3 +21,31 @@ JNIEXPORT jstring JNICALL Java_android_widget_EditText_native_1getText(JNIEnv *e
|
|||||||
const char *text = gtk_entry_buffer_get_text(gtk_entry_get_buffer(entry));
|
const char *text = gtk_entry_buffer_get_text(gtk_entry_get_buffer(entry));
|
||||||
return _JSTRING(text);
|
return _JSTRING(text);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
struct changed_callback_data {
|
||||||
|
jobject this;
|
||||||
|
jobject listener;
|
||||||
|
jmethodID listener_method;
|
||||||
|
jmethodID getText;
|
||||||
|
};
|
||||||
|
|
||||||
|
static void changed_cb(GtkEditable* self, struct changed_callback_data *d) {
|
||||||
|
JNIEnv *env = get_jni_env();
|
||||||
|
|
||||||
|
jobject text = (*env)->CallObjectMethod(env, d->this, d->getText);
|
||||||
|
(*env)->CallVoidMethod(env, d->listener, d->listener_method, text);
|
||||||
|
if((*env)->ExceptionCheck(env))
|
||||||
|
(*env)->ExceptionDescribe(env);
|
||||||
|
}
|
||||||
|
|
||||||
|
JNIEXPORT void JNICALL Java_android_widget_EditText_native_1addTextChangedListener(JNIEnv *env, jobject this, jlong widget_ptr, jobject listener) {
|
||||||
|
GtkEntry *entry = GTK_ENTRY(_PTR(widget_ptr));
|
||||||
|
|
||||||
|
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), "afterTextChanged", "(Landroid/text/Editable;)V");
|
||||||
|
callback_data->getText = _METHOD(_CLASS(this), "getText", "()Landroid/text/Editable;");
|
||||||
|
|
||||||
|
g_signal_connect(GTK_EDITABLE(entry), "changed", G_CALLBACK(changed_cb), callback_data);
|
||||||
|
}
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package android.widget;
|
|||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.text.Editable;
|
import android.text.Editable;
|
||||||
|
import android.text.TextWatcher;
|
||||||
import android.util.AttributeSet;
|
import android.util.AttributeSet;
|
||||||
|
|
||||||
public class EditText extends TextView {
|
public class EditText extends TextView {
|
||||||
@@ -16,6 +17,7 @@ public class EditText extends TextView {
|
|||||||
@Override
|
@Override
|
||||||
protected native long native_constructor(Context context, AttributeSet attrs);
|
protected native long native_constructor(Context context, AttributeSet attrs);
|
||||||
protected native String native_getText(long widget);
|
protected native String native_getText(long widget);
|
||||||
|
protected native void native_addTextChangedListener(long widget, TextWatcher watcher);
|
||||||
|
|
||||||
public Editable getText() {
|
public Editable getText() {
|
||||||
return new FIXME_Editable(native_getText(widget));
|
return new FIXME_Editable(native_getText(widget));
|
||||||
@@ -58,4 +60,9 @@ public class EditText extends TextView {
|
|||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void addTextChangedListener(TextWatcher watcher) {
|
||||||
|
native_addTextChangedListener(widget, watcher);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user