Loading core/java/android/widget/NumberPicker.java +47 −16 Original line number Diff line number Diff line Loading @@ -48,6 +48,7 @@ import android.view.ViewConfiguration; import android.view.accessibility.AccessibilityEvent; import android.view.accessibility.AccessibilityManager; import android.view.animation.DecelerateInterpolator; import android.view.inputmethod.EditorInfo; import android.view.inputmethod.InputMethodManager; import com.android.internal.R; Loading Loading @@ -367,9 +368,9 @@ public class NumberPicker extends LinearLayout { private float mLastMotionEventY; /** * Flag if to begin edit on next up event. * Flag if to check for double tap and potentially start edit. */ private boolean mBeginEditOnUpEvent; private boolean mCheckBeginEditOnUpEvent; /** * Flag if to adjust the selector wheel on next up event. Loading Loading @@ -446,6 +447,11 @@ public class NumberPicker extends LinearLayout { */ private boolean mScrollWheelAndFadingEdgesInitialized; /** * The time of the last up event. */ private long mLastUpEventTimeMillis; /** * Interface to listen for changes of the current value. */ Loading Loading @@ -624,10 +630,6 @@ public class NumberPicker extends LinearLayout { public void onFocusChange(View v, boolean hasFocus) { if (hasFocus) { mInputText.selectAll(); InputMethodManager inputMethodManager = InputMethodManager.peekInstance(); if (inputMethodManager != null) { inputMethodManager.showSoftInput(mInputText, 0); } } else { mInputText.setSelection(0, 0); validateInputTextView(v); Loading @@ -639,6 +641,7 @@ public class NumberPicker extends LinearLayout { }); mInputText.setRawInputType(InputType.TYPE_CLASS_NUMBER); mInputText.setImeOptions(EditorInfo.IME_ACTION_DONE); // initialize constants mTouchSlop = ViewConfiguration.getTapTimeout(); Loading Loading @@ -773,7 +776,7 @@ public class NumberPicker extends LinearLayout { removeAllCallbacks(); mShowInputControlsAnimator.cancel(); mDimSelectorWheelAnimator.cancel(); mBeginEditOnUpEvent = false; mCheckBeginEditOnUpEvent = false; mAdjustScrollerOnUpEvent = true; if (mSelectorWheelState == SELECTOR_WHEEL_STATE_LARGE) { mSelectorWheelPaint.setAlpha(SELECTOR_WHEEL_BRIGHT_ALPHA); Loading @@ -784,7 +787,7 @@ public class NumberPicker extends LinearLayout { mAdjustScroller.forceFinished(true); onScrollStateChange(OnScrollListener.SCROLL_STATE_IDLE); } mBeginEditOnUpEvent = scrollersFinished; mCheckBeginEditOnUpEvent = scrollersFinished; mAdjustScrollerOnUpEvent = true; hideInputControls(); return true; Loading @@ -801,7 +804,7 @@ public class NumberPicker extends LinearLayout { float currentMoveY = event.getY(); int deltaDownY = (int) Math.abs(currentMoveY - mLastDownEventY); if (deltaDownY > mTouchSlop) { mBeginEditOnUpEvent = false; mCheckBeginEditOnUpEvent = false; onScrollStateChange(OnScrollListener.SCROLL_STATE_TOUCH_SCROLL); setSelectorWheelState(SELECTOR_WHEEL_STATE_LARGE); hideInputControls(); Loading @@ -825,11 +828,11 @@ public class NumberPicker extends LinearLayout { switch (action) { case MotionEvent.ACTION_MOVE: float currentMoveY = ev.getY(); if (mBeginEditOnUpEvent if (mCheckBeginEditOnUpEvent || mScrollState != OnScrollListener.SCROLL_STATE_TOUCH_SCROLL) { int deltaDownY = (int) Math.abs(currentMoveY - mLastDownEventY); if (deltaDownY > mTouchSlop) { mBeginEditOnUpEvent = false; mCheckBeginEditOnUpEvent = false; onScrollStateChange(OnScrollListener.SCROLL_STATE_TOUCH_SCROLL); } } Loading @@ -839,12 +842,21 @@ public class NumberPicker extends LinearLayout { mLastMotionEventY = currentMoveY; break; case MotionEvent.ACTION_UP: if (mBeginEditOnUpEvent) { if (mCheckBeginEditOnUpEvent) { mCheckBeginEditOnUpEvent = false; final long deltaTapTimeMillis = ev.getEventTime() - mLastUpEventTimeMillis; if (deltaTapTimeMillis < ViewConfiguration.getDoubleTapTimeout()) { setSelectorWheelState(SELECTOR_WHEEL_STATE_SMALL); showInputControls(mShowInputControlsAnimimationDuration); mInputText.requestFocus(); InputMethodManager inputMethodManager = InputMethodManager.peekInstance(); if (inputMethodManager != null) { inputMethodManager.showSoftInput(mInputText, 0); } mLastUpEventTimeMillis = ev.getEventTime(); return true; } } VelocityTracker velocityTracker = mVelocityTracker; velocityTracker.computeCurrentVelocity(1000, mMaximumFlingVelocity); int initialVelocity = (int) velocityTracker.getYVelocity(); Loading @@ -862,6 +874,7 @@ public class NumberPicker extends LinearLayout { } mVelocityTracker.recycle(); mVelocityTracker = null; mLastUpEventTimeMillis = ev.getEventTime(); break; } return true; Loading Loading @@ -1985,4 +1998,22 @@ public class NumberPicker extends LinearLayout { postDelayed(this, mLongPressUpdateInterval); } } /** * @hide */ public static class CustomEditText extends EditText { public CustomEditText(Context context, AttributeSet attrs) { super(context, attrs); } @Override public void onEditorAction(int actionCode) { super.onEditorAction(actionCode); if (actionCode == EditorInfo.IME_ACTION_DONE) { clearFocus(); } } } } core/res/res/layout/number_picker.xml +2 −1 Original line number Diff line number Diff line Loading @@ -25,7 +25,8 @@ style="?android:attr/numberPickerUpButtonStyle" android:contentDescription="@string/number_picker_increment_button" /> <EditText android:id="@+id/numberpicker_input" <view class="android.widget.NumberPicker$CustomEditText" android:id="@+id/numberpicker_input" android:layout_width="fill_parent" android:layout_height="wrap_content" style="?android:attr/numberPickerInputTextStyle" /> Loading Loading
core/java/android/widget/NumberPicker.java +47 −16 Original line number Diff line number Diff line Loading @@ -48,6 +48,7 @@ import android.view.ViewConfiguration; import android.view.accessibility.AccessibilityEvent; import android.view.accessibility.AccessibilityManager; import android.view.animation.DecelerateInterpolator; import android.view.inputmethod.EditorInfo; import android.view.inputmethod.InputMethodManager; import com.android.internal.R; Loading Loading @@ -367,9 +368,9 @@ public class NumberPicker extends LinearLayout { private float mLastMotionEventY; /** * Flag if to begin edit on next up event. * Flag if to check for double tap and potentially start edit. */ private boolean mBeginEditOnUpEvent; private boolean mCheckBeginEditOnUpEvent; /** * Flag if to adjust the selector wheel on next up event. Loading Loading @@ -446,6 +447,11 @@ public class NumberPicker extends LinearLayout { */ private boolean mScrollWheelAndFadingEdgesInitialized; /** * The time of the last up event. */ private long mLastUpEventTimeMillis; /** * Interface to listen for changes of the current value. */ Loading Loading @@ -624,10 +630,6 @@ public class NumberPicker extends LinearLayout { public void onFocusChange(View v, boolean hasFocus) { if (hasFocus) { mInputText.selectAll(); InputMethodManager inputMethodManager = InputMethodManager.peekInstance(); if (inputMethodManager != null) { inputMethodManager.showSoftInput(mInputText, 0); } } else { mInputText.setSelection(0, 0); validateInputTextView(v); Loading @@ -639,6 +641,7 @@ public class NumberPicker extends LinearLayout { }); mInputText.setRawInputType(InputType.TYPE_CLASS_NUMBER); mInputText.setImeOptions(EditorInfo.IME_ACTION_DONE); // initialize constants mTouchSlop = ViewConfiguration.getTapTimeout(); Loading Loading @@ -773,7 +776,7 @@ public class NumberPicker extends LinearLayout { removeAllCallbacks(); mShowInputControlsAnimator.cancel(); mDimSelectorWheelAnimator.cancel(); mBeginEditOnUpEvent = false; mCheckBeginEditOnUpEvent = false; mAdjustScrollerOnUpEvent = true; if (mSelectorWheelState == SELECTOR_WHEEL_STATE_LARGE) { mSelectorWheelPaint.setAlpha(SELECTOR_WHEEL_BRIGHT_ALPHA); Loading @@ -784,7 +787,7 @@ public class NumberPicker extends LinearLayout { mAdjustScroller.forceFinished(true); onScrollStateChange(OnScrollListener.SCROLL_STATE_IDLE); } mBeginEditOnUpEvent = scrollersFinished; mCheckBeginEditOnUpEvent = scrollersFinished; mAdjustScrollerOnUpEvent = true; hideInputControls(); return true; Loading @@ -801,7 +804,7 @@ public class NumberPicker extends LinearLayout { float currentMoveY = event.getY(); int deltaDownY = (int) Math.abs(currentMoveY - mLastDownEventY); if (deltaDownY > mTouchSlop) { mBeginEditOnUpEvent = false; mCheckBeginEditOnUpEvent = false; onScrollStateChange(OnScrollListener.SCROLL_STATE_TOUCH_SCROLL); setSelectorWheelState(SELECTOR_WHEEL_STATE_LARGE); hideInputControls(); Loading @@ -825,11 +828,11 @@ public class NumberPicker extends LinearLayout { switch (action) { case MotionEvent.ACTION_MOVE: float currentMoveY = ev.getY(); if (mBeginEditOnUpEvent if (mCheckBeginEditOnUpEvent || mScrollState != OnScrollListener.SCROLL_STATE_TOUCH_SCROLL) { int deltaDownY = (int) Math.abs(currentMoveY - mLastDownEventY); if (deltaDownY > mTouchSlop) { mBeginEditOnUpEvent = false; mCheckBeginEditOnUpEvent = false; onScrollStateChange(OnScrollListener.SCROLL_STATE_TOUCH_SCROLL); } } Loading @@ -839,12 +842,21 @@ public class NumberPicker extends LinearLayout { mLastMotionEventY = currentMoveY; break; case MotionEvent.ACTION_UP: if (mBeginEditOnUpEvent) { if (mCheckBeginEditOnUpEvent) { mCheckBeginEditOnUpEvent = false; final long deltaTapTimeMillis = ev.getEventTime() - mLastUpEventTimeMillis; if (deltaTapTimeMillis < ViewConfiguration.getDoubleTapTimeout()) { setSelectorWheelState(SELECTOR_WHEEL_STATE_SMALL); showInputControls(mShowInputControlsAnimimationDuration); mInputText.requestFocus(); InputMethodManager inputMethodManager = InputMethodManager.peekInstance(); if (inputMethodManager != null) { inputMethodManager.showSoftInput(mInputText, 0); } mLastUpEventTimeMillis = ev.getEventTime(); return true; } } VelocityTracker velocityTracker = mVelocityTracker; velocityTracker.computeCurrentVelocity(1000, mMaximumFlingVelocity); int initialVelocity = (int) velocityTracker.getYVelocity(); Loading @@ -862,6 +874,7 @@ public class NumberPicker extends LinearLayout { } mVelocityTracker.recycle(); mVelocityTracker = null; mLastUpEventTimeMillis = ev.getEventTime(); break; } return true; Loading Loading @@ -1985,4 +1998,22 @@ public class NumberPicker extends LinearLayout { postDelayed(this, mLongPressUpdateInterval); } } /** * @hide */ public static class CustomEditText extends EditText { public CustomEditText(Context context, AttributeSet attrs) { super(context, attrs); } @Override public void onEditorAction(int actionCode) { super.onEditorAction(actionCode); if (actionCode == EditorInfo.IME_ACTION_DONE) { clearFocus(); } } } }
core/res/res/layout/number_picker.xml +2 −1 Original line number Diff line number Diff line Loading @@ -25,7 +25,8 @@ style="?android:attr/numberPickerUpButtonStyle" android:contentDescription="@string/number_picker_increment_button" /> <EditText android:id="@+id/numberpicker_input" <view class="android.widget.NumberPicker$CustomEditText" android:id="@+id/numberpicker_input" android:layout_width="fill_parent" android:layout_height="wrap_content" style="?android:attr/numberPickerInputTextStyle" /> Loading