Package com.ael

Source Code of com.ael.IndexMenu

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

package com.ael;

import javax.microedition.lcdui.Canvas;
import javax.microedition.lcdui.CommandListener;
import javax.microedition.lcdui.Graphics;
import javax.microedition.lcdui.Font;
import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.Displayable;
/**
*
* @author akassimi
*/
public class IndexMenu extends Canvas implements CommandListener
{
    private QuranMobile _quranMobile;
    private Command _cmdMenu;
    private int _selected;
    private int _width;
    private int _height;

    public IndexMenu(QuranMobile _quranMobile)
    {
        this._quranMobile = _quranMobile;
        _selected = 0;
        setFullScreenMode(true);
        _width = getWidth();
        _height = getHeight();
        _cmdMenu = new Command("Menu",Command.SCREEN, 1);
        addCommand(_cmdMenu);
        setCommandListener(this);

    }
    protected void paint(Graphics g)
    {
        Font f = Font.getFont(Font.FACE_MONOSPACE, Font.STYLE_PLAIN,
                Font.SIZE_SMALL);
        g.setFont(f);
        int fHeight = g.getFont().getHeight();
        int suratesPerColumn = _height / fHeight - 2;
        int suratesToView = 2 * suratesPerColumn;

        g.setColor(0x00FFFFFF);
        g.fillRect(0, 0, _width, _height);

        int start = (_selected / suratesToView) * suratesToView;

        int currentHeight = fHeight;
        boolean firstColumn = true;
        int currentWidth;
        int maxw = -1;
        int decw = _width / 10;
       
        for(int i = start;i < start + suratesToView && i < 114;++i)
        {
            String s = Utilities.getSurates()[i];
            int w = Utilities.getSize(s, g);
           
            if(firstColumn)
            {
               
                if(maxw < w)
                {
                    maxw = w;
                }
                currentWidth = _width - w - decw;
            }
            else
            {
                currentWidth = _width - w - decw - maxw;
            }
            if(i == _selected)
            {
                g.setColor(0x0000FF00);
            }
            else
            {
                g.setColor(0x0);
            }
            g.drawString(s, currentWidth, currentHeight, 0);

            currentHeight += fHeight;
            if(currentHeight + 2 * fHeight > _height)
            {
                currentHeight = fHeight;
                firstColumn = false;
            }
        }
    }

    public void keyPressed(int keyCode)
    {
        if(keyCode == KEY_NUM2)
        {
            _selected = (_selected + 113) % 114;
            repaint();
        }
        else if(keyCode == KEY_NUM8)
        {
            _selected = (_selected + 1) % 114;
            repaint();
        }
        else if(keyCode == KEY_NUM5)
        {
            int page = Utilities.getStartingPage(_selected + 1);
            _quranMobile.gotoPage(page);
        }
    }
    public void commandAction(Command c, Displayable d)
    {
        if(c == _cmdMenu)
        {
            _quranMobile.gotoMainMenu();
        }
    }
   
}
TOP

Related Classes of com.ael.IndexMenu

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.