Java源码示例:androidx.core.text.TextUtilsCompat

示例1
@Override
public void attachToRecyclerView(@Nullable RecyclerView recyclerView)
        throws IllegalStateException {
    if (this.recyclerView != null) {
        this.recyclerView.removeOnScrollListener(scrollListener);
    }
    if (recyclerView != null) {
        recyclerView.setOnFlingListener(null);
        if (gravity == Gravity.START || gravity == Gravity.END) {
            isRtl = TextUtilsCompat.getLayoutDirectionFromLocale(Locale.getDefault())
                    == ViewCompat.LAYOUT_DIRECTION_RTL;
        }
        recyclerView.addOnScrollListener(scrollListener);
        this.recyclerView = recyclerView;
    } else {
        this.recyclerView = null;
    }
    super.attachToRecyclerView(recyclerView);
}
 
示例2
/**
 * 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 Default style attribute to use for popup content.
 * @param defStyleRes Default style to use for popup content.
 */
public ListPopupWindow(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
    mContext = context;

    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();

    mPopup = new PopupWindow(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);
}
 
示例3
private boolean isRtl() {
    switch (manager.indicator().getRtlMode()) {
        case On:
            return true;

        case Off:
            return false;

        case Auto:
            return TextUtilsCompat.getLayoutDirectionFromLocale(getContext().getResources().getConfiguration().locale) == ViewCompat.LAYOUT_DIRECTION_RTL;
    }

    return false;
}
 
示例4
/**
 * Force set layout direction to RTL or LTR by Locale.
 *
 * @param view
 * @param locale
 */
public static void setLayoutDirection(View view, Locale locale) {
    switch (TextUtilsCompat.getLayoutDirectionFromLocale(locale)) {
        case ViewCompat.LAYOUT_DIRECTION_RTL:
            ViewCompat.setLayoutDirection(view, ViewCompat.LAYOUT_DIRECTION_RTL);
            break;
        case ViewCompat.LAYOUT_DIRECTION_LTR:
        default:
            ViewCompat.setLayoutDirection(view, ViewCompat.LAYOUT_DIRECTION_LTR);
            break;
    }
}
 
示例5
/**
 * Force set layout direction to RTL or LTR by Locale.
 *
 * @param view
 * @param locale
 */
public static void setLayoutDirection(View view, Locale locale) {
    switch (TextUtilsCompat.getLayoutDirectionFromLocale(locale)) {
        case ViewCompat.LAYOUT_DIRECTION_RTL:
            ViewCompat.setLayoutDirection(view, ViewCompat.LAYOUT_DIRECTION_RTL);
            break;
        case ViewCompat.LAYOUT_DIRECTION_LTR:
        default:
            ViewCompat.setLayoutDirection(view, ViewCompat.LAYOUT_DIRECTION_LTR);
            break;
    }
}
 
示例6
private boolean isRTL() {
    return TextUtilsCompat.getLayoutDirectionFromLocale(Locale.getDefault()) == LAYOUT_DIRECTION_RTL;
}
 
示例7
private boolean isRTL() {
    return TextUtilsCompat.getLayoutDirectionFromLocale(Locale.getDefault()) == LAYOUT_DIRECTION_RTL;
}
 
示例8
public Builder(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes){
	TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.LineMorphingDrawable, defStyleAttr, defStyleRes);
	int resId;
	
	if((resId = a.getResourceId(R.styleable.LineMorphingDrawable_lmd_state, 0)) != 0)
		states(readStates(context, resId));			
	curState(a.getInteger(R.styleable.LineMorphingDrawable_lmd_curState, 0));
	width(a.getDimensionPixelSize(R.styleable.LineMorphingDrawable_lmd_width, 0));
	height(a.getDimensionPixelSize(R.styleable.LineMorphingDrawable_lmd_height, 0));
	padding(a.getDimensionPixelSize(R.styleable.LineMorphingDrawable_lmd_padding, 0));
	paddingLeft(a.getDimensionPixelSize(R.styleable.LineMorphingDrawable_lmd_paddingLeft, mPaddingLeft));
	paddingTop(a.getDimensionPixelSize(R.styleable.LineMorphingDrawable_lmd_paddingTop, mPaddingTop));
	paddingRight(a.getDimensionPixelSize(R.styleable.LineMorphingDrawable_lmd_paddingRight, mPaddingRight));
	paddingBottom(a.getDimensionPixelSize(R.styleable.LineMorphingDrawable_lmd_paddingBottom, mPaddingBottom));
	animDuration(a.getInteger(R.styleable.LineMorphingDrawable_lmd_animDuration, context.getResources().getInteger(android.R.integer.config_mediumAnimTime)));
	if((resId = a.getResourceId(R.styleable.LineMorphingDrawable_lmd_interpolator, 0)) != 0)
		interpolator(AnimationUtils.loadInterpolator(context, resId));
	strokeSize(a.getDimensionPixelSize(R.styleable.LineMorphingDrawable_lmd_strokeSize, ThemeUtil.dpToPx(context, 3)));
	strokeColor(a.getColor(R.styleable.LineMorphingDrawable_lmd_strokeColor, 0xFFFFFFFF));
	int cap = a.getInteger(R.styleable.LineMorphingDrawable_lmd_strokeCap, 0);
	if(cap == 0)
		strokeCap(Paint.Cap.BUTT);
	else if(cap == 1)
		strokeCap(Paint.Cap.ROUND);
	else
		strokeCap(Paint.Cap.SQUARE);
	int join = a.getInteger(R.styleable.LineMorphingDrawable_lmd_strokeJoin, 0);
	if(join == 0)
		strokeJoin(Paint.Join.MITER);
	else if(join == 1)
		strokeJoin(Paint.Join.ROUND);
	else
		strokeJoin(Paint.Join.BEVEL);
	clockwise(a.getBoolean(R.styleable.LineMorphingDrawable_lmd_clockwise, true));

          int direction = a.getInteger(R.styleable.LineMorphingDrawable_lmd_layoutDirection, View.LAYOUT_DIRECTION_LTR);
          if(direction == View.LAYOUT_DIRECTION_LOCALE)
              rtl(TextUtilsCompat.getLayoutDirectionFromLocale(Locale.getDefault()) == ViewCompat.LAYOUT_DIRECTION_RTL);
          else
              rtl(direction == View.LAYOUT_DIRECTION_RTL);
	
	a.recycle();
}
 
示例9
public static void saveDeviceLocale(Locale deviceLocale) {
    isRtl = TextUtilsCompat.getLayoutDirectionFromLocale(deviceLocale) == ViewCompat.LAYOUT_DIRECTION_RTL;
}
 
示例10
/**
 * Animated the forward movement of the cursor.
 * <p>
 * Only available of JellyBean and above devices.
 * Does not work with RTL languages.
 *
 * @param animated Animate the cursors movement.
 */
@TargetApi(Build.VERSION_CODES.JELLY_BEAN)
public void setCursorAnimated(boolean animated) {
    final boolean isLayoutRtl = TextUtilsCompat.getLayoutDirectionFromLocale(Locale.getDefault()) == ViewCompat.LAYOUT_DIRECTION_RTL;
    mAnimateCursor = animated && Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN && !isLayoutRtl;

}