Java Code Examples for android.text.InputType#TYPE_TEXT_VARIATION_PASSWORD

The following examples show how to use android.text.InputType#TYPE_TEXT_VARIATION_PASSWORD . 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: GridPasswordView.java    From AndroidFrame with Apache License 2.0 6 votes vote down vote up
private void setCustomAttr(TextView view) {
    if (mTextColor != null)
        view.setTextColor(mTextColor);
    view.setTextSize(mTextSize);

    int inputType = InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_VARIATION_PASSWORD;
    switch (mPasswordType) {

        case 1:
            inputType = InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD;
            break;

        case 2:
            inputType = InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD;
            break;

        case 3:
            inputType = InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_WEB_PASSWORD;
            break;
    }
    view.setInputType(inputType);
    view.setTransformationMethod(mTransformationMethod);
}
 
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: HtmlInput.java    From WiFiAfterConnect with Apache License 2.0 6 votes vote down vote up
public int getAndroidInputType () {
   	if (matchType (HtmlInput.TYPE_PASSWORD))
   		return InputType.TYPE_CLASS_TEXT|InputType.TYPE_TEXT_VARIATION_PASSWORD;
   	else if (matchType (HtmlInput.TYPE_EMAIL))
   		return InputType.TYPE_CLASS_TEXT|InputType.TYPE_TEXT_VARIATION_EMAIL_ADDRESS;
   	else if (matchType (TYPE_TEXT))
   		return InputType.TYPE_CLASS_TEXT;
   	else if (matchType (TYPE_NUMBER))
   		return InputType.TYPE_CLASS_NUMBER;
   	else if (matchType (TYPE_TEL))
   		return InputType.TYPE_CLASS_NUMBER;
   	else if (matchType (TYPE_DATE))
   		return InputType.TYPE_CLASS_DATETIME|InputType.TYPE_DATETIME_VARIATION_DATE;
   	else if (matchType (TYPE_DATETIME) |matchType (TYPE_DATETIME_LOCAL))
   		return InputType.TYPE_CLASS_DATETIME;
   	else if (matchType (TYPE_TIME))
   		return InputType.TYPE_CLASS_DATETIME|InputType.TYPE_DATETIME_VARIATION_TIME;
   	return 0;
}
 
Example 4
Source File: AutoRunCommandListEditText.java    From revolution-irc with GNU General Public License v3.0 6 votes vote down vote up
@Override
protected void onSelectionChanged(int selStart, int selEnd) {
    super.onSelectionChanged(selStart, selEnd);

    if (getLayout() == null)
        return;
    String line = getText().subSequence(getLayout().getLineStart(getLayout()
            .getLineForOffset(selStart)), selEnd).toString();
    boolean isPassword = getPasswordStart(line) != -1;
    boolean wasPassword = (getInputType() & InputType.TYPE_TEXT_VARIATION_PASSWORD) != 0;
    if (isPassword && !wasPassword) {
        Typeface tf = getTypeface();
        setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_FLAG_MULTI_LINE |
                InputType.TYPE_TEXT_VARIATION_PASSWORD | InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD);
        setTypeface(tf);
        setSelection(selStart, selEnd);
    } else if (!isPassword && wasPassword) {
        createPasswordSpans();
        setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_FLAG_MULTI_LINE);
    }
}
 
Example 5
Source File: EditableValue.java    From document-viewer with GNU General Public License v3.0 5 votes vote down vote up
@Override
public Object getValue() {
    if ((this.input.getInputType() & InputType.TYPE_TEXT_VARIATION_PASSWORD) != 0) {
        return new PasswordEditable(this.input.getText());
    }
    return this.input.getText();
}
 
Example 6
Source File: PasswordToggleEndIconDelegate.java    From material-components-android with Apache License 2.0 5 votes vote down vote up
private static boolean isInputTypePassword(EditText editText) {
  return editText != null
      && (editText.getInputType() == InputType.TYPE_NUMBER_VARIATION_PASSWORD
          || editText.getInputType() == InputType.TYPE_TEXT_VARIATION_PASSWORD
          || editText.getInputType() == InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD
          || editText.getInputType() == InputType.TYPE_TEXT_VARIATION_WEB_PASSWORD);
}
 
