Java Code Examples for android.text.method.KeyListener

The following examples show how to use android.text.method.KeyListener. These examples are extracted from open source projects. 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 want to check out the right sidebar which shows the related API usage.
Example 1
/**
 * gets the key listener by type
 */
protected static KeyListener getKeyListenerForType(NumericType type) {
    switch (type) {
        case DIALPAD:
            return new DialerKeyListener();
        case INTEGER:
            return new DigitsKeyListener();
        case SIGNED:
            return new DigitsKeyListener(true, false);
        case DECIMAL:
            return new DigitsKeyListener(true, true);
        case NONE:
        default:
            return null;
    }
}
 
Example 2
/**
 * {@inheritDoc}
 */
@Override
protected View createView(Context c) {
    et = new EditText(c);
    et.setBackgroundResource(R.drawable.oval);
    et.setTextColor(c.getResources()
            .getColorStateList(R.color.primary_text_holo_light));
    et.setText(answer);
    et.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT,
            LayoutParams.WRAP_CONTENT));
    if (!NumericType.NONE.equals(numericType)) {
        KeyListener listener = getKeyListenerForType(numericType);
        if (listener != null)
            et.setKeyListener(listener);
    } else {
        et.setRawInputType(InputType.TYPE_TEXT_FLAG_CAP_SENTENCES |
                TYPE_TEXT_FLAG_NO_SUGGESTIONS);
    }
    return encapsulateQuestion(c, et);
}
 
Example 3
Source Project: android_9.0.0_r45   Source File: DialerFilter.java    License: Apache License 2.0 5 votes vote down vote up
private void swapPrimaryAndHint(boolean makeLettersPrimary) {
    Editable lettersText = mLetters.getText();
    Editable digitsText = mDigits.getText();
    KeyListener lettersInput = mLetters.getKeyListener();
    KeyListener digitsInput = mDigits.getKeyListener();

    if (makeLettersPrimary) {
        mLetters = mPrimary;
        mDigits = mHint;
    } else {
        mLetters = mHint;
        mDigits = mPrimary;
    }

    mLetters.setKeyListener(lettersInput);
    mLetters.setText(lettersText);
    lettersText = mLetters.getText();
    Selection.setSelection(lettersText, lettersText.length());

    mDigits.setKeyListener(digitsInput);
    mDigits.setText(digitsText);
    digitsText = mDigits.getText();
    Selection.setSelection(digitsText, digitsText.length());

    // Reset the filters
    mPrimary.setFilters(mInputFilters);
    mHint.setFilters(mInputFilters);
}
 
Example 4
public boolean clearMetaKeyStates(int states) {
    final Editable content = getEditable();
    if (content == null) return false;
    KeyListener kl = mTextView.getKeyListener();
    if (kl != null) {
        try {
            kl.clearMetaKeyState(mTextView, content, states);
        } catch (AbstractMethodError e) {
            // This is an old listener that doesn't implement the
            // new method.
        }
    }
    return true;
}
 
Example 5
Source Project: JotaTextEditor   Source File: EditableInputConnection.java    License: Apache License 2.0 5 votes vote down vote up
public boolean clearMetaKeyStates(int states) {
    final Editable content = getEditable();
    if (content == null) return false;
    KeyListener kl = mTextView.getKeyListener();
    if (kl != null) {
        try {
            kl.clearMetaKeyState(mTextView, content, states);
        } catch (AbstractMethodError e) {
            // This is an old listener that doesn't implement the
            // new method.
        }
    }
    return true;
}
 
Example 6
Source Project: BluetoothHidEmu   Source File: GenericUiControls.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * onKeyDown()
 */
@Override
public boolean processKeyDown(int keyCode, KeyEvent event) {
    
    if (mEchoEditText != null && (keyCode == KeyEvent.KEYCODE_VOLUME_UP || keyCode == KeyEvent.KEYCODE_VOLUME_DOWN)) {
        KeyListener keyListener = mEchoEditText.getKeyListener();
        keyListener.onKeyDown(mEchoEditText, mEchoEditText.getEditableText(), keyCode, event);
        return true;
    }
    return false;
}
 
