diff --git a/java/res/values-land/dimens.xml b/java/res/values-land/dimens.xml index 4a5c5a44c79518aa5b51474d34d173fc7f70f2da..dcbfe463ed03e265a29fa28071308e9f69fab975 100644 --- a/java/res/values-land/dimens.xml +++ b/java/res/values-land/dimens.xml @@ -53,6 +53,7 @@ <fraction name="key_hint_label_ratio">52%</fraction> <fraction name="key_uppercase_letter_ratio">40%</fraction> <fraction name="key_preview_text_ratio">90%</fraction> + <fraction name="spacebar_text_ratio">40.000%</fraction> <dimen name="key_preview_offset">0.08in</dimen> <dimen name="key_preview_offset_ics">0.01in</dimen> diff --git a/java/res/values-sw600dp-land/dimens.xml b/java/res/values-sw600dp-land/dimens.xml index 1b8c8a64a4b07c1067ace9f41f9c7ac96c4a8ed0..1c725a48454bb2767410dc9b87000868cddea08f 100644 --- a/java/res/values-sw600dp-land/dimens.xml +++ b/java/res/values-sw600dp-land/dimens.xml @@ -48,6 +48,7 @@ <fraction name="key_hint_letter_ratio">23%</fraction> <fraction name="key_hint_label_ratio">34%</fraction> <fraction name="key_uppercase_letter_ratio">29%</fraction> + <fraction name="spacebar_text_ratio">33.33%</fraction> <dimen name="suggestions_strip_padding">40.0mm</dimen> <integer name="max_more_suggestions_row">5</integer> diff --git a/java/res/values-sw600dp/config.xml b/java/res/values-sw600dp/config.xml index 1854a869673db7bb14529dd317b6bc68525c7024..1dd93121d425e30fe927eeec5fe848ee50d985f7 100644 --- a/java/res/values-sw600dp/config.xml +++ b/java/res/values-sw600dp/config.xml @@ -38,6 +38,5 @@ <integer name="config_long_press_space_key_timeout">0</integer> <!-- This configuration is the index of the array {@link KeyboardSwitcher.KEYBOARD_THEMES}. --> <string name="config_default_keyboard_theme_id" translatable="false">5</string> - <string name="config_text_size_of_language_on_spacebar" translatable="false">medium</string> <integer name="config_max_more_keys_column">5</integer> </resources> diff --git a/java/res/values-sw600dp/dimens.xml b/java/res/values-sw600dp/dimens.xml index 31830239d746723265016239a7082b3b9d6eae1c..e393be5791c57628676e802412b0079bea27e070 100644 --- a/java/res/values-sw600dp/dimens.xml +++ b/java/res/values-sw600dp/dimens.xml @@ -59,6 +59,7 @@ <fraction name="key_hint_label_ratio">28%</fraction> <fraction name="key_uppercase_letter_ratio">26%</fraction> <fraction name="key_preview_text_ratio">50%</fraction> + <fraction name="spacebar_text_ratio">32.14%</fraction> <dimen name="key_preview_height">15.0mm</dimen> <dimen name="key_preview_offset">0.1in</dimen> diff --git a/java/res/values-sw768dp-land/dimens.xml b/java/res/values-sw768dp-land/dimens.xml index 664e8c159a978322ded97cf6e1038bd2472cfe70..ef39f4393ee0a35f5978d869c36c7882b652773e 100644 --- a/java/res/values-sw768dp-land/dimens.xml +++ b/java/res/values-sw768dp-land/dimens.xml @@ -52,6 +52,7 @@ <fraction name="key_hint_letter_ratio">23%</fraction> <fraction name="key_hint_label_ratio">28%</fraction> <fraction name="key_uppercase_letter_ratio">24%</fraction> + <fraction name="spacebar_text_ratio">24.00%</fraction> <dimen name="key_preview_height">17.0mm</dimen> <dimen name="key_preview_height_ics">26.5mm</dimen> diff --git a/java/res/values-sw768dp/config.xml b/java/res/values-sw768dp/config.xml index c25139a42ec6b7eb5e0bf022df9a1040d17f526c..06553a7c997aac8269988ee284831377b5a32eca 100644 --- a/java/res/values-sw768dp/config.xml +++ b/java/res/values-sw768dp/config.xml @@ -36,7 +36,6 @@ <integer name="config_long_press_space_key_timeout">0</integer> <!-- This configuration is the index of the array {@link KeyboardSwitcher.KEYBOARD_THEMES}. --> <string name="config_default_keyboard_theme_id" translatable="false">5</string> - <string name="config_text_size_of_language_on_spacebar" translatable="false">medium</string> <integer name="config_max_more_keys_column">5</integer> <!-- Screen metrics for logging. 0 = "mdpi phone screen" diff --git a/java/res/values-sw768dp/dimens.xml b/java/res/values-sw768dp/dimens.xml index bb4937dd57e01a6508b20a6f069ceeb138f1da20..dbbd844f0c6cfbbf033461124a4d35904a76bb7e 100644 --- a/java/res/values-sw768dp/dimens.xml +++ b/java/res/values-sw768dp/dimens.xml @@ -62,6 +62,7 @@ <fraction name="key_hint_label_ratio">28%</fraction> <fraction name="key_uppercase_letter_ratio">26%</fraction> <fraction name="key_preview_text_ratio">50%</fraction> + <fraction name="spacebar_text_ratio">29.03%</fraction> <dimen name="key_preview_height">15.0mm</dimen> <dimen name="key_preview_offset">0.1in</dimen> diff --git a/java/res/values/attrs.xml b/java/res/values/attrs.xml index d08564444ad6719949f86ad8c2974ce2e1a241e2..2e8a0030e6a41bc080b1c72ed3375b509aee320c 100644 --- a/java/res/values/attrs.xml +++ b/java/res/values/attrs.xml @@ -321,10 +321,13 @@ <attr name="parentStyle" format="string" /> </declare-styleable> + <!-- Move these attributes to LatinKeyboardView --> <declare-styleable name="LatinKeyboard"> <attr name="autoCorrectionSpacebarLedEnabled" format="boolean" /> <attr name="autoCorrectionSpacebarLedIcon" format="reference" /> <attr name="disabledShortcutIcon" format="reference" /> + <!-- Size of the text for spacebar language label, in the proportion of key height. --> + <attr name="spacebarTextRatio" format="fraction" /> <attr name="spacebarTextColor" format="color" /> <attr name="spacebarTextShadowColor" format="color" /> </declare-styleable> diff --git a/java/res/values/config.xml b/java/res/values/config.xml index 8b99a1fcb1cd959b37c23fd19b86aafd23336e76..55f35f0c5ddfd7aa3a6cdb253789b6a60423dff5 100644 --- a/java/res/values/config.xml +++ b/java/res/values/config.xml @@ -66,7 +66,6 @@ <dimen name="config_touch_noise_threshold_distance">2.0mm</dimen> <!-- This configuration is the index of the array {@link KeyboardSwitcher.KEYBOARD_THEMES}. --> <string name="config_default_keyboard_theme_id" translatable="false">5</string> - <string name="config_text_size_of_language_on_spacebar" translatable="false">small</string> <integer name="config_max_more_keys_column">5</integer> <string-array name="auto_correction_threshold_values" translatable="false"> <!-- Off, When auto correction setting is Off, this value is not used. --> diff --git a/java/res/values/dimens.xml b/java/res/values/dimens.xml index 352141ca6ed3fab6014ff2b25bc36118c17f339f..e46ff7718f3167df9bc731004ccd35886817ab95 100644 --- a/java/res/values/dimens.xml +++ b/java/res/values/dimens.xml @@ -66,6 +66,7 @@ <fraction name="key_hint_label_ratio">44%</fraction> <fraction name="key_uppercase_letter_ratio">35%</fraction> <fraction name="key_preview_text_ratio">82%</fraction> + <fraction name="spacebar_text_ratio">33.735%</fraction> <dimen name="key_preview_height">80sp</dimen> <dimen name="key_preview_offset">0.1in</dimen> diff --git a/java/res/values/styles.xml b/java/res/values/styles.xml index 2025a7dac562b0c17b6334af3769d6b7a7648a4a..ed8795ade4e2e3da3f4414613af8246a39939f35 100644 --- a/java/res/values/styles.xml +++ b/java/res/values/styles.xml @@ -33,6 +33,7 @@ </style> <style name="LatinKeyboard"> <item name="autoCorrectionSpacebarLedEnabled">true</item> + <item name="spacebarTextRatio">@fraction/spacebar_text_ratio</item> <item name="spacebarTextColor">#FFC0C0C0</item> <item name="spacebarTextShadowColor">#80000000</item> </style> diff --git a/java/src/com/android/inputmethod/keyboard/LatinKeyboard.java b/java/src/com/android/inputmethod/keyboard/LatinKeyboard.java index d34e4108b2c6591d7543edeb996be28f3578a6e6..78a02547bb4582c31fd7a620fb90435d690d2372 100644 --- a/java/src/com/android/inputmethod/keyboard/LatinKeyboard.java +++ b/java/src/com/android/inputmethod/keyboard/LatinKeyboard.java @@ -18,7 +18,6 @@ package com.android.inputmethod.keyboard; import android.content.Context; import android.content.res.Resources; -import android.content.res.Resources.Theme; import android.content.res.TypedArray; import android.graphics.Bitmap; import android.graphics.Canvas; @@ -45,13 +44,13 @@ public class LatinKeyboard extends Keyboard { private static final int SPACE_LED_LENGTH_PERCENT = 80; private final Resources mRes; - private final Theme mTheme; /* Space key and its icons, drawables and colors. */ private final Key mSpaceKey; private final Drawable mSpaceIcon; private final boolean mAutoCorrectionSpacebarLedEnabled; private final Drawable mAutoCorrectionSpacebarLedIcon; + private final float mSpacebarTextSize; private final int mSpacebarTextColor; private final int mSpacebarTextShadowColor; private final HashMap<Integer, BitmapDrawable> mSpaceDrawableCache = @@ -74,13 +73,9 @@ public class LatinKeyboard extends Keyboard { // its short language name will be used instead. private static final float MINIMUM_SCALE_OF_LANGUAGE_NAME = 0.8f; - private static final String SMALL_TEXT_SIZE_OF_LANGUAGE_ON_SPACEBAR = "small"; - private static final String MEDIUM_TEXT_SIZE_OF_LANGUAGE_ON_SPACEBAR = "medium"; - private LatinKeyboard(Context context, KeyboardParams params) { super(params); mRes = context.getResources(); - mTheme = context.getTheme(); // The index of space key is available only after Keyboard constructor has finished. mSpaceKey = getKey(CODE_SPACE); @@ -99,6 +94,10 @@ public class LatinKeyboard extends Keyboard { mAutoCorrectionSpacebarLedIcon = a.getDrawable( R.styleable.LatinKeyboard_autoCorrectionSpacebarLedIcon); mDisabledShortcutIcon = a.getDrawable(R.styleable.LatinKeyboard_disabledShortcutIcon); + final float spacebarTextRatio = a.getFraction(R.styleable.LatinKeyboard_spacebarTextRatio, + 1000, 1000, 1) / 1000.0f; + final int keyHeight = mMostCommonKeyHeight - mVerticalGap; + mSpacebarTextSize = keyHeight * spacebarTextRatio; mSpacebarTextColor = a.getColor(R.styleable.LatinKeyboard_spacebarTextColor, 0); mSpacebarTextShadowColor = a.getColor( R.styleable.LatinKeyboard_spacebarTextShadowColor, 0); @@ -116,6 +115,8 @@ public class LatinKeyboard extends Keyboard { } } + // TODO: Move this drawing method to LatinKeyboardView. + // TODO: Use Key.keyLabel to draw language name of spacebar. public Key updateSpacebarLanguage(float fadeFactor, boolean multipleEnabledIMEsOrSubtypes, boolean needsToDisplayLanguage) { mSpacebarTextFadeFactor = fadeFactor; @@ -131,6 +132,7 @@ public class LatinKeyboard extends Keyboard { return newColor; } + // TODO: Move this drawing method to LatinKeyboardView. public Key updateShortcutKey(boolean available) { if (mShortcutKey == null) return null; @@ -139,10 +141,12 @@ public class LatinKeyboard extends Keyboard { return mShortcutKey; } + // TODO: Get rid of this method public boolean needsAutoCorrectionSpacebarLed() { return mAutoCorrectionSpacebarLedEnabled; } + // TODO: Move this drawing method to LatinKeyboardView. /** * @return a key which should be invalidated. */ @@ -238,7 +242,6 @@ public class LatinKeyboard extends Keyboard { final int height = mSpaceIcon != null ? mSpaceIcon.getIntrinsicHeight() : mSpaceKey.mHeight; final Bitmap buffer = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888); final Canvas canvas = new Canvas(buffer); - final Resources res = mRes; canvas.drawColor(Color.TRANSPARENT, PorterDuff.Mode.CLEAR); // If application locales are explicitly selected. @@ -247,25 +250,7 @@ public class LatinKeyboard extends Keyboard { paint.setAntiAlias(true); paint.setTextAlign(Align.CENTER); - final String textSizeOfLanguageOnSpacebar = res.getString( - R.string.config_text_size_of_language_on_spacebar, - SMALL_TEXT_SIZE_OF_LANGUAGE_ON_SPACEBAR); - final int textStyle; - final int defaultTextSize; - if (MEDIUM_TEXT_SIZE_OF_LANGUAGE_ON_SPACEBAR.equals(textSizeOfLanguageOnSpacebar)) { - // TODO: TextAppearance_Medium depends on the current system wide font size - // settings. Probably should stop using this. - textStyle = android.R.style.TextAppearance_Medium; - defaultTextSize = 18; - } else { - // TODO: TextAppearance_Small depends on the current system wide font size - // settings. Probably should stop using this. - textStyle = android.R.style.TextAppearance_Small; - defaultTextSize = 14; - } - - final String language = layoutSpacebar(paint, inputLocale, width, getTextSizeFromTheme( - mTheme, textStyle, defaultTextSize)); + final String language = layoutSpacebar(paint, inputLocale, width, mSpacebarTextSize); // Draw language text with shadow // In case there is no space icon, we will place the language text at the center of @@ -305,15 +290,4 @@ public class LatinKeyboard extends Keyboard { return super.getNearestKeys(Math.max(0, Math.min(x, mOccupiedWidth - 1)), Math.max(0, Math.min(y, mOccupiedHeight - 1))); } - - private static final int[] ATTR_TEXT_SIZE = { android.R.attr.textSize }; - - private static int getTextSizeFromTheme(Theme theme, int style, int defValue) { - // TODO: This method should return text size that is independent from the current - // system wide font size settings. - final TypedArray a = theme.obtainStyledAttributes(style, ATTR_TEXT_SIZE); - final int textSize = a.getDimensionPixelSize(a.getResourceId(0, 0), defValue); - a.recycle(); - return textSize; - } }