Clean up Calculator state, evaluation and cancellation logic

Bug: 33216049
Bug: 33219408
Bug: 33107696

Add INIT_FOR_RESULT state to represent INIT state, when we know that
computation has previously ended in RESULT state.

Stubbornly refuse to display the history view if we are currently
in EVALUATE or INIT state. Both of these are very temporary.

Break up Calculator.onCreate() to make it a bit more manageable.

Add a number of assertion checks to detect unexpected states, etc.

Add HISTORY_MAIN_INDEX to ensure that we only have one evaluation
listener per expression being evaluated.

Add cancelNonMain to better target cancellation requests.

Remove evaluateInstantIfNecessary() hack in HistoryFragment.
We should no longer be randomly cancelling evaluations we don't
own.

Be a little more aggressive about avoid redundant evaluations.

Change-Id: I5eaf6390b597926f9255c635fb44d50b47cbd1e1
diff --git a/src/com/android/calculator2/HistoryAdapter.java b/src/com/android/calculator2/HistoryAdapter.java
index 56399c7..429d0d7 100644
--- a/src/com/android/calculator2/HistoryAdapter.java
+++ b/src/com/android/calculator2/HistoryAdapter.java
@@ -73,7 +73,7 @@
         holder.mFormula.setText(item.getFormula());
         // Note: HistoryItems that are not the current expression will always have interesting ops.
         holder.mResult.setEvaluator(mEvaluator, item.getEvaluatorIndex());
-        if (item.getEvaluatorIndex() == Evaluator.MAIN_INDEX) {
+        if (item.getEvaluatorIndex() == Evaluator.HISTORY_MAIN_INDEX) {
             holder.mDate.setText(mCurrentExpressionDescription);
             holder.mDate.setContentDescription(mCurrentExpressionDescription);
         } else {
@@ -165,4 +165,4 @@
             return mDate;
         }
     }
-}
\ No newline at end of file
+}