2021-12-26 23:55:18 +01:00
|
|
|
package juloo.keyboard2;
|
|
|
|
|
|
|
|
import android.content.Context;
|
|
|
|
import android.content.res.Resources;
|
2021-12-28 19:12:50 +01:00
|
|
|
import android.content.res.TypedArray;
|
2021-12-26 23:55:18 +01:00
|
|
|
import android.graphics.Paint;
|
|
|
|
import android.graphics.Typeface;
|
|
|
|
import android.util.AttributeSet;
|
|
|
|
|
|
|
|
public class Theme
|
|
|
|
{
|
|
|
|
public final Paint keyBgPaint = new Paint();
|
|
|
|
public final Paint keyDownBgPaint = new Paint();
|
|
|
|
public final int lockedColor;
|
|
|
|
public final int activatedColor;
|
|
|
|
public final int labelColor;
|
|
|
|
public final int subLabelColor;
|
2021-12-30 00:52:50 +01:00
|
|
|
|
|
|
|
public final float keyBorderRadius;
|
|
|
|
|
2022-05-07 23:51:00 +02:00
|
|
|
public final int colorNavBar;
|
|
|
|
public final boolean isLightNavBar;
|
|
|
|
|
2021-12-26 23:55:18 +01:00
|
|
|
private final Paint _keyLabelPaint;
|
|
|
|
private final Paint _specialKeyLabelPaint;
|
|
|
|
private final Paint _keySubLabelPaint;
|
|
|
|
private final Paint _specialKeySubLabelPaint;
|
|
|
|
|
|
|
|
public Theme(Context context, AttributeSet attrs)
|
|
|
|
{
|
2021-12-30 00:26:05 +01:00
|
|
|
TypedArray s = context.getTheme().obtainStyledAttributes(attrs, R.styleable.keyboard, 0, 0);
|
2021-12-28 19:12:50 +01:00
|
|
|
keyBgPaint.setColor(s.getColor(R.styleable.keyboard_colorKey, 0));
|
|
|
|
keyDownBgPaint.setColor(s.getColor(R.styleable.keyboard_colorKeyActivated, 0));
|
|
|
|
// colorKeyboard = s.getColor(R.styleable.keyboard_colorKeyboard, 0);
|
2022-05-07 23:51:00 +02:00
|
|
|
colorNavBar = s.getColor(R.styleable.keyboard_navigationBarColor, 0);
|
|
|
|
isLightNavBar = s.getBoolean(R.styleable.keyboard_windowLightNavigationBar, false);
|
2021-12-28 19:12:50 +01:00
|
|
|
labelColor = s.getColor(R.styleable.keyboard_colorLabel, 0);
|
|
|
|
activatedColor = s.getColor(R.styleable.keyboard_colorLabelActivated, 0);
|
|
|
|
lockedColor = s.getColor(R.styleable.keyboard_colorLabelLocked, 0);
|
|
|
|
subLabelColor = s.getColor(R.styleable.keyboard_colorSubLabel, 0);
|
2021-12-30 00:52:50 +01:00
|
|
|
keyBorderRadius = s.getDimension(R.styleable.keyboard_keyBorderRadius, 0);
|
2021-12-28 19:12:50 +01:00
|
|
|
s.recycle();
|
2021-12-26 23:55:18 +01:00
|
|
|
_keyLabelPaint = initLabelPaint(Paint.Align.CENTER, null);
|
|
|
|
_keySubLabelPaint = initLabelPaint(Paint.Align.LEFT, null);
|
2022-09-19 11:41:18 +02:00
|
|
|
Typeface specialKeyFont = getKeyFont(context);
|
2021-12-28 17:53:58 +01:00
|
|
|
_specialKeyLabelPaint = initLabelPaint(Paint.Align.CENTER, specialKeyFont);
|
|
|
|
_specialKeySubLabelPaint = initLabelPaint(Paint.Align.LEFT, specialKeyFont);
|
2021-12-26 23:55:18 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public Paint labelPaint(boolean special_font)
|
|
|
|
{
|
|
|
|
Paint p = special_font ? _specialKeyLabelPaint : _keyLabelPaint;
|
|
|
|
return p;
|
|
|
|
}
|
|
|
|
|
2022-02-02 21:46:23 +01:00
|
|
|
public Paint subLabelPaint(boolean special_font, Paint.Align align)
|
2021-12-26 23:55:18 +01:00
|
|
|
{
|
|
|
|
Paint p = special_font ? _specialKeySubLabelPaint : _keySubLabelPaint;
|
2022-02-02 21:46:23 +01:00
|
|
|
p.setTextAlign(align);
|
2021-12-26 23:55:18 +01:00
|
|
|
return p;
|
|
|
|
}
|
|
|
|
|
|
|
|
private Paint initLabelPaint(Paint.Align align, Typeface font)
|
|
|
|
{
|
|
|
|
Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
|
|
|
|
paint.setTextAlign(align);
|
|
|
|
if (font != null)
|
|
|
|
paint.setTypeface(font);
|
|
|
|
return (paint);
|
|
|
|
}
|
2021-12-28 17:53:58 +01:00
|
|
|
|
2022-09-19 11:41:18 +02:00
|
|
|
private static Typeface _key_font = null;
|
2021-12-28 17:53:58 +01:00
|
|
|
|
2022-09-19 11:41:18 +02:00
|
|
|
static public Typeface getKeyFont(Context context)
|
2021-12-28 17:53:58 +01:00
|
|
|
{
|
2022-09-19 11:41:18 +02:00
|
|
|
if (_key_font == null)
|
|
|
|
_key_font = Typeface.createFromAsset(context.getAssets(), "special_font.ttf");
|
|
|
|
return _key_font;
|
2021-12-28 17:53:58 +01:00
|
|
|
}
|
2021-12-26 23:55:18 +01:00
|
|
|
}
|