Blackberry 6: how to detect a long click on track pad? - blackberry

how do you detect a long click on a track pad please? I.e. on this thingy:
I can detect a short click with:
public boolean navigationClick(int status, int time) {
// XXX
return super.navigationClick(status, time);
}
And also I can detect a long click on a touch screen with:
protected boolean touchEvent(TouchEvent event) {
if (event.getEvent() == TouchEvent.GESTURE) {
TouchGesture gesture = event.getGesture();
if (gesture.getEvent() == TouchGesture.HOVER) {
// XXX
return true;
}
}
return super.touchEvent(event);
}
But I just can't find how to detect the long click on a track pad (I'd like to show a popup menu in that case)...
Thank you!
Alex

I would play with trackwheelClick(int status, int time) and trackwheelUnclick(int status, int time) to determine click length. You'll have to set flags here and there (probably in navigationClick() as well) to not fire normal click events prematurely. Beyond that, I don't know of a LONG_CLICK flag or anything.

Related

Getting exception when clicking the back button in blackberry

From my application, i am going to the Blackberry Native Message Application to send mail.
when i am clicking the back button, it is giving Runtime Exception.
My code is below:
public void fieldChanged(Field field, int context)
{
if( field == m_lfMailId)
{
displayEmail();
}
}
private void displayEmail()
{
Invoke.invokeApplication(Invoke.APP_TYPE_MESSAGES, new MessageArguments(MessageArguments.ARG_NEW,"feedback#merucabs.com","",""));
Address toList[] = new Address[1];
}
We usually set the simulator to ignore Error 104 - start fledge with the flag /ignore-error=104. This should not be showing on a real device, you can see some more information in this thread. If you click continue on the simulator's white screen, does it continue alright?
Add this code below to your screen and click on back button.
public boolean onClose()
{
return super.onClose();
}

Process.Start opens too many browsers in XNA game

