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
4 files changed