Example usage for android.view View LAYOUT_DIRECTION_RTL

List of usage examples for android.view View LAYOUT_DIRECTION_RTL

Introduction

In this page you can find the example usage for android.view View LAYOUT_DIRECTION_RTL.

Prototype

int LAYOUT_DIRECTION_RTL

To view the source code for android.view View LAYOUT_DIRECTION_RTL.

Click Source Link

Document

Horizontal layout direction of this view is from Right to Left.

Usage

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  ww  .j av a 2  s .  c om*/

    /**
     * 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.safegees.safegees.gui.fragment.ProfileContactFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

    View view = inflater.inflate(R.layout.fragment_profile_contact, container, false);

    ArrayList<Friend> friends = SafegeesDAO.getInstance(view.getContext()).getMutualFriends();

    Friend friend = friends.get(position);

    //this.getActivity().onBackPressed();

    //ImageButton closeContact = (ImageButton) view.findViewById(R.id.close_contact);
    //closeContact.setOnClickListener(this);

    imageView = (ImageView) view.findViewById(R.id.result);
    editName = (EditText) view.findViewById(R.id.editName);
    editSurname = (EditText) view.findViewById(R.id.editSurname);
    editEmail = (EditText) view.findViewById(R.id.editEmail);
    editPhone = (EditText) view.findViewById(R.id.editPhone);
    editTopic = (TextView) view.findViewById(R.id.editTopic);

    LinearLayout llName = (LinearLayout) view.findViewById(R.id.lay_name);
    LinearLayout llSurname = (LinearLayout) view.findViewById(R.id.lay_surname);
    LinearLayout llMail = (LinearLayout) view.findViewById(R.id.lay_mail);
    LinearLayout llPhone = (LinearLayout) view.findViewById(R.id.lay_phone);
    //LinearLayout llBio = (LinearLayout) view.findViewById(R.id.lay_topic);

    //Show arrows to reveal user if there are more contacts
    ImageView arrowLeft = (ImageView) view.findViewById(R.id.contact_left);
    ImageView arrowRight = (ImageView) view.findViewById(R.id.contact_right);

    //Change arrows if Language is LTR (Ar or FA)
    //And reveal the accurate arrow
    if (TextUtilsCompat.getLayoutDirectionFromLocale(Locale.getDefault()) == View.LAYOUT_DIRECTION_RTL) {
        arrowLeft.setBackgroundResource(R.drawable.ic_chevron_right_black_24dp);
        arrowRight.setBackgroundResource(R.drawable.ic_chevron_left_black_24dp);
        if (position == 0)
            arrowRight.setVisibility(View.INVISIBLE);
        if (position == friends.size() - 1)
            arrowLeft.setVisibility(View.INVISIBLE);
    } else {/*from  w w  w. j  a v  a  2 s. co  m*/
        if (position == 0)
            arrowLeft.setVisibility(View.INVISIBLE);
        if (position == friends.size() - 1)
            arrowRight.setVisibility(View.INVISIBLE);
    }

    if (friend != null) {
        this.editName.setText(friend.getName() != null ? friend.getName() : "");
        this.editSurname.setText(friend.getSurname() != null ? friend.getSurname() : "");
        this.editEmail.setText(friend.getPublicEmail() != null ? friend.getPublicEmail() : "");
        this.editPhone.setText(friend.getPhoneNumber() != null ? friend.getPhoneNumber() : "");
        this.editTopic.setText(friend.getBio() != null ? "\"" + friend.getBio() + "\"" : "");
        ViewGroup.LayoutParams params = editTopic.getLayoutParams();
        params.height = ViewGroup.LayoutParams.WRAP_CONTENT;
        editTopic.setLayoutParams(params);
    }

    if (friend.getName() == null || friend.getName().equals(""))
        llName.setVisibility(View.GONE);
    if (friend.getSurname() == null || friend.getSurname().equals(""))
        llSurname.setVisibility(View.GONE);
    if (friend.getPublicEmail() == null || friend.getPublicEmail().equals(""))
        llMail.setVisibility(View.GONE);
    if (friend.getPhoneNumber() == null || friend.getPhoneNumber().equals(""))
        llPhone.setVisibility(View.GONE);
    if (friend.getBio() == null || friend.getBio().equals(""))
        editTopic.setVisibility(View.GONE);

    //Add image from friend
    if (friend.getPublicEmail() != null) {
        Bitmap bitmap = ImageController.getContactImageBitmap(getContext(), friend.getPublicEmail());
        if (bitmap != null)
            this.imageView.setImageBitmap(bitmap);
    }

    // Inflate the layout for this fragment
    return view;
}

