当前位置: 首页>>代码示例>>Java>>正文


Java ViewCompat.LAYOUT_DIRECTION_LTR属性代码示例

本文整理汇总了Java中android.support.v4.view.ViewCompat.LAYOUT_DIRECTION_LTR属性的典型用法代码示例。如果您正苦于以下问题:Java ViewCompat.LAYOUT_DIRECTION_LTR属性的具体用法?Java ViewCompat.LAYOUT_DIRECTION_LTR怎么用?Java ViewCompat.LAYOUT_DIRECTION_LTR使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在android.support.v4.view.ViewCompat的用法示例。


在下文中一共展示了ViewCompat.LAYOUT_DIRECTION_LTR属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: showHint

public void showHint(int color) {
    final int[] screenPos = new int[2];
    final Rect displayFrame = new Rect();
    getLocationOnScreen(screenPos);
    getWindowVisibleDisplayFrame(displayFrame);
    final Context context = getContext();
    final int width = getWidth();
    final int height = getHeight();
    final int midy = screenPos[1] + height / 2;
    int referenceX = screenPos[0] + width / 2;
    if (ViewCompat.getLayoutDirection(this) == ViewCompat.LAYOUT_DIRECTION_LTR) {
        final int screenWidth = context.getResources().getDisplayMetrics().widthPixels;
        referenceX = screenWidth - referenceX; // mirror
    }
    Toast cheatSheet = Toast.makeText(context, String.format("#%06X", 0xFFFFFF & color), Toast.LENGTH_SHORT);
    if (midy < displayFrame.height()) {
        // Show along the top; follow action buttons
        cheatSheet.setGravity(Gravity.TOP | GravityCompat.END, referenceX,
                screenPos[1] + height - displayFrame.top);
    } else {
        // Show along the bottom center
        cheatSheet.setGravity(Gravity.BOTTOM | Gravity.CENTER_HORIZONTAL, 0, height);
    }
    cheatSheet.show();
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:25,代码来源:CircleView.java

示例2: getItemOffsets

@Override
public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state) {
    Resources r = context.getResources();
    int horizontalPadding = (int) r.getDimension(R.dimen.category_preview__app_list__padding__horizontal);
    int horizontalPaddingFirst = (int) r.getDimension(
            R.dimen.category_preview__app_list__padding__horizontal__first);
    boolean isLtr = ViewCompat.getLayoutDirection(parent) == ViewCompat.LAYOUT_DIRECTION_LTR;
    int itemPosition = parent.getChildLayoutPosition(view);
    boolean first = itemPosition == 0;

    // Leave this "paddingEnd" local variable here for clarity when converting from
    // left/right to start/end for RTL friendly layout.
    // noinspection UnnecessaryLocalVariable
    int paddingEnd = horizontalPadding;
    int paddingStart = first ? horizontalPaddingFirst : horizontalPadding;

    int paddingLeft = isLtr ? paddingStart : paddingEnd;
    int paddingRight = isLtr ? paddingEnd : paddingStart;
    outRect.set(paddingLeft, 0, paddingRight, 0);
}
 
开发者ID:uhuru-mobile,项目名称:mobile-store,代码行数:20,代码来源:CategoryController.java

示例3: display

public void display(float x) {
  this.startPositionX = x;
  this.lastPositionX  = x;

  recordButtonFab.setVisibility(View.VISIBLE);

  float translation = ViewCompat.getLayoutDirection(recordButtonFab) ==
      ViewCompat.LAYOUT_DIRECTION_LTR ? -.25f : .25f;

  AnimationSet animation = new AnimationSet(true);
  animation.addAnimation(new TranslateAnimation(Animation.RELATIVE_TO_SELF, translation,
                                                Animation.RELATIVE_TO_SELF, translation,
                                                Animation.RELATIVE_TO_SELF, -.25f,
                                                Animation.RELATIVE_TO_SELF, -.25f));

  animation.addAnimation(new ScaleAnimation(.5f, 1f, .5f, 1f,
                                            Animation.RELATIVE_TO_SELF, .5f,
                                            Animation.RELATIVE_TO_SELF, .5f));

  animation.setFillBefore(true);
  animation.setFillAfter(true);
  animation.setDuration(ANIMATION_DURATION);
  animation.setInterpolator(new OvershootInterpolator());

  recordButtonFab.startAnimation(animation);
}
 
开发者ID:XecureIT,项目名称:PeSanKita-android,代码行数:26,代码来源:MicrophoneRecorderView.java

示例4: convertToRelativeDirection

