android.text.Layout#draw ( )源码实例Demo

下面列出了android.text.Layout#draw ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: litho   文件: TextureWarmer.java
@Override
public void handleMessage(Message msg) {
  if (mPicture == null) {
    return;
  }

  final Canvas canvas;

  try {
    switch (msg.what) {
      case WARM_LAYOUT:
        final Layout layout = ((WeakReference<Layout>) msg.obj).get();

        if (layout == null) {
          break;
        }

        canvas =
            mPicture.beginRecording(layout.getWidth(), LayoutMeasureUtil.getHeight(layout));

        layout.draw(canvas);
        mPicture.endRecording();
        break;
      case WARM_DRAWABLE:
        final WarmDrawable warmDrawable = ((WeakReference<WarmDrawable>) msg.obj).get();

        if (warmDrawable == null) {
          break;
        }

        canvas = mPicture.beginRecording(warmDrawable.width, warmDrawable.height);
        warmDrawable.drawable.draw(canvas);
        mPicture.endRecording();
        break;
    }
  } catch (Exception e) {
    // Nothing to do here. This is a best effort. No real problem if it fails.
  }
}
 
源代码2 项目: ucar-weex-core   文件: WXTextDomObject.java
/**
 * As warming up TextLayoutCache done in the DOM thread may manipulate UI operation,
 there may be some exception, in which case the exception is ignored. After all,
 this is just a warm up operation.
 * @return false for warm up failure, otherwise returns true.
 */
private boolean warmUpTextLayoutCache(Layout layout) {
  boolean result;
  try {
    layout.draw(DUMMY_CANVAS);
    result = true;
  } catch (Exception e) {
    WXLogUtils.eTag(TAG, e);
    result = false;
  }
  return result;
}
 
源代码3 项目: ucar-weex-core   文件: WXTextView.java
@Override
protected void onDraw(Canvas canvas) {
  super.onDraw(canvas);
  canvas.save();
  Layout layout= getTextLayout();
  if(layout!=null){
    canvas.translate(getPaddingLeft(),getPaddingTop());
    layout.draw(canvas);
  }
  canvas.restore();
}
 
源代码4 项目: weex-uikit   文件: WXTextDomObject.java
/**
 * As warming up TextLayoutCache done in the DOM thread may manipulate UI operation,
 there may be some exception, in which case the exception is ignored. After all,
 this is just a warm up operation.
 * @return false for warm up failure, otherwise returns true.
 */
private boolean warmUpTextLayoutCache(Layout layout) {
  boolean result;
  try {
    layout.draw(DUMMY_CANVAS);
    result = true;
  } catch (Exception e) {
    WXLogUtils.eTag(TAG, e);
    result = false;
  }
  return result;
}
 
源代码5 项目: weex-uikit   文件: WXTextView.java
@Override
protected void onDraw(Canvas canvas) {
  super.onDraw(canvas);
  canvas.save();
  Layout layout= getTextLayout();
  if(layout!=null){
    canvas.translate(getPaddingLeft(),getPaddingTop());
    layout.draw(canvas);
  }
  canvas.restore();
}
 
源代码6 项目: stepper-indicator   文件: StepperIndicator.java
/**
 * x and y anchored to top-middle point of StaticLayout
 */
public static void drawLayout(Layout layout, float x, float y,
                              Canvas canvas, TextPaint paint) {
    canvas.save();
    canvas.translate(x, y);
    layout.draw(canvas);
    canvas.restore();
}
 
源代码7 项目: weex   文件: WXTextView.java
@Override
protected void onDraw(Canvas canvas) {
  super.onDraw(canvas);
  canvas.save();
  Layout layout= getTextLayout();
  if(layout!=null){
    canvas.translate(getPaddingLeft(),getPaddingTop());
    layout.draw(canvas);
  }
  canvas.restore();
}
 
源代码8 项目: TextLayoutBuilder   文件: GlyphWarmerImpl.java
@Override
public void handleMessage(Message msg) {
  Layout layout = (Layout) msg.obj;
  try {
    Canvas canvas =
        mPicture.beginRecording(
            LayoutMeasureUtil.getWidth(layout), LayoutMeasureUtil.getHeight(layout));
    layout.draw(canvas);
    mPicture.endRecording();
  } catch (Exception e) {
    // Do nothing.
  }
}
 
