Commit 1283ee74 authored by Justin Klaassen's avatar Justin Klaassen
Browse files

Stop using RenderNodeAnimator callbacks

Bug: 17281017

- RenderNodeAnimator's callbacks are asynchronous and thus cannot be
  relied upon for synchronus state changes. Instead use Animator#end()
  and rely on the ValueAnimator synchronously invoking the listener's
  onAnimationStart callback.
- Also to prevent future NPEs, remove mCurrentButton ivar and instead
  specify the source button directly.

Change-Id: I4ca05b46c582474a6ca7e00d8d16df118ede7eb4
parent e61089e5
......@@ -86,7 +86,6 @@ public class Calculator extends Activity
case KeyEvent.KEYCODE_NUMPAD_ENTER:
case KeyEvent.KEYCODE_ENTER:
if (keyEvent.getAction() == KeyEvent.ACTION_UP) {
mCurrentButton = mEqualButton;
onEquals();
}
// ignore all other actions
......@@ -114,10 +113,9 @@ public class Calculator extends Activity
private CalculatorEditText mResultEditText;
private ViewPager mPadViewPager;
private View mDeleteButton;
private View mEqualButton;
private View mClearButton;
private View mEqualButton;
private View mCurrentButton;
private Animator mCurrentAnimator;
@Override
......@@ -156,9 +154,10 @@ public class Calculator extends Activity
@Override
protected void onSaveInstanceState(@NonNull Bundle outState) {
// If there's an animation in progress, cancel it first to ensure our state is up-to-date.
// If there's an animation in progress, end it immediately to ensure the state is
// up-to-date before it is serialized.
if (mCurrentAnimator != null) {
mCurrentAnimator.cancel();
mCurrentAnimator.end();
}
super.onSaveInstanceState(outState);
......@@ -212,16 +211,14 @@ public class Calculator extends Activity
public void onUserInteraction() {
super.onUserInteraction();
// If there's an animation in progress, cancel it so the user interaction can be handled
// immediately.
// If there's an animation in progress, end it immediately to ensure the state is
// up-to-date before the pending user interaction is handled.
if (mCurrentAnimator != null) {
mCurrentAnimator.cancel();
mCurrentAnimator.end();
}
}
public void onButtonClick(View view) {
mCurrentButton = view;
switch (view.getId()) {
case R.id.eq:
onEquals();
......@@ -248,8 +245,6 @@ public class Calculator extends Activity
@Override
public boolean onLongClick(View view) {
mCurrentButton = view;
if (view.getId() == R.id.del) {
onClear();
return true;
......@@ -348,11 +343,11 @@ public class Calculator extends Activity
revealCenterX, revealCenterY, 0.0f, revealRadius);
revealAnimator.setDuration(
getResources().getInteger(android.R.integer.config_longAnimTime));
revealAnimator.addListener(listener);
final Animator alphaAnimator = ObjectAnimator.ofFloat(revealView, View.ALPHA, 0.0f);
alphaAnimator.setDuration(
getResources().getInteger(android.R.integer.config_mediumAnimTime));
alphaAnimator.addListener(listener);
final AnimatorSet animatorSet = new AnimatorSet();
animatorSet.play(revealAnimator).before(alphaAnimator);
......@@ -374,9 +369,11 @@ public class Calculator extends Activity
return;
}
reveal(mCurrentButton, R.color.calculator_accent_color, new AnimatorListenerAdapter() {
final View sourceView = mClearButton.getVisibility() == View.VISIBLE
? mClearButton : mDeleteButton;
reveal(sourceView, R.color.calculator_accent_color, new AnimatorListenerAdapter() {
@Override
public void onAnimationEnd(Animator animation) {
public void onAnimationStart(Animator animation) {
mFormulaEditText.getEditableText().clear();
}
});
......@@ -389,9 +386,9 @@ public class Calculator extends Activity
return;
}
reveal(mCurrentButton, R.color.calculator_error_color, new AnimatorListenerAdapter() {
reveal(mEqualButton, R.color.calculator_error_color, new AnimatorListenerAdapter() {
@Override
public void onAnimationEnd(Animator animation) {
public void onAnimationStart(Animator animation) {
setState(CalculatorState.ERROR);
mResultEditText.setText(errorResourceId);
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment