private boolean containPoint(View view, float x, float y) {
Rect rect = new Rect();
view.getHitRect(rect);
Transformation trans = new Transformation();
Animation anim = view.getAnimation();
anim.getTransformation(view.getDrawingTime(), trans);
float dx = view.getLeft();
float dy = view.getTop();
Matrix matTranslate = new Matrix();
matTranslate.postTranslate(dx, dy);
Matrix matrix = trans.getMatrix();
matrix.postConcat(matTranslate);
// 求逆矩阵
Matrix mat = new Matrix();
if (matrix.invert(mat)) {
float[] pointsSrc = new float[] { x, y };
float[] pointsEnd = new float[] { 0, 0 };
// Get the point in inverted matrix.
mat.mapPoints(pointsEnd, pointsSrc);
// Offset the point because we translate matrix which dx and dy before.
x = pointsEnd[0] + dx;
y = pointsEnd[1] + dy;
x = (int)pointsEnd[0] + (int)dx;
y = (int)pointsEnd[1] + (int)dy;
}
return rect.contains((int)x, (int)y);
}
protected Rect mapRect(Matrix matrix, Rect srcRect) {
float[] values = new float[9];
matrix.getValues(values);
float scaleX = values[0];
float scaleY = values[4];
float left = srcRect.left + srcRect.width() * (1 - scaleX) / 2;
float top = srcRect.top + srcRect.height() * (1 - scaleY) / 2;
float right = srcRect.top - srcRect.width() * (1 - scaleX) / 2;
float bottom = srcRect.bottom - srcRect.height() * (1 - scaleY) / 2;
Rect rect = new Rect((int)left, (int)top, (int)right, (int)bottom);
return rect;
}
|