Tagged: java me Toggle Comment Threads | Keyboard Shortcuts

  • pit 1:15 pm on July 15, 2008 Permalink | Reply
    Tags: , , , java me, , , , streaming video, virtual operator   

    Mtv On Demand: new FlashLite and Java ME apps released! 

    Last friday (July 11th) was a big mobile day here in Italy: apart from the worldwide release of iPhone 3G (sold in Italy at something like 3 times the USA price…), MTV became virtual mobile operator!

    MTV Mobile logo

    For its initial launch (you can see some photos of the launch event on Flickr) MTV released 2 phones: a Nokia 5320 Xpress Music and a Sony Ericsson W760, both heavily customized with special covers and themes.

    But, what really interests to us, is the launch of 2 embedded applications on these phones :)

    The first one is called Mtv On Demand, and it’s a streaming video player that allows to view selected videos from MTV programs. The interface is pretty slick, and allows users to navigate video galleries using LEFT/RIGHT keys, while with UP/DOWN they’ll scroll videos within a single category.

    MtvOnDemand screenshots

    Interesing thing is that this app was built on each phone using different technologies: FlashLite for Nokia 5320 and Java ME for SE W760, so, reproducing the same look&feel and functionalities with 2 traditionally so-different technologies.

    Since I currently have not an MTV SIM and phone, I cannot make a video of the app itself, but I’ll post it (and also post about the 2nd application ;) ) asap!

     
    • Alessandro 5:37 pm on July 20, 2008 Permalink

      Ciao Alessandro,

      looks like a great application, would love to try it!!
      Alessandro

    • pit 10:12 am on July 21, 2008 Permalink

      Ciao Alessandro!

      Thanks for your feedback!

      Would be great to let you try them, but both the apps currently work only with the 2 MTV phones (and related SIMs).. my test SIM was cut off too, and I’m not able to test them anymore… :-(

      Pit

    • Li Yong Fei 1:46 pm on July 21, 2008 Permalink

      Very cool application,!

    • Jukka 4:20 pm on July 22, 2008 Permalink

      Hi Pit,
      great apps! Shows very good the possibilities of Flash Lite.
      Big thanks for promoting us :)

  • pit 1:39 pm on June 23, 2008 Permalink | Reply
    Tags: , , java me, 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:

     
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