Search in sources :

Example 6 with WeakReference

use of java.lang.ref.WeakReference in project buck by facebook.

the class ResourcesLoader method getActiveResourcesFromResourcesManager.

private static Collection<WeakReference<Resources>> getActiveResourcesFromResourcesManager() {
    try {
        Class resourcesManagerClass;
        try {
            resourcesManagerClass = Class.forName("android.app.ResourcesManager");
        } catch (ClassNotFoundException e) {
            return null;
        }
        Method getResourcesManager = resourcesManagerClass.getDeclaredMethod("getInstance");
        getResourcesManager.setAccessible(true);
        Object resourcesManager = getResourcesManager.invoke(null);
        try {
            return ((ArrayMap<?, WeakReference<Resources>>) Reflect.getField(resourcesManager, resourcesManagerClass, "mActiveResources")).values();
        } catch (NoSuchFieldException e) {
            return (Collection<WeakReference<Resources>>) Reflect.getField(resourcesManager, resourcesManagerClass, "mResourceReferences");
        }
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
Also used : WeakReference(java.lang.ref.WeakReference) ArrayMap(android.util.ArrayMap) Method(java.lang.reflect.Method) Resources(android.content.res.Resources) IOException(java.io.IOException)

Example 7 with WeakReference

use of java.lang.ref.WeakReference in project android_frameworks_base by ParanoidAndroid.

the class ActivityThread method applyConfigurationToResourcesLocked.

final int applyConfigurationToResourcesLocked(Configuration config, CompatibilityInfo compat) {
    if (mResConfiguration == null) {
        mResConfiguration = new Configuration();
    }
    if (!mResConfiguration.isOtherSeqNewer(config) && compat == null) {
        if (DEBUG_CONFIGURATION)
            Slog.v(TAG, "Skipping new config: curSeq=" + mResConfiguration.seq + ", newSeq=" + config.seq);
        return 0;
    }
    int changes = mResConfiguration.updateFrom(config);
    flushDisplayMetricsLocked();
    DisplayMetrics defaultDisplayMetrics = getDisplayMetricsLocked(Display.DEFAULT_DISPLAY, null);
    if (compat != null && (mResCompatibilityInfo == null || !mResCompatibilityInfo.equals(compat))) {
        mResCompatibilityInfo = compat;
        changes |= ActivityInfo.CONFIG_SCREEN_LAYOUT | ActivityInfo.CONFIG_SCREEN_SIZE | ActivityInfo.CONFIG_SMALLEST_SCREEN_SIZE;
    }
    // set it for java, this also affects newly created Resources
    if (config.locale != null) {
        Locale.setDefault(config.locale);
    }
    Resources.updateSystemConfiguration(config, defaultDisplayMetrics, compat);
    ApplicationPackageManager.configurationChanged();
    //Slog.i(TAG, "Configuration changed in " + currentPackageName());
    Configuration tmpConfig = null;
    Iterator<Map.Entry<ResourcesKey, WeakReference<Resources>>> it = mActiveResources.entrySet().iterator();
    while (it.hasNext()) {
        Map.Entry<ResourcesKey, WeakReference<Resources>> entry = it.next();
        Resources r = entry.getValue().get();
        if (r != null) {
            if (DEBUG_CONFIGURATION)
                Slog.v(TAG, "Changing resources " + r + " config to: " + config);
            int displayId = entry.getKey().mDisplayId;
            boolean isDefaultDisplay = (displayId == Display.DEFAULT_DISPLAY);
            DisplayMetrics dm = defaultDisplayMetrics;
            Configuration overrideConfig = entry.getKey().mOverrideConfiguration;
            boolean themeChanged = (changes & ActivityInfo.CONFIG_THEME_RESOURCE) != 0;
            if (themeChanged) {
                AssetManager am = r.getAssets();
                if (am.hasThemeSupport()) {
                    detachThemeAssets(am);
                    if (!TextUtils.isEmpty(config.customTheme.getThemePackageName())) {
                        attachThemeAssets(am, config.customTheme);
                    }
                }
            }
            if (!isDefaultDisplay || overrideConfig != null) {
                if (tmpConfig == null) {
                    tmpConfig = new Configuration();
                }
                tmpConfig.setTo(config);
                if (!isDefaultDisplay) {
                    dm = getDisplayMetricsLocked(displayId, null);
                    applyNonDefaultDisplayMetricsToConfigurationLocked(dm, tmpConfig);
                }
                if (overrideConfig != null) {
                    tmpConfig.updateFrom(overrideConfig);
                }
                r.updateConfiguration(tmpConfig, dm, compat);
            } else {
                r.updateConfiguration(config, dm, compat);
            }
            if (themeChanged) {
                r.updateStringCache();
            }
        //Slog.i(TAG, "Updated app resources " + v.getKey()
        //        + " " + r + ": " + r.getConfiguration());
        } else {
            //Slog.i(TAG, "Removing old resources " + v.getKey());
            it.remove();
        }
    }
    return changes;
}
Also used : AssetManager(android.content.res.AssetManager) Configuration(android.content.res.Configuration) WeakReference(java.lang.ref.WeakReference) Resources(android.content.res.Resources) DisplayMetrics(android.util.DisplayMetrics) PackageRedirectionMap(android.content.res.PackageRedirectionMap) Map(java.util.Map) HashMap(java.util.HashMap)

Example 8 with WeakReference

use of java.lang.ref.WeakReference in project android_frameworks_base by ParanoidAndroid.

the class SurfaceTexture method postEventFromNative.

/**
     * This method is invoked from native code only.
     */
@SuppressWarnings({ "UnusedDeclaration" })
private static void postEventFromNative(Object selfRef) {
    WeakReference weakSelf = (WeakReference) selfRef;
    SurfaceTexture st = (SurfaceTexture) weakSelf.get();
    if (st == null) {
        return;
    }
    if (st.mEventHandler != null) {
        Message m = st.mEventHandler.obtainMessage();
        st.mEventHandler.sendMessage(m);
    }
}
Also used : Message(android.os.Message) WeakReference(java.lang.ref.WeakReference)

Example 9 with WeakReference

use of java.lang.ref.WeakReference in project android_frameworks_base by ParanoidAndroid.

the class SparseWeakArray method append.

/**
     * Puts a key/value pair into the array, optimizing for the case where
     * the key is greater than all existing keys in the array.
     */
public void append(int key, E value) {
    if (mSize != 0 && key <= mKeys[mSize - 1]) {
        put(key, value);
        return;
    }
    if (mSize >= mKeys.length && (mGarbage || hasReclaimedRefs())) {
        gc();
    }
    int pos = mSize;
    if (pos >= mKeys.length) {
        int n = ArrayUtils.idealIntArraySize(pos + 1);
        int[] nkeys = new int[n];
        WeakReference<?>[] nvalues = new WeakReference[n];
        // Log.e("SparseArray", "grow " + mKeys.length + " to " + n);
        System.arraycopy(mKeys, 0, nkeys, 0, mKeys.length);
        System.arraycopy(mValues, 0, nvalues, 0, mValues.length);
        mKeys = nkeys;
        mValues = nvalues;
    }
    mKeys[pos] = key;
    mValues[pos] = new WeakReference(value);
    mSize = pos + 1;
}
Also used : WeakReference(java.lang.ref.WeakReference)

Example 10 with WeakReference

use of java.lang.ref.WeakReference in project LogisticsPipes by RS485.

the class ChestGuiOpened method processPacket.

@Override
public void processPacket(EntityPlayer player) {
    List<WeakReference<ModuleQuickSort>> list = LogisticsEventListener.chestQuickSortConnection.get(player);
    if (list == null || list.isEmpty()) {
        return;
    }
    MainProxy.sendPacketToPlayer(PacketHandler.getPacket(EnableQuickSortMarker.class), player);
    for (WeakReference<ModuleQuickSort> sorter : list) {
        ModuleQuickSort module = sorter.get();
        if (module == null) {
            continue;
        }
        module.addWatchingPlayer(player);
    }
}
Also used : WeakReference(java.lang.ref.WeakReference) ModuleQuickSort(logisticspipes.modules.ModuleQuickSort)

Aggregations

WeakReference (java.lang.ref.WeakReference)277 ArrayList (java.util.ArrayList)31 HashMap (java.util.HashMap)19 Map (java.util.Map)19 Field (java.lang.reflect.Field)18 Activity (android.app.Activity)17 Method (java.lang.reflect.Method)15 File (java.io.File)14 IOException (java.io.IOException)13 URLClassLoader (java.net.URLClassLoader)13 Test (org.junit.Test)13 Reference (java.lang.ref.Reference)12 ReferenceQueue (java.lang.ref.ReferenceQueue)12 Iterator (java.util.Iterator)12 Resources (android.content.res.Resources)10 Handler (android.os.Handler)10 AbstractModule (com.google.inject.AbstractModule)10 Injector (com.google.inject.Injector)10 ArrayMap (android.util.ArrayMap)9 URL (java.net.URL)8