Search code examples
delphifiremonkeydelphi-10-seattle

firemonkey - How to start mobile Keyboard in lower case letter?


At my application, there's a text field where the user will type their account e-mail.

With Java I can easily make the Android keyboard start with a lower-case letter by using

EditText text = new EditText(context);
text.setInputType(android.text.InputType.TYPE_CLASS_TEXT | android.text.InputType.TYPE_TEXT_FLAG_MULTI_LINE);

How is it possible to achieve the same with Delphi 10 Seattle?


Solution

  • I guess there is no easy way to make accurate settings like yours currently. Delphi and java vk types mapping is implemented inside fmx.dex.jar library, embedded by default with every FMX Android project.

    But for current purposes you can just set KeyboardType to EmailAddress, which will be converted to TYPE_CLASS_TEXT | TYPE_TEXT_VARIATION_EMAIL_ADDRESS combination. And this will be the best decision for Android.

    Here are all the mappings.

    On Android there is the following mapping between TVirtualKeyboardType values and TJFMXTextEditorProxy.JavaClass constants (see FMX.Platform.Android):

      case VirtKBControl.KeyboardType of
        TVirtualKeyboardType.Default:
          KbType := TJFMXTextEditorProxy.JavaClass.INPUT_TEXT;
        TVirtualKeyboardType.NumbersAndPunctuation:
          KbType := TJFMXTextEditorProxy.JavaClass.INPUT_NUMBER_AND_PUNCTUATION;
        TVirtualKeyboardType.NumberPad:
          KbType := TJFMXTextEditorProxy.JavaClass.INPUT_NUMBER;
        TVirtualKeyboardType.PhonePad:
          KbType := TJFMXTextEditorProxy.JavaClass.INPUT_PHONE;
        TVirtualKeyboardType.Alphabet:
          KbType := TJFMXTextEditorProxy.JavaClass.INPUT_ALPHABET;
        TVirtualKeyboardType.URL:
          KbType := TJFMXTextEditorProxy.JavaClass.INPUT_URL;
        TVirtualKeyboardType.NamePhonePad:
          KbType := TJFMXTextEditorProxy.JavaClass.INPUT_NAME_PHONE_PAD;
        TVirtualKeyboardType.EmailAddress:
          KbType := TJFMXTextEditorProxy.JavaClass.INPUT_EMAIL_ADDRESS;
      end;
    

    Mapping between TJFMXTextEditorProxy.JavaClass constants and android.text.InputType is the following (it's in fmx.dex.jar):

    switch (mInputType) {
    case INPUT_NUMBER:
        outAttrs.inputType = InputType.TYPE_CLASS_NUMBER;
        break;
    case INPUT_NUMBER_AND_PUNCTUATION:
        outAttrs.inputType = InputType.TYPE_CLASS_TEXT;
        break;
    case INPUT_PHONE:
        outAttrs.inputType = InputType.TYPE_CLASS_PHONE;
        break;
    case INPUT_ALPHABET:
        outAttrs.inputType = InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS;
        if (!mPassword)
            outAttrs.inputType |= InputType.TYPE_TEXT_FLAG_CAP_SENTENCES;
        break;
    case INPUT_URL:
        outAttrs.inputType = InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_URI;
        break;
    case INPUT_NAME_PHONE_PAD:
        outAttrs.inputType = InputType.TYPE_CLASS_PHONE;
        if (!mPassword)
            outAttrs.inputType |= InputType.TYPE_TEXT_FLAG_CAP_SENTENCES;
        break;
    case INPUT_EMAIL_ADDRESS:
        outAttrs.inputType = InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_EMAIL_ADDRESS;
        break;
    case INPUT_TEXT:
    default:
        outAttrs.inputType = InputType.TYPE_CLASS_TEXT;
        if (!mPassword)
            outAttrs.inputType |= InputType.TYPE_TEXT_FLAG_CAP_SENTENCES;
        break;          
    }
    
    if (mPassword)
    {
        if ((outAttrs.inputType & InputType.TYPE_CLASS_NUMBER) == InputType.TYPE_CLASS_NUMBER)
            outAttrs.inputType |= InputType.TYPE_NUMBER_VARIATION_PASSWORD;
        else
            outAttrs.inputType |= InputType.TYPE_TEXT_VARIATION_PASSWORD;
    }