Java Code Examples for android.util.DisplayMetrics#DENSITY_DEVICE_STABLE

The following examples show how to use android.util.DisplayMetrics#DENSITY_DEVICE_STABLE . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DisplayUtils.java    From talkback with Apache License 2.0 6 votes vote down vote up
/**
 * 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);
}
 
Example 2
Source File: AppWarnings.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
/**
 * 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);
    }
}
 
Example 3
Source File: PreferencesState.java    From LaunchEnr with GNU General Public License v3.0 5 votes vote down vote up
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;
}