blob: 4e2ccc3eb8707929d58959a69e679c8978311977 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
|
package com.android.gallery3d.filtershow.imageshow;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Rect;
import android.util.AttributeSet;
import android.view.MotionEvent;
public class ImageZoom extends ImageSlave {
private boolean mTouchDown = false;
private boolean mZoomedIn = false;
private Rect mZoomBounds = null;
public ImageZoom(Context context) {
super(context);
}
public ImageZoom(Context context, AttributeSet attrs) {
super(context, attrs);
}
@Override
public void onTouchDown(float x, float y) {
super.onTouchDown(x, y);
if (mZoomedIn || mTouchDown) {
return;
}
mTouchDown = true;
Rect originalBounds = mImageLoader.getOriginalBounds();
Rect imageBounds = getImageBounds();
float touchX = x - imageBounds.left;
float touchY = y - imageBounds.top;
float w = originalBounds.width();
float h = originalBounds.height();
float ratio = w / h;
int mw = getWidth() / 2;
int mh = getHeight() / 2;
int cx = (int) (w / 2);
int cy = (int) (h / 2);
cx = (int) (touchX / imageBounds.width() * w);
cy = (int) (touchY / imageBounds.height() * h);
int left = cx - mw;
int top = cy - mh;
mZoomBounds = new Rect(left, top, left + mw * 2, top + mh * 2);
}
@Override
public void onTouchUp() {
mTouchDown = false;
}
@Override
public void onDraw(Canvas canvas) {
drawBackground(canvas);
Bitmap filteredImage = null;
if ((mZoomedIn ||mTouchDown) && mImageLoader != null) {
filteredImage = mImageLoader.getScaleOneImageForPreset(this, getImagePreset(), mZoomBounds, false);
} else {
getFilteredImage();
filteredImage = mFilteredImage;
}
drawImage(canvas, filteredImage);
if (showControls()) {
mSliderController.onDraw(canvas);
}
drawToast(canvas);
}
@Override
public boolean onDoubleTap(MotionEvent event) {
if (!mZoomedIn) {
onTouchDown(event.getX(), event.getY());
} else {
onTouchUp();
}
mZoomedIn = !mZoomedIn;
invalidate();
return false;
}
}
|