How to prevent scrolling in one direction in a HorizontalFieldManager? - blackberry

I have a requirement for a one-line edit field that can accept text longer than the edit field's width (like a "normal" Windows textbox).
Since the BasicEditField control normally word-wraps its contents, I've implemented this requirement by placing my BasicEditField inside a HorizontalFieldManager that allows horizontal scrolling.
This works in one sense: if I type text longer than the edit field's width, the HFM automatically scrolls to the left (taking the edit field with it) which keeps the cursor visible at the right.
The problem is that the user can swipe right-to-left, which moves the BasicEditField completely off the screen to the left. I want to be able to only scroll left when the BasicEditField's contents are too wide to be shown entirely, and only allow just enough leftward scrolling to keep the cursor visible on the right.

I fought this exact scenario when implementing my own EditField. What's happening is since you allow horizontal scrolling, and an EditField by nature wants to use as much width as it can, you end up with a very wide EditField. I'm copying this from my code, so hopefully it will work for you, but if it doesn't add a comment and I'll try to see if I can help get it working.
EditField edit = new EditField(EditField.NO_NEWLINE | style) {
protected void fieldChangeNotify(int context) {
try{
super.fieldChangeNotify(context);
setExtent(this.getFont().getAdvance(this.getText()) + 10, this.getHeight());
}
catch(Exception e){
//don't recall why I needed this, but it works so I'm hesitant to remove it
}
}
protected void layout(int width, int height) {
super.layout(width, height);
setExtent(this.getFont().getAdvance(this.getText()) + 10, this.getHeight());
}
};
What this will do is progressively make the EditField wider as the text grows. I had this inside of an HFM that grew with it as well, but you might not need that. I did this because if the field grew wider than the screen width, rather than scrolling the entire screen you could let this single Field scroll horizontally. Also, the + 10 is in there because it was clipping the cursor without it. If you would like that as well I can edit this post to include it.

Related

Is there a way to auto-scroll horizontally in a Vaadin Grid?

Currently using Vaadin 23 and was wondering if it was possible to use scroll horizontally within a Grid programmatically, much like some of the built-in functionality with scrolling to the top or bottom row. However, in this case I would like to scroll using a column as reference (while maintaining the current vertical scroll position).
One idea would be to put a component into the column header, and then scroll to that component. Something like:
Grid.Column<SamplePerson> emailColumn = grid.addColumn("email");
Span emailHeaderText = new Span("Email");
emailColumn.setHeader(emailHeaderText);
Button scrollToEmail = new Button("Scroll", e ->
emailHeaderText.scrollIntoView()
);
It doesn't work perfectly, as the header component does not cover the whole column width, but it might be good enough.

Is there a way to remove the gap under my Today Extension

Ok, I'm trying to make todays view extension and I would really like to make it have 77 pixels of height. But no matter what iOS keeps inserting a padding under my top view.
Like this:
You see, I'm calling setPreferredContentSize passing a height of 77. But the gap is always there. Even If I set my content size smaller, it gets cut, but the padding is still there and apparently with the same size, the image bellow illustrates:
Does someone have anything to say about this? I'm trying this because Evernote's widget seems to manage to remove that gap, but i'm really stuck, I even disabled autolayout, but nothing.
Try adding the following:
-(UIEdgeInsets)widgetMarginInsetsForProposedMarginInsets:(UIEdgeInsets)defaultMarginInsets {
return UIEdgeInsetsMake(
defaultMarginInsets.top,
defaultMarginInsets.left,
0,
defaultMarginInsets.right );
}

Is there a way to make something truly free scrolling div (any direction) on iOs webview

I want a div that can be dragged any direction and is about 4x width and 4x height of the screen.
I set the body height and width, and you can scroll it diagonally some of the time, but other times when you go to scroll it will go only straight vertically or straight horizontally. It seems to be when you start scrolling straight up, it sticks that way. Is this normal for scrolling in an oversized webview div, or is there something else that might explain this?
This is on an iPad, with a body set to width:4000px and height:3000px.
The iPhone's tendency to scroll exactly horizontally or exactly vertically is intentional, and it's usually a useful feature: if you're reading a tall column of text that could scroll horizontally, it's nice to be able to scroll down without worrying about accidentally moving the view from side to side as you go. As far as I'm aware there's no way to turn this behavior off.
there is a property name directionalLockEnabled that get a bool
in scrollView class.
this will do the trick:
theWebView.scrollView.directionalLockEnabled = NO;

Blackberry fieldmanager issues

I am building a blackberry app for BB Curve.I have a verticalfieldmanager where i am adding a Button,i set its extent as 320*22.I have a horizontalfieldmanager where i am adding two editfield and its extent is 296*22.Finally i am adding both these manager into another verticalfieldmanager whose extent i have set as 320*240.i use setBackgroundBitmap(Background bg) to set the background image.But when i set the extent of the main verticalfieldmanager,only the background image is set,but the other two managers where i have added editfield and button are not visible.But when i dont set the extent of the main vertical manager,than the editfield and button are added to the screen,but the background image is not added.So where i am doing wrong?
It looks like you're going to have to play with your extents to make sure that you given the child Managers enough space to layout the Fields. In your sublayout(int width, int height) of the Managers, check what dimensions are getting passed to it. If they are less than the space it needs to layout, it won't be able to display its Fields.

Adding vertical scrollbar to screen in blackberry application

hi I am new to blackberry development..
I am trying to add a vertical scroll bar on the screen, but not able to do that. because I do not know the way.
VerticalScrollManger scroll = new VerticalScrollManager(Manager.VERTICAL_SCROLL);
please give me the solution.
thanks
Things that extends net.rim.device.api.ui.Manager (like a VerticalFieldManager) can have style bits set in the constructor that specify which type(s) of scrolling you want and whether or not the scrollbars (arrows) should be displayed. Put your Field into a manager that has scrolling enabled and set the manager for the screen You need to set the manager containing the component/field that is too large for the screen to have scrolling enabled AND scrollbars drawn to see scroll arrows.
The style bits you want to set are: Manager.VERTICAL_SCROLL | Manager.VERTICAL_SCROLLBAR
If your UI is built on top of the blackberry classes MainScreen or FullScreen, you can use the constructor taking an argument of type long to set the style bits: MainScreen(long style) could be called as MainScreen(Manager.VERTICAL_SCROLL | Manager.VERTICAL_SCROLLBAR); to set the style bits for the screen to include scrolling and vertical scroll indicator arrows.
There is an occasional issue that FieldManagers that are fixed size will sometimes not show scroll arrows (but they'll still scroll). See Blackberry VerticalFieldManager with fixed size : Scroll issue if you are concerned about that issue.
If by scrollbars you mean the small blue arrows, then you can get these to display using the method Jessica described above (set style bits VERTICAL_SCROLL and VERTICAL_SCROLLBAR). However, if by scrollbars you are referring to actual bars that indicate the scrolled position (as seen in the Browser app) then you would need to draw these on the manager yourself, as the BlackBerry API doesn't provide you with any way to display them automatically.
To do something like that you'd need to subclass VerticalFieldManager and override the paint method. Use a combination of the screen height (Display.getHeight()), the manager height (getVirtualHeight()) and the scroll position (getVerticalScroll()) to calculate the Y position and height of the bar, and then draw it on the screen using g.drawRect() or something similar.
If you want a fancier-looking scrollbar, take a look at my article in BlackBerry knowledge base:
http://supportforums.blackberry.com/t5/Java-Development/Implementing-a-standard-style-scrollbar-on-a-Blackberry-device/ta-p/504416

Resources