Friday, July 31, 2009

service book sample

import net.rim.device.api.system.*;
import net.rim.device.api.servicebook.*;

public class ServiceBookExample extends Application {
ServiceRecord[] _sRecordsArray; // Creates a ServiceRecord array.
ServiceBook _servicebook; // Creates a ServiceBook variable.
String cidValue, sbName, sbAPN;

public static void main(String[] args) {
// Create a new instance of the application and
// start the event thread.
ServiceBookExample app = new ServiceBookExample();
app.enterEventDispatcher();
}

public ServiceBookExample() {
// Returns a reference to the service book from the factory.
_servicebook = ServiceBook.getSB();
// Returns an array of all registered service records.
_sRecordsArray = _servicebook.getRecords();
// Loops through the service record array
// and obtains specific information relating
// to each item and prints it to the debugging output.
for (int i = 0; i < _sRecordsArray.length; i++) {
// Obtains the Service Book CID
cidValue = _sRecordsArray[i].getCid();
// Obtains the Name of the Service Book
sbName = _sRecordsArray[i].getName();
if (cidValue.equals("BrowserConfig")
&& sbName.startsWith("WAP Browser")) {
// Obtains the Service Book's APN
// (Associated Access Point Name)
String sbAPN = _sRecordsArray[i].getAPN();
}
}
}
}

Tuesday, July 21, 2009

About pushing for iPhone and Blackberry

I must say apple did it a neat and easier way, BB is not :(

BB
http://na.blackberry.com/eng/developers/javaappdev/pushapi.jsp#tab_tab_works

iPhone
A nice guide to setup your server:

http://www.macoscoders.com/2009/05/17/iphone-apple-push-notification-service-apns/
another good one:

http://blog.boxedice.com/2009/07/10/how-to-build-an-apple-push-notification-provider-server-tutorial/

basically you need a developer's id, then apply for the iPhone Push Notification Server (PNS) service. After got the certificate, you just put it on your Apache server. Or you may write a Java or .Net program to load the certificate and send out your testing data.

package com.demo.samples;
import java.io.ByteArrayOutputStream;
import java.io.FileInputStream;
import java.io.InputStream;
import java.io.OutputStream;
import java.security.KeyStore;

import javax.net.ssl.KeyManagerFactory;
import javax.net.ssl.SSLContext;
import javax.net.ssl.SSLSocket;
import javax.net.ssl.SSLSocketFactory;

import java.awt.image.RenderedImage;
import java.io.IOException;

public class pushdemo {

/**
* @param args
*/
public static void main(String[] args) {
System.out.println(args[0]);
if (args.length != 2) {
System.out.println("Usage: KeGenerator phonenumber ExpireDate(yyyy-MM-dd)");
System.exit(0);
}

// TODO Auto-generated method stub
try {
int port = 2195;
String hostname = "gateway.sandbox.push.apple.com";


char []passwKey = "keypassword".toCharArray();
KeyStore ts = KeyStore.getInstance("PKCS12");
ts.load(new FileInputStream("devCert.p12"), passwKey);

KeyManagerFactory tmf = KeyManagerFactory.getInstance("SunX509");
tmf.init(ts,passwKey);
SSLContext sslContext = SSLContext.getInstance("TLS");
sslContext.init(tmf.getKeyManagers(), null, null);
SSLSocketFactory factory =sslContext.getSocketFactory();
SSLSocket socket = (SSLSocket) factory.createSocket(hostname,port); // Create the ServerSocket
String[] suites = socket.getSupportedCipherSuites();
socket.setEnabledCipherSuites(suites);
//start handshake

socket.startHandshake();


// Create streams to securely send and receive data to the server
InputStream in = socket.getInputStream();
OutputStream out = socket.getOutputStream();



// Read from in and write to out...
ByteArrayOutputStream baos = new ByteArrayOutputStream();
baos.write(0); //The command
System.out.println("First byte Current size: " + baos.size());

baos.write(0); //The first byte of the deviceId length
baos.write(32); //The deviceId length

System.out.println("Second byte Current size: " + baos.size());

String deviceId = "02da851db4f2b5bfce1982700d3dac72bc87cd60";
baos.write(hexStringToByteArray(deviceId.toUpperCase()));
System.out.println("Device ID: Current size: " + baos.size());

//{ "aps" : { "alert" : { "body" : "Bob wants to play poker", "action-loc-key" : "PLAY" }, "badge" : 5, }, "acme1" : "bar", "acme2" : [ "bang", "whiz" ] }
String payload = "{\"aps\":{\"alert\":\"I like spoons also\",\"badge\":14}}";
System.out.println("Sending payload: " + payload);
baos.write(0); //First byte of payload length;
baos.write(payload.length());
baos.write(payload.getBytes());

out.write(baos.toByteArray());
out.flush();

System.out.println("Closing socket.." + in.read());
// Close the socket
in.close();
out.close();
} catch (Exception e) {
e.printStackTrace();
}

}
public static byte[] hexStringToByteArray(String s) {
byte[] b = new byte[s.length() / 2];
for (int i = 0; i < b.length; i++){
int index = i * 2;
int v = Integer.parseInt(s.substring(index, index + 2), 16);
b[i] = (byte)v;
}
return b;
}

}

Thursday, July 16, 2009

monitor Blackberry BackLight

SystemListener2
backlightStateChange

You need to implement the SystemListener2 interface and will be called when light changes. .

void backlightStateChange(boolean on)
Invoked when the backlight state changes.

http://www.blackberry.com/developers/docs/4.5.0api/net/rim/device/api/system/SystemListener2.html

Free tools

SVG Anti-Virus Free
WINScp ftp client
SciTE edit tool
Actual Multiple Monitors

Friday, July 10, 2009

Setting up a Subversion Server under Windows

Setting up a Subversion Server under Windows

I talked a little bit about what Subversion is in my previous post. Now, let's get it set it up in Windows.

Luckily for us, Joe White has done most of the work already; he has a tremendously helpful post that documents how to set up Subversion. I'll see if I can streamline his excellent post a bit further, and illustrate it with screenshots.

A) Download Subversion

