Example usage for android.content.res Configuration getLayoutDirection

List of usage examples for android.content.res Configuration getLayoutDirection

Introduction

In this page you can find the example usage for android.content.res Configuration getLayoutDirection.

Prototype

public int getLayoutDirection() 

Source Link

Document

Return the layout direction.

Usage

From source file:Main.java

/**
 * @see Configuration#getLayoutDirection()
 *//* w w w . jav  a2  s .co  m*/
public static int getLayoutDirection(Configuration configuration) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
        return configuration.getLayoutDirection();
    } else {
        // All layouts are LTR before JB MR1.
        return View.LAYOUT_DIRECTION_LTR;
    }
}

From source file:barqsoft.footballscores.utils.Utility.java

/**
 * Check if we are on a device in RTL mode
 * http://stackoverflow.com/questions/14402329/disable-actionbar-rtl-direction
 *
 * @return boolean//w  w w .j a va  2 s .c  o m
 */
public static boolean isRtlMode(Context context) {
    boolean rtl = false;
    // check direction depending on the api level device supports
    if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
        // if device supports API 17 or higher we can use getLayoutDirection
        Configuration config = context.getResources().getConfiguration();
        if (config.getLayoutDirection() == View.LAYOUT_DIRECTION_RTL) {
            rtl = true;
        }
    } else {
        // else get language codes
        Set<String> lang = new HashSet<>();
        lang.add("ar");
        lang.add("dv");
        lang.add("fa");
        lang.add("ha");
        lang.add("he");
        lang.add("iw");
        lang.add("ji");
        lang.add("ps");
        lang.add("ur");
        lang.add("yi");
        Set<String> RTL = Collections.unmodifiableSet(lang);
        Locale locale = Locale.getDefault();
        rtl = RTL.contains(locale.getLanguage());
    }
    return rtl;
}

From source file:com.pdftron.pdf.utils.Utils.java

public static boolean isRtlLayout(Context context) {
    if (isJellyBeanMR1()) {
        Configuration config = context.getResources().getConfiguration();
        if (config.getLayoutDirection() == View.LAYOUT_DIRECTION_RTL) {
            return true;
        }//  w ww .  j  av a 2s .co  m
    }
    return false;
}

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 ww  .  ja  v  a 2 s .  co m*/

    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:com.example.client.activity.imported.FlexibleSpaceWithImageWithViewPagerTabActivity.java

@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1)
private void setPivotXToTitle(View view) {
    final TextView mTitleView = (TextView) view.findViewById(R.id.title);
    Configuration config = getResources().getConfiguration();
    if (Build.VERSION_CODES.JELLY_BEAN_MR1 <= Build.VERSION.SDK_INT
            && config.getLayoutDirection() == View.LAYOUT_DIRECTION_RTL) {
        ViewHelper.setPivotX(mTitleView, view.findViewById(android.R.id.content).getWidth());
    } else {/*w  w  w .  ja  v  a  2  s .  c  o m*/
        ViewHelper.setPivotX(mTitleView, 0);
    }
}

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

protected boolean isRTL() {
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR1) {
        return false;
    }/*from  w w w  . jav a 2 s.c om*/
    Configuration config = getResources().getConfiguration();
    return config.getLayoutDirection() == View.LAYOUT_DIRECTION_RTL;
}

From source file:com.github.andrewlord1990.materialandroid.component.textfield.PasswordEditText.java

@TargetApi(VERSION_CODES.JELLY_BEAN_MR1)
private boolean isLeftToRightLayoutDirection() {
    Configuration config = getResources().getConfiguration();
    return config.getLayoutDirection() != View.LAYOUT_DIRECTION_RTL;
}

From source file:de.azapps.mirakel.custom_views.TaskDetailDueReminder.java

@SuppressLint("NewApi")
@Override/*from  ww  w  . j  a  v  a  2  s.  c o  m*/
protected void updateView() {
    final Drawable reminderImg = this.context.getResources()
            .getDrawable(android.R.drawable.ic_menu_recent_history);
    reminderImg.setBounds(0, 1, 42, 42);
    final Drawable dueImg = this.context.getResources().getDrawable(android.R.drawable.ic_menu_today);
    dueImg.setBounds(0, 1, 42, 42);
    final Configuration config = this.context.getResources().getConfiguration();
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1
            && config.getLayoutDirection() == View.LAYOUT_DIRECTION_RTL) {
        this.taskReminder.setCompoundDrawables(null, null, reminderImg, null);
        this.taskDue.setCompoundDrawables(null, null, dueImg, null);
    } else {
        this.taskReminder.setCompoundDrawables(reminderImg, null, null, null);
        this.taskDue.setCompoundDrawables(dueImg, null, null, null);
    }
    setRecurringImage(this.recurrenceDue, this.task.getRecurrenceId());
    setRecurringImage(this.recurrenceReminder, this.task.getRecurringReminderId());
    setupRecurrenceDrawable(this.recurrenceDue, this.task.getRecurrence());
    setupRecurrenceDrawable(this.recurrenceReminder, this.task.getRecurringReminder());
    setDue();
    setReminder();
}

From source file:com.aaa.activity.main.MainActivity.java

@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1)
private void setPivotXToTitle(View view) {
    final EditText mTitleView = (EditText) view.findViewById(R.id.title);
    Configuration config = getResources().getConfiguration();
    if (Build.VERSION_CODES.JELLY_BEAN_MR1 <= Build.VERSION.SDK_INT
            && config.getLayoutDirection() == View.LAYOUT_DIRECTION_RTL) {
        ViewHelper.setPivotX(mTitleView, view.findViewById(android.R.id.content).getWidth());
    } else {//from   www  . j  av  a 2  s .co  m
        ViewHelper.setPivotX(mTitleView, -1);
    }
}

From source file:com.example.client.activity.imported.FlexibleSpaceWithImageWithViewPagerTab2Activity.java

@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1)
private void setPivotXToTitle() {
    Configuration config = getResources().getConfiguration();
    if (Build.VERSION_CODES.JELLY_BEAN_MR1 <= Build.VERSION.SDK_INT
            && config.getLayoutDirection() == View.LAYOUT_DIRECTION_RTL) {
        ViewHelper.setPivotX(mTitleView, findViewById(android.R.id.content).getWidth());
    } else {/* w  w w.j a va 2s .  c om*/
        ViewHelper.setPivotX(mTitleView, 0);
    }
}