CodeEditText.java 文件源码

java
阅读 22 收藏 0 点赞 0 评论 0

项目:FxExplorer 作者:
@Override
protected void onDraw(Canvas canvas) {
    long st = System.currentTimeMillis();
    if (showLineNumber) {
        int height = getHeight();
        int line_height = getLineHeight();
        int count = height / line_height;
        if (getLineCount() > count) {
            count = getLineCount();//for long text with scrolling
        }
        Rect r = mRect;
        Paint paint = lineNumberPaint;
        String maxNumber = String.format("%0" + String.valueOf(count).length() + "d", 8);
        paint.getTextBounds(maxNumber, 0, maxNumber.length(), mRect);
        int baseLeft = getScrollX();
        int lineNumberWidth = r.width() + 2 * numberMargin;
        int baseline = getLineBounds(0, r);//first line
        //draw split line
        canvas.drawLine(baseLeft + lineNumberWidth, 0, baseLeft + lineNumberWidth, count * line_height, paint);
        getLocalVisibleRect(r);
        int startLine = r.top / line_height;
        baseline += startLine * line_height;
        int endLine = (r.bottom + line_height - 1) / line_height;
        Rect tRect = new Rect();
        PathEffect pathEffect = paint.getPathEffect();
        paint.setPathEffect(null);
        for (int i = startLine; i < endLine; i++) {
            String number = String.valueOf(i + 1);
            paint.getTextBounds(number, 0, number.length(), tRect);
            canvas.drawText(number, baseLeft + lineNumberWidth - tRect.width() - numberMargin, baseline + 1, paint);
            baseline += line_height;
        }
        paint.setPathEffect(pathEffect);
    }
    Log.d(null, "C Cost:" + (System.currentTimeMillis() - st));
    st = System.currentTimeMillis();
    super.onDraw(canvas);
    Log.d(null, "S Cost:" + (System.currentTimeMillis() - st));
}
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号