You'll need the latest version of..

B) Install Subversion

  1. Unzip the Windows binaries to a folder of your choice. I chose c:\program files\subversion\ as my path.
  2. Now, add the subversion binaries to the path environment variable for the machine. I used %programfiles%\subversion\bin\

  3. You'll also need another environment variable, SVN_EDITOR, set to the text editor of your choice. I used c:\windows\notepad.exe

C) Create a Repository

  1. Open a command prompt and type
    svnadmin create "c:\Documents and Settings\Subversion Repository"
  2. Navigate to the folder we just created. Within that folder, uncomment the following lines in the /conf/svnserve.conf file:
    [general]
    anon-access = read
    auth-access = write
    password-db = passwd

    Next, uncomment these lines in the /conf/passwd file:

    [users]
    harry = harryssecret
    sally = sallyssecret

D) Verify that everything is working

  1. Start the subversion server by issuing this command in the command window:
    svnserve --daemon --root "C:\Documents and Settings\Subversion Repository"
  2. Create a project by opening a second command window and entering this command:

    svn mkdir svn://localhost/myproject

    It's a standard Subversion convention to have three folders at the root of a project:

    /trunk
    /branches
    /tags

  3. At this point, Notepad should launch:

    Enter any comment you want at the top of the file, then save and exit.
  4. You'll now be prompted for credentials. In my case I was prompted for the administrator credentials as well:

    Authentication realm:  0f1a8b11-d50b-344d-9dc7-0d9ba12e22df
    Password for 'Administrator': *********
    Authentication realm: 0f1a8b11-d50b-344d-9dc7-0d9ba12e22df
    Username: sally
    Password for 'sally': ************

    Committed revision 1.

    Congratulations! You just checked a change into Subversion!

E) Start the server as a service

  1. Stop the existing command window that's running svnserve by pressing CTRL+C.
  2. Copy the file SVNService.exe from the zip file of the same name to the subversion\bin folder.
  3. Install the service by issuing the following commands:
    svnservice -install --daemon --root "C:\Documents and Settings\Subversion Repository"
    sc config svnservice start= auto
    net start svnservice
  4. Test the new service by listing all the files in the repository:
    svn ls svn://localhost/

    You should see the single project we created earlier, myproject/

F) Set up the shell extension

  1. Run the TortoiseSVN installer. It will tell you to restart, but you don't need to.
  2. Create a project folder somewhere on your hard drive. Right click in that folder and select "SVN Checkout..."



    type svn://localhost/myproject/ for the repository URL and click OK.


  3. Create a new file in that directory. Right click the file and select "TortoiseSVN, Add"


  4. The file hasn't actually been checked in yet. Subversion batches any changes and commits them as one atomic operation. To send all your changes to the server, right click and select "SVN Commit":



And we're done! You now have a networked Subversion server and client set up on your machine. Note that the default port for svnserve is 3690.

For more tips on using subversion, take a look at the free O'Reilly Subversion book.

good J2me UI framework

Great User Interface Libraries for J2ME Developers
J2ME
Written by Vimal
Wednesday, 23 July 2008 09:12

Rating 2.8/5 (10 votes)

J2ME is a primitive but powerful development platform for devloping applications for mobile devices. A serious issue with J2ME is the lack of built in libraries to accomplish several common tasks. There are several free and commercial libraries availbale that can be used to provide more functionality in our J2ME applications. In this article I shall list down several famous User Interface libraries for J2ME.


Apime

License: GPL

Category: User Interfaces

Apime is a framework to offer more funcionality to J2ME/MIDP. The core is the user interface, with basics components to make applications with swing structure.
Also it includes classes for file manage and customization (skins, internacionalization, keyboards for differents languages and mobiles, ...)

BaseMovil

License: GPL

Category: User Interfaces

BaseMovil is a framework for fast development of J2ME applications: a powerful J2ME database engine, a scripting engine and an ui toolkit which is fully integrated with both and allows xml view definition. The framework handles device differences/bugs.

Fire

License: LGPL

Category: User Interfaces

Fire (Flexible Interface Rendering Engine)is a lightweight themable GUI engine for j2me MIDP2 applications. It is designed to be an eye-candy replacement to the traditional midp GUI components. It provides more than the forms and items functionality and its not kvm-implementation depended.

LwVCL

License: GPL

Category: User Interfaces

Another User Interfaces library for the J2ME platform providing many UI components like Buttons, Checkbox, Radio Box, Progreess Bars, Tabbed Panes etc.. It is designed as a replacement to the traditional J2ME Widgets.

J4ME

License: Apache License 2.0

Category: User Interfaces, Utilities

J4ME is an open source library to help build J2ME applications. It solves many of J2ME's shortcomings including: Uese Interfaces, Logging, GPS and various other utility classes and methods.

jMobileCore

License: LGPL

Category: User Interfaces , Utilities

jMobileCore library is powerful tool for creating J2ME applications. jMobileCore provides support for developing compact and rich Canvas-based GUI, fast data access, reliable communications and simplifies creation of multithreading midlet applications.

kUI

License: GPL, Commerical

Category: User Interfaces

kUI is a Canvas based replacement for the high level LCDUI classes. It can be styled to meet your own branding requirements,avoids problems with implicit close commands, does not require a preprocessing step and offers a consistent behaviour and user interface experience among different devices, simplifying your development and documentation process.

Kuix

License: GPL

Category: User Interfaces

Kuix (Kalmeo User Interface eXtensions) is a development framework that allows to create easily high end J2ME applications. It provides most graphical elements (buttons, textfields, lists, menus, etc.) needed to create advanced user graphical interfaces and uses an XML/CSS approach to describe the screens and the user actions in the application.

LWUIT

License: GPL

Category: User Interfaces

LWUIT is a UI library that is bundled together with applications and helps content developers in creating compelling and consistent Java ME applications. LWUIT supports visual components and other UI goodies such as theming, transitions, animation and more.

Mewt

License: GPL

Category: User Interfaces

An advanced widget toolkit for J2ME devices, supporting cross-platform components such as tables, trees, graphical buttons, theming etc.

MWT (Micro Window Toolkit)

License: GPL

Category: User Interfaces

Inspired by its UI big brothers as AWT, Swing and SWT, MWT comes into the scene providing an UI framework designed and optimized for small devices.

Nextel's Open Source J2ME Toolkits

License: GPL

Category: User Interfaces

Nextel's Open Source J2ME Toolkits contain libraries for user interface and RMS development on J2ME handsets.

The windowing toolkit, OWT (Open Windowing Toolkit), employs a container/component model, and provides interfaces to permit developers to create their own user interface components. The toolkit is designed specifically for MIDP handsets with a small amount of screen real estate. It is built on top of MIDP's Canvas class.

The RMS toolkit provides classes that simplify record management on MIDP devices.

Thinlet

License: GPL

Category: User Interfaces

Thinlet is a GUI toolkit, a single Java class, parses the hierarchy and properties of the GUI, handles user interaction, and calls business logic. Separates the graphic presentation (described in an XML file) and the application methods (written as Java code).

Thinlet runs with Java 1.1 to 1.4, Personal Java, and Personal (Basis) Profile. Its MIDP version was dropped, but you still can find the last MIDP version at Thinlet Download page.

Synclast UI API

License: GPL

Category: User Interfaces

The Synclast UI API is an extensible toolkit for creating colorful custom user interfaces on MIDP devices in an intuitive yet efficient manner, It provides several Widgets, Layouts, Backgrounds, Powerful Forms and Menus.

Thursday, July 9, 2009

ant build for your blackberry

configure the eclipse for BB

http://www.blackberryforums.com/developer-forum/138210-setup-up-eclipse-blackberry-development.html

Blackberry ant tool
http://bb-ant-tools.sourceforge.net/docs

Apache ant here

http://gulus.usherbrooke.ca/pub/appl/apache/ant/binaries/apache-ant-1.7.1-bin.zip


How To - Format the electronic serial number (ESN)

Details

The following code can be used to format the ESN of a BlackBerry smartphone to match the format that is shown under Options > Status on the BlackBerry smartphone.

Note: ESNs are only present on BlackBerry smartphones that operate on the Code Division Multiple Access (CDMA) network.

public String getDecimalSerialNumber()
{
StringBuffer esnStringBuffer = new StringBuffer();

//Determine if the BlackBerry operates on the CDMA network.
if( RadioInfo.getNetworkType() == RadioInfo.NETWORK_CDMA )
{
//It does, so we'll format the ESN number.
int sn = CDMAInfo.getESN();
int firstPart = (sn >> 24) & 0xff;
int secondPart = sn & 0xffffff;

String firstPartString = String.valueOf( firstPart );
String secondPartString = String.valueOf( secondPart );
padESN( esnStringBuffer, 3 - firstPartString.length() );
esnStringBuffer.append( firstPartString );
padESN( esnStringBuffer, 8 - secondPartString.length() );
esnStringBuffer.append( secondPartString );

return esnStringBuffer.toString();
}
else
{
//This BlackBerry does not operate on the CDMA network,
//return 0.
esnStringBuffer.append(0);
}

return esnStringBuffer.toString();
}

//Inserts zeros into the ESN string.
private void padESN(StringBuffer esnStringBuffer, int padCount)
{
for (int i = 0; i < padCount; ++i) {
esnStringBuffer.append('0');
}
}