Fixed Size Blackberry VerticalFieldManager: Scrolling Problem

I am trying to have a full-screen interface with a patch title (manager with some fields) and scrollable content (list of custom field). The idea is to emulate some kind of scrollable list.

To do this, I created a custom VerticalFieldManager that accepts maxHeight (screen height - header height).

I am having the following issues:

  • Scrolling arrows are not displayed (ever)
  • In OS 4.7 (Storm), I can scroll lower than the last item until nothing but a title appears on the screen.

My code needs to be compiled using JDE 4.2.1 and 4.7 and run on Pearl and Storm. (in the worst case, I could have two versions of this class)

I suspect these two issues are related. I probably have something wrong. I looked through some examples / forum and always found a similar solution / code. Can you guys tell me what I did wrong?

/**
 *  custom class, so we can set a max height (to keep the header visible)
 */
class myVerticalFieldManager extends VerticalFieldManager{
private int maxHeight = 0;

myVerticalFieldManager(int _maxHeight){
  super(
   //this provoc an "empty scrollable zone" on Storm
   // but if you don't put it, on other OS, the vertical manager does not scroll at all.
   Manager.VERTICAL_SCROLL 

   | Manager.VERTICAL_SCROLLBAR
   ); 
  maxHeight = _maxHeight;
}


protected void sublayout(int width, int height){
        super.sublayout(width, getPreferredHeight());
        setExtent(width, getPreferredHeight());
}

public int getPreferredWidth() {
    return Graphics.getScreenWidth();
}

/**
 * allow the manager to use all the given height. (vs auto Height)
 */
public boolean forceMaxHeight = false;
public int getPreferredHeight() {
  if (forceMaxHeight) return maxHeight;
  int m = super.getPreferredHeight();
  if (m > maxHeight) m = maxHeight;
  return m;   
}    

////////////////////////////////////////////////////////////////////////////

protected boolean isUpArrowShown(){
  //TODO: does not seem to work (4.2.1 emulator & 4.5 device). (called with good return value but the arrows are not painted)
  int i = getFieldWithFocusIndex();
  //Trace("isUpArrowShown " + i);
  return i > 0;
  // note: algo not correct, cause the up arrow will be visible event when no field are hidden.
  //       but not so bad, so the user "know" that he can go up.
}

protected boolean isDownArrowShown(){
  int i = getFieldWithFocusIndex();
  return i < getFieldCount();
}

////////////////////////////////////////////////////////////////////////////
// note : since 4.6 you can use
// http://www.blackberry.com/developers/docs/4.6.0api/net/rim/device/api/ui/decor/Background.html

public int myBackgroundColor = 0xffffff;
protected void paint(Graphics g){
    g.setBackgroundColor(myBackgroundColor);
    // Clears the entire graphic area to the current background
    g.clear();
    super.paint(g);
}


} 

Any hints are welcome.

+3
source share
3 answers

So,

I came up with this workaround for the "empty scrollable zone" problem on STORM, it is ugly and does not allow ScrollChangeListener to be configured, but it works with Pearl and Storm

implements ScrollChangeListener

 //in constructor:

  setScrollListener(null);
  setScrollListener(this);


private boolean MY_CHANGING_SCROLL = false;
public void scrollChanged(Manager manager, int newHorizontalScroll, int newVerticalScroll){
  if (!MY_CHANGING_SCROLL){
    MY_CHANGING_SCROLL = true;
    myCheckVerticalScroll();
    MY_CHANGING_SCROLL = false;
  }      
}  


protected int myMaxVerticalScrollPosition(){
  int vh = getVirtualHeight();
  int h = getHeight();
  if (vh < h ) return 0; // no scroll
  return vh - h; // don't scroll lower than limit.
}

protected void invCheckVerticalScroll() {
    int i = getVerticalScroll();
    int m = myMaxVerticalScrollPosition();
    if ( i > m){
        i = m;
        setVerticalScroll(i);
    }
}

I'm still looking for a solution to the problem with scroll arrows ... If anyone got an idea ...

+4
source

setBanner() . VerticalFieldManager , , . , MainScreen VerticalScrollManager, vfm.

HorizontalFieldManager hfm = new HorizontalFieldManager();
setBanner(hfm)

add(new ButtonField("Hello 1");
add(new ButtonField("Hello 2");

...

+2

Hey, I did the same using the HorizontalFieldManager, which contains the image and title.

header_img = Bitmap.getBitmapResource("header.png");
             title = new LabelField("Welcome",LabelField.FIELD_RIGHT);
             header_manager =  new HorizontalFieldManager()
             {
                 protected void paint(net.rim.device.api.ui.Graphics graphics)
                    {
                         int y = this.getVerticalScroll();                                      
                         graphics.drawBitmap( 0, y, header_img.getWidth(), header_img.getHeight(), header_img, 0, 0 );
                         graphics.setColor(Color.LEMONCHIFFON);
                         super.paint( graphics );
                    }

                     protected void sublayout(int maxWidth, int maxHeight) 
                     {                      
                        super.sublayout(Display.getWidth(), 240);

                        Field field = title;
                        layoutChild(field, title.getWidth(), title.getHeight());
                        setPositionChild(field, (Display.getWidth()/2) -10, 13);
                        setExtent(Display.getWidth(),55);

                     }
             };
             header_manager.add(title);
0
source

Source: https://habr.com/ru/post/1721678/


All Articles