Java Code Examples for android.view.View#LAYOUT_DIRECTION_RTL

The following examples show how to use android.view.View#LAYOUT_DIRECTION_RTL . 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: RtlViewPager.java    From rtl-viewpager with Apache License 2.0 6 votes vote down vote up
@Override
public void onRtlPropertiesChanged(int layoutDirection) {
    super.onRtlPropertiesChanged(layoutDirection);
    int viewCompatLayoutDirection = layoutDirection == View.LAYOUT_DIRECTION_RTL ? ViewCompat.LAYOUT_DIRECTION_RTL : ViewCompat.LAYOUT_DIRECTION_LTR;
    if (viewCompatLayoutDirection != mLayoutDirection) {
        PagerAdapter adapter = super.getAdapter();
        int position = 0;
        if (adapter != null) {
            position = getCurrentItem();
        }
        mLayoutDirection = viewCompatLayoutDirection;
        if (adapter != null) {
            adapter.notifyDataSetChanged();
            setCurrentItem(position);
        }
    }
}
 
Example 2
Source File: DeviceProfile.java    From LB-Launcher with Apache License 2.0 6 votes vote down vote up
void updateFromConfiguration(Context context, Resources resources, int wPx, int hPx,
                             int awPx, int ahPx) {
    Configuration configuration = resources.getConfiguration();
    isLandscape = (configuration.orientation == Configuration.ORIENTATION_LANDSCAPE);
    isTablet = resources.getBoolean(R.bool.is_tablet);
    isLargeTablet = resources.getBoolean(R.bool.is_large_tablet);
    if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.JELLY_BEAN_MR1) {
        isLayoutRtl = (configuration.getLayoutDirection() == View.LAYOUT_DIRECTION_RTL);
    } else {
        isLayoutRtl = false;
    }
    widthPx = wPx;
    heightPx = hPx;
    availableWidthPx = awPx;
    availableHeightPx = ahPx;

    updateAvailableDimensions(context);
}
 
Example 3
Source File: PromptUtils.java    From styT with Apache License 2.0 6 votes vote down vote up
/**
 * Determines if the text in the supplied layout is displayed right to left.
 *
 * @param layout The layout to check.
 * @return True if the text in the supplied layout is displayed right to left. False otherwise.
 */
public static boolean isRtlText(@Nullable final Layout layout, @NonNull final Resources resources)
{
    boolean result = false;
    if (layout != null)
    {
        // Treat align opposite as right to left by default
        result = layout.getAlignment() == Layout.Alignment.ALIGN_OPPOSITE;
        // If the first character is a right to left character
        final boolean textIsRtl = layout.isRtlCharAt(0);
        // If the text and result are right to left then false otherwise use the textIsRtl value
        result = (!(result && textIsRtl) && !(!result && !textIsRtl)) || textIsRtl;
        if (!result && layout.getAlignment() == Layout.Alignment.ALIGN_NORMAL
                && Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1)
        {
            // If the layout and text are right to left and the alignment is normal then rtl
            result = resources.getConfiguration()
                        .getLayoutDirection() == View.LAYOUT_DIRECTION_RTL;
        }
        else if (layout.getAlignment() == Layout.Alignment.ALIGN_OPPOSITE && textIsRtl)
        {
            result = false;
        }
    }
    return result;
}
 
Example 4
Source File: Layout.java    From litho with Apache License 2.0 5 votes vote down vote up
@VisibleForTesting
static boolean isLayoutDirectionRTL(final Context context) {
  ApplicationInfo applicationInfo = context.getApplicationInfo();

  if ((SDK_INT >= JELLY_BEAN_MR1)
      && (applicationInfo.flags & ApplicationInfo.FLAG_SUPPORTS_RTL) != 0) {

    int layoutDirection = getLayoutDirection(context);
    return layoutDirection == View.LAYOUT_DIRECTION_RTL;
  }

  return false;
}
 
Example 5
Source File: MaterialProgressDrawable.java    From 365browser with Apache License 2.0 5 votes vote down vote up
private static boolean isLayoutRtl(View view) {
    if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.JELLY_BEAN_MR1) {
        return view.getLayoutDirection() == View.LAYOUT_DIRECTION_RTL;
    } else {
        // All layouts are LTR before JB MR1.
        return false;
    }
}
 
Example 6
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 7
Source File: ViewUtil.java    From deltachat-android with GNU General Public License v3.0 5 votes vote down vote up
@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 {
      textView.setGravity(Gravity.LEFT);
    }
  }
}
 
Example 8
Source File: MaterialMultiAutoCompleteTextView.java    From XERUNG with Apache License 2.0 5 votes vote down vote up
@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1)
private boolean isRTL() {
  if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR1) {
    return false;
  }
  Configuration config = getResources().getConfiguration();
  return config.getLayoutDirection() == View.LAYOUT_DIRECTION_RTL;
}
 
