android.util.LayoutDirection Java Examples
The following examples show how to use
android.util.LayoutDirection.
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: IconDrawable.java From edx-app-android with Apache License 2.0 | 6 votes |
@TargetApi(JELLY_BEAN_MR1) @CheckResult private boolean needMirroring() { if (isAutoMirrored()) { if (SDK_INT >= M) { return getLayoutDirection() == LayoutDirection.RTL; } // Since getLayoutDirection() is hidden prior to Marshmallow, we // will try to get the layout direction from the View, which we will // assume is set as the callback. As the setLayoutDirection() method // is also hidden, we can safely rely on the behaviour of the // platform Views to provide a correct replacement for the hidden // method. Callback callback = getCallback(); if (callback instanceof View) { return ((View) callback).getLayoutDirection() == LAYOUT_DIRECTION_RTL; } } return false; }
Example #2
Source File: FlowLayout.java From AndroidWallet with GNU General Public License v3.0 | 5 votes |
public FlowLayout(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); TypedArray ta = context.obtainStyledAttributes(attrs, R.styleable.TagFlowLayout); mGravity = ta.getInt(R.styleable.TagFlowLayout_tag_gravity, LEFT); int layoutDirection = TextUtilsCompat.getLayoutDirectionFromLocale(Locale.getDefault()); if (layoutDirection == LayoutDirection.RTL) { if (mGravity == LEFT) { mGravity = RIGHT; } else { mGravity = LEFT; } } ta.recycle(); }
Example #3
Source File: VectorDrawableCompat.java From VectorChildFinder with Apache License 2.0 | 5 votes |
@SuppressLint({"NewApi", "WrongConstant"}) private boolean needMirroring() { if (Build.VERSION.SDK_INT < 17) { return false; } else { return isAutoMirrored() && getLayoutDirection() == LayoutDirection.RTL; } }
Example #4
Source File: DrawableClickListener.java From adamant-android with GNU General Public License v3.0 | 5 votes |
@Override public boolean onTouch(View v, MotionEvent event) { if (!viewType.isInstance(v)) { return false; } EditText editableView = viewType.cast(v); if(editableView != null && event.getAction() == MotionEvent.ACTION_UP) { Drawable drawableStart = editableView.getCompoundDrawablesRelative()[DRAWABLE_START]; Drawable drawableEnd = editableView.getCompoundDrawablesRelative()[DRAWABLE_END]; if (drawableEnd == null && drawableStart == null) { return false; } boolean isStartClicked = false; boolean isEndClicked = false; int layoutDirection = editableView.getLayoutDirection(); if (layoutDirection == LayoutDirection.LTR) { isStartClicked = detectLeftClick(editableView, drawableStart, event); isEndClicked = detectRightClick(editableView, drawableStart, event); } else { isStartClicked = detectRightClick(editableView, drawableStart, event); isEndClicked = detectLeftClick(editableView, drawableStart, event); } if (isStartClicked) { onClickStartDrawable(v); return true; } if (isEndClicked) { onClickEndDrawable(v); return true; } } return false; }
Example #5
Source File: OverlayPanelTextViewInflater.java From AndroidChromium with Apache License 2.0 | 5 votes |
/** * Adjusts the given {@code TextView} to have a layout direction that matches the UI direction * when the contents of the view is considered short (based on SHORTNESS_FACTOR). * @param textView The text view to adjust. */ @SuppressLint("RtlHardcoded") private void adjustViewDirection(TextView textView) { float textWidth = textView.getPaint().measureText(textView.getText().toString()); if (textWidth < SHORTNESS_FACTOR * textView.getWidth()) { int layoutDirection = LocalizationUtils.isLayoutRtl() ? LayoutDirection.RTL : LayoutDirection.LTR; if (layoutDirection == LayoutDirection.LTR) textView.setGravity(Gravity.LEFT); if (layoutDirection == LayoutDirection.RTL) textView.setGravity(Gravity.RIGHT); } }
Example #6
Source File: FlowLayout.java From FlowLayout with Apache License 2.0 | 5 votes |
public FlowLayout(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); TypedArray ta = context.obtainStyledAttributes(attrs, R.styleable.TagFlowLayout); mGravity = ta.getInt(R.styleable.TagFlowLayout_tag_gravity, LEFT); int layoutDirection = TextUtilsCompat.getLayoutDirectionFromLocale(Locale.getDefault()); if (layoutDirection == LayoutDirection.RTL) { if (mGravity == LEFT) { mGravity = RIGHT; } else { mGravity = LEFT; } } ta.recycle(); }
Example #7
Source File: OverlayPanelTextViewInflater.java From 365browser with Apache License 2.0 | 5 votes |
/** * Adjusts the given {@code TextView} to have a layout direction that matches the UI direction * when the contents of the view is considered short (based on SHORTNESS_FACTOR). * @param textView The text view to adjust. */ @SuppressLint("RtlHardcoded") private void adjustViewDirection(TextView textView) { float textWidth = textView.getPaint().measureText(textView.getText().toString()); if (textWidth < SHORTNESS_FACTOR * textView.getWidth()) { int layoutDirection = LocalizationUtils.isLayoutRtl() ? LayoutDirection.RTL : LayoutDirection.LTR; if (layoutDirection == LayoutDirection.LTR) textView.setGravity(Gravity.LEFT); if (layoutDirection == LayoutDirection.RTL) textView.setGravity(Gravity.RIGHT); } }
Example #8
Source File: ReactToolbarManager.java From react-native-GPay with MIT License | 4 votes |
@ReactProp(name = "rtl") public void setRtl(ReactToolbar view, boolean rtl) { view.setLayoutDirection(rtl ? LayoutDirection.RTL : LayoutDirection.LTR); }
Example #9
Source File: DrawableContainerCompat.java From MaterialProgressBar with Apache License 2.0 | 4 votes |
@SuppressLint("WrongConstant") @TargetApi(Build.VERSION_CODES.M) private boolean needsMirroring() { return isAutoMirrored() && getLayoutDirection() == LayoutDirection.RTL; }
Example #10
Source File: LayerDrawable.java From Carbon with Apache License 2.0 | 4 votes |
private void updateLayerBounds(Rect bounds) { int padL = 0; int padT = 0; int padR = 0; int padB = 0; final Rect outRect = mTmpOutRect; int layoutDirection = LayoutDirection.LTR; if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) layoutDirection = getLayoutDirection(); final boolean nest = mLayerState.mPaddingMode == PADDING_MODE_NEST; final ChildDrawable[] array = mLayerState.mChildren; final int N = mLayerState.mNum; for (int i = 0; i < N; i++) { final ChildDrawable r = array[i]; final Drawable d = r.mDrawable; if (d == null) { continue; } final Rect container = mTmpContainer; container.set(d.getBounds()); // Take the resolved layout direction into account. If start / end // padding are defined, they will be resolved (hence overriding) to // left / right or right / left depending on the resolved layout // direction. If start / end padding are not defined, use the // left / right ones. final int insetL, insetR; if (layoutDirection == LayoutDirection.RTL) { insetL = r.mInsetE == UNDEFINED_INSET ? r.mInsetL : r.mInsetE; insetR = r.mInsetS == UNDEFINED_INSET ? r.mInsetR : r.mInsetS; } else { insetL = r.mInsetS == UNDEFINED_INSET ? r.mInsetL : r.mInsetS; insetR = r.mInsetE == UNDEFINED_INSET ? r.mInsetR : r.mInsetE; } // Establish containing region based on aggregate padding and // requested insets for the current layer. container.set(bounds.left + insetL + padL, bounds.top + r.mInsetT + padT, bounds.right - insetR - padR, bounds.bottom - r.mInsetB - padB); // Apply resolved gravity to drawable based on resolved size. final int gravity = resolveGravity(r.mGravity, r.mWidth, r.mHeight, d.getIntrinsicWidth(), d.getIntrinsicHeight()); final int w = r.mWidth < 0 ? d.getIntrinsicWidth() : r.mWidth; final int h = r.mHeight < 0 ? d.getIntrinsicHeight() : r.mHeight; GravityCompat.apply(gravity, w, h, container, outRect, layoutDirection); d.setBounds(outRect); if (nest) { padL += mPaddingL[i]; padR += mPaddingR[i]; padT += mPaddingT[i]; padB += mPaddingB[i]; } } }
Example #11
Source File: LayerDrawable.java From Carbon with Apache License 2.0 | 4 votes |
@Override public int getIntrinsicWidth() { int width = -1; int padL = 0; int padR = 0; final boolean nest = mLayerState.mPaddingMode == PADDING_MODE_NEST; final ChildDrawable[] array = mLayerState.mChildren; final int N = mLayerState.mNum; for (int i = 0; i < N; i++) { final ChildDrawable r = array[i]; if (r.mDrawable == null) { continue; } // Take the resolved layout direction into account. If start / end // padding are defined, they will be resolved (hence overriding) to // left / right or right / left depending on the resolved layout // direction. If start / end padding are not defined, use the // left / right ones. final int insetL, insetR; int layoutDirection = LayoutDirection.LTR; if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) layoutDirection = getLayoutDirection(); if (layoutDirection == LayoutDirection.RTL) { insetL = r.mInsetE == UNDEFINED_INSET ? r.mInsetL : r.mInsetE; insetR = r.mInsetS == UNDEFINED_INSET ? r.mInsetR : r.mInsetS; } else { insetL = r.mInsetS == UNDEFINED_INSET ? r.mInsetL : r.mInsetS; insetR = r.mInsetE == UNDEFINED_INSET ? r.mInsetR : r.mInsetE; } final int minWidth = r.mWidth < 0 ? r.mDrawable.getIntrinsicWidth() : r.mWidth; final int w = minWidth + insetL + insetR + padL + padR; if (w > width) { width = w; } if (nest) { padL += mPaddingL[i]; padR += mPaddingR[i]; } } return width; }
Example #12
Source File: Utils.java From MaterialScrollBar with Apache License 2.0 | 2 votes |
/** * * @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; }