-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add some custom keypad letter mappings
- Loading branch information
1 parent
30b338e
commit 4f91781
Showing
2 changed files
with
39 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
commons/src/main/kotlin/org/fossify/commons/helpers/KeypadHelper.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package org.fossify.commons.helpers | ||
|
||
import android.telephony.PhoneNumberUtils | ||
|
||
/** | ||
* Mostly depends on [android.telephony.PhoneNumberUtils]. | ||
*/ | ||
object KeypadHelper { | ||
// this should probably be split into language-specific mappings | ||
private val KEYPAD_MAP = mutableMapOf<Char, Int>().apply { | ||
put('ı', 4) | ||
put('İ', 4) | ||
|
||
put('ł', 5) | ||
put('Ł', 5) | ||
} | ||
|
||
/** | ||
* Translates any alphabetic letters (i.e. [A-Za-z]) in the | ||
* specified phone number into the equivalent numeric digits, | ||
* according to the phone keypad letter mapping described in | ||
* ITU E.161 and ISO/IEC 9995-8. | ||
* | ||
* @return the input string, with alpha letters converted to numeric | ||
* digits using the phone keypad letter mapping. For example, | ||
* an input of "1-800-FOSS-411" will return "1-800-3667-411". | ||
*/ | ||
fun convertKeypadLettersToDigits(input: String): String { | ||
val digits = PhoneNumberUtils.convertKeypadLettersToDigits(input) | ||
val result = StringBuilder(digits.length) | ||
for (c in digits) { | ||
val digit = KEYPAD_MAP[c] ?: c | ||
result.append(digit) | ||
} | ||
|
||
return result.toString() | ||
} | ||
} |