Example 7
Source Project: BluetoothHidEmu   Source File: GenericUiControls.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * onKeyUp()
 */
@Override
public boolean processKeyUp(int keyCode, KeyEvent event) {

    if (mEchoEditText != null && (keyCode == KeyEvent.KEYCODE_VOLUME_UP || keyCode == KeyEvent.KEYCODE_VOLUME_DOWN)) {
        KeyListener keyListener = mEchoEditText.getKeyListener();
        keyListener.onKeyUp(mEchoEditText, mEchoEditText.getEditableText(), keyCode, event);
        return true;
    }

    return false;
}
 
Example 8
Source Project: timecat   Source File: TEditText.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public void setKeyListener(KeyListener input) {
    super.setKeyListener(input);
}
 
Example 9
Source Project: anvil   Source File: DSL.java    License: MIT License 4 votes vote down vote up
public static Void keyListener(KeyListener arg) {
  return BaseDSL.attr("keyListener", arg);
}
 
Example 10
Source Project: anvil   Source File: DSL.java    License: MIT License 4 votes vote down vote up
public static Void keyListener(KeyListener arg) {
  return BaseDSL.attr("keyListener", arg);
}
 
Example 11
/**
 * Delegate method for the input widget
 */
public void setInputWidgetKeyListener(KeyListener input) {
    getInputWidget().setKeyListener(input);
}
 
Example 12
/**
 * Delegate method for the input widget
 */
public void setInputWidgetKeyListener(KeyListener input) {
    getInputWidget().setKeyListener(input);
}
 
Example 13
Source Project: DevUtils   Source File: EditTextUtils.java    License: Apache License 2.0 3 votes vote down vote up
/**
 * 设置 KeyListener
 * @param editText    {@link EditText}
 * @param keyListener {@link KeyListener}
 * @param <T>         泛型
 * @return {@link EditText}
 */
public static <T extends EditText> T setKeyListener(final T editText, final KeyListener keyListener) {
    if (editText != null) {
        editText.setKeyListener(keyListener);
    }
    return editText;
}
 
Example 14
Source Project: DevUtils   Source File: DevHelper.java    License: Apache License 2.0 2 votes vote down vote up
/**
 * 设置 KeyListener
 * @param editText    {@link EditText}
 * @param keyListener {@link KeyListener}
 * @return {@link DevHelper}
 */
public DevHelper setKeyListener(final EditText editText, final KeyListener keyListener) {
    EditTextUtils.setKeyListener(editText, keyListener);
    return this;
}
 
Example 15
Source Project: DevUtils   Source File: ViewHelper.java    License: Apache License 2.0 2 votes vote down vote up
/**
 * 设置 KeyListener
 * @param editText    {@link EditText}
 * @param keyListener {@link KeyListener}
 * @return {@link ViewHelper}
 */
public ViewHelper setKeyListener(final EditText editText, final KeyListener keyListener) {
    EditTextUtils.setKeyListener(editText, keyListener);
    return this;
}
 
Example 16
Source Project: MDPreference   Source File: EditText.java    License: Apache License 2.0 2 votes vote down vote up
/**
    * @return the current key listener for this TextView.
    * This will frequently be null for non-EditText TextViews.
    *
    * @attr ref android.R.styleable#TextView_numeric
    * @attr ref android.R.styleable#TextView_digits
    * @attr ref android.R.styleable#TextView_phoneNumber
    * @attr ref android.R.styleable#TextView_inputMethod
    * @attr ref android.R.styleable#TextView_capitalize
    * @attr ref android.R.styleable#TextView_autoText
    */
public final KeyListener getKeyListener (){
	return mInputView.getKeyListener();
}
 
