10-28-2011 05:19 AM
I have a verticalfieldmanager. Which is scrolling vertically and it has height of 100 pixels. I have added 50 bitmap fields vertically to it. Each field height is 35 pixels. So at a time 3 fields are visible. I want to give the middle field focus all the time. So when i scroll up or down. Focus should not move but fields should move vertically.
Also consider one thing this shuld be possible in touchscreen devices also.
If field is focusable it gets focus when we touch.
11-01-2011 09:02 AM
You can do this but it would require implementing much of your own logic, likely overriding several methods in the VerticalFieldManager. You'll want to look into the navigationMovement() and touchEvent() methods to begin, and you'll need to programmatically scroll the manager to keep your middle image in the center (setVerticalScroll()). If you hit any roadblocks please post back to this thread.
11-01-2011 09:42 AM
There might be a slightly easier way, though I have never tried ti with a VFM, I do something similar with a HFM.
Define a scroll changed listener for the VFM. In there, get notification each time scroll changes. Start a Thread, and put the Thread on 'hold watching the current scroll position' If the Thread detects no further scroll changes after a small period (say .1 of a second, then do a setVerticalScroll on the VFM to a point that will ensure that the middle image is centered and shutdwon the Thread.
I do this with an HFM to keep images cetered. In fact the Thread does not immediately go the the central position, but will move the HFM a bit at a time to make it look like it is scrolling. What the user sees is that they flick the images, it coasts to a stop (normal HFM processing), then my 'centering Thread' wiggles it into position. Looks kind of cool to a sad old developer like me......
Watch out for end cases.....
Sorry code was developed for some one else, so I can't publish.
11-01-2011 10:34 AM
Just to expand a little on what Peter has said:
You have two possible sources of navigation with your Manager: touch scroll (swipe / move) and trackball / touchpad. The first one is caught by the scroll change listener Peter described. The second one will cause focus changes and is detected with FocusChangeListener on the same Manager. The problem is, the two listeners will "notify" each other since they the first one will cause focus shifts while the second one will cause scroll changes. So make sure you are not recursively going back and forth between the two - do nothing when the screen is in the desired state.
To make it as generic as possible you will probably need the following methods:
1) in your Manager: getVerticalScroll, setVerticalScroll, setFocusListener, setScrollListener, getFieldAtPosition, getFieldWithFocus (or getFieldWithFocusIndex, depending on your implementation), getVisibleHeight, maybe getVirtualHeight;
2) in the field with focus (or the one about to receive focus): getExtent, setFocus
Also, any actions which will affect the screen (such as setVerticalScroll or setFocus) should be wrapped in invokeLater (not synchronized on Event Lock - that is insufficient!). Calculate the parameters then schedule the execution for after your scrollChanged or focusChanged processing is complete - otherwise you might create all kinds of infinite loops and eventual stack overflow.