android.text.method.DigitsKeyListener Java Examples

The following examples show how to use android.text.method.DigitsKeyListener. 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 Project: DevUtils   Author: afkT   File: EditTextUtils.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * 创建 DigitsKeyListener
 * @param inputType 输入类型
 * @param accepted  允许输入的内容
 * @return {@link DigitsKeyListener}
 */
public static DigitsKeyListener createDigitsKeyListener(final int inputType, final char[] accepted) {
    DigitsKeyListener digitsKeyListener = new DigitsKeyListener() {
        @Override
        protected char[] getAcceptedChars() {
            if (accepted != null) {
                return accepted;
            }
            return super.getAcceptedChars();
        }

        @Override
        public int getInputType() {
            if (inputType != -1) {
                return inputType;
            }
            return super.getInputType();
        }
    };
    return digitsKeyListener;
}
 
Example #2
Source Project: star-dns-changer   Author: msayan   File: MaskedEditText.java    License: MIT License 6 votes vote down vote up
@Override
public void setInputType(int type) {
    if (type == -1) {
        type = InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS | InputType.TYPE_TEXT_VARIATION_PASSWORD;
    }

    if (type == InputType.TYPE_CLASS_NUMBER ||
            type == InputType.TYPE_NUMBER_FLAG_SIGNED ||
            type == InputType.TYPE_NUMBER_FLAG_DECIMAL ||
            type == InputType.TYPE_CLASS_PHONE) {
        final String symbolExceptions = getSymbolExceptions();
        this.setKeyListener(DigitsKeyListener.getInstance("0123456789." + symbolExceptions));
    } else {
        super.setInputType(type);
    }
}
 
Example #3
Source Project: nfcspy   Author: sinpolib   File: ActivityMain.java    License: GNU General Public License v3.0 6 votes vote down vote up
private void setDiscoveryDelay() {

		final EditText input = new EditText(this);
		input.setHint(this.getString(R.string.hint_discoverydelay));
		input.setText(Integer.toString(nfc.getDiscoveryDelay()));
		input.setInputType(EditorInfo.TYPE_CLASS_NUMBER);
		input.setKeyListener(DigitsKeyListener.getInstance("01234567890"));
		input.setSingleLine(true);

		SetDelayHelper helper = new SetDelayHelper(nfc, input);

		new AlertDialog.Builder(this, AlertDialog.THEME_HOLO_LIGHT)
				.setTitle(R.string.action_discoverydelay)
				.setMessage(R.string.lab_discoverydelay).setView(input)
				.setPositiveButton(R.string.action_ok, helper)
				.setNegativeButton(R.string.action_cancel, helper).show();
	}
 
Example #4
Source Project: android-pin   Author: venmo   File: PinputView.java    License: MIT License 6 votes vote down vote up
private void init(AttributeSet attrs, int defStyle) {
    // @formatter:off
    final TypedArray a = getContext().obtainStyledAttributes(attrs, R.styleable.PinputView, defStyle, 0);
    // @formatter:on

    setFocusableInTouchMode(false);
    setKeyListener(DigitsKeyListener.getInstance(false, false));

    mPinLen = a.getInt(R.styleable.PinputView_pinputview_len, 4);
    mCharPadding = (int) a.getDimension(R.styleable.PinputView_pinputview_characterPadding,
            getResources().getDimension(R.dimen.pinputview_default_char_padding));
    int foregroundColor = a.getColor(R.styleable.PinputView_pinputview_foregroundColor, Color.BLUE);
    int backgroundColor = a.getColor(R.styleable.PinputView_pinputview_backgroundColor, Color.GRAY);

    a.recycle();

    initDrawables(foregroundColor, backgroundColor);
    initFilters();
    initializeAnimator();
}
 
