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 Etar-Calendar by Etar-Group.
the class CalendarController method getInstance.
/**
* Creates and/or returns an instance of CalendarController associated with
* the supplied context. It is best to pass in the current Activity.
*
* @param context The activity if at all possible.
*/
public static CalendarController getInstance(Context context) {
synchronized (instances) {
CalendarController controller = null;
WeakReference<CalendarController> weakController = instances.get(context);
if (weakController != null) {
controller = weakController.get();
}
if (controller == null) {
controller = new CalendarController(context);
instances.put(context, new WeakReference(controller));
}
return controller;
}
}
use of java.lang.ref.WeakReference in project PhotoNoter by yydcdut.
the class PhotoModel method findByMedia.
@NonNull
public Map<String, MediaFolder> findByMedia(@NonNull Context context) {
WeakReference<Context> contextWeakReference = new WeakReference<>(context);
if (mMediaCache == null) {
mMediaCache = new HashMap<>();
MediaFolder mediaFolder4All = new MediaFolder(MediaFolder.ALL, new ArrayList<MediaPhoto>());
mMediaCache.put(MediaFolder.ALL, mediaFolder4All);
final String[] projectionPhotos = { MediaStore.Images.Media._ID, MediaStore.Images.Media.BUCKET_ID, MediaStore.Images.Media.BUCKET_DISPLAY_NAME, MediaStore.Images.Media.DATA, MediaStore.Images.Media.DATE_TAKEN, MediaStore.Images.Media.ORIENTATION, MediaStore.Images.Thumbnails.DATA };
Cursor cursor = MediaStore.Images.Media.query(contextWeakReference.get().getContentResolver(), MediaStore.Images.Media.EXTERNAL_CONTENT_URI, projectionPhotos, "", null, MediaStore.Images.Media.DATE_TAKEN + " DESC");
if (cursor == null) {
return mMediaCache;
}
while (cursor.moveToNext()) {
String path = cursor.getString(cursor.getColumnIndex(MediaStore.Images.Media.DATA));
String thumb = cursor.getString(cursor.getColumnIndex(MediaStore.Images.Thumbnails.DATA));
File file = new File(path);
if (file.exists() && file.length() > 0) {
MediaPhoto mediaPhoto = new MediaPhoto(path, thumb);
String folderName = file.getParentFile().getName();
MediaFolder mediaFolder = mMediaCache.get(folderName);
if (mediaFolder == null) {
List<MediaPhoto> mediaPhotoList = new ArrayList<>();
mediaPhotoList.add(mediaPhoto);
mediaFolder = new MediaFolder(folderName, mediaPhotoList);
mMediaCache.put(folderName, mediaFolder);
} else {
mediaFolder.getMediaPhotoList().add(mediaPhoto);
}
mediaFolder4All.getMediaPhotoList().add(mediaPhoto);
}
}
}
contextWeakReference.clear();
return mMediaCache;
}
use of java.lang.ref.WeakReference in project pcgen by PCGen.
the class AbstractReferenceManufacturer method validateDuplicates.
private boolean validateDuplicates() {
boolean returnGood = true;
for (CaseInsensitiveString second : duplicates.getKeySet()) {
List<T> list = duplicates.getListFor(second);
T good = active.get(second.toString());
/*
* CONSIDER Should get CDOMObject reference out of here :(
*/
if (good instanceof CDOMObject) {
CDOMObject cdo = (CDOMObject) good;
for (int i = 0; i < list.size(); i++) {
T dupe = list.get(i);
if (cdo.isCDOMEqual((CDOMObject) dupe)) {
for (Iterator<WeakReference<T>> it = manufactured.iterator(); it.hasNext(); ) {
WeakReference<T> wr = it.next();
T mfg = wr.get();
if (mfg == null) {
it.remove();
} else // Yes this is instance equality, not .equals
if (mfg == good) {
forgetObject(good);
break;
}
}
}
}
}
if (duplicates.containsListFor(second)) {
Logging.errorPrint("More than one " + factory.getReferenceDescription() + " with key/name " + good.getKeyName() + " was built");
List<T> dupes = duplicates.getListFor(second);
StringBuilder sb = new StringBuilder(1000);
sb.append("Sources: ");
sb.append(good.isInternal() ? "<internal>" : good.getSourceURI());
for (T dupe : dupes) {
sb.append(", ").append(dupe.isInternal() ? "<internal>" : dupe.getSourceURI());
if (!dupe.getKeyName().equals(good.getKeyName())) {
Logging.errorPrint("Key case differed for " + dupe.getKeyName());
}
}
Logging.errorPrint(sb.toString());
returnGood = false;
}
}
return returnGood;
}
use of java.lang.ref.WeakReference in project pcgen by PCGen.
the class AbstractReferenceManufacturer method resolveGroupReferences.
private boolean resolveGroupReferences() {
for (T obj : getAllObjects()) {
if (allRef != null) {
allRef.addResolution(obj);
}
for (Map.Entry<FixedStringList, WeakReference<CDOMGroupRef<T>>> me : typeReferences.entrySet()) {
CDOMGroupRef<T> trt = me.getValue().get();
if (trt != null) {
boolean typeOkay = true;
for (String type : me.getKey()) {
if (!obj.isType(type)) {
typeOkay = false;
break;
}
}
if (typeOkay) {
trt.addResolution(obj);
}
}
}
}
if (allRef != null && allRef.getObjectCount() == 0) {
Logging.errorPrint("Error: No " + factory.getReferenceDescription() + " objects were loaded but were referred to in the data");
fireUnconstuctedEvent(allRef);
return false;
}
return true;
}
Aggregations