Show a cursor on long press

Digits field doesn't allow "paste" option when there's no
text there, since EditText doesn't allow that when the cursor
is invisible while we intentionally hide the cursor.

One side effect of this change is that users will see the cursor
regardless of "paste" status if they long-click the field.

Also hide the cursor when it is at the end of the text.

Bug: 5394377
Change-Id: I046db65ac869ab8de860448d4dfe05199f48406b
diff --git a/src/com/android/contacts/dialpad/DialpadFragment.java b/src/com/android/contacts/dialpad/DialpadFragment.java
index 1790b9e..064e054 100644
--- a/src/com/android/contacts/dialpad/DialpadFragment.java
+++ b/src/com/android/contacts/dialpad/DialpadFragment.java
@@ -248,6 +248,7 @@
         mDigits.setKeyListener(DialerKeyListener.getInstance());
         mDigits.setOnClickListener(this);
         mDigits.setOnKeyListener(this);
+        mDigits.setOnLongClickListener(this);
         mDigits.addTextChangedListener(this);
 
         PhoneNumberFormatter.setPhoneNumberFormattingTextWatcher(getActivity(), mDigits);
@@ -653,6 +654,12 @@
         mHaptic.vibrate();
         KeyEvent event = new KeyEvent(KeyEvent.ACTION_DOWN, keyCode);
         mDigits.onKeyDown(keyCode, event);
+
+        // If the cursor is at the end of the text we hide it.
+        final int length = mDigits.length();
+        if (length == mDigits.getSelectionStart() && length == mDigits.getSelectionEnd()) {
+            mDigits.setCursorVisible(false);
+        }
     }
 
     public boolean onKey(View view, int keyCode, KeyEvent event) {
@@ -804,6 +811,13 @@
                 keyPressed(KeyEvent.KEYCODE_PLUS);
                 return true;
             }
+            case R.id.digits: {
+                // Right now EditText does not show the "paste" option when cursor is not visible.
+                // To show that, make the cursor visible, and return false, letting the EditText
+                // show the option by itself.
+                mDigits.setCursorVisible(true);
+                return false;
+            }
         }
         return false;
     }