Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<h2>Background image</h2> <p>In Screen class there is a <a href="http://www.blackberry.com/developers/docs/4.5.0api/net/rim/device/api/ui/Screen.html#paintBackground(net.rim.device.api.ui.Graphics)" rel="noreferrer">protected void paintBackground(Graphics graphics)</a> method.<br> By some reason we can't use it directly to paint background image in screen. The catch: paintBackground method is derived from Field class, and we can use it in VerticalFieldManager on example: </p> <pre><code>class BgScreen extends MainScreen implements FieldChangeListener { ButtonField mButton; public BgScreen(Bitmap background) { super(); BGVerticalFieldManager manager = new BGVerticalFieldManager(background); add(manager); mButton = new ButtonField("Button", ButtonField.CONSUME_CLICK); mButton.setChangeListener(this); manager.add(mButton); } public void fieldChanged(Field field, int context) { if (mButton == field) Dialog.inform("You pressed button"); } } class BGVerticalFieldManager extends VerticalFieldManager { Bitmap mBgBitmap = null; int mBgWidth = -1; int mBgHeight = -1; int mBgX = -1; int mBgY = -1; public BGVerticalFieldManager(Bitmap background) { super(USE_ALL_WIDTH | USE_ALL_HEIGHT); mBgBitmap = background; mBgWidth = mBgBitmap.getWidth(); mBgHeight = mBgBitmap.getHeight(); mBgX = (Display.getWidth() - mBgWidth) &gt;&gt; 1; mBgY = (Display.getHeight() - mBgHeight) &gt;&gt; 1; } protected void paintBackground(Graphics graphics) { paintBackgroundBitmap(graphics); super.paintBackground(graphics); } private void paintBackgroundBitmap(Graphics graphics) { if (null != mBgBitmap) { graphics.drawBitmap( mBgX, mBgY, mBgWidth, mBgHeight, mBgBitmap, 0, 0); } } } </code></pre> <h2>GIF animation</h2> <p>To use GIF animation, override <a href="http://www.blackberry.com/developers/docs/4.5.0api/net/rim/device/api/ui/Screen.html#paint(net.rim.device.api.ui.Graphics)" rel="noreferrer">protected void paint(Graphics graphics)</a> method and use <a href="http://www.blackberry.com/developers/docs/4.5.0api/net/rim/device/api/ui/Graphics.html#drawImage(int,%20int,%20int,%20int,%20net.rim.device.api.system.EncodedImage,%20int,%20int,%20int)" rel="noreferrer">drawImage</a> of incremented frame index. Use <a href="http://www.blackberry.com/developers/docs/4.5.0api/java/util/Timer.html#scheduleAtFixedRate(java.util.TimerTask,%20long,%20long)" rel="noreferrer">Timer.scheduleAtFixedRate</a> to invalidate field: </p> <pre><code>class GIFVerticalFieldManager extends VerticalFieldManager { EncodedImage mGIFImage = null; int mGIFWidth = -1; int mGIFHeight = -1; int mGIFX = -1; int mGIFY = -1; int mGIFFrameCount = -1; int mGIFFrameIndex = -1; final int mGIFDelay = 30; public GIFVerticalFieldManager(EncodedImage gifAnimation) { super(USE_ALL_WIDTH | USE_ALL_HEIGHT); mGIFImage = gifAnimation; mGIFWidth = mGIFImage.getWidth(); mGIFHeight = mGIFImage.getHeight(); mGIFX = (Display.getWidth() - mGIFWidth) &gt;&gt; 1; mGIFY = (Display.getHeight() - mGIFHeight) &gt;&gt; 1; mGIFFrameCount = mGIFImage.getFrameCount(); mGIFFrameIndex = 0; Timer timer = new Timer(); timer.scheduleAtFixedRate(new TimerTask() { public void run() { invalidate(); } }, mGIFDelay, mGIFDelay); } protected void paint(Graphics graphics) { paintGifAnimation(graphics); super.paint(graphics); } private void paintGifAnimation(Graphics graphics) { if (null != mGIFImage) { graphics.drawImage( mGIFX, mGIFY, mGIFWidth, mGIFHeight, mGIFImage, mGIFFrameIndex, 0, 0); mGIFFrameIndex++; if (mGIFFrameIndex &gt; mGIFFrameCount - 1) mGIFFrameIndex = 0; } } } </code></pre> <p><strong>EDIT:</strong> Great article - <a href="http://na.blackberry.com/eng/devjournals/resources/journals/jan_2006/direct_screen_drawing.jsp" rel="noreferrer">Direct Screen Drawing</a></p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload