AbMonitorView.java 文件源码

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

项目:EntboostIM 作者:
/**
 * 描述:TODO.
 *
 * @param canvas the canvas
 * @see android.view.View#onDraw(android.graphics.Canvas)
 * @author: amsoft.cn
 * @date:2013-6-17 上午9:04:49
 * @version v1.0
 */
@Override
protected void onDraw(Canvas canvas) {

    //if(D)Log4jLog.d(LONG_TAG, "--AbMonitorView onDraw--");
    canvas.drawColor(Color.argb(80, 0, 0, 0));
    if (mStartTime == -1) {
        mStartTime = SystemClock.elapsedRealtime();
        mCounter = 0;
    }

    long now = SystemClock.elapsedRealtime();
    long delay = now - mStartTime;

    if(delay!=0){
        // 计算帧速率
        mFps = (int)(mCounter * 1000 / delay);
    }

       String text = mFps + " fps";
       //获取值的文本的高度
       TextPaint mTextPaint = new TextPaint(Paint.ANTI_ALIAS_FLAG);
       mTextPaint.setTypeface(Typeface.DEFAULT);
       mTextPaint.setTextSize(16);
       FontMetrics fm  = mTextPaint.getFontMetrics();
       //得到行高
       int textHeight = (int)Math.ceil(fm.descent - fm.ascent)+2;
       int textWidth = (int)AbGraphical.getStringWidth(text,mTextPaint);


    canvas.drawText(text,(this.getWidth()-textWidth)/2, textHeight, mPaint);
    if (delay > 1000L) {
        mStartTime = now;
        mFps = mCounter;
        mCounter = 0;
    }
    mCounter++;
    super.onDraw(canvas);
}
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号