use of java.lang.ref.WeakReference in project cglib by cglib.
the class Enhancer method wrapCachedClass.
@Override
protected Object wrapCachedClass(Class klass) {
Class[] argumentTypes = this.argumentTypes;
if (argumentTypes == null) {
argumentTypes = Constants.EMPTY_CLASS_ARRAY;
}
EnhancerFactoryData factoryData = new EnhancerFactoryData(klass, argumentTypes, classOnly);
Field factoryDataField = null;
try {
// The subsequent dance is performed just once for each class,
// so it does not matter much how fast it goes
factoryDataField = klass.getField(FACTORY_DATA_FIELD);
factoryDataField.set(null, factoryData);
Field callbackFilterField = klass.getDeclaredField(CALLBACK_FILTER_FIELD);
callbackFilterField.setAccessible(true);
callbackFilterField.set(null, this.filter);
} catch (NoSuchFieldException e) {
throw new CodeGenerationException(e);
} catch (IllegalAccessException e) {
throw new CodeGenerationException(e);
}
return new WeakReference<EnhancerFactoryData>(factoryData);
}
use of java.lang.ref.WeakReference in project Talon-for-Twitter by klinker24.
the class ImageUtils method imageUrlAsyncTask.
private static void imageUrlAsyncTask(final Context context, final ImageView imageView, final BitmapLruCache mCache, final boolean profile, final String url) {
final WeakReference<ImageView> mImageViewRef = new WeakReference<ImageView>(imageView);
Thread imageDownload = new Thread(new Runnable() {
@Override
public void run() {
try {
// Return early if the ImageView has disappeared.
if (null == mImageViewRef.get()) {
return;
}
// Now we're not on the main thread we can check all caches
CacheableBitmapDrawable result;
result = mCache.get(url, null);
if (null == result || profile) {
String mUrl = url;
if (url.contains("twitpic")) {
try {
URL address = new URL(url);
HttpURLConnection connection = (HttpURLConnection) address.openConnection(Proxy.NO_PROXY);
connection.setConnectTimeout(1000);
connection.setInstanceFollowRedirects(false);
connection.setReadTimeout(1000);
connection.connect();
String expandedURL = connection.getHeaderField("Location");
if (expandedURL != null) {
mUrl = expandedURL;
}
} catch (Exception e) {
e.printStackTrace();
}
}
// The bitmap isn't cached so download from the web
HttpURLConnection conn = (HttpURLConnection) new URL(mUrl).openConnection();
InputStream is = new BufferedInputStream(conn.getInputStream());
Bitmap b = decodeSampledBitmapFromResourceMemOpt(is, 500, 500);
try {
is.close();
} catch (Exception e) {
}
try {
conn.disconnect();
} catch (Exception e) {
}
// Add to cache
try {
result = mCache.put(mUrl, b);
} catch (Exception e) {
result = null;
}
}
final CacheableBitmapDrawable fResult = result;
((Activity) context).runOnUiThread(new Runnable() {
@Override
public void run() {
try {
final ImageView iv = mImageViewRef.get();
if (null != iv && iv.getVisibility() != View.GONE) {
iv.setImageDrawable(fResult);
Animation fadeInAnimation = AnimationUtils.loadAnimation(context, R.anim.fade_in);
iv.startAnimation(fadeInAnimation);
}
} catch (Exception e) {
e.printStackTrace();
}
}
});
} catch (IOException e) {
Log.e("ImageUrlAsyncTask", e.toString());
} catch (OutOfMemoryError e) {
Log.v("ImageUrlAsyncTask", "Out of memory error here");
} catch (Exception e) {
// something else
e.printStackTrace();
}
}
});
imageDownload.setPriority(8);
imageDownload.start();
}
use of java.lang.ref.WeakReference in project Klyph by jonathangerbaud.
the class FriendRequestService method onCreate.
@Override
public void onCreate() {
HandlerThread thread = new HandlerThread("ServiceStartArguments", android.os.Process.THREAD_PRIORITY_BACKGROUND);
thread.start();
mServiceLooper = thread.getLooper();
mServiceHandler = new ServiceHandler(mServiceLooper, new WeakReference<Service>(this));
}
use of java.lang.ref.WeakReference in project Klyph by jonathangerbaud.
the class NotificationService method onCreate.
@Override
public void onCreate() {
// Why initialize device values ?
// Because we need the density to calculate image size
// In notification request
KlyphDevice.initDeviceValues(this);
HandlerThread thread = new HandlerThread("ServiceStartArguments", android.os.Process.THREAD_PRIORITY_BACKGROUND);
thread.start();
mServiceLooper = thread.getLooper();
mServiceHandler = new ServiceHandler(mServiceLooper, new WeakReference<Service>(this));
}
use of java.lang.ref.WeakReference in project Klyph by jonathangerbaud.
the class UploadPhotoService method onCreate.
@Override
public void onCreate() {
HandlerThread thread = new HandlerThread("ServiceStartArguments", android.os.Process.THREAD_PRIORITY_BACKGROUND);
thread.start();
mServiceLooper = thread.getLooper();
mServiceHandler = new ServiceHandler(mServiceLooper, new WeakReference<Service>(this));
}
Aggregations