cancel
Showing results for 
Search instead for 
Did you mean: 

Touchgfx mixins touchlistener detect long-press on an image.

As.3
Associate II

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.

4 REPLIES 4
Romain DIELEMAN
ST Employee

Hi,

Alexandre shared in the forum an example with long press on a box. I adapted it to work on an image 👍

/Romain

Xzhiy.1
Associate II

Maybe you try unregisterTimerWidget(this) before gotoScreen2ScreenCoverTransitionEast()?

As.3
Associate II

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?

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.