Code example for Canvas

Methods: draw, drawBitmap, restore, restoreToCount, save, scale, translate

0
        } 
	} 
 
	@Override 
	protected boolean drawChild(Canvas canvas, View child, long drawingTime) {
		int saveCount = canvas.save();
		Drawable[] tmp=((TextView)child).getCompoundDrawables();
		if(mIconSize==0){
			mIconSize=tmp[1].getIntrinsicHeight()+child.getPaddingTop();
		} 
		if(isAnimating){
			postInvalidate();
			//float x; 
			//float y; 
			distH=(child.getLeft()+(child.getWidth()/2))-(getWidth()/2);
			distV=(child.getTop()+(child.getHeight()/2))-(getHeight()/2);
			x=child.getLeft()+(distH*(mScaleFactor-1))*(mScaleFactor);
			y=child.getTop()+(distV*(mScaleFactor-1))*(mScaleFactor);
			width=child.getWidth()*mScaleFactor;
			height=(child.getHeight()-(child.getHeight()-mIconSize))*mScaleFactor;
			if(shouldDrawLabels)child.setDrawingCacheEnabled(true);
			if(shouldDrawLabels && child.getDrawingCache()!=null){
				//ADW: try to manually draw labels 
				rl1.set(0,mIconSize,child.getDrawingCache().getWidth(),child.getDrawingCache().getHeight());
				rl2.set(child.getLeft(),child.getTop()+mIconSize,child.getLeft()+child.getDrawingCache().getWidth(),child.getTop()+child.getDrawingCache().getHeight());
				mLabelPaint.setAlpha((int) (mLabelFactor*255));
				canvas.drawBitmap(child.getDrawingCache(), rl1, rl2, mLabelPaint);
			} 
			scale=((width)/child.getWidth());
			r3 = tmp[1].getBounds();
			xx=(child.getWidth()/2)-(r3.width()/2);
			canvas.save();
			canvas.translate(x+xx, y+child.getPaddingTop());
			canvas.scale(scale, scale);
			tmp[1].draw(canvas);
			canvas.restore();
		}else{ 
			if(mDrawLabels){
				child.setDrawingCacheEnabled(true);
				if(child.getDrawingCache()!=null){
					mPaint.setAlpha(255);
					canvas.drawBitmap(child.getDrawingCache(), child.getLeft(), child.getTop(), mPaint);
				}else{ 
					canvas.save();
					canvas.translate(child.getLeft(), child.getTop());
					child.draw(canvas);
					canvas.restore();
				} 
			}else{ 
				r3 = tmp[1].getBounds();
				int xx=(child.getWidth()/2)-(r3.width()/2);
				canvas.save();
				canvas.translate(child.getLeft()+xx, child.getTop()+child.getPaddingTop());
				tmp[1].draw(canvas);
				canvas.restore();
			} 
		} 
		canvas.restoreToCount(saveCount);
		return true; 
	} 
	/** 
	 * Open/close public methods 
	 */