Search in sources :

Example 11 with DisplayAdjustments

use of android.view.DisplayAdjustments in project android_frameworks_base by crdroidandroid.

the class ResourcesManager method createResourcesImpl.

@Nullable
private ResourcesImpl createResourcesImpl(@NonNull ResourcesKey key) {
    final DisplayAdjustments daj = new DisplayAdjustments(key.mOverrideConfiguration);
    daj.setCompatibilityInfo(key.mCompatInfo);
    final AssetManager assets = createAssetManager(key);
    if (assets == null) {
        return null;
    }
    final DisplayMetrics dm = getDisplayMetrics(key.mDisplayId, daj);
    final Configuration config = generateConfig(key, dm);
    final ResourcesImpl impl = new ResourcesImpl(assets, dm, config, daj);
    if (DEBUG) {
        Slog.d(TAG, "- creating impl=" + impl + " with key: " + key);
    }
    return impl;
}
Also used : AssetManager(android.content.res.AssetManager) Configuration(android.content.res.Configuration) DisplayAdjustments(android.view.DisplayAdjustments) ResourcesImpl(android.content.res.ResourcesImpl) DisplayMetrics(android.util.DisplayMetrics) Nullable(android.annotation.Nullable)

Example 12 with DisplayAdjustments

use of android.view.DisplayAdjustments in project android_frameworks_base by AOSPA.

the class ResourcesManagerTest method setUp.

@Override
protected void setUp() throws Exception {
    super.setUp();
    mDisplayMetrics = new DisplayMetrics();
    mDisplayMetrics.setToDefaults();
    // Override defaults (which take device specific properties).
    mDisplayMetrics.density = 1.0f;
    mDisplayMetrics.densityDpi = DisplayMetrics.DENSITY_DEFAULT;
    mDisplayMetrics.xdpi = DisplayMetrics.DENSITY_DEFAULT;
    mDisplayMetrics.ydpi = DisplayMetrics.DENSITY_DEFAULT;
    mDisplayMetrics.noncompatDensity = mDisplayMetrics.density;
    mDisplayMetrics.noncompatDensityDpi = mDisplayMetrics.densityDpi;
    mDisplayMetrics.noncompatXdpi = DisplayMetrics.DENSITY_DEFAULT;
    mDisplayMetrics.noncompatYdpi = DisplayMetrics.DENSITY_DEFAULT;
    mResourcesManager = new ResourcesManager() {

        @Override
        protected AssetManager createAssetManager(@NonNull ResourcesKey key) {
            return new AssetManager();
        }

        @Override
        protected DisplayMetrics getDisplayMetrics(int displayId, DisplayAdjustments daj) {
            return mDisplayMetrics;
        }
    };
}
Also used : ResourcesManager(android.app.ResourcesManager) DisplayAdjustments(android.view.DisplayAdjustments) DisplayMetrics(android.util.DisplayMetrics)

Example 13 with DisplayAdjustments

use of android.view.DisplayAdjustments in project android_frameworks_base by DirtyUnicorns.

the class ResourcesManager method applyConfigurationToResourcesLocked.

