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


Java DrawableCompat.getLayoutDirection方法代码示例

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


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

示例1: draw

import android.support.v4.graphics.drawable.DrawableCompat; //导入方法依赖的package包/类
@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,代码行数:79,代码来源:DrawerArrowDrawable.java

示例2: draw

import android.support.v4.graphics.drawable.DrawableCompat; //导入方法依赖的package包/类
public void draw(Canvas canvas) {
    boolean flipToPointRight;
    float f;
    float f2;
    Rect bounds = getBounds();
    switch (this.mDirection) {
        case 0:
            flipToPointRight = false;
            break;
        case 1:
            flipToPointRight = true;
            break;
        case 3:
            flipToPointRight = DrawableCompat.getLayoutDirection(this) == 0;
            break;
        default:
            if (DrawableCompat.getLayoutDirection(this) != 1) {
                flipToPointRight = false;
                break;
            } else {
                flipToPointRight = true;
                break;
            }
    }
    float arrowHeadBarLength = lerp(this.mBarLength, (float) Math.sqrt((double) ((this.mArrowHeadLength * this.mArrowHeadLength) * 2.0f)), this.mProgress);
    float arrowShaftLength = lerp(this.mBarLength, this.mArrowShaftLength, this.mProgress);
    float arrowShaftCut = (float) Math.round(lerp(0.0f, this.mMaxCutForBarSize, this.mProgress));
    float rotation = lerp(0.0f, ARROW_HEAD_ANGLE, this.mProgress);
    if (flipToPointRight) {
        f = 0.0f;
    } else {
        f = -180.0f;
    }
    if (flipToPointRight) {
        f2 = 180.0f;
    } else {
        f2 = 0.0f;
    }
    float canvasRotate = lerp(f, f2, this.mProgress);
    float arrowWidth = (float) Math.round(((double) arrowHeadBarLength) * Math.cos((double) rotation));
    float arrowHeight = (float) Math.round(((double) arrowHeadBarLength) * Math.sin((double) rotation));
    this.mPath.rewind();
    float topBottomBarOffset = lerp(this.mBarGap + this.mPaint.getStrokeWidth(), -this.mMaxCutForBarSize, this.mProgress);
    float arrowEdge = (-arrowShaftLength) / 2.0f;
    this.mPath.moveTo(arrowEdge + arrowShaftCut, 0.0f);
    this.mPath.rLineTo(arrowShaftLength - (2.0f * arrowShaftCut), 0.0f);
    this.mPath.moveTo(arrowEdge, topBottomBarOffset);
    this.mPath.rLineTo(arrowWidth, arrowHeight);
    this.mPath.moveTo(arrowEdge, -topBottomBarOffset);
    this.mPath.rLineTo(arrowWidth, -arrowHeight);
    this.mPath.close();
    canvas.save();
    float barThickness = this.mPaint.getStrokeWidth();
    canvas.translate((float) bounds.centerX(), (float) (((double) ((float) ((((int) ((((float) bounds.height()) - (IPhotoView.DEFAULT_MAX_SCALE * barThickness)) - (this.mBarGap * 2.0f))) / 4) * 2))) + ((((double) barThickness) * 1.5d) + ((double) this.mBarGap))));
    if (this.mSpin) {
        canvas.rotate(((float) ((this.mVerticalMirror ^ flipToPointRight) != 0 ? -1 : 1)) * canvasRotate);
    } else if (flipToPointRight) {
        canvas.rotate(180.0f);
    }
    canvas.drawPath(this.mPath, this.mPaint);
    canvas.restore();
}
 
开发者ID:JackChan1999,项目名称:boohee_v5.6,代码行数:63,代码来源:DrawerArrowDrawable.java

示例3: getLayoutDirection

import android.support.v4.graphics.drawable.DrawableCompat; //导入方法依赖的package包/类
public int getLayoutDirection() {
    if (this.mDelegateDrawable != null) {
        DrawableCompat.getLayoutDirection(this.mDelegateDrawable);
    }
    return 0;
}
 
开发者ID:JackChan1999,项目名称:boohee_v5.6,代码行数:7,代码来源:VectorDrawableCommon.java


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