android.text.method.KeyListener Java Examples

The following examples show how to use android.text.method.KeyListener. 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: TextEntryElement.java    From sana.mobile with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * {@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 #2
Source File: TextEntryElement.java    From sana.mobile with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * 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 #3
Source File: EditableInputConnection.java    From JotaTextEditor with 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 #4
Source File: GenericUiControls.java    From BluetoothHidEmu with 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 #5
Source File: GenericUiControls.java    From BluetoothHidEmu with 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 #6
Source File: DialerFilter.java    From android_9.0.0_r45 with 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 #7
Source File: EditableInputConnection.java    From PowerFileExplorer with GNU General Public License v3.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 #8
Source File: DSL.java    From anvil with MIT License 4 votes vote down vote up
public static Void keyListener(KeyListener arg) {
  return BaseDSL.attr("keyListener", arg);
}
 
Example #9
Source File: DSL.java    From anvil with MIT License 4 votes vote down vote up
public static Void keyListener(KeyListener arg) {
  return BaseDSL.attr("keyListener", arg);
}
 
Example #10
Source File: TEditText.java    From timecat with Apache License 2.0 4 votes vote down vote up
@Override
public void setKeyListener(KeyListener input) {
    super.setKeyListener(input);
}
 
Example #11
Source File: FloatingLabelEditText.java    From android-floatinglabel-widgets with Apache License 2.0 4 votes vote down vote up
/**
 * Delegate method for the input widget
 */
public void setInputWidgetKeyListener(KeyListener input) {
    getInputWidget().setKeyListener(input);
}
 
Example #12
Source File: FloatingLabelAutoCompleteTextView.java    From android-floatinglabel-widgets with Apache License 2.0 4 votes vote down vote up
/**
 * Delegate method for the input widget
 */
public void setInputWidgetKeyListener(KeyListener input) {
    getInputWidget().setKeyListener(input);
}
 
Example #13
Source File: EditTextUtils.java    From DevUtils with 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 File: EditText.java    From MDPreference with 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 #15
Source File: EditText.java    From MDPreference with 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 #16
Source File: EditText.java    From AndroidMaterialValidation with 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 #17
Source File: EditText.java    From AndroidMaterialValidation with 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 #18
Source File: EditText.java    From material with 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 #19
Source File: EditText.java    From material with 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 #20
Source File: ViewHelper.java    From DevUtils with 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 #21
Source File: DevHelper.java    From DevUtils with 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;
}