Java Code Examples for androidx.core.view.ViewCompat#LAYOUT_DIRECTION_RTL

The following examples show how to use androidx.core.view.ViewCompat#LAYOUT_DIRECTION_RTL . 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: ButtonsContainer.java    From MaterialBanner with Apache License 2.0 6 votes vote down vote up
/**
 * Position the children during a layout pass if the orientation of this view is set to
 * {@link #HORIZONTAL}.
 */
private void layoutHorizontal() {
    int lBtnRight = mLeftButton.getMeasuredWidth();
    int lBtnLeft = 0;
    int rBtnRight = getMeasuredWidth() - mButtonMarginEnd;
    int rBtnLeft = rBtnRight - mRightButton.getMeasuredWidth();

    if (ViewCompat.getLayoutDirection(this) == ViewCompat.LAYOUT_DIRECTION_RTL) {
        rBtnLeft = mButtonMarginEnd;
        rBtnRight = rBtnLeft + mRightButton.getMeasuredWidth();
        lBtnRight = getMeasuredWidth();
        lBtnLeft = lBtnRight - mLeftButton.getMeasuredWidth();
    }

    if (mLeftButton.getVisibility() != GONE) {
        mLeftButton.layout(lBtnLeft, 0, lBtnRight, mLeftButton.getMeasuredHeight());
    }

    if (mRightButton.getVisibility() != GONE) {
        mRightButton.layout(rBtnLeft, 0, rBtnRight, mRightButton.getMeasuredHeight());
    }
}
 
Example 2
Source File: DayPickerGroup.java    From MaterialDateTimePicker with Apache License 2.0 5 votes vote down vote up
@Override
protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
    final ImageButton leftButton;
    final ImageButton rightButton;
    if (ViewCompat.getLayoutDirection(this) == ViewCompat.LAYOUT_DIRECTION_RTL) {
        leftButton = nextButton;
        rightButton = prevButton;
    } else {
        leftButton = prevButton;
        rightButton = nextButton;
    }

    final int topMargin = controller.getVersion() == DatePickerDialog.Version.VERSION_1
            ? 0
            : getContext().getResources().getDimensionPixelSize(R.dimen.mdtp_date_picker_view_animator_padding_v2);
    final int width = right - left;
    final int height = bottom - top;
    dayPickerView.layout(0, topMargin, width, height);

    final SimpleMonthView monthView = (SimpleMonthView) dayPickerView.getChildAt(0);
    final int monthHeight = monthView.getMonthHeight();
    final int cellWidth = monthView.getCellWidth();
    final int edgePadding = monthView.getEdgePadding();

    // Vertically center the previous/next buttons within the month
    // header, horizontally center within the day cell.
    final int leftDW = leftButton.getMeasuredWidth();
    final int leftDH = leftButton.getMeasuredHeight();
    final int leftIconTop = topMargin + monthView.getPaddingTop() + (monthHeight - leftDH) / 2;
    final int leftIconLeft = edgePadding + (cellWidth - leftDW) / 2;
    leftButton.layout(leftIconLeft, leftIconTop, leftIconLeft + leftDW, leftIconTop + leftDH);

    final int rightDW = rightButton.getMeasuredWidth();
    final int rightDH = rightButton.getMeasuredHeight();
    final int rightIconTop = topMargin + monthView.getPaddingTop() + (monthHeight - rightDH) / 2;
    final int rightIconRight = width - edgePadding - (cellWidth - rightDW) / 2 - 2;
    rightButton.layout(rightIconRight - rightDW, rightIconTop,
            rightIconRight, rightIconTop + rightDH);
}
 
Example 3
Source File: MaterialAlertDialogBuilder.java    From material-components-android with Apache License 2.0 5 votes vote down vote up
@NonNull
public MaterialAlertDialogBuilder setBackgroundInsetEnd(@Px int backgroundInsetEnd) {
  if (Build.VERSION.SDK_INT >= VERSION_CODES.JELLY_BEAN_MR1
      && getContext().getResources().getConfiguration().getLayoutDirection()
          == ViewCompat.LAYOUT_DIRECTION_RTL) {
    backgroundInsets.left = backgroundInsetEnd;
  } else {
    backgroundInsets.right = backgroundInsetEnd;
  }
  return this;
}
 
