Example usage for java.lang.ref WeakReference WeakReference

List of usage examples for java.lang.ref WeakReference WeakReference

Introduction

In this page you can find the example usage for java.lang.ref WeakReference WeakReference.

Prototype

public WeakReference(T referent) 

Source Link

Document

Creates a new weak reference that refers to the given object.

Usage

From source file:com.doublesunflower.android.lockcast.ImageManager.java

/**
 * Adds an observer to be notified when the set of items held by this ImageManager changes.
 *//*  w  w  w. ja va  2s  .  c o  m*/
public void addObserver(DataSetObserver observer) {
    WeakReference<DataSetObserver> obs = new WeakReference<DataSetObserver>(observer);
    mObservers.add(obs);
}

From source file:com.cerema.cloud2.ui.preview.PreviewTextFragment.java

private void loadAndShowTextPreview() {
    mTextLoadTask = new TextLoadAsyncTask(new WeakReference<TextView>(mTextPreview));
    mTextLoadTask.execute(getFile().getStoragePath());
}

From source file:com.oddrun.befrest.connectivity.WebSocketConnection.java

public WebSocketConnection() {
    if (DEBUG)/*w  w  w  . j  a  va2s .c  o m*/
        Log.d(TAG, "created");

    // create WebSocket master handler
    //        createHandler();
    mMasterHandler = new MasterHandler(new WeakReference<WebSocketConnection>(this));

    // set initial values
    mActive = false;
    mPrevConnected = false;
}

From source file:com.bullmobi.message.services.media.MediaController2KitKat.java

/**
 * {@inheritDoc}/*  ww w .j a  va2 s  .c o m*/
 */
protected MediaController2KitKat(@NonNull Activity activity) {
    super(activity);

    SparseIntArray cachedStateSparse = sStateSparse.get();
    if (cachedStateSparse == null) {
        mStateSparse = new SparseIntArray();
        mStateSparse.put(RemoteControlClient.PLAYSTATE_BUFFERING, PlaybackStateCompat.STATE_BUFFERING);
        mStateSparse.put(RemoteControlClient.PLAYSTATE_PLAYING, PlaybackStateCompat.STATE_PLAYING);
        mStateSparse.put(RemoteControlClient.PLAYSTATE_PAUSED, PlaybackStateCompat.STATE_PAUSED);
        mStateSparse.put(RemoteControlClient.PLAYSTATE_ERROR, PlaybackStateCompat.STATE_ERROR);
        mStateSparse.put(RemoteControlClient.PLAYSTATE_REWINDING, PlaybackStateCompat.STATE_REWINDING);
        mStateSparse.put(RemoteControlClient.PLAYSTATE_FAST_FORWARDING,
                PlaybackStateCompat.STATE_FAST_FORWARDING);
        mStateSparse.put(RemoteControlClient.PLAYSTATE_SKIPPING_FORWARDS,
                PlaybackStateCompat.STATE_SKIPPING_TO_NEXT);
        mStateSparse.put(RemoteControlClient.PLAYSTATE_SKIPPING_BACKWARDS,
                PlaybackStateCompat.STATE_SKIPPING_TO_PREVIOUS);

        // Cache sparse array
        sStateSparse = new WeakReference<>(mStateSparse);
    } else {
        mStateSparse = cachedStateSparse;
    }
}

From source file:mangotiger.poker.channel.EventChannelImpl.java

public void subscribe(final Object subscriber) {
    subscriptions.add(new WeakReference<Object>(subscriber));
    // remove subscriber from cancellation list to cater to a two directives given
    cancellations.remove(subscriber);// www  . j  a va  2  s .c om
}

From source file:com.bottomsheetbehavior.BackdropBottomSheetBehavior.java

/**
 * Look into the CoordiantorLayout for the {@link RNBottomSheetBehavior}
 * @param coordinatorLayout with app:layout_behavior= {@link RNBottomSheetBehavior}
 *//* w w  w .  j  a v a 2s .c  om*/
private void getBottomSheetBehavior(@NonNull CoordinatorLayout coordinatorLayout) {

    for (int i = 0; i < coordinatorLayout.getChildCount(); i++) {
        View child = coordinatorLayout.getChildAt(i);

        if (child instanceof NestedScrollView) {

            try {
                RNBottomSheetBehavior temp = RNBottomSheetBehavior.from(child);
                mBottomSheetBehaviorRef = new WeakReference<>(temp);
                break;
            } catch (IllegalArgumentException e) {
            }
        }
    }
}

From source file:com.adwhirl.AdWhirlLayout.java

protected void init(final Activity context, final String keyAdWhirl) {
    this.activityReference = new WeakReference<Activity>(context);
    this.superViewReference = new WeakReference<RelativeLayout>(this);
    this.keyAdWhirl = keyAdWhirl;
    this.hasWindow = true;
    this.isScheduled = true;
    scheduler.schedule(new InitRunnable(this, keyAdWhirl), 0, TimeUnit.SECONDS);

    setHorizontalScrollBarEnabled(false);
    setVerticalScrollBarEnabled(false);//from  w ww.  j a v  a 2  s  . c om

    this.maxWidth = 0;
    this.maxHeight = 0;
}

From source file:com.fastbootmobile.encore.app.fragments.RecognitionFragment.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    mHandler = new RecognitionHandler(new WeakReference<>(this));
}

From source file:com.comphenix.protocol.error.DetailedErrorReporter.java

/**
 * Create a central error reporting system.
 * @param plugin - the plugin owner.//from www .ja  v a  2  s  .co m
 * @param prefix - default line prefix.
 * @param supportURL - URL to report the error.
 * @param maxErrorCount - number of errors to print before giving up.
 * @param logger - current logger.
 */
public DetailedErrorReporter(Plugin plugin, String prefix, String supportURL, int maxErrorCount,
        Logger logger) {
    if (plugin == null)
        throw new IllegalArgumentException("Plugin cannot be NULL.");

    this.pluginReference = new WeakReference<Plugin>(plugin);
    this.pluginName = getNameSafely(plugin);
    this.prefix = prefix;
    this.supportURL = supportURL;
    this.maxErrorCount = maxErrorCount;
    this.logger = logger;
}

From source file:org.nabucco.alfresco.enhScriptEnv.common.script.batch.DefaultFacadeFactory.java

/**
 * {@inheritDoc}//  w w  w  .  ja  v  a 2  s  .  co  m
 */
@Override
public Scriptable toFacadedObject(final Scriptable obj, final Scriptable referenceScope,
        final String accessName) {
    final Scriptable facadedObject;

    if (obj != null && !(obj instanceof ObjectFacadingDelegator)) {
        final Scriptable threadLocalFacadedObj;
        final Map<Scriptable, WeakReference<Scriptable>> facadeByRealObject = this.facadeByRealObject.get();
        if (facadeByRealObject != null) {
            final WeakReference<Scriptable> threadLocalFacadedObjRef = facadeByRealObject.get(obj);
            threadLocalFacadedObj = threadLocalFacadedObjRef != null ? threadLocalFacadedObjRef.get() : null;
        } else {
            threadLocalFacadedObj = null;
            this.facadeByRealObject.set(new WeakHashMap<Scriptable, WeakReference<Scriptable>>());
        }

        if (threadLocalFacadedObj == null) {
            Map<Scriptable, WeakReference<Scriptable>> facadeByRealObjectAndReferenceScope = this.facadeByRealObjectAndReferenceScope
                    .get(referenceScope);
            if (facadeByRealObjectAndReferenceScope == null) {
                synchronized (this.facadeByRealObjectAndReferenceScope) {
                    facadeByRealObjectAndReferenceScope = this.facadeByRealObjectAndReferenceScope
                            .get(referenceScope);
                    if (facadeByRealObjectAndReferenceScope == null) {
                        facadeByRealObjectAndReferenceScope = new WeakHashMap<Scriptable, WeakReference<Scriptable>>();
                        this.facadeByRealObjectAndReferenceScope.put(referenceScope,
                                facadeByRealObjectAndReferenceScope);
                    }
                }
            }

            WeakReference<Scriptable> globalFacadedObjectRef = facadeByRealObjectAndReferenceScope.get(obj);
            Scriptable globalFacadedObject = globalFacadedObjectRef != null ? globalFacadedObjectRef.get()
                    : null;
            if (globalFacadedObject == null) {
                synchronized (facadeByRealObjectAndReferenceScope) {
                    globalFacadedObjectRef = facadeByRealObjectAndReferenceScope.get(obj);
                    globalFacadedObject = globalFacadedObjectRef != null ? globalFacadedObjectRef.get() : null;
                    if (globalFacadedObject == null) {
                        globalFacadedObject = this.toFacadedObjectImpl(obj, referenceScope, accessName);
                        facadeByRealObjectAndReferenceScope.put(obj,
                                new WeakReference<Scriptable>(globalFacadedObject));
                    }
                }
            }

            facadedObject = globalFacadedObject;

            this.facadeByRealObject.get().put(obj, new WeakReference<Scriptable>(facadedObject));
        } else {
            facadedObject = threadLocalFacadedObj;
        }
    } else {
        facadedObject = obj;
    }

    return facadedObject;
}