-
-
Notifications
You must be signed in to change notification settings - Fork 45
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Additional language on dialpad #49
Changes from 7 commits
d380cf6
9c9b116
5e7a277
1b6dc07
84451ce
5dfb444
a97cf00
213e18e
aad547f
ad2a978
5dc16cc
ca6c0ed
3b07c1d
6628cc2
7f3cc98
d0a58f8
556e583
e417047
c8a9877
6c54dd0
4e3a105
2bd95f1
a60cf78
763668e
106602d
b7d5ddc
1a4fee2
11a6024
cc9b6f2
deab562
01d5a00
1bf7e1a
b62aa36
0ce60b1
f380477
e6807f8
eb639fd
89031de
584769b
0b101d0
6d66f10
4dde36c
38bee09
7645fd4
73b99e2
f30084c
682f130
256b491
c05d95d
b6c0c29
bd4f0de
6fabf16
5b03867
0d13988
e3150d1
0c819ca
e41e582
ea9f287
42dcb41
3a5060b
3f03f3e
4d6ea9f
62d1d04
5332ad3
435d1cb
e45a8c0
3584b86
647ca9d
78d6e38
f8db75d
4ebf196
d97e473
c0b4118
0a223fb
cde7836
9200aeb
a9ee2a7
04b9501
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
package org.fossify.phone.helpers | ||
|
||
import android.telephony.PhoneNumberUtils | ||
import com.google.gson.JsonParser | ||
|
||
private typealias CharMap = HashMap<Char, Int> | ||
|
||
/** | ||
* A helper class to map chars of various alphabets to numbers | ||
*/ | ||
object DialpadT9 { | ||
|
||
private class T9Language{ | ||
public val letters = Array<String>(8) {""} | ||
public val charMap = CharMap() | ||
Comment on lines
+14
to
+15
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Redundant |
||
} | ||
|
||
private val languages = HashMap<String, T9Language>() | ||
|
||
/** | ||
* Create a map for Latin (English) characters according to ITU E.161 and ISO/IEC 9995-8 | ||
*/ | ||
private fun initLatinChars() { | ||
val lang = T9Language() | ||
for (c in 'A'..'Z') { | ||
val number = PhoneNumberUtils.convertKeypadLettersToDigits(c.toString()).toInt(); | ||
if(number in 2..9) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There is no space between |
||
lang.letters[number - 2] += c.toString() | ||
lang.charMap[c] = number | ||
} | ||
} | ||
|
||
languages[LOCALE_EN] = lang | ||
} | ||
|
||
public var Initialized = false | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The variable name should start with a lowercase letter. Another redundant |
||
|
||
init { | ||
initLatinChars() | ||
} | ||
|
||
/** | ||
* Read extra languages data from JSON | ||
*/ | ||
public fun readFromJson(jsonText: String){ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There is no space between |
||
for (arrayElement in JsonParser.parseString(jsonText).asJsonArray) { | ||
val objectElement = arrayElement.asJsonObject | ||
val lang = objectElement["lang"].asString | ||
if (languages[lang] != null) { | ||
continue | ||
} | ||
val language = T9Language() | ||
var i = 0 | ||
for (lettersElement in objectElement["letters"].asJsonArray) { | ||
val letters = lettersElement.asString | ||
language.letters[i] = letters | ||
for (c in letters) { | ||
language.charMap[c] = i + 2 | ||
} | ||
i++ | ||
} | ||
languages[lang] = language | ||
} | ||
|
||
Initialized = true; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Useless |
||
} | ||
|
||
public fun getLettersForNumber(number: Int, language: String): String { | ||
val lang = languages[language] | ||
return if (lang == null || number < 2 || number > 9) { | ||
"" | ||
} else { | ||
lang.letters[number - 2] | ||
} | ||
} | ||
|
||
public fun convertLettersToNumbers(letters: String, language: String): String { | ||
var res = "" | ||
val lang = languages[language] | ||
val langEn = languages[LOCALE_EN] | ||
|
||
for (c in letters) { | ||
if (lang != null && lang.charMap.containsKey(c)) { | ||
res += lang.charMap[c] | ||
} | ||
else if (langEn != null && langEn.charMap.containsKey(c)) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The code in |
||
res += langEn.charMap[c] | ||
} | ||
} | ||
|
||
return res | ||
} | ||
|
||
public fun getSupportedSecondaryLanguages(): List<String> { | ||
val res = MutableList<String>(0) {""} | ||
for (lang in languages.keys) { | ||
if (lang != LOCALE_EN) | ||
res += lang | ||
} | ||
res.sort() | ||
return res | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Duplicated code from
setupFontSize()