summaryrefslogtreecommitdiffstats
path: root/tests/TileBenchmark/src/com/test/tilebenchmark/PlaybackView.java
diff options
context:
space:
mode:
Diffstat (limited to 'tests/TileBenchmark/src/com/test/tilebenchmark/PlaybackView.java')
-rw-r--r--tests/TileBenchmark/src/com/test/tilebenchmark/PlaybackView.java122
1 files changed, 88 insertions, 34 deletions
diff --git a/tests/TileBenchmark/src/com/test/tilebenchmark/PlaybackView.java b/tests/TileBenchmark/src/com/test/tilebenchmark/PlaybackView.java
index f104eac..edc8643 100644
--- a/tests/TileBenchmark/src/com/test/tilebenchmark/PlaybackView.java
+++ b/tests/TileBenchmark/src/com/test/tilebenchmark/PlaybackView.java
@@ -16,6 +16,9 @@
package com.test.tilebenchmark;
+import android.animation.ArgbEvaluator;
+import android.animation.ObjectAnimator;
+import android.animation.ValueAnimator;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
@@ -30,8 +33,9 @@ import android.view.View;
import java.util.ArrayList;
public class PlaybackView extends View {
- public static final int TILEX = 300;
- public static final int TILEY = 300;
+ public static final int TILE_SCALE = 300;
+ private static final int INVAL_FLAG = -2;
+ private static final int INVAL_CYCLE = 250;
private Paint levelPaint = null, coordPaint = null, goldPaint = null;
private PlaybackGraphs mGraphs;
@@ -39,28 +43,46 @@ public class PlaybackView extends View {
private ArrayList<ShapeDrawable> mTempShapes = new ArrayList<ShapeDrawable>();
private TileData mProfData[][] = null;
private GestureDetector mGestureDetector = null;
- private String mRenderStrings[] = new String[3];
+ private String mRenderStrings[] = new String[4];
private class TileDrawable extends ShapeDrawable {
TileData tile;
+ String label;
- public TileDrawable(TileData t) {
- int tileColorId = t.isReady ? R.color.ready_tile
- : R.color.unready_tile;
- getPaint().setColor(getResources().getColor(tileColorId));
-
- setBounds(t.x * TILEX, t.y * TILEY, (t.x + 1) * TILEX, (t.y + 1)
- * TILEY);
+ public TileDrawable(TileData t, int colorId) {
this.tile = t;
+ getPaint().setColor(getResources().getColor(colorId));
+ if (colorId == R.color.ready_tile
+ || colorId == R.color.unready_tile) {
+
+ label = (int) (t.left / TILE_SCALE) + ", "
+ + (int) (t.top / TILE_SCALE);
+ // ignore scale value for tiles
+ setBounds(t.left, t.top,
+ t.right, t.bottom);
+ } else {
+ setBounds((int) (t.left * t.scale),
+ (int) (t.top * t.scale),
+ (int) (t.right * t.scale),
+ (int) (t.bottom * t.scale));
+ }
+ }
+
+ @SuppressWarnings("unused")
+ public void setColor(int color) {
+ getPaint().setColor(color);
}
@Override
public void draw(Canvas canvas) {
super.draw(canvas);
- canvas.drawText(Integer.toString(tile.level), getBounds().left,
- getBounds().bottom, levelPaint);
- canvas.drawText(tile.x + "," + tile.y, getBounds().left,
- ((getBounds().bottom + getBounds().top) / 2), coordPaint);
+ if (label != null) {
+ canvas.drawText(Integer.toString(tile.level), getBounds().left,
+ getBounds().bottom, levelPaint);
+ canvas.drawText(label, getBounds().left,
+ ((getBounds().bottom + getBounds().top) / 2),
+ coordPaint);
+ }
}
}
@@ -92,10 +114,10 @@ public class PlaybackView extends View {
private void init() {
levelPaint = new Paint();
levelPaint.setColor(Color.WHITE);
- levelPaint.setTextSize(TILEY / 2);
+ levelPaint.setTextSize(TILE_SCALE / 2);
coordPaint = new Paint();
coordPaint.setColor(Color.BLACK);
- coordPaint.setTextSize(TILEY / 3);
+ coordPaint.setTextSize(TILE_SCALE / 3);
goldPaint = new Paint();
goldPaint.setColor(0xffa0e010);
mGraphs = new PlaybackGraphs();
@@ -110,6 +132,7 @@ public class PlaybackView extends View {
}
mGraphs.draw(canvas, mTempShapes, mRenderStrings, getResources());
+ invalidate(); // may have animations, force redraw
}
public int setFrame(int frame) {
@@ -117,35 +140,66 @@ public class PlaybackView extends View {
return 0;
}
- int readyTiles = 0, unreadyTiles = 0, unplacedTiles = 0;
+ int readyTiles = 0, unreadyTiles = 0, unplacedTiles = 0, numInvals = 0;
mTempShapes.clear();
- // draw actual tiles
- for (int tileID = 2; tileID < mProfData[frame].length; tileID++) {
- TileData t = mProfData[frame][tileID];
- mTempShapes.add(new TileDrawable(t));
- if (t.isReady) {
- readyTiles++;
+ // create tile shapes (as they're drawn on bottom)
+ for (TileData t : mProfData[frame]) {
+ if (t.level != INVAL_FLAG && t != mProfData[frame][0]) {
+ int colorId;
+ if (t.isReady) {
+ readyTiles++;
+ colorId = R.color.ready_tile;
+ } else {
+ unreadyTiles++;
+ colorId = R.color.unready_tile;
+ }
+ if (t.left < 0 || t.top < 0) {
+ unplacedTiles++;
+ }
+ mTempShapes.add(new TileDrawable(t, colorId));
} else {
- unreadyTiles++;
+ numInvals++;
}
- if (t.x < 0 || t.y < 0) {
- unplacedTiles++;
+ }
+
+ // create invalidate shapes (drawn above tiles)
+ int invalId = 0;
+ for (TileData t : mProfData[frame]) {
+ if (t.level == INVAL_FLAG && t != mProfData[frame][0]) {
+ TileDrawable invalShape = new TileDrawable(t,
+ R.color.inval_region_start);
+ ValueAnimator tileAnimator = ObjectAnimator.ofInt(invalShape,
+ "color",
+ getResources().getColor(R.color.inval_region_start),
+ getResources().getColor(R.color.inval_region_stop));
+ tileAnimator.setDuration(numInvals * INVAL_CYCLE);
+ tileAnimator.setEvaluator(new ArgbEvaluator());
+ tileAnimator.setRepeatCount(ValueAnimator.INFINITE);
+ tileAnimator.setRepeatMode(ValueAnimator.RESTART);
+ float delay = (float) (invalId) * INVAL_CYCLE;
+ tileAnimator.setStartDelay((int) delay);
+ invalId++;
+ tileAnimator.start();
+
+ mTempShapes.add(invalShape);
}
}
+
mRenderStrings[0] = getResources().getString(R.string.format_stat_name,
getResources().getString(R.string.ready_tiles), readyTiles);
mRenderStrings[1] = getResources().getString(R.string.format_stat_name,
getResources().getString(R.string.unready_tiles), unreadyTiles);
mRenderStrings[2] = getResources().getString(R.string.format_stat_name,
- getResources().getString(R.string.unplaced_tiles), unplacedTiles);
-
- // draw view rect (using first two TileData objects)
- ShapeDrawable viewShape = new ShapeDrawable();
- viewShape.getPaint().setColor(0xff0000ff);
- viewShape.setAlpha(64);
- viewShape.setBounds(mProfData[frame][0].x, mProfData[frame][0].y,
- mProfData[frame][1].x, mProfData[frame][1].y);
+ getResources().getString(R.string.unplaced_tiles),
+ unplacedTiles);
+ mRenderStrings[3] = getResources().getString(R.string.format_stat_name,
+ getResources().getString(R.string.number_invalidates),
+ numInvals);
+
+ // draw view rect (using first TileData object, on top)
+ TileDrawable viewShape = new TileDrawable(mProfData[frame][0],
+ R.color.view);
mTempShapes.add(viewShape);
this.invalidate();
return frame;