Example 7
Source File: MaskFormatter.java    From MaskFormatter with Apache License 2.0 5 votes vote down vote up
private int getPasswordMask(EditText maskedField) {
    int inputType = maskedField.getInputType();
    int maskedFieldPasswordMask = (inputType & InputType.TYPE_TEXT_VARIATION_PASSWORD
        | inputType & InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD);

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
        maskedFieldPasswordMask |= inputType & InputType.TYPE_NUMBER_VARIATION_PASSWORD;
        maskedFieldPasswordMask |= inputType & InputType.TYPE_TEXT_VARIATION_WEB_PASSWORD;
    }

    return maskedFieldPasswordMask;
}
 
Example 8
Source File: InputAttributes.java    From Indic-Keyboard with Apache License 2.0 5 votes vote down vote up
private static String toTextVariationString(final int variation) {
    switch (variation) {
    case InputType.TYPE_TEXT_VARIATION_EMAIL_ADDRESS:
        return " TYPE_TEXT_VARIATION_EMAIL_ADDRESS";
    case InputType.TYPE_TEXT_VARIATION_EMAIL_SUBJECT:
        return "TYPE_TEXT_VARIATION_EMAIL_SUBJECT";
    case InputType.TYPE_TEXT_VARIATION_FILTER:
        return "TYPE_TEXT_VARIATION_FILTER";
    case InputType.TYPE_TEXT_VARIATION_LONG_MESSAGE:
        return "TYPE_TEXT_VARIATION_LONG_MESSAGE";
    case InputType.TYPE_TEXT_VARIATION_NORMAL:
        return "TYPE_TEXT_VARIATION_NORMAL";
    case InputType.TYPE_TEXT_VARIATION_PASSWORD:
        return "TYPE_TEXT_VARIATION_PASSWORD";
    case InputType.TYPE_TEXT_VARIATION_PERSON_NAME:
        return "TYPE_TEXT_VARIATION_PERSON_NAME";
    case InputType.TYPE_TEXT_VARIATION_PHONETIC:
        return "TYPE_TEXT_VARIATION_PHONETIC";
    case InputType.TYPE_TEXT_VARIATION_POSTAL_ADDRESS:
        return "TYPE_TEXT_VARIATION_POSTAL_ADDRESS";
    case InputType.TYPE_TEXT_VARIATION_SHORT_MESSAGE:
        return "TYPE_TEXT_VARIATION_SHORT_MESSAGE";
    case InputType.TYPE_TEXT_VARIATION_URI:
        return "TYPE_TEXT_VARIATION_URI";
    case InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD:
        return "TYPE_TEXT_VARIATION_VISIBLE_PASSWORD";
    case InputType.TYPE_TEXT_VARIATION_WEB_EDIT_TEXT:
        return "TYPE_TEXT_VARIATION_WEB_EDIT_TEXT";
    case InputType.TYPE_TEXT_VARIATION_WEB_EMAIL_ADDRESS:
        return "TYPE_TEXT_VARIATION_WEB_EMAIL_ADDRESS";
    case InputType.TYPE_TEXT_VARIATION_WEB_PASSWORD:
        return "TYPE_TEXT_VARIATION_WEB_PASSWORD";
    default:
        return String.format("unknownVariation<0x%08x>", variation);
    }
}
 
Example 9
Source File: AbstractEditComponent.java    From weex-uikit with MIT License 5 votes vote down vote up
private int getInputType(String type) {
  int inputType;
  switch (type) {
    case Constants.Value.TEXT:
      inputType = InputType.TYPE_CLASS_TEXT;
      break;
    case Constants.Value.DATE:
      inputType = InputType.TYPE_NULL;
      getHostView().setFocusable(false);
      break;
    case Constants.Value.DATETIME:
      inputType = InputType.TYPE_CLASS_DATETIME;
      break;
    case Constants.Value.EMAIL:
      inputType = InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_EMAIL_ADDRESS;
      break;
    case Constants.Value.PASSWORD:
      inputType = InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD;
      getHostView().setTransformationMethod(PasswordTransformationMethod.getInstance());
      break;
    case Constants.Value.TEL:
      inputType = InputType.TYPE_CLASS_PHONE;
      break;
    case Constants.Value.TIME:
      inputType = InputType.TYPE_NULL;
      getHostView().setFocusable(false);
      break;
    case Constants.Value.URL:
      inputType = InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_URI;
      break;
    default:
      inputType = InputType.TYPE_CLASS_TEXT;
  }
  return inputType;
}
 
