Java Code Examples for android.text.InputType#TYPE_NUMBER_FLAG_DECIMAL

The following examples show how to use android.text.InputType#TYPE_NUMBER_FLAG_DECIMAL . 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: DigitsKeyListener.java    From android_9.0.0_r45 with Apache License 2.0 6 votes vote down vote up
/**
 * Returns the input type for the listener.
 */
public int getInputType() {
    int contentType;
    if (mNeedsAdvancedInput) {
        contentType = InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_NORMAL;
    } else {
        contentType = InputType.TYPE_CLASS_NUMBER;
        if (mSign) {
            contentType |= InputType.TYPE_NUMBER_FLAG_SIGNED;
        }
        if (mDecimal) {
            contentType |= InputType.TYPE_NUMBER_FLAG_DECIMAL;
        }
    }
    return contentType;
}
 
Example 2
Source File: MaskedEditText.java    From star-dns-changer with 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 File: DigitsKeyListenerWithComma.java    From AndroidAPS with GNU Affero General Public License v3.0 5 votes vote down vote up
public int getInputType() {
    int contentType = InputType.TYPE_CLASS_NUMBER;
    if (mSign) {
        contentType |= InputType.TYPE_NUMBER_FLAG_SIGNED;
    }
    if (mDecimal) {
        contentType |= InputType.TYPE_NUMBER_FLAG_DECIMAL;
    }
    return contentType;
}
 
Example 4
Source File: FieldValidator.java    From tapchat-android with Apache License 2.0 5 votes vote down vote up
private static boolean validateEditText(EditText editText) {
    boolean valid = true;

    String text = editText.getText().toString();

    boolean isEmail   = (editText.getInputType() & InputType.TYPE_TEXT_VARIATION_EMAIL_ADDRESS) == InputType.TYPE_TEXT_VARIATION_EMAIL_ADDRESS;
    boolean isNumeric = (editText.getInputType() & InputType.TYPE_NUMBER_FLAG_DECIMAL) == InputType.TYPE_NUMBER_FLAG_DECIMAL;

    if (TextUtils.isEmpty(text)) {
        if (!isNumeric || !TextUtils.isDigitsOnly(editText.getHint())) {
            valid = false;
        }

    } else if (isEmail) {
        valid = android.util.Patterns.EMAIL_ADDRESS.matcher(text).matches();
    }

    if (!valid) {
        Context context = editText.getContext();
        if (isEmail) {
            editText.setError(context.getString(R.string.error_invalid_email));
        } else {
            editText.setError(context.getString(R.string.error_blank));
        }
        return false;
    }

    editText.setError(null);
    return true;
}
 
Example 5
Source File: NewTraitDialog.java    From Field-Book with GNU General Public License v2.0 5 votes vote down vote up
public void prepareFields(int index) {
    TraitFormat traitFormat = traitFormats.getTraitFormatByIndex(index);

    details.setHint(traitFormat.detailsBox().getParameterHint());
    def.setHint(traitFormat.defaultBox().getParameterHint());
    minimum.setHint(traitFormat.minimumBox().getParameterHint());
    maximum.setHint(traitFormat.maximumBox().getParameterHint());

    defBox.setVisibility(viewVisibility(traitFormat.isDefBoxVisible()));
    def.setVisibility(viewVisibility(traitFormat.defaultBox().getParameterVisibility()));
    minBox.setVisibility(viewVisibility(traitFormat.minimumBox().getParameterVisibility()));
    maxBox.setVisibility(viewVisibility(traitFormat.maximumBox().getParameterVisibility()));
    bool.setVisibility(viewVisibility(traitFormat.isBooleanVisible()));
    categoryBox.setVisibility(viewVisibility(traitFormat.categoriesBox().getParameterVisibility()));

    minimum.setText(traitFormat.minimumBox().getParameterDefaultValue());
    maximum.setText(traitFormat.maximumBox().getParameterDefaultValue());
    def.setText(traitFormat.defaultBox().getParameterDefaultValue());

    if (traitFormat.isNumericInputType()) {
        final int inputType = InputType.TYPE_CLASS_NUMBER |
                InputType.TYPE_NUMBER_FLAG_DECIMAL;
        def.setInputType(inputType);
        minimum.setInputType(inputType);
        maximum.setInputType(inputType);
    }
}
 
