Example usage for java.lang.ref SoftReference get

List of usage examples for java.lang.ref SoftReference get

Introduction

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

Prototype

public T get() 

Source Link

Document

Returns this reference object's referent.

Usage

From source file:im.ene.ribbon.ActionTabView.java

public void setTypeface(final SoftReference<Typeface> typeface) {
    if (null != typeface) {
        Typeface tf = typeface.get();
        if (null != tf) {
            textPaint.setTypeface(tf);/* w w  w.java  2 s .c o  m*/
        } else {
            textPaint.setTypeface(Typeface.DEFAULT);
        }

        textDirty = true;
        requestLayout();
    }
}

From source file:org.appcelerator.titanium.util.TiDownloadManager.java

protected void handleFireDownloadMessage(URI uri, int what) {
    ArrayList<SoftReference<TiDownloadListener>> toRemove = new ArrayList<SoftReference<TiDownloadListener>>();
    synchronized (listeners) {
        String hash = DigestUtils.shaHex(uri.toString());
        for (SoftReference<TiDownloadListener> listener : listeners.get(hash)) {
            if (listener.get() != null) {
                if (what == MSG_FIRE_DOWNLOAD_FINISHED) {
                    fireDownloadFinished(uri, listener.get());
                } else if (what == MSG_FIRE_DOWNLOAD_FAILED) {
                    fireDownloadFailed(listener.get());
                }//from www  . j a  v  a2s.co  m
                toRemove.add(listener);
            }
        }
        for (SoftReference<TiDownloadListener> listener : toRemove) {
            listeners.get(hash).remove(listener);
        }
    }
}

From source file:com.binroot.fatpita.BitmapManager2.java

public Bitmap fetchBitmap(String urlString, int sample) {
    SoftReference<Bitmap> ref = mCache.get(urlString);
    if (ref != null && ref.get() != null) {
        return ref.get();
    }/*  w w w. j ava 2s.  c o m*/

    Log.d(TAG, "image url:" + urlString);

    try {
        Bitmap bitmap = readBitmapFromNetwork(urlString, sample);
        mCache.put(urlString, new SoftReference<Bitmap>(bitmap));
        //          if (Constants.LOGGING) Log.d(this.getClass().getSimpleName(), "got a thumbnail drawable: " + drawable.getBounds() + ", "
        //                + drawable.getIntrinsicHeight() + "," + drawable.getIntrinsicWidth() + ", "
        //                + drawable.getMinimumHeight() + "," + drawable.getMinimumWidth());
        return bitmap;
    } catch (Exception e) {
        Log.e(TAG, "fetchBitmap failed", e);
        return null;
    }
}

From source file:com.andrewshu.android.reddit.threads.BitmapManager.java

public Bitmap fetchBitmap(String urlString) {
    SoftReference<Bitmap> ref = mCache.get(urlString);
    if (ref != null && ref.get() != null) {
        return ref.get();
    }/*from   w  w  w. ja va  2 s .  com*/

    if (Constants.LOGGING)
        Log.d(TAG, "image url:" + urlString);

    try {
        Bitmap bitmap = readBitmapFromNetwork(urlString);
        mCache.put(urlString, new SoftReference<Bitmap>(bitmap));
        //          if (Constants.LOGGING) Log.d(this.getClass().getSimpleName(), "got a thumbnail drawable: " + drawable.getBounds() + ", "
        //                + drawable.getIntrinsicHeight() + "," + drawable.getIntrinsicWidth() + ", "
        //                + drawable.getMinimumHeight() + "," + drawable.getMinimumWidth());
        return bitmap;
    } catch (Exception e) {
        if (Constants.LOGGING)
            Log.e(TAG, "fetchBitmap failed", e);
        return null;
    }
}

From source file:org.apache.ojb.broker.cache.ObjectCacheLocalDefaultImpl.java

/**
 * Lookup object with Identity oid in objectTable.
 * Returns null if no matching id is found
 *//* w  w  w  . j  av  a 2 s . c  om*/
public Object lookup(Identity oid) {
    CacheEntry entry = null;
    SoftReference ref = (SoftReference) objectTable.get(oid);
    if (ref != null) {
        entry = (CacheEntry) ref.get();
        if (entry == null || entry.lifetime < System.currentTimeMillis()) {
            objectTable.remove(oid); // Soft-referenced Object reclaimed by GC
            // timeout, so set null
            entry = null;
        }
    }
    return entry != null ? entry.object : null;
}

From source file:org.entrystore.repository.impl.SoftCache.java

public Entry getByEntryURI(URI uri) {
    SoftReference<Entry> sr = cache.get(uri);

    if (sr != null) {
        return sr.get();
    }/* w w  w. java 2  s . c o  m*/
    return null;
}

