androidx.core.text.TextUtilsCompat Java Examples

The following examples show how to use androidx.core.text.TextUtilsCompat. 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: GravitySnapHelper.java    From GravitySnapHelper with Apache License 2.0 6 votes vote down vote up
@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);
}
 
Example #2
Source File: ListPopupWindow.java    From material with Apache License 2.0 6 votes vote down vote up
/**
 * 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);
}
 
Example #3
Source File: PageIndicatorView.java    From Android-Image-Slider with Apache License 2.0 5 votes vote down vote up
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;
}
 
Example #4
Source File: LocaleAwareAppCompatActivity.java    From firefox-echo-show with Mozilla Public License 2.0 5 votes vote down vote up
/**
 * 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;
    }
}
 
Example #5
Source File: LocaleAwareAppCompatActivity.java    From focus-android with Mozilla Public License 2.0 5 votes vote down vote up
/**
 * 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;
    }
}
 
Example #6
Source File: RTLViewPager.java    From prayer-times-android with Apache License 2.0 4 votes vote down vote up
private boolean isRTL() {
    return TextUtilsCompat.getLayoutDirectionFromLocale(Locale.getDefault()) == LAYOUT_DIRECTION_RTL;
}
 
Example #7
Source File: RTLViewPager.java    From prayer-times-android with Apache License 2.0 4 votes vote down vote up
private boolean isRTL() {
    return TextUtilsCompat.getLayoutDirectionFromLocale(Locale.getDefault()) == LAYOUT_DIRECTION_RTL;
}
 
Example #8
Source File: LineMorphingDrawable.java    From material with Apache License 2.0 4 votes vote down vote up
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();
}
 
Example #9
Source File: LocalePreferences.java    From commcare-android with Apache License 2.0 4 votes vote down vote up
public static void saveDeviceLocale(Locale deviceLocale) {
    isRtl = TextUtilsCompat.getLayoutDirectionFromLocale(deviceLocale) == ViewCompat.LAYOUT_DIRECTION_RTL;
}
 
Example #10
Source File: AnimatedEditText.java    From AnimatedEditText with Apache License 2.0 3 votes vote down vote up
/**
 * 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;

}