Example #5
Source Project: sana.mobile   Author: SanaMobile   File: TextEntryElement.java    License: 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 #6
Source Project: Telegram-FOSS   Author: Telegram-FOSS-Team   File: PasscodeActivity.java    License: GNU General Public License v2.0 6 votes vote down vote up
private void updateDropDownTextView() {
    if (dropDown != null) {
        if (currentPasswordType == 0) {
            dropDown.setText(LocaleController.getString("PasscodePIN", R.string.PasscodePIN));
        } else if (currentPasswordType == 1) {
            dropDown.setText(LocaleController.getString("PasscodePassword", R.string.PasscodePassword));
        }
    }
    if (type == 1 && currentPasswordType == 0 || type == 2 && SharedConfig.passcodeType == 0) {
        InputFilter[] filterArray = new InputFilter[1];
        filterArray[0] = new InputFilter.LengthFilter(4);
        passwordEditText.setFilters(filterArray);
        passwordEditText.setInputType(InputType.TYPE_CLASS_PHONE);
        passwordEditText.setKeyListener(DigitsKeyListener.getInstance("1234567890"));
    } else if (type == 1 && currentPasswordType == 1 || type == 2 && SharedConfig.passcodeType == 1) {
        passwordEditText.setFilters(new InputFilter[0]);
        passwordEditText.setKeyListener(null);
        passwordEditText.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD);
    }
    passwordEditText.setTransformationMethod(PasswordTransformationMethod.getInstance());
}
 
Example #7
Source Project: Telegram   Author: DrKLO   File: PasscodeActivity.java    License: GNU General Public License v2.0 6 votes vote down vote up
private void updateDropDownTextView() {
    if (dropDown != null) {
        if (currentPasswordType == 0) {
            dropDown.setText(LocaleController.getString("PasscodePIN", R.string.PasscodePIN));
        } else if (currentPasswordType == 1) {
            dropDown.setText(LocaleController.getString("PasscodePassword", R.string.PasscodePassword));
        }
    }
    if (type == 1 && currentPasswordType == 0 || type == 2 && SharedConfig.passcodeType == 0) {
        InputFilter[] filterArray = new InputFilter[1];
        filterArray[0] = new InputFilter.LengthFilter(4);
        passwordEditText.setFilters(filterArray);
        passwordEditText.setInputType(InputType.TYPE_CLASS_PHONE);
        passwordEditText.setKeyListener(DigitsKeyListener.getInstance("1234567890"));
    } else if (type == 1 && currentPasswordType == 1 || type == 2 && SharedConfig.passcodeType == 1) {
        passwordEditText.setFilters(new InputFilter[0]);
        passwordEditText.setKeyListener(null);
        passwordEditText.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD);
    }
    passwordEditText.setTransformationMethod(PasswordTransformationMethod.getInstance());
}
 
Example #8
Source Project: TelePlus-Android   Author: TelePlusDev   File: PasscodeActivity.java    License: GNU General Public License v2.0 5 votes vote down vote up
private void updateDropDownTextView()
{
    if (dropDown != null)
    {
        if (currentPasswordType == 0)
        {
            dropDown.setText(LocaleController.getString("PasscodePIN", R.string.PasscodePIN));
        }
        else if (currentPasswordType == 1)
        {
            dropDown.setText(LocaleController.getString("PasscodePassword", R.string.PasscodePassword));
        }
    }
    if (type == 1 && currentPasswordType == 0 || type == 2 && SharedConfig.passcodeType == 0)
    {
        InputFilter[] filterArray = new InputFilter[1];
        filterArray[0] = new InputFilter.LengthFilter(4);
        passwordEditText.setFilters(filterArray);
        passwordEditText.setInputType(InputType.TYPE_CLASS_PHONE);
        passwordEditText.setKeyListener(DigitsKeyListener.getInstance("1234567890"));
    }
    else if (type == 1 && currentPasswordType == 1 || type == 2 && SharedConfig.passcodeType == 1)
    {
        passwordEditText.setFilters(new InputFilter[0]);
        passwordEditText.setKeyListener(null);
        passwordEditText.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD);
    }
    passwordEditText.setTransformationMethod(PasswordTransformationMethod.getInstance());
}
 
Example #9
Source Project: green_android   Author: Blockstream   File: UI.java    License: GNU General Public License v3.0 5 votes vote down vote up
public static void localeDecimalInput(final EditText editText) {
    final DecimalFormat decFormat = (DecimalFormat) DecimalFormat.getInstance(Locale.getDefault());
    final DecimalFormatSymbols symbols=decFormat.getDecimalFormatSymbols();
    final String defaultSeparator = Character.toString(symbols.getDecimalSeparator());
    final String otherSeparator = ".".equals(defaultSeparator) ? "," : ".";

    editText.setHint(String.format("0%s00",defaultSeparator));

    editText.addTextChangedListener(new TextWatcher() {
        private boolean isEditing =false;
        @Override
        public void onTextChanged(final CharSequence s, final int start, final int before, final int count) {
            Log.d(TAG,s + " " + start + " " + before + " " + count);
        }


        @Override
        public void afterTextChanged(Editable editable) {
            if (isEditing)
                return;
            isEditing = true;
            final int index = editable.toString().indexOf(otherSeparator);
            if (index > 0)
                editable.replace(index,index+1, defaultSeparator);

            if (editable.toString().contains(".") || editable.toString().contains(","))
                editText.setKeyListener(DigitsKeyListener.getInstance("0123456789"));
            else
                editText.setKeyListener(DigitsKeyListener.getInstance("0123456789.,"));

            isEditing =false;
        }
    });
}
 
