Java Code Examples for android.text.TextUtils#getLayoutDirectionFromLocale()

The following examples show how to use android.text.TextUtils#getLayoutDirectionFromLocale() . 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: TimeUtil.java    From AndroidWallet with GNU General Public License v3.0 6 votes vote down vote up
public static String getTimeZoneText(TimeZone tz, boolean includeName) {
    Date now = new Date();

    SimpleDateFormat gmtFormatter = new SimpleDateFormat("ZZZZ");
    gmtFormatter.setTimeZone(tz);
    String gmtString = gmtFormatter.format(now);
    BidiFormatter bidiFormatter = BidiFormatter.getInstance();
    Locale l = Locale.getDefault();
    boolean isRtl = TextUtils.getLayoutDirectionFromLocale(l) == View.LAYOUT_DIRECTION_RTL;
    gmtString = bidiFormatter.unicodeWrap(gmtString,
            isRtl ? TextDirectionHeuristics.RTL : TextDirectionHeuristics.LTR);

    if (!includeName) {
        return gmtString;
    }

    return gmtString;
}
 
Example 2
Source File: LatinIME.java    From simple-keyboard with Apache License 2.0 6 votes vote down vote up
@Override
public void onMovePointer(int steps) {
    if (mInputLogic.mConnection.hasCursorPosition()) {
        if (TextUtils.getLayoutDirectionFromLocale(mSettings.getCurrent().mLocale) == View.LAYOUT_DIRECTION_RTL)
            steps = -steps;

        final int end = mInputLogic.mConnection.getExpectedSelectionEnd() + steps;
        final int start = mInputLogic.mConnection.hasSelection() ? mInputLogic.mConnection.getExpectedSelectionStart() : end;
        mInputLogic.mConnection.setSelection(start, end);
    } else {
        for (; steps < 0; steps++)
            mInputLogic.sendDownUpKeyEvent(KeyEvent.KEYCODE_DPAD_LEFT);
        for (; steps > 0; steps--)
            mInputLogic.sendDownUpKeyEvent(KeyEvent.KEYCODE_DPAD_RIGHT);
    }
}
 
Example 3
Source File: Formatter.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
private static String bidiWrap(@NonNull Context context, String source) {
    final Locale locale = localeFromContext(context);
    if (TextUtils.getLayoutDirectionFromLocale(locale) == View.LAYOUT_DIRECTION_RTL) {
        return BidiFormatter.getInstance(true /* RTL*/).unicodeWrap(source);
    } else {
        return source;
    }
}
 
Example 4
Source File: LocalizationUtils.java    From android-chromium with BSD 2-Clause "Simplified" License 5 votes vote down vote up
/**
 * @return true if the system default layout direction is RTL, false otherwise.
 *         RTL layout support is from Jelly Bean MR1, so if the version is lower
 *         than that, it is always false.
 */
public static boolean isSystemLayoutDirectionRtl() {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
        return TextUtils.getLayoutDirectionFromLocale(Locale.getDefault())
                == View.LAYOUT_DIRECTION_RTL;
    }
    return false;
}
 
Example 5
Source File: LocalizationUtils.java    From android-chromium with BSD 2-Clause "Simplified" License 5 votes vote down vote up
/**
 * @return true if the system default layout direction is RTL, false otherwise.
 *         RTL layout support is from Jelly Bean MR1, so if the version is lower
 *         than that, it is always false.
 */
public static boolean isSystemLayoutDirectionRtl() {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
        return TextUtils.getLayoutDirectionFromLocale(Locale.getDefault())
                == View.LAYOUT_DIRECTION_RTL;
    }
    return false;
}
 
Example 6
Source File: IntroScreenSlidePagerAdapter.java    From QuickLyric with GNU General Public License v3.0 5 votes vote down vote up
public IntroScreenSlidePagerAdapter(final Activity activity) {
    super(activity.getFragmentManager());
    this.mActivity = activity;
    mPager = mActivity.findViewById(R.id.pager);
    mPager.setOnTouchListener(exitTouchListener);
    if (Build.VERSION.SDK_INT >= 17)
        rightToLeft = TextUtils.getLayoutDirectionFromLocale(Locale.getDefault()) == 1;
    if (rightToLeft) {
        List<Integer> list = Arrays.asList(colors);
        Collections.reverse(list);
        colors = (Integer[]) list.toArray();
    }
    ImageButton pagerArrow = mActivity.findViewById(R.id.pager_arrow);
    Button okButton = mActivity.findViewById(R.id.pager_ok);
    okButton.setOnClickListener(v -> {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT && !Tutorial_4.nlEnabled) {
            final ViewGroup nlFrame = activity.findViewById(R.id.NL_frame);
            final ValueAnimator colorAnimation = ValueAnimator.ofObject(new ArgbEvaluator(),
                    Color.parseColor("#30000000"), Color.parseColor("#80FFFFFF"));
            colorAnimation.addUpdateListener(animation -> nlFrame.setBackgroundColor((int) animation.getAnimatedValue()));
            colorAnimation.setInterpolator(new LinearOutSlowInInterpolator());
            colorAnimation.setRepeatCount(3);
            colorAnimation.setRepeatMode(ValueAnimator.REVERSE);
            colorAnimation.setDuration(650L);
            colorAnimation.start();
        } else if (!hasClicked) {
            exitAction();
            hasClicked = true;
        }
    });
    pagerArrow.setOnClickListener(v -> nextAction());
}
 
Example 7
Source File: SearchPagerAdapter.java    From QuickLyric with GNU General Public License v3.0 5 votes vote down vote up
public SearchPagerAdapter(FragmentManager fm, SearchActivity searchActivity, String query) {
    super(fm);
    this.searchQuery = query;
    this.searchTabs = searchActivity;
    if (Build.VERSION.SDK_INT >= 17)
        this.rightToLeft = TextUtils.getLayoutDirectionFromLocale(Locale.getDefault()) == 1;
}
 
Example 8
Source File: TimeDurationPicker.java    From PhoneProfilesPlus with Apache License 2.0 5 votes vote down vote up
private void applyLeftMargin(int margin, View... targetViews) {
    for (View view : targetViews) {
        final LinearLayout.LayoutParams params = (LinearLayout.LayoutParams) view.getLayoutParams();

        boolean isLeftToRight = TextUtils.getLayoutDirectionFromLocale(Locale.getDefault())==View.LAYOUT_DIRECTION_LTR;
        if (isLeftToRight)
            params.setMargins(margin, params.topMargin, params.rightMargin, params.bottomMargin);
        else
            params.setMargins(params.leftMargin, params.topMargin, margin, params.bottomMargin);

        view.setLayoutParams(params);
    }
}
 
Example 9
Source File: ViewUtils.java    From AndroidUtilCode with Apache License 2.0 5 votes vote down vote up
/**
 * Return whether horizontal layout direction of views are from Right to Left.
 *
 * @return {@code true}: yes<br>{@code false}: no
 */
public static boolean isLayoutRtl() {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
        Locale primaryLocale;
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
            primaryLocale = Utils.getApp().getResources().getConfiguration().getLocales().get(0);
        } else {
            primaryLocale = Utils.getApp().getResources().getConfiguration().locale;
        }
        return TextUtils.getLayoutDirectionFromLocale(primaryLocale) == View.LAYOUT_DIRECTION_RTL;
    }
    return false;
}
 
Example 10
Source File: DialpadView.java    From android-dialer with Apache License 2.0 5 votes vote down vote up
public DialpadView(Context context, AttributeSet attrs, int defStyle) {
  super(context, attrs, defStyle);

  mTranslateDistance =
      getResources().getDimensionPixelSize(R.dimen.dialpad_key_button_translate_y);

  mIsLandscape =
      getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE;
  mIsRtl = Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1 &&
      TextUtils.getLayoutDirectionFromLocale(Locale.getDefault()) == View.LAYOUT_DIRECTION_RTL;
}
 
Example 11
Source File: RtlHelper.java    From Virtualview-Android with MIT License 5 votes vote down vote up
/**
 * In Rtl env or not.
 * @return true if in Rtl env.
 */
public static boolean isRtl() {
    if (sEnable && Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
        return View.LAYOUT_DIRECTION_RTL == TextUtils.getLayoutDirectionFromLocale(Locale.getDefault());
    }

    return false;
}
 
Example 12
Source File: MainActivity.java    From AmazingAvatar with MIT License 5 votes vote down vote up
private void translationView(float offset) {
	float newAvatarSize = Utils.convertDpToPixel(
			EXPAND_AVATAR_SIZE_DP - (EXPAND_AVATAR_SIZE_DP - COLLAPSED_AVATAR_SIZE_DP) * offset,
			this);
	float expandAvatarSize = Utils.convertDpToPixel(EXPAND_AVATAR_SIZE_DP, this);
	float xAvatarOffset =
			(mSpacePoint[0] - mAvatarPoint[0] - (expandAvatarSize - newAvatarSize) / 2f) *
					offset;
	// If avatar center in vertical, just half `(expandAvatarSize - newAvatarSize)`
	float yAvatarOffset =
			(mSpacePoint[1] - mAvatarPoint[1] - (expandAvatarSize - newAvatarSize)) * offset;
	mAvatarImageView.getLayoutParams().width = Math.round(newAvatarSize);
	mAvatarImageView.getLayoutParams().height = Math.round(newAvatarSize);
	mAvatarImageView.setTranslationX(xAvatarOffset);
	mAvatarImageView.setTranslationY(yAvatarOffset);

	float newTextSize =
			mTitleTextSize - (mTitleTextSize - mToolbarTextView.getTextSize()) * offset;
	Paint paint = new Paint(mTitleTextView.getPaint());
	paint.setTextSize(newTextSize);
	float newTextWidth = Utils.getTextWidth(paint, mTitleTextView.getText().toString());
	paint.setTextSize(mTitleTextSize);
	float originTextWidth = Utils.getTextWidth(paint, mTitleTextView.getText().toString());
	// If rtl should move title view to end of view.
	boolean isRTL = TextUtils.getLayoutDirectionFromLocale(Locale.getDefault()) ==
			View.LAYOUT_DIRECTION_RTL ||
			mContainerView.getLayoutDirection() == View.LAYOUT_DIRECTION_RTL;
	float xTitleOffset = ((mToolbarTextPoint[0] + (isRTL ? mToolbarTextView.getWidth() : 0)) -
			(mTitleTextViewPoint[0] + (isRTL ? mTitleTextView.getWidth() : 0)) -
			(mToolbarTextView.getWidth() > newTextWidth ?
					(originTextWidth - newTextWidth) / 2f : 0)) * offset;
	float yTitleOffset = (mToolbarTextPoint[1] - mTitleTextViewPoint[1]) * offset;
	mTitleTextView.setTextSize(TypedValue.COMPLEX_UNIT_PX, newTextSize);
	mTitleTextView.setTranslationX(xTitleOffset);
	mTitleTextView.setTranslationY(yTitleOffset);
}
 
Example 13
Source File: ScrollPageHelper.java    From YCBanner with Apache License 2.0 4 votes vote down vote up
private boolean isRtl() {
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR1) {
        return false;
    }
    return TextUtils.getLayoutDirectionFromLocale(Locale.getDefault()) == View.LAYOUT_DIRECTION_RTL;
}
 
Example 14
Source File: ScrollPageHelper.java    From YCRefreshView with Apache License 2.0 4 votes vote down vote up
private boolean isRtl() {
    return TextUtils.getLayoutDirectionFromLocale(
            Locale.getDefault()) == View.LAYOUT_DIRECTION_RTL;
}
 
Example 15
Source File: DefaultMediaController.java    From GiraffePlayer2 with Apache License 2.0 4 votes vote down vote up
private boolean isRtl() {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
        return TextUtils.getLayoutDirectionFromLocale(Locale.getDefault()) == View.LAYOUT_DIRECTION_RTL;
    }
    return false;
}
 
