Search in sources :

Example 56 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 57 with WeakReference

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;
    }
}
Also used : WeakReference(java.lang.ref.WeakReference)

Example 58 with WeakReference

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;
}
Also used : Context(android.content.Context) ArrayList(java.util.ArrayList) MediaFolder(com.yydcdut.noteplugin.bean.MediaFolder) Cursor(android.database.Cursor) WeakReference(java.lang.ref.WeakReference) MediaPhoto(com.yydcdut.noteplugin.bean.MediaPhoto) File(java.io.File) TreeFile(com.yydcdut.noteplugin.bean.TreeFile) NonNull(android.support.annotation.NonNull)

Example 59 with WeakReference

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;
}
Also used : CDOMObject(pcgen.cdom.base.CDOMObject) WeakReference(java.lang.ref.WeakReference) CaseInsensitiveString(pcgen.base.lang.CaseInsensitiveString)

Example 60 with WeakReference

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;
}
Also used : WeakReference(java.lang.ref.WeakReference) FixedStringList(pcgen.base.util.FixedStringList) CaseInsensitiveString(pcgen.base.lang.CaseInsensitiveString) TreeMap(java.util.TreeMap) KeyMap(pcgen.base.util.KeyMap) Map(java.util.Map)

Aggregations

WeakReference (java.lang.ref.WeakReference)291 ArrayList (java.util.ArrayList)32 HashMap (java.util.HashMap)24 Map (java.util.Map)24 Field (java.lang.reflect.Field)19 Activity (android.app.Activity)17 Iterator (java.util.Iterator)17 IOException (java.io.IOException)16 Method (java.lang.reflect.Method)15 File (java.io.File)14 URLClassLoader (java.net.URLClassLoader)14 Test (org.junit.Test)13 Reference (java.lang.ref.Reference)12 ReferenceQueue (java.lang.ref.ReferenceQueue)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