Example 4
Source File: TextInputLayout.java    From material-components-android with Apache License 2.0 5 votes vote down vote up
@NonNull
private Rect calculateCollapsedTextBounds(@NonNull Rect rect) {
  if (editText == null) {
    throw new IllegalStateException();
  }
  Rect bounds = tmpBoundsRect;
  boolean isRtl = ViewCompat.getLayoutDirection(this) == ViewCompat.LAYOUT_DIRECTION_RTL;

  bounds.bottom = rect.bottom;
  switch (boxBackgroundMode) {
    case BOX_BACKGROUND_OUTLINE:
      bounds.left = rect.left + editText.getPaddingLeft();
      bounds.top = rect.top - calculateLabelMarginTop();
      bounds.right = rect.right - editText.getPaddingRight();
      return bounds;
    case BOX_BACKGROUND_FILLED:
      bounds.left = getLabelLeftBoundAlightWithPrefix(rect.left, isRtl);
      bounds.top = rect.top + boxCollapsedPaddingTopPx;
      bounds.right = getLabelRightBoundAlignedWithSuffix(rect.right, isRtl);
      return bounds;
    case BOX_BACKGROUND_NONE:
    default:
      bounds.left = getLabelLeftBoundAlightWithPrefix(rect.left, isRtl);
      bounds.top = getPaddingTop();
      bounds.right = getLabelRightBoundAlignedWithSuffix(rect.right, isRtl);
      return bounds;
  }
}
 
Example 5
Source File: SetupStepIndicatorView.java    From openboard with GNU General Public License v3.0 5 votes vote down vote up
public void setIndicatorPosition(final int stepPos, final int totalStepNum) {
    final int layoutDirection = ViewCompat.getLayoutDirection(this);
    // The indicator position is the center of the partition that is equally divided into
    // the total step number.
    final float partionWidth = 1.0f / totalStepNum;
    final float pos = stepPos * partionWidth + partionWidth / 2.0f;
    mXRatio = (layoutDirection == ViewCompat.LAYOUT_DIRECTION_RTL) ? 1.0f - pos : pos;
    invalidate();
}
 
Example 6
Source File: SuggestionStripView.java    From openboard with GNU General Public License v3.0 5 votes vote down vote up
public void setLayoutDirection(final boolean isRtlLanguage) {
    final int layoutDirection = isRtlLanguage ? ViewCompat.LAYOUT_DIRECTION_RTL
            : ViewCompat.LAYOUT_DIRECTION_LTR;
    ViewCompat.setLayoutDirection(mSuggestionStripView, layoutDirection);
    ViewCompat.setLayoutDirection(mSuggestionsStrip, layoutDirection);
    ViewCompat.setLayoutDirection(mImportantNoticeStrip, layoutDirection);
}
 
Example 7
Source File: SetupStepIndicatorView.java    From Android-Keyboard with Apache License 2.0 5 votes vote down vote up
public void setIndicatorPosition(final int stepPos, final int totalStepNum) {
    final int layoutDirection = ViewCompat.getLayoutDirection(this);
    // The indicator position is the center of the partition that is equally divided into
    // the total step number.
    final float partionWidth = 1.0f / totalStepNum;
    final float pos = stepPos * partionWidth + partionWidth / 2.0f;
    mXRatio = (layoutDirection == ViewCompat.LAYOUT_DIRECTION_RTL) ? 1.0f - pos : pos;
    invalidate();
}
 
