Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 76fc6a28 authored by Daisuke Miyakawa's avatar Daisuke Miyakawa
Browse files

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
parent 6493e0e4
Loading
Loading
Loading
Loading
+14 −0
Original line number Diff line number Diff line
@@ -248,6 +248,7 @@ public class DialpadFragment extends Fragment
        mDigits.setKeyListener(DialerKeyListener.getInstance());
        mDigits.setOnClickListener(this);
        mDigits.setOnKeyListener(this);
        mDigits.setOnLongClickListener(this);
        mDigits.addTextChangedListener(this);

        PhoneNumberFormatter.setPhoneNumberFormattingTextWatcher(getActivity(), mDigits);
@@ -653,6 +654,12 @@ public class DialpadFragment extends Fragment
        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 @@ public class DialpadFragment extends Fragment
                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;
    }