android.content.res.Configuration.getLayoutDirection()方法的使用及代码示例

x33g5p2x  于2022-01-18 转载在 其他  
字(8.7k)|赞(0)|评价(0)|浏览(135)

本文整理了Java中android.content.res.Configuration.getLayoutDirection()方法的一些代码示例,展示了Configuration.getLayoutDirection()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Configuration.getLayoutDirection()方法的具体详情如下:
包路径:android.content.res.Configuration
类名称:Configuration
方法名:getLayoutDirection

Configuration.getLayoutDirection介绍

暂无

代码示例

代码示例来源:origin: facebook/litho

@TargetApi(JELLY_BEAN_MR1)
private static int getLayoutDirection(Context context) {
 return context.getResources().getConfiguration().getLayoutDirection();
}

代码示例来源:origin: wdullaer/MaterialDateTimePicker

@Override
public void attachToRecyclerView(@Nullable RecyclerView recyclerView)
    throws IllegalStateException {
  if (recyclerView != null) {
    if ((gravity == Gravity.START || gravity == Gravity.END)
        && Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
      isRtlHorizontal
          = recyclerView.getContext().getResources().getConfiguration()
          .getLayoutDirection() == View.LAYOUT_DIRECTION_RTL;
    }
    if (listener != null) {
      recyclerView.addOnScrollListener(mScrollListener);
    }
  }
  super.attachToRecyclerView(recyclerView);
}

代码示例来源:origin: square/assertj-android

@TargetApi(JELLY_BEAN_MR1)
public ConfigurationAssert hasLayoutDirection(@ViewLayoutDirection int layoutDirection) {
 isNotNull();
 int actualLayoutDirection = actual.getLayoutDirection();
 //noinspection ResourceType
 assertThat(actualLayoutDirection) //
   .overridingErrorMessage("Expected layout direction to be <%s> but was <%s>.",
     layoutDirectionToString(layoutDirection),
     layoutDirectionToString(actualLayoutDirection)) //
   .isEqualTo(layoutDirection);
 return this;
}

代码示例来源:origin: timusus/RecyclerView-FastScroll

@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1)
  public static boolean isRtl(Resources res) {
    return (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) &&
        (res.getConfiguration().getLayoutDirection() == View.LAYOUT_DIRECTION_RTL);
  }
}

代码示例来源:origin: sjwall/MaterialTapTargetPrompt

final int layoutDirection = resources.getConfiguration().getLayoutDirection();
if (text != null && layoutDirection == View.LAYOUT_DIRECTION_RTL
    && new Bidi(text.toString(), Bidi.DIRECTION_DEFAULT_LEFT_TO_RIGHT).isRightToLeft())

代码示例来源:origin: sjwall/MaterialTapTargetPrompt

.getLayoutDirection() == View.LAYOUT_DIRECTION_RTL;

代码示例来源:origin: sjwall/MaterialTapTargetPrompt

@RequiresApi(api = Build.VERSION_CODES.JELLY_BEAN_MR1)
@Test
public void testIsRtlFirstCharacterNotRtl()
{
  ReflectionHelpers.setStaticField(Build.VERSION.class, "SDK_INT", Build.VERSION_CODES.JELLY_BEAN_MR1);
  final Resources resources = mock(Resources.class);
  final Configuration configuration = mock(Configuration.class);
  when(resources.getConfiguration()).thenReturn(configuration);
  when(configuration.getLayoutDirection()).thenReturn(View.LAYOUT_DIRECTION_LTR);
  final Layout layout = mock(Layout.class);
  when(layout.isRtlCharAt(0)).thenReturn(false);
  when(layout.getAlignment()).thenReturn(Layout.Alignment.ALIGN_NORMAL);
  assertFalse(PromptUtils.isRtlText(layout, resources));
}

代码示例来源:origin: sjwall/MaterialTapTargetPrompt

@RequiresApi(api = Build.VERSION_CODES.JELLY_BEAN_MR1)
@Test
public void testIsRtlFirstCharacterNotRtlOppositePreJellyBeanMR1()
{
  ReflectionHelpers.setStaticField(Build.VERSION.class, "SDK_INT", Build.VERSION_CODES.JELLY_BEAN_MR1);
  final Resources resources = mock(Resources.class);
  final Configuration configuration = mock(Configuration.class);
  when(resources.getConfiguration()).thenReturn(configuration);
  when(configuration.getLayoutDirection()).thenReturn(View.LAYOUT_DIRECTION_RTL);
  final Layout layout = mock(Layout.class);
  when(layout.isRtlCharAt(0)).thenReturn(false);
  when(layout.getAlignment()).thenReturn(Layout.Alignment.ALIGN_NORMAL);
  assertTrue(PromptUtils.isRtlText(layout, resources));
}

代码示例来源:origin: heinrichreimer/material-intro

