diff --git a/android/AndroidManifest.xml b/android/AndroidManifest.xml index 4518241..c52cac2 100644 --- a/android/AndroidManifest.xml +++ b/android/AndroidManifest.xml @@ -17,7 +17,8 @@ - + + diff --git a/android/res/layout/keyboardinput.xml b/android/res/layout/keyboardinput.xml new file mode 100644 index 0000000..e922a3a --- /dev/null +++ b/android/res/layout/keyboardinput.xml @@ -0,0 +1,14 @@ + + + + + + + + + + diff --git a/android/src/org/rockbox/HostCallback.java b/android/src/org/rockbox/HostCallback.java new file mode 100644 index 0000000..0e69b3f --- /dev/null +++ b/android/src/org/rockbox/HostCallback.java @@ -0,0 +1,7 @@ +package org.rockbox; + +import android.content.Intent; + +public interface HostCallback { + public void onComplete(int resultCode, Intent data); +} diff --git a/android/src/org/rockbox/RockboxActivity.java b/android/src/org/rockbox/RockboxActivity.java index fb41b90..d5a03c6 100644 --- a/android/src/org/rockbox/RockboxActivity.java +++ b/android/src/org/rockbox/RockboxActivity.java @@ -22,7 +22,9 @@ package org.rockbox; import android.app.Activity; +import android.app.PendingIntent; import android.content.Intent; +import android.content.IntentFilter; import android.os.Bundle; import android.util.Log; import android.view.ViewGroup; @@ -41,6 +43,8 @@ public class RockboxActivity extends Activity ,WindowManager.LayoutParams.FLAG_FULLSCREEN); final Intent intent = new Intent(this, RockboxService.class); + final Activity thisActivity = this; + //intent.put startService(intent); /* Now it gets a bit tricky: * The service is started in the same thread as we are now, @@ -66,6 +70,7 @@ public class RockboxActivity extends Activity runOnUiThread(new Runnable() { @Override public void run() { + RockboxService.fb.resume(thisActivity); setContentView(RockboxService.fb); RockboxService.fb.invalidate(); } @@ -76,6 +81,7 @@ public class RockboxActivity extends Activity public void onResume() { + super.onResume(); if (RockboxService.fb != null) @@ -89,7 +95,7 @@ public class RockboxActivity extends Activity g.removeView(RockboxService.fb); setContentView(RockboxService.fb); } - RockboxService.fb.resume(); + RockboxService.fb.resume(this); } } @@ -116,6 +122,23 @@ public class RockboxActivity extends Activity super.onDestroy(); RockboxService.fb.suspend(); } + + private HostCallback hostcallback = null; + public void waitForActivity(Intent i, HostCallback callback) + { + if (hostcallback != null) + { + LOG("Something has gone wrong"); + } + hostcallback = callback; + startActivityForResult(i, 0); + } + + public void onActivityResult(int requestCode, int resultCode, Intent data) + { + hostcallback.onComplete(resultCode, data); + hostcallback = null; + } private void LOG(CharSequence text) { diff --git a/android/src/org/rockbox/RockboxFramebuffer.java b/android/src/org/rockbox/RockboxFramebuffer.java index 070ef5c..5f3bc9a 100644 --- a/android/src/org/rockbox/RockboxFramebuffer.java +++ b/android/src/org/rockbox/RockboxFramebuffer.java @@ -23,7 +23,9 @@ package org.rockbox; import java.nio.ByteBuffer; +import android.app.Activity; import android.content.Context; +import android.content.Intent; import android.graphics.Bitmap; import android.graphics.Canvas; import android.util.Log; @@ -35,11 +37,15 @@ public class RockboxFramebuffer extends View { private Bitmap btm; private ByteBuffer native_buf; + public Context context; + private Activity activity; public RockboxFramebuffer(Context c) { super(c); + context = c; btm = null; + activity = null; /* Needed so we can catch KeyEvents */ setFocusable(true); @@ -113,8 +119,9 @@ public class RockboxFramebuffer extends View public void suspend() { /* suspend, Rockbox will not make any lcd updates */ set_lcd_active(0); + activity = null; } - public void resume() + public void resume(Activity a) { /* Needed so we can catch KeyEvents */ setFocusable(true); @@ -124,9 +131,16 @@ public class RockboxFramebuffer extends View /* make updates again, the underlying function will * send an event */ set_lcd_active(1); + activity = a; + } + + public Activity getActivity() + { + return activity; } public native void set_lcd_active(int active); public native void touchHandler(boolean down, int x, int y); public native boolean buttonHandler(int keycode, boolean state); + } diff --git a/android/src/org/rockbox/RockboxKeyboardInput.java b/android/src/org/rockbox/RockboxKeyboardInput.java new file mode 100644 index 0000000..c83b5d3 --- /dev/null +++ b/android/src/org/rockbox/RockboxKeyboardInput.java @@ -0,0 +1,85 @@ +/*************************************************************************** + * __________ __ ___. + * Open \______ \ ____ ____ | | _\_ |__ _______ ___ + * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / + * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < + * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ + * \/ \/ \/ \/ \/ + * $Id$ + * + * Copyright (C) 2010 Jonathan Gordon + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY + * KIND, either express or implied. + * + ****************************************************************************/ + +package org.rockbox; + +import java.util.Arrays; + +import android.app.Activity; +import android.content.BroadcastReceiver; +import android.content.Context; +import android.content.Intent; +import android.net.Uri; +import android.os.Handler; +import android.os.HandlerThread; +import android.os.Process; +import android.util.Log; +import android.view.View; + +public class RockboxKeyboardInput +{ + private BroadcastReceiver b; + private String result; + private Intent myIntent; + private void LOG(CharSequence text) + { + Log.d("Rockbox", (String) text); + } + + public RockboxKeyboardInput() + { + result = null; + } + + + public void kbd_input(String text) + { + final RockboxActivity a = (RockboxActivity) RockboxService.fb.getActivity(); + LOG("bar"); + Intent kbd = new Intent(a, KeyboardActivity.class); + kbd.putExtra("value", text); + a.waitForActivity(kbd, new HostCallback(){ + + @Override + public void onComplete(int resultCode, Intent data) { + if (resultCode == Activity.RESULT_OK) + { + result = data.getStringExtra("value"); + } + else { + result = ""; + } + } + }); + } + public String get_result() + { + return result; + } + + public boolean is_usable() + { + LOG("is_usable"); + return RockboxService.fb.getActivity() != null; + } + + +} diff --git a/android/src/org/rockbox/RockboxService.java b/android/src/org/rockbox/RockboxService.java index 1416886..27da217 100644 --- a/android/src/org/rockbox/RockboxService.java +++ b/android/src/org/rockbox/RockboxService.java @@ -35,6 +35,7 @@ import java.util.TimerTask; import java.util.zip.ZipEntry; import java.util.zip.ZipFile; +import android.app.Activity; import android.app.Notification; import android.app.NotificationManager; import android.app.PendingIntent; diff --git a/apps/SOURCES b/apps/SOURCES index ad1003b..cb5e6ef 100644 --- a/apps/SOURCES +++ b/apps/SOURCES @@ -116,7 +116,11 @@ player/keyboard.c #ifdef HAVE_LCD_BITMAP recorder/bmp.c recorder/icons.c +#if (CONFIG_PLATFORM&PLATFORM_ANDROID) +hosted/keyboard.c +#else recorder/keyboard.c +#endif recorder/peakmeter.c #if defined(HAVE_ALBUMART) || defined(HAVE_JPEG) recorder/resize.c diff --git a/apps/hosted/keyboard.c b/apps/hosted/keyboard.c new file mode 100644 index 0000000..766d8e8 --- /dev/null +++ b/apps/hosted/keyboard.c @@ -0,0 +1,88 @@ +/*************************************************************************** + * __________ __ ___. + * Open \______ \ ____ ____ | | _\_ |__ _______ ___ + * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / + * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < + * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ + * \/ \/ \/ \/ \/ + * $Id$ + * + * Copyright (C) 2010 Jonathan Gordon + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY + * KIND, either express or implied. + * + ****************************************************************************/ +#include "config.h" + +#if (CONFIG_PLATFORM&PLATFORM_ANDROID) +#include +#include +#include +#include +#include "debug.h" +#include "pcm.h" +#include "splash.h" + +extern JNIEnv *env_ptr; +static jclass RockboxKeyboardInput_class = NULL; +static jobject RockboxKeyboardInput_instance; +static jmethodID kbd_inputfunc, kbd_result; + +static void kdb_init(void) +{ + JNIEnv e = *env_ptr; + jmethodID kbd_is_usable; + if (RockboxKeyboardInput_class == NULL) + { + /* get the class and its constructor */ + RockboxKeyboardInput_class = e->FindClass(env_ptr, "org/rockbox/RockboxKeyboardInput"); + jmethodID constructor = e->GetMethodID(env_ptr, RockboxKeyboardInput_class, "", "()V"); + RockboxKeyboardInput_instance = e->NewObject(env_ptr, RockboxKeyboardInput_class, constructor); + kbd_inputfunc = e->GetMethodID(env_ptr, RockboxKeyboardInput_class, + "kbd_input", "(Ljava/lang/String;)V"); + kbd_result = e->GetMethodID(env_ptr, RockboxKeyboardInput_class, + "get_result", "()Ljava/lang/String;"); + } + /* 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, kbd_is_usable)) + sleep(HZ/10); +} + +int kbd_input(char* text, int buflen) +{ + JNIEnv e = *env_ptr; + jstring str = e->NewStringUTF(env_ptr, text); + jobject ret; + const char* retchars; + kdb_init(); + + e->CallVoidMethod(env_ptr, RockboxKeyboardInput_instance, kbd_inputfunc, str); + + do { + sleep(HZ/10); + ret = e->CallObjectMethod(env_ptr, RockboxKeyboardInput_instance, kbd_result); + } while (!ret); + + e->ReleaseStringChars(env_ptr, str, NULL); + retchars = e->GetStringUTFChars(env_ptr, ret, 0); + snprintf(text, buflen, retchars); + e->ReleaseStringUTFChars(env_ptr, ret, retchars); + + return text[0]?1:0; +} + +int load_kbd(unsigned char* filename) +{ + (void)filename; + return 1; +} + +#endif