static void setParams()

in litho-widget/src/main/java/com/facebook/litho/widget/TextInputSpec.java [416:549]


  static void setParams(
      EditText editText,
      @Nullable CharSequence hint,
      @Nullable Drawable background,
      float shadowRadius,
      float shadowDx,
      float shadowDy,
      int shadowColor,
      ColorStateList textColorStateList,
      ColorStateList hintColorStateList,
      Integer highlightColor,
      int textSize,
      Typeface typeface,
      int textAlignment,
      int gravity,
      boolean editable,
      int inputType,
      int rawInputType,
      @Nullable KeyListener keyListener,
      int imeOptions,
      @Nullable List<InputFilter> inputFilters,
      boolean multiline,
      @Nullable TextUtils.TruncateAt ellipsize,
      int minLines,
      int maxLines,
      int cursorDrawableRes,
      MovementMethod movementMethod,
      @Nullable CharSequence text,
      @Nullable CharSequence error,
      @Nullable Drawable errorDrawable,
      boolean isForMeasure) {

    if (textSize == TextSpec.UNSET) {
      editText.setTextSize(TypedValue.COMPLEX_UNIT_SP, TextSpec.DEFAULT_TEXT_SIZE_SP);
    } else {
      editText.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize);
    }

    if (multiline) {
      inputType |= EditorInfo.TYPE_CLASS_TEXT | EditorInfo.TYPE_TEXT_FLAG_MULTI_LINE;
      editText.setMinLines(minLines);
      editText.setMaxLines(maxLines);
    } else {
      inputType &= ~EditorInfo.TYPE_TEXT_FLAG_MULTI_LINE;
      editText.setLines(1);
    }

    if (!editable) {
      inputType = EditorInfo.TYPE_NULL;
    }

    if (rawInputType != EditorInfo.TYPE_NULL) {
      editText.setRawInputType(rawInputType);
    } else {
      // Only set inputType if rawInputType is not specified.
      setInputTypeAndKeyListenerIfChanged(editText, inputType, keyListener);
    }

    // Needs to be set before the text so it would apply to the current text
    if (inputFilters != null) {
      editText.setFilters(inputFilters.toArray(new InputFilter[inputFilters.size()]));
    } else {
      editText.setFilters(NO_FILTERS);
    }
    editText.setHint(hint);

    if (SDK_INT < JELLY_BEAN) {
      editText.setBackgroundDrawable(background);
    } else {
      editText.setBackground(background);
    }
    // From the docs for setBackground:
    // "If the background has padding, this View's padding is set to the background's padding.
    // However, when a background is removed, this View's padding isn't touched. If setting the
    // padding is desired, please use setPadding."
    if (background == null || !background.getPadding(sBackgroundPaddingRect)) {
      editText.setPadding(0, 0, 0, 0);
    }
    editText.setShadowLayer(shadowRadius, shadowDx, shadowDy, shadowColor);
    editText.setTypeface(typeface, 0);
    editText.setGravity(gravity);
    editText.setImeOptions(imeOptions);
    editText.setFocusable(editable);
    editText.setFocusableInTouchMode(editable);
    editText.setLongClickable(editable);
    editText.setCursorVisible(editable);
    editText.setTextColor(textColorStateList);
    editText.setHintTextColor(hintColorStateList);
    if (highlightColor != null) {
      editText.setHighlightColor(highlightColor);
    }
    editText.setMovementMethod(movementMethod);

    /**
     * Sets error state on the TextInput, which shows an error icon provided by errorDrawable and an
     * error message
     *
     * @param error Message that will be shown when error is not null and text input is in focused
     *     state
     * @param errorDrawable icon that signals an existing error and anchors a popover showing the
     *     errorMessage when component is focused.
     */
    editText.setError(error, errorDrawable);

    if (cursorDrawableRes != -1) {
      if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
        editText.setTextCursorDrawable(cursorDrawableRes);
      } else {
        try {
          // Uses reflection because there is no public API to change cursor color programmatically.
          // Based on
          // http://stackoverflow.com/questions/25996032/how-to-change-programatically-edittext-cursor-color-in-android.
          Field f = TextView.class.getDeclaredField("mCursorDrawableRes");
          f.setAccessible(true);
          f.set(editText, cursorDrawableRes);
        } catch (Exception exception) {
          // no-op don't set cursor drawable
        }
      }
    }

    editText.setEllipsize(ellipsize);
    if (SDK_INT >= JELLY_BEAN_MR1) {
      editText.setTextAlignment(textAlignment);
    }
    if (text != null && !ObjectsCompat.equals(editText.getText().toString(), text.toString())) {
      editText.setText(text);
      // Set the selection only when mounting because #setSelection does not affect measurement,
      // but it can mutate the span during measurement, potentially causing crashes.
      if (!isForMeasure) {
        editText.setSelection(editText.getText().toString().length());
      }
    }
  }