allow overriding sdk level for determining which emojis are shown

might show that dreaded [x] symbol, but allows newer emojis on older android versions with upgraded fonts
This commit is contained in:
Helium314 2025-01-12 21:08:20 +01:00
parent 465fc86e61
commit 7339000df3
7 changed files with 52 additions and 4 deletions

View file

@ -48,7 +48,7 @@ open class KeyboardBuilder<KP : KeyboardParams>(protected val mContext: Context,
if (id.isEmojiKeyboard) {
mParams.mAllowRedundantPopupKeys = true
readAttributes(R.xml.kbd_emoji)
keysInRows = EmojiParser(mParams, mContext).parse()
keysInRows = EmojiParser(mParams, mContext, Settings.getInstance().current.mEmojiMaxSdk).parse()
} else {
try {
setupParams()

View file

@ -2,7 +2,6 @@
package helium314.keyboard.keyboard.internal.keyboard_parser
import android.content.Context
import android.os.Build
import helium314.keyboard.keyboard.Key
import helium314.keyboard.keyboard.Key.KeyParams
import helium314.keyboard.keyboard.KeyboardId
@ -14,7 +13,7 @@ import helium314.keyboard.latin.settings.Settings
import helium314.keyboard.latin.utils.ResourceUtils
import kotlin.math.sqrt
class EmojiParser(private val params: KeyboardParams, private val context: Context) {
class EmojiParser(private val params: KeyboardParams, private val context: Context, private val maxSdk: Int) {
fun parse(): ArrayList<ArrayList<KeyParams>> {
val emojiArrayId = when (params.mId.mElementId) {
@ -64,7 +63,7 @@ class EmojiParser(private val params: KeyboardParams, private val context: Conte
private fun getLabelAndCode(spec: String): Pair<String, Int>? {
val specAndSdk = spec.split("||")
if (specAndSdk.getOrNull(1)?.toIntOrNull()?.let { it > Build.VERSION.SDK_INT } == true) return null
if (specAndSdk.getOrNull(1)?.toIntOrNull()?.let { it > maxSdk } == true) return null
if ("," !in specAndSdk.first()) {
val code = specAndSdk.first().toIntOrNull(16) ?: return specAndSdk.first() to KeyCode.MULTIPLE_CODE_POINTS // text emojis
val label = StringUtils.newSingleCodePointString(code)

View file

@ -134,6 +134,7 @@ class AdvancedSettingsFragment : SubScreenFragment() {
removePreference("load_gesture_library")
}
setupKeyLongpressTimeoutSettings()
setupEmojiSdkSetting()
findPreference<Preference>("load_gesture_library")?.setOnPreferenceClickListener { onClickLoadLibrary() }
findPreference<Preference>("backup_restore")?.setOnPreferenceClickListener { showBackupRestoreDialog() }
@ -535,10 +536,45 @@ class AdvancedSettingsFragment : SubScreenFragment() {
})
}
private fun setupEmojiSdkSetting() {
val prefs = sharedPreferences
findPreference<SeekBarDialogPreference>(Settings.PREF_EMOJI_MAX_SDK)?.setInterface(object : ValueProxy {
override fun writeValue(value: Int, key: String) = prefs.edit().putInt(key, value).apply()
override fun writeDefaultValue(key: String) = prefs.edit().remove(key).apply()
override fun readValue(key: String) = prefs.getInt(Settings.PREF_EMOJI_MAX_SDK, Build.VERSION.SDK_INT)
override fun readDefaultValue(key: String) = Build.VERSION.SDK_INT
override fun getValueText(value: Int) = "Android " + when(value) {
21 -> "5.0"
22 -> "5.1"
23 -> "6"
24 -> "7.0"
25 -> "7.1"
26 -> "8.0"
27 -> "8.1"
28 -> "9"
29 -> "10"
30 -> "11"
31 -> "12"
32 -> "12L"
33 -> "13"
34 -> "14"
35 -> "15"
else -> "version unknown"
}
override fun feedbackValue(value: Int) {}
})
}
override fun onSharedPreferenceChanged(prefs: SharedPreferences, key: String?) {
when (key) {
Settings.PREF_SHOW_SETUP_WIZARD_ICON -> SystemBroadcastReceiver.toggleAppIcon(requireContext())
Settings.PREF_MORE_POPUP_KEYS -> KeyboardLayoutSet.onSystemLocaleChanged()
Settings.PREF_EMOJI_MAX_SDK -> KeyboardSwitcher.getInstance().forceUpdateKeyboardTheme(requireContext())
}
}

View file

@ -174,6 +174,7 @@ public final class Settings implements SharedPreferences.OnSharedPreferenceChang
public static final String PREF_SPACE_BAR_TEXT = "space_bar_text";
// Emoji
public static final String PREF_EMOJI_MAX_SDK = "emoji_max_sdk";
public static final String PREF_EMOJI_RECENT_KEYS = "emoji_recent_keys";
public static final String PREF_LAST_SHOWN_EMOJI_CATEGORY_ID = "last_shown_emoji_category_id";
public static final String PREF_LAST_SHOWN_EMOJI_CATEGORY_PAGE_ID = "last_shown_emoji_category_page_id";

View file

@ -11,6 +11,7 @@ import android.content.Context;
import android.content.SharedPreferences;
import android.content.res.Configuration;
import android.content.res.Resources;
import android.os.Build;
import android.view.inputmethod.EditorInfo;
import android.view.inputmethod.InputMethodSubtype;
@ -138,6 +139,7 @@ public class SettingsValues {
public final boolean mIncognitoModeEnabled;
public final boolean mLongPressSymbolsForNumpad;
public final boolean mHasCustomFunctionalLayout;
public final int mEmojiMaxSdk;
// User-defined colors
public final Colors mColors;
@ -268,6 +270,7 @@ public class SettingsValues {
mAlphaAfterSymbolAndSpace = prefs.getBoolean(Settings.PREF_ABC_AFTER_SYMBOL_SPACE, true);
mRemoveRedundantPopups = prefs.getBoolean(Settings.PREF_REMOVE_REDUNDANT_POPUPS, false);
mSpaceBarText = prefs.getString(Settings.PREF_SPACE_BAR_TEXT, "");
mEmojiMaxSdk = prefs.getInt(Settings.PREF_EMOJI_MAX_SDK, Build.VERSION.SDK_INT);
}
public boolean isApplicationSpecifiedCompletionsOn() {