1
0
Fork 0

simplified the virtual key title size configuration

This commit is contained in:
sspanak 2024-09-20 17:48:38 +03:00 committed by Dimo Karaivanov
parent 671a2c2d15
commit 8d4dd1f067
6 changed files with 59 additions and 41 deletions

View file

@ -29,9 +29,6 @@ public class SoftKey extends androidx.appcompat.widget.AppCompatButton implement
protected TraditionalT9 tt9; protected TraditionalT9 tt9;
protected Vibration vibration; protected Vibration vibration;
protected float complexLabelTitleSize = SettingsStore.SOFT_KEY_COMPLEX_LABEL_TITLE_RELATIVE_SIZE;
protected float complexLabelSubTitleSize = SettingsStore.SOFT_KEY_COMPLEX_LABEL_SUB_TITLE_RELATIVE_SIZE;
private boolean hold = false; private boolean hold = false;
private boolean repeat = false; private boolean repeat = false;
private long lastLongClickTime = 0; private long lastLongClickTime = 0;
@ -230,6 +227,23 @@ public class SoftKey extends androidx.appcompat.widget.AppCompatButton implement
} }
/**
* Multiplier for the title font size.
*/
protected float getTitleRelativeSize() {
return SettingsStore.SOFT_KEY_COMPLEX_LABEL_TITLE_RELATIVE_SIZE;
}
/**
* Multiplier for the subtitle font size.
*/
protected float getSubTitleRelativeSize() {
return SettingsStore.SOFT_KEY_COMPLEX_LABEL_SUB_TITLE_RELATIVE_SIZE;
}
/** /**
* render * render
* Sets the key label using "getTitle()" and "getSubtitle()" or if they both * Sets the key label using "getTitle()" and "getSubtitle()" or if they both
@ -257,16 +271,16 @@ public class SoftKey extends androidx.appcompat.widget.AppCompatButton implement
sb.append(subtitle); sb.append(subtitle);
float padding = SettingsStore.SOFT_KEY_COMPLEX_LABEL_TITLE_RELATIVE_SIZE; float padding = SettingsStore.SOFT_KEY_COMPLEX_LABEL_TITLE_RELATIVE_SIZE;
if (complexLabelTitleSize == SettingsStore.SOFT_KEY_COMPLEX_LABEL_ARABIC_TITLE_RELATIVE_SIZE) { if (getTitleRelativeSize() == SettingsStore.SOFT_KEY_COMPLEX_LABEL_ARABIC_TITLE_RELATIVE_SIZE) {
padding /= 10; padding /= 10;
} }
sb.setSpan(new RelativeSizeSpan(complexLabelTitleSize), 0, titleLength, Spanned.SPAN_INCLUSIVE_INCLUSIVE); sb.setSpan(new RelativeSizeSpan(getTitleRelativeSize()), 0, titleLength, Spanned.SPAN_INCLUSIVE_INCLUSIVE);
if (!new Text(title).startsWithGraphic()) { if (!new Text(title).startsWithGraphic()) {
sb.setSpan(new StyleSpan(Typeface.ITALIC), 0, titleLength, Spanned.SPAN_EXCLUSIVE_INCLUSIVE); sb.setSpan(new StyleSpan(Typeface.ITALIC), 0, titleLength, Spanned.SPAN_EXCLUSIVE_INCLUSIVE);
} }
sb.setSpan(new RelativeSizeSpan(padding), titleLength, titleLength + 1, Spanned.SPAN_INCLUSIVE_INCLUSIVE); sb.setSpan(new RelativeSizeSpan(padding), titleLength, titleLength + 1, Spanned.SPAN_INCLUSIVE_INCLUSIVE);
sb.setSpan(new RelativeSizeSpan(complexLabelSubTitleSize), titleLength + 1, sb.length(), Spanned.SPAN_INCLUSIVE_INCLUSIVE); sb.setSpan(new RelativeSizeSpan(getSubTitleRelativeSize()), titleLength + 1, sb.length(), Spanned.SPAN_INCLUSIVE_INCLUSIVE);
setText(sb); setText(sb);
} }

View file

@ -7,14 +7,12 @@ import io.github.sspanak.tt9.preferences.settings.SettingsStore;
import io.github.sspanak.tt9.ui.Vibration; import io.github.sspanak.tt9.ui.Vibration;
public class SoftKeyFilter extends SoftKey { public class SoftKeyFilter extends SoftKey {
public SoftKeyFilter(Context context) { super(context); setFontSize(); } public SoftKeyFilter(Context context) { super(context); }
public SoftKeyFilter(Context context, AttributeSet attrs) { super(context, attrs); setFontSize(); } public SoftKeyFilter(Context context, AttributeSet attrs) { super(context, attrs); }
public SoftKeyFilter(Context context, AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); setFontSize(); } public SoftKeyFilter(Context context, AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); }
private void setFontSize() { @Override protected float getTitleRelativeSize() { return super.getTitleRelativeSize() / 0.85f; }
complexLabelTitleSize = SettingsStore.SOFT_KEY_COMPLEX_LABEL_TITLE_RELATIVE_SIZE / 0.85f; @Override protected float getSubTitleRelativeSize() { return super.getSubTitleRelativeSize() / 0.85f; }
complexLabelSubTitleSize = SettingsStore.SOFT_KEY_COMPLEX_LABEL_SUB_TITLE_RELATIVE_SIZE / 0.85f;
}
@Override @Override
protected void handleHold() { protected void handleHold() {

View file

@ -18,6 +18,8 @@ public class SoftKeyFn extends SoftKeyNumber {
public SoftKeyFn(Context context, AttributeSet attrs) { super(context, attrs);} public SoftKeyFn(Context context, AttributeSet attrs) { super(context, attrs);}
public SoftKeyFn(Context context, AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr);} public SoftKeyFn(Context context, AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr);}
@Override protected float getSubTitleRelativeSize() { return super.getSubTitleRelativeSize() * 0.8f; }
@Override protected void handleHold() { @Override protected void handleHold() {
preventRepeat(); preventRepeat();
@ -50,7 +52,6 @@ public class SoftKeyFn extends SoftKeyNumber {
protected String getTextSubTitle(int resId) { protected String getTextSubTitle(int resId) {
complexLabelSubTitleSize = SettingsStore.SOFT_KEY_COMPLEX_LABEL_SUB_TITLE_RELATIVE_SIZE * 0.8f;
return getContext().getString(resId); return getContext().getString(resId);
} }

View file

@ -8,23 +8,12 @@ import io.github.sspanak.tt9.preferences.settings.SettingsStore;
import io.github.sspanak.tt9.ui.Vibration; import io.github.sspanak.tt9.ui.Vibration;
public class SoftKeyLF4 extends SwipeableKey { public class SoftKeyLF4 extends SwipeableKey {
public SoftKeyLF4(Context context) { public SoftKeyLF4(Context context) { super(context); }
super(context); public SoftKeyLF4(Context context, AttributeSet attrs) { super(context, attrs); }
setFontSize(); public SoftKeyLF4(Context context, AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); }
}
public SoftKeyLF4(Context context, AttributeSet attrs) {
super(context, attrs);
setFontSize();
}
public SoftKeyLF4(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
setFontSize();
}
private void setFontSize() { @Override protected float getTitleRelativeSize() { return super.getTitleRelativeSize() / 0.85f; }
complexLabelTitleSize = SettingsStore.SOFT_KEY_COMPLEX_LABEL_TITLE_RELATIVE_SIZE / 0.85f; @Override protected float getSubTitleRelativeSize() { return super.getSubTitleRelativeSize() / 0.85f; }
complexLabelSubTitleSize = SettingsStore.SOFT_KEY_COMPLEX_LABEL_SUB_TITLE_RELATIVE_SIZE / 0.85f;
}
@Override @Override
protected void handleHold() { protected void handleHold() {

View file

@ -60,6 +60,27 @@ public class SoftKeyNumber extends SoftKey {
} }
private boolean isArabicNumber() {
return tt9 != null && !tt9.isInputModeNumeric() && LanguageKind.isArabic(tt9.getLanguage());
}
@Override
protected float getTitleRelativeSize() {
return isArabicNumber() ? SettingsStore.SOFT_KEY_COMPLEX_LABEL_ARABIC_TITLE_RELATIVE_SIZE : SettingsStore.SOFT_KEY_COMPLEX_LABEL_TITLE_RELATIVE_SIZE;
}
@Override
protected float getSubTitleRelativeSize() {
if (tt9 != null && !tt9.isInputModeNumeric() && getNumber(getId()) == 0) {
return 1.1f;
}
return super.getSubTitleRelativeSize();
}
@Override @Override
protected void handleHold() { protected void handleHold() {
preventRepeat(); preventRepeat();
@ -109,11 +130,9 @@ public class SoftKeyNumber extends SoftKey {
protected String getTitle() { protected String getTitle() {
int number = getNumber(getId()); int number = getNumber(getId());
if (tt9 != null && !tt9.isInputModeNumeric() && LanguageKind.isArabic(tt9.getLanguage())) { if (isArabicNumber() && tt9.getLanguage() != null) {
complexLabelTitleSize = SettingsStore.SOFT_KEY_COMPLEX_LABEL_ARABIC_TITLE_RELATIVE_SIZE;
return tt9.getLanguage().getKeyNumber(number); return tt9.getLanguage().getKeyNumber(number);
} else { } else {
complexLabelTitleSize = SettingsStore.SOFT_KEY_COMPLEX_LABEL_TITLE_RELATIVE_SIZE;
return String.valueOf(number); return String.valueOf(number);
} }
} }
@ -146,7 +165,6 @@ public class SoftKeyNumber extends SoftKey {
} else if (tt9.isInputModeNumeric()) { } else if (tt9.isInputModeNumeric()) {
return "+"; return "+";
} else { } else {
complexLabelSubTitleSize = 1;
return ""; return "";
} }
} }

View file

@ -7,14 +7,12 @@ import io.github.sspanak.tt9.R;
import io.github.sspanak.tt9.preferences.settings.SettingsStore; import io.github.sspanak.tt9.preferences.settings.SettingsStore;
public class SoftKeyRF3 extends SoftKey { public class SoftKeyRF3 extends SoftKey {
public SoftKeyRF3(Context context) { super(context); setFontSize(); } public SoftKeyRF3(Context context) { super(context); }
public SoftKeyRF3(Context context, AttributeSet attrs) { super(context, attrs); setFontSize(); } public SoftKeyRF3(Context context, AttributeSet attrs) { super(context, attrs); }
public SoftKeyRF3(Context context, AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); setFontSize(); } public SoftKeyRF3(Context context, AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); }
private void setFontSize() { @Override protected float getTitleRelativeSize() { return super.getTitleRelativeSize() / 0.85f; }
complexLabelTitleSize = SettingsStore.SOFT_KEY_COMPLEX_LABEL_TITLE_RELATIVE_SIZE / 0.85f; @Override protected float getSubTitleRelativeSize() { return super.getSubTitleRelativeSize() / 0.85f; }
complexLabelSubTitleSize = SettingsStore.SOFT_KEY_COMPLEX_LABEL_SUB_TITLE_RELATIVE_SIZE / 0.85f;
}
private boolean isVoiceInputMissing() { private boolean isVoiceInputMissing() {
return tt9 != null && tt9.isVoiceInputMissing(); return tt9 != null && tt9.isVoiceInputMissing();