1 |
|
|
2 |
|
package pl.magot.vetch.widgets; |
3 |
|
|
4 |
|
|
5 |
|
import android.graphics.RectF; |
6 |
|
import android.view.*; |
7 |
|
|
8 |
|
|
|
|
| 88,7% |
Uncovered Elements: 8 (71) |
Complexity: 20 |
Complexity Density: 0,44 |
|
9 |
|
public class KeyItem |
10 |
|
{ |
11 |
|
|
12 |
|
protected final static int kDefault = 0; |
13 |
|
protected final static int kDefaultSpace = 1; |
14 |
|
protected final static int kMode = 2; |
15 |
|
protected final static int kDelete = 3; |
16 |
|
protected final static int kAlphaCycle = 4; |
17 |
|
protected final static int kReturn = 5; |
18 |
|
|
19 |
|
|
20 |
|
public String sChar = null; |
21 |
|
public String sCharSmall = null; |
22 |
|
public int iCode = KeyEvent.KEYCODE_UNKNOWN; |
23 |
|
public boolean bAlt = false; |
24 |
|
public int iType = kDefault; |
25 |
|
|
26 |
|
|
27 |
|
public RectF rectFocus = new RectF(); |
28 |
|
public RectF rectFrame = new RectF(); |
29 |
|
|
30 |
|
|
31 |
|
public int iSymbolWidth = 0; |
32 |
|
public int iSymbolHeight = 0; |
33 |
|
public boolean bIsActive = false; |
34 |
|
|
35 |
|
|
36 |
|
private KeyItem keyDelete = null; |
37 |
|
private KeyItem[] cycleKeys = null; |
38 |
|
private int iCycleIndex = 0; |
39 |
|
private long lClickTime = 0; |
40 |
|
|
41 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (5) |
Complexity: 1 |
Complexity Density: 0,2 |
|
42 |
310
|
KeyItem(String sChar, int iCode, int iType, boolean bAlt)... |
43 |
|
{ |
44 |
310
|
this.sChar = sChar; |
45 |
310
|
this.sCharSmall = sChar.toLowerCase(); |
46 |
310
|
this.iCode = iCode; |
47 |
310
|
this.iType = iType; |
48 |
310
|
this.bAlt = bAlt; |
49 |
|
} |
50 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0,33 |
|
51 |
5
|
KeyItem(String sCycleSequence, final KeyItem[] cycleKeys)... |
52 |
|
{ |
53 |
5
|
this(sCycleSequence, 0, kAlphaCycle, false); |
54 |
5
|
this.cycleKeys = cycleKeys; |
55 |
5
|
this.keyDelete = new KeyItem("del", KeyEvent.KEYCODE_DEL, KeyItem.kDelete, false); |
56 |
|
} |
57 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0,5 |
|
58 |
285
|
public void setSymbolSize(int iWidth, int iHeight)... |
59 |
|
{ |
60 |
285
|
iSymbolWidth = iWidth; |
61 |
285
|
iSymbolHeight = iHeight; |
62 |
|
} |
63 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0,33 |
|
64 |
285
|
public void setRectangle(int iLeft, int iTop, int iWidth, int iHeight)... |
65 |
|
{ |
66 |
285
|
rectFocus.set(iLeft, iTop, iLeft + iWidth, iTop + iHeight); |
67 |
285
|
rectFrame.set(rectFocus); |
68 |
285
|
rectFrame.inset(1, 1); |
69 |
|
} |
70 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
71 |
3037
|
public boolean isDefaultKey()... |
72 |
|
{ |
73 |
3037
|
return ((iType == kDefault) || (iType == kDefaultSpace)); |
74 |
|
} |
75 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
76 |
2976
|
public boolean isSpaceKey()... |
77 |
|
{ |
78 |
2976
|
return (iType == kDefaultSpace); |
79 |
|
} |
80 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
81 |
26
|
public boolean isModeKey()... |
82 |
|
{ |
83 |
26
|
return (iType == kMode); |
84 |
|
} |
85 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
86 |
0
|
public boolean isCycleKey()... |
87 |
|
{ |
88 |
0
|
return (iType == kAlphaCycle); |
89 |
|
} |
90 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0,5 |
|
91 |
60
|
public void sendKeyEvent(View targetView, int iAction, int iKeyCode)... |
92 |
|
{ |
93 |
60
|
KeyEvent event = new KeyEvent(iAction, iKeyCode); |
94 |
60
|
targetView.dispatchKeyEvent(event); |
95 |
|
} |
96 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0,5 |
|
97 |
25
|
public void sendKeyEventClick(View targetView)... |
98 |
|
{ |
99 |
25
|
sendKeyEvent(targetView, KeyEvent.ACTION_DOWN, iCode); |
100 |
25
|
sendKeyEvent(targetView, KeyEvent.ACTION_UP, iCode); |
101 |
|
} |
102 |
|
|
|
|
| 75% |
Uncovered Elements: 2 (8) |
Complexity: 3 |
Complexity Density: 0,75 |
|
103 |
38
|
public void sendKeyEventModifier(View targetView, int iAction, boolean bCapital)... |
104 |
|
{ |
105 |
38
|
if (bCapital) |
106 |
10
|
sendKeyEvent(targetView, iAction, KeyEvent.KEYCODE_SHIFT_LEFT); |
107 |
38
|
if (bAlt) |
108 |
0
|
sendKeyEvent(targetView, iAction, KeyEvent.KEYCODE_ALT_LEFT); |
109 |
|
} |
110 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (11) |
Complexity: 3 |
Complexity Density: 0,43 |
|
111 |
26
|
public void sendKey(View targetView, boolean bCapital)... |
112 |
|
{ |
113 |
26
|
if (iType == kDefault) |
114 |
|
{ |
115 |
19
|
sendKeyEventModifier(targetView, KeyEvent.ACTION_DOWN, bCapital); |
116 |
19
|
sendKeyEventClick(targetView); |
117 |
19
|
sendKeyEventModifier(targetView, KeyEvent.ACTION_UP, bCapital); |
118 |
|
} else { |
119 |
7
|
if (iType == kAlphaCycle) |
120 |
|
{ |
121 |
1
|
sendKeyCycled(targetView); |
122 |
|
} else { |
123 |
6
|
sendKeyEventClick(targetView); |
124 |
|
} |
125 |
|
} |
126 |
|
} |
127 |
|
|
|
|
| 71,4% |
Uncovered Elements: 2 (7) |
Complexity: 2 |
Complexity Density: 0,4 |
|
128 |
1
|
private int getCycleIndex()... |
129 |
|
{ |
130 |
1
|
if (iCycleIndex > (cycleKeys.length - 1)) |
131 |
0
|
iCycleIndex = 0; |
132 |
1
|
int iout = iCycleIndex; |
133 |
1
|
iCycleIndex++; |
134 |
1
|
return iout; |
135 |
|
} |
136 |
|
|
|
|
| 80% |
Uncovered Elements: 2 (10) |
Complexity: 2 |
Complexity Density: 0,25 |
|
137 |
1
|
private void sendKeyCycled(View targetView)... |
138 |
|
{ |
139 |
1
|
final long lDuration = System.currentTimeMillis() - lClickTime; |
140 |
|
|
141 |
1
|
if (lDuration > 500) |
142 |
|
{ |
143 |
1
|
iCycleIndex = 0; |
144 |
|
} else { |
145 |
0
|
keyDelete.sendKey(targetView, false); |
146 |
|
} |
147 |
|
|
148 |
1
|
final int index = getCycleIndex(); |
149 |
|
|
150 |
1
|
lClickTime = System.currentTimeMillis(); |
151 |
1
|
KeyItem key = cycleKeys[index]; |
152 |
1
|
key.sendKey(targetView, false); |
153 |
|
} |
154 |
|
|
155 |
|
} |