From source file:com.android.settings.PreviewSeekBarPreferenceFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    final View root = super.onCreateView(inflater, container, savedInstanceState);
    final ViewGroup listContainer = (ViewGroup) root.findViewById(android.R.id.list_container);
    listContainer.removeAllViews();/*from  w w w.ja v a2s.c  om*/

    final View content = inflater.inflate(mActivityLayoutResId, listContainer, false);
    listContainer.addView(content);

    mLabel = (TextView) content.findViewById(R.id.current_label);

    // The maximum SeekBar value always needs to be non-zero. If there's
    // only one available value, we'll handle this by disabling the
    // seek bar.
    final int max = Math.max(1, mEntries.length - 1);

    final LabeledSeekBar seekBar = (LabeledSeekBar) content.findViewById(R.id.seek_bar);
    seekBar.setLabels(mEntries);
    seekBar.setMax(max);
    seekBar.setProgress(mInitialIndex);
    seekBar.setOnSeekBarChangeListener(new onPreviewSeekBarChangeListener());

    mSmaller = content.findViewById(R.id.smaller);
    mSmaller.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            final int progress = seekBar.getProgress();
            if (progress > 0) {
                seekBar.setProgress(progress - 1, true);
            }
        }
    });

    mLarger = content.findViewById(R.id.larger);
    mLarger.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            final int progress = seekBar.getProgress();
            if (progress < seekBar.getMax()) {
                seekBar.setProgress(progress + 1, true);
            }
        }
    });

    if (mEntries.length == 1) {
        // The larger and smaller buttons will be disabled when we call
        // setPreviewLayer() later in this method.
        seekBar.setEnabled(false);
    }

    final Context context = getContext();
    final Configuration origConfig = context.getResources().getConfiguration();
    final boolean isLayoutRtl = origConfig.getLayoutDirection() == View.LAYOUT_DIRECTION_RTL;
    Configuration[] configurations = new Configuration[mEntries.length];
    for (int i = 0; i < mEntries.length; ++i) {
        configurations[i] = createConfig(origConfig, i);
    }

    mPreviewPager = (ViewPager) content.findViewById(R.id.preview_pager);
    mPreviewPagerAdapter = new PreviewPagerAdapter(context, isLayoutRtl, mPreviewSampleResIds, configurations);
    mPreviewPager.setAdapter(mPreviewPagerAdapter);
    mPreviewPager.setCurrentItem(isLayoutRtl ? mPreviewSampleResIds.length - 1 : 0);
    mPreviewPager.addOnPageChangeListener(mPreviewPageChangeListener);

    mPageIndicator = (DotsPageIndicator) content.findViewById(R.id.page_indicator);
    if (mPreviewSampleResIds.length > 1) {
        mPageIndicator.setViewPager(mPreviewPager);
        mPageIndicator.setVisibility(View.VISIBLE);
        mPageIndicator.setOnPageChangeListener(mPageIndicatorPageChangeListener);
    } else {
        mPageIndicator.setVisibility(View.GONE);
    }

    setPreviewLayer(mInitialIndex, false);
    return root;
}

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  w w  w .  j  a  v  a 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:io.github.marktony.espresso.component.FastScroller.java

public FastScroller(Context context, FastScrollRecyclerView recyclerView, AttributeSet attrs) {

    Resources resources = context.getResources();

    mRecyclerView = recyclerView;//w ww  .  j a v a2s  .  c om
    mPopup = new FastScrollPopup(resources, recyclerView);

    mThumbHeight = DensityUtil.dip2px(context, 48);
    mWidth = DensityUtil.dip2px(context, 8);

    mTouchInset = DensityUtil.dip2px(context, -24);

    mThumb = new Paint(Paint.ANTI_ALIAS_FLAG);
    mTrack = new Paint(Paint.ANTI_ALIAS_FLAG);

    TypedArray typedArray = context.getTheme().obtainStyledAttributes(attrs, R.styleable.FastScrollRecyclerView,
            0, 0);
    try {
        mAutoHideEnabled = typedArray.getBoolean(R.styleable.FastScrollRecyclerView_fastScrollAutoHide, true);
        mAutoHideDelay = typedArray.getInteger(R.styleable.FastScrollRecyclerView_fastScrollAutoHideDelay,
                DEFAULT_AUTO_HIDE_DELAY);

        int trackColor = typedArray.getColor(R.styleable.FastScrollRecyclerView_fastScrollTrackColor,
                0x1f000000);
        int thumbColor = typedArray.getColor(R.styleable.FastScrollRecyclerView_fastScrollThumbColor,
                ContextCompat.getColor(context, R.color.colorPrimary));
        int popupBgColor = typedArray.getColor(R.styleable.FastScrollRecyclerView_fastScrollPopupBgColor,
                ContextCompat.getColor(context, R.color.colorPrimary));
        int popupTextColor = typedArray.getColor(R.styleable.FastScrollRecyclerView_fastScrollPopupTextColor,
                0xffffffff);
        int popupTextSize = typedArray.getDimensionPixelSize(
                R.styleable.FastScrollRecyclerView_fastScrollPopupTextSize, DensityUtil.dip2sp(context, 56));
        int popupBackgroundSize = typedArray.getDimensionPixelSize(
                R.styleable.FastScrollRecyclerView_fastScrollPopupBackgroundSize,
                DensityUtil.dip2px(context, 88));

        mTrack.setColor(trackColor);
        mThumb.setColor(thumbColor);
        mPopup.setBgColor(popupBgColor);
        mPopup.setTextColor(popupTextColor);
        mPopup.setTextSize(popupTextSize);
        mPopup.setBackgroundSize(popupBackgroundSize);
    } finally {
        typedArray.recycle();
    }

    mHideRunnable = new Runnable() {
        @Override
        public void run() {
            if (!mIsDragging) {
                if (mAutoHideAnimator != null) {
                    mAutoHideAnimator.cancel();
                }
                mAutoHideAnimator = ObjectAnimator.ofInt(FastScroller.this, "offsetX",
                        (mRecyclerView.getResources().getConfiguration()
                                .getLayoutDirection() == View.LAYOUT_DIRECTION_RTL ? -1 : 1) * mWidth);
                mAutoHideAnimator.setInterpolator(new FastOutLinearInInterpolator());
                mAutoHideAnimator.setDuration(200);
                mAutoHideAnimator.start();
            }
        }
    };

    mRecyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() {
        @Override
        public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
            super.onScrolled(recyclerView, dx, dy);
            show();
        }
    });

    if (mAutoHideEnabled) {
        postAutoHideDelayed();
    }
}

From source file:com.metinkale.prayerapp.BaseActivity.java

@Override
public void setContentView(int res) {
    super.setContentView(R.layout.activity_base);

    final Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    if (toolbar != null) {
        setSupportActionBar(toolbar);/*ww  w.  j  av  a 2  s  .  co  m*/
        toolbar.setBackgroundResource(R.color.colorPrimary);
        toolbar.setNavigationIcon(
                MaterialDrawableBuilder.with(this).setIcon(MaterialDrawableBuilder.IconValue.VIEW_HEADLINE)
                        .setColor(Color.WHITE).setToActionbarSize().build());
    }

    ViewGroup content = (ViewGroup) findViewById(R.id.basecontent);
    mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer);
    View v = LayoutInflater.from(this).inflate(res, content, false);
    content.addView(v, new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
    mNav = (ListView) mDrawerLayout.findViewById(R.id.base_nav);
    ArrayAdapter<String> list = new ArrayAdapter<String>(this, R.layout.drawer_list_item,
            getResources().getStringArray(R.array.dropdown)) {
        @NonNull
        @Override
        public View getView(int pos, View v, @NonNull ViewGroup p) {
            v = super.getView(pos, v, p);
            if (pos == mNavPos) {
                ((TextView) v).setTypeface(null, Typeface.BOLD);
            }

            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1
                    && getResources().getConfiguration().getLayoutDirection() == View.LAYOUT_DIRECTION_RTL) {
                ((TextView) v).setCompoundDrawablesWithIntrinsicBounds(0, 0, ICONS[pos], 0);
            } else {
                ((TextView) v).setCompoundDrawablesWithIntrinsicBounds(ICONS[pos], 0, 0, 0);
            }

            return v;
        }
    };
    mNav.setAdapter(list);
    mNav.setOnItemClickListener(new MyClickListener());

    final String title = list.getItem(mNavPos);

    mDrawerLayout.post(new Runnable() {
        @Override
        public void run() {
            if (toolbar != null) {
                toolbar.setTitle(title);
            }
        }
    });

    if (getIntent().getBooleanExtra("anim", false)) {

        mDrawerLayout.openDrawer(GravityCompat.START);
        mDrawerLayout.post(new Runnable() {

            @Override
            public void run() {
                mDrawerLayout.closeDrawers();

            }
        });

    }
}

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.  j  a  v  a  2  s  .c  o m*/
        return (opposite ? PhotoPosition.RIGHT : PhotoPosition.LEFT);
    }
}

From source file:org.smssecure.smssecure.util.ViewUtil.java

@SuppressLint("RtlHardcoded")
public static void setTextViewGravityStart(final @NonNull TextView textView, @NonNull Context context) {
    if (VERSION.SDK_INT >= VERSION_CODES.JELLY_BEAN_MR1) {
        if (DynamicLanguage.getLayoutDirection(context) == View.LAYOUT_DIRECTION_RTL) {
            textView.setGravity(Gravity.RIGHT);
        } else {/*from ww w  . j a v a2s.  c om*/
            textView.setGravity(Gravity.LEFT);
        }
    }
}

From source file:org.smssecure.smssecure.util.ViewUtil.java

public static void mirrorIfRtl(View view, Context context) {
    if (VERSION.SDK_INT >= VERSION_CODES.JELLY_BEAN_MR1
            && DynamicLanguage.getLayoutDirection(context) == View.LAYOUT_DIRECTION_RTL) {
        view.setScaleX(-1.0f);/*from   w ww. j a v a2  s .  c  om*/
    }
}

From source file:at.jclehner.rxdroid.ui.DialogLike.java

@TargetApi(17)
private boolean isRtlLanguage() {
    if (Build.VERSION.SDK_INT < 17)
        return false;

    return getActivity().getResources().getConfiguration().getLayoutDirection() == View.LAYOUT_DIRECTION_RTL;
}