Java Code Examples for com.facebook.litho.annotations.ResType#STRING

The following examples show how to use com.facebook.litho.annotations.ResType#STRING . 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: TextSpec.java    From litho with Apache License 2.0 6 votes vote down vote up
@OnPopulateAccessibilityNode
static void onPopulateAccessibilityNode(
    View host,
    AccessibilityNodeInfoCompat node,
    @Prop(resType = ResType.STRING) CharSequence text,
    @Prop(optional = true, resType = ResType.BOOL) boolean isSingleLine) {
  if (ViewCompat.getImportantForAccessibility(host)
      == ViewCompat.IMPORTANT_FOR_ACCESSIBILITY_AUTO) {
    ViewCompat.setImportantForAccessibility(host, ViewCompat.IMPORTANT_FOR_ACCESSIBILITY_YES);
  }
  CharSequence contentDescription = node.getContentDescription();
  node.setText(contentDescription != null ? contentDescription : text);
  node.setContentDescription(contentDescription != null ? contentDescription : text);

  node.addAction(AccessibilityNodeInfoCompat.ACTION_NEXT_AT_MOVEMENT_GRANULARITY);
  node.addAction(AccessibilityNodeInfoCompat.ACTION_PREVIOUS_AT_MOVEMENT_GRANULARITY);
  node.setMovementGranularities(
      AccessibilityNodeInfoCompat.MOVEMENT_GRANULARITY_CHARACTER
          | AccessibilityNodeInfoCompat.MOVEMENT_GRANULARITY_WORD
          | AccessibilityNodeInfoCompat.MOVEMENT_GRANULARITY_PARAGRAPH);

  if (!isSingleLine) {
    node.setMultiLine(true);
  }
}
 
Example 2
Source File: TestLayoutSpec.java    From litho with Apache License 2.0 6 votes vote down vote up
@OnCreateLayout
static <S extends View> Component onCreateLayout(
    ComponentContext context,
    @Prop @Nullable Object prop3,
    @Prop char[] prop4,
    @Prop EventHandler<ClickEvent> handler,
    @Prop Component child,
    @Prop(optional = true) boolean prop2,
    @Prop(resType = ResType.STRING, optional = true, varArg = "name") List<String> names,
    @State(canUpdateLazily = true) long state1,
    @State S state2,
    @State int state3,
    @TreeProp TestTreeProp treeProp,
    @CachedValue int cached) {
  return null;
}
 
Example 3
Source File: TextSpec.java    From litho with Apache License 2.0 5 votes vote down vote up
@OnUnmount
static void onUnmount(
    ComponentContext c,
    TextDrawable textDrawable,
    @Prop(resType = ResType.STRING) CharSequence text) {
  textDrawable.unmount();

  if (text instanceof MountableCharSequence) {
    ((MountableCharSequence) text).onUnmount(textDrawable);
  }
}
 
Example 4
Source File: TextSpec.java    From litho with Apache License 2.0 5 votes vote down vote up
@GetExtraAccessibilityNodeAt
static int getExtraAccessibilityNodeAt(
    int x,
    int y,
    @Prop(resType = ResType.STRING) CharSequence text,
    @FromBoundsDefined Layout textLayout,
    @FromBoundsDefined ClickableSpan[] clickableSpans) {
  if (!(text instanceof Spanned)) {
    return INVALID_ID;
  }

  final Spanned spanned = (Spanned) text;

  for (int i = 0; i < clickableSpans.length; i++) {
    final ClickableSpan span = clickableSpans[i];
    final int start = spanned.getSpanStart(span);
    final int end = spanned.getSpanEnd(span);

    textLayout.getSelectionPath(start, end, sTempPath);
    sTempPath.computeBounds(sTempRectF, /* unused */ true);

    if (sTempRectF.contains(x, y)) {
      return i;
    }
  }

  return INVALID_ID;
}
 
Example 5
Source File: TextInputSpec.java    From litho with Apache License 2.0 5 votes vote down vote up
@OnCreateInitialState
static void onCreateInitialState(
    final ComponentContext c,
    StateValue<AtomicReference<EditTextWithEventHandlers>> mountedView,
    StateValue<AtomicReference<CharSequence>> savedText,
    StateValue<Integer> measureSeqNumber,
    @Prop(optional = true, resType = ResType.STRING) CharSequence initialText) {
  mountedView.set(new AtomicReference<EditTextWithEventHandlers>());
  measureSeqNumber.set(0);
  savedText.set(new AtomicReference<>(initialText));
}
 
Example 6
Source File: FullGroupSectionSpec.java    From litho with Apache License 2.0 5 votes vote down vote up
@OnCreateChildren
protected static <T> Children onCreateChildren(
    SectionContext c,
    @Prop Component prop3,
    @Prop(resType = ResType.STRING) String prop4,
    @Prop Section prop5,
    @State T state1) {
  return null;
}
 
Example 7
Source File: TextSpec.java    From litho with Apache License 2.0 4 votes vote down vote up
@OnPopulateExtraAccessibilityNode
static void onPopulateExtraAccessibilityNode(
    AccessibilityNodeInfoCompat node,
    int extraNodeIndex,
    int componentBoundsLeft,
    int componentBoundsTop,
    @Prop(resType = ResType.STRING) CharSequence text,
    @FromBoundsDefined Layout textLayout,
    @FromBoundsDefined ClickableSpan[] clickableSpans) {
  if (!(text instanceof Spanned)) {
    return;
  }

  final Spanned spanned = (Spanned) text;

  final ClickableSpan span = clickableSpans[extraNodeIndex];
  final int start = spanned.getSpanStart(span);
  final int end = spanned.getSpanEnd(span);
  final int startLine = textLayout.getLineForOffset(start);
  final int endLine = textLayout.getLineForOffset(end);

  // The bounds for multi-line strings should *only* include the first line.  This is because
  // Talkback triggers its click at the center point of these bounds, and if that center point
  // is outside the spannable, it will click on something else.  There is no harm in not outlining
  // the wrapped part of the string, as the text for the whole string will be read regardless of
  // the bounding box.
  final int selectionPathEnd =
      startLine == endLine ? end : textLayout.getLineVisibleEnd(startLine);

  textLayout.getSelectionPath(start, selectionPathEnd, sTempPath);
  sTempPath.computeBounds(sTempRectF, /* unused */ true);

  sTempRect.set(
      componentBoundsLeft + (int) sTempRectF.left,
      componentBoundsTop + (int) sTempRectF.top,
      componentBoundsLeft + (int) sTempRectF.right,
      componentBoundsTop + (int) sTempRectF.bottom);

  if (sTempRect.isEmpty()) {
    // Text is not actually visible.
    // Override bounds so it doesn't crash ExploreByTouchHelper.java
    sTempRect.set(0, 0, 1, 1);
    node.setBoundsInParent(sTempRect);
    node.setContentDescription(""); // make node non-focusable
    return;
  }

  node.setBoundsInParent(sTempRect);

  node.setClickable(true);
  node.setFocusable(true);
  node.setEnabled(true);
  node.setVisibleToUser(true);
  node.setText(spanned.subSequence(start, end));
  if (span instanceof AccessibleClickableSpan) {
    AccessibleClickableSpan accessibleClickableSpan = (AccessibleClickableSpan) span;
    String contentDescription = accessibleClickableSpan.getAccessibilityDescription();
    String role = accessibleClickableSpan.getAccessibilityRole();
    if (contentDescription != null) {
      node.setContentDescription(contentDescription);
    }
    if (role != null) {
      node.setClassName(role);
    } else {
      node.setClassName(AccessibilityRole.BUTTON);
    }
  } else {
    node.setClassName(AccessibilityRole.BUTTON);
  }
}
 
