List of usage examples for java.lang.ref WeakReference WeakReference
public WeakReference(T referent)
From source file:com.creativtrendz.folio.ui.FolioWebViewScroll.java
public void setListener(final Activity activity, final Listener listener, final int requestCodeFilePicker) { if (activity != null) { mActivity = new WeakReference<>(activity); } else {/*from w ww . ja va2s.co m*/ mActivity = null; } setListener(listener, requestCodeFilePicker); }
From source file:br.com.anteros.social.instagram.AnterosInstagramSession.java
public void setActivity(Activity activity) { this.activity = new WeakReference<>(activity); }
From source file:com.am.pagergradienttab.view.PagerGradientTabStrip.java
void updateAdapter(PagerAdapter oldAdapter, PagerAdapter newAdapter) { if (oldAdapter != null) { oldAdapter.unregisterDataSetObserver(mPageListener); mWatchingAdapter = null;/*from w ww . ja v a 2s . c om*/ } tabs.clear(); if (newAdapter != null) { newAdapter.registerDataSetObserver(mPageListener); mWatchingAdapter = new WeakReference<PagerAdapter>(newAdapter); mLastKnownPosition = mPager.getCurrentItem(); currectPager = mLastKnownPosition; nextPager = mLastKnownPosition; for (int i = 0; i < newAdapter.getCount(); i++) { tabs.add(newAdapter.getPageTitle(i).toString()); } } if (mPager != null) { requestLayout(); } }
From source file:gridool.dht.btree.Paged.java
/** * getPage returns the page specified by pageNum. */// www . j a va2s. c o m protected final Page getPage(long pageNum) throws IndexException { Page p = null; // if not check if it's already loaded in the page cache Reference<Page> ref = _pages.get(pageNum); // Check if required page is in the volatile cache if (ref != null) { p = ref.get(); } if (p == null) { // if still not found we need to create it and add it to the page cache. p = new Page(pageNum); try { p.read(); // Load the page from disk if necessary } catch (IOException e) { throw new IndexException(e); } _pages.put(pageNum, new WeakReference<Page>(p)); } return p; }
From source file:com.android.launcher2.AsyncTaskCallback.java
public T get() { WeakReference<T> reference = mThreadLocal.get(); T obj;// w w w .j av a 2 s . c om if (reference == null) { obj = initialValue(); mThreadLocal.set(new WeakReference<T>(obj)); return obj; } else { obj = reference.get(); if (obj == null) { obj = initialValue(); mThreadLocal.set(new WeakReference<T>(obj)); } return obj; } }
From source file:android.support.design.widget.SheetBehavior.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); }// www. java 2 s . co m if (mSlideHelper == null) { mSlideHelper = createSlideHelper(mSlideModel); } if (mViewDragHelper == null) { mViewDragHelper = ViewDragHelper.create(parent, mDragCallback); } // Offset the bottom sheet mSlideHelper.onLayoutChild(child); mViewRef = new WeakReference<>(child); mNestedScrollingChildRef = new WeakReference<>(findScrollingChild(child)); return true; }
From source file:de.unwesen.web.DownloadCache.java
/*************************************************************************** * Implementation/*from w w w .jav a 2 s . c o m*/ **/ // The cachePrevix parameter specifies a directory name under which cache // content is stored. public DownloadCache(Context context, String cachePrefix, Tunables tunables) { if (null == context || null == tunables) { Log.e(LTAG, "DownloadCache instanciated without context or tunables."); throw new IllegalArgumentException("DownloadCache instanciated without " + "context or tunables."); } mContext = new WeakReference<Context>(context); mTunables = tunables; mCachePrefix = cachePrefix; if (null == mCachePrefix) { // Simple default for the cache prefix. mCachePrefix = "cache"; } mFetcher = new Fetcher(); mFetcher.start(); mLRUThread = new LRUThread(); mLRUThread.start(); }
From source file:com.creativtrendz.folio.ui.FolioWebViewScroll.java
public void setListener(final Fragment fragment, final Listener listener, final int requestCodeFilePicker) { if (fragment != null) { mFragment = new WeakReference<>(fragment); } else {/*w w w . j a v a 2 s . c o m*/ mFragment = null; } setListener(listener, requestCodeFilePicker); }
From source file:net.sf.maltcms.chromaui.charts.overlay.Peak1DHeatmapOverlay.java
/** * * @return/*from w w w .j a va 2 s .co m*/ */ @Override public Node createNodeDelegate() { Logger.getLogger(getClass().getName()).warning("Creating node delegate"); Node node = null; if (nodeReference == null) { node = Charts.overlayNode(this); nodeReference = new WeakReference<>(node); } else { node = nodeReference.get(); if (node == null) { node = Charts.overlayNode(this); nodeReference = new WeakReference<>(node); } } return node; }
From source file:org.modelmapper.internal.util.TypeResolver.java
private static Map<TypeVariable<?>, Type> getTypeVariableMap(final Class<?> targetType) { Reference<Map<TypeVariable<?>, Type>> ref = typeVariableCache.get(targetType); Map<TypeVariable<?>, Type> map = ref != null ? ref.get() : null; if (map == null) { map = new HashMap<TypeVariable<?>, Type>(); // Populate interfaces buildTypeVariableMap(targetType.getGenericInterfaces(), map); // Populate super classes and interfaces Type genericType = targetType.getGenericSuperclass(); Class<?> type = targetType.getSuperclass(); while (type != null && !Object.class.equals(type)) { if (genericType instanceof ParameterizedType) buildTypeVariableMap((ParameterizedType) genericType, map); buildTypeVariableMap(type.getGenericInterfaces(), map); genericType = type.getGenericSuperclass(); type = type.getSuperclass(); }/*w w w. j av a 2 s .co m*/ // Populate enclosing classes type = targetType; while (type.isMemberClass()) { genericType = type.getGenericSuperclass(); if (genericType instanceof ParameterizedType) buildTypeVariableMap((ParameterizedType) genericType, map); type = type.getEnclosingClass(); } typeVariableCache.put(targetType, new WeakReference<Map<TypeVariable<?>, Type>>(map)); } return map; }