Merge "Use XML animator definition"

main
Tadashi G. Takaoka 2012-03-13 21:10:08 -07:00 committed by Android (Google) Code Review
commit f147da0436
4 changed files with 67 additions and 39 deletions

View File

@ -0,0 +1,27 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
/*
**
** Copyright 2012, The Android Open Source Project
**
** Licensed under the Apache License, Version 2.0 (the "License");
** you may not use this file except in compliance with the License.
** You may obtain a copy of the License at
**
** http://www.apache.org/licenses/LICENSE-2.0
**
** Unless required by applicable law or agreed to in writing, software
** distributed under the License is distributed on an "AS IS" BASIS,
** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
** See the License for the specific language governing permissions and
** limitations under the License.
*/
-->
<animator
xmlns:android="http://schemas.android.com/apk/res/android"
android:valueType="intType"
android:startOffset="1200"
android:duration="200"
android:valueFrom="255"
android:valueTo="128" />

View File

@ -132,14 +132,8 @@
<attr name="spacebarTextRatio" format="fraction" /> <attr name="spacebarTextRatio" format="fraction" />
<attr name="spacebarTextColor" format="color" /> <attr name="spacebarTextColor" format="color" />
<attr name="spacebarTextShadowColor" format="color" /> <attr name="spacebarTextShadowColor" format="color" />
<!-- Animation parameters for spacebar language label. --> <!-- Fadeout animator for spacebar language label. -->
<attr name="durationOfFadeoutLanguageOnSpacebar" format="integer|enum"> <attr name="languageOnSpacebarFadeoutAnimator" format="reference" />
<!-- 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="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 -->

View File

@ -78,9 +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="ignoreSpecialKeyTimeout">@integer/config_ignore_special_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="showMoreKeysKeyboardAtTouchedPoint">@bool/config_show_more_keys_keyboard_at_touched_point</item>
<item name="durationOfFadeoutLanguageOnSpacebar">200</item> <item name="languageOnSpacebarFadeoutAnimator">@anim/language_on_spacebar_fadeout</item>
<item name="delayBeforeFadeoutLangageOnSpacebar">1200</item>
<item name="finalAlphaOfLanguageOnSpacebar">128</item>
</style> </style>
<style <style
name="LatinKeyboardView" name="LatinKeyboardView"

View File

@ -16,7 +16,11 @@
package com.android.inputmethod.keyboard; package com.android.inputmethod.keyboard;
import android.animation.Animator;
import android.animation.AnimatorInflater;
import android.animation.AnimatorListenerAdapter;
import android.animation.ValueAnimator; 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;
@ -75,12 +79,9 @@ 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 mLanguageOnSpacebarAnimator; private ValueAnimator mLanguageOnSpacebarFadeoutAnimator;
private int mFinalAlphaOfLanguageOnSpacebar; private int mFinalAlphaOfLanguageOnSpacebar;
private int mDurationOfFadeoutLanguageOnSpacebar;
private static final int ALPHA_OPAQUE = 255; private static final int ALPHA_OPAQUE = 255;
private static final int LANGUAGE_ON_SPACEBAR_NEVER_DISPLAY = 0;
private static final int LANGUAGE_ON_SPACEBAR_ALWAYS_DISPLAY = -1;
private boolean mNeedsToDisplayLanguage; private boolean mNeedsToDisplayLanguage;
private Locale mSpacebarLocale; private Locale mSpacebarLocale;
private int mSpacebarTextAlpha; private int mSpacebarTextAlpha;
@ -339,13 +340,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);
mDurationOfFadeoutLanguageOnSpacebar = a.getInt( final int languageOnSpacebarFadeoutAnimatorResId = a.getResourceId(
R.styleable.LatinKeyboardView_durationOfFadeoutLanguageOnSpacebar, R.styleable.LatinKeyboardView_languageOnSpacebarFadeoutAnimator, 0);
LANGUAGE_ON_SPACEBAR_NEVER_DISPLAY);
final int delayBeforeFadeoutLanguageOnSpacebar = a.getInt(
R.styleable.LatinKeyboardView_delayBeforeFadeoutLangageOnSpacebar, 0);
mFinalAlphaOfLanguageOnSpacebar = a.getInt(
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,19 +357,31 @@ public class LatinKeyboardView extends KeyboardView implements PointerTracker.Ke
PointerTracker.setParameters(mPointerTrackerParams); PointerTracker.setParameters(mPointerTrackerParams);
mLanguageOnSpacebarAnimator = ValueAnimator.ofInt( ValueAnimator animator = loadValueAnimator(context, languageOnSpacebarFadeoutAnimatorResId);
ALPHA_OPAQUE, mFinalAlphaOfLanguageOnSpacebar); if (animator != null) {
mLanguageOnSpacebarAnimator.setStartDelay(delayBeforeFadeoutLanguageOnSpacebar); animator.addUpdateListener(new AnimatorUpdateListener() {
if (mDurationOfFadeoutLanguageOnSpacebar > 0) { @Override
mLanguageOnSpacebarAnimator.setDuration(mDurationOfFadeoutLanguageOnSpacebar); public void onAnimationUpdate(ValueAnimator animation) {
mSpacebarTextAlpha = (Integer)animation.getAnimatedValue();
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();
} }
mLanguageOnSpacebarAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { mLanguageOnSpacebarFadeoutAnimator = animator;
@Override }
public void onAnimationUpdate(ValueAnimator animation) {
mSpacebarTextAlpha = (Integer)animation.getAnimatedValue(); private static ValueAnimator loadValueAnimator(Context context, int resId) {
invalidateKey(mSpaceKey); if (resId == 0) return null;
} return (ValueAnimator)AnimatorInflater.loadAnimator(context, resId);
});
} }
public void setKeyboardActionListener(KeyboardActionListener listener) { public void setKeyboardActionListener(KeyboardActionListener listener) {
@ -791,16 +799,17 @@ public class LatinKeyboardView extends KeyboardView implements PointerTracker.Ke
public void startDisplayLanguageOnSpacebar(boolean subtypeChanged, public void startDisplayLanguageOnSpacebar(boolean subtypeChanged,
boolean needsToDisplayLanguage) { boolean needsToDisplayLanguage) {
mLanguageOnSpacebarAnimator.cancel(); final ValueAnimator animator = mLanguageOnSpacebarFadeoutAnimator;
if (animator != null) {
animator.cancel();
}
mNeedsToDisplayLanguage = needsToDisplayLanguage; mNeedsToDisplayLanguage = needsToDisplayLanguage;
if (mDurationOfFadeoutLanguageOnSpacebar == LANGUAGE_ON_SPACEBAR_NEVER_DISPLAY) { if (animator == null) {
mNeedsToDisplayLanguage = false; mNeedsToDisplayLanguage = false;
} else if (mDurationOfFadeoutLanguageOnSpacebar == LANGUAGE_ON_SPACEBAR_ALWAYS_DISPLAY) {
mSpacebarTextAlpha = ALPHA_OPAQUE;
} else { } else {
if (subtypeChanged && needsToDisplayLanguage) { if (subtypeChanged && needsToDisplayLanguage) {
mSpacebarTextAlpha = ALPHA_OPAQUE; mSpacebarTextAlpha = ALPHA_OPAQUE;
mLanguageOnSpacebarAnimator.start(); animator.start();
} else { } else {
mSpacebarTextAlpha = mFinalAlphaOfLanguageOnSpacebar; mSpacebarTextAlpha = mFinalAlphaOfLanguageOnSpacebar;
} }