From source file:com.binroot.fatpita.BitmapManager.java

public Bitmap fetchBitmap(String urlString, boolean saveToHistory) {
    SoftReference<Bitmap> ref = mCache.get(urlString);
    if (ref != null && ref.get() != null) {
        return ref.get();
    }//www  . ja va  2 s  . c o  m

    Log.d(TAG, "image url:" + urlString);

    try {
        Bitmap bitmap = readBitmapFromNetwork(urlString, saveToHistory);
        mCache.put(urlString, new SoftReference<Bitmap>(bitmap));
        //          if (Constants.LOGGING) Log.d(this.getClass().getSimpleName(), "got a thumbnail drawable: " + drawable.getBounds() + ", "
        //                + drawable.getIntrinsicHeight() + "," + drawable.getIntrinsicWidth() + ", "
        //                + drawable.getMinimumHeight() + "," + drawable.getMinimumWidth());
        return bitmap;
    } catch (Exception e) {
        Log.e(TAG, "fetchBitmap failed", e);
        return null;
    }
}

From source file:com.andrewshu.android.reddit.threads.BitmapManager.java

public void fetchBitmapOnThread(final String urlString, final ImageView imageView,
        final ProgressBar indeterminateProgressBar, final Activity act) {
    SoftReference<Bitmap> ref = mCache.get(urlString);
    if (ref != null && ref.get() != null) {
        imageView.setImageBitmap(ref.get());
        return;/*from www .ja va2 s . c o m*/
    }

    final Runnable progressBarShow = new Runnable() {
        public void run() {
            if (indeterminateProgressBar != null) {
                imageView.setVisibility(View.GONE);
                indeterminateProgressBar.setVisibility(View.VISIBLE);
            }
        }
    };
    final Runnable progressBarHide = new Runnable() {
        public void run() {
            if (indeterminateProgressBar != null) {
                indeterminateProgressBar.setVisibility(View.GONE);
                imageView.setVisibility(View.VISIBLE);
            }
        }
    };

    final Handler handler = new Handler() {
        @Override
        public void handleMessage(Message message) {
            if (indeterminateProgressBar != null && act != null)
                act.runOnUiThread(progressBarHide);
            imageView.setImageBitmap((Bitmap) message.obj);
        }
    };

    Thread thread = new Thread() {
        @Override
        public void run() {
            if (indeterminateProgressBar != null && act != null)
                act.runOnUiThread(progressBarShow);
            Bitmap bitmap = fetchBitmap(urlString);
            Message message = handler.obtainMessage(1, bitmap);
            handler.sendMessage(message);
        }
    };
    thread.start();
}

From source file:com.binroot.fatpita.BitmapManager2.java

public void fetchBitmapOnThread(final String urlString, final ImageView imageView,
        final ProgressBar indeterminateProgressBar, final Activity act, final int sample) {
    SoftReference<Bitmap> ref = mCache.get(urlString);
    if (ref != null && ref.get() != null) {
        imageView.setImageBitmap(ref.get());
        return;//from   ww  w  . ja  va  2  s. c om
    }

    final Runnable progressBarShow = new Runnable() {
        public void run() {
            if (indeterminateProgressBar != null) {
                imageView.setVisibility(View.GONE);
                indeterminateProgressBar.setVisibility(View.VISIBLE);
            }
        }
    };
    final Runnable progressBarHide = new Runnable() {
        public void run() {
            if (indeterminateProgressBar != null) {
                indeterminateProgressBar.setVisibility(View.GONE);
                imageView.setVisibility(View.VISIBLE);
            }
        }
    };

    final Handler handler = new Handler() {
        @Override
        public void handleMessage(Message message) {
            if (indeterminateProgressBar != null && act != null)
                act.runOnUiThread(progressBarHide);
            imageView.setImageBitmap((Bitmap) message.obj);
        }
    };

    Thread thread = new Thread() {
        @Override
        public void run() {
            if (indeterminateProgressBar != null && act != null)
                act.runOnUiThread(progressBarShow);
            Bitmap bitmap = fetchBitmap(urlString, sample);
            Message message = handler.obtainMessage(1, bitmap);
            handler.sendMessage(message);
        }
    };
    thread.start();
}

From source file:com.taobao.common.tedis.cache.DefaultLocalCache.java

public Collection<V> values() {
    checkAll();//  ww w  .  j  a  v  a 2  s .c  om

    Collection<V> values = new ArrayList<V>();

    for (ConcurrentHashMap<K, SoftReference<V>> cache : caches) {
        for (SoftReference<V> sr : cache.values()) {
            values.add(sr.get());
        }
    }

    return values;
}