public final boolean applyConfigurationToResourcesLocked(@NonNull Configuration config, @Nullable CompatibilityInfo compat) {
    try {
        Trace.traceBegin(Trace.TRACE_TAG_RESOURCES, "ResourcesManager#applyConfigurationToResourcesLocked");
        if (!mResConfiguration.isOtherSeqNewer(config) && compat == null) {
            if (DEBUG || DEBUG_CONFIGURATION)
                Slog.v(TAG, "Skipping new config: curSeq=" + mResConfiguration.seq + ", newSeq=" + config.seq);
            return false;
        }
        int changes = mResConfiguration.updateFrom(config);
        // Things might have changed in display manager, so clear the cached displays.
        mDisplays.clear();
        DisplayMetrics defaultDisplayMetrics = getDisplayMetrics();
        if (compat != null && (mResCompatibilityInfo == null || !mResCompatibilityInfo.equals(compat))) {
            mResCompatibilityInfo = compat;
            changes |= ActivityInfo.CONFIG_SCREEN_LAYOUT | ActivityInfo.CONFIG_SCREEN_SIZE | ActivityInfo.CONFIG_SMALLEST_SCREEN_SIZE;
        }
        Resources.updateSystemConfiguration(config, defaultDisplayMetrics, compat);
        ApplicationPackageManager.configurationChanged();
        //Slog.i(TAG, "Configuration changed in " + currentPackageName());
        Configuration tmpConfig = null;
        for (int i = mResourceImpls.size() - 1; i >= 0; i--) {
            ResourcesKey key = mResourceImpls.keyAt(i);
            ResourcesImpl r = mResourceImpls.valueAt(i).get();
            if (r != null) {
                if (DEBUG || DEBUG_CONFIGURATION)
                    Slog.v(TAG, "Changing resources " + r + " config to: " + config);
                int displayId = key.mDisplayId;
                boolean isDefaultDisplay = (displayId == Display.DEFAULT_DISPLAY);
                DisplayMetrics dm = defaultDisplayMetrics;
                final boolean hasOverrideConfiguration = key.hasOverrideConfiguration();
                if (!isDefaultDisplay || hasOverrideConfiguration) {
                    if (tmpConfig == null) {
                        tmpConfig = new Configuration();
                    }
                    tmpConfig.setTo(config);
                    // Get new DisplayMetrics based on the DisplayAdjustments given
                    // to the ResourcesImpl. Update a copy if the CompatibilityInfo
                    // changed, because the ResourcesImpl object will handle the
                    // update internally.
                    DisplayAdjustments daj = r.getDisplayAdjustments();
                    if (compat != null) {
                        daj = new DisplayAdjustments(daj);
                        daj.setCompatibilityInfo(compat);
                    }
                    dm = getDisplayMetrics(displayId, daj);
                    if (!isDefaultDisplay) {
                        applyNonDefaultDisplayMetricsToConfiguration(dm, tmpConfig);
                    }
                    if (hasOverrideConfiguration) {
                        tmpConfig.updateFrom(key.mOverrideConfiguration);
                    }
                    r.updateConfiguration(tmpConfig, dm, compat);
                } else {
                    r.updateConfiguration(config, dm, compat);
                }
            //Slog.i(TAG, "Updated app resources " + v.getKey()
            //        + " " + r + ": " + r.getConfiguration());
            } else {
                //Slog.i(TAG, "Removing old resources " + v.getKey());
                mResourceImpls.removeAt(i);
            }
        }
        return changes != 0;
    } finally {
        Trace.traceEnd(Trace.TRACE_TAG_RESOURCES);
    }
}
Also used : Configuration(android.content.res.Configuration) ResourcesKey(android.content.res.ResourcesKey) DisplayAdjustments(android.view.DisplayAdjustments) ResourcesImpl(android.content.res.ResourcesImpl) DisplayMetrics(android.util.DisplayMetrics)

Example 14 with DisplayAdjustments

use of android.view.DisplayAdjustments in project android_frameworks_base by DirtyUnicorns.

the class ResourcesManager method createResourcesImpl.

@Nullable
private ResourcesImpl createResourcesImpl(@NonNull ResourcesKey key) {
    final DisplayAdjustments daj = new DisplayAdjustments(key.mOverrideConfiguration);
    daj.setCompatibilityInfo(key.mCompatInfo);
    final AssetManager assets = createAssetManager(key);
    if (assets == null) {
        return null;
    }
    final DisplayMetrics dm = getDisplayMetrics(key.mDisplayId, daj);
    final Configuration config = generateConfig(key, dm);
    final ResourcesImpl impl = new ResourcesImpl(assets, dm, config, daj);
    if (DEBUG) {
        Slog.d(TAG, "- creating impl=" + impl + " with key: " + key);
    }
    return impl;
}
Also used : AssetManager(android.content.res.AssetManager) Configuration(android.content.res.Configuration) DisplayAdjustments(android.view.DisplayAdjustments) ResourcesImpl(android.content.res.ResourcesImpl) DisplayMetrics(android.util.DisplayMetrics) Nullable(android.annotation.Nullable)

Example 15 with DisplayAdjustments

use of android.view.DisplayAdjustments in project platform_frameworks_base by android.

the class ResourcesManager method createResourcesImpl.

@Nullable
private ResourcesImpl createResourcesImpl(@NonNull ResourcesKey key) {
    final DisplayAdjustments daj = new DisplayAdjustments(key.mOverrideConfiguration);
    daj.setCompatibilityInfo(key.mCompatInfo);
    final AssetManager assets = createAssetManager(key);
    if (assets == null) {
        return null;
    }
    final DisplayMetrics dm = getDisplayMetrics(key.mDisplayId, daj);
    final Configuration config = generateConfig(key, dm);
    final ResourcesImpl impl = new ResourcesImpl(assets, dm, config, daj);
    if (DEBUG) {
        Slog.d(TAG, "- creating impl=" + impl + " with key: " + key);
    }
    return impl;
}
Also used : AssetManager(android.content.res.AssetManager) Configuration(android.content.res.Configuration) DisplayAdjustments(android.view.DisplayAdjustments) ResourcesImpl(android.content.res.ResourcesImpl) DisplayMetrics(android.util.DisplayMetrics) Nullable(android.annotation.Nullable)

Aggregations

DisplayAdjustments (android.view.DisplayAdjustments)20 DisplayMetrics (android.util.DisplayMetrics)15 Configuration (android.content.res.Configuration)10 ResourcesImpl (android.content.res.ResourcesImpl)10 Nullable (android.annotation.Nullable)5 ResourcesManager (android.app.ResourcesManager)5 AssetManager (android.content.res.AssetManager)5 ResourcesKey (android.content.res.ResourcesKey)5 DisplayManagerGlobal (android.hardware.display.DisplayManagerGlobal)5 Display (android.view.Display)5