Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

timob-15755: fix 'return' event on Jelly Bean #5035

Merged
merged 1 commit into from
Nov 27, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

import android.content.Context;
import android.graphics.Rect;
import android.os.Build;
import android.text.Editable;
import android.text.InputType;
import android.text.TextUtils.TruncateAt;
Expand Down Expand Up @@ -296,6 +297,17 @@ public void beforeTextChanged(CharSequence s, int start, int before, int count)
@Override
public void onTextChanged(CharSequence s, int start, int before, int count)
{
//Since Jelly Bean, pressing the 'return' key won't trigger onEditorAction callback
//http://stackoverflow.com/questions/11311790/oneditoraction-is-not-called-after-enter-key-has-been-pressed-on-jelly-bean-em
//So here we need to handle the 'return' key manually
if (Build.VERSION.SDK_INT >= 16 && before == 0 && s.length() > start && s.charAt(start) == '\n') {
//We use the previous value to make it consistent with pre Jelly Bean behavior (onEditorAction is called before
//onTextChanged.
String value = TiConvert.toString(proxy.getProperty(TiC.PROPERTY_VALUE));
KrollDict data = new KrollDict();
data.put(TiC.PROPERTY_VALUE, value);
fireEvent(TiC.EVENT_RETURN, data);
}
/**
* There is an Android bug regarding setting filter on EditText that impacts auto completion.
* Therefore we can't use filters to implement "maxLength" property. Instead we manipulate
Expand Down Expand Up @@ -374,7 +386,7 @@ public boolean onEditorAction(TextView v, int actionId, KeyEvent keyEvent)
if ((actionId == EditorInfo.IME_NULL && keyEvent != null) ||
actionId == EditorInfo.IME_ACTION_NEXT ||
actionId == EditorInfo.IME_ACTION_DONE ) {
fireEvent("return", data);
fireEvent(TiC.EVENT_RETURN, data);
}

Boolean enableReturnKey = (Boolean) proxy.getProperty(TiC.PROPERTY_ENABLE_RETURN_KEY);
Expand Down Expand Up @@ -576,4 +588,5 @@ public void handleReturnKeyType(int type)
break;
}
}

}
5 changes: 5 additions & 0 deletions android/titanium/src/java/org/appcelerator/titanium/TiC.java
Original file line number Diff line number Diff line change
Expand Up @@ -411,6 +411,11 @@ public class TiC
* @module.api
*/
public static final String EVENT_RESUME = "resume";

/**
* @module.api
*/
public static final String EVENT_RETURN = "return";

/**
* @module.api
Expand Down