Welcome to the Official BlackBerry® Support Community Forums. This is your resource to discuss support topics with your peers, and learn from each other. New to the forum? Please visit the ‘Getting Started’ link below.
inside custom component

Java Development

Reply
Developer
trivedirujuta
Posts: 192
Registered: 10-06-2009

Re: Storm landscape problem with images

No,I have already implemented the image resizing,it works but after a refresh,my problem is that I want to show the effect of tilting immediately.

Please use plain text.
Developer
peter_strange
Posts: 14,614
Registered: 07-14-2008

Re: Storm landscape problem with images

Which is ansered in my third point is it not?

Please use plain text.
Developer
trivedirujuta
Posts: 192
Registered: 10-06-2009

Re: Storm landscape problem with images

can you please explain that with some code snippet?please???

Please use plain text.
Developer
peter_strange
Posts: 14,614
Registered: 07-14-2008

Re: Storm landscape problem with images

Following is a sample sublayout. 

 

What you have in the layoutMyScreen() method will depend on what you want to do.  You could delete all the Fields from the screen and add new ones, or you could replace some Fields whose orientation changes, or you could just update Bitmaps. 

 

In this example, I have assumed that there are Field changes going on that will cause a re-layout of the Screen, so you must do it outside the sublayout() method.  It may be possible to do some of these things, for example, update Bitmaps, in sublayout(), however I would not do anything that involves a lot of processing there.  For example, I would not resize a Bitmap.  If you think you are going to need to resize a Bitmap, you should do it once at screen creation time, not every time your orientation changes.

 

Note that this is not real code, it is just something I mocked up to explain my suggestion (not compiled or tested in anyway, use at your own risk!).  Note that it assumes that layoutMyScreen() updates _displayHeight and _displayWdith and these variables are accessible.  This is code like I would put at a Screen level, I suspect you could do similar things at a Manager or Field Level if you wanted, so for example, you could have a Field that updates itself.  I've not done that, mainly becuase in the places I need to do this, I've taken a Screen view of the layout.  This is probably not the best way, having Fields look after themselves is a much more OO approach.  As noted right at the start, I'm not the best UI or even OO programmer on this forum.  Others may well have different and I suspect better approaches.

 

Hope this helps:

 

    protected final void sublayout(int width, int height) {
        if ( _displayHeight != Display.getHeight() ||
             _displayWdith != Display.getWidth()    ) {
            UiApplication.getUiApplication().invokeLater(new Runnable() {
                public void run() {
                    layoutMyScreen();
                }
            };
        }
        super.sublayout(width, height);
    }

 

Please use plain text.
Developer
trivedirujuta
Posts: 192
Registered: 10-06-2009

Re: Storm landscape problem with images

I have tried a lot according to your suggesion but its still not updating.It resizes after a refresh

Please use plain text.
Developer
peter_strange
Posts: 14,614
Registered: 07-14-2008

Re: Storm landscape problem with images

I suggest you use the debugger to determine why this is not happening for you.  Using sublayout in this way seems to work for me and other people too, so I think you are looking for something in your code that is different between a refresh and what happens in sublayout. 

 

Can your sublayout code not just do whatever your refresh code does?

Please use plain text.
Developer
trivedirujuta
Posts: 192
Registered: 10-06-2009

Re: Storm landscape problem with images

 protected final void sublayout(int width, int height) {

       if(Display.getWidth()!=checkwidth)//i want to just resize width
          {  UiApplication.getUiApplication().invokeLater(new Runnable() {
                public void run() {
                    checkwidth=Display.getWidth();
                    Status.show("change"+checkwidth);
                    layoutSScreen(checkwidth);
                 
                
                }
            });
    }
        super.sublayout(width, height);
    
    }

 

 

void layoutSScreen(int widh)

{

Tab tab=new Tab("My Tab",width,height);

 

//in this method i m passing width of the current screen to resize the image

Tab is my custom class that resizes the image and display text on tht like shown in image

}

9500.png

 

 

 

 

 

 

 

Please correct my mistake

 

Please use plain text.
Developer
peter_strange
Posts: 14,614
Registered: 07-14-2008

Re: Storm landscape problem with images

There are many potential places that you could have made a mistake.  Some, for example the Tab class, you do not include, so I have no hope of finding out what your problem is.

 

Nor do I think I need to.  You are quite capable I am sure of debugging this.  It will take time.  What I would do is go back to basics, get a screen that does work, then slowly try things until you find out what doesn't work.  I am not aware of any "magic" in here, it is all hard graft.

 

Sorry I can't be more helpful.

Please use plain text.
Developer
trivedirujuta
Posts: 192
Registered: 10-06-2009

Re: Storm landscape problem with images

Thanks,the problem is resolved finally!! I have done some mistake in custom class

Please use plain text.
Developer
davidmccormack
Posts: 168
Registered: 11-01-2008
My Carrier: Meteor (Ireland)

Re: Storm landscape problem with images

I must confess that I haven't read every post in this thread, so I might be missing the point a bit. But the following may be of use anyway, even if it's just to get a few ideas. It works a treat in my app and resizes nicely when the orientation of a Storm is changed.

 

 

    class AutoScaledBitmapField extends Field
    {
        private final EncodedImage m_image;
        private Bitmap m_scaledBitmap;
        
        AutoScaledBitmapField(EncodedImage image)
        {
            m_image = image;
        }
    
        public boolean isFocusable() { return false; }
        
        public int getPreferredWidth() { return m_image.getWidth(); }
        
        public int getPreferredHeight() { return m_image.getHeight(); }
        
        protected void layout(int width, int height)
        {
            // Set the extents of this control to use all available width and height.
            setExtent(width, height);
            
            // Cache a bitmap created from the image and scaled if necessary to fit the extent.
            m_scaledBitmap = getScaledBitmap(width, height);
        }
        
        protected void paint(Graphics graphics)
        {
            // Determine the offset within this field's extent
            // at which we will paint the bitmap so that it will
            // be centred in the space.
            int x = (getWidth() - m_scaledBitmap.getWidth()) / 2;
            int y = (getHeight() - m_scaledBitmap.getHeight()) / 2;
            
            // Paint the bitmap.
            graphics.drawBitmap(
                x,
                y,
                m_scaledBitmap.getWidth(),
                m_scaledBitmap.getHeight(),
                m_scaledBitmap,
                0,
                0);
        }
        
        private Bitmap getScaledBitmap(int maxWidth, int maxHeight)
        {
            // Determine if we need to scale the image.
            int fullImageWidth = m_image.getWidth();
            int fullImageHeight = m_image.getHeight();
            if (fullImageWidth > maxWidth || fullImageHeight > maxHeight)
            {
                // Calculate the scaling factor required for width and height.
                int widthScalingRequired = Fixed32.div(Fixed32.toFP(fullImageWidth), Fixed32.toFP(maxWidth));
                int heightScalingRequired = Fixed32.div(Fixed32.toFP(fullImageHeight), Fixed32.toFP(maxHeight));
                
                // Use the greater of the two scaling factors calculated.
                if (widthScalingRequired > heightScalingRequired)
                {
                    return m_image.scaleImage32(widthScalingRequired, widthScalingRequired).getBitmap();
                }
                else
                {
                    return m_image.scaleImage32(heightScalingRequired, heightScalingRequired).getBitmap();
                }
            }
            else
            {
                // The full image is small enough to use as is.
                return m_image.getBitmap();
            }
        }
    }

 

 

Please use plain text.