Example 6
Source File: ReactTextInputPropertyTest.java    From react-native-GPay with MIT License 4 votes vote down vote up
@Test
public void testKeyboardType() {
  ReactEditText view = mManager.createViewInstance(mThemedContext);
  int numberPadTypeFlags = InputType.TYPE_CLASS_NUMBER;
  int decimalPadTypeFlags = InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_FLAG_DECIMAL;
  int numericTypeFlags =
      InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_FLAG_DECIMAL |
      InputType.TYPE_NUMBER_FLAG_SIGNED;
  int emailTypeFlags = InputType.TYPE_TEXT_VARIATION_EMAIL_ADDRESS | InputType.TYPE_CLASS_TEXT;
  int passwordVisibilityFlag = InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD &
      ~InputType.TYPE_TEXT_VARIATION_PASSWORD;

  int generalKeyboardTypeFlags = numericTypeFlags |
      InputType.TYPE_TEXT_VARIATION_EMAIL_ADDRESS |
      InputType.TYPE_CLASS_TEXT | InputType.TYPE_CLASS_PHONE |
      passwordVisibilityFlag;

  mManager.updateProperties(view, buildStyles());
  assertThat(view.getInputType() & generalKeyboardTypeFlags).isEqualTo(InputType.TYPE_CLASS_TEXT);

  mManager.updateProperties(view, buildStyles("keyboardType", "text"));
  assertThat(view.getInputType() & generalKeyboardTypeFlags).isEqualTo(InputType.TYPE_CLASS_TEXT);

  mManager.updateProperties(view, buildStyles("keyboardType", "number-pad"));
  assertThat(view.getInputType() & generalKeyboardTypeFlags).isEqualTo(numberPadTypeFlags);

  mManager.updateProperties(view, buildStyles("keyboardType", "decimal-pad"));
  assertThat(view.getInputType() & generalKeyboardTypeFlags).isEqualTo(decimalPadTypeFlags);

  mManager.updateProperties(view, buildStyles("keyboardType", "numeric"));
  assertThat(view.getInputType() & generalKeyboardTypeFlags).isEqualTo(numericTypeFlags);

  mManager.updateProperties(view, buildStyles("keyboardType", "email-address"));
  assertThat(view.getInputType() & generalKeyboardTypeFlags).isEqualTo(emailTypeFlags);

  mManager.updateProperties(view, buildStyles("keyboardType", "phone-pad"));
  assertThat(view.getInputType() & generalKeyboardTypeFlags).isEqualTo(InputType.TYPE_CLASS_PHONE);

  mManager.updateProperties(view, buildStyles("keyboardType", "visible-password"));
  assertThat(view.getInputType() & generalKeyboardTypeFlags).isEqualTo(passwordVisibilityFlag);

  mManager.updateProperties(view, buildStyles("keyboardType", null));
  assertThat(view.getInputType() & generalKeyboardTypeFlags).isEqualTo(InputType.TYPE_CLASS_TEXT);
}
 
