安卓OnEditorActionListener()actionId给出0,当我点击完成关键 [英] Android OnEditorActionListener() actionId give 0 when I click Done key
问题描述
我已创建了一个keyboard.When用户输入数字,其进入特定的EditText.But当用户点击完成
键,它并没有去 setOnEditorActionListener
,但它的关闭键盘。
这是我的code:
最后的EditText txtQty =新的EditText(本);
txtQty.setHeight(1);
txtQty.setLayoutParams(新的LayoutParams(LayoutParams.WRAP_CONTENT,42));
txtQty.setInputType(InputType.TYPE_CLASS_PHONE);
txtQty.setImeOptions(EditorInfo.IME_ACTION_DONE);
txtQty.setSelectAllOnFocus(真正的);
txtQty.setTextSize(9);
txtQty.setVisibility(View.VISIBLE);
txtQty.setHint(0.0);
txtQty.setHighlightColor(R.color.green);
tr.addView(txtQty);
txtQty.setOnEditorActionListener(新OnEditorActionListener(){
公共布尔onEditorAction(TextView的V,INT actionId,KeyEvent的事件){
Log.i(键盘,内部编辑文本);
如果(actionId == EditorInfo.IME_ACTION_DONE || actionId == EditorInfo.IME_ACTION_NEXT){......}
下面的给予actionId = 0 和EditorInfo.IME_ACTION_NEXT = 5
当我通过Android Softkeyboard运行其做工精细
txtQty.setOnEditorActionListener(新OnEditorActionListener(){
公共布尔onEditorAction(TextView的V,INT actionId,KeyEvent的事件){
Log.i(键盘,内部编辑文本);
Log.i(--- EditorInfo.IME_ACTION_NEXT ---,EditorInfo.IME_ACTION_NEXT);
Log.i(--- actionId ---,actionId);
Log.i(---活动---,事件);
Log.i(--- EditorInfo.IME_ACTION_DONE ---,EditorInfo.IME_ACTION_DONE);
下面给 EditorInfo.IME_ACTION_NEXT = 5,actionId = 5安培; EditorInfo.IME_ACTION_DONE = 6,actionId = 6
但是,当我通过我的软键盘运行了 EditorInfo.IME_ACTION_NEXT = 5,actionId = 0&放大器; EditorInfo.IME_ACTION_DONE = 6,actionId = 0
这是problem.Where它错了吗?为什么它没有考虑 actionId
值?
这是那种情景我现在做的:
编辑/更新时间:
公共类SoftKeyboard扩展InputMethodService实现KeyboardView.OnKeyboardActionListener {
静态最终布尔DEBUG = FALSE;
静态最终布尔PROCESS_HARD_KEYS = TRUE;
私人KeyboardView mInputView;
私人CandidateView mCandidateView;
私人CompletionInfo [] mCompletions;
私人StringBuilder的mComposing =新的StringBuilder();
私人布尔米predictionOn;
私人布尔mCompletionOn;
私人诠释mLastDisplayWidth;
私人布尔mCapsLock;
专用长mLastShiftTime;
专用长mMetaState;
私人LatinKeyboard mSymbolsKeyboard;
私人LatinKeyboard mSymbolsShiftedKeyboard;
私人LatinKeyboard mQwertyKeyboard;
私人LatinKeyboard mCurKeyboard;
私人字符串mWordSeparators;
@覆盖公共无效的onCreate(){
super.onCreate();
mWordSeparators = getResources()的getString(R.string.word_separators)。
}
@覆盖公共无效onInitializeInterface(){
如果(mQwertyKeyboard!= NULL){
INT displayWidth = getMaxWidth();
如果(displayWidth == mLastDisplayWidth)回报;
mLastDisplayWidth = displayWidth;
}
mQwertyKeyboard =新LatinKeyboard(这一点,R.xml.qwerty);
mSymbolsKeyboard =新LatinKeyboard(这一点,R.xml.symbols);
mSymbolsShiftedKeyboard =新LatinKeyboard(这一点,R.xml.symbols_shift);
}
@覆盖公共查看onCreateInputView(){
mInputView =(KeyboardView)getLayoutInflater()。膨胀(
R.layout.input,NULL);
mInputView.setOnKeyboardActionListener(本);
mInputView.setKeyboard(mQwertyKeyboard);
返回mInputView;
}
@覆盖公共查看onCreateCandidatesView(){
mCandidateView =新CandidateView(本);
mCandidateView.setService(本);
返回mCandidateView;
}
@覆盖公共无效onStartInput(EditorInfo属性,布尔重新启动){
super.onStartInput(属性,重新启动);
mComposing.setLength(0);
updateCandidates();
如果(!重新启动){
mMetaState = 0;
}
米predictionOn = FALSE;
mCompletionOn = FALSE;
mCompletions = NULL;
开关(attribute.inputType&安培; EditorInfo.TYPE_MASK_CLASS){
案例EditorInfo.TYPE_CLASS_NUMBER:
案例EditorInfo.TYPE_CLASS_DATETIME:
mCurKeyboard = mSymbolsKeyboard;
打破;
案例EditorInfo.TYPE_CLASS_PHONE:
mCurKeyboard = mSymbolsKeyboard;
打破;
案例EditorInfo.TYPE_CLASS_TEXT:
mCurKeyboard = mQwertyKeyboard;
米predictionOn = TRUE;
INT变化= attribute.inputType和放大器; EditorInfo.TYPE_MASK_VARIATION;
如果(变化== EditorInfo.TYPE_TEXT_VARIATION_PASSWORD ||
变化== EditorInfo.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD){
米predictionOn = FALSE;
}
如果(变化== EditorInfo.TYPE_TEXT_VARIATION_EMAIL_ADDRESS
||变化== EditorInfo.TYPE_TEXT_VARIATION_URI
||变化== EditorInfo.TYPE_TEXT_VARIATION_FILTER){
米predictionOn = FALSE;
}
如果((attribute.inputType&安培;!EditorInfo.TYPE_TEXT_FLAG_AUTO_COMPLETE)= 0){
米predictionOn = FALSE;
mCompletionOn = isFullscreenMode();
}
updateShiftKeyState(属性);
打破;
默认:
mCurKeyboard = mQwertyKeyboard;
updateShiftKeyState(属性);
}
mCurKeyboard.setImeOptions(getResources(),attribute.imeOptions);
}
@覆盖公共无效onFinishInput(){
super.onFinishInput();
//清除当前合成的文本和候选人。
mComposing.setLength(0);
updateCandidates();
setCandidatesViewShown(假);
mCurKeyboard = mQwertyKeyboard;
如果(mInputView!= NULL){
mInputView.closing();
}
}
@覆盖公共无效onStartInputView(EditorInfo属性,布尔重新启动){
super.onStartInputView(属性,重新启动);
mInputView.setKeyboard(mCurKeyboard);
mInputView.closing();
}
@覆盖
公共无效onUpdateSelection(INT oldSelStart,INT oldSelEnd,
INT newSelStart,INT newSelEnd,
INT candidatesStart,诠释candidatesEnd){
super.onUpdateSelection(oldSelStart,oldSelEnd,newSelStart,newSelEnd,
candidatesStart,candidatesEnd);
如果(mComposing.length()大于0&安培;及(newSelStart = candidatesEnd!
|| newSelEnd!= candidatesEnd)){
mComposing.setLength(0);
updateCandidates();
InputConnection集成电路= getCurrentInputConnection();
如果(IC!= NULL){
ic.finishComposingText();
}
}
}
@覆盖
公共无效onDisplayCompletions(CompletionInfo []完工){
如果(mCompletionOn){
mCompletions =落成;
如果(完工== NULL){
setSuggestions(空,假的,假的);
返回;
}
名单<字符串> StringList的=新的ArrayList<字符串>();
对(INT I = 0; I&≤(完井=空completions.length:!?0);我++){
CompletionInfo CI =落成[I]
如果(CI!= NULL)stringList.add(ci.getText()的toString());
}
setSuggestions(StringList的,真实的,真正的);
}
}
私人布尔translateKeyDown(INT键code,KeyEvent的事件){
mMetaState = MetaKeyKeyListener.handleKeyDown(mMetaState,
关键code,事件);
INT C = event.getUni codeCHAR(MetaKeyKeyListener.getMetaState(mMetaState));
mMetaState = MetaKeyKeyListener.adjustMetaAfterKey preSS(mMetaState);
InputConnection集成电路= getCurrentInputConnection();
如果(C == 0 || IC == NULL){
返回false;
}
布尔死亡= FALSE;
如果((C&安培;!KeyCharacterMap.COMBINING_ACCENT)= 0){
死亡= TRUE;
C = C放大器; KeyCharacterMap.COMBINING_ACCENT_MASK;
}
如果(mComposing.length()大于0){
焦炭口音= mComposing.charAt(mComposing.length()-1);
诠释组成= KeyEvent.getDeadChar(口音,C);
如果(由!= 0){
C =组成;
mComposing.setLength(mComposing.length() - 1);
}
}
onKey(C,NULL);
返回true;
}
@覆盖
公共布尔的onkeydown(INT键code,KeyEvent的事件){
开关(钥匙code){
案例KeyEvent.KEY code_BACK:
如果(event.getRepeatCount()== 0安培;&安培;!mInputView = NULL){
如果(mInputView.handleBack()){
返回true;
}
}
打破;
案例KeyEvent.KEY code_DEL:
如果(mComposing.length()大于0){
onKey(Keyboard.KEY code_DELETE,NULL);
返回true;
}
打破;
案例KeyEvent.KEY code_ENTER:
返回false;
默认:
如果(PROCESS_HARD_KEYS){
如果(键code == KeyEvent.KEY code_SPACE
&功放;&安培; (event.getMetaState()及KeyEvent.META_ALT_ON)!= 0){
InputConnection集成电路= getCurrentInputConnection();
如果(IC!= NULL){
ic.clearMetaKeyStates(KeyEvent.META_ALT_ON);
keyDownUp(KeyEvent.KEY code_A);
keyDownUp(KeyEvent.KEY code_N);
keyDownUp(KeyEvent.KEY code_D);
keyDownUp(KeyEvent.KEY code_R);
keyDownUp(KeyEvent.KEY code_O);
keyDownUp(KeyEvent.KEY code_I);
keyDownUp(KeyEvent.KEY code_D);
返回true;
}
}
如果(M predictionOn和放大器;&安培; translateKeyDown(键code,事件)){
返回true;
}
}
}
返回super.onKeyDown(键code,事件);
}
@覆盖
公共布尔的onkeyup(INT键code,KeyEvent的事件){
如果(PROCESS_HARD_KEYS){
如果(M predictionOn){
mMetaState = MetaKeyKeyListener.handleKeyUp(mMetaState,
关键code,事件);
}
}
返回super.onKeyUp(键code,事件);
}
私人无效commitTyped(InputConnection inputConnection){
如果(mComposing.length()大于0){
inputConnection.commitText(mComposing,mComposing.length());
mComposing.setLength(0);
updateCandidates();
}
}
私人无效updateShiftKeyState(EditorInfo ATTR){
如果(ATTR!= NULL
&功放;&安培; mInputView = NULL和放大器;!&安培; mQwertyKeyboard == mInputView.getKeyboard()){
INT帽= 0;
EditorInfo的ei = getCurrentInputEditorInfo();
如果(EI = NULL和放大器;!&安培;!ei.inputType = EditorInfo.TYPE_NULL){
帽= getCurrentInputConnection()getCursorCapsMode(attr.inputType)。
}
mInputView.setShifted(mCapsLock ||帽子!= 0);
}
}
私人布尔isAlphabet(INT code){
如果(Character.isLetter(code)){
返回true;
} 其他 {
返回false;
}
}
私人无效keyDownUp(INT的keyEvent code){
getCurrentInputConnection()。sendKeyEvent(
新的KeyEvent(KeyEvent.ACTION_DOWN,的keyEvent code));
getCurrentInputConnection()。sendKeyEvent(
新的KeyEvent(KeyEvent.ACTION_UP,的keyEvent code));
}
私人无效sendKey(INT键code){
开关(钥匙code){
案'\ n'的
keyDownUp(KeyEvent.KEY code_ENTER);
打破;
默认:
如果(键code> ='0'和;&放大器;关键$ C $℃下='9'){
keyDownUp(键code - '0'+ KeyEvent.KEY code_0);
} 其他 {
。getCurrentInputConnection()commitText(将String.valueOf((char)的关键code),1);
}
打破;
}
}
公共无效onKey(int主code,INT []键codeS){
如果(isWordSeparator(主要code)){
//手柄分离器
如果(mComposing.length()大于0){
commitTyped(getCurrentInputConnection());
}
sendKey(主要code);
updateShiftKeyState(getCurrentInputEditorInfo());
}否则,如果(主要code == Keyboard.KEY code_DELETE){
handleBackspace();
}否则,如果(主要code == Keyboard.KEY code_SHIFT){
handleShift();
}否则,如果(主要code == Keyboard.KEY code_CANCEL){
handleClose();
返回;
}否则,如果(主要code == LatinKeyboardView.KEY code_OPTIONS){
//显示一个菜单或事端
}否则,如果(主要code == Keyboard.KEY code_MODE_CHANGE
&功放;&安培; mInputView!= NULL){
键盘电流= mInputView.getKeyboard();
如果(当前== mSymbolsKeyboard ||当前== mSymbolsShiftedKeyboard){
电流= mQwertyKeyboard;
} 其他 {
电流= mSymbolsKeyboard;
}
mInputView.setKeyboard(电流);
如果(当前== mSymbolsKeyboard){
current.setShifted(假);
}
} 其他 {
handleCharacter(主要code,关键codeS);
}
}
公共无效onText(CharSequence的文字){
InputConnection集成电路= getCurrentInputConnection();
如果(IC == NULL)回报;
ic.beginBatchEdit();
如果(mComposing.length()大于0){
commitTyped(IC);
}
ic.commitText(文字,0);
ic.endBatchEdit();
updateShiftKeyState(getCurrentInputEditorInfo());
}
私人无效updateCandidates(){
如果(!mCompletionOn){
如果(mComposing.length()大于0){
ArrayList的<字符串>名单=新的ArrayList<字符串>();
list.add(mComposing.toString());
setSuggestions(列表中,真正的,真实的);
} 其他 {
setSuggestions(空,假的,假的);
}
}
}
公共无效setSuggestions(名单<字符串>建议,布尔落成,
布尔typedWordValid){
如果(建议=空&安培;!&安培; suggestions.size()大于0){
setCandidatesViewShown(真正的);
}否则如果(isExtractViewShown()){
setCandidatesViewShown(真正的);
}
如果(mCandidateView!= NULL){
mCandidateView.setSuggestions(建议,完井,typedWordValid);
}
}
私人无效handleBackspace(){
最终诠释长度= mComposing.length();
如果(长度大于1){
mComposing.delete(长度 - 1,长度);
getCurrentInputConnection()setComposingText(mComposing,1);
updateCandidates();
}否则如果(长度大于0){
mComposing.setLength(0);
getCurrentInputConnection()commitText(,0);
updateCandidates();
} 其他 {
keyDownUp(KeyEvent.KEY code_DEL);
}
updateShiftKeyState(getCurrentInputEditorInfo());
}
私人无效handleShift(){
如果(mInputView == NULL){
返回;
}
键盘currentKeyboard = mInputView.getKeyboard();
如果(mQwertyKeyboard == currentKeyboard){
//字母键盘
checkToggleCapsLock();
mInputView.setShifted(mCapsLock || mInputView.isShifted()!);
}否则,如果(currentKeyboard == mSymbolsKeyboard){
mSymbolsKeyboard.setShifted(真正的);
mInputView.setKeyboard(mSymbolsShiftedKeyboard);
mSymbolsShiftedKeyboard.setShifted(真正的);
}否则,如果(currentKeyboard == mSymbolsShiftedKeyboard){
mSymbolsShiftedKeyboard.setShifted(假);
mInputView.setKeyboard(mSymbolsKeyboard);
mSymbolsKeyboard.setShifted(假);
}
}
私人无效handleCharacter(int主code,INT []键codeS){
如果(isInputViewShown()){
如果(mInputView.isShifted()){
主要code = Character.toUpperCase(主要code);
}
}
如果(isAlphabet(主要code)及和放大器,M predictionOn){
mComposing.append((char)的主要code);
getCurrentInputConnection()setComposingText(mComposing,1);
updateShiftKeyState(getCurrentInputEditorInfo());
updateCandidates();
} 其他 {
getCurrentInputConnection()。commitText(
将String.valueOf((char)的主要code),1);
}
}
私人无效handleClose(){
commitTyped(getCurrentInputConnection());
requestHideSelf(0);
mInputView.closing();
}
私人无效checkToggleCapsLock(){
长今= System.currentTimeMillis的();
如果(mLastShiftTime + 800>接着){
mCapsLock = mCapsLock!;
mLastShiftTime = 0;
} 其他 {
mLastShiftTime =现在;
}
}
私人字符串getWordSeparators(){
返回mWordSeparators;
}
公共布尔isWordSeparator(INT code){
串隔板= getWordSeparators();
返回separators.contains(将String.valueOf((char)的code));
}
公共无效pickDefaultCandidate(){
pickSuggestionManually(0);
}
公共无效pickSuggestionManually(INT指数){
如果(mCompletionOn&安培;&安培; mCompletions = NULL和放大器;!&安培;索引> = 0
&功放;&安培;指数< mCompletions.length){
CompletionInfo CI = mCompletions [指数]
。getCurrentInputConnection()commitCompletion(CI);
如果(mCandidateView!= NULL){
mCandidateView.clear();
}
updateShiftKeyState(getCurrentInputEditorInfo());
}否则如果(mComposing.length()大于0){
commitTyped(getCurrentInputConnection());
}
}
公共无效swipeRight(){
如果(mCompletionOn){
pickDefaultCandidate();
}
}
公共无效swipeLeft(){
handleBackspace();
}
公共无效swipeDown(){
handleClose();
}
公共无效swipeUp(){
}
在preSS(int主code){公共无效
}
公共无效onRelease(int主code){
}
}
和symbols.xml文件:
<关键的android:codeS = - 3安卓keyIcon =@可绘制/ sym_keyboard_done机器人:keyWidth =20%P机器人:keyEdgeFlags =左/>
当我点击完成
键也没去 OnEditorActionListener
方法。请帮我
请帮我这样的:
我已经试过这样:但不是正确的解决方案。无论如何,我想借此actionId,根据actionId我希望把switch语句和放大器;想知道为什么它没有考虑actionId当我们使用以外的Android键盘
txtQty.setOnEditorActionListener(新OnEditorActionListener(){
公共布尔onEditorAction(TextView的V,INT actionId,KeyEvent的事件){
如果(event.getKey code()== KeyEvent.KEY code_ENTER){} .....
试试这个添加监听器:
msg_title_text.setOnEditorActionListener(新DoneOnEditorActionListener());
创建了一个类:
类DoneOnEditorActionListener实现OnEditorActionListener {
@覆盖
公共布尔onEditorAction(TextView的V,INT actionId,KeyEvent的事件){
如果(actionId == EditorInfo.IME_ACTION_DONE){
Log.v(********,Clicke DA明昌);
//做你的东西
返回true;
}
返回false;
}
}
I have created one keyboard.When user enter numbers , its entering particular EditText.But When User click on Done
key, it didn't go to setOnEditorActionListener
but its closing the keyboard.
This is my code :
final EditText txtQty = new EditText(this);
txtQty.setHeight(1);
txtQty.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, 42));
txtQty.setInputType(InputType.TYPE_CLASS_PHONE);
txtQty.setImeOptions(EditorInfo.IME_ACTION_DONE);
txtQty.setSelectAllOnFocus(true);
txtQty.setTextSize(9);
txtQty.setVisibility(View.VISIBLE);
txtQty.setHint("0.0");
txtQty.setHighlightColor(R.color.green);
tr.addView(txtQty);
txtQty.setOnEditorActionListener( new OnEditorActionListener() {
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
Log.i("KeyBoard" ,"Inside the Edit Text");
if (actionId == EditorInfo.IME_ACTION_DONE ||actionId == EditorInfo.IME_ACTION_NEXT ) { ......}
Here its give actionId = 0 and EditorInfo.IME_ACTION_NEXT =5
When I run through the Android Softkeyboard its working fine
txtQty.setOnEditorActionListener( new OnEditorActionListener() {
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
Log.i("KeyBoard" ,"Inside the Edit Text");
Log.i("---EditorInfo.IME_ACTION_NEXT---" , EditorInfo.IME_ACTION_NEXT);
Log.i("---actionId---" , actionId);
Log.i("---event---" , event);
Log.i("---EditorInfo.IME_ACTION_DONE---" , EditorInfo.IME_ACTION_DONE);
Here giving EditorInfo.IME_ACTION_NEXT =5 , actionId =5 & EditorInfo.IME_ACTION_DONE = 6, actionId=6
But when I run through my Soft keyboard gave EditorInfo.IME_ACTION_NEXT =5 , actionId =0 & EditorInfo.IME_ACTION_DONE = 6, actionId=0
This is the problem.Where its wrong? Why it didn't take actionId
value?
This is kind of scenario i am doing:
EDITED/UPDATED
public class SoftKeyboard extends InputMethodService implements KeyboardView.OnKeyboardActionListener {
static final boolean DEBUG = false;
static final boolean PROCESS_HARD_KEYS = true;
private KeyboardView mInputView;
private CandidateView mCandidateView;
private CompletionInfo[] mCompletions;
private StringBuilder mComposing = new StringBuilder();
private boolean mPredictionOn;
private boolean mCompletionOn;
private int mLastDisplayWidth;
private boolean mCapsLock;
private long mLastShiftTime;
private long mMetaState;
private LatinKeyboard mSymbolsKeyboard;
private LatinKeyboard mSymbolsShiftedKeyboard;
private LatinKeyboard mQwertyKeyboard;
private LatinKeyboard mCurKeyboard;
private String mWordSeparators;
@Override public void onCreate() {
super.onCreate();
mWordSeparators = getResources().getString(R.string.word_separators);
}
@Override public void onInitializeInterface() {
if (mQwertyKeyboard != null) {
int displayWidth = getMaxWidth();
if (displayWidth == mLastDisplayWidth) return;
mLastDisplayWidth = displayWidth;
}
mQwertyKeyboard = new LatinKeyboard(this, R.xml.qwerty);
mSymbolsKeyboard = new LatinKeyboard(this, R.xml.symbols);
mSymbolsShiftedKeyboard = new LatinKeyboard(this, R.xml.symbols_shift);
}
@Override public View onCreateInputView() {
mInputView = (KeyboardView) getLayoutInflater().inflate(
R.layout.input, null);
mInputView.setOnKeyboardActionListener(this);
mInputView.setKeyboard(mQwertyKeyboard);
return mInputView;
}
@Override public View onCreateCandidatesView() {
mCandidateView = new CandidateView(this);
mCandidateView.setService(this);
return mCandidateView;
}
@Override public void onStartInput(EditorInfo attribute, boolean restarting) {
super.onStartInput(attribute, restarting);
mComposing.setLength(0);
updateCandidates();
if (!restarting) {
mMetaState = 0;
}
mPredictionOn = false;
mCompletionOn = false;
mCompletions = null;
switch (attribute.inputType&EditorInfo.TYPE_MASK_CLASS) {
case EditorInfo.TYPE_CLASS_NUMBER:
case EditorInfo.TYPE_CLASS_DATETIME:
mCurKeyboard = mSymbolsKeyboard;
break;
case EditorInfo.TYPE_CLASS_PHONE:
mCurKeyboard = mSymbolsKeyboard;
break;
case EditorInfo.TYPE_CLASS_TEXT:
mCurKeyboard = mQwertyKeyboard;
mPredictionOn = true;
int variation = attribute.inputType & EditorInfo.TYPE_MASK_VARIATION;
if (variation == EditorInfo.TYPE_TEXT_VARIATION_PASSWORD ||
variation == EditorInfo.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD) {
mPredictionOn = false;
}
if (variation == EditorInfo.TYPE_TEXT_VARIATION_EMAIL_ADDRESS
|| variation == EditorInfo.TYPE_TEXT_VARIATION_URI
|| variation == EditorInfo.TYPE_TEXT_VARIATION_FILTER) {
mPredictionOn = false;
}
if ((attribute.inputType&EditorInfo.TYPE_TEXT_FLAG_AUTO_COMPLETE) != 0) {
mPredictionOn = false;
mCompletionOn = isFullscreenMode();
}
updateShiftKeyState(attribute);
break;
default:
mCurKeyboard = mQwertyKeyboard;
updateShiftKeyState(attribute);
}
mCurKeyboard.setImeOptions(getResources(), attribute.imeOptions);
}
@Override public void onFinishInput() {
super.onFinishInput();
// Clear current composing text and candidates.
mComposing.setLength(0);
updateCandidates();
setCandidatesViewShown(false);
mCurKeyboard = mQwertyKeyboard;
if (mInputView != null) {
mInputView.closing();
}
}
@Override public void onStartInputView(EditorInfo attribute, boolean restarting) {
super.onStartInputView(attribute, restarting);
mInputView.setKeyboard(mCurKeyboard);
mInputView.closing();
}
@Override
public void onUpdateSelection(int oldSelStart, int oldSelEnd,
int newSelStart, int newSelEnd,
int candidatesStart, int candidatesEnd) {
super.onUpdateSelection(oldSelStart, oldSelEnd, newSelStart, newSelEnd,
candidatesStart, candidatesEnd);
if (mComposing.length() > 0 && (newSelStart != candidatesEnd
|| newSelEnd != candidatesEnd)) {
mComposing.setLength(0);
updateCandidates();
InputConnection ic = getCurrentInputConnection();
if (ic != null) {
ic.finishComposingText();
}
}
}
@Override
public void onDisplayCompletions(CompletionInfo[] completions) {
if (mCompletionOn) {
mCompletions = completions;
if (completions == null) {
setSuggestions(null, false, false);
return;
}
List<String> stringList = new ArrayList<String>();
for (int i=0; i<(completions != null ? completions.length : 0); i++) {
CompletionInfo ci = completions[i];
if (ci != null) stringList.add(ci.getText().toString());
}
setSuggestions(stringList, true, true);
}
}
private boolean translateKeyDown(int keyCode, KeyEvent event) {
mMetaState = MetaKeyKeyListener.handleKeyDown(mMetaState,
keyCode, event);
int c = event.getUnicodeChar(MetaKeyKeyListener.getMetaState(mMetaState));
mMetaState = MetaKeyKeyListener.adjustMetaAfterKeypress(mMetaState);
InputConnection ic = getCurrentInputConnection();
if (c == 0 || ic == null) {
return false;
}
boolean dead = false;
if ((c & KeyCharacterMap.COMBINING_ACCENT) != 0) {
dead = true;
c = c & KeyCharacterMap.COMBINING_ACCENT_MASK;
}
if (mComposing.length() > 0) {
char accent = mComposing.charAt(mComposing.length() -1 );
int composed = KeyEvent.getDeadChar(accent, c);
if (composed != 0) {
c = composed;
mComposing.setLength(mComposing.length()-1);
}
}
onKey(c, null);
return true;
}
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
switch (keyCode) {
case KeyEvent.KEYCODE_BACK:
if (event.getRepeatCount() == 0 && mInputView != null) {
if (mInputView.handleBack()) {
return true;
}
}
break;
case KeyEvent.KEYCODE_DEL:
if (mComposing.length() > 0) {
onKey(Keyboard.KEYCODE_DELETE, null);
return true;
}
break;
case KeyEvent.KEYCODE_ENTER:
return false;
default:
if (PROCESS_HARD_KEYS) {
if (keyCode == KeyEvent.KEYCODE_SPACE
&& (event.getMetaState()&KeyEvent.META_ALT_ON) != 0) {
InputConnection ic = getCurrentInputConnection();
if (ic != null) {
ic.clearMetaKeyStates(KeyEvent.META_ALT_ON);
keyDownUp(KeyEvent.KEYCODE_A);
keyDownUp(KeyEvent.KEYCODE_N);
keyDownUp(KeyEvent.KEYCODE_D);
keyDownUp(KeyEvent.KEYCODE_R);
keyDownUp(KeyEvent.KEYCODE_O);
keyDownUp(KeyEvent.KEYCODE_I);
keyDownUp(KeyEvent.KEYCODE_D);
return true;
}
}
if (mPredictionOn && translateKeyDown(keyCode, event)) {
return true;
}
}
}
return super.onKeyDown(keyCode, event);
}
@Override
public boolean onKeyUp(int keyCode, KeyEvent event) {
if (PROCESS_HARD_KEYS) {
if (mPredictionOn) {
mMetaState = MetaKeyKeyListener.handleKeyUp(mMetaState,
keyCode, event);
}
}
return super.onKeyUp(keyCode, event);
}
private void commitTyped(InputConnection inputConnection) {
if (mComposing.length() > 0) {
inputConnection.commitText(mComposing, mComposing.length());
mComposing.setLength(0);
updateCandidates();
}
}
private void updateShiftKeyState(EditorInfo attr) {
if (attr != null
&& mInputView != null && mQwertyKeyboard == mInputView.getKeyboard()) {
int caps = 0;
EditorInfo ei = getCurrentInputEditorInfo();
if (ei != null && ei.inputType != EditorInfo.TYPE_NULL) {
caps = getCurrentInputConnection().getCursorCapsMode(attr.inputType);
}
mInputView.setShifted(mCapsLock || caps != 0);
}
}
private boolean isAlphabet(int code) {
if (Character.isLetter(code)) {
return true;
} else {
return false;
}
}
private void keyDownUp(int keyEventCode) {
getCurrentInputConnection().sendKeyEvent(
new KeyEvent(KeyEvent.ACTION_DOWN, keyEventCode));
getCurrentInputConnection().sendKeyEvent(
new KeyEvent(KeyEvent.ACTION_UP, keyEventCode));
}
private void sendKey(int keyCode) {
switch (keyCode) {
case '\n':
keyDownUp(KeyEvent.KEYCODE_ENTER);
break;
default:
if (keyCode >= '0' && keyCode <= '9') {
keyDownUp(keyCode - '0' + KeyEvent.KEYCODE_0);
} else {
getCurrentInputConnection().commitText(String.valueOf((char) keyCode), 1);
}
break;
}
}
public void onKey(int primaryCode, int[] keyCodes) {
if (isWordSeparator(primaryCode)) {
// Handle separator
if (mComposing.length() > 0) {
commitTyped(getCurrentInputConnection());
}
sendKey(primaryCode);
updateShiftKeyState(getCurrentInputEditorInfo());
} else if (primaryCode == Keyboard.KEYCODE_DELETE) {
handleBackspace();
} else if (primaryCode == Keyboard.KEYCODE_SHIFT) {
handleShift();
} else if (primaryCode == Keyboard.KEYCODE_CANCEL) {
handleClose();
return;
} else if (primaryCode == LatinKeyboardView.KEYCODE_OPTIONS) {
// Show a menu or somethin'
} else if (primaryCode == Keyboard.KEYCODE_MODE_CHANGE
&& mInputView != null) {
Keyboard current = mInputView.getKeyboard();
if (current == mSymbolsKeyboard || current == mSymbolsShiftedKeyboard) {
current = mQwertyKeyboard;
} else {
current = mSymbolsKeyboard;
}
mInputView.setKeyboard(current);
if (current == mSymbolsKeyboard) {
current.setShifted(false);
}
} else {
handleCharacter(primaryCode, keyCodes);
}
}
public void onText(CharSequence text) {
InputConnection ic = getCurrentInputConnection();
if (ic == null) return;
ic.beginBatchEdit();
if (mComposing.length() > 0) {
commitTyped(ic);
}
ic.commitText(text, 0);
ic.endBatchEdit();
updateShiftKeyState(getCurrentInputEditorInfo());
}
private void updateCandidates() {
if (!mCompletionOn) {
if (mComposing.length() > 0) {
ArrayList<String> list = new ArrayList<String>();
list.add(mComposing.toString());
setSuggestions(list, true, true);
} else {
setSuggestions(null, false, false);
}
}
}
public void setSuggestions(List<String> suggestions, boolean completions,
boolean typedWordValid) {
if (suggestions != null && suggestions.size() > 0) {
setCandidatesViewShown(true);
} else if (isExtractViewShown()) {
setCandidatesViewShown(true);
}
if (mCandidateView != null) {
mCandidateView.setSuggestions(suggestions, completions, typedWordValid);
}
}
private void handleBackspace() {
final int length = mComposing.length();
if (length > 1) {
mComposing.delete(length - 1, length);
getCurrentInputConnection().setComposingText(mComposing, 1);
updateCandidates();
} else if (length > 0) {
mComposing.setLength(0);
getCurrentInputConnection().commitText("", 0);
updateCandidates();
} else {
keyDownUp(KeyEvent.KEYCODE_DEL);
}
updateShiftKeyState(getCurrentInputEditorInfo());
}
private void handleShift() {
if (mInputView == null) {
return;
}
Keyboard currentKeyboard = mInputView.getKeyboard();
if (mQwertyKeyboard == currentKeyboard) {
// Alphabet keyboard
checkToggleCapsLock();
mInputView.setShifted(mCapsLock || !mInputView.isShifted());
} else if (currentKeyboard == mSymbolsKeyboard) {
mSymbolsKeyboard.setShifted(true);
mInputView.setKeyboard(mSymbolsShiftedKeyboard);
mSymbolsShiftedKeyboard.setShifted(true);
} else if (currentKeyboard == mSymbolsShiftedKeyboard) {
mSymbolsShiftedKeyboard.setShifted(false);
mInputView.setKeyboard(mSymbolsKeyboard);
mSymbolsKeyboard.setShifted(false);
}
}
private void handleCharacter(int primaryCode, int[] keyCodes) {
if (isInputViewShown()) {
if (mInputView.isShifted()) {
primaryCode = Character.toUpperCase(primaryCode);
}
}
if (isAlphabet(primaryCode) && mPredictionOn) {
mComposing.append((char) primaryCode);
getCurrentInputConnection().setComposingText(mComposing, 1);
updateShiftKeyState(getCurrentInputEditorInfo());
updateCandidates();
} else {
getCurrentInputConnection().commitText(
String.valueOf((char) primaryCode), 1);
}
}
private void handleClose() {
commitTyped(getCurrentInputConnection());
requestHideSelf(0);
mInputView.closing();
}
private void checkToggleCapsLock() {
long now = System.currentTimeMillis();
if (mLastShiftTime + 800 > now) {
mCapsLock = !mCapsLock;
mLastShiftTime = 0;
} else {
mLastShiftTime = now;
}
}
private String getWordSeparators() {
return mWordSeparators;
}
public boolean isWordSeparator(int code) {
String separators = getWordSeparators();
return separators.contains(String.valueOf((char)code));
}
public void pickDefaultCandidate() {
pickSuggestionManually(0);
}
public void pickSuggestionManually(int index) {
if (mCompletionOn && mCompletions != null && index >= 0
&& index < mCompletions.length) {
CompletionInfo ci = mCompletions[index];
getCurrentInputConnection().commitCompletion(ci);
if (mCandidateView != null) {
mCandidateView.clear();
}
updateShiftKeyState(getCurrentInputEditorInfo());
} else if (mComposing.length() > 0) {
commitTyped(getCurrentInputConnection());
}
}
public void swipeRight() {
if (mCompletionOn) {
pickDefaultCandidate();
}
}
public void swipeLeft() {
handleBackspace();
}
public void swipeDown() {
handleClose();
}
public void swipeUp() {
}
public void onPress(int primaryCode) {
}
public void onRelease(int primaryCode) {
}
}
And symbols.xml file :
<Key android:codes="-3" android:keyIcon="@drawable/sym_keyboard_done" android:keyWidth="20%p" android:keyEdgeFlags="left" />
When I click Done
key also I didn't go to OnEditorActionListener
method. Please help me
Please help me this:
I have tried like this : But not proper solution. Anyhow I want to take actionId , according to actionId i want put switch statement & want to know why it didn't take actionId when we use other than the android keyboard
txtQty.setOnEditorActionListener( new OnEditorActionListener() {
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
if(event.getKeyCode() == KeyEvent.KEYCODE_ENTER){ } .....
Try this for adding Listener :
msg_title_text.setOnEditorActionListener(new DoneOnEditorActionListener());
Created a class :
class DoneOnEditorActionListener implements OnEditorActionListener {
@Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
if (actionId == EditorInfo.IME_ACTION_DONE) {
Log.v("*****************************", "Clicke da machan");
// Do your Stuffs
return true;
}
return false;
}
}
这篇关于安卓OnEditorActionListener()actionId给出0,当我点击完成关键的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!