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
Trusted Contributor
Posts: 242
Registered: ‎03-16-2010
My Device: 9530

Re: Problem with CustomLabelField

 

Peter, I guess I also faced the same problem that many of them are facing here i.e. problem with layouts. I added my contents to GridLayout and tested with ArrowLabel, every thing is working fine. All arrowLabel + close button with the addition of components - other non_focusable labels & bitmap.

 

But with this all I face is

* laying of componetns is not appropriate. Like bitmap comes on top instead of middle.

* I can't set the background bitmap/color due to which the grid color and background remains differnt. I want grid to be transparent and a bitmap in the background like I had added in custom manager .

* I wanted the grid to occupy all width, but then was facing problem with dividing the gird in  grids vertically. So each grid can have 3 cols and 1 row.

 

How do I solve them?

 

Regards,

 


--------------------------------------------------------------------------------
For any helpful answers give kudo's (star) to the helper.
Developer
Posts: 222
Registered: ‎11-11-2009
My Device: Storm

Re: Problem with CustomLabelField

If you are working with v4.7 for storm device, you need to prefer only touch events for handling the click events, using Field change listener you cant able to achieve what you are expecting to do in touch screen devices. So only way to handle them is to make use of touch events. You can go through the link what peter has suggested, it will give you the solution for you. If you are not able to get solution from that, then try to write some simple samples for touch screen device to handle all the touch events. there are lot of sample code available in the forum, which you can able to get with simple search. Also there are KB and articles in blackberry site. What are all the problems you are facing in current is not becuase custom fields, that was only because of Field change listener in touch screen device.

 

"I want the code to be compatible with 4.5 also." - It is not possible to write a code in higher version(4.7) and trying to make compatible for older version (4.5). Only the vice versa is possible. So please do different codes 4.5 and 4.7

with regards,
Vignesh J

-------------------------------------------------------------------------------------------------------------------------------------------------------------------
Don't forget to mark your post as solved if you get the answer and dont forget to give kudos if the answer is useful for you.
-------------------------------------------------------------------------------------------------------------------------------------------------------------------
Developer
Posts: 19,636
Registered: ‎07-14-2008
My Device: Not Specified

Re: Problem with CustomLabelField

@trupti.

 

Sorry I have not faced the problem you are seeing, as I suggested in my previous post I have just noted that other people have had the problem.

 

GridManager is not a RIM Manager until OS 5.0.  Since you seem to want code that works on older OS's I presume you have crated your own or picked up a Manager from somewhere, like the one here:

http://www.thinkingblackberry.com/archives/116

 

I have never used that manager.  When people ask for something like this, I always point them at TableLayoutManager, which is some sample code from RIM.  There is a KB article about it and a very good blog, search the forum, I've put links to both in a number of posts.  So I would try that.

 

But zany has a good point.  If you are going to be working with TouchScreen devices and creating your own buttons, then you may have to write TouchEvent processing code (i.e. 4.7 specific code) and use the preprocessor to exclude this code when compiling for an older OS.  Alternatively, if you extend ButtonField, you might be able to get the same functionality and I suspect that ButtonField might work in your custom manager - give it a try. 

Trusted Contributor
Posts: 242
Registered: ‎03-16-2010
My Device: 9530

Re: Problem with CustomLabelField

 

Vignesh, I agree with your point - code written and compiled in 4.7 can't work in 4.5, but code written in 4.5 can definetely work for 4.7 (mostly unless some method is removed or deprecated). That's what I take care of. I had initially downloaded 4.7, so am continuing working with that only. But my first approach is to make for 4.5.

If I am not wrong, then in code of 4.5, I need to add touchEvents for 4.7. But 4.7 will still need click events (fieldChangeListener) as it supports both.

 

I had tried the code you have provided in the link shown by peter, but on 1st right click (right click for touch effect) on a component, the touch effect doesn't go to other components how much I click other ones.

 

Please correct me if I am wrong.


--------------------------------------------------------------------------------
For any helpful answers give kudo's (star) to the helper.
Trusted Contributor
Posts: 242
Registered: ‎03-16-2010
My Device: 9530

Re: Problem with CustomLabelField

 

Yes Peter, I had picked up GridManager from a link provided by you (not sure if its the same link or not), but the manager is very good and works very well. It is same as our GridLayout in Java, but doesn't change the size basis on component added to its size. We can specify how many cols, rows we needs and their size limit. Like col1 - 110, col2 -100, col3 -80, etc.

 

I also saw TableLayoutManager term in many posts but never found its code & as I was happy with Grid, i didn't look out more for it.

 

ButtonField also works very well, only point I find hard is the space it occupies and compared tothe text shown, I want to show just an arrow ">", If I make normal size, its less visible, if I increase the size or make it bold, button size also increases which thne turns out to be a focus attractive point on the screen. That was the only reason, I opted for extending LabelField.

 

Oh yes, I will implement the touchevent part as it is a requirement. But I guess at present, I should only concentrate on main program and its logic andd flow and then work on expanding it.

 

I have another screen also where I display textfields, buttons & a big bitmap. That screen also I implemented using custom manger and am facing problems in that also. I guess that must be of this layout issue only. I will go for standard layout for that too.

 

I again came up to the stage where I had started facing problems and opted for custom layout manager. How to set background image using standard managers? For this issue, experts suggested to try custom managers. Now what do I do & how to set background image on the screen.

 

Let me know, if you know.

 

 

Regards & Thanks

 

 


--------------------------------------------------------------------------------
For any helpful answers give kudo's (star) to the helper.
Developer
Posts: 222
Registered: ‎11-11-2009
My Device: Storm

Re: Problem with CustomLabelField

[ Edited ]

"If I am not wrong, then in code of 4.5, I need to add touchEvents for 4.7. But 4.7 will still need click events (fieldChangeListener) as it supports both." - yes, fieldChangeListener was supported by v4.7, we can make use of it. the thing is it will not give you much efficient output as you got from touch event. Also it is preferred to use only touch events to handle all touch events like click, tap and more.

 

"I had tried the code you have provided in the link shown by peter, but on 1st right click (right click for touch effect) on a component, the touch effect doesn't go to other components how much I click other ones." - so you tried to tap the simulator screen is it correct? the code what i have given the link shown by peter was just a snippet of code, not the actual code. That code will handle only the click event alone and will ignore the rest of the touch events like tap, hover, etc... following code snippet will handle all the touch events. try it use this code

 

class MyBitmapField extends BitmapField
{
    protected boolean touchEvent(TouchEvent message)
    {
        if (message.getEvent() == TouchEvent.CLICK)

        {
            if (message.getY(1) < 0)
                return false;
            if (message.getY(1) > getHeight())
                return false;
            if (message.getX(1) < 0)
                return false;
            if (message.getX(1) > getWidth())
                return false;

            // do your code here
            return true;
        }

        else if (message.getGesture().getEvent() == TouchEvent.TAP)

        {

            if (message.getY(1) < 0)
                return false;
            if (message.getY(1) > getHeight())
                return false;
            if (message.getX(1) < 0)
                return false;
            if (message.getX(1) > getWidth())
                return false;

           setFocus();
        }
        return false;
    }
}

with regards,
Vignesh J

-------------------------------------------------------------------------------------------------------------------------------------------------------------------
Don't forget to mark your post as solved if you get the answer and dont forget to give kudos if the answer is useful for you.
-------------------------------------------------------------------------------------------------------------------------------------------------------------------
Highlighted
Trusted Contributor
Posts: 242
Registered: ‎03-16-2010
My Device: 9530

Re: Problem with CustomLabelField

 

What is TouchEvent.TAP event. I can't find in the API. It also gives me error.

 

cannot find symbol
symbol  : variable TAP
location: class net.rim.device.api.ui.TouchEvent
            } else if (message.getGesture().getEvent() == TouchEvent.TAP) {
                                                                    ^

 

TAP field is in TouchGesture. I tried adding TouchGesture.TAP, that also resulted in runtime exception. TouchEvent.up, Down, calls TAP event, so I replaced with TouchEvent.UP, but yet exception on runtime.

 

I use 4.7.0.41 version of jde & 9530 simulator.

 

Can you tell what should be handled out here.

 

 

Thanks,

 


--------------------------------------------------------------------------------
For any helpful answers give kudo's (star) to the helper.
Developer
Posts: 222
Registered: ‎11-11-2009
My Device: Storm

Re: Problem with CustomLabelField

sorry for my wrong code. TAP event will be available in TouchGesture class

we have to write the code like

else if (message.getGesture().getEvent() == TouchEvent.TAP)

 

 it should work, can  you please give me the complete stack trace of your exception and code snippet?

with regards,
Vignesh J

-------------------------------------------------------------------------------------------------------------------------------------------------------------------
Don't forget to mark your post as solved if you get the answer and dont forget to give kudos if the answer is useful for you.
-------------------------------------------------------------------------------------------------------------------------------------------------------------------
Trusted Contributor
Posts: 242
Registered: ‎03-16-2010
My Device: 9530

Re: Problem with CustomLabelField

 

Zany,

 

   The code gives me Compile time Error -

cannot find symbol
symbol  : variable TAP
location: class net.rim.device.api.ui.TouchEvent
            } else if (message.getGesture().getEvent() == TouchEvent.TAP) {
                                                                    ^
1 error
Error!: Error: java compiler failed: javac -source 1.3 -target 1.3 -deprecation -g -O -d C:\Users\Vikram\AppData\Local\Temp\rapc_14ab78d ...
Error while building project

 

Full method code -

       // try..catch was just added now to catch Runtime Exception
        protected boolean touchEvent(TouchEvent message) {
            try {
            if (message.getEvent() == TouchEvent.CLICK) {
                if (message.getY(1) < 0)
                    return false;
                if (message.getY(1) > getHeight())
                    return false;
                if (message.getX(1) < 0)
                    return false;
                if (message.getX(1) > getWidth())
                    return false;
                    
                // do your code
                return true;
            } else if (message.getGesture().getEvent() == TouchEvent.TAP) {
                if (message.getY(1) < 0)
                    return false;
                if (message.getY(1) > getHeight())
                    return false;
                if (message.getX(1) < 0)
                    return false;
                if (message.getX(1) > getWidth())
                    return false;
                setFocus();
            }
            }catch(Exception e) {
                System.out.println("Excep - " + e.getMessage());
                e.printStackTrace();
            }
            return false;
        }

 

Without try .. catch the arrow is at TouchEvent.TAP instead of getGesture()

 

I have jdk6.

 

 

Regards,

 

 


--------------------------------------------------------------------------------
For any helpful answers give kudo's (star) to the helper.
Developer
Posts: 222
Registered: ‎11-11-2009
My Device: Storm

Re: Problem with CustomLabelField

once again sorry for my wrong codeSmiley Sad.  I was busy over some other work, not able to give you correct code. here is the proper code

else if (message.getGesture().getEvent() == TouchGesture.TAP)

 

        protected boolean touchEvent(TouchEvent message) {
if (message.getEvent() == TouchEvent.CLICK) {
if (message.getY(1) < 0)
return false;
if (message.getY(1) > getHeight())
return false;
if (message.getX(1) < 0)
return false;
if (message.getX(1) > getWidth())
return false;

// do your code
return true;
} else if (message.getGesture().getEvent() == TouchEvent.TAP)
{
if (message.getY(1) < 0)
return false;
if (message.getY(1) > getHeight())
return false;
if (message.getX(1) < 0)
return false;
if (message.getX(1) > getWidth())
return false;
setFocus();

return true;
}
return false;
}

 

sorry once again

with regards,
Vignesh J

-------------------------------------------------------------------------------------------------------------------------------------------------------------------
Don't forget to mark your post as solved if you get the answer and dont forget to give kudos if the answer is useful for you.
-------------------------------------------------------------------------------------------------------------------------------------------------------------------