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
Developer
Posts: 109
Registered: ‎08-21-2012
My Device: Blackberry curve
My Carrier: company
Accepted Solution

touch event in picturescrollfield

I am implementing picturescrollfield for a group of image horizontally. when i am moving with traceball it is moving but when i am touching the screen and trying to scroll nothing is happeing. Can any one tell me how to give touchevent so that the screen scroll horizontally without using traceball by touch

Developer
Posts: 68
Registered: ‎11-24-2010
My Device: Not Specified

Re: touch event in picturescrollfield

Can you please post code snippet?

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

Re: touch event in picturescrollfield

As this Field should handle touchEvents OK as supplied, I suspect you have some code that is capturing the touchEvents and not allowing these to be passed on to the PictureScrollField.

 

I would add your Field to a standard MainScreen, with no overrides of any methods and make sure that it fails in that situation.  If you write this test code in a generic way, so it uses only standard supplied controls, then if this fails, you will be able to paste this in here and we can all run and test it ourselves.

 

Please do not paste in a snippet of code that is just cut/pasted from your current application.  That will almost certainly have redundant stuff that makes it difficult to read and is also specific to your application. 

Developer
Posts: 109
Registered: ‎08-21-2012
My Device: Blackberry curve
My Carrier: company

Re: touch event in picturescrollfield

 pictureScrollField = new PictureScrollField(640,280){};

 pictureScrollField.setData(finalentries, count-1);
         pictureScrollField.setHighlightStyle(HighlightStyle.ILLUMINATE_WITH_MAGNIFY_LENS);
         pictureScrollField.setHighlightBorderColor(Color.WHITE);
        //  pictureScrollField.setLabelsVisible(true);
         Bitmap bgImage=Bitmap.getBitmapResource("background/bg white.png");
         pictureScrollField.setBackground(BackgroundFactory.createBitmapBackground(bgImage));
         FeatureStaticManager staticM=new FeatureStaticManager();
         VerticalFieldManager pictureVert=new VerticalFieldManager(){
                   };
         pictureVert.add(pictureScrollField);
         staticM.add(pictureVert);

 

 

 

Here StaticM is a staticManager where i am desiging the sublayout like this

 

 

package deal.com.firstscreen;

import net.rim.device.api.system.Display;
import net.rim.device.api.ui.Field;
import net.rim.device.api.ui.FocusChangeListener;
import net.rim.device.api.ui.Graphics;
import net.rim.device.api.ui.Manager;
import net.rim.device.api.ui.ScrollChangeListener;
import net.rim.device.api.ui.TouchEvent;
import net.rim.device.api.ui.XYRect;
import net.rim.device.api.ui.component.Dialog;
import net.rim.device.api.ui.container.VerticalFieldManager;
import net.rim.device.api.ui.extension.component.PictureScrollField;

