Use ObjectAnimator
Bug: 6187069 Change-Id: I7df18b470b7e746da601fab3311fb4b086f40d41main
parent
4897df803d
commit
31c94cea82
|
@ -35,6 +35,14 @@
|
||||||
*;
|
*;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
-keep class com.android.inputmethod.keyboard.LatinKeyboardView {
|
||||||
|
# Keep getter/setter methods for ObjectAnimator
|
||||||
|
int getLanguageOnSpacebarAnimAlpha();
|
||||||
|
void setLanguageOnSpacebarAnimAlpha(int);
|
||||||
|
int getAltCodeKeyWhileTypingAnimAlhpa();
|
||||||
|
void setAltCodeKeyWhileTypingAnimAlpha(int);
|
||||||
|
}
|
||||||
|
|
||||||
-keep class com.android.inputmethod.keyboard.MoreKeysKeyboard$Builder$MoreKeysKeyboardParams {
|
-keep class com.android.inputmethod.keyboard.MoreKeysKeyboard$Builder$MoreKeysKeyboardParams {
|
||||||
<init>(...);
|
<init>(...);
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,8 +18,9 @@
|
||||||
*/
|
*/
|
||||||
-->
|
-->
|
||||||
|
|
||||||
<animator
|
<objectAnimator
|
||||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:propertyName="altCodeKeyWhileTypingAnimAlpha"
|
||||||
android:valueType="intType"
|
android:valueType="intType"
|
||||||
android:duration="100"
|
android:duration="100"
|
||||||
android:valueFrom="128"
|
android:valueFrom="128"
|
||||||
|
|
|
@ -18,8 +18,9 @@
|
||||||
*/
|
*/
|
||||||
-->
|
-->
|
||||||
|
|
||||||
<animator
|
<objectAnimator
|
||||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:propertyName="altCodeKeyWhileTypingAnimAlpha"
|
||||||
android:valueType="intType"
|
android:valueType="intType"
|
||||||
android:duration="70"
|
android:duration="70"
|
||||||
android:valueFrom="255"
|
android:valueFrom="255"
|
||||||
|
|
|
@ -18,10 +18,11 @@
|
||||||
*/
|
*/
|
||||||
-->
|
-->
|
||||||
|
|
||||||
<animator
|
<objectAnimator
|
||||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:propertyName="languageOnSpacebarAnimAlpha"
|
||||||
android:valueType="intType"
|
android:valueType="intType"
|
||||||
android:startOffset="1200"
|
android:startOffset="1200"
|
||||||
android:duration="200"
|
android:duration="200"
|
||||||
android:valueFrom="255"
|
android:valueFrom="255"
|
||||||
android:valueTo="128" />
|
android:valueTo="@integer/config_language_on_spacebar_final_alpha" />
|
||||||
|
|
|
@ -133,6 +133,7 @@
|
||||||
<attr name="spacebarTextColor" format="color" />
|
<attr name="spacebarTextColor" format="color" />
|
||||||
<attr name="spacebarTextShadowColor" format="color" />
|
<attr name="spacebarTextShadowColor" format="color" />
|
||||||
<!-- Fadeout animator for spacebar language label. -->
|
<!-- Fadeout animator for spacebar language label. -->
|
||||||
|
<attr name="languageOnSpacebarFinalAlpha" format="integer" />
|
||||||
<attr name="languageOnSpacebarFadeoutAnimator" format="reference" />
|
<attr name="languageOnSpacebarFadeoutAnimator" format="reference" />
|
||||||
<!-- Fadeout and fadein animator for altCodeWhileTyping keys. -->
|
<!-- Fadeout and fadein animator for altCodeWhileTyping keys. -->
|
||||||
<attr name="altCodeKeyWhileTypingFadeoutAnimator" format="reference" />
|
<attr name="altCodeKeyWhileTypingFadeoutAnimator" format="reference" />
|
||||||
|
|
|
@ -38,6 +38,7 @@
|
||||||
<integer name="config_delay_update_suggestions">100</integer>
|
<integer name="config_delay_update_suggestions">100</integer>
|
||||||
<integer name="config_delay_update_old_suggestions">300</integer>
|
<integer name="config_delay_update_old_suggestions">300</integer>
|
||||||
<integer name="config_delay_update_shift_state">100</integer>
|
<integer name="config_delay_update_shift_state">100</integer>
|
||||||
|
<integer name="config_language_on_spacebar_final_alpha">128</integer>
|
||||||
<integer name="config_more_keys_keyboard_fadein_anim_time">0</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_more_keys_keyboard_fadeout_anim_time">100</integer>
|
||||||
<integer name="config_keyboard_grid_width">32</integer>
|
<integer name="config_keyboard_grid_width">32</integer>
|
||||||
|
|
|
@ -78,6 +78,7 @@
|
||||||
<item name="longPressSpaceKeyTimeout">@integer/config_long_press_space_key_timeout</item>
|
<item name="longPressSpaceKeyTimeout">@integer/config_long_press_space_key_timeout</item>
|
||||||
<item name="ignoreAltCodeKeyTimeout">@integer/config_ignore_alt_code_key_timeout</item>
|
<item name="ignoreAltCodeKeyTimeout">@integer/config_ignore_alt_code_key_timeout</item>
|
||||||
<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="languageOnSpacebarFinalAlpha">@integer/config_language_on_spacebar_final_alpha</item>
|
||||||
<item name="languageOnSpacebarFadeoutAnimator">@anim/language_on_spacebar_fadeout</item>
|
<item name="languageOnSpacebarFadeoutAnimator">@anim/language_on_spacebar_fadeout</item>
|
||||||
<item name="altCodeKeyWhileTypingFadeoutAnimator">@anim/alt_code_key_while_typing_fadeout</item>
|
<item name="altCodeKeyWhileTypingFadeoutAnimator">@anim/alt_code_key_while_typing_fadeout</item>
|
||||||
<item name="altCodeKeyWhileTypingFadeinAnimator">@anim/alt_code_key_while_typing_fadein</item>
|
<item name="altCodeKeyWhileTypingFadeinAnimator">@anim/alt_code_key_while_typing_fadein</item>
|
||||||
|
|
|
@ -16,11 +16,8 @@
|
||||||
|
|
||||||
package com.android.inputmethod.keyboard;
|
package com.android.inputmethod.keyboard;
|
||||||
|
|
||||||
import android.animation.Animator;
|
|
||||||
import android.animation.AnimatorInflater;
|
import android.animation.AnimatorInflater;
|
||||||
import android.animation.AnimatorListenerAdapter;
|
import android.animation.ObjectAnimator;
|
||||||
import android.animation.ValueAnimator;
|
|
||||||
import android.animation.ValueAnimator.AnimatorUpdateListener;
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.pm.PackageManager;
|
import android.content.pm.PackageManager;
|
||||||
import android.content.res.TypedArray;
|
import android.content.res.TypedArray;
|
||||||
|
@ -79,12 +76,12 @@ public class LatinKeyboardView extends KeyboardView implements PointerTracker.Ke
|
||||||
private Key mSpaceKey;
|
private Key mSpaceKey;
|
||||||
private Drawable mSpaceIcon;
|
private Drawable mSpaceIcon;
|
||||||
// Stuff to draw language name on spacebar.
|
// Stuff to draw language name on spacebar.
|
||||||
private ValueAnimator mLanguageOnSpacebarFadeoutAnimator;
|
private final int mLanguageOnSpacebarFinalAlpha;
|
||||||
private int mFinalAlphaOfLanguageOnSpacebar;
|
private ObjectAnimator mLanguageOnSpacebarFadeoutAnimator;
|
||||||
private static final int ALPHA_OPAQUE = 255;
|
private static final int ALPHA_OPAQUE = 255;
|
||||||
private boolean mNeedsToDisplayLanguage;
|
private boolean mNeedsToDisplayLanguage;
|
||||||
private Locale mSpacebarLocale;
|
private Locale mSpacebarLocale;
|
||||||
private int mSpacebarTextAlpha = ALPHA_OPAQUE;
|
private int mLanguageOnSpacebarAnimAlpha = ALPHA_OPAQUE;
|
||||||
private final float mSpacebarTextRatio;
|
private final float mSpacebarTextRatio;
|
||||||
private float mSpacebarTextSize;
|
private float mSpacebarTextSize;
|
||||||
private final int mSpacebarTextColor;
|
private final int mSpacebarTextColor;
|
||||||
|
@ -99,8 +96,8 @@ public class LatinKeyboardView extends KeyboardView implements PointerTracker.Ke
|
||||||
private static final int SPACE_LED_LENGTH_PERCENT = 80;
|
private static final int SPACE_LED_LENGTH_PERCENT = 80;
|
||||||
|
|
||||||
// Stuff to draw altCodeWhileTyping keys.
|
// Stuff to draw altCodeWhileTyping keys.
|
||||||
private ValueAnimator mAltCodeKeyWhileTypingFadeoutAnimator;
|
private ObjectAnimator mAltCodeKeyWhileTypingFadeoutAnimator;
|
||||||
private ValueAnimator mAltCodeKeyWhileTypingFadeinAnimator;
|
private ObjectAnimator mAltCodeKeyWhileTypingFadeinAnimator;
|
||||||
private int mAltCodeKeyWhileTypingAnimAlpha = ALPHA_OPAQUE;
|
private int mAltCodeKeyWhileTypingAnimAlpha = ALPHA_OPAQUE;
|
||||||
|
|
||||||
// More keys keyboard
|
// More keys keyboard
|
||||||
|
@ -230,8 +227,8 @@ public class LatinKeyboardView extends KeyboardView implements PointerTracker.Ke
|
||||||
removeMessages(MSG_LONGPRESS_KEY);
|
removeMessages(MSG_LONGPRESS_KEY);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void cancelAndStartAnimators(ValueAnimator animatorToCancel,
|
public static void cancelAndStartAnimators(ObjectAnimator animatorToCancel,
|
||||||
ValueAnimator animatorToStart) {
|
ObjectAnimator animatorToStart) {
|
||||||
if (animatorToCancel != null && animatorToCancel.isStarted()) {
|
if (animatorToCancel != null && animatorToCancel.isStarted()) {
|
||||||
animatorToCancel.cancel();
|
animatorToCancel.cancel();
|
||||||
}
|
}
|
||||||
|
@ -365,6 +362,8 @@ public class LatinKeyboardView extends KeyboardView implements PointerTracker.Ke
|
||||||
mSpacebarTextColor = a.getColor(R.styleable.LatinKeyboardView_spacebarTextColor, 0);
|
mSpacebarTextColor = a.getColor(R.styleable.LatinKeyboardView_spacebarTextColor, 0);
|
||||||
mSpacebarTextShadowColor = a.getColor(
|
mSpacebarTextShadowColor = a.getColor(
|
||||||
R.styleable.LatinKeyboardView_spacebarTextShadowColor, 0);
|
R.styleable.LatinKeyboardView_spacebarTextShadowColor, 0);
|
||||||
|
mLanguageOnSpacebarFinalAlpha = a.getInt(
|
||||||
|
R.styleable.LatinKeyboardView_languageOnSpacebarFinalAlpha, ALPHA_OPAQUE);
|
||||||
final int languageOnSpacebarFadeoutAnimatorResId = a.getResourceId(
|
final int languageOnSpacebarFadeoutAnimatorResId = a.getResourceId(
|
||||||
R.styleable.LatinKeyboardView_languageOnSpacebarFadeoutAnimator, 0);
|
R.styleable.LatinKeyboardView_languageOnSpacebarFadeoutAnimator, 0);
|
||||||
final int altCodeKeyWhileTypingFadeoutAnimatorResId = a.getResourceId(
|
final int altCodeKeyWhileTypingFadeoutAnimatorResId = a.getResourceId(
|
||||||
|
@ -386,56 +385,42 @@ public class LatinKeyboardView extends KeyboardView implements PointerTracker.Ke
|
||||||
|
|
||||||
PointerTracker.setParameters(mPointerTrackerParams);
|
PointerTracker.setParameters(mPointerTrackerParams);
|
||||||
|
|
||||||
final ValueAnimator animator = loadValueAnimator(languageOnSpacebarFadeoutAnimatorResId);
|
mLanguageOnSpacebarFadeoutAnimator = loadObjectAnimator(
|
||||||
|
languageOnSpacebarFadeoutAnimatorResId, this);
|
||||||
|
mAltCodeKeyWhileTypingFadeoutAnimator = loadObjectAnimator(
|
||||||
|
altCodeKeyWhileTypingFadeoutAnimatorResId, this);
|
||||||
|
mAltCodeKeyWhileTypingFadeinAnimator = loadObjectAnimator(
|
||||||
|
altCodeKeyWhileTypingFadeinAnimatorResId, this);
|
||||||
|
}
|
||||||
|
|
||||||
|
private ObjectAnimator loadObjectAnimator(int resId, Object target) {
|
||||||
|
if (resId == 0) return null;
|
||||||
|
final ObjectAnimator animator = (ObjectAnimator)AnimatorInflater.loadAnimator(
|
||||||
|
getContext(), resId);
|
||||||
if (animator != null) {
|
if (animator != null) {
|
||||||
animator.addUpdateListener(new AnimatorUpdateListener() {
|
animator.setTarget(target);
|
||||||
@Override
|
}
|
||||||
public void onAnimationUpdate(ValueAnimator animation) {
|
return animator;
|
||||||
mSpacebarTextAlpha = (Integer)animation.getAnimatedValue();
|
}
|
||||||
|
|
||||||
|
// Getter/setter methods for {@link ObjectAnimator}.
|
||||||
|
public int getLanguageOnSpacebarAnimAlpha() {
|
||||||
|
return mLanguageOnSpacebarAnimAlpha;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setLanguageOnSpacebarAnimAlpha(int alpha) {
|
||||||
|
mLanguageOnSpacebarAnimAlpha = alpha;
|
||||||
invalidateKey(mSpaceKey);
|
invalidateKey(mSpaceKey);
|
||||||
}
|
}
|
||||||
});
|
|
||||||
animator.addListener(new AnimatorListenerAdapter() {
|
|
||||||
@Override
|
|
||||||
public void onAnimationEnd(Animator a) {
|
|
||||||
final ValueAnimator valueAnimator = (ValueAnimator)a;
|
|
||||||
mFinalAlphaOfLanguageOnSpacebar = (Integer)valueAnimator.getAnimatedValue();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
// In order to get the final value of animator.
|
|
||||||
animator.end();
|
|
||||||
}
|
|
||||||
mLanguageOnSpacebarFadeoutAnimator = animator;
|
|
||||||
|
|
||||||
final ValueAnimator fadeout = loadValueAnimator(altCodeKeyWhileTypingFadeoutAnimatorResId);
|
public int getAltCodeKeyWhileTypingAnimAlpha() {
|
||||||
if (fadeout != null) {
|
return mAltCodeKeyWhileTypingAnimAlpha;
|
||||||
fadeout.addUpdateListener(new AnimatorUpdateListener() {
|
}
|
||||||
@Override
|
|
||||||
public void onAnimationUpdate(ValueAnimator animation) {
|
public void setAltCodeKeyWhileTypingAnimAlpha(int alpha) {
|
||||||
mAltCodeKeyWhileTypingAnimAlpha = (Integer)animation.getAnimatedValue();
|
mAltCodeKeyWhileTypingAnimAlpha = alpha;
|
||||||
updateAltCodeKeyWhileTyping();
|
updateAltCodeKeyWhileTyping();
|
||||||
}
|
}
|
||||||
});
|
|
||||||
}
|
|
||||||
mAltCodeKeyWhileTypingFadeoutAnimator = fadeout;
|
|
||||||
|
|
||||||
final ValueAnimator fadein = loadValueAnimator(altCodeKeyWhileTypingFadeinAnimatorResId);
|
|
||||||
if (fadein != null) {
|
|
||||||
fadein.addUpdateListener(new AnimatorUpdateListener() {
|
|
||||||
@Override
|
|
||||||
public void onAnimationUpdate(ValueAnimator animation) {
|
|
||||||
mAltCodeKeyWhileTypingAnimAlpha = (Integer)animation.getAnimatedValue();
|
|
||||||
updateAltCodeKeyWhileTyping();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
mAltCodeKeyWhileTypingFadeinAnimator = fadein;
|
|
||||||
}
|
|
||||||
|
|
||||||
private ValueAnimator loadValueAnimator(int resId) {
|
|
||||||
if (resId == 0) return null;
|
|
||||||
return (ValueAnimator)AnimatorInflater.loadAnimator(getContext(), resId);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setKeyboardActionListener(KeyboardActionListener listener) {
|
public void setKeyboardActionListener(KeyboardActionListener listener) {
|
||||||
mKeyboardActionListener = listener;
|
mKeyboardActionListener = listener;
|
||||||
|
@ -859,19 +844,21 @@ public class LatinKeyboardView extends KeyboardView implements PointerTracker.Ke
|
||||||
|
|
||||||
public void startDisplayLanguageOnSpacebar(boolean subtypeChanged,
|
public void startDisplayLanguageOnSpacebar(boolean subtypeChanged,
|
||||||
boolean needsToDisplayLanguage) {
|
boolean needsToDisplayLanguage) {
|
||||||
final ValueAnimator animator = mLanguageOnSpacebarFadeoutAnimator;
|
final ObjectAnimator animator = mLanguageOnSpacebarFadeoutAnimator;
|
||||||
if (animator != null) {
|
|
||||||
animator.cancel();
|
|
||||||
}
|
|
||||||
mNeedsToDisplayLanguage = needsToDisplayLanguage;
|
mNeedsToDisplayLanguage = needsToDisplayLanguage;
|
||||||
if (animator == null) {
|
if (animator == null) {
|
||||||
mNeedsToDisplayLanguage = false;
|
mNeedsToDisplayLanguage = false;
|
||||||
} else {
|
} else {
|
||||||
if (subtypeChanged && needsToDisplayLanguage) {
|
if (subtypeChanged && needsToDisplayLanguage) {
|
||||||
mSpacebarTextAlpha = ALPHA_OPAQUE;
|
setLanguageOnSpacebarAnimAlpha(ALPHA_OPAQUE);
|
||||||
|
if (animator.isStarted()) {
|
||||||
|
animator.cancel();
|
||||||
|
}
|
||||||
animator.start();
|
animator.start();
|
||||||
} else {
|
} else {
|
||||||
mSpacebarTextAlpha = mFinalAlphaOfLanguageOnSpacebar;
|
if (!animator.isStarted()) {
|
||||||
|
mLanguageOnSpacebarAnimAlpha = mLanguageOnSpacebarFinalAlpha;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
invalidateKey(mSpaceKey);
|
invalidateKey(mSpaceKey);
|
||||||
|
@ -965,10 +952,10 @@ public class LatinKeyboardView extends KeyboardView implements PointerTracker.Ke
|
||||||
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(mSpacebarTextShadowColor);
|
paint.setColor(mSpacebarTextShadowColor);
|
||||||
paint.setAlpha(mSpacebarTextAlpha);
|
paint.setAlpha(mLanguageOnSpacebarAnimAlpha);
|
||||||
canvas.drawText(language, width / 2, baseline - descent - 1, paint);
|
canvas.drawText(language, width / 2, baseline - descent - 1, paint);
|
||||||
paint.setColor(mSpacebarTextColor);
|
paint.setColor(mSpacebarTextColor);
|
||||||
paint.setAlpha(mSpacebarTextAlpha);
|
paint.setAlpha(mLanguageOnSpacebarAnimAlpha);
|
||||||
canvas.drawText(language, width / 2, baseline - descent, paint);
|
canvas.drawText(language, width / 2, baseline - descent, paint);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue