List of usage examples for android.text Layout draw
public void draw(Canvas c)
From source file:com.taobao.weex.dom.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./*from ww w. j a v a2 s . c om*/ * @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; }
From source file:io.plaidapp.core.ui.transitions.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; }
From source file:lewa.support.v7.widget.SwitchCompat.java
@Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); final Rect padding = mTempRect; final Drawable trackDrawable = mTrackDrawable; if (trackDrawable != null) { trackDrawable.getPadding(padding); } else {/* w w w . j ava 2s. c o m*/ padding.setEmpty(); } final int switchTop = mSwitchTop; final int switchBottom = mSwitchBottom; final int switchInnerTop = switchTop + padding.top; final int switchInnerBottom = switchBottom - padding.bottom; final Drawable thumbDrawable = mThumbDrawable; if (trackDrawable != null) { trackDrawable.draw(canvas); } final int saveCount = canvas.save(); if (thumbDrawable != null) { thumbDrawable.draw(canvas); } final Layout switchText = getTargetCheckedState() ? mOnLayout : mOffLayout; if (switchText != null) { final int drawableState[] = getDrawableState(); if (mTextColors != null) { mTextPaint.setColor(mTextColors.getColorForState(drawableState, 0)); } mTextPaint.drawableState = drawableState; final int cX; if (thumbDrawable != null) { final Rect bounds = thumbDrawable.getBounds(); cX = bounds.left + bounds.right; } else { cX = getWidth(); } final int left = cX / 2 - switchText.getWidth() / 2; final int top = (switchInnerTop + switchInnerBottom) / 2 - switchText.getHeight() / 2; canvas.translate(left, top); switchText.draw(canvas); } canvas.restoreToCount(saveCount); }
From source file:android.support.v7.widget.SwitchCompat.java
@Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); final Rect padding = mTempRect; final Drawable trackDrawable = mTrackDrawable; if (trackDrawable != null) { trackDrawable.getPadding(padding); } else {//w w w . j av a2 s . c om padding.setEmpty(); } final int switchTop = mSwitchTop; final int switchBottom = mSwitchBottom; final int switchInnerTop = switchTop + padding.top; final int switchInnerBottom = switchBottom - padding.bottom; final Drawable thumbDrawable = mThumbDrawable; if (trackDrawable != null) { if (mSplitTrack && thumbDrawable != null) { final Rect insets = DrawableUtils.getOpticalBounds(thumbDrawable); thumbDrawable.copyBounds(padding); padding.left += insets.left; padding.right -= insets.right; final int saveCount = canvas.save(); canvas.clipRect(padding, Region.Op.DIFFERENCE); trackDrawable.draw(canvas); canvas.restoreToCount(saveCount); } else { trackDrawable.draw(canvas); } } final int saveCount = canvas.save(); if (thumbDrawable != null) { thumbDrawable.draw(canvas); } final Layout switchText = getTargetCheckedState() ? mOnLayout : mOffLayout; if (switchText != null) { final int drawableState[] = getDrawableState(); if (mTextColors != null) { mTextPaint.setColor(mTextColors.getColorForState(drawableState, 0)); } mTextPaint.drawableState = drawableState; final int cX; if (thumbDrawable != null) { final Rect bounds = thumbDrawable.getBounds(); cX = bounds.left + bounds.right; } else { cX = getWidth(); } final int left = cX / 2 - switchText.getWidth() / 2; final int top = (switchInnerTop + switchInnerBottom) / 2 - switchText.getHeight() / 2; canvas.translate(left, top); switchText.draw(canvas); } canvas.restoreToCount(saveCount); }
From source file:rikka.akashitoolkit.ui.widget.IconSwitchCompat.java
@Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); final Rect padding = mTempRect; final Drawable trackDrawable = mTrackDrawable; if (trackDrawable != null) { trackDrawable.getPadding(padding); } else {/*from w w w. ja v a2 s . c o m*/ padding.setEmpty(); } final int switchTop = mSwitchTop; final int switchBottom = mSwitchBottom; final int switchInnerTop = switchTop + padding.top; final int switchInnerBottom = switchBottom - padding.bottom; final Drawable thumbDrawable = mThumbDrawable; if (trackDrawable != null) { if (mSplitTrack && thumbDrawable != null) { final Rect insets = DrawableUtils.getOpticalBounds(thumbDrawable); thumbDrawable.copyBounds(padding); padding.left += insets.left; padding.right -= insets.right; final int saveCount = canvas.save(); canvas.clipRect(padding, Region.Op.DIFFERENCE); trackDrawable.draw(canvas); canvas.restoreToCount(saveCount); } else { trackDrawable.draw(canvas); } } final int saveCount = canvas.save(); if (thumbDrawable != null) { thumbDrawable.draw(canvas); } final Drawable iconDrawable = mIconDrawable; if (iconDrawable != null) { if (mSplitTrack) { final Rect insets = DrawableUtils.getOpticalBounds(iconDrawable); iconDrawable.copyBounds(padding); padding.left += insets.left; padding.right -= insets.right; //final int saveCount = canvas.save(); canvas.clipRect(padding, Region.Op.DIFFERENCE); iconDrawable.draw(canvas); canvas.restoreToCount(saveCount); } else { iconDrawable.draw(canvas); } } final Layout switchText = getTargetCheckedState() ? mOnLayout : mOffLayout; if (switchText != null) { final int drawableState[] = getDrawableState(); if (mTextColors != null) { mTextPaint.setColor(mTextColors.getColorForState(drawableState, 0)); } mTextPaint.drawableState = drawableState; final int cX; if (thumbDrawable != null) { final Rect bounds = thumbDrawable.getBounds(); cX = bounds.left + bounds.right; } else { cX = getWidth(); } final int left = cX / 2 - switchText.getWidth() / 2; final int top = (switchInnerTop + switchInnerBottom) / 2 - switchText.getHeight() / 2; canvas.translate(left, top); switchText.draw(canvas); } canvas.restoreToCount(saveCount); }
From source file:com.mixiaoxiao.support.widget.SmoothSwitch.java
@Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); if (!isEnabled()) {//wangbin added this line if (mThumbDrawable != null) { mThumbDrawable.setColor(getDisableColor(isChecked() ? mThumbColorOn : mThumbColorOff)); }//ww w . j a va 2 s . c o m if (mTrackDrawable != null) { mTrackDrawable.setColor(getDisableColor(isChecked() ? mTrackColorOn : mTrackColorOff)); } } final Rect padding = mTempRect; final Drawable trackDrawable = mTrackDrawable; if (trackDrawable != null) { trackDrawable.getPadding(padding); } else { padding.setEmpty(); } final int switchTop = mSwitchTop; final int switchBottom = mSwitchBottom; final int switchInnerTop = switchTop + padding.top; final int switchInnerBottom = switchBottom - padding.bottom; final Drawable thumbDrawable = mThumbDrawable; if (trackDrawable != null) { trackDrawable.draw(canvas); } final int saveCount = canvas.save(); if (thumbDrawable != null) { thumbDrawable.draw(canvas); } final Layout switchText = getTargetCheckedState() ? mOnLayout : mOffLayout; if (switchText != null) { final int drawableState[] = getDrawableState(); if (mTextColors != null) { mTextPaint.setColor(mTextColors.getColorForState(drawableState, 0)); } mTextPaint.drawableState = drawableState; final int cX; if (thumbDrawable != null) { final Rect bounds = thumbDrawable.getBounds(); cX = bounds.left + bounds.right; } else { cX = getWidth(); } final int left = cX / 2 - switchText.getWidth() / 2; final int top = (switchInnerTop + switchInnerBottom) / 2 - switchText.getHeight() / 2; canvas.translate(left, top); switchText.draw(canvas); } canvas.restoreToCount(saveCount); }