I am creating a custom component in HarmonyOS using Java SDK, Where I have to perform some task on double-tap. But I am not able to detect double-tap event.
In Android, with the help of GestureDetector class we can detect double-tap event as follow:
GestureDetector gestureDetector = new GestureDetector(context, new GestureDetector.SimpleOnGestureListener(){
@Override
public boolean onSingleTapConfirmed(MotionEvent e) {
return super.onSingleTapConfirmed(e);
}
@Override
public boolean onDoubleTap(MotionEvent e) {
return super.onDoubleTap(e);
}
});
In HMOS, I have tried to detect double-tap using Component.TouchEventListener as follow:
Component.TouchEventListener touchEventListener = new TouchEventListener() {
@Override
public boolean onTouchEvent(Component component, TouchEvent touchEvent) {
if(touchEvent.getPointerCount() == 1) {
LogUtil.info(TAG, "single click detected");
}
if(touchEvent.getPointerCount() == 2) {
LogUtil.info(TAG, "double click detected");
}
return false;
}
};
but, It has not detected double-tap. On double-tap also it has printed single click detected.
try registering Component.DoubleClickedListener and you will be able to detect Double Tap in Custom Component, sample Usage
customComponent.setDoubleClickedListener(new Component.DoubleClickedListener() {
@Override
public void onDoubleClick(Component component) {
LogUtil.info(TAG, "double click detected");
}
});
Supports component double-clicking in SDK API Version 5 or later.
As@Gowtham GS mentioned, sample usage is as follows:
customComponent.setDoubleClickedListener(new Component.DoubleClickedListener() {
@Override
public void onDoubleClick(Component component) {
LogUtil.info(TAG, "double click detected");
}
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With