Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix the issue where the long-press trigger delay does not refresh properly. #6392

Open
wants to merge 1 commit into
base: v3_openjdk
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading