Android Question Inline JAVA Help

wonder

Expert
Licensed User
Longtime User
Hi!

Can anyone help me implement this function using Inline JAVA?

B4X:
@SuppressLint("NewApi")
private int getSoftButtonsBarHeight() {
    // getRealMetrics is only available with API 17 and +
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
        DisplayMetrics metrics = new DisplayMetrics();
        getWindowManager().getDefaultDisplay().getMetrics(metrics);
        int usableHeight = metrics.heightPixels;
        getWindowManager().getDefaultDisplay().getRealMetrics(metrics);
        int realHeight = metrics.heightPixels;
        if (realHeight > usableHeight)
            return realHeight - usableHeight;
        else
            return 0;
    }
    return 0;
}

Resources:
https://developer.android.com/refer...l#getRealMetrics(android.util.DisplayMetrics)
http://stackoverflow.com/questions/...ht-of-the-status-bar-and-soft-key-buttons-bar

Many, many thanks in advance!
 

JordiCP

Expert
Licensed User
Longtime User
Try this ;)
B4X:
Sub Process_Globals
   'These global variables will be declared once when the application starts.
   'These variables can be accessed from all modules.
   Dim JO As JavaObject
End Sub

Sub Globals
   'These global variables will be redeclared each time the activity is created.
   'These variables can only be accessed from this module.

End Sub

Sub Activity_Create(FirstTime As Boolean)
   'Do not forget to load the layout file created with the visual designer. For example:
   'Activity.LoadLayout("Layout1")
   If FirstTime=True Then
     JO.InitializeContext
   End If
End Sub

Sub Activity_Resume
   Dim h As Int = JO.RunMethod("getSoftButtonsBarHeight",Null)
   Log(h)
End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub

#if JAVA

import android.os.Build;
import android.util.DisplayMetrics;

public int getSoftButtonsBarHeight() {
  // getRealMetrics is only available with API 17 and +
  if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
    DisplayMetrics metrics = new DisplayMetrics();
    getWindowManager().getDefaultDisplay().getMetrics(metrics);
    int usableHeight = metrics.heightPixels;
    getWindowManager().getDefaultDisplay().getRealMetrics(metrics);
    int realHeight = metrics.heightPixels;
    if (realHeight > usableHeight)
      return realHeight - usableHeight;
    else
    return 0;
  }
  return 0;
}

#end if
 
Upvote 0

JordiCP

Expert
Licensed User
Longtime User
Yes. Most of the times it is just a matter of finding the correct "imports"
and making the called function "public", otherwise it will not be found
 
Upvote 0
Top