Use integer alpha value instead of factor for animation
Change-Id: I3099a7625e0176a1d2be42e58d6eb5fa95797bcbmain
parent
95fcb0cce9
commit
aee5f03d6e
|
@ -139,7 +139,7 @@
|
||||||
<enum name="alwaysDisplay" value="-1" />
|
<enum name="alwaysDisplay" value="-1" />
|
||||||
</attr>
|
</attr>
|
||||||
<attr name="delayBeforeFadeoutLangageOnSpacebar" format="integer" />
|
<attr name="delayBeforeFadeoutLangageOnSpacebar" format="integer" />
|
||||||
<attr name="finalFadeoutFactorOfLanguageOnSpacebar" format="float" />
|
<attr name="finalAlphaOfLanguageOnSpacebar" format="integer" />
|
||||||
<!-- Key detection hysteresis distance. -->
|
<!-- Key detection hysteresis distance. -->
|
||||||
<attr name="keyHysteresisDistance" format="dimension" />
|
<attr name="keyHysteresisDistance" format="dimension" />
|
||||||
<!-- Touch noise threshold time in millisecond -->
|
<!-- Touch noise threshold time in millisecond -->
|
||||||
|
|
|
@ -80,7 +80,7 @@
|
||||||
<item name="showMoreKeysKeyboardAtTouchedPoint">@bool/config_show_more_keys_keyboard_at_touched_point</item>
|
<item name="showMoreKeysKeyboardAtTouchedPoint">@bool/config_show_more_keys_keyboard_at_touched_point</item>
|
||||||
<item name="durationOfFadeoutLanguageOnSpacebar">200</item>
|
<item name="durationOfFadeoutLanguageOnSpacebar">200</item>
|
||||||
<item name="delayBeforeFadeoutLangageOnSpacebar">1200</item>
|
<item name="delayBeforeFadeoutLangageOnSpacebar">1200</item>
|
||||||
<item name="finalFadeoutFactorOfLanguageOnSpacebar">0.5</item>
|
<item name="finalAlphaOfLanguageOnSpacebar">128</item>
|
||||||
</style>
|
</style>
|
||||||
<style
|
<style
|
||||||
name="LatinKeyboardView"
|
name="LatinKeyboardView"
|
||||||
|
|
|
@ -21,7 +21,6 @@ import android.content.Context;
|
||||||
import android.content.pm.PackageManager;
|
import android.content.pm.PackageManager;
|
||||||
import android.content.res.TypedArray;
|
import android.content.res.TypedArray;
|
||||||
import android.graphics.Canvas;
|
import android.graphics.Canvas;
|
||||||
import android.graphics.Color;
|
|
||||||
import android.graphics.Paint;
|
import android.graphics.Paint;
|
||||||
import android.graphics.Paint.Align;
|
import android.graphics.Paint.Align;
|
||||||
import android.graphics.Typeface;
|
import android.graphics.Typeface;
|
||||||
|
@ -77,13 +76,14 @@ public class LatinKeyboardView extends KeyboardView implements PointerTracker.Ke
|
||||||
private Drawable mSpaceIcon;
|
private Drawable mSpaceIcon;
|
||||||
// Stuff to draw language name on spacebar.
|
// Stuff to draw language name on spacebar.
|
||||||
private ValueAnimator mLanguageOnSpacebarAnimator;
|
private ValueAnimator mLanguageOnSpacebarAnimator;
|
||||||
private float mFinalFadeoutFactorOfLanguageOnSpacebar;
|
private int mFinalAlphaOfLanguageOnSpacebar;
|
||||||
private int mDurationOfFadeoutLanguageOnSpacebar;
|
private int mDurationOfFadeoutLanguageOnSpacebar;
|
||||||
|
private static final int ALPHA_OPAQUE = 255;
|
||||||
private static final int LANGUAGE_ON_SPACEBAR_NEVER_DISPLAY = 0;
|
private static final int LANGUAGE_ON_SPACEBAR_NEVER_DISPLAY = 0;
|
||||||
private static final int LANGUAGE_ON_SPACEBAR_ALWAYS_DISPLAY = -1;
|
private static final int LANGUAGE_ON_SPACEBAR_ALWAYS_DISPLAY = -1;
|
||||||
private boolean mNeedsToDisplayLanguage;
|
private boolean mNeedsToDisplayLanguage;
|
||||||
private Locale mSpacebarLocale;
|
private Locale mSpacebarLocale;
|
||||||
private float mSpacebarTextFadeFactor = 0.0f;
|
private int mSpacebarTextAlpha;
|
||||||
private final float mSpacebarTextRatio;
|
private final float mSpacebarTextRatio;
|
||||||
private float mSpacebarTextSize;
|
private float mSpacebarTextSize;
|
||||||
private final int mSpacebarTextColor;
|
private final int mSpacebarTextColor;
|
||||||
|
@ -344,8 +344,8 @@ public class LatinKeyboardView extends KeyboardView implements PointerTracker.Ke
|
||||||
LANGUAGE_ON_SPACEBAR_NEVER_DISPLAY);
|
LANGUAGE_ON_SPACEBAR_NEVER_DISPLAY);
|
||||||
final int delayBeforeFadeoutLanguageOnSpacebar = a.getInt(
|
final int delayBeforeFadeoutLanguageOnSpacebar = a.getInt(
|
||||||
R.styleable.LatinKeyboardView_delayBeforeFadeoutLangageOnSpacebar, 0);
|
R.styleable.LatinKeyboardView_delayBeforeFadeoutLangageOnSpacebar, 0);
|
||||||
mFinalFadeoutFactorOfLanguageOnSpacebar = a.getFloat(
|
mFinalAlphaOfLanguageOnSpacebar = a.getInt(
|
||||||
R.styleable.LatinKeyboardView_finalFadeoutFactorOfLanguageOnSpacebar, 0.0f);
|
R.styleable.LatinKeyboardView_finalAlphaOfLanguageOnSpacebar, 0);
|
||||||
|
|
||||||
final KeyTimerParams keyTimerParams = new KeyTimerParams(a);
|
final KeyTimerParams keyTimerParams = new KeyTimerParams(a);
|
||||||
mPointerTrackerParams = new PointerTrackerParams(a);
|
mPointerTrackerParams = new PointerTrackerParams(a);
|
||||||
|
@ -361,8 +361,8 @@ public class LatinKeyboardView extends KeyboardView implements PointerTracker.Ke
|
||||||
|
|
||||||
PointerTracker.setParameters(mPointerTrackerParams);
|
PointerTracker.setParameters(mPointerTrackerParams);
|
||||||
|
|
||||||
mLanguageOnSpacebarAnimator = ValueAnimator.ofFloat(
|
mLanguageOnSpacebarAnimator = ValueAnimator.ofInt(
|
||||||
1.0f, mFinalFadeoutFactorOfLanguageOnSpacebar);
|
ALPHA_OPAQUE, mFinalAlphaOfLanguageOnSpacebar);
|
||||||
mLanguageOnSpacebarAnimator.setStartDelay(delayBeforeFadeoutLanguageOnSpacebar);
|
mLanguageOnSpacebarAnimator.setStartDelay(delayBeforeFadeoutLanguageOnSpacebar);
|
||||||
if (mDurationOfFadeoutLanguageOnSpacebar > 0) {
|
if (mDurationOfFadeoutLanguageOnSpacebar > 0) {
|
||||||
mLanguageOnSpacebarAnimator.setDuration(mDurationOfFadeoutLanguageOnSpacebar);
|
mLanguageOnSpacebarAnimator.setDuration(mDurationOfFadeoutLanguageOnSpacebar);
|
||||||
|
@ -370,7 +370,7 @@ public class LatinKeyboardView extends KeyboardView implements PointerTracker.Ke
|
||||||
mLanguageOnSpacebarAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
|
mLanguageOnSpacebarAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onAnimationUpdate(ValueAnimator animation) {
|
public void onAnimationUpdate(ValueAnimator animation) {
|
||||||
mSpacebarTextFadeFactor = (Float)animation.getAnimatedValue();
|
mSpacebarTextAlpha = (Integer)animation.getAnimatedValue();
|
||||||
invalidateKey(mSpaceKey);
|
invalidateKey(mSpaceKey);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -794,15 +794,15 @@ public class LatinKeyboardView extends KeyboardView implements PointerTracker.Ke
|
||||||
mLanguageOnSpacebarAnimator.cancel();
|
mLanguageOnSpacebarAnimator.cancel();
|
||||||
mNeedsToDisplayLanguage = needsToDisplayLanguage;
|
mNeedsToDisplayLanguage = needsToDisplayLanguage;
|
||||||
if (mDurationOfFadeoutLanguageOnSpacebar == LANGUAGE_ON_SPACEBAR_NEVER_DISPLAY) {
|
if (mDurationOfFadeoutLanguageOnSpacebar == LANGUAGE_ON_SPACEBAR_NEVER_DISPLAY) {
|
||||||
mSpacebarTextFadeFactor = 0.0f;
|
mNeedsToDisplayLanguage = false;
|
||||||
} else if (mDurationOfFadeoutLanguageOnSpacebar == LANGUAGE_ON_SPACEBAR_ALWAYS_DISPLAY) {
|
} else if (mDurationOfFadeoutLanguageOnSpacebar == LANGUAGE_ON_SPACEBAR_ALWAYS_DISPLAY) {
|
||||||
mSpacebarTextFadeFactor = 1.0f;
|
mSpacebarTextAlpha = ALPHA_OPAQUE;
|
||||||
} else {
|
} else {
|
||||||
if (subtypeChanged && needsToDisplayLanguage) {
|
if (subtypeChanged && needsToDisplayLanguage) {
|
||||||
mSpacebarTextFadeFactor = 1.0f;
|
mSpacebarTextAlpha = ALPHA_OPAQUE;
|
||||||
mLanguageOnSpacebarAnimator.start();
|
mLanguageOnSpacebarAnimator.start();
|
||||||
} else {
|
} else {
|
||||||
mSpacebarTextFadeFactor = mFinalFadeoutFactorOfLanguageOnSpacebar;
|
mSpacebarTextAlpha = mFinalAlphaOfLanguageOnSpacebar;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
invalidateKey(mSpaceKey);
|
invalidateKey(mSpaceKey);
|
||||||
|
@ -835,12 +835,6 @@ public class LatinKeyboardView extends KeyboardView implements PointerTracker.Ke
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Compute width of text with specified text size using paint.
|
// Compute width of text with specified text size using paint.
|
||||||
private int getTextWidth(Paint paint, String text, float textSize) {
|
private int getTextWidth(Paint paint, String text, float textSize) {
|
||||||
paint.setTextSize(textSize);
|
paint.setTextSize(textSize);
|
||||||
|
@ -888,7 +882,7 @@ public class LatinKeyboardView extends KeyboardView implements PointerTracker.Ke
|
||||||
final int width = key.mWidth;
|
final int width = key.mWidth;
|
||||||
final int height = key.mHeight;
|
final int height = key.mHeight;
|
||||||
|
|
||||||
// If application locales are explicitly selected.
|
// If input subtypes are explicitly selected.
|
||||||
if (mNeedsToDisplayLanguage) {
|
if (mNeedsToDisplayLanguage) {
|
||||||
final String language = layoutLanguageOnSpacebar(paint, mSpacebarLocale, width,
|
final String language = layoutLanguageOnSpacebar(paint, mSpacebarLocale, width,
|
||||||
mSpacebarTextSize);
|
mSpacebarTextSize);
|
||||||
|
@ -898,9 +892,11 @@ public class LatinKeyboardView extends KeyboardView implements PointerTracker.Ke
|
||||||
final float descent = paint.descent();
|
final float descent = paint.descent();
|
||||||
final float textHeight = -paint.ascent() + descent;
|
final float textHeight = -paint.ascent() + descent;
|
||||||
final float baseline = height / 2 + textHeight / 2;
|
final float baseline = height / 2 + textHeight / 2;
|
||||||
paint.setColor(getSpacebarTextColor(mSpacebarTextShadowColor, mSpacebarTextFadeFactor));
|
paint.setColor(mSpacebarTextShadowColor);
|
||||||
|
paint.setAlpha(mSpacebarTextAlpha);
|
||||||
canvas.drawText(language, width / 2, baseline - descent - 1, paint);
|
canvas.drawText(language, width / 2, baseline - descent - 1, paint);
|
||||||
paint.setColor(getSpacebarTextColor(mSpacebarTextColor, mSpacebarTextFadeFactor));
|
paint.setColor(mSpacebarTextColor);
|
||||||
|
paint.setAlpha(mSpacebarTextAlpha);
|
||||||
canvas.drawText(language, width / 2, baseline - descent, paint);
|
canvas.drawText(language, width / 2, baseline - descent, paint);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue