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
Highlighted
New Developer
Posts: 11
Registered: ‎06-25-2009
My Device: Not Specified
Accepted Solution

Horizontal scrollable text edit field issue on 6.0 devices

Greetings,

 

I'm trying to create a editable horizontally scrollable text field.  The general approach is by adding an EditField to a HorizontalFieldManager thats has the style bit HORIZONTAL_SCROLL.  This works great on all devices up to 5.0.  However I am getting a problem on 6.0 devices.

 

When the user attempts to scroll right while focused on this field, the text moves to the left and goes off the horizontal field manager's visible region.  This can also be reproduced when touching the field (Torch device) and continue dragging it to the left until it goes off the screen.

 

Now I understand that this is happening because the edit field itself has a width of ~infinity because its containing manager has scrolling enabled, but this is not an acceptable user experience.

 

I've tried restricting the width to the edit field to the width of the text but that caused illegal argument exceptions.  I've tried hacking a RichTextField with USE_TEXT_WIDTH style bit by directing keyDown inputs to setText on the field but that had other problems.

 

My remaining solution is to restrict the character limit to the width of the manager, wrapping the text onto new line which I've seen almost all other application do, or writing my own scrolling implementation.  The only exception is the BlackBerry native browser app's address bar which seems to be a custom implementation.

 

Reference:

http://supportforums.blackberry.com/t5/Java-Development/Sample-Code-Scrollable-one-line-text-input-f...

 

Any thoughts would be appreciated,

Thank you.

Developer
Posts: 2,268
Registered: ‎07-08-2009
My Device: various
My Carrier: various

Re: Horizontal scrollable text edit field issue on 6.0 devices

Yes, I've seen that problem on both simulator and real Torch and it's extremely annoying. It is the same for any EditField inside a HORIZONTAL_SCROLL Manager, not just for the code in the article. Torch is so sensitive that a simple move seems to cause an almost unbounded scroll.

 

As the first measure, I would setScrollingInertial(false) on textMgr - the inner HorizontalFieldManager (defined in API 6.0.0 only meaning you'll need some conditional compilation).

 

If that fails, I would try something like this:

1) Add a FieldChangeListener on the inner EditField (actually, make the whole class implement FieldchangeListener and add _editField.setChangeListener(this); after creating the new EditField in the constructor)

2) In sublayout, check the current _editField text advance (probably add a whitespace advance to it as a "padding") and calculate how many actual widths (passed to your textMgr's sublayout as width minus borders and padding) it will take to fully contain that text. Restrict the _editField to have only that amount of room and save the number in a class member;

3) In fieldChanged, invokeLater the following:

  - get the current text from _editField and recalculate the necessary width (again, whole number of visible widths)

  - compare that with the current allowed width. If the value is different, updateLayout().

----------------------------------------------------------
please click 'Accept Solution' on posts that provide the solution to the question you've posted. Don't say "Thanks", press 'Like' button instead!
New Developer
Posts: 11
Registered: ‎06-25-2009
My Device: Not Specified

Re: Horizontal scrollable text edit field issue on 6.0 devices

Thank you, the setScrollingInertial(false) was actually what I was looking for. 

 

I wasn't able to implement your approach correctly but I was able to complete another work around I had previously with the help of setScrollingInertial(false).

 

I used a scrolling listener instead to restrict the scroll based on the length of the text (set new scroll when the bounds are reached).  Without setScrollingInertial(false), the scrollChanged callback would have been called numerous time while animating the inertia.

 

Unfortunately, I won't be able to apply this fix because my build must support 4.7 and setScrollingInertial is 5.0+ (client does not want additional builds).  However, this will be useful for future projects.

Developer
Posts: 2,268
Registered: ‎07-08-2009
My Device: various
My Carrier: various

Re: Horizontal scrollable text edit field issue on 6.0 devices

 


williams8 wrote:

 

I wasn't able to implement your approach correctly ...

 


I'm curious as to what exactly was problematic? If I knew what you did and how it failed I could try and see what went wrong and suggest the fix. If it worked, you or I could post a comment to the article describing the problem and the solution.

 

----------------------------------------------------------
please click 'Accept Solution' on posts that provide the solution to the question you've posted. Don't say "Thanks", press 'Like' button instead!
New Developer
Posts: 11
Registered: ‎06-25-2009
My Device: Not Specified

Re: Horizontal scrollable text edit field issue on 6.0 devices

I gave up after identifying that this can only be fixed on 5.0+.  I left the issue as cannot be fixed.

 

On a separate project, I revisited this issue and found another work around.  It is a hack but it serves my purpose. 

 

Fix:

Prevent Navigation Right movement when user has their curson at the end of the text field.

 

Override the following in the horizontal field manager containing the edit field (Of course this is a lazy hack and has issues of its own such as user can't scroll out to the right of this field).

 

protected boolean navigationMovement(int dx, int dy, int status, int time) {
  if (dx > 0 && (_editField != null) && (_editField.getTextLength() == _editField.getCursorPosition())) {
    return true;
  }
  return super.navigationMovement(dx, dy, status, time);
}

Developer
Posts: 2,268
Registered: ‎07-08-2009
My Device: various
My Carrier: various

Re: Horizontal scrollable text edit field issue on 6.0 devices

This is not a hack - it is totally legitimate piece of code. I don't know if dx and dy both can be non-zero, though, so just to safeguard against that case, you could write it like this:

 

protected boolean navigationMovement(int dx, int dy, int status, int time) {
  if (dx > 0 && (_editField != null) && (_editField.getTextLength() == _editField.getCursorPosition())) {
    if (dy != 0) {
      return super.navigationMovement(0, dy, status, time);
    }
    return true;
  }
  return super.navigationMovement(dx, dy, status, time);
}

Still, it's not clear to me why you couldn't use the other, non-setScrollingInertial suggestion. It would at least prevent the field from flying into infinity.

 

----------------------------------------------------------
please click 'Accept Solution' on posts that provide the solution to the question you've posted. Don't say "Thanks", press 'Like' button instead!
Contributor
Posts: 15
Registered: ‎04-01-2011
My Device: Droid 1
My Carrier: Verizon

Re: Horizontal scrollable text edit field issue on 6.0 devices

[ Edited ]

I can verify that applying setScrollingInertial(false) on the inner manager does not work as I use the following inner class for my inntermanager:

 

private class MyHorizontalFieldManager extends HorizontalFieldManager {

        public MyHorizontalFieldManager(long style) {

            super( style );
            setScrollingInertial( false );
        }
    }

 

To add to this post: I too have implemented a work around by capturing every possible navigation movement and handling it in my native code as opposed to passing it up to the managers to handle.

 

This has fixed the scrolling issue while the text box has focus, but the issue is still there when focus is on anything else.

 

I have tried focus checks on just about everything, yet the text will go flying off the screen when a user navigates via the trackpad and the text box is not in focus.

Caleb Hamilton | Metova
www.metova.com
Contributor
Posts: 35
Registered: ‎10-06-2010
My Device: Bold 9650
My Carrier: Verizon

Re: Horizontal scrollable text edit field issue on 6.0 devices

[ Edited ]

Just wanted to let everyone know that I have opened an issue in RIM's issue tracker for this scrolling issue: https://www.blackberry.com/jira/browse/JAVAAPI-1750

 


Joe Davis, Lead Developer
Metova, Inc.
www.metova.com

Joe Davis
Developer | Metova
http://www.metova.com
New Member
Posts: 1
Registered: ‎05-29-2011
My Device: bold
My Carrier: verizon

Re: Horizontal scrollable text edit field issue on 6.0 devices

not ideal but this will handle the case when the field does not have focus (it handles it in a better way than all the text vanishing)

 

protected void paint(Graphics g)

{

if (!this.isFocus() && !textfield.isFocus() && this.getHorizontalScroll() != 0) { this.setHorizontalScroll(0); invalidate(); }

else { super.paint(g); }

}

Trusted Contributor
Posts: 184
Registered: ‎11-26-2010
My Device: Not Specified

Re: Horizontal scrollable text edit field issue on 6.0 devices

Hi William8, I know this is a closed thread, but I am posting here because I am facing a very similar issue on OS 7.1.0(BB Bold 9900). The fix which has been working correctly on OS 6.0 model is not effective on OS 7. 

 

If you tried the same on OS 7.0 or any knowledge on how to handle this or any other update about this issue on the above version would be of very great help for me! I have posted a seperate question for my issue, please visit by and drop me your valuable solution.  ISSUE LINK

 

 

A Y.

Smiley Happy