Add LatinKeyboard.spacebarTextRatio attribute

Bug: 5776979
Change-Id: Ia568d1170ed33a000eb3bb02ecdf611e4b5ff2d5
main
Tadashi G. Takaoka 2011-12-18 00:58:47 +09:00
parent ebec5259b7
commit 7cc2595b6f
12 changed files with 21 additions and 40 deletions

View File

@ -53,6 +53,7 @@
<fraction name="key_hint_label_ratio">52%</fraction> <fraction name="key_hint_label_ratio">52%</fraction>
<fraction name="key_uppercase_letter_ratio">40%</fraction> <fraction name="key_uppercase_letter_ratio">40%</fraction>
<fraction name="key_preview_text_ratio">90%</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">0.08in</dimen>
<dimen name="key_preview_offset_ics">0.01in</dimen> <dimen name="key_preview_offset_ics">0.01in</dimen>

View File

@ -48,6 +48,7 @@
<fraction name="key_hint_letter_ratio">23%</fraction> <fraction name="key_hint_letter_ratio">23%</fraction>
<fraction name="key_hint_label_ratio">34%</fraction> <fraction name="key_hint_label_ratio">34%</fraction>
<fraction name="key_uppercase_letter_ratio">29%</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> <dimen name="suggestions_strip_padding">40.0mm</dimen>
<integer name="max_more_suggestions_row">5</integer> <integer name="max_more_suggestions_row">5</integer>

View File

@ -38,6 +38,5 @@
<integer name="config_long_press_space_key_timeout">0</integer> <integer name="config_long_press_space_key_timeout">0</integer>
<!-- This configuration is the index of the array {@link KeyboardSwitcher.KEYBOARD_THEMES}. --> <!-- 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_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> <integer name="config_max_more_keys_column">5</integer>
</resources> </resources>

View File

@ -59,6 +59,7 @@
<fraction name="key_hint_label_ratio">28%</fraction> <fraction name="key_hint_label_ratio">28%</fraction>
<fraction name="key_uppercase_letter_ratio">26%</fraction> <fraction name="key_uppercase_letter_ratio">26%</fraction>
<fraction name="key_preview_text_ratio">50%</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_height">15.0mm</dimen>
<dimen name="key_preview_offset">0.1in</dimen> <dimen name="key_preview_offset">0.1in</dimen>

View File

@ -52,6 +52,7 @@
<fraction name="key_hint_letter_ratio">23%</fraction> <fraction name="key_hint_letter_ratio">23%</fraction>
<fraction name="key_hint_label_ratio">28%</fraction> <fraction name="key_hint_label_ratio">28%</fraction>
<fraction name="key_uppercase_letter_ratio">24%</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">17.0mm</dimen>
<dimen name="key_preview_height_ics">26.5mm</dimen> <dimen name="key_preview_height_ics">26.5mm</dimen>

View File

@ -36,7 +36,6 @@
<integer name="config_long_press_space_key_timeout">0</integer> <integer name="config_long_press_space_key_timeout">0</integer>
<!-- This configuration is the index of the array {@link KeyboardSwitcher.KEYBOARD_THEMES}. --> <!-- 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_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> <integer name="config_max_more_keys_column">5</integer>
<!-- Screen metrics for logging. <!-- Screen metrics for logging.
0 = "mdpi phone screen" 0 = "mdpi phone screen"

View File

@ -62,6 +62,7 @@
<fraction name="key_hint_label_ratio">28%</fraction> <fraction name="key_hint_label_ratio">28%</fraction>
<fraction name="key_uppercase_letter_ratio">26%</fraction> <fraction name="key_uppercase_letter_ratio">26%</fraction>
<fraction name="key_preview_text_ratio">50%</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_height">15.0mm</dimen>
<dimen name="key_preview_offset">0.1in</dimen> <dimen name="key_preview_offset">0.1in</dimen>

View File

@ -321,10 +321,13 @@
<attr name="parentStyle" format="string" /> <attr name="parentStyle" format="string" />
</declare-styleable> </declare-styleable>
<!-- Move these attributes to LatinKeyboardView -->
<declare-styleable name="LatinKeyboard"> <declare-styleable name="LatinKeyboard">
<attr name="autoCorrectionSpacebarLedEnabled" format="boolean" /> <attr name="autoCorrectionSpacebarLedEnabled" format="boolean" />
<attr name="autoCorrectionSpacebarLedIcon" format="reference" /> <attr name="autoCorrectionSpacebarLedIcon" format="reference" />
<attr name="disabledShortcutIcon" 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="spacebarTextColor" format="color" />
<attr name="spacebarTextShadowColor" format="color" /> <attr name="spacebarTextShadowColor" format="color" />
</declare-styleable> </declare-styleable>

View File

@ -66,7 +66,6 @@
<dimen name="config_touch_noise_threshold_distance">2.0mm</dimen> <dimen name="config_touch_noise_threshold_distance">2.0mm</dimen>
<!-- This configuration is the index of the array {@link KeyboardSwitcher.KEYBOARD_THEMES}. --> <!-- 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_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> <integer name="config_max_more_keys_column">5</integer>
<string-array name="auto_correction_threshold_values" translatable="false"> <string-array name="auto_correction_threshold_values" translatable="false">
<!-- Off, When auto correction setting is Off, this value is not used. --> <!-- Off, When auto correction setting is Off, this value is not used. -->

View File

@ -66,6 +66,7 @@
<fraction name="key_hint_label_ratio">44%</fraction> <fraction name="key_hint_label_ratio">44%</fraction>
<fraction name="key_uppercase_letter_ratio">35%</fraction> <fraction name="key_uppercase_letter_ratio">35%</fraction>
<fraction name="key_preview_text_ratio">82%</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_height">80sp</dimen>
<dimen name="key_preview_offset">0.1in</dimen> <dimen name="key_preview_offset">0.1in</dimen>

View File

@ -33,6 +33,7 @@
</style> </style>
<style name="LatinKeyboard"> <style name="LatinKeyboard">
<item name="autoCorrectionSpacebarLedEnabled">true</item> <item name="autoCorrectionSpacebarLedEnabled">true</item>
<item name="spacebarTextRatio">@fraction/spacebar_text_ratio</item>
<item name="spacebarTextColor">#FFC0C0C0</item> <item name="spacebarTextColor">#FFC0C0C0</item>
<item name="spacebarTextShadowColor">#80000000</item> <item name="spacebarTextShadowColor">#80000000</item>
</style> </style>

View File

