Skip to content
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

Closed
Closed
Show file tree
Hide file tree
Changes from 4 commits
Commits
Show all changes
78 commits
Select commit Hold shift + click to select a range
d380cf6
Use a separate section for dialpad settings
Belyavin Dec 24, 2023
9c9b116
Support for different languages for T9 on dialpad
Belyavin Dec 24, 2023
5e7a277
Added Belarusian
Belyavin Jan 8, 2024
1b6dc07
Setup languages on startup
Belyavin Jan 21, 2024
84451ce
Use common string instead of a new one
Belyavin Jan 22, 2024
5dfb444
Text aligned
Belyavin Jan 23, 2024
a97cf00
Ukrainian corrected
Belyavin Jan 26, 2024
213e18e
Russian corrected
Belyavin Feb 6, 2024
aad547f
Update bug report template
naveensingh Jan 24, 2024
ad2a978
Update bug report template
naveensingh Jan 24, 2024
5dc16cc
Update feature request template
naveensingh Jan 24, 2024
ca6c0ed
Update README.md
Aga-C Jan 23, 2024
3b07c1d
Create pull request template
naveensingh Jan 24, 2024
6628cc2
Fix contribution guidelines link
naveensingh Jan 24, 2024
7f3cc98
Translated using Weblate (German)
Jan 15, 2024
d0a58f8
Translated using Weblate (Spanish)
gallegonovato Jan 15, 2024
556e583
Translated using Weblate (Polish)
Aga-C Jan 15, 2024
e417047
Translated using Weblate (Chinese (Simplified))
Jan 16, 2024
c8a9877
Translated using Weblate (Polish)
Aga-C Jan 15, 2024
6c54dd0
Translated using Weblate (German)
Jan 15, 2024
4e3a105
Translated using Weblate (Spanish)
gallegonovato Jan 15, 2024
2bd95f1
Translated using Weblate (Czech)
Jan 17, 2024
a60cf78
Translated using Weblate (Turkish)
oersen Jan 16, 2024
763668e
Translated using Weblate (French)
Jan 16, 2024
106602d
Translated using Weblate (Swedish)
Jan 17, 2024
b7d5ddc
Translated using Weblate (Estonian)
Jan 19, 2024
1a4fee2
Translated using Weblate (French)
Jan 19, 2024
11a6024
Translated using Weblate (Estonian)
Jan 19, 2024
cc9b6f2
Translated using Weblate (Portuguese)
muxina-credo Jan 18, 2024
deab562
Translated using Weblate (French)
Jan 19, 2024
01d5a00
Translated using Weblate (Swedish)
Jan 19, 2024
1bf7e1a
Translated using Weblate (Portuguese)
Jan 20, 2024
b62aa36
Translated using Weblate (Russian)
Artem13327 Jan 20, 2024
0ce60b1
Translated using Weblate (Italian)
gdonisi Jan 21, 2024
f380477
Translated using Weblate (Portuguese)
Jan 21, 2024
e6807f8
Translated using Weblate (Russian)
solokot Jan 21, 2024
eb639fd
Translated using Weblate (Ukrainian)
Belyavin Jan 21, 2024
89031de
Translated using Weblate (Vietnamese)
Jan 21, 2024
584769b
Translated using Weblate (Italian)
gdonisi Jan 21, 2024
0b101d0
Translated using Weblate (Dutch)
ltguillaume Jan 22, 2024
6d66f10
Translated using Weblate (Galician)
Jan 23, 2024
4dde36c
Translated using Weblate (Interlingua)
softinterlingua Jan 23, 2024
38bee09
Translated using Weblate (Czech)
Fjuro Jan 22, 2024
7645fd4
Translated using Weblate (Galician)
Jan 24, 2024
73b99e2
Translated using Weblate (Slovenian)
Ziiga Jan 23, 2024
f30084c
Translated using Weblate (Galician)
Jan 24, 2024
682f130
Translated using Weblate (Swedish)
Jan 23, 2024
256b491
Translated using Weblate (Basque)
Jan 24, 2024
c05d95d
Translated using Weblate (Czech)
Fjuro Jan 24, 2024
b6c0c29
Translated using Weblate (Bulgarian)
salif Jan 24, 2024
bd4f0de
Add Github image minimizer
naveensingh Jan 26, 2024
6fabf16
Reduce GitHub image minimizer height
naveensingh Jan 26, 2024
5b03867
Move image minimizer to .github/workflows
naveensingh Jan 26, 2024
0d13988
Translated using Weblate (Bulgarian)
salif Jan 25, 2024
e3150d1
Translated using Weblate (Italian)
gdonisi Jan 26, 2024
0c819ca
Translated using Weblate (Persian)
Jan 26, 2024
e41e582
Translated using Weblate (Croatian)
milotype Jan 28, 2024
ea9f287
Translated using Weblate (Croatian)
milotype Jan 27, 2024
42dcb41
Update README.md
Aga-C Feb 12, 2024
3a5060b
Removed call history limit (#125)
Aga-C Mar 4, 2024
3f03f3e
Update AGP
naveensingh Mar 17, 2024
4d6ea9f
Update danish strings.xml
lianergoist Jan 31, 2024
62d1d04
Update danish strings.xml
lianergoist Jan 31, 2024
5332ad3
Update danish strings.xml
lianergoist Jan 31, 2024
435d1cb
Don't hide hang up button when showing dialpad (#9)
Aga-C Jan 20, 2024
e45a8c0
Added margin and elevation to hang up button
Aga-C Jan 20, 2024
3584b86
Increase dialpad button size
naveensingh Mar 17, 2024
647ca9d
Readjust the layout so dialpad is elevated
naveensingh Mar 17, 2024
78d6e38
Increase avatar size
naveensingh Mar 17, 2024
f8db75d
Hide ongoing end call button on incoming calls!
naveensingh Mar 17, 2024
4ebf196
Use elevated dialpad color in dark theme
naveensingh Mar 17, 2024
d97e473
Show placeholder icon when no avatar is available
naveensingh Mar 17, 2024
c0b4118
Moved dialpad settings to the separate section (#116) (#117)
Aga-C Mar 17, 2024
0a223fb
Minor code improvement
naveensingh Mar 17, 2024
cde7836
Update RecentsHelper.kt
Aga-C Mar 17, 2024
9200aeb
Fix view IDs
naveensingh Mar 18, 2024
a9ee2a7
Merge branch 'master' into additional_language_on_dialpad
naveensingh Mar 18, 2024
04b9501
Center "*" and "#"
naveensingh Mar 18, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 20 additions & 36 deletions app/src/main/kotlin/org/fossify/phone/activities/DialpadActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import android.os.Bundle
import android.os.Handler
import android.os.Looper
import android.provider.Telephony.Sms.Intents.SECRET_CODE_ACTION
import android.telephony.PhoneNumberUtils
import android.telephony.TelephonyManager
import android.util.TypedValue
import android.view.KeyEvent
Expand All @@ -31,6 +30,9 @@ import org.fossify.phone.extensions.*
import org.fossify.phone.helpers.DIALPAD_TONE_LENGTH_MS
import org.fossify.phone.helpers.ToneGeneratorHelper
import org.fossify.phone.models.SpeedDial
import org.fossify.phone.helpers.DialpadT9
import org.fossify.phone.helpers.LANGUAGE_NONE
import java.io.InputStreamReader
import java.util.Locale
import kotlin.math.roundToInt

Expand All @@ -39,8 +41,6 @@ class DialpadActivity : SimpleActivity() {

private var allContacts = ArrayList<Contact>()
private var speedDialValues = ArrayList<SpeedDial>()
private val russianCharsMap = HashMap<Char, Int>()
private var hasRussianLocale = false
private var privateCursor: Cursor? = null
private var toneGeneratorHelper: ToneGeneratorHelper? = null
private val longPressTimeout = ViewConfiguration.getLongPressTimeout().toLong()
Expand All @@ -50,7 +50,6 @@ class DialpadActivity : SimpleActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(binding.root)
hasRussianLocale = Locale.getDefault().language == "ru"

binding.apply {
updateMaterialActivityViews(dialpadCoordinator, dialpadHolder, useTransparentNavigation = true, useTopSearchMenu = false)
Expand Down Expand Up @@ -105,16 +104,21 @@ class DialpadActivity : SimpleActivity() {
toneGeneratorHelper = ToneGeneratorHelper(this, DIALPAD_TONE_LENGTH_MS)

binding.dialpadWrapper.apply {
if (hasRussianLocale) {
initRussianChars()
dialpad2Letters.append("\nАБВГ")
dialpad3Letters.append("\nДЕЁЖЗ")
dialpad4Letters.append("\nИЙКЛ")
dialpad5Letters.append("\nМНОП")
dialpad6Letters.append("\nРСТУ")
dialpad7Letters.append("\nФХЦЧ")
dialpad8Letters.append("\nШЩЪЫ")
dialpad9Letters.append("\nЬЭЮЯ")
val lang = config.dialpadSecondaryLanguage
if (lang!! != LANGUAGE_NONE) {
if (!DialpadT9.Initialized) {
val reader = InputStreamReader(resources.openRawResource(R.raw.t9languages))
DialpadT9.readFromJson(reader.readText())
}

dialpad2Letters.append("\n" + DialpadT9.getLettersForNumber(2, lang))
dialpad3Letters.append("\n" + DialpadT9.getLettersForNumber(3, lang))
dialpad4Letters.append("\n" + DialpadT9.getLettersForNumber(4, lang))
dialpad5Letters.append("\n" + DialpadT9.getLettersForNumber(5, lang))
dialpad6Letters.append("\n" + DialpadT9.getLettersForNumber(6, lang))
dialpad7Letters.append("\n" + DialpadT9.getLettersForNumber(7, lang))
dialpad8Letters.append("\n" + DialpadT9.getLettersForNumber(8, lang))
dialpad9Letters.append("\n" + DialpadT9.getLettersForNumber(9, lang))

val fontSize = resources.getDimension(R.dimen.small_text_size)
arrayOf(
Expand Down Expand Up @@ -272,17 +276,8 @@ class DialpadActivity : SimpleActivity() {
(binding.dialpadList.adapter as? ContactsAdapter)?.finishActMode()

val filtered = allContacts.filter {
var convertedName = PhoneNumberUtils.convertKeypadLettersToDigits(it.name.normalizeString())

if (hasRussianLocale) {
var currConvertedName = ""
convertedName.lowercase(Locale.getDefault()).forEach { char ->
val convertedChar = russianCharsMap.getOrElse(char) { char }
currConvertedName += convertedChar
}
convertedName = currConvertedName
}

val convertedName = DialpadT9.convertLettersToNumbers(
it.name.normalizeString().uppercase(), config.dialpadSecondaryLanguage!!)
it.doesContainPhoneNumber(text) || (convertedName.contains(text, true))
}.sortedWith(compareBy {
!it.doesContainPhoneNumber(text)
Expand Down Expand Up @@ -360,17 +355,6 @@ class DialpadActivity : SimpleActivity() {
return false
}

private fun initRussianChars() {
russianCharsMap['а'] = 2; russianCharsMap['б'] = 2; russianCharsMap['в'] = 2; russianCharsMap['г'] = 2
russianCharsMap['д'] = 3; russianCharsMap['е'] = 3; russianCharsMap['ё'] = 3; russianCharsMap['ж'] = 3; russianCharsMap['з'] = 3
russianCharsMap['и'] = 4; russianCharsMap['й'] = 4; russianCharsMap['к'] = 4; russianCharsMap['л'] = 4
russianCharsMap['м'] = 5; russianCharsMap['н'] = 5; russianCharsMap['о'] = 5; russianCharsMap['п'] = 5
russianCharsMap['р'] = 6; russianCharsMap['с'] = 6; russianCharsMap['т'] = 6; russianCharsMap['у'] = 6
russianCharsMap['ф'] = 7; russianCharsMap['х'] = 7; russianCharsMap['ц'] = 7; russianCharsMap['ч'] = 7
russianCharsMap['ш'] = 8; russianCharsMap['щ'] = 8; russianCharsMap['ъ'] = 8; russianCharsMap['ы'] = 8
russianCharsMap['ь'] = 9; russianCharsMap['э'] = 9; russianCharsMap['ю'] = 9; russianCharsMap['я'] = 9
}

private fun startDialpadTone(char: Char) {
if (config.dialpadBeeps) {
pressedKeys.add(char)
Expand Down
25 changes: 22 additions & 3 deletions app/src/main/kotlin/org/fossify/phone/activities/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@ import org.fossify.phone.fragments.ContactsFragment
import org.fossify.phone.fragments.FavoritesFragment
import org.fossify.phone.fragments.MyViewPagerFragment
import org.fossify.phone.fragments.RecentsFragment
import org.fossify.phone.helpers.OPEN_DIAL_PAD_AT_LAUNCH
import org.fossify.phone.helpers.RecentsHelper
import org.fossify.phone.helpers.tabsList
import org.fossify.phone.helpers.*
import java.io.InputStreamReader
import java.util.Locale

class MainActivity : SimpleActivity() {
private val binding by viewBinding(ActivityMainBinding::inflate)
Expand Down Expand Up @@ -90,6 +90,8 @@ class MainActivity : SimpleActivity() {
setDefaultCallerIdApp()
}

setupSecondaryLanguage()

setupTabs()
Contact.sorting = config.sorting
}
Expand Down Expand Up @@ -612,4 +614,21 @@ class MainActivity : SimpleActivity() {
} catch (e: Exception) {
}
}

private fun setupSecondaryLanguage() {
if (!DialpadT9.Initialized) {
val reader = InputStreamReader(resources.openRawResource(R.raw.t9languages))
DialpadT9.readFromJson(reader.readText())
}

if (config.dialpadSecondaryLanguage == "") {
val currentLang = Locale.getDefault().language
if (DialpadT9.getSupportedSecondaryLanguages().contains(currentLang)) {
config.dialpadSecondaryLanguage = currentLang
} else {
config.dialpadSecondaryLanguage = LANGUAGE_NONE
}
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ import org.fossify.phone.dialogs.ManageVisibleTabsDialog
import org.fossify.phone.extensions.config
import org.fossify.phone.helpers.RecentsHelper
import org.fossify.phone.models.RecentCall
import org.fossify.phone.helpers.DialpadT9
import org.fossify.phone.helpers.LANGUAGE_NONE
import org.fossify.phone.helpers.SECONDARY_LANGUAGE_NONE_ID
import java.util.Locale
import kotlin.system.exitProcess

Expand Down Expand Up @@ -80,6 +83,7 @@ class SettingsActivity : SimpleActivity() {
setupDialpadVibrations()
setupDialpadNumbers()
setupDialpadBeeps()
setupDialpadSecondaryLanguage()
setupShowCallConfirmation()
setupDisableProximitySensor()
setupDisableSwipeToAnswer()
Expand All @@ -92,6 +96,7 @@ class SettingsActivity : SimpleActivity() {
arrayOf(
settingsColorCustomizationSectionLabel,
settingsGeneralSettingsLabel,
settingsDialpadSettingsLabel,
settingsStartupLabel,
settingsCallsLabel,
settingsMigrationSectionLabel
Expand Down Expand Up @@ -283,6 +288,52 @@ class SettingsActivity : SimpleActivity() {
}
}

private fun getLanguageName(lang: String?): String? {
return if (lang == LANGUAGE_NONE) {
getString(R.string.none_explicit)
} else {
val currentLocale = Locale.getDefault()
val locale = Locale(lang!!)
locale.getDisplayLanguage(currentLocale)
}
}

private fun setupDialpadSecondaryLanguage() {
binding.settingsDialpadSecondaryLanguage.text = getLanguageName(config.dialpadSecondaryLanguage)
binding.settingsDialpadSecondaryLanguageHolder.setOnClickListener {
val items: ArrayList<RadioItem> = arrayListOf(RadioItem(SECONDARY_LANGUAGE_NONE_ID, getString(R.string.none_explicit)))
val supportedLanguages = DialpadT9.getSupportedSecondaryLanguages()
for (i in supportedLanguages.indices) {
items.add(RadioItem(i, getLanguageName(supportedLanguages[i])!!))
}

RadioGroupDialog(this@SettingsActivity, items, supportedLanguages.indexOf(config.dialpadSecondaryLanguage)) {
val index = it as Int
if (index == -1 || index >= supportedLanguages.size) {
config.dialpadSecondaryLanguage = LANGUAGE_NONE
} else {
config.dialpadSecondaryLanguage = supportedLanguages[it]
}
binding.settingsDialpadSecondaryLanguage.text = getLanguageName(config.dialpadSecondaryLanguage)
}
}

binding.settingsFontSize.text = getFontSizeText()
binding.settingsFontSizeHolder.setOnClickListener {
val items = arrayListOf(
RadioItem(FONT_SIZE_SMALL, getString(R.string.small)),
RadioItem(FONT_SIZE_MEDIUM, getString(R.string.medium)),
RadioItem(FONT_SIZE_LARGE, getString(R.string.large)),
RadioItem(FONT_SIZE_EXTRA_LARGE, getString(R.string.extra_large))
)

RadioGroupDialog(this@SettingsActivity, items, config.fontSize) {
config.fontSize = it as Int
binding.settingsFontSize.text = getFontSizeText()
}
}
Comment on lines +320 to +334
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Duplicated code from setupFontSize()

}

private fun setupShowCallConfirmation() {
binding.apply {
settingsShowCallConfirmation.isChecked = config.showCallConfirmation
Expand Down
4 changes: 4 additions & 0 deletions app/src/main/kotlin/org/fossify/phone/helpers/Config.kt
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,10 @@ class Config(context: Context) : BaseConfig(context) {
get() = prefs.getBoolean(DIALPAD_VIBRATION, true)
set(dialpadVibration) = prefs.edit().putBoolean(DIALPAD_VIBRATION, dialpadVibration).apply()

var dialpadSecondaryLanguage: String?
get() = prefs.getString(DIALPAD_SECONDARY_LANGUAGE, "")
set(dialpadSecondaryLanguage) = prefs.edit().putString(DIALPAD_SECONDARY_LANGUAGE, dialpadSecondaryLanguage).apply()

var hideDialpadNumbers: Boolean
get() = prefs.getBoolean(HIDE_DIALPAD_NUMBERS, false)
set(hideDialpadNumbers) = prefs.edit().putBoolean(HIDE_DIALPAD_NUMBERS, hideDialpadNumbers).apply()
Expand Down
7 changes: 7 additions & 0 deletions app/src/main/kotlin/org/fossify/phone/helpers/Constants.kt
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ const val FAVORITES_CUSTOM_ORDER_SELECTED = "favorites_custom_order_selected"
const val WAS_OVERLAY_SNACKBAR_CONFIRMED = "was_overlay_snackbar_confirmed"
const val DIALPAD_VIBRATION = "dialpad_vibration"
const val DIALPAD_BEEPS = "dialpad_beeps"
const val DIALPAD_SECONDARY_LANGUAGE = "dialpad_secondary_language"
const val HIDE_DIALPAD_NUMBERS = "hide_dialpad_numbers"
const val ALWAYS_SHOW_FULLSCREEN = "always_show_fullscreen"

Expand All @@ -31,3 +32,9 @@ const val DECLINE_CALL = PATH + "decline_call"
const val DIALPAD_TONE_LENGTH_MS = 150L // The length of DTMF tones in milliseconds

const val MIN_RECENTS_THRESHOLD = 30

const val LANGUAGE_NONE = "none"

const val SECONDARY_LANGUAGE_NONE_ID: Int = -1

const val LOCALE_EN = "en"
103 changes: 103 additions & 0 deletions app/src/main/kotlin/org/fossify/phone/helpers/DialpadT9.kt
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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Redundant public modifier.

}

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) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is no space between if and (...

lang.letters[number - 2] += c.toString()
lang.charMap[c] = number
}
}

languages[LOCALE_EN] = lang
}

public var Initialized = false
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The variable name should start with a lowercase letter. Another redundant public modifier.


init {
initLatinChars()
}

/**
* Read extra languages data from JSON
*/
public fun readFromJson(jsonText: String){
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is no space between ) and {...

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;
Copy link
Member

Choose a reason for hiding this comment

The 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)) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
}
}
Loading