BlackBerry Forums Support Community               

Closed Thread
 
LinkBack Thread Tools
Old 08-30-2004, 04:24 AM   #1 (permalink)
Knows Where the Search Button Is
 
Join Date: Aug 2004
Posts: 29
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default TrackwheelClick

Please Login to Remove!

Do you know if it is possible to block multiple-click?

IE : when you click once on a button, if you click another time during the treatment of the action called by the first click, the action won't execute another time as you click but will wait for the first action to finish.

What I would like to do would be to block the click during the execution of the click-caused action.

Dunno if it's clear.

Thanks

Matt
Offline  
Old 08-31-2004, 09:05 AM   #2 (permalink)
Retired BBF Moderator
 
Mark Rejhon's Avatar
 
Join Date: Aug 2004
Location: Ottawa, Ontario, Canada
Model: Bold
Carrier: Rogers
Posts: 4,870
Post Thanks: 1
Thanked 0 Times in 0 Posts
Default

On most platforms in most programming whenever I only want to run an event once and ignore other events of the same kind, I generally use a static variable to set a flag. (or a global variable or a class member variable, if statics are not available or if I need to use the same variable to block all events while one of them is running). I mainly do C/C++, but it's extremely similiar in format in Java too. May need minor tweaks. The important thing here is static so you remember the last state of the variable between execution of events. But this could easily be a class member, as the class members are persistent (like static) between event calls. Or in the worst case scenario, a global variable can be used instead.

Code:
WhateverEventxxx40; xxx41;
xxx123;
   static boolean bEventRunning = FALSE; // Only initialized on first execution

   if xxx40;bEventRunningxxx41;
   xxx123;
      // The event is already running, exit immediately
      return;
   xxx125;
   bEventRunning = TRUE;

   // Do your deed --
   // Put your event code here.

   bEventRunning = FALSE;
xxx125;
__________________
Thanks,
Mark Rejhon
Author of XMPP extension XEP-0301:
www.xmpp.org/extensions/xep-0301.html - specification
www.realjabber.org - open source
Offline  
Old 09-02-2004, 11:21 AM   #3 (permalink)
Knows Where the Search Button Is
 
Join Date: Aug 2004
Posts: 29
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanx a lot for your answer but...but...but...
it does not work

and why does this thing not work?

I'll try to explain what i found with this little sequence of what happens :

First click --> start of event code -->second click ---> click event put on top of events stack ----->end of event code ---->start of SECOND event code

what i would like to do is to prevent the BB form receiveing external events (click, key or whatever) when code that is linked to an event is beeing runned
Offline  
Old 09-02-2004, 05:32 PM   #4 (permalink)
Retired BBF Moderator
 
Mark Rejhon's Avatar
 
Join Date: Aug 2004
Location: Ottawa, Ontario, Canada
Model: Bold
Carrier: Rogers
Posts: 4,870
Post Thanks: 1
Thanked 0 Times in 0 Posts
Default

Ahhh, the click events are being buffered up.

What you want to do is use a timer-value variable. Ignore all click events that occur within 0.5 seconds of the end of the first. You can tweak this down to something like 0.25 seconds, make sure it's at least about 3 or 4 times the minimum interval. This is probably not the only way, but the easiest way (especially if there's no way to clear the event queue).

There's probably a better way, but this would be a simple fix.

Code:
WhateverEventxxx40;xxx41;
xxx123;
   static integer lasttick;

   // Replace above line with something appropriate to your platform
   // GetSystemTickCount is a generic name for system milliseconds timer
   // You can use any system timer that has enough precision 
   // You could even change use a timer event driven semaphore instead

   if xxx40;xxx40;lasttick - GetSystemTickCountxxx40;xxx41;xxx41; < 300xxx41;
   xxx123;
      // Less than 300 milliseconds passed since ending of last event.
      return;
   xxx125;

   // **********
   // Do your deed; put your code here
   // **********

   // Finally, record the time of the ending of event
   lasttick = GetSystemTickCountxxx40;xxx41;;
xxx125;
Or, alternatively, if you have an idle loop, you could even clear an ignore flag (say, "ignoreevents" boolean variable) that is set during a call to an event. So that only the first event in a series of queued events, is executed, and future calls to same event are ignored until the event queue is empty (i.e. idle loop runs only after an event queue is empty, and the idle loop clears the ignoreevents flag). This method would be more efficient, but I don't know if there's an idle loop capability in a J2ME application.

Terminology may be slightly different for the J2ME platform, as I am not yet familiar with the limitations of mobile programming.
__________________
Thanks,
Mark Rejhon
Author of XMPP extension XEP-0301:
www.xmpp.org/extensions/xep-0301.html - specification
www.realjabber.org - open source
Offline  
Old 09-03-2004, 02:49 AM   #5 (permalink)
Knows Where the Search Button Is
 
Join Date: Aug 2004
Posts: 29
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

yes, i had thought about it but my problem is that with that solution, I have to guess (and I insist on this point) what time it will take my BB to execute the code that's inside my listener.

Moreover, it will be impossible to double click.

And we have to remember that the execution time depends on :
-blackberry speed (not so regular)
-if and while and for and ... loops...
-amount of data(it won't take the same time if I have to insert 1 record or 100 records in my database)
-quality of the GPRS network, of the server i'm trying to reach, and so on if my trackwheelclick calls a wireless synchonization function
-so many more parameters...

So, yes, that solution could help, and for that, I thank you, but I think that if you compare the time of development needed to make it work to a simple advice to the end user (something like : "Hey you, *****(replace with wathever you like :P), don't use brute force clicking on our application" )

But indeed, a real solution like idle loop if it works efficiently or something like clearing the event queue would rock
Offline  
Old 09-03-2004, 11:46 AM   #6 (permalink)
Retired BBF Moderator
 
Mark Rejhon's Avatar
 
Join Date: Aug 2004
Location: Ottawa, Ontario, Canada
Model: Bold
Carrier: Rogers
Posts: 4,870
Post Thanks: 1
Thanked 0 Times in 0 Posts
Default

Very true to all. Your post brings up excellent points about speed. But I had thought of it, and made a workaround:

Quote:
yes, i had thought about it but my problem is that with that solution, I have to guess (and I insist on this point) what time it will take my BB to execute the code that's inside my listener.
It doesn't matter -- because in my example I record the timer at the end of your listener. What matters is the time between the end (exiting) of event and the beginning (entering) of the next event.

This should theoretically eliminate 90-95% of the variability you are trying to say; unless I am missing something? But then again, maybe you had an excellent reason why this wouldn't work such as code that is concurrently executed outside your listener (multithreading) that keeps running even when your code exits;
__________________
Thanks,
Mark Rejhon
Author of XMPP extension XEP-0301:
www.xmpp.org/extensions/xep-0301.html - specification
www.realjabber.org - open source
Offline  
Old 09-03-2004, 11:47 AM   #7 (permalink)
Talking BlackBerry Encyclopedia
 
kirson's Avatar
 
Join Date: Aug 2004
Location: Chicago
Model: 9000
Carrier: ATT
Posts: 421
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

I had the same thought, Mark. I would suspect it will eliminate OVER 95% of the variability.
Offline  
Old 09-03-2004, 12:10 PM   #8 (permalink)
Retired BBF Moderator
 
Mark Rejhon's Avatar
 
Join Date: Aug 2004
Location: Ottawa, Ontario, Canada
Model: Bold
Carrier: Rogers
Posts: 4,870
Post Thanks: 1
Thanked 0 Times in 0 Posts
Default

It's definitely not the ideal way to go about things, but I've used similiar techniques to good success when there were no other ways to do it. One of the things that I've done is writing button anti-bounce code, which uses a timer as well.
__________________
Thanks,
Mark Rejhon
Author of XMPP extension XEP-0301:
www.xmpp.org/extensions/xep-0301.html - specification
www.realjabber.org - open source
Offline  
Old 09-03-2004, 12:16 PM   #9 (permalink)
Talking BlackBerry Encyclopedia
 
Join Date: Sep 2004
Model: 8700r
Carrier: Rogers
Posts: 221
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

Should be looking at a multi-threaded solution.
Offline  
Old 09-03-2004, 01:14 PM   #10 (permalink)
Retired BBF Moderator
 
Mark Rejhon's Avatar
 
Join Date: Aug 2004
Location: Ottawa, Ontario, Canada
Model: Bold
Carrier: Rogers
Posts: 4,870
Post Thanks: 1
Thanked 0 Times in 0 Posts
Default

eradis, that's another good solution. Basically the button click triggers the code in another thread, and the button click event exits immediately while the other thread continues to process. The other thread sets a flag at the beginning and clears the flag at the end of the processing. The original button click event can check this flag and ignore subsequent clicks if the other thread is still processing.

Another method of this multithreaded way if there's a continuous loop in the other thread monitoring a flag, is that the button click event sets the flag, and the other thread only clears the flag when all the processing is done and that new button clicks are okay.

Some people need to avoid multithreaded programming for certain reasons though, or when it's too difficult (i.e. potentially makes software unstable). In these cases, it's better to err on the side of stability.
__________________
Thanks,
Mark Rejhon
Author of XMPP extension XEP-0301:
www.xmpp.org/extensions/xep-0301.html - specification
www.realjabber.org - open source
Offline  
Old 09-23-2004, 09:24 AM   #11 (permalink)
Knows Where the Search Button Is
 
Join Date: Aug 2004
Posts: 29
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

I think i m going to try to use the time parameter from trackwheelclick method

it should work...
i'll keep you informed
Offline  
Old 09-23-2004, 10:41 AM   #12 (permalink)
Knows Where the Search Button Is
 
Join Date: Aug 2004
Posts: 29
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

doooooooooooooooooooooooooooooone

okay boys and girls, here is my solution

int endExec = 0;
long resetDate = 0;
boolean firstExecution = true;

public boolean trackwheelClick(int status, int time) {
if(firstExecution){
resetDate = System.currentTimeMillis() - time;
firstExecution = false;
}
if(time>endExec){
...
//execute an action here
...
endExec= (int)(System.currentTimeMillis() - resetDate);
}
return true;
}

it seems to be working
BUT (because there is always stg to be improved)
it would be more beautiful(with butterflies and little flowers) if I could get the resetDate directly form the device itself.
Offline  
Closed Thread


Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On





Copyright 2004-2014 BlackBerryForums.com.
The names RIM and BlackBerry are registered Trademarks of BlackBerry Inc.