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

Implement disable and enable of accent characters #172

60 changes: 57 additions & 3 deletions app/src/main/java/be/scri/fragments/LanguageSettingsFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ class LanguageSettingsFragment : Fragment() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
val viewpager = requireActivity().findViewById<ViewPager2>(R.id.view_pager)
val frameLayout = requireActivity().findViewById<ViewGroup>(R.id.fragment_container)
(requireActivity() as MainActivity).setActionBarButtonFunction(3, R.string.app_settings_title)
val callback =
requireActivity().onBackPressedDispatcher.addCallback(this) {
Expand All @@ -47,7 +46,7 @@ class LanguageSettingsFragment : Fragment() {
inflater: LayoutInflater,
container: ViewGroup?,
savedInstanceState: Bundle?,
): View? {
): View {
requireActivity().onBackPressedDispatcher.addCallback(
viewLifecycleOwner,
object : OnBackPressedCallback(true) {
Expand Down Expand Up @@ -105,14 +104,52 @@ class LanguageSettingsFragment : Fragment() {

private fun getRecyclerViewData(language: String): List<SwitchItem> {
val sharedPref = requireActivity().getSharedPreferences("app_preferences", Context.MODE_PRIVATE)
return listOf(
val list = mutableListOf<SwitchItem>()
when (language) {
"German" -> {
list.add(
SwitchItem(
isChecked = sharedPref.getBoolean("disable_accent_character_$language", false),
title = getString(R.string.app_settings_keyboard_layout_disable_accent_characters),
description = getString(R.string.app_settings_keyboard_layout_disable_accent_characters_description),
action = { disableAccentCharacter(language) },
action2 = { enableAccentCharacters(language) },
),
)
}
"Swedish" -> {
list.add(
SwitchItem(
isChecked = sharedPref.getBoolean("disable_accent_character_$language", false),
title = getString(R.string.app_settings_keyboard_layout_disable_accent_characters),
description = getString(R.string.app_settings_keyboard_layout_disable_accent_characters_description),
action = { disableAccentCharacter(language) },
action2 = { enableAccentCharacters(language) },
),
)
}
"Spanish" -> {
list.add(
SwitchItem(
isChecked = sharedPref.getBoolean("disable_accent_character_$language", false),
title = getString(R.string.app_settings_keyboard_layout_disable_accent_characters),
description = getString(R.string.app_settings_keyboard_layout_disable_accent_characters_description),
action = { disableAccentCharacter(language) },
action2 = { enableAccentCharacters(language) },
),
)
}
}
list.add(
SwitchItem(
isChecked = sharedPref.getBoolean("period_on_double_tap_$language", false),
title = getString(R.string.app_settings_keyboard_functionality_double_space_period),
description = getString(R.string.app_settings_keyboard_functionality_double_space_period_description),
action = { enablePeriodOnSpaceBarDoubleTap(language) },
action2 = { disablePeriodOnSpaceBarDoubleTap(language) },
),
)
list.add(
SwitchItem(
isChecked = sharedPref.getBoolean("autosuggest_emojis_$language", true),
title = getString(R.string.app_settings_keyboard_functionality_auto_suggest_emoji),
Expand All @@ -121,6 +158,15 @@ class LanguageSettingsFragment : Fragment() {
action2 = { disableEmojiAutosuggestions(language) },
),
)
return list
}

private fun enableAccentCharacters(language: String) {
val sharedPref = requireActivity().getSharedPreferences("app_preferences", Context.MODE_PRIVATE)
val editor = sharedPref.edit()
editor.putBoolean("disable_accent_character_$language", false)
editor.apply()
Toast.makeText(requireContext(), "$language Accent Character Enabled", Toast.LENGTH_SHORT).show()
}

private fun enablePeriodOnSpaceBarDoubleTap(language: String) {
Expand All @@ -139,6 +185,14 @@ class LanguageSettingsFragment : Fragment() {
Toast.makeText(requireContext(), "$language Period on Double Tap of Space Bar on ", Toast.LENGTH_SHORT).show()
}

private fun disableAccentCharacter(language: String) {
val sharedPref = requireActivity().getSharedPreferences("app_preferences", Context.MODE_PRIVATE)
val editor = sharedPref.edit()
editor.putBoolean("disable_accent_character_$language", true)
editor.apply()
Toast.makeText(requireContext(), "$language Accent Characters Disabled", Toast.LENGTH_SHORT).show()
}

private fun enableEmojiAutosuggestions(language: String) {
val sharedPref = requireActivity().getSharedPreferences("app_preferences", Context.MODE_PRIVATE)
val editor = sharedPref.edit()
Expand Down
4 changes: 4 additions & 0 deletions app/src/main/java/be/scri/fragments/SettingsFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import android.os.Bundle
import android.provider.Settings.ACTION_APPLICATION_DETAILS_SETTINGS
import android.provider.Settings.ACTION_APP_LOCALE_SETTINGS
import android.provider.Settings.ACTION_INPUT_METHOD_SETTINGS
import android.util.Log
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
Expand Down Expand Up @@ -154,6 +155,7 @@ class SettingsFragment : Fragment() {
"Spanish" -> R.string.app__global_spanish
"Italian" -> R.string.app__global_italian
"Portuguese" -> R.string.app__global_portuguese
"Swedish" -> R.string.app__global_swedish
else -> 0
}
list.add(
Expand Down Expand Up @@ -188,6 +190,7 @@ class SettingsFragment : Fragment() {
val result = mutableListOf<String>()

for (inputMethod in enabledInputMethods) {
Log.i("MY-TAG", inputMethod.serviceName)
when (inputMethod.serviceName) {
"be.scri.services.EnglishKeyboardIME" -> result.add("English")
"be.scri.services.GermanKeyboardIME" -> result.add("German")
Expand All @@ -196,6 +199,7 @@ class SettingsFragment : Fragment() {
"be.scri.services.FrenchKeyboardIME" -> result.add("French")
"be.scri.services.ItalianKeyboardIME" -> result.add("Italian")
"be.scri.services.PortugueseKeyboardIME" -> result.add("Portuguese")
"be.scri.services.SwedishKeyboardIME" -> result.add("Swedish")
}
}
return result
Expand Down
6 changes: 4 additions & 2 deletions app/src/main/java/be/scri/helpers/CustomAdapter.kt
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ class CustomAdapter(
position: Int,
) {
val item = mList[position] as ItemsViewModel

holder.imageView.setImageResource(item.image)
holder.textView.text =
with(item.text) {
Expand Down Expand Up @@ -128,8 +129,9 @@ class CustomAdapter(
holder: SwitchViewHolder,
position: Int,
) {
val item = mList[position] as SwitchItem
holder.switchView.isChecked = item.isChecked
val item = mList[position] as? SwitchItem

holder.switchView.isChecked = item!!.isChecked
holder.switchView.setOnCheckedChangeListener(null)
holder.textView.text = item.title
if (item.description.isNullOrEmpty()) {
Expand Down
29 changes: 24 additions & 5 deletions app/src/main/java/be/scri/services/GermanKeyboardIME.kt
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,22 @@ import be.scri.R
import be.scri.databinding.KeyboardViewCommandOptionsBinding
import be.scri.databinding.KeyboardViewKeyboardBinding
import be.scri.helpers.MyKeyboard
import be.scri.services.EnglishKeyboardIME.ScribeState
import be.scri.views.MyKeyboardView

class GermanKeyboardIME : SimpleKeyboardIME() {
override fun getKeyboardLayoutXML(): Int = R.xml.keys_letters_german
override fun getKeyboardLayoutXML(): Int =
if (getIsAccentCharacter()) {
R.xml.keys_letter_german_without_accent_character
} else {
R.xml.keys_letters_german
}

private fun getIsAccentCharacter(): Boolean {
val sharedPref = getSharedPreferences("app_preferences", Context.MODE_PRIVATE)
val isAccentCharacter = sharedPref.getBoolean("disable_accent_character_German", false)
return isAccentCharacter
}

enum class ScribeState {
IDLE,
Expand Down Expand Up @@ -62,6 +74,7 @@ class GermanKeyboardIME : SimpleKeyboardIME() {
updateEnterKeyColor(isUserDarkMode)
setupIdleView()
super.onStartInputView(editorInfo, restarting)
onInitializeInterface()
setupCommandBarTheme(binding)
}

Expand All @@ -84,6 +97,10 @@ class GermanKeyboardIME : SimpleKeyboardIME() {
Log.i("MY-TAG", "From German Keyboard IME")
keyboardView = binding.keyboardView
keyboardView!!.setKeyboard(keyboard!!)
when (currentState) {
ScribeState.IDLE -> keyboardView!!.setEnterKeyColor(null)
else -> keyboardView!!.setEnterKeyColor(R.color.dark_scribe_blue)
}
setupCommandBarTheme(binding)
keyboardView!!.setKeyboardHolder()
keyboardView!!.mOnKeyboardActionListener = this
Expand Down Expand Up @@ -138,7 +155,7 @@ class GermanKeyboardIME : SimpleKeyboardIME() {
when (code) {
MyKeyboard.KEYCODE_DELETE -> {
if (currentState == ScribeState.IDLE || currentState == ScribeState.SELECT_COMMAND) {
handleDelete(false, keyboardBinding)
handleDelete(false, binding = null)
} else {
handleDelete(true, keyboardBinding)
}
Expand All @@ -150,7 +167,7 @@ class GermanKeyboardIME : SimpleKeyboardIME() {
}
MyKeyboard.KEYCODE_ENTER -> {
if (currentState == ScribeState.IDLE || currentState == ScribeState.SELECT_COMMAND) {
handleKeycodeEnter(keyboardBinding, false)
handleKeycodeEnter(binding = null, false)
} else {
handleKeycodeEnter(keyboardBinding, true)
currentState = ScribeState.IDLE
Expand Down Expand Up @@ -254,13 +271,15 @@ class GermanKeyboardIME : SimpleKeyboardIME() {
}

private fun updateUI() {
val sharedPref = getSharedPreferences("app_preferences", Context.MODE_PRIVATE)
val currentNightMode = resources.configuration.uiMode and Configuration.UI_MODE_NIGHT_MASK
val isSystemDarkMode = currentNightMode == Configuration.UI_MODE_NIGHT_YES
val isUserDarkMode = sharedPref.getBoolean("dark_mode", isSystemDarkMode)
when (currentState) {
ScribeState.IDLE -> setupIdleView()
ScribeState.SELECT_COMMAND -> setupSelectCommandView()
else -> switchToToolBar()
}
val sharedPref = getSharedPreferences("app_preferences", Context.MODE_PRIVATE)
val isUserDarkMode = sharedPref.getBoolean("dark_mode", true)
updateEnterKeyColor(isUserDarkMode)
}
}
25 changes: 20 additions & 5 deletions app/src/main/java/be/scri/services/SpanishKeyboardIME.kt
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,18 @@ import be.scri.services.EnglishKeyboardIME.ScribeState
import be.scri.views.MyKeyboardView

class SpanishKeyboardIME : SimpleKeyboardIME() {
override fun getKeyboardLayoutXML(): Int = R.xml.keys_letters_spanish
override fun getKeyboardLayoutXML(): Int =
if (getIsAccentCharacter()) {
R.xml.keys_letter_spanish_without_accent_character
} else {
R.xml.keys_letters_spanish
}

private fun getIsAccentCharacter(): Boolean {
val sharedPref = getSharedPreferences("app_preferences", Context.MODE_PRIVATE)
val isAccentCharacter = sharedPref.getBoolean("disable_accent_character_Spanish", false)
return isAccentCharacter
}

enum class ScribeState {
IDLE,
Expand Down Expand Up @@ -141,7 +152,7 @@ class SpanishKeyboardIME : SimpleKeyboardIME() {
when (code) {
MyKeyboard.KEYCODE_DELETE -> {
if (currentState == ScribeState.IDLE || currentState == ScribeState.SELECT_COMMAND) {
handleDelete(false, keyboardBinding)
handleDelete(false, binding = null)
} else {
handleDelete(true, keyboardBinding)
}
Expand All @@ -166,7 +177,7 @@ class SpanishKeyboardIME : SimpleKeyboardIME() {
}
else -> {
if (currentState == ScribeState.IDLE || currentState == ScribeState.SELECT_COMMAND) {
handleElseCondition(code, keyboardMode, keyboardBinding)
handleElseCondition(code, keyboardMode, binding = null)
} else {
handleElseCondition(code, keyboardMode, keyboardBinding, commandBarState = true)
}
Expand Down Expand Up @@ -218,8 +229,7 @@ class SpanishKeyboardIME : SimpleKeyboardIME() {
}

private fun switchToToolBar() {
val keyboardBinding = KeyboardViewKeyboardBinding.inflate(layoutInflater)
this.keyboardBinding = keyboardBinding
val keyboardBinding = initializeKeyboardBinding()
val keyboardHolder = keyboardBinding.root
keyboardView = keyboardBinding.keyboardView
super.setupToolBarTheme(keyboardBinding)
Expand Down Expand Up @@ -268,4 +278,9 @@ class SpanishKeyboardIME : SimpleKeyboardIME() {
val isUserDarkMode = sharedPref.getBoolean("dark_mode", isSystemDarkMode)
updateEnterKeyColor(isUserDarkMode)
}

private fun initializeKeyboardBinding(): KeyboardViewKeyboardBinding {
val keyboardBinding = KeyboardViewKeyboardBinding.inflate(layoutInflater)
return keyboardBinding
}
}
19 changes: 16 additions & 3 deletions app/src/main/java/be/scri/services/SwedishKeyboardIME.kt
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,20 @@ import be.scri.services.EnglishKeyboardIME.ScribeState
import be.scri.views.MyKeyboardView

class SwedishKeyboardIME : SimpleKeyboardIME() {
override fun getKeyboardLayoutXML(): Int = R.xml.keys_letters_spanish
override fun getKeyboardLayoutXML(): Int =
if (getIsAccentCharacter()) {
Log.i("MY-TAG", getIsAccentCharacter().toString())
R.xml.keys_letter_swedish_without_accent_characters
} else {
Log.i("MY-TAG", getIsAccentCharacter().toString())
R.xml.keys_letters_swedish
}

private fun getIsAccentCharacter(): Boolean {
val sharedPref = getSharedPreferences("app_preferences", Context.MODE_PRIVATE)
val isAccentCharacter = sharedPref.getBoolean("disable_accent_character_Swedish", false)
return isAccentCharacter
}

enum class ScribeState {
IDLE,
Expand Down Expand Up @@ -92,7 +105,7 @@ class SwedishKeyboardIME : SimpleKeyboardIME() {
when (code) {
MyKeyboard.KEYCODE_DELETE -> {
if (currentState == ScribeState.IDLE || currentState == ScribeState.SELECT_COMMAND) {
handleDelete(false, keyboardBinding)
handleDelete(false, binding = null)
} else {
handleDelete(true, keyboardBinding)
}
Expand All @@ -117,7 +130,7 @@ class SwedishKeyboardIME : SimpleKeyboardIME() {
}
else -> {
if (currentState == ScribeState.IDLE || currentState == ScribeState.SELECT_COMMAND) {
handleElseCondition(code, keyboardMode, keyboardBinding)
handleElseCondition(code, keyboardMode, binding = null)
} else {
handleElseCondition(code, keyboardMode, keyboardBinding, commandBarState = true)
}
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/layout/fragment_third_party.xml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="16dp">

<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
Expand Down
Loading