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:org.nabucco.alfresco.enhScriptEnv.common.script.functions.AbstractLogFunction.java

protected void handleRegisterChildScope(final Object parentScope, final Object childScope) {
    ParameterCheck.mandatory("parentScope", parentScope);
    ParameterCheck.mandatory("childScope", childScope);

    final ReferenceScript script = this.scriptProcessor.getContextScriptLocation();
    this.scopeParentLock.writeLock().lock();
    try {/*  w  ww  .j av  a 2s  .c  o  m*/
        this.scopeParents.put(childScope, new Pair<WeakReference<Object>, ReferenceScript>(
                new WeakReference<Object>(parentScope), script));
    } finally {
        this.scopeParentLock.writeLock().unlock();
    }
}

From source file:android.support.designox.widget.BottomSheetBehavior.java

@Override
public boolean onLayoutChild(CoordinatorLayout parent, V child, int layoutDirection) {
    // First let the parent lay it out
    if (mState != STATE_DRAGGING && mState != STATE_SETTLING) {
        parent.onLayoutChild(child, layoutDirection);
    }//from ww w. j a va2s .  com
    // Offset the bottom sheet
    mParentHeight = parent.getHeight();
    mMinOffset = Math.max(0, mParentHeight - child.getHeight());
    mMaxOffset = Math.max(mParentHeight - mPeekHeight, mMinOffset);
    if (mState == STATE_EXPANDED) {
        ViewCompat.offsetTopAndBottom(child, mMinOffset);
    } else if (mHideable && mState == STATE_HIDDEN) {
        ViewCompat.offsetTopAndBottom(child, mParentHeight);
    } else if (mState == STATE_COLLAPSED) {
        ViewCompat.offsetTopAndBottom(child, mMaxOffset);
    }
    if (mViewDragHelper == null) {
        mViewDragHelper = ViewDragHelper.create(parent, mDragCallback);
    }
    mViewRef = new WeakReference<>(child);
    mNestedScrollingChildRef = new WeakReference<>(findScrollingChild(child));
    return true;
}

From source file:com.example.g40_70m.framedemo.view.photoview.PhotoViewAttacher.java

public PhotoViewAttacher(ImageView imageView, boolean zoomable) {
    mImageView = new WeakReference<>(imageView);

    imageView.setDrawingCacheEnabled(true);
    imageView.setOnTouchListener(this);

    ViewTreeObserver observer = imageView.getViewTreeObserver();
    if (null != observer)
        observer.addOnGlobalLayoutListener(this);

    // Make sure we using MATRIX Scale Type
    setImageViewScaleTypeMatrix(imageView);

    if (imageView.isInEditMode()) {
        return;/*from w ww.j  a  va  2  s.c  om*/
    }
    // Create Gesture Detectors...
    mScaleDragDetector = VersionedGestureDetector.newInstance(imageView.getContext(), this);
    mGestureDetector = new GestureDetector(imageView.getContext().getApplicationContext(),
            new GestureDetector.SimpleOnGestureListener() {

                @Override
                public boolean onDown(MotionEvent e) {
                    downTime = System.currentTimeMillis();
                    singeClick = !singeClick;
                    return super.onDown(e);
                }

                @Override
                public boolean onSingleTapUp(MotionEvent e) {
                    if (System.currentTimeMillis() - downTime < 200) {
                        getImageView().postDelayed(new Runnable() {//300? ?
                            @Override
                            public void run() {
                                if (singeClick) {
                                    onClickListener.onClick(getImageView());
                                }
                            }
                        }, 300);
                    }
                    downTime = 0;
                    return super.onSingleTapUp(e);
                }

                // forward long click listener
                @Override
                public void onLongPress(MotionEvent e) {
                    singeClick = false;
                    if (null != mLongClickListener) {
                        mLongClickListener.onLongClick(getImageView());
                    }
                }

                @Override
                public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
                    if (mSingleFlingListener != null) {
                        if (getScale() > DEFAULT_MIN_SCALE) {
                            return false;
                        }
                        if (MotionEventCompat.getPointerCount(e1) > SINGLE_TOUCH
                                || MotionEventCompat.getPointerCount(e2) > SINGLE_TOUCH) {
                            return false;
                        }

                        return mSingleFlingListener.onFling(e1, e2, velocityX, velocityY);
                    }
                    return false;
                }
            });

    mGestureDetector.setOnDoubleTapListener(new DefaultOnDoubleTapListener(this));
    mBaseRotation = 0.0f;

    // Finally, update the UI so that we're zoomable
    setZoomable(zoomable);
}

From source file:com.bilibili.magicasakura.utils.TintManager.java

private boolean addCachedDrawable(final int key, @NonNull final Drawable drawable) {
    if (drawable instanceof FilterableStateListDrawable) {
        return false;
    }//from  w ww. j ava2 s.  c o m
    final Drawable.ConstantState cs = drawable.getConstantState();
    if (cs != null) {
        synchronized (mDrawableCacheLock) {
            if (mCacheDrawables == null) {
                mCacheDrawables = new SparseArray<>();
            }
            mCacheDrawables.put(key, new WeakReference<>(cs));
        }
        return true;
    }
    return false;
}

