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
Posts: 52
Registered: ‎11-03-2008
My Device: Not Specified
Accepted Solution

Implement own Custom Manager

Hi all,

 

I wish to implement my own Manager for my screen. Basically, I want to move around over an area that consists of bitmap field tiles i.e. say I wish to have a manager that contains 9 tiles of 200x200 bitmap fields; but the visible region of the manager is also 200x200 so that it can display only a single tile at a time. And I want to move around up, down, left and right to view other tiles as well.

 

I have created a class that extends Manager class, have overridden the 3 methods as well - getPreferredWidth(), getPreferredHeight() and sublayout(). Then I created an instance of this class in my screen class.

 

Is this the right way of doing it ? If yes, I am still not able to see anything on my screen. Could anyone please help me out ?

 

 

Thanks & regards

- Arun

Developer
Posts: 507
Registered: ‎07-15-2008
My Device: Not Specified

Re: Implement own Custom Manager

Check this link:

 

http://www.blackberry.com/knowledgecenterpublic/livelink.exe/fetch/2000/348583/800332/800505/800508/...

----------------
if your issue solved set "Solution" mark at the relevant post
Developer
Posts: 52
Registered: ‎11-03-2008
My Device: Not Specified

Re: Implement own Custom Manager

Thanks for the quick response rafo !

 

Yes I already referred to that piece of code. I too have done it the same way but I am still not able to see anything.

Developer
Posts: 696
Registered: ‎12-02-2008
My Device: Not Specified

Re: Implement own Custom Manager

Hi,

 

Try setting style in your constructor as HORIZONTAL_SCROLL or RIGHTMOST or VERTICAL_SCROLL

 

Below I am providing you some code this code is not exactly doing what you want but may be help you out

 

protected boolean keyChar( char c, int status, int time ) {
            switch( c ) {
                  case Characters.SPACE:
                         if ((status & KeypadListener.STATUS_SHIFT) == 0) {
                                     scroll( Manager.DOWNWARD );
                            } else {
                                       scroll( Manager.UPWARD );
                              }
                              return true;
                   case 't':
                              scroll( Manager.TOPMOST );
                             return true;
                   case 'b':
                              scroll( Manager.BOTTOMMOST );
                          return true;
           }
             
        return super.keyChar(c, status, time);
        }

Regards,
Rajat Gupta.
--------------------------------------------------------------------------------
If your problem was get solved then please mark the thread as "Accepted solution" and kudos - your wish
Developer
Posts: 52
Registered: ‎11-03-2008
My Device: Not Specified

Re: Implement own Custom Manager

[ Edited ]

Scrolling is not the issue right now, the Screen just doesnt show anything even initially. How should I set or change the visible / focused area of the manager class ?

 

Here is the code...

 

********************************************************************************************************************************************************************

/*
 * LayoutManager.java
 *
 * © <your company here>, 2003-2005
 * Confidential and proprietary.
 */

package src;

//  IMPORTS ------------------------------------------------------------------------------------------

import net.rim.device.api.ui.Manager;
import net.rim.device.api.ui.Field;
import net.rim.device.api.ui.component.BitmapField;
//import net.rim.device.api.ui.container.HorizontalFieldManager;
//import net.rim.device.api.ui.container.VerticalFieldManager;
import java.util.Vector;
import src.Constants;
import net.rim.device.api.ui.XYRect;
import net.rim.device.api.ui.Graphics;
import net.rim.device.api.system.Bitmap;

//  END -------------------------------------------------------------------------------------- IMPORTS

public class LayoutManager extends net.rim.device.api.ui.Manager
{
    //  MEMBER VARIABLES    --------------------------------------------------------------------------
  
    private Vector m_Fields;// = null;
   
    //  END -----------------------------------------------------------------------   MEMBER VARIABLES
   
    //  CONSTRUCTOR ----------------------------------------------------------------------------------
    public LayoutManager(Vector _Fields)
    {
        super(net.rim.device.api.ui.Manager.HORIZONTAL_SCROLLBAR | net.rim.device.api.ui.Manager.VERTICAL_SCROLLBAR);
        m_Fields = _Fields;
    }
   
   
    //  IMPLEMENTED METHODS ---------------------------------------------------------------------------
   
    //  1.
    protected void sublayout(int width, int height)
    {
        setExtent(this.getScreen().getWidth(), this.getScreen().getHeight());
        //LayoutFields();       
        return;
    }
   
    //  2.
    public int getPreferredWidth()
    {
        return (Constants.TILE_ROWS * Constants.TILE_WIDTH);
    }
   
