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
Regular Contributor
Posts: 59
Registered: ‎03-06-2012
My Device: 9700
My Carrier: airtel

Not able to set the focus on a HFM

Hi All,

 

I am not able to set teh focus on the HFM having two label fields the text is 7:00 i want to highlight this value on select i am using the following code to focus but its not working

 

    HorizontalFieldManager hrzMgrTimeLabel = new HorizontalFieldManager(
                Manager.USE_ALL_HEIGHT|Manager.FOCUSABLE)
            
            {protected void onFocus(int direction) {
                focussed = true;
                invalidate();
                super.onFocus(direction);

            }

            protected void onUnfocus() {
                focussed = false;
                invalidate();
                super.onUnfocus();
            }
            protected void paint(Graphics g) {
                g.setBackgroundColor(0x646060);
                if (focussed) {
                    g.setColor(Color.BLUE);
                }
                g.clear();
                super.paint(g);
            }
        };

        hrzMgrTimeLabel.add(a);
        hrzMgrTimeLabel.add(b);

        horizontalFieldManager_left15.add(hrzMgrTimeLabel);

 

What is wrong over here,the labelfields are

 

final LabelField a= new LabelField("") {
        protected void paint(Graphics graphics) {
            graphics.setColor(Color.WHITE);
            graphics.setBackgroundColor(0x646060);
            graphics.clear();
            super.paint(graphics);
        }
    };

final LabelField b= new LabelField("") {
        protected void paint(Graphics graphics) {
            graphics.setColor(Color.WHITE);
            graphics.setBackgroundColor(0x646060);
            graphics.clear();
            super.paint(graphics);
        }
    };

Developer
Posts: 17,012
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport
My Carrier: O2 Germany

Re: Not able to set the focus on a HFM

usually a field gets the focus, not the manager.
i would suggest that you overwrite the fields onFocus/onUnfocus and let them trigger the manager background.
----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
Regular Contributor
Posts: 59
Registered: ‎03-06-2012
My Device: 9700
My Carrier: airtel

Re: Not able to set the focus on a HFM

you mean to say i have to overwrite the focus /unfocus methods for two labelfields ? but how will i get the focus as a whole ?Pls explain with a small snippet
Developer
Posts: 17,012
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport
My Carrier: O2 Germany

Re: Not able to set the focus on a HFM

the field will be focused, but you can draw the focus for the field or the manager however you like.
----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
Regular Contributor
Posts: 59
Registered: ‎03-06-2012
My Device: 9700
My Carrier: airtel

Re: Not able to set the focus on a HFM

[ Edited ]

 

  I am not sure what is wrong here this declaration is at the class level


    final CustomTimeLabelField time15 = new CustomTimeLabelField("",
            LabelField.FOCUSABLE);
    final CustomTimeLabelField  min15 = new CustomTimeLabelField ("",LabelField.FOCUSABLE) ;
       
and in the constructor i have 

 

CustomHFM horizontalFieldManager_left15 = new CustomHFM(
                Manager.HORIZONTAL_SCROLL);

        HorizontalFieldManager hrzMgrTimeLabel = new HorizontalFieldManager(
                Manager.USE_ALL_HEIGHT) {

            protected void paint(Graphics g) {
                g.setBackgroundColor(0x646060);

                g.clear();
                super.paint(g);
            }
        };
        hrzMgrTimeLabel.add(time15);
        hrzMgrTimeLabel.add(min15);

        horizontalFieldManager_left15.add(hrzMgrTimeLabel);

 

I want to set the focus for both the lable fields as a whole the data in labelfields are like 15:00

for now i am just hightlighting 15 as i am not abe to hightlight as a whole.The custom class is like :





public class CustomTimeLabelField extends LabelField {
    private boolean focussed;
    private String text;
    private long style;

    public CustomTimeLabelField(String text, long style) {

        super(" ", LabelField.FOCUSABLE);
        text = text;
        style = style;
    }

    protected void onFocus(int direction) {
        focussed = true;
        invalidate();
        super.onFocus(direction);

    }

    protected void onUnfocus() {
        focussed = false;
        invalidate();
        super.onUnfocus();
    }

    protected void paint(Graphics graphics) {
        graphics.setColor(Color.WHITE);
        graphics.setBackgroundColor(0x646060);
        if (focussed) {
            graphics.setColor(Color.BLUE);
        }
        graphics.clear();
        super.paint(graphics);
    }
}

-------------------------------------------------------------------



public class CustomHFM extends HorizontalFieldManager {

    private long style;

    public CustomHFM(long style) {
        super(HORIZONTAL_SCROLL);
        style = style;
    }

    public int getPreferredWidth() {
        return Display.getWidth();
    }

    // define height
    public int getPreferredHeight() {
        return 40;
    }

    protected void sublayout(int maxWidth, int maxHeight) {
        super.sublayout(getPreferredWidth(), getPreferredHeight());
        setExtent(getPreferredWidth(), getPreferredHeight());
    }

}


Please let me know what is wrong here.

 

Developer
Posts: 208
Registered: ‎08-04-2009
My Device: Not Specified

Re: Not able to set the focus on a HFM

[ Edited ]

You can add a NullField to HFM, and set a FocusChangeListener on NullField, like this:

 

NullField null=new NullField(NullField.FOCUSABLE)
{
     protected void onFocus(int direction) {
                focussed = true;
                hfm.invalidate();
                super.onFocus(direction);
     }

     protected void onUnfocus() {
            focussed = false;
            hfm.invalidate();
            super.onUnfocus();
     }
};

HorizontalFieldManager hrzMgrTimeLabel = new HorizontalFieldManager(
                Manager.USE_ALL_HEIGHT|Manager.FOCUSABLE)
{
      protected void paint(Graphics g) {
                g.setBackgroundColor(0x646060);
                if (focussed) {
                    g.setBackgroundColor(Color.BLUE);
                }
                g.clear();
                super.paint(g);
            }
        };
}

 


Developer
Posts: 19,636
Registered: ‎07-14-2008
My Device: Not Specified

Re: Not able to set the focus on a HFM

Sorry only just dipping in here.  I don't see any code in the Customer HFM for painting it differently when it is in focus.  Anyway, as an option, you could, in your paint routine, check all the fields on the manager and see if any are focused - just a for loop using the getFieldCount(), finding each Field using getField(), then checking they are focused (isFocus().  Before you embark on this, make sure that this.isFocus() doesn't work correctly anyway.  Either way you will now in the paint method of the Manager if one of its Fields is focus, and you can paint the Manager appropriately.  . 

Regular Contributor
Posts: 59
Registered: ‎03-06-2012
My Device: 9700
My Carrier: airtel

Re: Not able to set the focus on a HFM

nothing seems to be working,can u please verify my code above
Highlighted
Developer
Posts: 19,636
Registered: ‎07-14-2008
My Device: Not Specified

Re: Not able to set the focus on a HFM

As noted"I don't see any code in the Customer HFM for painting it differently when it is in focus.".  Without this coe why would it work?