more convenient access to settingsValues

Settings.getInstance().getCurrent() -> Settings.getValues()
This commit is contained in:
Helium314 2025-02-28 22:17:06 +01:00
parent 98640c6b0d
commit 1b5a793690
46 changed files with 116 additions and 112 deletions

View file

@ -271,7 +271,7 @@ class KeyboardAccessibilityNodeProvider<KV : KeyboardView>(
private fun getKeyDescription(key: Key): String? {
val editorInfo = mKeyboard?.mId?.mEditorInfo
val shouldObscure = mAccessibilityUtils.shouldObscureInput(editorInfo)
val currentSettings = Settings.getInstance().current
val currentSettings = Settings.getValues()
val keyCodeDescription = mKeyCodeDescriptionMapper.getDescriptionForKey(
mKeyboardView.context, mKeyboard, key, shouldObscure)
return if (currentSettings.isWordSeparator(key.code)) {

View file

@ -75,14 +75,14 @@ class KeyboardActionListenerImpl(private val latinIME: LatinIME, private val inp
return false
}
override fun onHorizontalSpaceSwipe(steps: Int): Boolean = when (Settings.getInstance().current.mSpaceSwipeHorizontal) {
override fun onHorizontalSpaceSwipe(steps: Int): Boolean = when (Settings.getValues().mSpaceSwipeHorizontal) {
KeyboardActionListener.SWIPE_MOVE_CURSOR -> onMoveCursorHorizontally(steps)
KeyboardActionListener.SWIPE_SWITCH_LANGUAGE -> onLanguageSlide(steps)
KeyboardActionListener.SWIPE_TOGGLE_NUMPAD -> toggleNumpad(false, false)
else -> false
}
override fun onVerticalSpaceSwipe(steps: Int): Boolean = when (Settings.getInstance().current.mSpaceSwipeVertical) {
override fun onVerticalSpaceSwipe(steps: Int): Boolean = when (Settings.getValues().mSpaceSwipeVertical) {
KeyboardActionListener.SWIPE_MOVE_CURSOR -> onMoveCursorVertically(steps)
KeyboardActionListener.SWIPE_SWITCH_LANGUAGE -> onLanguageSlide(steps)
KeyboardActionListener.SWIPE_TOGGLE_NUMPAD -> toggleNumpad(false, false)

View file

@ -220,9 +220,9 @@ public final class KeyboardLayoutSet {
public static KeyboardLayoutSet buildEmojiClipBottomRow(final Context context, @Nullable final EditorInfo ei) {
final Builder builder = new Builder(context, ei);
builder.mParams.mMode = KeyboardId.MODE_TEXT;
final int width = ResourceUtils.getKeyboardWidth(context, Settings.getInstance().getCurrent());
final int width = ResourceUtils.getKeyboardWidth(context, Settings.getValues());
// actually the keyboard does not have full height, but at this point we use it to get correct key heights
final int height = ResourceUtils.getKeyboardHeight(context.getResources(), Settings.getInstance().getCurrent());
final int height = ResourceUtils.getKeyboardHeight(context.getResources(), Settings.getValues());
builder.setKeyboardGeometry(width, height);
builder.setSubtype(RichInputMethodManager.getInstance().getCurrentSubtype());
return builder.build();

View file

@ -127,7 +127,7 @@ public final class KeyboardSwitcher implements KeyboardState.SwitchActions {
|| mCurrentOrientation != res.getConfiguration().orientation
|| (mCurrentUiMode & Configuration.UI_MODE_NIGHT_MASK) != (res.getConfiguration().uiMode & Configuration.UI_MODE_NIGHT_MASK)
|| !mThemeContext.getResources().equals(res)
|| Settings.getInstance().getCurrent().mColors.haveColorsChanged(context)) {
|| Settings.getValues().mColors.haveColorsChanged(context)) {
mKeyboardTheme = keyboardTheme;
mThemeContext = new ContextThemeWrapper(context, keyboardTheme.mStyleId);
mCurrentUiMode = res.getConfiguration().uiMode;
@ -193,7 +193,7 @@ public final class KeyboardSwitcher implements KeyboardState.SwitchActions {
private void setKeyboard(final int keyboardId, @NonNull final KeyboardSwitchState toggleState) {
// Make {@link MainKeyboardView} visible and hide {@link EmojiPalettesView}.
final SettingsValues currentSettingsValues = Settings.getInstance().getCurrent();
final SettingsValues currentSettingsValues = Settings.getValues();
setMainKeyboardFrame(currentSettingsValues, toggleState);
// TODO: pass this object to setKeyboard instead of getting the current values.
final MainKeyboardView keyboardView = mKeyboardView;
@ -519,7 +519,7 @@ public final class KeyboardSwitcher implements KeyboardState.SwitchActions {
public void reloadKeyboard() {
if (mCurrentInputView != null)
loadKeyboard(mLatinIME.getCurrentInputEditorInfo(), Settings.getInstance().getCurrent(),
loadKeyboard(mLatinIME.getCurrentInputEditorInfo(), Settings.getValues(),
mLatinIME.getCurrentAutoCapsState(), mLatinIME.getCurrentRecapitalizeState());
}

View file

@ -104,7 +104,7 @@ public class KeyboardView extends View {
public KeyboardView(final Context context, final AttributeSet attrs, final int defStyle) {
super(context, attrs, defStyle);
mColors = Settings.getInstance().getCurrent().mColors;
mColors = Settings.getValues().mColors;
final TypedArray keyboardViewAttr = context.obtainStyledAttributes(attrs,
R.styleable.KeyboardView, defStyle, R.style.KeyboardView);
@ -126,7 +126,7 @@ public class KeyboardView extends View {
R.styleable.KeyboardView_spacebarIconWidthRatio, 1.0f);
mKeyHintLetterPadding = keyboardViewAttr.getDimension(
R.styleable.KeyboardView_keyHintLetterPadding, 0.0f);
mKeyPopupHintLetter = Settings.getInstance().getCurrent().mShowsPopupHints
mKeyPopupHintLetter = Settings.getValues().mShowsPopupHints
? keyboardViewAttr.getString(R.styleable.KeyboardView_keyPopupHintLetter)
: "";
mKeyPopupHintLetterPadding = keyboardViewAttr.getDimension(
@ -184,15 +184,15 @@ public class KeyboardView extends View {
}
mKeyboard = keyboard;
mKeyScaleForText = (float) Math.sqrt(1 / Settings.getInstance().getCurrent().mKeyboardHeightScale);
mKeyScaleForText = (float) Math.sqrt(1 / Settings.getValues().mKeyboardHeightScale);
final int scaledKeyHeight = (int) ((keyboard.mMostCommonKeyHeight - keyboard.mVerticalGap) * mKeyScaleForText);
mKeyDrawParams.updateParams(scaledKeyHeight, mKeyVisualAttributes);
mKeyDrawParams.updateParams(scaledKeyHeight, keyboard.mKeyVisualAttributes);
invalidateAllKeys();
requestLayout();
mFontSizeMultiplier = mKeyboard.mId.isEmojiKeyboard()
? Settings.getInstance().getCurrent().mFontSizeMultiplierEmoji
: Settings.getInstance().getCurrent().mFontSizeMultiplier;
? Settings.getValues().mFontSizeMultiplierEmoji
: Settings.getValues().mFontSizeMultiplier;
}
/**
@ -281,8 +281,8 @@ public class KeyboardView extends View {
return;
}
mShowsHints = Settings.getInstance().getCurrent().mShowsHints;
final float scale = Settings.getInstance().getCurrent().mKeyboardHeightScale;
mShowsHints = Settings.getValues().mShowsHints;
final float scale = Settings.getValues().mKeyboardHeightScale;
mIconScaleFactor = scale < 0.8f ? scale + 0.2f : 1f;
final Paint paint = mPaint;
final Drawable background = getBackground();

View file

@ -166,8 +166,8 @@ public final class MainKeyboardView extends KeyboardView implements DrawingProxy
mBackgroundDimAlphaPaint.setAlpha(backgroundDimAlpha);
mLanguageOnSpacebarTextRatio = mainKeyboardViewAttr.getFraction(
R.styleable.MainKeyboardView_languageOnSpacebarTextRatio, 1, 1, 1.0f)
* Settings.getInstance().getCurrent().mFontSizeMultiplier;
final Colors colors = Settings.getInstance().getCurrent().mColors;
* Settings.getValues().mFontSizeMultiplier;
final Colors colors = Settings.getValues().mColors;
mLanguageOnSpacebarTextColor = colors.get(ColorType.SPACE_BAR_TEXT);
mLanguageOnSpacebarTextShadowRadius = mainKeyboardViewAttr.getFloat(
R.styleable.MainKeyboardView_languageOnSpacebarTextShadowRadius,
@ -193,7 +193,7 @@ public final class MainKeyboardView extends KeyboardView implements DrawingProxy
mConfigShowPopupKeysKeyboardAtTouchedPoint = mainKeyboardViewAttr.getBoolean(
R.styleable.MainKeyboardView_showPopupKeysKeyboardAtTouchedPoint, false);
final int gestureTrailFadeoutDuration = Settings.getInstance().getCurrent().mGestureTrailFadeoutDuration;
final int gestureTrailFadeoutDuration = Settings.getValues().mGestureTrailFadeoutDuration;
mGestureFloatingPreviewTextLingerTimeout = gestureTrailFadeoutDuration / 4;
mGestureFloatingTextDrawingPreview = new GestureFloatingTextDrawingPreview(mainKeyboardViewAttr);
@ -734,7 +734,7 @@ public final class MainKeyboardView extends KeyboardView implements DrawingProxy
final RichInputMethodSubtype subtype, final int width) {
// Choose appropriate language name to fit into the width.
final List<Locale> secondaryLocales = Settings.getInstance().getCurrent().mSecondaryLocales;
final List<Locale> secondaryLocales = Settings.getValues().mSecondaryLocales;
// avoid showing same language twice
final List<Locale> secondaryLocalesToUse = withoutDuplicateLanguages(secondaryLocales, subtype.getLocale().getLanguage());
if (secondaryLocalesToUse.size() > 0) {
@ -802,7 +802,7 @@ public final class MainKeyboardView extends KeyboardView implements DrawingProxy
paint.setTextAlign(Align.CENTER);
paint.setTypeface(mTypeface == null ? Typeface.DEFAULT : mTypeface);
paint.setTextSize(mLanguageOnSpacebarTextSize);
final String customText = Settings.getInstance().getCurrent().mSpaceBarText;
final String customText = Settings.getValues().mSpaceBarText;
final String spaceText;
if (!customText.isEmpty()) {
spaceText = customText;

View file

@ -745,7 +745,7 @@ public final class PointerTracker implements PointerTrackerQueue.Element,
}
private boolean isSwiper(final int code) {
final SettingsValues sv = Settings.getInstance().getCurrent();
final SettingsValues sv = Settings.getValues();
return switch (code) {
case Constants.CODE_SPACE -> sv.mSpaceSwipeHorizontal != KeyboardActionListener.SWIPE_NO_ACTION
|| sv.mSpaceSwipeVertical != KeyboardActionListener.SWIPE_NO_ACTION;
@ -921,7 +921,7 @@ public final class PointerTracker implements PointerTrackerQueue.Element,
}
private void onKeySwipe(final int code, final int x, final int y, final long eventTime) {
final SettingsValues sv = Settings.getInstance().getCurrent();
final SettingsValues sv = Settings.getValues();
final int fastTypingTimeout = 2 * sv.mKeyLongpressTimeout / 3;
// we don't want keyswipes to start immediately if the user is fast-typing,
// see https://github.com/openboard-team/openboard/issues/411
@ -1137,7 +1137,7 @@ public final class PointerTracker implements PointerTrackerQueue.Element,
}
final int code = key.getCode();
if (code == KeyCode.LANGUAGE_SWITCH
|| (code == Constants.CODE_SPACE && key.getPopupKeys() == null && Settings.getInstance().getCurrent().mSpaceForLangChange)
|| (code == Constants.CODE_SPACE && key.getPopupKeys() == null && Settings.getValues().mSpaceForLangChange)
) {
// Long pressing the space key invokes IME switcher dialog.
if (sListener.onCustomRequest(Constants.CUSTOM_CODE_SHOW_INPUT_METHOD_PICKER)) {
@ -1146,7 +1146,7 @@ public final class PointerTracker implements PointerTrackerQueue.Element,
return;
}
}
if (code == KeyCode.SYMBOL_ALPHA && Settings.getInstance().getCurrent().mLongPressSymbolsForNumpad) {
if (code == KeyCode.SYMBOL_ALPHA && Settings.getValues().mLongPressSymbolsForNumpad) {
// toggle numpad with sliding input enabled, forcing return to the alpha layout when done
sListener.toggleNumpad(true, true);
return;
@ -1249,7 +1249,7 @@ public final class PointerTracker implements PointerTrackerQueue.Element,
}
private int getLongPressTimeout(final int code) {
final int longpressTimeout = Settings.getInstance().getCurrent().mKeyLongpressTimeout;
final int longpressTimeout = Settings.getValues().mKeyLongpressTimeout;
if (code == KeyCode.SHIFT || code == KeyCode.SYMBOL_ALPHA) {
// We use slightly longer timeout for shift-lock and the numpad long-press.
return longpressTimeout * 3 / 2;

View file

@ -59,7 +59,7 @@ class ClipboardAdapter(
setOnLongClickListener(this@ViewHolder)
setBackgroundResource(itemBackgroundId)
}
Settings.getInstance().current.mColors.setBackground(view, ColorType.KEY_BACKGROUND)
Settings.getValues().mColors.setBackground(view, ColorType.KEY_BACKGROUND)
pinnedIconView = view.findViewById<ImageView>(R.id.clipboard_entry_pinned_icon).apply {
visibility = View.GONE
setImageResource(pinnedIconResId)
@ -70,7 +70,7 @@ class ClipboardAdapter(
setTextSize(TypedValue.COMPLEX_UNIT_PX, itemTextSize)
}
clipboardLayoutParams.setItemProperties(view)
val colors = Settings.getInstance().current.mColors
val colors = Settings.getValues().mColors
colors.setColor(pinnedIconView, ColorType.CLIPBOARD_PIN)
}

View file

@ -77,15 +77,15 @@ class ClipboardHistoryView @JvmOverloads constructor(
super.onMeasure(widthMeasureSpec, heightMeasureSpec)
val res = context.resources
// The main keyboard expands to the entire this {@link KeyboardView}.
val width = ResourceUtils.getKeyboardWidth(context, Settings.getInstance().current) + paddingLeft + paddingRight
val height = ResourceUtils.getKeyboardHeight(res, Settings.getInstance().current) + paddingTop + paddingBottom
val width = ResourceUtils.getKeyboardWidth(context, Settings.getValues()) + paddingLeft + paddingRight
val height = ResourceUtils.getKeyboardHeight(res, Settings.getValues()) + paddingTop + paddingBottom
setMeasuredDimension(width, height)
}
@SuppressLint("ClickableViewAccessibility")
private fun initialize() { // needs to be delayed for access to ClipboardStrip, which is not a child of this view
if (initialized) return
val colors = Settings.getInstance().current.mColors
val colors = Settings.getValues().mColors
clipboardAdapter = ClipboardAdapter(clipboardLayoutParams, this).apply {
itemBackgroundId = keyBackgroundId
pinnedIconResId = pinIconId
@ -231,7 +231,7 @@ class ClipboardHistoryView @JvmOverloads constructor(
val clipContent = clipboardHistoryManager?.getHistoryEntryContent(clipId)
keyboardActionListener?.onTextInput(clipContent?.content.toString())
keyboardActionListener?.onReleaseKey(KeyCode.NOT_SPECIFIED, false)
if (Settings.getInstance().current.mAlphaAfterClipHistoryEntry)
if (Settings.getValues().mAlphaAfterClipHistoryEntry)
keyboardActionListener?.onCodeInput(KeyCode.ALPHA, Constants.NOT_A_COORDINATE, Constants.NOT_A_COORDINATE, false)
}

View file

@ -21,7 +21,7 @@ class ClipboardLayoutParams(ctx: Context) {
init {
val res = ctx.resources
val sv = Settings.getInstance().current
val sv = Settings.getValues()
val defaultKeyboardHeight = ResourceUtils.getKeyboardHeight(res, sv)
val defaultKeyboardWidth = ResourceUtils.getKeyboardWidth(ctx, sv)

View file

@ -59,14 +59,14 @@ final class DynamicGridKeyboard extends Keyboard {
final int paddingWidth = mOccupiedWidth - mBaseWidth;
mBaseWidth = width - paddingWidth;
mOccupiedWidth = width;
final float spacerWidth = Settings.getInstance().getCurrent().mSplitKeyboardSpacerRelativeWidth * mBaseWidth;
final float spacerWidth = Settings.getValues().mSplitKeyboardSpacerRelativeWidth * mBaseWidth;
final Key key0 = getTemplateKey(TEMPLATE_KEY_CODE_0);
final Key key1 = getTemplateKey(TEMPLATE_KEY_CODE_1);
final int horizontalGap = Math.abs(key1.getX() - key0.getX()) - key0.getWidth();
final float widthScale = determineWidthScale(key0.getWidth() + horizontalGap);
mHorizontalGap = (int) (horizontalGap * widthScale);
mHorizontalStep = (int) ((key0.getWidth() + horizontalGap) * widthScale);
mVerticalStep = (int) ((key0.getHeight() + mVerticalGap) / Math.sqrt(Settings.getInstance().getCurrent().mKeyboardHeightScale));
mVerticalStep = (int) ((key0.getHeight() + mVerticalGap) / Math.sqrt(Settings.getValues().mKeyboardHeightScale));
mColumnsNum = mBaseWidth / mHorizontalStep;
if (spacerWidth > 0)
setSpacerColumns(spacerWidth);

View file

@ -305,7 +305,7 @@ final class EmojiCategory {
return mCategoryKeyboardMap.get(categoryKeyboardMapKey);
}
final int currentWidth = ResourceUtils.getKeyboardWidth(mContext, Settings.getInstance().getCurrent());
final int currentWidth = ResourceUtils.getKeyboardWidth(mContext, Settings.getValues());
if (categoryId == EmojiCategory.ID_RECENTS) {
final DynamicGridKeyboard kbd = new DynamicGridKeyboard(mPrefs,
mLayoutSet.getKeyboard(KeyboardId.ELEMENT_EMOJI_RECENTS),
@ -338,7 +338,7 @@ final class EmojiCategory {
private int computeMaxKeyCountPerPage() {
final DynamicGridKeyboard tempKeyboard = new DynamicGridKeyboard(mPrefs,
mLayoutSet.getKeyboard(KeyboardId.ELEMENT_EMOJI_RECENTS),
0, 0, ResourceUtils.getKeyboardWidth(mContext, Settings.getInstance().getCurrent()));
0, 0, ResourceUtils.getKeyboardWidth(mContext, Settings.getValues()));
return MAX_LINE_COUNT_PER_PAGE * tempKeyboard.getColumnsCount();
}

View file

@ -21,7 +21,7 @@ internal class EmojiLayoutParams(res: Resources) {
val bottomRowKeyboardHeight: Int
init {
val sv = Settings.getInstance().current
val sv = Settings.getValues()
val defaultKeyboardHeight = ResourceUtils.getKeyboardHeight(res, sv)
val keyVerticalGap = if (sv.mNarrowKeyGaps) {

View file

@ -241,7 +241,7 @@ public final class EmojiPageKeyboardView extends KeyboardView implements
}
private int getLongPressTimeout() {
return Settings.getInstance().getCurrent().mKeyLongpressTimeout;
return Settings.getValues().mKeyLongpressTimeout;
}
/**

View file

@ -48,7 +48,7 @@ final class EmojiPalettesAdapter extends RecyclerView.Adapter<EmojiPalettesAdapt
}
public void addRecentKey(final Key key) {
if (Settings.getInstance().getCurrent().mIncognitoModeEnabled) {
if (Settings.getValues().mIncognitoModeEnabled) {
// We do not want to log recent keys while being in incognito
return;
}

View file

@ -85,12 +85,12 @@ public final class EmojiPalettesView extends LinearLayout
public EmojiPalettesView(final Context context, final AttributeSet attrs, final int defStyle) {
super(context, attrs, defStyle);
mColors = Settings.getInstance().getCurrent().mColors;
mColors = Settings.getValues().mColors;
final KeyboardLayoutSet.Builder builder = new KeyboardLayoutSet.Builder(context, null);
final Resources res = context.getResources();
mEmojiLayoutParams = new EmojiLayoutParams(res);
builder.setSubtype(RichInputMethodSubtype.Companion.getEmojiSubtype());
builder.setKeyboardGeometry(ResourceUtils.getKeyboardWidth(context, Settings.getInstance().getCurrent()),
builder.setKeyboardGeometry(ResourceUtils.getKeyboardWidth(context, Settings.getValues()),
mEmojiLayoutParams.getEmojiKeyboardHeight());
final KeyboardLayoutSet layoutSet = builder.build();
final TypedArray emojiPalettesViewAttr = context.obtainStyledAttributes(attrs,
@ -113,9 +113,9 @@ public final class EmojiPalettesView extends LinearLayout
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
final Resources res = getContext().getResources();
// The main keyboard expands to the entire this {@link KeyboardView}.
final int width = ResourceUtils.getKeyboardWidth(getContext(), Settings.getInstance().getCurrent())
final int width = ResourceUtils.getKeyboardWidth(getContext(), Settings.getValues())
+ getPaddingLeft() + getPaddingRight();
final int height = ResourceUtils.getKeyboardHeight(res, Settings.getInstance().getCurrent())
final int height = ResourceUtils.getKeyboardHeight(res, Settings.getValues())
+ getPaddingTop() + getPaddingBottom();
mEmojiCategoryPageIndicatorView.mWidth = width;
setMeasuredDimension(width, height);
@ -252,7 +252,7 @@ public final class EmojiPalettesView extends LinearLayout
mKeyboardActionListener.onCodeInput(code, NOT_A_COORDINATE, NOT_A_COORDINATE, false);
}
mKeyboardActionListener.onReleaseKey(code, false);
if (Settings.getInstance().getCurrent().mAlphaAfterEmojiInEmojiView)
if (Settings.getValues().mAlphaAfterEmojiInEmojiView)
mKeyboardActionListener.onCodeInput(KeyCode.ALPHA, NOT_A_COORDINATE, NOT_A_COORDINATE, false);
}
@ -286,7 +286,7 @@ public final class EmojiPalettesView extends LinearLayout
}
private void setupSidePadding() {
final SettingsValues sv = Settings.getInstance().getCurrent();
final SettingsValues sv = Settings.getValues();
final int keyboardWidth = ResourceUtils.getKeyboardWidth(getContext(), sv);
final TypedArray keyboardAttr = getContext().obtainStyledAttributes(
null, R.styleable.Keyboard, R.attr.keyboardStyle, R.style.Keyboard);
@ -352,9 +352,9 @@ public final class EmojiPalettesView extends LinearLayout
final View current = mTabStrip.findViewWithTag((long) categoryId);
if (old instanceof ImageView)
Settings.getInstance().getCurrent().mColors.setColor((ImageView) old, ColorType.EMOJI_CATEGORY);
Settings.getValues().mColors.setColor((ImageView) old, ColorType.EMOJI_CATEGORY);
if (current instanceof ImageView)
Settings.getInstance().getCurrent().mColors.setColor((ImageView) current, ColorType.EMOJI_CATEGORY_SELECTED);
Settings.getValues().mColors.setColor((ImageView) current, ColorType.EMOJI_CATEGORY_SELECTED);
}
public void clearKeyboardCache() {

View file

@ -46,8 +46,8 @@ public class GestureFloatingTextDrawingPreview extends AbstractDrawingPreview {
private static final char[] TEXT_HEIGHT_REFERENCE_CHAR = { 'M' };
public GesturePreviewTextParams(final TypedArray mainKeyboardViewAttr) {
final Colors colors = Settings.getInstance().getCurrent().mColors;
mGesturePreviewDynamic = Settings.getInstance().getCurrent().mGestureFloatingPreviewDynamicEnabled;
final Colors colors = Settings.getValues().mColors;
mGesturePreviewDynamic = Settings.getValues().mGestureFloatingPreviewDynamicEnabled;
mGesturePreviewTextSize = mainKeyboardViewAttr.getDimensionPixelSize(
R.styleable.MainKeyboardView_gestureFloatingPreviewTextSize, 0);
mGesturePreviewTextColor = colors.get(ColorType.KEY_TEXT);

View file

@ -105,7 +105,7 @@ public final class GestureStrokeRecognitionPoints {
public void addDownEventPoint(final int x, final int y, final int elapsedTimeSinceFirstDown,
final int elapsedTimeSinceLastTyping) {
reset();
if (elapsedTimeSinceLastTyping < Settings.getInstance().getCurrent().mGestureFastTypingCooldown) {
if (elapsedTimeSinceLastTyping < Settings.getValues().mGestureFastTypingCooldown) {
mAfterFastTyping = true;
}
if (DEBUG) {

View file

@ -36,7 +36,7 @@ final class GestureTrailDrawingParams {
public final int mTrailLingerDuration;
public GestureTrailDrawingParams(final TypedArray mainKeyboardViewAttr) {
mTrailColor = Settings.getInstance().getCurrent().mColors.get(ColorType.GESTURE_TRAIL);
mTrailColor = Settings.getValues().mColors.get(ColorType.GESTURE_TRAIL);
mTrailStartWidth = mainKeyboardViewAttr.getDimension(
R.styleable.MainKeyboardView_gestureTrailStartWidth, 0.0f);
mTrailEndWidth = mainKeyboardViewAttr.getDimension(
@ -55,7 +55,7 @@ final class GestureTrailDrawingParams {
R.styleable.MainKeyboardView_gestureTrailFadeoutStartDelay, 0);
mFadeoutDuration = GestureTrailDrawingPoints.DEBUG_SHOW_POINTS
? FADEOUT_DURATION_FOR_DEBUG
: Settings.getInstance().getCurrent().mGestureTrailFadeoutDuration;
: Settings.getValues().mGestureTrailFadeoutDuration;
mTrailLingerDuration = mFadeoutStartDelay + mFadeoutDuration;
mUpdateInterval = mainKeyboardViewAttr.getInt(
R.styleable.MainKeyboardView_gestureTrailUpdateInterval, 0);

View file

@ -107,7 +107,7 @@ public final class KeyPreviewChoreographer {
}
final boolean hasPopupKeys = (key.getPopupKeys() != null);
keyPreviewView.setPreviewBackground(hasPopupKeys, keyPreviewPosition);
final Colors colors = Settings.getInstance().getCurrent().mColors;
final Colors colors = Settings.getValues().mColors;
colors.setBackground(keyPreviewView, ColorType.KEY_PREVIEW);
// The key preview is placed vertically above the top edge of the parent key with an

View file

@ -58,7 +58,7 @@ public class KeyPreviewView extends AppCompatTextView {
setCompoundDrawables(null, null, null, null);
setTextColor(drawParams.mPreviewTextColor);
setTextSize(TypedValue.COMPLEX_UNIT_PX, key.selectPreviewTextSize(drawParams)
* Settings.getInstance().getCurrent().mFontSizeMultiplier);
* Settings.getValues().mFontSizeMultiplier);
setTypeface(mTypeface == null ? key.selectPreviewTypeface(drawParams) : mTypeface);
// TODO Should take care of temporaryShiftLabel here.
setTextAndScaleX(key.getPreviewLabel());

View file

@ -114,7 +114,7 @@ public final class KeyVisualAttributes {
R.styleable.Keyboard_Key_keyPreviewTextRatio);
// todo: check what colors do, and if irrelevant and no plan to use -> remove here and from attr
final Colors colors = Settings.getInstance().getCurrent().mColors;
final Colors colors = Settings.getValues().mColors;
mTextColor = colors.get(ColorType.KEY_TEXT);
// when? -> isShiftedLetterActivated, which is a label flag
mTextInactivatedColor = keyAttr.getColor(R.styleable.Keyboard_Key_keyTextInactivatedColor, 0);

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, Settings.getInstance().current.mEmojiMaxSdk).parse()
keysInRows = EmojiParser(mParams, mContext, Settings.getValues().mEmojiMaxSdk).parse()
} else {
try {
setupParams()
@ -65,7 +65,7 @@ open class KeyboardBuilder<KP : KeyboardParams>(protected val mContext: Context,
}
private fun setupParams() {
val sv = Settings.getInstance().current
val sv = Settings.getValues()
mParams.mAllowRedundantPopupKeys = !sv.mRemoveRedundantPopups
mParams.mProximityCharsCorrectionEnabled = mParams.mId.mElementId == KeyboardId.ELEMENT_ALPHABET
|| (mParams.mId.isAlphabetKeyboard && !mParams.mId.mSubtype.hasExtraValue(Constants.Subtype.ExtraValue.NO_SHIFT_PROXIMITY_CORRECTION))
@ -126,7 +126,7 @@ open class KeyboardBuilder<KP : KeyboardParams>(protected val mContext: Context,
}
private fun addSplit() {
val spacerRelativeWidth = Settings.getInstance().current.mSplitKeyboardSpacerRelativeWidth
val spacerRelativeWidth = Settings.getValues().mSplitKeyboardSpacerRelativeWidth
// adjust gaps for the whole keyboard, so it's the same for all rows
mParams.mRelativeHorizontalGap *= 1f / (1f + spacerRelativeWidth)
mParams.mHorizontalGap = (mParams.mRelativeHorizontalGap * mParams.mId.mWidth).toInt()

View file

@ -82,7 +82,7 @@ public class KeyboardParams {
@NonNull
public final KeyboardIconsSet mIconsSet = KeyboardIconsSet.Companion.getInstance();
@NonNull // todo: not good, this only works because params are currently always created for the active subtype
public final List<Locale> mSecondaryLocales = Settings.getInstance().getCurrent().mSecondaryLocales;
public final List<Locale> mSecondaryLocales = Settings.getValues().mSecondaryLocales;
public final ArrayList<String> mPopupKeyTypes = new ArrayList<>();
public final ArrayList<String> mPopupKeyLabelSources = new ArrayList<>();
@ -224,13 +224,13 @@ public class KeyboardParams {
R.styleable.Keyboard_keyboardTopPadding, height, height, 0);
mBottomPadding = (int) (keyboardAttr.getFraction(
R.styleable.Keyboard_keyboardBottomPadding, height, height, 0)
* Settings.getInstance().getCurrent().mBottomPaddingScale);
* Settings.getValues().mBottomPaddingScale);
mLeftPadding = (int) (keyboardAttr.getFraction(
R.styleable.Keyboard_keyboardLeftPadding, width, width, 0)
* Settings.getInstance().getCurrent().mSidePaddingScale);
* Settings.getValues().mSidePaddingScale);
mRightPadding = (int) (keyboardAttr.getFraction(
R.styleable.Keyboard_keyboardRightPadding, width, width, 0)
* Settings.getInstance().getCurrent().mSidePaddingScale);
* Settings.getValues().mSidePaddingScale);
mBaseWidth = mOccupiedWidth - mLeftPadding - mRightPadding;
final float defaultKeyWidthFactor = context.getResources().getInteger(R.integer.config_screen_metrics) > 2 ? 0.9f : 1f;
@ -240,7 +240,7 @@ public class KeyboardParams {
mDefaultAbsoluteKeyWidth = (int) (mDefaultKeyWidth * mBaseWidth);
mAbsolutePopupKeyWidth = (int) (alphaSymbolKeyWidth * mBaseWidth);
if (Settings.getInstance().getCurrent().mNarrowKeyGaps) {
if (Settings.getValues().mNarrowKeyGaps) {
mRelativeHorizontalGap = keyboardAttr.getFraction(
R.styleable.Keyboard_horizontalGapNarrow, 1, 1, 0);
mRelativeVerticalGap = keyboardAttr.getFraction(

View file

@ -784,7 +784,7 @@ public final class KeyboardState {
case SWITCH_STATE_SYMBOL:
// Switch back to alpha keyboard mode if user types one or more non-space/enter
// characters followed by a space/enter.
if (isSpaceOrEnter(code) && Settings.getInstance().getCurrent().mAlphaAfterSymbolAndSpace) {
if (isSpaceOrEnter(code) && Settings.getValues().mAlphaAfterSymbolAndSpace) {
toggleAlphabetAndSymbols(autoCapsFlags, recapitalizeMode);
mPrevSymbolsKeyboardWasShifted = false;
}
@ -801,7 +801,7 @@ public final class KeyboardState {
} else if (code == KeyCode.CLIPBOARD) {
// Note: Printing clipboard content is handled in
// {@link InputLogic#handleFunctionalEvent(Event,InputTransaction,int,LatinIME.UIHandler)}.
if (Settings.getInstance().getCurrent().mClipboardHistoryEnabled) {
if (Settings.getValues().mClipboardHistoryEnabled) {
setClipboardKeyboard();
}
} else if (code == KeyCode.NUMPAD) {
@ -809,7 +809,7 @@ public final class KeyboardState {
} else if (code == KeyCode.SYMBOL) {
setSymbolsKeyboard();
} else if (code == KeyCode.TOGGLE_ONE_HANDED_MODE) {
setOneHandedModeEnabled(!Settings.getInstance().getCurrent().mOneHandedModeEnabled);
setOneHandedModeEnabled(!Settings.getValues().mOneHandedModeEnabled);
} else if (code == KeyCode.SWITCH_ONE_HANDED_MODE) {
switchOneHandedMode();
}

View file

@ -32,7 +32,7 @@ public final class SlidingKeyInputDrawingPreview extends AbstractDrawingPreview
private final Paint mPaint = new Paint();
public SlidingKeyInputDrawingPreview(final TypedArray mainKeyboardViewAttr) {
final int previewColor = Settings.getInstance().getCurrent().mColors.get(ColorType.GESTURE_TRAIL);
final int previewColor = Settings.getValues().mColors.get(ColorType.GESTURE_TRAIL);
final float previewRadius = mainKeyboardViewAttr.getDimension(
R.styleable.MainKeyboardView_slidingKeyInputPreviewWidth, 0) / 2.0f;
final int PERCENTAGE_INT = 100;

View file

@ -44,11 +44,11 @@ class EmojiParser(private val params: KeyboardParams, private val context: Conte
// this is a bit long, but ensures that emoji size stays the same, independent of these settings
// we also ignore side padding for key width, and prefer fewer keys per row over narrower keys
val defaultKeyWidth = ResourceUtils.getDefaultKeyboardWidth(context) * params.mDefaultKeyWidth
val keyWidth = defaultKeyWidth * sqrt(Settings.getInstance().current.mKeyboardHeightScale)
val keyWidth = defaultKeyWidth * sqrt(Settings.getValues().mKeyboardHeightScale)
val defaultKeyboardHeight = ResourceUtils.getDefaultKeyboardHeight(context.resources, false)
val defaultBottomPadding = context.resources.getFraction(R.fraction.config_keyboard_bottom_padding_holo, defaultKeyboardHeight, defaultKeyboardHeight)
val emojiKeyboardHeight = ResourceUtils.getDefaultKeyboardHeight(context.resources, false) * 0.75f + params.mVerticalGap - defaultBottomPadding - context.resources.getDimensionPixelSize(R.dimen.config_emoji_category_page_id_height)
val keyHeight = emojiKeyboardHeight * params.mDefaultRowHeight * Settings.getInstance().current.mKeyboardHeightScale // still apply height scale to key
val keyHeight = emojiKeyboardHeight * params.mDefaultRowHeight * Settings.getValues().mKeyboardHeightScale // still apply height scale to key
emojiArray.forEachIndexed { i, codeArraySpec ->
val keyParams = parseEmojiKey(codeArraySpec, popupEmojisArray?.get(i)?.takeIf { it.isNotEmpty() }) ?: return@forEachIndexed

View file

@ -53,7 +53,7 @@ class KeyboardParser(private val params: KeyboardParams, private val context: Co
KeyboardId.ELEMENT_PHONE -> LayoutType.PHONE
KeyboardId.ELEMENT_PHONE_SYMBOLS -> LayoutType.PHONE_SYMBOLS
KeyboardId.ELEMENT_NUMBER -> LayoutType.NUMBER
KeyboardId.ELEMENT_NUMPAD -> if (Settings.getInstance().current.mDisplayOrientation == Configuration.ORIENTATION_LANDSCAPE)
KeyboardId.ELEMENT_NUMPAD -> if (Settings.getValues().mDisplayOrientation == Configuration.ORIENTATION_LANDSCAPE)
LayoutType.NUMPAD_LANDSCAPE else LayoutType.NUMPAD
KeyboardId.ELEMENT_EMOJI_BOTTOM_ROW -> LayoutType.EMOJI_BOTTOM
KeyboardId.ELEMENT_CLIPBOARD_BOTTOM_ROW -> LayoutType.CLIPBOARD_BOTTOM
@ -65,7 +65,7 @@ class KeyboardParser(private val params: KeyboardParams, private val context: Co
if (params.mId.isEmojiClipBottomRow) {
heightRescale = 4f
// params rescale is not perfect, especially mTopPadding may cause 1 pixel offsets because it's already been converted to int once
if (Settings.getInstance().current.mShowsNumberRow) {
if (Settings.getValues().mShowsNumberRow) {
params.mOccupiedHeight /= 5
params.mBaseHeight /= 5
params.mTopPadding = (params.mTopPadding / 5.0).roundToInt()
@ -100,7 +100,7 @@ class KeyboardParser(private val params: KeyboardParams, private val context: Co
addSymbolPopupKeys(baseKeys)
if (params.mId.isAlphaOrSymbolKeyboard && params.mId.mNumberRowEnabled) {
val newLabelFlags = defaultLabelFlags or
if (Settings.getInstance().current.mShowNumberRowHints) 0 else Key.LABEL_FLAGS_DISABLE_HINT_LABEL
if (Settings.getValues().mShowNumberRowHints) 0 else Key.LABEL_FLAGS_DISABLE_HINT_LABEL
baseKeys.add(0, numberRow.mapTo(mutableListOf()) { it.copy(newLabelFlags = newLabelFlags) })
}
if (!params.mAllowRedundantPopupKeys)
@ -297,7 +297,7 @@ class KeyboardParser(private val params: KeyboardParams, private val context: Co
val row = LayoutParser.parseLayout(LayoutType.NUMBER_ROW, params, context).first()
val localizedNumbers = params.mLocaleKeyboardInfos.localizedNumberKeys
if (localizedNumbers?.size != 10) return row
if (Settings.getInstance().current.mLocalizedNumberRow) {
if (Settings.getValues().mLocalizedNumberRow) {
// replace 0-9 with localized numbers, and move latin number into popup
for (i in row.indices) {
val key = row[i]
@ -323,7 +323,7 @@ class KeyboardParser(private val params: KeyboardParams, private val context: Co
// some layouts have numbers hardcoded in the main layout (pcqwerty as keys, and others as popups)
private fun hasBuiltInNumbers() = params.mId.mSubtype.mainLayoutName == "pcqwerty"
|| (Settings.getInstance().current.mPopupKeyTypes.contains(POPUP_KEYS_LAYOUT)
|| (Settings.getValues().mPopupKeyTypes.contains(POPUP_KEYS_LAYOUT)
&& params.mId.mSubtype.mainLayoutName in listOf("lao", "thai", "korean_sebeolsik_390", "korean_sebeolsik_final")
)

View file

@ -569,7 +569,7 @@ public class DictionaryFacilitatorImpl implements DictionaryFacilitator {
// add word to user dictionary if it is in no other dictionary except user history dictionary,
// reasoning: typing the same word again -> we probably want it in some dictionary permanently
final SettingsValues sv = Settings.getInstance().getCurrent();
final SettingsValues sv = Settings.getValues();
if (sv.mAddToPersonalDictionary // require the setting
&& sv.mAutoCorrectEnabled == sv.mAutoCorrectionEnabledPerUserSettings // don't add if user wants autocorrect but input field does not, see https://github.com/Helium314/HeliBoard/issues/427#issuecomment-1905438000
&& mDictionaryGroups.get(0).hasDict(Dictionary.TYPE_USER_HISTORY, mDictionaryGroups.get(0).mAccount) // require personalized suggestions

View file

@ -160,7 +160,7 @@ final class EmojiAltPhysicalKeyDetector {
}
private static boolean shouldProcessEvent(@NonNull final KeyEvent keyEvent) {
if (!Settings.getInstance().getCurrent().mEnableEmojiAltPhysicalKey) {
if (!Settings.getValues().mEnableEmojiAltPhysicalKey) {
// The feature is disabled.
if (DEBUG) {
Log.d(TAG, "shouldProcessEvent(): Disabled");

View file

@ -44,7 +44,7 @@ public final class InputView extends FrameLayout {
mMoreSuggestionsViewCanceler = new MoreSuggestionsViewCanceler(
mMainKeyboardView, suggestionStripView);
ViewKt.doOnNextLayout(this, v -> {
Settings.getInstance().getCurrent().mColors.setBackground(findViewById(R.id.main_keyboard_frame), ColorType.MAIN_BACKGROUND);
Settings.getValues().mColors.setBackground(findViewById(R.id.main_keyboard_frame), ColorType.MAIN_BACKGROUND);
return null;
});
}

View file

@ -78,7 +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 oldScale = Settings.readOneHandedModeScale(context.prefs(), Settings.getInstance().current.mDisplayOrientation == Configuration.ORIENTATION_PORTRAIT)
val oldScale = Settings.readOneHandedModeScale(context.prefs(), Settings.getValues().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)
@ -90,7 +90,7 @@ class KeyboardWrapperView @JvmOverloads constructor(
true
}
val colors = Settings.getInstance().current.mColors
val colors = Settings.getValues().mColors
colors.setColor(stopOneHandedModeBtn, ColorType.ONE_HANDED_MODE_BUTTON)
colors.setColor(switchOneHandedModeBtn, ColorType.ONE_HANDED_MODE_BUTTON)
colors.setColor(resizeOneHandedModeBtn, ColorType.ONE_HANDED_MODE_BUTTON)
@ -147,7 +147,7 @@ class KeyboardWrapperView @JvmOverloads constructor(
keyboardView.measuredHeight
)
val scale = Settings.getInstance().current.mKeyboardHeightScale
val scale = Settings.getValues().mKeyboardHeightScale
// scale one-handed mode button height if keyboard height scale is < 80%
val heightScale = if (scale < 0.8f) scale + 0.2f else 1f
val buttonsLeft = if (isLeftGravity) keyboardView.measuredWidth else 0

View file

@ -954,7 +954,7 @@ public class LatinIME extends InputMethodService implements
final boolean isDifferentTextField = !restarting || inputTypeChanged;
StatsUtils.onStartInputView(editorInfo.inputType,
Settings.getInstance().getCurrent().mDisplayOrientation,
Settings.getValues().mDisplayOrientation,
!isDifferentTextField);
// The EditorInfo might have a flag that affects fullscreen mode.

View file

@ -685,7 +685,7 @@ public final class RichInputConnection implements PrivateCommandPerformer {
// newCursorPosition != 1.
if (isConnected()) {
mIC.setComposingText(text, newCursorPosition);
if (!Settings.getInstance().getCurrent().mInputAttributes.mShouldShowSuggestions && text.length() > 0) {
if (!Settings.getValues().mInputAttributes.mShouldShowSuggestions && text.length() > 0) {
// We have a field that disables suggestions, but still committed text is set.
// This might lead to weird bugs (e.g. https://github.com/Helium314/HeliBoard/issues/225), so better do
// a sanity check whether the wanted text has been set.

View file

@ -361,9 +361,9 @@ public class RichInputMethodManager {
public static boolean canSwitchLanguage() {
if (!isInitialized()) return false;
if (Settings.getInstance().getCurrent().mLanguageSwitchKeyToOtherSubtypes && getInstance().hasMultipleEnabledSubtypesInThisIme(false))
if (Settings.getValues().mLanguageSwitchKeyToOtherSubtypes && getInstance().hasMultipleEnabledSubtypesInThisIme(false))
return true;
if (Settings.getInstance().getCurrent().mLanguageSwitchKeyToOtherImes && getInstance().mImm.getEnabledInputMethodList().size() > 1)
if (Settings.getValues().mLanguageSwitchKeyToOtherImes && getInstance().mImm.getEnabledInputMethodList().size() > 1)
return true;
return false;
}

View file

@ -118,7 +118,7 @@ class Suggest(private val mDictionaryFacilitator: DictionaryFacilitator) {
// If there is an incoming autocorrection, make sure typed word is shown, so user is able to override it.
// Otherwise, if the relevant setting is enabled, show the typed word in the middle.
val indexOfTypedWord = if (hasAutoCorrection) 2 else 1
if ((hasAutoCorrection || Settings.getInstance().current.mCenterSuggestionTextToEnter)
if ((hasAutoCorrection || Settings.getValues().mCenterSuggestionTextToEnter)
&& suggestionsList.size >= indexOfTypedWord && !TextUtils.isEmpty(typedWordString)) {
if (typedWordFirstOccurrenceWordInfo != null) {
if (SuggestionStripView.DEBUG_SUGGESTIONS) addDebugInfo(typedWordFirstOccurrenceWordInfo, typedWordString)
@ -153,7 +153,7 @@ class Suggest(private val mDictionaryFacilitator: DictionaryFacilitator) {
else typedWordString
val firstAndTypedEmptyInfos by lazy { getEmptyWordSuggestions() }
val scoreLimit = Settings.getInstance().current.mScoreLimitForAutocorrect
val scoreLimit = Settings.getValues().mScoreLimitForAutocorrect
// We allow auto-correction if whitelisting is not required or the word is whitelisted,
// or if the word had more than one char and was not suggested.
val allowsToBeAutoCorrected: Boolean
@ -344,7 +344,7 @@ class Suggest(private val mDictionaryFacilitator: DictionaryFacilitator) {
suggestionsContainer: ArrayList<SuggestedWordInfo>,
nextWordSuggestions: SuggestionResults, rejected: SuggestedWordInfo?
): SuggestedWordInfo? {
if (pseudoTypedWordInfo == null || !Settings.getInstance().current.mUsePersonalizedDicts
if (pseudoTypedWordInfo == null || !Settings.getValues().mUsePersonalizedDicts
|| pseudoTypedWordInfo.mSourceDict.mDictType != Dictionary.TYPE_MAIN || suggestionsContainer.size < 2
) return pseudoTypedWordInfo
nextWordSuggestions.removeAll { info: SuggestedWordInfo -> info.mScore < 170 } // we only want reasonably often typed words, value may require tuning

View file

@ -346,7 +346,7 @@ public class SuggestedWords {
public boolean isAppropriateForAutoCorrection() {
return (mKindAndFlags & KIND_FLAG_APPROPRIATE_FOR_AUTO_CORRECTION) != 0
|| (isKindOf(KIND_SHORTCUT) && Settings.getInstance().getCurrent().mAutoCorrectShortcuts);
|| (isKindOf(KIND_SHORTCUT) && Settings.getValues().mAutoCorrectShortcuts);
}
public void setDebugString(final String str) {

View file

@ -194,6 +194,10 @@ public final class Settings implements SharedPreferences.OnSharedPreferenceChang
return sInstance;
}
public static SettingsValues getValues() {
return sInstance.mSettingsValues;
}
public static void init(final Context context) {
sInstance.onCreate(context);
}
@ -354,7 +358,7 @@ public final class Settings implements SharedPreferences.OnSharedPreferenceChang
public void writeOneHandedModeEnabled(final boolean enabled) {
mPrefs.edit().putBoolean(PREF_ONE_HANDED_MODE_PREFIX +
(getCurrent().mDisplayOrientation == Configuration.ORIENTATION_PORTRAIT), enabled).apply();
(mSettingsValues.mDisplayOrientation == Configuration.ORIENTATION_PORTRAIT), enabled).apply();
}
public static float readOneHandedModeScale(final SharedPreferences prefs, final boolean isLandscape) {
@ -363,7 +367,7 @@ public final class Settings implements SharedPreferences.OnSharedPreferenceChang
public void writeOneHandedModeScale(final Float scale) {
mPrefs.edit().putFloat(PREF_ONE_HANDED_SCALE_PREFIX +
(getCurrent().mDisplayOrientation == Configuration.ORIENTATION_PORTRAIT), scale).apply();
(mSettingsValues.mDisplayOrientation == Configuration.ORIENTATION_PORTRAIT), scale).apply();
}
public static int readOneHandedModeGravity(final SharedPreferences prefs, final boolean isLandscape) {
@ -372,7 +376,7 @@ public final class Settings implements SharedPreferences.OnSharedPreferenceChang
public void writeOneHandedModeGravity(final int gravity) {
mPrefs.edit().putInt(PREF_ONE_HANDED_GRAVITY_PREFIX +
(getCurrent().mDisplayOrientation == Configuration.ORIENTATION_PORTRAIT), gravity).apply();
(mSettingsValues.mDisplayOrientation == Configuration.ORIENTATION_PORTRAIT), gravity).apply();
}
public void writeSplitKeyboardEnabled(final boolean enabled, final boolean isLandscape) {

View file

@ -189,7 +189,7 @@ public final class AndroidSpellCheckerService extends SpellCheckerService
}
private Keyboard createKeyboardForLocale(final Locale locale) {
if (Settings.getInstance().getCurrent() == null) {
if (Settings.getValues() == null) {
// creating a keyboard reads SettingsValues from Settings instance
// maybe it would be "more correct" to create an instance of SettingsValues and use that one instead
// but creating a global one if not existing should be fine too

View file

@ -117,7 +117,7 @@ final class SuggestionStripLayoutHelper {
mSuggestionStripOptions = a.getInt(R.styleable.SuggestionStripView_suggestionStripOptions, 0);
mAlphaObsoleted = ResourceUtils.getFraction(a, R.styleable.SuggestionStripView_alphaObsoleted, 1.0f);
final Colors colors = Settings.getInstance().getCurrent().mColors;
final Colors colors = Settings.getValues().mColors;
mColorValidTypedWord = colors.get(ColorType.SUGGESTION_VALID_WORD);
mColorTypedWord = colors.get(ColorType.SUGGESTION_TYPED_WORD);
mColorAutoCorrect = colors.get(ColorType.SUGGESTION_AUTO_CORRECT);
@ -222,7 +222,7 @@ final class SuggestionStripLayoutHelper {
*/
private int getPositionInSuggestionStrip(final int indexInSuggestedWords,
final SuggestedWords suggestedWords) {
final SettingsValues settingsValues = Settings.getInstance().getCurrent();
final SettingsValues settingsValues = Settings.getValues();
final boolean shouldOmitTypedWord = shouldOmitTypedWord(suggestedWords.mInputStyle,
settingsValues.mGestureFloatingPreviewTextEnabled, true);
return getPositionInSuggestionStrip(indexInSuggestedWords, suggestedWords.mWillAutoCorrect,

View file

@ -143,7 +143,7 @@ public final class SuggestionStripView extends RelativeLayout implements OnClick
@SuppressLint("InflateParams") // does not seem suitable here
public SuggestionStripView(final Context context, final AttributeSet attrs, final int defStyle) {
super(context, attrs, defStyle);
final Colors colors = Settings.getInstance().getCurrent().mColors;
final Colors colors = Settings.getValues().mColors;
final SharedPreferences prefs = KtxKt.prefs(context);
DEBUG_SUGGESTIONS = prefs.getBoolean(DebugSettings.PREF_SHOW_SUGGESTION_INFOS, Defaults.PREF_SHOW_SUGGESTION_INFOS);
@ -212,7 +212,7 @@ public final class SuggestionStripView extends RelativeLayout implements OnClick
mEnabledToolKeyBackground.setGradientRadius(mToolbarExpandKey.getLayoutParams().height / 2f); // nothing else has a usable height at this state
mToolbarExpandKey.setOnClickListener(this);
mToolbarExpandKey.setImageDrawable(Settings.getInstance().getCurrent().mIncognitoModeEnabled ? mIncognitoIcon : mToolbarArrowIcon);
mToolbarExpandKey.setImageDrawable(Settings.getValues().mIncognitoModeEnabled ? mIncognitoIcon : mToolbarArrowIcon);
colors.setColor(mToolbarExpandKey, ColorType.TOOL_BAR_EXPAND_KEY);
mToolbarExpandKey.setBackground(new ShapeDrawable(new OvalShape())); // ShapeDrawable color is black, need src_atop filter
mToolbarExpandKey.getBackground().setColorFilter(colors.get(ColorType.TOOL_BAR_EXPAND_KEY_BACKGROUND), PorterDuff.Mode.SRC_ATOP);
@ -225,7 +225,7 @@ public final class SuggestionStripView extends RelativeLayout implements OnClick
setupKey(button, colors);
mPinnedKeys.addView(button);
final View pinnedKeyInToolbar = mToolbar.findViewWithTag(pinnedKey);
if (pinnedKeyInToolbar != null && Settings.getInstance().getCurrent().mQuickPinToolbarKeys)
if (pinnedKeyInToolbar != null && Settings.getValues().mQuickPinToolbarKeys)
pinnedKeyInToolbar.setBackground(mEnabledToolKeyBackground);
}
@ -247,7 +247,7 @@ public final class SuggestionStripView extends RelativeLayout implements OnClick
}
private void updateKeys() {
final SettingsValues currentSettingsValues = Settings.getInstance().getCurrent();
final SettingsValues currentSettingsValues = Settings.getValues();
final View toolbarVoiceKey = mToolbar.findViewWithTag(ToolbarKey.VOICE);
if (toolbarVoiceKey != null)
toolbarVoiceKey.setVisibility(currentSettingsValues.mShowsVoiceInputKey ? VISIBLE : GONE);
@ -269,7 +269,7 @@ public final class SuggestionStripView extends RelativeLayout implements OnClick
public void setRtl(final boolean isRtlLanguage) {
final int layoutDirection;
if (!Settings.getInstance().getCurrent().mVarToolbarDirection)
if (!Settings.getValues().mVarToolbarDirection)
layoutDirection = View.LAYOUT_DIRECTION_LOCALE;
else{
layoutDirection = isRtlLanguage ? View.LAYOUT_DIRECTION_RTL : View.LAYOUT_DIRECTION_LTR;
@ -291,7 +291,7 @@ public final class SuggestionStripView extends RelativeLayout implements OnClick
clear();
isExternalSuggestionVisible = true;
mSuggestionsStrip.addView(view);
if (Settings.getInstance().getCurrent().mAutoHideToolbar)
if (Settings.getValues().mAutoHideToolbar)
setToolbarVisibility(false);
}
@ -383,7 +383,7 @@ public final class SuggestionStripView extends RelativeLayout implements OnClick
private void onLongClickToolKey(final View view) {
if (!(view.getTag() instanceof ToolbarKey tag)) return;
if (view.getParent() == mPinnedKeys || !Settings.getInstance().getCurrent().mQuickPinToolbarKeys) {
if (view.getParent() == mPinnedKeys || !Settings.getValues().mQuickPinToolbarKeys) {
final int longClickCode = getCodeForToolbarKeyLongClick(tag);
if (longClickCode != KeyCode.UNSPECIFIED) {
mListener.onCodeInput(longClickCode, Constants.SUGGESTION_STRIP_COORDINATE, Constants.SUGGESTION_STRIP_COORDINATE, false);
@ -412,7 +412,7 @@ public final class SuggestionStripView extends RelativeLayout implements OnClick
}
if (showIcon) {
final Drawable icon = mBinIcon;
Settings.getInstance().getCurrent().mColors.setColor(icon, ColorType.REMOVE_SUGGESTION_ICON);
Settings.getValues().mColors.setColor(icon, ColorType.REMOVE_SUGGESTION_ICON);
int w = icon.getIntrinsicWidth();
int h = icon.getIntrinsicWidth();
wordView.setCompoundDrawablesWithIntrinsicBounds(icon, null, null, null);
@ -491,7 +491,7 @@ public final class SuggestionStripView extends RelativeLayout implements OnClick
getContext(), mSuggestedWords, mSuggestionsStrip, SuggestionStripView.this);
mStripVisibilityGroup.showSuggestionsStrip();
// Show the toolbar if no suggestions are left and the "Auto show toolbar" setting is enabled
if (mSuggestedWords.isEmpty() && Settings.getInstance().getCurrent().mAutoShowToolbar){
if (mSuggestedWords.isEmpty() && Settings.getValues().mAutoShowToolbar){
setToolbarVisibility(true);
}
}
@ -722,7 +722,7 @@ public final class SuggestionStripView extends RelativeLayout implements OnClick
copy.setImageDrawable(original.getDrawable());
copy.setLayoutParams(original.getLayoutParams());
copy.setActivated(original.isActivated());
setupKey(copy, Settings.getInstance().getCurrent().mColors);
setupKey(copy, Settings.getValues().mColors);
mPinnedKeys.addView(copy);
}

View file

@ -52,7 +52,7 @@ import helium314.keyboard.latin.settings.Settings;
public class InlineAutofillUtils {
public static InlineSuggestionsRequest createInlineSuggestionRequest(final Context context) {
final Colors colors = Settings.getInstance().getCurrent().mColors;
final Colors colors = Settings.getValues().mColors;
final int chipBgDrawableId = androidx.autofill.R.drawable.autofill_inline_suggestion_chip_background;
final int chipBgColor = colors.get(ColorType.AUTOFILL_BACKGROUND_CHIP);
final int chipTextColor = colors.get(ColorType.KEY_TEXT);

View file

@ -33,13 +33,13 @@ public final class LanguageOnSpacebarUtils {
}
public static int getLanguageOnSpacebarFormatType(@NonNull final RichInputMethodSubtype subtype) {
if (!Settings.getInstance().getCurrent().mSpaceBarText.isEmpty())
if (!Settings.getValues().mSpaceBarText.isEmpty())
return FORMAT_TYPE_FULL_LOCALE;
if (subtype.isNoLanguage()) {
return FORMAT_TYPE_FULL_LOCALE;
}
// Only this subtype is enabled and equals to the system locale.
if (sEnabledSubtypes.size() < 2 && sIsSystemLanguageSameAsInputLanguage && Settings.getInstance().getCurrent().mSecondaryLocales.isEmpty()) {
if (sEnabledSubtypes.size() < 2 && sIsSystemLanguageSameAsInputLanguage && Settings.getValues().mSecondaryLocales.isEmpty()) {
return FORMAT_TYPE_NONE;
}
final Locale locale = subtype.getLocale();

View file

@ -49,9 +49,9 @@ fun setToolbarButtonsActivatedStateOnPrefChange(buttonsGroup: ViewGroup, key: St
private fun setToolbarButtonActivatedState(button: ImageButton) {
button.isActivated = when (button.tag) {
INCOGNITO -> button.context.prefs().getBoolean(Settings.PREF_ALWAYS_INCOGNITO_MODE, Defaults.PREF_ALWAYS_INCOGNITO_MODE)
ONE_HANDED -> Settings.getInstance().current.mOneHandedModeEnabled
SPLIT -> Settings.getInstance().current.mIsSplitKeyboardEnabled
AUTOCORRECT -> Settings.getInstance().current.mAutoCorrectionEnabledPerUserSettings
ONE_HANDED -> Settings.getValues().mOneHandedModeEnabled
SPLIT -> Settings.getValues().mIsSplitKeyboardEnabled
AUTOCORRECT -> Settings.getValues().mAutoCorrectionEnabledPerUserSettings
else -> true
}
}

View file

@ -60,7 +60,7 @@ class SettingsActivity : AppCompatActivity(), SharedPreferences.OnSharedPreferen
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
if (Settings.getInstance().current == null) {
if (Settings.getValues() == null) {
val inputAttributes = InputAttributes(EditorInfo(), false, packageName)
Settings.getInstance().loadSettings(this, resources.configuration.locale(), inputAttributes)
}