From 676fb5b665127f43b7062dfa5ebeb36b1e9f9280 Mon Sep 17 00:00:00 2001 From: Amith Yamasani Date: Fri, 5 Feb 2010 16:24:40 -0800 Subject: [PATCH] Use title-case for language name on spacebar, even for the abbrev. And fix a bug in opening keyboard settings when Voice is not available. --- .../latin/InputLanguageSelection.java | 19 ++--- .../inputmethod/latin/LanguageSwitcher.java | 8 +++ .../inputmethod/latin/LatinIMESettings.java | 5 +- .../inputmethod/latin/LatinKeyboard.java | 72 ++++++++++--------- 4 files changed, 57 insertions(+), 47 deletions(-) diff --git a/src/com/android/inputmethod/latin/InputLanguageSelection.java b/src/com/android/inputmethod/latin/InputLanguageSelection.java index 47ace7a6f..2c5fec6e8 100644 --- a/src/com/android/inputmethod/latin/InputLanguageSelection.java +++ b/src/com/android/inputmethod/latin/InputLanguageSelection.java @@ -70,7 +70,7 @@ public class InputLanguageSelection extends PreferenceActivity { for (int i = 0; i < mAvailableLanguages.size(); i++) { CheckBoxPreference pref = new CheckBoxPreference(this); Locale locale = mAvailableLanguages.get(i).locale; - pref.setTitle(toTitleCase(locale.getDisplayName(locale))); + pref.setTitle(LanguageSwitcher.toTitleCase(locale.getDisplayName(locale))); boolean checked = isLocaleIn(locale, languageList); pref.setChecked(checked); parent.addPreference(pref); @@ -138,7 +138,7 @@ public class InputLanguageSelection extends PreferenceActivity { if (finalSize == 0) { preprocess[finalSize++] = - new Loc(toTitleCase(l.getDisplayName(l)), l); + new Loc(LanguageSwitcher.toTitleCase(l.getDisplayName(l)), l); } else { // check previous entry: // same lang and a country -> upgrade to full name and @@ -146,15 +146,15 @@ public class InputLanguageSelection extends PreferenceActivity { // diff lang -> insert ours with lang-only name if (preprocess[finalSize-1].locale.getLanguage().equals( language)) { - preprocess[finalSize-1].label = toTitleCase( + preprocess[finalSize-1].label = LanguageSwitcher.toTitleCase( preprocess[finalSize-1].locale.getDisplayName()); preprocess[finalSize++] = - new Loc(toTitleCase(l.getDisplayName()), l); + new Loc(LanguageSwitcher.toTitleCase(l.getDisplayName()), l); } else { String displayName; if (s.equals("zz_ZZ")) { } else { - displayName = toTitleCase(l.getDisplayName(l)); + displayName = LanguageSwitcher.toTitleCase(l.getDisplayName(l)); preprocess[finalSize++] = new Loc(displayName, l); } } @@ -166,13 +166,4 @@ public class InputLanguageSelection extends PreferenceActivity { } return uniqueLocales; } - - private static String toTitleCase(String s) { - if (s.length() == 0) { - return s; - } - - return Character.toUpperCase(s.charAt(0)) + s.substring(1); - } - } diff --git a/src/com/android/inputmethod/latin/LanguageSwitcher.java b/src/com/android/inputmethod/latin/LanguageSwitcher.java index 3fa882e44..68d0d15cc 100644 --- a/src/com/android/inputmethod/latin/LanguageSwitcher.java +++ b/src/com/android/inputmethod/latin/LanguageSwitcher.java @@ -169,4 +169,12 @@ public class LanguageSwitcher { editor.putString(LatinIME.PREF_INPUT_LANGUAGE, getInputLanguage()); editor.commit(); } + + static String toTitleCase(String s) { + if (s.length() == 0) { + return s; + } + + return Character.toUpperCase(s.charAt(0)) + s.substring(1); + } } diff --git a/src/com/android/inputmethod/latin/LatinIMESettings.java b/src/com/android/inputmethod/latin/LatinIMESettings.java index 98a0af9d1..14725cb08 100644 --- a/src/com/android/inputmethod/latin/LatinIMESettings.java +++ b/src/com/android/inputmethod/latin/LatinIMESettings.java @@ -48,6 +48,7 @@ public class LatinIMESettings extends PreferenceActivity private static final String SHOW_SUGGESTIONS_KEY = "show_suggestions"; private static final String PREDICTION_SETTINGS_KEY = "prediction_settings"; private static final String VOICE_SETTINGS_KEY = "enable_voice_input"; + private static final String VOICE_ON_PRIMARY_KEY = "voice_on_main"; private static final String VOICE_SERVER_KEY = "voice_server_url"; private static final String TAG = "LatinIMESettings"; @@ -58,6 +59,7 @@ public class LatinIMESettings extends PreferenceActivity private CheckBoxPreference mQuickFixes; private CheckBoxPreference mShowSuggestions; private CheckBoxPreference mVoicePreference; + private CheckBoxPreference mVoiceOnPrimary; private VoiceInputLogger mLogger; @@ -70,7 +72,7 @@ public class LatinIMESettings extends PreferenceActivity mQuickFixes = (CheckBoxPreference) findPreference(QUICK_FIXES_KEY); mShowSuggestions = (CheckBoxPreference) findPreference(SHOW_SUGGESTIONS_KEY); mVoicePreference = (CheckBoxPreference) findPreference(VOICE_SETTINGS_KEY); - + mVoiceOnPrimary = (CheckBoxPreference) findPreference(VOICE_ON_PRIMARY_KEY); SharedPreferences prefs = getPreferenceManager().getSharedPreferences(); prefs.registerOnSharedPreferenceChangeListener(this); @@ -93,6 +95,7 @@ public class LatinIMESettings extends PreferenceActivity } if (!LatinIME.VOICE_INSTALLED || !RecognitionManager.isRecognitionAvailable(this)) { + getPreferenceScreen().removePreference(mVoiceOnPrimary); getPreferenceScreen().removePreference(mVoicePreference); } diff --git a/src/com/android/inputmethod/latin/LatinKeyboard.java b/src/com/android/inputmethod/latin/LatinKeyboard.java index 27c409a03..64b4529f3 100644 --- a/src/com/android/inputmethod/latin/LatinKeyboard.java +++ b/src/com/android/inputmethod/latin/LatinKeyboard.java @@ -298,36 +298,7 @@ public class LatinKeyboard extends Keyboard { Bitmap buffer = Bitmap.createBitmap(mSpaceKey.width, mSpaceIcon.getIntrinsicHeight(), Bitmap.Config.ARGB_8888); Canvas canvas = new Canvas(buffer); - canvas.drawColor(0x00000000, PorterDuff.Mode.CLEAR); - Paint paint = new Paint(); - paint.setAntiAlias(true); - // Get the text size from the theme - paint.setTextSize(getTextSizeFromTheme(android.R.style.TextAppearance_Small, 14)); - paint.setTextAlign(Align.CENTER); - // Draw a drop shadow for the text - paint.setShadowLayer(2f, 0, 0, 0xFF000000); - paint.setColor(0xFF808080); - final String language = getInputLanguage(mSpaceKey.width, paint); - final int ascent = (int) -paint.ascent(); - canvas.drawText(language, - buffer.getWidth() / 2, ascent, paint); - // Put arrows on either side of the text - if (mLanguageSwitcher.getLocaleCount() > 1) { - Rect bounds = new Rect(); - paint.getTextBounds(language, 0, language.length(), bounds); - drawButtonArrow(mButtonArrowLeftIcon, canvas, - (mSpaceKey.width - bounds.right) / 2 - - mButtonArrowLeftIcon.getIntrinsicWidth(), - (int) paint.getTextSize()); - drawButtonArrow(mButtonArrowRightIcon, canvas, - (mSpaceKey.width + bounds.right) / 2, (int) paint.getTextSize()); - } - // Draw the spacebar icon at the bottom - int x = (buffer.getWidth() - mSpaceIcon.getIntrinsicWidth()) / 2; - int y = buffer.getHeight() - mSpaceIcon.getIntrinsicHeight(); - mSpaceIcon.setBounds(x, y, - x + mSpaceIcon.getIntrinsicWidth(), y + mSpaceIcon.getIntrinsicHeight()); - mSpaceIcon.draw(canvas); + drawSpaceBar(canvas, buffer.getWidth(), buffer.getHeight(), 255); mSpaceKey.icon = new BitmapDrawable(mRes, buffer); mSpaceKey.repeatable = mLanguageSwitcher.getLocaleCount() < 2; } else { @@ -336,6 +307,43 @@ public class LatinKeyboard extends Keyboard { } } + private void drawSpaceBar(Canvas canvas, int width, int height, int opacity) { + canvas.drawColor(0x00000000, PorterDuff.Mode.CLEAR); + Paint paint = new Paint(); + paint.setAntiAlias(true); + paint.setAlpha(opacity); + // Get the text size from the theme + paint.setTextSize(getTextSizeFromTheme(android.R.style.TextAppearance_Small, 14)); + paint.setTextAlign(Align.CENTER); + //// Draw a drop shadow for the text + //paint.setShadowLayer(2f, 0, 0, 0xFF000000); + final String language = getInputLanguage(mSpaceKey.width, paint); + final int ascent = (int) -paint.ascent(); + paint.setColor(0x80000000); + canvas.drawText(language, + width / 2, ascent - 1, paint); + paint.setColor(0xFF808080); + canvas.drawText(language, + width / 2, ascent, paint); + // Put arrows on either side of the text + if (mLanguageSwitcher.getLocaleCount() > 1) { + Rect bounds = new Rect(); + paint.getTextBounds(language, 0, language.length(), bounds); + drawButtonArrow(mButtonArrowLeftIcon, canvas, + (mSpaceKey.width - bounds.right) / 2 + - mButtonArrowLeftIcon.getIntrinsicWidth(), + (int) paint.getTextSize()); + drawButtonArrow(mButtonArrowRightIcon, canvas, + (mSpaceKey.width + bounds.right) / 2, (int) paint.getTextSize()); + } + // Draw the spacebar icon at the bottom + int x = (width - mSpaceIcon.getIntrinsicWidth()) / 2; + int y = height - mSpaceIcon.getIntrinsicHeight(); + mSpaceIcon.setBounds(x, y, + x + mSpaceIcon.getIntrinsicWidth(), y + mSpaceIcon.getIntrinsicHeight()); + mSpaceIcon.draw(canvas); + } + private void drawButtonArrow(Drawable arrow, Canvas canvas, int x, int bottomY) { arrow.setBounds(x, bottomY - arrow.getIntrinsicHeight(), x + arrow.getIntrinsicWidth(), bottomY); @@ -356,9 +364,9 @@ public class LatinKeyboard extends Keyboard { private String chooseDisplayName(Locale locale, int widthAvail, Paint paint) { if (widthAvail < (int) (.35 * getMinWidth())) { - return locale.getLanguage().substring(0, 2).toUpperCase(locale); + return LanguageSwitcher.toTitleCase(locale.getLanguage().substring(0, 2)); } else { - return locale.getDisplayLanguage(locale); + return LanguageSwitcher.toTitleCase(locale.getDisplayLanguage(locale)); } }