Updates from June, 2008 Toggle Comment Threads | Keyboard Shortcuts

  • pit 1:39 pm on June 23, 2008 Permalink | Reply
    Tags: , , , sliding animations,   

    How to add sliding transitions between Canvas in J2ME 

    Today we’ll see a simple way to add sliding transition between Canvas in a Java ME application. Just take a look at it in the emulator page to see how it performs: Canvas sliding transitions in action!

    j2me canvas sliding transition screenshot

    The source code

    FxBaseCanvas

    First of all, we know that Canvas paint() method is protected, so, to access it from the class we’ll build, we must extend its visibility by extending Canvas class itself. We’ll do it by defining our FxBaseClass in this simple way:

    import javax.microedition.lcdui.Canvas;
    import javax.microedition.lcdui.Graphics;
    import javax.microedition.lcdui.Canvas;
    import javax.microedition.lcdui.Graphics;
     
    public class FxBaseCanvas extends Canvas
    {
    	public void paint(Graphics g)
    	{
    	}
    }

    CanvasSlideFx

    Now, we start building our CanvasSlideFx class, that will extend Canvas itself. We start defining some useful properties:

    // time related properties
    long startTime = 0;
    long duration = 0;
     
    // current state of the transition
    boolean running = false;
     
    // direction of sliding
    int direction = LEFT;
     
    // the previous and next Canvas instances
    FxBaseCanvas fromCanvas = null;
    FxBaseCanvas toCanvas = null;
     
    // the current Display object
    Display display = null;
     
    // properties used to correctly place the 2 Canvas
    int deltaX = 0;
    int deltaY = 0;

    Now, we define our class constructor, that will initialize coordinate properties according to the specified transition direction. The detailed argument list is:

    • The current Display object, that will be used to retrieve the current displayed Canvas, and to set the next one
    • The destination Canvas, that will extend the previously defined FxBaseCanvas class
    • The transition direction (one of Canvas.UP, RIGHT, DOWN or LEFT)
    • The transition duration, in milliseconds
    public CanvasSlideFx(Display display, FxBaseCanvas toCanvas, int direction, long duration)
    {
    	this.display = display;
    	this.fromCanvas = (FxBaseCanvas)display.getCurrent();
    	this.toCanvas = toCanvas;
    	this.direction = direction;
    	this.duration = duration;
     
    	switch(direction)
    	{
    	case UP:
    		deltaY = - getHeight(); break;
    	case RIGHT:
    		deltaX = getWidth(); break;
    	case DOWN:
    		deltaY = getHeight(); break;
    	case LEFT:
    		deltaX = - getWidth(); break;
    	}
    }

    Now, we define a startTransition() method, that will actually start the animation. To implement the animation itself, we let our class implement Runnable.

    void startTransition()
    {
    	this.startTime = System.currentTimeMillis();
     
    	running = true;
     
    	new Thread(this).start();
    }

    And here’s the run() method implementation, that we must implement from Runnable interface. As long as the animation is running, we will repaint our animated Canvas, with a given interval of 50 milliseconds (but you can freely change this). When it finishes (so, running is false), we will exit the main loop and set the current Displayable to our toCanvas.

    public void run()
    {
    	try
    	{
    		while(running)
    		{
    			repaint();
     
    			synchronized(this)
    			{
    				wait(50L);
    			}
    		}
    	}
    	catch(Exception e)
    	{
    		e.printStackTrace();
    	}
    	display.setCurrent(toCanvas);
    }

    Finally, we have our paint() method, that will actually paint our transition. It will do this by painting both the source and the destination Canvas, translating them according to the transition direction, and to the elapsed time.

    protected void paint(Graphics g)
    {
    	if(!running)
    		startTransition();
     
    	long diff = System.currentTimeMillis() - startTime;
     
    	if(diff >= duration)
    	{
    		running = false;
     
    		diff = duration;
    	}
     
    	int perc = (int)(100 * diff / duration);
     
    	int dx = deltaX * perc / 100;
    	int dy = deltaY * perc / 100;
     
    	g.translate(dx, dy);
     
    	fromCanvas.paint(g);
     
    	g.translate(- deltaX, - deltaY);
     
    	toCanvas.paint(g);
     
    	g.translate(deltaX - dx, deltaY - dy);
    }

    How to use it?

    Now we’ll see how to integrate the CanvasSlideFx within an existing code that already uses Canvas.
    So, let’s assume that our application currently has, somewhere in its code, these lines:

    MyCanvas firstCanvas = new MyCanvas();
     
    Display.getDisplay(myMidlet).setCurrent(firstCanvas);
    ...
    //and somewhere else
    MyOtherCanvas secondCanvas = new MyOtherCanvas();
     
    Display.getDisplay(myMidlet).setCurrent(secondCanvas);

    where MyCanvas and MyOtherCanvas will likely extend Canvas.

    Now here are the required steps to integrate transitions in our code:

    1. First of all, we must make MyCanvas and MyOtherCanvas extend FxBaseCanvas instead of directly Canvas. So, we’ll have:
      public class MyCanvas extend FxBaseCanvas ...
    2. Then, let’s say we want to animate the transition between firstCanvas and secondCanvas, we will remove the code:
      Display.getDisplay(myMidlet).setCurrent(secondCanvas);

      and replace it with:

      CanvasSlideFx fxCanvas = new CanvasSlideFx(
      	Display.getDisplay(myMidlet),
      	secondCanvas,
      	Canvas.LEFT,
      	500L
      );
       
      Display.getDisplay(myMidlet).setCurrent(fxCanvas);
    3. and we’ve done it! :)

    Resources and download

    You can download the code explained in this article with the following links:

     
  • pit 12:46 pm on June 13, 2008 Permalink | Reply
    Tags: code challenge, contest winners, ,   

    Forum Nokia 2008 Code Example Challenge Winners announced! 

    2008 Code Example Challenge took place on Forum Nokia Wiki, and reached the goal of nearly 300 articles (code examples and applications) submitted by more than 50 developers around the globe.

    2008 Code Example Challenge winners banner

    And finally… here are the Winners!

    Also, special prizes (Nokia 6220 Classic Devices) were given to: Raheal Akhtar, David Caabeiro, Gerald Madlmayr, Felipe Andrade, Olympio Cipriano and… me :) I’m too happy!!

    If you want to take a look at the impressive list of all articles submitted by developers for the whole contest, take a look here: 2008 Code Example Challenge article list.

     
    • Croozeus 6:49 pm on June 13, 2008 Permalink

      Congrats Jappit!

      Your work at the wiki was impressive.

      Best regards,
      Croozeus

    • pit 11:15 pm on June 13, 2008 Permalink

      Thanks Croozeus!

      I’m really happy to know that my articles are useful to developers… this gives me a lot of will to write more :)

      Pit

  • pit 1:46 pm on June 12, 2008 Permalink | Reply
    Tags: , , google static maps, , ,   

    Displaying GPS position in FlashLite using Google Static Maps and KuneriLite 

    Today’s tutorial is about using Google Maps static images, and GPS data, to display maps in a FlashLite application using KuneriLite.

    FlashLite KuneriLite Google Maps application screenshot

    Prerequisites

    Get your own Google Maps API key

    To use Google Maps services, you should have a Google Maps API key. If you do not have one, you can go here:

    http://code.google.com/apis/maps/signup.html

    and signup for your API key.

    Download and install KuneriLite

    KuneriLite is a tookit that extends FlashLite capabilites allowing applications to access native Symbian functionalities, like file writing, or reading GPS data.

    To proceed in this tutorial, you must download and install KuneriLite: KuneriLite download page.

    Create FlashLite application

    Create your FlashLite movie

    In this example, we’ll use FlashLite 2.1, but porting it to other (older or newer) FlashLite versions will be quite straightforward. So, after you’ve created an empty FlashLite movie, follow this simple steps:

    • Create a Button by going to Insert -> New Symbol…
    • enter GpsButton as name
    • check the Export for ActionScript and Export in first frame checkboxes

    GpsButton properties

    • Now, design your Button as you prefer, for example placing a big “Find me!” label on it
    • After you’ve finished designing your Button, place it on movie root, in the lower part of the stage, as in the attached screenshot, and give it startButton as Instance Name

    Place GpsButton on stage

    Enter ActionScript code

    On movie root, create a new layer called Actions, and open its ActionScript editor. We’ll start defining some properties:

    // Enter your api key here
    var apiKey = 'API_KEY';
     
    //If you're using non-commercial version of KuneriLite, you'll not need to change this
    var kuneriPath = 'http://127.0.0.1:1001/Basic/';

    Now, we’ll define some useful functions that we’ll use in our code:

    //We'll call this function when some KuneriLite related errors occur
    function kuneriError(error:String)
    {
    	trace("KuneriLite error: " + error);
    }
     
    //This function will do all calls to KuneriLite servers
    //and call the given handler passing response values as argument
    function kuneriLoad(url, handler)
    {
    	var loader:LoadVars = new LoadVars();
     
    	loader.onLoad = function()
    	{
    		handler(this);
    	}
    	trace("LOADING: " + url);
     
    	loader.load(url);
    }

    Now, let’s code the Button-related logic. When the user presses the startButton we want to:

    • start the GPS
    • retrieve the current GPS position
    • display a map centered in the retrieved GPS position

    To get full infos about about KuneriLite GPS plugin, you can check the related Wiki page: http://wiki.kunerilite.net/index.php?title=GPS_plugin

    We begin starting the GPS on gpsButton press, using the start klCommand:

    startButton.onPress = function()
    {
    	kuneriLoad(kuneriPath + 'GPS?klCommand=start', gpsStarted);
    }
    function gpsStarted(res:LoadVars)
    {
    	if(res.klError == 0 || res.klError == -11)
    	{
    		trace("GPS started");
     
    		kuneriLoad(kuneriPath + 'GPS?klCommand=read', gpsDataRead);
    	}
    	else
    	{
    		kuneriError("Error starting GPS!");
    	}
    }

    The gpsStarted() handler will:

    • check if there is no error (klError = 0) or if GPS is already started (klError = -11). For full errors list associated with GPS plugin, check KuneriLite Wiki page: http://wiki.kunerilite.net/index.php?title=GPS_plugin
    • if there’s an error starting the GPS, call our kuneriError() function defined above
    • if GPS is correctly started, it will make a second call to KuneriLite, this time to retrieve current GPS position (klCommand=read)

    This second call to KuneriLite will call gpsDataRead() handler, defined below:

    function gpsDataRead(res:LoadVars)
    {
    	if(res.klError == 0)
    	{
    		if(res.klPosLatitude != undefined)
    		{
    			var lat = res.klPosLatitude;
    			var lng = res.klPosLongitude;
     
    			trace("POSITION: " + lat + ", " + lng);
     
    			loadMap(lat, lng);
    		}
    		else
    		{
    			kuneriLoad(kuneriPath + 'GPS?klCommand=read', gpsDataRead);
    		}
    	else
    	{
    		kuneriError("Error retrieving GPS position!");
    	}
    }

    This handler, as above, will check if there is any error raised by KuneriLite and, if not, will check if latitude and longitude coordinates are available, by checking response klPosLatitude and klPosLongitude property values. If they’re not available, a new call to read klCommand is done, otherwise the following loadMap() function is called.

    function loadMap(lat:Number, lng:Number)
    {
    	var mapClip:MovieClip = _root.createEmptyMovieClip('mapClip', _root.getNextHighestDepth());
     
    	mapClip._x = 0;
    	mapClip._y = 0;
     
    	var mapWidth = 240;
    	var mapHeight = 280;
     
    	var loader:MovieClipLoader = new MovieClipLoader();
     
    	var mapUrl:String = 'http://maps.google.com/staticmap?center=' +
    		lat + ',' + lng + '&format=jpg&zoom=8&size=' +
    		mapWidth + 'x' + mapHeight + '&key=' + apiKey;
     
    	loader.loadClip(mapUrl, mapClip);
    }

    The above function:

    • attaches a new empty movie clip to movie root
    • places it to coordinates (0,0)
    • use a MovieClipLoader to load a 240×280 map image, in jpeg format, in the empty clip

    Done that, you can actually test your FlashLite movie

    Test your FlashLite application

    Test on PC

    To test your application without deploying on real device, you must follow these simple steps:

    • Start KuneriLite emulator with default settings (port: 1001, key: Basic)
    • Start your FlashLite movie
    • Press Find Me! and wait for your image to be loaded (of course, being an emulator, the GPS position will be not real :))

    For more infos about KuneriLite Emulator, you can go here: KuneriLite Emulator Wiki page

    Test on real device

    To test your app on real device, you must package your SIS application using KuneriLite Wizard, following these steps:

    KuneriLite Emulator screenshot

    • Export your FlashLite movie
    • Create a new KuneriLite project
    • Enter application name and other data, checking GPS from the available plugins
    • Check “Use external player” option if you developed for a development player (2.x or 3.x) and would like to launch the application using one of those players
    • It is also recommended to always check “Use stub” option
    • Select the exported SWF as project Main SWF

    Note: to use GPS you should sign your application, specifying certificate, key and password in KuneriLite Wizard interface. Otherwise, your application will not be able to access GPS functionalities.

    For more infos about KuneriLite Wizard, you can go here: KuneriLite Wizard Beginner’s Guide

    Source code and resources

     
    • Ugur 2:16 pm on June 12, 2008 Permalink

      Great tutorial Alessandro, kudos!

      FYI – couldn’t get the ZIP file, gives 404

      cheers,

      Ugur.-

    • Pit 2:20 pm on June 12, 2008 Permalink

      Thanks Ugur!

      I missed a letter in the ZIP name… now It should work :)

      Pit

    • Pasi Manninen 6:49 am on June 14, 2008 Permalink

      Great Tutorial!

      Br,
      Pasi Manninen.

    • senthil kumar 1:55 pm on June 15, 2008 Permalink

      Hi am trying to get microsoft virtual map into my flash lite. How i can get the virtual map into flash lite?

    • Hudarsono 6:40 pm on July 19, 2008 Permalink

      This tutorial uses Symbian, how about android?

    • java.padawan 11:53 pm on February 10, 2009 Permalink

      I created a simple GPS tutorial using android.

      http://www.androidph.com/2009/02/app-10-beer-radar.html

  • pit 9:56 am on June 4, 2008 Permalink | Reply
    Tags: iphone 3g, , nokia code camp   

    Nokia Code Camp Winners, iPhone 3G and Jarpa 

    After a busy period, I finally got some time to come back to Jappit blog, just in time to announce…

    Forum Nokia Code Champ Winners!

    This competition, launched by Nokia to promote the development of WebRuntime and Flash-based applications has finally announced his winners, and there are really cool applications!

    CityLite

    CityLite of IdeasLite is a guide to night life in Latin American capitals, with informations about events, theaters, and a lot more. Really cool interface!

    Kuneri EasyVote

    KuneriLite team also won the award for Europe/Middle East/Africa with their one-button voting system: Kuneri Easy Vote! Congratulations for their good work!

    For the full list of winners, you can look here.

    iPhone 3G is finally here!

    Iphone 3g

    After months of guessing and posting, Apple will finally announce, during San Francisco Apple WorldWide Developers Conference of June 9th, the 3G version of its iPhone. And it seems that it’ll arrive in Italy before the end of June branded by the two Carriers Tim and Vofafone.

    While it’s definitely a good news that it’ll support HSDPA, it seems that we’ll not have a builtin GPS… too bad for all location-fanatics! :)

    Jarpa, source code is out!

    Jarpa

    Jarpa is an absolutely interesting project aiming to extend FlashLite and Java ME feature by allowing them to intercommunicate, and so allowing developers to create hybrid applications that can take the best of both worlds.

    Some days ago, Felipe Andrade has finally released Jarpa sourcecode, so developers can finally start to benefit of this framework, and for J2ME and FL-addicted like me, this is a GREAT news!

    And, if you need one more reason to congratulate with Felipe for its great and extensive work, here is its Nokia Championship award!

     
  • pit 2:20 pm on May 20, 2008 Permalink | Reply
    Tags: , integration, , mobile development   

    Random thoughts after 2 months on KuneriLite 

    Yesterday I’ve finished 2 projects developed using FlashLite 3.0 in conjunction with KuneriLite. Now, it’s time for some considerations.

    About FlashLite

    FlashLite Gallery screenshot

    My opinion: FlashLite is far from being a mature platform for mobile development. Why?

    No access to native phone functionalities.

    This means no GPS, no data storage (apart from text), no video/audio capture, and much more. Since one of mobile apps strengths is in its integration with the device itself, this sounds like a big limitation (but someway it’s something like first J2ME years). This could be due to a different perspective and target users/developers, but having a powerful platform like Flash being limited to casual games or screensavers looks a bit odd to me.

    Odd, senseless behavior.

    What happens if you try to load more that 5 resources together? They won’t load, simple.

    Or want to quit your application? You can, but at conditions: user must press some key for quit to work and, even if he does, there’s the chance that the app simply won’t close.

    And if a network or local resource, for example loaded via LoadVars, is not available? You’ll have a terrible popup telling the user that he has a “Problem with content: -6″, or other similar, anti-usability things.

    Security encounters insanity.

    Since FlashLite 3.0, there was a nice introduction, with the new player Security settings. About this there are good articles from Ugur and chall3ng3r that point out this has caused problems in having, for example, an application loading both local and remote resources. Fortunately, there are workarounds that allow to overcome some of the limitations involved in this (like using the notorious “Trusted” folder), but we’re still far from painless development :)

    Good news under the sun.

    Bill Perry from Adobe posted back, few days after the posts from Ugur and chall3ng3r, with the news that Adobe is working to solve some of the issues pointed out, and this is absolutely a welcome kind of feedback from Adobe team!

    About KuneriLite

    KuneriLite Wizard screenshot

    Install, plug, use.

    When you must merge 2 technologies to overcome their own limitations, it’s already a pain. So, when you do it, you want simple, immediate tools, that would make your work easier, not harder. With KuneriLite you have exacly this: an easy-to-use, understand and test tool. You have an intuitive Wizard that will allow you to create, setup and SIS package all your apps, and an emulator for easy testing and debugging. This IS what we want!

    Support matters!

    Briefly said: KuneriLite team is fantastic! Having worked with their product for more than 2 months, I can say to be more than happy for their help and support. You can find all the infos you want on their forums an Wiki pages.

    Yes, but what?

    Ok, maybe you don’t know what KuneriLite is, so here’s a brief introduction: KuneriLite is a tool that allows you to access Symbian native functionalities from your FlashLite application. They (your FlashLite app and KuneriLite) will interact via simple HTTP requests, and results are returned in the classical form of key/value pairs. So said, integration with your app will be quite straightforward.

    Past, present and future.

    Mobile Development is currently undergoing a lot of changes, merging and shuffles.

    FlashLite seems to be trying to find his way by merging with other technologies, from Java (see Jarpa) to Python (FlyerFramework) to Symbian C++ (KuneriLite, Janus, and others) and, why not, Web Runtime. Far from having a definite solution, there’s a lot to see and experiment.

    And we’re here to do it :)

     
  • pit 12:00 pm on April 28, 2008 Permalink | Reply
    Tags: , , ,   

    New KuneriLite version with cool improvements 

    KuneriLite is a great tool to extend FlashLite functionalities adding support for native features like local filesystem read/write, camera recording, accelerometer capabilities and much more. All these without the need to have any Symbian knowledge.

    Practically, you interact with KuneriLite engine via localhost calls. For example, if you want to get recursive folder listing starting from current application base path, you can simply do:

    loadVariables("http://127.0.0.1:1001/Basic/file?
    klCommand=dir&klPath=\\&klArgs=/s", targetMc);

    Their tool comes with an integrated wizard and an emulator, to be used with Symbian S60 3rd edition SDK Maintenance Release, to allow full development without the need of a real device.

    KuneriLite logo

    Now they’ve just released 0.9.6.1 version, that fixes issues with Flash Lite 3 and add new cool features, as you can read on their blog, and it’s more than ever worth a try!

     
    • Ugur 2:30 pm on April 28, 2008 Permalink

      Thanks for the post Pit! Great to hear you like it :)

c
compose new post
j
next post/next comment
k
previous post/previous comment
r
reply
e
edit
o
show/hide comments
t
go to top
l
go to login
h
show/hide help
shift + esc
cancel