Namespaces
Variants
Actions
Revision as of 09:19, 6 August 2012 by hamishwillee (Talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Barra de loading simples, usando Canvas, em Java ME

Jump to: navigation, search
MultiMediaTile.png
Dados do artigo

Artigo
Tradução:
Por TK2000
Última alteração feita por hamishwillee em 06 Aug 2012

Este é um exemplo de uma simples barra de 'loading' baseada no 'Canvas', você pode utiliza-la como uma 'splash screen' (tela de inicialização) para sua aplicação.

Primeiro criamos o 'Canvas' da aplicação e pegamos a largura (width) e a altura (height) da tela:

height = getHeight();
width = getWidth();

Em seguida preparamos um "fator" para a incrementação do 'loading':

factor = width / 4;

Também criamos um objeto Timer:

Timer timer = new Timer();

Este é o código que será usado no método 'paint' de nosso Canvas:

g.setColor(0x00ffccff);
g.fillRect(0, 0, width, height);
g.setColor(0x00ffffff);
g.fillRect(25, height / 2, width - 50, 2);
g.setColor(0x003399ff);
g.drawString("Application name", 100, (height / 2) - 30, Graphics.TOP | Graphics.HCENTER);
g.fillRect(25, height / 2, current, 2);
g.drawString("Loading...", 100, (height / 2) + 20, Graphics.BOTTOM | Graphics.HCENTER);

Em seguida criamos a classe que irá herdar/extender de TimerTask, dentro de nossa classe Canvas, para manipular a animação:

     private class Draw extends TimerTask {
public void run() {
current = current + factor;
if (current > width - 50) {
current = 0;
repaint();
} else {
repaint();
}
}
}

No construtor do MIDlet, nós programamos o objeto 'timer' para ser ser executador:

repaint();
timer.schedule(new Draw(), 2000, 2000);

Precisamos criar agora um objeto do tipo Canvas, em nosso MIDlet, e exibir nossa barra de 'loading'.

114 page views in the last 30 days.
Nokia Developer aims to help you create apps and publish them so you can connect with users around the world.

京ICP备05048969号  © Copyright Nokia 2013 All rights reserved