Skip to content

Commit

Permalink
Fix the issue where the long-press trigger delay does not refresh pro…
Browse files Browse the repository at this point in the history
…perly.
  • Loading branch information
MovTery committed Dec 17, 2024
1 parent 89f0254 commit ea85559
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public class LeftClickGesture extends ValidatorGesture {
private boolean mMouseActivated;

public LeftClickGesture(Handler handler) {
super(handler, LauncherPreferences.PREF_LONGPRESS_TRIGGER);
super(handler);
}

public final void inputEvent() {
Expand All @@ -27,6 +27,11 @@ public final void inputEvent() {
}
}

@Override
protected int getDelayValue() {
return LauncherPreferences.PREF_LONGPRESS_TRIGGER;
}

@Override
public boolean checkAndTrigger() {
boolean fingerStill = LeftClickGesture.isFingerStill(mGestureStartX, mGestureStartY, mGestureEndX, mGestureEndY, FINGER_STILL_THRESHOLD);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@

import org.lwjgl.glfw.CallbackBridge;

public class RightClickGesture extends ValidatorGesture{
public class RightClickGesture extends ValidatorGesture {
private boolean mGestureEnabled = true;
private boolean mGestureValid = true;
private float mGestureStartX, mGestureStartY, mGestureEndX, mGestureEndY;
public RightClickGesture(Handler mHandler) {
super(mHandler, 150);
super(mHandler);
}

public final void inputEvent() {
Expand All @@ -29,6 +29,11 @@ public void setMotion(float deltaX, float deltaY) {
mGestureEndY += deltaY;
}

@Override
protected int getDelayValue() {
return 150;
}

@Override
public boolean checkAndTrigger() {
// If the validate() method was called, it means that the user held on for too long. The cancellation should be ignored.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,13 @@
public abstract class ValidatorGesture implements Runnable{
private final Handler mHandler;
private boolean mGestureActive;
private final int mRequiredDuration;

/**
* @param mHandler the Handler that will be used for calling back the checkAndTrigger() method.
* This Handler should run on the same thread as the callee of submit()/cancel()
* @param mRequiredDuration the duration after which the class will call checkAndTrigger().
*/
public ValidatorGesture(Handler mHandler, int mRequiredDuration) {
public ValidatorGesture(Handler mHandler) {
this.mHandler = mHandler;
this.mRequiredDuration = mRequiredDuration;
}

/**
Expand All @@ -28,7 +25,7 @@ public ValidatorGesture(Handler mHandler, int mRequiredDuration) {
*/
public final boolean submit() {
if(mGestureActive) return false;
mHandler.postDelayed(this, mRequiredDuration);
mHandler.postDelayed(this, getDelayValue());
mGestureActive = true;
return true;
}
Expand All @@ -54,6 +51,11 @@ public final void run() {
onGestureCancelled(false);
}

/**
* @return the duration after which the class will call checkAndTrigger().
*/
protected abstract int getDelayValue();

/**
* This method will be called after mRequiredDuration milliseconds, if the gesture was not cancelled.
* @return false if you want to mark this gesture as "inactive"
Expand Down

0 comments on commit ea85559

Please sign in to comment.