forked from len0rd/rockbox
Android: Use wakeup objects instead of polling for the dialog results in the keyboard and yesno dialog, allowing a lot of code to be removed.
First part of FS#11708 git-svn-id: svn://svn.rockbox.org/rockbox/trunk@28512 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
parent
be51be6a99
commit
988bdc1cc4
5 changed files with 74 additions and 81 deletions
|
@ -43,21 +43,13 @@ public class RockboxKeyboardInput
|
||||||
{
|
{
|
||||||
public void onComplete(int resultCode, Intent data)
|
public void onComplete(int resultCode, Intent data)
|
||||||
{
|
{
|
||||||
if (resultCode == Activity.RESULT_OK)
|
put_result(resultCode == Activity.RESULT_OK,
|
||||||
{
|
data.getStringExtra("value"));
|
||||||
result = data.getStringExtra("value");
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
result = "";
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
public String get_result()
|
|
||||||
{
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
private native void put_result(boolean accepted, String new_string);
|
||||||
public boolean is_usable()
|
public boolean is_usable()
|
||||||
{
|
{
|
||||||
return RockboxService.get_instance().get_activity() != null;
|
return RockboxService.get_instance().get_activity() != null;
|
||||||
|
|
|
@ -26,15 +26,8 @@ import android.content.Intent;
|
||||||
|
|
||||||
public class RockboxYesno
|
public class RockboxYesno
|
||||||
{
|
{
|
||||||
private boolean result;
|
@SuppressWarnings("unused")
|
||||||
private boolean have_result;
|
private void yesno_display(String text)
|
||||||
|
|
||||||
public RockboxYesno()
|
|
||||||
{
|
|
||||||
have_result = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void yesno_display(String text)
|
|
||||||
{
|
{
|
||||||
RockboxActivity a = (RockboxActivity) RockboxService.get_instance().get_activity();
|
RockboxActivity a = (RockboxActivity) RockboxService.get_instance().get_activity();
|
||||||
Intent kbd = new Intent(a, YesnoActivity.class);
|
Intent kbd = new Intent(a, YesnoActivity.class);
|
||||||
|
@ -43,30 +36,16 @@ public class RockboxYesno
|
||||||
{
|
{
|
||||||
public void onComplete(int resultCode, Intent data)
|
public void onComplete(int resultCode, Intent data)
|
||||||
{
|
{
|
||||||
if (resultCode == Activity.RESULT_OK)
|
put_result(resultCode == Activity.RESULT_OK);
|
||||||
{
|
|
||||||
result = true;
|
|
||||||
have_result = true;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
result = false;
|
|
||||||
have_result = true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean result_ready()
|
@SuppressWarnings("unused")
|
||||||
{
|
private boolean is_usable()
|
||||||
return have_result;
|
|
||||||
}
|
|
||||||
public boolean get_result()
|
|
||||||
{
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean is_usable()
|
|
||||||
{
|
{
|
||||||
return RockboxService.get_instance().get_activity() != null;
|
return RockboxService.get_instance().get_activity() != null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private native void put_result(boolean result);
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,21 +23,40 @@
|
||||||
#if (CONFIG_PLATFORM&PLATFORM_ANDROID)
|
#if (CONFIG_PLATFORM&PLATFORM_ANDROID)
|
||||||
#include <jni.h>
|
#include <jni.h>
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
#include <stdio.h>
|
#include "string-extra.h"
|
||||||
#include <string.h>
|
#include "kernel.h"
|
||||||
#include <system.h>
|
|
||||||
|
|
||||||
extern JNIEnv *env_ptr;
|
extern JNIEnv *env_ptr;
|
||||||
static jclass RockboxKeyboardInput_class;
|
static jclass RockboxKeyboardInput_class;
|
||||||
static jobject RockboxKeyboardInput_instance;
|
static jobject RockboxKeyboardInput_instance;
|
||||||
static jmethodID kbd_inputfunc, kbd_result;
|
static jmethodID kbd_inputfunc;
|
||||||
|
static struct wakeup kbd_wakeup;
|
||||||
|
static bool accepted;
|
||||||
|
static jstring new_string;
|
||||||
|
|
||||||
|
JNIEXPORT void JNICALL
|
||||||
|
Java_org_rockbox_RockboxKeyboardInput_put_1result(JNIEnv *env, jobject this,
|
||||||
|
jboolean _accepted,
|
||||||
|
jstring _new_string)
|
||||||
|
{
|
||||||
|
(void)env;(void)this;
|
||||||
|
|
||||||
|
accepted = (bool)_accepted;
|
||||||
|
if (accepted)
|
||||||
|
{
|
||||||
|
new_string = _new_string;
|
||||||
|
(*env)->NewGlobalRef(env, new_string); /* prevet GC'ing */
|
||||||
|
}
|
||||||
|
wakeup_signal(&kbd_wakeup);
|
||||||
|
}
|
||||||
|
|
||||||
static void kdb_init(void)
|
static void kdb_init(void)
|
||||||
{
|
{
|
||||||
JNIEnv e = *env_ptr;
|
JNIEnv e = *env_ptr;
|
||||||
jmethodID kbd_is_usable;
|
static jmethodID kbd_is_usable;
|
||||||
if (RockboxKeyboardInput_class == NULL)
|
if (RockboxKeyboardInput_class == NULL)
|
||||||
{
|
{
|
||||||
|
wakeup_init(&kbd_wakeup);
|
||||||
/* get the class and its constructor */
|
/* get the class and its constructor */
|
||||||
RockboxKeyboardInput_class = e->FindClass(env_ptr,
|
RockboxKeyboardInput_class = e->FindClass(env_ptr,
|
||||||
"org/rockbox/RockboxKeyboardInput");
|
"org/rockbox/RockboxKeyboardInput");
|
||||||
|
@ -49,12 +68,11 @@ static void kdb_init(void)
|
||||||
constructor);
|
constructor);
|
||||||
kbd_inputfunc = e->GetMethodID(env_ptr, RockboxKeyboardInput_class,
|
kbd_inputfunc = e->GetMethodID(env_ptr, RockboxKeyboardInput_class,
|
||||||
"kbd_input", "(Ljava/lang/String;)V");
|
"kbd_input", "(Ljava/lang/String;)V");
|
||||||
kbd_result = e->GetMethodID(env_ptr, RockboxKeyboardInput_class,
|
kbd_is_usable = e->GetMethodID(env_ptr, RockboxKeyboardInput_class,
|
||||||
"get_result", "()Ljava/lang/String;");
|
"is_usable", "()Z");
|
||||||
}
|
}
|
||||||
|
|
||||||
/* need to get it every time incase the activity died/restarted */
|
/* need to get it every time incase the activity died/restarted */
|
||||||
kbd_is_usable = e->GetMethodID(env_ptr, RockboxKeyboardInput_class,
|
|
||||||
"is_usable", "()Z");
|
|
||||||
while (!e->CallBooleanMethod(env_ptr, RockboxKeyboardInput_instance,
|
while (!e->CallBooleanMethod(env_ptr, RockboxKeyboardInput_instance,
|
||||||
kbd_is_usable))
|
kbd_is_usable))
|
||||||
sleep(HZ/10);
|
sleep(HZ/10);
|
||||||
|
@ -64,24 +82,22 @@ int kbd_input(char* text, int buflen)
|
||||||
{
|
{
|
||||||
JNIEnv e = *env_ptr;
|
JNIEnv e = *env_ptr;
|
||||||
jstring str = e->NewStringUTF(env_ptr, text);
|
jstring str = e->NewStringUTF(env_ptr, text);
|
||||||
jobject ret;
|
const char *utf8_string;
|
||||||
const char* retchars;
|
|
||||||
kdb_init();
|
kdb_init();
|
||||||
|
|
||||||
e->CallVoidMethod(env_ptr, RockboxKeyboardInput_instance,kbd_inputfunc,str);
|
e->CallVoidMethod(env_ptr, RockboxKeyboardInput_instance,kbd_inputfunc,str);
|
||||||
|
|
||||||
do {
|
wakeup_wait(&kbd_wakeup, TIMEOUT_BLOCK);
|
||||||
sleep(HZ/10);
|
|
||||||
ret = e->CallObjectMethod(env_ptr, RockboxKeyboardInput_instance,
|
if (accepted)
|
||||||
kbd_result);
|
{
|
||||||
} while (!ret);
|
utf8_string = e->GetStringUTFChars(env_ptr, new_string, 0);
|
||||||
|
strlcpy(text, utf8_string, buflen);
|
||||||
|
e->ReleaseStringUTFChars(env_ptr, new_string, utf8_string);
|
||||||
|
e->DeleteGlobalRef(env_ptr, new_string);
|
||||||
|
}
|
||||||
|
|
||||||
retchars = e->GetStringUTFChars(env_ptr, ret, 0);
|
return !accepted; /* return 0 on success */
|
||||||
if (retchars[0])
|
|
||||||
strncpy(text, retchars, buflen);
|
|
||||||
e->ReleaseStringUTFChars(env_ptr, ret, retchars);
|
|
||||||
|
|
||||||
return text[0] ? 0 : 1; /* return 0 on success */
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int load_kbd(unsigned char* filename)
|
int load_kbd(unsigned char* filename)
|
||||||
|
|
|
@ -24,22 +24,34 @@
|
||||||
#include <jni.h>
|
#include <jni.h>
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <system.h>
|
|
||||||
#include "yesno.h"
|
#include "yesno.h"
|
||||||
#include "settings.h"
|
#include "settings.h"
|
||||||
#include "lang.h"
|
#include "lang.h"
|
||||||
|
#include "kernel.h"
|
||||||
|
|
||||||
extern JNIEnv *env_ptr;
|
extern JNIEnv *env_ptr;
|
||||||
static jclass RockboxYesno_class = NULL;
|
static jclass RockboxYesno_class = NULL;
|
||||||
static jobject RockboxYesno_instance = NULL;
|
static jobject RockboxYesno_instance = NULL;
|
||||||
static jmethodID yesno_func, result_ready, yesno_result;
|
static jmethodID yesno_func;
|
||||||
|
static struct wakeup yesno_wakeup;
|
||||||
|
static bool ret;
|
||||||
|
|
||||||
|
JNIEXPORT void JNICALL
|
||||||
|
Java_org_rockbox_RockboxYesno_put_1result(JNIEnv *env, jobject this, jboolean result)
|
||||||
|
{
|
||||||
|
(void)env;
|
||||||
|
(void)this;
|
||||||
|
ret = (bool)result;
|
||||||
|
wakeup_signal(&yesno_wakeup);
|
||||||
|
}
|
||||||
|
|
||||||
static void yesno_init(void)
|
static void yesno_init(void)
|
||||||
{
|
{
|
||||||
JNIEnv e = *env_ptr;
|
JNIEnv e = *env_ptr;
|
||||||
jmethodID yesno_is_usable;
|
static jmethodID yesno_is_usable;
|
||||||
if (RockboxYesno_class == NULL)
|
if (RockboxYesno_class == NULL)
|
||||||
{
|
{
|
||||||
|
wakeup_init(&yesno_wakeup);
|
||||||
/* get the class and its constructor */
|
/* get the class and its constructor */
|
||||||
RockboxYesno_class = e->FindClass(env_ptr,
|
RockboxYesno_class = e->FindClass(env_ptr,
|
||||||
"org/rockbox/RockboxYesno");
|
"org/rockbox/RockboxYesno");
|
||||||
|
@ -51,14 +63,10 @@ static void yesno_init(void)
|
||||||
constructor);
|
constructor);
|
||||||
yesno_func = e->GetMethodID(env_ptr, RockboxYesno_class,
|
yesno_func = e->GetMethodID(env_ptr, RockboxYesno_class,
|
||||||
"yesno_display", "(Ljava/lang/String;)V");
|
"yesno_display", "(Ljava/lang/String;)V");
|
||||||
yesno_result = e->GetMethodID(env_ptr, RockboxYesno_class,
|
yesno_is_usable = e->GetMethodID(env_ptr, RockboxYesno_class,
|
||||||
"get_result", "()Z");
|
"is_usable", "()Z");
|
||||||
result_ready = e->GetMethodID(env_ptr, RockboxYesno_class,
|
|
||||||
"result_ready", "()Z");
|
|
||||||
}
|
}
|
||||||
/* need to get it every time incase the activity died/restarted */
|
/* need to get it every time incase the activity died/restarted */
|
||||||
yesno_is_usable = e->GetMethodID(env_ptr, RockboxYesno_class,
|
|
||||||
"is_usable", "()Z");
|
|
||||||
while (!e->CallBooleanMethod(env_ptr, RockboxYesno_instance,
|
while (!e->CallBooleanMethod(env_ptr, RockboxYesno_instance,
|
||||||
yesno_is_usable))
|
yesno_is_usable))
|
||||||
sleep(HZ/10);
|
sleep(HZ/10);
|
||||||
|
@ -92,16 +100,13 @@ enum yesno_res gui_syncyesno_run(const struct text_message * main_message,
|
||||||
|
|
||||||
JNIEnv e = *env_ptr;
|
JNIEnv e = *env_ptr;
|
||||||
jstring message = build_message(main_message);
|
jstring message = build_message(main_message);
|
||||||
jboolean ret;
|
|
||||||
|
|
||||||
e->CallVoidMethod(env_ptr, RockboxYesno_instance, yesno_func, message);
|
e->CallVoidMethod(env_ptr, RockboxYesno_instance, yesno_func, message);
|
||||||
|
|
||||||
do {
|
|
||||||
sleep(HZ/10);
|
|
||||||
ret = e->CallBooleanMethod(env_ptr, RockboxYesno_instance, result_ready);
|
|
||||||
} while (!ret);
|
|
||||||
|
|
||||||
ret = e->CallBooleanMethod(env_ptr, RockboxYesno_instance, yesno_result);
|
wakeup_wait(&yesno_wakeup, TIMEOUT_BLOCK);
|
||||||
|
|
||||||
|
e->DeleteLocalRef(env_ptr, message);
|
||||||
|
|
||||||
return ret ? YESNO_YES : YESNO_NO;
|
return ret ? YESNO_YES : YESNO_NO;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -721,7 +721,8 @@ Lyre prototype 1 */
|
||||||
|
|
||||||
#if defined(HAVE_USBSTACK) || (CONFIG_CPU == JZ4732) \
|
#if defined(HAVE_USBSTACK) || (CONFIG_CPU == JZ4732) \
|
||||||
|| (CONFIG_CPU == AS3525) || (CONFIG_CPU == AS3525v2) \
|
|| (CONFIG_CPU == AS3525) || (CONFIG_CPU == AS3525v2) \
|
||||||
|| defined(CPU_S5L870X) || (CONFIG_CPU == S3C2440)
|
|| defined(CPU_S5L870X) || (CONFIG_CPU == S3C2440) \
|
||||||
|
|| defined(APPLICATION)
|
||||||
#define HAVE_WAKEUP_OBJECTS
|
#define HAVE_WAKEUP_OBJECTS
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue