android.text.method.DialerKeyListener Java Examples

The following examples show how to use android.text.method.DialerKeyListener. 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: DialerFragment.java    From CSipSimple with GNU General Public License v3.0 6 votes vote down vote up
private void initButtons(View v) {
    /*
    for (int buttonId : buttonsToAttach) {
        attachButtonListener(v, buttonId, false);
    }
    */
    for (int buttonId : buttonsToLongAttach) {
        attachButtonListener(v, buttonId, true);
    }

    digits.setOnClickListener(this);
    digits.setKeyListener(DialerKeyListener.getInstance());
    digits.addTextChangedListener(this);
    digits.setCursorVisible(false);
    afterTextChanged(digits.getText());
}
 
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: DialerFilter.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
@Override
protected void onFinishInflate() {
    super.onFinishInflate();

    // Setup the filter view
    mInputFilters = new InputFilter[] { new InputFilter.AllCaps() };

    mHint = (EditText) findViewById(com.android.internal.R.id.hint);
    if (mHint == null) {
        throw new IllegalStateException("DialerFilter must have a child EditText named hint");
    }
    mHint.setFilters(mInputFilters);

    mLetters = mHint;
    mLetters.setKeyListener(TextKeyListener.getInstance());
    mLetters.setMovementMethod(null);
    mLetters.setFocusable(false);

    // Setup the digits view
    mPrimary = (EditText) findViewById(com.android.internal.R.id.primary);
    if (mPrimary == null) {
        throw new IllegalStateException("DialerFilter must have a child EditText named primary");
    }
    mPrimary.setFilters(mInputFilters);

    mDigits = mPrimary;
    mDigits.setKeyListener(DialerKeyListener.getInstance());
    mDigits.setMovementMethod(null);
    mDigits.setFocusable(false);

    // Look for an icon
    mIcon = (ImageView) findViewById(com.android.internal.R.id.icon);

    // Setup focus & highlight for this view
    setFocusable(true);

    // XXX Force the mode to QWERTY for now, since 12-key isn't supported
    mIsQwerty = true;
    setMode(DIGITS_AND_LETTERS);
}
 
Example #4
Source File: PatientIdElement.java    From sana.mobile with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
protected View createView(Context c) {

    et = new EditText(c);
    et.setPadding(10, 5, 10, 5);
    et.setText(answer);
    et.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT,
            LayoutParams.WRAP_CONTENT));
    et.setGravity(Gravity.CENTER_HORIZONTAL);
    et.setKeyListener(new DialerKeyListener());

    LinearLayout ll = new LinearLayout(c);
    ll.setOrientation(LinearLayout.VERTICAL);

    ll.addView(et, new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT,
            LayoutParams.WRAP_CONTENT));
    ll.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT,
            LayoutParams.WRAP_CONTENT));

    //SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(c);
    boolean barcodeEnable = true; //sp.getBoolean(Constants.PREFERENCE_BARCODE_ENABLED, false);

    if (barcodeEnable) {
        barcodeButton = new Button(c);
        barcodeButton.setText(c.getResources().getString(
                R.string.procedurerunner_scan_id));
        barcodeButton.setOnClickListener(this);
        barcodeButton.setGravity(Gravity.CENTER_HORIZONTAL);
        ll.addView(barcodeButton, new LinearLayout.LayoutParams(
                LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT));
    }
    return encapsulateQuestion(c, ll);
}
 
Example #5
Source File: DialerFilter.java    From android_9.0.0_r45 with Apache License 2.0 4 votes vote down vote up
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    boolean handled = false;

    switch (keyCode) {
        case KeyEvent.KEYCODE_DPAD_UP:
        case KeyEvent.KEYCODE_DPAD_DOWN:
        case KeyEvent.KEYCODE_DPAD_LEFT:
        case KeyEvent.KEYCODE_DPAD_RIGHT:
        case KeyEvent.KEYCODE_ENTER:
        case KeyEvent.KEYCODE_DPAD_CENTER:
            break;

        case KeyEvent.KEYCODE_DEL:
            switch (mMode) {
                case DIGITS_AND_LETTERS:
                    handled = mDigits.onKeyDown(keyCode, event);
                    handled &= mLetters.onKeyDown(keyCode, event);
                    break;

                case DIGITS_AND_LETTERS_NO_DIGITS:
                    handled = mLetters.onKeyDown(keyCode, event);
                    if (mLetters.getText().length() == mDigits.getText().length()) {
                        setMode(DIGITS_AND_LETTERS);
                    }
                    break;

                case DIGITS_AND_LETTERS_NO_LETTERS:
                    if (mDigits.getText().length() == mLetters.getText().length()) {
                        mLetters.onKeyDown(keyCode, event);
                        setMode(DIGITS_AND_LETTERS);
                    }
                    handled = mDigits.onKeyDown(keyCode, event);
                    break;

                case DIGITS_ONLY:
                    handled = mDigits.onKeyDown(keyCode, event);
                    break;

                case LETTERS_ONLY:
                    handled = mLetters.onKeyDown(keyCode, event);
                    break;
            }
            break;

        default:
            //mIsQwerty = msg.getKeyIsQwertyKeyboard();

            switch (mMode) {
                case DIGITS_AND_LETTERS:
                    handled = mLetters.onKeyDown(keyCode, event);

                    // pass this throw so the shift state is correct (for example,
                    // on a standard QWERTY keyboard, * and 8 are on the same key)
                    if (KeyEvent.isModifierKey(keyCode)) {
                        mDigits.onKeyDown(keyCode, event);
                        handled = true;
                        break;
                    }

                    // Only check to see if the digit is valid if the key is a printing key
                    // in the TextKeyListener. This prevents us from hiding the digits
                    // line when keys like UP and DOWN are hit.
                    // XXX note that KEYCODE_TAB is special-cased here for
                    // devices that share tab and 0 on a single key.
                    boolean isPrint = event.isPrintingKey();
                    if (isPrint || keyCode == KeyEvent.KEYCODE_SPACE
                            || keyCode == KeyEvent.KEYCODE_TAB) {
                        char c = event.getMatch(DialerKeyListener.CHARACTERS);
                        if (c != 0) {
                            handled &= mDigits.onKeyDown(keyCode, event);
                        } else {
                            setMode(DIGITS_AND_LETTERS_NO_DIGITS);
                        }
                    }
                    break;

                case DIGITS_AND_LETTERS_NO_LETTERS:
                case DIGITS_ONLY:
                    handled = mDigits.onKeyDown(keyCode, event);
                    break;

                case DIGITS_AND_LETTERS_NO_DIGITS:
                case LETTERS_ONLY:
                    handled = mLetters.onKeyDown(keyCode, event);
                    break;
            }
    }

    if (!handled) {
        return super.onKeyDown(keyCode, event);
    } else {
        return true;
    }
}