merge in lmp-mr1-release history after reset to lmp-mr1-dev
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 @@
                 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 @@
     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 @@
 
     @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 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 @@
 
     @Override
     public boolean onLongClick(View view) {
-        mCurrentButton = view;
-
         if (view.getId() == R.id.del) {
             onClear();
             return true;
@@ -348,11 +343,11 @@
                         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 @@
             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 @@
             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);
             }
diff --git a/src/com/android/calculator2/CalculatorExpressionEvaluator.java b/src/com/android/calculator2/CalculatorExpressionEvaluator.java
index 26cd404..85d719b 100644
--- a/src/com/android/calculator2/CalculatorExpressionEvaluator.java
+++ b/src/com/android/calculator2/CalculatorExpressionEvaluator.java
@@ -22,8 +22,16 @@
 
 public class CalculatorExpressionEvaluator {
 
+    /**
+     * The maximum number of significant digits to display.
+     */
     private static final int MAX_DIGITS = 12;
-    private static final int ROUNDING_DIGITS = 2;
+
+    /**
+     * A {@link Double} has at least 17 significant digits, we show the first {@link #MAX_DIGITS}
+     * and use the remaining digits as guard digits to hide floating point precision errors.
+     */
+    private static final int ROUNDING_DIGITS = Math.max(17 - MAX_DIGITS, 0);
 
     private final Symbols mSymbols;
     private final CalculatorExpressionTokenizer mTokenizer;