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
BlackBerry Development Advisor
Posts: 15,810
Registered: ‎07-09-2008
My Device: BlackBerry PRIV
My Carrier: Bell

Re: Storm, HorizontalFieldManager, Buttons, Swiping, and Focus -- has something changed in 4.7.0.148

WIth the exception of capturing input (handling the touch/clicks) and handling the focus changes programmatically, there isn't any way to bring back the previous functionality.
Mark Sohm
BlackBerry Development Advisor

Please refrain from posting new questions in solved threads.
Problem solved? Click the Accept As Solution button.
Developer
Posts: 35
Registered: ‎12-12-2008
My Device: Not Specified

Re: Storm, HorizontalFieldManager, Buttons, Swiping, and Focus -- has something changed in 4.7.0.148

Thanks Mark.

 

Here's what I have done in the test app to recreate the old behavior. It wasn't too much trouble after all. Should probably have done this before, rather than bothering you guys.

 

-Morgan

 

===================================================================================================

 

Custom HorizontalFieldManager

========================

public class BitmapMenuBarHFM extends HorizontalFieldManager
{

    private NullField _null;
   
    public BitmapMenuBarHFM()
    {
    }

    public BitmapMenuBarHFM(long style)
    {
        super(style);
        _null = new NullField(NullField.FOCUSABLE);
        add(_null);
       
    }
   
    protected boolean touchEvent(TouchEvent message)
    {
        int iEvent = message.getEvent();
        switch (iEvent)
        {
            case TouchEvent.DOWN:
            case TouchEvent.MOVE:
            case TouchEvent.UP:
            {
                Field fld = null;
                // get target
                int x = message.getX(1);
                int y = message.getY(1);
                int iField = getFieldAtLocation(x, y);
                if (iField >= 0)
                {
                    fld = getField(iField);
                    if (!fld.getExtent().contains(x, y))
                        fld = null;
                }
                if (fld == null)
                {
                    fld = getFieldWithFocus();
                    if (fld != null)
                        _null.setFocus(); 

                }
                else
                {
                    if (!fld.isFocus())
                        fld.setFocus();
                }
                return true;
            }
       
            case TouchEvent.CLICK:
            case TouchEvent.UNCLICK:
            {
                return super.touchEvent(message);
            }
        }
        return true;
       
    }
   
 

And a custom BitmapField

=====================

public class BitmapMenuBarBitmapField extends BitmapField
{

    public BitmapMenuBarBitmapField()
    {
    }

    public BitmapMenuBarBitmapField(Bitmap bitmap)
    {
        super(bitmap);
    }

    public BitmapMenuBarBitmapField(Bitmap bitmap, long style)
    {
        super(bitmap, style);
    }

    protected boolean touchEvent(TouchEvent message)
    {
        int iEvent = message.getEvent();
        switch (iEvent)
        {
        case TouchEvent.CLICK:
            fieldChangeNotify(1);
            return true;
        case TouchEvent.UNCLICK: // suppress default menu
            return true;
        }
        return super.touchEvent(message);
    }
}
 

 

And my revised screen

=========================

public class BitmapMenuBarScreen extends MainScreen implements FocusChangeListener, FieldChangeListener
{
    LabelField _lblInfo;
    BitmapField _bf1, _bf2, _bf3, _bf4;
    BitmapMenuBarHFM _mgr;
   
    public BitmapMenuBarScreen()
    {
        super(MainScreen.DEFAULT_CLOSE | MainScreen.DEFAULT_MENU);
       
        _mgr = new BitmapMenuBarHFM(HorizontalFieldManager.USE_ALL_WIDTH | HorizontalFieldManager.FOCUSABLE);
       
        _bf1 = new BitmapMenuBarBitmapField(Bitmap.getBitmapResource("status.png"), BitmapField.FOCUSABLE);
        _bf1.setFocusListener(this);
        _bf1.setChangeListener(this);
        _mgr.add(_bf1);
       
        _bf2 = new BitmapMenuBarBitmapField(Bitmap.getBitmapResource("tmActive.png"), BitmapField.FOCUSABLE);
        _bf2.setFocusListener(this);
        _bf2.setChangeListener(this);
        _mgr.add(_bf2);

        _bf3 = new BitmapMenuBarBitmapField(Bitmap.getBitmapResource("tmPaused.png"), BitmapField.FOCUSABLE);
        _bf3.setFocusListener(this);
        _bf3.setChangeListener(this);
        _mgr.add(_bf3);

        _bf4 = new BitmapMenuBarBitmapField(Bitmap.getBitmapResource("tmStopped.png"), BitmapField.FOCUSABLE);
        _bf4.setFocusListener(this);
        _bf4.setChangeListener(this);
        _mgr.add(_bf4);

        add(_mgr);
       
        _lblInfo = new LabelField("no info yet");
        add(_lblInfo);
   
    }

    public void focusChanged(Field field, int eventType)
    {
        int i = field.getIndex();
        if (eventType == FocusChangeListener.FOCUS_GAINED)
            _lblInfo.setText("focusGained for " + String.valueOf(i));
    }

    public void fieldChanged(Field field, int context)
    {
        int i = field.getIndex();
        if (context == 1)
            _lblInfo.setText("button clicked for " + String.valueOf(i));               
    }
}
 

Highlighted
BlackBerry Development Advisor
Posts: 15,810
Registered: ‎07-09-2008
My Device: BlackBerry PRIV
My Carrier: Bell

Re: Storm, HorizontalFieldManager, Buttons, Swiping, and Focus -- has something changed in 4.7.0.148

Thanks for posting your follow up.  Note that other applications are also affected by this change.  You can see this by gliding your finger across applications icons on the home screen (of a folder that doesn't scroll).
Mark Sohm
BlackBerry Development Advisor

Please refrain from posting new questions in solved threads.
Problem solved? Click the Accept As Solution button.