Created
May 28, 2024 06:11
-
-
Save yccheok/f22654c330c863937290da5000ef7d68 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 ScreenDensity getScreenDensity() { | |
| try { | |
| final String screenDensity = MyApplication.instance().getResources().getString(R.string.screen_density); | |
| if ("ldpi".equals(screenDensity)) { | |
| return ScreenDensity.ldpi; | |
| } else if ("hdpi".equals(screenDensity)) { | |
| return ScreenDensity.hdpi; | |
| } else if ("xhdpi".equals(screenDensity)) { | |
| return ScreenDensity.xhdpi; | |
| } else if ("xxhdpi".equals(screenDensity)) { | |
| return ScreenDensity.xxhdpi; | |
| } else if ("xxxhdpi".equals(screenDensity)) { | |
| return ScreenDensity.xxxhdpi; | |
| } | |
| } catch (Resources.NotFoundException e) { | |
| Log.e(TAG, "", e); | |
| } | |
| // Fallback method. | |
| final DisplayMetrics metrics = MyApplication.instance().getResources().getDisplayMetrics(); | |
| final int densityDpi = metrics.densityDpi; | |
| if (densityDpi <= DisplayMetrics.DENSITY_LOW) { | |
| return ScreenDensity.ldpi; | |
| } else if (densityDpi <= DisplayMetrics.DENSITY_HIGH) { | |
| return ScreenDensity.hdpi; | |
| } else if (densityDpi <= DisplayMetrics.DENSITY_XHIGH) { | |
| return ScreenDensity.xhdpi; | |
| } else if (densityDpi <= DisplayMetrics.DENSITY_XXHIGH) { | |
| return ScreenDensity.xxhdpi; | |
| } else if (densityDpi <= DisplayMetrics.DENSITY_XXXHIGH) { | |
| return ScreenDensity.xxxhdpi; | |
| } | |
| return null; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment