Skip to content

Commit 2a1ea01

Browse files
committed
add thumbstick support
1 parent 1dcf1c1 commit 2a1ea01

File tree

2 files changed

+149
-40
lines changed

2 files changed

+149
-40
lines changed

android/src/main/java/com/henninghall/date_picker/generated/NumberPicker.java

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1050,6 +1050,58 @@ public boolean dispatchTrackballEvent(MotionEvent event) {
10501050
return super.dispatchTrackballEvent(event);
10511051
}
10521052

1053+
/**
1054+
* Timestamp of last scroll action, used for throttling continuous input.
1055+
*/
1056+
private long mLastScrollTime = 0;
1057+
1058+
/**
1059+
* Minimum interval between scroll actions in milliseconds.
1060+
*/
1061+
private static final long SCROLL_INTERVAL_MS = 150;
1062+
1063+
/**
1064+
* Handle generic motion events for scroll support.
1065+
*/
1066+
@Override
1067+
public boolean onGenericMotionEvent(MotionEvent event) {
1068+
if (!mHasSelectorWheel || !isEnabled()) {
1069+
return super.onGenericMotionEvent(event);
1070+
}
1071+
1072+
final int action = event.getActionMasked();
1073+
final int source = event.getSource();
1074+
1075+
// Handle mouse/trackpad scroll wheel (ACTION_SCROLL with AXIS_VSCROLL)
1076+
if (action == MotionEvent.ACTION_SCROLL) {
1077+
float vscroll = event.getAxisValue(MotionEvent.AXIS_VSCROLL);
1078+
if (vscroll != 0) {
1079+
// Throttle scroll input to prevent rapid value changes
1080+
long currentTime = System.currentTimeMillis();
1081+
if (currentTime - mLastScrollTime < SCROLL_INTERVAL_MS) {
1082+
return true; // Consume event but don't act on it yet
1083+
}
1084+
1085+
mLastScrollTime = currentTime;
1086+
// Determine scroll direction: positive = scroll up (decrement), negative = scroll down (increment)
1087+
if (vscroll < 0) {
1088+
// Scroll down - increment value
1089+
if (mWrapSelectorWheel || getValue() < getMaxValue()) {
1090+
changeValueByOne(true);
1091+
}
1092+
} else {
1093+
// Scroll up - decrement value
1094+
if (mWrapSelectorWheel || getValue() > getMinValue()) {
1095+
changeValueByOne(false);
1096+
}
1097+
}
1098+
return true;
1099+
}
1100+
}
1101+
1102+
return super.onGenericMotionEvent(event);
1103+
}
1104+
10531105
@Override
10541106
protected boolean dispatchHoverEvent(MotionEvent event) {
10551107
if (!mHasSelectorWheel) {

0 commit comments

Comments
 (0)