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? { private fun getKeyDescription(key: Key): String? {
val editorInfo = mKeyboard?.mId?.mEditorInfo val editorInfo = mKeyboard?.mId?.mEditorInfo
val shouldObscure = mAccessibilityUtils.shouldObscureInput(editorInfo) val shouldObscure = mAccessibilityUtils.shouldObscureInput(editorInfo)
val currentSettings = Settings.getInstance().current val currentSettings = Settings.getValues()
val keyCodeDescription = mKeyCodeDescriptionMapper.getDescriptionForKey( val keyCodeDescription = mKeyCodeDescriptionMapper.getDescriptionForKey(
mKeyboardView.context, mKeyboard, key, shouldObscure) mKeyboardView.context, mKeyboard, key, shouldObscure)
return if (currentSettings.isWordSeparator(key.code)) { return if (currentSettings.isWordSeparator(key.code)) {

View file

@ -75,14 +75,14 @@ class KeyboardActionListenerImpl(private val latinIME: LatinIME, private val inp
return false 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_MOVE_CURSOR -> onMoveCursorHorizontally(steps)
KeyboardActionListener.SWIPE_SWITCH_LANGUAGE -> onLanguageSlide(steps) KeyboardActionListener.SWIPE_SWITCH_LANGUAGE -> onLanguageSlide(steps)
KeyboardActionListener.SWIPE_TOGGLE_NUMPAD -> toggleNumpad(false, false) KeyboardActionListener.SWIPE_TOGGLE_NUMPAD -> toggleNumpad(false, false)
else -> 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_MOVE_CURSOR -> onMoveCursorVertically(steps)
KeyboardActionListener.SWIPE_SWITCH_LANGUAGE -> onLanguageSlide(steps) KeyboardActionListener.SWIPE_SWITCH_LANGUAGE -> onLanguageSlide(steps)
KeyboardActionListener.SWIPE_TOGGLE_NUMPAD -> toggleNumpad(false, false) 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) { public static KeyboardLayoutSet buildEmojiClipBottomRow(final Context context, @Nullable final EditorInfo ei) {
final Builder builder = new Builder(context, ei); final Builder builder = new Builder(context, ei);
builder.mParams.mMode = KeyboardId.MODE_TEXT; 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 // 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.setKeyboardGeometry(width, height);
builder.setSubtype(RichInputMethodManager.getInstance().getCurrentSubtype()); builder.setSubtype(RichInputMethodManager.getInstance().getCurrentSubtype());
return builder.build(); return builder.build();

View file

@ -127,7 +127,7 @@ public final class KeyboardSwitcher implements KeyboardState.SwitchActions {
|| mCurrentOrientation != res.getConfiguration().orientation || mCurrentOrientation != res.getConfiguration().orientation
|| (mCurrentUiMode & Configuration.UI_MODE_NIGHT_MASK) != (res.getConfiguration().uiMode & Configuration.UI_MODE_NIGHT_MASK) || (mCurrentUiMode & Configuration.UI_MODE_NIGHT_MASK) != (res.getConfiguration().uiMode & Configuration.UI_MODE_NIGHT_MASK)
|| !mThemeContext.getResources().equals(res) || !mThemeContext.getResources().equals(res)
|| Settings.getInstance().getCurrent().mColors.haveColorsChanged(context)) { || Settings.getValues().mColors.haveColorsChanged(context)) {
mKeyboardTheme = keyboardTheme; mKeyboardTheme = keyboardTheme;
mThemeContext = new ContextThemeWrapper(context, keyboardTheme.mStyleId); mThemeContext = new ContextThemeWrapper(context, keyboardTheme.mStyleId);
mCurrentUiMode = res.getConfiguration().uiMode; 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) { private void setKeyboard(final int keyboardId, @NonNull final KeyboardSwitchState toggleState) {
// Make {@link MainKeyboardView} visible and hide {@link EmojiPalettesView}. // Make {@link MainKeyboardView} visible and hide {@link EmojiPalettesView}.
final SettingsValues currentSettingsValues = Settings.getInstance().getCurrent(); final SettingsValues currentSettingsValues = Settings.getValues();
setMainKeyboardFrame(currentSettingsValues, toggleState); setMainKeyboardFrame(currentSettingsValues, toggleState);
// TODO: pass this object to setKeyboard instead of getting the current values. // TODO: pass this object to setKeyboard instead of getting the current values.
final MainKeyboardView keyboardView = mKeyboardView; final MainKeyboardView keyboardView = mKeyboardView;
@ -519,7 +519,7 @@ public final class KeyboardSwitcher implements KeyboardState.SwitchActions {
public void reloadKeyboard() { public void reloadKeyboard() {
if (mCurrentInputView != null) if (mCurrentInputView != null)
loadKeyboard(mLatinIME.getCurrentInputEditorInfo(), Settings.getInstance().getCurrent(), loadKeyboard(mLatinIME.getCurrentInputEditorInfo(), Settings.getValues(),
mLatinIME.getCurrentAutoCapsState(), mLatinIME.getCurrentRecapitalizeState()); 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) { public KeyboardView(final Context context, final AttributeSet attrs, final int defStyle) {
super(context, attrs, defStyle); super(context, attrs, defStyle);
mColors = Settings.getInstance().getCurrent().mColors; mColors = Settings.getValues().mColors;
final TypedArray keyboardViewAttr = context.obtainStyledAttributes(attrs, final TypedArray keyboardViewAttr = context.obtainStyledAttributes(attrs,
R.styleable.KeyboardView, defStyle, R.style.KeyboardView); R.styleable.KeyboardView, defStyle, R.style.KeyboardView);
@ -126,7 +126,7 @@ public class KeyboardView extends View {
R.styleable.KeyboardView_spacebarIconWidthRatio, 1.0f); R.styleable.KeyboardView_spacebarIconWidthRatio, 1.0f);
mKeyHintLetterPadding = keyboardViewAttr.getDimension( mKeyHintLetterPadding = keyboardViewAttr.getDimension(
R.styleable.KeyboardView_keyHintLetterPadding, 0.0f); R.styleable.KeyboardView_keyHintLetterPadding, 0.0f);
mKeyPopupHintLetter = Settings.getInstance().getCurrent().mShowsPopupHints mKeyPopupHintLetter = Settings.getValues().mShowsPopupHints
? keyboardViewAttr.getString(R.styleable.KeyboardView_keyPopupHintLetter) ? keyboardViewAttr.getString(R.styleable.KeyboardView_keyPopupHintLetter)
: ""; : "";
mKeyPopupHintLetterPadding = keyboardViewAttr.getDimension( mKeyPopupHintLetterPadding = keyboardViewAttr.getDimension(
@ -184,15 +184,15 @@ public class KeyboardView extends View {
} }
mKeyboard = keyboard; 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); final int scaledKeyHeight = (int) ((keyboard.mMostCommonKeyHeight - keyboard.mVerticalGap) * mKeyScaleForText);
mKeyDrawParams.updateParams(scaledKeyHeight, mKeyVisualAttributes); mKeyDrawParams.updateParams(scaledKeyHeight, mKeyVisualAttributes);
mKeyDrawParams.updateParams(scaledKeyHeight, keyboard.mKeyVisualAttributes); mKeyDrawParams.updateParams(scaledKeyHeight, keyboard.mKeyVisualAttributes);
invalidateAllKeys(); invalidateAllKeys();
requestLayout(); requestLayout();
mFontSizeMultiplier = mKeyboard.mId.isEmojiKeyboard() mFontSizeMultiplier = mKeyboard.mId.isEmojiKeyboard()
? Settings.getInstance().getCurrent().mFontSizeMultiplierEmoji ? Settings.getValues().mFontSizeMultiplierEmoji
: Settings.getInstance().getCurrent().mFontSizeMultiplier; : Settings.getValues().mFontSizeMultiplier;
} }
/** /**
@ -281,8 +281,8 @@ public class KeyboardView extends View {
return; return;
} }
mShowsHints = Settings.getInstance().getCurrent().mShowsHints; mShowsHints = Settings.getValues().mShowsHints;
final float scale = Settings.getInstance().getCurrent().mKeyboardHeightScale; final float scale = Settings.getValues().mKeyboardHeightScale;
mIconScaleFactor = scale < 0.8f ? scale + 0.2f : 1f; mIconScaleFactor = scale < 0.8f ? scale + 0.2f : 1f;
final Paint paint = mPaint; final Paint paint = mPaint;
final Drawable background = getBackground(); final Drawable background = getBackground();

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -59,14 +59,14 @@ final class DynamicGridKeyboard extends Keyboard {
final int paddingWidth = mOccupiedWidth - mBaseWidth; final int paddingWidth = mOccupiedWidth - mBaseWidth;
mBaseWidth = width - paddingWidth; mBaseWidth = width - paddingWidth;
mOccupiedWidth = width; 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 key0 = getTemplateKey(TEMPLATE_KEY_CODE_0);
final Key key1 = getTemplateKey(TEMPLATE_KEY_CODE_1); final Key key1 = getTemplateKey(TEMPLATE_KEY_CODE_1);
final int horizontalGap = Math.abs(key1.getX() - key0.getX()) - key0.getWidth(); final int horizontalGap = Math.abs(key1.getX() - key0.getX()) - key0.getWidth();
final float widthScale = determineWidthScale(key0.getWidth() + horizontalGap); final float widthScale = determineWidthScale(key0.getWidth() + horizontalGap);
mHorizontalGap = (int) (horizontalGap * widthScale); mHorizontalGap = (int) (horizontalGap * widthScale);
mHorizontalStep = (int) ((key0.getWidth() + 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; mColumnsNum = mBaseWidth / mHorizontalStep;
if (spacerWidth > 0) if (spacerWidth > 0)
setSpacerColumns(spacerWidth); setSpacerColumns(spacerWidth);

View file

@ -305,7 +305,7 @@ final class EmojiCategory {
return mCategoryKeyboardMap.get(categoryKeyboardMapKey); 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) { if (categoryId == EmojiCategory.ID_RECENTS) {
final DynamicGridKeyboard kbd = new DynamicGridKeyboard(mPrefs, final DynamicGridKeyboard kbd = new DynamicGridKeyboard(mPrefs,
mLayoutSet.getKeyboard(KeyboardId.ELEMENT_EMOJI_RECENTS), mLayoutSet.getKeyboard(KeyboardId.ELEMENT_EMOJI_RECENTS),
@ -338,7 +338,7 @@ final class EmojiCategory {
private int computeMaxKeyCountPerPage() { private int computeMaxKeyCountPerPage() {
final DynamicGridKeyboard tempKeyboard = new DynamicGridKeyboard(mPrefs, final DynamicGridKeyboard tempKeyboard = new DynamicGridKeyboard(mPrefs,
mLayoutSet.getKeyboard(KeyboardId.ELEMENT_EMOJI_RECENTS), 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(); return MAX_LINE_COUNT_PER_PAGE * tempKeyboard.getColumnsCount();
} }

View file

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

View file

@ -241,7 +241,7 @@ public final class EmojiPageKeyboardView extends KeyboardView implements
} }
private int getLongPressTimeout() { 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) { 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 // We do not want to log recent keys while being in incognito
return; return;
} }

View file

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

View file

@ -46,8 +46,8 @@ public class GestureFloatingTextDrawingPreview extends AbstractDrawingPreview {
private static final char[] TEXT_HEIGHT_REFERENCE_CHAR = { 'M' }; private static final char[] TEXT_HEIGHT_REFERENCE_CHAR = { 'M' };
public GesturePreviewTextParams(final TypedArray mainKeyboardViewAttr) { public GesturePreviewTextParams(final TypedArray mainKeyboardViewAttr) {
final Colors colors = Settings.getInstance().getCurrent().mColors; final Colors colors = Settings.getValues().mColors;
mGesturePreviewDynamic = Settings.getInstance().getCurrent().mGestureFloatingPreviewDynamicEnabled; mGesturePreviewDynamic = Settings.getValues().mGestureFloatingPreviewDynamicEnabled;
mGesturePreviewTextSize = mainKeyboardViewAttr.getDimensionPixelSize( mGesturePreviewTextSize = mainKeyboardViewAttr.getDimensionPixelSize(
R.styleable.MainKeyboardView_gestureFloatingPreviewTextSize, 0); R.styleable.MainKeyboardView_gestureFloatingPreviewTextSize, 0);
mGesturePreviewTextColor = colors.get(ColorType.KEY_TEXT); 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, public void addDownEventPoint(final int x, final int y, final int elapsedTimeSinceFirstDown,
final int elapsedTimeSinceLastTyping) { final int elapsedTimeSinceLastTyping) {
reset(); reset();
if (elapsedTimeSinceLastTyping < Settings.getInstance().getCurrent().mGestureFastTypingCooldown) { if (elapsedTimeSinceLastTyping < Settings.getValues().mGestureFastTypingCooldown) {
mAfterFastTyping = true; mAfterFastTyping = true;
} }
if (DEBUG) { if (DEBUG) {

View file

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

View file

@ -107,7 +107,7 @@ public final class KeyPreviewChoreographer {
} }
final boolean hasPopupKeys = (key.getPopupKeys() != null); final boolean hasPopupKeys = (key.getPopupKeys() != null);
keyPreviewView.setPreviewBackground(hasPopupKeys, keyPreviewPosition); keyPreviewView.setPreviewBackground(hasPopupKeys, keyPreviewPosition);
final Colors colors = Settings.getInstance().getCurrent().mColors; final Colors colors = Settings.getValues().mColors;
colors.setBackground(keyPreviewView, ColorType.KEY_PREVIEW); colors.setBackground(keyPreviewView, ColorType.KEY_PREVIEW);
// The key preview is placed vertically above the top edge of the parent key with an // 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); setCompoundDrawables(null, null, null, null);
setTextColor(drawParams.mPreviewTextColor); setTextColor(drawParams.mPreviewTextColor);
setTextSize(TypedValue.COMPLEX_UNIT_PX, key.selectPreviewTextSize(drawParams) setTextSize(TypedValue.COMPLEX_UNIT_PX, key.selectPreviewTextSize(drawParams)
* Settings.getInstance().getCurrent().mFontSizeMultiplier); * Settings.getValues().mFontSizeMultiplier);
setTypeface(mTypeface == null ? key.selectPreviewTypeface(drawParams) : mTypeface); setTypeface(mTypeface == null ? key.selectPreviewTypeface(drawParams) : mTypeface);
// TODO Should take care of temporaryShiftLabel here. // TODO Should take care of temporaryShiftLabel here.
setTextAndScaleX(key.getPreviewLabel()); setTextAndScaleX(key.getPreviewLabel());

View file

@ -114,7 +114,7 @@ public final class KeyVisualAttributes {
R.styleable.Keyboard_Key_keyPreviewTextRatio); R.styleable.Keyboard_Key_keyPreviewTextRatio);
// todo: check what colors do, and if irrelevant and no plan to use -> remove here and from attr // 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); mTextColor = colors.get(ColorType.KEY_TEXT);
// when? -> isShiftedLetterActivated, which is a label flag // when? -> isShiftedLetterActivated, which is a label flag
mTextInactivatedColor = keyAttr.getColor(R.styleable.Keyboard_Key_keyTextInactivatedColor, 0); 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) { if (id.isEmojiKeyboard) {
mParams.mAllowRedundantPopupKeys = true mParams.mAllowRedundantPopupKeys = true
readAttributes(R.xml.kbd_emoji) readAttributes(R.xml.kbd_emoji)
keysInRows = EmojiParser(mParams, mContext, Settings.getInstance().current.mEmojiMaxSdk).parse() keysInRows = EmojiParser(mParams, mContext, Settings.getValues().mEmojiMaxSdk).parse()
} else { } else {
try { try {
setupParams() setupParams()
@ -65,7 +65,7 @@ open class KeyboardBuilder<KP : KeyboardParams>(protected val mContext: Context,
} }
private fun setupParams() { private fun setupParams() {
val sv = Settings.getInstance().current val sv = Settings.getValues()
mParams.mAllowRedundantPopupKeys = !sv.mRemoveRedundantPopups mParams.mAllowRedundantPopupKeys = !sv.mRemoveRedundantPopups
mParams.mProximityCharsCorrectionEnabled = mParams.mId.mElementId == KeyboardId.ELEMENT_ALPHABET mParams.mProximityCharsCorrectionEnabled = mParams.mId.mElementId == KeyboardId.ELEMENT_ALPHABET
|| (mParams.mId.isAlphabetKeyboard && !mParams.mId.mSubtype.hasExtraValue(Constants.Subtype.ExtraValue.NO_SHIFT_PROXIMITY_CORRECTION)) || (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() { 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 // adjust gaps for the whole keyboard, so it's the same for all rows
mParams.mRelativeHorizontalGap *= 1f / (1f + spacerRelativeWidth) mParams.mRelativeHorizontalGap *= 1f / (1f + spacerRelativeWidth)
mParams.mHorizontalGap = (mParams.mRelativeHorizontalGap * mParams.mId.mWidth).toInt() mParams.mHorizontalGap = (mParams.mRelativeHorizontalGap * mParams.mId.mWidth).toInt()

View file

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

View file

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

View file

@ -32,7 +32,7 @@ public final class SlidingKeyInputDrawingPreview extends AbstractDrawingPreview
private final Paint mPaint = new Paint(); private final Paint mPaint = new Paint();
public SlidingKeyInputDrawingPreview(final TypedArray mainKeyboardViewAttr) { 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( final float previewRadius = mainKeyboardViewAttr.getDimension(
R.styleable.MainKeyboardView_slidingKeyInputPreviewWidth, 0) / 2.0f; R.styleable.MainKeyboardView_slidingKeyInputPreviewWidth, 0) / 2.0f;
final int PERCENTAGE_INT = 100; 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 // 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 // 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 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 defaultKeyboardHeight = ResourceUtils.getDefaultKeyboardHeight(context.resources, false)
val defaultBottomPadding = context.resources.getFraction(R.fraction.config_keyboard_bottom_padding_holo, defaultKeyboardHeight, defaultKeyboardHeight) 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 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 -> emojiArray.forEachIndexed { i, codeArraySpec ->
val keyParams = parseEmojiKey(codeArraySpec, popupEmojisArray?.get(i)?.takeIf { it.isNotEmpty() }) ?: return@forEachIndexed 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 -> LayoutType.PHONE
KeyboardId.ELEMENT_PHONE_SYMBOLS -> LayoutType.PHONE_SYMBOLS KeyboardId.ELEMENT_PHONE_SYMBOLS -> LayoutType.PHONE_SYMBOLS
KeyboardId.ELEMENT_NUMBER -> LayoutType.NUMBER 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 LayoutType.NUMPAD_LANDSCAPE else LayoutType.NUMPAD
KeyboardId.ELEMENT_EMOJI_BOTTOM_ROW -> LayoutType.EMOJI_BOTTOM KeyboardId.ELEMENT_EMOJI_BOTTOM_ROW -> LayoutType.EMOJI_BOTTOM
KeyboardId.ELEMENT_CLIPBOARD_BOTTOM_ROW -> LayoutType.CLIPBOARD_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) { if (params.mId.isEmojiClipBottomRow) {
heightRescale = 4f heightRescale = 4f
// params rescale is not perfect, especially mTopPadding may cause 1 pixel offsets because it's already been converted to int once // 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.mOccupiedHeight /= 5
params.mBaseHeight /= 5 params.mBaseHeight /= 5
params.mTopPadding = (params.mTopPadding / 5.0).roundToInt() params.mTopPadding = (params.mTopPadding / 5.0).roundToInt()
@ -100,7 +100,7 @@ class KeyboardParser(private val params: KeyboardParams, private val context: Co
addSymbolPopupKeys(baseKeys) addSymbolPopupKeys(baseKeys)
if (params.mId.isAlphaOrSymbolKeyboard && params.mId.mNumberRowEnabled) { if (params.mId.isAlphaOrSymbolKeyboard && params.mId.mNumberRowEnabled) {
val newLabelFlags = defaultLabelFlags or 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) }) baseKeys.add(0, numberRow.mapTo(mutableListOf()) { it.copy(newLabelFlags = newLabelFlags) })
} }
if (!params.mAllowRedundantPopupKeys) 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 row = LayoutParser.parseLayout(LayoutType.NUMBER_ROW, params, context).first()
val localizedNumbers = params.mLocaleKeyboardInfos.localizedNumberKeys val localizedNumbers = params.mLocaleKeyboardInfos.localizedNumberKeys
if (localizedNumbers?.size != 10) return row 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 // replace 0-9 with localized numbers, and move latin number into popup
for (i in row.indices) { for (i in row.indices) {
val key = row[i] 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) // some layouts have numbers hardcoded in the main layout (pcqwerty as keys, and others as popups)
private fun hasBuiltInNumbers() = params.mId.mSubtype.mainLayoutName == "pcqwerty" 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") && 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, // 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 // 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 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 && 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 && 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) { private static boolean shouldProcessEvent(@NonNull final KeyEvent keyEvent) {
if (!Settings.getInstance().getCurrent().mEnableEmojiAltPhysicalKey) { if (!Settings.getValues().mEnableEmojiAltPhysicalKey) {
// The feature is disabled. // The feature is disabled.
if (DEBUG) { if (DEBUG) {
Log.d(TAG, "shouldProcessEvent(): Disabled"); Log.d(TAG, "shouldProcessEvent(): Disabled");

View file

@ -44,7 +44,7 @@ public final class InputView extends FrameLayout {
mMoreSuggestionsViewCanceler = new MoreSuggestionsViewCanceler( mMoreSuggestionsViewCanceler = new MoreSuggestionsViewCanceler(
mMainKeyboardView, suggestionStripView); mMainKeyboardView, suggestionStripView);
ViewKt.doOnNextLayout(this, v -> { 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; return null;
}); });
} }

View file

@ -78,7 +78,7 @@ class KeyboardWrapperView @JvmOverloads constructor(
val changePercent = 2 * sign * (x - motionEvent.rawX) / context.resources.displayMetrics.density val changePercent = 2 * sign * (x - motionEvent.rawX) / context.resources.displayMetrics.density
if (abs(changePercent) < 1) return@setOnTouchListener true if (abs(changePercent) < 1) return@setOnTouchListener true
x = motionEvent.rawX 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) val newScale = (oldScale + changePercent / 100f).coerceAtMost(2.5f).coerceAtLeast(0.5f)
if (newScale == oldScale) return@setOnTouchListener true if (newScale == oldScale) return@setOnTouchListener true
Settings.getInstance().writeOneHandedModeScale(newScale) Settings.getInstance().writeOneHandedModeScale(newScale)
@ -90,7 +90,7 @@ class KeyboardWrapperView @JvmOverloads constructor(
true true
} }
val colors = Settings.getInstance().current.mColors val colors = Settings.getValues().mColors
colors.setColor(stopOneHandedModeBtn, ColorType.ONE_HANDED_MODE_BUTTON) colors.setColor(stopOneHandedModeBtn, ColorType.ONE_HANDED_MODE_BUTTON)
colors.setColor(switchOneHandedModeBtn, ColorType.ONE_HANDED_MODE_BUTTON) colors.setColor(switchOneHandedModeBtn, ColorType.ONE_HANDED_MODE_BUTTON)
colors.setColor(resizeOneHandedModeBtn, ColorType.ONE_HANDED_MODE_BUTTON) colors.setColor(resizeOneHandedModeBtn, ColorType.ONE_HANDED_MODE_BUTTON)
@ -147,7 +147,7 @@ class KeyboardWrapperView @JvmOverloads constructor(
keyboardView.measuredHeight 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% // scale one-handed mode button height if keyboard height scale is < 80%
val heightScale = if (scale < 0.8f) scale + 0.2f else 1f val heightScale = if (scale < 0.8f) scale + 0.2f else 1f
val buttonsLeft = if (isLeftGravity) keyboardView.measuredWidth else 0 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; final boolean isDifferentTextField = !restarting || inputTypeChanged;
StatsUtils.onStartInputView(editorInfo.inputType, StatsUtils.onStartInputView(editorInfo.inputType,
Settings.getInstance().getCurrent().mDisplayOrientation, Settings.getValues().mDisplayOrientation,
!isDifferentTextField); !isDifferentTextField);
// The EditorInfo might have a flag that affects fullscreen mode. // The EditorInfo might have a flag that affects fullscreen mode.

View file

@ -685,7 +685,7 @@ public final class RichInputConnection implements PrivateCommandPerformer {
// newCursorPosition != 1. // newCursorPosition != 1.
if (isConnected()) { if (isConnected()) {
mIC.setComposingText(text, newCursorPosition); 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. // 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 // 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. // a sanity check whether the wanted text has been set.

View file

@ -361,9 +361,9 @@ public class RichInputMethodManager {
public static boolean canSwitchLanguage() { public static boolean canSwitchLanguage() {
if (!isInitialized()) return false; if (!isInitialized()) return false;
if (Settings.getInstance().getCurrent().mLanguageSwitchKeyToOtherSubtypes && getInstance().hasMultipleEnabledSubtypesInThisIme(false)) if (Settings.getValues().mLanguageSwitchKeyToOtherSubtypes && getInstance().hasMultipleEnabledSubtypesInThisIme(false))
return true; return true;
if (Settings.getInstance().getCurrent().mLanguageSwitchKeyToOtherImes && getInstance().mImm.getEnabledInputMethodList().size() > 1) if (Settings.getValues().mLanguageSwitchKeyToOtherImes && getInstance().mImm.getEnabledInputMethodList().size() > 1)
return true; return true;
return false; 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. // 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. // Otherwise, if the relevant setting is enabled, show the typed word in the middle.
val indexOfTypedWord = if (hasAutoCorrection) 2 else 1 val indexOfTypedWord = if (hasAutoCorrection) 2 else 1
if ((hasAutoCorrection || Settings.getInstance().current.mCenterSuggestionTextToEnter) if ((hasAutoCorrection || Settings.getValues().mCenterSuggestionTextToEnter)
&& suggestionsList.size >= indexOfTypedWord && !TextUtils.isEmpty(typedWordString)) { && suggestionsList.size >= indexOfTypedWord && !TextUtils.isEmpty(typedWordString)) {
if (typedWordFirstOccurrenceWordInfo != null) { if (typedWordFirstOccurrenceWordInfo != null) {
if (SuggestionStripView.DEBUG_SUGGESTIONS) addDebugInfo(typedWordFirstOccurrenceWordInfo, typedWordString) if (SuggestionStripView.DEBUG_SUGGESTIONS) addDebugInfo(typedWordFirstOccurrenceWordInfo, typedWordString)
@ -153,7 +153,7 @@ class Suggest(private val mDictionaryFacilitator: DictionaryFacilitator) {
else typedWordString else typedWordString
val firstAndTypedEmptyInfos by lazy { getEmptyWordSuggestions() } 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, // 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. // or if the word had more than one char and was not suggested.
val allowsToBeAutoCorrected: Boolean val allowsToBeAutoCorrected: Boolean
@ -344,7 +344,7 @@ class Suggest(private val mDictionaryFacilitator: DictionaryFacilitator) {
suggestionsContainer: ArrayList<SuggestedWordInfo>, suggestionsContainer: ArrayList<SuggestedWordInfo>,
nextWordSuggestions: SuggestionResults, rejected: SuggestedWordInfo? nextWordSuggestions: SuggestionResults, rejected: SuggestedWordInfo?
): SuggestedWordInfo? { ): SuggestedWordInfo? {
if (pseudoTypedWordInfo == null || !Settings.getInstance().current.mUsePersonalizedDicts if (pseudoTypedWordInfo == null || !Settings.getValues().mUsePersonalizedDicts
|| pseudoTypedWordInfo.mSourceDict.mDictType != Dictionary.TYPE_MAIN || suggestionsContainer.size < 2 || pseudoTypedWordInfo.mSourceDict.mDictType != Dictionary.TYPE_MAIN || suggestionsContainer.size < 2
) return pseudoTypedWordInfo ) return pseudoTypedWordInfo
nextWordSuggestions.removeAll { info: SuggestedWordInfo -> info.mScore < 170 } // we only want reasonably often typed words, value may require tuning 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() { public boolean isAppropriateForAutoCorrection() {
return (mKindAndFlags & KIND_FLAG_APPROPRIATE_FOR_AUTO_CORRECTION) != 0 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) { public void setDebugString(final String str) {

View file

@ -194,6 +194,10 @@ public final class Settings implements SharedPreferences.OnSharedPreferenceChang
return sInstance; return sInstance;
} }
public static SettingsValues getValues() {
return sInstance.mSettingsValues;
}
public static void init(final Context context) { public static void init(final Context context) {
sInstance.onCreate(context); sInstance.onCreate(context);
} }
@ -354,7 +358,7 @@ public final class Settings implements SharedPreferences.OnSharedPreferenceChang
public void writeOneHandedModeEnabled(final boolean enabled) { public void writeOneHandedModeEnabled(final boolean enabled) {
mPrefs.edit().putBoolean(PREF_ONE_HANDED_MODE_PREFIX + 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) { 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) { public void writeOneHandedModeScale(final Float scale) {
mPrefs.edit().putFloat(PREF_ONE_HANDED_SCALE_PREFIX + 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) { 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) { public void writeOneHandedModeGravity(final int gravity) {
mPrefs.edit().putInt(PREF_ONE_HANDED_GRAVITY_PREFIX + 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) { 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) { private Keyboard createKeyboardForLocale(final Locale locale) {
if (Settings.getInstance().getCurrent() == null) { if (Settings.getValues() == null) {
// creating a keyboard reads SettingsValues from Settings instance // 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 // 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 // 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); mSuggestionStripOptions = a.getInt(R.styleable.SuggestionStripView_suggestionStripOptions, 0);
mAlphaObsoleted = ResourceUtils.getFraction(a, R.styleable.SuggestionStripView_alphaObsoleted, 1.0f); 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); mColorValidTypedWord = colors.get(ColorType.SUGGESTION_VALID_WORD);
mColorTypedWord = colors.get(ColorType.SUGGESTION_TYPED_WORD); mColorTypedWord = colors.get(ColorType.SUGGESTION_TYPED_WORD);
mColorAutoCorrect = colors.get(ColorType.SUGGESTION_AUTO_CORRECT); mColorAutoCorrect = colors.get(ColorType.SUGGESTION_AUTO_CORRECT);
@ -222,7 +222,7 @@ final class SuggestionStripLayoutHelper {
*/ */
private int getPositionInSuggestionStrip(final int indexInSuggestedWords, private int getPositionInSuggestionStrip(final int indexInSuggestedWords,
final SuggestedWords suggestedWords) { final SuggestedWords suggestedWords) {
final SettingsValues settingsValues = Settings.getInstance().getCurrent(); final SettingsValues settingsValues = Settings.getValues();
final boolean shouldOmitTypedWord = shouldOmitTypedWord(suggestedWords.mInputStyle, final boolean shouldOmitTypedWord = shouldOmitTypedWord(suggestedWords.mInputStyle,
settingsValues.mGestureFloatingPreviewTextEnabled, true); settingsValues.mGestureFloatingPreviewTextEnabled, true);
return getPositionInSuggestionStrip(indexInSuggestedWords, suggestedWords.mWillAutoCorrect, 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 @SuppressLint("InflateParams") // does not seem suitable here
public SuggestionStripView(final Context context, final AttributeSet attrs, final int defStyle) { public SuggestionStripView(final Context context, final AttributeSet attrs, final int defStyle) {
super(context, attrs, defStyle); super(context, attrs, defStyle);
final Colors colors = Settings.getInstance().getCurrent().mColors; final Colors colors = Settings.getValues().mColors;
final SharedPreferences prefs = KtxKt.prefs(context); final SharedPreferences prefs = KtxKt.prefs(context);
DEBUG_SUGGESTIONS = prefs.getBoolean(DebugSettings.PREF_SHOW_SUGGESTION_INFOS, Defaults.PREF_SHOW_SUGGESTION_INFOS); 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 mEnabledToolKeyBackground.setGradientRadius(mToolbarExpandKey.getLayoutParams().height / 2f); // nothing else has a usable height at this state
mToolbarExpandKey.setOnClickListener(this); 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); colors.setColor(mToolbarExpandKey, ColorType.TOOL_BAR_EXPAND_KEY);
mToolbarExpandKey.setBackground(new ShapeDrawable(new OvalShape())); // ShapeDrawable color is black, need src_atop filter 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); 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); setupKey(button, colors);
mPinnedKeys.addView(button); mPinnedKeys.addView(button);
final View pinnedKeyInToolbar = mToolbar.findViewWithTag(pinnedKey); final View pinnedKeyInToolbar = mToolbar.findViewWithTag(pinnedKey);
if (pinnedKeyInToolbar != null && Settings.getInstance().getCurrent().mQuickPinToolbarKeys) if (pinnedKeyInToolbar != null && Settings.getValues().mQuickPinToolbarKeys)
pinnedKeyInToolbar.setBackground(mEnabledToolKeyBackground); pinnedKeyInToolbar.setBackground(mEnabledToolKeyBackground);
} }
@ -247,7 +247,7 @@ public final class SuggestionStripView extends RelativeLayout implements OnClick
} }
private void updateKeys() { private void updateKeys() {
final SettingsValues currentSettingsValues = Settings.getInstance().getCurrent(); final SettingsValues currentSettingsValues = Settings.getValues();
final View toolbarVoiceKey = mToolbar.findViewWithTag(ToolbarKey.VOICE); final View toolbarVoiceKey = mToolbar.findViewWithTag(ToolbarKey.VOICE);
if (toolbarVoiceKey != null) if (toolbarVoiceKey != null)
toolbarVoiceKey.setVisibility(currentSettingsValues.mShowsVoiceInputKey ? VISIBLE : GONE); toolbarVoiceKey.setVisibility(currentSettingsValues.mShowsVoiceInputKey ? VISIBLE : GONE);
@ -269,7 +269,7 @@ public final class SuggestionStripView extends RelativeLayout implements OnClick
public void setRtl(final boolean isRtlLanguage) { public void setRtl(final boolean isRtlLanguage) {
final int layoutDirection; final int layoutDirection;
if (!Settings.getInstance().getCurrent().mVarToolbarDirection) if (!Settings.getValues().mVarToolbarDirection)
layoutDirection = View.LAYOUT_DIRECTION_LOCALE; layoutDirection = View.LAYOUT_DIRECTION_LOCALE;
else{ else{
layoutDirection = isRtlLanguage ? View.LAYOUT_DIRECTION_RTL : View.LAYOUT_DIRECTION_LTR; layoutDirection = isRtlLanguage ? View.LAYOUT_DIRECTION_RTL : View.LAYOUT_DIRECTION_LTR;
@ -291,7 +291,7 @@ public final class SuggestionStripView extends RelativeLayout implements OnClick
clear(); clear();
isExternalSuggestionVisible = true; isExternalSuggestionVisible = true;
mSuggestionsStrip.addView(view); mSuggestionsStrip.addView(view);
if (Settings.getInstance().getCurrent().mAutoHideToolbar) if (Settings.getValues().mAutoHideToolbar)
setToolbarVisibility(false); setToolbarVisibility(false);
} }
@ -383,7 +383,7 @@ public final class SuggestionStripView extends RelativeLayout implements OnClick
private void onLongClickToolKey(final View view) { private void onLongClickToolKey(final View view) {
if (!(view.getTag() instanceof ToolbarKey tag)) return; 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); final int longClickCode = getCodeForToolbarKeyLongClick(tag);
if (longClickCode != KeyCode.UNSPECIFIED) { if (longClickCode != KeyCode.UNSPECIFIED) {
mListener.onCodeInput(longClickCode, Constants.SUGGESTION_STRIP_COORDINATE, Constants.SUGGESTION_STRIP_COORDINATE, false); 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) { if (showIcon) {
final Drawable icon = mBinIcon; 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 w = icon.getIntrinsicWidth();
int h = icon.getIntrinsicWidth(); int h = icon.getIntrinsicWidth();
wordView.setCompoundDrawablesWithIntrinsicBounds(icon, null, null, null); wordView.setCompoundDrawablesWithIntrinsicBounds(icon, null, null, null);
@ -491,7 +491,7 @@ public final class SuggestionStripView extends RelativeLayout implements OnClick
getContext(), mSuggestedWords, mSuggestionsStrip, SuggestionStripView.this); getContext(), mSuggestedWords, mSuggestionsStrip, SuggestionStripView.this);
mStripVisibilityGroup.showSuggestionsStrip(); mStripVisibilityGroup.showSuggestionsStrip();
// Show the toolbar if no suggestions are left and the "Auto show toolbar" setting is enabled // 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); setToolbarVisibility(true);
} }
} }
@ -722,7 +722,7 @@ public final class SuggestionStripView extends RelativeLayout implements OnClick
copy.setImageDrawable(original.getDrawable()); copy.setImageDrawable(original.getDrawable());
copy.setLayoutParams(original.getLayoutParams()); copy.setLayoutParams(original.getLayoutParams());
copy.setActivated(original.isActivated()); copy.setActivated(original.isActivated());
setupKey(copy, Settings.getInstance().getCurrent().mColors); setupKey(copy, Settings.getValues().mColors);
mPinnedKeys.addView(copy); mPinnedKeys.addView(copy);
} }

View file

@ -52,7 +52,7 @@ import helium314.keyboard.latin.settings.Settings;
public class InlineAutofillUtils { public class InlineAutofillUtils {
public static InlineSuggestionsRequest createInlineSuggestionRequest(final Context context) { 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 chipBgDrawableId = androidx.autofill.R.drawable.autofill_inline_suggestion_chip_background;
final int chipBgColor = colors.get(ColorType.AUTOFILL_BACKGROUND_CHIP); final int chipBgColor = colors.get(ColorType.AUTOFILL_BACKGROUND_CHIP);
final int chipTextColor = colors.get(ColorType.KEY_TEXT); 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) { public static int getLanguageOnSpacebarFormatType(@NonNull final RichInputMethodSubtype subtype) {
if (!Settings.getInstance().getCurrent().mSpaceBarText.isEmpty()) if (!Settings.getValues().mSpaceBarText.isEmpty())
return FORMAT_TYPE_FULL_LOCALE; return FORMAT_TYPE_FULL_LOCALE;
if (subtype.isNoLanguage()) { if (subtype.isNoLanguage()) {
return FORMAT_TYPE_FULL_LOCALE; return FORMAT_TYPE_FULL_LOCALE;
} }
// Only this subtype is enabled and equals to the system 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; return FORMAT_TYPE_NONE;
} }
final Locale locale = subtype.getLocale(); final Locale locale = subtype.getLocale();

View file

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

View file

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

View file

@ -49,7 +49,7 @@ import kotlin.test.assertEquals
]) ])
class InputLogicTest { class InputLogicTest {
private lateinit var latinIME: LatinIME private lateinit var latinIME: LatinIME
private val settingsValues get() = Settings.getInstance().current private val settingsValues get() = Settings.getValues()
private val inputLogic get() = latinIME.mInputLogic private val inputLogic get() = latinIME.mInputLogic
private val connection: RichInputConnection get() = inputLogic.mConnection private val connection: RichInputConnection get() = inputLogic.mConnection
private val composerReader = InputLogic::class.java.getDeclaredField("mWordComposer").apply { isAccessible = true } private val composerReader = InputLogic::class.java.getDeclaredField("mWordComposer").apply { isAccessible = true }