|
using Android.Content; |
|
using Android.Graphics; |
|
using Android.OS; |
|
using Android.Runtime; |
|
using Android.Views; |
|
using Java.Lang; |
|
using Java.Lang.Reflect; |
|
|
|
public static class NavigationbarSize { |
|
public static Point getNavigationBarSize(Context context) { |
|
var appUsableSize = getAppUsableScreenSize(context); |
|
var realScreenSize = getRealScreenSize(context); |
|
|
|
// navigation bar on the right |
|
if (appUsableSize.X < realScreenSize.X) { |
|
return new Point(realScreenSize.X - appUsableSize.X, appUsableSize.Y); |
|
} |
|
|
|
// navigation bar at the bottom |
|
return (appUsableSize.Y < realScreenSize.Y) |
|
? new Point(appUsableSize.X, realScreenSize.Y - appUsableSize.Y) |
|
: new Point(); |
|
|
|
// navigation bar is not present |
|
} |
|
public static Point getAppUsableScreenSize(Context context) { |
|
var windowManager = context.GetSystemService(Context.WindowService); |
|
//var display = windowManager.DefaultDisplay; |
|
var display = JNIEnv.CallObjectMethod(windowManager.Handle, JNIEnv.GetMethodID(JNIEnv.FindClass("android/view/WindowManagerImpl"), "getDefaultDisplay", "()Landroid/view/Display;")); |
|
var size = new Point(); |
|
//display.GetSize(size); |
|
JNIEnv.CallVoidMethod(display, JNIEnv.GetMethodID(JNIEnv.FindClass("android/view/Display"), "getSize", "(Landroid/graphics/Point;)V"), new JValue(size.Handle)); |
|
return size; |
|
} |
|
public static Point getRealScreenSize(Context context) { |
|
var windowManager = context.GetSystemService(Context.WindowService); |
|
//var display = windowManager.DefaultDisplay; |
|
var display = JNIEnv.CallObjectMethod(windowManager.Handle, JNIEnv.GetMethodID(JNIEnv.FindClass("android/view/WindowManagerImpl"), "getDefaultDisplay", "()Landroid/view/Display;")); |
|
var size = new Point(); |
|
|
|
if (Build.VERSION.SdkInt >= BuildVersionCodes.JellyBeanMr1) { |
|
//display.GetRealSize(size); |
|
JNIEnv.CallVoidMethod(display, JNIEnv.GetMethodID(JNIEnv.FindClass("android/view/Display"), "getRealSize", "(Landroid/graphics/Point;)V"), new JValue(size.Handle)); |
|
} else if (Build.VERSION.SdkInt >= BuildVersionCodes.IceCreamSandwich) { |
|
try { |
|
size.X = JNIEnv.CallIntMethod(context.Handle, JNIEnv.GetMethodID(JNIEnv.FindClass("android/view/Display"), "getRawWidth", "()I")); |
|
size.Y = JNIEnv.CallIntMethod(context.Handle, JNIEnv.GetMethodID(JNIEnv.FindClass("android/view/Display"), "getRawHeight", "()I")); |
|
//size.X = Display::class.java.getMethod("getRawWidth").invoke(display) as Int; |
|
//size.Y = Display::class.java.getMethod("getRawHeight").invoke(display) as Int |
|
} catch (IllegalAccessException e) { } catch (InvocationTargetException e) { } catch (NoSuchMethodException e) { } |
|
} |
|
return size; |
|
} |
|
} |