Atendendo a pedidos, segue o código do componente para animação de botões para LWUIT - Ginga-J.
001 002 003 004 005 006 007 008 009 010 011 012 013 014 015 016 017 018 019 020 021 022 023 024 025 026 027 028 029 030 031 032 033 034 035 036 037 038 039 040 041 042 043 044 045 046 047 048 049 050 051 052 053 054 055 056 057 058 059 060 061 062 063 064 065 066 067 068 069 070 071 072 073 074 075 076 077 078 079 080 081 082 083 084 085 086 087 088 089 090 091 092 093 094 095 096 097 098 099 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 | package org.gvlabs.sbtvd.ui; import com.sun.dtv.lwuit.Button; import com.sun.dtv.lwuit.Graphics; import com.sun.dtv.lwuit.Image; /** * Animated Button * * @author Thiago Galbiatti Vespa * @version 1.0 */ public class AnimatedButton extends Button { private int speed = 50 ; private Image[] animaImgs; private int currentImage = 0 ; private long lastInvoke; private boolean forward = true ; private boolean backAndForth = true ; private boolean loop = true ; private boolean disableLoop = false ; /** * Default constructor */ public AnimatedButton() { } /** * Get array of images * @return array of images */ public Image[] getAnimaImgs() { return animaImgs; } /** * Set array of images to be animated * @param animaImgs array of images */ public void setAnimaImgs(Image[] animaImgs) { this .animaImgs = animaImgs; if (animaImgs != null && animaImgs.length > 0 ) { this .setIcon(animaImgs[ 0 ]); } } /** * Get animation speed is ms * @return animation speed */ public int getSpeed() { return speed; } /** * Set animation speed in ms * @param speed animation speed */ public void setSpeed( int speed) { this .speed = speed; } /** * Back and Forth animation * @return true if is a back and forth animation */ public boolean isBackAndForth() { return backAndForth; } /** * Set back and forth animation value * @param backAndForth */ public void setBackAndForth( boolean backAndForth) { this .backAndForth = backAndForth; } /** * Is loop? * @return true if is a loop animation */ public boolean isLoop() { return loop; } /** * true = loop, false = one animation * @param loop */ public void setLoop( boolean loop) { this .loop = loop; } public boolean animate() { if (disableLoop) return false ; long current = System.currentTimeMillis(); if (current - lastInvoke > speed) { lastInvoke = current; if (forward) { currentImage++; } else { currentImage--; } if (currentImage >= animaImgs.length) { if (!loop) { disableLoop = true ; return false ; } else if (!backAndForth) { forward = true ; currentImage = 0 ; } else { forward = false ; currentImage = animaImgs.length - 1 ; } } else if (currentImage < 0 ) { forward = true ; currentImage = 0 ; } return true ; } return false ; } /* (non-Javadoc) * @see com.sun.dtv.lwuit.Button#paint(com.sun.dtv.lwuit.Graphics) */ public void paint(Graphics g) { g.drawImage(animaImgs[currentImage], getX(), getY()); } } |
Para utilizar é só atribuir o conjunto de imagens para o método setAnimaImgs e registrar a animação no formulário, por exemplo: form.registerAnimation(animatedButton);
Botão Animado em LWUIT – Ginga: Atendendo a pedidos, segue o código do componente para anim... http://t.co/Hab5ZsZKmG (via @thiagovespa)
Show de bola Thiago, mamão com açucar para utilizar! agora consigo aplicar imagens animadas para dar o efeito do gif animado!!!
Olá Thiago, parabéns pelo trabalho!
Estou desenvolvendo, para um TCC, uma aplicação cujo foco é a mineração de dados para tv digital, no entanto, queria fazer uma GUI bem simples usando o xletview, com um formulário. Acho que o xletview não suporta lwuit, vc sabe que bibliotecas poderiam ser usadas para criar botões, textbox e outros componentes de formulários?
Desde já muito grato!
O Xletview não tem quase nada a ver com a implementação do modelo de tv brasileira. Você utilizar ele não vai ser perda de tempo?