Fixed some text scaling issues. The keyboard should now look 'the same' on all screen sizes
This commit is contained in:
parent
d23efc4e60
commit
7d32a3fe4e
9 changed files with 85 additions and 26 deletions
|
|
@ -3,6 +3,7 @@ package io.github.sspanak.tt9.hacks;
|
|||
import android.content.Context;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.content.res.Configuration;
|
||||
import android.content.res.Resources;
|
||||
import android.os.Build;
|
||||
import android.view.KeyCharacterMap;
|
||||
import android.view.KeyEvent;
|
||||
|
|
@ -10,16 +11,33 @@ import android.view.KeyEvent;
|
|||
import androidx.annotation.NonNull;
|
||||
|
||||
public class DeviceInfo {
|
||||
private static Resources resources;
|
||||
|
||||
private static Resources getResources(Context context) {
|
||||
if (resources == null) {
|
||||
resources = context.getResources();
|
||||
}
|
||||
return resources;
|
||||
}
|
||||
|
||||
public static boolean isLandscapeOrientation(Context context) {
|
||||
return context.getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE;
|
||||
return getResources(context).getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE;
|
||||
}
|
||||
|
||||
public static int getScreenWidth(Context context) {
|
||||
return context.getResources().getDisplayMetrics().widthPixels;
|
||||
return getResources(context).getDisplayMetrics().widthPixels;
|
||||
}
|
||||
|
||||
public static int getScreenHeight(Context context) {
|
||||
return context.getResources().getDisplayMetrics().heightPixels;
|
||||
return getResources(context).getDisplayMetrics().heightPixels;
|
||||
}
|
||||
|
||||
public static float getScreenHeightDp(Context context) {
|
||||
return getScreenHeight(context) / getResources(context).getDisplayMetrics().density;
|
||||
}
|
||||
|
||||
public static float getScreenWidthDp(Context context) {
|
||||
return getScreenWidth(context) / getResources(context).getDisplayMetrics().density;
|
||||
}
|
||||
|
||||
public static boolean noBackspaceKey() {
|
||||
|
|
|
|||
|
|
@ -24,7 +24,9 @@ public class SettingsStore extends SettingsUI {
|
|||
public final static byte SLOW_QUERY_TIME = 50; // ms
|
||||
public final static int SLOW_QUERY_TIMEOUT = 3000; // ms
|
||||
public final static float SOFT_KEY_AMOUNT_OF_KEY_SIZE_FOR_SWIPE = 0.5f; // 1 = full key size
|
||||
public final static float SOFT_KEY_CONTENT_DEFAULT_SCALE = 1.15f; // % / 100
|
||||
public final static float SOFT_KEY_SCALE_SCREEN_COMPENSATION_NORMAL_HEIGHT = 360; // dp
|
||||
public final static float SOFT_KEY_SCALE_SCREEN_COMPENSATION_NORMAL_WIDTH = 640; // dp
|
||||
public final static float SOFT_KEY_SCALE_SCREEN_COMPENSATION_MAX = 1.4f;
|
||||
public final static int SOFT_KEY_DOUBLE_CLICK_DELAY = 500; // ms
|
||||
public final static int SOFT_KEY_REPEAT_DELAY = 40; // ms
|
||||
public final static int SOFT_KEY_TITLE_MAX_CHARS = 5;
|
||||
|
|
|
|||
|
|
@ -19,6 +19,7 @@ import android.widget.TextView;
|
|||
import androidx.annotation.Nullable;
|
||||
import androidx.appcompat.content.res.AppCompatResources;
|
||||
|
||||
import io.github.sspanak.tt9.hacks.DeviceInfo;
|
||||
import io.github.sspanak.tt9.ime.TraditionalT9;
|
||||
import io.github.sspanak.tt9.preferences.settings.SettingsStore;
|
||||
import io.github.sspanak.tt9.ui.Vibration;
|
||||
|
|
@ -44,6 +45,9 @@ public class SoftKey extends com.google.android.material.button.MaterialButton i
|
|||
private Drawable holdIcon = null;
|
||||
private RelativeLayout overlay = null;
|
||||
|
||||
private static float screenScaleX = 0;
|
||||
private static float screenScaleY = 0;
|
||||
|
||||
|
||||
public SoftKey(Context context) {
|
||||
super(context);
|
||||
|
|
@ -82,6 +86,34 @@ public class SoftKey extends com.google.android.material.button.MaterialButton i
|
|||
}
|
||||
|
||||
|
||||
protected float getScreenScaleX() {
|
||||
if (screenScaleX == 0) {
|
||||
boolean isLandscape = DeviceInfo.isLandscapeOrientation(getContext());
|
||||
float width = isLandscape ? DeviceInfo.getScreenWidthDp(getContext()) : DeviceInfo.getScreenHeightDp(getContext());
|
||||
|
||||
screenScaleX = Math.min(
|
||||
width / SettingsStore.SOFT_KEY_SCALE_SCREEN_COMPENSATION_NORMAL_WIDTH,
|
||||
SettingsStore.SOFT_KEY_SCALE_SCREEN_COMPENSATION_MAX
|
||||
);
|
||||
}
|
||||
return screenScaleX;
|
||||
}
|
||||
|
||||
|
||||
protected float getScreenScaleY() {
|
||||
if (screenScaleY == 0) {
|
||||
boolean isLandscape = DeviceInfo.isLandscapeOrientation(getContext());
|
||||
float height = isLandscape ? DeviceInfo.getScreenHeightDp(getContext()) : DeviceInfo.getScreenWidthDp(getContext());
|
||||
|
||||
screenScaleY = Math.min(
|
||||
height / SettingsStore.SOFT_KEY_SCALE_SCREEN_COMPENSATION_NORMAL_HEIGHT,
|
||||
SettingsStore.SOFT_KEY_SCALE_SCREEN_COMPENSATION_MAX
|
||||
);
|
||||
}
|
||||
return screenScaleY;
|
||||
}
|
||||
|
||||
|
||||
protected float getTT9Width() {
|
||||
return tt9 != null ? tt9.getSettings().getNumpadWidthPercent() / 100f : 1;
|
||||
}
|
||||
|
|
@ -305,10 +337,12 @@ public class SoftKey extends com.google.android.material.button.MaterialButton i
|
|||
|
||||
/**
|
||||
* Multiplier for the main text font size. Used for automatically adjusting the font size to fit
|
||||
* the key when changing the keyboard dimensions.
|
||||
* the key when changing the keyboard dimensions, and to look good on different screen sizes.
|
||||
*/
|
||||
protected float getTitleScale() {
|
||||
return SettingsStore.SOFT_KEY_CONTENT_DEFAULT_SCALE * Math.min(getTT9Width(), getTT9Height());
|
||||
float keyboardSizeScale = Math.max(0.7f, Math.min(getTT9Width(), getTT9Height()));
|
||||
float screenSizeScale = Math.min(getScreenScaleX(), getScreenScaleY());
|
||||
return keyboardSizeScale * screenSizeScale;
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -316,8 +350,9 @@ public class SoftKey extends com.google.android.material.button.MaterialButton i
|
|||
* Same as getTitleScale(), but for keys that have icons instead of text.
|
||||
*/
|
||||
protected float getCentralIconScale() {
|
||||
float width = getTT9Width();
|
||||
return width > 0.95f ? Math.min(1.15f, getTT9Height()) : Math.min(width, getTT9Height());
|
||||
float keyboardSizeScale = Math.max(0.7f, Math.min(getTT9Width(), getTT9Height()));
|
||||
keyboardSizeScale = Math.min(1.15f, keyboardSizeScale);
|
||||
return keyboardSizeScale * Math.min(getScreenScaleX(), getScreenScaleY());
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -325,7 +360,8 @@ public class SoftKey extends com.google.android.material.button.MaterialButton i
|
|||
* Similar to getTitleScale(), adjusts the font size of the hold text or icon
|
||||
*/
|
||||
protected float getHoldElementScale() {
|
||||
return SettingsStore.SOFT_KEY_CONTENT_DEFAULT_SCALE * Math.min(1, getTT9Height());
|
||||
float keyboardSizeScale = Math.min(1, Math.max(getTT9Width(), getTT9Height()));
|
||||
return keyboardSizeScale * Math.min(getScreenScaleX(), getScreenScaleY());
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -143,7 +143,7 @@ public class SoftKeyBackspace extends SwipeableKey {
|
|||
|
||||
@Override
|
||||
protected float getTitleScale() {
|
||||
float scale = tt9 != null && tt9.getSettings().isMainLayoutNumpad() ? super.getTitleScale() : SettingsStore.SOFT_KEY_CONTENT_DEFAULT_SCALE;
|
||||
float scale = tt9 != null && tt9.getSettings().isMainLayoutNumpad() ? super.getTitleScale() : 1;
|
||||
return scale * 1.1f;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -49,7 +49,7 @@ public class SoftKeyFilter extends SoftKey {
|
|||
@Override protected int getCentralIcon() { return isKorean() ? 0 : R.drawable.ic_fn_filter; }
|
||||
@Override protected int getHoldIcon() { return isKorean() ? 0 : R.drawable.ic_fn_filter_off; }
|
||||
|
||||
@Override protected float getTitleScale() { return isKorean() ? 1.5f * getTT9Height() : 1; }
|
||||
@Override protected float getTitleScale() { return isKorean() ? 1.3f * Math.min(1, getTT9Height()) * getScreenScaleY() : super.getTitleScale(); }
|
||||
|
||||
@Override
|
||||
public void render() {
|
||||
|
|
|
|||
|
|
@ -80,9 +80,12 @@ public class SoftKeyLF4 extends SwipeableKey {
|
|||
|
||||
if (areThereManyLanguages() && isKeySmall()) {
|
||||
setGravity(Gravity.CENTER_HORIZONTAL | Gravity.BOTTOM);
|
||||
} else {
|
||||
setPaddingRelative(0, 0, 0, 10);
|
||||
} else if (areThereManyLanguages()) {
|
||||
setPaddingRelative(0, 20, 0, 0);
|
||||
setGravity(Gravity.CENTER);
|
||||
} else {
|
||||
setGravity(Gravity.CENTER);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -63,7 +63,7 @@ public class SoftKeyNumber0 extends SoftKeyNumber {
|
|||
@Override
|
||||
protected float getTitleScale() {
|
||||
if (tt9 != null && !tt9.isInputModeNumeric() && !LanguageKind.isKorean(tt9.getLanguage())) {
|
||||
return 1.5f * getTT9Height();
|
||||
return 1.3f * Math.min(1, getTT9Height()) * getScreenScaleY();
|
||||
}
|
||||
|
||||
return super.getTitleScale();
|
||||
|
|
|
|||
|
|
@ -5,8 +5,8 @@
|
|||
to ignore the Android text size scale. We can't allow scaling because it breaks the layout.
|
||||
-->
|
||||
|
||||
<!-- standard font size for keys -->
|
||||
<dimen name="key_text_size">18dp</dimen>
|
||||
<!-- standard text size for keys -->
|
||||
<dimen name="key_text_size">21dp</dimen>
|
||||
|
||||
<!-- Status Bar -->
|
||||
<dimen name="status_bar_height">26sp</dimen>
|
||||
|
|
@ -18,15 +18,16 @@
|
|||
|
||||
<dimen name="main_small_main_key_wrapper_height">46dp</dimen> <!-- key height + margin -->
|
||||
<dimen name="main_small_command_palette_height">66dp</dimen>
|
||||
<dimen name="main_small_command_palette_key_text_size">18dp</dimen>
|
||||
|
||||
<!-- Preferences, default font size -->
|
||||
<!-- Preferences, default text size -->
|
||||
<dimen name="pref_custom_min_height">48dp</dimen>
|
||||
<dimen name="pref_custom_spacing_horizontal">16dp</dimen>
|
||||
<dimen name="pref_custom_spacing_vertical">12dp</dimen>
|
||||
<dimen name="pref_deletable_word_icon_size">32sp</dimen>
|
||||
<dimen name="pref_search_height">72dp</dimen>
|
||||
|
||||
<!-- Preferences, large font size -->
|
||||
<!-- Preferences, large text size -->
|
||||
<dimen name="large_pref_category_spacing_top">30dp</dimen>
|
||||
<dimen name="large_pref_category_spacing_bottom">12dp</dimen>
|
||||
|
||||
|
|
@ -49,16 +50,16 @@
|
|||
|
||||
<dimen name="numpad_key_overlay_z">666dp</dimen>
|
||||
<dimen name="numpad_key_overlay_side_text_size">9dp</dimen>
|
||||
<dimen name="numpad_key_overlay_hold_icon_size">13dp</dimen>
|
||||
<dimen name="numpad_key_overlay_hold_text_size">11dp</dimen>
|
||||
<dimen name="numpad_key_overlay_hold_icon_size">15dp</dimen>
|
||||
<dimen name="numpad_key_overlay_hold_text_size">13dp</dimen>
|
||||
|
||||
<dimen name="numpad_key_overlay_side_text_spacing">2dp</dimen>
|
||||
<dimen name="numpad_key_overlay_hold_icon_spacing_top">4dp</dimen>
|
||||
<dimen name="numpad_key_overlay_hold_icon_spacing_right">3dp</dimen>
|
||||
<dimen name="numpad_key_overlay_hold_text_spacing_top">3dp</dimen>
|
||||
<dimen name="numpad_key_overlay_hold_icon_spacing_top">1dp</dimen>
|
||||
<dimen name="numpad_key_overlay_hold_icon_spacing_right">1dp</dimen>
|
||||
<dimen name="numpad_key_overlay_hold_text_spacing_top">2dp</dimen>
|
||||
<dimen name="numpad_key_overlay_hold_text_spacing_right">5dp</dimen>
|
||||
|
||||
<dimen name="numpad_suggestion_font_size">17sp</dimen>
|
||||
<dimen name="numpad_suggestion_text_size">17sp</dimen>
|
||||
<dimen name="numpad_suggestion_height">40sp</dimen>
|
||||
<dimen name="numpad_suggestion_min_width">36sp</dimen>
|
||||
</resources>
|
||||
|
|
|
|||
|
|
@ -132,6 +132,7 @@
|
|||
<item name="android:paddingRight">0dp</item>
|
||||
<item name="android:paddingBottom">2dp</item>
|
||||
<item name="android:paddingLeft">0dp</item>
|
||||
<item name="android:textSize">@dimen/main_small_command_palette_key_text_size</item>
|
||||
</style>
|
||||
|
||||
|
||||
|
|
@ -193,7 +194,7 @@
|
|||
<item name="android:paddingLeft">@dimen/main_small_suggestion_spacing_horizontal</item>
|
||||
<item name="android:paddingRight">@dimen/main_small_suggestion_spacing_horizontal</item>
|
||||
|
||||
<item name="android:textSize">@dimen/numpad_suggestion_font_size</item>
|
||||
<item name="android:textSize">@dimen/numpad_suggestion_text_size</item>
|
||||
</style>
|
||||
|
||||
|
||||
|
|
@ -308,8 +309,6 @@
|
|||
<item name="android:layout_marginRight">@dimen/numpad_key_spacing</item>
|
||||
<item name="android:padding">0dp</item>
|
||||
|
||||
<item name="android:textSize">@dimen/key_text_size</item>
|
||||
|
||||
<item name="android:textColor">@color/key_fn_text</item>
|
||||
<item name="backgroundTint">@color/key_fn_background</item>
|
||||
<item name="rippleColor">@color/key_fn_ripple</item>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue