1 |
|
|
2 |
|
package pl.magot.vetch.widgets; |
3 |
|
|
4 |
|
|
5 |
|
import android.content.Context; |
6 |
|
import android.graphics.Canvas; |
7 |
|
import android.graphics.Paint; |
8 |
|
import android.util.AttributeSet; |
9 |
|
import android.view.*; |
10 |
|
import android.widget.EditText; |
11 |
|
import android.graphics.*; |
12 |
|
|
13 |
|
|
|
|
| 89,5% |
Uncovered Elements: 9 (86) |
Complexity: 16 |
Complexity Density: 0,26 |
|
14 |
|
public class TouchEdit extends EditText |
15 |
|
{ |
16 |
|
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 0 |
Complexity Density: - |
|
17 |
|
public interface OnOpenKeyboard |
18 |
|
{ |
19 |
|
public void OnOpenKeyboardEvent(); |
20 |
|
} |
21 |
|
|
22 |
|
|
23 |
|
protected OnOpenKeyboard mEventOnOpenKeyboard = null; |
24 |
|
|
25 |
|
|
26 |
|
private final static int iEditHeight = 54; |
27 |
|
private final static int iArrowWidth = 20; |
28 |
|
private final static int iArrowHeight = 16; |
29 |
|
private final static int iMarginHorz = 3; |
30 |
|
private final static int iMarginVertTop = 4; |
31 |
|
private final static int iMarginVertBottom = 8; |
32 |
|
|
33 |
|
|
34 |
|
private RectF rect = new RectF(); |
35 |
|
private int iDelta = 0; |
36 |
|
private Paint pt = new Paint(); |
37 |
|
private boolean bTouchedDown = false; |
38 |
|
|
39 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
40 |
0
|
public TouchEdit(Context context)... |
41 |
|
{ |
42 |
0
|
super(context); |
43 |
|
} |
44 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
45 |
21
|
@SuppressWarnings("all")... |
46 |
|
public TouchEdit(Context context, AttributeSet attrs) |
47 |
|
{ |
48 |
21
|
super(context, attrs); |
49 |
|
} |
50 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0,5 |
|
51 |
21
|
public void setOnOpenKeyboard(OnOpenKeyboard openKeyboard) ... |
52 |
|
{ |
53 |
|
|
54 |
21
|
this.mEventOnOpenKeyboard = openKeyboard; |
55 |
|
|
56 |
21
|
setOnLongClickListener(new EditText.OnLongClickListener() |
57 |
|
{ |
|
|
| 80% |
Uncovered Elements: 1 (5) |
Complexity: 2 |
Complexity Density: 0,67 |
|
58 |
1
|
public boolean onLongClick(View arg0)... |
59 |
|
{ |
60 |
1
|
if (mEventOnOpenKeyboard != null) |
61 |
1
|
mEventOnOpenKeyboard.OnOpenKeyboardEvent(); |
62 |
1
|
return true; |
63 |
|
} |
64 |
|
}); |
65 |
|
} |
66 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (23) |
Complexity: 2 |
Complexity Density: 0,1 |
|
67 |
418
|
@Override... |
68 |
|
protected void onDraw(Canvas canvas) |
69 |
|
{ |
70 |
418
|
super.onDraw(canvas); |
71 |
|
|
72 |
418
|
if (bTouchedDown) |
73 |
|
{ |
74 |
20
|
final int iOffsetY = this.getScrollY(); |
75 |
|
|
76 |
20
|
pt.setAntiAlias(true); |
77 |
20
|
pt.setStrokeCap(Paint.Cap.ROUND); |
78 |
|
|
79 |
20
|
pt.setColor(0x88ffffff); |
80 |
20
|
canvas.drawRect(iMarginHorz, iMarginVertTop + iOffsetY, getWidth() - iMarginHorz, getHeight() - iMarginVertBottom + iOffsetY, pt); |
81 |
|
|
82 |
20
|
int iLeft = this.getWidth() - iArrowWidth - 12; |
83 |
20
|
int iTop = (iEditHeight >> 1) - (iArrowHeight >> 1) + iOffsetY; |
84 |
|
|
85 |
20
|
rect.set(iLeft, iTop, iLeft + iArrowWidth, iTop + iArrowHeight); |
86 |
|
|
87 |
|
|
88 |
20
|
drawDottedLine(canvas); |
89 |
|
|
90 |
|
|
91 |
20
|
pt.setStrokeWidth(7); |
92 |
20
|
pt.setColor(0xff3366bb); |
93 |
20
|
canvas.drawLine(rect.left, rect.centerY(), rect.right, rect.centerY(), pt); |
94 |
20
|
canvas.drawLine(rect.right, rect.centerY(), rect.right - 6, rect.top, pt); |
95 |
20
|
canvas.drawLine(rect.right, rect.centerY(), rect.right - 6, rect.bottom, pt); |
96 |
|
|
97 |
|
|
98 |
20
|
pt.setStrokeWidth(4); |
99 |
20
|
pt.setColor(0xff66bbff); |
100 |
20
|
canvas.drawLine(rect.left, rect.centerY(), rect.right, rect.centerY(), pt); |
101 |
20
|
canvas.drawLine(rect.right, rect.centerY(), rect.right - 6, rect.top, pt); |
102 |
20
|
canvas.drawLine(rect.right, rect.centerY(), rect.right - 6, rect.bottom, pt); |
103 |
|
} |
104 |
|
} |
105 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (12) |
Complexity: 2 |
Complexity Density: 0,2 |
|
106 |
20
|
private void drawDottedLine(Canvas canvas)... |
107 |
|
{ |
108 |
20
|
int iSpace = 12; |
109 |
20
|
int iPosX = 0; |
110 |
80
|
for (int i = 0; i < 3; i++) |
111 |
|
{ |
112 |
60
|
iPosX += iSpace; |
113 |
60
|
pt.setStrokeWidth(7); |
114 |
60
|
pt.setColor(0xff3366bb); |
115 |
60
|
canvas.drawPoint(rect.left - iPosX, rect.centerY(), pt); |
116 |
60
|
pt.setStrokeWidth(4); |
117 |
60
|
pt.setColor(0xff66bbff); |
118 |
60
|
canvas.drawPoint(rect.left - iPosX, rect.centerY(), pt); |
119 |
|
} |
120 |
|
} |
121 |
|
|
|
|
| 82,9% |
Uncovered Elements: 6 (35) |
Complexity: 7 |
Complexity Density: 0,3 |
|
122 |
152
|
@Override... |
123 |
|
public boolean onTouchEvent(MotionEvent event) |
124 |
|
{ |
125 |
152
|
super.onTouchEvent(event); |
126 |
|
|
127 |
152
|
boolean bHandled = false; |
128 |
|
|
129 |
152
|
if (event.getAction() == MotionEvent.ACTION_DOWN) |
130 |
|
{ |
131 |
18
|
iDelta = (int)event.getX(); |
132 |
18
|
bTouchedDown = true; |
133 |
18
|
invalidate(); |
134 |
18
|
bHandled = true; |
135 |
|
} |
136 |
152
|
if (event.getAction() == MotionEvent.ACTION_CANCEL) |
137 |
|
{ |
138 |
0
|
iDelta = 0; |
139 |
0
|
bTouchedDown = false; |
140 |
0
|
invalidate(); |
141 |
0
|
bHandled = true; |
142 |
|
} |
143 |
152
|
if (event.getAction() == MotionEvent.ACTION_UP) |
144 |
|
{ |
145 |
18
|
bTouchedDown = false; |
146 |
18
|
invalidate(); |
147 |
18
|
int iRange = (this.getWidth() >> 2); |
148 |
18
|
if (((int)event.getX() - iDelta) > iRange) |
149 |
|
{ |
150 |
4
|
if (mEventOnOpenKeyboard != null) |
151 |
|
{ |
152 |
4
|
mEventOnOpenKeyboard.OnOpenKeyboardEvent(); |
153 |
4
|
bHandled = true; |
154 |
|
} |
155 |
|
} |
156 |
|
} |
157 |
152
|
if (event.getAction() == MotionEvent.ACTION_MOVE) |
158 |
|
{ |
159 |
116
|
bHandled = true; |
160 |
|
} |
161 |
|
|
162 |
152
|
return bHandled; |
163 |
|
} |
164 |
|
|
165 |
|
} |