mirror of
https://github.com/Helium314/HeliBoard.git
synced 2025-06-09 16:17:44 +00:00
use context.prefs() instead of the long DeviceProtected...
This commit is contained in:
parent
deb9dda7e7
commit
125a483591
29 changed files with 112 additions and 113 deletions
|
@ -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)
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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()
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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()
|
||||
}
|
||||
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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()
|
||||
}
|
||||
|
|
|
@ -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(
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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))
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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());
|
||||
|
||||
|
|
|
@ -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());
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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() }
|
||||
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue