Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Native Development

Reply
Regular Contributor
bemipefe
Posts: 75
Registered: ‎06-14-2013
My Device: Z10
Accepted Solution

Detect finger up/down on the screen

Is it possible to detect a generic touch event on the screen regardless to what component is touched ?
I need to know when the finger is down the screen and up the screen to handle specific behaviour on the app.

Developer
simon_hain
Posts: 16,282
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport

Re: Detect finger up/down on the screen

you can handle touch events by using onTouch in a Container. if this container happens to span the full screen...
----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
Developer
bcs925
Posts: 262
Registered: ‎07-13-2012
My Device: PlayBook, DA B, DA C, LE Z10 #102, Q10, Z30

Re: Detect finger up/down on the screen

Yes you can find where the user has touched using event.windowX and event.windowY. Then What I have done is captured that location on an onTouch event.isDown. Then in event.isUp signal find the user's position again and calculate the difference to see if they went up/down on the screen.

 

An example of this (and I was calculating left/right movement so event.windowX only) is my custom tabs sample here: https://github.com/bcs925/CrackBerry/tree/master/CustomCascades and little write up on it here: http://crackberry.com/weekend-coder-mimic-cascades-layouts-custom-elements

---
Check out my BB10 Cascades Coding site: BBcascades.com & Cascades Blog: bbcascadescode.tumblr.com

My Built for BlackBerry app: The Dive Plan
Regular Contributor
bemipefe
Posts: 75
Registered: ‎06-14-2013
My Device: Z10

Re: Detect finger up/down on the screen

I know that it's possible to get the TouchEvent for a specific component and get all the related information.

 

However it's not important for me the point of the screen touched or what component have been touched. I only need to know when the finger is down or up of the screen. I need to set a timer when the finger is up and stop the timer when the finger is down regardless to position or component touched.

 

Actually I have a container setted as content of a ScrollView that is the container of all the objects on the page. I'll try to connect to the container signal touch(bb::cascades::TouchEvent *TEvent).

I thought It was possible to know in a more simple way if the finger is on the screen or not.

 

Thank you.

 

 

Developer
bcs925
Posts: 262
Registered: ‎07-13-2012
My Device: PlayBook, DA B, DA C, LE Z10 #102, Q10, Z30

Re: Detect finger up/down on the screen

How about something like:

onTouch {
if (event.isDown()){
//start timer
}
else if(event.isUp()){
//stop timer
}
}

And apply this to the root container of the UI
---
Check out my BB10 Cascades Coding site: BBcascades.com & Cascades Blog: bbcascadescode.tumblr.com

My Built for BlackBerry app: The Dive Plan
Regular Contributor
bemipefe
Posts: 75
Registered: ‎06-14-2013
My Device: Z10

Re: Detect finger up/down on the screen

You read my mind. :smileyhappy:

That's exactly what I've done.

 

I connected the signal touch(bb::cascades::TouchEvent *TEvent)

to this slot method:

void MyClass::receivedTouchEvent(bb::cascades::TouchEvent *TEvent)
{
    if(TEvent->isUp() == true)
    {
	Timer.start(2000);
    }

    if(TEvent->isDown() == true)
    {
	Timer.stop();
} if(TEvent->isCancel() == true) { Timer.start(2000); } }

 

Thank you again.