Java Code Examples for android.widget.EditText#focusSearch()

The following examples show how to use android.widget.EditText#focusSearch() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: EditTimerActivity.java    From ClockPlus with GNU General Public License v3.0 6 votes vote down vote up
@OnClick({ R.id.zero, R.id.one, R.id.two, R.id.three, R.id.four,
            R.id.five, R.id.six, R.id.seven, R.id.eight, R.id.nine })
    void onClick(TextView view) {
        if (mFocusGrabber.isFocused())
            return;
        EditText field = getFocusedField();
        int at = field.getSelectionStart();
        field.getText().replace(at, at + 1, view.getText());
        field.setSelection(at + 1);
//        updateStartButtonVisibility();
        if (field.getSelectionStart() == FIELD_LENGTH) {
            // At the end of the current field, so try to focus to the next field.
            // The search will return null if no view can be focused next.
            View next = field.focusSearch(View.FOCUS_RIGHT);
            if (next != null) {
                next.requestFocus();
                if (next instanceof EditText) {
                    // Should always start off at the beginning of the field
                    ((EditText) next).setSelection(0);
                }
            }
        }
    }
 
Example 2
Source File: EntryKeyboardView.java    From bither-android with Apache License 2.0 6 votes vote down vote up
private void handleEnter() {
    View currentFocusView = getRootView().findFocus();
    if (currentFocusView == null) {
        return;
    }
    if (currentFocusView instanceof EditText) {
        EditText currentFocusEt = (EditText) currentFocusView;
        if (currentFocusEt.getImeActionId() > 0) {
            currentFocusEt.onEditorAction(currentFocusEt.getImeActionId());
        } else {
            View nextFocusView = currentFocusEt.focusSearch(View.FOCUS_DOWN);
            if (nextFocusView != null) {
                nextFocusView.requestFocus(View.FOCUS_DOWN);
                return;
            } else {
                if (imm.isActive(currentFocusEt)) {
                    imm.hideSoftInputFromWindow(currentFocusEt.getWindowToken(), 0);
                }
                hideKeyboard();
                return;
            }
        }
    }
}
 
Example 3
Source File: EditTimerActivity.java    From ClockPlus with GNU General Public License v3.0 5 votes vote down vote up
@OnClick(R.id.backspace)
    void backspace() {
        if (mFocusGrabber.isFocused()) {
            mEditFieldsLayout.focusSearch(mFocusGrabber, View.FOCUS_LEFT).requestFocus();
        }
        EditText field = getFocusedField();
        if (field == null)
            return;
        int at = field.getSelectionStart();
        if (at == 0) {
            // At the beginning of current field, so move focus
            // to the preceding field
            View prev = field.focusSearch(View.FOCUS_LEFT);
            if (null == prev) {
                // Reached the beginning of the hours field
                return;
            }
            if (prev.requestFocus()) {
                if (prev instanceof EditText) {
                    // Always move the cursor to the end when moving focus back
                    ((EditText) prev).setSelection(FIELD_LENGTH);
                }
                // Recursively backspace on the newly focused field
                backspace();
            }
        } else {
            field.getText().replace(at - 1, at, "0");
            field.setSelection(at - 1);
//            updateStartButtonVisibility();
        }
    }
 
Example 4
Source File: EntryKeyboardView.java    From bither-android with Apache License 2.0 5 votes vote down vote up
private void configureDoneButton() {
    View currentFocusView = getRootView().findFocus();
    if (currentFocusView == null) {
        return;
    }
    if (currentFocusView instanceof EditText) {
        EditText currentFocusEt = (EditText) currentFocusView;
        if (!Utils.isEmpty(currentFocusEt.getImeActionLabel() == null ? null :
                currentFocusEt.getImeActionLabel().toString())) {
            setEnterKeyText(currentFocusEt.getImeActionLabel());
        } else if (currentFocusEt.getImeActionId() > 0) {
            switch (currentFocusEt.getImeActionId()) {
                case EditorInfo.IME_ACTION_DONE:
                case EditorInfo.IME_ACTION_GO:
                case EditorInfo.IME_ACTION_SEND:
                    setEnterKeyText(getResources().getString(R.string.password_keyboard_done));
                    break;
                case EditorInfo.IME_ACTION_NEXT:
                    setEnterKeyText(getResources().getString(R.string.password_keyboard_next));
                    break;
                default:
                    break;
            }
        } else {
            View nextFocusView = currentFocusEt.focusSearch(View.FOCUS_DOWN);
            if (nextFocusView != null) {
                setEnterKeyText(getResources().getString(R.string.password_keyboard_next));
            } else {
                setEnterKeyText(getResources().getString(R.string.password_keyboard_done));
            }
        }
        EntryKeyboard keyboard = (EntryKeyboard) getKeyboard();
        invalidateKey(keyboard.getEnterKeyIndex());
    }
}