@@ -5,6 +5,7 @@ package be.scri.services
55import DataContract
66import android.R.color.white
77import android.content.Context
8+ import android.content.Intent
89import android.database.sqlite.SQLiteException
910import android.graphics.Color
1011import android.graphics.drawable.GradientDrawable
@@ -29,11 +30,13 @@ import android.view.inputmethod.InputConnection
2930import android.widget.Button
3031import androidx.core.content.ContextCompat
3132import androidx.core.content.edit
33+ import androidx.core.graphics.ColorUtils
3234import androidx.core.graphics.toColorInt
3335import androidx.core.view.ViewCompat
3436import androidx.core.view.WindowCompat
3537import androidx.core.view.WindowInsetsCompat
3638import be.scri.R
39+ import be.scri.activities.MainActivity
3740import be.scri.databinding.InputMethodViewBinding
3841import be.scri.helpers.AnnotationTextUtils.handleColorAndTextForNounType
3942import be.scri.helpers.AnnotationTextUtils.handleTextForCaseAnnotation
@@ -289,6 +292,7 @@ abstract class GeneralKeyboardIME(
289292 keyboardMode = keyboardSymbols
290293 R .xml.keys_symbols
291294 }
295+
292296 else -> {
293297 keyboardMode = keyboardLetters
294298 getKeyboardLayoutXML()
@@ -323,6 +327,57 @@ abstract class GeneralKeyboardIME(
323327
324328 moveToIdleState()
325329
330+ val languageAlias = getLanguageAlias(language)
331+ val dbFile = applicationContext.getDatabasePath(" ${languageAlias} LanguageData.sqlite" )
332+ val hasData = dbFile.exists()
333+ val banner = binding.root.findViewById<Button >(R .id.empty_state_banner)
334+ banner.visibility =
335+ if (hasData) View .GONE else View .VISIBLE
336+ binding.commandOptionsBar.visibility =
337+ if (hasData) View .VISIBLE else View .GONE
338+ val isDarkMode = getIsDarkModeOrNot(applicationContext)
339+ val bannerColor = if (isDarkMode) R .color.dark_tutorial_button_color else R .color.light_tutorial_button_color
340+ val bannerTextColor = if (isDarkMode) R .color.dark_button_outline_color else R .color.light_text_color
341+ banner.setTextColor(ContextCompat .getColor(applicationContext, bannerTextColor))
342+ banner.post {
343+ val iconColor = ContextCompat .getColor(applicationContext, bannerTextColor)
344+ banner.compoundDrawables.forEach { drawable ->
345+ drawable?.setTint(iconColor)
346+ }
347+ }
348+ val border = GradientDrawable ()
349+ border.cornerRadius = 12f * resources.displayMetrics.density
350+ border.setColor(ContextCompat .getColor(applicationContext, bannerColor))
351+
352+ if (isDarkMode) {
353+ border.setStroke((2f * resources.displayMetrics.density).toInt(), ContextCompat .getColor(applicationContext, bannerTextColor))
354+ }
355+
356+ val rippleColor =
357+ ColorUtils .setAlphaComponent(
358+ ContextCompat .getColor(applicationContext, bannerTextColor),
359+ 51 ,
360+ )
361+
362+ val ripple =
363+ RippleDrawable (
364+ android.content.res.ColorStateList
365+ .valueOf(rippleColor),
366+ border,
367+ null ,
368+ )
369+ banner.background = ripple
370+
371+ banner.setOnClickListener {
372+ val intent =
373+ Intent (applicationContext, MainActivity ::class .java)
374+ .apply {
375+ flags = Intent .FLAG_ACTIVITY_NEW_TASK
376+ }
377+
378+ startActivity(intent)
379+ }
380+
326381 applyNavBarColor()
327382
328383 // Set initial shift state for empty text fields.
@@ -434,6 +489,7 @@ abstract class GeneralKeyboardIME(
434489 handleModeChange(keyboardMode, keyboardView, this )
435490 }
436491 }
492+
437493 KeyboardBase .KEYCODE_ENTER -> handleKeycodeEnter()
438494 KeyboardBase .KEYCODE_MODE_CHANGE -> handleModeChange(keyboardMode, keyboardView, this )
439495 else -> {
@@ -759,14 +815,17 @@ abstract class GeneralKeyboardIME(
759815 refreshUI()
760816 return
761817 }
818+
762819 null -> " "
763820 else -> if (isAllCaps) pluralResult.uppercase() else pluralResult
764821 }
765822 }
823+
766824 ScribeState .TRANSLATE -> {
767825 val translation = getTranslation(language, rawInput)
768826 if (isAllCaps) translation.uppercase() else translation
769827 }
828+
770829 else -> " "
771830 }
772831
@@ -1272,10 +1331,12 @@ abstract class GeneralKeyboardIME(
12721331 handleMultipleNounFormats(nounTypeSuggestion, " noun" )
12731332 true
12741333 }
1334+
12751335 ((nounTypeSuggestion?.size ? : 0 ) > 1 ) -> {
12761336 handleMultipleNounFormats(nounTypeSuggestion, " noun" )
12771337 true
12781338 }
1339+
12791340 handlePluralIfNeeded(isPlural) -> true
12801341 handleSingleNounSuggestion(nounTypeSuggestion) -> true
12811342 handleMultipleCases(caseAnnotationSuggestion) -> true
@@ -1543,9 +1604,11 @@ abstract class GeneralKeyboardIME(
15431604 " noun" ->
15441605 handleColorAndTextForNounType(leftType, language, applicationContext) to
15451606 handleColorAndTextForNounType(rightType, language, applicationContext)
1607+
15461608 " preposition" ->
15471609 handleTextForCaseAnnotation(leftType, language, applicationContext) to
15481610 handleTextForCaseAnnotation(rightType, language, applicationContext)
1611+
15491612 else -> null
15501613 }
15511614 }
@@ -1594,9 +1657,11 @@ abstract class GeneralKeyboardIME(
15941657 hasLinguisticSuggestions && emojiCount != 0 -> {
15951658 uiManager.updateButtonVisibility(currentState, true , autoSuggestEmojis)
15961659 }
1660+
15971661 hasLinguisticSuggestions && emojiCount == 0 -> {
15981662 setSuggestionButton(uiManager.pluralBtn!! , suggestion2)
15991663 }
1664+
16001665 else -> {
16011666 setSuggestionButton(uiManager.binding.translateBtn, suggestion2)
16021667 setSuggestionButton(uiManager.pluralBtn!! , suggestion3)
@@ -1744,6 +1809,7 @@ abstract class GeneralKeyboardIME(
17441809 keyboardView?.setKeyLabel(flattenList[1 ], " HI" , KeyboardBase .CODE_2X1_BOTTOM )
17451810 subsequentAreaRequired = false
17461811 }
1812+
17471813 DATA_CONSTANT_3 -> {
17481814 keyboardView?.setKeyLabel(flattenList[0 ], " HI" , KeyboardBase .CODE_1X3_RIGHT )
17491815 keyboardView?.setKeyLabel(flattenList[1 ], " HI" , KeyboardBase .CODE_1X3_CENTER )
@@ -1786,6 +1852,7 @@ abstract class GeneralKeyboardIME(
17861852 }
17871853 }
17881854 }
1855+
17891856 else -> {
17901857 getKeyboardLayoutXML()
17911858 }
0 commit comments