@ -18,7 +18,6 @@ package com.android.inputmethod.keyboard;
import android.content.Context; import android.content.Context;
import android.content.res.Resources; import android.content.res.Resources;
import android.content.res.Resources.Theme;
import android.content.res.TypedArray; import android.content.res.TypedArray;
import android.graphics.Bitmap; import android.graphics.Bitmap;
import android.graphics.Canvas; import android.graphics.Canvas;
@ -45,13 +44,13 @@ public class LatinKeyboard extends Keyboard {
private static final int SPACE_LED_LENGTH_PERCENT = 80; private static final int SPACE_LED_LENGTH_PERCENT = 80;
private final Resources mRes; private final Resources mRes;
private final Theme mTheme;
/* Space key and its icons, drawables and colors. */ /* Space key and its icons, drawables and colors. */
private final Key mSpaceKey; private final Key mSpaceKey;
private final Drawable mSpaceIcon; private final Drawable mSpaceIcon;
private final boolean mAutoCorrectionSpacebarLedEnabled; private final boolean mAutoCorrectionSpacebarLedEnabled;
private final Drawable mAutoCorrectionSpacebarLedIcon; private final Drawable mAutoCorrectionSpacebarLedIcon;
private final float mSpacebarTextSize;
private final int mSpacebarTextColor; private final int mSpacebarTextColor;
private final int mSpacebarTextShadowColor; private final int mSpacebarTextShadowColor;
private final HashMap<Integer, BitmapDrawable> mSpaceDrawableCache = private final HashMap<Integer, BitmapDrawable> mSpaceDrawableCache =
@ -74,13 +73,9 @@ public class LatinKeyboard extends Keyboard {
// its short language name will be used instead. // its short language name will be used instead.
private static final float MINIMUM_SCALE_OF_LANGUAGE_NAME = 0.8f; 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) { private LatinKeyboard(Context context, KeyboardParams params) {
super(params); super(params);
mRes = context.getResources(); mRes = context.getResources();
mTheme = context.getTheme();
// The index of space key is available only after Keyboard constructor has finished. // The index of space key is available only after Keyboard constructor has finished.
mSpaceKey = getKey(CODE_SPACE); mSpaceKey = getKey(CODE_SPACE);
@ -99,6 +94,10 @@ public class LatinKeyboard extends Keyboard {
mAutoCorrectionSpacebarLedIcon = a.getDrawable( mAutoCorrectionSpacebarLedIcon = a.getDrawable(
R.styleable.LatinKeyboard_autoCorrectionSpacebarLedIcon); R.styleable.LatinKeyboard_autoCorrectionSpacebarLedIcon);
mDisabledShortcutIcon = a.getDrawable(R.styleable.LatinKeyboard_disabledShortcutIcon); 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); mSpacebarTextColor = a.getColor(R.styleable.LatinKeyboard_spacebarTextColor, 0);
mSpacebarTextShadowColor = a.getColor( mSpacebarTextShadowColor = a.getColor(
R.styleable.LatinKeyboard_spacebarTextShadowColor, 0); 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, public Key updateSpacebarLanguage(float fadeFactor, boolean multipleEnabledIMEsOrSubtypes,
boolean needsToDisplayLanguage) { boolean needsToDisplayLanguage) {
mSpacebarTextFadeFactor = fadeFactor; mSpacebarTextFadeFactor = fadeFactor;
@ -131,6 +132,7 @@ public class LatinKeyboard extends Keyboard {
return newColor; return newColor;
} }
// TODO: Move this drawing method to LatinKeyboardView.
public Key updateShortcutKey(boolean available) { public Key updateShortcutKey(boolean available) {
if (mShortcutKey == null) if (mShortcutKey == null)
return null; return null;
@ -139,10 +141,12 @@ public class LatinKeyboard extends Keyboard {
return mShortcutKey; return mShortcutKey;
} }
// TODO: Get rid of this method
public boolean needsAutoCorrectionSpacebarLed() { public boolean needsAutoCorrectionSpacebarLed() {
return mAutoCorrectionSpacebarLedEnabled; return mAutoCorrectionSpacebarLedEnabled;
} }
// TODO: Move this drawing method to LatinKeyboardView.
/** /**
* @return a key which should be invalidated. * @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 int height = mSpaceIcon != null ? mSpaceIcon.getIntrinsicHeight() : mSpaceKey.mHeight;
final Bitmap buffer = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888); final Bitmap buffer = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
final Canvas canvas = new Canvas(buffer); final Canvas canvas = new Canvas(buffer);
final Resources res = mRes;
canvas.drawColor(Color.TRANSPARENT, PorterDuff.Mode.CLEAR); canvas.drawColor(Color.TRANSPARENT, PorterDuff.Mode.CLEAR);
// If application locales are explicitly selected. // If application locales are explicitly selected.
@ -247,25 +250,7 @@ public class LatinKeyboard extends Keyboard {
paint.setAntiAlias(true); paint.setAntiAlias(true);
paint.setTextAlign(Align.CENTER); paint.setTextAlign(Align.CENTER);
final String textSizeOfLanguageOnSpacebar = res.getString( final String language = layoutSpacebar(paint, inputLocale, width, mSpacebarTextSize);
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));
// Draw language text with shadow // Draw language text with shadow
// In case there is no space icon, we will place the language text at the center of // 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)), return super.getNearestKeys(Math.max(0, Math.min(x, mOccupiedWidth - 1)),
Math.max(0, Math.min(y, mOccupiedHeight - 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;
}
} }