Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Reply
Developer
arunbiet
Posts: 376
Registered: ‎06-22-2010
My Device: na
My Carrier: blackberry developer

Animation in a bitmapfield

Nelow is my code for Animated BitmapField.Here the entire screen is fading IN-OUT.I want that only the portion in which i add BitmapField should fade IN-OUT and rest of the screen should not.How can i achive it.

 

package mypackage;
import java.util.Timer;

import net.rim.device.api.system.Bitmap;
import net.rim.device.api.ui.Graphics;
import net.rim.device.api.ui.component.BitmapField;

public class AnimBitmapField extends BitmapField {
	Timer animTimer = new Timer();
	Bitmap animBitmap;
	int alpha;
	
     AnimBitmapField(Bitmap myBitmap, long flags)
     {
    	 super(myBitmap, flags);
    	 animBitmap = myBitmap;
    	 alpha = 0;
     }
     
     void setAlpha(int newAlpha)
     {
    	 alpha = newAlpha;
    	 invalidate();
     }
     
     protected void paint(Graphics graphics)
     {
     graphics.setGlobalAlpha(alpha);
	 graphics.drawBitmap(0, 0, getWidth(), getHeight(), animBitmap, 0, 0);
	 System.out.println("AnimBitmapField::Paint");
     }
     
     protected void onDisplay()
     {
    	MyScreen.getTimer().schedule(new AnimTimerTask(this), 0,18); // 20 ms gives a full 10 seconds cycle for fade in/out    	 
     }
     
     protected void onUndisplay()
     {
    	MyScreen.getTimer().cancel();
     }
}

 Please help

Please use plain text.
Developer
simon_hain
Posts: 16,010
Registered: ‎07-29-2008
My Device: Z10 LE
My Carrier: O2 Germany

Re: Animation in a bitmapfield

i would try to store the current alpha, set it, draw the bitmap and then restore alpha to the previous value.
global sounds like it would be used on all drawing operations, even on another graphics object.
----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
Please use plain text.