Example 8
Source File: TextInputSpec.java    From litho with Apache License 2.0 4 votes vote down vote up
@OnMeasure
static void onMeasure(
    ComponentContext c,
    ComponentLayout layout,
    int widthSpec,
    int heightSpec,
    Size size,
    @Prop(optional = true, resType = ResType.STRING) CharSequence hint,
    @Prop(optional = true, resType = ResType.DRAWABLE) Drawable inputBackground,
    @Prop(optional = true, resType = ResType.DIMEN_OFFSET) float shadowRadius,
    @Prop(optional = true, resType = ResType.DIMEN_OFFSET) float shadowDx,
    @Prop(optional = true, resType = ResType.DIMEN_OFFSET) float shadowDy,
    @Prop(optional = true, resType = ResType.COLOR) int shadowColor,
    @Prop(optional = true) ColorStateList textColorStateList,
    @Prop(optional = true) ColorStateList hintColorStateList,
    @Prop(optional = true, resType = ResType.COLOR) Integer highlightColor,
    @Prop(optional = true, resType = ResType.DIMEN_TEXT) int textSize,
    @Prop(optional = true) Typeface typeface,
    @Prop(optional = true) int textAlignment,
    @Prop(optional = true) int gravity,
    @Prop(optional = true) boolean editable,
    @Prop(optional = true) int inputType,
    @Prop(optional = true) int imeOptions,
    @Prop(optional = true, varArg = "inputFilter") List<InputFilter> inputFilters,
    @Prop(optional = true) boolean multiline,
    @Prop(optional = true) TextUtils.TruncateAt ellipsize,
    @Prop(optional = true) int minLines,
    @Prop(optional = true) int maxLines,
    @Prop(optional = true) int cursorDrawableRes,
    @Prop(optional = true, resType = ResType.STRING) CharSequence error,
    @Prop(optional = true, resType = ResType.DRAWABLE) Drawable errorDrawable,
    @State AtomicReference<CharSequence> savedText,
    @State int measureSeqNumber) {

  // The height should be the measured height of EditText with relevant params
  final EditText forMeasure = new ForMeasureEditText(c.getAndroidContext());
  // If text contains Spans, we don't want it to be mutable for the measurement case
  CharSequence text = savedText.get();
  if (text instanceof Spannable) {
    text = text.toString();
  }
  setParams(
      forMeasure,
      hint,
      getBackgroundOrDefault(
          c, inputBackground == UNSET_DRAWABLE ? forMeasure.getBackground() : inputBackground),
      shadowRadius,
      shadowDx,
      shadowDy,
      shadowColor,
      textColorStateList,
      hintColorStateList,
      highlightColor,
      textSize,
      typeface,
      textAlignment,
      gravity,
      editable,
      inputType,
      imeOptions,
      inputFilters,
      multiline,
      ellipsize,
      minLines,
      maxLines,
      cursorDrawableRes,
      forMeasure.getMovementMethod(),
      // onMeasure happens:
      // 1. After initState before onMount: savedText = initText.
      // 2. After onMount before onUnmount: savedText preserved from underlying editText.
      text,
      error,
      errorDrawable);
  forMeasure.measure(
      MeasureUtils.getViewMeasureSpec(widthSpec), MeasureUtils.getViewMeasureSpec(heightSpec));

  size.height = forMeasure.getMeasuredHeight();

  // For width we always take all available space, or collapse to 0 if unspecified.
  if (SizeSpec.getMode(widthSpec) == SizeSpec.UNSPECIFIED) {
    size.width = 0;
  } else {
    size.width = Math.min(SizeSpec.getSize(widthSpec), forMeasure.getMeasuredWidth());
  }
}
 
Example 9
Source File: TextInputSpec.java    From litho with Apache License 2.0 4 votes vote down vote up
@OnMount
static void onMount(
    final ComponentContext c,
    EditTextWithEventHandlers editText,
    @Prop(optional = true, resType = ResType.STRING) CharSequence hint,
    @Prop(optional = true, resType = ResType.DRAWABLE) Drawable inputBackground,
    @Prop(optional = true, resType = ResType.DIMEN_OFFSET) float shadowRadius,
    @Prop(optional = true, resType = ResType.DIMEN_OFFSET) float shadowDx,
    @Prop(optional = true, resType = ResType.DIMEN_OFFSET) float shadowDy,
    @Prop(optional = true, resType = ResType.COLOR) int shadowColor,
    @Prop(optional = true) ColorStateList textColorStateList,
    @Prop(optional = true) ColorStateList hintColorStateList,
    @Prop(optional = true, resType = ResType.COLOR) Integer highlightColor,
    @Prop(optional = true, resType = ResType.DIMEN_TEXT) int textSize,
    @Prop(optional = true) Typeface typeface,
    @Prop(optional = true) int textAlignment,
    @Prop(optional = true) int gravity,
    @Prop(optional = true) boolean editable,
    @Prop(optional = true) int inputType,
    @Prop(optional = true) int imeOptions,
    @Prop(optional = true, varArg = "inputFilter") List<InputFilter> inputFilters,
    @Prop(optional = true) boolean multiline,
    @Prop(optional = true) int minLines,
    @Prop(optional = true) int maxLines,
    @Prop(optional = true) TextUtils.TruncateAt ellipsize,
    @Prop(optional = true) int cursorDrawableRes,
    @Prop(optional = true) MovementMethod movementMethod,
    @Prop(optional = true, resType = ResType.STRING) CharSequence error,
    @Prop(optional = true, resType = ResType.DRAWABLE) Drawable errorDrawable,
    @State AtomicReference<CharSequence> savedText,
    @State AtomicReference<EditTextWithEventHandlers> mountedView) {
  mountedView.set(editText);

  setParams(
      editText,
      hint,
      getBackgroundOrDefault(c, inputBackground),
      shadowRadius,
      shadowDx,
      shadowDy,
      shadowColor,
      textColorStateList,
      hintColorStateList,
      highlightColor,
      textSize,
      typeface,
      textAlignment,
      gravity,
      editable,
      inputType,
      imeOptions,
      inputFilters,
      multiline,
      ellipsize,
      minLines,
      maxLines,
      cursorDrawableRes,
      movementMethod,
      // onMount happens:
      // 1. After initState: savedText = initText.
      // 2. After onUnmount: savedText preserved from underlying editText.
      savedText.get(),
      error,
      errorDrawable);
  editText.setTextState(savedText);
}
 
