properly reload on DPI changes

This commit is contained in:
Helium314 2025-01-05 14:47:03 +01:00
parent cd1ed0e1e7
commit c9b8dfd4c2
3 changed files with 15 additions and 8 deletions

View file

@ -13,6 +13,7 @@ import android.text.InputType;
import android.view.inputmethod.EditorInfo;
import helium314.keyboard.keyboard.internal.KeyboardBuilder;
import helium314.keyboard.keyboard.internal.KeyboardIconsSet;
import helium314.keyboard.keyboard.internal.KeyboardParams;
import helium314.keyboard.keyboard.internal.UniqueKeysCache;
import helium314.keyboard.keyboard.internal.keyboard_parser.LocaleKeyboardInfos;
@ -104,6 +105,7 @@ public final class KeyboardLayoutSet {
sKeyboardCache.clear();
sUniqueKeysCache.clear();
RawKeyboardParser.INSTANCE.clearCache();
KeyboardIconsSet.Companion.setNeedsReload(true);
}
KeyboardLayoutSet(final Context context, @NonNull final Params params) {

View file

@ -74,6 +74,7 @@ public final class KeyboardSwitcher implements KeyboardState.SwitchActions {
private Context mThemeContext;
private int mCurrentUiMode;
private int mCurrentOrientation;
private int mCurrentDpi;
@SuppressLint("StaticFieldLeak") // this is a keyboard, we want to keep it alive in background
private static final KeyboardSwitcher sInstance = new KeyboardSwitcher();
@ -112,18 +113,20 @@ public final class KeyboardSwitcher implements KeyboardState.SwitchActions {
mLatinIME.setInputView(onCreateInputView(displayContext, mIsHardwareAcceleratedDrawingEnabled));
}
private boolean updateKeyboardThemeAndContextThemeWrapper(final Context context,
final KeyboardTheme keyboardTheme) {
private boolean updateKeyboardThemeAndContextThemeWrapper(final Context context, final KeyboardTheme keyboardTheme) {
final Resources res = context.getResources();
if (mThemeContext == null
|| !keyboardTheme.equals(mKeyboardTheme)
|| mCurrentOrientation != context.getResources().getConfiguration().orientation
|| (mCurrentUiMode & Configuration.UI_MODE_NIGHT_MASK) != (context.getResources().getConfiguration().uiMode & Configuration.UI_MODE_NIGHT_MASK)
|| !mThemeContext.getResources().equals(context.getResources())
|| mCurrentDpi != res.getDisplayMetrics().densityDpi
|| 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)) {
mKeyboardTheme = keyboardTheme;
mThemeContext = new ContextThemeWrapper(context, keyboardTheme.mStyleId);
mCurrentUiMode = context.getResources().getConfiguration().uiMode;
mCurrentOrientation = context.getResources().getConfiguration().orientation;
mCurrentUiMode = res.getConfiguration().uiMode;
mCurrentOrientation = res.getConfiguration().orientation;
mCurrentDpi = res.getDisplayMetrics().densityDpi;
KeyboardLayoutSet.onKeyboardThemeChanged();
return true;
}

View file

@ -28,7 +28,7 @@ class KeyboardIconsSet private constructor() {
}
val overrideIds = customIconIds(context, prefs)
val ids = if (overrideIds.isEmpty()) defaultIds else defaultIds + overrideIds
if (ids == iconIds) return
if (!needsReload && ids == iconIds) return
iconIds = ids
iconsByName.clear()
ids.forEach { (name, id) ->
@ -40,6 +40,7 @@ class KeyboardIconsSet private constructor() {
Log.w(TAG, "Drawable resource for icon $name not found")
}
}
needsReload = false
}
fun getIconDrawable(name: String?): Drawable? = name?.lowercase(Locale.US)?.let {
@ -289,5 +290,6 @@ class KeyboardIconsSet private constructor() {
}
val instance = KeyboardIconsSet()
var needsReload = false
}
}