private void updateButtonBackPosition() {
  float realPosition = position + positionOffset;
  float yOffset = getResources().getDimensionPixelSize(R.dimen.mi_y_offset);
  if (realPosition < 1 && buttonBackFunction == BUTTON_BACK_FUNCTION_BACK) {
    //Hide back button
    miButtonBack.setTranslationY((1 - positionOffset) * yOffset);
  } else if (realPosition < adapter.getCount() - 2) {
    //Reset
    miButtonBack.setTranslationY(0);
    miButtonBack.setTranslationX(0);
  } else if (realPosition < adapter.getCount() - 1) {
    //Scroll away skip button
    if (buttonBackFunction == BUTTON_BACK_FUNCTION_SKIP) {
      boolean rtl = Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1 && getResources().getConfiguration().getLayoutDirection() ==
          View.LAYOUT_DIRECTION_RTL;
      miButtonBack.setTranslationX(positionOffset * (rtl ? 1 : -1) * miPager.getWidth());
    } else {
      miButtonBack.setTranslationX(0);
    }
  } else {
    //Keep skip button scrolled away, hide next button
    if (buttonBackFunction == BUTTON_BACK_FUNCTION_SKIP) {
      boolean rtl = Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1 && getResources().getConfiguration().getLayoutDirection() ==
          View.LAYOUT_DIRECTION_RTL;
      miButtonBack.setTranslationX((rtl ? 1 : -1) * miPager.getWidth());
    } else {
      miButtonBack.setTranslationY(positionOffset * yOffset);
    }
  }
}

代码示例来源:origin: jaredrummler/MaterialSpinner

/**
 * Check if layout direction is RTL
 *
 * @param context the current context
 * @return {@code true} if the layout direction is right-to-left
 */
static boolean isRtl(Context context) {
 return Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1
   && context.getResources().getConfiguration().getLayoutDirection() == View.LAYOUT_DIRECTION_RTL;
}

代码示例来源:origin: turing-tech/MaterialScrollBar

/**
 *
 * @param c Context
 * @return True if the current layout is RTL.
 */
static boolean isRightToLeft(Context c) {
  return Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT &&
      c.getResources().getConfiguration().getLayoutDirection() == LayoutDirection.RTL;
}

代码示例来源:origin: philliphsu/NumberPadTimePicker

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;
    }
  }
}

代码示例来源:origin: fookwood/Launcher3

@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1)
public static boolean isRtl(Resources res) {
  return ATLEAST_JB_MR1 &&
      (res.getConfiguration().getLayoutDirection() == View.LAYOUT_DIRECTION_RTL);
}

代码示例来源:origin: smuyyh/SprintNBA

@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1)
private boolean isLeftToRight() {
  // If we are pre JB assume always LTR
  if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR1) {
    return true;
  }
  Configuration config = getResources().getConfiguration();
  return !(config.getLayoutDirection() == View.LAYOUT_DIRECTION_RTL);
}

代码示例来源:origin: michael-rapp/AndroidPreferenceActivity

/**
 * Returns, whether the activity uses a right-to-left (RTL) layout, or not.
 *
 * @return True, if the activity uses a RTL layout, false otherwise
 */
private boolean isRtlLayoutUsed() {
  return Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1 &&
      getResources().getConfiguration().getLayoutDirection() == View.LAYOUT_DIRECTION_RTL;
}

代码示例来源:origin: esafirm/android-image-picker

public static Drawable getArrowIcon(Context context) {
  final int backResourceId;
  if (Build.VERSION.SDK_INT >= 17 && context.getResources().getConfiguration().getLayoutDirection() == View.LAYOUT_DIRECTION_RTL) {
    // For right-to-left layouts, pick the drawable that points to the right (forward).
    backResourceId = R.drawable.ef_ic_arrow_forward;
  } else {
    // For left-to-right layouts, pick the drawable that points to the left (back).
    backResourceId = R.drawable.ef_ic_arrow_back;
  }
  return ContextCompat.getDrawable(context.getApplicationContext(), backResourceId);
}

代码示例来源:origin: sjwall/MaterialTapTargetPrompt

final Configuration configuration = mock(Configuration.class);
when(resources.getConfiguration()).thenReturn(configuration);
when(configuration.getLayoutDirection()).thenReturn(View.LAYOUT_DIRECTION_RTL);

代码示例来源:origin: Catrobat/Paintroid

private void setLayoutDirection() {
  if (VERSION.SDK_INT > Build.VERSION_CODES.N_MR1) {
    Configuration config = getResources().getConfiguration();
    getWindow().getDecorView().setLayoutDirection(config.getLayoutDirection());
  }
}

代码示例来源:origin: braintree/android-card-form

private void setupRTL() {
    if (SDK_INT >= JELLY_BEAN_MR1) {
      if (getResources().getConfiguration().getLayoutDirection() == View.LAYOUT_DIRECTION_RTL) {
        setTextDirection(View.TEXT_DIRECTION_LTR);
        setGravity(Gravity.END);
      }
    }
  }
}

代码示例来源:origin: Catrobat/Paintroid

@Test
  public void testFarsiNumberFormatOfSizeSpinner() throws Exception {
    assertEquals(Locale.getDefault().getDisplayLanguage(), FARSILOCALE.getDisplayLanguage());
    assertEquals(View.LAYOUT_DIRECTION_RTL, getConfiguration().getLayoutDirection());
    assertTrue(checkTextDirection(Locale.getDefault().getDisplayName()));

    selectTool(ToolType.TEXT);
    onView(withId(R.id.pocketpaint_text_tool_dialog_spinner_text_size)).perform(click());

    onView(withIndex(withId(android.R.id.text1), 0)).check(matches(withText("۲۰px")));
    onView(withIndex(withId(android.R.id.text1), 1)).check(matches(withText("۳۰px")));
    onView(withIndex(withId(android.R.id.text1), 2)).check(matches(withText("۴۰px")));
  }
}

相关文章