Example #10
Source Project: TelePlus-Android   Author: TelePlusDev   File: PasscodeActivity.java    License: GNU General Public License v2.0 5 votes vote down vote up
private void updateDropDownTextView()
{
    if (dropDown != null)
    {
        if (currentPasswordType == 0)
        {
            dropDown.setText(LocaleController.getString("PasscodePIN", R.string.PasscodePIN));
        }
        else if (currentPasswordType == 1)
        {
            dropDown.setText(LocaleController.getString("PasscodePassword", R.string.PasscodePassword));
        }
    }
    if (type == 1 && currentPasswordType == 0 || type == 2 && SharedConfig.passcodeType == 0)
    {
        InputFilter[] filterArray = new InputFilter[1];
        filterArray[0] = new InputFilter.LengthFilter(4);
        passwordEditText.setFilters(filterArray);
        passwordEditText.setInputType(InputType.TYPE_CLASS_PHONE);
        passwordEditText.setKeyListener(DigitsKeyListener.getInstance("1234567890"));
    }
    else if (type == 1 && currentPasswordType == 1 || type == 2 && SharedConfig.passcodeType == 1)
    {
        passwordEditText.setFilters(new InputFilter[0]);
        passwordEditText.setKeyListener(null);
        passwordEditText.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD);
    }
    passwordEditText.setTransformationMethod(PasswordTransformationMethod.getInstance());
}
 
Example #11
Source Project: VMLibrary   Author: lzan13   File: VMEditView.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * 设置输入限制
 */
public void setLimit(String limit) {
    mLimit = limit;
    if (!VMStr.isEmpty(mLimit)) {
        mInputView.setKeyListener(DigitsKeyListener.getInstance(mLimit));
    }
}
 
Example #12
Source Project: AddSubUtils   Author: Jmengfei   File: AddSubUtils.java    License: Apache License 2.0 5 votes vote down vote up
private void setEditable(boolean editable) {
    if (editable) {
        etInput.setFocusable(true);
        etInput.setKeyListener(new DigitsKeyListener());
    } else {
        etInput.setFocusable(false);
        etInput.setKeyListener(null);
    }
}
 
Example #13
Source Project: NumberButton   Author: qinci   File: NumberButton.java    License: Apache License 2.0 5 votes vote down vote up
private void setEditable(boolean editable) {
    if (editable) {
        mCount.setFocusable(true);
        mCount.setKeyListener(new DigitsKeyListener());
    } else {
        mCount.setFocusable(false);
        mCount.setKeyListener(null);
    }
}
 
Example #14
Source Project: commcare-android   Author: dimagi   File: StringNumberWidget.java    License: Apache License 2.0 5 votes vote down vote up
public StringNumberWidget(Context context, FormEntryPrompt prompt, boolean secret) {
    super(context, prompt, secret);

    mAnswer.setTextSize(TypedValue.COMPLEX_UNIT_DIP, mAnswerFontSize);
    mAnswer.setImeOptions(EditorInfo.IME_FLAG_NO_EXTRACT_UI | EditorInfo.IME_ACTION_NEXT);

    // needed to make long readonly text scroll
    mAnswer.setHorizontallyScrolling(false);
    if (!secret) {
        mAnswer.setSingleLine(false);
    }

    mAnswer.setKeyListener(new DigitsKeyListener(true, true) {
        @Override
        protected char[] getAcceptedChars() {
            return new char[]{
                    '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '.', '-', '+', ' '
            };
        }
    });

    if (prompt.isReadOnly()) {
        setBackgroundDrawable(null);
        setFocusable(false);
        setClickable(false);
    }

    //This might be redundant, but I assume that it's about there being a difference
    //between a display value somewhere. We should double check
    if (prompt.getAnswerValue() != null) {
        String curAnswer = getCurrentAnswer().getValue().toString().trim();
        try {
            mAnswer.setText(curAnswer);
        } catch (Exception NumberFormatException) {

        }
    }

}
 
