Yet another blog

Wednesday, September 30, 2009

How to include external jar file in BlackBerry Eclipse plugin

You might need to preverify the jar file. This is how you can preverify a jar file

Go to your JDE installation folder, for Windows XP it is usually C:\Program Files\Research In Motion\BlackBerry JDE 4.3.0\bin. If you are using eclipse then you can also find the installation directory of BlackBerry plugin.
2. Copy your jar  file to bin folder.
3. Notice the preverify.exe file. This is the tool we'll use.
4. Now open your command prompt and change your current directory to your JDE installation directory.
5. execute the following command:
preverify -classpath "JDE_PATH_HERE\lib\net_rim_api.jar" "your_jar_filename"
6. Notice that in bin directory, another folder named output has been created. Preverified jar file resides here. Copy the preverified jar file with the same name that the non-preverified jar file has.
7. Now replace the non-preverified jar file with the verified one. Use this jar in next steps

Create a new Blackberry project with any name like LibProject.
   Right-click on the project and go to Properties.
   Go to Blackberry Project Properties. Click on the Application tab.
   Under Project Type, change to Library.
   Next, go to the Java Build Path.
  go to libraries and add the jar file as an external library.
  Go to Order and Export tab here, and mark your jar file as exportable
  Click OK.

Build the library project.

Now, create your main BlackBerry project
   Keep this projects type to as you wish it to be.
   Now go to the properties of this project, In the Java Build Path, add the LibProject project as a Project dependency.

You are pretty much ready to import the jar in your code. Try to import a class and see if it works.

Alternatively, what I think that we might skip the first works of creating a new project and try to add the jar directly to our app. I think that might also work. Though I did not try it yet. Let me know if anyone was successful doing it.

That’s all for now

Saturday, August 8, 2009

BlackBerry get UserAgent

System.getProperty("browser.useragent")

Wednesday, July 22, 2009

Decode utf string to java string in Blackberry or j2me

 

public static String unescape(String s)

{
  StringBuffer sbuf = new StringBuffer () ;
  int l  = s.length() ;
  int ch = -1 ;
  int b, sumb = 0;
  for (int i = 0, more = -1 ; i < l ; i++) {
    /* Get next byte b from URL segment s */
    switch (ch = s.charAt(i)) {
      case '%':
        ch = s.charAt (++i) ;
        int hb = (Character.isDigit ((char) ch)
                  ? ch - '0'
                  : 10+Character.toLowerCase((char) ch) - 'a') & 0xF ;
        ch = s.charAt (++i) ;
        int lb = (Character.isDigit ((char) ch)
                  ? ch - '0'
                  : 10+Character.toLowerCase ((char) ch)-'a') & 0xF ;
        b = (hb << 4) | lb ;
        break ;
      case '+':
        b = ' ' ;
        break ;
      default:
        b = ch ;
    }
    /* Decode byte b as UTF-8, sumb collects incomplete chars */
    if ((b & 0xc0) == 0x80) {                 // 10xxxxxx (continuation byte)
      sumb = (sumb << 6) | (b & 0x3f) ;       // Add 6 bits to sumb
      if (--more == 0) sbuf.append((char) sumb) ; // Add char to sbuf
    } else if ((b & 0x80) == 0x00) {          // 0xxxxxxx (yields 7 bits)
      sbuf.append((char) b) ;                 // Store in sbuf
    } else if ((b & 0xe0) == 0xc0) {          // 110xxxxx (yields 5 bits)
      sumb = b & 0x1f;
      more = 1;                               // Expect 1 more byte
    } else if ((b & 0xf0) == 0xe0) {          // 1110xxxx (yields 4 bits)
      sumb = b & 0x0f;
      more = 2;                               // Expect 2 more bytes
    } else if ((b & 0xf8) == 0xf0) {          // 11110xxx (yields 3 bits)
      sumb = b & 0x07;
      more = 3;                               // Expect 3 more bytes
    } else if ((b & 0xfc) == 0xf8) {          // 111110xx (yields 2 bits)
      sumb = b & 0x03;
      more = 4;                               // Expect 4 more bytes
    } else /*if ((b & 0xfe) == 0xfc)*/ {      // 1111110x (yields 1 bit)
      sumb = b & 0x01;
      more = 5;                               // Expect 5 more bytes
    }
    /* We don't test if the UTF-8 encoding is well-formed */
  }
  return sbuf.toString() ;
}

Saturday, July 11, 2009

How to display GIF images in Blackberry applications

In order to show GIF images in Blackberry applications you have to disable exporting all images to png format. This can be done from JDE by right clicking the project and going to properties. In resources tab select “Don’t convert image files to png”.

dontpng

Now add the gif image in the project. And add this class with your project.



/*

* AnimatedGIFField.java
*
* © <your company here>, 2003-2008
* Confidential and proprietary.
*/

import net.rim.device.api.ui.UiApplication;

import net.rim.device.api.system.GIFEncodedImage;
import net.rim.device.api.ui.Graphics;
import net.rim.device.api.ui.component.BitmapField;

//A field that displays an animated GIF.

public class AnimatedGIFField extends BitmapField
{
private GIFEncodedImage _image; //The image to draw.
private int _currentFrame; //The current frame in the animation sequence.
private int _width; //The width of the image (background frame).
private int _height; //The height of the image (background frame).
private AnimatorThread _animatorThread;

public AnimatedGIFField(GIFEncodedImage image)
{
this(image, 0);
}

public AnimatedGIFField(GIFEncodedImage image, long style)
{
//Call super to setup the field with the specified style.
//The image is passed in as well for the field to
//configure its required size.
super(image.getBitmap(), style);

//Store the image and it's dimensions.
_image = image;
_width = image.getWidth();
_height = image.getHeight();

//Start the animation thread.
_animatorThread = new AnimatorThread(this);
_animatorThread.start();
}

protected void paint(Graphics graphics)
{
//Call super.paint. This will draw the first background
//frame and handle any required focus drawing.
super.paint(graphics);

//Don't redraw the background if this is the first frame.
if (_currentFrame != 0)
{
//Draw the animation frame.
graphics.drawImage(_image.getFrameLeft(_currentFrame), _image.getFrameTop(_currentFrame),
_image.getFrameWidth(_currentFrame), _image.getFrameHeight(_currentFrame), _image, _currentFrame, 0, 0);
}
}

//Stop the animation thread when the screen the field is on is
//popped off of the display stack.
protected void onUndisplay()
{
_animatorThread.stop();
super.onUndisplay();
}

//A thread to handle the animation.
private class AnimatorThread extends Thread
{
private AnimatedGIFField _theField;
private boolean _keepGoing = true;
private int _totalFrames; //The total number of frames in the image.
private int _loopCount; //The number of times the animation has looped (completed).
private int _totalLoops; //The number of times the animation should loop (set in the image).

public AnimatorThread(AnimatedGIFField theField)
{
_theField = theField;
_totalFrames = _image.getFrameCount();
_totalLoops = _image.getIterations();

}

public synchronized void stop()
{
_keepGoing = false;
}

public void run()
{
while(_keepGoing)
{
//Invalidate the field so that it is redrawn.
UiApplication.getUiApplication().invokeAndWait(new Runnable()
{
public void run()
{
_theField.invalidate();
}
});

try
{
//Sleep for the current frame delay before
//the next frame is drawn.
sleep(_image.getFrameDelay(_currentFrame) * 10);
}
catch (InterruptedException iex)
{} //Couldn't sleep.

//Increment the frame.
++_currentFrame;

if (_currentFrame == _totalFrames)
{
//Reset back to frame 0 if we have reached the end.
_currentFrame = 0;

++_loopCount;

//Check if the animation should continue.
if (_loopCount == _totalLoops)
{
_keepGoing = false;
}
}
}
}
}
}

This class will create a custom field type object. You can add it with a Screen type objects.

The following code will add a GIF image with a Screen type object



AnimatedGIFField testanimated= new AnimatedGIFField((GIFEncodedImage)(GIFEncodedImage.getEncodedImageResource( "loading2.gif" )),AnimatedGIFField.FIELD_LEFT);
//add(answer);
add(testanimated);


You are done. Let me know if you found any difficulties adding it.

9530

Friday, May 22, 2009

How to install MySql in CentOS 5.3 from shell or webmin

In my server webmin was installed but mysql was not there. The server was running centos5.3.

After some googling i found some solutions and here is the combination which might solve your problems.

You have to have access to a shell window in the server. You can access using putty or
by loggin into your webmin, go to Others->Command Shell.You can type commands in this shell.

If using putty, you will get the command shell any way :) after logging in.

Inorder to check if mysql is already installed or not run this command
which mysql
If found it will show some directory name otherwise not found

In order to remove old mysql
yum remove mysql-server
yum remove mysql

Now to install mysql run this command from the shell or a command line access point
yum install mysql-server
yum install mysql
yum install mysql-devel

Inorder to use with php
yum install php-mysql

By default mysql has the no passward. To change the password in command shell write the following commands
mysql
mysql> USE mysql;
mysql> UPDATE user SET Password=PASSWORD('new-password') WHERE user='root';
mysql> FLUSH PRIVILEGES;

That's all, if anything is missing let me know

Wednesday, April 15, 2009

Shuvo noboborsho


bangla 1416


Monday, March 23, 2009

Movie

Watch sad movies alone, funny movies all together