Browse Source

Android: keyboard input support.

tags/2021-05-28
jules 13 years ago
parent
commit
f292238b32
4 changed files with 132 additions and 9 deletions
  1. +51
    -0
      extras/JuceDemo/Builds/Android/src/com/juce/JuceDemo.java
  2. +51
    -0
      modules/juce_core/native/java/JuceAppActivity.java
  3. +24
    -8
      modules/juce_gui_basics/native/juce_android_Windowing.cpp
  4. +6
    -1
      modules/juce_gui_basics/widgets/juce_Label.cpp

+ 51
- 0
extras/JuceDemo/Builds/Android/src/com/juce/JuceDemo.java View File

@@ -34,9 +34,14 @@ import android.content.res.Configuration;
import android.net.Uri; import android.net.Uri;
import android.os.Bundle; import android.os.Bundle;
import android.view.*; import android.view.*;
import android.view.inputmethod.BaseInputConnection;
import android.view.inputmethod.EditorInfo;
import android.view.inputmethod.InputConnection;
import android.view.inputmethod.InputMethodManager;
import android.graphics.*; import android.graphics.*;
import android.opengl.*; import android.opengl.*;
import android.text.ClipboardManager; import android.text.ClipboardManager;
import android.text.InputType;
import java.io.BufferedInputStream; import java.io.BufferedInputStream;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
@@ -350,6 +355,52 @@ public final class JuceDemo extends Activity
return false; return false;
} }
//==============================================================================
private native void handleKeyDown (int keycode, int textchar);
private native void handleKeyUp (int keycode, int textchar);
public void showKeyboard (boolean shouldShow)
{
InputMethodManager imm = (InputMethodManager) getSystemService (Context.INPUT_METHOD_SERVICE);
if (imm != null)
{
if (shouldShow)
imm.showSoftInput (this, InputMethodManager.SHOW_FORCED);
else
imm.hideSoftInputFromWindow (getWindowToken(), 0);
}
}
@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;
}
// this is here to make keyboard entry work on a Galaxy Tab2 10.1
@Override
public InputConnection onCreateInputConnection (EditorInfo outAttrs)
{
outAttrs.actionLabel = "";
outAttrs.hintText = "";
outAttrs.initialCapsMode = 0;
outAttrs.initialSelEnd = outAttrs.initialSelStart = -1;
outAttrs.label = "";
outAttrs.imeOptions = EditorInfo.IME_ACTION_DONE | EditorInfo.IME_FLAG_NO_EXTRACT_UI;
outAttrs.inputType = InputType.TYPE_NULL;
return new BaseInputConnection (this, false);
}
//============================================================================== //==============================================================================
@Override @Override
protected void onSizeChanged (int w, int h, int oldw, int oldh) protected void onSizeChanged (int w, int h, int oldw, int oldh)


+ 51
- 0
modules/juce_core/native/java/JuceAppActivity.java View File

@@ -34,9 +34,14 @@ import android.content.res.Configuration;
import android.net.Uri; import android.net.Uri;
import android.os.Bundle; import android.os.Bundle;
import android.view.*; import android.view.*;
import android.view.inputmethod.BaseInputConnection;
import android.view.inputmethod.EditorInfo;
import android.view.inputmethod.InputConnection;
import android.view.inputmethod.InputMethodManager;
import android.graphics.*; import android.graphics.*;
import android.opengl.*; import android.opengl.*;
import android.text.ClipboardManager; import android.text.ClipboardManager;
import android.text.InputType;
import java.io.BufferedInputStream; import java.io.BufferedInputStream;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
@@ -350,6 +355,52 @@ public final class JuceAppActivity extends Activity
return false; return false;
} }
//==============================================================================
private native void handleKeyDown (int keycode, int textchar);
private native void handleKeyUp (int keycode, int textchar);
public void showKeyboard (boolean shouldShow)
{
InputMethodManager imm = (InputMethodManager) getSystemService (Context.INPUT_METHOD_SERVICE);
if (imm != null)
{
if (shouldShow)
imm.showSoftInput (this, InputMethodManager.SHOW_FORCED);
else
imm.hideSoftInputFromWindow (getWindowToken(), 0);
}
}
@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;
}
// this is here to make keyboard entry work on a Galaxy Tab2 10.1
@Override
public InputConnection onCreateInputConnection (EditorInfo outAttrs)
{
outAttrs.actionLabel = "";
outAttrs.hintText = "";
outAttrs.initialCapsMode = 0;
outAttrs.initialSelEnd = outAttrs.initialSelStart = -1;
outAttrs.label = "";
outAttrs.imeOptions = EditorInfo.IME_ACTION_DONE | EditorInfo.IME_FLAG_NO_EXTRACT_UI;
outAttrs.inputType = InputType.TYPE_NULL;
return new BaseInputConnection (this, false);
}
//============================================================================== //==============================================================================
@Override @Override
protected void onSizeChanged (int w, int h, int oldw, int oldh) protected void onSizeChanged (int w, int h, int oldw, int oldh)


