Hello, i’ve been using this juce hack for a while now and it’s mostly ok.
Yes, there are some other boring changes to make it work, i skipped over. let me see…
juce_ComponentPeer.h
// any OS keyboard not required
virtual void textInputNotRequired () {}
juce_android_windowing.cpp. note the hacks to the key codes. i’ve only fixed a few of them so that the basics work.
*** 91,102 ****
--- 94,106 ----
METHOD (requestFocus, "requestFocus", "()Z") \
METHOD (setVisible, "setVisible", "(Z)V") \
METHOD (isVisible, "isVisible", "()Z") \
METHOD (hasFocus, "hasFocus", "()Z") \
METHOD (invalidate, "invalidate", "(IIII)V") \
METHOD (containsPoint, "containsPoint", "(II)Z") \
+ METHOD (showKeyboard, "showKeyboard", "(Z)V") \
METHOD (createGLView, "createGLView", "()L" JUCE_ANDROID_ACTIVITY_CLASSPATH "$OpenGLView;") \
DECLARE_JNI_CLASS (ComponentPeerView, JUCE_ANDROID_ACTIVITY_CLASSPATH "$ComponentPeerView");
#undef JNI_CLASS_MEMBERS
***************
*** 353,364 ****
--- 357,379 ----
{
lastMousePos.setXY ((int) x, (int) y);
currentModifiers = currentModifiers.withoutMouseButtons();
handleMouseEvent (0, lastMousePos, currentModifiers, time);
}
+ void handleKeyDownCallback (int k, int kc)
+ {
+ handleKeyPress(k, kc);
+ }
+
+ void handleKeyUpCallback (int k, int kc)
+ {
+ //handleKeyUpOrDown(false);
+ }
+
+
//==============================================================================
bool isFocused() const
{
return view.callBooleanMethod (ComponentPeerView.hasFocus);
}
***************
*** 374,386 ****
else
handleFocusLoss();
}
void textInputRequired (const Point<int>& position)
{
! // TODO
}
//==============================================================================
void handlePaintCallback (JNIEnv* env, jobject canvas)
{
jobject rect = env->CallObjectMethod (canvas, CanvasMinimal.getClipBounds);
--- 389,411 ----
else
handleFocusLoss();
}
void textInputRequired (const Point<int>& position)
{
! view.callVoidMethod (ComponentPeerView.showKeyboard, true);
! }
!
! void textInputNotRequired ()
! {
! view.callVoidMethod (ComponentPeerView.showKeyboard, false);
! }
!
! void dismissPendingTextInput()
! {
! view.callVoidMethod (ComponentPeerView.showKeyboard, false);
}
//==============================================================================
void handlePaintCallback (JNIEnv* env, jobject canvas)
{
jobject rect = env->CallObjectMethod (canvas, CanvasMinimal.getClipBounds);
***************
*** 557,568 ****
--- 582,597 ----
JUCE_VIEW_CALLBACK (void, handleMouseDown, (JNIEnv* env, jobject view, jfloat x, jfloat y, jlong time), handleMouseDownCallback ((float) x, (float) y, (int64) time))
JUCE_VIEW_CALLBACK (void, handleMouseDrag, (JNIEnv* env, jobject view, jfloat x, jfloat y, jlong time), handleMouseDragCallback ((float) x, (float) y, (int64) time))
JUCE_VIEW_CALLBACK (void, handleMouseUp, (JNIEnv* env, jobject view, jfloat x, jfloat y, jlong time), handleMouseUpCallback ((float) x, (float) y, (int64) time))
JUCE_VIEW_CALLBACK (void, viewSizeChanged, (JNIEnv* env, jobject view), handleMovedOrResized())
JUCE_VIEW_CALLBACK (void, focusChanged, (JNIEnv* env, jobject view, jboolean hasFocus), handleFocusChangeCallback (hasFocus))
+ JUCE_VIEW_CALLBACK (void, handleKeyDown, (JNIEnv* env, jobject view, jint k, jint kc), handleKeyDownCallback ((int) k, (int)kc))
+
+ JUCE_VIEW_CALLBACK (void, handleKeyUp, (JNIEnv* env, jobject view, jint k, jint kc), handleKeyUpCallback ((int) k, (int)kc))
+
//==============================================================================
ComponentPeer* Component::createNewPeer (int styleFlags, void*)
{
return new AndroidComponentPeer (*this, styleFlags);
}
***************
*** 621,637 ****
//==============================================================================
bool Process::isForegroundProcess()
{
return true; // TODO
}
-
void Process::makeForegroundProcess()
{
}
-
//==============================================================================
void JUCE_CALLTYPE NativeMessageBox::showMessageBoxAsync (AlertWindow::AlertIconType iconType,
const String& title, const String& message,
Component* associatedComponent)
{
android.activity.callVoidMethod (JuceAppActivity.showMessageBox, javaString (title).get(), javaString (message).get(), (jlong) 0);
--- 650,664 ----
***************
*** 752,778 ****
return juceString (text);
}
//==============================================================================
const int extendedKeyModifier = 0x10000;
const int KeyPress::spaceKey = ' ';
! const int KeyPress::returnKey = 0x0d;
! const int KeyPress::escapeKey = 0x1b;
! const int KeyPress::backspaceKey = 0x7f;
const int KeyPress::leftKey = extendedKeyModifier + 1;
const int KeyPress::rightKey = extendedKeyModifier + 2;
const int KeyPress::upKey = extendedKeyModifier + 3;
const int KeyPress::downKey = extendedKeyModifier + 4;
const int KeyPress::pageUpKey = extendedKeyModifier + 5;
const int KeyPress::pageDownKey = extendedKeyModifier + 6;
const int KeyPress::endKey = extendedKeyModifier + 7;
const int KeyPress::homeKey = extendedKeyModifier + 8;
const int KeyPress::deleteKey = extendedKeyModifier + 9;
const int KeyPress::insertKey = -1;
! const int KeyPress::tabKey = 9;
const int KeyPress::F1Key = extendedKeyModifier + 10;
const int KeyPress::F2Key = extendedKeyModifier + 11;
const int KeyPress::F3Key = extendedKeyModifier + 12;
const int KeyPress::F4Key = extendedKeyModifier + 13;
const int KeyPress::F5Key = extendedKeyModifier + 14;
const int KeyPress::F6Key = extendedKeyModifier + 16;
--- 779,810 ----
return juceString (text);
}
//==============================================================================
const int extendedKeyModifier = 0x10000;
+ const int KeyPress::returnKey = 66;
+ const int KeyPress::escapeKey = 4;
+ const int KeyPress::backspaceKey = 67;
+ const int KeyPress::tabKey = 61;
+
const int KeyPress::spaceKey = ' ';
! //const int KeyPress::returnKey = 0x0d;
! //const int KeyPress::escapeKey = 0x1b;
! //const int KeyPress::backspaceKey = 0x7f;
const int KeyPress::leftKey = extendedKeyModifier + 1;
const int KeyPress::rightKey = extendedKeyModifier + 2;
const int KeyPress::upKey = extendedKeyModifier + 3;
const int KeyPress::downKey = extendedKeyModifier + 4;
const int KeyPress::pageUpKey = extendedKeyModifier + 5;
const int KeyPress::pageDownKey = extendedKeyModifier + 6;
const int KeyPress::endKey = extendedKeyModifier + 7;
const int KeyPress::homeKey = extendedKeyModifier + 8;
const int KeyPress::deleteKey = extendedKeyModifier + 9;
const int KeyPress::insertKey = -1;
! //const int KeyPress::tabKey = 9;
const int KeyPress::F1Key = extendedKeyModifier + 10;
const int KeyPress::F2Key = extendedKeyModifier + 11;
const int KeyPress::F3Key = extendedKeyModifier + 12;
const int KeyPress::F4Key = extendedKeyModifier + 13;
const int KeyPress::F5Key = extendedKeyModifier + 14;
const int KeyPress::F6Key = extendedKeyModifier + 16;
There are some changes you have to make also to your generated java activity class:
[code]import android.view.inputmethod.InputMethodManager;
…
private native void handleKeyDown (int keycode, int textchar);
private native void handleKeyUp (int keycode, int textchar);
@Override
public boolean onKeyDown(int keyCode, KeyEvent event)
{
handleKeyDown(keyCode, event.getUnicodeChar());
return true;
}
@Override
public boolean onKeyUp(int keyCode, KeyEvent event)
{
handleKeyUp(keyCode, event.getUnicodeChar());
return true;
}
public void showKeyboard(boolean v)
{
InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
if (v)
imm.showSoftInput(this, InputMethodManager.SHOW_FORCED);
else
imm.hideSoftInputFromWindow(getWindowToken(), 0);
}
[/code]
i think that might be it,
– hugh.