How to display Half screen? - blackberry

I am working on a project where I need to display a ListField that takes the top half of the screen when the user clicks on a menu item. It should display on top of the earlier screen. How can I implement it?
Here are my ideas:
Use ListField directly with the above screen size to required screen.
Use PopupScreen with ListField
Use some screensplit functionality to display half of the screen

PopupScreen is best fit for your question. Can you try and post the code that didn't work?
Another option is to use managers to split the screen (higher manager and lower manager) and to hold another two managers: one that will be displayed on click and one that will be used as a pointer to the displayed Manager. Then, when ever the replace event is fired you should call the following function:
void updateManagers(boolean click)
{
if(click)
{
currentManager = afterClickManager;
}
else
{
currrentManager = beforeClickManager;
}
invalidate();
}
Where currentManager is an instance of Manager and afterClickManager & beforeClickManager are instances of some class which extends Manager (no need to be the same class).
Note that you should add currentManager to your screen layout before using the invalidate function.

Related

How to make content navigation button (remains pressed when clicked) in Vaadin

I created basic vertical layout that work as side menu and now I want to place some buttons in it. Few of them gonna work as common side menu buttons, they just change page content so I want to mark that they are clicked in some way, how can I achive that? Or maybe there is better way?
As stated in the 5th version of Vaadin7 manual, you can attach an event listener to the Button.
button.addClickListener(new Button.ClickListener() {
public void buttonClick(ClickEvent event) {
// show the button has been clicked with a CSS class:
button.addStyleName("v-button-clicked");
}
});
Don’t forget to define the v-button-clicked class. Of course you’re free to add the class of your liking through the .addStyleName() method.

set header and footer in BlackBerry in VerticalFieldManager

I searched how to set header and footer in BlackBerry and I found the functions setTitle() and setStatus().
My problem is I have created a class that extends VerticalFieldManager. In VerticalFieldManager, it is not showing me setStatus function as this is function of MainScreen class.
You're right. A VerticalFieldManager does not allow you to setStatus() directly.
It's important to understand the relationship between the classes in the BlackBerry UI framework.
First of all, there are Screen classes. Normally, a Screen will take up the entire device screen. You can have many different Screen classes in your app. Maybe one Screen for a splash image, one screen for a map view, one screen for settings, etc.
Inside your screens, you will often have Manager classes. A VerticalFieldManager is a kind of Manager that arranges its contents top-to-bottom, in the order that you add them. A Manager holds a group of related objects, but it does not have to span the full screen height, or width.
Inside your managers, you will usually have multiple Field objects. A Field is the individual item in the heirarchy. ButtonField, EditField, or BrowserField are all kinds of fields. They will usually be added to managers (containers). Those managers will then usually be added to screens.
So, in your case, I think what you should have is a screen class. In that screen class, you will set the header and footer by calling setTitle() and setStatus(). The content between the header and footer will all be contained in a VerticalFieldManager that you add to the screen. Something like this:
public class MyScreen extends MainScreen {
public MyScreen() {
super(MainScreen.VERTICAL_SCROLL | MainScreen.VERTICAL_SCROLLBAR);
// set a header for this screen
setTitle("My Header / Title");
// screen contents go in the vertical field manager
// NOTE: you can replace VerticalFieldManager with your own class
// that extends Manager, or VerticalFieldManager, if you like
VerticalFieldManager vfm = new VerticalFieldManager();
vfm.add(new LabelField("One"));
vfm.add(new ButtonField("Two", ButtonField.CONSUME_CLICK));
vfm.add(new CheckboxField("Three", true));
add(vfm);
// use a bitmap as a footer
Bitmap footer = Bitmap.getBitmapResource("footer.png");
setStatus(new BitmapField(footer));
}
}

BlackBerry software keyboard listener on OS 4.5 (or later) compatible code

