Java Code Examples for android.util.DisplayMetrics#DENSITY_DEFAULT_SCALE

The following examples show how to use android.util.DisplayMetrics#DENSITY_DEFAULT_SCALE . 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: DisplayInfo.java    From android_9.0.0_r45 with Apache License 2.0 6 votes vote down vote up
private void getMetricsWithSize(DisplayMetrics outMetrics, CompatibilityInfo compatInfo,
        Configuration configuration, int width, int height) {
    outMetrics.densityDpi = outMetrics.noncompatDensityDpi = logicalDensityDpi;
    outMetrics.density = outMetrics.noncompatDensity =
            logicalDensityDpi * DisplayMetrics.DENSITY_DEFAULT_SCALE;
    outMetrics.scaledDensity = outMetrics.noncompatScaledDensity = outMetrics.density;
    outMetrics.xdpi = outMetrics.noncompatXdpi = physicalXDpi;
    outMetrics.ydpi = outMetrics.noncompatYdpi = physicalYDpi;

    final Rect appBounds = configuration != null
            ? configuration.windowConfiguration.getAppBounds() : null;
    width = appBounds != null ? appBounds.width() : width;
    height = appBounds != null ? appBounds.height() : height;

    outMetrics.noncompatWidthPixels  = outMetrics.widthPixels = width;
    outMetrics.noncompatHeightPixels = outMetrics.heightPixels = height;

    if (!compatInfo.equals(CompatibilityInfo.DEFAULT_COMPATIBILITY_INFO)) {
        compatInfo.applyToDisplayMetrics(outMetrics);
    }
}
 
Example 2
Source File: TaskRecord.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
/** Clears passed config and fills it with new override values. */
// TODO(b/36505427): TaskRecord.computeOverrideConfiguration() is a utility method that doesn't
// depend on task or stacks, but uses those object to get the display to base the calculation
// on. Probably best to centralize calculations like this in ConfigurationContainer.
void computeOverrideConfiguration(Configuration config, Rect bounds, Rect insetBounds,
        boolean overrideWidth, boolean overrideHeight) {
    mTmpNonDecorBounds.set(bounds);
    mTmpStableBounds.set(bounds);

    config.unset();
    final Configuration parentConfig = getParent().getConfiguration();

    final float density = parentConfig.densityDpi * DisplayMetrics.DENSITY_DEFAULT_SCALE;

    if (mStack != null) {
        final StackWindowController stackController = mStack.getWindowContainerController();
        stackController.adjustConfigurationForBounds(bounds, insetBounds,
                mTmpNonDecorBounds, mTmpStableBounds, overrideWidth, overrideHeight, density,
                config, parentConfig, getWindowingMode());
    } else {
        throw new IllegalArgumentException("Expected stack when calculating override config");
    }

    config.orientation = (config.screenWidthDp <= config.screenHeightDp)
            ? Configuration.ORIENTATION_PORTRAIT
            : Configuration.ORIENTATION_LANDSCAPE;

    // For calculating screen layout, we need to use the non-decor inset screen area for the
    // calculation for compatibility reasons, i.e. screen area without system bars that could
    // never go away in Honeycomb.
    final int compatScreenWidthDp = (int) (mTmpNonDecorBounds.width() / density);
    final int compatScreenHeightDp = (int) (mTmpNonDecorBounds.height() / density);
    // We're only overriding LONG, SIZE and COMPAT parts of screenLayout, so we start override
    // calculation with partial default.
    final int sl = Configuration.SCREENLAYOUT_LONG_YES | Configuration.SCREENLAYOUT_SIZE_XLARGE;
    final int longSize = Math.max(compatScreenHeightDp, compatScreenWidthDp);
    final int shortSize = Math.min(compatScreenHeightDp, compatScreenWidthDp);
    config.screenLayout = Configuration.reduceScreenLayout(sl, longSize, shortSize);
}