微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

android.util.LayoutDirection的实例源码

项目:Vafrinn    文件UrlContainer.java   
@SuppressLint("NewApi")
@Override
public void onRtlPropertiesChanged(int layoutDirection) {
    super.onRtlPropertiesChanged(layoutDirection);

    // Layout direction is driven by the text direction of the URL bar,so we just force
    // the path text view to match.
    switch (layoutDirection) {
        case LayoutDirection.LTR:
            ApiCompatibilityUtils.setTextDirection(mTrailingTextView,TEXT_DIRECTION_LTR);
            break;
        case LayoutDirection.RTL:
            ApiCompatibilityUtils.setTextDirection(mTrailingTextView,TEXT_DIRECTION_RTL);
            break;
        case LayoutDirection.LOCALE:
            ApiCompatibilityUtils.setTextDirection(mTrailingTextView,TEXT_DIRECTION_LOCALE);
            break;
        case LayoutDirection.INHERIT:
        default:
            ApiCompatibilityUtils.setTextDirection(mTrailingTextView,TEXT_DIRECTION_INHERIT);
            break;
    }
}
项目:edx-app-android    文件IconDrawable.java   
@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;
}
项目:fonticon    文件FontIconDrawable.java   
static int invoke(Drawable drawable) {
    if (sMethod != null) {
        try {
            Object result = sMethod.invoke(drawable);
            if (result instanceof Integer) {
                return (Integer) result;
            }
        } catch (Throwable ex) {
            if (SNAPSHOT) {
                Log.w(LOG_TAG,ex);
            }
        }
    }

    return LayoutDirection.LTR;
}
项目:chromium-for-android-56-debug-video    文件OverlayPanelTextViewInflater.java   
/**
 * 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);
    }
}
项目:Blog    文件GravityCompatHelper.java   
public void apply(RecyclerView.LayoutManager layoutManager,Rect outRect) {
    if (layoutManager instanceof GridLayoutManager &&
            layoutDirection == LayoutDirection.RTL) {
        int oldLeft = outRect.left;
        outRect.left = outRect.right;
        outRect.right = oldLeft;
    }
}
项目:SetupWizardLibCompat    文件Illustration.java   
private boolean shouldMirrorDrawable(Drawable drawable,int layoutDirection) {
    if (layoutDirection == LayoutDirection.RTL) {
        if (VERSION.SDK_INT >= VERSION_CODES.KITKAT) {
            return drawable.isAutoMirrored();
        } else if (VERSION.SDK_INT >= VERSION_CODES.JELLY_BEAN_MR1) {
            final int flags = getContext().getApplicationInfo().flags;
            //noinspection AndroidLintInlinedApi
            return (flags & ApplicationInfo.FLAG_SUPPORTS_RTL) != 0;
        }
    }
    return false;
}
项目:AndroidChromium    文件OverlayPanelTextViewInflater.java   
/**
 * 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);
    }
}
项目:365browser    文件OverlayPanelTextViewInflater.java   
/**
 * 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);
    }
}
项目:fonticon    文件FontIconDrawable.java   
protected boolean needMirroring() {
    //noinspection SimplifiableIfStatement
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) {
        //noinspection deprecation
        return isNeedMirroring();
    } else {
        return isAutoMirrored() && MethodGetLayoutDirection.invoke(this) == LayoutDirection.RTL;
    }
}
项目:RNLearn_Project1    文件ReactToolbarManager.java   
@ReactProp(name = "rtl")
public void setRtl(ReactToolbar view,boolean rtl) {
  view.setLayoutDirection(rtl ? LayoutDirection.RTL : LayoutDirection.LTR);
}
项目:ReactNativeSignatureExample    文件ReactToolbarManager.java   
@ReactProp(name = "rtl")
public void setRtl(ReactToolbar view,boolean rtl) {
  view.setLayoutDirection(rtl ? LayoutDirection.LTR : LayoutDirection.RTL);
}
项目:react-native-ibeacon-android    文件ReactToolbarManager.java   
@ReactProp(name = "rtl")
public void setRtl(ReactToolbar view,boolean rtl) {
  view.setLayoutDirection(rtl ? LayoutDirection.LTR : LayoutDirection.RTL);
}
项目:react-native-Box-loaders    文件ReactToolbarManager.java   
@ReactProp(name = "rtl")
public void setRtl(ReactToolbar view,boolean rtl) {
  view.setLayoutDirection(rtl ? LayoutDirection.LTR : LayoutDirection.RTL);
}
项目:Ironman    文件ReactToolbarManager.java   
@ReactProp(name = "rtl")
public void setRtl(ReactToolbar view,boolean rtl) {
  view.setLayoutDirection(rtl ? LayoutDirection.RTL : LayoutDirection.LTR);
}
项目:Carbon    文件LayerDrawable.java   
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];
        }
    }
}
项目:Carbon    文件LayerDrawable.java   
@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,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;
}
项目:talkback    文件KeyboardShortcutDialogPreferenceTest.java   
public void testOverwriteKeyComboDialogWithDefaultKeymap() {
    setKeymapToDefaultKeymap();

    KeyComboManager keyComboManager = TalkBackService.getInstance().getKeyComboManager();

    // Confirm that DPAD LEFT is used for navigate prevIoUs.
    assertEquals(getActivity().getString(R.string.keycombo_shortcut_navigate_prevIoUs),keyComboManager.getKeyComboModel().getKeyForKeyComboCode(
                    KeyComboManager.getKeyComboCode(
                            KeyComboModel.NO_MODIFIER,KeyEvent.KEYCODE_DPAD_LEFT)));

    startTalkBackKeyboardShortcutPreferencesActivity();
    assertNotNull(mPreferencesActivity);

    KeyboardShortcutDialogPreference dialogPreference =
            openNavigateNextDialogPreference(mPreferencesActivity);

    // Set ALT + DPAD LEFT.
    assertAssignedKeyComboText(KeyEvent.Meta_ALT_ON,KeyEvent.KEYCODE_DPAD_RIGHT,keyComboManager,dialogPreference);
    sendKeyEventDownAndUp(KeyEvent.Meta_ALT_ON,KeyEvent.KEYCODE_DPAD_LEFT,keyComboManager);
    assertAssignedKeyComboText(KeyEvent.Meta_ALT_ON,dialogPreference);

    // Try to set it. Overwrite confirm dialog will come up.
    sendKeyEventDownAndUp(KeyComboModel.NO_MODIFIER,KeyEvent.KEYCODE_ENTER,keyComboManager);

    // Select cancel with keyboard. Default focus is on cancel button.
    // Note: do this operation with keyboard to test the dialog can handle key events properly.
    sendKeyEventDownAndUp(KeyComboModel.NO_MODIFIER,keyComboManager);

    // Confirm that key combo is not changed.
    assertEquals(KeyComboManager.getKeyComboCode(
                    KeyComboModel.NO_MODIFIER,KeyEvent.KEYCODE_DPAD_RIGHT),keyComboManager.getKeyComboModel().getKeyComboCodeForKey(
                    getActivity().getString(R.string.keycombo_shortcut_navigate_next)));
    assertEquals(KeyComboManager.getKeyComboCode(
                    KeyComboModel.NO_MODIFIER,KeyEvent.KEYCODE_DPAD_LEFT),keyComboManager.getKeyComboModel().getKeyComboCodeForKey(
                    getActivity().getString(R.string.keycombo_shortcut_navigate_prevIoUs)));

    // Confirm that ALT + DPAD LEFT is still set in the dialog,and try again.
    assertAssignedKeyComboText(KeyEvent.Meta_ALT_ON,dialogPreference);
    sendKeyEventDownAndUp(KeyComboModel.NO_MODIFIER,keyComboManager);

    // Press OK. Since default focus is on cancel button,we need to move focus to OK button.
    int keyToSelectOK =
            getLayoutDirection(mPreferencesActivity.findViewById(android.R.id.content)) ==
                    LayoutDirection.RTL ?
                    KeyEvent.KEYCODE_DPAD_LEFT : KeyEvent.KEYCODE_DPAD_RIGHT;
    sendKeyEventDownAndUp(KeyComboModel.NO_MODIFIER,keyToSelectOK,keyComboManager);
    sendKeyEventDownAndUp(KeyComboModel.NO_MODIFIER,keyComboManager);

    // Confirm that key combos are changed.
    assertEquals(KeyComboManager.getKeyComboCode(
                    KeyComboModel.NO_MODIFIER,keyComboManager.getKeyComboModel().getKeyComboCodeForKey(
                    getActivity().getString(R.string.keycombo_shortcut_navigate_next)));
    assertEquals(KeyComboModel.KEY_COMBO_CODE_UNASSIGNED,keyComboManager.getKeyComboModel().getKeyComboCodeForKey(
                    getActivity().getString(R.string.keycombo_shortcut_navigate_prevIoUs)));
}
项目:MaterialScrollBar    文件Utils.java   
/**
 *
 * @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;
}

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。