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
EpicDraws
Posts: 109
Registered: ‎02-09-2009
My Device: Not Specified
Accepted Solution

Problem with Background Images and scrolling

I have been battling for a while to get background images work correctly. Here is what I do:

 

  VerticalFieldManager vfm = new VerticalFieldManager();

Bitmap map = Bitmap.getBitmapResource("MyImage.jpg");

       Background bg = BackgroundFactory.createBitmapBackground(map);

     vfm.setBackground(bg);

 

This works but has a pitfall. First of all, it only paints as much as you have fields taking up space, so I have to add blank fields just to take up vertical space. However, on a page with something like a listField, where the height is variable, this can lead to having the background image start to repeat and allow scrolling.

 

What I want to do is block all scrolling and have the background exactly fill the screen with no scrolling or white blank places.

 

Am I just going about this wrong? Would realy love some help... 

Please use plain text.
Developer
bikas
Posts: 984
Registered: ‎02-10-2009
My Device: Not Specified

Re: Problem with Background Images and scrolling

Hi Epicdraw,

 

You can try this.

 

 

verticalManager = new VerticalFieldManager(Manager.VERTICAL_SCROLL | Manager.VERTICAL_SCROLLBAR) { public void paint(Graphics graphics) { graphics.setBackgroundColor(Color.BLACK); graphics.clear(); super.paint(graphics); } protected void sublayout( int maxWidth, int maxHeight ) { int displayWidth = Display.getWidth(); int displayHeight = Display.getHeight(); super.sublayout( displayWidth, displayHeight); setExtent( displayWidth, displayHeight); } };

 

Regards

Bikas

Please use plain text.
Developer
EpicDraws
Posts: 109
Registered: ‎02-09-2009
My Device: Not Specified

Re: Problem with Background Images and scrolling

How can I make that work with the bitmaps?
Please use plain text.
Developer
Rajat_10Sep
Posts: 696
Registered: ‎12-02-2008
My Device: Not Specified

Re: Problem with Background Images and scrolling

Hi,

 

Hope this piece of code will help you.Instead of using Background API i had used paint () for this purpose as this API was made available in JDE 4.7 only.

 

 

import net.rim.device.api.ui.container.MainScreen; import net.rim.device.api.ui.container.VerticalFieldManager; import net.rim.device.api.ui.component.BitmapField; import net.rim.device.api.ui.Graphics; import net.rim.device.api.ui.Field; import net.rim.device.api.ui.component.ListField; import net.rim.device.api.ui.component.ListFieldCallback; import net.rim.device.api.system.Bitmap; import net.rim.device.api.ui.Manager; class MSBMainScreen extends MainScreen implements ListFieldCallback { String Data[] = {"Task ID","Priority","Task Name","Location","Task Type","State","AAA","BBB","CCCC","DDD","EEE","FFFF","GGGG","HHHH","IIII"}; private VerticalFieldManager objManager; private Bitmap objBitmap; ListField objList = null; public MSBMainScreen(){ super(); drawComponent(); setTitle( "Inbox Screen" ); objBitmap = Bitmap.getBitmapResource( "watermark.png"); objManager = new VerticalFieldManager( Manager.VERTICAL_SCROLL | Manager.VERTICAL_SCROLLBAR ) { protected void paint( Graphics g ){ int y = MSBMainScreen.this.getMainManager().getVerticalScroll(); g.drawBitmap( 0, y, objBitmap.getWidth(), objBitmap.getHeight(), objBitmap, 0, 0 ); super.paint( g ); } protected boolean keyDown( int keycode, int status ){ invalidate(); return super.keyDown( keycode, status ); } protected boolean navigationMovement( int dx, int dy, int status, int time ){ invalidate(); return super.navigationMovement( dx, dy, status, time ); } protected int moveFocus(int amount, int status, int time){ invalidate(); return super.moveFocus(amount, status, time); } }; add(objList); super.add( objManager ); } public void add( Field field ){ objManager.add( field ); } public void delete( Field field ){ objManager.delete( field ); } public void drawListRow(ListField listField, Graphics g, int index, int y, int width){ g.drawText(Data[index], /*10*/10, /*CTIAMain.ROW_HEIGHT*index*/y ); } public int indexOfList(ListField listField, String prefix, int start){ return 0; } public Object get(ListField listField, int index){ return Data[index]; } public int getPreferredWidth(ListField listField){ return 0; } private void drawComponent(){ objList = new ListField(Data.length); objList.setCallback(this); } }

 

 

 

Regards,
Rajat Gupta.
--------------------------------------------------------------------------------
If your problem was get solved then please mark the thread as "Accepted solution" and kudos - your wish
Please use plain text.
Developer
EpicDraws
Posts: 109
Registered: ‎02-09-2009
My Device: Not Specified

Re: Problem with Background Images and scrolling

Is there some way to just change what I have a bit? Its currently pretty simple, and the other solution posted looks quite a bit more involved.
Please use plain text.
Developer
Rajat_10Sep
Posts: 696
Registered: ‎12-02-2008
My Device: Not Specified

Re: Problem with Background Images and scrolling

Hi,

 

Sorry there is on other way.

 

I am also doing the same thing what you are doing.I had used one verticalFieldManager and overided it's function so that image gets repainted in different secenarios like when you are moving in the list etc.

 

There might be different solution to this problem but real problem comes when you draw listfield over an image.In that case image do not get repainted properly.For this problem this the only solution.

Regards,
Rajat Gupta.
--------------------------------------------------------------------------------
If your problem was get solved then please mark the thread as "Accepted solution" and kudos - your wish
Please use plain text.
Developer
EpicDraws
Posts: 109
Registered: ‎02-09-2009
My Device: Not Specified

Re: Problem with Background Images and scrolling

At no point will the listField be big enough to require scrolling though, so I want to disable that.
Please use plain text.
Developer
Rajat_10Sep
Posts: 696
Registered: ‎12-02-2008
My Device: Not Specified

Re: Problem with Background Images and scrolling

Hi,

 

Hope this will help you.

 

class LoginScreen extends MainScreen {
//Manager
private VerticalFieldManager _manager;

LoginScreen() {
//Set Background image
_manager = (VerticalFieldManager)getMainManager();
Background bg = BackgroundFactory.createBitmapBackground(Bitmap.getBitmapResource("back.png"));
_manager.setBackground(bg);


}
}

 Add this manageron your screen do not add any other component in this manager.

 

 Add you fields in other manager and add that manager on screen.

 

Let me know if this solves your problem or not.

Regards,
Rajat Gupta.
--------------------------------------------------------------------------------
If your problem was get solved then please mark the thread as "Accepted solution" and kudos - your wish
Please use plain text.
Developer
EpicDraws
Posts: 109
Registered: ‎02-09-2009
My Device: Not Specified

Re: Problem with Background Images and scrolling

Works perfect!
Please use plain text.
Developer
Rajat_10Sep
Posts: 696
Registered: ‎12-02-2008
My Device: Not Specified

Re: Problem with Background Images and scrolling

hi,

 

Please close the thread.

Regards,
Rajat Gupta.
--------------------------------------------------------------------------------
If your problem was get solved then please mark the thread as "Accepted solution" and kudos - your wish
Please use plain text.