Example 9
Source File: ShowHidePasswordEditText.java    From PowerFileExplorer with GNU General Public License v3.0 5 votes vote down vote up
private boolean isLeftToRight() {
    // If we are pre JB assume always LTR
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR1) {
        return true;
    }

    // Other methods, seemingly broken when testing though.
    // return ViewCompat.getLayoutDirection(this) == ViewCompat.LAYOUT_DIRECTION_RTL
    // return !ViewUtils.isLayoutRtl(this);

    Configuration config = getResources().getConfiguration();
    return !(config.getLayoutDirection() == View.LAYOUT_DIRECTION_RTL);
}
 
Example 10
Source File: ViewUtils.java    From Android-Next with Apache License 2.0 5 votes vote down vote up
/**
 * 23      * Returns true if view's layout direction is right-to-left.
 * 24      *
 * 25      * @param view the View whose layout is being considered
 * 26
 */
public static boolean isLayoutRtl(View view) {
    if (Build.VERSION.SDK_INT >= VERSION_CODES.JELLY_BEAN_MR1) {
        return view.getLayoutDirection() == View.LAYOUT_DIRECTION_RTL;
    } else {
        // All layouts are LTR before JB MR1.
        return false;
    }
}
 
Example 11
Source File: FlexibleSpaceWithImageGridViewActivity.java    From Android-ObservableScrollView with Apache License 2.0 5 votes vote down vote up
@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 {
        ViewHelper.setPivotX(mTitleView, 0);
    }
}
 
Example 12
Source File: LocaleModel.java    From BottomSheetPickers with Apache License 2.0 5 votes vote down vote up
boolean isLayoutRtl() {
    if (Build.VERSION.SDK_INT >= 17) {
        return mAppContext.getResources().getConfiguration()
                .getLayoutDirection() == View.LAYOUT_DIRECTION_RTL;
    } else {
        // There is only LTR before SDK 17.
        return false;
    }
}
 
Example 13
Source File: UIUtils.java    From v2ex with Apache License 2.0 5 votes vote down vote up
@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1)
public static boolean isRtl(final Context context) {
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR1) {
        return false;
    } else {
        return context.getResources().getConfiguration().getLayoutDirection()
                == View.LAYOUT_DIRECTION_RTL;
    }
}
 
Example 14
Source File: BaseActivity.java    From prayer-times-android with Apache License 2.0 4 votes vote down vote up
protected boolean isRTL() {
    Configuration config = getResources().getConfiguration();
    return config.getLayoutDirection() == View.LAYOUT_DIRECTION_RTL;
}
 
Example 15
Source File: ViewUtils.java    From Transitions-Everywhere with Apache License 2.0 4 votes vote down vote up
@Override
public boolean isRtl(@NonNull View view) {
    return view.getLayoutDirection() == View.LAYOUT_DIRECTION_RTL;
}
 
Example 16
Source File: ButtonDropTarget.java    From LB-Launcher with Apache License 2.0 4 votes vote down vote up
private boolean isRtl() {
    return (getLayoutDirection() == View.LAYOUT_DIRECTION_RTL);
}
 
Example 17
Source File: ConversationItemSwipeCallback.java    From mollyim-android with GNU General Public License v3.0 4 votes vote down vote up
private static float getSignFromDirection(@NonNull View view) {
  return view.getLayoutDirection() == View.LAYOUT_DIRECTION_RTL ? -1f : 1f;
}
 
Example 18
Source File: ViewUtils.java    From BreadcrumbsView with MIT License 2 votes vote down vote up
/**
 * Check if the current language is RTL
 *
 * @param context Context
 * @return Result
 */
static boolean isRtlLayout(Context context) {
	return context.getResources().getConfiguration().getLayoutDirection() == View.LAYOUT_DIRECTION_RTL;
}
 
Example 19
Source File: BidiFormatter.java    From android_9.0.0_r45 with Apache License 2.0 2 votes vote down vote up
/**
 * Helper method to return true if the Locale directionality is RTL.
 *
 * @param locale The Locale whose directionality will be checked to be RTL or LTR
 * @return true if the {@code locale} directionality is RTL. False otherwise.
 */
private static boolean isRtlLocale(Locale locale) {
    return (TextUtils.getLayoutDirectionFromLocale(locale) == View.LAYOUT_DIRECTION_RTL);
}
 
Example 20
Source File: Configuration.java    From android_9.0.0_r45 with Apache License 2.0 2 votes vote down vote up
/**
 * Return the layout direction. Will be either {@link View#LAYOUT_DIRECTION_LTR} or
 * {@link View#LAYOUT_DIRECTION_RTL}.
 *
 * @return Returns {@link View#LAYOUT_DIRECTION_RTL} if the configuration
 * is {@link #SCREENLAYOUT_LAYOUTDIR_RTL}, otherwise {@link View#LAYOUT_DIRECTION_LTR}.
 */
public int getLayoutDirection() {
    return (screenLayout&SCREENLAYOUT_LAYOUTDIR_MASK) == SCREENLAYOUT_LAYOUTDIR_RTL
            ? View.LAYOUT_DIRECTION_RTL : View.LAYOUT_DIRECTION_LTR;
}