Methods Summary |
---|
public void | addStroke(GestureStroke stroke)Adds a stroke to the gesture.
mStrokes.add(stroke);
mBoundingBox.union(stroke.boundingBox);
|
public java.lang.Object | clone()
Gesture gesture = new Gesture();
gesture.mBoundingBox.set(mBoundingBox.left, mBoundingBox.top,
mBoundingBox.right, mBoundingBox.bottom);
final int count = mStrokes.size();
for (int i = 0; i < count; i++) {
GestureStroke stroke = mStrokes.get(i);
gesture.mStrokes.add((GestureStroke)stroke.clone());
}
return gesture;
|
public int | describeContents()
return 0;
|
static android.gesture.Gesture | deserialize(java.io.DataInputStream in)
final Gesture gesture = new Gesture();
// Gesture ID
gesture.mGestureID = in.readLong();
// Number of strokes
final int count = in.readInt();
for (int i = 0; i < count; i++) {
gesture.addStroke(GestureStroke.deserialize(in));
}
return gesture;
|
public android.graphics.RectF | getBoundingBox()
return mBoundingBox;
|
public long | getID()
return mGestureID;
|
public float | getLength()Calculates the total length of the gesture. When there are multiple strokes in
the gesture, this returns the sum of the lengths of all the strokes.
int len = 0;
final ArrayList<GestureStroke> strokes = mStrokes;
final int count = strokes.size();
for (int i = 0; i < count; i++) {
len += strokes.get(i).length;
}
return len;
|
public java.util.ArrayList | getStrokes()
return mStrokes;
|
public int | getStrokesCount()
return mStrokes.size();
|
void | serialize(java.io.DataOutputStream out)
final ArrayList<GestureStroke> strokes = mStrokes;
final int count = strokes.size();
// Write gesture ID
out.writeLong(mGestureID);
// Write number of strokes
out.writeInt(count);
for (int i = 0; i < count; i++) {
strokes.get(i).serialize(out);
}
|
void | setID(long id)Sets the id of the gesture.
mGestureID = id;
|
public android.graphics.Bitmap | toBitmap(int width, int height, int edge, int numSample, int color)Creates a bitmap of the gesture with a transparent background.
final Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
final Canvas canvas = new Canvas(bitmap);
canvas.translate(edge, edge);
final Paint paint = new Paint();
paint.setAntiAlias(BITMAP_RENDERING_ANTIALIAS);
paint.setDither(BITMAP_RENDERING_DITHER);
paint.setColor(color);
paint.setStyle(Paint.Style.STROKE);
paint.setStrokeJoin(Paint.Join.ROUND);
paint.setStrokeCap(Paint.Cap.ROUND);
paint.setStrokeWidth(BITMAP_RENDERING_WIDTH);
final ArrayList<GestureStroke> strokes = mStrokes;
final int count = strokes.size();
for (int i = 0; i < count; i++) {
Path path = strokes.get(i).toPath(width - 2 * edge, height - 2 * edge, numSample);
canvas.drawPath(path, paint);
}
return bitmap;
|
public android.graphics.Bitmap | toBitmap(int width, int height, int inset, int color)Creates a bitmap of the gesture with a transparent background.
final Bitmap bitmap = Bitmap.createBitmap(width, height,
Bitmap.Config.ARGB_8888);
final Canvas canvas = new Canvas(bitmap);
final Paint paint = new Paint();
paint.setAntiAlias(BITMAP_RENDERING_ANTIALIAS);
paint.setDither(BITMAP_RENDERING_DITHER);
paint.setColor(color);
paint.setStyle(Paint.Style.STROKE);
paint.setStrokeJoin(Paint.Join.ROUND);
paint.setStrokeCap(Paint.Cap.ROUND);
paint.setStrokeWidth(BITMAP_RENDERING_WIDTH);
final Path path = toPath();
final RectF bounds = new RectF();
path.computeBounds(bounds, true);
final float sx = (width - 2 * inset) / bounds.width();
final float sy = (height - 2 * inset) / bounds.height();
final float scale = sx > sy ? sy : sx;
paint.setStrokeWidth(2.0f / scale);
path.offset(-bounds.left + (width - bounds.width() * scale) / 2.0f,
-bounds.top + (height - bounds.height() * scale) / 2.0f);
canvas.translate(inset, inset);
canvas.scale(scale, scale);
canvas.drawPath(path, paint);
return bitmap;
|
public android.graphics.Path | toPath(int width, int height, int edge, int numSample)
return toPath(null, width, height, edge, numSample);
|
public android.graphics.Path | toPath(android.graphics.Path path, int width, int height, int edge, int numSample)
if (path == null) path = new Path();
final ArrayList<GestureStroke> strokes = mStrokes;
final int count = strokes.size();
for (int i = 0; i < count; i++) {
path.addPath(strokes.get(i).toPath(width - 2 * edge, height - 2 * edge, numSample));
}
return path;
|
public android.graphics.Path | toPath()
return toPath(null);
|
public android.graphics.Path | toPath(android.graphics.Path path)
if (path == null) path = new Path();
final ArrayList<GestureStroke> strokes = mStrokes;
final int count = strokes.size();
for (int i = 0; i < count; i++) {
path.addPath(strokes.get(i).getPath());
}
return path;
|
public void | writeToParcel(android.os.Parcel out, int flags)
out.writeLong(mGestureID);
boolean result = false;
final ByteArrayOutputStream byteStream =
new ByteArrayOutputStream(GestureConstants.IO_BUFFER_SIZE);
final DataOutputStream outStream = new DataOutputStream(byteStream);
try {
serialize(outStream);
result = true;
} catch (IOException e) {
Log.e(GestureConstants.LOG_TAG, "Error writing Gesture to parcel:", e);
} finally {
GestureUtils.closeStream(outStream);
GestureUtils.closeStream(byteStream);
}
if (result) {
out.writeByteArray(byteStream.toByteArray());
}
|