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: 81
Registered: ‎06-24-2009
My Device: Not Specified

Re: PopupScreen with transparent background and theme for Storm

Anyone else? Curious if this work around makes any sense.

Developer
Posts: 638
Registered: ‎07-02-2009
My Device: Not Specified

Re: PopupScreen with transparent background and theme for Storm

Hi, i didnt go thru ur code, but transparent manager wont give the popupscreen look and feel. It seems to be, a field added to the current screen, instead. 

Thanks and Regards,
PraveenGoparaju.
Developer
Posts: 81
Registered: ‎06-24-2009
My Device: Not Specified

Re: PopupScreen with transparent background and theme for Storm

True, but can't one easily paint it to look like a popup?

New Developer
Posts: 54
Registered: ‎01-24-2009
My Device: Not Specified

Re: PopupScreen with transparent background and theme for Storm

I did some testing with tkroll's idea and it seems like it could work.

 

I also did some testing with BackgroundFactory for the 4.6+ builds of my application.

 

The problem I run into with both is that all I'm trying to accomplish is having a "busy" screen popup (as I said in my first post).  For this I'm using an animated GIF.  Using either tkroll's code or BackgroundFactory on newer OS gives me the transparent background.  But, as the GIF animates, the border flashes.  There is no border to the GIF file and I've tried using BorderFactory to set the border to transparent as well for 4.6+ OS.  Neither seems to help.  I still get a 1px border.  And it doesn't shows around the entire GIF, only one side at a time.  So, it might show only on the right border, then as the image animates, it will only show the bottom border, then the left, etc.

 

Anyone else run into this?

 

I don't want to get off topic too far, just wanted to check.  tkroll's solution looks like it could work for all versions of the OS that I need, 4.5+.  Anyone see any problems with this method?

 

 

New Contributor
Posts: 7
Registered: ‎01-22-2010
My Device: 8330/8900
My Carrier: AT&T

Re: PopupScreen with transparent background and theme for Storm

 

 

Hey all,

So I've been reading through these forums for quite some time and I thought I should finally post something, since it might be helpful to some. I, too, was using some of this code to create a custom transparent popup with the default theme overriden. I'm also trying to keep a 4.5 target. It seems that devices that run on 4.5 like my 8320 and the simulators zany mentioned below all create a transparent popup as expected, but when you run the same code on a 4.6+ device like my 8900 or 9700 etc...you get an opaque popup with the white background. This is consistent with everything everyone else has mentioned on this thread, but I don't think everyone realized that the differences were between 4.5 devices and newer devices.
A suggestion in this thread is to take a screenshot of the active screen when you're pushing your "popup" and use that screenshot as the background for your "popup" screen class. I haven't tried it yet since I can't find any screenshot taking threads, but if it worked, at least you'd know it was universal between all devices....

zany wrote:

oh, i have tested this code in the following models' simulators but not in any real devices of 4.5

8100
8330
8300
8703e

 

since it was working fine for me in the simulators, i thought it should have same behavior in the real device but it is not

 

sorry

 


New Contributor
Posts: 7
Registered: ‎01-22-2010
My Device: 8330/8900
My Carrier: AT&T

Re: PopupScreen with transparent background and theme for Storm

Actually, this post tells you how to take a screenshot. Not hard at all, you just need to make sure you have code signing keys from RIM since the Display class is part of the Controlled APIs that require signing.

 

Signing info..

 

online app form for signing keys: https://www.blackberry.com/SignedKeys/

New Contributor
Posts: 7
Registered: ‎01-22-2010
My Device: 8330/8900
My Carrier: AT&T

Re: PopupScreen with transparent background and theme for Storm

[ Edited ]