Example 17
Source Project: MDPreference   Source File: EditText.java    License: Apache License 2.0 2 votes vote down vote up
/**
    * Sets the key listener to be used with this TextView.  This can be null
    * to disallow user input.  Note that this method has significant and
    * subtle interactions with soft keyboards and other input method:
    * see {@link KeyListener#getInputType() KeyListener.getContentType()}
    * for important details.  Calling this method will replace the current
    * content type of the text view with the content type returned by the
    * key listener.
    * <p>
    * Be warned that if you want a TextView with a key listener or movement
    * method not to be focusable, or if you want a TextView without a
    * key listener or movement method to be focusable, you must call
    * {@link #setFocusable} again after calling this to get the focusability
    * back the way you want it.
    *
    * @attr ref android.R.styleable#TextView_numeric
    * @attr ref android.R.styleable#TextView_digits
    * @attr ref android.R.styleable#TextView_phoneNumber
    * @attr ref android.R.styleable#TextView_inputMethod
    * @attr ref android.R.styleable#TextView_capitalize
    * @attr ref android.R.styleable#TextView_autoText
    */
public void setKeyListener (KeyListener input){
	mInputView.setKeyListener(input);
}
 
Example 18
Source Project: AndroidMaterialValidation   Source File: EditText.java    License: Apache License 2.0 2 votes vote down vote up
/**
 * @return the current key listener for this TextView. This will frequently be null for
 * non-EditText TextViews.
 */
public final KeyListener getKeyListener() {
    return getView().getKeyListener();
}
 
Example 19
Source Project: AndroidMaterialValidation   Source File: EditText.java    License: Apache License 2.0 2 votes vote down vote up
/**
 * Sets the key listener to be used with this TextView. This can be null to disallow user input.
 * Note that this method has significant and subtle interactions with soft keyboards and other
 * input method: see {@link KeyListener#getInputType() KeyListener.getContentType()} for
 * important details. Calling this method will replace the current content type of the text view
 * with the content type returned by the key listener. <p> Be warned that if you want a TextView
 * with a key listener or movement method not to be focusable, or if you want a TextView without
 * a key listener or movement method to be focusable, you must call {@link #setFocusable} again
 * after calling this to get the focusability back the way you want it.
 */
public final void setKeyListener(final KeyListener input) {
    getView().setKeyListener(input);
}
 
Example 20
Source Project: material   Source File: EditText.java    License: Apache License 2.0 2 votes vote down vote up
/**
    * @return the current key listener for this TextView.
    * This will frequently be null for non-EditText TextViews.
    *
    * @attr ref android.R.styleable#TextView_numeric
    * @attr ref android.R.styleable#TextView_digits
    * @attr ref android.R.styleable#TextView_phoneNumber
    * @attr ref android.R.styleable#TextView_inputMethod
    * @attr ref android.R.styleable#TextView_capitalize
    * @attr ref android.R.styleable#TextView_autoText
    */
public final KeyListener getKeyListener (){
	return mInputView.getKeyListener();
}
 
Example 21
Source Project: material   Source File: EditText.java    License: Apache License 2.0 2 votes vote down vote up
/**
    * Sets the key listener to be used with this TextView.  This can be null
    * to disallow user input.  Note that this method has significant and
    * subtle interactions with soft keyboards and other input method:
    * see {@link KeyListener#getInputType() KeyListener.getContentType()}
    * for important details.  Calling this method will replace the current
    * content type of the text view with the content type returned by the
    * key listener.
    * <p>
    * Be warned that if you want a TextView with a key listener or movement
    * method not to be focusable, or if you want a TextView without a
    * key listener or movement method to be focusable, you must call
    * {@link #setFocusable} again after calling this to get the focusability
    * back the way you want it.
    *
    * @attr ref android.R.styleable#TextView_numeric
    * @attr ref android.R.styleable#TextView_digits
    * @attr ref android.R.styleable#TextView_phoneNumber
    * @attr ref android.R.styleable#TextView_inputMethod
    * @attr ref android.R.styleable#TextView_capitalize
    * @attr ref android.R.styleable#TextView_autoText
    */
public void setKeyListener (KeyListener input){
	mInputView.setKeyListener(input);
}