PointCloudpublic class PointCloud extends Object
Fields Summary |
---|
private static final float | MIN_POINT_SIZE | private static final float | MAX_POINT_SIZE | private static final int | INNER_POINTS | private static final String | TAG | private ArrayList | mPointCloud | private android.graphics.drawable.Drawable | mDrawable | private float | mCenterX | private float | mCenterY | private android.graphics.Paint | mPaint | private float | mScale | private static final float | PI | WaveManager | waveManager | GlowManager | glowManager | private float | mOuterRadius |
Constructors Summary |
---|
public PointCloud(android.graphics.drawable.Drawable drawable)
mPaint = new Paint();
mPaint.setFilterBitmap(true);
mPaint.setColor(Color.rgb(255, 255, 255)); // TODO: make configurable
mPaint.setAntiAlias(true);
mPaint.setDither(true);
mDrawable = drawable;
if (mDrawable != null) {
drawable.setBounds(0, 0, drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight());
}
|
Methods Summary |
---|
public void | draw(android.graphics.Canvas canvas)
ArrayList<Point> points = mPointCloud;
canvas.save(Canvas.MATRIX_SAVE_FLAG);
canvas.scale(mScale, mScale, mCenterX, mCenterY);
for (int i = 0; i < points.size(); i++) {
Point point = points.get(i);
final float pointSize = interp(MAX_POINT_SIZE, MIN_POINT_SIZE,
point.radius / mOuterRadius);
final float px = point.x + mCenterX;
final float py = point.y + mCenterY;
int alpha = getAlphaForPoint(point);
if (alpha == 0) continue;
if (mDrawable != null) {
canvas.save(Canvas.MATRIX_SAVE_FLAG);
final float cx = mDrawable.getIntrinsicWidth() * 0.5f;
final float cy = mDrawable.getIntrinsicHeight() * 0.5f;
final float s = pointSize / MAX_POINT_SIZE;
canvas.scale(s, s, px, py);
canvas.translate(px - cx, py - cy);
mDrawable.setAlpha(alpha);
mDrawable.draw(canvas);
canvas.restore();
} else {
mPaint.setAlpha(alpha);
canvas.drawCircle(px, py, pointSize, mPaint);
}
}
canvas.restore();
| public int | getAlphaForPoint(com.android.internal.widget.multiwaveview.PointCloud$Point point)
// Contribution from positional glow
float glowDistance = hypot(glowManager.x - point.x, glowManager.y - point.y);
float glowAlpha = 0.0f;
if (glowDistance < glowManager.radius) {
float cosf = FloatMath.cos(PI * 0.25f * glowDistance / glowManager.radius);
glowAlpha = glowManager.alpha * max(0.0f, (float) Math.pow(cosf, 10.0f));
}
// Compute contribution from Wave
float radius = hypot(point.x, point.y);
float waveAlpha = 0.0f;
if (radius < waveManager.radius * 2) {
float distanceToWaveRing = (radius - waveManager.radius);
float cosf = FloatMath.cos(PI * 0.5f * distanceToWaveRing / waveManager.radius);
waveAlpha = waveManager.alpha * max(0.0f, (float) Math.pow(cosf, 6.0f));
}
return (int) (max(glowAlpha, waveAlpha) * 255);
| public float | getScale()
return mScale;
| private static float | hypot(float x, float y)
return FloatMath.sqrt(x*x + y*y);
| private float | interp(float min, float max, float f)
return min + (max - min) * f;
| public void | makePointCloud(float innerRadius, float outerRadius)
if (innerRadius == 0) {
Log.w(TAG, "Must specify an inner radius");
return;
}
mOuterRadius = outerRadius;
mPointCloud.clear();
final float pointAreaRadius = (outerRadius - innerRadius);
final float ds = (2.0f * PI * innerRadius / INNER_POINTS);
final int bands = (int) Math.round(pointAreaRadius / ds);
final float dr = pointAreaRadius / bands;
float r = innerRadius;
for (int b = 0; b <= bands; b++, r += dr) {
float circumference = 2.0f * PI * r;
final int pointsInBand = (int) (circumference / ds);
float eta = PI/2.0f;
float dEta = 2.0f * PI / pointsInBand;
for (int i = 0; i < pointsInBand; i++) {
float x = r * FloatMath.cos(eta);
float y = r * FloatMath.sin(eta);
eta += dEta;
mPointCloud.add(new Point(x, y, r));
}
}
| private static float | max(float a, float b)
return a > b ? a : b;
| public void | setCenter(float x, float y)
mCenterX = x;
mCenterY = y;
| public void | setScale(float scale)
mScale = scale;
|
|