/**
 * Replaces a movement direction with its relative version by taking layout direction into
 * account.
 *
 * @param flags           The flag value that include any number of movement flags.
 * @param layoutDirection The layout direction of the View. Can be obtained from
 *                        {@link ViewCompat#getLayoutDirection(android.view.View)}.
 * @return Updated flags which uses relative flags ({@link #START}, {@link #END}) instead
 * of {@link #LEFT}, {@link #RIGHT}.
 * @see #convertToAbsoluteDirection(int, int)
 */
public static int convertToRelativeDirection(int flags, int layoutDirection) {
    int masked = flags & ABS_HORIZONTAL_DIR_FLAGS;
    if (masked == 0) {
        return flags;// does not have any abs flags, good.
    }
    flags &= ~masked; //remove left / right.
    if (layoutDirection == ViewCompat.LAYOUT_DIRECTION_LTR) {
        // no change. just OR with 2 bits shifted mask and return
        flags |= masked << 2; // START is 2 bits after LEFT, END is 2 bits after RIGHT.
        return flags;
    } else {
        // add RIGHT flag as START
        flags |= ((masked << 1) & ~ABS_HORIZONTAL_DIR_FLAGS);
        // first clean RIGHT bit then add LEFT flag as END
        flags |= ((masked << 1) & ABS_HORIZONTAL_DIR_FLAGS) << 2;
    }
    return flags;
}
 
开发者ID:MLNO,项目名称:airgram,代码行数:29,代码来源:ItemTouchHelper.java

示例5: convertToAbsoluteDirection

/**
 * Converts a given set of flags to absolution direction which means {@link #START} and
 * {@link #END} are replaced with {@link #LEFT} and {@link #RIGHT} depending on the layout
 * direction.
 *
 * @param flags           The flag value that include any number of movement flags.
 * @param layoutDirection The layout direction of the RecyclerView.
 * @return Updated flags which includes only absolute direction values.
 */
public int convertToAbsoluteDirection(int flags, int layoutDirection) {
    int masked = flags & RELATIVE_DIR_FLAGS;
    if (masked == 0) {
        return flags;// does not have any relative flags, good.
    }
    flags &= ~masked; //remove start / end
    if (layoutDirection == ViewCompat.LAYOUT_DIRECTION_LTR) {
        // no change. just OR with 2 bits shifted mask and return
        flags |= masked >> 2; // START is 2 bits after LEFT, END is 2 bits after RIGHT.
        return flags;
    } else {
        // add START flag as RIGHT
        flags |= ((masked >> 1) & ~RELATIVE_DIR_FLAGS);
        // first clean start bit then add END flag as LEFT
        flags |= ((masked >> 1) & RELATIVE_DIR_FLAGS) >> 2;
    }
    return flags;
}
 
开发者ID:MLNO,项目名称:airgram,代码行数:27,代码来源:ItemTouchHelper.java

示例6: onRtlPropertiesChanged

@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);
        }
    }
}
 
开发者ID:fekracomputers,项目名称:IslamicLibraryAndroid,代码行数:19,代码来源:RtlViewPager.java

示例7: calculateScrollXForTab

private int calculateScrollXForTab(int position, float positionOffset) {
  if (mMode == MODE_SCROLLABLE) {
    final View selectedChild = mTabStrip.getChildAt(position);
          final View nextChild = position + 1 < mTabStrip.getChildCount()
                  ? mTabStrip.getChildAt(position + 1)
                  : null;
    final int selectedWidth = selectedChild != null ? selectedChild.getWidth() : 0;
    final int nextWidth = nextChild != null ? nextChild.getWidth() : 0;

          // base scroll amount: places center of tab in center of parent
          int scrollBase = selectedChild.getLeft() + (selectedWidth / 2) - (getWidth() / 2);
          // offset amount: fraction of the distance between centers of tabs
          int scrollOffset = (int) ((selectedWidth + nextWidth) * 0.5f * positionOffset);

          return (ViewCompat.getLayoutDirection(this) == ViewCompat.LAYOUT_DIRECTION_LTR)
                  ? scrollBase + scrollOffset
                  : scrollBase - scrollOffset;
  }
  return 0;
}
 
开发者ID:commonsguy,项目名称:cwac-crossport,代码行数:20,代码来源:TabLayoutLite.java

示例8: convertToRelativeDirection

/**
 * Replaces a movement direction with its relative version by taking layout direction into
 * account.
 *
 * @param flags           The flag value that include any number of movement flags.
 * @param layoutDirection The layout direction of the View. Can be obtained from
 *                        {@link ViewCompat#getLayoutDirection(View)}.
 * @return Updated flags which uses relative flags ({@link #START}, {@link #END}) instead
 * of {@link #LEFT}, {@link #RIGHT}.
 * @see #convertToAbsoluteDirection(int, int)
 */
