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.
Java Source Code
package de.devisnik.android.sliding.tile;
//fromwww.java2s.comimport android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.PorterDuffXfermode;
import android.graphics.Rect;
import android.graphics.PorterDuff.Mode;
import de.devisnik.sliding.IPiece;
import de.devisnik.sliding.Point;
publicclass ImagePieceDrawer implements IPieceDrawer {
privatefinal Bitmap itsImage;
privatefinal Rect itsDstRect;
privatefinal Rect itsSrcRect;
privatefinal Point itsTileSize;
privatefinal Point itsHomeUpperLeft;
privatefinal Paint mPaint;
public ImagePieceDrawer(final Bitmap image, final Point tileSize) {
itsImage = image;
itsTileSize = tileSize;
itsDstRect = new Rect(0, 0, tileSize.x, tileSize.y);
itsSrcRect = new Rect();
itsHomeUpperLeft = new Point(0, 0);
mPaint = new Paint();
mPaint.setXfermode(new PorterDuffXfermode(Mode.SCREEN));
}
@Override
public Point getTileSize() {
return itsTileSize;
}
publicvoid drawTile(final IPiece piece, final Canvas canvas, final Paint paint) {
itsHomeUpperLeft.set(itsTileSize).multiplyBy(piece.getHomePosition());
itsSrcRect.set(itsHomeUpperLeft.x, itsHomeUpperLeft.y, itsHomeUpperLeft.x + itsTileSize.x, itsHomeUpperLeft.y
+ itsTileSize.y);
canvas.drawBitmap(itsImage, itsSrcRect, itsDstRect, mPaint);
}
}