Move language on spacebar parameters to LatinKeyboardView attributes

Change-Id: I06e5d7d158a9b14b00df34e68b12cd012faf17d1
This commit is contained in:
Tadashi G. Takaoka 2012-03-13 14:15:39 +09:00
parent 6fbcd0d219
commit dabf96896e
5 changed files with 38 additions and 30 deletions

View file

@ -132,6 +132,14 @@
<attr name="spacebarTextRatio" format="fraction" />
<attr name="spacebarTextColor" format="color" />
<attr name="spacebarTextShadowColor" format="color" />
<!-- Animation parameters for spacebar language label. -->
<attr name="durationOfFadeoutLanguageOnSpacebar" format="integer|enum">
<!-- This should be aligned with LatinKeyboardView.LANGUAGE_ON_SPACEBAR_* -->
<enum name="neverDisplay" value="0" />
<enum name="alwaysDisplay" value="-1" />
</attr>
<attr name="delayBeforeFadeoutLangageOnSpacebar" format="integer" />
<attr name="finalFadeoutFactorOfLanguageOnSpacebar" format="float" />
<!-- Key detection hysteresis distance. -->
<attr name="keyHysteresisDistance" format="dimension" />
<!-- Touch noise threshold time in millisecond -->

View file

@ -35,13 +35,9 @@
<bool name="config_default_bigram_prediction">false</bool>
<bool name="config_default_sound_enabled">false</bool>
<bool name="config_default_vibration_enabled">true</bool>
<!-- The language is never displayed if == 0, always displayed if < 0 -->
<integer name="config_delay_before_fadeout_language_on_spacebar">1200</integer>
<integer name="config_delay_update_suggestions">100</integer>
<integer name="config_delay_update_old_suggestions">300</integer>
<integer name="config_delay_update_shift_state">100</integer>
<integer name="config_duration_of_fadeout_language_on_spacebar">200</integer>
<integer name="config_final_fadeout_percentage_of_language_on_spacebar">50</integer>
<integer name="config_more_keys_keyboard_fadein_anim_time">0</integer>
<integer name="config_more_keys_keyboard_fadeout_anim_time">100</integer>
<integer name="config_keyboard_grid_width">32</integer>

View file

@ -78,6 +78,9 @@
<item name="longPressSpaceKeyTimeout">@integer/config_long_press_space_key_timeout</item>
<item name="ignoreSpecialKeyTimeout">@integer/config_ignore_special_key_timeout</item>
<item name="showMoreKeysKeyboardAtTouchedPoint">@bool/config_show_more_keys_keyboard_at_touched_point</item>
<item name="durationOfFadeoutLanguageOnSpacebar">200</item>
<item name="delayBeforeFadeoutLangageOnSpacebar">1200</item>
<item name="finalFadeoutFactorOfLanguageOnSpacebar">0.5</item>
</style>
<style
name="LatinKeyboardView"

View file

@ -180,11 +180,11 @@ public class KeyboardSwitcher implements KeyboardState.SwitchActions {
SettingsValues.getKeyPreviewPopupDismissDelay(mPrefs, mResources));
mKeyboardView.updateAutoCorrectionState(mIsAutoCorrectionActive);
mKeyboardView.updateShortcutKey(mSubtypeSwitcher.isShortcutImeReady());
final boolean subtypeChanged = (oldKeyboard == null)
|| !keyboard.mId.mLocale.equals(oldKeyboard.mId.mLocale);
final boolean needsToDisplayLanguage = mSubtypeSwitcher.needsToDisplayLanguage(
keyboard.mId.mLocale);
final boolean localeChanged = (oldKeyboard == null)
|| !keyboard.mId.mLocale.equals(oldKeyboard.mId.mLocale);
mKeyboardView.startDisplayLanguageOnSpacebar(localeChanged, needsToDisplayLanguage);
mKeyboardView.startDisplayLanguageOnSpacebar(subtypeChanged, needsToDisplayLanguage);
}
public Keyboard getKeyboard() {

View file

@ -19,7 +19,6 @@ package com.android.inputmethod.keyboard;
import android.animation.ValueAnimator;
import android.content.Context;
import android.content.pm.PackageManager;
import android.content.res.Resources;
import android.content.res.TypedArray;
import android.graphics.Canvas;
import android.graphics.Color;
@ -79,7 +78,9 @@ public class LatinKeyboardView extends KeyboardView implements PointerTracker.Ke
// Stuff to draw language name on spacebar.
private ValueAnimator mLanguageOnSpacebarAnimator;
private float mFinalFadeoutFactorOfLanguageOnSpacebar;
private int mDelayBeforeFadeoutLanguageOnSpacebar;
private int mDurationOfFadeoutLanguageOnSpacebar;
private static final int LANGUAGE_ON_SPACEBAR_NEVER_DISPLAY = 0;
private static final int LANGUAGE_ON_SPACEBAR_ALWAYS_DISPLAY = -1;
private boolean mNeedsToDisplayLanguage;
private Locale mSpacebarLocale;
private float mSpacebarTextFadeFactor = 0.0f;
@ -338,6 +339,13 @@ public class LatinKeyboardView extends KeyboardView implements PointerTracker.Ke
mSpacebarTextColor = a.getColor(R.styleable.LatinKeyboardView_spacebarTextColor, 0);
mSpacebarTextShadowColor = a.getColor(
R.styleable.LatinKeyboardView_spacebarTextShadowColor, 0);
mDurationOfFadeoutLanguageOnSpacebar = a.getInt(
R.styleable.LatinKeyboardView_durationOfFadeoutLanguageOnSpacebar,
LANGUAGE_ON_SPACEBAR_NEVER_DISPLAY);
final int delayBeforeFadeoutLanguageOnSpacebar = a.getInt(
R.styleable.LatinKeyboardView_delayBeforeFadeoutLangageOnSpacebar, 0);
mFinalFadeoutFactorOfLanguageOnSpacebar = a.getFloat(
R.styleable.LatinKeyboardView_finalFadeoutFactorOfLanguageOnSpacebar, 0.0f);
final KeyTimerParams keyTimerParams = new KeyTimerParams(a);
mPointerTrackerParams = new PointerTrackerParams(a);
@ -353,18 +361,12 @@ public class LatinKeyboardView extends KeyboardView implements PointerTracker.Ke
PointerTracker.setParameters(mPointerTrackerParams);
// TODO: These resources should be attributes of LatinKeyboardView.
final Resources res = getResources();
mFinalFadeoutFactorOfLanguageOnSpacebar = res.getInteger(
R.integer.config_final_fadeout_percentage_of_language_on_spacebar) / 100.0f;
mDelayBeforeFadeoutLanguageOnSpacebar = res.getInteger(
R.integer.config_delay_before_fadeout_language_on_spacebar);
final int durationOfFadeoutLanguageOnSpacebar = res.getInteger(
R.integer.config_duration_of_fadeout_language_on_spacebar);
mLanguageOnSpacebarAnimator = ValueAnimator.ofFloat(
1.0f, mFinalFadeoutFactorOfLanguageOnSpacebar);
mLanguageOnSpacebarAnimator.setStartDelay(mDelayBeforeFadeoutLanguageOnSpacebar);
mLanguageOnSpacebarAnimator.setDuration(durationOfFadeoutLanguageOnSpacebar);
mLanguageOnSpacebarAnimator.setStartDelay(delayBeforeFadeoutLanguageOnSpacebar);
if (mDurationOfFadeoutLanguageOnSpacebar > 0) {
mLanguageOnSpacebarAnimator.setDuration(mDurationOfFadeoutLanguageOnSpacebar);
}
mLanguageOnSpacebarAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
@Override
public void onAnimationUpdate(ValueAnimator animation) {
@ -747,7 +749,7 @@ public class LatinKeyboardView extends KeyboardView implements PointerTracker.Ke
super.draw(c);
tryGC = false;
} catch (OutOfMemoryError e) {
tryGC = Utils.GCUtils.getInstance().tryGCOrWait("LatinKeyboardView", e);
tryGC = Utils.GCUtils.getInstance().tryGCOrWait(TAG, e);
}
}
}
@ -787,22 +789,21 @@ public class LatinKeyboardView extends KeyboardView implements PointerTracker.Ke
invalidateKey(shortcutKey);
}
public void startDisplayLanguageOnSpacebar(boolean localeChanged,
public void startDisplayLanguageOnSpacebar(boolean subtypeChanged,
boolean needsToDisplayLanguage) {
mLanguageOnSpacebarAnimator.cancel();
mNeedsToDisplayLanguage = needsToDisplayLanguage;
if (mDelayBeforeFadeoutLanguageOnSpacebar == 0) {
// The language is never displayed when the delay is zero.
if (mDurationOfFadeoutLanguageOnSpacebar == LANGUAGE_ON_SPACEBAR_NEVER_DISPLAY) {
mSpacebarTextFadeFactor = 0.0f;
} else if (localeChanged || mDelayBeforeFadeoutLanguageOnSpacebar < 0) {
// The language is always displayed when the delay is negative.
} else if (mDurationOfFadeoutLanguageOnSpacebar == LANGUAGE_ON_SPACEBAR_ALWAYS_DISPLAY) {
mSpacebarTextFadeFactor = 1.0f;
} else {
mSpacebarTextFadeFactor = mFinalFadeoutFactorOfLanguageOnSpacebar;
}
if (localeChanged && mDelayBeforeFadeoutLanguageOnSpacebar > 0 && mNeedsToDisplayLanguage) {
// The fadeout animation will start when the delay is positive.
mLanguageOnSpacebarAnimator.start();
if (subtypeChanged && needsToDisplayLanguage) {
mSpacebarTextFadeFactor = 1.0f;
mLanguageOnSpacebarAnimator.start();
} else {
mSpacebarTextFadeFactor = mFinalFadeoutFactorOfLanguageOnSpacebar;
}
}
invalidateKey(mSpaceKey);
}