ShawnLin013 / NumberPicker

:slot_machine: The android library that provides a simple and customizable NumberPicker.
MIT License
1.07k stars 240 forks source link

OnClick called as soon as the user touches #183

Open esuljic opened 3 years ago

esuljic commented 3 years ago

Background: I created CustomView with NumberPicker and EditText in the middle, and if the user clicks on NumberPicker, it shows the EditText with that value so the user can the value by the keyboard.

The problem is that onClickListener fires as soon as the user touches the middle number. The convention is that onClick should be called when the user lifts finger within getTapTimeout milliseconds.

I fixed it myself, but I would like you to integrate it into your library so I can continue using it.

My approach:

  1. Insert

    private long clickedMillis = 0;

  2. Replace the 2 occurrences of:

    if (mOnClickListener != null) { mOnClickListener.onClick(this); }

to:

clickedMillis = System.currentTimeMillis();

  1. Add this to ACTION_UP switch of onTouchEvent() method, when selectorIndexOffset == 0:

    if (clickedMillis > System.currentTimeMillis() - ViewConfiguration.getTapTimeout() && mOnClickListener != null) { mOnClickListener.onClick(this); }