From 5cd87e1b1c4258e8d016518914eccfbb4437cace Mon Sep 17 00:00:00 2001 From: "Tadashi G. Takaoka" Date: Tue, 25 Jan 2011 12:13:35 +0900 Subject: [PATCH] Disable shortcut key when network is not available Bug: 3345931 Change-Id: I1deef774598b8e78da4404535b6d3814464a9d2d --- java/AndroidManifest.xml | 1 + .../sym_bkeyboard_mic_disabled.png | Bin 0 -> 1410 bytes .../sym_keyboard_mic_disabled.png | Bin 0 -> 886 bytes .../sym_bkeyboard_mic_disabled.png | Bin 0 -> 838 bytes .../sym_keyboard_mic_disabled.png | Bin 0 -> 3439 bytes java/res/xml/method.xml | 34 ++++---- .../com/android/inputmethod/keyboard/Key.java | 11 ++- .../inputmethod/keyboard/Keyboard.java | 11 --- .../inputmethod/keyboard/KeyboardParser.java | 2 - .../keyboard/KeyboardSwitcher.java | 7 +- .../inputmethod/keyboard/LatinKeyboard.java | 70 ++++++++++++---- .../inputmethod/keyboard/PointerTracker.java | 3 +- .../inputmethod/latin/SubtypeSwitcher.java | 76 +++++++++++++++--- 13 files changed, 151 insertions(+), 64 deletions(-) create mode 100644 java/res/drawable-hdpi/sym_bkeyboard_mic_disabled.png create mode 100644 java/res/drawable-hdpi/sym_keyboard_mic_disabled.png create mode 100644 java/res/drawable-mdpi/sym_bkeyboard_mic_disabled.png create mode 100644 java/res/drawable-mdpi/sym_keyboard_mic_disabled.png diff --git a/java/AndroidManifest.xml b/java/AndroidManifest.xml index de4ac610c..e0eecfc7d 100644 --- a/java/AndroidManifest.xml +++ b/java/AndroidManifest.xml @@ -2,6 +2,7 @@ package="com.android.inputmethod.latin"> + diff --git a/java/res/drawable-hdpi/sym_bkeyboard_mic_disabled.png b/java/res/drawable-hdpi/sym_bkeyboard_mic_disabled.png new file mode 100644 index 0000000000000000000000000000000000000000..512f46080022eb99c3af40d970362a783264a78b GIT binary patch literal 1410 zcmV-|1%3L7P)zyT;`=CMM^ z4tRlLKH2E#=q;Iu3{G-oW#tw0y9VR~Zdy=U32A^2CVvuTqkWGqRne^2oS6BBcDTU00mX4E86iS8<16OKmYv1GD z{C@vWJcj{2z|CZNjH9%)^jGxj2VMkPL_JC+P(&&~GtO^MktQ5DIXMR>OGP0IX=Zed z%jJsFSI6w^tY2;-5f?X|C`m;638}KOGA^_-*4Njs(!)5hSY>79FUbfsHa7lD&(Y@R z=dbWORaGNWZZj>=7zwce@Ho&c%-!4D`x$=s@mI01uyD)ibnYd2T{nT(f!<&+_yeym zE-t=}-%kN$BxN+S@*^gT_44xa?|9|-_;`!hnGFpM8*_7WAJo^^FN;Ch+1cA&U0vU- zuC9JWW0kS7vBIULr6+iMb93|8(sPgE?J}0&I>t^~hU;ekV`8)7skl zDG9IZC@*6&7m*VEc4-1mChf4iI^#t*z}Vhr_We`u6nngwXaha23di;qzn+dw`6Tuo$xa}tP62|Hi%2~}E9G0alW*yX ziHQ&_^am$`9rq&-2dIAyXak<4EuKeYoJ5A5_SB)%E;t~^jgVtT#1Xl(vvb4kcArFL z5ZgvL_>&xVj~sYMa`?kk7Z7G-gwQWXL~LKm*ztBs%+Ob4_L!O55VN{Qmp=74B;|4_ z5!K_2P0QI{A!p=%P*7c6{cfsk&(YV{*G}8qLt%ua^W-Y6A@yxL#KBHMLBZcvZ`7E{ zn|x+af0qC+i7gk^+vs&gCFkEJr{0r%E^YTi@{Wtp@2Dhkcwa%>V!Z literal 0 HcmV?d00001 diff --git a/java/res/drawable-hdpi/sym_keyboard_mic_disabled.png b/java/res/drawable-hdpi/sym_keyboard_mic_disabled.png new file mode 100644 index 0000000000000000000000000000000000000000..c8dca62a08d1ac203b243a3e7a2a90ef0c030caf GIT binary patch literal 886 zcmV-+1Bv{JP)DT&`uiHG8-2rMUaAsM3kb5q%%xvLG~EU zpV$5D3Sv6%XMEG&J8jY18nqNy(S)Qnnb2QHNW&9n zBz}%~UBnotiCbxGZ4oo1k3=H(TCLW0Fc`cklnr7KiyT}#H(x@htX8W{tJUf(7K>RZ zA;cgSIgsn0ENUDBBYm?(tl#es_$CJyF}S8V*hLWPwcG74xX|fzXEK@04vs1w(qafK zVn)jCXO7+?2r)!>eZU0~Vi$6`+-{*zc*_+846uly;te?%UNVy7v{xAnhO6WWzv2`R zg+dQEH#hHeI-UJ_Cq4Rr0T%a&MULqSIE?%-#pCg3NKRhi=KA{jbqKJ%y}g}jGH62| zFuvB;!dK7@pb{Ied9=W;X} zeXQ5(mr=CoboymJpUcE4w>QjEY*#b}gTQ)9QaplGp7<7FH#589}}w{Y#uiy}0(6U5iBQe#4NM%HMbs5ksD zM+Y;jE{N^$+HVfA56!Y=eBx|uY}}5;Vo%32w6(SM#Ow9mqMtu{QDciBw1)aAm&?V2 zzR7^0%O@$JRTS(&yY%F4O^bU~DniG|K68U%m~Sjk0~RreA>tF7Ng!`umA0GyZ&IRQO584ib^@A3H`5zJixM}R`ihTK=A28T+e z((%p-p69jcbb1<>I*L1l(@-7CK|SUbi5rOynx1lmN@p*5u?QdvIWN zb@eQZM?4;X)oI-0@st9AKxJ)h&0eWgEO?9e^!zWWTEtR*4ESv}+XgEK`F#Ek##gi1 z>=KN=b-7&SnVFfFxOW}gn3$M&!_4GzxjBqoKr2^^bl}*+!op4VpxJExw7k50j|>W2 z19MYTQ|oMv-|v5cv5z*VloL>aQE)06jouduo6qN4Po+|iA^ac~i#;=$Okda>T(f~{ zdlBpHw0llYfGyB~ad4WwiNoR8?5w6nqp=zag`Q%~dElhVtLU{{3nF7w^TXwG`Ig|4 zm6eqx+`9tK02>)scC#gxrEHf!K#h*e8eCCBJifBYNF?$ZT^;ODa`AtCJv|(mZOUv_ zFc`e7*XxfKi$yz|n4O&sRI61tzN#nl^YdF$)wGur&DH6D0k7A4mtr+2W<&1KXN7B* z9h>M6)9Jv5^4 QegFUf07*qoM6N<$f{;RzLI3~& literal 0 HcmV?d00001 diff --git a/java/res/drawable-mdpi/sym_keyboard_mic_disabled.png b/java/res/drawable-mdpi/sym_keyboard_mic_disabled.png new file mode 100644 index 0000000000000000000000000000000000000000..e926b3fa6d5ea231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Bp_lTPlfP|z zrTyx_>lv@x#=^!PzR7qqF<$gm`|ZJZ+;<)Cqu&ot2z=0000WV@Og>004R=004l4008;_004mL004C`008P>0026e000+nl3&F} z0007-Nklp#jOYJ^B|2JqB+=|AC;F z)|x=h4S{&})YC$sr=T$iQV`m-abvK-xLXpsM(fVL9%`X%T(i-H9-1%AW!{_jVRz0Lh*Qf?IysDo4m5J z@^qY-?Nc-}Gcz?#%r-#Rbz_{^ZTbMmjEx4+G#vy0FCr4l>c3;&L9YEqo12?^va_@E zuH9~*UR+!#R*MNC{q61TH(sxoOC%C60pP^e7qBcFh(scbJkQU&-R@~CfZOe!=6QZT z5{WFbEE}->iwGfIUDvz4Ue8cf^~wsMs_Ip**E4io?-D|~wgIZDp2@N-`+UBIa=CnL z1t^!x$3CBLL6&7%Rn;@w08P`*^ZC3a2*MJ_ah_~8yJ61BX0sa{$9V)nSjy+~lBQ|r zLydEoxeeUZQ!EzuMNt%z$>ghnZL9(S6bgk80DxOtTdxle4nB&a_zVDk+}ce;p^#Xu zR*w)7OQq8O=H_NDm&?5^7K{6ch}CNKC=?2b6PcaU>GY@5>0G1HIQe68&1Um7lgVs2 zolgJ6Zu+-MrP9}Wz5WdVD2v7$4?t1W3-IA{wR~+As{G*=&9$gj`y^DyWCo^*;yv8UO)%ggj0+ RSl$2t002ovPDHLkV1n8FbbJ5+ literal 0 HcmV?d00001 diff --git a/java/res/xml/method.xml b/java/res/xml/method.xml index 3bff3fccd..b1f737903 100644 --- a/java/res/xml/method.xml +++ b/java/res/xml/method.xml @@ -38,7 +38,7 @@ android:label="@string/subtype_mode_en_voice" android:imeSubtypeLocale="en" android:imeSubtypeMode="voice" - android:imeSubtypeExtraValue="excludeFromLastInputMethod" + android:imeSubtypeExtraValue="excludeFromLastInputMethod,requireNetworkConnectivity" /> diff --git a/java/src/com/android/inputmethod/keyboard/Key.java b/java/src/com/android/inputmethod/keyboard/Key.java index 35bafea80..23886ad97 100644 --- a/java/src/com/android/inputmethod/keyboard/Key.java +++ b/java/src/com/android/inputmethod/keyboard/Key.java @@ -95,6 +95,8 @@ public class Key { public boolean mPressed; /** If this is a sticky key, is it on? */ public boolean mOn; + /** Key is enabled or not. */ + public boolean mEnabled = true; private final static int[] KEY_STATE_NORMAL_ON = { android.R.attr.state_checkable, @@ -385,8 +387,9 @@ public class Key { * @see android.graphics.drawable.StateListDrawable#setState(int[]) */ public int[] getCurrentDrawableState() { + final boolean pressed = mEnabled && mPressed; if (isFunctionalKey()) { - if (mPressed) { + if (pressed) { return KEY_STATE_FUNCTIONAL_PRESSED; } else { return KEY_STATE_FUNCTIONAL_NORMAL; @@ -396,20 +399,20 @@ public class Key { int[] states = KEY_STATE_NORMAL; if (mOn) { - if (mPressed) { + if (pressed) { states = KEY_STATE_PRESSED_ON; } else { states = KEY_STATE_NORMAL_ON; } } else { if (mSticky) { - if (mPressed) { + if (pressed) { states = KEY_STATE_PRESSED_OFF; } else { states = KEY_STATE_NORMAL_OFF; } } else { - if (mPressed) { + if (pressed) { states = KEY_STATE_PRESSED; } } diff --git a/java/src/com/android/inputmethod/keyboard/Keyboard.java b/java/src/com/android/inputmethod/keyboard/Keyboard.java index 863421f18..3a0bf53ab 100644 --- a/java/src/com/android/inputmethod/keyboard/Keyboard.java +++ b/java/src/com/android/inputmethod/keyboard/Keyboard.java @@ -107,11 +107,6 @@ public class Keyboard { private final HashSet mShiftLockEnabled = new HashSet(); private final KeyboardShiftState mShiftState = new KeyboardShiftState(); - /** Space key and its icons */ - protected Key mSpaceKey; - protected Drawable mSpaceIcon; - protected Drawable mSpacePreviewIcon; - /** Total height of the keyboard, including the padding and keys */ private int mTotalHeight; @@ -350,12 +345,6 @@ public class Keyboard { return mId != null && mId.isNumberKeyboard(); } - public void setSpaceKey(Key space) { - mSpaceKey = space; - mSpaceIcon = space.getIcon(); - mSpacePreviewIcon = space.getPreviewIcon(); - } - private void computeNearestNeighbors() { // Round-up so we don't have any pixels outside the grid mCellWidth = (getMinWidth() + GRID_WIDTH - 1) / GRID_WIDTH; diff --git a/java/src/com/android/inputmethod/keyboard/KeyboardParser.java b/java/src/com/android/inputmethod/keyboard/KeyboardParser.java index c41d57075..e8324e5fd 100644 --- a/java/src/com/android/inputmethod/keyboard/KeyboardParser.java +++ b/java/src/com/android/inputmethod/keyboard/KeyboardParser.java @@ -286,8 +286,6 @@ public class KeyboardParser { keys.add(key); if (key.mCode == Keyboard.CODE_SHIFT) mKeyboard.getShiftKeys().add(key); - if (key.mCode == Keyboard.CODE_SPACE) - mKeyboard.setSpaceKey(key); endKey(key); } } diff --git a/java/src/com/android/inputmethod/keyboard/KeyboardSwitcher.java b/java/src/com/android/inputmethod/keyboard/KeyboardSwitcher.java index 558de66a4..2648ff3d4 100644 --- a/java/src/com/android/inputmethod/keyboard/KeyboardSwitcher.java +++ b/java/src/com/android/inputmethod/keyboard/KeyboardSwitcher.java @@ -17,11 +17,11 @@ package com.android.inputmethod.keyboard; import com.android.inputmethod.latin.LatinIME; -import com.android.inputmethod.latin.Settings; -import com.android.inputmethod.latin.Utils; import com.android.inputmethod.latin.LatinImeLogger; import com.android.inputmethod.latin.R; +import com.android.inputmethod.latin.Settings; import com.android.inputmethod.latin.SubtypeSwitcher; +import com.android.inputmethod.latin.Utils; import android.content.Context; import android.content.SharedPreferences; @@ -222,8 +222,9 @@ public class KeyboardSwitcher implements SharedPreferences.OnSharedPreferenceCha keyboard.setShifted(false); // If the cached keyboard had been switched to another keyboard while the language was // displayed on its spacebar, it might have had arbitrary text fade factor. In such case, - // we should reset the text fade factor. + // we should reset the text fade factor. It is also applicable to shortcut key. keyboard.setSpacebarTextFadeFactor(0.0f, null); + keyboard.updateShortcutKey(mSubtypeSwitcher.isShortcutAvailable(), null); return keyboard; } diff --git a/java/src/com/android/inputmethod/keyboard/LatinKeyboard.java b/java/src/com/android/inputmethod/keyboard/LatinKeyboard.java index 1977f5fae..dc134d6be 100644 --- a/java/src/com/android/inputmethod/keyboard/LatinKeyboard.java +++ b/java/src/com/android/inputmethod/keyboard/LatinKeyboard.java @@ -45,18 +45,30 @@ public class LatinKeyboard extends Keyboard { public static final int OPACITY_FULLY_OPAQUE = 255; private static final int SPACE_LED_LENGTH_PERCENT = 80; + private final Context mContext; + + /* Space key and its icons, drawables and colors. */ + private final Key mSpaceKey; + private final Drawable mSpaceIcon; + private final Drawable mSpacePreviewIcon; + private final int[] mSpaceKeyIndexArray; private final Drawable mSpaceAutoCorrectionIndicator; private final Drawable mButtonArrowLeftIcon; private final Drawable mButtonArrowRightIcon; private final int mSpacebarTextColor; private final int mSpacebarTextShadowColor; + private final int mSpacebarVerticalCorrection; private float mSpacebarTextFadeFactor = 0.0f; - private final int[] mSpaceKeyIndexArray; private int mSpaceDragStartX; private int mSpaceDragLastDiff; - private final Context mContext; private boolean mCurrentlyInSpace; private SlidingLocaleDrawable mSlidingLocaleIcon; + + /* Shortcut key and its icons if available */ + private final Key mShortcutKey; + private final Drawable mEnabledShortcutIcon; + private final Drawable mDisabledShortcutIcon; + private int[] mPrefLetterFrequencies; private int mPrefLetter; private int mPrefLetterX; @@ -74,8 +86,6 @@ public class LatinKeyboard extends Keyboard { // its short language name will be used instead. private static final float MINIMUM_SCALE_OF_LANGUAGE_NAME = 0.8f; - private static int sSpacebarVerticalCorrection; - private static final String SMALL_TEXT_SIZE_OF_LANGUAGE_ON_SPACEBAR = "small"; private static final String MEDIUM_TEXT_SIZE_OF_LANGUAGE_ON_SPACEBAR = "medium"; @@ -83,21 +93,47 @@ public class LatinKeyboard extends Keyboard { super(context, id.getXmlId(), id); final Resources res = context.getResources(); mContext = context; + + final List keys = getKeys(); + int spaceKeyIndex = -1; + int shortcutKeyIndex = -1; + final int keyCount = keys.size(); + for (int index = 0; index < keyCount; index++) { + // For now, assuming there are up to one space key and one shortcut key respectively. + switch (keys.get(index).mCode) { + case CODE_SPACE: + spaceKeyIndex = index; + break; + case CODE_VOICE: + shortcutKeyIndex = index; + break; + } + } + + // The index of space key is available only after Keyboard constructor has finished. + mSpaceKey = (spaceKeyIndex >= 0) ? keys.get(spaceKeyIndex) : null; + mSpaceIcon = (mSpaceKey != null) ? mSpaceKey.getIcon() : null; + mSpacePreviewIcon = (mSpaceKey != null) ? mSpaceKey.getPreviewIcon() : null; + mSpaceKeyIndexArray = new int[] { spaceKeyIndex }; + + mShortcutKey = (shortcutKeyIndex >= 0) ? keys.get(shortcutKeyIndex) : null; + mEnabledShortcutIcon = (mShortcutKey != null) ? mShortcutKey.getIcon() : null; + mSpacebarTextColor = res.getColor(R.color.latinkeyboard_bar_language_text); if (id.mColorScheme == KeyboardView.COLOR_SCHEME_BLACK) { mSpacebarTextShadowColor = res.getColor( R.color.latinkeyboard_bar_language_shadow_black); + mDisabledShortcutIcon = res.getDrawable(R.drawable.sym_keyboard_mic_disabled); } else { // default color scheme is KeyboardView.COLOR_SCHEME_WHITE mSpacebarTextShadowColor = res.getColor( R.color.latinkeyboard_bar_language_shadow_white); + mDisabledShortcutIcon = res.getDrawable(R.drawable.sym_bkeyboard_mic_disabled); } mSpaceAutoCorrectionIndicator = res.getDrawable(R.drawable.sym_keyboard_space_led); mButtonArrowLeftIcon = res.getDrawable(R.drawable.sym_keyboard_language_arrows_left); mButtonArrowRightIcon = res.getDrawable(R.drawable.sym_keyboard_language_arrows_right); - sSpacebarVerticalCorrection = res.getDimensionPixelOffset( + mSpacebarVerticalCorrection = res.getDimensionPixelOffset( R.dimen.spacebar_vertical_correction); - // The index of space key is available only after Keyboard constructor has finished. - mSpaceKeyIndexArray = new int[] { indexOf(CODE_SPACE) }; } public void setSpacebarTextFadeFactor(float fadeFactor, LatinKeyboardView view) { @@ -113,6 +149,15 @@ public class LatinKeyboard extends Keyboard { return newColor; } + public void updateShortcutKey(boolean available, LatinKeyboardView view) { + if (mShortcutKey == null) + return; + mShortcutKey.mEnabled = available; + mShortcutKey.setIcon(available ? mEnabledShortcutIcon : mDisabledShortcutIcon); + if (view != null) + view.invalidateKey(mShortcutKey); + } + /** * @return a key which should be invalidated. */ @@ -316,7 +361,7 @@ public class LatinKeyboard extends Keyboard { int y = pointY; final int code = key.mCode; if (code == CODE_SPACE) { - y += LatinKeyboard.sSpacebarVerticalCorrection; + y += mSpacebarVerticalCorrection; if (SubtypeSwitcher.getInstance().useSpacebarLanguageSwitcher() && SubtypeSwitcher.getInstance().getEnabledKeyboardLocaleCount() > 1) { if (mCurrentlyInSpace) { @@ -442,15 +487,6 @@ public class LatinKeyboard extends Keyboard { } } - private int indexOf(int code) { - List keys = getKeys(); - int count = keys.size(); - for (int i = 0; i < count; i++) { - if (keys.get(i).mCode == code) return i; - } - return -1; - } - private int getTextSizeFromTheme(int style, int defValue) { TypedArray array = mContext.getTheme().obtainStyledAttributes( style, new int[] { android.R.attr.textSize }); diff --git a/java/src/com/android/inputmethod/keyboard/PointerTracker.java b/java/src/com/android/inputmethod/keyboard/PointerTracker.java index 49f29f923..cf379f0bf 100644 --- a/java/src/com/android/inputmethod/keyboard/PointerTracker.java +++ b/java/src/com/android/inputmethod/keyboard/PointerTracker.java @@ -561,7 +561,8 @@ public class PointerTracker { codes[1] = codes[0]; codes[0] = code; } - callListenerOnCodeInput(code, codes, x, y); + if (key.mEnabled) + callListenerOnCodeInput(code, codes, x, y); callListenerOnRelease(code); } } diff --git a/java/src/com/android/inputmethod/latin/SubtypeSwitcher.java b/java/src/com/android/inputmethod/latin/SubtypeSwitcher.java index c1e14ad18..67ca9aaad 100644 --- a/java/src/com/android/inputmethod/latin/SubtypeSwitcher.java +++ b/java/src/com/android/inputmethod/latin/SubtypeSwitcher.java @@ -17,16 +17,23 @@ package com.android.inputmethod.latin; import com.android.inputmethod.keyboard.KeyboardSwitcher; +import com.android.inputmethod.keyboard.LatinKeyboard; +import com.android.inputmethod.keyboard.LatinKeyboardView; import com.android.inputmethod.voice.SettingsUtil; import com.android.inputmethod.voice.VoiceIMEConnector; import com.android.inputmethod.voice.VoiceInput; +import android.content.BroadcastReceiver; import android.content.Context; +import android.content.Intent; +import android.content.IntentFilter; import android.content.SharedPreferences; import android.content.pm.PackageManager; import android.content.res.Configuration; import android.content.res.Resources; import android.graphics.drawable.Drawable; +import android.net.ConnectivityManager; +import android.net.NetworkInfo; import android.os.IBinder; import android.text.TextUtils; import android.util.Log; @@ -47,6 +54,8 @@ public class SubtypeSwitcher { private static final char LOCALE_SEPARATER = '_'; private static final String KEYBOARD_MODE = "keyboard"; private static final String VOICE_MODE = "voice"; + private static final String SUBTYPE_EXTRAVALUE_REQUIRE_NETWORK_CONNECTIVITY = + "requireNetworkConnectivity"; private final TextUtils.SimpleStringSplitter mLocaleSplitter = new TextUtils.SimpleStringSplitter(LOCALE_SEPARATER); @@ -55,17 +64,17 @@ public class SubtypeSwitcher { private /* final */ SharedPreferences mPrefs; private /* final */ InputMethodManager mImm; private /* final */ Resources mResources; + private /* final */ ConnectivityManager mConnectivityManager; + private /* final */ boolean mConfigUseSpacebarLanguageSwitcher; private final ArrayList mEnabledKeyboardSubtypesOfCurrentInputMethod = new ArrayList(); private final ArrayList mEnabledLanguagesOfCurrentInputMethod = new ArrayList(); - private boolean mConfigUseSpacebarLanguageSwitcher; - /*-----------------------------------------------------------*/ // Variants which should be changed only by reload functions. private boolean mNeedsToDisplayLanguage; private boolean mIsSystemLanguageSameAsInputLanguage; - private InputMethodInfo mShortcutInfo; + private InputMethodInfo mShortcutInputMethodInfo; private InputMethodSubtype mShortcutSubtype; private List mAllEnabledSubtypesOfCurrentInputMethod; private Locale mSystemLocale; @@ -75,6 +84,8 @@ public class SubtypeSwitcher { private VoiceInput mVoiceInput; /*-----------------------------------------------------------*/ + private boolean mIsNetworkConnected; + public static SubtypeSwitcher getInstance() { return sInstance; } @@ -95,6 +106,8 @@ public class SubtypeSwitcher { mService = service; mResources = service.getResources(); mImm = (InputMethodManager) service.getSystemService(Context.INPUT_METHOD_SERVICE); + mConnectivityManager = (ConnectivityManager) service.getSystemService( + Context.CONNECTIVITY_SERVICE); mEnabledKeyboardSubtypesOfCurrentInputMethod.clear(); mEnabledLanguagesOfCurrentInputMethod.clear(); mSystemLocale = null; @@ -109,6 +122,17 @@ public class SubtypeSwitcher { R.bool.config_use_spacebar_language_switcher); if (mConfigUseSpacebarLanguageSwitcher) initLanguageSwitcher(service); + + final NetworkInfo info = mConnectivityManager.getActiveNetworkInfo(); + mIsNetworkConnected = (info != null && info.isConnected()); + final BroadcastReceiver receiver = new BroadcastReceiver() { + @Override + public void onReceive(Context context, Intent intent) { + onNetworkStateChanged(intent); + } + }; + service.registerReceiver(receiver, + new IntentFilter(ConnectivityManager.CONNECTIVITY_ACTION)); } // Update all parameters stored in SubtypeSwitcher. @@ -165,7 +189,8 @@ public class SubtypeSwitcher { private void updateShortcutIME() { if (DBG) { Log.d(TAG, "Update shortcut IME from : " - + (mShortcutInfo == null ? "" : mShortcutInfo.getId()) + ", " + + (mShortcutInputMethodInfo == null + ? "" : mShortcutInputMethodInfo.getId()) + ", " + (mShortcutSubtype == null ? "" : (mShortcutSubtype.getLocale() + ", " + mShortcutSubtype.getMode()))); } @@ -176,7 +201,7 @@ public class SubtypeSwitcher { List subtypes = shortcuts.get(imi); // TODO: Returns the first found IMI for now. Should handle all shortcuts as // appropriate. - mShortcutInfo = imi; + mShortcutInputMethodInfo = imi; // TODO: Pick up the first found subtype for now. Should handle all subtypes // as appropriate. mShortcutSubtype = subtypes.size() > 0 ? subtypes.get(0) : null; @@ -184,7 +209,8 @@ public class SubtypeSwitcher { } if (DBG) { Log.d(TAG, "Update shortcut IME to : " - + (mShortcutInfo == null ? "" : mShortcutInfo.getId()) + ", " + + (mShortcutInputMethodInfo == null + ? "" : mShortcutInputMethodInfo.getId()) + ", " + (mShortcutSubtype == null ? "" : (mShortcutSubtype.getLocale() + ", " + mShortcutSubtype.getMode()))); } @@ -289,10 +315,10 @@ public class SubtypeSwitcher { public void switchToShortcutIME() { final IBinder token = mService.getWindow().getWindow().getAttributes().token; - if (token == null || mShortcutInfo == null) { + if (token == null || mShortcutInputMethodInfo == null) { return; } - final String imiId = mShortcutInfo.getId(); + final String imiId = mShortcutInputMethodInfo.getId(); final InputMethodSubtype subtype = mShortcutSubtype; new Thread("SwitchToShortcutIME") { @Override @@ -303,7 +329,7 @@ public class SubtypeSwitcher { } public Drawable getShortcutIcon() { - return getSubtypeIcon(mShortcutInfo, mShortcutSubtype); + return getSubtypeIcon(mShortcutInputMethodInfo, mShortcutSubtype); } private Drawable getSubtypeIcon(InputMethodInfo imi, InputMethodSubtype subtype) { @@ -332,6 +358,38 @@ public class SubtypeSwitcher { return null; } + private static boolean contains(String[] hay, String needle) { + for (String element : hay) { + if (element.equals(needle)) + return true; + } + return false; + } + + public boolean isShortcutAvailable() { + if (mShortcutInputMethodInfo == null) + return false; + if (mShortcutSubtype != null && contains(mShortcutSubtype.getExtraValue().split(","), + SUBTYPE_EXTRAVALUE_REQUIRE_NETWORK_CONNECTIVITY)) { + return mIsNetworkConnected; + } + return true; + } + + private void onNetworkStateChanged(Intent intent) { + final boolean noConnection = intent.getBooleanExtra( + ConnectivityManager.EXTRA_NO_CONNECTIVITY, false); + mIsNetworkConnected = !noConnection; + + final LatinKeyboardView inputView = KeyboardSwitcher.getInstance().getInputView(); + if (inputView != null) { + final LatinKeyboard keyboard = inputView.getLatinKeyboard(); + if (keyboard != null) { + keyboard.updateShortcutKey(isShortcutAvailable(), inputView); + } + } + } + ////////////////////////////////// // Language Switching functions // //////////////////////////////////