Example #15
Source Project: Task-Reminder-App   Author: hitenpratap   File: TaskPreferences.java    License: MIT License 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
	super.onCreate(savedInstanceState);
	addPreferencesFromResource(R.xml.task_preferences);

	// Set the time default to a numeric number only
	EditTextPreference timeDefault = (EditTextPreference) findPreference(getString(R.string.pref_default_time_from_now_key)); 	
	timeDefault.getEditText().setKeyListener(DigitsKeyListener.getInstance()); 
}
 
Example #16
Source Project: UltimateAndroid   Author: cymcsg   File: ConfigureStandupTimer.java    License: Apache License 2.0 5 votes vote down vote up
private View createMeetingLengthTextBox() {
    meetingLengthEditText = new EditText(this);
    meetingLengthEditText.setGravity(Gravity.CENTER);
    meetingLengthEditText.setKeyListener(new DigitsKeyListener());
    meetingLengthEditText.setRawInputType(InputType.TYPE_CLASS_PHONE);
    meetingLengthEditText.setLayoutParams(new LayoutParams(dipsToPixels(60), LayoutParams.WRAP_CONTENT));
    meetingLengthEditText.setText(Integer.toString(meetingLength));
    meetingLengthEditText.setLines(1);

    meetingLengthSpinner = null;
    return meetingLengthEditText;
}
 
Example #17
Source Project: UltimateAndroid   Author: cymcsg   File: ConfigureStandupTimer.java    License: Apache License 2.0 5 votes vote down vote up
private View createMeetingLengthTextBox() {
    meetingLengthEditText = new EditText(this);
    meetingLengthEditText.setGravity(Gravity.CENTER);
    meetingLengthEditText.setKeyListener(new DigitsKeyListener());
    meetingLengthEditText.setRawInputType(InputType.TYPE_CLASS_PHONE);
    meetingLengthEditText.setLayoutParams(new LayoutParams(dipsToPixels(60), LayoutParams.WRAP_CONTENT));
    meetingLengthEditText.setText(Integer.toString(meetingLength));
    meetingLengthEditText.setLines(1);

    meetingLengthSpinner = null;
    return meetingLengthEditText;
}
 
Example #18
Source Project: sana.mobile   Author: SanaMobile   File: ResourceSettings.java    License: BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Sets the default values for the preference screen
 */
private void initPreferences() {

    // Binary file location
    EditTextPreference binaryFileLocation = (EditTextPreference) findPreference(Constants.PREFERENCE_STORAGE_DIRECTORY);
    if (TextUtils.isEmpty(binaryFileLocation.getText())) {
        binaryFileLocation.setText(EnvironmentUtil.getProcedureDirectory());
    }

    // Image downscale factor
    EditTextPreference imageDownscale = (EditTextPreference) findPreference(Constants.PREFERENCE_IMAGE_SCALE);
    if (TextUtils.isEmpty(imageDownscale.getText())) {
        imageDownscale.setText("" + Constants.IMAGE_SCALE_FACTOR);
    }
    imageDownscale.getEditText().setKeyListener(new DigitsKeyListener());

    // View all edu resources
    PreferenceScreen resourcePref = (PreferenceScreen) findPreference("s_education_resource");
    Intent intent = EducationResourceList.getIntent(Intent.ACTION_PICK,
            Audience.ALL);
    intent.putExtra(Intent.EXTRA_INTENT, new Intent(Intent.ACTION_VIEW));
    resourcePref.setIntent(intent);

    // SD card loading procedures
    PreferenceScreen intentPref = (PreferenceScreen) findPreference("s_procedures");
    intentPref.setIntent(new Intent("org.sana.android.activity.IMPORT_PROCEDURE"));
    //intentPref.setIntent(new Intent(ResourceSettings.this, 
    //		ProcedureSdImporter.class));
}
 
Example #19
Source Project: java-n-IDE-for-Android   Author: shenghuntianlang   File: NonnegativeIntegerEditTextPreference.java    License: Apache License 2.0 4 votes vote down vote up
private void setUpEditText() {
    getEditText().setKeyListener(DigitsKeyListener.getInstance(false, false));
}
 
Example #20
private void setInputType(ValueType valueType) {

        editText.setFilters(new InputFilter[]{});


        if (editTextModel.editable())
            switch (valueType) {
                case PHONE_NUMBER:
                    editText.setInputType(InputType.TYPE_CLASS_PHONE);
                    break;
                case EMAIL:
                    editText.setInputType(InputType.TYPE_CLASS_TEXT |
                            InputType.TYPE_TEXT_VARIATION_EMAIL_ADDRESS);
                    break;
                case TEXT:
                case LONG_TEXT:
                    editText.setKeyListener(null);
                    editText.setFocusable(false);
                    editText.setOnClickListener(v -> {
                        showEditDialog();
                    });
                    break;
                case LETTER:
                    editText.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_FLAG_CAP_CHARACTERS);
                    editText.setFilters(new InputFilter[]{
                            new InputFilter.LengthFilter(1),
                            (source, start, end, dest, dstart, dend) -> {
                                if (source.equals(""))
                                    return source;
                                if (source.toString().matches("[a-zA-Z]"))
                                    return source;
                                return "";
                            }});
                    break;
                case NUMBER:
                    editText.setInputType(InputType.TYPE_CLASS_NUMBER |
                            InputType.TYPE_NUMBER_FLAG_DECIMAL |
                            InputType.TYPE_NUMBER_FLAG_SIGNED);
                    break;
                case INTEGER_NEGATIVE:
                case INTEGER:
                    editText.setInputType(InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_FLAG_SIGNED);
                    break;
                case INTEGER_ZERO_OR_POSITIVE:
                case INTEGER_POSITIVE:
                    editText.setInputType(InputType.TYPE_CLASS_NUMBER);
                    editText.setKeyListener(DigitsKeyListener.getInstance(false, false));
                    break;
                case UNIT_INTERVAL:
                    editText.setInputType(InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_FLAG_DECIMAL);
                    break;
                case PERCENTAGE:
                    editText.setInputType(InputType.TYPE_CLASS_NUMBER);
                    break;
                case URL:
                    editText.setInputType(InputType.TYPE_TEXT_VARIATION_WEB_EDIT_TEXT);
                    break;
                default:
                    break;
            }
        else {
            editText.setInputType(0);
        }
    }
 
