2021-09-14 01:55 AM
I am trying to implement long press 3sec on an image which has touchlistener mixins enabled.
I am tried the button like tickEvent approch it doesn't work.
void Screen1View::handleTickEvent()
{
if(evaluate_long_press)
{
counter++;
if(counter == 1000)
{
evaluate_long_press = false;
counter = 0;
static_cast<FrontendApplication*>(Application::getInstance())->gotoScreen2ScreenCoverTransitionEast();
}
}
}
And I am also tried adding this line to the image class.
Application::getInstance()->registerTimerWidget(this);
I don't know how to implement this please someone help me to implement 3s long press on an image.
2021-09-14 06:08 AM
2021-09-14 07:27 AM
Maybe you try unregisterTimerWidget(this) before gotoScreen2ScreenCoverTransitionEast()?
2021-09-14 09:57 AM
Thank you that worked.
I am tried to unregister the timer
Application::getInstance()->unregisterTimerWidget(this);
static_cast<FrontendApplication*>(Application::getInstance())->gotoScreen2ScreenCoverTransitionEast();
But i have got error.
error: cannot convert 'Screen1View*' to 'const touchgfx::Drawable*'
167 | Application::getInstance()->unregisterTimerWidget(this);
It expects a drawable what is the correct way to call the function?
2021-09-14 06:58 PM
So, this error hint the problem there,registerTimerWidget or unregisterTimerWidget need the host object is drawable, and View is not obviously which derived from Screen.
You may write a class which derive from Container class, and add the Button to it, override the handleClickEvent function of that Container. At end, add the class you just write to View class.
Another better way is use ClickListener<Button>, with the button's handleClickEvent function do nothing, instead you write a callback in View class and install the callback to ClickListener<Button> object . so you can intercepted the Click Event in View and do what you want to do within the button object itself. so, the callback here is just what you writed, just rename it to longpressbuttonAction, and change this to address of button object or some thing else I have not noticed.
May not work, just a discuss or hint.