So after working with this for a while, I came up with something that works for me on both 8300 series phones and 8900 series phones (or what I'm assuming is an underlying issue between OS4.5 and OS4.6+ devices).

 

Using the information I got from the linked post and code from this thread, I came up with a custom popupscreen class that appears to be transparent.

 

 

import net.rim.device.api.system.Bitmap;
import net.rim.device.api.system.Display;
import net.rim.device.api.ui.Color;
import net.rim.device.api.ui.Field;
import net.rim.device.api.ui.FieldChangeListener;
import net.rim.device.api.ui.Graphics;
import net.rim.device.api.ui.Manager;
import net.rim.device.api.ui.XYRect;
import net.rim.device.api.ui.container.PopupScreen;

/*
* This class creates a custom transparent popupscreen with a semi-transparent rounded rectangle
* as a background of specified color. It takes in an existing Manager as the content of the popup.
*/
public class CustomPopup extends PopupScreen implements FieldChangeListener {

int color;
Bitmap backgroundBitmap;
private int _CUSTOM_WIDTH;
private int _CUSTOM_HEIGHT;
private int _X;
private int _Y;

protected void sublayout( int width, int height ) {
setExtent( _CUSTOM_WIDTH, _CUSTOM_HEIGHT );
// If you want to make it look like the popupscreen is glass that "distorts" the light, you can
// add a little offset of a pixel or two to the setPosition method below, so that the background of
// the popupscreen is painted a bit off from the actual screen below. Just a thought....
setPosition( _X, _Y );
layoutDelegate( _CUSTOM_WIDTH - 20, _CUSTOM_HEIGHT - 20 );
setPositionDelegate(10,10);
}
protected void applyTheme(){

}
public CustomPopup(Manager manager, int color) {
super(manager);

_CUSTOM_WIDTH = manager.getPreferredWidth() + 20;
_CUSTOM_HEIGHT = manager.getPreferredHeight() + 20;
backgroundBitmap = new Bitmap(_CUSTOM_WIDTH,_CUSTOM_HEIGHT);
_X = ( Display.getWidth() - _CUSTOM_WIDTH ) >> 1;
_Y = ( Display.getHeight() - _CUSTOM_HEIGHT ) >> 1;
// Take screenshot of active screen which will be used as our background later
Display.screenshot(backgroundBitmap, _X, _Y, _CUSTOM_WIDTH, _CUSTOM_HEIGHT);
this.color = color;
}
protected void paintBackground(Graphics g){
// Instead of trying to make the background transparent (which only work on OS4.5 devices and not OS4.6 devices for some reason),
// we'll just draw the screenshot bitmap to the background of our popup and make it appear that it's transparent
g.drawBitmap(0, 0, backgroundBitmap.getWidth(), backgroundBitmap.getHeight(), backgroundBitmap, 0, 0);
}
protected void paint(Graphics g){
XYRect myExtent = getExtent();
int alpha = g.getGlobalAlpha();
// Set transparency ~70%
g.setGlobalAlpha(0xB0);
g.setColor(this.color);
// Fill transparent rounded rectangle
g.fillRoundRect(0, 0, myExtent.width, myExtent.height,20,20);
g.setColor(Color.BLACK);
// Draw black rounded border
g.drawRoundRect(0, 0, myExtent.width, myExtent.height, 20, 20);
g.setGlobalAlpha(alpha);
// Draw the rest of the content from the manager specified in constructor
super.paint(g);
}
public void fieldChanged(Field arg0, int arg1) {
this.close();
}
}

 

I've tested it on my devices and it works perfectly now. Please note that in order to make the popupscreen appear transparent, a screenshot is being taken before the popup is pushed, and that is used as the background of the popup.

 

Also note that this is just a custom popup which takes in an existing manager defined elsewhere, and paints a rounded semi-transparent rectangle with a color of your choice. You can change the paint() method to have it paint whatever you want instead.

 

Well hope this helps, thanks for all the help that led up to this.

 

Developer
Posts: 142
Registered: ‎06-26-2009
My Device: Not Specified

Re: PopupScreen with transparent background and theme for Storm

Hi ketithmay,

 

Thanks a lot for transparent popup.Your  code works fine. Thanks you..:smileyhappy: