BlackBerry Forums Support Community               

Closed Thread
 
LinkBack Thread Tools
Old 04-27-2008, 11:37 PM   #21 (permalink)
Thumbs Must Hurt
 
Join Date: Dec 2005
Model: 8310
Carrier: Rogers
Posts: 138
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

Please Login to Remove!

When you create your MainScreen and your Field Managers, call super on those items with style:

Code:
Manager.NO_VERTICAL_SCROLL | Manager.NO_VERTICAL_SCROLLBAR

Just also wanted to comment on a few posts by jfisher:

1. You can take screenshots in 4.2.0 with Display.screenshot( Bitmap template ) ( this in response to a different thread that was closed in which he claimed it was impossible ).
2. You can most certainly draw transparent backgrounds... but it requires some trickery. You have to take a screen-shot, isolate the screen region and map it to a new Bitmap buffer via getArgb and setArgb, then draw it to the background of your new screen. After that you can set the global alpha to something pretty and draw away.
3. What's all this about adding padding fields? Unless you intend to do drawing in those fields, the Field class has the undocumented function setPadding( int top, int right, int bottom, int left ) for this purpose. In conjunction with Richard's description of the sublayout function, you can achieve just about any layout you can imagine.

Last edited by CELITE : 04-27-2008 at 11:59 PM.
Offline  
Old 05-19-2008, 11:06 AM   #22 (permalink)
CrackBerry Addict
 
Join Date: Jun 2005
Location: Manchester, UK
Model: BOLD
Carrier: t-mobile
Posts: 714
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

as i mentioned in my message to you responding to this rude post - the user referred to in points 1 and 2 wanted a floating widget type app on the homescreen, if anyone can illustrate this i'll kindy stfu.

regarding point 3 - like i said above: 'it feels like a hack so wouldn't want to blog about it, i'm sure other more experienced proto geeks could do it better' - i've already said here it isn't ideal but was a workaround i used in a project.

i don't understand your fractious remarks, i do my best here and i don't see you joining in the community day in day out.

While we're at it - has anyone managed to set the background color of a MainScreen in a manner that doesn't introduce issues when scrolling? an example would be lovely. for example, the above example by richard does set the background colour but messes up when we add fields to the screen requiring a scroll, the additional info from CELITE suppresses this but then we have a screen with no scroll and can't get to the fields offscreen. will have a look at it at some point but for the moment i'll stick to working method described in previous posts.
__________________
new job doesn't allow a public profile - please do not contact this user with questions, you will not get a response. good luck!

Last edited by jfisher : 05-19-2008 at 11:17 AM.
Offline  
Old 05-19-2008, 12:11 PM   #23 (permalink)
Thumbs Must Hurt
 
Join Date: Dec 2005
Model: 8310
Carrier: Rogers
Posts: 138
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

jfisher, I'm sorry if my post came across as rude, it was certainly not intended that way. I just noticed a few posts that could be complemented with some additional information to help out other users. Also I want to add to my own post: re: transparent backgrounds; you do not necessarily have to create an additional buffer if you don't mind the whole display image sitting in memory. You can just call drawBitmap and pass in the parameters that draw from the appropriate region.

Adding to jfisher's post, you can add another vertical field manager that has scrolling capabilities to the MainScreen's delegate and it will not mess up the background drawing
Offline  
Old 05-19-2008, 12:23 PM   #24 (permalink)
CrackBerry Addict
 
Join Date: Jun 2005
Location: Manchester, UK
Model: BOLD
Carrier: t-mobile
Posts: 714
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

thanks for clarifying. i'm still not convinced it's possible to create a floating transparant application, for example a floating round analog style clock - if you could post a code snippet illustrating this it'd be awesome.

i can see several issues and can't think of clean ways around, for example i thought that taking a screenshot you can only take a screen of your own app? (Could be wrong here) if you did manage to take a screenshot of the homescreen and then manually build your app over a section giving the transparancy the user was after; you'd have to monitor for incoming events that'd change the homescreen, background your app, take the screenshot, foreground it and redraw. unless i'm missing something.
__________________
new job doesn't allow a public profile - please do not contact this user with questions, you will not get a response. good luck!

Last edited by jfisher : 05-19-2008 at 12:24 PM.
Offline  
Old 05-19-2008, 01:30 PM   #25 (permalink)
Thumbs Must Hurt
 
Join Date: Dec 2005
Model: 8310
Carrier: Rogers
Posts: 138
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

I think the following code *might* be what you're after? Give it a try and let me know.

Code:
class FloatingScreenMain extends UiApplication {
    
    public static void main( String[] args ) {
        FloatingScreenMain app = new FloatingScreenMain();
        app.enterEventDispatcher();
    }
    
    FloatingScreenMain() {    
    
        /**
         * Putting this on the event stack instead of pushing a screen from main 
         * ensures that the backbuffer is not cleared and that the main ribbon
         * continues to repaint.
         */
        UiApplication.getUiApplication().invokeLater( new Runnable() {
            public void run() {
                CustomPopupScreen popup = new CustomPopupScreen();
                pushScreen( popup );
            }
        });
    }
} 


class CustomPopupScreen extends Screen {
    
    private final static int _CUSTOM_SIZE   = 100;
    private final static int _ALPHA         = 0xBF; // 75% alpha
    private final static int _X             = ( Display.getWidth() - _CUSTOM_SIZE ) >> 1;
    private final static int _Y             = ( Display.getHeight() - _CUSTOM_SIZE ) >> 1; 
    
    
    CustomPopupScreen() {    
        super( new VerticalFieldManager( Manager.NO_VERTICAL_SCROLL | Manager.NO_VERTICAL_SCROLLBAR ) );
        add( new LabelField( "Floating Popup" ) );
    }
    
    protected void sublayout( int width, int height ) {
        setExtent( _CUSTOM_SIZE, _CUSTOM_SIZE );
        setPosition( _X, _Y );
        layoutDelegate( _CUSTOM_SIZE, _CUSTOM_SIZE );
    }
    
    protected void paintBackground( Graphics g ) {
        XYRect myExtent = getExtent();
        int color = g.getColor();
        int alpha = g.getGlobalAlpha();
        g.setGlobalAlpha( _ALPHA );
        g.setColor( 0xE3E3E3 );
        g.fillRect( 0, 0, myExtent.width, myExtent.height );
        g.setColor( color );
        g.setGlobalAlpha( alpha );
    }
    
    protected boolean keyDown( int keycode, int status ) {
        if ( Keypad.key( keycode ) == Keypad.KEY_ESCAPE ) {
            close();
            return true;
        }
        return super.keyDown( keycode, status );
    }
        
    
    
}
Perhaps we should take this discussion to a new thread

*EDIT* I just wanted to add that if you wanted to do fade in effects you have to take into account that the back buffer is not being cleared and therefor you have to make up for the exponential effect of layering transparent pixels on top of each other. The solution to this is to take a display snapshot and paint on top of it

Last edited by CELITE : 05-19-2008 at 01:34 PM. Reason: Additions
Offline  
Old 05-19-2008, 05:40 PM   #26 (permalink)
Thumbs Must Hurt
 
