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);
}
}
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;
}
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);
}
}
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;
}
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);
}
}
Aggregations