diff --git a/TaigiDict/.idea/misc.xml b/TaigiDict/.idea/misc.xml index cca2cda..7158618 100644 --- a/TaigiDict/.idea/misc.xml +++ b/TaigiDict/.idea/misc.xml @@ -37,7 +37,7 @@ - + diff --git a/TaigiDict/app/build.gradle b/TaigiDict/app/build.gradle index d33990c..f79852e 100644 --- a/TaigiDict/app/build.gradle +++ b/TaigiDict/app/build.gradle @@ -24,8 +24,8 @@ android { applicationId "com.taccotap.taigidict" minSdkVersion 16 targetSdkVersion 25 - versionCode 5 - versionName "1.0.4" + versionCode 6 + versionName "1.0.5" testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" } @@ -74,11 +74,11 @@ dependencies { compile project(':taigi_dict_realm_model') // Support library - compile 'com.android.support:support-v4:25.2.0' - compile 'com.android.support:appcompat-v7:25.2.0' - compile 'com.android.support:design:25.2.0' - compile 'com.android.support:recyclerview-v7:25.2.0' - compile 'com.android.support:percent:25.2.0' + compile 'com.android.support:support-v4:25.3.0' + compile 'com.android.support:appcompat-v7:25.3.0' + compile 'com.android.support:design:25.3.0' + compile 'com.android.support:recyclerview-v7:25.3.0' + compile 'com.android.support:percent:25.3.0' // Realm compile 'com.github.eggheadgames:android-realm-asset-helper:2.0.0' diff --git a/TaigiDict/app/src/main/assets/fonts/HanaMinB.ttf b/TaigiDict/app/src/main/assets/fonts/mingliub.ttc old mode 100755 new mode 100644 similarity index 65% rename from TaigiDict/app/src/main/assets/fonts/HanaMinB.ttf rename to TaigiDict/app/src/main/assets/fonts/mingliub.ttc index 94830d1..0d960fb Binary files a/TaigiDict/app/src/main/assets/fonts/HanaMinB.ttf and b/TaigiDict/app/src/main/assets/fonts/mingliub.ttc differ diff --git a/TaigiDict/app/src/main/java/com/taccotap/taigidict/TaigiDictApp.java b/TaigiDict/app/src/main/java/com/taccotap/taigidict/TaigiDictApp.java index baabc65..1bebade 100644 --- a/TaigiDict/app/src/main/java/com/taccotap/taigidict/TaigiDictApp.java +++ b/TaigiDict/app/src/main/java/com/taccotap/taigidict/TaigiDictApp.java @@ -43,7 +43,7 @@ private void initFabric() { private void initCalligraphy() { CalligraphyConfig.initDefault(new CalligraphyConfig.Builder() - .setDefaultFontPath("fonts/Roboto-RobotoRegular.ttf") + .setDefaultFontPath("fonts/twu3.ttf") .setFontAttrId(R.attr.fontPath) .build()); } diff --git a/TaigiDict/app/src/main/java/com/taccotap/taigidict/utils/LomajiUnicodeUtils.java b/TaigiDict/app/src/main/java/com/taccotap/taigidict/converter/LomajiUnicodeConverter.java similarity index 95% rename from TaigiDict/app/src/main/java/com/taccotap/taigidict/utils/LomajiUnicodeUtils.java rename to TaigiDict/app/src/main/java/com/taccotap/taigidict/converter/LomajiUnicodeConverter.java index 8ddce86..557f88f 100644 --- a/TaigiDict/app/src/main/java/com/taccotap/taigidict/utils/LomajiUnicodeUtils.java +++ b/TaigiDict/app/src/main/java/com/taccotap/taigidict/converter/LomajiUnicodeConverter.java @@ -1,9 +1,9 @@ -package com.taccotap.taigidict.utils; +package com.taccotap.taigidict.converter; -public class LomajiUnicodeUtils { +public class LomajiUnicodeConverter { // fix two-char word to one-char word - public static String fixTwoCharWord(String unicodeLomaji) { + public static String convertTwoCharWordToOneCharWord(String unicodeLomaji) { String fixed = unicodeLomaji // x8 not change diff --git a/TaigiDict/app/src/main/java/com/taccotap/taigidict/converter/Poj.java b/TaigiDict/app/src/main/java/com/taccotap/taigidict/converter/Poj.java new file mode 100644 index 0000000..8f9b7f4 --- /dev/null +++ b/TaigiDict/app/src/main/java/com/taccotap/taigidict/converter/Poj.java @@ -0,0 +1,120 @@ +package com.taccotap.taigidict.converter; + +import java.util.HashMap; +import java.util.Set; + +public class Poj { + + // + public static HashMap sPojUnicodeToPojNumberHashMap; + + // + public static HashMap sPojNumberToPojUnicodeHashMap; + + static { + sPojUnicodeToPojNumberHashMap = new HashMap<>(); + sPojNumberToPojUnicodeHashMap = new HashMap<>(); + + // A + sPojUnicodeToPojNumberHashMap.put("Á", "A2"); + sPojUnicodeToPojNumberHashMap.put("À", "A3"); + sPojUnicodeToPojNumberHashMap.put("Â", "A5"); + sPojUnicodeToPojNumberHashMap.put("Ā", "A7"); + sPojUnicodeToPojNumberHashMap.put("A̍", "A8"); + sPojUnicodeToPojNumberHashMap.put("Ă", "A9"); + + // a + sPojUnicodeToPojNumberHashMap.put("á", "a2"); + sPojUnicodeToPojNumberHashMap.put("à", "a3"); + sPojUnicodeToPojNumberHashMap.put("â", "a5"); + sPojUnicodeToPojNumberHashMap.put("ā", "a7"); + sPojUnicodeToPojNumberHashMap.put("a̍", "a8"); + sPojUnicodeToPojNumberHashMap.put("ă", "a9"); + + // I + sPojUnicodeToPojNumberHashMap.put("Í", "I2"); + sPojUnicodeToPojNumberHashMap.put("Ì", "I3"); + sPojUnicodeToPojNumberHashMap.put("Î", "I5"); + sPojUnicodeToPojNumberHashMap.put("Ī", "I7"); + sPojUnicodeToPojNumberHashMap.put("I̍", "I8"); + sPojUnicodeToPojNumberHashMap.put("Ĭ", "I9"); + + // i + sPojUnicodeToPojNumberHashMap.put("í", "i2"); + sPojUnicodeToPojNumberHashMap.put("ì", "i3"); + sPojUnicodeToPojNumberHashMap.put("î", "i5"); + sPojUnicodeToPojNumberHashMap.put("ī", "i7"); + sPojUnicodeToPojNumberHashMap.put("i̍", "i8"); + sPojUnicodeToPojNumberHashMap.put("ĭ", "i9"); + + // U + sPojUnicodeToPojNumberHashMap.put("Ú", "U2"); + sPojUnicodeToPojNumberHashMap.put("Ù", "U3"); + sPojUnicodeToPojNumberHashMap.put("Û", "U5"); + sPojUnicodeToPojNumberHashMap.put("Ū", "U7"); + sPojUnicodeToPojNumberHashMap.put("U̍", "U8"); + sPojUnicodeToPojNumberHashMap.put("Ŭ", "U9"); + + // u + sPojUnicodeToPojNumberHashMap.put("ú", "u2"); + sPojUnicodeToPojNumberHashMap.put("ù", "u3"); + sPojUnicodeToPojNumberHashMap.put("û", "u5"); + sPojUnicodeToPojNumberHashMap.put("ū", "u7"); + sPojUnicodeToPojNumberHashMap.put("u̍", "u8"); + sPojUnicodeToPojNumberHashMap.put("ŭ", "u9"); + + // E + sPojUnicodeToPojNumberHashMap.put("É", "E2"); + sPojUnicodeToPojNumberHashMap.put("È", "E3"); + sPojUnicodeToPojNumberHashMap.put("Ê", "E5"); + sPojUnicodeToPojNumberHashMap.put("Ē", "E7"); + sPojUnicodeToPojNumberHashMap.put("E̍", "E8"); + sPojUnicodeToPojNumberHashMap.put("Ĕ", "E9"); + + // e + sPojUnicodeToPojNumberHashMap.put("é", "e2"); + sPojUnicodeToPojNumberHashMap.put("è", "e3"); + sPojUnicodeToPojNumberHashMap.put("ê", "e5"); + sPojUnicodeToPojNumberHashMap.put("ē", "e7"); + sPojUnicodeToPojNumberHashMap.put("e̍", "e8"); + sPojUnicodeToPojNumberHashMap.put("ĕ", "e9"); + + // O + sPojUnicodeToPojNumberHashMap.put("Ó", "O2"); + sPojUnicodeToPojNumberHashMap.put("Ò", "O3"); + sPojUnicodeToPojNumberHashMap.put("Ô", "O5"); + sPojUnicodeToPojNumberHashMap.put("Ō", "O7"); + sPojUnicodeToPojNumberHashMap.put("O̍", "O8"); + sPojUnicodeToPojNumberHashMap.put("Ŏ", "O9"); + + // o + sPojUnicodeToPojNumberHashMap.put("ó", "o2"); + sPojUnicodeToPojNumberHashMap.put("ò", "o3"); + sPojUnicodeToPojNumberHashMap.put("ô", "o5"); + sPojUnicodeToPojNumberHashMap.put("ō", "o7"); + sPojUnicodeToPojNumberHashMap.put("o̍", "o8"); + sPojUnicodeToPojNumberHashMap.put("ŏ", "o9"); + + // O͘ + sPojUnicodeToPojNumberHashMap.put("Ó\u0358", "O\u03582"); + sPojUnicodeToPojNumberHashMap.put("Ò\u0358", "O\u03583"); + sPojUnicodeToPojNumberHashMap.put("Ô\u0358", "O\u03585"); + sPojUnicodeToPojNumberHashMap.put("Ō\u0358", "O\u03587"); + sPojUnicodeToPojNumberHashMap.put("O̍\u0358", "O\u03588"); + sPojUnicodeToPojNumberHashMap.put("Ŏ\u0358", "O\u03589"); + + // o͘ + sPojUnicodeToPojNumberHashMap.put("ó\u0358", "o\u03582"); + sPojUnicodeToPojNumberHashMap.put("ò\u0358", "o\u03583"); + sPojUnicodeToPojNumberHashMap.put("ô\u0358", "o\u03585"); + sPojUnicodeToPojNumberHashMap.put("ō\u0358", "o\u03587"); + sPojUnicodeToPojNumberHashMap.put("o̍\u0358", "o\u03588"); + sPojUnicodeToPojNumberHashMap.put("ŏ\u0358", "o\u03589"); + + final Set keys = sPojUnicodeToPojNumberHashMap.keySet(); + for (String key : keys) { + String value = sPojUnicodeToPojNumberHashMap.get(key); + sPojNumberToPojUnicodeHashMap.put(value, key); + } + } +} diff --git a/TaigiDict/app/src/main/java/com/taccotap/taigidict/converter/PojInputConverter.java b/TaigiDict/app/src/main/java/com/taccotap/taigidict/converter/PojInputConverter.java new file mode 100644 index 0000000..288e7e8 --- /dev/null +++ b/TaigiDict/app/src/main/java/com/taccotap/taigidict/converter/PojInputConverter.java @@ -0,0 +1,84 @@ +package com.taccotap.taigidict.converter; + +import android.text.TextUtils; +import android.util.Log; + +import com.taccotap.taigidict.BuildConfig; + +public class PojInputConverter { + private static final String TAG = PojInputConverter.class.getSimpleName(); + + public static String convertPojMixedInputToPojNumberWords(String input) { + if (BuildConfig.DEBUG_LOG) { + Log.d(TAG, "convertPojMixedInputToPojNumberWords(): input=" + input); + } + + if (input == null) { + return input; + } + + StringBuilder stringBuilder = new StringBuilder(); + final String[] words = input.split("[ -]"); + for (String foundTaigiWord : words) { + String pojNumber = convertPojWordToPojNumberWord(foundTaigiWord); + if (BuildConfig.DEBUG_LOG) { + Log.d(TAG, "foundTaigiWord=" + foundTaigiWord + ", pojNumber=" + pojNumber); + } + + stringBuilder.append(pojNumber); + stringBuilder.append(" "); + } + + return stringBuilder.toString(); + } + + private static final String convertPojWordToPojNumberWord(String poj) { + if (TextUtils.isEmpty(poj)) { + return poj; + } + + StringBuilder stringBuilder = new StringBuilder(); + + boolean hasFoundUnicodeToneChar = false; + int length = poj.length(); + for (int i = 0; i < length; i++) { + final String currentCharString = poj.substring(i, i + 1); + + final String currentPojNumber = Poj.sPojUnicodeToPojNumberHashMap.get(currentCharString); + if (currentPojNumber != null) { + stringBuilder.append(currentPojNumber); + hasFoundUnicodeToneChar = true; + } else { + if (hasFoundUnicodeToneChar && TextUtils.isDigitsOnly(currentCharString)) { + // remove useless ending numbers, skip + } else { + stringBuilder.append(currentCharString); + } + } + } + + final String pojNumberInTheMiddle = stringBuilder.toString(); + + stringBuilder = new StringBuilder(); + length = pojNumberInTheMiddle.length(); + String number = null; + for (int i = 0; i < length; i++) { + final String currentCharString = pojNumberInTheMiddle.substring(i, i + 1); + + // only find the closest number, ignore other ending numbers + if (TextUtils.isDigitsOnly(currentCharString)) { + if (number == null) { + number = currentCharString; + } + } else { + stringBuilder.append(currentCharString); + } + } + + if (number != null) { + stringBuilder.append(number); + } + + return stringBuilder.toString(); + } +} diff --git a/TaigiDict/app/src/main/java/com/taccotap/taigidict/converter/PojToTailoConverter.java b/TaigiDict/app/src/main/java/com/taccotap/taigidict/converter/PojToTailoConverter.java new file mode 100644 index 0000000..c651923 --- /dev/null +++ b/TaigiDict/app/src/main/java/com/taccotap/taigidict/converter/PojToTailoConverter.java @@ -0,0 +1,39 @@ +package com.taccotap.taigidict.converter; + +import android.util.Log; + +import com.taccotap.taigidict.BuildConfig; + +public class PojToTailoConverter { + private static final String TAG = PojToTailoConverter.class.getSimpleName(); + + public static final String convertPojMixedInputToTailoWords(String poj) { + final String pojNumber = PojInputConverter.convertPojMixedInputToPojNumberWords(poj); + final String tailoNumber = pojNumberToTailoNumber(pojNumber); + final String tailo = TailoInputConverter.convertTailoNumberRawInputToTailoWords(tailoNumber); + + if (BuildConfig.DEBUG_LOG) { + Log.d(TAG, "poj=" + poj + ", pojNumber=" + pojNumber + ", tailoNumber=" + tailoNumber + ", tailo=" + tailo); + } + + return tailo; + } + + public static final String pojNumberToTailoNumber(String pojNumber) { + String tailoNumber = pojNumber + .replaceAll("ch", "ts") // ch -> ts + .replaceAll("Ch", "Ts") // Ch -> Ts + .replaceAll("\u207f", "nn") // ⁿ -> nn + .replaceAll("o\u0358", "oo") // o͘ -> oo + .replaceAll("O\u0358", "Oo") // O͘ -> Oo + .replaceAll("o([aAeE])", "u$1") // oa -> ua, oe -> ue. + .replaceAll("O([aAeE])", "U$1") // Oa -> Ua, Oe -> Ue. + .replaceAll("ek", "ik") // ek -> ik + .replaceAll("Ek", "Ik") // Ek -> Ik + .replaceAll("eng", "ing") // eng -> ing + .replaceAll("Eng", "Ing"); // Eng -> Ing + + return tailoNumber; + } + +} diff --git a/TaigiDict/app/src/main/java/com/taccotap/taigidict/converter/Tailo.java b/TaigiDict/app/src/main/java/com/taccotap/taigidict/converter/Tailo.java new file mode 100644 index 0000000..46d23b5 --- /dev/null +++ b/TaigiDict/app/src/main/java/com/taccotap/taigidict/converter/Tailo.java @@ -0,0 +1,128 @@ +package com.taccotap.taigidict.converter; + +import java.util.HashMap; +import java.util.Set; + +public class Tailo { + + // + public static HashMap sTailoUnicodeToTailoNumberHashMap; + + // + public static HashMap sTailoNumberToTailoUnicodeHashMap; + + static { + sTailoUnicodeToTailoNumberHashMap = new HashMap<>(); + sTailoNumberToTailoUnicodeHashMap = new HashMap<>(); + + // A + sTailoUnicodeToTailoNumberHashMap.put("Á", "A2"); + sTailoUnicodeToTailoNumberHashMap.put("À", "A3"); + sTailoUnicodeToTailoNumberHashMap.put("Â", "A5"); + sTailoUnicodeToTailoNumberHashMap.put("Ā", "A7"); + sTailoUnicodeToTailoNumberHashMap.put("A̍", "A8"); + sTailoUnicodeToTailoNumberHashMap.put("A̋", "A9"); + + // a + sTailoUnicodeToTailoNumberHashMap.put("á", "a2"); + sTailoUnicodeToTailoNumberHashMap.put("à", "a3"); + sTailoUnicodeToTailoNumberHashMap.put("â", "a5"); + sTailoUnicodeToTailoNumberHashMap.put("ā", "a7"); + sTailoUnicodeToTailoNumberHashMap.put("a̍", "a8"); + sTailoUnicodeToTailoNumberHashMap.put("a̋", "a9"); + + // I + sTailoUnicodeToTailoNumberHashMap.put("Í", "I2"); + sTailoUnicodeToTailoNumberHashMap.put("Ì", "I3"); + sTailoUnicodeToTailoNumberHashMap.put("Î", "I5"); + sTailoUnicodeToTailoNumberHashMap.put("Ī", "I7"); + sTailoUnicodeToTailoNumberHashMap.put("I̍", "I8"); + sTailoUnicodeToTailoNumberHashMap.put("I̋", "I9"); + + // i + sTailoUnicodeToTailoNumberHashMap.put("í", "i2"); + sTailoUnicodeToTailoNumberHashMap.put("ì", "i3"); + sTailoUnicodeToTailoNumberHashMap.put("î", "i5"); + sTailoUnicodeToTailoNumberHashMap.put("ī", "i7"); + sTailoUnicodeToTailoNumberHashMap.put("i̍", "i8"); + sTailoUnicodeToTailoNumberHashMap.put("i̋", "i9"); + + // U + sTailoUnicodeToTailoNumberHashMap.put("Ú", "U2"); + sTailoUnicodeToTailoNumberHashMap.put("Ù", "U3"); + sTailoUnicodeToTailoNumberHashMap.put("Û", "U5"); + sTailoUnicodeToTailoNumberHashMap.put("Ū", "U7"); + sTailoUnicodeToTailoNumberHashMap.put("U̍", "U8"); + sTailoUnicodeToTailoNumberHashMap.put("Ű", "U9"); + + // u + sTailoUnicodeToTailoNumberHashMap.put("ú", "u2"); + sTailoUnicodeToTailoNumberHashMap.put("ù", "u3"); + sTailoUnicodeToTailoNumberHashMap.put("û", "u5"); + sTailoUnicodeToTailoNumberHashMap.put("ū", "u7"); + sTailoUnicodeToTailoNumberHashMap.put("u̍", "u8"); + sTailoUnicodeToTailoNumberHashMap.put("ű", "u9"); + + // E + sTailoUnicodeToTailoNumberHashMap.put("É", "E2"); + sTailoUnicodeToTailoNumberHashMap.put("È", "E3"); + sTailoUnicodeToTailoNumberHashMap.put("Ê", "E5"); + sTailoUnicodeToTailoNumberHashMap.put("Ē", "E7"); + sTailoUnicodeToTailoNumberHashMap.put("E̍", "E8"); + sTailoUnicodeToTailoNumberHashMap.put("E̋", "E9"); + + // e + sTailoUnicodeToTailoNumberHashMap.put("é", "e2"); + sTailoUnicodeToTailoNumberHashMap.put("è", "e3"); + sTailoUnicodeToTailoNumberHashMap.put("ê", "e5"); + sTailoUnicodeToTailoNumberHashMap.put("ē", "e7"); + sTailoUnicodeToTailoNumberHashMap.put("e̍", "e8"); + sTailoUnicodeToTailoNumberHashMap.put("e̋", "e9"); + + // O + sTailoUnicodeToTailoNumberHashMap.put("Ó", "O2"); + sTailoUnicodeToTailoNumberHashMap.put("Ò", "O3"); + sTailoUnicodeToTailoNumberHashMap.put("Ô", "O5"); + sTailoUnicodeToTailoNumberHashMap.put("Ō", "O7"); + sTailoUnicodeToTailoNumberHashMap.put("O̍", "O8"); + sTailoUnicodeToTailoNumberHashMap.put("Ő", "O9"); + + // o + sTailoUnicodeToTailoNumberHashMap.put("ó", "o2"); + sTailoUnicodeToTailoNumberHashMap.put("ò", "o3"); + sTailoUnicodeToTailoNumberHashMap.put("ô", "o5"); + sTailoUnicodeToTailoNumberHashMap.put("ō", "o7"); + sTailoUnicodeToTailoNumberHashMap.put("o̍", "o8"); + sTailoUnicodeToTailoNumberHashMap.put("ő", "o9"); + + // Oo + sTailoUnicodeToTailoNumberHashMap.put("Óo", "Oo2"); + sTailoUnicodeToTailoNumberHashMap.put("Òo", "Oo3"); + sTailoUnicodeToTailoNumberHashMap.put("Ôo", "Oo5"); + sTailoUnicodeToTailoNumberHashMap.put("Ōo", "Oo7"); + sTailoUnicodeToTailoNumberHashMap.put("O̍o", "Oo8"); + sTailoUnicodeToTailoNumberHashMap.put("Őo", "Oo9"); + + // OO + sTailoUnicodeToTailoNumberHashMap.put("ÓO", "OO2"); + sTailoUnicodeToTailoNumberHashMap.put("ÒO", "OO3"); + sTailoUnicodeToTailoNumberHashMap.put("ÔO", "OO5"); + sTailoUnicodeToTailoNumberHashMap.put("ŌO", "OO7"); + sTailoUnicodeToTailoNumberHashMap.put("O̍O", "OO8"); + sTailoUnicodeToTailoNumberHashMap.put("ŐO", "OO9"); + + // o + sTailoUnicodeToTailoNumberHashMap.put("óo", "oo2"); + sTailoUnicodeToTailoNumberHashMap.put("òo", "oo3"); + sTailoUnicodeToTailoNumberHashMap.put("ôo", "oo5"); + sTailoUnicodeToTailoNumberHashMap.put("ōo", "oo7"); + sTailoUnicodeToTailoNumberHashMap.put("o̍o", "oo8"); + sTailoUnicodeToTailoNumberHashMap.put("őo", "oo9"); + + final Set keys = sTailoUnicodeToTailoNumberHashMap.keySet(); + for (String key : keys) { + String value = sTailoUnicodeToTailoNumberHashMap.get(key); + sTailoNumberToTailoUnicodeHashMap.put(value, key); + } + } +} diff --git a/TaigiDict/app/src/main/java/com/taccotap/taigidict/converter/TailoInputConverter.java b/TaigiDict/app/src/main/java/com/taccotap/taigidict/converter/TailoInputConverter.java new file mode 100644 index 0000000..2beeff6 --- /dev/null +++ b/TaigiDict/app/src/main/java/com/taccotap/taigidict/converter/TailoInputConverter.java @@ -0,0 +1,173 @@ +package com.taccotap.taigidict.converter; + +import android.text.TextUtils; +import android.util.Log; + +import com.taccotap.taigidict.BuildConfig; + +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +class TailoInputConverter { + private static final String TAG = TailoInputConverter.class.getSimpleName(); + + private static Pattern sTailoWordExtractPattern = Pattern.compile("(?:(ph|p|m|b|th|tsh|ts|t|n|l|kh|k|ng|g|h|s|j)?([aiueo+]+(?:nn)?|ng|m)(?:(ng|m|n)|(p|t|h|k))?([1-9])?|(ph|p|m|b|th|tsh|ts|t|n|l|kh|k|ng|g|h|s|j)-?-?)", Pattern.CASE_INSENSITIVE); + + public static String convertTailoNumberRawInputToTailoWords(String input) { + if (BuildConfig.DEBUG_LOG) { + Log.d(TAG, "convertTailoNumberRawInputToTailoWords(): input=" + input); + } + + if (input == null) { + return input; + } + + final Matcher matcher = sTailoWordExtractPattern.matcher(input); + int groupCount = matcher.groupCount(); + if (groupCount == 0) { + Log.w(TAG, "groupCount=0, return. input = " + input); + return input; + } + + StringBuilder stringBuilder = new StringBuilder(); + boolean isMatcherFound = false; + while (matcher.find()) { + final String foundTaigiWord = matcher.group(); + + String tailo = parseTailoNumberToTailo(foundTaigiWord); + if (BuildConfig.DEBUG_LOG) { + Log.d(TAG, "foundTaigiWord=" + foundTaigiWord + ", tailo=" + tailo); + } + + stringBuilder.append(tailo); + stringBuilder.append("-"); + + isMatcherFound = true; + } + if (isMatcherFound) { + stringBuilder.deleteCharAt(stringBuilder.length() - 1); + } + + return stringBuilder.toString(); + } + + private static String parseTailoNumberToTailo(String tailoNumber) { + String fixedTailoNumber = fixTailoNumber(tailoNumber); + + if (fixedTailoNumber.length() <= 1) { + return fixedTailoNumber; + } + + if (BuildConfig.DEBUG_LOG) { + Log.d(TAG, "fixedTailoNumber=" + fixedTailoNumber); + } + + String number = ""; + + final String lastCharString = fixedTailoNumber.substring(fixedTailoNumber.length() - 1); + if (BuildConfig.DEBUG_LOG) { + Log.d(TAG, "lastCharString=" + lastCharString); + } + if (TextUtils.isDigitsOnly(lastCharString)) { + number = lastCharString; + } + + if (TextUtils.isEmpty(number)) { + return tailoNumber; + } + + if (BuildConfig.DEBUG_LOG) { + Log.d(TAG, "number=" + number); + } + + String tailoWithoutNumber = fixedTailoNumber.substring(0, fixedTailoNumber.length() - 1); + + if (BuildConfig.DEBUG_LOG) { + Log.d(TAG, "tailoWithoutNumber=" + tailoWithoutNumber); + } + + if (tailoWithoutNumber.contains("a")) { + return replaceTailoNumberWithTailoUnicode(number, tailoWithoutNumber, "a"); + } else if (tailoWithoutNumber.contains("A")) { + return replaceTailoNumberWithTailoUnicode(number, tailoWithoutNumber, "A"); + } else if (tailoWithoutNumber.contains("oo")) { + return replaceTailoNumberWithTailoUnicode(number, tailoWithoutNumber, "o"); + } else if (tailoWithoutNumber.contains("Oo") || tailoWithoutNumber.contains("OO")) { + return replaceTailoNumberWithTailoUnicode(number, tailoWithoutNumber, "O"); + } else if (tailoWithoutNumber.contains("e")) { + return replaceTailoNumberWithTailoUnicode(number, tailoWithoutNumber, "e"); + } else if (tailoWithoutNumber.contains("E")) { + return replaceTailoNumberWithTailoUnicode(number, tailoWithoutNumber, "E"); + } else if (tailoWithoutNumber.contains("o")) { + return replaceTailoNumberWithTailoUnicode(number, tailoWithoutNumber, "o"); + } else if (tailoWithoutNumber.contains("O")) { + return replaceTailoNumberWithTailoUnicode(number, tailoWithoutNumber, "O"); + } else if (tailoWithoutNumber.contains("iu") || tailoWithoutNumber.contains("Iu")) { + return replaceTailoNumberWithTailoUnicode(number, tailoWithoutNumber, "u"); + } else if (tailoWithoutNumber.contains("IU")) { + return replaceTailoNumberWithTailoUnicode(number, tailoWithoutNumber, "U"); + } else if (tailoWithoutNumber.contains("ui") || tailoWithoutNumber.contains("Ui")) { + return replaceTailoNumberWithTailoUnicode(number, tailoWithoutNumber, "i"); + } else if (tailoWithoutNumber.contains("UI")) { + return replaceTailoNumberWithTailoUnicode(number, tailoWithoutNumber, "I"); + } else if (tailoWithoutNumber.contains("i")) { + return replaceTailoNumberWithTailoUnicode(number, tailoWithoutNumber, "i"); + } else if (tailoWithoutNumber.contains("I")) { + return replaceTailoNumberWithTailoUnicode(number, tailoWithoutNumber, "I"); + } else if (tailoWithoutNumber.contains("u")) { + return replaceTailoNumberWithTailoUnicode(number, tailoWithoutNumber, "u"); + } else if (tailoWithoutNumber.contains("U")) { + return replaceTailoNumberWithTailoUnicode(number, tailoWithoutNumber, "U"); + } else if (tailoWithoutNumber.contains("ng")) { + return replaceTailoNumberWithTailoUnicode(number, tailoWithoutNumber, "n"); + } else if (tailoWithoutNumber.contains("Ng") || tailoWithoutNumber.contains("NG")) { + return replaceTailoNumberWithTailoUnicode(number, tailoWithoutNumber, "N"); + } else if (tailoWithoutNumber.contains("m")) { + return replaceTailoNumberWithTailoUnicode(number, tailoWithoutNumber, "m"); + } else if (tailoWithoutNumber.contains("M")) { + return replaceTailoNumberWithTailoUnicode(number, tailoWithoutNumber, "M"); + } else if (tailoWithoutNumber.contains("n")) { + return replaceTailoNumberWithTailoUnicode(number, tailoWithoutNumber, "n"); + } else if (tailoWithoutNumber.contains("N")) { + return replaceTailoNumberWithTailoUnicode(number, tailoWithoutNumber, "N"); + } + + return fixedTailoNumber; + } + + private static String replaceTailoNumberWithTailoUnicode(String number, String tailoWithoutNumber, String contains) { + String tailoCharNumber = contains + number; + final String tailoUnicode = Tailo.sTailoNumberToTailoUnicodeHashMap.get(tailoCharNumber); + if (tailoUnicode != null) { + return tailoWithoutNumber.replaceFirst(contains, tailoUnicode); + } else { + return tailoWithoutNumber; + } + } + + private static String fixTailoNumber(String tailoNumber) { + final int foundNumberIndex = findCorrectNumberIndex(tailoNumber); + if (foundNumberIndex == -1) { + return tailoNumber; + } + + return tailoNumber.substring(0, foundNumberIndex + 1); + } + + // ex: handle tai5566 -> tai5 + private static int findCorrectNumberIndex(String tailoNumber) { + int foundNumberIndex = -1; + + final int count = tailoNumber.length(); + for (int i = count - 1; i >= 0; i--) { + char c = tailoNumber.charAt(i); + if (Character.isDigit(c)) { + foundNumberIndex = i; + } else { + break; + } + } + + return foundNumberIndex; + } +} diff --git a/TaigiDict/app/src/main/java/com/taccotap/taigidict/utils/TailoNumberToneUtils.java b/TaigiDict/app/src/main/java/com/taccotap/taigidict/converter/TailoNumberToneUtils.java similarity index 99% rename from TaigiDict/app/src/main/java/com/taccotap/taigidict/utils/TailoNumberToneUtils.java rename to TaigiDict/app/src/main/java/com/taccotap/taigidict/converter/TailoNumberToneUtils.java index 4831f1c..2724408 100644 --- a/TaigiDict/app/src/main/java/com/taccotap/taigidict/utils/TailoNumberToneUtils.java +++ b/TaigiDict/app/src/main/java/com/taccotap/taigidict/converter/TailoNumberToneUtils.java @@ -1,8 +1,9 @@ -package com.taccotap.taigidict.utils; +package com.taccotap.taigidict.converter; import java.util.regex.Matcher; import java.util.regex.Pattern; +@Deprecated public class TailoNumberToneUtils { private static final String TAG = TailoNumberToneUtils.class.getSimpleName(); diff --git a/TaigiDict/app/src/main/java/com/taccotap/taigidict/tailo/TailoDictFragment.java b/TaigiDict/app/src/main/java/com/taccotap/taigidict/tailo/TailoDictFragment.java index 79a46ab..d6adcaa 100644 --- a/TaigiDict/app/src/main/java/com/taccotap/taigidict/tailo/TailoDictFragment.java +++ b/TaigiDict/app/src/main/java/com/taccotap/taigidict/tailo/TailoDictFragment.java @@ -4,14 +4,11 @@ import android.content.Intent; import android.os.Bundle; import android.support.v4.app.Fragment; -import android.text.Html; -import android.text.method.LinkMovementMethod; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.Button; import android.widget.ImageView; -import android.widget.TextView; import com.mikepenz.community_material_typeface_library.CommunityMaterial; import com.mikepenz.iconics.IconicsDrawable; @@ -30,11 +27,11 @@ public class TailoDictFragment extends Fragment { @BindView(R.id.descIcon2) ImageView mDescIcon2ImageView; - @BindView(R.id.descIcon3) - ImageView mDescIcon3ImageView; - - @BindView(R.id.descText3) - TextView mDesc3TextView; +// @BindView(R.id.descIcon3) +// ImageView mDescIcon3ImageView; +// +// @BindView(R.id.descText3) +// TextView mDesc3TextView; @BindView(R.id.button_search_lmj) Button mSearchLmjButton; @@ -70,11 +67,11 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container, final IconicsDrawable infoIconDrawable = new IconicsDrawable(getContext()).icon(CommunityMaterial.Icon.cmd_information_outline).color(getContext().getResources().getColor(R.color.colorPrimary)).sizeDp(18); mDescIcon1ImageView.setImageDrawable(infoIconDrawable); mDescIcon2ImageView.setImageDrawable(infoIconDrawable); - mDescIcon3ImageView.setImageDrawable(infoIconDrawable); +// mDescIcon3ImageView.setImageDrawable(infoIconDrawable); - mDesc3TextView.setClickable(true); - mDesc3TextView.setMovementMethod(LinkMovementMethod.getInstance()); - mDesc3TextView.setText(Html.fromHtml(getString(R.string.fragment_tailo_search_description3))); +// mDesc3TextView.setClickable(true); +// mDesc3TextView.setMovementMethod(LinkMovementMethod.getInstance()); +// mDesc3TextView.setText(Html.fromHtml(getString(R.string.fragment_tailo_search_description3))); return view; } diff --git a/TaigiDict/app/src/main/java/com/taccotap/taigidict/tailo/search/TailoSearchActivity.java b/TaigiDict/app/src/main/java/com/taccotap/taigidict/tailo/search/TailoSearchActivity.java index 57371a8..9e475ac 100644 --- a/TaigiDict/app/src/main/java/com/taccotap/taigidict/tailo/search/TailoSearchActivity.java +++ b/TaigiDict/app/src/main/java/com/taccotap/taigidict/tailo/search/TailoSearchActivity.java @@ -1,5 +1,6 @@ package com.taccotap.taigidict.tailo.search; +import android.content.Context; import android.content.Intent; import android.os.Bundle; import android.support.v7.app.AppCompatActivity; @@ -15,18 +16,18 @@ import com.taccotap.taigidict.BuildConfig; import com.taccotap.taigidict.R; +import com.taccotap.taigidict.converter.LomajiUnicodeConverter; +import com.taccotap.taigidict.converter.PojToTailoConverter; import com.taccotap.taigidict.tailo.utils.TailoConstants; import com.taccotap.taigidict.tailo.word.TailoWordActivity; import com.taccotap.taigidict.utils.LomajiSearchUtils; -import com.taccotap.taigidict.utils.LomajiUnicodeUtils; -import com.taccotap.taigidict.utils.Poj2TailoUtils; -import com.taccotap.taigidict.utils.TailoNumberToneUtils; import com.taccotap.taigidictmodel.tailo.TlTaigiWord; import butterknife.BindView; import butterknife.ButterKnife; import io.reactivex.functions.Consumer; import io.realm.Realm; +import uk.co.chrisjenx.calligraphy.CalligraphyContextWrapper; public class TailoSearchActivity extends AppCompatActivity implements SearchView.OnQueryTextListener, CompoundButton.OnCheckedChangeListener { private static final String TAG = TailoSearchActivity.class.getSimpleName(); @@ -63,6 +64,11 @@ public class TailoSearchActivity extends AppCompatActivity implements SearchView private String mCurrentQueryString = TailoConstants.DEFAULT_QUERY_STRING; private boolean mIsCurrentSearchEquals = false; + @Override + protected void attachBaseContext(Context newBase) { + super.attachBaseContext(CalligraphyContextWrapper.wrap(newBase)); + } + @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); @@ -72,6 +78,7 @@ protected void onCreate(Bundle savedInstanceState) { handleIntent(); mRealm = Realm.getDefaultInstance(); + initRecyclerView(); initRadioButton(); initSearch(); @@ -183,21 +190,13 @@ public boolean onQueryTextChange(String query) { String handledQueryString = query.trim(); if (mCurrentSearchType == SEARCH_TYPE_LOMAJI) { - String fixedLomaji = LomajiUnicodeUtils.fixTwoCharWord(query); + String fixedLomaji = LomajiUnicodeConverter.convertTwoCharWordToOneCharWord(query); if (BuildConfig.DEBUG_LOG) { logInputUnicode(fixedLomaji); } - handledQueryString = Poj2TailoUtils.poj2tailo(fixedLomaji); - - if (BuildConfig.DEBUG_LOG) { - Log.d(TAG, "handledQueryString (before number tone parser): " + handledQueryString); - } - handledQueryString = TailoNumberToneUtils.numberTone2LomaijiTone(handledQueryString); - if (BuildConfig.DEBUG_LOG) { - Log.d(TAG, "handledQueryString (after number tone parser): " + handledQueryString); - } + handledQueryString = PojToTailoConverter.convertPojMixedInputToTailoWords(fixedLomaji); } if (handledQueryString.contains(" ")) { diff --git a/TaigiDict/app/src/main/java/com/taccotap/taigidict/tailo/search/TailoSearchAdapter.java b/TaigiDict/app/src/main/java/com/taccotap/taigidict/tailo/search/TailoSearchAdapter.java index ceb682a..048dbe2 100644 --- a/TaigiDict/app/src/main/java/com/taccotap/taigidict/tailo/search/TailoSearchAdapter.java +++ b/TaigiDict/app/src/main/java/com/taccotap/taigidict/tailo/search/TailoSearchAdapter.java @@ -2,6 +2,7 @@ import android.content.Context; import android.databinding.DataBindingUtil; +import android.graphics.Typeface; import android.view.View; import android.view.ViewGroup; import android.widget.TextView; @@ -58,14 +59,22 @@ public PublishProcessor getItemClickProcessor() { @Override public TailoSearchViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { final ListitemTailoSearchBinding dataBinding = DataBindingUtil.inflate(inflater, R.layout.listitem_tailo_search, parent, false); - return new TailoSearchViewHolder(dataBinding); + + final TailoSearchViewHolder viewHolder = new TailoSearchViewHolder(dataBinding); + + Typeface lomajiTypeface = Typeface.createFromAsset(viewHolder.itemView.getContext().getAssets(), "fonts/twu3.ttf"); + viewHolder.titleContentTextView1.setTypeface(lomajiTypeface); + Typeface hanjiTypeface = Typeface.createFromAsset(viewHolder.itemView.getContext().getAssets(), "fonts/mingliub.ttc"); + viewHolder.titleContentTextView2.setTypeface(hanjiTypeface); + + return viewHolder; } @Override - public void onBindViewHolder(TailoSearchViewHolder holder, final int position) { + public void onBindViewHolder(TailoSearchViewHolder viewHolder, final int position) { TlTaigiWord tlTaigiWord = getData().get(position); - holder.itemView.setOnClickListener(new View.OnClickListener() { + viewHolder.itemView.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { mOnClickSubject.onNext(position); @@ -74,17 +83,17 @@ public void onClick(View view) { // [屬性] 附-外來詞表 if (tlTaigiWord.getWordPropertyCode() == 12) { - holder.titleTextView1.setText(R.string.listitem_tailo_search_title_text_1_goalaigi); - holder.titleTextView2.setText(R.string.listitem_tailo_search_title_text_2_goalaigi); + viewHolder.titleTextView1.setText(R.string.listitem_tailo_search_title_text_1_goalaigi); + viewHolder.titleTextView2.setText(R.string.listitem_tailo_search_title_text_2_goalaigi); - holder.titleContentTextView1.setText(tlTaigiWord.getHanji()); - holder.titleContentTextView2.setText(TailoDictHelper.getCombinatedHoagi(tlTaigiWord)); + viewHolder.titleContentTextView1.setText(tlTaigiWord.getHanji()); + viewHolder.titleContentTextView2.setText(TailoDictHelper.getCombinatedHoagi(tlTaigiWord)); } else { - holder.titleTextView1.setText(R.string.listitem_tailo_search_title_text_1_tailo); - holder.titleTextView2.setText(R.string.listitem_tailo_search_title_text_2_tailo); + viewHolder.titleTextView1.setText(R.string.listitem_tailo_search_title_text_1_tailo); + viewHolder.titleTextView2.setText(R.string.listitem_tailo_search_title_text_2_tailo); - holder.dataBinding.setTaigiWord(tlTaigiWord); - holder.dataBinding.executePendingBindings(); + viewHolder.dataBinding.setTaigiWord(tlTaigiWord); + viewHolder.dataBinding.executePendingBindings(); } } diff --git a/TaigiDict/app/src/main/java/com/taccotap/taigidict/tailo/word/TailoWordActivity.java b/TaigiDict/app/src/main/java/com/taccotap/taigidict/tailo/word/TailoWordActivity.java index 66beb02..d4e2572 100644 --- a/TaigiDict/app/src/main/java/com/taccotap/taigidict/tailo/word/TailoWordActivity.java +++ b/TaigiDict/app/src/main/java/com/taccotap/taigidict/tailo/word/TailoWordActivity.java @@ -1,6 +1,8 @@ package com.taccotap.taigidict.tailo.word; +import android.content.Context; import android.databinding.DataBindingUtil; +import android.graphics.Typeface; import android.media.AudioManager; import android.media.MediaPlayer; import android.net.Uri; @@ -29,6 +31,7 @@ import io.realm.RealmChangeListener; import io.realm.RealmList; import io.realm.RealmModel; +import uk.co.chrisjenx.calligraphy.CalligraphyContextWrapper; public class TailoWordActivity extends AppCompatActivity { private static final String TAG = TailoWordActivity.class.getSimpleName(); @@ -70,6 +73,11 @@ public class TailoWordActivity extends AppCompatActivity { private TlTaigiWord mTaigiWord; private String mVoiceUrl; + @Override + protected void attachBaseContext(Context newBase) { + super.attachBaseContext(CalligraphyContextWrapper.wrap(newBase)); + } + @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); @@ -78,9 +86,21 @@ protected void onCreate(Bundle savedInstanceState) { setVolumeControlStream(AudioManager.STREAM_MUSIC); + setFonts(); + handleIntent(); } + private void setFonts() { + Typeface lomajiTypeface = Typeface.createFromAsset(getAssets(), "fonts/twu3.ttf"); + mTitleContentTextView1.setTypeface(lomajiTypeface); + + Typeface hanjiTypeface = Typeface.createFromAsset(getAssets(), "fonts/mingliub.ttc"); + mTitleContentTextView2.setTypeface(hanjiTypeface); + mDescriptionTextView.setTypeface(hanjiTypeface); + mWordPropertyTextView.setTypeface(hanjiTypeface); + } + private void handleIntent() { if (!ACTION_TAILO_WORD_MAIN_CODE.equals(getIntent().getAction())) { finish(); diff --git a/TaigiDict/app/src/main/java/com/taccotap/taigidict/utils/Poj2TailoUtils.java b/TaigiDict/app/src/main/java/com/taccotap/taigidict/utils/Poj2TailoUtils.java deleted file mode 100644 index e341dcc..0000000 --- a/TaigiDict/app/src/main/java/com/taccotap/taigidict/utils/Poj2TailoUtils.java +++ /dev/null @@ -1,31 +0,0 @@ -package com.taccotap.taigidict.utils; - -public class Poj2TailoUtils { - - public static final String poj2tailo(String poj) { - String tailo = poj.replaceAll("ch", "ts") // ch -> ts - .replaceAll("Ch", "Ts") // Ch -> Ts - .replaceAll("\u207f", "nn") // ⁿ -> nn - .replaceAll("o(.?)\u0358", "o$1o") // o͘ -> oo, ó͘ -> óo, and etc. - .replaceAll("O(.?)\u0358", "O$1o") // o͘ -> oo, ó͘ -> óo, and etc. - .replaceAll("o([aáàâāa̍AÁÀÂĀA̍eéèêēe̍EÉÈÊĒE̍])", "u$1") // oa -> ua, oe -> ue, and etc. - .replaceAll("O([aáàâāa̍AÁÀÂĀA̍eéèêēe̍EÉÈÊĒE̍])", "U$1") // Oa -> Ua, Oe -> Ue, and etc. - .replaceAll("ek", "ik") // ek -> ik - .replaceAll("Ek", "Ik") // Ek -> Ik - .replaceAll("e\u030dk", "i\u030dk") // e̍k -> i̍k - .replaceAll("E\u030dk", "I\u030dk") // E̍k -> I̍k - .replaceAll("eng", "ing") // eng -> ing - .replaceAll("Eng", "Ing") // Eng -> Ing - .replaceAll("\u00e9ng", "\u00edng") // éng -> íng - .replaceAll("\u00c9ng", "\u00cdng") // Éng -> Íng - .replaceAll("\u00e8ng", "\u00ecng") // èng -> ìng - .replaceAll("\u00c8ng", "\u00ccng") // Èng -> Ìng - .replaceAll("\u00eang", "\u00eeng") // êng -> îng - .replaceAll("\u00cang", "\u00ceng") // Êng -> Îng - .replaceAll("\u0113ng", "\u012bng") // ēng -> īng - .replaceAll("\u0102ng", "\u012ang") // Ēng -> Īng - .replaceAll("e\u030dng", "i\u030dng") // e̍ng -> i̍ng - .replaceAll("E\u030dng", "I\u030dng"); // E̍ng -> I̍ng - return tailo; - } -} diff --git a/TaigiDict/app/src/main/res/drawable/textview_border_light.xml b/TaigiDict/app/src/main/res/drawable/textview_border_light.xml index e9df9fb..f063723 100644 --- a/TaigiDict/app/src/main/res/drawable/textview_border_light.xml +++ b/TaigiDict/app/src/main/res/drawable/textview_border_light.xml @@ -9,7 +9,7 @@ diff --git a/TaigiDict/app/src/main/res/layout/activity_tailo_word.xml b/TaigiDict/app/src/main/res/layout/activity_tailo_word.xml index 8d6ef2c..361a8c7 100644 --- a/TaigiDict/app/src/main/res/layout/activity_tailo_word.xml +++ b/TaigiDict/app/src/main/res/layout/activity_tailo_word.xml @@ -61,9 +61,9 @@ + android:orientation="horizontal" + android:visibility="gone"> 關於 授權資訊 - 若是欲用「羅馬字」來揣,會使輸入「臺羅」抑是「白話字」,請用羅馬字 ê 聲調符號。 - 若是欲聽看覓按怎唸,需要上網才會使聽。 + 若是欲用「羅馬字」來揣,會使輸入「臺羅」抑是「白話字」,聲調符號欲用「數字」抑是「羅馬字」攏會使。 + 若是欲聽字詞按怎唸,愛上網才會使聽。 加我 ê LINE。]]> 請選一種揣 ê 方式: 臺語羅馬字