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
Contributor
sanghamitra_83
Posts: 17
Registered: ‎08-06-2012
My Device: Curve 9320
My Carrier: Vodaphone

handling touchEvent in navigation Click

Hi,

 

 

Field focus = UiApplication.getUiApplication().getActiveScreen().getLeafFieldWithFocus();

 

This one returns the focused field in navigationClick, Which method should I call to get the touched field in navigation click

 

or How can I handle touchEvent in NavigationClick?

 

Thanks,

 

Please use plain text.
Super Contributor
pp
Posts: 278
Registered: ‎11-04-2010
My Device: 4.5 and above
My Carrier: none

Re: handling touchEvent in navigation Click

Hi,

 

In your customField class add these method to handle click event for touch, trackball click, trackwheel click.

 

/**
     * <description> handle touch event for above 4.7 device
     * @param message <description>
     * @return <description>
     */
    protected boolean touchEvent( TouchEvent message )
    {
        int x = message.getX( 1 );
        int y = message.getY( 1 );
        if( x < 0 || y < 0 || x > getExtent().width || y > getExtent().height ) {
            // Outside the field
            return false;
        }
        switch( message.getEvent() ) {
       
            case TouchEvent.UNCLICK:
                //clickButton();
                return true;
            case TouchEvent.DOWN:
                {
                    setFocus();
                    invalidate();
                    return true;
                }
        }
        return super.touchEvent( message );
    }
    //#endif 
    
    /**
     * <description> handle click events
     * @param status <description>
     * @param time <description>
     * @return <description>
     */
    protected boolean trackwheelClick( int status, int time ){        
        clickButton();    
        return true;
    }
    protected boolean navigationClick( int status, int time ) {
        clickButton(); 
        return true;    
    }
    protected boolean keyChar( char character, int status, int time ) {
        if( character == Characters.ENTER ) {
            clickButton();
            return true;
        }
        return super.keyChar( character, status, time );
    }
    public void clickButton() {
        fieldChangeNotify( 0 );
    }

 

 

Regards,

pp

Please use plain text.
Super Contributor
pp
Posts: 278
Registered: ‎11-04-2010
My Device: 4.5 and above
My Carrier: none

Re: handling touchEvent in navigation Click

Hi,

and for handling touch event in screen override touchvent method, and same method is used to get the focused field.

Field f = manager.getField(manager.getFieldWithFocusIndex());

Regards,
pp
Please use plain text.
Contributor
sanghamitra_83
Posts: 17
Registered: ‎08-06-2012
My Device: Curve 9320
My Carrier: Vodaphone

Re: handling touchEvent in navigation Click

Hi,

 

This is fine. But I have heard that for Blackberry 6 onwards, no need to handle touchEvent separately,  the navigationClick() does all. But for me in simulator it is not working unless the focus is set on the field.

 

That is my question, without setting the focus on a field how to handle the touchEvent.

Please use plain text.
Super Contributor
pp
Posts: 278
Registered: ‎11-04-2010
My Device: 4.5 and above
My Carrier: none

Re: handling touchEvent in navigation Click

Hi,

can you pls add some sample code and where its not working.

and if you want to handle touch without making it focus, then get x and y values in touchEvent and control it.

something like this..

protected boolean touchEvent(TouchEvent message) {
int eventCode = message.getEvent();
if (message.getEvent() == TouchEvent.CLICK) {
int x = message.getX(1);
int y = message.getY(1);
XYRect r = yourManager.getExtent();
if (r.contains(x, y)) {
//control it here
}
}
}


and if you put click event code i.e in prev post - methods in custom field the you can just override fieldChange method.

Regards,
pp
Please use plain text.
New Developer
saurabh0208
Posts: 10
Registered: ‎08-24-2012
My Device: 9820
My Carrier: Airtel

Re: handling touchEvent in navigation Click

U have to override the touch event and handle the down event.

Please use plain text.