From 93704cca0ace3bff31dea5d3841ba185ad89398a Mon Sep 17 00:00:00 2001 From: Jules Aguillon Date: Tue, 28 Dec 2021 17:53:58 +0100 Subject: [PATCH] Reference the "special key font" in the Theme object Remove the last cast of the context. --- srcs/juloo.keyboard2/EmojiKeyButton.java | 2 +- srcs/juloo.keyboard2/Keyboard2.java | 7 ------- srcs/juloo.keyboard2/Theme.java | 17 ++++++++++++++--- 3 files changed, 15 insertions(+), 11 deletions(-) diff --git a/srcs/juloo.keyboard2/EmojiKeyButton.java b/srcs/juloo.keyboard2/EmojiKeyButton.java index 6f662b4..51ff14f 100644 --- a/srcs/juloo.keyboard2/EmojiKeyButton.java +++ b/srcs/juloo.keyboard2/EmojiKeyButton.java @@ -17,7 +17,7 @@ public class EmojiKeyButton extends Button _key = KeyValue.getKeyByName(attrs.getAttributeValue(null, "key")); setText(_key.symbol); if ((_key.flags & KeyValue.FLAG_KEY_FONT) != 0) - setTypeface(((Keyboard2)context).getSpecialKeyFont()); + setTypeface(Theme.getSpecialKeyFont(context)); } public void onClick(View v) diff --git a/srcs/juloo.keyboard2/Keyboard2.java b/srcs/juloo.keyboard2/Keyboard2.java index 0eb2a23..17c9d4e 100644 --- a/srcs/juloo.keyboard2/Keyboard2.java +++ b/srcs/juloo.keyboard2/Keyboard2.java @@ -31,7 +31,6 @@ public class Keyboard2 extends InputMethodService private Keyboard2View _keyboardView; private int _currentTextLayout; private ViewGroup _emojiPane = null; - private Typeface _specialKeyFont = null; private Config _config; @@ -52,7 +51,6 @@ public class Keyboard2 extends InputMethodService public void onCreate() { super.onCreate(); - _specialKeyFont = Typeface.createFromAsset(getAssets(), "fonts/keys.ttf"); PreferenceManager.setDefaultValues(this, R.xml.settings, false); PreferenceManager.getDefaultSharedPreferences(this).registerOnSharedPreferenceChangeListener(this); Config.initGlobalConfig(this, new KeyEventHandler(this.new Receiver())); @@ -61,11 +59,6 @@ public class Keyboard2 extends InputMethodService _keyboardView.reset(); } - public Typeface getSpecialKeyFont() - { - return (_specialKeyFont); - } - private List getEnabledSubtypes(InputMethodManager imm) { String pkg = getPackageName(); diff --git a/srcs/juloo.keyboard2/Theme.java b/srcs/juloo.keyboard2/Theme.java index 60c9b88..af2f3d7 100644 --- a/srcs/juloo.keyboard2/Theme.java +++ b/srcs/juloo.keyboard2/Theme.java @@ -35,9 +35,9 @@ public class Theme keyDownBgPaint.setColor(res.getColor(R.color.key_down_bg)); _keyLabelPaint = initLabelPaint(Paint.Align.CENTER, null); _keySubLabelPaint = initLabelPaint(Paint.Align.LEFT, null); - Typeface specialKeysFont = ((Keyboard2)context).getSpecialKeyFont(); - _specialKeyLabelPaint = initLabelPaint(Paint.Align.CENTER, specialKeysFont); - _specialKeySubLabelPaint = initLabelPaint(Paint.Align.LEFT, specialKeysFont); + Typeface specialKeyFont = getSpecialKeyFont(context); + _specialKeyLabelPaint = initLabelPaint(Paint.Align.CENTER, specialKeyFont); + _specialKeySubLabelPaint = initLabelPaint(Paint.Align.LEFT, specialKeyFont); } public Paint labelPaint(boolean special_font) @@ -61,4 +61,15 @@ public class Theme paint.setTypeface(font); return (paint); } + + private static Typeface _specialKeyFont = null; + + static public Typeface getSpecialKeyFont(Context context) + { + if (_specialKeyFont == null) + { + _specialKeyFont = Typeface.createFromAsset(context.getAssets(), "fonts/keys.ttf"); + } + return _specialKeyFont; + } }