android.support.v4.view.ViewCompat#LAYOUT_DIRECTION_RTL源码实例Demo

下面列出了android.support.v4.view.ViewCompat#LAYOUT_DIRECTION_RTL 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: V.FlyoutTest   文件: ActionBarDrawerToggle.java
@Override
public void draw(Canvas canvas) {
    copyBounds(mTmpRect);
    canvas.save();

    // Layout direction must be obtained from the activity.
    final boolean isLayoutRTL = ViewCompat.getLayoutDirection(
            mActivity.getWindow().getDecorView()) == ViewCompat.LAYOUT_DIRECTION_RTL;
    final int flipRtl = isLayoutRTL ? -1 : 1;
    final int width = mTmpRect.width();
    canvas.translate(-mOffset * width * mPosition * flipRtl, 0);

    // Force auto-mirroring if it's not supported by the platform.
    if (isLayoutRTL && !mHasMirroring) {
        canvas.translate(width, 0);
        canvas.scale(-1, 1);
    }

    super.draw(canvas);
    canvas.restore();
}
 
源代码2 项目: Indic-Keyboard   文件: SetupStartIndicatorView.java
@Override
protected void onDraw(final Canvas canvas) {
    super.onDraw(canvas);
    final int layoutDirection = ViewCompat.getLayoutDirection(this);
    final int width = getWidth();
    final int height = getHeight();
    final float halfHeight = height / 2.0f;
    final Path path = mIndicatorPath;
    path.rewind();
    if (layoutDirection == ViewCompat.LAYOUT_DIRECTION_RTL) {
        // Left arrow
        path.moveTo(width, 0.0f);
        path.lineTo(0.0f, halfHeight);
        path.lineTo(width, height);
    } else { // LAYOUT_DIRECTION_LTR
        // Right arrow
        path.moveTo(0.0f, 0.0f);
        path.lineTo(width, halfHeight);
        path.lineTo(0.0f, height);
    }
    path.close();
    final int[] stateSet = getDrawableState();
    final int color = mIndicatorColor.getColorForState(stateSet, 0);
    mIndicatorPaint.setColor(color);
    canvas.drawPath(path, mIndicatorPaint);
}
 
源代码3 项目: android-recipes-app   文件: TextUtilsCompat.java
/**
 * Return the layout direction for a given Locale
 *
 * @param locale the Locale for which we want the layout direction. Can be null.
 * @return the layout direction. This may be one of:
 * {@link ViewCompat#LAYOUT_DIRECTION_LTR} or
 * {@link ViewCompat#LAYOUT_DIRECTION_RTL}.
 *
 * Be careful: this code will need to be updated when vertical scripts will be supported
 */
public static int getLayoutDirectionFromLocale(Locale locale) {
    if (locale != null && !locale.equals(ROOT)) {
        final String scriptSubtag = ICUCompat.getScript(
                ICUCompat.addLikelySubtags(locale.toString()));
        if (scriptSubtag == null) return getLayoutDirectionFromFirstChar(locale);

        if (scriptSubtag.equalsIgnoreCase(ARAB_SCRIPT_SUBTAG) ||
                scriptSubtag.equalsIgnoreCase(HEBR_SCRIPT_SUBTAG)) {
            return ViewCompat.LAYOUT_DIRECTION_RTL;
        }
    }

    return ViewCompat.LAYOUT_DIRECTION_LTR;
}
 
源代码4 项目: guideshow   文件: TextUtilsCompat.java
/**
 * Return the layout direction for a given Locale
 *
 * @param locale the Locale for which we want the layout direction. Can be null.
 * @return the layout direction. This may be one of:
 * {@link ViewCompat#LAYOUT_DIRECTION_LTR} or
 * {@link ViewCompat#LAYOUT_DIRECTION_RTL}.
 *
 * Be careful: this code will need to be updated when vertical scripts will be supported
 */
public static int getLayoutDirectionFromLocale(Locale locale) {
    if (locale != null && !locale.equals(ROOT)) {
        final String scriptSubtag = ICUCompat.getScript(
                ICUCompat.addLikelySubtags(locale.toString()));
        if (scriptSubtag == null) return getLayoutDirectionFromFirstChar(locale);

        if (scriptSubtag.equalsIgnoreCase(ARAB_SCRIPT_SUBTAG) ||
                scriptSubtag.equalsIgnoreCase(HEBR_SCRIPT_SUBTAG)) {
            return ViewCompat.LAYOUT_DIRECTION_RTL;
        }
    }

    return ViewCompat.LAYOUT_DIRECTION_LTR;
}
 
源代码5 项目: TelePlus-Android   文件: FastScroller.java
private boolean isLayoutRTL() {
    return ViewCompat.getLayoutDirection(mRecyclerView) == ViewCompat.LAYOUT_DIRECTION_RTL;
}
 