Example #21
private void configureViews() {

        editText.setFilters(new InputFilter[]{});

        TextInputLayout.LayoutParams lp = new TextInputLayout.LayoutParams(0, ViewGroup.LayoutParams.WRAP_CONTENT);
        lp.weight = 1f;
        inputLayout.setLayoutParams(lp);
        editText.setMaxLines(1);
        editText.setVerticalScrollBarEnabled(false);

        if (valueType != null)
            switch (valueType) {
                case PHONE_NUMBER:
                    editText.setInputType(InputType.TYPE_CLASS_PHONE);
                    descIcon.setVisibility(VISIBLE);
                    descIcon.setImageResource(R.drawable.ic_form_number);
                    break;
                case EMAIL:
                    editText.setInputType(InputType.TYPE_CLASS_TEXT |
                            InputType.TYPE_TEXT_VARIATION_EMAIL_ADDRESS);
                    descIcon.setVisibility(VISIBLE);
                    descIcon.setImageResource(R.drawable.ic_form_email);
                    break;
                case TEXT:
                    editText.setInputType(InputType.TYPE_CLASS_TEXT);
                    editText.setFilters(new InputFilter[]{new InputFilter.LengthFilter(50000)});
                    editText.setLines(1);
                    editText.setEllipsize(TextUtils.TruncateAt.END);
                    descIcon.setVisibility(VISIBLE);
                    descIcon.setImageResource(R.drawable.ic_form_text);
                    break;
                case LONG_TEXT:
                    editText.getLayoutParams().height = ViewGroup.LayoutParams.WRAP_CONTENT;
                    editText.setMaxLines(Integer.MAX_VALUE);
                    editText.setEllipsize(null);
                    editText.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_FLAG_MULTI_LINE);
                    editText.setVerticalScrollBarEnabled(true);
                    editText.setScrollBarStyle(View.SCROLLBARS_INSIDE_INSET);
                    editText.setOverScrollMode(View.OVER_SCROLL_ALWAYS);
                    editText.setSingleLine(false);
                    editText.setImeOptions(EditorInfo.IME_FLAG_NO_ENTER_ACTION);
                    descIcon.setVisibility(VISIBLE);
                    descIcon.setImageResource(R.drawable.ic_form_text);
                    break;
                case LETTER:
                    editText.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_FLAG_CAP_CHARACTERS);
                    editText.setFilters(new InputFilter[]{
                            new InputFilter.LengthFilter(1),
                            (source, start, end, dest, dstart, dend) -> {
                                if (source.equals(""))
                                    return source;
                                if (source.toString().matches("[a-zA-Z]"))
                                    return source;
                                return "";
                            }});
                    descIcon.setVisibility(VISIBLE);
                    descIcon.setImageResource(R.drawable.ic_form_letter);
                    break;
                case NUMBER:
                    editText.setInputType(InputType.TYPE_CLASS_NUMBER |
                            InputType.TYPE_NUMBER_FLAG_DECIMAL |
                            InputType.TYPE_NUMBER_FLAG_SIGNED);
                    descIcon.setVisibility(VISIBLE);
                    descIcon.setImageResource(R.drawable.ic_form_number);
                    break;
                case INTEGER_NEGATIVE:
                case INTEGER:
                    descIcon.setVisibility(VISIBLE);
                    descIcon.setImageResource(R.drawable.ic_form_number);
                    editText.setInputType(InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_FLAG_SIGNED);
                    break;
                case INTEGER_ZERO_OR_POSITIVE:
                case INTEGER_POSITIVE:
                    descIcon.setVisibility(VISIBLE);
                    descIcon.setImageResource(R.drawable.ic_form_number);
                    editText.setInputType(InputType.TYPE_CLASS_NUMBER);
                    editText.setKeyListener(DigitsKeyListener.getInstance(false, false));
                    break;
                case UNIT_INTERVAL:
                    descIcon.setVisibility(VISIBLE);
                    descIcon.setImageResource(R.drawable.ic_form_number);
                    editText.setInputType(InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_FLAG_DECIMAL);
                    break;
                case PERCENTAGE:
                    descIcon.setVisibility(VISIBLE);
                    descIcon.setImageResource(R.drawable.ic_form_percentage);
                    editText.setInputType(InputType.TYPE_CLASS_NUMBER);
                    break;
                case URL:
                    descIcon.setVisibility(VISIBLE);
                    descIcon.setImageResource(R.drawable.ic_i_url);
                    editText.setInputType(InputType.TYPE_TEXT_VARIATION_WEB_EDIT_TEXT);
                    break;
                default:
                    break;
            }
        editText.setCompoundDrawablePadding(24);
        binding.executePendingBindings();
    }
 
Example #22
Source Project: natrium-android-wallet   Author: BananoCoin   File: SendDialogFragment.java    License: BSD 2-Clause "Simplified" License 4 votes vote down vote up
/**
 * Handle switching to local currency
 */
private void switchCurrency() {
    // Keep a cache of previous amounts because, it's kinda nice to see approx what nano is worth
    // this way you can tap button and tap back and not end up with X.9993451 NANO
    if (useLocalCurrency) {
        // Switch back to NANO
        binding.sendAmount.setKeyListener(DigitsKeyListener.getInstance("0123456789."));
        if (lastLocalCurrencyAmount != null && lastNanoAmount != null && wallet.getLocalCurrencyAmountNoSymbol().equals(lastLocalCurrencyAmount)) {
            lastLocalCurrencyAmount = wallet.getLocalCurrencyAmountNoSymbol();
            wallet.setSendNanoAmount(lastNanoAmount);
        } else {
            lastLocalCurrencyAmount = wallet.getLocalCurrencyAmountNoSymbol();
        }
        useLocalCurrency = false;
        binding.sendAmount.setText(wallet.getSendNanoAmountFormatted());
        lastNanoAmount = wallet.getSendNanoAmount();
        binding.sendBalance.setText(getString(R.string.send_balance, wallet.getAccountBalanceBanano()));
        binding.sendAmount.setFilters(new InputFilter[]{new DigitsInputFilter(Integer.MAX_VALUE, 6, Integer.MAX_VALUE)});
    } else {
        // Switch to local currency);
        NumberFormat nf = NumberFormat.getCurrencyInstance(wallet.getLocalCurrency().getLocale());
        String allowedChars = "0123456789.";
        if (nf instanceof DecimalFormat) {
            DecimalFormatSymbols sym = ((DecimalFormat)nf).getDecimalFormatSymbols();
            allowedChars = String.format("0123456789%s", sym.getDecimalSeparator());
        }
        binding.sendAmount.setKeyListener(DigitsKeyListener.getInstance(allowedChars));
        if (lastNanoAmount != null && lastLocalCurrencyAmount != null && wallet.getSendNanoAmount().equals(lastNanoAmount)) {
            lastNanoAmount = wallet.getSendNanoAmount();
            wallet.setLocalCurrencyAmount(lastLocalCurrencyAmount);
        } else {
            lastNanoAmount = wallet.getSendNanoAmount();
        }
        useLocalCurrency = true;
        binding.sendAmount.setText(wallet.getLocalCurrencyAmountNoSymbol());
        lastLocalCurrencyAmount = wallet.getLocalCurrencyAmountNoSymbol();
        binding.sendBalance.setText(String.format("(%s)", wallet.getAccountBalanceLocalCurrency()));
        binding.sendAmount.setFilters(new InputFilter[]{new DigitsInputFilter(Integer.MAX_VALUE, 2, Integer.MAX_VALUE)});
    }
    binding.sendAmount.setSelection(binding.sendAmount.getText().length());
}
 
