BlackBerry Development Tips: 5 ways to alert users by flashing/shaking

Source: Internet
Author: User

The following code allows the phone to alert the user in five ways, not cool.

1.LED Flash Light Flashing

2.Vibrate Vibration

3.icon-read/unread program icon

4.Icon with number program icon with dynamic numbers

5.Title Bar with icon and number of mobile phone screen with dynamic digital icon

How to: Select each menu in the program for a different "reminder" demo. Note To see the program icon changes, do not press "back" to exit the program, so that the counter to zero, the correct way is to long press the "BlackBerry" key switch to the main screen.

LED Flash Light flashing effect as follows:

the effect of shaking , there is no screenshot.

to modify the program's icon, add an asterisk:

to modify the icon for the program, add the unread number you want to do:

and cooler, on the top of the phone, add new icons and numbers:

all the code is as follows:

------------------------------------

Package bsg.sample.ecl;

Import Net.rim.blackberry.api.messagelist.ApplicationIcon;
Import Net.rim.blackberry.api.messagelist.ApplicationIndicator;
Import Net.rim.blackberry.api.messagelist.ApplicationIndicatorRegistry;
Import Net.rim.device.api.system.Bitmap;
Import Net.rim.device.api.system.EncodedImage;
Import Net.rim.device.api.system.LED;
Import Net.rim.device.api.ui.Color;
Import Net.rim.device.api.ui.Font;
Import Net.rim.device.api.ui.Graphics;
Import Net.rim.device.api.ui.MenuItem;
Import Net.rim.device.api.ui.Ui;
Import net.rim.device.api.ui.UiApplication;
Import Net.rim.device.api.ui.XYRect;
Import Net.rim.device.api.ui.component.LabelField;
Import Net.rim.device.api.ui.component.Menu;
Import Net.rim.device.api.ui.component.RichTextField;
Import Net.rim.device.api.ui.container.MainScreen;

public class Eclscreen extends Mainscreen
{
int counter = 0;
Public Eclscreen ()
{
Settitle ("backend Alert");

For Titlebarmenu to change titlebar of homescreen
Applicationindicatorregistry indicatorregistry=applicationindicatorregistry.getinstance ();
Encodedimage Image=encodedimage.getencodedimageresource ("Icon/icon"). JPG ");
ApplicationIcon appicon=new ApplicationIcon (image);
Indicatorregistry.register (AppIcon, False, true);

}

/******************************************************************************************
* Makemenu (Menu,int)-Creates a custom Menu to add user define fields
******************************************************************************************/
protected void Makemenu (Menu menu, int instance)
{
MenuItem Flashmenu = new MenuItem ("Flash", 100, 10) {
public void Run () {
if (led.issupported LED. Led_type_status)) {
Led.setstate (LED. STATE_ON);
To close, call Led.setstate (LED. State_off);
Or
Led.setstate (LED. state_blinking);
Led.setconfiguration (1000, LED. BRIGHTNESS_100);
}
}
};
Menu.add (Flashmenu);

          menuitem stopflashmenu = new MenuItem ("Stop Flash", 100, 10) {
                public void Run () {
                   if ( Led.issupported (LED. Led_type_status)) {
                    led.setstate (LED. State_off);
                  }
               }
           };    
              menu.add (Stopflashmenu);

             MenuItem viberatemenu = new MenuItem (" Viberate 5 Seconds {
                 public void Run () {
                    //viberate for seconds
                  net.rim.device.api.system.alert.startvibrate (5*1000);
               }
           };    
              menu.add (Viberatemenu);

MenuItem Readmenu = new MenuItem ("Change icon to read", 100, 10) {
public void Run () {
Bitmap Icon=bitmap.getbitmapresource ("Icon/read.gif");
Net.rim.blackberry.api.homescreen.HomeScreen.updateIcon (icon);
}
};
Menu.add (Readmenu);

MenuItem Unreadmenu = new MenuItem ("Change icon to unread", 100, 10) {
public void Run () {
Bitmap Icon=bitmap.getbitmapresource ("Icon/unread.gif");
Net.rim.blackberry.api.homescreen.HomeScreen.updateIcon (icon);
}
};
Menu.add (Unreadmenu);

MenuItem Unreadnumbermenu = new MenuItem ("Change icon to unread number", 100, 10) {
public void Run () {
counter++;

Bitmap Icon=bitmap.getbitmapresource ("Icon/unread.gif");
icon = Getupdateiconbitmap (icon, counter);
Net.rim.blackberry.api.homescreen.HomeScreen.updateIcon (icon);
}
};
Menu.add (Unreadnumbermenu);

MenuItem Titlebarmenu = new MenuItem ("title bar with number", 100, 10) {
public void Run () {
counter++;

Applicationindicatorregistry indicatorregistry=applicationindicatorregistry.getinstance ();
Applicationindicator Indicator=indicatorregistry.getapplicationindicator ();
Indicator.setvalue (counter);

               Bitmap icon= Bitmap.getbitmapresource ("Icon/unread.gif");
               icon = Getupdateiconbitmap ( icon, counter);
               Net.rim.blackberry.api.homescreen.HomeScreen.updateIcon (icon);

                    }
            };     
              menu.add (titlebarmenu) ;
    }
    
  private Bitmap getupdateiconbitmap (Bitmap bmp, int count) {
     int width = bmp.getwidth ();
    int height = bmp.getheight ();
    Bitmap iconbmp = new Bitmap (width, height);
    Graphics g = new Graphics (iconbmp);
    xyrect rect = new Xyrect (0, 0, width, height);
    G.drawbitmap (rect, BMP, 0, 0);

G.setfont (G.getfont (). Derive (Font.Bold, UI.UNITS_PX,
Font.antialias_standard, Font.colored_outline_effect));

String Text = integer.tostring (count);
G.setcolor (color.red);
G.drawtext (text, 0, 0);

return iconbmp;
}
}

-----------------------------------------------

Package bsg.sample.ecl;

Import net.rim.device.api.ui.*;
Class Eclapplication extends UIApplication {

   /**************************************************************************************** * *
    * Main ()-controls the startup of the Application...thread would start in the background
  ;   *           and the GUI starts when user clicks from Main Menu
    ******************************************************************************** /   
    public static void Main (string[] args) {
         eclapplication Theapp = new Eclapplication ();
        Theapp.entereventdispatcher ();
   }

/******************************************************************************************
* Constructor:
* Builds the GUI and displays the fields
******************************************************************************************/
Public Eclapplication () {
Eclscreen screen = new Eclscreen ();
Pushscreen (screen);
}
}

The following 3 icon placed in the Src/icon directory, respectively, is icon. Jpg,read.gif,unread.gif

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.