Search in sources :

Example 76 with WeakReference

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;
}
Also used : Bundle(android.os.Bundle) WeakReference(java.lang.ref.WeakReference)

Example 77 with WeakReference

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;
}
Also used : ThemeKey(android.content.res.Resources.ThemeKey) WeakReference(java.lang.ref.WeakReference) Nullable(android.annotation.Nullable)

Example 78 with WeakReference

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);
    }
}
Also used : Message(android.os.Message) WeakReference(java.lang.ref.WeakReference)

Example 79 with WeakReference

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);
    }
}
Also used : WeakReference(java.lang.ref.WeakReference) Handler(android.os.Handler)

Example 80 with WeakReference

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);
    }
}
Also used : WeakReference(java.lang.ref.WeakReference) Handler(android.os.Handler)

Aggregations

WeakReference (java.lang.ref.WeakReference)291 ArrayList (java.util.ArrayList)32 HashMap (java.util.HashMap)24 Map (java.util.Map)24 Field (java.lang.reflect.Field)19 Activity (android.app.Activity)17 Iterator (java.util.Iterator)17 IOException (java.io.IOException)16 Method (java.lang.reflect.Method)15 File (java.io.File)14 URLClassLoader (java.net.URLClassLoader)14 Test (org.junit.Test)13 Reference (java.lang.ref.Reference)12 ReferenceQueue (java.lang.ref.ReferenceQueue)12 Resources (android.content.res.Resources)10 Handler (android.os.Handler)10 AbstractModule (com.google.inject.AbstractModule)10 Injector (com.google.inject.Injector)10 ArrayMap (android.util.ArrayMap)9 URL (java.net.URL)8