use context.prefs() instead of the long DeviceProtected...

This commit is contained in:
Helium314 2025-02-09 13:52:59 +01:00
parent deb9dda7e7
commit 125a483591
29 changed files with 112 additions and 113 deletions

View file

@ -44,7 +44,7 @@ import helium314.keyboard.latin.settings.SettingsValues;
import helium314.keyboard.latin.suggestions.SuggestionStripView;
import helium314.keyboard.latin.utils.AdditionalSubtypeUtils;
import helium314.keyboard.latin.utils.CapsModeUtils;
import helium314.keyboard.latin.utils.DeviceProtectedUtils;
import helium314.keyboard.latin.utils.KtxKt;
import helium314.keyboard.latin.utils.LanguageOnSpacebarUtils;
import helium314.keyboard.latin.utils.Log;
import helium314.keyboard.latin.utils.RecapitalizeStatus;
@ -651,7 +651,7 @@ public final class KeyboardSwitcher implements KeyboardState.SwitchActions {
mKeyboardView.closing();
}
PointerTracker.clearOldViewData();
final SharedPreferences prefs = DeviceProtectedUtils.getSharedPreferences(displayContext);
final SharedPreferences prefs = KtxKt.prefs(displayContext);
if (mSuggestionStripView != null)
prefs.unregisterOnSharedPreferenceChangeListener(mSuggestionStripView);
if (mClipboardHistoryView != null)

View file

@ -18,7 +18,7 @@ import helium314.keyboard.latin.common.DefaultColors
import helium314.keyboard.latin.common.DynamicColors
import helium314.keyboard.latin.common.readAllColorsMap
import helium314.keyboard.latin.settings.Settings
import helium314.keyboard.latin.utils.DeviceProtectedUtils
import helium314.keyboard.latin.utils.prefs
class KeyboardTheme // Note: The themeId should be aligned with "themeId" attribute of Keyboard style in values/themes-<style>.xml.
private constructor(val themeId: Int, @JvmField val mStyleId: Int) {
@ -84,7 +84,7 @@ private constructor(val themeId: Int, @JvmField val mStyleId: Int) {
@JvmStatic
fun getKeyboardTheme(context: Context): KeyboardTheme {
val prefs = DeviceProtectedUtils.getSharedPreferences(context)
val prefs = context.prefs()
val style = prefs.getString(Settings.PREF_THEME_STYLE, STYLE_MATERIAL)
val borders = prefs.getBoolean(Settings.PREF_THEME_KEY_BORDERS, false)
val matchingId = when (style) {

View file

@ -53,7 +53,7 @@ import helium314.keyboard.latin.common.CoordinateUtils;
import helium314.keyboard.latin.define.DebugFlags;
import helium314.keyboard.latin.settings.DebugSettings;
import helium314.keyboard.latin.settings.Settings;
import helium314.keyboard.latin.utils.DeviceProtectedUtils;
import helium314.keyboard.latin.utils.KtxKt;
import helium314.keyboard.latin.utils.LanguageOnSpacebarUtils;
import helium314.keyboard.latin.utils.Log;
import helium314.keyboard.latin.utils.TypefaceUtils;
@ -151,7 +151,7 @@ public final class MainKeyboardView extends KeyboardView implements DrawingProxy
PointerTracker.init(mainKeyboardViewAttr, mTimerHandler, this /* DrawingProxy */);
final SharedPreferences prefs = DeviceProtectedUtils.getSharedPreferences(context);
final SharedPreferences prefs = KtxKt.prefs(context);
final boolean forceNonDistinctMultitouch = prefs.getBoolean(
DebugSettings.PREF_FORCE_NON_DISTINCT_MULTITOUCH, false);
final boolean hasDistinctMultitouch = context.getPackageManager()

View file

@ -28,13 +28,13 @@ import helium314.keyboard.latin.R
import helium314.keyboard.latin.common.ColorType
import helium314.keyboard.latin.common.Constants
import helium314.keyboard.latin.settings.Settings
import helium314.keyboard.latin.utils.DeviceProtectedUtils
import helium314.keyboard.latin.utils.ResourceUtils
import helium314.keyboard.latin.utils.ToolbarKey
import helium314.keyboard.latin.utils.createToolbarKey
import helium314.keyboard.latin.utils.getCodeForToolbarKey
import helium314.keyboard.latin.utils.getCodeForToolbarKeyLongClick
import helium314.keyboard.latin.utils.getEnabledClipboardToolbarKeys
import helium314.keyboard.latin.utils.prefs
import helium314.keyboard.latin.utils.setToolbarButtonsActivatedStateOnPrefChange
@SuppressLint("CustomViewStyleable")
@ -68,7 +68,7 @@ class ClipboardHistoryView @JvmOverloads constructor(
keyBackgroundId = keyboardViewAttr.getResourceId(R.styleable.KeyboardView_keyBackground, 0)
keyboardViewAttr.recycle()
val keyboardAttr = context.obtainStyledAttributes(attrs, R.styleable.Keyboard, defStyle, R.style.SuggestionStripView)
getEnabledClipboardToolbarKeys(DeviceProtectedUtils.getSharedPreferences(context))
getEnabledClipboardToolbarKeys(context.prefs())
.forEach { toolbarKeys.add(createToolbarKey(context, KeyboardIconsSet.instance, it)) }
keyboardAttr.recycle()
}

View file

@ -13,7 +13,7 @@ import android.content.res.TypedArray;
import android.graphics.Paint;
import android.graphics.Rect;
import helium314.keyboard.latin.utils.DeviceProtectedUtils;
import helium314.keyboard.latin.utils.KtxKt;
import helium314.keyboard.latin.utils.Log;
import androidx.core.graphics.PaintCompat;
@ -129,7 +129,7 @@ final class EmojiCategory {
private int mCurrentCategoryPageId = 0;
public EmojiCategory(final Context ctx, final KeyboardLayoutSet layoutSet, final TypedArray emojiPaletteViewAttr) {
mPrefs = DeviceProtectedUtils.getSharedPreferences(ctx);
mPrefs = KtxKt.prefs(ctx);
mRes = ctx.getResources();
mContext = ctx;
mMaxRecentsKeyCount = mRes.getInteger(R.integer.config_emoji_keyboard_max_recents_key_count);

View file

@ -8,9 +8,9 @@ import helium314.keyboard.keyboard.KeyboardTheme
import helium314.keyboard.latin.R
import helium314.keyboard.latin.customIconIds
import helium314.keyboard.latin.settings.Settings
import helium314.keyboard.latin.utils.DeviceProtectedUtils
import helium314.keyboard.latin.utils.Log
import helium314.keyboard.latin.utils.ToolbarKey
import helium314.keyboard.latin.utils.prefs
import java.util.Locale
class KeyboardIconsSet private constructor() {
@ -19,7 +19,7 @@ class KeyboardIconsSet private constructor() {
private val iconsByName = HashMap<String, Drawable>(80)
fun loadIcons(context: Context) {
val prefs = DeviceProtectedUtils.getSharedPreferences(context)
val prefs = context.prefs()
val iconStyle = prefs.getString(Settings.PREF_ICON_STYLE, KeyboardTheme.STYLE_MATERIAL)
val defaultIds = when (iconStyle) {
KeyboardTheme.STYLE_HOLO -> keyboardIconsHolo
@ -281,8 +281,7 @@ class KeyboardIconsSet private constructor() {
fun getAllIcons(context: Context): Map<String, List<Int>> {
// currently active style first
val prefs = DeviceProtectedUtils.getSharedPreferences(context)
val iconStyle = prefs.getString(Settings.PREF_ICON_STYLE, KeyboardTheme.STYLE_MATERIAL)
val iconStyle = context.prefs().getString(Settings.PREF_ICON_STYLE, KeyboardTheme.STYLE_MATERIAL)
return keyboardIconsMaterial.entries.associate { (name, id) ->
name to when (iconStyle) {
KeyboardTheme.STYLE_HOLO -> listOfNotNull(keyboardIconsHolo[name], keyboardIconsRounded[name], id)

View file

@ -9,14 +9,13 @@ import helium314.keyboard.latin.common.LocaleUtils.constructLocale
import helium314.keyboard.latin.settings.Settings
import helium314.keyboard.latin.settings.USER_DICTIONARY_SUFFIX
import helium314.keyboard.latin.utils.CUSTOM_LAYOUT_PREFIX
import helium314.keyboard.latin.utils.DeviceProtectedUtils
import helium314.keyboard.latin.utils.DictionaryInfoUtils
import helium314.keyboard.latin.utils.Log
import helium314.keyboard.latin.utils.ToolbarKey
import helium314.keyboard.latin.utils.defaultPinnedToolbarPref
import helium314.keyboard.latin.utils.getCustomLayoutFile
import helium314.keyboard.latin.utils.getCustomLayoutFiles
import helium314.keyboard.latin.utils.onCustomLayoutFileListChanged
import helium314.keyboard.latin.utils.prefs
import helium314.keyboard.latin.utils.upgradeToolbarPrefs
import java.io.File
@ -39,7 +38,7 @@ class App : Application() {
}
fun checkVersionUpgrade(context: Context) {
val prefs = DeviceProtectedUtils.getSharedPreferences(context)
val prefs = context.prefs()
val oldVersion = prefs.getInt(Settings.PREF_VERSION_CODE, 0)
if (oldVersion == BuildConfig.VERSION_CODE)
return
@ -171,7 +170,7 @@ private fun upgradesWhenComingFromOldAppName(context: Context) {
}
} catch (_: Exception) {}
// upgrade prefs
val prefs = DeviceProtectedUtils.getSharedPreferences(context)
val prefs = context.prefs()
if (prefs.all.containsKey("theme_variant")) {
prefs.edit().putString(Settings.PREF_THEME_COLORS, prefs.getString("theme_variant", "")).apply()
prefs.edit().remove("theme_variant").apply()

View file

@ -11,7 +11,6 @@ import android.view.View
import android.view.ViewGroup
import android.view.inputmethod.EditorInfo
import androidx.core.view.isGone
import kotlinx.serialization.encodeToString
import kotlinx.serialization.json.Json
import helium314.keyboard.compat.ClipboardManagerCompat
import helium314.keyboard.keyboard.internal.keyboard_parser.floris.KeyCode
@ -19,9 +18,9 @@ import helium314.keyboard.latin.common.ColorType
import helium314.keyboard.latin.common.isValidNumber
import helium314.keyboard.latin.databinding.ClipboardSuggestionBinding
import helium314.keyboard.latin.settings.Settings
import helium314.keyboard.latin.utils.DeviceProtectedUtils
import helium314.keyboard.latin.utils.InputTypeUtils
import helium314.keyboard.latin.utils.ToolbarKey
import helium314.keyboard.latin.utils.prefs
import kotlin.collections.ArrayList
class ClipboardHistoryManager(
@ -37,7 +36,7 @@ class ClipboardHistoryManager(
clipboardManager.addPrimaryClipChangedListener(this)
if (historyEntries.isEmpty())
loadPinnedClips()
if (Settings.readClipboardHistoryEnabled(DeviceProtectedUtils.getSharedPreferences(latinIME)))
if (Settings.readClipboardHistoryEnabled(latinIME.prefs()))
fetchPrimaryClip()
}

View file

@ -13,7 +13,7 @@ import android.text.TextUtils;
import helium314.keyboard.latin.common.StringUtilsKt;
import helium314.keyboard.latin.settings.SettingsValues;
import helium314.keyboard.latin.utils.DeviceProtectedUtils;
import helium314.keyboard.latin.utils.KtxKt;
import helium314.keyboard.latin.utils.Log;
import android.util.LruCache;
@ -339,7 +339,7 @@ public class DictionaryFacilitatorImpl implements DictionaryFacilitator {
Log.i(TAG, "resetDictionaries, force reloading main dictionary: " + forceReloadMainDictionary);
final List<Locale> allLocales = new ArrayList<>() {{
add(newLocale);
addAll(Settings.getSecondaryLocales(DeviceProtectedUtils.getSharedPreferences(context), newLocale));
addAll(Settings.getSecondaryLocales(KtxKt.prefs(context), newLocale));
}};
// Do not use contacts dictionary if we do not have permissions to read contacts.

View file

@ -18,7 +18,7 @@ import helium314.keyboard.keyboard.internal.keyboard_parser.floris.KeyCode
import helium314.keyboard.latin.common.ColorType
import helium314.keyboard.latin.common.Constants
import helium314.keyboard.latin.settings.Settings
import helium314.keyboard.latin.utils.DeviceProtectedUtils
import helium314.keyboard.latin.utils.prefs
import kotlin.math.abs
class KeyboardWrapperView @JvmOverloads constructor(
@ -78,8 +78,7 @@ class KeyboardWrapperView @JvmOverloads constructor(
val changePercent = 2 * sign * (x - motionEvent.rawX) / context.resources.displayMetrics.density
if (abs(changePercent) < 1) return@setOnTouchListener true
x = motionEvent.rawX
val prefs = DeviceProtectedUtils.getSharedPreferences(context)
val oldScale = Settings.readOneHandedModeScale(prefs, Settings.getInstance().current.mDisplayOrientation == Configuration.ORIENTATION_PORTRAIT)
val oldScale = Settings.readOneHandedModeScale(context.prefs(), Settings.getInstance().current.mDisplayOrientation == Configuration.ORIENTATION_PORTRAIT)
val newScale = (oldScale + changePercent / 100f).coerceAtMost(2.5f).coerceAtLeast(0.5f)
if (newScale == oldScale) return@setOnTouchListener true
Settings.getInstance().writeOneHandedModeScale(newScale)

View file

@ -18,7 +18,7 @@ import android.view.inputmethod.InputMethodSubtype;
import helium314.keyboard.compat.ConfigurationCompatKt;
import helium314.keyboard.latin.common.LocaleUtils;
import helium314.keyboard.latin.settings.Settings;
import helium314.keyboard.latin.utils.DeviceProtectedUtils;
import helium314.keyboard.latin.utils.KtxKt;
import helium314.keyboard.latin.utils.LanguageOnSpacebarUtils;
import helium314.keyboard.latin.utils.Log;
import helium314.keyboard.latin.utils.ScriptUtils;
@ -171,7 +171,7 @@ public class RichInputMethodManager {
if (imi == getInputMethodOfThisIme()) {
// allowsImplicitlySelectedSubtypes means system should choose if nothing is enabled,
// use it to fall back to system locales or en_US to avoid returning an empty list
result = SubtypeSettingsKt.getEnabledSubtypes(DeviceProtectedUtils.getSharedPreferences(sInstance.mContext), allowsImplicitlySelectedSubtypes);
result = SubtypeSettingsKt.getEnabledSubtypes(KtxKt.prefs(sInstance.mContext), allowsImplicitlySelectedSubtypes);
} else {
result = mImm.getEnabledInputMethodSubtypeList(imi, allowsImplicitlySelectedSubtypes);
}
@ -319,7 +319,7 @@ public class RichInputMethodManager {
// search for first secondary language & script match
final int count = subtypes.size();
final SharedPreferences prefs = DeviceProtectedUtils.getSharedPreferences(mContext);
final SharedPreferences prefs = KtxKt.prefs(mContext);
final String language = locale.getLanguage();
final String script = ScriptUtils.script(locale);
for (int i = 0; i < count; ++i) {
@ -350,13 +350,13 @@ public class RichInputMethodManager {
public void refreshSubtypeCaches() {
mInputMethodInfoCache.clear();
SharedPreferences prefs = DeviceProtectedUtils.getSharedPreferences(mContext);
SharedPreferences prefs = KtxKt.prefs(mContext);
updateCurrentSubtype(SubtypeSettingsKt.getSelectedSubtype(prefs));
updateShortcutIme();
}
private void updateCurrentSubtype(final InputMethodSubtype subtype) {
SubtypeSettingsKt.setSelectedSubtype(DeviceProtectedUtils.getSharedPreferences(mContext), subtype);
SubtypeSettingsKt.setSelectedSubtype(KtxKt.prefs(mContext), subtype);
mCurrentRichInputMethodSubtype = RichInputMethodSubtype.getRichInputMethodSubtype(subtype);
}

View file

@ -14,36 +14,37 @@ import android.content.SharedPreferences;
import android.content.pm.PackageManager;
import android.os.Build;
import android.os.Process;
import helium314.keyboard.latin.utils.KtxKt;
import helium314.keyboard.latin.utils.Log;
import android.view.inputmethod.InputMethodManager;
import helium314.keyboard.keyboard.KeyboardLayoutSet;
import helium314.keyboard.latin.settings.Settings;
import helium314.keyboard.latin.setup.SetupActivity;
import helium314.keyboard.latin.utils.DeviceProtectedUtils;
import helium314.keyboard.latin.utils.UncachedInputMethodManagerUtils;
/**
* This class detects the {@link Intent#ACTION_MY_PACKAGE_REPLACED} broadcast intent when this IME
* package has been replaced by a newer version of the same package. This class also detects
* {@link Intent#ACTION_BOOT_COMPLETED} and {@link Intent#ACTION_USER_INITIALIZE} broadcast intent.
*
* <p>
* If this IME has already been installed in the system image and a new version of this IME has
* been installed, {@link Intent#ACTION_MY_PACKAGE_REPLACED} is received by this receiver and it
* will hide the setup wizard's icon.
*
* <p>
* If this IME has already been installed in the data partition and a new version of this IME has
* been installed, {@link Intent#ACTION_MY_PACKAGE_REPLACED} is received by this receiver but it
* will not hide the setup wizard's icon, and the icon will appear on the launcher.
*
* <p>
* If this IME hasn't been installed yet and has been newly installed, no
* {@link Intent#ACTION_MY_PACKAGE_REPLACED} will be sent and the setup wizard's icon will appear
* on the launcher.
*
* <p>
* When the device has been booted, {@link Intent#ACTION_BOOT_COMPLETED} is received by this
* receiver and it checks whether the setup wizard's icon should be appeared or not on the launcher
* depending on which partition this IME is installed.
*
* <p>
* When the system locale has been changed, {@link Intent#ACTION_LOCALE_CHANGED} is received by
* this receiver and the {@link KeyboardLayoutSet}'s cache is cleared.
*/
@ -86,7 +87,7 @@ public final class SystemBroadcastReceiver extends BroadcastReceiver {
public static void toggleAppIcon(final Context context) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q)
return; // can't change visibility in Android 10 and above
final SharedPreferences prefs = DeviceProtectedUtils.getSharedPreferences(context);
final SharedPreferences prefs = KtxKt.prefs(context);
context.getPackageManager().setComponentEnabledSetting(
new ComponentName(context, SetupActivity.class),
Settings.readShowSetupWizardIcon(prefs, context)

View file

@ -10,8 +10,8 @@ import android.content.Context
import android.os.Build
import helium314.keyboard.latin.BuildConfig
import helium314.keyboard.latin.settings.DebugSettings
import helium314.keyboard.latin.utils.DeviceProtectedUtils
import helium314.keyboard.latin.utils.Log
import helium314.keyboard.latin.utils.prefs
import java.io.File
import java.io.IOException
import java.io.PrintWriter
@ -24,8 +24,7 @@ object DebugFlags {
@JvmStatic
fun init(context: Context) {
val prefs = DeviceProtectedUtils.getSharedPreferences(context)
DEBUG_ENABLED = prefs.getBoolean(DebugSettings.PREF_DEBUG_MODE, false)
DEBUG_ENABLED = context.prefs().getBoolean(DebugSettings.PREF_DEBUG_MODE, false)
if (DEBUG_ENABLED || BuildConfig.DEBUG)
CrashReportExceptionHandler(context.applicationContext).install()
}

View file

@ -43,6 +43,7 @@ import helium314.keyboard.latin.utils.DeviceProtectedUtils
import helium314.keyboard.latin.utils.ExecutorUtils
import helium314.keyboard.latin.utils.ResourceUtils
import helium314.keyboard.latin.utils.infoDialog
import helium314.keyboard.latin.utils.prefs
import kotlinx.serialization.Serializable
import kotlinx.serialization.SerializationException
import kotlinx.serialization.encodeToString
@ -62,7 +63,7 @@ open class ColorsSettingsFragment : Fragment(R.layout.color_settings), MenuProvi
get() = prefs.getInt(Settings.getColorPref(Settings.PREF_SHOW_MORE_COLORS, isNight), 0)
set(value) { prefs.edit().putInt(Settings.getColorPref(Settings.PREF_SHOW_MORE_COLORS, isNight), value).apply() }
private val prefs by lazy { DeviceProtectedUtils.getSharedPreferences(requireContext()) }
private val prefs by lazy { requireContext().prefs() }
private val colorPrefsAndNames by lazy {
listOf(

View file

@ -21,12 +21,12 @@ import androidx.core.widget.doAfterTextChanged
import androidx.recyclerview.widget.RecyclerView
import helium314.keyboard.latin.R
import helium314.keyboard.latin.common.LocaleUtils
import helium314.keyboard.latin.utils.DeviceProtectedUtils
import helium314.keyboard.latin.utils.SubtypeLocaleUtils
import helium314.keyboard.latin.utils.addEnabledSubtype
import helium314.keyboard.latin.utils.displayName
import helium314.keyboard.latin.utils.isAdditionalSubtype
import helium314.keyboard.latin.utils.locale
import helium314.keyboard.latin.utils.prefs
import helium314.keyboard.latin.utils.removeEnabledSubtype
import helium314.keyboard.latin.utils.showMissingDictionaryDialog
@ -58,7 +58,7 @@ class LanguageFilterList(searchField: EditText, recyclerView: RecyclerView) {
private class LanguageAdapter(list: List<MutableList<SubtypeInfo>> = listOf(), context: Context) :
RecyclerView.Adapter<LanguageAdapter.ViewHolder>() {
var onlySystemLocales = false
private val prefs = DeviceProtectedUtils.getSharedPreferences(context)
private val prefs = context.prefs()
var fragment: LanguageSettingsFragment? = null
var list: List<MutableList<SubtypeInfo>> = list

View file

@ -39,7 +39,7 @@ class LanguageSettingsDialog(
private val onlySystemLocales: Boolean,
private val reloadSetting: () -> Unit
) : AlertDialog(context), LanguageSettingsFragment.Listener {
private val prefs = DeviceProtectedUtils.getSharedPreferences(context)
private val prefs = context.prefs()
private val binding = LocaleSettingsDialogBinding.inflate(LayoutInflater.from(context))
private val mainLocale = infos.first().subtype.locale()
private var hasInternalDictForLanguage = false

View file

@ -20,7 +20,6 @@ import androidx.fragment.app.Fragment
import helium314.keyboard.latin.R
import helium314.keyboard.latin.common.LocaleUtils
import helium314.keyboard.latin.common.LocaleUtils.constructLocale
import helium314.keyboard.latin.utils.DeviceProtectedUtils
import helium314.keyboard.latin.utils.DictionaryInfoUtils
import helium314.keyboard.latin.utils.ScriptUtils.script
import helium314.keyboard.latin.utils.SubtypeLocaleUtils
@ -29,6 +28,7 @@ import helium314.keyboard.latin.utils.getDictionaryLocales
import helium314.keyboard.latin.utils.getEnabledSubtypes
import helium314.keyboard.latin.utils.getSystemLocales
import helium314.keyboard.latin.utils.locale
import helium314.keyboard.latin.utils.prefs
import java.util.*
// not a SettingsFragment, because with androidx.preferences it's very complicated or
@ -38,7 +38,7 @@ class LanguageSettingsFragment : Fragment(R.layout.language_settings) {
private val enabledSubtypes = mutableListOf<InputMethodSubtype>()
private val systemLocales = mutableListOf<Locale>()
private lateinit var languageFilterList: LanguageFilterList
private lateinit var sharedPreferences: SharedPreferences
private lateinit var prefs: SharedPreferences
private lateinit var systemOnlySwitch: Switch
private val dictionaryLocales by lazy { getDictionaryLocales(requireContext()) }
@ -56,22 +56,22 @@ class LanguageSettingsFragment : Fragment(R.layout.language_settings) {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
sharedPreferences = DeviceProtectedUtils.getSharedPreferences(requireContext())
prefs = requireContext().prefs()
SubtypeLocaleUtils.init(requireContext())
enabledSubtypes.addAll(getEnabledSubtypes(sharedPreferences))
enabledSubtypes.addAll(getEnabledSubtypes(prefs))
systemLocales.addAll(getSystemLocales())
}
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
val view = super.onCreateView(inflater, container, savedInstanceState) ?: return null
systemOnlySwitch = view.findViewById(R.id.language_switch)
systemOnlySwitch.isChecked = sharedPreferences.getBoolean(Settings.PREF_USE_SYSTEM_LOCALES, true)
systemOnlySwitch.isChecked = prefs.getBoolean(Settings.PREF_USE_SYSTEM_LOCALES, true)
systemOnlySwitch.setOnCheckedChangeListener { _, b ->
sharedPreferences.edit { putBoolean(Settings.PREF_USE_SYSTEM_LOCALES, b) }
prefs.edit { putBoolean(Settings.PREF_USE_SYSTEM_LOCALES, b) }
enabledSubtypes.clear()
enabledSubtypes.addAll(getEnabledSubtypes(sharedPreferences))
enabledSubtypes.addAll(getEnabledSubtypes(prefs))
loadSubtypes(b)
}
languageFilterList = LanguageFilterList(view.findViewById(R.id.search_field), view.findViewById(R.id.language_list))

View file

@ -40,6 +40,7 @@ import helium314.keyboard.latin.utils.AdditionalSubtypeUtils;
import helium314.keyboard.latin.utils.ColorUtilKt;
import helium314.keyboard.latin.utils.DeviceProtectedUtils;
import helium314.keyboard.latin.utils.JniUtils;
import helium314.keyboard.latin.utils.KtxKt;
import helium314.keyboard.latin.utils.Log;
import helium314.keyboard.latin.utils.ResourceUtils;
import helium314.keyboard.latin.utils.RunInLocaleKt;
@ -237,7 +238,7 @@ public final class Settings implements SharedPreferences.OnSharedPreferenceChang
private void onCreate(final Context context) {
mContext = context;
mPrefs = DeviceProtectedUtils.getSharedPreferences(context);
mPrefs = KtxKt.prefs(context);
mPrefs.registerOnSharedPreferenceChangeListener(this);
}

View file

@ -25,10 +25,10 @@ import helium314.keyboard.latin.BuildConfig;
import helium314.keyboard.latin.R;
import helium314.keyboard.latin.common.FileUtils;
import helium314.keyboard.latin.define.DebugFlags;
import helium314.keyboard.latin.utils.DeviceProtectedUtils;
import helium314.keyboard.latin.utils.DictionaryUtilsKt;
import helium314.keyboard.latin.utils.ExecutorUtils;
import helium314.keyboard.latin.utils.JniUtils;
import helium314.keyboard.latin.utils.KtxKt;
import helium314.keyboard.latin.utils.SubtypeSettingsKt;
import helium314.keyboard.latin.utils.SubtypeUtilsKt;
@ -85,7 +85,7 @@ public final class SettingsFragment extends PreferenceFragmentCompat {
}
private String getEnabledSubtypesLabel() {
final List<InputMethodSubtype> subtypes = SubtypeSettingsKt.getEnabledSubtypes(DeviceProtectedUtils.getSharedPreferences(getActivity()), true);
final List<InputMethodSubtype> subtypes = SubtypeSettingsKt.getEnabledSubtypes(KtxKt.prefs(getActivity()), true);
final StringBuilder sb = new StringBuilder();
for (final InputMethodSubtype subtype : subtypes) {
if (sb.length() > 0)

View file

@ -24,7 +24,7 @@ import androidx.preference.Preference;
import androidx.preference.PreferenceGroup;
import helium314.keyboard.latin.R;
import helium314.keyboard.latin.utils.DeviceProtectedUtils;
import helium314.keyboard.latin.utils.KtxKt;
import helium314.keyboard.latin.utils.SubtypeLocaleUtils;
import helium314.keyboard.latin.utils.SubtypeSettingsKt;
import helium314.keyboard.latin.utils.SubtypeUtilsKt;
@ -105,7 +105,7 @@ public class UserDictionaryListFragment extends SubScreenFragment {
}
static TreeSet<Locale> getSortedDictionaryLocales(final Context context) {
final SharedPreferences prefs = DeviceProtectedUtils.getSharedPreferences(context);
final SharedPreferences prefs = KtxKt.prefs(context);
final boolean localeSystemOnly = prefs.getBoolean(Settings.PREF_USE_SYSTEM_LOCALES, true);
final TreeSet<Locale> sortedLocales = new TreeSet<>(new LocaleComparator());

View file

@ -30,7 +30,7 @@ import helium314.keyboard.latin.common.ComposedData;
import helium314.keyboard.latin.settings.Settings;
import helium314.keyboard.latin.settings.SettingsValuesForSuggestion;
import helium314.keyboard.latin.utils.AdditionalSubtypeUtils;
import helium314.keyboard.latin.utils.DeviceProtectedUtils;
import helium314.keyboard.latin.utils.KtxKt;
import helium314.keyboard.latin.utils.SubtypeSettingsKt;
import helium314.keyboard.latin.utils.SuggestionResults;
@ -79,7 +79,7 @@ public final class AndroidSpellCheckerService extends SpellCheckerService
public void onCreate() {
super.onCreate();
mRecommendedThreshold = Float.parseFloat(getString(R.string.spellchecker_recommended_threshold_value));
final SharedPreferences prefs = DeviceProtectedUtils.getSharedPreferences(this);
final SharedPreferences prefs = KtxKt.prefs(this);
prefs.registerOnSharedPreferenceChangeListener(this);
onSharedPreferenceChanged(prefs, Settings.PREF_USE_CONTACTS);
final boolean blockOffensive = Settings.readBlockPotentiallyOffensive(prefs, getResources());

View file

@ -13,6 +13,8 @@ import android.os.Binder;
import android.provider.UserDictionary.Words;
import android.service.textservice.SpellCheckerService.Session;
import android.text.TextUtils;
import helium314.keyboard.latin.utils.KtxKt;
import helium314.keyboard.latin.utils.Log;
import android.util.LruCache;
import android.view.inputmethod.InputMethodManager;
@ -30,7 +32,6 @@ import helium314.keyboard.latin.common.StringUtils;
import helium314.keyboard.latin.define.DebugFlags;
import com.android.inputmethod.latin.utils.BinaryDictionaryUtils;
import helium314.keyboard.latin.utils.DeviceProtectedUtils;
import helium314.keyboard.latin.utils.ScriptUtils;
import helium314.keyboard.latin.utils.StatsUtils;
import helium314.keyboard.latin.utils.SubtypeSettingsKt;
@ -153,7 +154,7 @@ public abstract class AndroidWordLevelSpellCheckerSession extends Session {
// localeString for this app is always empty, get it from settings if possible
// and we're sure this app is used
if (SubtypeSettingsKt.getInitialized() && "dummy".equals(currentInputMethodSubtype.getExtraValue())) {
final SharedPreferences prefs = DeviceProtectedUtils.getSharedPreferences(mService);
final SharedPreferences prefs = KtxKt.prefs(mService);
return SubtypeSettingsKt.getSelectedSubtype(prefs).getLocale();
}
}

View file

@ -58,7 +58,7 @@ import helium314.keyboard.latin.settings.DebugSettings;
import helium314.keyboard.latin.settings.Settings;
import helium314.keyboard.latin.settings.SettingsValues;
import helium314.keyboard.latin.suggestions.PopupSuggestionsView.MoreSuggestionsListener;
import helium314.keyboard.latin.utils.DeviceProtectedUtils;
import helium314.keyboard.latin.utils.KtxKt;
import helium314.keyboard.latin.utils.Log;
import helium314.keyboard.latin.utils.ToolbarKey;
import helium314.keyboard.latin.utils.ToolbarUtilsKt;
@ -143,7 +143,7 @@ public final class SuggestionStripView extends RelativeLayout implements OnClick
public SuggestionStripView(final Context context, final AttributeSet attrs, final int defStyle) {
super(context, attrs, defStyle);
final Colors colors = Settings.getInstance().getCurrent().mColors;
final SharedPreferences prefs = DeviceProtectedUtils.getSharedPreferences(context);
final SharedPreferences prefs = KtxKt.prefs(context);
DEBUG_SUGGESTIONS = prefs.getBoolean(DebugSettings.PREF_SHOW_SUGGESTION_INFOS, false);
final LayoutInflater inflater = LayoutInflater.from(context);
@ -392,9 +392,9 @@ public final class SuggestionStripView extends RelativeLayout implements OnClick
if (pinnedKeyView == null) {
addKeyToPinnedKeys(tag);
mToolbar.findViewWithTag(tag).setBackground(mEnabledToolKeyBackground);
ToolbarUtilsKt.addPinnedKey(DeviceProtectedUtils.getSharedPreferences(getContext()), tag);
ToolbarUtilsKt.addPinnedKey(KtxKt.prefs(getContext()), tag);
} else {
ToolbarUtilsKt.removePinnedKey(DeviceProtectedUtils.getSharedPreferences(getContext()), tag);
ToolbarUtilsKt.removePinnedKey(KtxKt.prefs(getContext()), tag);
mToolbar.findViewWithTag(tag).setBackground(mDefaultBackground.getConstantState().newDrawable(getResources()));
mPinnedKeys.removeView(pinnedKeyView);
}

View file

@ -62,7 +62,7 @@ fun reorderDialog(
@StringRes dialogTitleId: Int,
getIcon: (String) -> Drawable? = { null }
) {
val prefs = DeviceProtectedUtils.getSharedPreferences(context)
val prefs = context.prefs()
val orderedItems = prefs.getString(key, defaultSetting)!!.split(";").mapTo(ArrayList()) {
val both = it.split(",")
both.first() to both.last().toBoolean()

View file

@ -39,7 +39,7 @@ fun getDictionaryLocales(context: Context): MutableSet<Locale> {
}
fun showMissingDictionaryDialog(context: Context, locale: Locale) {
val prefs = DeviceProtectedUtils.getSharedPreferences(context)
val prefs = context.prefs()
if (prefs.getBoolean(Settings.PREF_DONT_SHOW_MISSING_DICTIONARY_DIALOG, false) || locale.toString() == "zz")
return
val repositoryLink = "<a href='$DICTIONARY_URL'>" + context.getString(R.string.dictionary_link_text) + "</a>"
@ -99,7 +99,7 @@ fun createDictionaryTextHtml(message: String, locale: Locale, context: Context):
fun cleanUnusedMainDicts(context: Context) {
val dictionaryDir = File(DictionaryInfoUtils.getWordListCacheDirectory(context))
val dirs = dictionaryDir.listFiles() ?: return
val prefs = DeviceProtectedUtils.getSharedPreferences(context)
val prefs = context.prefs()
val usedLocaleLanguageTags = hashSetOf<String>()
getEnabledSubtypes(prefs).forEach { subtype ->
val locale = subtype.locale()

View file

@ -243,7 +243,7 @@ private fun loadResourceSubtypes(resources: Resources) {
// remove custom subtypes without a layout file
private fun removeInvalidCustomSubtypes(context: Context) {
val prefs = DeviceProtectedUtils.getSharedPreferences(context)
val prefs = context.prefs()
val additionalSubtypes = Settings.readPrefAdditionalSubtypes(prefs, context.resources).split(";")
val customSubtypeFiles by lazy { getCustomLayoutFiles(context).map { it.name } }
val subtypesToRemove = mutableListOf<String>()
@ -259,15 +259,14 @@ private fun removeInvalidCustomSubtypes(context: Context) {
}
private fun loadAdditionalSubtypes(context: Context) {
val prefs = DeviceProtectedUtils.getSharedPreferences(context)
val additionalSubtypeString = Settings.readPrefAdditionalSubtypes(prefs, context.resources)
val additionalSubtypeString = Settings.readPrefAdditionalSubtypes(context.prefs(), context.resources)
val subtypes = AdditionalSubtypeUtils.createAdditionalSubtypesArray(additionalSubtypeString)
additionalSubtypes.addAll(subtypes)
}
// requires loadResourceSubtypes to be called before
private fun loadEnabledSubtypes(context: Context) {
val prefs = DeviceProtectedUtils.getSharedPreferences(context)
val prefs = context.prefs()
val subtypeStrings = prefs.getString(Settings.PREF_ENABLED_SUBTYPES, "")!!
.split(SUBTYPE_SEPARATOR).filter { it.isNotEmpty() }.map { it.toLocaleAndLayout() }

View file

@ -62,7 +62,7 @@ fun setToolbarButtonsActivatedStateOnPrefChange(buttonsGroup: ViewGroup, key: St
private fun setToolbarButtonActivatedState(button: ImageButton) {
button.isActivated = when (button.tag) {
INCOGNITO -> Settings.readAlwaysIncognitoMode(DeviceProtectedUtils.getSharedPreferences(button.context))
INCOGNITO -> Settings.readAlwaysIncognitoMode(button.context.prefs())
ONE_HANDED -> Settings.getInstance().current.mOneHandedModeEnabled
SPLIT -> Settings.getInstance().current.mIsSplitKeyboardEnabled
AUTOCORRECT -> Settings.getInstance().current.mAutoCorrectionEnabledPerUserSettings
@ -226,7 +226,7 @@ fun toolbarKeysCustomizer(context: Context) {
.setTitle(R.string.customize_toolbar_key_codes)
.setView(ScrollView(context).apply { addView(ll) })
.setPositiveButton(R.string.dialog_close, null)
val prefs = DeviceProtectedUtils.getSharedPreferences(context)
val prefs = context.prefs()
if (readCustomKeyCodes(prefs).isNotEmpty() || readCustomLongpressCodes(prefs).isNotEmpty())
builder.setNeutralButton(R.string.button_default) { _, _ ->
confirmDialog(context, context.getString(R.string.customize_toolbar_key_code_reset_message), context.getString(android.R.string.ok)) {
@ -257,7 +257,7 @@ fun toolbarKeysCustomizer(context: Context) {
@SuppressLint("SetTextI18n")
private fun toolbarKeyCustomizer(context: Context, key: ToolbarKey) {
val layout = LayoutInflater.from(context).inflate(R.layout.toolbar_key_customizer, null)
val prefs = DeviceProtectedUtils.getSharedPreferences(context)
val prefs = context.prefs()
var keyCode: String? = null
var longpressCode: String? = null
val builder = AlertDialog.Builder(context)

View file

@ -22,8 +22,8 @@ import helium314.keyboard.latin.common.StringUtils
import helium314.keyboard.latin.inputlogic.InputLogic
import helium314.keyboard.latin.inputlogic.SpaceState
import helium314.keyboard.latin.settings.Settings
import helium314.keyboard.latin.utils.DeviceProtectedUtils
import helium314.keyboard.latin.utils.ScriptUtils
import helium314.keyboard.latin.utils.prefs
import org.junit.runner.RunWith
import org.mockito.Mockito
import org.robolectric.Robolectric
@ -165,7 +165,7 @@ class InputLogicTest {
input('.')
input('a')
assertEquals("hello.a", textBeforeCursor)
DeviceProtectedUtils.getSharedPreferences(latinIME).edit { putBoolean(Settings.PREF_AUTOSPACE_AFTER_PUNCTUATION, true) }
latinIME.prefs().edit { putBoolean(Settings.PREF_AUTOSPACE_AFTER_PUNCTUATION, true) }
setText("hello")
input('.')
input('a')
@ -180,7 +180,7 @@ class InputLogicTest {
input('a')
assertEquals("hello.a", textBeforeCursor)
assertEquals("hello.a there", text)
DeviceProtectedUtils.getSharedPreferences(latinIME).edit { putBoolean(Settings.PREF_AUTOSPACE_AFTER_PUNCTUATION, true) }
latinIME.prefs().edit { putBoolean(Settings.PREF_AUTOSPACE_AFTER_PUNCTUATION, true) }
setText("hello there")
setCursorPosition(5) // after hello
input('.')
@ -191,7 +191,7 @@ class InputLogicTest {
@Test fun noAutospaceInUrlField() {
reset()
DeviceProtectedUtils.getSharedPreferences(latinIME).edit { putBoolean(Settings.PREF_AUTOSPACE_AFTER_PUNCTUATION, true) }
latinIME.prefs().edit { putBoolean(Settings.PREF_AUTOSPACE_AFTER_PUNCTUATION, true) }
chainInput("example.net")
assertEquals("example. net", text)
lastAddedWord = ""
@ -221,7 +221,7 @@ class InputLogicTest {
@Test fun noAutospaceForDetectedUrl() { // "light" version, should work without url detection
reset()
DeviceProtectedUtils.getSharedPreferences(latinIME).edit { putBoolean(Settings.PREF_AUTOSPACE_AFTER_PUNCTUATION, true) }
latinIME.prefs().edit { putBoolean(Settings.PREF_AUTOSPACE_AFTER_PUNCTUATION, true) }
chainInput("http://example.net")
assertEquals("http://example.net", text)
assertEquals("http", lastAddedWord)
@ -230,14 +230,14 @@ class InputLogicTest {
@Test fun noAutospaceForDetectedEmail() {
reset()
DeviceProtectedUtils.getSharedPreferences(latinIME).edit { putBoolean(Settings.PREF_AUTOSPACE_AFTER_PUNCTUATION, true) }
latinIME.prefs().edit { putBoolean(Settings.PREF_AUTOSPACE_AFTER_PUNCTUATION, true) }
chainInput("mail@example.com")
assertEquals("mail@example.com", text)
assertEquals("mail@example", lastAddedWord) // todo: do we want this? not really nice, but don't want to be too aggressive with URL detection disabled
assertEquals("com", composingText) // todo: maybe this should still see the whole address as a single word? or don't be too aggressive?
setText("")
lastAddedWord = ""
DeviceProtectedUtils.getSharedPreferences(latinIME).edit { putBoolean(Settings.PREF_URL_DETECTION, true) }
latinIME.prefs().edit { putBoolean(Settings.PREF_URL_DETECTION, true) }
chainInput("mail@example.com")
assertEquals("", lastAddedWord)
assertEquals("mail@example.com", composingText)
@ -245,23 +245,23 @@ class InputLogicTest {
@Test fun urlDetectionThings() {
reset()
DeviceProtectedUtils.getSharedPreferences(latinIME).edit { putBoolean(Settings.PREF_URL_DETECTION, true) }
latinIME.prefs().edit { putBoolean(Settings.PREF_URL_DETECTION, true) }
chainInput("...h")
assertEquals("...h", text)
assertEquals("h", composingText)
reset()
DeviceProtectedUtils.getSharedPreferences(latinIME).edit { putBoolean(Settings.PREF_URL_DETECTION, true) }
latinIME.prefs().edit { putBoolean(Settings.PREF_URL_DETECTION, true) }
chainInput("bla..")
assertEquals("bla..", text)
assertEquals("", composingText)
reset()
DeviceProtectedUtils.getSharedPreferences(latinIME).edit { putBoolean(Settings.PREF_URL_DETECTION, true) }
latinIME.prefs().edit { putBoolean(Settings.PREF_URL_DETECTION, true) }
chainInput("bla.c")
assertEquals("bla.c", text)
assertEquals("bla.c", composingText)
reset()
DeviceProtectedUtils.getSharedPreferences(latinIME).edit { putBoolean(Settings.PREF_URL_DETECTION, true) }
DeviceProtectedUtils.getSharedPreferences(latinIME).edit { putBoolean(Settings.PREF_AUTOSPACE_AFTER_PUNCTUATION, true) }
latinIME.prefs().edit { putBoolean(Settings.PREF_URL_DETECTION, true) }
latinIME.prefs().edit { putBoolean(Settings.PREF_AUTOSPACE_AFTER_PUNCTUATION, true) }
input("bla")
input('.')
functionalKeyPress(KeyCode.SHIFT) // should remove the phantom space (in addition to normal effect)
@ -272,7 +272,7 @@ class InputLogicTest {
@Test fun stripSeparatorsBeforeAddingToHistoryWithURLDetection() {
reset()
DeviceProtectedUtils.getSharedPreferences(latinIME).edit { putBoolean(Settings.PREF_URL_DETECTION, true) }
latinIME.prefs().edit { putBoolean(Settings.PREF_URL_DETECTION, true) }
chainInput("example.com.")
assertEquals("example.com.", composingText)
input(' ')
@ -281,7 +281,7 @@ class InputLogicTest {
@Test fun dontSelectConsecutiveSeparatorsWithURLDetection() {
reset()
DeviceProtectedUtils.getSharedPreferences(latinIME).edit { putBoolean(Settings.PREF_URL_DETECTION, true) }
latinIME.prefs().edit { putBoolean(Settings.PREF_URL_DETECTION, true) }
chainInput("bla..")
assertEquals("", composingText)
assertEquals("bla..", text)
@ -300,7 +300,7 @@ class InputLogicTest {
input('a')
input('b')
assertEquals("", composingText)
DeviceProtectedUtils.getSharedPreferences(latinIME).edit { putBoolean(Settings.PREF_URL_DETECTION, true) }
latinIME.prefs().edit { putBoolean(Settings.PREF_URL_DETECTION, true) }
input('.')
input('c')
assertEquals("", composingText)
@ -315,7 +315,7 @@ class InputLogicTest {
@Test fun `select whole thing except http(s) as composing word if URL detection enabled and selecting`() {
reset()
DeviceProtectedUtils.getSharedPreferences(latinIME).edit { putBoolean(Settings.PREF_URL_DETECTION, true) }
latinIME.prefs().edit { putBoolean(Settings.PREF_URL_DETECTION, true) }
setText("http://example.com")
setCursorPosition(13) // between l and e
assertEquals("example.com", composingText)
@ -326,14 +326,14 @@ class InputLogicTest {
@Test fun `select whole thing except http(s) as composing word if URL detection enabled and typing`() {
reset()
DeviceProtectedUtils.getSharedPreferences(latinIME).edit { putBoolean(Settings.PREF_URL_DETECTION, true) }
latinIME.prefs().edit { putBoolean(Settings.PREF_URL_DETECTION, true) }
chainInput("http://example.com")
assertEquals("example.com", composingText)
}
@Test fun `don't add partial URL to history`() {
reset()
DeviceProtectedUtils.getSharedPreferences(latinIME).edit { putBoolean(Settings.PREF_URL_DETECTION, true) }
latinIME.prefs().edit { putBoolean(Settings.PREF_URL_DETECTION, true) }
setText("http:/") // just so lastAddedWord isn't set to http
chainInput("/bla.com")
assertEquals("", lastAddedWord)
@ -341,7 +341,7 @@ class InputLogicTest {
@Test fun urlProperlySelected() {
reset()
DeviceProtectedUtils.getSharedPreferences(latinIME).edit { putBoolean(Settings.PREF_URL_DETECTION, true) }
latinIME.prefs().edit { putBoolean(Settings.PREF_URL_DETECTION, true) }
setInputType(InputType.TYPE_CLASS_TEXT or InputType.TYPE_TEXT_VARIATION_URI)
setText("http://example.com/here")
setCursorPosition(18) // after .com
@ -357,7 +357,7 @@ class InputLogicTest {
@Test fun urlProperlySelectedWhenNotDeletingFullTld() {
reset()
DeviceProtectedUtils.getSharedPreferences(latinIME).edit { putBoolean(Settings.PREF_URL_DETECTION, true) }
latinIME.prefs().edit { putBoolean(Settings.PREF_URL_DETECTION, true) }
setText("http://example.com/here")
setCursorPosition(18) // after .com
functionalKeyPress(KeyCode.DELETE)
@ -372,7 +372,7 @@ class InputLogicTest {
@Test fun dontCommitPartialUrlBeforeFirstPeriod() {
reset()
DeviceProtectedUtils.getSharedPreferences(latinIME).edit { putBoolean(Settings.PREF_URL_DETECTION, true) }
latinIME.prefs().edit { putBoolean(Settings.PREF_URL_DETECTION, true) }
// type http://bla. -> bla not selected, but clearly url, also means http://bla is committed which we probably don't want
chainInput("http://bla.")
assertEquals("bla.", composingText)
@ -391,7 +391,7 @@ class InputLogicTest {
@Test fun `intermediate commit in text field without protocol and with URL detection`() {
reset()
DeviceProtectedUtils.getSharedPreferences(latinIME).edit { putBoolean(Settings.PREF_URL_DETECTION, true) }
latinIME.prefs().edit { putBoolean(Settings.PREF_URL_DETECTION, true) }
chainInput("bla.com/img.jpg")
assertEquals("bla", lastAddedWord)
assertEquals("bla.com/img.jpg", composingText)
@ -399,7 +399,7 @@ class InputLogicTest {
@Test fun `only protocol commit in text field with protocol and URL detection`() {
reset()
DeviceProtectedUtils.getSharedPreferences(latinIME).edit { putBoolean(Settings.PREF_URL_DETECTION, true) }
latinIME.prefs().edit { putBoolean(Settings.PREF_URL_DETECTION, true) }
chainInput("http://bla.com/img.jpg")
assertEquals("http", lastAddedWord)
assertEquals("bla.com/img.jpg", composingText)
@ -416,7 +416,7 @@ class InputLogicTest {
@Test fun `no intermediate commit in URL field with protocol and URL detection`() {
reset()
DeviceProtectedUtils.getSharedPreferences(latinIME).edit { putBoolean(Settings.PREF_URL_DETECTION, true) }
latinIME.prefs().edit { putBoolean(Settings.PREF_URL_DETECTION, true) }
setInputType(InputType.TYPE_CLASS_TEXT or InputType.TYPE_TEXT_VARIATION_URI)
chainInput("http://bla.com/img.jpg")
assertEquals("http", lastAddedWord) // todo: somehow avoid?
@ -435,7 +435,7 @@ class InputLogicTest {
@Test fun `no intermediate commit in URL field without protocol and with URL detection`() {
reset()
DeviceProtectedUtils.getSharedPreferences(latinIME).edit { putBoolean(Settings.PREF_URL_DETECTION, true) }
latinIME.prefs().edit { putBoolean(Settings.PREF_URL_DETECTION, true) }
setInputType(InputType.TYPE_CLASS_TEXT or InputType.TYPE_TEXT_VARIATION_URI)
chainInput("bla.com/img.jpg")
assertEquals("", lastAddedWord)
@ -446,7 +446,7 @@ class InputLogicTest {
@Test fun `don't accidentally detect some other text fields as URI`() {
// see comment in InputLogic.textBeforeCursorMayBeUrlOrSimilar
reset()
DeviceProtectedUtils.getSharedPreferences(latinIME).edit { putBoolean(Settings.PREF_AUTOSPACE_AFTER_PUNCTUATION, true) }
latinIME.prefs().edit { putBoolean(Settings.PREF_AUTOSPACE_AFTER_PUNCTUATION, true) }
setInputType(InputType.TYPE_CLASS_TEXT or InputType.TYPE_TEXT_VARIATION_LONG_MESSAGE)
chainInput("Hey,why")
assertEquals("Hey, why", text)
@ -460,7 +460,7 @@ class InputLogicTest {
assertEquals("", composingText)
// then with URL detection
reset()
DeviceProtectedUtils.getSharedPreferences(latinIME).edit { putBoolean(Settings.PREF_URL_DETECTION, true) }
latinIME.prefs().edit { putBoolean(Settings.PREF_URL_DETECTION, true) }
chainInput("15:50-17")
assertEquals("15:50-17", text)
assertEquals("", composingText)
@ -476,7 +476,7 @@ class InputLogicTest {
@Test fun `autospace works in URL field when input isn't URL`() {
reset()
DeviceProtectedUtils.getSharedPreferences(latinIME).edit { putBoolean(Settings.PREF_URL_DETECTION, true) }
latinIME.prefs().edit { putBoolean(Settings.PREF_URL_DETECTION, true) }
setInputType(InputType.TYPE_CLASS_TEXT or InputType.TYPE_TEXT_VARIATION_URI)
pickSuggestion("this")
input('b')
@ -488,7 +488,7 @@ class InputLogicTest {
// https://github.com/Helium314/HeliBoard/issues/229
@Test fun `autospace works in URL field when input isn't URL, also for multiple suggestions`() {
reset()
DeviceProtectedUtils.getSharedPreferences(latinIME).edit { putBoolean(Settings.PREF_URL_DETECTION, true) }
latinIME.prefs().edit { putBoolean(Settings.PREF_URL_DETECTION, true) }
setInputType(InputType.TYPE_CLASS_TEXT or InputType.TYPE_TEXT_VARIATION_URI)
pickSuggestion("this")
pickSuggestion("is")
@ -545,7 +545,7 @@ class InputLogicTest {
@Test fun `autospace works in URL field when starting with quotes`() {
reset()
DeviceProtectedUtils.getSharedPreferences(latinIME).edit { putBoolean(Settings.PREF_URL_DETECTION, true) }
latinIME.prefs().edit { putBoolean(Settings.PREF_URL_DETECTION, true) }
setInputType(InputType.TYPE_CLASS_TEXT or InputType.TYPE_TEXT_VARIATION_URI)
input("\"")
pickSuggestion("this")
@ -569,21 +569,21 @@ class InputLogicTest {
assertEquals("\"\"\"", text)
reset()
DeviceProtectedUtils.getSharedPreferences(latinIME).edit { putBoolean(Settings.PREF_AUTOSPACE_AFTER_PUNCTUATION, true) }
latinIME.prefs().edit { putBoolean(Settings.PREF_AUTOSPACE_AFTER_PUNCTUATION, true) }
chainInput("\"\"\"")
assertEquals("\"\"\"", text)
}
@Test fun `autospace still happens after "`() {
reset()
DeviceProtectedUtils.getSharedPreferences(latinIME).edit { putBoolean(Settings.PREF_AUTOSPACE_AFTER_PUNCTUATION, true) }
latinIME.prefs().edit { putBoolean(Settings.PREF_AUTOSPACE_AFTER_PUNCTUATION, true) }
chainInput("\"hello\"you")
assertEquals("\"hello\" you", text)
}
@Test fun `autospace still happens after " if next word is in quotes`() {
reset()
DeviceProtectedUtils.getSharedPreferences(latinIME).edit { putBoolean(Settings.PREF_AUTOSPACE_AFTER_PUNCTUATION, true) }
latinIME.prefs().edit { putBoolean(Settings.PREF_AUTOSPACE_AFTER_PUNCTUATION, true) }
chainInput("\"hello\"\"you\"")
assertEquals("\"hello\" \"you\"", text)
}
@ -599,14 +599,14 @@ class InputLogicTest {
@Test fun `autospace still happens after " if nex word is in " and after comma`() {
reset()
DeviceProtectedUtils.getSharedPreferences(latinIME).edit { putBoolean(Settings.PREF_AUTOSPACE_AFTER_PUNCTUATION, true) }
latinIME.prefs().edit { putBoolean(Settings.PREF_AUTOSPACE_AFTER_PUNCTUATION, true) }
chainInput("\"hello\",\"you\"")
assertEquals("\"hello\", \"you\"", text)
}
@Test fun `autospace in json editor`() {
reset()
DeviceProtectedUtils.getSharedPreferences(latinIME).edit { putBoolean(Settings.PREF_AUTOSPACE_AFTER_PUNCTUATION, true) }
latinIME.prefs().edit { putBoolean(Settings.PREF_AUTOSPACE_AFTER_PUNCTUATION, true) }
chainInput("{\"label\":\"")
assertEquals("{\"label\": \"", text)
input('c')
@ -676,7 +676,7 @@ class InputLogicTest {
lastAddedWord = ""
// reset settings
DeviceProtectedUtils.getSharedPreferences(latinIME).edit { clear() }
latinIME.prefs().edit { clear() }
setText("") // (re)sets selection and composing word
}

View file

@ -15,6 +15,7 @@ import helium314.keyboard.latin.settings.Settings
import helium314.keyboard.latin.settings.SettingsValuesForSuggestion
import helium314.keyboard.latin.utils.DeviceProtectedUtils
import helium314.keyboard.latin.utils.SuggestionResults
import helium314.keyboard.latin.utils.prefs
import org.junit.runner.RunWith
import org.robolectric.Robolectric
import org.robolectric.RobolectricTestRunner
@ -253,7 +254,7 @@ class SuggestTest {
}
@Test fun `shortcuts are not autocorrected when setting is off`() {
val prefs = DeviceProtectedUtils.getSharedPreferences(latinIME)
val prefs = latinIME.prefs()
prefs.edit { putBoolean(Settings.PREF_AUTOCORRECT_SHORTCUTS, false) }
val locale = Locale.ENGLISH
val result = shouldBeAutoCorrected(
@ -268,7 +269,7 @@ class SuggestTest {
}
private fun setAutCorrectThreshold(threshold: String) {
val prefs = DeviceProtectedUtils.getSharedPreferences(latinIME)
val prefs = latinIME.prefs()
prefs.edit { putString(Settings.PREF_AUTO_CORRECTION_CONFIDENCE, threshold) }
}