mirror of https://github.com/axmolengine/axmol.git
android lanscope keyboard ok.
This commit is contained in:
parent
e895d9d073
commit
73a3f776f0
|
@ -16,18 +16,34 @@ import android.view.inputmethod.InputMethodManager;
|
||||||
|
|
||||||
class Cocos2dxInputConnection implements InputConnection {
|
class Cocos2dxInputConnection implements InputConnection {
|
||||||
|
|
||||||
|
private boolean mDebug = false;
|
||||||
|
void LogD(String msg) {
|
||||||
|
if (mDebug) {
|
||||||
|
Log.d("Cocos2dxInputConnection", msg);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private Cocos2dxGLSurfaceView mView;
|
||||||
|
|
||||||
|
Cocos2dxInputConnection(Cocos2dxGLSurfaceView view) {
|
||||||
|
mView = view;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean beginBatchEdit() {
|
public boolean beginBatchEdit() {
|
||||||
|
LogD("beginBatchEdit");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean clearMetaKeyStates(int states) {
|
public boolean clearMetaKeyStates(int states) {
|
||||||
|
LogD("clearMetaKeyStates: " + states);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean commitCompletion(CompletionInfo text) {
|
public boolean commitCompletion(CompletionInfo text) {
|
||||||
|
LogD("commitCompletion: " + text.getText().toString());
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -36,53 +52,63 @@ class Cocos2dxInputConnection implements InputConnection {
|
||||||
if (null != mView) {
|
if (null != mView) {
|
||||||
final String insertText = text.toString();
|
final String insertText = text.toString();
|
||||||
mView.insertText(insertText);
|
mView.insertText(insertText);
|
||||||
|
LogD("commitText: " + insertText);
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean deleteSurroundingText(int leftLength, int rightLength) {
|
public boolean deleteSurroundingText(int leftLength, int rightLength) {
|
||||||
|
LogD("deleteSurroundingText: " + leftLength + "," + rightLength);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean endBatchEdit() {
|
public boolean endBatchEdit() {
|
||||||
|
LogD("endBatchEdit");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean finishComposingText() {
|
public boolean finishComposingText() {
|
||||||
|
LogD("finishComposingText");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getCursorCapsMode(int reqModes) {
|
public int getCursorCapsMode(int reqModes) {
|
||||||
|
LogD("getCursorCapsMode: " + reqModes);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ExtractedText getExtractedText(ExtractedTextRequest request,
|
public ExtractedText getExtractedText(ExtractedTextRequest request,
|
||||||
int flags) {
|
int flags) {
|
||||||
return null;
|
LogD("getExtractedText: " + request.toString() + "," + flags);
|
||||||
|
return new ExtractedText();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public CharSequence getTextAfterCursor(int n, int flags) {
|
public CharSequence getTextAfterCursor(int n, int flags) {
|
||||||
|
LogD("getTextAfterCursor: " + n + "," + flags);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public CharSequence getTextBeforeCursor(int n, int flags) {
|
public CharSequence getTextBeforeCursor(int n, int flags) {
|
||||||
|
LogD("getTextBeforeCursor: " + n + "," + flags);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean performContextMenuAction(int id) {
|
public boolean performContextMenuAction(int id) {
|
||||||
|
Log.d("Cocos2dxInputConnection", "performContextMenuAction");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean performEditorAction(int editorAction) {
|
public boolean performEditorAction(int editorAction) {
|
||||||
|
LogD("performEditorAction: " + editorAction);
|
||||||
if (null != mView) {
|
if (null != mView) {
|
||||||
final String insertText = "\n";
|
final String insertText = "\n";
|
||||||
mView.insertText(insertText);
|
mView.insertText(insertText);
|
||||||
|
@ -92,16 +118,19 @@ class Cocos2dxInputConnection implements InputConnection {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean performPrivateCommand(String action, Bundle data) {
|
public boolean performPrivateCommand(String action, Bundle data) {
|
||||||
|
LogD("performPrivateCommand: " + action + "," + data.toString());
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean reportFullscreenMode(boolean enabled) {
|
public boolean reportFullscreenMode(boolean enabled) {
|
||||||
|
LogD("reportFullscreenMode: " + enabled);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean sendKeyEvent(KeyEvent event) {
|
public boolean sendKeyEvent(KeyEvent event) {
|
||||||
|
LogD("sendKeyEvent: " + event.toString());
|
||||||
if (null != mView) {
|
if (null != mView) {
|
||||||
switch (event.getKeyCode()) {
|
switch (event.getKeyCode()) {
|
||||||
|
|
||||||
|
@ -115,19 +144,15 @@ class Cocos2dxInputConnection implements InputConnection {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean setComposingText(CharSequence text, int newCursorPosition) {
|
public boolean setComposingText(CharSequence text, int newCursorPosition) {
|
||||||
|
LogD("setComposingText: " + text.toString() + "," + newCursorPosition);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean setSelection(int start, int end) {
|
public boolean setSelection(int start, int end) {
|
||||||
|
LogD("setSelection: " + start + "," + end);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setGLSurfaceView(Cocos2dxGLSurfaceView view) {
|
|
||||||
mView = view;
|
|
||||||
}
|
|
||||||
|
|
||||||
private Cocos2dxGLSurfaceView mView;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public class Cocos2dxGLSurfaceView extends GLSurfaceView {
|
public class Cocos2dxGLSurfaceView extends GLSurfaceView {
|
||||||
|
@ -192,7 +217,8 @@ public class Cocos2dxGLSurfaceView extends GLSurfaceView {
|
||||||
if (imm == null) {
|
if (imm == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
imm.showSoftInput(mainView, InputMethodManager.SHOW_IMPLICIT);
|
boolean ret = imm.showSoftInput(mainView, 0);
|
||||||
|
Log.d("openIMEKeboard", (ret)? "true" : "false");
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void closeIMEKeyboard() {
|
public static void closeIMEKeyboard() {
|
||||||
|
@ -221,15 +247,14 @@ public class Cocos2dxGLSurfaceView extends GLSurfaceView {
|
||||||
if (onCheckIsTextEditor()) {
|
if (onCheckIsTextEditor()) {
|
||||||
|
|
||||||
outAttrs.inputType = EditorInfo.TYPE_CLASS_TEXT;
|
outAttrs.inputType = EditorInfo.TYPE_CLASS_TEXT;
|
||||||
outAttrs.imeOptions = EditorInfo.IME_NULL;
|
outAttrs.imeOptions = EditorInfo.IME_FLAG_NO_EXTRACT_UI;
|
||||||
outAttrs.initialSelStart = -1;
|
outAttrs.initialSelStart = -1;
|
||||||
outAttrs.initialSelEnd = -1;
|
outAttrs.initialSelEnd = -1;
|
||||||
outAttrs.initialCapsMode = 0;
|
outAttrs.initialCapsMode = 1;
|
||||||
|
|
||||||
if (null == ic)
|
if (null == ic)
|
||||||
{
|
{
|
||||||
ic = new Cocos2dxInputConnection();
|
ic = new Cocos2dxInputConnection(this);
|
||||||
ic.setGLSurfaceView(this);
|
|
||||||
}
|
}
|
||||||
return ic;
|
return ic;
|
||||||
}
|
}
|
||||||
|
@ -253,6 +278,7 @@ public class Cocos2dxGLSurfaceView extends GLSurfaceView {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////
|
||||||
// for touch event
|
// for touch event
|
||||||
///////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
//#define COCOS2D_DEBUG 1
|
||||||
|
|
||||||
#include "TextInputTest.h"
|
#include "TextInputTest.h"
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
|
@ -150,19 +152,29 @@ void KeyboardNotificationLayer::registerWithTouchDispatcher()
|
||||||
|
|
||||||
void KeyboardNotificationLayer::keyboardWillShow(CCIMEKeyboardNotificationInfo& info)
|
void KeyboardNotificationLayer::keyboardWillShow(CCIMEKeyboardNotificationInfo& info)
|
||||||
{
|
{
|
||||||
|
CCLOG("TextInputTest:keyboardWillShowAt(origin:%f,%f, size:%f,%f)",
|
||||||
|
info.end.origin.x, info.end.origin.y, info.end.size.width, info.end.size.height);
|
||||||
|
|
||||||
if (! m_pTrackNode)
|
if (! m_pTrackNode)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
CCRect rectTracked = getRect(m_pTrackNode);
|
CCRect rectTracked = getRect(m_pTrackNode);
|
||||||
|
CCLOG("TextInputTest:trackingNodeAt(origin:%f,%f, size:%f,%f)",
|
||||||
|
rectTracked.origin.x, rectTracked.origin.y, rectTracked.size.width, rectTracked.size.height);
|
||||||
|
|
||||||
|
// if the keyboard area doesn't intersect with the tracking node area, nothing need to do.
|
||||||
if (! CCRect::CCRectIntersectsRect(rectTracked, info.end))
|
if (! CCRect::CCRectIntersectsRect(rectTracked, info.end))
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// assume keyboard at the bottom of screen, calculate the vertical adjustment.
|
||||||
float adjustVert = CCRect::CCRectGetMaxY(info.end) - CCRect::CCRectGetMinY(rectTracked);
|
float adjustVert = CCRect::CCRectGetMaxY(info.end) - CCRect::CCRectGetMinY(rectTracked);
|
||||||
|
CCLOG("TextInputTest:needAdjustVerticalPosition(%f)", adjustVert);
|
||||||
|
|
||||||
|
// move all the children node of KeyboardNotificationLayer
|
||||||
CCArray * children = getChildren();
|
CCArray * children = getChildren();
|
||||||
CCNode * node = 0;
|
CCNode * node = 0;
|
||||||
int count = children->count();
|
int count = children->count();
|
||||||
|
@ -226,27 +238,46 @@ void TextFieldTTFTest::ccTouchEnded(CCTouch *pTouch, CCEvent *pEvent)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// decide the index of CCTextFieldTTF which is clicked.
|
||||||
int index = 0;
|
int index = 0;
|
||||||
|
CCRect rect;
|
||||||
|
CCPoint point = convertTouchToNodeSpaceAR(pTouch);
|
||||||
|
CCLOG("TextFieldTTFTest:clickedAt(%f,%f)", point.x, point.y);
|
||||||
|
|
||||||
for (; index < sizeof(m_pTextField) / sizeof(CCTextFieldTTF *); ++index)
|
for (; index < sizeof(m_pTextField) / sizeof(CCTextFieldTTF *); ++index)
|
||||||
{
|
{
|
||||||
if (CCRect::CCRectContainsPoint(getRect(m_pTextField[index]), convertTouchToNodeSpaceAR(pTouch)))
|
rect = getRect(m_pTextField[index]);
|
||||||
|
CCLOG("TextFieldTTFTest:CCTextFieldTTF[%d]at(origin:%f,%f, size:%f,%f)",
|
||||||
|
index, rect.origin.x, rect.origin.y, rect.size.width, rect.size.height);
|
||||||
|
|
||||||
|
if (CCRect::CCRectContainsPoint(rect, point))
|
||||||
{
|
{
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (index < sizeof(m_pTextField) / sizeof(CCTextFieldTTF *))
|
if (index == m_nSelected)
|
||||||
{
|
{
|
||||||
m_nSelected = index;
|
CCLOG("TextFieldTTFTest:noCCTextFieldTTFClicked.");
|
||||||
m_pTrackNode = m_pTextField[index];
|
return;
|
||||||
m_pTextField[index]->attachWithIME();
|
|
||||||
}
|
}
|
||||||
else if (m_nSelected >= 0)
|
|
||||||
|
if (m_nSelected >= 0)
|
||||||
{
|
{
|
||||||
|
// hide the keyboard
|
||||||
|
CCLOG("TextFieldTTFTest:CCTextFieldTTF[%d]detachWithIME", m_nSelected);
|
||||||
m_pTextField[m_nSelected]->detachWithIME();
|
m_pTextField[m_nSelected]->detachWithIME();
|
||||||
m_nSelected = -1;
|
m_nSelected = -1;
|
||||||
m_pTrackNode = 0;
|
m_pTrackNode = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (index < sizeof(m_pTextField) / sizeof(CCTextFieldTTF *))
|
||||||
|
{
|
||||||
|
CCLOG("TextFieldTTFTest:CCTextFieldTTF[%d]attachWithIME", index);
|
||||||
|
m_nSelected = index;
|
||||||
|
m_pTrackNode = m_pTextField[index];
|
||||||
|
m_pTextField[index]->attachWithIME();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
|
|
Loading…
Reference in New Issue