Search in sources :

Example 6 with ThemeKey

use of android.content.res.Resources.ThemeKey in project android_frameworks_base by crdroidandroid.

the class ThemedResourceCache method getThemedLocked.

/**
     * Returns the cached data for the specified theme, optionally creating a
     * new entry if one does not already exist.
     *
     * @param t the theme for which to return cached data
     * @param create {@code true} to create an entry if one does not already
     *               exist, {@code false} otherwise
     * @return the cached data for the theme, or {@code null} if the cache is
     *         empty and {@code create} was {@code false}
     */
@Nullable
private LongSparseArray<WeakReference<T>> getThemedLocked(@Nullable Theme t, boolean create) {
    if (t == null) {
        if (mNullThemedEntries == null && create) {
            mNullThemedEntries = new LongSparseArray<>(1);
        }
        return mNullThemedEntries;
    }
    if (mThemedEntries == null) {
        if (create) {
            mThemedEntries = new ArrayMap<>(1);
        } else {
            return null;
        }
    }
    final ThemeKey key = t.getKey();
    LongSparseArray<WeakReference<T>> cache = mThemedEntries.get(key);
    if (cache == null && create) {
        cache = new LongSparseArray<>(1);
        final ThemeKey keyClone = key.clone();
        mThemedEntries.put(keyClone, cache);
    }
    return cache;
}
Also used : ThemeKey(android.content.res.Resources.ThemeKey) WeakReference(java.lang.ref.WeakReference) Nullable(android.annotation.Nullable)

Example 7 with ThemeKey

use of android.content.res.Resources.ThemeKey in project platform_frameworks_base by android.

the class ThemedResourceCache method getThemedLocked.

/**
     * Returns the cached data for the specified theme, optionally creating a
     * new entry if one does not already exist.
     *
     * @param t the theme for which to return cached data
     * @param create {@code true} to create an entry if one does not already
     *               exist, {@code false} otherwise
     * @return the cached data for the theme, or {@code null} if the cache is
     *         empty and {@code create} was {@code false}
     */
@Nullable
private LongSparseArray<WeakReference<T>> getThemedLocked(@Nullable Theme t, boolean create) {
    if (t == null) {
        if (mNullThemedEntries == null && create) {
            mNullThemedEntries = new LongSparseArray<>(1);
        }
        return mNullThemedEntries;
    }
    if (mThemedEntries == null) {
        if (create) {
            mThemedEntries = new ArrayMap<>(1);
        } else {
            return null;
        }
    }
    final ThemeKey key = t.getKey();
    LongSparseArray<WeakReference<T>> cache = mThemedEntries.get(key);
    if (cache == null && create) {
        cache = new LongSparseArray<>(1);
        final ThemeKey keyClone = key.clone();
        mThemedEntries.put(keyClone, cache);
    }
    return cache;
}
Also used : ThemeKey(android.content.res.Resources.ThemeKey) WeakReference(java.lang.ref.WeakReference) Nullable(android.annotation.Nullable)

Example 8 with ThemeKey

use of android.content.res.Resources.ThemeKey in project android_frameworks_base by AOSPA.

the class ThemedResourceCache method getThemedLocked.

/**
     * Returns the cached data for the specified theme, optionally creating a
     * new entry if one does not already exist.
     *
     * @param t the theme for which to return cached data
     * @param create {@code true} to create an entry if one does not already
     *               exist, {@code false} otherwise
     * @return the cached data for the theme, or {@code null} if the cache is
     *         empty and {@code create} was {@code false}
     */
@Nullable
private LongSparseArray<WeakReference<T>> getThemedLocked(@Nullable Theme t, boolean create) {
    if (t == null) {
        if (mNullThemedEntries == null && create) {
            mNullThemedEntries = new LongSparseArray<>(1);
        }
        return mNullThemedEntries;
    }
    if (mThemedEntries == null) {
        if (create) {
            mThemedEntries = new ArrayMap<>(1);
        } else {
            return null;
        }
    }
    final ThemeKey key = t.getKey();
    LongSparseArray<WeakReference<T>> cache = mThemedEntries.get(key);
    if (cache == null && create) {
        cache = new LongSparseArray<>(1);
        final ThemeKey keyClone = key.clone();
        mThemedEntries.put(keyClone, cache);
    }
    return cache;
}
Also used : ThemeKey(android.content.res.Resources.ThemeKey) WeakReference(java.lang.ref.WeakReference) Nullable(android.annotation.Nullable)

Example 9 with ThemeKey

use of android.content.res.Resources.ThemeKey in project android_frameworks_base by crdroidandroid.

the class Resources_Theme_Delegate method setupResources.

// ---- private helper methods ----
private static boolean setupResources(Theme thisTheme) {
    // Key is a space-separated list of theme ids applied that have been merged into the
    // BridgeContext's theme to make thisTheme.
    final ThemeKey key = thisTheme.getKey();
    final int[] resId = key.mResId;
    final boolean[] force = key.mForce;
    boolean changed = false;
    for (int i = 0, N = key.mCount; i < N; i++) {
        StyleResourceValue style = resolveStyle(resId[i]);
        if (style != null) {
            RenderSessionImpl.getCurrentContext().getRenderResources().applyStyle(style, force[i]);
            changed = true;
        }
    }
    return changed;
}
Also used : StyleResourceValue(com.android.ide.common.rendering.api.StyleResourceValue) ThemeKey(android.content.res.Resources.ThemeKey)

Aggregations

ThemeKey (android.content.res.Resources.ThemeKey)9 Nullable (android.annotation.Nullable)5 WeakReference (java.lang.ref.WeakReference)5 StyleResourceValue (com.android.ide.common.rendering.api.StyleResourceValue)4