Example usage for android.util LayoutDirection RTL

List of usage examples for android.util LayoutDirection RTL

Introduction

In this page you can find the example usage for android.util LayoutDirection RTL.

Prototype

int RTL

To view the source code for android.util LayoutDirection RTL.

Click Source Link

Document

Horizontal layout direction is from Right to Left.

Usage

From source file:Main.java

/**
 *
 * @param c Context//from ww w  .  j  a v  a  2s  .  c  o  m
 * @return True if the current layout is RTL.
 */
static boolean isRightToLeft(Context c) {
    return Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT
            && c.getResources().getConfiguration().getLayoutDirection() == LayoutDirection.RTL;
}

From source file:android.support.v7.widget.AbstractXpListPopupWindow.java

public void setMarginStart(int px) {
    if (mLayoutDirection == LayoutDirection.RTL) {
        mMargins.right = px;/*from w  ww  . j a  va  2 s .  c  o  m*/
    } else {
        mMargins.left = px;
    }
}

From source file:android.support.v7.widget.AbstractXpListPopupWindow.java

public int getMarginStart(int px) {
    if (mLayoutDirection == LayoutDirection.RTL) {
        return mMargins.right;
    } else {/*from w ww.  java 2 s .c  om*/
        return mMargins.left;
    }
}

From source file:android.support.v7.widget.AbstractXpListPopupWindow.java

public void setMarginEnd(int px) {
    if (mLayoutDirection == LayoutDirection.RTL) {
        mMargins.left = px;// w  w  w. j av  a2 s .  co  m
    } else {
        mMargins.right = px;
    }
}

From source file:android.support.v7.widget.AbstractXpListPopupWindow.java

public int getMarginEnd(int px) {
    if (mLayoutDirection == LayoutDirection.RTL) {
        return mMargins.left;
    } else {/*ww w  . jav  a2 s.  c om*/
        return mMargins.right;
    }
}

From source file:android.support.v7.widget.AbstractXpListPopupWindow.java

public void setMarginRelative(int start, int top, int end, int bottom) {
    int left, right;
    if (mLayoutDirection == LayoutDirection.RTL) {
        right = start;//from ww w.  java  2s.  c o m
        left = end;
    } else {
        left = start;
        right = end;
    }
    mMargins.set(left, top, right, bottom);
}

From source file:android.support.v7.widget.AbstractXpListPopupWindow.java

/**
 * Create a new, empty popup window capable of displaying items from a ListAdapter.
 * Backgrounds should be set using {@link #setBackgroundDrawable(Drawable)}.
 *
 * @param context Context used for contained views.
 * @param attrs Attributes from inflating parent views used to style the popup.
 * @param defStyleAttr Style attribute to read for default styling of popup content.
 * @param defStyleRes Style resource ID to use for default styling of popup content.
 *///from w  ww .j  a  va2  s  .c o  m
public AbstractXpListPopupWindow(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
    mContext = context;
    mHandler = new Handler(context.getMainLooper());

    final TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.ListPopupWindow, defStyleAttr,
            defStyleRes);
    mDropDownHorizontalOffset = a
            .getDimensionPixelOffset(R.styleable.ListPopupWindow_android_dropDownHorizontalOffset, 0);
    mDropDownVerticalOffset = a
            .getDimensionPixelOffset(R.styleable.ListPopupWindow_android_dropDownVerticalOffset, 0);
    if (mDropDownVerticalOffset != 0) {
        mDropDownVerticalOffsetSet = true;
    }
    a.recycle();

    int defaultMargin = Util.dpToPxOffset(context, 8);
    final TypedArray b = context.obtainStyledAttributes(attrs, R.styleable.XpListPopupWindow, defStyleAttr,
            defStyleRes);
    if (b.hasValue(R.styleable.XpListPopupWindow_android_layout_margin)) {
        int margin = b.getDimensionPixelOffset(R.styleable.XpListPopupWindow_android_layout_margin,
                defaultMargin);
        mMargins.bottom = margin;
        mMargins.top = margin;
        mMargins.left = margin;
        mMargins.right = margin;
    } else {
        if (API_18 && b.hasValue(R.styleable.XpListPopupWindow_android_layout_marginEnd)) {
            int margin = b.getDimensionPixelOffset(R.styleable.XpListPopupWindow_android_layout_marginEnd, 0);
            if (mLayoutDirection == LayoutDirection.RTL) {
                mMargins.left = margin;
            } else {
                mMargins.right = margin;
            }
        } else {
            mMargins.right = b.getDimensionPixelOffset(R.styleable.XpListPopupWindow_android_layout_marginRight,
                    defaultMargin);
        }
        if (API_18 && b.hasValue(R.styleable.XpListPopupWindow_android_layout_marginStart)) {
            int margin = b.getDimensionPixelOffset(R.styleable.XpListPopupWindow_android_layout_marginStart, 0);
            if (mLayoutDirection == LayoutDirection.RTL) {
                mMargins.right = margin;
            } else {
                mMargins.left = margin;
            }
        } else {
            mMargins.left = b.getDimensionPixelOffset(R.styleable.XpListPopupWindow_android_layout_marginLeft,
                    defaultMargin);
        }
        mMargins.top = b.getDimensionPixelOffset(R.styleable.XpListPopupWindow_android_layout_marginTop,
                defaultMargin);
        mMargins.bottom = b.getDimensionPixelOffset(R.styleable.XpListPopupWindow_android_layout_marginBottom,
                defaultMargin);
    }
    b.recycle();

    mPopup = new AppCompatPopupWindow(context, attrs, defStyleAttr);
    mPopup.setInputMethodMode(PopupWindow.INPUT_METHOD_NEEDED);

    // Set the default layout direction to match the default locale one
    final Locale locale = mContext.getResources().getConfiguration().locale;
    mLayoutDirection = TextUtilsCompat.getLayoutDirectionFromLocale(locale);

    setAllowScrollingAnchorParent(false);
}

From source file:com.hippo.vector.VectorDrawable.java

private boolean needMirroring() {
    return Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && isAutoMirrored()
            && getLayoutDirection() == LayoutDirection.RTL;
}

From source file:com.bettervectordrawable.lib.graphics.drawable.VectorDrawable.java

private boolean needMirroring() {
    return isAutoMirrored() && getLayoutDirection(this) == LayoutDirection.RTL;
}