Merge pull request #4902 from Dhilan007/develop_crash

fix TextInput not show IME on android.
This commit is contained in:
minggo 2014-01-05 19:50:19 -08:00
commit e4bec7d1ef
1 changed files with 8 additions and 6 deletions

View File

@ -23,6 +23,7 @@ THE SOFTWARE.
****************************************************************************/ ****************************************************************************/
package org.cocos2dx.lib; package org.cocos2dx.lib;
import android.app.Activity;
import android.content.Context; import android.content.Context;
import android.text.Editable; import android.text.Editable;
import android.text.TextWatcher; import android.text.TextWatcher;
@ -59,9 +60,11 @@ public class Cocos2dxEditText extends EditText {
this.setOnEditorActionListener(this.mTextWatcher); this.setOnEditorActionListener(this.mTextWatcher);
ViewGroup.LayoutParams layout = ViewGroup.LayoutParams layout =
new ViewGroup.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT, new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
ViewGroup.LayoutParams.WRAP_CONTENT); ViewGroup.LayoutParams.WRAP_CONTENT);
this.setLayoutParams(layout);
Activity activity = (Activity)context;
activity.addContentView(this, layout);
} }
// =========================================================== // ===========================================================
@ -84,7 +87,7 @@ public class Cocos2dxEditText extends EditText {
this.removeTextChangedListener(mTextWatcher); this.removeTextChangedListener(mTextWatcher);
final InputMethodManager imm = (InputMethodManager)mContext.getSystemService(Context.INPUT_METHOD_SERVICE); final InputMethodManager imm = (InputMethodManager)mContext.getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(this.getWindowToken(), 0); imm.hideSoftInputFromWindow(this.getWindowToken(), 0);
Cocos2dxHelper.nativeRequestFocus(); //Cocos2dxHelper.nativeRequestFocus();
} }
public void openIMEKeyboard() { public void openIMEKeyboard() {
@ -96,7 +99,7 @@ public class Cocos2dxEditText extends EditText {
this.addTextChangedListener(mTextWatcher); this.addTextChangedListener(mTextWatcher);
final InputMethodManager imm = (InputMethodManager)mContext.getSystemService(Context.INPUT_METHOD_SERVICE); final InputMethodManager imm = (InputMethodManager)mContext.getSystemService(Context.INPUT_METHOD_SERVICE);
imm.showSoftInput(this, InputMethodManager.SHOW_IMPLICIT); imm.showSoftInput(this, InputMethodManager.SHOW_FORCED);
} }
@Override @Override
@ -105,7 +108,7 @@ public class Cocos2dxEditText extends EditText {
/* Let GlSurfaceView get focus if back key is input. */ /* Let GlSurfaceView get focus if back key is input. */
if (keyCode == KeyEvent.KEYCODE_BACK) { if (keyCode == KeyEvent.KEYCODE_BACK) {
this.requestFocus(); //Cocos2dxHelper.nativeRequestFocus();
} }
return true; return true;
@ -189,7 +192,6 @@ class Cocos2dxTextInputWraper implements TextWatcher, OnEditorActionListener {
@Override @Override
public void onTextChanged(final CharSequence pCharSequence, final int start, final int before, final int count) { public void onTextChanged(final CharSequence pCharSequence, final int start, final int before, final int count) {
} }
@Override @Override