    //  3.
    public int getPreferredHeight()
    {
        return (Constants.TILE_COLUMNS * Constants.TILE_HEIGHT);
    }


    //  END ---------------------------------------------------------------------   IMPLEMENTED METHODS
   
    //  Laying out fields   ---------------------------------------------------------------------------
    public void LayoutFields()
    {
        try
        {
            int nX = 0;
            int nY = 0;
            int nBmpCount = 0;
            String strBmpResource = "";
            //this.deleteAll();
            for(int nRow = 0; nRow < Constants.TILE_ROWS; nRow++)
            {
                try
                {
                    for(int nCol = 0 ; nCol < Constants.TILE_COLUMNS; nCol++)
                    {
                        try
                        {
                            //  Add bitmap, one by one, upto maximum of 3 (in each row)
                            Bitmap bmpMapTile = (Bitmap)m_Fields.elementAt(nBmpCount);
                            XYRect _Rect = new XYRect(nX, nY, Constants.TILE_WIDTH, Constants.TILE_HEIGHT);
                            Graphics graphics = new Graphics(bmpMapTile);
                            graphics.drawBitmap(_Rect, bmpMapTile, 0,0);
                           
                            //  Increment BmpCounter
                            nBmpCount++;
                            nX += Constants.TILE_WIDTH;
                        }
                        catch(Exception Ex)
                        {
                            continue;
                        }
                    }
                    nX = 0;
                    nY += Constants.TILE_HEIGHT;
                }
                catch(Exception Ex)
                {
                    continue;
                }
               
            }
            
        }
        catch(Exception Ex)
        {
            this.deleteAll();
            return;
        }
    }
     
       
}

********************************************************************************************************************************************************************

Message Edited by arunsingh on 05-15-2009 05:48 AM
Developer
Posts: 696
Registered: ‎12-02-2008
My Device: Not Specified

Re: Implement own Custom Manager

[ Edited ]

Hi,

 

I think you are first setting the extent and then laying out your fields.

 

Do it other way first lay your fields and then call setExtent().

 

protected void sublayout(int width, int height) {
       Field field;
       //get total number of fields within this manager
       int numberOfFields = getFieldCount();
       int x = 0;
       int y = 0;
       for (int i = 0;i < numberOfFields;i++) {
           field = getField(i); //get the field
           setPositionChild(field,x,y); //set the position for the field
           layoutChild(field, width, height); //lay out the field

           y += ...;
           ...
       }
       setExtent(width, height);
   }

Message Edited by Rajat_10Sep on 05-15-2009 09:33 AM
Regards,
Rajat Gupta.
--------------------------------------------------------------------------------
If your problem was get solved then please mark the thread as "Accepted solution" and kudos - your wish
Developer
Posts: 52
Registered: ‎11-03-2008
My Device: Not Specified

Re: Implement own Custom Manager

Thanks Rajat !

 

I called the setExtent() function in the manager's sublayout() method and I used the setPosition and layoutChild methods. And fortunately I am able to do what I wished. But this is only a part of my task.

 

Now what I want to do is to move the visible area of the manager in all the four directions (one at a time) so that I may see some of the region of the other images as well.

 

How should I go about it ?

Developer
Posts: 696
Registered: ‎12-02-2008
My Device: Not Specified

Re: Implement own Custom Manager

Hi,

 

Try using VERTICAL_SCROLL and HORIZONTAL_SCROLL style while creating you manager.

Regards,
Rajat Gupta.
--------------------------------------------------------------------------------
If your problem was get solved then please mark the thread as "Accepted solution" and kudos - your wish
Developer
Posts: 52
Registered: ‎11-03-2008
My Device: Not Specified

Re: Implement own Custom Manager

[ Edited ]

I have already used that but it doesnt do anything. Moreover, I don't just want to enable the scrolling, I want to control it completely. For example, I have 9 image tiles in my manager of 200x200 each right now but only one of them is visible initially as I have set the extents of my manager to 200, 200.

 

Now I want to move, say 10 %, towards right. So that 90% of the original image and 10% of the image right next to it gets fit in the visible region of my manager. This is what I want to imlpement.

 

Thanks

- arun

Message Edited by arunsingh on 05-18-2009 06:24 AM
Developer
Posts: 52
Registered: ‎11-03-2008
My Device: Not Specified

Re: Implement own Custom Manager

[ Edited ]

Hi all,

 

Thanks for your replies. I am able to achieve what I asked above. I implemented my own ScrollListener class and handled scrolling there itself.

 

Now, can anyone please tell me how can I draw a shape or text with a transparent background ?

 

Thanks !

- arun

Message Edited by arunsingh on 05-19-2009 06:35 AM