cancel
Showing results for 
Search instead for 
Did you mean: 

Does TouchGFX's clickevent support "long press" event?

PLin.4
Associate II
 
1 ACCEPTED SOLUTION

Accepted Solutions
Martin KJELDSEN
Chief III

​Oh, I misunderstood - I thought it was for a Click Event for a Button and not a view. The code should be the same - Except you don't have to register as a timer widget to receive ticks and keep track of time. You're already receiving ticks in your view through the handleTickEvent() method.

So, instead of just looking at evt.getType(), start a timer when you receive the first clickEvent (manage some state through the handleTickEvent() method. Once your time-threshold has been reached and the user has NOT released yet, then do whatever you want to do for your "long press". Does that make sense?

Some quick pesudo code to explain:

void Screen1View::handleClickEvent(ClickEvent& evt)
{
  if(evt.pressed)
  {
    evaluate_long_press = true;
  }
  else if(evt.released)
  {
    evaluate_long_press = false;
    counter = 0;
  }
}
 
void Screen1View::handleTickEvent()
{
  if(evaluate_long_press)
  {
    counter++;
    if(counter == 1000)
    {
      execute_long_press_action();
      evaluate_long_press = false;
    }
  }
}

View solution in original post

7 REPLIES 7
Martin KJELDSEN
Chief III

Hi,

Check the RepeatButton class, it's open souce to you. It already supports part of what you want, and you can modify it to your liking =) It counts ticks and determines when to fire (continuously). You just want to set the tick threshhold higher before activation (long press), and then never activate again.

I'm sure you'll be able to figure it out - otherwise let me know.

/Martin

PLin.4
Associate II

Hi Martin,

Thanks for your help. Do you mean setDelay() function? But I am not going to click a button. I want to click a whole screenview. The code like below:

void Screen1View::handleClickEvent(const ClickEvent& evt)

{

  if(evt.getType()==ClickEvent::RELEASED) // When "long press", the dialog show.

  {

    if(!modalDialog.isVisible())

    {

      clickX=evt.getX();

      clickY=evt.getY();

      modalDialog.setXY(clickX, clickY);

      modalDialog.setVisible(true);

      modalDialog.invalidate();

    }

    else

    {

      background.invalidate();

      modalDialog.setVisible(false);

    }

 }

  View::handleClickEvent(evt); 

}

Martin KJELDSEN
Chief III

​Oh, I misunderstood - I thought it was for a Click Event for a Button and not a view. The code should be the same - Except you don't have to register as a timer widget to receive ticks and keep track of time. You're already receiving ticks in your view through the handleTickEvent() method.

So, instead of just looking at evt.getType(), start a timer when you receive the first clickEvent (manage some state through the handleTickEvent() method. Once your time-threshold has been reached and the user has NOT released yet, then do whatever you want to do for your "long press". Does that make sense?

Some quick pesudo code to explain:

void Screen1View::handleClickEvent(ClickEvent& evt)
{
  if(evt.pressed)
  {
    evaluate_long_press = true;
  }
  else if(evt.released)
  {
    evaluate_long_press = false;
    counter = 0;
  }
}
 
void Screen1View::handleTickEvent()
{
  if(evaluate_long_press)
  {
    counter++;
    if(counter == 1000)
    {
      execute_long_press_action();
      evaluate_long_press = false;
    }
  }
}

PLin.4
Associate II

Hi Martin,

​

It's work, thanks a lot !

Martin KJELDSEN
Chief III

Nice! :) No problem.

/Martin

ZRego.1
Associate II

Hi Martin, I added

void Screen1View::handleClickEvent(ClickEvent& evt)

{

amount++; // just some code to be able to put breakpoint here

}

to Screen1View.cpp, but after inserting breakpoint into it that line, it does not stop there in debug mode, therefore it does not actually execute the contents of handleClickEvent().

Is there anything else that I need to include or declare in .cpp or .hpp. file? I have dificulties with implementing event handlers :\

Thanks

Freedom_Neo
Senior

Hi @Martin KJELDSEN​ 

How do we know which button was pressed? For example, When button2 pressed, get evaluate_long_press = true

void Screen1View::handleClickEvent(ClickEvent& evt)
{
  if(evt.pressed)
  {
    evaluate_long_press = true;
  }
  else if(evt.released)
  {
    evaluate_long_press = false;
    counter = 0;
  }
}