Example 7
Source File: TextFieldImpl.java    From J2ME-Loader with Apache License 2.0 4 votes vote down vote up
void setConstraints(int constraints) {
	this.constraints = constraints;

	if (textview != null) {
		int inputtype;

		switch (constraints & TextField.CONSTRAINT_MASK) {
			default:
			case TextField.ANY:
				inputtype = InputType.TYPE_CLASS_TEXT;
				break;

			case TextField.EMAILADDR:
				inputtype = InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_EMAIL_ADDRESS;
				break;

			case TextField.NUMERIC:
				inputtype = InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_FLAG_SIGNED;
				break;

			case TextField.PHONENUMBER:
				inputtype = InputType.TYPE_CLASS_PHONE;
				break;

			case TextField.URL:
				inputtype = InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_URI;
				break;

			case TextField.DECIMAL:
				inputtype = InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_FLAG_SIGNED | InputType.TYPE_NUMBER_FLAG_DECIMAL;
				break;
		}

		if ((constraints & TextField.PASSWORD) != 0 ||
				(constraints & TextField.SENSITIVE) != 0) {
			inputtype = InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD;
		}

		if ((constraints & TextField.UNEDITABLE) != 0) {
			inputtype = InputType.TYPE_NULL;
		}

		if ((constraints & TextField.NON_PREDICTIVE) != 0) {
			inputtype |= InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS;
		}

		if ((constraints & TextField.INITIAL_CAPS_WORD) != 0) {
			inputtype |= InputType.TYPE_TEXT_FLAG_CAP_WORDS;
		}

		if ((constraints & TextField.INITIAL_CAPS_SENTENCE) != 0) {
			inputtype |= InputType.TYPE_TEXT_FLAG_CAP_SENTENCES;
		}

		textview.setInputType(inputtype);
		if ((constraints & TextField.CONSTRAINT_MASK) == TextField.ANY) {
			textview.setSingleLine(false);
		}
	}
}
 
Example 8
Source File: InPlaceEditView.java    From CodenameOne with GNU General Public License v2.0 4 votes vote down vote up
private int getAndroidInputType(int codenameOneInputType, boolean multiline) {
    int type = mInputTypeMap.get(codenameOneInputType, -1);
    if (type == -1) {
        
        if (!multiline && hasConstraint(codenameOneInputType, TextArea.NUMERIC)) {
            type = InputType.TYPE_CLASS_NUMBER;
        } else if (!multiline && hasConstraint(codenameOneInputType, TextArea.DECIMAL)) {
            type = InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_FLAG_DECIMAL | InputType.TYPE_NUMBER_FLAG_SIGNED;
        } else if (!multiline && hasConstraint(codenameOneInputType, TextArea.EMAILADDR)) {
            type = makeNonPredictive(codenameOneInputType, InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_EMAIL_ADDRESS);
            
        } else if (hasConstraint(codenameOneInputType, TextArea.INITIAL_CAPS_SENTENCE)) {
            type = makeNonPredictive(codenameOneInputType, InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_FLAG_CAP_SENTENCES);
            
        } else if (hasConstraint(codenameOneInputType, TextArea.INITIAL_CAPS_WORD)) {
            type = makeNonPredictive(codenameOneInputType, InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_FLAG_CAP_WORDS);

        } else if (!multiline && hasConstraint(codenameOneInputType, TextArea.PASSWORD)) {
            type = InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD;
        } else if (!multiline && hasConstraint(codenameOneInputType, TextArea.PHONENUMBER)) {
            type = makeNonPredictive(codenameOneInputType, InputType.TYPE_CLASS_PHONE);
        } else if (!multiline && hasConstraint(codenameOneInputType, TextArea.URL)) {
            type = makeNonPredictive(codenameOneInputType, InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_URI);
        } else {
            type = makeNonPredictive(codenameOneInputType, InputType.TYPE_CLASS_TEXT);
        }
    }

    // If we're editing standard text, disable auto complete.
    // The name of the flag is a little misleading. From the docs:
    // the text editor is performing auto-completion of the text being entered
    // based on its own semantics, which it will present to the user as they type.
    // This generally means that the input method should not be showing candidates itself,
    // but can expect for the editor to supply its own completions/candidates from
    // InputMethodSession.displayCompletions().
    if ((type & InputType.TYPE_CLASS_TEXT) != 0 && (type & InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS) == 0) {
        type |= InputType.TYPE_TEXT_FLAG_AUTO_COMPLETE;
    }
    if (multiline) {
        type |= InputType.TYPE_TEXT_FLAG_MULTI_LINE;
    }
    return type;
}