Search in sources :

Example 16 with DisplayAdjustments

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

the class ResourcesManager method getAdjustedDisplay.

/**
     * Returns an adjusted {@link Display} object based on the inputs or null if display isn't
     * available.
     *
     * @param displayId display Id.
     * @param displayAdjustments display adjustments.
     */
public Display getAdjustedDisplay(final int displayId, @Nullable DisplayAdjustments displayAdjustments) {
    final DisplayAdjustments displayAdjustmentsCopy = (displayAdjustments != null) ? new DisplayAdjustments(displayAdjustments) : new DisplayAdjustments();
    final Pair<Integer, DisplayAdjustments> key = Pair.create(displayId, displayAdjustmentsCopy);
    synchronized (this) {
        WeakReference<Display> wd = mDisplays.get(key);
        if (wd != null) {
            final Display display = wd.get();
            if (display != null) {
                return display;
            }
        }
        final DisplayManagerGlobal dm = DisplayManagerGlobal.getInstance();
        if (dm == null) {
            // may be null early in system startup
            return null;
        }
        final Display display = dm.getCompatibleDisplay(displayId, key.second);
        if (display != null) {
            mDisplays.put(key, new WeakReference<>(display));
        }
        return display;
    }
}
Also used : DisplayManagerGlobal(android.hardware.display.DisplayManagerGlobal) DisplayAdjustments(android.view.DisplayAdjustments) Display(android.view.Display)

Example 17 with DisplayAdjustments

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

the class ResourcesManager method getAdjustedDisplay.

/**
     * Returns an adjusted {@link Display} object based on the inputs or null if display isn't
     * available.
     *
     * @param displayId display Id.
     * @param displayAdjustments display adjustments.
     */
public Display getAdjustedDisplay(final int displayId, @Nullable DisplayAdjustments displayAdjustments) {
    final DisplayAdjustments displayAdjustmentsCopy = (displayAdjustments != null) ? new DisplayAdjustments(displayAdjustments) : new DisplayAdjustments();
    final Pair<Integer, DisplayAdjustments> key = Pair.create(displayId, displayAdjustmentsCopy);
    synchronized (this) {
        WeakReference<Display> wd = mDisplays.get(key);
        if (wd != null) {
            final Display display = wd.get();
            if (display != null) {
                return display;
            }
        }
        final DisplayManagerGlobal dm = DisplayManagerGlobal.getInstance();
        if (dm == null) {
            // may be null early in system startup
            return null;
        }
        final Display display = dm.getCompatibleDisplay(displayId, key.second);
        if (display != null) {
            mDisplays.put(key, new WeakReference<>(display));
        }
        return display;
    }
}
Also used : DisplayManagerGlobal(android.hardware.display.DisplayManagerGlobal) DisplayAdjustments(android.view.DisplayAdjustments) Display(android.view.Display)

Example 18 with DisplayAdjustments

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

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 19 with DisplayAdjustments

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

the class ResourcesManager method getAdjustedDisplay.

/**
     * Returns an adjusted {@link Display} object based on the inputs or null if display isn't
     * available.
     *
     * @param displayId display Id.
     * @param displayAdjustments display adjustments.
     */
public Display getAdjustedDisplay(final int displayId, @Nullable DisplayAdjustments displayAdjustments) {
    final DisplayAdjustments displayAdjustmentsCopy = (displayAdjustments != null) ? new DisplayAdjustments(displayAdjustments) : new DisplayAdjustments();
    final Pair<Integer, DisplayAdjustments> key = Pair.create(displayId, displayAdjustmentsCopy);
    synchronized (this) {
        WeakReference<Display> wd = mDisplays.get(key);
        if (wd != null) {
            final Display display = wd.get();
            if (display != null) {
                return display;
            }
        }
        final DisplayManagerGlobal dm = DisplayManagerGlobal.getInstance();
        if (dm == null) {
            // may be null early in system startup
            return null;
        }
        final Display display = dm.getCompatibleDisplay(displayId, key.second);
        if (display != null) {
            mDisplays.put(key, new WeakReference<>(display));
        }
        return display;
    }
}
Also used : DisplayManagerGlobal(android.hardware.display.DisplayManagerGlobal) DisplayAdjustments(android.view.DisplayAdjustments) Display(android.view.Display)

Example 20 with DisplayAdjustments

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

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)

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