mirror of
https://github.com/juce-framework/JUCE.git
synced 2026-01-30 02:50:05 +00:00
Android: keyboard input support.
This commit is contained in:
parent
9a9adab648
commit
f292238b32
4 changed files with 132 additions and 9 deletions
|
|
@ -34,9 +34,14 @@ import android.content.res.Configuration;
|
|||
import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
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.opengl.*;
|
||||
import android.text.ClipboardManager;
|
||||
import android.text.InputType;
|
||||
import java.io.BufferedInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
|
|
@ -350,6 +355,52 @@ public final class JuceDemo extends Activity
|
|||
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
|
||||
protected void onSizeChanged (int w, int h, int oldw, int oldh)
|
||||
|
|
|
|||
|
|
@ -34,9 +34,14 @@ import android.content.res.Configuration;
|
|||
import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
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.opengl.*;
|
||||
import android.text.ClipboardManager;
|
||||
import android.text.InputType;
|
||||
import java.io.BufferedInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
|
|
@ -350,6 +355,52 @@ public final class JuceAppActivity extends Activity
|
|||
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
|
||||
protected void onSizeChanged (int w, int h, int oldw, int oldh)
|
||||
|
|
|
|||
|
|
@ -94,6 +94,7 @@ DECLARE_JNI_CLASS (CanvasMinimal, "android/graphics/Canvas");
|
|||
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");
|
||||
|
|
@ -356,6 +357,15 @@ public:
|
|||
handleMouseEvent (index, lastMousePos, currentModifiers, time);
|
||||
}
|
||||
|
||||
void handleKeyDownCallback (int k, int kc)
|
||||
{
|
||||
handleKeyPress (k, kc);
|
||||
}
|
||||
|
||||
void handleKeyUpCallback (int k, int kc)
|
||||
{
|
||||
}
|
||||
|
||||
//==============================================================================
|
||||
bool isFocused() const
|
||||
{
|
||||
|
|
@ -375,11 +385,16 @@ public:
|
|||
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)
|
||||
{
|
||||
|
|
@ -548,8 +563,7 @@ Point<int> AndroidComponentPeer::lastMousePos;
|
|||
#define JUCE_VIEW_CALLBACK(returnType, javaMethodName, params, juceMethodInvocation) \
|
||||
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; \
|
||||
}
|
||||
|
||||
|
|
@ -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, 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*)
|
||||
|
|
@ -756,9 +772,9 @@ String SystemClipboard::getTextFromClipboard()
|
|||
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::returnKey = 66;
|
||||
const int KeyPress::escapeKey = 4;
|
||||
const int KeyPress::backspaceKey = 67;
|
||||
const int KeyPress::leftKey = extendedKeyModifier + 1;
|
||||
const int KeyPress::rightKey = extendedKeyModifier + 2;
|
||||
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::deleteKey = extendedKeyModifier + 9;
|
||||
const int KeyPress::insertKey = -1;
|
||||
const int KeyPress::tabKey = 9;
|
||||
const int KeyPress::tabKey = 61;
|
||||
const int KeyPress::F1Key = extendedKeyModifier + 10;
|
||||
const int KeyPress::F2Key = extendedKeyModifier + 11;
|
||||
const int KeyPress::F3Key = extendedKeyModifier + 12;
|
||||
|
|
|
|||
|
|
@ -192,7 +192,12 @@ void Label::componentVisibilityChanged (Component& component)
|
|||
void Label::textWasEdited() {}
|
||||
void Label::textWasChanged() {}
|
||||
void Label::editorShown (TextEditor*) {}
|
||||
void Label::editorAboutToBeHidden (TextEditor*) {}
|
||||
|
||||
void Label::editorAboutToBeHidden (TextEditor*)
|
||||
{
|
||||
if (ComponentPeer* const peer = getPeer())
|
||||
peer->dismissPendingTextInput();
|
||||
}
|
||||
|
||||
void Label::showEditor()
|
||||
{
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue