Search in sources :

Example 36 with ResourcesKey

use of android.content.res.ResourcesKey in project android_frameworks_base by crdroidandroid.

the class ResourcesManager method redirectResourcesToNewImplLocked.

private void redirectResourcesToNewImplLocked(@NonNull final ArrayMap<ResourcesImpl, ResourcesKey> updatedResourceKeys) {
    // Bail early if there is no work to do.
    if (updatedResourceKeys.isEmpty()) {
        return;
    }
    // Update any references to ResourcesImpl that require reloading.
    final int resourcesCount = mResourceReferences.size();
    for (int i = 0; i < resourcesCount; i++) {
        final Resources r = mResourceReferences.get(i).get();
        if (r != null) {
            final ResourcesKey key = updatedResourceKeys.get(r.getImpl());
            if (key != null) {
                final ResourcesImpl impl = findOrCreateResourcesImplForKeyLocked(key);
                if (impl == null) {
                    throw new Resources.NotFoundException("failed to load");
                }
                r.setImpl(impl);
            }
        }
    }
    // Update any references to ResourcesImpl that require reloading for each Activity.
    for (final ActivityResources activityResources : mActivityResourceReferences.values()) {
        final int resCount = activityResources.activityResources.size();
        for (int i = 0; i < resCount; i++) {
            final Resources r = activityResources.activityResources.get(i).get();
            if (r != null) {
                final ResourcesKey key = updatedResourceKeys.get(r.getImpl());
                if (key != null) {
                    final ResourcesImpl impl = findOrCreateResourcesImplForKeyLocked(key);
                    if (impl == null) {
                        throw new Resources.NotFoundException("failed to load");
                    }
                    r.setImpl(impl);
                }
            }
        }
    }
}
Also used : ResourcesKey(android.content.res.ResourcesKey) Resources(android.content.res.Resources) ResourcesImpl(android.content.res.ResourcesImpl)

Example 37 with ResourcesKey

use of android.content.res.ResourcesKey in project android_frameworks_base by crdroidandroid.

the class ResourcesManager method getResources.

/**
     * Gets or creates a new Resources object associated with the IBinder token. References returned
     * by this method live as long as the Activity, meaning they can be cached and used by the
     * Activity even after a configuration change. If any other parameter is changed
     * (resDir, splitResDirs, overrideConfig) for a given Activity, the same Resources object
     * is updated and handed back to the caller. However, changing the class loader will result in a
     * new Resources object.
     * <p/>
     * If activityToken is null, a cached Resources object will be returned if it matches the
     * input parameters. Otherwise a new Resources object that satisfies these parameters is
     * returned.
     *
     * @param activityToken Represents an Activity. If null, global resources are assumed.
     * @param resDir The base resource path. Can be null (only framework resources will be loaded).
     * @param splitResDirs An array of split resource paths. Can be null.
     * @param overlayDirs An array of overlay paths. Can be null.
     * @param libDirs An array of resource library paths. Can be null.
     * @param displayId The ID of the display for which to create the resources.
     * @param overrideConfig The configuration to apply on top of the base configuration. Can be
     * null. Mostly used with Activities that are in multi-window which may override width and
     * height properties from the base config.
     * @param compatInfo The compatibility settings to use. Cannot be null. A default to use is
     * {@link CompatibilityInfo#DEFAULT_COMPATIBILITY_INFO}.
     * @param classLoader The class loader to use when inflating Resources. If null, the
     * {@link ClassLoader#getSystemClassLoader()} is used.
     * @return a Resources object from which to access resources.
     */
@Nullable
public Resources getResources(@Nullable IBinder activityToken, @Nullable String resDir, @Nullable String[] splitResDirs, @Nullable String[] overlayDirs, @Nullable String[] libDirs, int displayId, @Nullable Configuration overrideConfig, @NonNull CompatibilityInfo compatInfo, @Nullable ClassLoader classLoader) {
    try {
        Trace.traceBegin(Trace.TRACE_TAG_RESOURCES, "ResourcesManager#getResources");
        final ResourcesKey key = new ResourcesKey(resDir, splitResDirs, overlayDirs, libDirs, displayId, // Copy
        overrideConfig != null ? new Configuration(overrideConfig) : null, compatInfo);
        classLoader = classLoader != null ? classLoader : ClassLoader.getSystemClassLoader();
        return getOrCreateResources(activityToken, key, classLoader);
    } finally {
        Trace.traceEnd(Trace.TRACE_TAG_RESOURCES);
    }
}
Also used : Configuration(android.content.res.Configuration) ResourcesKey(android.content.res.ResourcesKey) Nullable(android.annotation.Nullable)

Example 38 with ResourcesKey

use of android.content.res.ResourcesKey in project android_frameworks_base by crdroidandroid.

the class ResourcesManager method createBaseActivityResources.

/**
     * Creates base resources for an Activity. Calls to
     * {@link #getResources(IBinder, String, String[], String[], String[], int, Configuration,
     * CompatibilityInfo, ClassLoader)} with the same activityToken will have their override
     * configurations merged with the one specified here.
     *
     * @param activityToken Represents an Activity.
     * @param resDir The base resource path. Can be null (only framework resources will be loaded).
     * @param splitResDirs An array of split resource paths. Can be null.
     * @param overlayDirs An array of overlay paths. Can be null.
     * @param libDirs An array of resource library paths. Can be null.
     * @param displayId The ID of the display for which to create the resources.
     * @param overrideConfig The configuration to apply on top of the base configuration. Can be
     *                       null. This provides the base override for this Activity.
     * @param compatInfo The compatibility settings to use. Cannot be null. A default to use is
     *                   {@link CompatibilityInfo#DEFAULT_COMPATIBILITY_INFO}.
     * @param classLoader The class loader to use when inflating Resources. If null, the
     *                    {@link ClassLoader#getSystemClassLoader()} is used.
     * @return a Resources object from which to access resources.
     */
@Nullable
public Resources createBaseActivityResources(@NonNull IBinder activityToken, @Nullable String resDir, @Nullable String[] splitResDirs, @Nullable String[] overlayDirs, @Nullable String[] libDirs, int displayId, @Nullable Configuration overrideConfig, @NonNull CompatibilityInfo compatInfo, @Nullable ClassLoader classLoader) {
    try {
        Trace.traceBegin(Trace.TRACE_TAG_RESOURCES, "ResourcesManager#createBaseActivityResources");
        final ResourcesKey key = new ResourcesKey(resDir, splitResDirs, overlayDirs, libDirs, displayId, // Copy
        overrideConfig != null ? new Configuration(overrideConfig) : null, compatInfo);
        classLoader = classLoader != null ? classLoader : ClassLoader.getSystemClassLoader();
        if (DEBUG) {
            Slog.d(TAG, "createBaseActivityResources activity=" + activityToken + " with key=" + key);
        }
        synchronized (this) {
            // Force the creation of an ActivityResourcesStruct.
            getOrCreateActivityResourcesStructLocked(activityToken);
        }
        // Update any existing Activity Resources references.
        updateResourcesForActivity(activityToken, overrideConfig);
        // Now request an actual Resources object.
        return getOrCreateResources(activityToken, key, classLoader);
    } finally {
        Trace.traceEnd(Trace.TRACE_TAG_RESOURCES);
    }
}
Also used : Configuration(android.content.res.Configuration) ResourcesKey(android.content.res.ResourcesKey) Nullable(android.annotation.Nullable)

Aggregations

ResourcesKey (android.content.res.ResourcesKey)38 ResourcesImpl (android.content.res.ResourcesImpl)28 Configuration (android.content.res.Configuration)20 Nullable (android.annotation.Nullable)10 Resources (android.content.res.Resources)10 ArrayMap (android.util.ArrayMap)9 DisplayMetrics (android.util.DisplayMetrics)5 DisplayAdjustments (android.view.DisplayAdjustments)5