am c99c0ed9: Merge "Notify keyboard language on space bar when it has changed" into honeycomb
* commit 'c99c0ed939bb441a4ee7b2c3eb643620f3dbce28': Notify keyboard language on space bar when it has changedmain
commit
42b62c1440
|
@ -28,6 +28,9 @@
|
|||
<bool name="config_digit_popup_characters_enabled">false</bool>
|
||||
<!-- Whether or not Popup on key press is enabled by default -->
|
||||
<bool name="config_default_popup_preview">false</bool>
|
||||
<bool name="config_use_spacebar_language_switcher">false</bool>
|
||||
<!-- The language is never displayed if == 0, always displayed if < 0 -->
|
||||
<integer name="config_delay_before_fadeout_language_on_spacebar">1200</integer>
|
||||
<!-- This configuration is the index of the array {@link KeyboardSwitcher.KEYBOARD_THEMES}. -->
|
||||
<string name="config_default_keyboard_theme_id" translatable="false">5</string>
|
||||
<string name="config_text_size_of_language_on_spacebar" translatable="false">medium</string>
|
||||
|
|
|
@ -31,6 +31,10 @@
|
|||
<bool name="config_digit_popup_characters_enabled">true</bool>
|
||||
<!-- Whether or not Popup on key press is enabled by default -->
|
||||
<bool name="config_default_popup_preview">true</bool>
|
||||
<bool name="config_use_spacebar_language_switcher">true</bool>
|
||||
<!-- The language is never displayed if == 0, always displayed if < 0 -->
|
||||
<integer name="config_delay_before_fadeout_language_on_spacebar">-1</integer>
|
||||
<integer name="config_duration_of_fadeout_language_on_spacebar">50</integer>
|
||||
<integer name="config_delay_before_preview">0</integer>
|
||||
<integer name="config_delay_after_preview">10</integer>
|
||||
<integer name="config_preview_fadein_anim_time">0</integer>
|
||||
|
|
|
@ -57,7 +57,6 @@
|
|||
<key-style
|
||||
latin:styleName="nonSpecialBackgroundSpaceKeyStyle"
|
||||
latin:code="@integer/key_space"
|
||||
latin:keyIcon="@drawable/sym_keyboard_space_holo"
|
||||
latin:iconPreview="@drawable/sym_keyboard_feedback_space" />
|
||||
<key-style
|
||||
latin:styleName="smileyKeyStyle"
|
||||
|
@ -102,12 +101,10 @@
|
|||
<key-style
|
||||
latin:styleName="spaceKeyStyle"
|
||||
latin:code="@integer/key_space"
|
||||
latin:keyIcon="@drawable/sym_bkeyboard_space"
|
||||
latin:iconPreview="@drawable/sym_keyboard_feedback_space" />
|
||||
<key-style
|
||||
latin:styleName="nonSpecialBackgroundSpaceKeyStyle"
|
||||
latin:code="@integer/key_space"
|
||||
latin:keyIcon="@drawable/sym_bkeyboard_space"
|
||||
latin:iconPreview="@drawable/sym_keyboard_feedback_space" />
|
||||
<key-style
|
||||
latin:styleName="smileyKeyStyle"
|
||||
|
|
|
@ -81,7 +81,6 @@
|
|||
<key-style
|
||||
latin:styleName="numSpaceKeyStyle"
|
||||
latin:code="@integer/key_space"
|
||||
latin:keyIcon="@drawable/sym_keyboard_space_holo"
|
||||
latin:iconPreview="@drawable/sym_keyboard_feedback_space" />
|
||||
</case>
|
||||
<case
|
||||
|
@ -143,7 +142,6 @@
|
|||
<key-style
|
||||
latin:styleName="numSpaceKeyStyle"
|
||||
latin:code="@integer/key_space"
|
||||
latin:keyIcon="@drawable/sym_bkeyboard_space"
|
||||
latin:iconPreview="@drawable/sym_keyboard_feedback_space" />
|
||||
</case>
|
||||
</switch>
|
||||
|
|
|
@ -157,7 +157,14 @@ public class KeyboardSwitcher implements SharedPreferences.OnSharedPreferenceCha
|
|||
boolean voiceButtonOnPrimary) {
|
||||
mAutoModeSwitchState = AUTO_MODE_SWITCH_STATE_ALPHA;
|
||||
try {
|
||||
if (mInputView == null) return;
|
||||
final Keyboard oldKeyboard = mInputView.getKeyboard();
|
||||
loadKeyboardInternal(mode, imeOptions, voiceKeyEnabled, voiceButtonOnPrimary, false);
|
||||
final Keyboard newKeyboard = mInputView.getKeyboard();
|
||||
if (newKeyboard.isAlphaKeyboard() && (oldKeyboard == null
|
||||
|| !newKeyboard.mId.mLocale.equals(oldKeyboard.mId.mLocale))) {
|
||||
mInputMethodService.mHandler.startDisplayLanguageOnSpacebar();
|
||||
}
|
||||
} catch (RuntimeException e) {
|
||||
Log.w(TAG, e);
|
||||
LatinImeLogger.logOnException(mode + "," + imeOptions, e);
|
||||
|
@ -167,6 +174,11 @@ public class KeyboardSwitcher implements SharedPreferences.OnSharedPreferenceCha
|
|||
private void loadKeyboardInternal(int mode, int imeOptions, boolean voiceButtonEnabled,
|
||||
boolean voiceButtonOnPrimary, boolean isSymbols) {
|
||||
if (mInputView == null) return;
|
||||
final Keyboard oldKeyboard = mInputView.getKeyboard();
|
||||
final KeyboardId id = getKeyboardId(mode, imeOptions, isSymbols);
|
||||
if (oldKeyboard != null && oldKeyboard.mId.equals(id))
|
||||
return;
|
||||
|
||||
mInputView.setPreviewEnabled(mInputMethodService.getPopupOn());
|
||||
|
||||
mMode = mode;
|
||||
|
@ -178,11 +190,8 @@ public class KeyboardSwitcher implements SharedPreferences.OnSharedPreferenceCha
|
|||
mHasSettingsKey = getSettingsKeyMode(mPrefs, mInputMethodService);
|
||||
makeSymbolsKeyboardIds();
|
||||
|
||||
KeyboardId id = getKeyboardId(mode, imeOptions, isSymbols);
|
||||
LatinKeyboard keyboard = getKeyboard(id);
|
||||
|
||||
mCurrentId = id;
|
||||
mInputView.setKeyboard(keyboard);
|
||||
mInputView.setKeyboard(getKeyboard(id));
|
||||
}
|
||||
|
||||
private LatinKeyboard getKeyboard(KeyboardId id) {
|
||||
|
@ -210,6 +219,10 @@ public class KeyboardSwitcher implements SharedPreferences.OnSharedPreferenceCha
|
|||
|
||||
keyboard.onAutoCorrectionStateChanged(mIsAutoCorrectionActive);
|
||||
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.
|
||||
keyboard.setSpacebarTextFadeFactor(0.0f, null);
|
||||
return keyboard;
|
||||
}
|
||||
|
||||
|
|
|
@ -912,9 +912,8 @@ public class KeyboardView extends View implements PointerTracker.UIProxy {
|
|||
// We should re-draw popup preview when 1) we need to hide the preview, 2) we will show
|
||||
// the space key preview and 3) pointer moves off the space key to other letter key, we
|
||||
// should hide the preview of the previous key.
|
||||
@SuppressWarnings("unused")
|
||||
final boolean hidePreviewOrShowSpaceKeyPreview = (tracker == null)
|
||||
|| (SubtypeSwitcher.USE_SPACEBAR_LANGUAGE_SWITCHER
|
||||
|| (SubtypeSwitcher.getInstance().useSpacebarLanguageSwitcher()
|
||||
&& SubtypeSwitcher.getInstance().needsToDisplayLanguage()
|
||||
&& (tracker.isSpaceKey(keyIndex) || tracker.isSpaceKey(oldKeyIndex)));
|
||||
// If key changed and preview is on or the key is space (language switch is enabled)
|
||||
|
|
|
@ -24,6 +24,7 @@ import android.content.res.Resources;
|
|||
import android.content.res.TypedArray;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.Canvas;
|
||||
import android.graphics.Color;
|
||||
import android.graphics.Paint;
|
||||
import android.graphics.Paint.Align;
|
||||
import android.graphics.PorterDuff;
|
||||
|
@ -47,7 +48,9 @@ public class LatinKeyboard extends Keyboard {
|
|||
private final Drawable mSpaceAutoCorrectionIndicator;
|
||||
private final Drawable mButtonArrowLeftIcon;
|
||||
private final Drawable mButtonArrowRightIcon;
|
||||
private final int mSpaceBarTextShadowColor;
|
||||
private final int mSpacebarTextColor;
|
||||
private final int mSpacebarTextShadowColor;
|
||||
private float mSpacebarTextFadeFactor = 0.0f;
|
||||
private final int[] mSpaceKeyIndexArray;
|
||||
private int mSpaceDragStartX;
|
||||
private int mSpaceDragLastDiff;
|
||||
|
@ -67,6 +70,7 @@ public class LatinKeyboard extends Keyboard {
|
|||
private static final float SPACEBAR_POPUP_MIN_RATIO = 0.4f;
|
||||
// Height in space key the language name will be drawn. (proportional to space key height)
|
||||
public static final float SPACEBAR_LANGUAGE_BASELINE = 0.6f;
|
||||
private static final float SPACEBAR_LANGUAGE_BASELINE_WITHOUT_ICON = 0.65f;
|
||||
// If the full language name needs to be smaller than this value to be drawn on space key,
|
||||
// its short language name will be used instead.
|
||||
private static final float MINIMUM_SCALE_OF_LANGUAGE_NAME = 0.8f;
|
||||
|
@ -80,11 +84,12 @@ public class LatinKeyboard extends Keyboard {
|
|||
super(context, id.getXmlId(), id);
|
||||
final Resources res = context.getResources();
|
||||
mContext = context;
|
||||
mSpacebarTextColor = res.getColor(R.color.latinkeyboard_bar_language_text);
|
||||
if (id.mColorScheme == KeyboardView.COLOR_SCHEME_BLACK) {
|
||||
mSpaceBarTextShadowColor = res.getColor(
|
||||
mSpacebarTextShadowColor = res.getColor(
|
||||
R.color.latinkeyboard_bar_language_shadow_black);
|
||||
} else { // default color scheme is KeyboardView.COLOR_SCHEME_WHITE
|
||||
mSpaceBarTextShadowColor = res.getColor(
|
||||
mSpacebarTextShadowColor = res.getColor(
|
||||
R.color.latinkeyboard_bar_language_shadow_white);
|
||||
}
|
||||
mSpaceAutoCorrectionIndicator = res.getDrawable(R.drawable.sym_keyboard_space_led);
|
||||
|
@ -96,25 +101,38 @@ public class LatinKeyboard extends Keyboard {
|
|||
mSpaceKeyIndexArray = new int[] { indexOf(CODE_SPACE) };
|
||||
}
|
||||
|
||||
public void setSpacebarTextFadeFactor(float fadeFactor, LatinKeyboardView view) {
|
||||
mSpacebarTextFadeFactor = fadeFactor;
|
||||
updateSpacebarForLocale(false);
|
||||
if (view != null)
|
||||
view.invalidateKey(mSpaceKey);
|
||||
}
|
||||
|
||||
private static int getSpacebarTextColor(int color, float fadeFactor) {
|
||||
final int newColor = Color.argb((int)(Color.alpha(color) * fadeFactor),
|
||||
Color.red(color), Color.green(color), Color.blue(color));
|
||||
return newColor;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return a key which should be invalidated.
|
||||
*/
|
||||
public Key onAutoCorrectionStateChanged(boolean isAutoCorrection) {
|
||||
updateSpaceBarForLocale(isAutoCorrection);
|
||||
updateSpacebarForLocale(isAutoCorrection);
|
||||
return mSpaceKey;
|
||||
}
|
||||
|
||||
private void updateSpaceBarForLocale(boolean isAutoCorrection) {
|
||||
private void updateSpacebarForLocale(boolean isAutoCorrection) {
|
||||
final Resources res = mContext.getResources();
|
||||
// If application locales are explicitly selected.
|
||||
if (SubtypeSwitcher.getInstance().needsToDisplayLanguage()) {
|
||||
mSpaceKey.setIcon(new BitmapDrawable(res,
|
||||
drawSpaceBar(OPACITY_FULLY_OPAQUE, isAutoCorrection)));
|
||||
drawSpacebar(OPACITY_FULLY_OPAQUE, isAutoCorrection)));
|
||||
} else {
|
||||
// sym_keyboard_space_led can be shared with Black and White symbol themes.
|
||||
if (isAutoCorrection) {
|
||||
mSpaceKey.setIcon(new BitmapDrawable(res,
|
||||
drawSpaceBar(OPACITY_FULLY_OPAQUE, isAutoCorrection)));
|
||||
drawSpacebar(OPACITY_FULLY_OPAQUE, isAutoCorrection)));
|
||||
} else {
|
||||
mSpaceKey.setIcon(mSpaceIcon);
|
||||
}
|
||||
|
@ -129,7 +147,7 @@ public class LatinKeyboard extends Keyboard {
|
|||
}
|
||||
|
||||
// Layout local language name and left and right arrow on spacebar.
|
||||
private static String layoutSpaceBar(Paint paint, Locale locale, Drawable lArrow,
|
||||
private static String layoutSpacebar(Paint paint, Locale locale, Drawable lArrow,
|
||||
Drawable rArrow, int width, int height, float origTextSize,
|
||||
boolean allowVariableTextSize) {
|
||||
final float arrowWidth = lArrow.getIntrinsicWidth();
|
||||
|
@ -138,7 +156,7 @@ public class LatinKeyboard extends Keyboard {
|
|||
final Rect bounds = new Rect();
|
||||
|
||||
// Estimate appropriate language name text size to fit in maxTextWidth.
|
||||
String language = SubtypeSwitcher.getDisplayLanguage(locale);
|
||||
String language = SubtypeSwitcher.getFullDisplayName(locale, true);
|
||||
int textWidth = getTextWidth(paint, language, origTextSize, bounds);
|
||||
// Assuming text width and text size are proportional to each other.
|
||||
float textSize = origTextSize * Math.min(maxTextWidth / textWidth, 1.0f);
|
||||
|
@ -171,8 +189,7 @@ public class LatinKeyboard extends Keyboard {
|
|||
return language;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
private Bitmap drawSpaceBar(int opacity, boolean isAutoCorrection) {
|
||||
private Bitmap drawSpacebar(int opacity, boolean isAutoCorrection) {
|
||||
final int width = mSpaceKey.mWidth;
|
||||
final int height = mSpaceIcon != null ? mSpaceIcon.getIntrinsicHeight() : mSpaceKey.mHeight;
|
||||
final Bitmap buffer = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
|
||||
|
@ -202,21 +219,22 @@ public class LatinKeyboard extends Keyboard {
|
|||
}
|
||||
|
||||
final boolean allowVariableTextSize = true;
|
||||
final String language = layoutSpaceBar(paint, subtypeSwitcher.getInputLocale(),
|
||||
final String language = layoutSpacebar(paint, subtypeSwitcher.getInputLocale(),
|
||||
mButtonArrowLeftIcon, mButtonArrowRightIcon, width, height,
|
||||
getTextSizeFromTheme(textStyle, defaultTextSize),
|
||||
allowVariableTextSize);
|
||||
|
||||
// Draw language text with shadow
|
||||
final float baseline = height * SPACEBAR_LANGUAGE_BASELINE;
|
||||
final float baseline = height * (mSpaceIcon != null ? SPACEBAR_LANGUAGE_BASELINE
|
||||
: SPACEBAR_LANGUAGE_BASELINE_WITHOUT_ICON);
|
||||
final float descent = paint.descent();
|
||||
paint.setColor(mSpaceBarTextShadowColor);
|
||||
paint.setColor(getSpacebarTextColor(mSpacebarTextShadowColor, mSpacebarTextFadeFactor));
|
||||
canvas.drawText(language, width / 2, baseline - descent - 1, paint);
|
||||
paint.setColor(res.getColor(R.color.latinkeyboard_bar_language_text));
|
||||
paint.setColor(getSpacebarTextColor(mSpacebarTextColor, mSpacebarTextFadeFactor));
|
||||
canvas.drawText(language, width / 2, baseline - descent, paint);
|
||||
|
||||
// Put arrows that are already layed out on either side of the text
|
||||
if (SubtypeSwitcher.USE_SPACEBAR_LANGUAGE_SWITCHER
|
||||
if (SubtypeSwitcher.getInstance().useSpacebarLanguageSwitcher()
|
||||
&& subtypeSwitcher.getEnabledKeyboardLocaleCount() > 1) {
|
||||
mButtonArrowLeftIcon.draw(canvas);
|
||||
mButtonArrowRightIcon.draw(canvas);
|
||||
|
@ -291,7 +309,6 @@ public class LatinKeyboard extends Keyboard {
|
|||
* switching input languages.
|
||||
*/
|
||||
@Override
|
||||
@SuppressWarnings("unused") // SubtypeSwitcher.USE_SPACEBAR_LANGUAGE_SWITCHER is constant
|
||||
public boolean isInside(Key key, int pointX, int pointY) {
|
||||
int x = pointX;
|
||||
int y = pointY;
|
||||
|
@ -302,7 +319,7 @@ public class LatinKeyboard extends Keyboard {
|
|||
if (code == CODE_DELETE) x -= key.mWidth / 6;
|
||||
} else if (code == CODE_SPACE) {
|
||||
y += LatinKeyboard.sSpacebarVerticalCorrection;
|
||||
if (SubtypeSwitcher.USE_SPACEBAR_LANGUAGE_SWITCHER
|
||||
if (SubtypeSwitcher.getInstance().useSpacebarLanguageSwitcher()
|
||||
&& SubtypeSwitcher.getInstance().getEnabledKeyboardLocaleCount() > 1) {
|
||||
if (mCurrentlyInSpace) {
|
||||
int diff = x - mSpaceDragStartX;
|
||||
|
|
|
@ -85,6 +85,14 @@ public class LatinKeyboardView extends KeyboardView {
|
|||
}
|
||||
}
|
||||
|
||||
public void setSpacebarTextFadeFactor(float fadeFactor, LatinKeyboard oldKeyboard) {
|
||||
final LatinKeyboard currentKeyboard = getLatinKeyboard();
|
||||
// We should not set text fade factor to the keyboard which does not display the language on
|
||||
// its spacebar.
|
||||
if (currentKeyboard != null && currentKeyboard == oldKeyboard)
|
||||
currentKeyboard.setSpacebarTextFadeFactor(fadeFactor, this);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean onLongPress(Key key) {
|
||||
int primaryCode = key.mCode;
|
||||
|
|
|
@ -21,6 +21,7 @@ import com.android.inputmethod.keyboard.KeyboardActionListener;
|
|||
import com.android.inputmethod.keyboard.KeyboardId;
|
||||
import com.android.inputmethod.keyboard.KeyboardSwitcher;
|
||||
import com.android.inputmethod.keyboard.KeyboardView;
|
||||
import com.android.inputmethod.keyboard.LatinKeyboard;
|
||||
import com.android.inputmethod.keyboard.LatinKeyboardView;
|
||||
import com.android.inputmethod.latin.Utils.RingCharBuffer;
|
||||
import com.android.inputmethod.voice.VoiceIMEConnector;
|
||||
|
@ -151,6 +152,8 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
|
|||
private boolean mAutoCap;
|
||||
private boolean mQuickFixes;
|
||||
private boolean mConfigSwipeDownDismissKeyboardEnabled;
|
||||
private int mConfigDelayBeforeFadeoutLanguageOnSpacebar;
|
||||
private int mConfigDurationOfFadeoutLanguageOnSpacebar;
|
||||
|
||||
private int mCorrectionMode;
|
||||
private int mCommittedLength;
|
||||
|
@ -241,9 +244,13 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
|
|||
private static final int MSG_UPDATE_OLD_SUGGESTIONS = 1;
|
||||
private static final int MSG_UPDATE_SHIFT_STATE = 2;
|
||||
private static final int MSG_VOICE_RESULTS = 3;
|
||||
private static final int MSG_FADEOUT_LANGUAGE_ON_SPACEBAR = 4;
|
||||
private static final int MSG_DISMISS_LANGUAGE_ON_SPACEBAR = 5;
|
||||
|
||||
@Override
|
||||
public void handleMessage(Message msg) {
|
||||
final KeyboardSwitcher switcher = mKeyboardSwitcher;
|
||||
final LatinKeyboardView inputView = switcher.getInputView();
|
||||
switch (msg.what) {
|
||||
case MSG_UPDATE_SUGGESTIONS:
|
||||
updateSuggestions();
|
||||
|
@ -252,12 +259,21 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
|
|||
setOldSuggestions();
|
||||
break;
|
||||
case MSG_UPDATE_SHIFT_STATE:
|
||||
mKeyboardSwitcher.updateShiftState();
|
||||
switcher.updateShiftState();
|
||||
break;
|
||||
case MSG_VOICE_RESULTS:
|
||||
mVoiceConnector.handleVoiceResults(preferCapitalization()
|
||||
|| (mKeyboardSwitcher.isAlphabetMode()
|
||||
&& mKeyboardSwitcher.isShiftedOrShiftLocked()));
|
||||
|| (switcher.isAlphabetMode() && switcher.isShiftedOrShiftLocked()));
|
||||
break;
|
||||
case MSG_FADEOUT_LANGUAGE_ON_SPACEBAR:
|
||||
if (inputView != null)
|
||||
inputView.setSpacebarTextFadeFactor(0.5f, (LatinKeyboard)msg.obj);
|
||||
sendMessageDelayed(obtainMessage(MSG_DISMISS_LANGUAGE_ON_SPACEBAR, msg.obj),
|
||||
mConfigDurationOfFadeoutLanguageOnSpacebar);
|
||||
break;
|
||||
case MSG_DISMISS_LANGUAGE_ON_SPACEBAR:
|
||||
if (inputView != null)
|
||||
inputView.setSpacebarTextFadeFactor(0.0f, (LatinKeyboard)msg.obj);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -297,6 +313,23 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
|
|||
public void updateVoiceResults() {
|
||||
sendMessage(obtainMessage(MSG_VOICE_RESULTS));
|
||||
}
|
||||
|
||||
public void startDisplayLanguageOnSpacebar() {
|
||||
removeMessages(MSG_FADEOUT_LANGUAGE_ON_SPACEBAR);
|
||||
removeMessages(MSG_DISMISS_LANGUAGE_ON_SPACEBAR);
|
||||
final LatinKeyboardView inputView = mKeyboardSwitcher.getInputView();
|
||||
if (inputView != null) {
|
||||
final LatinKeyboard keyboard = inputView.getLatinKeyboard();
|
||||
// The language is never displayed when the delay is zero.
|
||||
if (mConfigDelayBeforeFadeoutLanguageOnSpacebar != 0)
|
||||
inputView.setSpacebarTextFadeFactor(1.0f, keyboard);
|
||||
// The language is always displayed when the delay is negative.
|
||||
if (mConfigDelayBeforeFadeoutLanguageOnSpacebar > 0) {
|
||||
sendMessageDelayed(obtainMessage(MSG_FADEOUT_LANGUAGE_ON_SPACEBAR, keyboard),
|
||||
mConfigDelayBeforeFadeoutLanguageOnSpacebar);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -319,6 +352,10 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
|
|||
res.getBoolean(R.bool.default_recorrection_enabled));
|
||||
mConfigSwipeDownDismissKeyboardEnabled = res.getBoolean(
|
||||
R.bool.config_swipe_down_dismiss_keyboard_enabled);
|
||||
mConfigDelayBeforeFadeoutLanguageOnSpacebar = res.getInteger(
|
||||
R.integer.config_delay_before_fadeout_language_on_spacebar);
|
||||
mConfigDurationOfFadeoutLanguageOnSpacebar = res.getInteger(
|
||||
R.integer.config_duration_of_fadeout_language_on_spacebar);
|
||||
|
||||
Utils.GCUtils.getInstance().reset();
|
||||
boolean tryGC = true;
|
||||
|
@ -401,23 +438,12 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
|
|||
|
||||
@Override
|
||||
public void onConfigurationChanged(Configuration conf) {
|
||||
mSubtypeSwitcher.onConfigurationChanged(conf);
|
||||
if (mSubtypeSwitcher.isKeyboardMode())
|
||||
onKeyboardLanguageChanged();
|
||||
updateAutoTextEnabled();
|
||||
|
||||
// If orientation changed while predicting, commit the change
|
||||
if (conf.orientation != mOrientation) {
|
||||
InputConnection ic = getCurrentInputConnection();
|
||||
commitTyped(ic);
|
||||
if (ic != null) ic.finishComposingText(); // For voice input
|
||||
mOrientation = conf.orientation;
|
||||
final int mode = mKeyboardSwitcher.getKeyboardMode();
|
||||
final EditorInfo attribute = getCurrentInputEditorInfo();
|
||||
final int imeOptions = (attribute != null) ? attribute.imeOptions : 0;
|
||||
mKeyboardSwitcher.loadKeyboard(mode, imeOptions,
|
||||
mVoiceConnector.isVoiceButtonEnabled(),
|
||||
mVoiceConnector.isVoiceButtonOnPrimary());
|
||||
}
|
||||
|
||||
mConfigurationChanging = true;
|
||||
|
@ -1817,7 +1843,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
|
|||
|
||||
// "reset" and "next" are used only for USE_SPACEBAR_LANGUAGE_SWITCHER.
|
||||
private void toggleLanguage(boolean reset, boolean next) {
|
||||
if (SubtypeSwitcher.USE_SPACEBAR_LANGUAGE_SWITCHER) {
|
||||
if (mSubtypeSwitcher.useSpacebarLanguageSwitcher()) {
|
||||
mSubtypeSwitcher.toggleLanguage(reset, next);
|
||||
}
|
||||
// Reload keyboard because the current language has been changed.
|
||||
|
|
|
@ -41,10 +41,6 @@ import java.util.Locale;
|
|||
import java.util.Map;
|
||||
|
||||
public class SubtypeSwitcher {
|
||||
// TODO: This should be configurable by resource
|
||||
// This flag indicates if we support language switching by swipe on space bar.
|
||||
// We may or may not draw the current language on space bar regardless of this flag.
|
||||
public static final boolean USE_SPACEBAR_LANGUAGE_SWITCHER = false;
|
||||
private static final boolean DBG = false;
|
||||
private static final String TAG = "SubtypeSwitcher";
|
||||
|
||||
|
@ -63,6 +59,8 @@ public class SubtypeSwitcher {
|
|||
new ArrayList<InputMethodSubtype>();
|
||||
private final ArrayList<String> mEnabledLanguagesOfCurrentInputMethod = new ArrayList<String>();
|
||||
|
||||
private boolean mConfigUseSpacebarLanguageSwitcher;
|
||||
|
||||
/*-----------------------------------------------------------*/
|
||||
// Variants which should be changed only by reload functions.
|
||||
private boolean mNeedsToDisplayLanguage;
|
||||
|
@ -84,10 +82,6 @@ public class SubtypeSwitcher {
|
|||
public static void init(LatinIME service, SharedPreferences prefs) {
|
||||
sInstance.mPrefs = prefs;
|
||||
sInstance.resetParams(service);
|
||||
if (USE_SPACEBAR_LANGUAGE_SWITCHER) {
|
||||
sInstance.initLanguageSwitcher(service);
|
||||
}
|
||||
|
||||
sInstance.updateAllParameters();
|
||||
}
|
||||
|
||||
|
@ -109,6 +103,10 @@ public class SubtypeSwitcher {
|
|||
mAllEnabledSubtypesOfCurrentInputMethod = null;
|
||||
// TODO: Voice input should be created here
|
||||
mVoiceInput = null;
|
||||
mConfigUseSpacebarLanguageSwitcher = mResources.getBoolean(
|
||||
R.bool.config_use_spacebar_language_switcher);
|
||||
if (mConfigUseSpacebarLanguageSwitcher)
|
||||
initLanguageSwitcher(service);
|
||||
}
|
||||
|
||||
// Update all parameters stored in SubtypeSwitcher.
|
||||
|
@ -122,8 +120,8 @@ public class SubtypeSwitcher {
|
|||
// Update parameters which are changed outside LatinIME. This parameters affect UI so they
|
||||
// should be updated every time onStartInputview.
|
||||
public void updateParametersOnStartInputView() {
|
||||
if (USE_SPACEBAR_LANGUAGE_SWITCHER) {
|
||||
updateForSpaceBarLanguageSwitch();
|
||||
if (mConfigUseSpacebarLanguageSwitcher) {
|
||||
updateForSpacebarLanguageSwitch();
|
||||
} else {
|
||||
updateEnabledSubtypes();
|
||||
}
|
||||
|
@ -307,19 +305,23 @@ public class SubtypeSwitcher {
|
|||
//////////////////////////////////
|
||||
|
||||
public int getEnabledKeyboardLocaleCount() {
|
||||
if (USE_SPACEBAR_LANGUAGE_SWITCHER) {
|
||||
if (mConfigUseSpacebarLanguageSwitcher) {
|
||||
return mLanguageSwitcher.getLocaleCount();
|
||||
} else {
|
||||
return mEnabledKeyboardSubtypesOfCurrentInputMethod.size();
|
||||
}
|
||||
}
|
||||
|
||||
public boolean useSpacebarLanguageSwitcher() {
|
||||
return mConfigUseSpacebarLanguageSwitcher;
|
||||
}
|
||||
|
||||
public boolean needsToDisplayLanguage() {
|
||||
return mNeedsToDisplayLanguage;
|
||||
}
|
||||
|
||||
public Locale getInputLocale() {
|
||||
if (USE_SPACEBAR_LANGUAGE_SWITCHER) {
|
||||
if (mConfigUseSpacebarLanguageSwitcher) {
|
||||
return mLanguageSwitcher.getInputLocale();
|
||||
} else {
|
||||
return mInputLocale;
|
||||
|
@ -327,7 +329,7 @@ public class SubtypeSwitcher {
|
|||
}
|
||||
|
||||
public String getInputLocaleStr() {
|
||||
if (USE_SPACEBAR_LANGUAGE_SWITCHER) {
|
||||
if (mConfigUseSpacebarLanguageSwitcher) {
|
||||
String inputLanguage = null;
|
||||
inputLanguage = mLanguageSwitcher.getInputLanguage();
|
||||
// Should return system locale if there is no Language available.
|
||||
|
@ -341,7 +343,7 @@ public class SubtypeSwitcher {
|
|||
}
|
||||
|
||||
public String[] getEnabledLanguages() {
|
||||
if (USE_SPACEBAR_LANGUAGE_SWITCHER) {
|
||||
if (mConfigUseSpacebarLanguageSwitcher) {
|
||||
return mLanguageSwitcher.getEnabledLanguages();
|
||||
} else {
|
||||
return mEnabledLanguagesOfCurrentInputMethod.toArray(
|
||||
|
@ -350,7 +352,7 @@ public class SubtypeSwitcher {
|
|||
}
|
||||
|
||||
public Locale getSystemLocale() {
|
||||
if (USE_SPACEBAR_LANGUAGE_SWITCHER) {
|
||||
if (mConfigUseSpacebarLanguageSwitcher) {
|
||||
return mLanguageSwitcher.getSystemLocale();
|
||||
} else {
|
||||
return mSystemLocale;
|
||||
|
@ -358,7 +360,7 @@ public class SubtypeSwitcher {
|
|||
}
|
||||
|
||||
public boolean isSystemLanguageSameAsInputLanguage() {
|
||||
if (USE_SPACEBAR_LANGUAGE_SWITCHER) {
|
||||
if (mConfigUseSpacebarLanguageSwitcher) {
|
||||
return getSystemLocale().getLanguage().equalsIgnoreCase(
|
||||
getInputLocaleStr().substring(0, 2));
|
||||
} else {
|
||||
|
@ -366,25 +368,8 @@ public class SubtypeSwitcher {
|
|||
}
|
||||
}
|
||||
|
||||
public void onConfigurationChanged(Configuration conf) {
|
||||
final Locale systemLocale = conf.locale;
|
||||
// If system configuration was changed, update all parameters.
|
||||
if (!TextUtils.equals(systemLocale.toString(), mSystemLocale.toString())) {
|
||||
if (USE_SPACEBAR_LANGUAGE_SWITCHER) {
|
||||
// If the system locale changes and is different from the saved
|
||||
// locale (mSystemLocale), then reload the input locale list from the
|
||||
// latin ime settings (shared prefs) and reset the input locale
|
||||
// to the first one.
|
||||
mLanguageSwitcher.loadLocales(mPrefs);
|
||||
mLanguageSwitcher.setSystemLocale(systemLocale);
|
||||
} else {
|
||||
updateAllParameters();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
|
||||
if (USE_SPACEBAR_LANGUAGE_SWITCHER) {
|
||||
if (mConfigUseSpacebarLanguageSwitcher) {
|
||||
if (Settings.PREF_SELECTED_LANGUAGES.equals(key)) {
|
||||
mLanguageSwitcher.loadLocales(sharedPreferences);
|
||||
}
|
||||
|
@ -438,7 +423,7 @@ public class SubtypeSwitcher {
|
|||
}
|
||||
|
||||
//////////////////////////////////////
|
||||
// SpaceBar Language Switch support //
|
||||
// Spacebar Language Switch support //
|
||||
//////////////////////////////////////
|
||||
|
||||
private LanguageSwitcher mLanguageSwitcher;
|
||||
|
@ -466,7 +451,7 @@ public class SubtypeSwitcher {
|
|||
return Character.toUpperCase(s.charAt(0)) + s.substring(1);
|
||||
}
|
||||
|
||||
private void updateForSpaceBarLanguageSwitch() {
|
||||
private void updateForSpacebarLanguageSwitch() {
|
||||
// We need to update mNeedsToDisplayLanguage in onStartInputView because
|
||||
// getEnabledKeyboardLocaleCount could have been changed.
|
||||
mNeedsToDisplayLanguage = !(getEnabledKeyboardLocaleCount() <= 1
|
||||
|
@ -479,7 +464,7 @@ public class SubtypeSwitcher {
|
|||
}
|
||||
|
||||
public String getNextInputLanguageName() {
|
||||
if (USE_SPACEBAR_LANGUAGE_SWITCHER) {
|
||||
if (mConfigUseSpacebarLanguageSwitcher) {
|
||||
return getDisplayLanguage(mLanguageSwitcher.getNextInputLocale());
|
||||
} else {
|
||||
return "";
|
||||
|
@ -487,7 +472,7 @@ public class SubtypeSwitcher {
|
|||
}
|
||||
|
||||
public String getPreviousInputLanguageName() {
|
||||
if (USE_SPACEBAR_LANGUAGE_SWITCHER) {
|
||||
if (mConfigUseSpacebarLanguageSwitcher) {
|
||||
return getDisplayLanguage(mLanguageSwitcher.getPrevInputLocale());
|
||||
} else {
|
||||
return "";
|
||||
|
@ -524,13 +509,13 @@ public class SubtypeSwitcher {
|
|||
}
|
||||
|
||||
public void loadSettings() {
|
||||
if (USE_SPACEBAR_LANGUAGE_SWITCHER) {
|
||||
if (mConfigUseSpacebarLanguageSwitcher) {
|
||||
mLanguageSwitcher.loadLocales(mPrefs);
|
||||
}
|
||||
}
|
||||
|
||||
public void toggleLanguage(boolean reset, boolean next) {
|
||||
if (USE_SPACEBAR_LANGUAGE_SWITCHER) {
|
||||
if (mConfigUseSpacebarLanguageSwitcher) {
|
||||
if (reset) {
|
||||
mLanguageSwitcher.reset();
|
||||
} else {
|
||||
|
|
Loading…
Reference in New Issue