4848import android .view .accessibility .AccessibilityEvent ;
4949import android .view .accessibility .AccessibilityManager ;
5050import android .view .animation .DecelerateInterpolator ;
51+ import android .view .inputmethod .EditorInfo ;
5152import android .view .inputmethod .InputMethodManager ;
5253
5354import com .android .internal .R ;
@@ -367,9 +368,9 @@ public String format(int value) {
367368 private float mLastMotionEventY ;
368369
369370 /**
370- * Flag if to begin edit on next up event .
371+ * Flag if to check for double tap and potentially start edit .
371372 */
372- private boolean mBeginEditOnUpEvent ;
373+ private boolean mCheckBeginEditOnUpEvent ;
373374
374375 /**
375376 * Flag if to adjust the selector wheel on next up event.
@@ -446,6 +447,11 @@ public String format(int value) {
446447 */
447448 private boolean mScrollWheelAndFadingEdgesInitialized ;
448449
450+ /**
451+ * The time of the last up event.
452+ */
453+ private long mLastUpEventTimeMillis ;
454+
449455 /**
450456 * Interface to listen for changes of the current value.
451457 */
@@ -624,10 +630,6 @@ public boolean onLongClick(View v) {
624630 public void onFocusChange (View v , boolean hasFocus ) {
625631 if (hasFocus ) {
626632 mInputText .selectAll ();
627- InputMethodManager inputMethodManager = InputMethodManager .peekInstance ();
628- if (inputMethodManager != null ) {
629- inputMethodManager .showSoftInput (mInputText , 0 );
630- }
631633 } else {
632634 mInputText .setSelection (0 , 0 );
633635 validateInputTextView (v );
@@ -639,6 +641,7 @@ public void onFocusChange(View v, boolean hasFocus) {
639641 });
640642
641643 mInputText .setRawInputType (InputType .TYPE_CLASS_NUMBER );
644+ mInputText .setImeOptions (EditorInfo .IME_ACTION_DONE );
642645
643646 // initialize constants
644647 mTouchSlop = ViewConfiguration .getTapTimeout ();
@@ -773,7 +776,7 @@ public boolean onInterceptTouchEvent(MotionEvent event) {
773776 removeAllCallbacks ();
774777 mShowInputControlsAnimator .cancel ();
775778 mDimSelectorWheelAnimator .cancel ();
776- mBeginEditOnUpEvent = false ;
779+ mCheckBeginEditOnUpEvent = false ;
777780 mAdjustScrollerOnUpEvent = true ;
778781 if (mSelectorWheelState == SELECTOR_WHEEL_STATE_LARGE ) {
779782 mSelectorWheelPaint .setAlpha (SELECTOR_WHEEL_BRIGHT_ALPHA );
@@ -784,7 +787,7 @@ public boolean onInterceptTouchEvent(MotionEvent event) {
784787 mAdjustScroller .forceFinished (true );
785788 onScrollStateChange (OnScrollListener .SCROLL_STATE_IDLE );
786789 }
787- mBeginEditOnUpEvent = scrollersFinished ;
790+ mCheckBeginEditOnUpEvent = scrollersFinished ;
788791 mAdjustScrollerOnUpEvent = true ;
789792 hideInputControls ();
790793 return true ;
@@ -801,7 +804,7 @@ public boolean onInterceptTouchEvent(MotionEvent event) {
801804 float currentMoveY = event .getY ();
802805 int deltaDownY = (int ) Math .abs (currentMoveY - mLastDownEventY );
803806 if (deltaDownY > mTouchSlop ) {
804- mBeginEditOnUpEvent = false ;
807+ mCheckBeginEditOnUpEvent = false ;
805808 onScrollStateChange (OnScrollListener .SCROLL_STATE_TOUCH_SCROLL );
806809 setSelectorWheelState (SELECTOR_WHEEL_STATE_LARGE );
807810 hideInputControls ();
@@ -825,11 +828,11 @@ public boolean onTouchEvent(MotionEvent ev) {
825828 switch (action ) {
826829 case MotionEvent .ACTION_MOVE :
827830 float currentMoveY = ev .getY ();
828- if (mBeginEditOnUpEvent
831+ if (mCheckBeginEditOnUpEvent
829832 || mScrollState != OnScrollListener .SCROLL_STATE_TOUCH_SCROLL ) {
830833 int deltaDownY = (int ) Math .abs (currentMoveY - mLastDownEventY );
831834 if (deltaDownY > mTouchSlop ) {
832- mBeginEditOnUpEvent = false ;
835+ mCheckBeginEditOnUpEvent = false ;
833836 onScrollStateChange (OnScrollListener .SCROLL_STATE_TOUCH_SCROLL );
834837 }
835838 }
@@ -839,11 +842,20 @@ public boolean onTouchEvent(MotionEvent ev) {
839842 mLastMotionEventY = currentMoveY ;
840843 break ;
841844 case MotionEvent .ACTION_UP :
842- if (mBeginEditOnUpEvent ) {
843- setSelectorWheelState (SELECTOR_WHEEL_STATE_SMALL );
844- showInputControls (mShowInputControlsAnimimationDuration );
845- mInputText .requestFocus ();
846- return true ;
845+ if (mCheckBeginEditOnUpEvent ) {
846+ mCheckBeginEditOnUpEvent = false ;
847+ final long deltaTapTimeMillis = ev .getEventTime () - mLastUpEventTimeMillis ;
848+ if (deltaTapTimeMillis < ViewConfiguration .getDoubleTapTimeout ()) {
849+ setSelectorWheelState (SELECTOR_WHEEL_STATE_SMALL );
850+ showInputControls (mShowInputControlsAnimimationDuration );
851+ mInputText .requestFocus ();
852+ InputMethodManager inputMethodManager = InputMethodManager .peekInstance ();
853+ if (inputMethodManager != null ) {
854+ inputMethodManager .showSoftInput (mInputText , 0 );
855+ }
856+ mLastUpEventTimeMillis = ev .getEventTime ();
857+ return true ;
858+ }
847859 }
848860 VelocityTracker velocityTracker = mVelocityTracker ;
849861 velocityTracker .computeCurrentVelocity (1000 , mMaximumFlingVelocity );
@@ -862,6 +874,7 @@ public boolean onTouchEvent(MotionEvent ev) {
862874 }
863875 mVelocityTracker .recycle ();
864876 mVelocityTracker = null ;
877+ mLastUpEventTimeMillis = ev .getEventTime ();
865878 break ;
866879 }
867880 return true ;
@@ -1985,4 +1998,22 @@ public void run() {
19851998 postDelayed (this , mLongPressUpdateInterval );
19861999 }
19872000 }
2001+
2002+ /**
2003+ * @hide
2004+ */
2005+ public static class CustomEditText extends EditText {
2006+
2007+ public CustomEditText (Context context , AttributeSet attrs ) {
2008+ super (context , attrs );
2009+ }
2010+
2011+ @ Override
2012+ public void onEditorAction (int actionCode ) {
2013+ super .onEditorAction (actionCode );
2014+ if (actionCode == EditorInfo .IME_ACTION_DONE ) {
2015+ clearFocus ();
2016+ }
2017+ }
2018+ }
19882019}
0 commit comments