public static int convertToRelativeDirection(int flags, int layoutDirection) {
    int masked = flags & ABS_HORIZONTAL_DIR_FLAGS;
    if (masked == 0) {
        return flags;// does not have any abs flags, good.
    }
    flags &= ~masked; //remove left / right.
    if (layoutDirection == ViewCompat.LAYOUT_DIRECTION_LTR) {
        // no change. just OR with 2 bits shifted mask and return
        flags |= masked << 2; // START is 2 bits after LEFT, END is 2 bits after RIGHT.
        return flags;
    } else {
        // add RIGHT flag as START
        flags |= ((masked << 1) & ~ABS_HORIZONTAL_DIR_FLAGS);
        // first clean RIGHT bit then add LEFT flag as END
        flags |= ((masked << 1) & ABS_HORIZONTAL_DIR_FLAGS) << 2;
    }
    return flags;
}
 
开发者ID:pooyafaroka,项目名称:PlusGram,代码行数:29,代码来源:ItemTouchHelper.java

示例9: getItemOffsets

@Override
public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state) {
    int position = parent.getChildAdapterPosition(view);
    Resources resources = context.getResources();
    int horizontalPadding = (int) resources.getDimension(R.dimen.whats_new__padding__app_card__horizontal);
    int verticalPadding = (int) resources.getDimension(R.dimen.whats_new__padding__app_card__vertical);

    int relativePositionInCycle = position % 5;
    if (position == 0) {
        // Don't set any padding for the first item as the FeatureImage behind it needs to butt right
        // up against the left/top/right of the screen.
        outRect.set(0, 0, 0, verticalPadding);
    } else if (relativePositionInCycle != 0) {
        // The item on the left will have both left and right padding. The item on the right
        // will only have padding on the right. This will allow the same amount of padding
        // on the left, centre, and right of the grid, rather than double the padding in the
        // middle (which would happen if both left+right paddings were set for both items).
        boolean isLtr = ViewCompat.getLayoutDirection(parent) == ViewCompat.LAYOUT_DIRECTION_LTR;
        boolean isAtStart = relativePositionInCycle == 1 || relativePositionInCycle == 3;
        int paddingStart = isAtStart ? horizontalPadding : 0;
        int paddingLeft = isLtr ? paddingStart : horizontalPadding;
        int paddingRight = isLtr ? horizontalPadding : paddingStart;
        outRect.set(paddingLeft, 0, paddingRight, verticalPadding);
    } else {
        outRect.set(horizontalPadding, 0, horizontalPadding, verticalPadding);
    }
}
 
开发者ID:uhuru-mobile,项目名称:mobile-store,代码行数:27,代码来源:WhatsNewAdapter.java

示例10: onRecordMoved

@Override
public void onRecordMoved(float x, float absoluteX) {
  slideToCancel.moveTo(x);

  int   direction = ViewCompat.getLayoutDirection(this);
  float position  = absoluteX / recordingContainer.getWidth();

  if (direction == ViewCompat.LAYOUT_DIRECTION_LTR && position <= 0.5 ||
      direction == ViewCompat.LAYOUT_DIRECTION_RTL && position >= 0.6)
  {
    this.microphoneRecorderView.cancelAction();
  }
}
 
开发者ID:XecureIT,项目名称:PeSanKita-android,代码行数:13,代码来源:InputPanel.java

示例11: showHint

/**
 * Show a toast message with the hex color code below the view.
 */
public void showHint() {
  final int[] screenPos = new int[2];
  final Rect displayFrame = new Rect();
  getLocationOnScreen(screenPos);
  getWindowVisibleDisplayFrame(displayFrame);
  final Context context = getContext();
  final int width = getWidth();
  final int height = getHeight();
  final int midy = screenPos[1] + height / 2;
  int referenceX = screenPos[0] + width / 2;
  if (ViewCompat.getLayoutDirection(this) == ViewCompat.LAYOUT_DIRECTION_LTR) {
    final int screenWidth = context.getResources().getDisplayMetrics().widthPixels;
    referenceX = screenWidth - referenceX; // mirror
  }
  StringBuilder hint = new StringBuilder("#");
  if (Color.alpha(color) != 255) {
    hint.append(Integer.toHexString(color).toUpperCase(Locale.ENGLISH));
  } else {
    hint.append(String.format("%06X", 0xFFFFFF & color).toUpperCase(Locale.ENGLISH));
  }
  Toast cheatSheet = Toast.makeText(context, hint.toString(), Toast.LENGTH_SHORT);
  if (midy < displayFrame.height()) {
    // Show along the top; follow action buttons
    cheatSheet.setGravity(Gravity.TOP | GravityCompat.END, referenceX,
        screenPos[1] + height - displayFrame.top);
  } else {
    // Show along the bottom center
    cheatSheet.setGravity(Gravity.BOTTOM | Gravity.CENTER_HORIZONTAL, 0, height);
  }
  cheatSheet.show();
}
 
