Java Code Examples for androidx.core.view.ViewCompat#setLayoutDirection()

The following examples show how to use androidx.core.view.ViewCompat#setLayoutDirection() . 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: BaseDynamicCoordinatorLayoutTest.java    From material-components-android with Apache License 2.0 6 votes vote down vote up
protected ViewAction setLayoutDirection(final int layoutDir) {
  return new ViewAction() {
    @Override
    public Matcher<View> getConstraints() {
      return any(View.class);
    }

    @Override
    public String getDescription() {
      return "Sets layout direction";
    }

    @Override
    public void perform(UiController uiController, View view) {
      uiController.loopMainThreadUntilIdle();

      ViewCompat.setLayoutDirection(view, layoutDir);

      uiController.loopMainThreadUntilIdle();
    }
  };
}
 
Example 2
Source File: TestUtilsActions.java    From material-components-android with Apache License 2.0 6 votes vote down vote up
/** Sets layout direction on the view. */
public static ViewAction setLayoutDirection(final int layoutDirection) {
  return new ViewAction() {
    @Override
    public Matcher<View> getConstraints() {
      return isDisplayed();
    }

    @Override
    public String getDescription() {
      return "set layout direction";
    }

    @Override
    public void perform(UiController uiController, View view) {
      uiController.loopMainThreadUntilIdle();

      ViewCompat.setLayoutDirection(view, layoutDirection);

      uiController.loopMainThreadUntilIdle();
    }
  };
}
 
Example 3
Source File: TabLayout.java    From Carbon with Apache License 2.0 6 votes vote down vote up
private void initPagerTabStrip(AttributeSet attrs, @AttrRes int defStyleAttr, @StyleRes int defStyleRes) {
    int layoutDirection = ViewCompat.getLayoutDirection(this);
    ViewCompat.setLayoutDirection(this, ViewCompat.LAYOUT_DIRECTION_LTR);
    content = new LinearLayout(getContext());
    ViewCompat.setLayoutDirection(content, layoutDirection);
    addView(content, LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);

    TypedArray a = getContext().obtainStyledAttributes(attrs, R.styleable.TabLayout, defStyleAttr, defStyleRes);

    setIndicatorHeight(a.getDimension(R.styleable.TabLayout_carbon_indicatorWidth, 2));
    setFixed(a.getBoolean(R.styleable.TabLayout_carbon_fixedTabs, true));
    itemFactory = ItemComponent::new;

    a.recycle();

    setHorizontalFadingEdgeEnabled(false);
    setHorizontalScrollBarEnabled(false);

    initTabs();
}
 
Example 4
Source File: CustomInputStyleSettingsFragment.java    From openboard with GNU General Public License v3.0 5 votes vote down vote up
@Override
public View onCreateView(final LayoutInflater inflater, final ViewGroup container,
        final Bundle savedInstanceState) {
    final View view = super.onCreateView(inflater, container, savedInstanceState);
    // For correct display in RTL locales, we need to set the layout direction of the
    // fragment's top view.
    ViewCompat.setLayoutDirection(view, ViewCompat.LAYOUT_DIRECTION_LOCALE);
    return view;
}
 
Example 5
Source File: SuggestionStripView.java    From openboard with GNU General Public License v3.0 5 votes vote down vote up
public void setLayoutDirection(final boolean isRtlLanguage) {
    final int layoutDirection = isRtlLanguage ? ViewCompat.LAYOUT_DIRECTION_RTL
            : ViewCompat.LAYOUT_DIRECTION_LTR;
    ViewCompat.setLayoutDirection(mSuggestionStripView, layoutDirection);
    ViewCompat.setLayoutDirection(mSuggestionsStrip, layoutDirection);
    ViewCompat.setLayoutDirection(mImportantNoticeStrip, layoutDirection);
}
 
Example 6
Source File: CustomInputStyleSettingsFragment.java    From Android-Keyboard with Apache License 2.0 5 votes vote down vote up
@Override
public View onCreateView(final LayoutInflater inflater, final ViewGroup container,
        final Bundle savedInstanceState) {
    final View view = super.onCreateView(inflater, container, savedInstanceState);
    // For correct display in RTL locales, we need to set the layout direction of the
    // fragment's top view.
    ViewCompat.setLayoutDirection(view, ViewCompat.LAYOUT_DIRECTION_LOCALE);
    return view;
}
 
Example 7
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 8
Source File: VerticalSeekBar.java    From MTweaks-KernelAdiutorMOD with GNU General Public License v3.0 5 votes vote down vote up
private void initialize(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
    ViewCompat.setLayoutDirection(this, ViewCompat.LAYOUT_DIRECTION_LTR);

    if (attrs != null) {
        TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.VerticalSeekBar, defStyleAttr, defStyleRes);
        final int rotationAngle = a.getInteger(R.styleable.VerticalSeekBar_seekBarRotation, 0);
        if (isValidRotationAngle(rotationAngle)) {
            mRotationAngle = rotationAngle;
        }

        grxSetUPAdditionalOptions(a); // grx

        a.recycle();
    }
}
 
Example 9
Source File: CustomInputStyleSettingsFragment.java    From AOSP-Kayboard-7.1.2 with Apache License 2.0 5 votes vote down vote up
@Override
public View onCreateView(final LayoutInflater inflater, final ViewGroup container,
        final Bundle savedInstanceState) {
    final View view = super.onCreateView(inflater, container, savedInstanceState);
    // For correct display in RTL locales, we need to set the layout direction of the
    // fragment's top view.
    ViewCompat.setLayoutDirection(view, ViewCompat.LAYOUT_DIRECTION_LOCALE);
    return view;
}
 
Example 10
Source File: SuggestionStripView.java    From AOSP-Kayboard-7.1.2 with Apache License 2.0 5 votes vote down vote up
public void setLayoutDirection(final boolean isRtlLanguage) {
    final int layoutDirection = isRtlLanguage ? ViewCompat.LAYOUT_DIRECTION_RTL
            : ViewCompat.LAYOUT_DIRECTION_LTR;
    ViewCompat.setLayoutDirection(mSuggestionStripView, layoutDirection);
    ViewCompat.setLayoutDirection(mSuggestionsStrip, layoutDirection);
    ViewCompat.setLayoutDirection(mImportantNoticeStrip, layoutDirection);
}
 
Example 11
Source File: AdvanceDrawer6Activity.java    From Drawer-Behavior with MIT License 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_advance6);
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);

    FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
    fab.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
                    .setAction("Action", null).show();
        }
    });


    drawer = (AdvanceDrawerLayout) findViewById(R.id.drawer_layout);

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
        ViewCompat.setLayoutDirection(drawer, View.LAYOUT_DIRECTION_RTL);
    }

    ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
            this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
    drawer.addDrawerListener(toggle);
    toggle.syncState();

    NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
    navigationView.setNavigationItemSelectedListener(this);


    drawer.setViewScale(GravityCompat.START, 0.9f);
    drawer.setRadius(GravityCompat.START, 35);
    drawer.setViewElevation(GravityCompat.START, 20);


}
 
Example 12
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 13
Source File: VerticalSeekBar.java    From android-verticalseekbar with Apache License 2.0 5 votes vote down vote up
private void initialize(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
    ViewCompat.setLayoutDirection(this, ViewCompat.LAYOUT_DIRECTION_LTR);

    if (attrs != null) {
        TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.VerticalSeekBar, defStyleAttr, defStyleRes);
        final int rotationAngle = a.getInteger(R.styleable.VerticalSeekBar_seekBarRotation, 0);
        if (isValidRotationAngle(rotationAngle)) {
            mRotationAngle = rotationAngle;
        }
        a.recycle();
    }
}
 
Example 14
Source File: SimpleDialog.java    From material with Apache License 2.0 5 votes vote down vote up
private void initScrollView(){
    mScrollView = new InternalScrollView(getContext());
    mScrollView.setPadding(0, 0, 0, mContentPadding - mActionPadding);
    mScrollView.setClipToPadding(false);
    mScrollView.setFillViewport(true);
    mScrollView.setScrollBarStyle(View.SCROLLBARS_OUTSIDE_OVERLAY);
    ViewCompat.setLayoutDirection(mScrollView, View.LAYOUT_DIRECTION_INHERIT);
}
 
Example 15
Source File: SimpleDialog.java    From material with Apache License 2.0 5 votes vote down vote up
private void initListView(){
    mListView = new InternalListView(getContext());
    mListView.setDividerHeight(0);
    mListView.setCacheColorHint(0x00000000);
    mListView.setScrollBarStyle(View.SCROLLBARS_OUTSIDE_OVERLAY);
    mListView.setClipToPadding(false);
    mListView.setSelector(BlankDrawable.getInstance());
    mListView.setPadding(0, 0, 0, mContentPadding - mActionPadding);
    mListView.setVerticalFadingEdgeEnabled(false);
    mListView.setOverScrollMode(ListView.OVER_SCROLL_NEVER);
    ViewCompat.setLayoutDirection(mListView, ViewCompat.LAYOUT_DIRECTION_INHERIT);

    mAdapter = new InternalAdapter();
    mListView.setAdapter(mAdapter);
}
 
Example 16
Source File: Dialog.java    From material with Apache License 2.0 2 votes vote down vote up
/**
 * Set the layout direction of this Dialog
 * @param direction The layout direction value. Can be {@link View#LAYOUT_DIRECTION_LTR}, {@link View#LAYOUT_DIRECTION_RTL} or {@link View#LAYOUT_DIRECTION_LOCALE}
 * @return The Dialog for chaining methods.
 */
public Dialog layoutDirection(int direction){
    ViewCompat.setLayoutDirection(mCardView, direction);
    return this;
}