Merge "Change symbol on space bar when autocompletion is activated" into gingerbread

main
satok 2010-09-02 23:26:06 -07:00 committed by Android (Google) Code Review
commit c5841994af
5 changed files with 68 additions and 27 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.3 KiB

After

Width:  |  Height:  |  Size: 563 B

View File

@ -237,6 +237,8 @@ public class CandidateView extends View {
final boolean typedWordValid = mTypedWordValid; final boolean typedWordValid = mTypedWordValid;
final int y = (int) (height + mPaint.getTextSize() - mDescent) / 2; final int y = (int) (height + mPaint.getTextSize() - mDescent) / 2;
boolean existsAutoCompletion = false;
for (int i = 0; i < count; i++) { for (int i = 0; i < count; i++) {
CharSequence suggestion = mSuggestions.get(i); CharSequence suggestion = mSuggestions.get(i);
if (suggestion == null) continue; if (suggestion == null) continue;
@ -245,6 +247,7 @@ public class CandidateView extends View {
&& ((i == 1 && !typedWordValid) || (i == 0 && typedWordValid))) { && ((i == 1 && !typedWordValid) || (i == 0 && typedWordValid))) {
paint.setTypeface(Typeface.DEFAULT_BOLD); paint.setTypeface(Typeface.DEFAULT_BOLD);
paint.setColor(mColorRecommended); paint.setColor(mColorRecommended);
existsAutoCompletion = true;
} else if (i != 0) { } else if (i != 0) {
paint.setColor(mColorOther); paint.setColor(mColorOther);
} }
@ -285,6 +288,7 @@ public class CandidateView extends View {
paint.setTypeface(Typeface.DEFAULT); paint.setTypeface(Typeface.DEFAULT);
x += wordWidth; x += wordWidth;
} }
mService.onAutoCompletionStateChanged(existsAutoCompletion);
mTotalWidth = x; mTotalWidth = x;
if (mTargetScrollX != scrollX) { if (mTargetScrollX != scrollX) {
scrollToTarget(); scrollToTarget();

View File

@ -88,6 +88,9 @@ public class KeyboardSwitcher implements SharedPreferences.OnSharedPreferenceCha
private int mMode = MODE_NONE; /** One of the MODE_XXX values */ private int mMode = MODE_NONE; /** One of the MODE_XXX values */
private int mImeOptions; private int mImeOptions;
private boolean mIsSymbols; private boolean mIsSymbols;
/** mIsAutoCompletionActive indicates that auto completed word will be input instead of
* what user actually typed. */
private boolean mIsAutoCompletionActive;
private boolean mHasVoice; private boolean mHasVoice;
private boolean mVoiceOnPrimary; private boolean mVoiceOnPrimary;
private boolean mPreferSymbols; private boolean mPreferSymbols;
@ -239,7 +242,7 @@ public class KeyboardSwitcher implements SharedPreferences.OnSharedPreferenceCha
keyboard.setShifted(false); keyboard.setShifted(false);
keyboard.setShiftLocked(keyboard.isShiftLocked()); keyboard.setShiftLocked(keyboard.isShiftLocked());
keyboard.setImeOptions(mContext.getResources(), mMode, imeOptions); keyboard.setImeOptions(mContext.getResources(), mMode, imeOptions);
keyboard.setBlackFlag(isBlackSym()); keyboard.setColorOfSymbolIcons(mIsAutoCompletionActive, isBlackSym());
} }
private LatinKeyboard getKeyboard(KeyboardId id) { private LatinKeyboard getKeyboard(KeyboardId id) {
@ -249,12 +252,10 @@ public class KeyboardSwitcher implements SharedPreferences.OnSharedPreferenceCha
Locale saveLocale = conf.locale; Locale saveLocale = conf.locale;
conf.locale = mInputLocale; conf.locale = mInputLocale;
orig.updateConfiguration(conf, null); orig.updateConfiguration(conf, null);
LatinKeyboard keyboard = new LatinKeyboard( LatinKeyboard keyboard = new LatinKeyboard(mContext, id.mXml, id.mKeyboardMode);
mContext, id.mXml, id.mKeyboardMode);
keyboard.setVoiceMode(hasVoiceButton(id.mXml == R.xml.kbd_symbols keyboard.setVoiceMode(hasVoiceButton(id.mXml == R.xml.kbd_symbols
|| id.mXml == R.xml.kbd_symbols_black), mHasVoice); || id.mXml == R.xml.kbd_symbols_black), mHasVoice);
keyboard.setLanguageSwitcher(mLanguageSwitcher); keyboard.setLanguageSwitcher(mLanguageSwitcher, mIsAutoCompletionActive, isBlackSym());
keyboard.setBlackFlag(isBlackSym());
if (id.mEnableShiftLock) { if (id.mEnableShiftLock) {
keyboard.enableShiftLock(); keyboard.enableShiftLock();
@ -450,4 +451,12 @@ public class KeyboardSwitcher implements SharedPreferences.OnSharedPreferenceCha
} }
} }
public void onAutoCompletionStateChanged(boolean isAutoCompletion) {
if (isAutoCompletion != mIsAutoCompletionActive) {
LatinKeyboardView keyboardView = getInputView();
mIsAutoCompletionActive = isAutoCompletion;
keyboardView.invalidateKey(((LatinKeyboard) keyboardView.getKeyboard())
.onAutoCompletionStateChanged(isAutoCompletion));
}
}
} }

