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
Contributor
Dan277
Posts: 21
Registered: ‎04-10-2013
My Device: All
My Carrier: 447920403580

Re: Get virtual keyboard height

I now have my program resizing perfectly when tilting, however, I can still not get the height of the keyboard. The only time Display.getHeight() returns the height minus the keyboard size is when the screen is tilted horizontally and the keyboard isn't even displayed. Can someone please help me with this? There must be some way to get the height of virtual keyboard. Thank you

Please use plain text.
Developer
peter_strange
Posts: 19,603
Registered: ‎07-14-2008
My Device: Not Specified

Re: Get virtual keyboard height

As noted, I have never managed.  I will see if any thoughts pop up.

 

My understanding is that this is not a great thing to do:

"I can simply call setFont(font) in my fields' paint functions"

 

I believe this can be recursive - in that you call setFont, the Field thinks you have changed the Font, and so invalidates itself, which causes a layout and a repaint.  Which causes a setFont.....

Please use plain text.
Developer
simon_hain
Posts: 16,113
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport
My Carrier: O2 Germany

Re: Get virtual keyboard height

you can call setFont on the graphics object
----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
Please use plain text.
Developer
peter_strange
Posts: 19,603
Registered: ‎07-14-2008
My Device: Not Specified

Re: Get virtual keyboard height

Oppss,  thought OP meant on the Field.  Sorry.

Please use plain text.
Contributor
Dan277
Posts: 21
Registered: ‎04-10-2013
My Device: All
My Carrier: 447920403580

Re: Get virtual keyboard height

I've finally managed to get the height of the virtual keyboard. I only want the virtual keyboard when the screen is in portrait mode, so as soon as it's in portrait mode I load this screen:

 

public class StartScreen extends MainScreen
{
   private boolean alreadyRun;
	
   public StartScreen()
   {
      getScreen().getVirtualKeyboard().setVisibility(VirtualKeyboard.SHOW_FORCE);
   }
	
   protected void paint(Graphics graphics)
   {
      UiApplication.getUiApplication().invokeLater(new Runnable()
      {
         public void run()
         {
            if (!alreadyRun)
            {
               alreadyRun = true;
               NewScreen.KeyboardHeight = NewScreen.StartingScreenHeight - Display.getHeight();
               close();
            }
         }
      });
   }
}

 

I also had to override paint so I can update the changes:

 

static boolean UpdateDisplay;
protected void paint(Graphics graphics)
{
   if (UpdateDisplay
   {
      UpdateDisplay = false;
      UiApplication.getUiApplication().invokeLater(new Runnable()
      {
         public void run()
         {
            SetLayout();
            invalidate();
         }
      });
   }
   super.paint(graphics);
}

 It causes the screen to flicker when getting the keyboard height, so it's not a perfect solution, but it's the only solution I have. I can save the keyboard height using persistent storage, so the code will only need to run the first time the program is run in portrait mode.

 

Please use plain text.