package ir.arminkh.screencomponentsize;
import android.graphics.Rect;
import android.view.Window;
import anywheresoftware.b4a.BA;
import anywheresoftware.b4a.BA.ActivityObject;
import anywheresoftware.b4a.BA.Author;
import anywheresoftware.b4a.BA.ShortName;
import anywheresoftware.b4a.BA.Version;
@ShortName("ScreenComponentSize")
@Version(1.00f)
@Author("ArminKH")
@ActivityObject
public class ScreenComponentSize {
private int StatusBarHeight(BA ba) {
Rect r = new Rect();
Window w = ba.activity.getWindow();
w.getDecorView().getWindowVisibleDisplayFrame(r);
return r.top;
}
/**
* Height of the title bar
*/
public int TitleBarHeight(BA ba) {
int viewTop = ba.activity.getWindow().findViewById(Window.ID_ANDROID_CONTENT).getTop();
return (viewTop - StatusBarHeight(ba));
}
/**
* Height of the status bar
*/
public int StatusBarHeight(){
int result = 0;
int resId = BA.applicationContext.getResources().getIdentifier("status_bar_height", "dimen", "android");
if (resId > 0) {
result = BA.applicationContext.getResources().getDimensionPixelSize(resId);
}
return result;
}
/**
* Height of the bottom navigation / system bar
*/
public int NavigationBarHeight(){
int result = 0;
int resId = BA.applicationContext.getResources().getIdentifier("navigation_bar_height", "dimen", "android");
if (resId > 0) {
result = BA.applicationContext.getResources().getDimensionPixelSize(resId);
}
return result;
}
/**
* Height of the bottom navigation bar in portrait; often the same as @dimen/navigation_bar_height
*/
public int NavigationBarHeightLandscape(){
int result = 0;
int resId = BA.applicationContext.getResources().getIdentifier("navigation_bar_height_landscape", "dimen", "android");
if (resId > 0) {
result = BA.applicationContext.getResources().getDimensionPixelSize(resId);
}
return result;
}
/**
* Default height of an action bar
*/
public int ActionBarDefaultHeight(){
int result = 0;
int resId = BA.applicationContext.getResources().getIdentifier("action_bar_default_height", "dimen", "android");
if (resId > 0) {
result = BA.applicationContext.getResources().getDimensionPixelSize(resId);
}
return result;
}
}
//