views:

237

answers:

1

I have a simple blackberry app that changes the LED settings (color, blinking, pattern). My current testing environment consists of a live Blackberry Bold (9000), and I have been running into an problem which I am not sure how to proceed.

Assume that my current Blackberry setup (LED wise) is to not flash unless there is a missed call, new message (of all varieties). The program I wrote will change the LED, which is fine, but the problem lies in closing the program. Closing the program causes a save/discard/cancel dialog to appear. For now, that isn't a problem since I'm only testing the application, the current problem is that even if you Discard the changes made, the light will continue flashing. I demoed the program to a friend and it kept flashing, I also noticed that when I received a new message and the light changes to red and kept flashing (instead of being Green, the last color i showed in the demo).

How do I reset the LED to it's previous state when exiting the program? Should or can I copy the existing settings (like flashing or not flashing when network is available) then on exit reset to saved defaults? Or is there a better way of resetting LED?

Code is pretty simple; view:

public HomeScreen(boolean error) {
 redLED = new CustomButtonField("RED", Color.RED, Color.BLACK, Color.BLACK,
   Color.WHITE, Field.FOCUSABLE);
 add(redLED);
 blueLED = new CustomButtonField("BLUE", Color.RED, Color.BLACK, Color.BLACK,
   Color.WHITE, Field.FOCUSABLE);
 add(blueLED);
 whiteLED = new CustomButtonField("WHITE", Color.RED, Color.BLACK, Color.BLACK,
   Color.WHITE, Field.FOCUSABLE);
 add(whiteLED);
 greenLED = new CustomButtonField("GREEN", Color.RED, Color.BLACK, Color.BLACK,
   Color.WHITE, Field.FOCUSABLE);
 add(greenLED);
 redLED.setChangeListener(this);
 blueLED.setChangeListener(this);
 whiteLED.setChangeListener(this);
 greenLED.setChangeListener(this);
}

public HomeScreen(long arg0)
{
 super(arg0);
 // TODO Auto-generated constructor stub
}

public void fieldChanged(Field field, int context)
{   

  LED.setState(LED.LED_TYPE_STATUS, LED.STATE_BLINKING);

  if(field == redLED) {
   LED.setColorConfiguration(500,5000,Color.RED);
  }
  if(field == blueLED) {
   LED.setColorConfiguration(500,5000,Color.BLUE);
  }
  if(field == whiteLED) {
   LED.setColorConfiguration(500,5000,Color.WHITE);
  }
  if(field == greenLED) {
   LED.setColorConfiguration(500,5000,Color.GREEN);
  }

}
+1  A: 

To get rid of the save/discard/cancel dialog when you exit the screen, you need to override the onSavePrompt() method on the Screen. You can also put some code in here that you'd like to execute when the user is leaving the screen. For example, you might want to try:

protected boolean onSavePrompt() {
    LED.setState(LED.STATE_OFF);
    return true;
}
Marc Novakowski
Doing this solves the problem of the save dialog and does turn off the LED, but is it possible to reset the LED say, flash when message arrives or flash when i have coverage? Well is it possible to do that.
Matt R
If you want your program to continue running in the background after all of the screens are popped off the stack, you'll need to call something like "Application.getApplication().requestBackground()" in the onClose() method of your screen.
Marc Novakowski
Will opening the program again from the bb menu create a new instance of the application or will it just bring the app to the foreground with a new screen on the stack?
Matt R
It will just bring the app to the foreground - you'll want to override the activate() method (make sure you still call its super) and push your desired screen onto the stack.
Marc Novakowski