[PB8] Add an animation upon status change.
Bug: 7600384 Change-Id: If5efb9357075193d10255187008e870e2933bdb8main
parent
2d72590ced
commit
513c63e877
|
@ -16,9 +16,12 @@
|
||||||
|
|
||||||
package com.android.inputmethod.dictionarypack;
|
package com.android.inputmethod.dictionarypack;
|
||||||
|
|
||||||
|
import android.animation.Animator;
|
||||||
|
import android.animation.AnimatorListenerAdapter;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.util.AttributeSet;
|
import android.util.AttributeSet;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
|
import android.view.ViewPropertyAnimator;
|
||||||
import android.widget.Button;
|
import android.widget.Button;
|
||||||
import android.widget.FrameLayout;
|
import android.widget.FrameLayout;
|
||||||
|
|
||||||
|
@ -115,22 +118,35 @@ public class ButtonSwitcher extends FrameLayout {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void animateButtonPosition(final int oldStatus, final int newStatus) {
|
private void animateButtonPosition(final int oldStatus, final int newStatus) {
|
||||||
animateButton(getButton(oldStatus), ANIMATION_OUT);
|
final View oldButton = getButton(oldStatus);
|
||||||
animateButton(getButton(newStatus), ANIMATION_IN);
|
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) {
|
public void setInternalOnClickListener(final OnClickListener listener) {
|
||||||
mOnClickListener = listener;
|
mOnClickListener = listener;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void animateButton(final View button, final int direction) {
|
private ViewPropertyAnimator animateButton(final View button, final int direction) {
|
||||||
if (null == button) return;
|
|
||||||
final float outerX = getWidth();
|
final float outerX = getWidth();
|
||||||
final float innerX = button.getX() - button.getTranslationX();
|
final float innerX = button.getX() - button.getTranslationX();
|
||||||
if (ANIMATION_IN == direction) {
|
if (ANIMATION_IN == direction) {
|
||||||
button.animate().translationX(0);
|
return button.animate().translationX(0);
|
||||||
} else {
|
} else {
|
||||||
button.animate().translationX(outerX - innerX);
|
return button.animate().translationX(outerX - innerX);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -44,6 +44,12 @@ public class DictionaryListInterfaceState {
|
||||||
return state.mOpen;
|
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) {
|
public void setOpen(final String wordlistId, final int status) {
|
||||||
final State newState;
|
final State newState;
|
||||||
final State state = mWordlistToState.get(wordlistId);
|
final State state = mWordlistToState.get(wordlistId);
|
||||||
|
|
|
@ -191,8 +191,20 @@ public final class WordListPreference extends Preference {
|
||||||
((ViewGroup)view).setLayoutTransition(null);
|
((ViewGroup)view).setLayoutTransition(null);
|
||||||
final ButtonSwitcher buttonSwitcher =
|
final ButtonSwitcher buttonSwitcher =
|
||||||
(ButtonSwitcher)view.findViewById(R.id.wordlist_button_switcher);
|
(ButtonSwitcher)view.findViewById(R.id.wordlist_button_switcher);
|
||||||
buttonSwitcher.setStatusAndUpdateVisuals(mInterfaceState.isOpen(mWordlistId) ?
|
if (mInterfaceState.isOpen(mWordlistId)) {
|
||||||
getButtonSwitcherStatus(mStatus) : ButtonSwitcher.STATUS_NO_BUTTON);
|
// 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);
|
buttonSwitcher.setInternalOnClickListener(mActionButtonClickHandler);
|
||||||
view.setOnClickListener(mPreferenceClickHandler);
|
view.setOnClickListener(mPreferenceClickHandler);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue