private void drawPuzzles() { puzzles.forEach( new Matrix.OnEachHandler<Bitmap>() { @Override public void handle(Matrix<Bitmap> matrix, Position pos) { if (!existDraggedPuzzle() || !pos.equals(draggedPosition)) { Point leftUpper = leftUpperOfPuzzle(pos); Paint paint = paintForPosition(pos); Bitmap puzzle = puzzles.get(pos); canvas.drawBitmap(puzzle, leftUpper.x, leftUpper.y, paint); } } }); if (existDraggedPuzzle()) { Bitmap draggedPuzzle = puzzles.get(draggedPosition); canvas.drawBitmap(draggedPuzzle, draggedLeftUpper.x, draggedLeftUpper.y, null); } }
private void cutIntoPuzzles() { puzzles.forEach( new Matrix.OnEachHandler<Bitmap>() { @Override public void handle(Matrix<Bitmap> matrix, Position pos) { matrix.set(pos, puzzleByPosition(pos)); } }); }
private void onUpTouch(Point pt) { if (!existDraggedPuzzle()) { return; } if (draggedAndNearestCanBeSwapped()) { puzzles.swap(nearestPosition, draggedPosition); } nearestPosition = null; draggingStopped(); invalidate(); if (puzzlesChecker.puzzleAssembled(puzzles)) { notifyThatPuzzleAssembled(); } }
public void releaseImageResources() { if (!imageWasSet()) { return; } fullImage.recycle(); puzzles.forEach( new Matrix.OnEachHandler<Bitmap>() { @Override public void handle(Matrix<Bitmap> matrix, Position pos) { Bitmap bitmap = matrix.get(pos); bitmap.recycle(); matrix.set(pos, null); } }); }