+ 24
- 8
modules/juce_gui_basics/native/juce_android_Windowing.cpp View File

@@ -94,6 +94,7 @@ DECLARE_JNI_CLASS (CanvasMinimal, "android/graphics/Canvas");
METHOD (hasFocus, "hasFocus", "()Z") \ METHOD (hasFocus, "hasFocus", "()Z") \
METHOD (invalidate, "invalidate", "(IIII)V") \ METHOD (invalidate, "invalidate", "(IIII)V") \
METHOD (containsPoint, "containsPoint", "(II)Z") \ METHOD (containsPoint, "containsPoint", "(II)Z") \
METHOD (showKeyboard, "showKeyboard", "(Z)V") \
METHOD (createGLView, "createGLView", "()L" JUCE_ANDROID_ACTIVITY_CLASSPATH "$OpenGLView;") \ METHOD (createGLView, "createGLView", "()L" JUCE_ANDROID_ACTIVITY_CLASSPATH "$OpenGLView;") \
DECLARE_JNI_CLASS (ComponentPeerView, JUCE_ANDROID_ACTIVITY_CLASSPATH "$ComponentPeerView"); DECLARE_JNI_CLASS (ComponentPeerView, JUCE_ANDROID_ACTIVITY_CLASSPATH "$ComponentPeerView");
@@ -356,6 +357,15 @@ public:
handleMouseEvent (index, lastMousePos, currentModifiers, time); handleMouseEvent (index, lastMousePos, currentModifiers, time);
} }
void handleKeyDownCallback (int k, int kc)
{
handleKeyPress (k, kc);
}
void handleKeyUpCallback (int k, int kc)
{
}
//============================================================================== //==============================================================================
bool isFocused() const bool isFocused() const
{ {
@@ -375,11 +385,16 @@ public:
handleFocusLoss(); handleFocusLoss();
} }
void textInputRequired (const Point<int>& position)
void textInputRequired (const Point<int>&)
{ {
// TODO
view.callVoidMethod (ComponentPeerView.showKeyboard, true);
} }
void dismissPendingTextInput()
{
view.callVoidMethod (ComponentPeerView.showKeyboard, false);
}
//============================================================================== //==============================================================================
void handlePaintCallback (JNIEnv* env, jobject canvas) void handlePaintCallback (JNIEnv* env, jobject canvas)
{ {
@@ -548,8 +563,7 @@ Point<int> AndroidComponentPeer::lastMousePos;
#define JUCE_VIEW_CALLBACK(returnType, javaMethodName, params, juceMethodInvocation) \ #define JUCE_VIEW_CALLBACK(returnType, javaMethodName, params, juceMethodInvocation) \
JUCE_JNI_CALLBACK (JUCE_JOIN_MACRO (JUCE_ANDROID_ACTIVITY_CLASSNAME, _00024ComponentPeerView), javaMethodName, returnType, params) \ JUCE_JNI_CALLBACK (JUCE_JOIN_MACRO (JUCE_ANDROID_ACTIVITY_CLASSNAME, _00024ComponentPeerView), javaMethodName, returnType, params) \
{ \ { \
AndroidComponentPeer* const peer = AndroidComponentPeer::findPeerForJavaView (env, view); \
if (peer != nullptr) \
if (AndroidComponentPeer* const peer = AndroidComponentPeer::findPeerForJavaView (env, view)) \
peer->juceMethodInvocation; \ peer->juceMethodInvocation; \
} }
@@ -559,6 +573,8 @@ JUCE_VIEW_CALLBACK (void, handleMouseDrag, (JNIEnv* env, jobject view, jint i,
JUCE_VIEW_CALLBACK (void, handleMouseUp, (JNIEnv* env, jobject view, jint i, jfloat x, jfloat y, jlong time), handleMouseUpCallback (i, (float) x, (float) y, (int64) time)) JUCE_VIEW_CALLBACK (void, handleMouseUp, (JNIEnv* env, jobject view, jint i, jfloat x, jfloat y, jlong time), handleMouseUpCallback (i, (float) x, (float) y, (int64) time))
JUCE_VIEW_CALLBACK (void, viewSizeChanged, (JNIEnv* env, jobject view), handleMovedOrResized()) 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, 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*) ComponentPeer* Component::createNewPeer (int styleFlags, void*)
@@ -756,9 +772,9 @@ String SystemClipboard::getTextFromClipboard()
const int extendedKeyModifier = 0x10000; const int extendedKeyModifier = 0x10000;
const int KeyPress::spaceKey = ' '; const int KeyPress::spaceKey = ' ';
const int KeyPress::returnKey = 0x0d;
const int KeyPress::escapeKey = 0x1b;
const int KeyPress::backspaceKey = 0x7f;
const int KeyPress::returnKey = 66;
const int KeyPress::escapeKey = 4;
const int KeyPress::backspaceKey = 67;
const int KeyPress::leftKey = extendedKeyModifier + 1; const int KeyPress::leftKey = extendedKeyModifier + 1;
const int KeyPress::rightKey = extendedKeyModifier + 2; const int KeyPress::rightKey = extendedKeyModifier + 2;
const int KeyPress::upKey = extendedKeyModifier + 3; const int KeyPress::upKey = extendedKeyModifier + 3;
@@ -769,7 +785,7 @@ const int KeyPress::endKey = extendedKeyModifier + 7;
const int KeyPress::homeKey = extendedKeyModifier + 8; const int KeyPress::homeKey = extendedKeyModifier + 8;
const int KeyPress::deleteKey = extendedKeyModifier + 9; const int KeyPress::deleteKey = extendedKeyModifier + 9;
const int KeyPress::insertKey = -1; const int KeyPress::insertKey = -1;
const int KeyPress::tabKey = 9;
const int KeyPress::tabKey = 61;
const int KeyPress::F1Key = extendedKeyModifier + 10; const int KeyPress::F1Key = extendedKeyModifier + 10;
const int KeyPress::F2Key = extendedKeyModifier + 11; const int KeyPress::F2Key = extendedKeyModifier + 11;
const int KeyPress::F3Key = extendedKeyModifier + 12; const int KeyPress::F3Key = extendedKeyModifier + 12;


+ 6
- 1
modules/juce_gui_basics/widgets/juce_Label.cpp View File

@@ -192,7 +192,12 @@ void Label::componentVisibilityChanged (Component& component)
void Label::textWasEdited() {} void Label::textWasEdited() {}
void Label::textWasChanged() {} void Label::textWasChanged() {}
void Label::editorShown (TextEditor*) {} void Label::editorShown (TextEditor*) {}
void Label::editorAboutToBeHidden (TextEditor*) {}
void Label::editorAboutToBeHidden (TextEditor*)
{
if (ComponentPeer* const peer = getPeer())
peer->dismissPendingTextInput();
}
void Label::showEditor() void Label::showEditor()
{ {


Loading…
Cancel
Save