login | new user? join now!
Mobile
         
 

Categories

» Java
» Symbian
» iPhone
» Android
» Windows Mobile
» Others
» Blackberry RIM
Bookmark and Share

 

 This is the code of custom List item implementation with marquee effect. I don’t think it’s a fully bug free code or it’s good on coding standards but it will give you some idea about custom item.

CustomList class implementation:

import javax.microedition.lcdui.*;

// implementation of a MIDP 2.0

// custom item List with marquee effect.

public class CustomList extends CustomItem implements Runnable{

    private Display _display;

    private String[] _listelements;

    private final static int UPPER = 0;

    private final static int IN = 1;

    private final static int LOWER = 2;

    private int status = IN;

    private int index=1;

    private boolean mTrucking;

    private int move=10;

    private long mDelay=100;

 

    public CustomList( String label,Display display,String[] listelements){

        super( label );

        _display = display;

        _listelements = listelements;

        start();

    }

 

    // Returns the minimal height of the content

    // area.

 

    protected int getMinContentHeight(){

       

        return 250;

    }

 

    // Returns the minimal width of the content

    // area.

 

    protected int getMinContentWidth(){

        return 250;

    }

 

    // Returns the preferred height of the content

    // area. A tentative value for the opposite

    // dimension -- the width -- is passed to aid

    // in the height calculation. The tentative value

    // should be ignored if it is -1.

 

    protected int getPrefContentHeight( int width ){

        return getMinContentHeight();

    }

 

    // Returns the preferred width of the content

    // area. A tentative value for the opposite

    // dimension -- the height -- is passed to aid

    // in the width calculation. The tentative value

    // should be ignored if it is -1.

 

    protected int getPrefContentWidth( int height ){

        return getMinContentWidth();

    }

 

    public String getSelectedString(){

        return _listelements[index-1];

    }

 

    public void start() {

        mTrucking = true;

        Thread t = new Thread(this);

        t.start();

    }

 

    public void stop() {

        mTrucking = false;

    }

    // Draws the item's content area, whose dimensions

    // are given by the width and height parameters.

 

    protected void paint( Graphics g, int width, int height ){

        g.setFont(Font.getDefaultFont());

        g.setColor( 255, 255, 255 );

        g.fillRect( 0, 0, width, height );

        g.setColor(0xabcdef);

 

        g.fillRect(0, g.getFont().getHeight()*(index*2), width, g.getFont().getHeight());

 

        g.setColor(0x000000);

        for(int i=1;i<=_listelements.length;i++){

            //for marquee effect

            if(i==index)

                g.drawString(_listelements[i-1], move, g.getFont().getHeight()*(i*2), Graphics.TOP|Graphics.LEFT);

            else

        g.drawString(_listelements[i-1], 10, g.getFont().getHeight()*(i*2), Graphics.TOP|Graphics.LEFT);

      

        }

       }

page 2

Comments:
Post Your Comment
Rate this article
Name
Email
Comment