I have a class like this that pushes to the stack a new screen that is a picture (jpeg, gif or something). In the case i have an animated gif I have a problem with displaying the frames of the gif. Here is my class:
Code:
public class FullScreenBanner extends MainScreen {
private int bannerWidth;
private int bannerHeight;
private int wFrame;
private int hFrame;
private int lOffset = 0;
private int tOffset = 0;
private EncodedImage encodedImage;
private Bitmap fullScreen;
private int index = 0;
private int backgroundColor;
/**
* Constructor
*
* @param fullScreenBanner - byte array
*/
public FullScreenBanner(byte[] fullScreenBanner, int color) {
super(Manager.NO_VERTICAL_SCROLL);
encodedImage = EncodedImage.createEncodedImage(fullScreenBanner, 0, fullScreenBanner.length);
wFrame = bannerWidth = encodedImage.getWidth();
hFrame = bannerHeight = encodedImage.getHeight();
if (encodedImage.getImageType() == EncodedImage.IMAGE_TYPE_GIF) {
getNextFrame();
} else {
fullScreen = Bitmap.createBitmapFromBytes(fullScreenBanner, 0, -1, 1);
}
this.backgroundColor = color;
}
protected void paint(Graphics g) {
g.setBackgroundColor(backgroundColor);
int wp = (Display.getWidth() + bannerWidth) / 2;
int wm = (Display.getWidth() - bannerWidth) / 2;
int hp = (Display.getHeight() + bannerHeight) / 2;
int hm = (Display.getHeight() - bannerHeight) / 2;
g.clear(0, 0, wp, hm);
g.clear(wp, 0, wm, hp);
g.clear(0, hm, wm, hp);
g.clear(wm, hp, wp, hm);
g.drawBitmap(wm + lOffset, hm + tOffset, wFrame, hFrame, fullScreen, 0, 0);
}
private void getNextFrame() {
index = 0;
TimerTask ttask = new TimerTask() {
public void run() {
fullScreen = encodedImage.getBitmap(index);
GIFEncodedImage gif = (GIFEncodedImage) encodedImage;
lOffset = gif.getScaledFrameLeft(index);
tOffset = gif.getScaledFrameTop(index);
wFrame = gif.getFrameWidth(index);
hFrame = gif.getFrameHeight(index);
if (index == (gif.getFrameCount() - 1)) {
index = -1;
}
index++;
UiApplication.getUiApplication().getActiveScreen().invalidate();
}
};
GIFEncodedImage gif = (GIFEncodedImage) encodedImage;
new Timer().scheduleAtFixedRate(ttask, gif.getFrameTransition(index) * 100,
gif.getFrameDelay(index) * 10);
}
protected void onFocus(int direction) {
super.onFocus(direction);
}
protected boolean trackwheelClick(int status, int time) {
return true;
}
}
I have a timer task that gets the next frame and its offsets and a timer that execute the task. When I have a frame smaller than the gif size the frame under is gone out. I mean that every time when the area is repainting itself the old content is missing but i need it because the old frame of the gif is a part of the new one. Do u understand what i mean ?