am 988a1f31: Merge "Fix a bug with bad view reuse."

* commit '988a1f3132d2e13fcd108ef945f91d9f30d8e222':
  Fix a bug with bad view reuse.
main
Jean Chalard 2013-07-15 22:46:07 -07:00 committed by Android Git Automerger
commit 8850a158f8
3 changed files with 9 additions and 2 deletions

View File

@ -47,6 +47,7 @@ public class ButtonSwitcher extends FrameLayout {
private Button mInstallButton; private Button mInstallButton;
private Button mCancelButton; private Button mCancelButton;
private Button mDeleteButton; private Button mDeleteButton;
private DictionaryListInterfaceState mInterfaceState;
private OnClickListener mOnClickListener; private OnClickListener mOnClickListener;
public ButtonSwitcher(Context context, AttributeSet attrs) { public ButtonSwitcher(Context context, AttributeSet attrs) {
@ -57,9 +58,10 @@ public class ButtonSwitcher extends FrameLayout {
super(context, attrs, defStyle); super(context, attrs, defStyle);
} }
public void reset() { public void reset(final DictionaryListInterfaceState interfaceState) {
mStatus = NOT_INITIALIZED; mStatus = NOT_INITIALIZED;
mAnimateToStatus = NOT_INITIALIZED; mAnimateToStatus = NOT_INITIALIZED;
mInterfaceState = interfaceState;
} }
@Override @Override
@ -153,6 +155,7 @@ public class ButtonSwitcher extends FrameLayout {
private ViewPropertyAnimator animateButton(final View button, final int direction) { private ViewPropertyAnimator animateButton(final View button, final int direction) {
final float outerX = getWidth(); final float outerX = getWidth();
final float innerX = button.getX() - button.getTranslationX(); final float innerX = button.getX() - button.getTranslationX();
mInterfaceState.removeFromCache((View)getParent());
if (ANIMATION_IN == direction) { if (ANIMATION_IN == direction) {
button.setClickable(true); button.setClickable(true);
return button.animate().translationX(0); return button.animate().translationX(0);

View File

@ -80,4 +80,8 @@ public class DictionaryListInterfaceState {
mViewCache.add(view); mViewCache.add(view);
return view; return view;
} }
public void removeFromCache(final View view) {
mViewCache.remove(view);
}
} }

View File

@ -224,7 +224,7 @@ public final class WordListPreference extends Preference {
(ButtonSwitcher)view.findViewById(R.id.wordlist_button_switcher); (ButtonSwitcher)view.findViewById(R.id.wordlist_button_switcher);
// We need to clear the state of the button switcher, because we reuse views; if we didn't // We need to clear the state of the button switcher, because we reuse views; if we didn't
// reset it would animate from whatever its old state was. // reset it would animate from whatever its old state was.
buttonSwitcher.reset(); buttonSwitcher.reset(mInterfaceState);
if (mInterfaceState.isOpen(mWordlistId)) { if (mInterfaceState.isOpen(mWordlistId)) {
// The button is open. // The button is open.
final int previousStatus = mInterfaceState.getStatus(mWordlistId); final int previousStatus = mInterfaceState.getStatus(mWordlistId);