[PB8] Add an animation upon status change.

Bug: 7600384
Change-Id: If5efb9357075193d10255187008e870e2933bdb8
This commit is contained in:
Jean Chalard 2013-04-24 15:27:56 +09:00
parent 2d72590ced
commit 513c63e877
3 changed files with 42 additions and 8 deletions

View file

@ -16,9 +16,12 @@
package com.android.inputmethod.dictionarypack;
import android.animation.Animator;
import android.animation.AnimatorListenerAdapter;
import android.content.Context;
import android.util.AttributeSet;
import android.view.View;
import android.view.ViewPropertyAnimator;
import android.widget.Button;
import android.widget.FrameLayout;
@ -115,22 +118,35 @@ public class ButtonSwitcher extends FrameLayout {
}
private void animateButtonPosition(final int oldStatus, final int newStatus) {
animateButton(getButton(oldStatus), ANIMATION_OUT);
animateButton(getButton(newStatus), ANIMATION_IN);
final View oldButton = getButton(oldStatus);
final View newButton = getButton(newStatus);
if (null != oldButton && null != newButton) {
// Transition between two buttons : animate out, then in
animateButton(oldButton, ANIMATION_OUT).setListener(
new AnimatorListenerAdapter() {
@Override
public void onAnimationEnd(final Animator animation) {
animateButton(newButton, ANIMATION_IN);
}
});
} else if (null != oldButton) {
animateButton(oldButton, ANIMATION_OUT);
} else if (null != newButton) {
animateButton(newButton, ANIMATION_IN);
}
}
public void setInternalOnClickListener(final OnClickListener listener) {
mOnClickListener = listener;
}
private void animateButton(final View button, final int direction) {
if (null == button) return;
private ViewPropertyAnimator animateButton(final View button, final int direction) {
final float outerX = getWidth();
final float innerX = button.getX() - button.getTranslationX();
if (ANIMATION_IN == direction) {
button.animate().translationX(0);
return button.animate().translationX(0);
} else {
button.animate().translationX(outerX - innerX);
return button.animate().translationX(outerX - innerX);
}
}
}

View file

@ -44,6 +44,12 @@ public class DictionaryListInterfaceState {
return state.mOpen;
}
public int getStatus(final String wordlistId) {
final State state = mWordlistToState.get(wordlistId);
if (null == state) return MetadataDbHelper.STATUS_UNKNOWN;
return state.mStatus;
}
public void setOpen(final String wordlistId, final int status) {
final State newState;
final State state = mWordlistToState.get(wordlistId);

View file

@ -191,8 +191,20 @@ public final class WordListPreference extends Preference {
((ViewGroup)view).setLayoutTransition(null);
final ButtonSwitcher buttonSwitcher =
(ButtonSwitcher)view.findViewById(R.id.wordlist_button_switcher);
buttonSwitcher.setStatusAndUpdateVisuals(mInterfaceState.isOpen(mWordlistId) ?
getButtonSwitcherStatus(mStatus) : ButtonSwitcher.STATUS_NO_BUTTON);
if (mInterfaceState.isOpen(mWordlistId)) {
// The button is open.
final int previousStatus = mInterfaceState.getStatus(mWordlistId);
buttonSwitcher.setStatusAndUpdateVisuals(getButtonSwitcherStatus(previousStatus));
if (previousStatus != mStatus) {
// We come here if the status has changed since last time. We need to animate
// the transition.
buttonSwitcher.setStatusAndUpdateVisuals(getButtonSwitcherStatus(mStatus));
mInterfaceState.setOpen(mWordlistId, mStatus);
}
} else {
// The button is closed.
buttonSwitcher.setStatusAndUpdateVisuals(ButtonSwitcher.STATUS_NO_BUTTON);
}
buttonSwitcher.setInternalOnClickListener(mActionButtonClickHandler);
view.setOnClickListener(mPreferenceClickHandler);
}