Wednesday, July 22, 2009

 

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

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

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

Sunday, February 22, 2009

I was in a need to show a date picker with a java application. After some searching I came into here for a free calendar component.

Might become useful for somebody.

And to show a time picker control, you can use the jspinner itself, nothing extra is required. It amazed me

JSpinner spinner =
new JSpinner(sm);
JSpinner.DateEditor de = new JSpinner.DateEditor(spinner, "hh:mm");
spinner.setEditor(de);


You can do it in netbeans by going into the properties of jspinner and changing the Editor properties from there,

When you have a bluetooth dongle you can receive business card/files/contacts from mobile devices using your bluetooth software. Now if you want to receive contacts/file in your own software and you also don't want to install any application in your mobile device then you can continue reading.

The main thing is to open a obex receiver in your bluetooth device from your application, then other remote device can do ServiceSearch and find your dongle to send contact/vcard/business card without installing any application.

The trick is done using OBEX, to know about OBEX google please.
I am going to use Java as my source language as there is already a API made named bluecove

I tried to find an already made project and couldn't find after some searching(may be my search strings were weak)

After one/two day i came to the bluecove code repository, there i found the source of it.

So i made a netbeans project of my own and is posted at the end of this post(i think if you are interested then you are now looking into the end section for the code ;) )

Ok no rush, the original source code of bluecove people are here. Thanks god i found it.

And my code in netbeans can be found here.

To run it in windows no problem, but to run in it newer ubuntu when this post was written you had to include bluecove-gpl with the project, which is already included and you will need to install libbluetooth-dev for ubuntu 8.10 with this command
sudo apt-get install libbluetooth-dev

I hope the code works.