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.
This commit is contained in:
Amith Yamasani 2010-02-05 16:24:40 -08:00
parent 6d09dd7a0d
commit 676fb5b665
4 changed files with 57 additions and 47 deletions

View file

@ -70,7 +70,7 @@ public class InputLanguageSelection extends PreferenceActivity {
for (int i = 0; i < mAvailableLanguages.size(); i++) { for (int i = 0; i < mAvailableLanguages.size(); i++) {
CheckBoxPreference pref = new CheckBoxPreference(this); CheckBoxPreference pref = new CheckBoxPreference(this);
Locale locale = mAvailableLanguages.get(i).locale; Locale locale = mAvailableLanguages.get(i).locale;
pref.setTitle(toTitleCase(locale.getDisplayName(locale))); pref.setTitle(LanguageSwitcher.toTitleCase(locale.getDisplayName(locale)));
boolean checked = isLocaleIn(locale, languageList); boolean checked = isLocaleIn(locale, languageList);
pref.setChecked(checked); pref.setChecked(checked);
parent.addPreference(pref); parent.addPreference(pref);
@ -138,7 +138,7 @@ public class InputLanguageSelection extends PreferenceActivity {
if (finalSize == 0) { if (finalSize == 0) {
preprocess[finalSize++] = preprocess[finalSize++] =
new Loc(toTitleCase(l.getDisplayName(l)), l); new Loc(LanguageSwitcher.toTitleCase(l.getDisplayName(l)), l);
} else { } else {
// check previous entry: // check previous entry:
// same lang and a country -> upgrade to full name and // 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 // diff lang -> insert ours with lang-only name
if (preprocess[finalSize-1].locale.getLanguage().equals( if (preprocess[finalSize-1].locale.getLanguage().equals(
language)) { language)) {
preprocess[finalSize-1].label = toTitleCase( preprocess[finalSize-1].label = LanguageSwitcher.toTitleCase(
preprocess[finalSize-1].locale.getDisplayName()); preprocess[finalSize-1].locale.getDisplayName());
preprocess[finalSize++] = preprocess[finalSize++] =
new Loc(toTitleCase(l.getDisplayName()), l); new Loc(LanguageSwitcher.toTitleCase(l.getDisplayName()), l);
} else { } else {
String displayName; String displayName;
if (s.equals("zz_ZZ")) { if (s.equals("zz_ZZ")) {
} else { } else {
displayName = toTitleCase(l.getDisplayName(l)); displayName = LanguageSwitcher.toTitleCase(l.getDisplayName(l));
preprocess[finalSize++] = new Loc(displayName, l); preprocess[finalSize++] = new Loc(displayName, l);
} }
} }
@ -166,13 +166,4 @@ public class InputLanguageSelection extends PreferenceActivity {
} }
return uniqueLocales; return uniqueLocales;
} }
private static String toTitleCase(String s) {
if (s.length() == 0) {
return s;
}
return Character.toUpperCase(s.charAt(0)) + s.substring(1);
}
} }

View file

@ -169,4 +169,12 @@ public class LanguageSwitcher {
editor.putString(LatinIME.PREF_INPUT_LANGUAGE, getInputLanguage()); editor.putString(LatinIME.PREF_INPUT_LANGUAGE, getInputLanguage());
editor.commit(); editor.commit();
} }
static String toTitleCase(String s) {
if (s.length() == 0) {
return s;
}
return Character.toUpperCase(s.charAt(0)) + s.substring(1);
}
} }

View file

@ -48,6 +48,7 @@ public class LatinIMESettings extends PreferenceActivity
private static final String SHOW_SUGGESTIONS_KEY = "show_suggestions"; private static final String SHOW_SUGGESTIONS_KEY = "show_suggestions";
private static final String PREDICTION_SETTINGS_KEY = "prediction_settings"; private static final String PREDICTION_SETTINGS_KEY = "prediction_settings";
private static final String VOICE_SETTINGS_KEY = "enable_voice_input"; 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 VOICE_SERVER_KEY = "voice_server_url";
private static final String TAG = "LatinIMESettings"; private static final String TAG = "LatinIMESettings";
@ -58,6 +59,7 @@ public class LatinIMESettings extends PreferenceActivity
private CheckBoxPreference mQuickFixes; private CheckBoxPreference mQuickFixes;
private CheckBoxPreference mShowSuggestions; private CheckBoxPreference mShowSuggestions;
private CheckBoxPreference mVoicePreference; private CheckBoxPreference mVoicePreference;
private CheckBoxPreference mVoiceOnPrimary;
private VoiceInputLogger mLogger; private VoiceInputLogger mLogger;
@ -70,7 +72,7 @@ public class LatinIMESettings extends PreferenceActivity
mQuickFixes = (CheckBoxPreference) findPreference(QUICK_FIXES_KEY); mQuickFixes = (CheckBoxPreference) findPreference(QUICK_FIXES_KEY);
mShowSuggestions = (CheckBoxPreference) findPreference(SHOW_SUGGESTIONS_KEY); mShowSuggestions = (CheckBoxPreference) findPreference(SHOW_SUGGESTIONS_KEY);
mVoicePreference = (CheckBoxPreference) findPreference(VOICE_SETTINGS_KEY); mVoicePreference = (CheckBoxPreference) findPreference(VOICE_SETTINGS_KEY);
mVoiceOnPrimary = (CheckBoxPreference) findPreference(VOICE_ON_PRIMARY_KEY);
SharedPreferences prefs = getPreferenceManager().getSharedPreferences(); SharedPreferences prefs = getPreferenceManager().getSharedPreferences();
prefs.registerOnSharedPreferenceChangeListener(this); prefs.registerOnSharedPreferenceChangeListener(this);
@ -93,6 +95,7 @@ public class LatinIMESettings extends PreferenceActivity
} }
if (!LatinIME.VOICE_INSTALLED if (!LatinIME.VOICE_INSTALLED
|| !RecognitionManager.isRecognitionAvailable(this)) { || !RecognitionManager.isRecognitionAvailable(this)) {
getPreferenceScreen().removePreference(mVoiceOnPrimary);
getPreferenceScreen().removePreference(mVoicePreference); getPreferenceScreen().removePreference(mVoicePreference);
} }

View file

@ -298,36 +298,7 @@ public class LatinKeyboard extends Keyboard {
Bitmap buffer = Bitmap.createBitmap(mSpaceKey.width, mSpaceIcon.getIntrinsicHeight(), Bitmap buffer = Bitmap.createBitmap(mSpaceKey.width, mSpaceIcon.getIntrinsicHeight(),
Bitmap.Config.ARGB_8888); Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(buffer); Canvas canvas = new Canvas(buffer);
canvas.drawColor(0x00000000, PorterDuff.Mode.CLEAR); drawSpaceBar(canvas, buffer.getWidth(), buffer.getHeight(), 255);
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);
mSpaceKey.icon = new BitmapDrawable(mRes, buffer); mSpaceKey.icon = new BitmapDrawable(mRes, buffer);
mSpaceKey.repeatable = mLanguageSwitcher.getLocaleCount() < 2; mSpaceKey.repeatable = mLanguageSwitcher.getLocaleCount() < 2;
} else { } 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) { private void drawButtonArrow(Drawable arrow, Canvas canvas, int x, int bottomY) {
arrow.setBounds(x, bottomY - arrow.getIntrinsicHeight(), x + arrow.getIntrinsicWidth(), arrow.setBounds(x, bottomY - arrow.getIntrinsicHeight(), x + arrow.getIntrinsicWidth(),
bottomY); bottomY);
@ -356,9 +364,9 @@ public class LatinKeyboard extends Keyboard {
private String chooseDisplayName(Locale locale, int widthAvail, Paint paint) { private String chooseDisplayName(Locale locale, int widthAvail, Paint paint) {
if (widthAvail < (int) (.35 * getMinWidth())) { if (widthAvail < (int) (.35 * getMinWidth())) {
return locale.getLanguage().substring(0, 2).toUpperCase(locale); return LanguageSwitcher.toTitleCase(locale.getLanguage().substring(0, 2));
} else { } else {
return locale.getDisplayLanguage(locale); return LanguageSwitcher.toTitleCase(locale.getDisplayLanguage(locale));
} }
} }