下面列出了android.util.DisplayMetrics#DENSITY_DEVICE_STABLE 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
/**
* Returns context with default screen densityDpi.This context is used to keep the layout size as
* per the default screen densityDpi and not based on the display size setting changed by the
* user.
*/
public static Context getDefaultScreenDensityContext(Context context) {
Resources res = context.getResources();
Configuration configuration = new Configuration(res.getConfiguration());
/* get default display density */
if (BuildVersionUtils.isAtLeastN()) {
configuration.densityDpi = DisplayMetrics.DENSITY_DEVICE_STABLE;
} else {
WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
DisplayMetrics dm = new DisplayMetrics();
wm.getDefaultDisplay().getRealMetrics(dm);
configuration.densityDpi = dm.densityDpi;
}
configuration.setTo(configuration);
return context.createConfigurationContext(configuration);
}
/**
* Shows the "unsupported display size" warning, if necessary.
*
* @param r activity record for which the warning may be displayed
*/
public void showUnsupportedDisplaySizeDialogIfNeeded(ActivityRecord r) {
final Configuration globalConfig = mAms.getGlobalConfiguration();
if (globalConfig.densityDpi != DisplayMetrics.DENSITY_DEVICE_STABLE
&& r.appInfo.requiresSmallestWidthDp > globalConfig.smallestScreenWidthDp) {
mUiHandler.showUnsupportedDisplaySizeDialog(r);
}
}
static boolean getAllowRotationDefaultValue(Context context) {
if (AndroidVersion.isAtLeastNougat) {
// If the device was scaled, used the original dimensions to determine if rotation
// is allowed of not.
Resources res = context.getResources();
int originalSmallestWidth = res.getConfiguration().smallestScreenWidthDp
* res.getDisplayMetrics().densityDpi / DisplayMetrics.DENSITY_DEVICE_STABLE;
return originalSmallestWidth >= 600;
}
return false;
}