Friday, July 1, 2011

Small Roads in Eclipse

Hello All,
When i was wondering for some easy steps or shorcuts in eclipse i searched and got many but i wanted to keep them at one place.So here i am with small collection.
May be it helps somebody!!!


1) Ctrl + Space – Intelli-sense or auto completion 

2) How do I get line numbers?
Go to Window -> Preferences -> General -> Editors -> All Text Editors and check Show line numbers.




NOTE: You can also change the color appearance.

3) How do I get soft tabs?
        To get soft tabs (tabs replaced by spaces) as you type, go to Window -> Preferences -> Java -> Code style-> Formatter and select the profile Java Conventions [built-in]. This should be set correctly to  give soft tabs.

    You can create your own profile by clicking Show...; for soft tabs, go to Indentation un-check Use tab   characters. After making your changes, you will be prompted for a name for your new profile.





4)      Global Search - One of my favorites is Ctrl + Shift + G, which searches the workspace for   references to the selected method or variable.



5)       A complete list of shortcuts can be seen with Alt + Shift + L. Going through that list is sure to teach you a few new tricks about Eclipse.





 6) Ctrl + O - Doing it once gives you the ability to quick search/jump to methods in the class you have already open.Doing it twice, gives you the same ability but then for all methods in the current class plus super classes. Very handy!

7)  Ctrl + F6 - toggle between tabbed editors.




8) Ctrl + E - List of open editors.

9)  Ctrl + F3 and Ctrl + O also show the list of the functions in a class.




10)  Ctrl + T - type hierarchy 




11)      Ctrl + Shift + R - will open a dialog for you where you can type the name of method which u wish to open.





12)      Add getter and setters for particular field:
                       write String temp and press (Ctrl + 1) after selecting the field


    you will get an option to add getters and setters for that field.





13)      To quickly do a rename that doesn't require full analysis of dependencies in other files, write String temp and press (Ctrl + 1) after selecting the field you will get an option to rename.





14)  Edit -> Quick fix will produce effect of Ctrl + 1

15)      Ctrl + L - to go to specific line number.





16)      To find a matching bracket select an opening or closing bracket and pressCtrl + Shift + P or select Navigate > Go To > Matching Bracket. You can also double click before an opening or after a closing bracket - this selects the text between the two brackets.

17) To create a delegate method for a field select the field's declaration and invoke Source > Generate Delegate Methods. This adds the selected methods to the type that contains a forward call to delegated methods. This is an example of a delegate method.


   

18)      F4 To display hierarchy view of current class.





19) Ctrl + Shift + O - To manage imports automatically.

20) Ctrl + 3 –  Check this out.





21) Ctrl + Alt + H - Open Call Hierarchy.





22) Ctrl + Mouse Click - takes you to the declaration or definition

23) Ctrl + Q - Go to the last edit location.

24) Alt + ← and Alt + → - Hop back and forth through the files you have visited.

25)  ALT + Shift + C  - To change method signature.    






Wednesday, April 27, 2011

Screen Resolutions of Blackberry Devices



BlackBerry 7100                   240 x 260
BlackBerry 7100i                  240 x 260
BlackBerry 7100g                 240 x 260
BlackBerry 7100r                  240 x 260
BlackBerry 7100v                 240 x 260
BlackBerry 7100x                 240 x 260
BlackBerry 7100t                  324 x 352
BlackBerry 7105t                  240 x 260
BlackBerry 7130                   240 x 260
BlackBerry 7130c                 240 x 260
BlackBerry 7130e                 240 x 260
BlackBerry 7130g                 240 x 260
BlackBerry 7130v                 240 x 260
BlackBerry 7210                   240 x 160
BlackBerry 7220                   240 x 160
BlackBerry 7230                   240 x 160
BlackBerry 7250                   240 x 160
BlackBerry 7270                   240 x 160
BlackBerry 7280                   240 x 160
BlackBerry 7290                   240 x 160
BlackBerry 7510                   240 x 160
BlackBerry 7520                   240 x 160
BlackBerry 7730                   240 x 240
BlackBerry 7750                   240 x 240
BlackBerry 7780                   240 x 240
BlackBerry 8100                   240 x 260
BlackBerry 8120                   240 x 260
BlackBerry 8130                   240 x 260
BlackBerry 8220                   240 x 320
BlackBerry 8300                   320 x 240
BlackBerry 8310                   320 x 240
Blackberry 8320                   320 x 240
BlackBerry 8330                   320 x 240
BlackBerry 8350i                  320 x 240
BlackBerry 8520                   320 x 240
BlackBerry 8530                   320 x 240
BlackBerry 857                     160 x 160
BlackBerry 8700 (c/r/f/g)       320 x 240
BlackBerry 8703e                  320 x 240
BlackBerry 8707 (g/h/v)         320 x 240
BlackBerry 8800                    320 x 240
BlackBerry 8820                    320 x 240
BlackBerry 8830                    320 x 240
BlackBerry 8900                    480 x 360
BlackBerry 9000                    480 x 320
BlackBerry 9105                    360 x 400
BlackBerry 9501                    32 x 65
BlackBerry 9500                    360 x 480
BlackBerry 9520                    360 x 480
BlackBerry 9530                    360 x 480
BlackBerry 9550                    360 x 480
BlackBerry 957                     160 x 160
BlackBerry 9630                   480 x 360
BlackBerry 9700                   480 x 360
BlackBerry 9800                   360X480

Sunday, April 24, 2011

Configure Eclipse for Blackberry

System Requirements:


1) Monitor Resolution - 1024X768 or higher.

2) Intel Pentium 4 Processor

3) Windows Vista/XP/7.

4) JDK Versio 5 or 6;

5) BB Eclipse Pluggin

6) BB e_JDE's


Things To Download with links:


1) Download JDK

http://java.sun.com/javase/downloads//index.jsp


2) Download Eclipse IDE (Ganymede/Helios etc.. higher versions)

http://www.eclipse.org/downloads/


3) To get BB tools go to:

http://na.blackberry.com/eng/developers/resources/devtools.jsp



Installation:


1) Install JDK

2) Install Eclipse (Just unzip the folder).

3) Now install pluggins.


Setting Environment Variables:


Path variables tell the JVM where to look for user defined classes and packages when running java programs.


1) Right Clivk on MyComputer

2) Go to properties

3) Advanced System Properties.

4) Environment Variables.


1) Create Variable : JAVA_HOME

PATH : D:\SUN\SDK\JDK


2) Now just append %JAVA_HOME%\jre\bin; to the end of your CLASSPATH and PATH variable


3) To verify that you have set environment variable properly :

type java-version in windows command prompt.

If correctly installed it will show you all versions installed else error message.

Thursday, April 7, 2011

Send SMS in Blackberry using J2ME

Hello,

When i had to implement this feature then i surfed a lot.I was new to Blackberry and J2ME.
I saw several posts but non was able to help me truely.

I gathered up the code and made it to work.
I had to send the message to the person whose call i missed up or to person whose incomming call is explicitly disconnected by me when i was busy.

The moment i disconnect the call, immediately a message is send to thta number.
That too should be done in a separate thread to avoid hang ups.

Hope it help someone. :)


Send SMS from Blackberry Application:

import java.io.IOException;
import javax.microedition.io.Connector;
import javax.microedition.io.Datagram;
import javax.microedition.io.DatagramConnection;
import javax.wireless.messaging.MessageConnection;
import javax.wireless.messaging.TextMessage;

import net.rim.device.api.system.RadioInfo;
public class SendSMS extends Thread {
    private String to;
    private String msg;

    public SendSMS(String to, String msg) {
        this.to = to;
        this.msg = msg;

    }
    public void run() {
        if (RadioInfo.getNetworkType() == RadioInfo.NETWORK_CDMA) {
            DatagramConnection dc = null;
            try {
                dc = (DatagramConnection) Connector.open("sms://" + to);
                byte[] data = msg.getBytes();
                Datagram dg = dc.newDatagram(dc.getMaximumLength());
                dg.setData(data, 0, data.length);
                dc.send(dg);
            } catch (IOException e) {
                e.printStackTrace();
            } finally {
                try {
                    dc.close();
                } catch (IOException e) {
                    System.out.println(e.getMessage());
                }
            }

        } else {
            MessageConnection mc = null;
            try {
                mc = (MessageConnection) Connector
                        .open("sms://" + to);
                TextMessage m = (TextMessage) mc
                        .newMessage(MessageConnection.TEXT_MESSAGE);
                m.setPayloadText(msg);
                mc.send(m);
            } catch (IOException e1) {
                e1.printStackTrace();
            } finally {
                try {
                    mc.close();
                } catch (IOException e) {
                    System.out.println(e.getMessage());

                }
            }
        }
    }

}

Send msg when call gets disconnected:
public void callDisconnected(int callId)
{
        final PhoneCall call = Phone.getCall(callId);
        final String number = call.getDisplayPhoneNumber();
        SendSMS sendSMS = new SendSMS(number, "message");
        sendSMS.start();
        super.callDisconnected(callId);
    }
You can try other methods also depending upon the requirements.


Links:
http://stackoverflow.com/questions/3051301/send-sms-from-background-thread-in-blackberry-using-j2me

Tuesday, April 5, 2011

Sending Email with Attachment in Blackberry using J2ME


Now days in almost every application user has to send email and share the contents such as score of any game etc..
Using the below code in any blackberry application one can easily do that.


Address[] address = new Address[1];
try

  {
    address[0] = new Address(email,name);
  }

   catch (AddressException e1)
    {
      e1.printStackTrace();
    }
 byte[] data = readFile();
 Multipart multipart = new Multipart();
 SupportedAttachmentPart attach ;

 attach = new SupportedAttachmentPart(multipart,"application/x-example", "test.txt", data);
 multipart.addBodyPart(attach);
 Message msg = new Message();

// add the recipient list to the message
 try

  {
     msg.addRecipients(Message.RecipientType.TO, address);

    // set a subject for the message
   msg.setSubject("Mail from mobile");
   msg.setContent(multipart);
  }

  catch (MessagingException e1)
   {
      e1.printStackTrace();
   }


try

 {
     Transport.send(msg);
 }

 catch (MessagingException e) {
    System.out.println(e.getMessage());
  }
 private static byte[] readFile() {
 String fName ="
file:///store/home/user/test.txt";
 byte[] data = null;
 FileConnection fconn = null;
 DataInputStream is = null;
 try

  {
      fconn = (FileConnection) Connector.open(fName, Connector.READ_WRITE);
      is = fconn.openDataInputStream();
     data = IOUtilities.streamToBytes(is);
   }

  catch (IOException e)
   {
      System.out.println(e.getMessage());
   }

  finally
  {
     try

     {
        if (null != is)
        is.close();
        if (null != fconn)
       fconn.close();
     }

   catch (IOException e)
     {
             System.out.println(e.getMessage());
      }
  }
 return data;
 }


Have a look at this sample image:

Custom Popups in Blackberry



Procedure:

1) Create a class that extends Popup .
2) In this class use your own manager
a) take one vertical field manager
b) add some text using label field and also a button inside this vertica field manager
c) And add vertical field manager in your screen


PopupScreen popup = new PopupScreen(new VerticalFieldManager());
popup.add(new LabelField("Hello!"));
popup.add(new ButtonField("OK"));



Create Border less Popup screen
PopupScreen popup = new PopupScreen(new VerticalFieldManager());
popup.add(new LabelField("Hello!"));
Border border = BorderFactory.createSimpleBorder(new XYEdges(), Border.STYLE_TRANSPARENT);
popup.setBorder(border);



Push popup screen:

UiApplication.getUiApplication().pushScreen(new MyPopup());

Closing a popup scren when uer clicks on Escape Key:
Need to implement Keychar method

popupscreen1=new PopupScreen(myverticalfieldmanager)
   {
        protected boolean keyChar(char c, int status, int time)
          {
               if (c == Characters.ESCAPE)
              close();
              return super.keyChar(c, status, time);
         }
   };



Have a look at this:

Monday, January 17, 2011

Using image for a TextEditField in Blackberry

Hello all,
 
When i started coding for basic edit field in blackberry i found 
that it is transparent but the look was not exactly that i wanted. 
I wanted a look of TextEditField that appears in websites 
so i tried the below mentioned code. 
May be it can help to any blackberry developer.
 
Here is the code:
 
LabelField label = new LabelField("name");

textbox=new EditField("","",500, 
 EditField.NO_NEWLINE|Field.FOCUSABLE) 
 {
  protected void paint(Graphics g)
   {
     g.setColor(Color.MAROON);
     super.paint(g);
   }
  protected boolean keyChar(char key, int status, int time) 
   {
     return super.keyChar(key, status, time);
   }
 };


 manager = new VerticalFieldManager(HORIZONTAL_SCROLL )
  {
    protected void paint(Graphics g) 
     {
      int x = this.getHorizontalScroll();
      if(textbox.getText().equals(""))
      {
        g.drawBitmap( x, 0, textbox_img.getWidth(), 
           textbox_img.getHeight(),textbox_img, 0, 0 );
      }
     super.paint(g);
   }
}
manager.add(textbox);
 
add(label);
add(manager); 
 
now add this manager in your main screen and see how it looks.
Its even supports horizontal scroll.
  
Look at this: