1 |
|
package com.choibean.android.hangeulider; |
2 |
|
|
3 |
|
import java.util.HashMap; |
4 |
|
import java.util.regex.Matcher; |
5 |
|
import java.util.regex.Pattern; |
6 |
|
|
7 |
|
import android.text.Editable; |
8 |
|
import android.text.TextWatcher; |
9 |
|
import android.widget.Button; |
10 |
|
import android.widget.EditText; |
11 |
|
import android.widget.LinearLayout; |
12 |
|
import android.widget.TextView; |
13 |
|
|
|
|
| 86,5% |
Uncovered Elements: 51 (379) |
Complexity: 45 |
Complexity Density: 0,15 |
|
14 |
|
public class HangeulParser implements TextWatcher { |
15 |
|
private static Pattern vowelPattern; |
16 |
|
|
17 |
|
protected Hangeulider mHangeulider; |
18 |
|
|
19 |
|
|
20 |
|
public EditText input; |
21 |
|
public EditText output; |
22 |
|
protected Button preview; |
23 |
|
protected Button mode; |
24 |
|
protected Button copy; |
25 |
|
protected Button help; |
26 |
|
protected TextView helper; |
27 |
|
|
28 |
|
private static HashMap<String, Integer> consonants; |
29 |
|
private static HashMap<String, Integer> vowels; |
30 |
|
private static HashMap<String, Integer> bachims; |
31 |
|
private static HashMap<String, Integer> jaeums; |
32 |
|
private static HashMap<String, String> dubs; |
33 |
|
|
|
|
| 93,9% |
Uncovered Elements: 3 (49) |
Complexity: 6 |
Complexity Density: 0,15 |
|
34 |
1
|
public HangeulParser(Hangeulider Hangeulider) {... |
35 |
1
|
this.mHangeulider = Hangeulider; |
36 |
1
|
MyButtonListener buttonListener = new MyButtonListener(Hangeulider, |
37 |
|
output); |
38 |
1
|
output = (EditText) Hangeulider.findViewById(R.id.outputEdit); |
39 |
1
|
helper = (TextView) Hangeulider.findViewById(R.id.helperLabel); |
40 |
1
|
preview = (Button) Hangeulider.findViewById(R.id.previewButton); |
41 |
1
|
preview.setText(""); |
42 |
1
|
preview.setOnClickListener(buttonListener); |
43 |
|
|
44 |
|
|
45 |
1
|
copy = (Button) Hangeulider.findViewById(R.id.copyButton); |
46 |
1
|
copy.setOnClickListener(buttonListener); |
47 |
1
|
help = (Button) Hangeulider.findViewById(R.id.helpButton); |
48 |
1
|
help.setOnClickListener(buttonListener); |
49 |
1
|
input = (EditText) Hangeulider.findViewById(R.id.inputEdit); |
50 |
1
|
input.addTextChangedListener(this); |
51 |
1
|
input.requestFocus(); |
52 |
1
|
Hangeulider.findViewById(R.id.outputClearButton).setOnClickListener( |
53 |
|
buttonListener); |
54 |
1
|
if (Hangeulider.isWide()) { |
55 |
0
|
mode = (Button) Hangeulider.findViewById(R.id.modeButton); |
56 |
0
|
mode.setOnClickListener(buttonListener); |
57 |
|
} else { |
58 |
1
|
LinearLayout layout = (LinearLayout) Hangeulider |
59 |
|
.findViewById(R.id.LinearLayout01); |
60 |
8
|
for (int i = 0; i < layout.getChildCount(); i++) { |
61 |
7
|
Button button = (Button) layout.getChildAt(i); |
62 |
7
|
button.setOnClickListener(buttonListener); |
63 |
|
} |
64 |
1
|
layout = (LinearLayout) Hangeulider |
65 |
|
.findViewById(R.id.LinearLayout02); |
66 |
8
|
for (int i = 0; i < layout.getChildCount(); i++) { |
67 |
7
|
Button button = (Button) layout.getChildAt(i); |
68 |
7
|
button.setOnClickListener(buttonListener); |
69 |
|
} |
70 |
1
|
layout = (LinearLayout) Hangeulider |
71 |
|
.findViewById(R.id.LinearLayout03); |
72 |
8
|
for (int i = 0; i < layout.getChildCount(); i++) { |
73 |
7
|
Button button = (Button) layout.getChildAt(i); |
74 |
7
|
button.setOnClickListener(buttonListener); |
75 |
|
} |
76 |
1
|
layout = (LinearLayout) Hangeulider |
77 |
|
.findViewById(R.id.LinearLayout04); |
78 |
8
|
for (int i = 0; i < layout.getChildCount(); i++) { |
79 |
7
|
Button button = (Button) layout.getChildAt(i); |
80 |
7
|
button.setOnClickListener(buttonListener); |
81 |
|
} |
82 |
1
|
Button buttonBackspace = (Button) Hangeulider |
83 |
|
.findViewById(R.id.keyDelete); |
84 |
1
|
buttonBackspace.setOnClickListener(buttonListener); |
85 |
1
|
Button buttonSpace = (Button) Hangeulider |
86 |
|
.findViewById(R.id.keySpace); |
87 |
1
|
buttonSpace.setOnClickListener(buttonListener); |
88 |
|
} |
89 |
1
|
setupObjects(); |
90 |
|
} |
91 |
|
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
|
92 |
217
|
public void afterTextChanged(Editable e) {... |
93 |
|
} |
94 |
|
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
|
95 |
217
|
public void beforeTextChanged(CharSequence cs, int a, int b, int c) {... |
96 |
|
} |
97 |
|
|
|
|
| 85% |
Uncovered Elements: 3 (20) |
Complexity: 8 |
Complexity Density: 0,67 |
|
98 |
217
|
public void onTextChanged(CharSequence s, int start, int before, int count) {... |
99 |
|
|
100 |
217
|
String text = s.toString(); |
101 |
217
|
boolean finalize = false; |
102 |
217
|
if (text.indexOf(' ') != -1 || text.indexOf('\t') != -1 |
103 |
|
|| text.indexOf('\n') != -1) |
104 |
17
|
finalize = true; |
105 |
217
|
if (text.length() > 0 && text.trim().equals("")) { |
106 |
17
|
Hangeulider.logD("text", "should enter space here"); |
107 |
17
|
if (input != null) |
108 |
17
|
input.setText(""); |
109 |
17
|
output.setText(output.getText().append(' ')); |
110 |
|
} else { |
111 |
200
|
if (mHangeulider.getDubeolshikMode()) { |
112 |
0
|
parseDuBeolShik(text, finalize); |
113 |
|
} else { |
114 |
200
|
parseKonglish(text, finalize); |
115 |
|
} |
116 |
|
} |
117 |
|
|
118 |
|
|
119 |
|
|
120 |
|
} |
121 |
|
|
|
|
| 83,3% |
Uncovered Elements: 2 (12) |
Complexity: 3 |
Complexity Density: 0,38 |
|
122 |
31
|
public void grabText() {... |
123 |
31
|
CharSequence cs = preview.getText(); |
124 |
31
|
output.setText(output.getText().append(cs)); |
125 |
31
|
int len = output.length(); |
126 |
31
|
if (len != 0) |
127 |
31
|
output.setSelection(len - 1, len); |
128 |
31
|
if (input != null) |
129 |
31
|
input.setText(""); |
130 |
31
|
preview.setText(""); |
131 |
|
|
132 |
|
} |
133 |
|
|
|
|
| 0% |
Uncovered Elements: 18 (18) |
Complexity: 4 |
Complexity Density: 0,33 |
|
134 |
0
|
public void parseDuBeolShik(String text, boolean finalize) {... |
135 |
0
|
StringBuffer sb = new StringBuffer(); |
136 |
0
|
int length = text.length(); |
137 |
0
|
for (int i = 0; i < length; i++) { |
138 |
0
|
String c = text.substring(i, i + 1); |
139 |
0
|
String s = dubs.get(c); |
140 |
0
|
if (s == null) { |
141 |
0
|
s = dubs.get(c.toLowerCase()); |
142 |
|
} |
143 |
0
|
if (s != null) { |
144 |
0
|
sb.append(s); |
145 |
|
} |
146 |
|
} |
147 |
0
|
parseKonglish(sb.toString(), finalize); |
148 |
0
|
sb.insert(0, ">").insert(0, text).insert(0, "[dbs]"); |
149 |
0
|
Hangeulider.logD("char", sb.toString()); |
150 |
|
} |
151 |
|
|
|
|
| 88,1% |
Uncovered Elements: 7 (59) |
Complexity: 13 |
Complexity Density: 0,33 |
|
152 |
200
|
public void parseKonglish(String text, boolean finalize) {... |
153 |
200
|
String v = "", parts[]; |
154 |
200
|
text = text.trim().toLowerCase(); |
155 |
200
|
parts = vowelPattern.split(text); |
156 |
200
|
Matcher m = vowelPattern.matcher(text); |
157 |
200
|
if (m.find()) { |
158 |
92
|
v = m.group(); |
159 |
|
} |
160 |
|
|
161 |
200
|
if (parts.length < 1 || parts[0] == "") { |
162 |
80
|
Hangeulider.logD("status", text + " = too short"); |
163 |
80
|
preview.setText(""); |
164 |
80
|
setModeText(); |
165 |
80
|
return; |
166 |
|
} |
167 |
|
|
168 |
120
|
if (helper != null) { |
169 |
0
|
helper.setText(R.string.press_space); |
170 |
0
|
helper.setTextColor(0xd0ffff00); |
171 |
|
} |
172 |
120
|
Integer consonant, vowel, bachim = null; |
173 |
120
|
vowel = vowels.get(v); |
174 |
120
|
int unicode = 44032; |
175 |
120
|
if (vowel == null) { |
176 |
94
|
unicode = 12593; |
177 |
94
|
consonant = jaeums.get(parts[0]); |
178 |
94
|
if (consonant == null && parts[0].length() > 1) { |
179 |
58
|
consonant = jaeums.get(parts[0].charAt(parts[0].length() - 1)); |
180 |
|
} |
181 |
94
|
if (consonant != null) { |
182 |
18
|
unicode += consonant; |
183 |
|
} |
184 |
|
} else { |
185 |
26
|
unicode += vowel * 28; |
186 |
26
|
consonant = consonants.get(parts[0]); |
187 |
26
|
if (consonant != null) |
188 |
18
|
unicode += consonant * 588; |
189 |
26
|
if (parts.length > 1) { |
190 |
16
|
bachim = bachims.get(parts[1]); |
191 |
16
|
if (bachim != null) { |
192 |
4
|
unicode += bachim; |
193 |
|
} |
194 |
|
} |
195 |
|
} |
196 |
|
|
197 |
|
|
198 |
|
|
199 |
|
|
200 |
|
|
201 |
|
|
202 |
120
|
char c = (char) (unicode); |
203 |
120
|
Hangeulider.logD("status", String.valueOf(c)); |
204 |
|
|
205 |
120
|
if (finalize) { |
206 |
0
|
input.setText(""); |
207 |
0
|
output.setText(output.getText().append(c)); |
208 |
0
|
preview.setText(""); |
209 |
|
} else { |
210 |
120
|
preview.setText("" + c); |
211 |
|
} |
212 |
|
} |
213 |
|
|
|
|
| 34,8% |
Uncovered Elements: 15 (23) |
Complexity: 7 |
Complexity Density: 0,64 |
|
214 |
81
|
public void setModeText() {... |
215 |
81
|
if (mHangeulider.getDubeolshikMode()) { |
216 |
0
|
if (helper != null) |
217 |
0
|
helper.setText(R.string.type_here2); |
218 |
0
|
if (mode != null) |
219 |
0
|
mode.setText(R.string.dbs_on); |
220 |
|
} else { |
221 |
81
|
if (helper != null) |
222 |
0
|
helper.setText(R.string.type_here1); |
223 |
81
|
if (mode != null) |
224 |
0
|
mode.setText(R.string.dbs_off); |
225 |
|
} |
226 |
81
|
if (helper != null) |
227 |
0
|
helper.setTextColor(0xa0ffffff); |
228 |
|
} |
229 |
|
|
|
|
| 98,9% |
Uncovered Elements: 2 (189) |
Complexity: 2 |
Complexity Density: 0,01 |
|
230 |
1
|
private static void setupObjects() {... |
231 |
1
|
if (consonants != null) |
232 |
0
|
return; |
233 |
1
|
vowelPattern = Pattern.compile("([aeiouwy]+)"); |
234 |
1
|
consonants = new HashMap<String, Integer>(); |
235 |
1
|
vowels = new HashMap<String, Integer>(); |
236 |
1
|
bachims = new HashMap<String, Integer>(); |
237 |
1
|
jaeums = new HashMap<String, Integer>(); |
238 |
1
|
dubs = new HashMap<String, String>(); |
239 |
|
|
240 |
1
|
consonants.put("g", new Integer(0)); |
241 |
1
|
consonants.put("gh", new Integer(0)); |
242 |
1
|
consonants.put("gg", new Integer(1)); |
243 |
1
|
consonants.put("q", new Integer(1)); |
244 |
1
|
consonants.put("n", new Integer(2)); |
245 |
1
|
consonants.put("d", new Integer(3)); |
246 |
1
|
consonants.put("dd", new Integer(4)); |
247 |
1
|
consonants.put("th", new Integer(4)); |
248 |
1
|
consonants.put("r", new Integer(5)); |
249 |
1
|
consonants.put("l", new Integer(5)); |
250 |
1
|
consonants.put("m", new Integer(6)); |
251 |
1
|
consonants.put("b", new Integer(7)); |
252 |
1
|
consonants.put("v", new Integer(8)); |
253 |
1
|
consonants.put("bb", new Integer(8)); |
254 |
1
|
consonants.put("s", new Integer(9)); |
255 |
1
|
consonants.put("sh", new Integer(9)); |
256 |
1
|
consonants.put("ss", new Integer(10)); |
257 |
1
|
consonants.put("x", new Integer(10)); |
258 |
1
|
consonants.put("", new Integer(11)); |
259 |
1
|
consonants.put("ng", new Integer(11)); |
260 |
1
|
consonants.put("rh", new Integer(11)); |
261 |
1
|
consonants.put("j", new Integer(12)); |
262 |
1
|
consonants.put("jj", new Integer(13)); |
263 |
1
|
consonants.put("z", new Integer(13)); |
264 |
1
|
consonants.put("c", new Integer(13)); |
265 |
1
|
consonants.put("ch", new Integer(14)); |
266 |
1
|
consonants.put("k", new Integer(15)); |
267 |
1
|
consonants.put("kh", new Integer(15)); |
268 |
1
|
consonants.put("t", new Integer(16)); |
269 |
1
|
consonants.put("p", new Integer(17)); |
270 |
1
|
consonants.put("h", new Integer(18)); |
271 |
1
|
consonants.put("f", new Integer(18)); |
272 |
1
|
consonants.put("ph", new Integer(18)); |
273 |
|
|
274 |
1
|
vowels.put("a", new Integer(0)); |
275 |
1
|
vowels.put("ae", new Integer(1)); |
276 |
1
|
vowels.put("ya", new Integer(2)); |
277 |
1
|
vowels.put("yae", new Integer(3)); |
278 |
1
|
vowels.put("eo", new Integer(4)); |
279 |
1
|
vowels.put("e", new Integer(5)); |
280 |
1
|
vowels.put("yeo", new Integer(6)); |
281 |
1
|
vowels.put("ye", new Integer(7)); |
282 |
1
|
vowels.put("o", new Integer(8)); |
283 |
1
|
vowels.put("wa", new Integer(9)); |
284 |
1
|
vowels.put("oa", new Integer(9)); |
285 |
1
|
vowels.put("ua", new Integer(9)); |
286 |
1
|
vowels.put("wae", new Integer(10)); |
287 |
1
|
vowels.put("oae", new Integer(10)); |
288 |
1
|
vowels.put("uae", new Integer(10)); |
289 |
1
|
vowels.put("oi", new Integer(11)); |
290 |
1
|
vowels.put("yo", new Integer(12)); |
291 |
1
|
vowels.put("u", new Integer(13)); |
292 |
1
|
vowels.put("oo", new Integer(13)); |
293 |
1
|
vowels.put("weo", new Integer(14)); |
294 |
1
|
vowels.put("ueo", new Integer(14)); |
295 |
1
|
vowels.put("wo", new Integer(14)); |
296 |
1
|
vowels.put("we", new Integer(15)); |
297 |
1
|
vowels.put("ue", new Integer(15)); |
298 |
1
|
vowels.put("wee", new Integer(16)); |
299 |
1
|
vowels.put("wi", new Integer(16)); |
300 |
1
|
vowels.put("ui", new Integer(16)); |
301 |
1
|
vowels.put("yu", new Integer(17)); |
302 |
1
|
vowels.put("yoo", new Integer(17)); |
303 |
1
|
vowels.put("eu", new Integer(18)); |
304 |
1
|
vowels.put("eui", new Integer(19)); |
305 |
1
|
vowels.put("i", new Integer(20)); |
306 |
1
|
vowels.put("ee", new Integer(20)); |
307 |
1
|
vowels.put("yi", new Integer(20)); |
308 |
1
|
vowels.put("yee", new Integer(20)); |
309 |
1
|
vowels.put("y", new Integer(20)); |
310 |
|
|
311 |
1
|
bachims.put("g", new Integer(1)); |
312 |
1
|
bachims.put("gg", new Integer(2)); |
313 |
1
|
bachims.put("gs", new Integer(3)); |
314 |
1
|
bachims.put("n", new Integer(4)); |
315 |
1
|
bachims.put("nj", new Integer(5)); |
316 |
1
|
bachims.put("nh", new Integer(6)); |
317 |
1
|
bachims.put("d", new Integer(7)); |
318 |
1
|
bachims.put("l", new Integer(8)); |
319 |
1
|
bachims.put("r", new Integer(8)); |
320 |
1
|
bachims.put("lg", new Integer(9)); |
321 |
1
|
bachims.put("rg", new Integer(9)); |
322 |
1
|
bachims.put("lm", new Integer(10)); |
323 |
1
|
bachims.put("rm", new Integer(10)); |
324 |
1
|
bachims.put("lb", new Integer(11)); |
325 |
1
|
bachims.put("rb", new Integer(11)); |
326 |
1
|
bachims.put("ls", new Integer(12)); |
327 |
1
|
bachims.put("rs", new Integer(12)); |
328 |
1
|
bachims.put("lt", new Integer(13)); |
329 |
1
|
bachims.put("rt", new Integer(13)); |
330 |
1
|
bachims.put("lp", new Integer(14)); |
331 |
1
|
bachims.put("rp", new Integer(14)); |
332 |
1
|
bachims.put("lh", new Integer(15)); |
333 |
1
|
bachims.put("rh", new Integer(15)); |
334 |
1
|
bachims.put("m", new Integer(16)); |
335 |
1
|
bachims.put("b", new Integer(17)); |
336 |
1
|
bachims.put("bs", new Integer(18)); |
337 |
1
|
bachims.put("s", new Integer(19)); |
338 |
1
|
bachims.put("ss", new Integer(20)); |
339 |
1
|
bachims.put("x", new Integer(20)); |
340 |
1
|
bachims.put("ng", new Integer(21)); |
341 |
1
|
bachims.put("j", new Integer(22)); |
342 |
1
|
bachims.put("ch", new Integer(23)); |
343 |
1
|
bachims.put("c", new Integer(23)); |
344 |
1
|
bachims.put("k", new Integer(24)); |
345 |
1
|
bachims.put("ck", new Integer(24)); |
346 |
1
|
bachims.put("t", new Integer(25)); |
347 |
1
|
bachims.put("p", new Integer(26)); |
348 |
1
|
bachims.put("h", new Integer(27)); |
349 |
1
|
bachims.put("f", new Integer(27)); |
350 |
1
|
bachims.put("ph", new Integer(27)); |
351 |
|
|
352 |
1
|
jaeums.put("g", new Integer(0)); |
353 |
1
|
jaeums.put("gg", new Integer(1)); |
354 |
1
|
jaeums.put("q", new Integer(1)); |
355 |
1
|
jaeums.put("gs", new Integer(2)); |
356 |
1
|
jaeums.put("n", new Integer(3)); |
357 |
1
|
jaeums.put("nj", new Integer(4)); |
358 |
1
|
jaeums.put("nh", new Integer(5)); |
359 |
1
|
jaeums.put("d", new Integer(6)); |
360 |
1
|
jaeums.put("dd", new Integer(7)); |
361 |
1
|
jaeums.put("r", new Integer(8)); |
362 |
1
|
jaeums.put("l", new Integer(8)); |
363 |
1
|
jaeums.put("rg", new Integer(9)); |
364 |
1
|
jaeums.put("rm", new Integer(10)); |
365 |
1
|
jaeums.put("rb", new Integer(11)); |
366 |
1
|
jaeums.put("rs", new Integer(12)); |
367 |
1
|
jaeums.put("rt", new Integer(13)); |
368 |
1
|
jaeums.put("rp", new Integer(14)); |
369 |
1
|
jaeums.put("rh", new Integer(15)); |
370 |
1
|
jaeums.put("m", new Integer(16)); |
371 |
1
|
jaeums.put("b", new Integer(17)); |
372 |
1
|
jaeums.put("v", new Integer(18)); |
373 |
1
|
jaeums.put("bb", new Integer(18)); |
374 |
1
|
jaeums.put("bs", new Integer(19)); |
375 |
1
|
jaeums.put("s", new Integer(20)); |
376 |
1
|
jaeums.put("ss", new Integer(21)); |
377 |
1
|
jaeums.put("x", new Integer(21)); |
378 |
1
|
jaeums.put("ng", new Integer(22)); |
379 |
1
|
jaeums.put("j", new Integer(23)); |
380 |
1
|
jaeums.put("jj", new Integer(24)); |
381 |
1
|
jaeums.put("c", new Integer(25)); |
382 |
1
|
jaeums.put("ch", new Integer(25)); |
383 |
1
|
jaeums.put("k", new Integer(26)); |
384 |
1
|
jaeums.put("t", new Integer(27)); |
385 |
1
|
jaeums.put("p", new Integer(28)); |
386 |
1
|
jaeums.put("h", new Integer(29)); |
387 |
1
|
jaeums.put("f", new Integer(29)); |
388 |
1
|
jaeums.put("ph", new Integer(29)); |
389 |
|
|
390 |
1
|
dubs.put("q", "b"); |
391 |
1
|
dubs.put("Q", "bb"); |
392 |
1
|
dubs.put("w", "j"); |
393 |
1
|
dubs.put("W", "jj"); |
394 |
1
|
dubs.put("e", "d"); |
395 |
1
|
dubs.put("E", "dd"); |
396 |
1
|
dubs.put("r", "g"); |
397 |
1
|
dubs.put("R", "gg"); |
398 |
1
|
dubs.put("t", "s"); |
399 |
1
|
dubs.put("T", "ss"); |
400 |
|
|
401 |
1
|
dubs.put("y", "yo"); |
402 |
1
|
dubs.put("u", "yeo"); |
403 |
1
|
dubs.put("i", "ya"); |
404 |
1
|
dubs.put("o", "ae"); |
405 |
1
|
dubs.put("O", "yae"); |
406 |
1
|
dubs.put("p", "e"); |
407 |
1
|
dubs.put("P", "ye"); |
408 |
|
|
409 |
1
|
dubs.put("a", "m"); |
410 |
1
|
dubs.put("s", "n"); |
411 |
1
|
dubs.put("d", "ng"); |
412 |
1
|
dubs.put("f", "r"); |
413 |
1
|
dubs.put("g", "h"); |
414 |
|
|
415 |
1
|
dubs.put("h", "o"); |
416 |
1
|
dubs.put("j", "eo"); |
417 |
1
|
dubs.put("k", "a"); |
418 |
1
|
dubs.put("l", "i"); |
419 |
|
|
420 |
1
|
dubs.put("z", "k"); |
421 |
1
|
dubs.put("x", "t"); |
422 |
1
|
dubs.put("c", "ch"); |
423 |
1
|
dubs.put("v", "p"); |
424 |
|
|
425 |
1
|
dubs.put("b", "yu"); |
426 |
1
|
dubs.put("n", "u"); |
427 |
1
|
dubs.put("m", "eu"); |
428 |
|
} |
429 |
|
} |