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++) {
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);
}
}

View file

@ -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);
}
}

View file

@ -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);
}

View file

@ -298,19 +298,33 @@ public class LatinKeyboard extends Keyboard {
Bitmap buffer = Bitmap.createBitmap(mSpaceKey.width, mSpaceIcon.getIntrinsicHeight(),
Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(buffer);
drawSpaceBar(canvas, buffer.getWidth(), buffer.getHeight(), 255);
mSpaceKey.icon = new BitmapDrawable(mRes, buffer);
mSpaceKey.repeatable = mLanguageSwitcher.getLocaleCount() < 2;
} else {
mSpaceKey.icon = mRes.getDrawable(R.drawable.sym_keyboard_space);
mSpaceKey.repeatable = true;
}
}
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);
paint.setColor(0xFF808080);
//// 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,
buffer.getWidth() / 2, ascent, paint);
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();
@ -323,17 +337,11 @@ public class LatinKeyboard extends Keyboard {
(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();
int x = (width - mSpaceIcon.getIntrinsicWidth()) / 2;
int y = height - mSpaceIcon.getIntrinsicHeight();
mSpaceIcon.setBounds(x, y,
x + mSpaceIcon.getIntrinsicWidth(), y + mSpaceIcon.getIntrinsicHeight());
mSpaceIcon.draw(canvas);
mSpaceKey.icon = new BitmapDrawable(mRes, buffer);
mSpaceKey.repeatable = mLanguageSwitcher.getLocaleCount() < 2;
} else {
mSpaceKey.icon = mRes.getDrawable(R.drawable.sym_keyboard_space);
mSpaceKey.repeatable = true;
}
}
private void drawButtonArrow(Drawable arrow, Canvas canvas, int x, int 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));
}
}