Skip to content

Commit f657f6e

Browse files
committed
fix(android): 修复气泡长按手势计时及取消处理逻辑
在 FloatingTriggerService 而非 MicBubbleView 中跟踪手势开始时间,以确保长按检测的准确性。此前,MicBubbleView 中的 downAt 时间戳可能会过期,导致 ACTION_UP 时协调器行为异常。同时增加了适当的 ACTION_CANCEL 处理,用于重置手势状态,防止过时的计时数据影响后续手势。
1 parent 80ceb65 commit f657f6e

1 file changed

Lines changed: 9 additions & 8 deletions

File tree

openless-android/src/com/openless/android/FloatingTriggerService.java

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@ public final class FloatingTriggerService extends Service implements AndroidDict
5050
private final Handler main = new Handler(Looper.getMainLooper());
5151
private int stateGeneration;
5252
private boolean dragging;
53+
/** 0 = no active bubble press; set on ACTION_DOWN, cleared on ACTION_UP/CANCEL. */
54+
private long bubbleGestureDownAtMs;
5355
private float downX;
5456
private float downY;
5557
private int startX;
@@ -212,6 +214,7 @@ private boolean onBubbleTouch(View view, MotionEvent event) {
212214
case MotionEvent.ACTION_DOWN:
213215
downX = event.getRawX(); downY = event.getRawY();
214216
startX = params.x; startY = params.y; dragging = false;
217+
bubbleGestureDownAtMs = System.currentTimeMillis();
215218
return true;
216219
case MotionEvent.ACTION_MOVE:
217220
float dx = event.getRawX() - downX;
@@ -225,10 +228,15 @@ private boolean onBubbleTouch(View view, MotionEvent event) {
225228
return true;
226229
case MotionEvent.ACTION_UP:
227230
if (!dragging) {
228-
if (System.currentTimeMillis() - bubble.downAt >= LONG_PRESS_CANCEL_MS) {
231+
if (System.currentTimeMillis() - bubbleGestureDownAtMs >= LONG_PRESS_CANCEL_MS) {
229232
coordinator.cancel();
230233
} else { coordinator.toggle(); }
231234
}
235+
bubbleGestureDownAtMs = 0;
236+
return true;
237+
case MotionEvent.ACTION_CANCEL:
238+
bubbleGestureDownAtMs = 0;
239+
dragging = false;
232240
return true;
233241
default: return true;
234242
}
@@ -286,7 +294,6 @@ private static class MicBubbleView extends View {
286294
private String statusText;
287295
private boolean showDot = true;
288296
private boolean dotOn = true;
289-
long downAt;
290297

291298
MicBubbleView(android.content.Context context) {
292299
super(context);
@@ -378,12 +385,6 @@ private void drawMicIcon(Canvas canvas, float cx, float cy, float r) {
378385
}
379386
}
380387

381-
@Override
382-
public boolean onTouchEvent(MotionEvent event) {
383-
if (event.getAction() == MotionEvent.ACTION_DOWN) downAt = System.currentTimeMillis();
384-
return super.onTouchEvent(event);
385-
}
386-
387388
private int dp(int value) { return (int) (value * getResources().getDisplayMetrics().density + 0.5f); }
388389
}
389390
}

0 commit comments

Comments
 (0)