开发者ID:Blankeer,项目名称:MDWechat,代码行数:34,代码来源:ColorPanelView.java

示例12: setLayoutDirection

/**
 * 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;
    }
}
 
开发者ID:mozilla-mobile,项目名称:firefox-tv,代码行数:17,代码来源:LocaleAwareAppCompatActivity.java

示例13: getOffset

private float getOffset(float x) {
  return ViewCompat.getLayoutDirection(slideToCancelView) == ViewCompat.LAYOUT_DIRECTION_LTR ?
      -Math.max(0, this.startPositionX - x) : Math.max(0, x - this.startPositionX);
}
 
开发者ID:CableIM,项目名称:Cable-Android,代码行数:4,代码来源:InputPanel.java

示例14: getWidthAdjustment

private int getWidthAdjustment() {
  int width = recordButtonFab.getWidth() / 4;
  return ViewCompat.getLayoutDirection(recordButtonFab) == ViewCompat.LAYOUT_DIRECTION_LTR ? -width : width;
}
 
开发者ID:XecureIT,项目名称:PeSanKita-android,代码行数:4,代码来源:MicrophoneRecorderView.java

示例15: draw

@Override
public void draw(Canvas canvas) {
  Rect bounds = getBounds();

  final boolean flipToPointRight;
  switch (mDirection) {
    case ARROW_DIRECTION_LEFT:
      flipToPointRight = false;
      break;
    case ARROW_DIRECTION_RIGHT:
      flipToPointRight = true;
      break;
    case ARROW_DIRECTION_END:
      flipToPointRight = DrawableCompat.getLayoutDirection(this)
        == ViewCompat.LAYOUT_DIRECTION_LTR;
      break;
    case ARROW_DIRECTION_START:
    default:
      flipToPointRight = DrawableCompat.getLayoutDirection(this)
        == ViewCompat.LAYOUT_DIRECTION_RTL;
      break;
  }

  // Interpolated widths of arrow bars

  float arrowHeadBarLength = (float) Math.sqrt(mArrowHeadLength * mArrowHeadLength * 2);
  arrowHeadBarLength = lerp(mBarLength, arrowHeadBarLength, mProgress);
  final float arrowShaftLength = lerp(mBarLength, mArrowShaftLength, mProgress);
  // Interpolated size of middle bar
  final float arrowShaftCut = Math.round(lerp(0, mMaxCutForBarSize, mProgress));
  // The rotation of the top and bottom bars (that make the arrow head)
  final float rotation = lerp(0, ARROW_HEAD_ANGLE, mProgress);

  // The whole canvas rotates as the transition happens
  final float canvasRotate = lerp(flipToPointRight ? 0 : -180,
    flipToPointRight ? 180 : 0, mProgress);

  final float arrowWidth = Math.round(arrowHeadBarLength * Math.cos(rotation));
  final float arrowHeight = Math.round(arrowHeadBarLength * Math.sin(rotation));

  mPath.rewind();
  final float topBottomBarOffset = lerp(mBarGap + mPaint.getStrokeWidth(), -mMaxCutForBarSize,
    mProgress);

  final float arrowEdge = -arrowShaftLength / 2;
  // draw middle bar
  mPath.moveTo(arrowEdge + arrowShaftCut, 0);
  mPath.rLineTo(arrowShaftLength - arrowShaftCut * 2, 0);

  // bottom bar
  mPath.moveTo(arrowEdge, topBottomBarOffset);
  mPath.rLineTo(arrowWidth, arrowHeight);

  // top bar
  mPath.moveTo(arrowEdge, -topBottomBarOffset);
  mPath.rLineTo(arrowWidth, -arrowHeight);

  mPath.close();

  canvas.save();

  // Rotate the whole canvas if spinning, if not, rotate it 180 to get
  // the arrow pointing the other way for RTL.
  final float barThickness = mPaint.getStrokeWidth();
  final int remainingSpace = (int) (bounds.height() - barThickness * 3 - mBarGap * 2);
  float yOffset = (remainingSpace / 4) * 2; // making sure it is a multiple of 2.
      yOffset += barThickness * 1.5f + mBarGap;

  canvas.translate(bounds.centerX(), yOffset);
  if (mSpin) {
    canvas.rotate(canvasRotate * ((mVerticalMirror ^ flipToPointRight) ? -1 : 1));
  } else if (flipToPointRight) {
    canvas.rotate(180);
  }
  canvas.drawPath(mPath, mPaint);

  canvas.restore();
}
 
开发者ID:commonsguy,项目名称:cwac-crossport,代码行数:78,代码来源:DrawerArrowDrawable.java


注:本文中的android.support.v4.view.ViewCompat.LAYOUT_DIRECTION_LTR属性示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。