源代码6 项目: FireFiles   文件: NumberProgressBar.java
public boolean isLayoutRtl() {
    return ViewCompat.getLayoutDirection(this) == ViewCompat.LAYOUT_DIRECTION_RTL;
}
 
源代码7 项目: TelePlus-Android   文件: LinearLayoutManager.java
protected boolean isLayoutRTL() {
    return getLayoutDirection() == ViewCompat.LAYOUT_DIRECTION_RTL;
}
 
@Override
protected boolean defaultIsRtl() {
    final int dir = TextUtilsCompat.getLayoutDirectionFromLocale(java.util.Locale.getDefault());
    return (dir == ViewCompat.LAYOUT_DIRECTION_RTL);
}
 
/**
 * Used in combination of a TabLayout to create a multi view layout.
 * @param views Thew views to use in the pager Adapter.
 */
TabularContextMenuPagerAdapter(List<Pair<String, ViewGroup>> views) {
    mViewList = views;
    mIsRightToLeft = TextUtilsCompat.getLayoutDirectionFromLocale(Locale.getDefault())
            == ViewCompat.LAYOUT_DIRECTION_RTL;
}
 
源代码10 项目: FireFiles   文件: NumberProgressBar.java
public boolean isLayoutRtl() {
    return ViewCompat.getLayoutDirection(this) == ViewCompat.LAYOUT_DIRECTION_RTL;
}
 
源代码11 项目: RecyclerViewLib   文件: BaseLayoutManager.java
protected boolean isLayoutRTL() {
    return getLayoutDirection() == ViewCompat.LAYOUT_DIRECTION_RTL;
}
 
boolean isLayoutRTL() {
    return getLayoutDirection() == ViewCompat.LAYOUT_DIRECTION_RTL;
}
 
源代码13 项目: TelePlus-Android   文件: LinearLayoutManager.java
protected boolean isLayoutRTL() {
    return getLayoutDirection() == ViewCompat.LAYOUT_DIRECTION_RTL;
}
 
源代码14 项目: react-native-GPay   文件: I18nUtil.java
private boolean isDevicePreferredLanguageRTL() {
 final int directionality =
   TextUtilsCompat.getLayoutDirectionFromLocale(Locale.getDefault());
 return directionality == ViewCompat.LAYOUT_DIRECTION_RTL;
}
 
源代码15 项目: floatingsearchview   文件: FloatingSearchView.java
private boolean isRTL() {

        Configuration config = getResources().getConfiguration();
        return ViewCompat.getLayoutDirection(this) == ViewCompat.LAYOUT_DIRECTION_RTL;
    }
 
源代码16 项目: JD-Test   文件: FlexboxLayout.java
@Override
protected void onDraw(Canvas canvas) {
    if (mDividerDrawableVertical == null && mDividerDrawableHorizontal == null) {
        return;
    }
    if (mShowDividerHorizontal == SHOW_DIVIDER_NONE
            && mShowDividerVertical == SHOW_DIVIDER_NONE) {
        return;
    }

    int layoutDirection = ViewCompat.getLayoutDirection(this);
    boolean isRtl;
    boolean fromBottomToTop = false;
    switch (mFlexDirection) {
        case FLEX_DIRECTION_ROW:
            isRtl = layoutDirection == ViewCompat.LAYOUT_DIRECTION_RTL;
            if (mFlexWrap == FLEX_WRAP_WRAP_REVERSE) {
                fromBottomToTop = true;
            }
            drawDividersHorizontal(canvas, isRtl, fromBottomToTop);
            break;
        case FLEX_DIRECTION_ROW_REVERSE:
            isRtl = layoutDirection != ViewCompat.LAYOUT_DIRECTION_RTL;
            if (mFlexWrap == FLEX_WRAP_WRAP_REVERSE) {
                fromBottomToTop = true;
            }
            drawDividersHorizontal(canvas, isRtl, fromBottomToTop);
            break;
        case FLEX_DIRECTION_COLUMN:
            isRtl = layoutDirection == ViewCompat.LAYOUT_DIRECTION_RTL;
            if (mFlexWrap == FLEX_WRAP_WRAP_REVERSE) {
                isRtl = !isRtl;
            }
            fromBottomToTop = false;
            drawDividersVertical(canvas, isRtl, fromBottomToTop);
            break;
        case FLEX_DIRECTION_COLUMN_REVERSE:
            isRtl = layoutDirection == ViewCompat.LAYOUT_DIRECTION_RTL;
            if (mFlexWrap == FLEX_WRAP_WRAP_REVERSE) {
                isRtl = !isRtl;
            }
            fromBottomToTop = true;
            drawDividersVertical(canvas, isRtl, fromBottomToTop);
            break;
    }
}
 
