Back to project page slider.
The source code is released under:
Apache License
If you think the Android project slider listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
package de.devisnik.android.sliding.tile; /*from w ww. j a v a2 s. co m*/ import java.util.HashMap; import android.graphics.Canvas; import android.graphics.Paint; import android.graphics.Picture; import de.devisnik.android.sliding.Logger; import de.devisnik.sliding.IPiece; import de.devisnik.sliding.Point; public class CachingPieceDrawer implements IPieceDrawer { private static final String TAG = "CachingTileDrawer"; private final IPieceDrawer itsTileDrawer; private HashMap<IPiece, Picture> itsCache = new HashMap<IPiece, Picture>(); public CachingPieceDrawer(IPieceDrawer tileDrawer) { itsTileDrawer = tileDrawer; } @Override public Point getTileSize() { return itsTileDrawer.getTileSize(); } @Override public void drawTile(IPiece piece, Canvas canvas, Paint paint) { if (!itsCache.containsKey(piece)) cachePicture(piece, paint); canvas.drawPicture(itsCache.get(piece)); } private void cachePicture(IPiece piece, Paint paint) { Logger.d(TAG, "caching piece " + piece.getLabel()); Picture picture = new Picture(); Point tileSize = itsTileDrawer.getTileSize(); Canvas recording = picture.beginRecording(tileSize.x, tileSize.y); itsTileDrawer.drawTile(piece, recording, paint); picture.endRecording(); itsCache.put(piece, picture); } }