am a2b41b43: NumberPicker showing IME when its input field gains focus.
* commit 'a2b41b438d45570867e4682c0caaf93ace5e712e': NumberPicker showing IME when its input field gains focus.
This commit is contained in:
@@ -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;
|
||||
@@ -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.
|
||||
@@ -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.
|
||||
*/
|
||||
@@ -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);
|
||||
@@ -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();
|
||||
@@ -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);
|
||||
@@ -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;
|
||||
@@ -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();
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
@@ -839,11 +842,20 @@ public class NumberPicker extends LinearLayout {
|
||||
mLastMotionEventY = currentMoveY;
|
||||
break;
|
||||
case MotionEvent.ACTION_UP:
|
||||
if (mBeginEditOnUpEvent) {
|
||||
setSelectorWheelState(SELECTOR_WHEEL_STATE_SMALL);
|
||||
showInputControls(mShowInputControlsAnimimationDuration);
|
||||
mInputText.requestFocus();
|
||||
return true;
|
||||
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);
|
||||
@@ -862,6 +874,7 @@ public class NumberPicker extends LinearLayout {
|
||||
}
|
||||
mVelocityTracker.recycle();
|
||||
mVelocityTracker = null;
|
||||
mLastUpEventTimeMillis = ev.getEventTime();
|
||||
break;
|
||||
}
|
||||
return true;
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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" />
|
||||
|
||||
Reference in New Issue
Block a user