源代码9 项目: android-proguards   文件: ReflowText.java
private Bitmap createBitmap(@NonNull ReflowData data, @NonNull Layout layout) {
    Bitmap bitmap = Bitmap.createBitmap(
            data.bounds.width(), data.bounds.height(), Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(bitmap);
    canvas.translate(data.textPosition.x, data.textPosition.y);
    layout.draw(canvas);
    return bitmap;
}
 
@Override
protected void onDraw(Canvas canvas) {
    super.onDraw(canvas);
    canvas.save();
    canvas.translate(getPaddingLeft(), getPaddingRight());
    Layout switchText = mChecked ? mOnLayout : mOffLayout;
    switchText.draw(canvas);
    canvas.restore();
}
 
源代码11 项目: PreferenceFragment   文件: Switch.java
@Override
protected void onDraw(Canvas canvas) {
    super.onDraw(canvas);

    // Draw the switch
    int switchLeft = mSwitchLeft;
    int switchTop = mSwitchTop;
    int switchRight = mSwitchRight;
    int switchBottom = mSwitchBottom;

    mTrackDrawable.setBounds(switchLeft, switchTop, switchRight, switchBottom);
    mTrackDrawable.draw(canvas);

    canvas.save();

    mTrackDrawable.getPadding(mTempRect);
    int switchInnerLeft = switchLeft + mTempRect.left;
    int switchInnerTop = switchTop + mTempRect.top;
    int switchInnerRight = switchRight - mTempRect.right;
    int switchInnerBottom = switchBottom - mTempRect.bottom;
    canvas.clipRect(switchInnerLeft, switchTop, switchInnerRight, switchBottom);

    mThumbDrawable.getPadding(mTempRect);
    final int thumbPos = (int) (mThumbPosition + 0.5f);
    int thumbLeft = switchInnerLeft - mTempRect.left + thumbPos;
    int thumbRight = switchInnerLeft + thumbPos + mThumbWidth + mTempRect.right;

    mThumbDrawable.setBounds(thumbLeft, switchTop, thumbRight, switchBottom);
    mThumbDrawable.draw(canvas);

    // mTextColors should not be null, but just in case
    if (mTextColors != null) {
        mTextPaint.setColor(mTextColors.getColorForState(getDrawableState(),
                mTextColors.getDefaultColor()));
    }
    mTextPaint.drawableState = getDrawableState();

    Layout switchText = getTargetCheckedState() ? mOnLayout : mOffLayout;
    if (switchText != null) {
        canvas.translate((thumbLeft + thumbRight) / 2 - switchText.getWidth() / 2,
                (switchInnerTop + switchInnerBottom) / 2 - switchText.getHeight() / 2);
        switchText.draw(canvas);
    }

    canvas.restore();
}
 
源代码12 项目: holoaccent   文件: AccentSwitch.java
@Override
protected void onDraw(Canvas canvas) {
	super.onDraw(canvas);

	// Draw the switch
	int switchLeft = mSwitchLeft;
	int switchTop = mSwitchTop;
	int switchRight = mSwitchRight;
	int switchBottom = mSwitchBottom;

	mTrackDrawable.setBounds(switchLeft, switchTop, switchRight,
			switchBottom);
	mTrackDrawable.draw(canvas);

	canvas.save();

	mTrackDrawable.getPadding(mTempRect);
	int switchInnerLeft = switchLeft + mTempRect.left;
	int switchInnerTop = switchTop + mTempRect.top;
	int switchInnerRight = switchRight - mTempRect.right;
	int switchInnerBottom = switchBottom - mTempRect.bottom;
	canvas.clipRect(switchInnerLeft, switchTop, switchInnerRight,
			switchBottom);

	mThumbDrawable.getPadding(mTempRect);
	final int thumbPos = (int) (mThumbPosition + 0.5f);
	int thumbLeft = switchInnerLeft - mTempRect.left + thumbPos;
	int thumbRight = switchInnerLeft + thumbPos + mThumbWidth
			+ mTempRect.right;

	mThumbDrawable
			.setBounds(thumbLeft, switchTop, thumbRight, switchBottom);
	mThumbDrawable.draw(canvas);

	// mTextColors should not be null, but just in case
	if (mTextColors != null) {
		mTextPaint.setColor(mTextColors.getColorForState(
				getDrawableState(), mTextColors.getDefaultColor()));
	}
	mTextPaint.drawableState = getDrawableState();

	Layout switchText = getTargetCheckedState() ? mOnLayout : mOffLayout;
	if (switchText != null) {
		canvas.translate(
				(thumbLeft + thumbRight) / 2 - switchText.getWidth() / 2,
				(switchInnerTop + switchInnerBottom) / 2
						- switchText.getHeight() / 2);
		switchText.draw(canvas);
	}

	canvas.restore();
}
 
源代码13 项目: MCPELauncher   文件: Switch.java
@Override
protected void onDraw(Canvas canvas)
{
	super.onDraw(canvas);

	// Draw the switch
	int switchLeft = mSwitchLeft;
	int switchTop = mSwitchTop;
	int switchRight = mSwitchRight;
	int switchBottom = mSwitchBottom;

	mTrackDrawable.setBounds(switchLeft, switchTop, switchRight, switchBottom);
	mTrackDrawable.draw(canvas);

	canvas.save();

	mTrackDrawable.getPadding(mTempRect);
	int switchInnerLeft = switchLeft + mTempRect.left;
	int switchInnerTop = switchTop + mTempRect.top;
	int switchInnerRight = switchRight - mTempRect.right;
	int switchInnerBottom = switchBottom - mTempRect.bottom;
	canvas.clipRect(switchInnerLeft, switchTop, switchInnerRight, switchBottom);

	mThumbDrawable.getPadding(mTempRect);
	final int thumbPos = (int) (mThumbPosition + 0.5f);
	int thumbLeft = switchInnerLeft - mTempRect.left + thumbPos;
	int thumbRight = switchInnerLeft + thumbPos + mThumbWidth + mTempRect.right;

	mThumbDrawable.setBounds(thumbLeft, switchTop, thumbRight, switchBottom);
	mThumbDrawable.draw(canvas);

	// mTextColors should not be null, but just in case
	if (mTextColors != null)
	{
		mTextPaint.setColor(mTextColors.getColorForState(getDrawableState(), mTextColors.getDefaultColor()));
	}
	mTextPaint.drawableState = getDrawableState();

	Layout switchText = getTargetCheckedState() ? mOnLayout : mOffLayout;
	if (switchText != null)
	{
		canvas.translate((thumbLeft + thumbRight) / 2 - switchText.getWidth() / 2, (switchInnerTop + switchInnerBottom) / 2 - switchText.getHeight() / 2);
		switchText.draw(canvas);
	}

	canvas.restore();
}