I am developing an app which supposed to work on devices that have OS 4.5 or later. In my application I need to know when the virtual keyboard is visible or invisible. Because if virtual keyboard is visible, the text area which the user is supposed to type in is behind the keyboard. If I could determine the moment of virtual keyboards state changed, I could refresh the screen and move the text area upper location.
Is there a way to do that?
Edit: the next button is at the status panel. The edit field is at the custom horizontal field manager.
When I touch the edit field, the virtual keyboard opens and the contents of the edit field is lost.
There is no way to do that with the same code. You need to divide your code in two. One of them handles 4.5 - 4.7. The other handles 4.7 and later.
You can add a keyboard listener to 4.7 (and later) code that should check whether the screen changes in a continuous thread. It is not good, but it can work.
You have two choices. The first choice is better:
Figure out an invariant that works with the keyboard visible or hidden. The screen layout method is invoked when the visibility state of the keyboard changes, and the vertical size is reduced for a visible keyboard. If your invariants take advantage of that then you can just implement the logic in the screen layout method.
In this case, I would suggest a layout method that always keeps the 'next' button at the bottom of the screen, and puts the username textbox in the center of the remaining space.
Use conditional compilation so you can write code that makes reference to the VirtualKeyboard class on OS 4.7+, and that code goes away in the older BlackBerry releases. 4 July: by conditional compilation, I mean use the BlackBerry preprocessor.
There is no event for this, but you can determine current state of virtual keyboard and set required state.
For example hide it
if(VirtualKeyboard.isSupported() == true){
VirtualKeyboard keyboard = getVirtualKeyboard();
if(keyboard != null)
keyboard.setVisibility(VirtualKeyboard.HIDE);
}
It is a quite challenging job. However, I believe there is no direct API or way to determine the virtual Keyboard state. The only way is to override the setLayout() method and determine if the screen width and height has been changed. And also you need to check the GUI layouts of your screen.
Set the VERTICAL_SCROLL style for the Manager which holds the EditField, or you can use a Screen with VERTICAL_SCROLL style. Doing this, the EditField automatically scrolls when the keyboard is displayed.
Use following class, maybe this is helpful for you:
class FocusableManager extends MainScreen implements FocusChangeListener
{
private BasicEditField b;
public FocusableManager()
{
VerticalFieldManager vfm=new VerticalFieldManager(VERTICAL_SCROLL);
vfm.add(new ButtonField("first"));
b=new BasicEditField();
b.setFocusListener(this);
vfm.add(b);
vfm.add(new ButtonField("second"));
vfm.setMargin(250,0,0,0);
add(vfm);
}
public void focusChanged(Field field, int eventType)
{
if(field==b)
{
if(eventType==1)//when edit field gain focus
{
VirtualKeyboard virtKbd;
virtKbd = getScreen().getVirtualKeyboard();
virtKbd.setVisibility(VirtualKeyboard.SHOW_FORCE);
}
else if(eventType==3)//when edit field lost focus
{
VirtualKeyboard virtKbd;
virtKbd = getScreen().getVirtualKeyboard();
virtKbd.setVisibility(VirtualKeyboard.HIDE_FORCE);
}
}
}
}

How to access filed on the screen using Screen Object ( UiApplication.getUiApplication().getActiveScreen())

My Query is How to access Fields on the stacked screen using Screen Object ?
The exact problem is as follows:
I have one screen which has one text field (ClientName) when user clicks on that field , application will then push a new screen and it will allow the user to search in remote database using MyWebSerivces. and when user selects the one client from the search result ,i want to set the text Field on the previous screen with the text that user has selected on the current screen..
i have tried the pushScreen( new screen("text) ) and that might be the result if i want to do this operation only once but this is not the option for me since there is two more such field which will go to other screen to fetch the data from webservices . and if i every time i push new screen then after every pushscreen operation i will only get one field set with the desired text
This not a blackberry (or any specific programming language) related question. This is a question of application architecture and common sense. If one screen should change a Field of another screen, then just pass a reference of the Field to the screen that will change it.
hi i once had same problem and i did like this:
Screen1
------------------
Client Name | text field |
------------------
When user clicks on this text field or any button you push Screen2
In screen 2 when user selects a particular value then u do this.
1) take a static variable in main class say clientName.
2) set value of this variable.
3) pop active screen
UiApplication.getUiApplication().getActiveScreen();
when this code is called then u come back to Screen1
Now in screen1 a method is called
public void onExposed()
{
//here u can set the text in textfield using the static variable
invalidate(); // for repainting
}
i have found the answer to my question. the solution was there lying in my question but at first i was not able to find it.
solution was very simple
when i wrote i want to use
UiApplication.getUiApplication().getActiveScreen()
that was almost the right way and i was proceeding in right direction but the thing that i was missing was " I was not casting the screen (that i have just retrieved form the stack top ) to its type
only thing i should have done is "should have casted screen to its type.like this
UiApplication.getUiApplication().posScreen(this)
(MyScreen1) UiApplication.getUiApplication().getActiveScreen()
now i am able to access all the fields on the retrieved screen (MyScreen1)
things to keep in mind
make sure u cast the screen to its type only otherwise bb will give u resource not found error
Benifits of using screen on Stack
u can use already created screen from the stack no need to create new one
if u will create new screen it will be stacked in memory and will consume more and more memory even if its of no use ( make habit to pop the screen if it is of no use instead of leaving it on stack))
no need to create any static variable since u will be able to set all the field right away from other screen

Remove menu item on Blackberry

In my Blackberry application, I have screen with few menu items (created by myself in makeMenu()).
On this screen, sometimes I should remove two of this menu items.
But menu.deleteItem() method does not work.
How i can remove menu item in application menu, without recreate new instance of screen? Is it real for already constructed menu? Or mb I should refresh menu/screen someway?
Thanx.
The menu is drawn at the point it's selected so all I do is set conditions on anything that's not static, example below:
protected void makeMenu( Menu menu, int instance ) {
menu.add(staticMenuItem);
if (condition) menu.add(dynamicMenuItem);
}

Resources