Delay clearing digits until onStop()

It is a bit astonishing when users see digits being cleared
just after pressing "call" button on dialer screen, while
we're sure we should clear the previous digits entered when
a phone call is made.

Because onDestroy() may not be called even after the Activity's
being done, check the flag on onResume() too.

TESTED:
- make a phone call
- access voicemail service
- enter phone number and exit dialer without calling
- play with swipe (which may destroy the fragment)

Bug: 1745781
Change-Id: Ie0bc0ee8d5b1bb55bfea3b394b86cd31799c8238
diff --git a/src/com/android/contacts/dialpad/DialpadFragment.java b/src/com/android/contacts/dialpad/DialpadFragment.java
index 0cefe2d..47d4f9f 100644
--- a/src/com/android/contacts/dialpad/DialpadFragment.java
+++ b/src/com/android/contacts/dialpad/DialpadFragment.java
@@ -109,6 +109,9 @@
     private View mDigitsContainer;
     private EditText mDigits;
 
+    /** Remembers if we need to clear digits field when the screen is completely gone. */
+    private boolean mClearDigitsOnStop;
+
     private View mDelete;
     private ToneGenerator mToneGenerator;
     private final Object mToneGeneratorLock = new Object();
@@ -565,6 +568,15 @@
     }
 
     @Override
+    public void onStop() {
+        super.onStop();
+        if (mClearDigitsOnStop) {
+            mClearDigitsOnStop = false;
+            mDigits.getText().clear();
+        }
+    }
+
+    @Override
     public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
         super.onCreateOptionsMenu(menu, inflater);
         if (ViewConfiguration.get(getActivity()).hasPermanentMenuKey() &&
@@ -929,7 +941,7 @@
 
     public void callVoicemail() {
         startActivity(ContactsUtils.getVoicemailIntent());
-        mDigits.getText().clear(); // TODO: Fix bug 1745781
+        mClearDigitsOnStop = true;
         getActivity().finish();
     }
 
@@ -1054,7 +1066,7 @@
                         (getActivity() instanceof DialtactsActivity ?
                                 ((DialtactsActivity)getActivity()).getCallOrigin() : null));
                 startActivity(intent);
-                mDigits.getText().clear();  // TODO: Fix bug 1745781
+                mClearDigitsOnStop = true;
                 getActivity().finish();
             }
         }