diff --git a/app/src/main/kotlin/org/fossify/keyboard/activities/SettingsActivity.kt b/app/src/main/kotlin/org/fossify/keyboard/activities/SettingsActivity.kt index 552a2366..ae2465fb 100644 --- a/app/src/main/kotlin/org/fossify/keyboard/activities/SettingsActivity.kt +++ b/app/src/main/kotlin/org/fossify/keyboard/activities/SettingsActivity.kt @@ -52,7 +52,12 @@ class SettingsActivity : SimpleActivity() { binding.apply { updateTextColors(settingsNestedScrollview) - arrayOf(settingsColorCustomizationSectionLabel, settingsGeneralSettingsLabel).forEach { + arrayOf( + settingsColorCustomizationSectionLabel, + settingsGeneralSettingsLabel, + settingsKeyboardSettingsLabel, + settingsClipboardSettingsLabel + ).forEach { it.setTextColor(getProperPrimaryColor()) } } diff --git a/app/src/main/kotlin/org/fossify/keyboard/extensions/Context.kt b/app/src/main/kotlin/org/fossify/keyboard/extensions/Context.kt index c0cbac3d..c48c4279 100644 --- a/app/src/main/kotlin/org/fossify/keyboard/extensions/Context.kt +++ b/app/src/main/kotlin/org/fossify/keyboard/extensions/Context.kt @@ -57,6 +57,26 @@ fun Context.getCurrentClip(): String? { return clipboardManager.primaryClip?.getItemAt(0)?.text?.toString() } +fun Context.getKeyboardBackgroundColor(): Int { + val color = if (config.isUsingSystemTheme) { + resources.getColor(R.color.you_keyboard_background_color, theme) + } else { + getProperBackgroundColor().darkenColor(2) + } + + // use darker background color when key borders are enabled + if (config.showKeyBorders) { + val darkerColor = color.darkenColor(2) + return if (darkerColor == Color.WHITE) { + resources.getColor(R.color.md_grey_200, theme) + } else { + darkerColor + } + } + + return color +} + fun Context.getStrokeColor(): Int { return if (config.isUsingSystemTheme) { if (isUsingSystemDarkTheme()) { diff --git a/app/src/main/kotlin/org/fossify/keyboard/helpers/Config.kt b/app/src/main/kotlin/org/fossify/keyboard/helpers/Config.kt index cbc73164..c40dfd75 100644 --- a/app/src/main/kotlin/org/fossify/keyboard/helpers/Config.kt +++ b/app/src/main/kotlin/org/fossify/keyboard/helpers/Config.kt @@ -24,7 +24,7 @@ class Config(context: Context) : BaseConfig(context) { set(enableCapitalization) = prefs.edit().putBoolean(SENTENCES_CAPITALIZATION, enableCapitalization).apply() var showKeyBorders: Boolean - get() = prefs.getBoolean(SHOW_KEY_BORDERS, false) + get() = prefs.getBoolean(SHOW_KEY_BORDERS, true) set(showKeyBorders) = prefs.edit().putBoolean(SHOW_KEY_BORDERS, showKeyBorders).apply() var lastExportedClipsFolder: String diff --git a/app/src/main/kotlin/org/fossify/keyboard/helpers/MyKeyboard.kt b/app/src/main/kotlin/org/fossify/keyboard/helpers/MyKeyboard.kt index 2fafc83b..0e85f200 100644 --- a/app/src/main/kotlin/org/fossify/keyboard/helpers/MyKeyboard.kt +++ b/app/src/main/kotlin/org/fossify/keyboard/helpers/MyKeyboard.kt @@ -300,7 +300,7 @@ class MyKeyboard { row.defaultHorizontalGap = mDefaultHorizontalGap mKeyboardHeightMultiplier = getKeyboardHeightMultiplier(context.config.keyboardHeightPercentage) - characters.forEachIndexed { index, character -> + characters.forEach { character -> val key = Key(row) if (column >= MAX_KEYS_PER_MINI_ROW) { column = 0 diff --git a/app/src/main/kotlin/org/fossify/keyboard/services/SimpleKeyboardIME.kt b/app/src/main/kotlin/org/fossify/keyboard/services/SimpleKeyboardIME.kt index 12ebe9af..a3e89328 100644 --- a/app/src/main/kotlin/org/fossify/keyboard/services/SimpleKeyboardIME.kt +++ b/app/src/main/kotlin/org/fossify/keyboard/services/SimpleKeyboardIME.kt @@ -3,6 +3,7 @@ package org.fossify.keyboard.services import android.annotation.SuppressLint import android.content.SharedPreferences import android.graphics.Bitmap +import android.graphics.Color import android.graphics.drawable.Icon import android.graphics.drawable.LayerDrawable import android.graphics.drawable.RippleDrawable @@ -29,15 +30,16 @@ import androidx.autofill.inline.common.TextViewStyle import androidx.autofill.inline.common.ViewStyle import androidx.autofill.inline.v1.InlineSuggestionUi import androidx.core.graphics.drawable.toBitmap -import org.fossify.commons.extensions.applyColorFilter -import org.fossify.commons.extensions.getProperBackgroundColor -import org.fossify.commons.extensions.getProperTextColor -import org.fossify.commons.extensions.getSharedPrefs +import androidx.core.view.WindowCompat +import androidx.core.view.WindowInsetsCompat +import androidx.core.view.updatePadding +import org.fossify.commons.extensions.* import org.fossify.commons.helpers.isNougatPlus import org.fossify.commons.helpers.isPiePlus import org.fossify.keyboard.R import org.fossify.keyboard.databinding.KeyboardViewKeyboardBinding import org.fossify.keyboard.extensions.config +import org.fossify.keyboard.extensions.getKeyboardBackgroundColor import org.fossify.keyboard.extensions.getStrokeColor import org.fossify.keyboard.extensions.safeStorageContext import org.fossify.keyboard.helpers.* @@ -81,15 +83,38 @@ class SimpleKeyboardIME : InputMethodService(), OnKeyboardActionListener, Shared override fun onCreateInputView(): View { binding = KeyboardViewKeyboardBinding.inflate(layoutInflater) + binding.keyboardHolder.setBackgroundColor(safeStorageContext.getKeyboardBackgroundColor()) keyboardView = binding.keyboardView.apply { setKeyboardHolder(binding) setKeyboard(keyboard!!) setEditorInfo(currentInputEditorInfo) + setupNavigationBarPadding() mOnKeyboardActionListener = this@SimpleKeyboardIME } + return binding.root } + private fun setupNavigationBarPadding() { + window.window?.apply { + WindowCompat.setDecorFitsSystemWindows(this, false) + decorView.setOnApplyWindowInsetsListener { _, insets -> + val windowInsets = WindowInsetsCompat.toWindowInsetsCompat(insets) + val bottomPadding = windowInsets.getInsets(WindowInsetsCompat.Type.systemBars()).bottom + binding.keyboardHolder.updatePadding(bottom = bottomPadding) + insets + } + } + } + + override fun onStartInputView(editorInfo: EditorInfo?, restarting: Boolean) { + super.onStartInputView(editorInfo, restarting) + window.window?.apply { + navigationBarColor = Color.TRANSPARENT + updateNavigationBarForegroundColor(safeStorageContext.getKeyboardBackgroundColor()) + } + } + override fun onPress(primaryCode: Int) { if (primaryCode != 0) { keyboardView?.vibrateIfNeeded() diff --git a/app/src/main/kotlin/org/fossify/keyboard/views/MyKeyboardView.kt b/app/src/main/kotlin/org/fossify/keyboard/views/MyKeyboardView.kt index b4a5a895..157f0ee7 100644 --- a/app/src/main/kotlin/org/fossify/keyboard/views/MyKeyboardView.kt +++ b/app/src/main/kotlin/org/fossify/keyboard/views/MyKeyboardView.kt @@ -87,7 +87,9 @@ class MyKeyboardView @JvmOverloads constructor(context: Context, attrs: Attribut private var mTextColor = 0 private var mBackgroundColor = 0 + private var mKeyboardBackgroundColor = 0 private var mPrimaryColor = 0 + private var mStrokeColor = 0 private var mKeyColor = 0 private var mKeyColorPressed = 0 @@ -144,6 +146,7 @@ class MyKeyboardView @JvmOverloads constructor(context: Context, attrs: Attribut private var mKeyBackground: Drawable? = null private var mShowKeyBorders: Boolean = false private var mUsingSystemTheme: Boolean = true + private var mVoiceInputMethod: String = "" private var mToolbarHolder: View? = null private var mClipboardManagerHolder: View? = null @@ -209,7 +212,9 @@ class MyKeyboardView @JvmOverloads constructor(context: Context, attrs: Attribut with(context.safeStorageContext) { mTextColor = getProperTextColor() mBackgroundColor = getProperBackgroundColor() + mKeyboardBackgroundColor = getKeyboardBackgroundColor() mPrimaryColor = getProperPrimaryColor() + mStrokeColor = getStrokeColor() } mPreviewPopup = PopupWindow(context) @@ -381,46 +386,43 @@ class MyKeyboardView @JvmOverloads constructor(context: Context, attrs: Attribut with(context.safeStorageContext) { mTextColor = getProperTextColor() mBackgroundColor = getProperBackgroundColor() + mKeyboardBackgroundColor = getKeyboardBackgroundColor() mPrimaryColor = getProperPrimaryColor() + mStrokeColor = getStrokeColor() mShowKeyBorders = config.showKeyBorders mUsingSystemTheme = config.isUsingSystemTheme + mVoiceInputMethod = config.voiceInputMethod } val isMainKeyboard = changedView == null || changedView != keyboardPopupBinding?.miniKeyboardView + mKeyColor = getKeyColor() + mKeyColorPressed = mKeyColor.adjustAlpha(0.2f) mKeyBackground = if (mShowKeyBorders && isMainKeyboard) { resources.getDrawable(R.drawable.keyboard_key_selector_outlined, context.theme) } else { resources.getDrawable(R.drawable.keyboard_key_selector, context.theme) } - mKeyColor = getKeyColor() - mKeyColorPressed = mKeyColor.adjustAlpha(0.2f) - - val strokeColor = context.getStrokeColor() - - val toolbarColor = getToolbarColor() - val darkerColor = getKeyboardBackgroundColor() - val miniKeyboardBackgroundColor = getToolbarColor(4) if (!isMainKeyboard) { val previewBackground = background as LayerDrawable - previewBackground.findDrawableByLayerId(R.id.button_background_shape).applyColorFilter(miniKeyboardBackgroundColor) - previewBackground.findDrawableByLayerId(R.id.button_background_stroke).applyColorFilter(strokeColor) + previewBackground.findDrawableByLayerId(R.id.button_background_shape).applyColorFilter(mKeyboardBackgroundColor) + previewBackground.findDrawableByLayerId(R.id.button_background_stroke).applyColorFilter(mStrokeColor) background = previewBackground } else { - background.applyColorFilter(darkerColor) + background.applyColorFilter(mKeyboardBackgroundColor) } val rippleBg = resources.getDrawable(R.drawable.clipboard_background, context.theme) as RippleDrawable val layerDrawable = rippleBg.findDrawableByLayerId(R.id.clipboard_background_holder) as LayerDrawable - layerDrawable.findDrawableByLayerId(R.id.clipboard_background_stroke).applyColorFilter(strokeColor) + layerDrawable.findDrawableByLayerId(R.id.clipboard_background_stroke).applyColorFilter(mStrokeColor) layerDrawable.findDrawableByLayerId(R.id.clipboard_background_shape).applyColorFilter(mBackgroundColor) val wasDarkened = mBackgroundColor != mBackgroundColor.darkenColor() keyboardViewBinding?.apply { topKeyboardDivider.beGoneIf(wasDarkened) - topKeyboardDivider.background = ColorDrawable(strokeColor) - mToolbarHolder?.background = ColorDrawable(toolbarColor) + topKeyboardDivider.background = ColorDrawable(mStrokeColor) + mToolbarHolder?.background = ColorDrawable(mKeyboardBackgroundColor) clipboardValue.apply { background = rippleBg @@ -432,13 +434,13 @@ class MyKeyboardView @JvmOverloads constructor(context: Context, attrs: Attribut pinnedClipboardItems.applyColorFilter(mTextColor) clipboardClear.applyColorFilter(mTextColor) voiceInputButton.applyColorFilter(mTextColor) - voiceInputButton.beGoneIf(context.config.voiceInputMethod.isEmpty()) + voiceInputButton.beGoneIf(mVoiceInputMethod.isEmpty()) mToolbarHolder?.beInvisibleIf(context.isDeviceLocked) topClipboardDivider.beGoneIf(wasDarkened) - topClipboardDivider.background = ColorDrawable(strokeColor) - clipboardManagerHolder.background = ColorDrawable(toolbarColor) + topClipboardDivider.background = ColorDrawable(mStrokeColor) + clipboardManagerHolder.background = ColorDrawable(mKeyboardBackgroundColor) clipboardManagerClose.applyColorFilter(mTextColor) clipboardManagerManage.applyColorFilter(mTextColor) @@ -448,7 +450,7 @@ class MyKeyboardView @JvmOverloads constructor(context: Context, attrs: Attribut clipboardContentPlaceholder2.setTextColor(mTextColor) } - setupEmojiPalette(toolbarColor = toolbarColor, backgroundColor = mBackgroundColor, textColor = mTextColor) + setupEmojiPalette(toolbarColor = mKeyboardBackgroundColor, backgroundColor = mBackgroundColor, textColor = mTextColor) if (context.config.keyboardLanguage == LANGUAGE_VIETNAMESE_TELEX) { setupLanguageTelex() } else { @@ -587,7 +589,6 @@ class MyKeyboardView @JvmOverloads constructor(context: Context, attrs: Attribut val key = keys[i] val code = key.code - // TODO: Space key background on a KEYBOARD_PHONE should not be applied setupKeyBackground(key, code, canvas) // Switch the character to uppercase if shift is pressed @@ -616,7 +617,16 @@ class MyKeyboardView @JvmOverloads constructor(context: Context, attrs: Attribut } if (key.topSmallNumber.isNotEmpty() && !(context.config.showNumbersRow && Regex("\\d").matches(key.topSmallNumber))) { - canvas.drawText(key.topSmallNumber, key.width - mTopSmallNumberMarginWidth, mTopSmallNumberMarginHeight, smallLetterPaint) + val bounds = Rect().also { + smallLetterPaint.getTextBounds(key.topSmallNumber, 0, key.topSmallNumber.length, it) + } + + canvas.drawText( + key.topSmallNumber, + key.width - bounds.width() / 2f - mTopSmallNumberMarginWidth, + key.y + mTopSmallNumberSize + mTopSmallNumberMarginHeight, + smallLetterPaint + ) } // Turn off drop shadow @@ -633,19 +643,19 @@ class MyKeyboardView @JvmOverloads constructor(context: Context, attrs: Attribut if (code == KEYCODE_ENTER) { key.icon!!.applyColorFilter(mPrimaryColor.getContrastColor()) - key.secondaryIcon?.applyColorFilter(mPrimaryColor.getContrastColor()) + key.secondaryIcon?.applyColorFilter(mPrimaryColor.getContrastColor().adjustAlpha(0.6f)) } else if (code == KEYCODE_DELETE || code == KEYCODE_SHIFT || code == KEYCODE_EMOJI) { key.icon!!.applyColorFilter(mTextColor) - key.secondaryIcon?.applyColorFilter(mTextColor) + key.secondaryIcon?.applyColorFilter(mTextColor.adjustAlpha(0.6f)) } + val keyIcon = key.icon!! val secondaryIcon = key.secondaryIcon - if (secondaryIcon != null) { val keyIconWidth = (keyIcon.intrinsicWidth * 0.9f).toInt() val keyIconHeight = (keyIcon.intrinsicHeight * 0.9f).toInt() - val secondaryIconWidth = (secondaryIcon.intrinsicWidth * .6f).toInt() - val secondaryIconHeight = (secondaryIcon.intrinsicHeight * .6f).toInt() + val secondaryIconWidth = (secondaryIcon.intrinsicWidth * 0.5f).toInt() + val secondaryIconHeight = (secondaryIcon.intrinsicHeight * 0.5f).toInt() val centerX = key.width / 2 val centerY = key.height / 2 @@ -733,19 +743,16 @@ class MyKeyboardView @JvmOverloads constructor(context: Context, attrs: Attribut } private fun getSpaceKeyBackground(): Drawable? { - val drawableId = if (mUsingSystemTheme) { - if (mShowKeyBorders) { - R.drawable.keyboard_space_background_material_outlined - } else { - R.drawable.keyboard_space_background_material - } - } else { - if (mShowKeyBorders) { - R.drawable.keyboard_key_selector_outlined - } else { - R.drawable.keyboard_space_background - } + if (mShowKeyBorders) { + return mKeyBackground } + + val drawableId = if (mUsingSystemTheme) { + R.drawable.keyboard_space_background_material + } else { + R.drawable.keyboard_space_background + } + return resources.getDrawable(drawableId, context.theme) } @@ -897,11 +904,9 @@ class MyKeyboardView @JvmOverloads constructor(context: Context, attrs: Attribut } } - val previewBackgroundColor = getToolbarColor(4) - val previewBackground = mPreviewText!!.background as LayerDrawable - previewBackground.findDrawableByLayerId(R.id.button_background_shape).applyColorFilter(previewBackgroundColor) - previewBackground.findDrawableByLayerId(R.id.button_background_stroke).applyColorFilter(context.getStrokeColor()) + previewBackground.findDrawableByLayerId(R.id.button_background_shape).applyColorFilter(mKeyboardBackgroundColor) + previewBackground.findDrawableByLayerId(R.id.button_background_stroke).applyColorFilter(mStrokeColor) mPreviewText!!.background = previewBackground mPreviewText!!.setTextColor(mTextColor) @@ -1462,7 +1467,7 @@ class MyKeyboardView @JvmOverloads constructor(context: Context, attrs: Attribut emojiPaletteClose.applyColorFilter(textColor) emojiPaletteLabel.setTextColor(textColor) - emojiPaletteBottomBar.background = ColorDrawable(backgroundColor) + emojiPaletteBottomBar.background = ColorDrawable(toolbarColor) emojiPaletteModeChange.apply { setTextColor(textColor) setOnClickListener { @@ -1505,6 +1510,7 @@ class MyKeyboardView @JvmOverloads constructor(context: Context, attrs: Attribut fun openEmojiPalette() { keyboardViewBinding!!.emojiPaletteHolder.beVisible() + keyboardViewBinding!!.suggestionsHolder.beGone() setupEmojis() } @@ -1512,6 +1518,7 @@ class MyKeyboardView @JvmOverloads constructor(context: Context, attrs: Attribut keyboardViewBinding?.apply { emojiPaletteHolder.beGone() emojisList.scrollToPosition(0) + suggestionsHolder.beVisible() } } @@ -1649,39 +1656,8 @@ class MyKeyboardView @JvmOverloads constructor(context: Context, attrs: Attribut } } - private fun maybeDarkenColor(color: Int, factor: Int): Int { - // use darker background color when key borders are enabled - if (context.config.showKeyBorders) { - val darkerColor = color.darkenColor(factor) - return if (darkerColor == Color.WHITE) { - resources.getColor(R.color.md_grey_200, context.theme) - } else { - darkerColor - } - } - return color - } - - private fun getToolbarColor(factor: Int = 8): Int { - val color = if (context.config.isUsingSystemTheme) { - resources.getColor(R.color.you_keyboard_toolbar_color, context.theme) - } else { - mBackgroundColor.darkenColor(factor) - } - return maybeDarkenColor(color, 2) - } - - private fun getKeyboardBackgroundColor(): Int { - val color = if (context.config.isUsingSystemTheme) { - resources.getColor(R.color.you_keyboard_background_color, context.theme) - } else { - mBackgroundColor.darkenColor(2) - } - return maybeDarkenColor(color, 6) - } - private fun getKeyColor(): Int { - val backgroundColor = getKeyboardBackgroundColor() + val backgroundColor = context.getKeyboardBackgroundColor() val lighterColor = backgroundColor.lightenColor() val keyColor = if (context.config.isUsingSystemTheme) { lighterColor diff --git a/app/src/main/res/drawable/keyboard_space_background_material_outlined.xml b/app/src/main/res/drawable/keyboard_space_background_material_outlined.xml deleted file mode 100644 index fcb54960..00000000 --- a/app/src/main/res/drawable/keyboard_space_background_material_outlined.xml +++ /dev/null @@ -1,23 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - diff --git a/app/src/main/res/layout/activity_settings.xml b/app/src/main/res/layout/activity_settings.xml index 25ff292b..3997d55e 100644 --- a/app/src/main/res/layout/activity_settings.xml +++ b/app/src/main/res/layout/activity_settings.xml @@ -117,20 +117,54 @@ + + + + + + + + + android:text="@string/manage_keyboard_languages" /> + + + + - - - - - - + + + + + + + + + + + + + + android:text="@string/manage_clipboard_items" /> - - - + android:text="@string/show_clipboard_content" /> - - - - - - - diff --git a/app/src/main/res/layout/keyboard_view_keyboard.xml b/app/src/main/res/layout/keyboard_view_keyboard.xml index 2c98b48f..1897354b 100644 --- a/app/src/main/res/layout/keyboard_view_keyboard.xml +++ b/app/src/main/res/layout/keyboard_view_keyboard.xml @@ -9,7 +9,6 @@ android:id="@+id/toolbar_holder" android:layout_width="match_parent" android:layout_height="@dimen/toolbar_height" - android:layout_above="@+id/keyboard_view" app:layout_constraintBottom_toTopOf="@+id/keyboard_view" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toStartOf="parent"> @@ -70,7 +69,6 @@ - - + app:showAsAction="ifRoom" /> + diff --git a/app/src/main/res/values-night-v31/colors.xml b/app/src/main/res/values-night-v31/colors.xml index 79cc1e3c..7ac423b4 100644 --- a/app/src/main/res/values-night-v31/colors.xml +++ b/app/src/main/res/values-night-v31/colors.xml @@ -1,5 +1,4 @@ - @android:color/system_neutral1_900 - #151515 + @android:color/system_neutral2_900 diff --git a/app/src/main/res/values-v31/colors.xml b/app/src/main/res/values-v31/colors.xml index 25d6491a..8517cc1d 100644 --- a/app/src/main/res/values-v31/colors.xml +++ b/app/src/main/res/values-v31/colors.xml @@ -1,5 +1,4 @@ - @android:color/system_neutral1_10 - @android:color/system_neutral1_50 + @color/m3_ref_palette_dynamic_neutral_variant96 diff --git a/app/src/main/res/values/dimens.xml b/app/src/main/res/values/dimens.xml index b67257d1..98999f3b 100644 --- a/app/src/main/res/values/dimens.xml +++ b/app/src/main/res/values/dimens.xml @@ -1,14 +1,14 @@ 60dp - 12dp - 18dp + 5dp + 5dp 46dp 32dp 40dp 60dp -10dp 28dp - 46dp + 42dp 24dp 4dp 42dp @@ -17,6 +17,6 @@ 22sp 26sp 16sp - 28sp + 30sp 14sp diff --git a/app/src/main/res/xml/keys_letters_hebrew.xml b/app/src/main/res/xml/keys_letters_hebrew.xml index 69f3b5d7..8e2ecf49 100644 --- a/app/src/main/res/xml/keys_letters_hebrew.xml +++ b/app/src/main/res/xml/keys_letters_hebrew.xml @@ -143,7 +143,7 @@