Created
August 27, 2017 12:39
-
-
Save THEb0nny/d26057834252bd6f488e14030c2aead8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static void displayMetric(Context context) { | |
Display display = ((WindowManager)context.getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay(); | |
DisplayMetrics metricsDisplay = new DisplayMetrics(); | |
display.getMetrics(metricsDisplay); | |
if (!SharedPref.firstStart) { // Делаем это только при первом запуске! | |
if (getRotateOrientation(context) == 0 || getRotateOrientation(context) == 180) { // Нужно при первом запуске верно добавить высоту NavBar | |
SharedPref.wScreen = (metricsDisplay.widthPixels < metricsDisplay.heightPixels ? metricsDisplay.widthPixels : metricsDisplay.heightPixels); | |
SharedPref.hScreen = (metricsDisplay.heightPixels > metricsDisplay.widthPixels ? metricsDisplay.heightPixels : metricsDisplay.widthPixels) + SharedPref.navBarHeight; | |
} else { | |
SharedPref.wScreen = (metricsDisplay.widthPixels < metricsDisplay.heightPixels ? metricsDisplay.widthPixels : metricsDisplay.heightPixels) + SharedPref.navBarHeight; | |
SharedPref.hScreen = (metricsDisplay.heightPixels > metricsDisplay.widthPixels ? metricsDisplay.heightPixels : metricsDisplay.widthPixels); | |
} | |
SharedPref.mmInPx = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_MM, 1, context.getResources().getDisplayMetrics()); // Вычисляем сколько равен 1 мм в пикселях | |
SharedPref.wNavRingView = SharedPref.wScreen; | |
SharedPref.hNavRingView = (SharedPref.hScreen / 2) - (int) (SharedPref.mmInPx * 10); // 14 мм - статус бар, нав бар; | |
} | |
SharedPref.xDisplay = metricsDisplay.widthPixels; | |
SharedPref.yDisplay = metricsDisplay.heightPixels; | |
} | |
static short getRotateOrientation(Context context) { | |
Display display = ((WindowManager)context.getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay(); | |
displayMetric(context); // Нужно же новые параметры размера записать после смены ориентации | |
switch (display.getRotation()) { | |
case Surface.ROTATION_0: | |
return 0; | |
case Surface.ROTATION_90: | |
return 90; | |
case Surface.ROTATION_180: | |
return 180; | |
case Surface.ROTATION_270: | |
return 270; | |
default: | |
return 999; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment