Example usage for android.text TextUtils getLayoutDirectionFromLocale

List of usage examples for android.text TextUtils getLayoutDirectionFromLocale

Introduction

In this page you can find the example usage for android.text TextUtils getLayoutDirectionFromLocale.

Prototype

public static int getLayoutDirectionFromLocale(Locale locale) 

Source Link

Document

Return the layout direction for a given Locale

Usage

From source file:Main.java

public static int getLayoutDirectionFromLocale(@Nullable Locale locale) {
    return TextUtils.getLayoutDirectionFromLocale(locale);
}

From source file:com.sonymobile.androidapp.gridcomputing.fragments.WizardMainFragment.java

/**
 * Verifies if current displayed language is Right-to-left.
 *
 * @return true if current displayed language is Right-to-left, false
 * otherwise./*from  w  ww  .  j av  a 2  s.  com*/
 */
public static boolean isRtl() {
    return TextUtils.getLayoutDirectionFromLocale(Locale.getDefault()) == View.LAYOUT_DIRECTION_RTL;
}

From source file:com.geecko.QuickLyric.adapter.SearchPagerAdapter.java

public SearchPagerAdapter(FragmentManager fm, SearchActivity searchActivity, String query) {
    super(fm);/*from w w  w  .  j a v  a2 s  .  c om*/
    this.searchQuery = query;
    this.searchTabs = searchActivity;
    if (Build.VERSION.SDK_INT >= 17)
        this.rightToLeft = TextUtils.getLayoutDirectionFromLocale(Locale.getDefault()) == 1;
}

From source file:com.android.settings.widget.RtlCompatibleViewPager.java

/**
 * Get a "RTL friendly" index. If the locale is LTR, the index is returned as is.
 * Otherwise it's transformed so view pager can render views using the new index for RTL. For
 * example, the second view will be rendered to the left of first view.
 *
 * @param index The logical index.//  w w  w  .  ja va  2  s . co m
 */
public int getRtlAwareIndex(int index) {
    // Using TextUtils rather than View.getLayoutDirection() because LayoutDirection is not
    // defined until onMeasure, and this is called before then.
    if (TextUtils.getLayoutDirectionFromLocale(Locale.getDefault()) == View.LAYOUT_DIRECTION_RTL) {
        return getAdapter().getCount() - index - 1;
    }
    return index;
}

From source file:com.android.deskclock.widget.RtlViewPager.java

/**
 * Get a "RTL friendly" index. If the locale is LTR, the index is returned as is.
 * Otherwise it's transformed so view pager can render views using the new index for RTL. For
 * example, the second view will be rendered to the left of first view.
 *
 * @param index The logical index./*from  ww w  .  java2  s .co m*/
 */
public int getRtlAwareIndex(int index) {
    if (TextUtils.getLayoutDirectionFromLocale(Locale.getDefault()) == View.LAYOUT_DIRECTION_RTL) {
        return getAdapter().getCount() - index - 1;
    }
    return index;
}

From source file:com.onyx.deskclock.deskclock.widget.RtlViewPager.java

/**
 * Get a "RTL friendly" index. If the locale is LTR, the index is returned as is.
 * Otherwise it's transformed so view pager can render views using the new index for RTL. For
 * example, the second view will be rendered to the left of first view.
 *
 * @param index The logical index.//from   w w w . j ava 2 s .  c  o  m
 */
public int getRtlAwareIndex(int index) {
    if (Build.VERSION.SDK_INT >= 17) {
        if (TextUtils.getLayoutDirectionFromLocale(Locale.getDefault()) == View.LAYOUT_DIRECTION_RTL) {
            return getAdapter().getCount() - index - 1;
        }
    } else {
        if (TextUtilsCompat.getLayoutDirectionFromLocale(Locale.getDefault()) == View.LAYOUT_DIRECTION_RTL) {
            return getAdapter().getCount() - index - 1;
        }
    }
    return index;
}

From source file:com.appsimobile.appsii.module.home.SunriseDrawable.java

public SunriseDrawable(Context context) {

    mContext = context;/*from  ww w  .jav  a  2  s.  c o  m*/

    Resources res = context.getResources();
    final TypedArray a = context.obtainStyledAttributes(new int[] { R.attr.colorPrimary, R.attr.colorAccent,
            R.attr.colorPrimaryDark, R.attr.appsiHomeWidgetPrimaryColor, });

    int primaryColor = a.getColor(0, Color.BLACK);
    int accentColor = a.getColor(1, Color.BLACK);
    int primaryColorDark = a.getColor(2, Color.BLACK);
    int textColor = a.getColor(3, Color.BLACK);
    a.recycle();

    mIsRtl = TextUtils.getLayoutDirectionFromLocale(Locale.getDefault()) == View.LAYOUT_DIRECTION_RTL;

    float density = res.getDisplayMetrics().density;
    int sunBounds = (int) (density * 16);
    mTopOffset = (int) (density * 12);
    mLeftOffset = (int) (density * 24);
    mRightOffset = (int) (density * 24);
    mBottomOffset = (int) (density * 24);
    mDotRadius = (int) (density * 2);

    mSunImage = mContext.getResources().getDrawable(R.drawable.ic_weather_clear);
    mSunImage.setBounds(0, 0, sunBounds, sunBounds);

    mArcPaint = new Paint();
    mArcPaint.setColor(primaryColorDark);
    mArcPaint.setStyle(Paint.Style.STROKE);
    mArcPaint.setAntiAlias(true);

    mArcFillPaint = new Paint();
    mArcFillPaint.setColor(primaryColor);
    mArcFillPaint.setAlpha(64);
    mArcFillPaint.setStyle(Paint.Style.FILL);
    mArcFillPaint.setAntiAlias(true);

    mLinePaint = new Paint();
    mLinePaint.setColor(textColor);
    mLinePaint.setAlpha(128);
    mLinePaint.setStyle(Paint.Style.STROKE);

    mDotPaint = new Paint();
    mDotPaint.setStyle(Paint.Style.FILL);
    mDotPaint.setColor(primaryColorDark);
    mDotPaint.setAntiAlias(true);
}

From source file:com.android.mms.ui.ConversationListItem.java

private CharSequence formatMessage() {
    final int color = android.R.styleable.Theme_textColorSecondary;
    String from = mConversation.getRecipients().formatNames(", ");
    if (MessageUtils.isWapPushNumber(from)) {
        String[] mAddresses = from.split(":");
        from = mAddresses[mContext.getResources().getInteger(R.integer.wap_push_address_index)];
    }//w  w  w .j  a  v a2  s. c  o m

    /**
     * Add boolean to know that the "from" haven't the Arabic and '+'.
     * Make sure the "from" display normally for RTL.
     */
    boolean isEnName = false;
    boolean isLayoutRtl = (TextUtils
            .getLayoutDirectionFromLocale(Locale.getDefault()) == View.LAYOUT_DIRECTION_RTL);
    if (isLayoutRtl && from != null) {
        if (from.length() >= 1) {
            Pattern pattern = Pattern.compile("[^-]+");
            Matcher matcher = pattern.matcher(from);
            isEnName = matcher.matches();
            if (isEnName && from.charAt(0) != '\u202D') {
                from = "\u202D" + from + "\u202C";
            }
        }
    }

    SpannableStringBuilder buf = new SpannableStringBuilder(from);

    if (mConversation.getMessageCount() > 1) {
        int before = buf.length();
        if (isLayoutRtl && isEnName) {
            buf.insert(1, mConversation.getMessageCount() + " ");
            buf.setSpan(new ForegroundColorSpan(mContext.getResources().getColor(R.color.message_count_color)),
                    1, buf.length() - before, Spannable.SPAN_INCLUSIVE_EXCLUSIVE);
        } else {
            buf.append(mContext.getResources().getString(R.string.message_count_format,
                    mConversation.getMessageCount()));
            buf.setSpan(new ForegroundColorSpan(mContext.getResources().getColor(R.color.message_count_color)),
                    before, buf.length(), Spannable.SPAN_INCLUSIVE_EXCLUSIVE);
        }
    }
    if (mConversation.hasDraft()) {
        if (isLayoutRtl && isEnName) {
            int before = buf.length();
            buf.insert(1, '\u202E' + mContext.getResources().getString(R.string.draft_separator) + '\u202C');
            buf.setSpan(new ForegroundColorSpan(mContext.getResources().getColor(R.drawable.text_color_black)),
                    1, buf.length() - before + 1, Spannable.SPAN_INCLUSIVE_EXCLUSIVE);
            before = buf.length();
            int size;
            buf.insert(1, mContext.getResources().getString(R.string.has_draft));
            size = android.R.style.TextAppearance_Small;
            buf.setSpan(new TextAppearanceSpan(mContext, size), 1, buf.length() - before + 1,
                    Spannable.SPAN_INCLUSIVE_EXCLUSIVE);
            buf.setSpan(new ForegroundColorSpan(mContext.getResources().getColor(R.drawable.text_color_red)), 1,
                    buf.length() - before + 1, Spannable.SPAN_INCLUSIVE_EXCLUSIVE);
        } else {
            buf.append(mContext.getResources().getString(R.string.draft_separator));
            int before = buf.length();
            int size;
            buf.append(mContext.getResources().getString(R.string.has_draft));
            size = android.R.style.TextAppearance_Small;
            buf.setSpan(new TextAppearanceSpan(mContext, size, color), before, buf.length(),
                    Spannable.SPAN_INCLUSIVE_EXCLUSIVE);
            buf.setSpan(new ForegroundColorSpan(mContext.getResources().getColor(R.drawable.text_color_red)),
                    before, buf.length(), Spannable.SPAN_INCLUSIVE_EXCLUSIVE);
        }
    }

    // Unread messages are shown in bold
    if (mConversation.hasUnreadMessages()) {
        buf.setSpan(STYLE_BOLD, 0, buf.length(), Spannable.SPAN_INCLUSIVE_EXCLUSIVE);
    }
    return buf;
}

From source file:org.chromium.ChromeI18n.java

@SuppressLint("NewApi")
private static boolean isRtlLocale(Locale l) {
    if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.JELLY_BEAN_MR1) {
        return View.LAYOUT_DIRECTION_RTL == TextUtils.getLayoutDirectionFromLocale(l);
    }/*from ww  w  .  java  2  s .co m*/
    String lang = l.getLanguage().toLowerCase(Locale.ENGLISH);
    return (lang.equals("ar") || lang.equals("fa") || lang.equals("ur") || lang.equals("ps")
            || lang.equals("syr") || lang.equals("dv") || lang.equals("he") || lang.equals("yi"));
}

From source file:com.android.contacts.common.list.ContactListItemView.java

static public final PhotoPosition getDefaultPhotoPosition(boolean opposite) {
    final Locale locale = Locale.getDefault();
    final int layoutDirection = TextUtils.getLayoutDirectionFromLocale(locale);
    switch (layoutDirection) {
    case View.LAYOUT_DIRECTION_RTL:
        return (opposite ? PhotoPosition.LEFT : PhotoPosition.RIGHT);
    case View.LAYOUT_DIRECTION_LTR:
    default:/*from w w w .  ja v  a  2s  .  c  o  m*/
        return (opposite ? PhotoPosition.RIGHT : PhotoPosition.LEFT);
    }
}