| | |
| | | package com.moral.yunfushao.ui; |
| | | |
| | | import android.animation.ValueAnimator; |
| | | import android.content.Context; |
| | | import android.content.res.Resources; |
| | | import android.graphics.Bitmap; |
| | |
| | | private Bitmap mBitmap; |
| | | |
| | | private float percent = 0;//百分比数据 |
| | | private float percent2 = (float) 0.27;//百分比数据 |
| | | |
| | | |
| | | private String statusStr = "未连接"; |
| | | private ValueAnimator anim; |
| | | |
| | | public void setStatusStr(String statusStr){ |
| | | this.statusStr = statusStr; |
| | |
| | | |
| | | public void setPercent(float percent){ |
| | | this.percent = percent; |
| | | // this.percent2 = percent; |
| | | postInvalidate(); |
| | | // if (anim.isStarted() || anim.isRunning()) { |
| | | // anim.end(); |
| | | // anim.cancel(); |
| | | // } |
| | | // anim.start(); |
| | | } |
| | | |
| | | public PanelView(Context context) { |
| | |
| | | mBitPaint.setFilterBitmap(true); |
| | | mBitPaint.setDither(true); |
| | | mBitmap = ((BitmapDrawable)mContext.getResources().getDrawable(R.mipmap.zhizhen)).getBitmap(); |
| | | // startAnimation(); |
| | | } |
| | | |
| | | @Override |
| | |
| | | setMeasuredDimension(mmWidth, mmHeight); |
| | | } |
| | | |
| | | // private void startAnimation() { |
| | | // anim = ValueAnimator.ofObject(new CustomPointEvaluator(),(float)0, percent2); |
| | | // anim.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { |
| | | // @Override |
| | | // public void onAnimationUpdate(ValueAnimator animation) { |
| | | // percent = (float) animation.getAnimatedValue(); |
| | | // System.out.println("chenqi rotato " + percent + " all -> " + percent2 * 300); |
| | | //// invalidate(); |
| | | // } |
| | | // }); |
| | | // anim.setDuration(3000L); |
| | | // anim.setRepeatCount(Animation.INFINITE); |
| | | // } |
| | | // |
| | | // private class CustomPointEvaluator implements TypeEvaluator<Float> { |
| | | // @Override |
| | | // public Float evaluate(float fraction, Float startValue, Float endValue) { |
| | | // System.out.println("chenqi2 rotato " + fraction + " all -> " + endValue); |
| | | // float y = fraction * endValue; |
| | | // return y; |
| | | // } |
| | | // } |
| | | |
| | | |
| | | @Override |
| | | protected void onDraw(Canvas canvas) { |
| | | super.onDraw(canvas); |
| | |
| | | float bitH = circleR; |
| | | float bitW = bitH*0.448f; |
| | | canvas.save(); |
| | | |
| | | System.out.println("chenqi percent connect" + percent); |
| | | canvas.rotate(percent*300-150,mWidth/2,mWidth/2); |
| | | RectF btmRect = new RectF((float) (cirlcleRect.left+bitH-bitW*0.535), (float) (cirlcleRect.top+mCircleWidth*0.68),(float) (cirlcleRect.left+bitH+bitW*0.465), (float) (cirlcleRect.top+bitH+mCircleWidth*0.68)); |
| | | // Log.d("haijiang","left="+btmRect.left); |
| | |
| | | int statusStrWidth = (int) drawTextPaint.measureText(this.statusStr); |
| | | canvas.drawText(this.statusStr,mWidth / 2-statusStrWidth/2, mWidth/2+(btmRect.bottom-btmRect.top)/2,drawTextPaint); |
| | | if(percent>0) |
| | | canvas.drawArc(new RectF(mShaderWidth + widthInner+mCircleWidth+innerPadding, mShaderWidth + widthInner+mCircleWidth+innerPadding, mWidth - mShaderWidth - widthInner-mCircleWidth-innerPadding, mWidth - mShaderWidth - widthInner-mCircleWidth-innerPadding), 120, 300*percent, false, mProgressPaint); |
| | | canvas.drawArc(new RectF(mShaderWidth + widthInner + mCircleWidth + innerPadding, mShaderWidth + widthInner + mCircleWidth + innerPadding, mWidth - mShaderWidth - widthInner - mCircleWidth - innerPadding, mWidth - mShaderWidth - widthInner - mCircleWidth - innerPadding), |
| | | 120, 300 * percent, false, mProgressPaint); |
| | | } |
| | | |
| | | /** |
| | | * 画刻度 |
| | | * |
| | | * @param canvas |
| | | */ |
| | | private void drawKedu(Canvas canvas){ |
| | |
| | | |
| | | /** |
| | | * 画刻度文字 |
| | | * |
| | | * @param canvas |
| | | */ |
| | | private void drawTextKedu(Canvas canvas){ |
| | |
| | | |
| | | /** |
| | | * 画渐变圆环 |
| | | * |
| | | * @param canvas |
| | | */ |
| | | private void drawJianbianCircle(Canvas canvas){ |