Example 8
Source File: SetupActivity.java    From revolution-irc with GNU General Public License v3.0 5 votes vote down vote up
protected void setSlideAnimation(boolean fromRight) {
    if (ViewCompat.getLayoutDirection(getWindow().getDecorView())
            == ViewCompat.LAYOUT_DIRECTION_RTL)
        fromRight = !fromRight;

    if (fromRight)
        overridePendingTransition(R.anim.slide_rtl_enter, R.anim.slide_rtl_exit);
    else
        overridePendingTransition(R.anim.slide_enter, R.anim.slide_exit);
}
 
Example 9
Source File: EpoxyItemSpacingDecorator.java    From epoxy with Apache License 2.0 5 votes vote down vote up
private static boolean shouldReverseLayout(LayoutManager layout, boolean horizontallyScrolling) {
  boolean reverseLayout =
      layout instanceof LinearLayoutManager && ((LinearLayoutManager) layout).getReverseLayout();
  boolean rtl = layout.getLayoutDirection() == ViewCompat.LAYOUT_DIRECTION_RTL;
  if (horizontallyScrolling && rtl) {
    // This is how linearlayout checks if it should reverse layout in #resolveShouldLayoutReverse
    reverseLayout = !reverseLayout;
  }

  return reverseLayout;
}
 
Example 10
Source File: SetupStepIndicatorView.java    From AOSP-Kayboard-7.1.2 with Apache License 2.0 5 votes vote down vote up
public void setIndicatorPosition(final int stepPos, final int totalStepNum) {
    final int layoutDirection = ViewCompat.getLayoutDirection(this);
    // The indicator position is the center of the partition that is equally divided into
    // the total step number.
    final float partionWidth = 1.0f / totalStepNum;
    final float pos = stepPos * partionWidth + partionWidth / 2.0f;
    mXRatio = (layoutDirection == ViewCompat.LAYOUT_DIRECTION_RTL) ? 1.0f - pos : pos;
    invalidate();
}
 
Example 11
Source File: SwipeDismissBehavior.java    From material-components-android with Apache License 2.0 5 votes vote down vote up
@Override
public int clampViewPositionHorizontal(@NonNull View child, int left, int dx) {
  final boolean isRtl =
      ViewCompat.getLayoutDirection(child) == ViewCompat.LAYOUT_DIRECTION_RTL;
  int min;
  int max;

  if (swipeDirection == SWIPE_DIRECTION_START_TO_END) {
    if (isRtl) {
      min = originalCapturedViewLeft - child.getWidth();
      max = originalCapturedViewLeft;
    } else {
      min = originalCapturedViewLeft;
      max = originalCapturedViewLeft + child.getWidth();
    }
  } else if (swipeDirection == SWIPE_DIRECTION_END_TO_START) {
    if (isRtl) {
      min = originalCapturedViewLeft;
      max = originalCapturedViewLeft + child.getWidth();
    } else {
      min = originalCapturedViewLeft - child.getWidth();
      max = originalCapturedViewLeft;
    }
  } else {
    min = originalCapturedViewLeft - child.getWidth();
    max = originalCapturedViewLeft + child.getWidth();
  }

  return clamp(min, left, max);
}
 
Example 12
Source File: CollapsingTextHelper.java    From UIWidget with Apache License 2.0 5 votes vote down vote up
private boolean calculateIsRtl(CharSequence text) {
    final boolean defaultIsRtl = ViewCompat.getLayoutDirection(mView)
            == ViewCompat.LAYOUT_DIRECTION_RTL;
    return (defaultIsRtl
            ? TextDirectionHeuristicsCompat.FIRSTSTRONG_RTL
            : TextDirectionHeuristicsCompat.FIRSTSTRONG_LTR).isRtl(text, 0, text.length());
}
 
Example 13
Source File: MaterialButton.java    From material-components-android with Apache License 2.0 4 votes vote down vote up
private boolean isLayoutRTL() {
  return ViewCompat.getLayoutDirection(this) == ViewCompat.LAYOUT_DIRECTION_RTL;
}
 
Example 14
Source File: SlideDistanceProvider.java    From material-components-android with Apache License 2.0 4 votes vote down vote up
private static boolean isRtl(View view) {
  return ViewCompat.getLayoutDirection(view) == ViewCompat.LAYOUT_DIRECTION_RTL;
}
 
Example 15
Source File: Utils.java    From SmartTabLayout with Apache License 2.0 4 votes vote down vote up
static boolean isLayoutRtl(View v) {
  return ViewCompat.getLayoutDirection(v) == ViewCompat.LAYOUT_DIRECTION_RTL;
}
 
Example 16
Source File: PinEntryEditText.java    From PinEntryEditText with Apache License 2.0 4 votes vote down vote up
@Override
protected void onSizeChanged(int w, int h, int oldw, int oldh) {
    super.onSizeChanged(w, h, oldw, oldh);
    mOriginalTextColors = getTextColors();
    if (mOriginalTextColors != null) {
        mLastCharPaint.setColor(mOriginalTextColors.getDefaultColor());
        mCharPaint.setColor(mOriginalTextColors.getDefaultColor());
        mSingleCharPaint.setColor(getCurrentHintTextColor());
    }
    int availableWidth = getWidth() - ViewCompat.getPaddingEnd(this) - ViewCompat.getPaddingStart(this);
    if (mSpace < 0) {
        mCharSize = (availableWidth / (mNumChars * 2 - 1));
    } else {
        mCharSize = (availableWidth - (mSpace * (mNumChars - 1))) / mNumChars;
    }
    mLineCoords = new RectF[(int) mNumChars];
    mCharBottom = new float[(int) mNumChars];
    int startX;
    int bottom = getHeight() - getPaddingBottom();
    int rtlFlag;
    final boolean isLayoutRtl = ViewCompat.getLayoutDirection(this) == ViewCompat.LAYOUT_DIRECTION_RTL;
    if (isLayoutRtl) {
        rtlFlag = -1;
        startX = (int) (getWidth() - ViewCompat.getPaddingStart(this) - mCharSize);
    } else {
        rtlFlag = 1;
        startX = ViewCompat.getPaddingStart(this);
    }
    for (int i = 0; i < mNumChars; i++) {
        mLineCoords[i] = new RectF(startX, bottom, startX + mCharSize, bottom);
        if (mPinBackground != null) {
            if (mIsDigitSquare) {
                mLineCoords[i].top = getPaddingTop();
                mLineCoords[i].right = startX + mLineCoords[i].width();
            } else {
                mLineCoords[i].top -= mTextHeight.height() + mTextBottomPadding * 2;
            }
        }

        if (mSpace < 0) {
            startX += rtlFlag * mCharSize * 2;
        } else {
            startX += rtlFlag * (mCharSize + mSpace);
        }
        mCharBottom[i] = mLineCoords[i].bottom - mTextBottomPadding;
    }
}
 
Example 17
Source File: ViewUtils.java    From material-components-android with Apache License 2.0 4 votes vote down vote up
public static boolean isLayoutRtl(View view) {
  return ViewCompat.getLayoutDirection(view) == ViewCompat.LAYOUT_DIRECTION_RTL;
}
 
Example 18
Source File: ViewUtils.java    From Jockey with Apache License 2.0 4 votes vote down vote up
public static boolean isRtl(Context context) {
    return Build.VERSION.SDK_INT > Build.VERSION_CODES.JELLY_BEAN
            && context.getResources().getConfiguration().getLayoutDirection()
            == ViewCompat.LAYOUT_DIRECTION_RTL;
}
 
Example 19
Source File: CustomFastScroller.java    From FirefoxReality with Mozilla Public License 2.0 4 votes vote down vote up
private boolean isLayoutRTL() {
    return ViewCompat.getLayoutDirection(mRecyclerView) == ViewCompat.LAYOUT_DIRECTION_RTL;
}
 
Example 20
Source File: FastScroller.java    From Telegram with GNU General Public License v2.0 4 votes vote down vote up
private boolean isLayoutRTL() {
    return ViewCompat.getLayoutDirection(mRecyclerView) == ViewCompat.LAYOUT_DIRECTION_RTL;
}