Example 16
Source File: TimePickerClockDelegate.java    From android_9.0.0_r45 with Apache License 2.0 4 votes vote down vote up
private void setAmPmStart(boolean isAmPmAtStart) {
    final RelativeLayout.LayoutParams params =
            (RelativeLayout.LayoutParams) mAmPmLayout.getLayoutParams();
    if (params.getRule(RelativeLayout.RIGHT_OF) != 0
            || params.getRule(RelativeLayout.LEFT_OF) != 0) {
        // Horizontal mode, with AM/PM appearing to left/right of hours and minutes.
        final boolean isAmPmAtLeft;
        if (TextUtils.getLayoutDirectionFromLocale(mLocale) == View.LAYOUT_DIRECTION_LTR) {
            isAmPmAtLeft = isAmPmAtStart;
        } else {
            isAmPmAtLeft = !isAmPmAtStart;
        }
        if (mIsAmPmAtLeft == isAmPmAtLeft) {
            // AM/PM is already at the correct location. No change needed.
            return;
        }

        if (isAmPmAtLeft) {
            params.removeRule(RelativeLayout.RIGHT_OF);
            params.addRule(RelativeLayout.LEFT_OF, mHourView.getId());
        } else {
            params.removeRule(RelativeLayout.LEFT_OF);
            params.addRule(RelativeLayout.RIGHT_OF, mMinuteView.getId());
        }
        mIsAmPmAtLeft = isAmPmAtLeft;
    } else if (params.getRule(RelativeLayout.BELOW) != 0
            || params.getRule(RelativeLayout.ABOVE) != 0) {
        // Vertical mode, with AM/PM appearing to top/bottom of hours and minutes.
        if (mIsAmPmAtTop == isAmPmAtStart) {
            // AM/PM is already at the correct location. No change needed.
            return;
        }

        final int otherViewId;
        if (isAmPmAtStart) {
            otherViewId = params.getRule(RelativeLayout.BELOW);
            params.removeRule(RelativeLayout.BELOW);
            params.addRule(RelativeLayout.ABOVE, otherViewId);
        } else {
            otherViewId = params.getRule(RelativeLayout.ABOVE);
            params.removeRule(RelativeLayout.ABOVE);
            params.addRule(RelativeLayout.BELOW, otherViewId);
        }

        // Switch the top and bottom paddings on the other view.
        final View otherView = mRadialTimePickerHeader.findViewById(otherViewId);
        final int top = otherView.getPaddingTop();
        final int bottom = otherView.getPaddingBottom();
        final int left = otherView.getPaddingLeft();
        final int right = otherView.getPaddingRight();
        otherView.setPadding(left, bottom, right, top);

        mIsAmPmAtTop = isAmPmAtStart;
    }

    mAmPmLayout.setLayoutParams(params);
}
 
Example 17
Source File: ScrollPageHelper.java    From YCScrollPager with Apache License 2.0 4 votes vote down vote up
private boolean isRtl() {
    return TextUtils.getLayoutDirectionFromLocale(
            Locale.getDefault()) == View.LAYOUT_DIRECTION_RTL;
}
 
Example 18
Source File: Configuration.java    From android_9.0.0_r45 with Apache License 2.0 3 votes vote down vote up
/**
 * Set the layout direction from a Locale.
 *
 * @param loc The Locale. If null will set the layout direction to
 * {@link View#LAYOUT_DIRECTION_LTR}. If not null will set it to the layout direction
 * corresponding to the Locale.
 *
 * @see View#LAYOUT_DIRECTION_LTR
 * @see View#LAYOUT_DIRECTION_RTL
 */
public void setLayoutDirection(Locale loc) {
    // There is a "1" difference between the configuration values for
    // layout direction and View constants for layout direction, just add "1".
    final int layoutDirection = 1 + TextUtils.getLayoutDirectionFromLocale(loc);
    screenLayout = (screenLayout&~SCREENLAYOUT_LAYOUTDIR_MASK)|
            (layoutDirection << SCREENLAYOUT_LAYOUTDIR_SHIFT);
}