FileDocCategorySizeDatePackage
BaseKeyListener.javaAPI DocAndroid 1.5 API4900Wed May 06 22:41:56 BST 2009android.text.method

BaseKeyListener

public abstract class BaseKeyListener extends MetaKeyKeyListener implements KeyListener

Fields Summary
static final Object
OLD_SEL_START
Constructors Summary
Methods Summary
private booleanaltBackspace(android.view.View view, Editable content, int keyCode, android.view.KeyEvent event)

        if (getMetaState(content, META_ALT_ON) != 1) {
            return false;
        }

        if (!(view instanceof TextView)) {
            return false;
        }

        Layout layout = ((TextView) view).getLayout();

        if (layout == null) {
            return false;
        }

        int l = layout.getLineForOffset(Selection.getSelectionStart(content));
        int start = layout.getLineStart(l);
        int end = layout.getLineEnd(l);

        if (end == start) {
            return false;
        }

        content.delete(start, end);
        return true;
    
public booleanbackspace(android.view.View view, Editable content, int keyCode, android.view.KeyEvent event)
Performs the action that happens when you press the DEL key in a TextView. If there is a selection, deletes the selection; otherwise, DEL alone deletes the character before the cursor, if any; ALT+DEL deletes everything on the line the cursor is on.

return
true if anything was deleted; false otherwise.


                                                                
           
                               
        int selStart, selEnd;
        boolean result = true;

        {
            int a = Selection.getSelectionStart(content);
            int b = Selection.getSelectionEnd(content);

            selStart = Math.min(a, b);
            selEnd = Math.max(a, b);
        }

        if (selStart != selEnd) {
            content.delete(selStart, selEnd);
        } else if (altBackspace(view, content, keyCode, event)) {
            result = true;
        } else {
            int to = TextUtils.getOffsetBefore(content, selEnd);

            if (to != selEnd) {
                content.delete(Math.min(to, selEnd), Math.max(to, selEnd));
            }
            else {
                result = false;
            }
        }

        if (result)
            adjustMetaAfterKeypress(content);

        return result;
    
static intmakeTextContentType(android.text.method.TextKeyListener.Capitalize caps, boolean autoText)

        int contentType = InputType.TYPE_CLASS_TEXT;
        switch (caps) {
            case CHARACTERS:
                contentType |= InputType.TYPE_TEXT_FLAG_CAP_CHARACTERS;
                break;
            case WORDS:
                contentType |= InputType.TYPE_TEXT_FLAG_CAP_WORDS;
                break;
            case SENTENCES:
                contentType |= InputType.TYPE_TEXT_FLAG_CAP_SENTENCES;
                break;
        }
        if (autoText) {
            contentType |= InputType.TYPE_TEXT_FLAG_AUTO_CORRECT;
        }
        return contentType;
    
public booleanonKeyDown(android.view.View view, Editable content, int keyCode, android.view.KeyEvent event)

        if (keyCode == KeyEvent.KEYCODE_DEL) {
            backspace(view, content, keyCode, event);
            return true;
        }
        
        return super.onKeyDown(view, content, keyCode, event);
    
public booleanonKeyOther(android.view.View view, Editable content, android.view.KeyEvent event)
Base implementation handles ACTION_MULTIPLE KEYCODE_UNKNOWN by inserting the event's text into the content.

        if (event.getAction() != KeyEvent.ACTION_MULTIPLE
                || event.getKeyCode() != KeyEvent.KEYCODE_UNKNOWN) {
            // Not something we are interested in.
            return false;
        }
        
        int selStart, selEnd;

        {
            int a = Selection.getSelectionStart(content);
            int b = Selection.getSelectionEnd(content);

            selStart = Math.min(a, b);
            selEnd = Math.max(a, b);
        }

        CharSequence text = event.getCharacters();
        if (text == null) {
            return false;
        }
        
        content.replace(selStart, selEnd, text);
        return true;