View File

@ -2483,4 +2483,7 @@ public class LatinIME extends InputMethodService
System.out.println("CPS = " + ((CPS_BUFFER_SIZE * 1000f) / total)); System.out.println("CPS = " + ((CPS_BUFFER_SIZE * 1000f) / total));
} }
public void onAutoCompletionStateChanged(boolean isAutoCompletion) {
mKeyboardSwitcher.onAutoCompletionStateChanged(isAutoCompletion);
}
} }

View File

@ -43,11 +43,13 @@ public class LatinKeyboard extends Keyboard {
private static final boolean DEBUG_PREFERRED_LETTER = false; private static final boolean DEBUG_PREFERRED_LETTER = false;
private static final String TAG = "LatinKeyboard"; private static final String TAG = "LatinKeyboard";
private static final int OPACITY_FULLY_OPAQUE = 255;
private Drawable mShiftLockIcon; private Drawable mShiftLockIcon;
private Drawable mShiftLockPreviewIcon; private Drawable mShiftLockPreviewIcon;
private Drawable mOldShiftIcon; private Drawable mOldShiftIcon;
private Drawable mSpaceIcon; private Drawable mSpaceIcon;
private Drawable mSpaceAutoCompletionIndicator;
private Drawable mSpacePreviewIcon; private Drawable mSpacePreviewIcon;
private Drawable mMicIcon; private Drawable mMicIcon;
private Drawable mMicPreviewIcon; private Drawable mMicPreviewIcon;
@ -111,6 +113,7 @@ public class LatinKeyboard extends Keyboard {
mShiftLockPreviewIcon.getIntrinsicWidth(), mShiftLockPreviewIcon.getIntrinsicWidth(),
mShiftLockPreviewIcon.getIntrinsicHeight()); mShiftLockPreviewIcon.getIntrinsicHeight());
mSpaceIcon = res.getDrawable(R.drawable.sym_keyboard_space); mSpaceIcon = res.getDrawable(R.drawable.sym_keyboard_space);
mSpaceAutoCompletionIndicator = res.getDrawable(R.drawable.sym_keyboard_space_led);
mSpacePreviewIcon = res.getDrawable(R.drawable.sym_keyboard_feedback_space); mSpacePreviewIcon = res.getDrawable(R.drawable.sym_keyboard_feedback_space);
mMicIcon = res.getDrawable(R.drawable.sym_keyboard_mic); mMicIcon = res.getDrawable(R.drawable.sym_keyboard_mic);
mMicPreviewIcon = res.getDrawable(R.drawable.sym_keyboard_feedback_mic); mMicPreviewIcon = res.getDrawable(R.drawable.sym_keyboard_feedback_mic);
@ -277,9 +280,9 @@ public class LatinKeyboard extends Keyboard {
return mIsAlphaKeyboard; return mIsAlphaKeyboard;
} }
public void setBlackFlag(boolean f) { public void setColorOfSymbolIcons(boolean isAutoCompletion, boolean isBlack) {
mIsBlackSym = f; mIsBlackSym = isBlack;
if (f) { if (isBlack) {
mShiftLockIcon = mRes.getDrawable(R.drawable.sym_bkeyboard_shift_locked); mShiftLockIcon = mRes.getDrawable(R.drawable.sym_bkeyboard_shift_locked);
mSpaceIcon = mRes.getDrawable(R.drawable.sym_bkeyboard_space); mSpaceIcon = mRes.getDrawable(R.drawable.sym_bkeyboard_space);
mMicIcon = mRes.getDrawable(R.drawable.sym_bkeyboard_mic); mMicIcon = mRes.getDrawable(R.drawable.sym_bkeyboard_mic);
@ -292,8 +295,7 @@ public class LatinKeyboard extends Keyboard {
} }
updateF1Key(); updateF1Key();
if (mSpaceKey != null) { if (mSpaceKey != null) {
mSpaceKey.icon = mSpaceIcon; updateSpaceBarForLocale(isAutoCompletion, isBlack);
updateSpaceBarForLocale(f);
} }
} }
@ -334,23 +336,34 @@ public class LatinKeyboard extends Keyboard {
} }
} }
private void updateSpaceBarForLocale(boolean isBlack) { /**
* @return a key which should be invalidated.
*/
public Key onAutoCompletionStateChanged(boolean isAutoCompletion) {
updateSpaceBarForLocale(isAutoCompletion, mIsBlackSym);
return mSpaceKey;
}
private void updateSpaceBarForLocale(boolean isAutoCompletion, boolean isBlack) {
if (mLocale != null) { if (mLocale != null) {
// Create the graphic for spacebar Bitmap buffer = drawSpaceBar(OPACITY_FULLY_OPAQUE, isAutoCompletion, isBlack);
Bitmap buffer = Bitmap.createBitmap(mSpaceKey.width, mSpaceIcon.getIntrinsicHeight(),
Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(buffer);
drawSpaceBar(canvas, buffer.getWidth(), buffer.getHeight(), 255, isBlack);
mSpaceKey.icon = new BitmapDrawable(mRes, buffer); mSpaceKey.icon = new BitmapDrawable(mRes, buffer);
mSpaceKey.repeatable = mLanguageSwitcher.getLocaleCount() < 2; mSpaceKey.repeatable = mLanguageSwitcher.getLocaleCount() < 2;
} else { } else {
mSpaceKey.icon = isBlack ? mRes.getDrawable(R.drawable.sym_bkeyboard_space) // sym_keyboard_space_led can be shared with Black and White symbol themes.
: mRes.getDrawable(R.drawable.sym_keyboard_space); mSpaceKey.icon =
isAutoCompletion ? mRes.getDrawable(R.drawable.sym_keyboard_space_led)
: isBlack ? mRes.getDrawable(R.drawable.sym_bkeyboard_space)
: mRes.getDrawable(R.drawable.sym_keyboard_space);
mSpaceKey.repeatable = true; mSpaceKey.repeatable = true;
} }
} }
private void drawSpaceBar(Canvas canvas, int width, int height, int opacity, boolean isBlack) { private Bitmap drawSpaceBar(int opacity, boolean isAutoCompletion, boolean isBlack) {
int width = mSpaceKey.width;
int height = mSpaceIcon.getIntrinsicHeight();
Bitmap buffer = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(buffer);
canvas.drawColor(mRes.getColor(R.color.latinkeyboard_transparent), PorterDuff.Mode.CLEAR); canvas.drawColor(mRes.getColor(R.color.latinkeyboard_transparent), PorterDuff.Mode.CLEAR);
Paint paint = new Paint(); Paint paint = new Paint();
paint.setAntiAlias(true); paint.setAntiAlias(true);
@ -380,11 +393,22 @@ public class LatinKeyboard extends Keyboard {
(mSpaceKey.width + bounds.right) / 2, (int) paint.getTextSize()); (mSpaceKey.width + bounds.right) / 2, (int) paint.getTextSize());
} }
// Draw the spacebar icon at the bottom // Draw the spacebar icon at the bottom
int x = (width - mSpaceIcon.getIntrinsicWidth()) / 2; if (isAutoCompletion) {
int y = height - mSpaceIcon.getIntrinsicHeight(); final int iconWidth = mSpaceAutoCompletionIndicator.getIntrinsicWidth();
mSpaceIcon.setBounds(x, y, final int iconHeight = mSpaceAutoCompletionIndicator.getIntrinsicHeight();
x + mSpaceIcon.getIntrinsicWidth(), y + mSpaceIcon.getIntrinsicHeight()); int x = (width - iconWidth) / 2;
mSpaceIcon.draw(canvas); int y = height - iconHeight;
mSpaceAutoCompletionIndicator.setBounds(x, y, x + iconWidth, y + iconHeight);
mSpaceAutoCompletionIndicator.draw(canvas);
} else {
final int iconWidth = mSpaceIcon.getIntrinsicWidth();
final int iconHeight = mSpaceIcon.getIntrinsicHeight();
int x = (width - iconWidth) / 2;
int y = height - iconHeight;
mSpaceIcon.setBounds(x, y, x + iconWidth, y + iconHeight);
mSpaceIcon.draw(canvas);
}
return buffer;
} }
private void drawButtonArrow(Drawable arrow, Canvas canvas, int x, int bottomY) { private void drawButtonArrow(Drawable arrow, Canvas canvas, int x, int bottomY) {
@ -438,7 +462,8 @@ public class LatinKeyboard extends Keyboard {
return mSpaceDragLastDiff > 0 ? 1 : -1; return mSpaceDragLastDiff > 0 ? 1 : -1;
} }
public void setLanguageSwitcher(LanguageSwitcher switcher) { public void setLanguageSwitcher(LanguageSwitcher switcher, boolean isAutoCompletion,
boolean isBlackSym) {
mLanguageSwitcher = switcher; mLanguageSwitcher = switcher;
Locale locale = mLanguageSwitcher.getLocaleCount() > 0 Locale locale = mLanguageSwitcher.getLocaleCount() > 0
? mLanguageSwitcher.getInputLocale() ? mLanguageSwitcher.getInputLocale()
@ -450,9 +475,9 @@ public class LatinKeyboard extends Keyboard {
.equalsIgnoreCase(locale.getLanguage())) { .equalsIgnoreCase(locale.getLanguage())) {
locale = null; locale = null;
} }
setColorOfSymbolIcons(isAutoCompletion, isBlackSym);
if (mLocale != null && mLocale.equals(locale)) return; if (mLocale != null && mLocale.equals(locale)) return;
mLocale = locale; mLocale = locale;
updateSpaceBarForLocale(mIsBlackSym);
} }
boolean isCurrentlyInSpace() { boolean isCurrentlyInSpace() {
@ -729,7 +754,7 @@ public class LatinKeyboard extends Keyboard {
mTextPaint.setTextSize(textSize); mTextPaint.setTextSize(textSize);
mTextPaint.setColor(R.color.latinkeyboard_transparent); mTextPaint.setColor(R.color.latinkeyboard_transparent);
mTextPaint.setTextAlign(Align.CENTER); mTextPaint.setTextAlign(Align.CENTER);
mTextPaint.setAlpha(255); mTextPaint.setAlpha(OPACITY_FULLY_OPAQUE);
mTextPaint.setAntiAlias(true); mTextPaint.setAntiAlias(true);
mAscent = (int) mTextPaint.ascent(); mAscent = (int) mTextPaint.ascent();
mMiddleX = (mWidth - mBackground.getIntrinsicWidth()) / 2; mMiddleX = (mWidth - mBackground.getIntrinsicWidth()) / 2;