TileViewpublic class TileView extends android.view.View TileView: a View-variant designed for handling arrays of "icons" or other
drawables. |
Fields Summary |
---|
protected static int | mTileSizeParameters controlling the size of the tiles and their range within view.
Width/Height are in pixels, and Drawables will be scaled to fit to these
dimensions. X/Y Tile Counts are the number of tiles that will be drawn. | protected static int | mXTileCount | protected static int | mYTileCount | private static int | mXOffset | private static int | mYOffset | private android.graphics.Bitmap[] | mTileArrayA hash that maps integer handles specified by the subclasser to the
drawable that will be used for that reference | private int[] | mTileGridA two-dimensional array of integers in which the number represents the
index of the tile that should be drawn at that locations | private final android.graphics.Paint | mPaint |
Constructors Summary |
---|
public TileView(android.content.Context context, android.util.AttributeSet attrs, int defStyle)
super(context, attrs, defStyle);
TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.TileView);
mTileSize = a.getInt(R.styleable.TileView_tileSize, 12);
a.recycle();
| public TileView(android.content.Context context, android.util.AttributeSet attrs)
super(context, attrs);
TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.TileView);
mTileSize = a.getInt(R.styleable.TileView_tileSize, 12);
a.recycle();
|
Methods Summary |
---|
public void | clearTiles()Resets all tiles to 0 (empty)
for (int x = 0; x < mXTileCount; x++) {
for (int y = 0; y < mYTileCount; y++) {
setTile(0, x, y);
}
}
| public void | loadTile(int key, android.graphics.drawable.Drawable tile)Function to set the specified Drawable as the tile for a particular
integer key.
Bitmap bitmap = Bitmap.createBitmap(mTileSize, mTileSize, Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(bitmap);
tile.setBounds(0, 0, mTileSize, mTileSize);
tile.draw(canvas);
mTileArray[key] = bitmap;
| public void | onDraw(android.graphics.Canvas canvas)
super.onDraw(canvas);
for (int x = 0; x < mXTileCount; x += 1) {
for (int y = 0; y < mYTileCount; y += 1) {
if (mTileGrid[x][y] > 0) {
canvas.drawBitmap(mTileArray[mTileGrid[x][y]],
mXOffset + x * mTileSize,
mYOffset + y * mTileSize,
mPaint);
}
}
}
| protected void | onSizeChanged(int w, int h, int oldw, int oldh)
mXTileCount = (int) Math.floor(w / mTileSize);
mYTileCount = (int) Math.floor(h / mTileSize);
mXOffset = ((w - (mTileSize * mXTileCount)) / 2);
mYOffset = ((h - (mTileSize * mYTileCount)) / 2);
mTileGrid = new int[mXTileCount][mYTileCount];
clearTiles();
| public void | resetTiles(int tilecount)Rests the internal array of Bitmaps used for drawing tiles, and
sets the maximum index of tiles to be inserted
mTileArray = new Bitmap[tilecount];
| public void | setTile(int tileindex, int x, int y)Used to indicate that a particular tile (set with loadTile and referenced
by an integer) should be drawn at the given x/y coordinates during the
next invalidate/draw cycle.
mTileGrid[x][y] = tileindex;
|
|