class FeatureStaticManager extends Manager implements ScrollChangeListener, FocusChangeListener {
    // Implement ScrollChangeListener so tha on a scroll, we repaint
    // because the default action is optimised and does not cope
    // with the overlaid Fields.  
    boolean scrollListenerSet = false;
    //SpecialButtonField bf = null;
    XYRect ourExtent = new XYRect();
    public FeatureStaticManager() {
        super( Manager.USE_ALL_HEIGHT);
    }
    // Override paintBackground just so we can see the extent of this Manager
    // Not necessary, just done to make it easier to see.  
    public void paintBackground(Graphics g) {
        int currentBackgroundColor = g.getBackgroundColor();
        try {
            g.setBackgroundColor(0X00CCCCCC);
            g.clear();
        } finally {
            g.setBackgroundColor(currentBackgroundColor);
        }
    }
    // Only expect two Fields
    // 1) A VFM which will scroll to handle the ListField
    // 2) A button that we will stuck at the bottom right
    protected void sublayout(int maxWidth, int maxHeight) {
        maxHeight = Display.getHeight()/2;
        // Set the Height that the ListField will use when scrolling.  
        if ( this.getFieldCount() != 2 ) {
            //throw new RuntimeException("Incorrect number of Fields added"+ this.getFieldCount());
            //Dialog.alert("field count:"+this.getFieldCount() );
        }
        VerticalFieldManager listFieldManager = (VerticalFieldManager) this.getField(0);
        
//        if ( !scrollListenerSet ) {
//            scrollListenerSet = true;
//            
//            listFieldManager.setFocusListener(this);
//        }
        super.layoutChild(listFieldManager, 640, 300);
        super.setPositionChild(listFieldManager, 0, 0);
        if ( listFieldManager.getHeight() < maxHeight ) {
            maxHeight = listFieldManager.getHeight();
        }
        VerticalFieldManager imgVert=(VerticalFieldManager) this.getField(1);
//        bf = (SpecialButtonField) this.getField(1);
        super.layoutChild(imgVert, 640, 60);
        super.setPositionChild(imgVert,0, 190);
        setExtent(640, 290);
        
    }
    public void scrollChanged(Manager manager, int newHorizontalScroll, int newVerticalScroll) {
        this.invalidate(); // repaint everything....
    }
    /*
     * Might be needed, comment out code just in case
    public int getFieldAtLocation(int x, int y) {
        if ( x >= this.getWidth() - bf.getWidth() &&
             y >= this.getHeight() - bf.getHeight() ) {
            return 1;
        }
        return super.getFieldAtLocation(x, y);
    }
    */
    // Just used to allow the user to use the trackpad to go horizontally and select the button.
    // Not really needed
    protected boolean navigationMovement(int dx, int dy, int status, int time) {
//        boolean buttonInFocus = bf.isFocus();
//        if ( dx > 0 && !buttonInFocus ) {
//            bf.setFocus();
//            return true;
//        } else
//        if ( dx < 0 && buttonInFocus ) {
//            this.getField(0).setFocus();
//            return true;
//        }
        return super.navigationMovement(dx, dy, status, time);
    }
    // Because the Button keeps moving in relation t the manager
    // and the manager does not expect this,
    // We have to check the touch location ourselves
    protected boolean touchEvent(TouchEvent message) {
        int x = message.getX( 1 );
        int y = message.getY( 1 );
        getExtent(ourExtent);
        if( x < 0 || y < 0 || x > ourExtent.width || y > ourExtent.height ) {
                // Outside the field
                return false;
        }
//        if ( x >= 0 &&
//             y >= ourExtent.height -60 ) {
//        //    bf.onClick();
//            return true;
//        }
      return true;
    }
    public void focusChanged(Field field, int eventType) {
        this.invalidate();
        
    }
}

 

 

**The code is running fine with traceball navigation but when i am using touch screen no horizontal scroll is happening

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

Re: touch event in picturescrollfield

Please read my post above.

 

From looking at your code, the touchEvent processing in your Manager is almost certainly causing the problem. 

Developer
Posts: 109
Registered: ‎08-21-2012
My Device: Blackberry curve
My Carrier: company

Re: touch event in picturescrollfield

Ya i understood ..i am try to remove the touchevent

Developer
Posts: 109
Registered: ‎08-21-2012
My Device: Blackberry curve
My Carrier: company

Re: touch event in picturescrollfield

Ya i got it...i remove that touchevent and now my touch is working ..Thankyou for ur valuable suggestion.

Developer
Posts: 68
Registered: ‎11-24-2010
My Device: Not Specified

Re: touch event in picturescrollfield

I agree what peter said. Why do you need to repaint the screen when scrollchanged is called.I am not able to get the use of FeatureStaticManager . Bit confusing code. Ca you please specify what is it that you are exactly trying to do?
Developer
Posts: 19,633
Registered: ‎07-14-2008
My Device: Not Specified

Re: touch event in picturescrollfield

[ Edited ]

Ah I see you are running code I have given on this forum to always put a button in the bottom right.  There are parts of that code that were specifically designed around the fact that it was a restricted height and scrolled within that - this scrolling will by default move the visible portion of the button and so the Manager needed to be repainted.  However, in this case the PictureScrollField will not scroll vertically and so you probably only need a subset of the code in the Manager, for example, it probably does not need to listen for scroll events,  I suspect it will work as is, but some of the code is probably redundant and potentially confusing.  Your call as to whether you change it. 

 

As documented in the Thread where I gave that code, remember that the code was not production level code, use at your own risk! 

Developer
Posts: 109
Registered: ‎08-21-2012
My Device: Blackberry curve
My Carrier: company

Re: touch event in picturescrollfield

ok. i dont need button on the manager now . i need a transparent image and upon that some lines of code. Because of  which i replace the button from second field and placed the vertical manager . so that i can design my second field as i want ...But doing all i forget about the touchevent what is there in touchevent. now i modefied the touchevent...my code is working