[java] view plaincopy
private void transformImageBitmap(ImageView child, Transformation t,
int rotationAngle) {
mCamera.save();
final Matrix imageMatrix = t.getMatrix();
imageHeight = child.getLayoutParams().height;
imageWidth = child.getLayoutParams().width;
final int rotation = Math.abs(rotationAngle);
Log.i("msg", imageHeight+ ","+imageWidth);
mCamera.translate(0.0f, 0.0f, 60.0f);
// As the angle of the view gets less, zoom in
if (rotation < mMaxRotationAngle) {
float zoomAmount = (float) (mMaxZoom + (rotation * 1.5));
mCamera.translate(0.0f, 0.0f, zoomAmount);
}
mCamera.rotateY(-rotationAngle);
mCamera.getMatrix(imageMatrix);
imageMatrix.preTranslate(-(imageWidth / 2), -(imageHeight / 2));
imageMatrix.postTranslate((imageWidth / 2), (imageHeight / 2));
mCamera.restore();
if(changed){ // 保证在滑动的时候不会恢复坐标
int[] location = new int[2];
child.getLocationOnScreen(location);
int x = location[0];
int y = location[1];
left_move_x = x - imageWidth / 4;
left_move_y = y - (imageHeight / 8);
left_line_x_01 = left_move_x * 2;
left_line_y_01 = left_move_y + 20;
left_line_x_02 = left_line_x_01;
left_line_y_02 = left_line_y_01 + (imageHeight / 3);
left_line_x_03 = left_move_x;
left_line_y_03 = left_line_y_02 + 20;
right_move_x = x + (imageWidth + imageWidth / 3);
right_move_y = y - (imageHeight / 8);
right_line_x_01 = right_move_x - imageWidth / 2;
right_line_y_01 = left_move_y + 20;
right_line_x_02 = right_line_x_01;
right_line_y_02 = right_line_y_01 + (imageHeight / 3);
right_line_x_03 = right_move_x;
right_line_y_03 = right_line_y_02 + 20;
moveLeftX = left_move_x - 10;
moveRightX = right_move_x + 10;
moveLineLeftX = left_move_x;
moveLineRightX = right_move_x;
this.invalidate();
}
}
@Override
public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX,
float velocityY) {
return false;
}
@Override
public boolean onTouchEvent(MotionEvent event) {
switch(event.getAction()) {
case MotionEvent.ACTION_DOWN:
eventX = event.getX();
changed = false;
break;
case MotionEvent.ACTION_UP:
changed = true;
break;
case MotionEvent.ACTION_MOVE:
if (event.getX() > eventX) { // to right
// if(left_move_x > moveLeftX) {
// --left_move_x;
// --left_line_x_03;
//
// --right_move_x;
// --right_line_x_03;
// }
// if(left_line_x_01 > moveLineLeftX) {
// --left_line_x_01; --left_line_x_02;
// --right_line_x_01; --right_line_x_02;
// }
} else if (event.getX() < eventX) { // to left
if(right_move_x < moveRightX) {
++left_move_x;
++left_line_x_03;
++right_move_x;
++right_line_x_03;
}
if(right_line_x_01 < moveLineRightX) {
++left_line_x_01; ++left_line_x_02;
++right_line_x_01; ++right_line_x_02;
}
}
break;
}
return super.onTouchEvent(event);
}
private int left_move_x, left_move_y, left_line_x_01,
left_line_x_02, left_line_x_03,
left_line_y_01, left_line_y_02, left_line_y_03;
private int right_move_x, right_move_y, right_line_x_01,
right_line_x_02, right_line_x_03,
right_line_y_01, right_line_y_02, right_line_y_03;
private float eventX;
private int moveLeftX, moveRightX, moveLineLeftX, moveLineRightX;
private boolean changed = true;
@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
// Paint black = new Paint();
// black.setAntiAlias(true);
// black.setColor(Color.GRAY);
// Path left=new Path();
// left.moveTo(left_move_x, left_move_y);
// left.lineTo(left_line_x_01, left_line_y_01);
// left.lineTo(left_line_x_02, left_line_y_02);
// left.lineTo(left_line_x_03, left_line_y_03);
// left.close();
// canvas.drawPath(left, black);
//
// Path right=new Path();
// right.moveTo(right_move_x, right_move_y);
// right.lineTo(right_line_x_01, right_line_y_01);
// right.lineTo(right_line_x_02, right_line_y_02);
// right.lineTo(right_line_x_03, right_line_y_03);
// right.close();
// canvas.drawPath(right, black);
Bitmap bm = BitmapFactory.decodeResource(getResources(), R.drawable.home_black_bg);
int width = bm.getWidth();
int height = bm.getHeight();
if(imageWidth > 0 && imageHeight > 0) {
Matrix d_matrix = new Matrix();
d_matrix.preScale(1, -1);
Bitmap d_reflectionBitmap = Bitmap.createBitmap(bm, 0, height / 2, width, height / 4, d_matrix, false);
// Paint paint = new Paint();
// LinearGradient shader = new LinearGradient(0, height,
// 0, height + d_reflectionBitmap.getHeight(), 0x70ffffff, 0x00ffffff,
// TileMode.MIRROR);
// paint.setShader(shader);
// paint.setXfermode(new PorterDuffXfermode(Mode.DST_IN));
// canvas.drawRect(left_move_x, left_move_y + height, 0, 0, paint);
canvas.drawBitmap(bm, left_move_x, left_move_y, null);
canvas.drawBitmap(bm, right_move_x, left_move_y, null);
}
}