android.util.DisplayMetrics#DENSITY_DEFAULT_SCALE源码实例Demo

下面列出了android.util.DisplayMetrics#DENSITY_DEFAULT_SCALE 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: android_9.0.0_r45   文件: DisplayInfo.java
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);
    }
}
 
源代码2 项目: android_9.0.0_r45   文件: TaskRecord.java
/** 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);
}