Example 10
Source File: CopyTextItem.java    From passman-android with GNU General Public License v3.0 5 votes vote down vote up
@OnClick(R.id.copy_btn_toggle_visible)
public void toggleVisibility() {
    switch (text.getInputType()) {
        case InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD:
            text.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD);
            toggle.setImageDrawable(getResources().getDrawable(R.drawable.ic_eye_off_grey));
            break;
        case InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD:
            text.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD);
            toggle.setImageDrawable(getResources().getDrawable(R.drawable.ic_eye_grey));
            break;
    }
}
 
Example 11
Source File: PasswordEntryActivity.java    From spark-setup-android with Apache License 2.0 5 votes vote down vote up
private void togglePasswordVisibility(boolean showPassword) {
    int inputType;
    if (showPassword) {
        inputType = InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD;
    } else {
        inputType = InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD;
    }
    passwordBox.setInputType(inputType);
}
 
Example 12
Source File: InputAttributes.java    From openboard with GNU General Public License v3.0 5 votes vote down vote up
private static String toTextVariationString(final int variation) {
    switch (variation) {
    case InputType.TYPE_TEXT_VARIATION_EMAIL_ADDRESS:
        return " TYPE_TEXT_VARIATION_EMAIL_ADDRESS";
    case InputType.TYPE_TEXT_VARIATION_EMAIL_SUBJECT:
        return "TYPE_TEXT_VARIATION_EMAIL_SUBJECT";
    case InputType.TYPE_TEXT_VARIATION_FILTER:
        return "TYPE_TEXT_VARIATION_FILTER";
    case InputType.TYPE_TEXT_VARIATION_LONG_MESSAGE:
        return "TYPE_TEXT_VARIATION_LONG_MESSAGE";
    case InputType.TYPE_TEXT_VARIATION_NORMAL:
        return "TYPE_TEXT_VARIATION_NORMAL";
    case InputType.TYPE_TEXT_VARIATION_PASSWORD:
        return "TYPE_TEXT_VARIATION_PASSWORD";
    case InputType.TYPE_TEXT_VARIATION_PERSON_NAME:
        return "TYPE_TEXT_VARIATION_PERSON_NAME";
    case InputType.TYPE_TEXT_VARIATION_PHONETIC:
        return "TYPE_TEXT_VARIATION_PHONETIC";
    case InputType.TYPE_TEXT_VARIATION_POSTAL_ADDRESS:
        return "TYPE_TEXT_VARIATION_POSTAL_ADDRESS";
    case InputType.TYPE_TEXT_VARIATION_SHORT_MESSAGE:
        return "TYPE_TEXT_VARIATION_SHORT_MESSAGE";
    case InputType.TYPE_TEXT_VARIATION_URI:
        return "TYPE_TEXT_VARIATION_URI";
    case InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD:
        return "TYPE_TEXT_VARIATION_VISIBLE_PASSWORD";
    case InputType.TYPE_TEXT_VARIATION_WEB_EDIT_TEXT:
        return "TYPE_TEXT_VARIATION_WEB_EDIT_TEXT";
    case InputType.TYPE_TEXT_VARIATION_WEB_EMAIL_ADDRESS:
        return "TYPE_TEXT_VARIATION_WEB_EMAIL_ADDRESS";
    case InputType.TYPE_TEXT_VARIATION_WEB_PASSWORD:
        return "TYPE_TEXT_VARIATION_WEB_PASSWORD";
    default:
        return String.format("unknownVariation<0x%08x>", variation);
    }
}
 
Example 13
Source File: InputAttributes.java    From openboard with GNU General Public License v3.0 4 votes vote down vote up
public InputAttributes(final EditorInfo editorInfo, final boolean isFullscreenMode,
        final String packageNameForPrivateImeOptions) {
    mEditorInfo = editorInfo;
    mPackageNameForPrivateImeOptions = packageNameForPrivateImeOptions;
    mTargetApplicationPackageName = null != editorInfo ? editorInfo.packageName : null;
    final int inputType = null != editorInfo ? editorInfo.inputType : 0;
    final int inputClass = inputType & InputType.TYPE_MASK_CLASS;
    mInputType = inputType;
    mIsPasswordField = InputTypeUtils.isPasswordInputType(inputType)
            || InputTypeUtils.isVisiblePasswordInputType(inputType);
    if (inputClass != InputType.TYPE_CLASS_TEXT) {
        // If we are not looking at a TYPE_CLASS_TEXT field, the following strange
        // cases may arise, so we do a couple sanity checks for them. If it's a
        // TYPE_CLASS_TEXT field, these special cases cannot happen, by construction
        // of the flags.
        if (null == editorInfo) {
            Log.w(TAG, "No editor info for this field. Bug?");
        } else if (InputType.TYPE_NULL == inputType) {
            // TODO: We should honor TYPE_NULL specification.
            Log.i(TAG, "InputType.TYPE_NULL is specified");
        } else if (inputClass == 0) {
            // TODO: is this check still necessary?
            Log.w(TAG, String.format("Unexpected input class: inputType=0x%08x"
                    + " imeOptions=0x%08x", inputType, editorInfo.imeOptions));
        }
        mShouldShowSuggestions = false;
        mInputTypeNoAutoCorrect = false;
        mApplicationSpecifiedCompletionOn = false;
        mShouldInsertSpacesAutomatically = false;
        mShouldShowVoiceInputKey = false;
        mDisableGestureFloatingPreviewText = false;
        mIsGeneralTextInput = false;
        mNoLearning = false;
        return;
    }
    // inputClass == InputType.TYPE_CLASS_TEXT
    final int variation = inputType & InputType.TYPE_MASK_VARIATION;
    final boolean flagNoSuggestions =
            0 != (inputType & InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS);
    final boolean flagMultiLine =
            0 != (inputType & InputType.TYPE_TEXT_FLAG_MULTI_LINE);
    final boolean flagAutoCorrect =
            0 != (inputType & InputType.TYPE_TEXT_FLAG_AUTO_CORRECT);
    final boolean flagAutoComplete =
            0 != (inputType & InputType.TYPE_TEXT_FLAG_AUTO_COMPLETE);

    // TODO: Have a helper method in InputTypeUtils
    // Make sure that passwords are not displayed in {@link SuggestionStripView}.
    final boolean shouldSuppressSuggestions = mIsPasswordField
            || InputTypeUtils.isEmailVariation(variation)
            || InputType.TYPE_TEXT_VARIATION_URI == variation
            || InputType.TYPE_TEXT_VARIATION_FILTER == variation
            //|| flagNoSuggestions
            || flagAutoComplete;
    mShouldShowSuggestions = !shouldSuppressSuggestions;

    mShouldInsertSpacesAutomatically = InputTypeUtils.isAutoSpaceFriendlyType(inputType);

    final boolean noMicrophone = mIsPasswordField
            || InputTypeUtils.isEmailVariation(variation)
            || InputType.TYPE_TEXT_VARIATION_URI == variation
            || hasNoMicrophoneKeyOption();
    mShouldShowVoiceInputKey = !noMicrophone;

    mDisableGestureFloatingPreviewText = InputAttributes.inPrivateImeOptions(
            mPackageNameForPrivateImeOptions, NO_FLOATING_GESTURE_PREVIEW, editorInfo);

    // If it's a browser edit field and auto correct is not ON explicitly, then
    // disable auto correction, but keep suggestions on.
    // If NO_SUGGESTIONS is set, don't do prediction.
    // If it's not multiline and the autoCorrect flag is not set, then don't correct
    mInputTypeNoAutoCorrect =
            (variation == InputType.TYPE_TEXT_VARIATION_WEB_EDIT_TEXT && !flagAutoCorrect)
            || flagNoSuggestions
            || (!flagAutoCorrect && !flagMultiLine);

    mApplicationSpecifiedCompletionOn = flagAutoComplete && isFullscreenMode;

    // If we come here, inputClass is always TYPE_CLASS_TEXT
    mIsGeneralTextInput = InputType.TYPE_TEXT_VARIATION_EMAIL_ADDRESS != variation
            && InputType.TYPE_TEXT_VARIATION_PASSWORD != variation
            && InputType.TYPE_TEXT_VARIATION_PHONETIC != variation
            && InputType.TYPE_TEXT_VARIATION_URI != variation
            && InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD != variation
            && InputType.TYPE_TEXT_VARIATION_WEB_EMAIL_ADDRESS != variation
            && InputType.TYPE_TEXT_VARIATION_WEB_PASSWORD != variation;

    mNoLearning = (editorInfo.imeOptions & EditorInfo.IME_FLAG_NO_PERSONALIZED_LEARNING) != 0;
}
 
