Merge pull request #13324 from zilongshanren/fix-editbox-soft-keyboard-backissue

fix ui::TextField status error.
This commit is contained in:
子龙山人 2015-08-12 13:57:10 +08:00
commit be1d3ccc67
8 changed files with 39 additions and 162 deletions

View File

@ -406,7 +406,7 @@ public abstract class Cocos2dxActivity extends Activity implements Cocos2dxHelpe
ViewGroup.LayoutParams edittext_layout_params =
new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
ViewGroup.LayoutParams.WRAP_CONTENT);
Cocos2dxEditText edittext = new Cocos2dxEditText(this);
Cocos2dxEditBox edittext = new Cocos2dxEditBox(this);
edittext.setLayoutParams(edittext_layout_params);

View File

@ -108,18 +108,6 @@ public class Cocos2dxEditBox extends EditText {
public Cocos2dxEditBox(Context context){
super(context);
this.setFocusable(true);
this.setFocusableInTouchMode(true);
this.setInputFlag(kEditBoxInputFlagInitialCapsAllCharacters);
this.setInputMode(kEditBoxInputModeSingleLine);
this.setReturnType(kKeyboardReturnTypeDefault);
this.setHintTextColor(Color.GRAY);
this.setVisibility(View.INVISIBLE);
this.setBackgroundColor(Color.TRANSPARENT);
this.setTextColor(Color.WHITE);
this.setSingleLine();
}
public void setEditBoxViewRect(int left, int top, int maxWidth, int maxHeight) {

View File

@ -82,6 +82,18 @@ public class Cocos2dxEditBoxHelper {
@Override
public void run() {
final Cocos2dxEditBox editBox = new Cocos2dxEditBox(mCocos2dxActivity);
editBox.setFocusable(true);
editBox.setFocusableInTouchMode(true);
editBox.setInputFlag(4); //kEditBoxInputFlagInitialCapsAllCharacters
editBox.setInputMode(6); //kEditBoxInputModeSingleLine
editBox.setReturnType(0); //kKeyboardReturnTypeDefault
editBox.setHintTextColor(Color.GRAY);
editBox.setVisibility(View.INVISIBLE);
editBox.setBackgroundColor(Color.TRANSPARENT);
editBox.setTextColor(Color.WHITE);
editBox.setSingleLine();
FrameLayout.LayoutParams lParams = new FrameLayout.LayoutParams(
FrameLayout.LayoutParams.WRAP_CONTENT,
FrameLayout.LayoutParams.WRAP_CONTENT);

View File

@ -1,90 +0,0 @@
/****************************************************************************
Copyright (c) 2010-2012 cocos2d-x.org
Copyright (c) 2013-2014 Chukong Technologies Inc.
http://www.cocos2d-x.org
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
****************************************************************************/
package org.cocos2dx.lib;
import android.content.Context;
import android.util.AttributeSet;
import android.view.KeyEvent;
import android.widget.EditText;
public class Cocos2dxEditText extends EditText {
// ===========================================================
// Constants
// ===========================================================
// ===========================================================
// Fields
// ===========================================================
private Cocos2dxGLSurfaceView mCocos2dxGLSurfaceView;
// ===========================================================
// Constructors
// ===========================================================
public Cocos2dxEditText(final Context context) {
super(context);
}
public Cocos2dxEditText(final Context context, final AttributeSet attrs) {
super(context, attrs);
}
public Cocos2dxEditText(final Context context, final AttributeSet attrs, final int defStyle) {
super(context, attrs, defStyle);
}
// ===========================================================
// Getter & Setter
// ===========================================================
public void setCocos2dxGLSurfaceView(final Cocos2dxGLSurfaceView pCocos2dxGLSurfaceView) {
this.mCocos2dxGLSurfaceView = pCocos2dxGLSurfaceView;
}
// ===========================================================
// Methods for/from SuperClass/Interfaces
// ===========================================================
@Override
public boolean onKeyDown(final int pKeyCode, final KeyEvent pKeyEvent) {
super.onKeyDown(pKeyCode, pKeyEvent);
// Let GlSurfaceView get focus if back key is input.
if (pKeyCode == KeyEvent.KEYCODE_BACK) {
this.mCocos2dxGLSurfaceView.requestFocus();
}
return true;
}
// ===========================================================
// Methods
// ===========================================================
// ===========================================================
// Inner and Anonymous Classes
// ===========================================================
}

View File

@ -56,7 +56,7 @@ public class Cocos2dxGLSurfaceView extends GLSurfaceView {
private static Cocos2dxTextInputWraper sCocos2dxTextInputWraper;
private Cocos2dxRenderer mCocos2dxRenderer;
private Cocos2dxEditText mCocos2dxEditText;
private Cocos2dxEditBox mCocos2dxEditText;
public boolean isSoftKeyboardShown() {
return mSoftKeyboardShown;
@ -151,15 +151,14 @@ public class Cocos2dxGLSurfaceView extends GLSurfaceView {
return this.mCocos2dxRenderer.getContentText();
}
public Cocos2dxEditText getCocos2dxEditText() {
public Cocos2dxEditBox getCocos2dxEditText() {
return this.mCocos2dxEditText;
}
public void setCocos2dxEditText(final Cocos2dxEditText pCocos2dxEditText) {
public void setCocos2dxEditText(final Cocos2dxEditBox pCocos2dxEditText) {
this.mCocos2dxEditText = pCocos2dxEditText;
if (null != this.mCocos2dxEditText && null != Cocos2dxGLSurfaceView.sCocos2dxTextInputWraper) {
this.mCocos2dxEditText.setOnEditorActionListener(Cocos2dxGLSurfaceView.sCocos2dxTextInputWraper);
this.mCocos2dxEditText.setCocos2dxGLSurfaceView(this);
this.requestFocus();
}
}

View File

@ -67,7 +67,7 @@ public class Cocos2dxHttpURLConnection
urlConnection.setRequestProperty("Accept-Encoding", "identity");
urlConnection.setDoInput(true);
} catch (Exception e) {
Log.e("Cocos2dxHttpURLConnection exception", e.toString());
Log.e("URLConnection exception", e.toString());
return null;
}
@ -86,7 +86,7 @@ public class Cocos2dxHttpURLConnection
urlConnection.setDoOutput(true);
}
} catch (ProtocolException e) {
Log.e("Cocos2dxHttpURLConnection exception", e.toString());
Log.e("URLConnection exception", e.toString());
}
}
@ -131,7 +131,7 @@ public class Cocos2dxHttpURLConnection
httpsURLConnection.setSSLSocketFactory(context.getSocketFactory());
} catch (Exception e) {
Log.e("Cocos2dxHttpURLConnection exception", e.toString());
Log.e("URLConnection exception", e.toString());
}
}
@ -167,7 +167,7 @@ public class Cocos2dxHttpURLConnection
}
out.close();
} catch (IOException e) {
Log.e("Cocos2dxHttpURLConnection exception", e.toString());
Log.e("URLConnection exception", e.toString());
}
}
@ -268,7 +268,7 @@ public class Cocos2dxHttpURLConnection
} catch (IOException e) {
in = http.getErrorStream();
} catch (Exception e) {
Log.e("Cocos2dxHttpURLConnection exception", e.toString());
Log.e("URLConnection exception", e.toString());
return null;
}
@ -284,7 +284,7 @@ public class Cocos2dxHttpURLConnection
bytestream.close();
return retbuffer;
} catch (Exception e) {
Log.e("Cocos2dxHttpURLConnection exception", e.toString());
Log.e("URLConnection exception", e.toString());
}
return null;
@ -295,7 +295,7 @@ public class Cocos2dxHttpURLConnection
try {
code = http.getResponseCode();
} catch (IOException e) {
Log.e("Cocos2dxHttpURLConnection exception", e.toString());
Log.e("URLConnection exception", e.toString());
}
return code;
}
@ -306,7 +306,7 @@ public class Cocos2dxHttpURLConnection
msg = http.getResponseMessage();
} catch (IOException e) {
msg = e.toString();
Log.e("Cocos2dxHttpURLConnection exception", msg);
Log.e("URLConnection exception", msg);
}
return msg;
@ -395,7 +395,7 @@ public class Cocos2dxHttpURLConnection
c.setTime(new SimpleDateFormat("EEE, dd-MMM-yy hh:mm:ss zzz", Locale.US).parse(strTime));
millisSecond = c.getTimeInMillis()/1000;
} catch (ParseException e) {
Log.e("Cocos2dxHttpURLConnection exception", e.toString());
Log.e("URLConnection exception", e.toString());
}
return Long.toString(millisSecond);

View File

@ -26,6 +26,7 @@ package org.cocos2dx.lib;
import android.content.Context;
import android.text.Editable;
import android.text.TextWatcher;
import android.util.Log;
import android.view.KeyEvent;
import android.view.inputmethod.EditorInfo;
import android.view.inputmethod.InputMethodManager;
@ -79,26 +80,14 @@ public class Cocos2dxTextInputWraper implements TextWatcher, OnEditorActionListe
return;
}
//if (BuildConfig.DEBUG) {
//Log.d(TAG, "afterTextChanged: " + s);
//}
int nModified = s.length() - this.mText.length();
if (nModified > 0) {
final String insertText = s.subSequence(this.mText.length(), s.length()).toString();
this.mCocos2dxGLSurfaceView.insertText(insertText);
/*
if (BuildConfig.DEBUG) {
Log.d(TAG, "insertText(" + insertText + ")");
}
*/
} else {
} else if(nModified < 0) {
for (; nModified < 0; ++nModified) {
this.mCocos2dxGLSurfaceView.deleteBackward();
/*
if (BuildConfig.DEBUG) {
Log.d(TAG, "deleteBackward");
}
*/
}
}
this.mText = s.toString();
@ -106,11 +95,6 @@ public class Cocos2dxTextInputWraper implements TextWatcher, OnEditorActionListe
@Override
public void beforeTextChanged(final CharSequence pCharSequence, final int start, final int count, final int after) {
/*
if (BuildConfig.DEBUG) {
Log.d(TAG, "beforeTextChanged(" + pCharSequence + ")start: " + start + ",count: " + count + ",after: " + after);
}
*/
this.mText = pCharSequence.toString();
}
@ -126,11 +110,6 @@ public class Cocos2dxTextInputWraper implements TextWatcher, OnEditorActionListe
if (null != mOriginText) {
for (int i = this.mOriginText.length(); i > 0; i--) {
this.mCocos2dxGLSurfaceView.deleteBackward();
/*
if (BuildConfig.DEBUG) {
Log.d(TAG, "deleteBackward");
}
*/
}
}
@ -149,11 +128,7 @@ public class Cocos2dxTextInputWraper implements TextWatcher, OnEditorActionListe
final String insertText = text;
this.mCocos2dxGLSurfaceView.insertText(insertText);
/*
if (BuildConfig.DEBUG) {
Log.d(TAG, "insertText(" + insertText + ")");
}
*/
}
if (pActionID == EditorInfo.IME_ACTION_DONE) {
@ -162,11 +137,4 @@ public class Cocos2dxTextInputWraper implements TextWatcher, OnEditorActionListe
return false;
}
// ===========================================================
// Methods
// ===========================================================
// ===========================================================
// Inner and Anonymous Classes
// ===========================================================
}

View File

@ -603,7 +603,16 @@ void TextField::update(float dt)
attachWithIMEEvent();
setAttachWithIME(false);
}
if (getDeleteBackward())
{
_textFieldRendererAdaptDirty = true;
updateContentSizeWithTextureSize(_textFieldRenderer->getContentSize());
deleteBackwardEvent();
setDeleteBackward(false);
}
if (getInsertText())
{
//we update the content size first such that when user call getContentSize() in event callback won't be wrong
@ -613,15 +622,6 @@ void TextField::update(float dt)
insertTextEvent();
setInsertText(false);
}
if (getDeleteBackward())
{
_textFieldRendererAdaptDirty = true;
updateContentSizeWithTextureSize(_textFieldRenderer->getContentSize());
deleteBackwardEvent();
setDeleteBackward(false);
}
}
bool TextField::getAttachWithIME()const