Java Code Examples for androidx.core.graphics.drawable.DrawableCompat#getLayoutDirection()

The following examples show how to use androidx.core.graphics.drawable.DrawableCompat#getLayoutDirection() . 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: ChipDrawable.java    From material-components-android with Apache License 2.0 6 votes vote down vote up
/**
 * Calculates the chip icon's ChipDrawable-absolute bounds (top-left is <code>
 * [ChipDrawable.getBounds().left, ChipDrawable.getBounds().top]</code>).
 */
private void calculateChipIconBounds(@NonNull Rect bounds, @NonNull RectF outBounds) {
  outBounds.setEmpty();

  if (showsChipIcon() || showsCheckedIcon()) {
    float offsetFromStart = chipStartPadding + iconStartPadding;
    float chipWidth = getCurrentChipIconWidth();

    if (DrawableCompat.getLayoutDirection(this) == ViewCompat.LAYOUT_DIRECTION_LTR) {
      outBounds.left = bounds.left + offsetFromStart;
      outBounds.right = outBounds.left + chipWidth;
    } else {
      outBounds.right = bounds.right - offsetFromStart;
      outBounds.left = outBounds.right - chipWidth;
    }

    float chipHeight = getCurrentChipIconHeight();
    outBounds.top = bounds.exactCenterY() - chipHeight / 2f;
    outBounds.bottom = outBounds.top + chipHeight;
  }
}
 
Example 2
Source File: ChipDrawable.java    From material-components-android with Apache License 2.0 6 votes vote down vote up
/** Calculates the chip text's origin and alignment based on the ChipDrawable-absolute bounds. */
@NonNull
Align calculateTextOriginAndAlignment(@NonNull Rect bounds, @NonNull PointF pointF) {
  pointF.set(0, 0);
  Align align = Align.LEFT;

  if (text != null) {
    float offsetFromStart = chipStartPadding + calculateChipIconWidth() + textStartPadding;

    if (DrawableCompat.getLayoutDirection(this) == ViewCompat.LAYOUT_DIRECTION_LTR) {
      pointF.x = bounds.left + offsetFromStart;
      align = Align.LEFT;
    } else {
      pointF.x = bounds.right - offsetFromStart;
      align = Align.RIGHT;
    }

    pointF.y = bounds.centerY() - calculateTextCenterFromBaseline();
  }

  return align;
}
 
Example 3
Source File: ChipDrawable.java    From material-components-android with Apache License 2.0 6 votes vote down vote up
/**
 * Calculates the chip text's ChipDrawable-absolute bounds (top-left is <code>
 * [ChipDrawable.getBounds().left, ChipDrawable.getBounds().top]</code>).
 */
private void calculateTextBounds(@NonNull Rect bounds, @NonNull RectF outBounds) {
  outBounds.setEmpty();

  if (text != null) {
    float offsetFromStart = chipStartPadding + calculateChipIconWidth() + textStartPadding;
    float offsetFromEnd = chipEndPadding + calculateCloseIconWidth() + textEndPadding;

    if (DrawableCompat.getLayoutDirection(this) == ViewCompat.LAYOUT_DIRECTION_LTR) {
      outBounds.left = bounds.left + offsetFromStart;
      outBounds.right = bounds.right - offsetFromEnd;
    } else {
      outBounds.left = bounds.left + offsetFromEnd;
      outBounds.right = bounds.right - offsetFromStart;
    }

    // Top and bottom included for completion. Don't position the chip text vertically based on
    // these bounds. Instead, use #calculateTextOriginAndAlignment().
    outBounds.top = bounds.top;
    outBounds.bottom = bounds.bottom;
  }
}
 
Example 4
Source File: ChipDrawable.java    From material-components-android with Apache License 2.0 6 votes vote down vote up
/**
 * Calculates the close icon's ChipDrawable-absolute bounds (top-left is <code>
 * [ChipDrawable.getBounds().left, ChipDrawable.getBounds().top]</code>).
 */
private void calculateCloseIconBounds(@NonNull Rect bounds, @NonNull RectF outBounds) {
  outBounds.setEmpty();

  if (showsCloseIcon()) {
    float offsetFromEnd = chipEndPadding + closeIconEndPadding;

    if (DrawableCompat.getLayoutDirection(this) == ViewCompat.LAYOUT_DIRECTION_LTR) {
      outBounds.right = bounds.right - offsetFromEnd;
      outBounds.left = outBounds.right - closeIconSize;
    } else {
      outBounds.left = bounds.left + offsetFromEnd;
      outBounds.right = outBounds.left + closeIconSize;
    }

    outBounds.top = bounds.exactCenterY() - closeIconSize / 2f;
    outBounds.bottom = outBounds.top + closeIconSize;
  }
}
 
Example 5
Source File: ChipDrawable.java    From material-components-android with Apache License 2.0 6 votes vote down vote up
private void calculateChipTouchBounds(@NonNull Rect bounds, @NonNull RectF outBounds) {
  outBounds.set(bounds);

  if (showsCloseIcon()) {
    float offsetFromEnd =
        chipEndPadding
            + closeIconEndPadding
            + closeIconSize
            + closeIconStartPadding
            + textEndPadding;

    if (DrawableCompat.getLayoutDirection(this) == ViewCompat.LAYOUT_DIRECTION_LTR) {
      outBounds.right = bounds.right - offsetFromEnd;
    } else {
      outBounds.left = bounds.left + offsetFromEnd;
    }
  }
}
 
Example 6
Source File: ChipDrawable.java    From material-components-android with Apache License 2.0 6 votes vote down vote up
private void calculateCloseIconTouchBounds(@NonNull Rect bounds, @NonNull RectF outBounds) {
  outBounds.setEmpty();

  if (showsCloseIcon()) {
    float offsetFromEnd =
        chipEndPadding
            + closeIconEndPadding
            + closeIconSize
            + closeIconStartPadding
            + textEndPadding;

    if (DrawableCompat.getLayoutDirection(this) == ViewCompat.LAYOUT_DIRECTION_LTR) {
      outBounds.right = bounds.right;
      outBounds.left = outBounds.right - offsetFromEnd;
    } else {
      outBounds.left = bounds.left;
      outBounds.right = bounds.left + offsetFromEnd;
    }

    outBounds.top = bounds.top;
    outBounds.bottom = bounds.bottom;
  }
}
 
Example 7
Source File: AutoMirrorDrawable.java    From AndroidFastScroll with Apache License 2.0 4 votes vote down vote up
private boolean needMirroring() {
    return DrawableCompat.getLayoutDirection(this) == View.LAYOUT_DIRECTION_RTL;
}
 
Example 8
Source File: Md2PopupBackground.java    From AndroidFastScroll with Apache License 2.0 4 votes vote down vote up
private boolean needMirroring() {
    return DrawableCompat.getLayoutDirection(this) == View.LAYOUT_DIRECTION_RTL;
}