Example 14
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 15
Source File: InputAttributes.java    From AOSP-Kayboard-7.1.2 with Apache License 2.0 4 votes vote down vote up
public InputAttributes(final EditorInfo editorInfo, final boolean isFullscreenMode,
        final String packageNameForPrivateImeOptions) {
    mEditorInfo = editorInfo;
    mPackageNameForPrivateImeOptions = packageNameForPrivateImeOptions;
    mTargetApplicationPackageName = null != editorInfo ? editorInfo.packageName : null;
    final int inputType = null != editorInfo ? editorInfo.inputType : 0;
    final int inputClass = inputType & InputType.TYPE_MASK_CLASS;
    mInputType = inputType;
    mIsPasswordField = InputTypeUtils.isPasswordInputType(inputType)
            || InputTypeUtils.isVisiblePasswordInputType(inputType);
    if (inputClass != InputType.TYPE_CLASS_TEXT) {
        // If we are not looking at a TYPE_CLASS_TEXT field, the following strange
        // cases may arise, so we do a couple sanity checks for them. If it's a
        // TYPE_CLASS_TEXT field, these special cases cannot happen, by construction
        // of the flags.
        if (null == editorInfo) {
            Log.w(TAG, "No editor info for this field. Bug?");
        } else if (InputType.TYPE_NULL == inputType) {
            // TODO: We should honor TYPE_NULL specification.
            Log.i(TAG, "InputType.TYPE_NULL is specified");
        } else if (inputClass == 0) {
            // TODO: is this check still necessary?
            Log.w(TAG, String.format("Unexpected input class: inputType=0x%08x"
                    + " imeOptions=0x%08x", inputType, editorInfo.imeOptions));
        }
        mShouldShowSuggestions = false;
        mInputTypeNoAutoCorrect = false;
        mApplicationSpecifiedCompletionOn = false;
        mShouldInsertSpacesAutomatically = false;
        mShouldShowVoiceInputKey = false;
        mDisableGestureFloatingPreviewText = false;
        mIsGeneralTextInput = false;
        return;
    }
    // inputClass == InputType.TYPE_CLASS_TEXT
    final int variation = inputType & InputType.TYPE_MASK_VARIATION;
    final boolean flagNoSuggestions =
            0 != (inputType & InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS);
    final boolean flagMultiLine =
            0 != (inputType & InputType.TYPE_TEXT_FLAG_MULTI_LINE);
    final boolean flagAutoCorrect =
            0 != (inputType & InputType.TYPE_TEXT_FLAG_AUTO_CORRECT);
    final boolean flagAutoComplete =
            0 != (inputType & InputType.TYPE_TEXT_FLAG_AUTO_COMPLETE);

    // TODO: Have a helper method in InputTypeUtils
    // Make sure that passwords are not displayed in {@link SuggestionStripView}.
    final boolean shouldSuppressSuggestions = mIsPasswordField
            || InputTypeUtils.isEmailVariation(variation)
            || InputType.TYPE_TEXT_VARIATION_URI == variation
            || InputType.TYPE_TEXT_VARIATION_FILTER == variation
            || flagNoSuggestions
            || flagAutoComplete;
    mShouldShowSuggestions = !shouldSuppressSuggestions;

    mShouldInsertSpacesAutomatically = InputTypeUtils.isAutoSpaceFriendlyType(inputType);

    final boolean noMicrophone = mIsPasswordField
            || InputTypeUtils.isEmailVariation(variation)
            || InputType.TYPE_TEXT_VARIATION_URI == variation
            || hasNoMicrophoneKeyOption();
    mShouldShowVoiceInputKey = !noMicrophone;

    mDisableGestureFloatingPreviewText = InputAttributes.inPrivateImeOptions(
            mPackageNameForPrivateImeOptions, NO_FLOATING_GESTURE_PREVIEW, editorInfo);

    // If it's a browser edit field and auto correct is not ON explicitly, then
    // disable auto correction, but keep suggestions on.
    // If NO_SUGGESTIONS is set, don't do prediction.
    // If it's not multiline and the autoCorrect flag is not set, then don't correct
    mInputTypeNoAutoCorrect =
            (variation == InputType.TYPE_TEXT_VARIATION_WEB_EDIT_TEXT && !flagAutoCorrect)
            || flagNoSuggestions
            || (!flagAutoCorrect && !flagMultiLine);

    mApplicationSpecifiedCompletionOn = flagAutoComplete && isFullscreenMode;

    // If we come here, inputClass is always TYPE_CLASS_TEXT
    mIsGeneralTextInput = InputType.TYPE_TEXT_VARIATION_EMAIL_ADDRESS != variation
            && InputType.TYPE_TEXT_VARIATION_PASSWORD != variation
            && InputType.TYPE_TEXT_VARIATION_PHONETIC != variation
            && InputType.TYPE_TEXT_VARIATION_URI != variation
            && InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD != variation
            && InputType.TYPE_TEXT_VARIATION_WEB_EMAIL_ADDRESS != variation
            && InputType.TYPE_TEXT_VARIATION_WEB_PASSWORD != variation;
}
 