Example #23
Source Project: financisto   Author: dsolonenko   File: AmountInput.java    License: GNU General Public License v2.0 4 votes vote down vote up
@AfterViews
protected void initialize() {
    setMinimumHeight(minHeight);
    plusDrawable.mutate().setColorFilter(plusColor, PorterDuff.Mode.SRC_ATOP);
    minusDrawable.mutate().setColorFilter(minusColor, PorterDuff.Mode.SRC_ATOP);
    requestId = EDIT_AMOUNT_REQUEST.incrementAndGet();
    signSwitcher.setFactory(() -> {
        ImageView v = new ImageView(getContext());
        v.setScaleType(ImageView.ScaleType.FIT_CENTER);
        v.setLayoutParams(new ImageSwitcher.LayoutParams(
                LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
        return v;
    });
    signSwitcher.setImageDrawable(minusDrawable);
    primary.setKeyListener(keyListener);
    primary.addTextChangedListener(textWatcher);
    primary.setOnFocusChangeListener(selectAllOnFocusListener);
    secondary.setKeyListener(new DigitsKeyListener(false, false) {

        @Override
        public boolean onKeyDown(View view, Editable content, int keyCode, KeyEvent event) {
            if (keyCode == KeyEvent.KEYCODE_DEL) {
                if (content.length() == 0) {
                    primary.requestFocus();
                    int pos = primary.getText().length();
                    primary.setSelection(pos, pos);
                    return true;
                }
            }
            return super.onKeyDown(view, content, keyCode, event);
        }

        @Override
        public int getInputType() {
            return InputType.TYPE_CLASS_PHONE;
        }

    });
    secondary.addTextChangedListener(textWatcher);
    secondary.setOnFocusChangeListener(selectAllOnFocusListener);

    if (!MyPreferences.isEnterCurrencyDecimalPlaces(getContext())) {
        secondary.setVisibility(GONE);
        delimiter.setVisibility(GONE);
    }
}
 
Example #24
Source Project: javaide   Author: tranleduy2000   File: NonnegativeIntegerEditTextPreference.java    License: GNU General Public License v3.0 4 votes vote down vote up
private void setUpEditText() {
    getEditText().setKeyListener(DigitsKeyListener.getInstance(false, false));
}
 
Example #25
Source Project: AutoFormatEditText   Author: aldoKelvianto   File: AutoFormatEditText.java    License: Apache License 2.0 4 votes vote down vote up
private void setSoftInputKeyboard() {
    setKeyListener(new DigitsKeyListener(false, isDecimal));
}
 
Example #26
Source Project: matlog   Author: plusCubed   File: NonnegativeIntegerEditTextPreference.java    License: GNU General Public License v3.0 4 votes vote down vote up
private void setUpEditText() {
    getEditText().setKeyListener(DigitsKeyListener.getInstance(false, false));
}
 
Example #27
Source Project: commcare-android   Author: dimagi   File: DecimalWidget.java    License: Apache License 2.0 4 votes vote down vote up
public DecimalWidget(Context context, FormEntryPrompt prompt, boolean secret, boolean compact) {
    super(context, prompt, secret, compact);

    // formatting
    mAnswer.setTextSize(TypedValue.COMPLEX_UNIT_DIP, mAnswerFontSize);
    mAnswer.setImeOptions(EditorInfo.IME_FLAG_NO_EXTRACT_UI | EditorInfo.IME_ACTION_NEXT);

    // needed to make long readonly text scroll
    mAnswer.setHorizontallyScrolling(isInCompactMode());

    // only numbers are allowed
    mAnswer.setKeyListener(new DigitsKeyListener(true, true));

    // only 15 characters allowed
    InputFilter[] fa = new InputFilter[1];
    fa[0] = new InputFilter.LengthFilter(15);
    mAnswer.setFilters(fa);

    Double d = null;
    if (getCurrentAnswer() != null) {
        d = (Double)getCurrentAnswer().getValue();
    }

    NumberFormat nf = NumberFormat.getNumberInstance(Locale.ENGLISH);
    nf.setMaximumFractionDigits(15);
    nf.setMaximumIntegerDigits(15);
    nf.setGroupingUsed(false);
    if (d != null) {
        Double dAnswer = (Double)getCurrentAnswer().getValue();
        String dString = nf.format(dAnswer);
        dString = dString.replace(',', '.');
        mAnswer.setText(dString);
    }

    // disable if read only
    if (prompt.isReadOnly()) {
        setBackgroundDrawable(null);
        setFocusable(false);
        setClickable(false);
    }
}
 
Example #28
Source Project: sana.mobile   Author: SanaMobile   File: NetworkSettings.java    License: BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
/**
 * Sets the default values for the preference screen
 */
private void initPreferences() {
    // Phone name
    String phoneNum = ((TelephonyManager) getSystemService(
            Context.TELEPHONY_SERVICE))
            .getLine1Number();
    Log.d(TAG, "Phone number of this phone: " + phoneNum);
    if (TextUtils.isEmpty(phoneNum))
        phoneNum = Constants.DEFAULT_PHONE_NUMBER;

    EditTextPreference prefPhoneName = (EditTextPreference) findPreference(Constants.PREFERENCE_PHONE_NAME);
    if (TextUtils.isEmpty(prefPhoneName.getText())) {
        prefPhoneName.setText(phoneNum);
    }
    // Sana Dispatch Server URL
    EditTextPreference prefMdsUrl = (EditTextPreference) findPreference(Constants.PREFERENCE_MDS_URL);
    if (TextUtils.isEmpty(prefMdsUrl.getText())) {
        prefMdsUrl.setText(Constants.DEFAULT_DISPATCH_SERVER);
    }

    // Initial packet size
    EditTextPreference prefInitPacketSize = (EditTextPreference) findPreference(Constants.PREFERENCE_PACKET_SIZE);
    if (TextUtils.isEmpty(prefMdsUrl.getText())) {
        prefInitPacketSize.setText("" + Constants.DEFAULT_INIT_PACKET_SIZE);
    }
    prefInitPacketSize.getEditText().setKeyListener(new DigitsKeyListener());

    // How often the database gets refreshed
    EditTextPreference prefDatabaseRefresh = (EditTextPreference) findPreference(Constants.PREFERENCE_DATABASE_UPLOAD);
    if (TextUtils.isEmpty(prefDatabaseRefresh.getText())) {
        prefDatabaseRefresh.setText("" + Constants.DEFAULT_DATABASE_UPLOAD);
    }
    prefDatabaseRefresh.getEditText().setKeyListener(new DigitsKeyListener());

    // Estimated network bandwidth
    EditTextPreference prefEstimatedNetworkBandwidth = (EditTextPreference) findPreference(Constants.PREFERENCE_NETWORK_BANDWIDTH);
    if (TextUtils.isEmpty(prefEstimatedNetworkBandwidth.getText())) {
        prefEstimatedNetworkBandwidth.setText("" + Constants.ESTIMATED_NETWORK_BANDWIDTH);
    }
    prefEstimatedNetworkBandwidth.getEditText().setKeyListener(
            new DigitsKeyListener());
}
 
Example #29
Source Project: ministocks   Author: niteshpatel   File: InputTools.java    License: MIT License 4 votes vote down vote up
public static DigitsKeyListener getDecimalKeyListener() {
    char separator = DecimalFormatSymbols.getInstance().getDecimalSeparator();

    return DigitsKeyListener.getInstance("0123456789" + separator);
}
 
Example #30
Source Project: ministocks   Author: niteshpatel   File: InputTools.java    License: MIT License 4 votes vote down vote up
public static DigitsKeyListener getSignedDecimalKeyListener() {
    char separator = DecimalFormatSymbols.getInstance().getDecimalSeparator();

    return DigitsKeyListener.getInstance("0123456789-" + separator);
}