From source file:am.widget.basetabstrip.BaseTabStrip.java

/**
 * ?PagerAdapter// ww  w  .j a v  a  2 s.  co m
 *
 * @param oldAdapter Adapter
 * @param newAdapter Adapter
 */
protected void bindPagerAdapter(PagerAdapter oldAdapter, PagerAdapter newAdapter) {
    if (oldAdapter != null) {
        oldAdapter.unregisterDataSetObserver(mPageListener);
        mWatchingAdapter = null;
    }
    if (newAdapter != null) {
        newAdapter.registerDataSetObserver(mPageListener);
        mWatchingAdapter = new WeakReference<>(newAdapter);
    }
    createItemBackgrounds();
    onBindPagerAdapter();
    checkCurrentItem();
    requestLayout();
    invalidate();
}

From source file:JDBCPool.dbcp.demo.sourcecode.BaseGenericObjectPool.java

/**
 * Handles JMX registration (if required) and the initialization required for
 * monitoring.//from   w ww . j  a v  a2s . co m
 *
 * @param config        Pool configuration
 * @param jmxNameBase   The default base JMX name for the new pool unless
 *                      overridden by the config
 * @param jmxNamePrefix Prefix to be used for JMX name for the new pool
 */
public BaseGenericObjectPool(BaseObjectPoolConfig config, String jmxNameBase, String jmxNamePrefix) {
    if (config.getJmxEnabled()) {
        this.oname = jmxRegister(config, jmxNameBase, jmxNamePrefix);
    } else {
        this.oname = null;
    }

    // Populate the creation stack trace
    this.creationStackTrace = getStackTrace(new Exception());

    // save the current TCCL (if any) to be used later by the evictor Thread
    ClassLoader cl = Thread.currentThread().getContextClassLoader();
    if (cl == null) {
        factoryClassLoader = null;
    } else {
        factoryClassLoader = new WeakReference<ClassLoader>(cl);
    }

    fairness = config.getFairness();
}

From source file:com.gargoylesoftware.htmlunit.javascript.background.DefaultJavaScriptExecutor.java

private synchronized void updateJobMangerList(final JavaScriptJobManager newJobManager) {
    for (WeakReference<JavaScriptJobManager> weakReference : jobManagerList_) {
        final JavaScriptJobManager manager = weakReference.get();
        if (newJobManager == manager) {
            return;
        }/*from ww  w. j a  v  a  2  s.  c om*/
    }

    final List<WeakReference<JavaScriptJobManager>> managers = new LinkedList<>();
    for (WeakReference<JavaScriptJobManager> weakReference : jobManagerList_) {
        final JavaScriptJobManager manager = weakReference.get();
        if (null != manager) {
            managers.add(weakReference);
        }
    }
    managers.add(new WeakReference<>(newJobManager));
    jobManagerList_ = managers;
}

From source file:com.demos.support_23_2.MyBottomBehavior.java

@Override
public boolean onLayoutChild(CoordinatorLayout parent, V child, int layoutDirection) {
    // First let the parent lay it out
    if (mState != STATE_DRAGGING && mState != STATE_SETTLING) {
        parent.onLayoutChild(child, layoutDirection);
    }//from  w ww .  j  av a2s .  c  om
    // Offset the bottom sheet
    mParentHeight = parent.getHeight();
    mMinOffset = Math.max(0, mParentHeight - child.getHeight());
    mMaxOffset = mParentHeight - mPeekHeight;
    if (mState == STATE_EXPANDED) {
        ViewCompat.offsetTopAndBottom(child, mMinOffset);
    } else if (mHideable && mState == STATE_HIDDEN) {
        ViewCompat.offsetTopAndBottom(child, mParentHeight);
    } else if (mState == STATE_COLLAPSED) {
        ViewCompat.offsetTopAndBottom(child, mMaxOffset);
    }
    if (mViewDragHelper == null) {
        mViewDragHelper = ViewDragHelper.create(parent, mDragCallback);
    }
    mViewRef = new WeakReference<>(child);
    mNestedScrollingChildRef = new WeakReference<>(findScrollingChild(child));
    return true;
}

From source file:com.android.launcher2.AsyncTaskCallback.java

public void set(T t) {
    mThreadLocal.set(new WeakReference<T>(t));
}

From source file:com.achep.acdisplay.services.activemode.sensors.ProximitySensor.java

@NonNull
public static ProximitySensor getInstance() {
    ProximitySensor sensor = sProximitySensorWeak != null ? sProximitySensorWeak.get() : null;
    if (sensor == null) {
        sensor = new ProximitySensor();
        sProximitySensorWeak = new WeakReference<>(sensor);
    }//  ww  w  .  j  a va2  s  . c  o m
    return sensor;
}