mirror of
https://github.com/Helium314/HeliBoard.git
synced 2025-05-14 14:02:44 +00:00
properly reload on DPI changes
This commit is contained in:
parent
cd1ed0e1e7
commit
c9b8dfd4c2
3 changed files with 15 additions and 8 deletions
|
@ -13,6 +13,7 @@ import android.text.InputType;
|
||||||
import android.view.inputmethod.EditorInfo;
|
import android.view.inputmethod.EditorInfo;
|
||||||
|
|
||||||
import helium314.keyboard.keyboard.internal.KeyboardBuilder;
|
import helium314.keyboard.keyboard.internal.KeyboardBuilder;
|
||||||
|
import helium314.keyboard.keyboard.internal.KeyboardIconsSet;
|
||||||
import helium314.keyboard.keyboard.internal.KeyboardParams;
|
import helium314.keyboard.keyboard.internal.KeyboardParams;
|
||||||
import helium314.keyboard.keyboard.internal.UniqueKeysCache;
|
import helium314.keyboard.keyboard.internal.UniqueKeysCache;
|
||||||
import helium314.keyboard.keyboard.internal.keyboard_parser.LocaleKeyboardInfos;
|
import helium314.keyboard.keyboard.internal.keyboard_parser.LocaleKeyboardInfos;
|
||||||
|
@ -104,6 +105,7 @@ public final class KeyboardLayoutSet {
|
||||||
sKeyboardCache.clear();
|
sKeyboardCache.clear();
|
||||||
sUniqueKeysCache.clear();
|
sUniqueKeysCache.clear();
|
||||||
RawKeyboardParser.INSTANCE.clearCache();
|
RawKeyboardParser.INSTANCE.clearCache();
|
||||||
|
KeyboardIconsSet.Companion.setNeedsReload(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
KeyboardLayoutSet(final Context context, @NonNull final Params params) {
|
KeyboardLayoutSet(final Context context, @NonNull final Params params) {
|
||||||
|
|
|
@ -74,6 +74,7 @@ public final class KeyboardSwitcher implements KeyboardState.SwitchActions {
|
||||||
private Context mThemeContext;
|
private Context mThemeContext;
|
||||||
private int mCurrentUiMode;
|
private int mCurrentUiMode;
|
||||||
private int mCurrentOrientation;
|
private int mCurrentOrientation;
|
||||||
|
private int mCurrentDpi;
|
||||||
|
|
||||||
@SuppressLint("StaticFieldLeak") // this is a keyboard, we want to keep it alive in background
|
@SuppressLint("StaticFieldLeak") // this is a keyboard, we want to keep it alive in background
|
||||||
private static final KeyboardSwitcher sInstance = new KeyboardSwitcher();
|
private static final KeyboardSwitcher sInstance = new KeyboardSwitcher();
|
||||||
|
@ -112,18 +113,20 @@ public final class KeyboardSwitcher implements KeyboardState.SwitchActions {
|
||||||
mLatinIME.setInputView(onCreateInputView(displayContext, mIsHardwareAcceleratedDrawingEnabled));
|
mLatinIME.setInputView(onCreateInputView(displayContext, mIsHardwareAcceleratedDrawingEnabled));
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean updateKeyboardThemeAndContextThemeWrapper(final Context context,
|
private boolean updateKeyboardThemeAndContextThemeWrapper(final Context context, final KeyboardTheme keyboardTheme) {
|
||||||
final KeyboardTheme keyboardTheme) {
|
final Resources res = context.getResources();
|
||||||
if (mThemeContext == null
|
if (mThemeContext == null
|
||||||
|| !keyboardTheme.equals(mKeyboardTheme)
|
|| !keyboardTheme.equals(mKeyboardTheme)
|
||||||
|| mCurrentOrientation != context.getResources().getConfiguration().orientation
|
|| mCurrentDpi != res.getDisplayMetrics().densityDpi
|
||||||
|| (mCurrentUiMode & Configuration.UI_MODE_NIGHT_MASK) != (context.getResources().getConfiguration().uiMode & Configuration.UI_MODE_NIGHT_MASK)
|
|| mCurrentOrientation != res.getConfiguration().orientation
|
||||||
|| !mThemeContext.getResources().equals(context.getResources())
|
|| (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.getInstance().getCurrent().mColors.haveColorsChanged(context)) {
|
||||||
mKeyboardTheme = keyboardTheme;
|
mKeyboardTheme = keyboardTheme;
|
||||||
mThemeContext = new ContextThemeWrapper(context, keyboardTheme.mStyleId);
|
mThemeContext = new ContextThemeWrapper(context, keyboardTheme.mStyleId);
|
||||||
mCurrentUiMode = context.getResources().getConfiguration().uiMode;
|
mCurrentUiMode = res.getConfiguration().uiMode;
|
||||||
mCurrentOrientation = context.getResources().getConfiguration().orientation;
|
mCurrentOrientation = res.getConfiguration().orientation;
|
||||||
|
mCurrentDpi = res.getDisplayMetrics().densityDpi;
|
||||||
KeyboardLayoutSet.onKeyboardThemeChanged();
|
KeyboardLayoutSet.onKeyboardThemeChanged();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,7 +28,7 @@ class KeyboardIconsSet private constructor() {
|
||||||
}
|
}
|
||||||
val overrideIds = customIconIds(context, prefs)
|
val overrideIds = customIconIds(context, prefs)
|
||||||
val ids = if (overrideIds.isEmpty()) defaultIds else defaultIds + overrideIds
|
val ids = if (overrideIds.isEmpty()) defaultIds else defaultIds + overrideIds
|
||||||
if (ids == iconIds) return
|
if (!needsReload && ids == iconIds) return
|
||||||
iconIds = ids
|
iconIds = ids
|
||||||
iconsByName.clear()
|
iconsByName.clear()
|
||||||
ids.forEach { (name, id) ->
|
ids.forEach { (name, id) ->
|
||||||
|
@ -40,6 +40,7 @@ class KeyboardIconsSet private constructor() {
|
||||||
Log.w(TAG, "Drawable resource for icon $name not found")
|
Log.w(TAG, "Drawable resource for icon $name not found")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
needsReload = false
|
||||||
}
|
}
|
||||||
|
|
||||||
fun getIconDrawable(name: String?): Drawable? = name?.lowercase(Locale.US)?.let {
|
fun getIconDrawable(name: String?): Drawable? = name?.lowercase(Locale.US)?.let {
|
||||||
|
@ -289,5 +290,6 @@ class KeyboardIconsSet private constructor() {
|
||||||
}
|
}
|
||||||
|
|
||||||
val instance = KeyboardIconsSet()
|
val instance = KeyboardIconsSet()
|
||||||
|
var needsReload = false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue