Я использовал Android SDK для решения этой проблемы. Вы можете посмотреть, как использовать java с соответствующей здесь.
Это мой java-код
public Point screenSize(Activity activity) {
DisplayMetrics displayMetrics = new DisplayMetrics();
WindowManager wm = (WindowManager) activity.getSystemService(Context.WINDOW_SERVICE);
Display disp = wm.getDefaultDisplay();
int API_LEVEL = android.os.Build.VERSION.SDK_INT;
if (API_LEVEL >= 17) {
disp.getRealMetrics(displayMetrics);
} else {
disp.getMetrics(displayMetrics);
}
int width = displayMetrics.widthPixels;
int height = displayMetrics.heightPixels;
return new Point(width, height); //String.format("%d,%d,%d,%d", portraitNavBarHeight, landscapeNavBarHeight, width, height);
}
public Point navigationBarHeights(Activity activity) {
Resources resources = activity.getResources();
int resourceId = resources.getIdentifier("navigation_bar_height", "dimen", "android");
int resourceIdLandscape = resources.getIdentifier("navigation_bar_height_landscape", "dimen", "android");
int portraitNavBarHeight = 0;
int landscapeNavBarHeight = 0;
boolean hasPermanentMenuKey = ViewConfiguration.get(activity).hasPermanentMenuKey();
if (resourceId > 0 && !hasPermanentMenuKey) {
portraitNavBarHeight = resources.getDimensionPixelSize(resourceId);
}
if (resourceIdLandscape > 0 && !hasPermanentMenuKey) {
landscapeNavBarHeight = resources.getDimensionPixelSize(resourceIdLandscape);
}
return new Point(portraitNavBarHeight, landscapeNavBarHeight); //String.format("%d,%d,%d,%d", portraitNavBarHeight, landscapeNavBarHeight, width, height);
}
и часть Objective-C
+ (void)initializeJava
{
[super initializeJava];
// here your initialize code
...
[KeyboardBridge registerInstanceMethod:@"screenSize"
selector:@selector(screenSize:)
returnValue:[AndroidPoint className]
arguments:[AndroidActivity className], nil];
[KeyboardBridge registerInstanceMethod:@"navigationBarHeights"
selector:@selector(navigationBarHeights:)
returnValue:[AndroidPoint className]
arguments:[AndroidActivity className], nil];
}
- (CGRect)displayMetrics {
AndroidPoint *screenSize = [self screenSize:[AndroidActivity currentActivity]];
AndroidPoint *navigationBarHeights = [self navigationBarHeights:[AndroidActivity currentActivity]];
return CGRectMake(navigationBarHeights.x, navigationBarHeights.y, screenSize.x, screenSize.y);
}
и окончательный результат
CGRect rect = [[[KeyboardBridge alloc] init] displayMetrics];
float portraitWidth;
float portraitHeight;
if(rect.size.width > rect.size.height) {
portraitHeight = rect.size.width;
portraitWidth = rect.size.height;
} else {
portraitHeight = rect.size.height;
portraitWidth = rect.size.width;
}
landscapeSize.width = portraitHeight;
landscapeSize.height = portraitWidth - rect.origin.y;
portraitSize.width = portraitWidth;
portraitSize.height = portraitHeight - rect.origin.x;
person
Dima Portenko
schedule
14.03.2014