Repository navigation
Expand file tree
/
Copy pathEyeView.java
More file actions
63 lines (53 loc) · 1.71 KB
/
Copy pathEyeView.java
File metadata and controls
63 lines (53 loc) · 1.71 KB
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
package com.bluemor.pulllayout;
import android.annotation.SuppressLint;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.PorterDuff;
import android.graphics.PorterDuffXfermode;
import android.os.Build;
import android.util.AttributeSet;
import android.widget.FrameLayout;
public class EyeView extends FrameLayout {
private Paint paint;
private Bitmap bitmap;
public EyeView(Context context) {
super(context);
init();
}
public EyeView(Context context, AttributeSet attrs) {
super(context, attrs);
init();
}
public EyeView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
init();
}
@SuppressLint("NewApi")
private void init() {
setDrawingCacheEnabled(true);
if (Build.VERSION.SDK_INT >= 11) {
setLayerType(LAYER_TYPE_SOFTWARE, null);
}
paint = new Paint(Paint.ANTI_ALIAS_FLAG);
}
@Override
protected void dispatchDraw(Canvas canvas) {
super.dispatchDraw(canvas);
if (bitmap != null) {
paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.DST_IN));
canvas.drawBitmap(bitmap, 0, 0, paint);
paint.setXfermode(null);
}
}
public void setRadius(int radius) {
if (bitmap != null && !bitmap.isRecycled()) {
bitmap.recycle();
}
bitmap = Bitmap.createBitmap(getWidth(), getHeight(), Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(bitmap);
canvas.drawCircle(getWidth() / 2f, getHeight() / 2f, radius, paint);
invalidate();
}
}