use of java.lang.ref.WeakReference in project Android-Image-Cropper by ArthurHub.
the class CropImageView method onSaveInstanceState.
@Override
public Parcelable onSaveInstanceState() {
Bundle bundle = new Bundle();
bundle.putParcelable("instanceState", super.onSaveInstanceState());
bundle.putParcelable("LOADED_IMAGE_URI", mLoadedImageUri);
bundle.putInt("LOADED_IMAGE_RESOURCE", mImageResource);
if (mLoadedImageUri == null && mImageResource < 1) {
bundle.putParcelable("SET_BITMAP", mBitmap);
}
if (mLoadedImageUri != null && mBitmap != null) {
String key = UUID.randomUUID().toString();
BitmapUtils.mStateBitmap = new Pair<>(key, new WeakReference<>(mBitmap));
bundle.putString("LOADED_IMAGE_STATE_BITMAP_KEY", key);
}
if (mBitmapLoadingWorkerTask != null) {
BitmapLoadingWorkerTask task = mBitmapLoadingWorkerTask.get();
if (task != null) {
bundle.putParcelable("LOADING_IMAGE_URI", task.getUri());
}
}
bundle.putInt("LOADED_SAMPLE_SIZE", mLoadedSampleSize);
bundle.putInt("DEGREES_ROTATED", mDegreesRotated);
bundle.putParcelable("INITIAL_CROP_RECT", mCropOverlayView.getInitialCropWindowRect());
BitmapUtils.RECT.set(mCropOverlayView.getCropWindowRect());
mImageMatrix.invert(mImageInverseMatrix);
mImageInverseMatrix.mapRect(BitmapUtils.RECT);
bundle.putParcelable("CROP_WINDOW_RECT", BitmapUtils.RECT);
bundle.putString("CROP_SHAPE", mCropOverlayView.getCropShape().name());
bundle.putBoolean("CROP_AUTO_ZOOM_ENABLED", mAutoZoomEnabled);
bundle.putInt("CROP_MAX_ZOOM", mMaxZoom);
return bundle;
}
use of java.lang.ref.WeakReference in project android_frameworks_base by DirtyUnicorns.
the class ThemedResourceCache method getThemedLocked.
/**
* Returns the cached data for the specified theme, optionally creating a
* new entry if one does not already exist.
*
* @param t the theme for which to return cached data
* @param create {@code true} to create an entry if one does not already
* exist, {@code false} otherwise
* @return the cached data for the theme, or {@code null} if the cache is
* empty and {@code create} was {@code false}
*/
@Nullable
private LongSparseArray<WeakReference<T>> getThemedLocked(@Nullable Theme t, boolean create) {
if (t == null) {
if (mNullThemedEntries == null && create) {
mNullThemedEntries = new LongSparseArray<>(1);
}
return mNullThemedEntries;
}
if (mThemedEntries == null) {
if (create) {
mThemedEntries = new ArrayMap<>(1);
} else {
return null;
}
}
final ThemeKey key = t.getKey();
LongSparseArray<WeakReference<T>> cache = mThemedEntries.get(key);
if (cache == null && create) {
cache = new LongSparseArray<>(1);
final ThemeKey keyClone = key.clone();
mThemedEntries.put(keyClone, cache);
}
return cache;
}
use of java.lang.ref.WeakReference in project android_frameworks_base by DirtyUnicorns.
the class SoundPool method postEventFromNative.
// post event from native code to message handler
@SuppressWarnings("unchecked")
private static void postEventFromNative(Object ref, int msg, int arg1, int arg2, Object obj) {
SoundPool soundPool = ((WeakReference<SoundPool>) ref).get();
if (soundPool == null)
return;
if (soundPool.mEventHandler != null) {
Message m = soundPool.mEventHandler.obtainMessage(msg, arg1, arg2, obj);
soundPool.mEventHandler.sendMessage(m);
}
}
use of java.lang.ref.WeakReference in project android_frameworks_base by DirtyUnicorns.
the class ImageReader method postEventFromNative.
/**
* Called from Native code when an Event happens.
*
* This may be called from an arbitrary Binder thread, so access to the ImageReader must be
* synchronized appropriately.
*/
private static void postEventFromNative(Object selfRef) {
@SuppressWarnings("unchecked") WeakReference<ImageReader> weakSelf = (WeakReference<ImageReader>) selfRef;
final ImageReader ir = weakSelf.get();
if (ir == null) {
return;
}
final Handler handler;
synchronized (ir.mListenerLock) {
handler = ir.mListenerHandler;
}
if (handler != null) {
handler.sendEmptyMessage(0);
}
}
use of java.lang.ref.WeakReference in project android_frameworks_base by DirtyUnicorns.
the class ImageWriter method postEventFromNative.
/**
* Called from Native code when an Event happens. This may be called from an
* arbitrary Binder thread, so access to the ImageWriter must be
* synchronized appropriately.
*/
private static void postEventFromNative(Object selfRef) {
@SuppressWarnings("unchecked") WeakReference<ImageWriter> weakSelf = (WeakReference<ImageWriter>) selfRef;
final ImageWriter iw = weakSelf.get();
if (iw == null) {
return;
}
final Handler handler;
synchronized (iw.mListenerLock) {
handler = iw.mListenerHandler;
}
if (handler != null) {
handler.sendEmptyMessage(0);
}
}
Aggregations