Reference the "special key font" in the Theme object

Remove the last cast of the context.
This commit is contained in:
Jules Aguillon 2021-12-28 17:53:58 +01:00
parent 15ce200ce3
commit 93704cca0a
3 changed files with 15 additions and 11 deletions

View File

@ -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)

View File

@ -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<InputMethodSubtype> getEnabledSubtypes(InputMethodManager imm)
{
String pkg = getPackageName();

View File

@ -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;
}
}