Example 16
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 17
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;
}
 
Example 18
Source File: InputAttributes.java    From Indic-Keyboard with Apache License 2.0 4 votes vote down vote up
public InputAttributes(final EditorInfo editorInfo, final boolean isFullscreenMode,
        final String packageNameForPrivateImeOptions) {
    mEditorInfo = editorInfo;
    mPackageNameForPrivateImeOptions = packageNameForPrivateImeOptions;
    mTargetApplicationPackageName = null != editorInfo ? editorInfo.packageName : null;
    final int inputType = null != editorInfo ? editorInfo.inputType : 0;
    final int inputClass = inputType & InputType.TYPE_MASK_CLASS;
    mInputType = inputType;
    mIsPasswordField = InputTypeUtils.isPasswordInputType(inputType)
            || InputTypeUtils.isVisiblePasswordInputType(inputType);
    if (inputClass != InputType.TYPE_CLASS_TEXT) {
        // If we are not looking at a TYPE_CLASS_TEXT field, the following strange
        // cases may arise, so we do a couple sanity checks for them. If it's a
        // TYPE_CLASS_TEXT field, these special cases cannot happen, by construction
        // of the flags.
        if (null == editorInfo) {
            Log.w(TAG, "No editor info for this field. Bug?");
        } else if (InputType.TYPE_NULL == inputType) {
            // TODO: We should honor TYPE_NULL specification.
            Log.i(TAG, "InputType.TYPE_NULL is specified");
        } else if (inputClass == 0) {
            // TODO: is this check still necessary?
            Log.w(TAG, String.format("Unexpected input class: inputType=0x%08x"
                    + " imeOptions=0x%08x", inputType, editorInfo.imeOptions));
        }
        mShouldShowSuggestions = false;
        mInputTypeNoAutoCorrect = false;
        mApplicationSpecifiedCompletionOn = false;
        mShouldInsertSpacesAutomatically = false;
        mShouldShowVoiceInputKey = false;
        mDisableGestureFloatingPreviewText = false;
        mIsGeneralTextInput = false;
        mNoLearning = false;
        return;
    }
    // inputClass == InputType.TYPE_CLASS_TEXT
    final int variation = inputType & InputType.TYPE_MASK_VARIATION;
    final boolean flagNoSuggestions =
            0 != (inputType & InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS);
    final boolean flagMultiLine =
            0 != (inputType & InputType.TYPE_TEXT_FLAG_MULTI_LINE);
    final boolean flagAutoCorrect =
            0 != (inputType & InputType.TYPE_TEXT_FLAG_AUTO_CORRECT);
    final boolean flagAutoComplete =
            0 != (inputType & InputType.TYPE_TEXT_FLAG_AUTO_COMPLETE);

    // TODO: Have a helper method in InputTypeUtils
    // Make sure that passwords are not displayed in {@link SuggestionStripView}.
    final boolean shouldSuppressSuggestions = mIsPasswordField
            || InputTypeUtils.isEmailVariation(variation)
            || InputType.TYPE_TEXT_VARIATION_URI == variation
            || InputType.TYPE_TEXT_VARIATION_FILTER == variation
            || flagNoSuggestions
            || flagAutoComplete;
    mShouldShowSuggestions = !shouldSuppressSuggestions;

    mShouldInsertSpacesAutomatically = InputTypeUtils.isAutoSpaceFriendlyType(inputType);

    final boolean noMicrophone = mIsPasswordField
            || InputTypeUtils.isEmailVariation(variation)
            || InputType.TYPE_TEXT_VARIATION_URI == variation
            || hasNoMicrophoneKeyOption();
    mShouldShowVoiceInputKey = !noMicrophone;

    mDisableGestureFloatingPreviewText = InputAttributes.inPrivateImeOptions(
            mPackageNameForPrivateImeOptions, NO_FLOATING_GESTURE_PREVIEW, editorInfo);

    // If it's a browser edit field and auto correct is not ON explicitly, then
    // disable auto correction, but keep suggestions on.
    // If NO_SUGGESTIONS is set, don't do prediction.
    // If it's not multiline and the autoCorrect flag is not set, then don't correct
    mInputTypeNoAutoCorrect =
            (variation == InputType.TYPE_TEXT_VARIATION_WEB_EDIT_TEXT && !flagAutoCorrect)
            || flagNoSuggestions
            || (!flagAutoCorrect && !flagMultiLine);

    mApplicationSpecifiedCompletionOn = flagAutoComplete && isFullscreenMode;

    // If we come here, inputClass is always TYPE_CLASS_TEXT
    mIsGeneralTextInput = InputType.TYPE_TEXT_VARIATION_EMAIL_ADDRESS != variation
            && InputType.TYPE_TEXT_VARIATION_PASSWORD != variation
            && InputType.TYPE_TEXT_VARIATION_PHONETIC != variation
            && InputType.TYPE_TEXT_VARIATION_URI != variation
            && InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD != variation
            && InputType.TYPE_TEXT_VARIATION_WEB_EMAIL_ADDRESS != variation
            && InputType.TYPE_TEXT_VARIATION_WEB_PASSWORD != variation;

    mNoLearning = (editorInfo.imeOptions & EditorInfo.IME_FLAG_NO_PERSONALIZED_LEARNING) != 0;
}
 
Example 19
Source File: SettingsActivity.java    From mockgeofix with Apache License 2.0 4 votes vote down vote up
@Override
public boolean onPreferenceChange(Preference pref, Object value) {
    String stringValue = value.toString();

    /* validation */
    if (pref.getKey().equals("listen_port")) {
        try {
            int port = Integer.parseInt(stringValue);
            if (port < 0 || port > 65535) {
                throw new NumberFormatException("Invalid port number.");
            }
        } catch (NumberFormatException ex) {
            Log.i(TAG, String.format("Invalid port number %s. Not Changing.",stringValue) );
            Toast.makeText(this, R.string.invalid_port, Toast.LENGTH_LONG).show();
            return false;
        }
    }

    /* set summary in the views*/
    if (pref.getKey().equals("require_password")) {
        Boolean boolValue = (Boolean)value;
        if (boolValue == Boolean.FALSE) {
            pref.setSummary("");
        } else {
            pref.setSummary(getResources().getString(R.string.require_password_summary));
        }
    } else if (pref instanceof  ListPreference) {
        ListPreference listPreference = (ListPreference) pref;
        int index = listPreference.findIndexOfValue(stringValue);

        // Set the summary to reflect the new value.
        pref.setSummary(
                index >= 0
                        ? listPreference.getEntries()[index]
                        : null);
    } else if (pref instanceof EditTextPreference) {
        EditTextPreference textPreference = (EditTextPreference) pref;
        if ( (textPreference.getEditText().getInputType() & InputType.TYPE_TEXT_VARIATION_PASSWORD)
                == InputType.TYPE_TEXT_VARIATION_PASSWORD ) {
            pref.setSummary( stringValue.replaceAll(".","*") );
        } else {
            pref.setSummary(stringValue);
        }
    }

    /* Warn the user that the change won't take effect until the service is restarted */
    if (pref.getKey().equals("listen_port") || pref.getKey().equals("listen_ip")
            || pref.getKey().equals("foreground_service") || pref.getKey().equals("oom_adj")) {
        if ( ! mInitialBinding && (mService != null && mService.isRunning()) ) {
            Toast.makeText(getApplicationContext(), getString(R.string.note_needsreset),
                    Toast.LENGTH_LONG).show();
        }
    }

    return true;
}
 
Example 20
Source File: EditTextController.java    From NexusDialog with Apache License 2.0 2 votes vote down vote up
/**
 * Indicates whether this text field hides the input text for security reasons.
 *
 * @return  true if this text field hides the input text, or false otherwise
 */
public boolean isSecureEntry() {
    return (inputType | InputType.TYPE_TEXT_VARIATION_PASSWORD) != 0;
}