I'm creating a game in XNA that runs on a PC.
On the splash screen, the user has three options. If they press "Enter" the game will begin, if they press "M" they'll go to the Help menu and if they press "W" I want that to take them to my website.
I'm using Process.Start to open the browser to my website.
The problem is that when I press "W", sometimes it will open 1 browser with the website. However, most of the time it will open anywhere from 3 - 7 browsers simultaneously.
Why is it opening multiple browsers simultaneously?
How do I make it open only 1 browser when "W" is pressed?
Here is my code. I haven't built my website yet, so I'm using yahoo.com as the destination:
private void UpdateSplashScreen()
{
KeyboardState keyState = Keyboard.GetState();
if (gameState == GameState.StartScreen)
{
if (keyState.IsKeyDown(Keys.Enter))
{
gameState = GameState.Level1;
explosionTime = 0.0f;
}
if (keyState.IsKeyDown(Keys.M))
{
gameState = GameState.HelpScreen;
}
if (keyState.IsKeyDown(Keys.W))
{
Process.Start("IExplore.exe", "www.yahoo.com");
}
}
Thanks,
Mike
A common way to handle this is to always track the keyboard state from the previous frame. If a key wasn't down on the previous frame, but is down this frame then you know it was just pressed. If the key was down on the previous frame then you know it's being held down.
// somewhere in your initialization code
KeyboardState keyState = Keyboard.GetState();
KeyboardState previousKeyState = keyState;
...
private void UpdateSplashScreen()
{
previousKeyState = keyState; // remember the state from the previous frame
keyState = Keyboard.GetState(); // get the current state
if (gameState == GameState.StartScreen)
{
if (keyState.IsKeyDown(Keys.Enter) && !previousKeyState.IsKeyDown(Keys.Enter))
{
gameState = GameState.Level1;
explosionTime = 0.0f;
}
if (keyState.IsKeyDown(Keys.M) && !previousKeyState.IsKeyDown(Keys.M))
{
gameState = GameState.HelpScreen;
}
if (keyState.IsKeyDown(Keys.W) && !previousKeyState.IsKeyDown(Keys.W))
{
Process.Start("IExplore.exe", "www.yahoo.com");
}
}
I usually create a KeyPressed function which cleans things up a bit.
bool KeyPressed(Keys key)
{
return keyState.IsKeyDown(key) && !previousKeyState.IsKeyDown(key);
}
The code you are using runs about 60 times a second; you may only press your key down for 100ms or so but in that time it checks to see if W is pressed down about 7 times. As such, it opens a large number of browser windows.
Try recording a timestamp (using DateTime.Now) of when you open the browser and then check that a certain time has elapsed (~2 secs?) before allowing another window to be opened. Or, create a boolean flag that is set false by opening the browser, so the browser can be opened only once.
Thanks guys, that's what the problem was.
Callum Rogers solution was the easiest:
I declared a boolean:
bool launchFlag = false;
Then checked it and set it to true after the website launched.
private void UpdateSplashScreen()
{
KeyboardState keyState = Keyboard.GetState();
if (gameState == GameState.StartScreen)
{
if (keyState.IsKeyDown(Keys.Enter))
{
gameState = GameState.Level1;
explosionTime = 0.0f;
}
if (keyState.IsKeyDown(Keys.M))
{
gameState = GameState.HelpScreen;
}
if (keyState.IsKeyDown(Keys.W))
{
if (launchFlag == false)
{
Process.Start("IExplore.exe", "www.yahoo.com");
launchFlag = true;
}
}
}
I held the W key down for 30 seconds and it launched just 1 browser!
Thanks,
Mike

Make a phone call from app when user presses the call button (override default behaviour)

I have a listfield in my app showing a list of contacts. I would like to call the selected contact when the user presses the green call button (instead of the default behaviour which launches the phone call log app).
This means there are 2 issues:
1) can I intercept the green call button?
2) how can I make the call from the app?
Before answering the question, it is assumed that you are keeping track of the currently selected item in the list, and you have a way of finding the related phone number.
1) Intercept the call button
You need to implement the keyDown(int, int) method in a Manager or Screen, catch the correct keycode, and return true:
protected boolean keyDown(int keycode, int time)
{
// check for the green phone button
if (keycode == 1114112)
{
/*
* Place your custom calling code here.
*/
return true; // indicates that this method has consumed the keypress
}
else
{
return super.keyDown(keycode, time);
}
}
(based on answer given at http://supportforums.blackberry.com/t5/Java-Development/Can-Over-ride-Call-Button-using-api-Issue-Shows-Context-Menu-on/m-p/252554/highlight/true#M41073)
2) Make a phone call
You need to Invoke() the phone app, passing it the phone number you wish to call:
PhoneArguments callArgs = new PhoneArguments(
PhoneArguments.ARG_CALL, "+27 83 111 1234");
Invoke.invokeApplication(Invoke.APP_TYPE_PHONE, callArgs);
So combining gives this code:
protected boolean keyDown(int keycode, int time)
{
// check for the green phone button
if (keycode == 1114112)
{
// get phone number - you must write this yourself
String number = selectedContact.getNumber(); // assume some method here depending on your solution
// make the call
PhoneArguments callArgs = new PhoneArguments(
PhoneArguments.ARG_CALL, number);
Invoke.invokeApplication(Invoke.APP_TYPE_PHONE, callArgs);
// indicate that the key has been processed
return true;
}
else
{
return super.keyDown(keycode, time);
}
}
From the Blackberry documentation:
net.rim.blackberry.api.phone
public final class Phone extends
Object
This class provides the following:
* Advanced utilities for interaction with the Phone
application. You can use the methods
in this class for finer manipulation
of the Phone application. For example,
injecting DTMF tones into active
calls.
* Access multiple lines on the device.
* Adding data to the incoming and active call screens, if supported.
Multi-line examples
Example A: Switching a line
Create a class that extends MultiLineListener.
public class MultiLineAction extends MultiLineListener
Register the class as a PhoneListener.
Phone.addPhoneListener(this);
Implement the MultiLineListener callbacks so that the app can be
notified of switching results.
public void setPreferredLineFailure(int lineId)
{
_screen.popupMessage("Switching failed");
}
public void setPreferredLineSuccess(int lineId)
{
_screen.popupMessage("Switching to " + Phone.getLineNumber(lineId) + "
completed" );
}
Invoke Phone.setPreferredLine().
Phone.setPreferredLine( Phone.getLineIds()[0]);
Example B: Initiate an outgoing call
Invoke Phone.initiateCall.
Phone.initiateCall(Phone.getLineIds()[0],
"5195550123");
Deregister the class from the phone listener before the application
is closed.
Phone.removePhoneListener(this);
Category:
Signed: This element is only accessible by signed applications. If
you intend to use this element, please
visit
http://www.blackberry.com/go/codesigning
to obtain a set of code signing keys.
Code signing is only required for
applications running on BlackBerry
smartphones; development on BlackBerry
Smartphone Simulators can occur
without code signing. Since:
BlackBerry API 4.0.0
http://www.blackberry.com/developers/docs/6.0.0api/

How can I use A dialog with No BUTTON and automatically Closes? On BlackBerry

I need to use a dialog. That appears 2-3 seconds and after closes automatically.
Which object should I use On BlackBerry?
you can also use
Status.show(String message)
Shows a status screen for two seconds.
or
Status.show(String message, Bitmap bitmap, int time)
Shows a status screen with specified
icon, for specified time.
Create a class that extends PopupScreen and use a TimerTask to automatically close it. So you would have code in your constructor that looks sort of like this:
Timer timer = new Timer();
timer.schedule(new TimerTask(){
public void run()
{
if(TestScreen.this.isDisplayed())
{
synchronized (Application.getEventLock())
{
TestScreen.this.close();
}
}
}
}, WAIT_TIME_IN_MILLISECONDS);

Navigate one screen to another screen based on time period in BlackBerry app

For my Blackberry application I am using a start up screen with progress bar. I am filling the progress bar using a timer and after the progress bar is complete, I need to navigate to another screen.
I am checking like this, where 'i' is time, increasing from 0 to 100.
timer.cancel();
if(i>=99)
UiApplication.getUiApplication().pushScreen(new TipCalculatorScreen());
This code is not working.
For progress bar I am using code like this:
private GaugeField percentGauge;
percentGauge = new GaugeField(null, 0, 100,50, GaugeField.PERCENT);
timer=new Timer();
timer.scheduleAtFixedRate(new TimerTask(){
int i=0;
public void run() {
percentGauge.setValue(i);
i++;
if(i>=99)
{
timer.cancel();
//for page navigating i am given like this here screen is not navigating getting error
UiApplication.getUiApplication().pushScreen(new nextscreen());
}
}
}, 100,100);
You need to make changes to the UI on the UI thread. The TimerTask is executing on its own thread. Instead of
UiApplication.getUiApplication().pushScreen(new nextscreen());
you should use
UiApplication.getUiApplication().invokeLater(new Runnable() {
public void run() {
UiApplication.getUiApplication()..pushScreen(new nextscreen());
}
});
The update to your gauge control probably needs the same treatment.

Resources