summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJustin Klaassen <justinklaassen@google.com>2014-12-04 14:21:53 -0800
committerJustin Klaassen <justinklaassen@google.com>2014-12-04 14:21:53 -0800
commit1283ee748254cce69fda2d1a3d2af1cf881b2738 (patch)
treeac50c8a67b5e158293104daf563b9d567ae07548 /src
parente61089e594fb1718376926c515a1e6b594a865cf (diff)
downloadCalculator-1283ee748254cce69fda2d1a3d2af1cf881b2738.tar.gz
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
Diffstat (limited to 'src')
-rw-r--r--src/com/android/calculator2/Calculator.java31
1 files changed, 14 insertions, 17 deletions
diff --git a/src/com/android/calculator2/Calculator.java b/src/com/android/calculator2/Calculator.java
index 5dd04bf..a2bcad1 100644
--- a/src/com/android/calculator2/Calculator.java
+++ b/src/com/android/calculator2/Calculator.java
@@ -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);
}