Messages by raz2009

2 topics, 5 messages
Kuix general board » Animating GIF image freezes the app

Hi eveybody! I've written a custom widget to play GIF animated images by extending the Picture widget and the Sprite
class. This is my GifSprite:

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package org.kalmeo.kuix.util;

import java.io.IOException;
import javax.microedition.lcdui.Image;
import javax.microedition.lcdui.game.Sprite;
import org.kalmeo.kuix.widget.GIFPicture;

/**
 *
 * @author Administrator
 */
public class GifSprite extends Sprite implements Runnable{

    GifDecoder decoder;
    GIFPicture widget = null;
    boolean animated = false;
   
    public GifSprite(String  imageUrl, GIFPicture w) throws Exception{
        super(Image.createImage(imageUrl));
        this.widget = w;
        decoder = new GifDecoder();
        if (decoder != null) {

            int err = decoder.read(imageUrl);
            if (err == 0) {

                setImage(decoder.getImage(), decoder.getImage().getWidth(),decoder.getImage().getHeight() );
            } // end if
        } // end if
    }

    public GifSprite(Image image, int frameWidth, int frameHeight) {
        super(image, frameWidth, frameHeight);
    }

    public GifSprite(Image image) {
        super(image);
    }

    public void animate(){
        if(animated)
            return;
        animated = true;
        new Thread(this).start();
    }

    public void stopAnimation(){
        animated = false;
//        setImage(decoder.getFrame(0), decoder.getFrame(0).getWidth(), decoder.getFrame(0).getHeight());
//        widget.invalidateAppearance();
    }

    public void run() {
        int t;
        while(animated){
            if(decoder == null)
                continue;
            int n = decoder.getFrameCount();
            for (int i = 0; i < n; i++) {
                t = decoder.getDelay(i);
                setImage(decoder.getFrame(i), decoder.getFrame(i).getWidth(), decoder.getFrame(i).getHeight());
                widget.invalidateAppearance();
              
                try {
                    Thread.sleep(t);
                } catch (InterruptedException ex) {
                    ex.printStackTrace();
                }
            }
        }
    }

}

And I then extend the Picture widget by replace the original sprite by mine and made the following modifications:

 public GIFPicture setSource(String source) {
  if ((source == null) || (source.length() == 0)) {
   return this;
  }
                String imgsrc=new StringBuffer(KuixConstants.DEFAULT_IMG_RES_FOLDER).append(source).toString();
                try {
                    sprite = new GifSprite(imgsrc, this);
                } catch (Exception ex) {
                    ex.printStackTrace();
                }
  
  return this;
 }
.......
.......

        public void setVisible(boolean v){
            super.setVisible(v);
            if(!v){
                action = false;
                sprite.stopAnimation();
            }else{
                action = true;
                sprite.animate();
            }
        }
  
And at the end of the doLayout() method I added the following line:
 sprite.animate();
 
Also I clean up and call removeALL() method of all my screen when they are not more displayed and that their
Frame is removed from the FrameHandler list (This is just to free the memory).
Despite all this the Gif plays well and the application works fine on the emulator but freezes on real device. From one run to another some times it doesn't froze at the same point. But if I replace the GifPicture in the screen by a common Picture widget, evrything
works ok.

So please tell me what am I doing wrong or is there a tip that I don't know I should use?

P.S: I'm using two phone to test my applications : NOKIA 6500 and NOKIA E51-1. I tried a SonyEcricsson S312 but the Gif doesn't play on it.

Regards!

Kuix technical support » Direct textfield input

Please Venky could you just post your code, that willbe very kin of yours cuz many of us (kuix users) are facing the same problem, and I think we should join our effort to write a complete custom textfield widget for that with support for at least maximun number of keybords.

Best regards!

Kuix technical support » Textfield constrains

Please maybe there's another thread about the same topic but I couldn't find it. Just wanted to know how it is possible to add more than one constrains to a textfield from xml file just like "numeric and password". If there is anyway to do it please let me know.

Thanks!

Kuix technical support » retrieving image via HTTP and Display in a popup...

Please can you just post some code about you googleMap class; just to let us (me) know how to retrive a google map image from my mobile phone.

Thanks!

Kuix general board » What do you think about Kuix ?

I haven't use Kuix yet but at first impression is seems to be very nice with good XML/CSS approach  and cannot say it's heavy compare to lwuit (more than 300kb after built). Just hope handling user events is quite easy like with lwuit.