Join Date: Dec 2005
Model: 8310
Carrier: Rogers
Posts: 138
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi folks. I thought I'd post the solution to that MainScreen problem. jfisher was quite right when he said I didn't read the whole thing sorry :(

Anyways here is the solution, which will work with drawBitmap as well:

Code:
class CustomMainScreen extends MainScreen {
   private VerticalFieldManager _container;

    CustomMainScreen() {    
        super( Manager.NO_VERTICAL_SCROLL | Manager.NO_VERTICAL_SCROLLBAR );
        setTitle( "Test" );
        VerticalFieldManager internalManager = new VerticalFieldManager( Manager.NO_VERTICAL_SCROLL | Manager.NO_VERTICAL_SCROLLBAR ) {
            public void paintBackground( Graphics g ) {
                g.clear();
                int color = g.getColor();
                g.setColor( 0xc0dce0 );
                g.fillRect( 0, 0, Display.getWidth(), Display.getHeight() );
                g.setColor( color );
            }

            protected void sublayout( int width, int height ) {
                super.sublayout( Display.getWidth(), Display.getHeight() );
            }
        };
        _container = new VerticalFieldManager( Manager.VERTICAL_SCROLL | Manager.VERTICAL_SCROLLBAR );
        RichTextField rtf = new RichTextField( "This is a readonly textfield that is here to show programmers how they can create a mainscreen with a custom background and proper vertical scrolling. \n\n\nABCABCABC\n\n\nABCABCABC\n\n\nABCABCABC", Field.READONLY );
        _container.add( rtf );
        internalManager.add( _container );
        super.add( internalManager );
    }

    public void add( Field field ) {
        _container.add( field );
    }
}
*EDIT*
Sorry I have a habit of just posting things without an explanation. What I've really done in this code is circumvent the behavior of the MainScreen's main manager. In effect, every time you call add(), you now have to container.add() instead. This is because there is no way to access or override the main manager's painting behavior. To make matters worse, the main manager calls clear in its paint routine so that if you override paintBackground() in the MainScreen, the main manager will just paint a white rectangle over top of what you painted in paintBackground. Hope this makes sense.

Another addition: You should subtract the height of the title bar from Display.getHeight() in the innerManager's sublayout function.

Last edited by CELITE : 05-19-2008 at 08:04 PM. Reason: Explanation
Offline  
Old 05-20-2008, 07:14 AM   #27 (permalink)
CrackBerry Addict
 
Join Date: Jun 2005
Location: Manchester, UK
Model: BOLD
Carrier: t-mobile
Posts: 714
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default



[edit - disregard that, i had the screen and font colors the same.... ]
__________________
new job doesn't allow a public profile - please do not contact this user with questions, you will not get a response. good luck!

Last edited by jfisher : 05-20-2008 at 07:38 AM.
Offline  
Old 05-20-2008, 08:26 AM   #28 (permalink)
CrackBerry Addict
 
Join Date: Jun 2005
Location: Manchester, UK
Model: BOLD
Carrier: t-mobile
Posts: 714
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

okay - the above is still giving me issues, i'm sticking with my original method (i'm not claiming it's better, it works for me - so no flames please), it works well and is less code (well, the code is hidden in the spacerfield class but i use it as a nicer LabelField throughtout my apps anyway), i create a new spacerfield in the MainScreens constructor: Blackberry - SpacerField and add it to my screen as the last field:

Code:
SpacerField pad = new SpacerField(Graphics.getScreenHeight(), 0xAAAAAA);

 public myScreen() {
        setTitle("Title");
        add(pad);
    }
Then everytime a field is added to the screen I resize it, in my case fields are added to the screen by another process so i have a function like below, the fields can be anything as long as you can return their height, i just delete and then add the field again so i don't have to worry about the index in the screens manager:

Code:
public void updateScreen() {
System.out.println("SCREEN > UPDATE_SCREEN");
CustomField someField = new CustomField();
add(someField);
pad.setHeight(pad.getPreferredHeight() -  someField.getPreferredHeight());
delete(pad);
add(pad);
        }
    }
Regardless of what anyone thinks of this method - it works and there are no knockon effects, you could add some extra logic to just delete the pad field once the other fields extend to greater than the screen height if you want or create a function to wrap it all up.
__________________
new job doesn't allow a public profile - please do not contact this user with questions, you will not get a response. good luck!

Last edited by jfisher : 05-20-2008 at 08:33 AM.
Offline  
Old 05-20-2008, 08:55 AM   #29 (permalink)
Thumbs Must Hurt
 
Join Date: Dec 2005
Model: 8310
Carrier: Rogers
Posts: 138
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

jfisher I would like to help you work through this because if employed properly, the method I described should work without the need for field hacks. What issues are you encountering?

*EDIT*
I now see what you mean. The background only draws to the bottom of the filled fields. To be truthful, I have employed spacer fields as a hack in the past. I'll see if I can get it to work without spacer fields.

Last edited by CELITE : 05-20-2008 at 09:05 AM.
Offline  
Old 05-20-2008, 09:01 AM   #30 (permalink)
CrackBerry Addict
 
Join Date: Jun 2005
Location: Manchester, UK
Model: BOLD
Carrier: t-mobile
Posts: 714
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

if i create a screen class that extends CustomMainScreen the background color isn't being set, it's probably easy for you to figure but i've got a deadline today so have to go with what i've got for now. if we could sort it it'd be great for the future though. as discussed in private messages once this is done i'll add a post to the community section of northcubed for future reference.

[edit - and thanks for all the help and effort with this!]
__________________
new job doesn't allow a public profile - please do not contact this user with questions, you will not get a response. good luck!

Last edited by jfisher : 05-20-2008 at 09:03 AM.
Offline  
Old 05-20-2008, 09:09 AM   #31 (permalink)
Thumbs Must Hurt
 
Join Date: Dec 2005
Model: 8310
Carrier: Rogers
Posts: 138
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

Fixed it. I forgot to add a critical line to the sublayout routine:

Code:
protected void sublayout( int width, int height ) {
    int displayWidth = Display.getWidth();    // I would probably make these global
    int displayHeight = Display.getHeight();
    
    super.sublayout( displayWidth, displayHeight );
    setExtent( displayWIdth, displayHeight );
}


Try that out. It should work.


Ahhhh new problem with nothing painting at all. I'll look into it.

Last edited by CELITE : 05-20-2008 at 09:17 AM.
Offline  
Old 05-20-2008, 09:22 AM   #32 (permalink)
Thumbs Must Hurt
 
Join Date: Dec 2005
Model: 8310
Carrier: Rogers
Posts: 138
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

jfisher I think I see where you might have run into problems

I'm going to re-paste the code here for brevity:

Code:
class ExtendedCustomMainScreen extends CustomMainScreen {
    ExtendedCustomMainScreen() {    
        super();
        RichTextField rtf = new RichTextField( "This is a readonly textfield", Field.READONLY );
        LabelField helloWorld = new LabelField( "Hi jfisher!" );
        add( rtf );
        add( helloWorld );
    }
} 

class CustomMainScreen extends MainScreen {
    
    private VerticalFieldManager _container;
    
    CustomMainScreen() {    
        super( Manager.NO_VERTICAL_SCROLL | Manager.NO_VERTICAL_SCROLLBAR );
        setTitle( "Test" );
        
        VerticalFieldManager internalManager = new VerticalFieldManager( Manager.NO_VERTICAL_SCROLL | Manager.NO_VERTICAL_SCROLLBAR ) {
            public void paintBackground( Graphics g ) {
                g.clear();
                int color = g.getColor();
                g.setColor( 0xc0dce0 );
                g.fillRect( 0, 0, Display.getWidth(), Display.getHeight() );
                g.setColor( color );
            }
            protected void sublayout( int maxWidth, int maxHeight ) {
                Field titleField = getMyTitleField();
                int titleFieldHeight = 0;
                if ( titleField != null ) {
                    titleFieldHeight = titleField.getHeight();
                }
                
                int displayWidth = Display.getWidth();    // I would probably make these global
                int displayHeight = Display.getHeight();
    
                super.sublayout( displayWidth, displayHeight - titleFieldHeight );
                setExtent( displayWidth, displayHeight - titleFieldHeight );
            }
               
        };
        _container = new VerticalFieldManager( Manager.VERTICAL_SCROLL | Manager.VERTICAL_SCROLLBAR );
        internalManager.add( _container );
        super.add( internalManager );
    }
    
    public void add( Field field ) {
        _container.add( field );
    }
    
    private Field getMyTitleField() {
        Manager delegate = getDelegate();
        Field titleField = null;
        try {
            titleField = delegate.getField( 0 );
        }
        catch ( IndexOutOfBoundsException ioobe ) {
            //
        }
        return titleField;
    }
} 

class MainScreenWithBackgroundMain extends UiApplication {
    
    public static void main( String[] args ) {
        MainScreenWithBackgroundMain app = new MainScreenWithBackgroundMain();
        app.enterEventDispatcher();
    }
    
    MainScreenWithBackgroundMain() {    
        ExtendedCustomMainScreen mainScreen = new ExtendedCustomMainScreen();
        pushScreen( mainScreen );
    }
}
I ran a few tests on it and they came out clean. Give her a shot.

Last edited by CELITE : 05-20-2008 at 10:07 AM.
Offline  
Old 05-20-2008, 09:38 AM   #33 (permalink)
CrackBerry Addict
 
Join Date: Jun 2005
Location: Manchester, UK
Model: BOLD
Carrier: t-mobile
Posts: 714
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

aha! - result! just the issue with the setTitle area height as you mentioned earlier (edit - even if we know the height of whatever's in setTitle, in my case its a field 28 pixels high, there is a few pixels difference due to the padding graphic between the Title area and Main area, i hope this is the same size across all models/os versions but have a feeling it may not be.)
__________________
new job doesn't allow a public profile - please do not contact this user with questions, you will not get a response. good luck!

Last edited by jfisher : 05-20-2008 at 09:48 AM.
Offline  
Old 05-20-2008, 10:02 AM   #34 (permalink)
Thumbs Must Hurt
 
Join Date: Dec 2005
Model: 8310
Carrier: Rogers
Posts: 138
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

Check my above post for a little hack that grabs the height of the title bar. It's very dirty but since the class TitleStatusManager is hidden from the public it was the only way :(

BTW did you try that floating transparent screen code? I'm hoping that worked :( Didn't really have time to test it on a device.

Last edited by CELITE : 05-20-2008 at 10:09 AM.
Offline  
Closed Thread


Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On





Copyright 2004-2014 BlackBerryForums.com.
The names RIM and BlackBerry are registered Trademarks of BlackBerry Inc.