From 41feaaadb758a8b31d3e436063b4b5faed104d4d Mon Sep 17 00:00:00 2001 From: satok Date: Thu, 2 Sep 2010 22:54:37 +0900 Subject: [PATCH] Change symbol on space bar when autocompletion is activated bug: 2959279 Change-Id: Icc70b7cce0c245ae2451d324debd346f226b8769 --- .../sym_keyboard_space_led.9.png | Bin 1291 -> 563 bytes .../inputmethod/latin/CandidateView.java | 4 + .../inputmethod/latin/KeyboardSwitcher.java | 19 +++-- .../android/inputmethod/latin/LatinIME.java | 3 + .../inputmethod/latin/LatinKeyboard.java | 69 ++++++++++++------ 5 files changed, 68 insertions(+), 27 deletions(-) diff --git a/java/res/drawable-hdpi/sym_keyboard_space_led.9.png b/java/res/drawable-hdpi/sym_keyboard_space_led.9.png index 71da57319421de5694f096ad10c42e319d7c4828..af5c7d80f9b90e2e6ba68a73f149e7b99447e908 100644 GIT binary patch delta 536 zcmeC?+RUQZ8Q|y6%O%Cdz`(%k>ERLtq%DBhl!FaOib!Z2n5d{;&v@0-#WAGf)|*?W zy$(BwusxU=W02drh+DK!`HGm=_kGRY+aH}<`at_DXAQ&MpB#%GEtPf*=ytuJ<~wI* zkFf2=#TE4 z4hJ-5J(_U6XQlG`8~LKwb3ZTH@jUgs7R!&?vj_G@-r4wm7N2^^46g7>%{mtQ@Umk| z7X<}zs9q6XGPA$u;BQDy>w9Ut;@`84oaiIlU^MNrGVm&j}%)(CbVF7YlxN z9CKy1W!S5De*KHK1>UzCpX*s)sXy~_O^BD#gFnaAzrS_!mCFh?mHNHZeV)AZx|(^@ z7L;GS85_N0?U@dBCst#oDeL@&*6%91+51gu>s4h5*ZfJ1g>G_vK&3(6vz94&9iBJK z;mm_4DK1~+J4AH;UAlilY4Z8MK2vnI&3b$8<;`cKi^-U{h9si*R{z`w)bBMDO)O^zh18L&h3J=8S5GQci*cY>4jHr+2Ff`flE1Vh-a^73J?AU$?5){jb=|Wxz01cEz)=LRX}K PkgTe~DWM4f46ElV literal 1291 zcmeAS@N?(olHy`uVBq!ia0vp^8bHj)!3HE_x#Qe`lw^r(L`iUdT1k0gQ7VIDN`6wR zf@f}GdTLN=VoGJ<$y6H#24v4 zq}24xJX@vryZ0+8WTx0Eg`4^s_!c;)W@LI)6{QAO`Gq7`WhYyvDB0U7*i={n4aiL` zNmQuF&B-gas<2f8n`;GRgM{^!6u?SKvTcwn`Gtf;oFf&jvGt@IQ zHZeCh*HJJsFf`CNFw!?P(ls=ndS0-B(gnVDkcYHDiXVq|XS=xFF_Xz1eRv4~Pj*wm=R%;iu*SQ+p9GSr?1m^k-mTtoL+r45_$v zX6kOg!v-P_>o2?bMlYDMFhqxgvxTLGDL&xXxtyAadImMKG`ocyA0;M8ELdc7ORaaK zY%%loNu5EqH8nJ2S6=Bh9s(N=7p^n}T3wisudN`(4Jsj0hqgo?e-rI?)L z{-yFox3c#1uCCHP=lz==8a_Lsb5$xW$d2v9o%?sMiHEIB-u?W{leJ3OZKpr~-aNN# zabRe2f|rHhm8lFn?zhZNw6V0g_3Gh8=}%sJ(%)BHi@G3|Ict?guUiDe!wox_u6$wL zBINn*-yucAt>=4w{5lx-Kd+#4(-D``$$ftUlrJ6B*v-BE*|l90U8@aV?-!Mtpw{wM zOeepr;b-Gz!HYo$o;>87lo)o8KgnnB5AEhzopr E04}7?xBvhE diff --git a/java/src/com/android/inputmethod/latin/CandidateView.java b/java/src/com/android/inputmethod/latin/CandidateView.java index 4995727da..bd73c6fb8 100755 --- a/java/src/com/android/inputmethod/latin/CandidateView.java +++ b/java/src/com/android/inputmethod/latin/CandidateView.java @@ -237,6 +237,8 @@ public class CandidateView extends View { final boolean typedWordValid = mTypedWordValid; final int y = (int) (height + mPaint.getTextSize() - mDescent) / 2; + boolean existsAutoCompletion = false; + for (int i = 0; i < count; i++) { CharSequence suggestion = mSuggestions.get(i); if (suggestion == null) continue; @@ -245,6 +247,7 @@ public class CandidateView extends View { && ((i == 1 && !typedWordValid) || (i == 0 && typedWordValid))) { paint.setTypeface(Typeface.DEFAULT_BOLD); paint.setColor(mColorRecommended); + existsAutoCompletion = true; } else if (i != 0) { paint.setColor(mColorOther); } @@ -285,6 +288,7 @@ public class CandidateView extends View { paint.setTypeface(Typeface.DEFAULT); x += wordWidth; } + mService.onAutoCompletionStateChanged(existsAutoCompletion); mTotalWidth = x; if (mTargetScrollX != scrollX) { scrollToTarget(); diff --git a/java/src/com/android/inputmethod/latin/KeyboardSwitcher.java b/java/src/com/android/inputmethod/latin/KeyboardSwitcher.java index 9c0a5a3aa..2919e9b56 100644 --- a/java/src/com/android/inputmethod/latin/KeyboardSwitcher.java +++ b/java/src/com/android/inputmethod/latin/KeyboardSwitcher.java @@ -88,6 +88,9 @@ public class KeyboardSwitcher implements SharedPreferences.OnSharedPreferenceCha private int mMode = MODE_NONE; /** One of the MODE_XXX values */ private int mImeOptions; 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 mVoiceOnPrimary; private boolean mPreferSymbols; @@ -239,7 +242,7 @@ public class KeyboardSwitcher implements SharedPreferences.OnSharedPreferenceCha keyboard.setShifted(false); keyboard.setShiftLocked(keyboard.isShiftLocked()); keyboard.setImeOptions(mContext.getResources(), mMode, imeOptions); - keyboard.setBlackFlag(isBlackSym()); + keyboard.setColorOfSymbolIcons(mIsAutoCompletionActive, isBlackSym()); } private LatinKeyboard getKeyboard(KeyboardId id) { @@ -249,12 +252,10 @@ public class KeyboardSwitcher implements SharedPreferences.OnSharedPreferenceCha Locale saveLocale = conf.locale; conf.locale = mInputLocale; orig.updateConfiguration(conf, null); - LatinKeyboard keyboard = new LatinKeyboard( - mContext, id.mXml, id.mKeyboardMode); + LatinKeyboard keyboard = new LatinKeyboard(mContext, id.mXml, id.mKeyboardMode); keyboard.setVoiceMode(hasVoiceButton(id.mXml == R.xml.kbd_symbols || id.mXml == R.xml.kbd_symbols_black), mHasVoice); - keyboard.setLanguageSwitcher(mLanguageSwitcher); - keyboard.setBlackFlag(isBlackSym()); + keyboard.setLanguageSwitcher(mLanguageSwitcher, mIsAutoCompletionActive, isBlackSym()); if (id.mEnableShiftLock) { 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)); + } + } } diff --git a/java/src/com/android/inputmethod/latin/LatinIME.java b/java/src/com/android/inputmethod/latin/LatinIME.java index 7afee3fad..d0e6e69c7 100644 --- a/java/src/com/android/inputmethod/latin/LatinIME.java +++ b/java/src/com/android/inputmethod/latin/LatinIME.java @@ -2483,4 +2483,7 @@ public class LatinIME extends InputMethodService System.out.println("CPS = " + ((CPS_BUFFER_SIZE * 1000f) / total)); } + public void onAutoCompletionStateChanged(boolean isAutoCompletion) { + mKeyboardSwitcher.onAutoCompletionStateChanged(isAutoCompletion); + } } diff --git a/java/src/com/android/inputmethod/latin/LatinKeyboard.java b/java/src/com/android/inputmethod/latin/LatinKeyboard.java index 33519e4be..b7c4fc4dc 100644 --- a/java/src/com/android/inputmethod/latin/LatinKeyboard.java +++ b/java/src/com/android/inputmethod/latin/LatinKeyboard.java @@ -43,11 +43,13 @@ public class LatinKeyboard extends Keyboard { private static final boolean DEBUG_PREFERRED_LETTER = false; private static final String TAG = "LatinKeyboard"; + private static final int OPACITY_FULLY_OPAQUE = 255; private Drawable mShiftLockIcon; private Drawable mShiftLockPreviewIcon; private Drawable mOldShiftIcon; private Drawable mSpaceIcon; + private Drawable mSpaceAutoCompletionIndicator; private Drawable mSpacePreviewIcon; private Drawable mMicIcon; private Drawable mMicPreviewIcon; @@ -111,6 +113,7 @@ public class LatinKeyboard extends Keyboard { mShiftLockPreviewIcon.getIntrinsicWidth(), mShiftLockPreviewIcon.getIntrinsicHeight()); 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); mMicIcon = res.getDrawable(R.drawable.sym_keyboard_mic); mMicPreviewIcon = res.getDrawable(R.drawable.sym_keyboard_feedback_mic); @@ -277,9 +280,9 @@ public class LatinKeyboard extends Keyboard { return mIsAlphaKeyboard; } - public void setBlackFlag(boolean f) { - mIsBlackSym = f; - if (f) { + public void setColorOfSymbolIcons(boolean isAutoCompletion, boolean isBlack) { + mIsBlackSym = isBlack; + if (isBlack) { mShiftLockIcon = mRes.getDrawable(R.drawable.sym_bkeyboard_shift_locked); mSpaceIcon = mRes.getDrawable(R.drawable.sym_bkeyboard_space); mMicIcon = mRes.getDrawable(R.drawable.sym_bkeyboard_mic); @@ -292,8 +295,7 @@ public class LatinKeyboard extends Keyboard { } updateF1Key(); if (mSpaceKey != null) { - mSpaceKey.icon = mSpaceIcon; - updateSpaceBarForLocale(f); + updateSpaceBarForLocale(isAutoCompletion, isBlack); } } @@ -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) { - // Create the graphic for spacebar - 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); + Bitmap buffer = drawSpaceBar(OPACITY_FULLY_OPAQUE, isAutoCompletion, isBlack); mSpaceKey.icon = new BitmapDrawable(mRes, buffer); mSpaceKey.repeatable = mLanguageSwitcher.getLocaleCount() < 2; } else { - mSpaceKey.icon = isBlack ? mRes.getDrawable(R.drawable.sym_bkeyboard_space) - : mRes.getDrawable(R.drawable.sym_keyboard_space); + // sym_keyboard_space_led can be shared with Black and White symbol themes. + 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; } } - 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); Paint paint = new Paint(); paint.setAntiAlias(true); @@ -380,11 +393,22 @@ public class LatinKeyboard extends Keyboard { (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); + if (isAutoCompletion) { + final int iconWidth = mSpaceAutoCompletionIndicator.getIntrinsicWidth(); + final int iconHeight = mSpaceAutoCompletionIndicator.getIntrinsicHeight(); + int x = (width - iconWidth) / 2; + 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) { @@ -438,7 +462,8 @@ public class LatinKeyboard extends Keyboard { return mSpaceDragLastDiff > 0 ? 1 : -1; } - public void setLanguageSwitcher(LanguageSwitcher switcher) { + public void setLanguageSwitcher(LanguageSwitcher switcher, boolean isAutoCompletion, + boolean isBlackSym) { mLanguageSwitcher = switcher; Locale locale = mLanguageSwitcher.getLocaleCount() > 0 ? mLanguageSwitcher.getInputLocale() @@ -450,9 +475,9 @@ public class LatinKeyboard extends Keyboard { .equalsIgnoreCase(locale.getLanguage())) { locale = null; } + setColorOfSymbolIcons(isAutoCompletion, isBlackSym); if (mLocale != null && mLocale.equals(locale)) return; mLocale = locale; - updateSpaceBarForLocale(mIsBlackSym); } boolean isCurrentlyInSpace() { @@ -729,7 +754,7 @@ public class LatinKeyboard extends Keyboard { mTextPaint.setTextSize(textSize); mTextPaint.setColor(R.color.latinkeyboard_transparent); mTextPaint.setTextAlign(Align.CENTER); - mTextPaint.setAlpha(255); + mTextPaint.setAlpha(OPACITY_FULLY_OPAQUE); mTextPaint.setAntiAlias(true); mAscent = (int) mTextPaint.ascent(); mMiddleX = (mWidth - mBackground.getIntrinsicWidth()) / 2;