@Override
protected boolean defaultIsRtl() {
    final int dir = TextUtilsCompat.getLayoutDirectionFromLocale(java.util.Locale.getDefault());
    return (dir == ViewCompat.LAYOUT_DIRECTION_RTL);
}
 
源代码18 项目: android-proguards   文件: CollapsingTitleLayout.java
public CollapsingTitleLayout(Context context, AttributeSet attrs, int defStyleAttr,
                             int defStyleRes) {
    super(context, attrs, defStyleAttr, defStyleRes);
    setWillNotDraw(false);
    paint = new TextPaint(Paint.ANTI_ALIAS_FLAG);

    TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.CollapsingTitleLayout);
    final boolean isRtl = ViewCompat.getLayoutDirection(this)
            == ViewCompat.LAYOUT_DIRECTION_RTL;

    // first check if all insets set the same
    titleInsetStart = titleInsetEnd = titleInsetBottom =
            a.getDimensionPixelSize(R.styleable.CollapsingTitleLayout_titleInset, 0);
    titleInsetTop = titleInsetStart;

    if (a.hasValue(R.styleable.CollapsingTitleLayout_titleInsetStart)) {
        final int insetStart = a.getDimensionPixelSize(
                R.styleable.CollapsingTitleLayout_titleInsetStart, 0);
        if (isRtl) {
            titleInsetEnd = insetStart;
        } else {
            titleInsetStart = insetStart;
        }
    }
    if (a.hasValue(R.styleable.CollapsingTitleLayout_titleInsetTop)) {
        titleInsetTop = a.getDimensionPixelSize(
                R.styleable.CollapsingTitleLayout_titleInsetTop, 0);
    }
    if (a.hasValue(R.styleable.CollapsingTitleLayout_titleInsetEnd)) {
        final int insetEnd = a.getDimensionPixelSize(
                R.styleable.CollapsingTitleLayout_titleInsetEnd, 0);
        if (isRtl) {
            titleInsetStart = insetEnd;
        } else {
            titleInsetEnd = insetEnd;
        }
    }
    if (a.hasValue(R.styleable.CollapsingTitleLayout_titleInsetBottom)) {
        titleInsetBottom = a.getDimensionPixelSize(
                R.styleable.CollapsingTitleLayout_titleInsetBottom, 0);
    }

    final int textAppearance = a.getResourceId(
            R.styleable.CollapsingTitleLayout_android_textAppearance,
            android.R.style.TextAppearance);
    TypedArray atp = getContext().obtainStyledAttributes(textAppearance,
            R.styleable.CollapsingTextAppearance);
    paint.setColor(atp.getColor(R.styleable.CollapsingTextAppearance_android_textColor,
            Color.WHITE));
    collapsedTextSize = atp.getDimensionPixelSize(
            R.styleable.CollapsingTextAppearance_android_textSize, 0);
    if (atp.hasValue(R.styleable.CollapsingTextAppearance_font)) {
        paint.setTypeface(FontUtil.get(getContext(),
                atp.getString(R.styleable.CollapsingTextAppearance_font)));
    }
    atp.recycle();

    if (a.hasValue(R.styleable.CollapsingTitleLayout_collapsedTextSize)) {
        collapsedTextSize = a.getDimensionPixelSize(
                R.styleable.CollapsingTitleLayout_collapsedTextSize, 0);
        paint.setTextSize(collapsedTextSize);
    }

    maxExpandedTextSize = a.getDimensionPixelSize(
            R.styleable.CollapsingTitleLayout_maxExpandedTextSize, Integer.MAX_VALUE);
    lineHeightHint =
            a.getDimensionPixelSize(R.styleable.CollapsingTitleLayout_lineHeightHint, 0);
    maxLines = a.getInteger(R.styleable.CollapsingTitleLayout_android_maxLines, 5);
    a.recycle();
}
 
源代码19 项目: KinoCast   文件: BaseLayoutManager.java
protected boolean isLayoutRTL() {
    return getLayoutDirection() == ViewCompat.LAYOUT_DIRECTION_RTL;
}
 
源代码20 项目: android-recipes-app   文件: BidiFormatter.java
/**
 * Helper method to return true if the Locale directionality is RTL.
 *
 * @param locale The Locale whose directionality will be checked to be RTL or LTR
 * @return true if the {@code locale} directionality is RTL. False otherwise.
 */
private static boolean isRtlLocale(Locale locale) {
    return (TextUtilsCompat.getLayoutDirectionFromLocale(locale) == ViewCompat.LAYOUT_DIRECTION_RTL);
}
 
 同类方法