Example 10
Source File: EditTextSpec.java    From litho with Apache License 2.0 4 votes vote down vote up
@OnMount
static void onMount(
    final ComponentContext c,
    EditTextWithEventHandlers editText,
    @Prop(optional = true, resType = ResType.STRING) CharSequence text,
    @Prop(optional = true, resType = ResType.STRING) CharSequence initialText,
    @Prop(optional = true, resType = ResType.STRING) CharSequence hint,
    @Prop(optional = true) TextUtils.TruncateAt ellipsize,
    @Prop(optional = true, resType = ResType.INT) int minLines,
    @Prop(optional = true, resType = ResType.INT) int maxLines,
    @Prop(optional = true, resType = ResType.INT) int maxLength,
    @Prop(optional = true, resType = ResType.DIMEN_OFFSET) float shadowRadius,
    @Prop(optional = true, resType = ResType.DIMEN_OFFSET) float shadowDx,
    @Prop(optional = true, resType = ResType.DIMEN_OFFSET) float shadowDy,
    @Prop(optional = true, resType = ResType.COLOR) int shadowColor,
    @Prop(optional = true, resType = ResType.BOOL) boolean isSingleLine,
    @Prop(optional = true, resType = ResType.COLOR) int textColor,
    @Prop(optional = true) ColorStateList textColorStateList,
    @Prop(optional = true, resType = ResType.COLOR) int hintColor,
    @Prop(optional = true) ColorStateList hintColorStateList,
    @Prop(optional = true, resType = ResType.COLOR) int linkColor,
    @Prop(optional = true, resType = ResType.COLOR) int highlightColor,
    @Prop(optional = true) ColorStateList tintColorStateList,
    @Prop(optional = true, resType = ResType.DIMEN_TEXT) int textSize,
    @Prop(optional = true, resType = ResType.DIMEN_OFFSET) float extraSpacing,
    @Prop(optional = true, resType = ResType.FLOAT) float spacingMultiplier,
    @Prop(optional = true) int textStyle,
    @Prop(optional = true) Typeface typeface,
    @Prop(optional = true) Layout.Alignment textAlignment,
    @Prop(optional = true) int gravity,
    @Prop(optional = true) boolean editable,
    @Prop(optional = true) int selection,
    @Prop(optional = true) int inputType,
    @Prop(optional = true) int rawInputType,
    @Prop(optional = true) int imeOptions,
    @Prop(optional = true) TextView.OnEditorActionListener editorActionListener,
    @Prop(optional = true) boolean isSingleLineWrap,
    @Prop(optional = true) boolean requestFocus,
    @Prop(optional = true) int cursorDrawableRes,
    @Prop(optional = true, varArg = "inputFilter") List<InputFilter> inputFilters,
    @State AtomicReference<EditTextWithEventHandlers> mountedView,
    @State AtomicBoolean configuredInitialText,
    @State(canUpdateLazily = true) CharSequence input) {

  mountedView.set(editText);

  initEditText(
      editText,
      input == null ? text : input,
      // Only set initialText on the EditText during the very first mount.
      configuredInitialText.getAndSet(true) ? null : initialText,
      hint,
      ellipsize,
      inputFilters,
      minLines,
      maxLines,
      maxLength,
      shadowRadius,
      shadowDx,
      shadowDy,
      shadowColor,
      isSingleLine,
      textColor,
      textColorStateList,
      hintColor,
      hintColorStateList,
      linkColor,
      highlightColor,
      tintColorStateList,
      textSize,
      extraSpacing,
      spacingMultiplier,
      textStyle,
      typeface,
      textAlignment,
      gravity,
      editable,
      selection,
      inputType,
      rawInputType,
      imeOptions,
      editorActionListener,
      isSingleLineWrap,
      requestFocus,
      cursorDrawableRes);
}