Merge "Use XML animator definition"
commit
f147da0436
|
@ -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" />
|
|
@ -132,14 +132,8 @@
|
|||
<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="finalAlphaOfLanguageOnSpacebar" format="integer" />
|
||||
<!-- Fadeout animator for spacebar language label. -->
|
||||
<attr name="languageOnSpacebarFadeoutAnimator" format="reference" />
|
||||
<!-- Key detection hysteresis distance. -->
|
||||
<attr name="keyHysteresisDistance" format="dimension" />
|
||||
<!-- Touch noise threshold time in millisecond -->
|
||||
|
|
|
@ -78,9 +78,7 @@
|
|||
<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="finalAlphaOfLanguageOnSpacebar">128</item>
|
||||
<item name="languageOnSpacebarFadeoutAnimator">@anim/language_on_spacebar_fadeout</item>
|
||||
</style>
|
||||
<style
|
||||
name="LatinKeyboardView"
|
||||
|
|
|
@ -16,7 +16,11 @@
|
|||
|
||||
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.AnimatorUpdateListener;
|
||||
import android.content.Context;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.content.res.TypedArray;
|
||||
|
@ -75,12 +79,9 @@ public class LatinKeyboardView extends KeyboardView implements PointerTracker.Ke
|
|||
private Key mSpaceKey;
|
||||
private Drawable mSpaceIcon;
|
||||
// Stuff to draw language name on spacebar.
|
||||
private ValueAnimator mLanguageOnSpacebarAnimator;
|
||||
private ValueAnimator mLanguageOnSpacebarFadeoutAnimator;
|
||||
private int mFinalAlphaOfLanguageOnSpacebar;
|
||||
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_ALWAYS_DISPLAY = -1;
|
||||
private boolean mNeedsToDisplayLanguage;
|
||||
private Locale mSpacebarLocale;
|
||||
private int mSpacebarTextAlpha;
|
||||
|
@ -339,13 +340,8 @@ 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);
|
||||
mFinalAlphaOfLanguageOnSpacebar = a.getInt(
|
||||
R.styleable.LatinKeyboardView_finalAlphaOfLanguageOnSpacebar, 0);
|
||||
final int languageOnSpacebarFadeoutAnimatorResId = a.getResourceId(
|
||||
R.styleable.LatinKeyboardView_languageOnSpacebarFadeoutAnimator, 0);
|
||||
|
||||
final KeyTimerParams keyTimerParams = new KeyTimerParams(a);
|
||||
mPointerTrackerParams = new PointerTrackerParams(a);
|
||||
|
@ -361,19 +357,31 @@ public class LatinKeyboardView extends KeyboardView implements PointerTracker.Ke
|
|||
|
||||
PointerTracker.setParameters(mPointerTrackerParams);
|
||||
|
||||
mLanguageOnSpacebarAnimator = ValueAnimator.ofInt(
|
||||
ALPHA_OPAQUE, mFinalAlphaOfLanguageOnSpacebar);
|
||||
mLanguageOnSpacebarAnimator.setStartDelay(delayBeforeFadeoutLanguageOnSpacebar);
|
||||
if (mDurationOfFadeoutLanguageOnSpacebar > 0) {
|
||||
mLanguageOnSpacebarAnimator.setDuration(mDurationOfFadeoutLanguageOnSpacebar);
|
||||
ValueAnimator animator = loadValueAnimator(context, languageOnSpacebarFadeoutAnimatorResId);
|
||||
if (animator != null) {
|
||||
animator.addUpdateListener(new AnimatorUpdateListener() {
|
||||
@Override
|
||||
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() {
|
||||
@Override
|
||||
public void onAnimationUpdate(ValueAnimator animation) {
|
||||
mSpacebarTextAlpha = (Integer)animation.getAnimatedValue();
|
||||
invalidateKey(mSpaceKey);
|
||||
}
|
||||
});
|
||||
mLanguageOnSpacebarFadeoutAnimator = animator;
|
||||
}
|
||||
|
||||
private static ValueAnimator loadValueAnimator(Context context, int resId) {
|
||||
if (resId == 0) return null;
|
||||
return (ValueAnimator)AnimatorInflater.loadAnimator(context, resId);
|
||||
}
|
||||
|
||||
public void setKeyboardActionListener(KeyboardActionListener listener) {
|
||||
|
@ -791,16 +799,17 @@ public class LatinKeyboardView extends KeyboardView implements PointerTracker.Ke
|
|||
|
||||
public void startDisplayLanguageOnSpacebar(boolean subtypeChanged,
|
||||
boolean needsToDisplayLanguage) {
|
||||
mLanguageOnSpacebarAnimator.cancel();
|
||||
final ValueAnimator animator = mLanguageOnSpacebarFadeoutAnimator;
|
||||
if (animator != null) {
|
||||
animator.cancel();
|
||||
}
|
||||
mNeedsToDisplayLanguage = needsToDisplayLanguage;
|
||||
if (mDurationOfFadeoutLanguageOnSpacebar == LANGUAGE_ON_SPACEBAR_NEVER_DISPLAY) {
|
||||
if (animator == null) {
|
||||
mNeedsToDisplayLanguage = false;
|
||||
} else if (mDurationOfFadeoutLanguageOnSpacebar == LANGUAGE_ON_SPACEBAR_ALWAYS_DISPLAY) {
|
||||
mSpacebarTextAlpha = ALPHA_OPAQUE;
|
||||
} else {
|
||||
if (subtypeChanged && needsToDisplayLanguage) {
|
||||
mSpacebarTextAlpha = ALPHA_OPAQUE;
|
||||
mLanguageOnSpacebarAnimator.start();
|
||||
animator.start();
|
||||
} else {
|
||||
mSpacebarTextAlpha = mFinalAlphaOfLanguageOnSpacebar;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue