// Account for paddingfloatxpad=(float)(getPaddingLeft()+getPaddingRight());floatypad=(float)(getPaddingTop()+getPaddingBottom());// Account for the labelif(mShowText)xpad+=mTextWidth;floatww=(float)w-xpad;floathh=(float)h-ypad;// Figure out how big we can make the pie.floatdiameter=Math.min(ww,hh);
@OverrideprotectedvoidonMeasure(intwidthMeasureSpec,intheightMeasureSpec){// Try for a width based on our minimumintminw=getPaddingLeft()+getPaddingRight()+getSuggestedMinimumWidth();intw=resolveSizeAndState(minw,widthMeasureSpec,1);// Whatever the width ends up being, ask for a height that would let the pie// get as big as it canintminh=MeasureSpec.getSize(w)-(int)mTextWidth+getPaddingBottom()+getPaddingTop();inth=resolveSizeAndState(MeasureSpec.getSize(w)-(int)mTextWidth,heightMeasureSpec,0);setMeasuredDimension(w,h);}
protectedvoidonDraw(Canvascanvas){super.onDraw(canvas);// Draw the shadowcanvas.drawOval(mShadowBounds,mShadowPaint);// Draw the label textcanvas.drawText(mData.get(mCurrentItem).mLabel,mTextX,mTextY,mTextPaint);// Draw the pie slicesfor(inti=0;i<mData.size();++i){Itemit=mData.get(i);mPiePaint.setShader(it.mShader);canvas.drawArc(mBounds,360-it.mEndAngle,it.mEndAngle-it.mStartAngle,true,mPiePaint);}// Draw the pointercanvas.drawLine(mTextX,mPointerY,mPointerX,mPointerY,mTextPaint);canvas.drawCircle(mPointerX,mPointerY,mPointerSize,mTextPaint);}