Android KeyEvent Check isUserDoneEditing(int actionId, KeyEvent event)

Here you can find the source of isUserDoneEditing(int actionId, KeyEvent event)

Description

Has the user finished editing some field

License

Apache License

Parameter

Parameter Description
actionId Identifier of the action. This will be either the identifier you supplied, or EditorInfo.IME_NULL if being called due to the enter key being pressed.
event If triggered by an enter key, this is the event; otherwise, this is null.

Return

true if user is done editing

Declaration

public static boolean isUserDoneEditing(int actionId, KeyEvent event) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

import android.view.KeyEvent;

import android.view.inputmethod.EditorInfo;

public class Main {
    /**/*from ww  w. j ava  2 s .  c o  m*/
     * Has the user finished editing some field
     * 
     * @param actionId Identifier of the action. This will be either the
     *           identifier you supplied, or EditorInfo.IME_NULL if being called
     *           due to the enter key being pressed.
     * @param event If triggered by an enter key, this is the event; otherwise,
     *           this is null.
     * @return true if user is done editing
     */
    public static boolean isUserDoneEditing(int actionId, KeyEvent event) {
        switch (actionId) {
        case EditorInfo.IME_ACTION_SEARCH:
        case EditorInfo.IME_ACTION_DONE:
            return true;
        }

        if (event != null) {
            int eventAction = event.getAction();
            int eventKeyCode = event.getKeyCode();

            if ((eventAction == KeyEvent.ACTION_DOWN)
                    && (eventKeyCode == KeyEvent.KEYCODE_ENTER)
                    && (!event.isShiftPressed())) {
                return true;
            }
        }

        return false;
    }
}