Move mStoreToMemoryRequested to CalculatorResult.
Fixes: 33085082
Change-Id: Ifa95eafd1fd94d8efd16a5bdb802385c0f30ea88
diff --git a/src/com/android/calculator2/CalculatorResult.java b/src/com/android/calculator2/CalculatorResult.java
index c604a6f..e001bee 100644
--- a/src/com/android/calculator2/CalculatorResult.java
+++ b/src/com/android/calculator2/CalculatorResult.java
@@ -142,6 +142,9 @@
private ActionMode.Callback mCopyActionModeCallback;
private ContextMenu mContextMenu;
+ // The user requested that the result currently being evaluated should be stored to "memory".
+ private boolean mStoreToMemoryRequested = false;
+
public CalculatorResult(Context context, AttributeSet attrs) {
super(context, attrs);
mScroller = new OverScroller(context);
@@ -384,10 +387,29 @@
public void onEvaluate(long index, int initPrec, int msd, int leastDigPos,
String truncatedWholePart) {
initPositions(initPrec, msd, leastDigPos, truncatedWholePart);
+
+ if (mStoreToMemoryRequested) {
+ mEvaluator.copyToMemory(index);
+ mStoreToMemoryRequested = false;
+ }
redisplay();
}
/**
+ * Store the result for this index if it is available.
+ * If it is unavailable, set mStoreToMemoryRequested to indicate that we should store
+ * when evaluation is complete.
+ */
+ public void onMemoryStore() {
+ if (mEvaluator.hasResult(mIndex)) {
+ mEvaluator.copyToMemory(mIndex);
+ } else {
+ mStoreToMemoryRequested = true;
+ mEvaluator.requireResult(mIndex, this /* listener */, this /* CharMetricsInfo */);
+ }
+ }
+
+ /**
* Set up scroll bounds (mMinPos, mMaxPos, etc.) and determine whether the result is
* scrollable, based on the supplied information about the result.
* This is unfortunately complicated because we need to predict whether trailing digits
@@ -513,6 +535,7 @@
*/
@Override
public void onError(long index, int resourceId) {
+ mStoreToMemoryRequested = false;
mValid = true;
setLongClickable(false);
mScrollable = false;
@@ -818,6 +841,7 @@
@Override
public void onCancelled(long index) {
clear();
+ mStoreToMemoryRequested = false;
}
/**