本文整理匯總了Java中com.facebook.common.references.CloseableReference.get方法的典型用法代碼示例。如果您正苦於以下問題:Java CloseableReference.get方法的具體用法?Java CloseableReference.get怎麽用?Java CloseableReference.get使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類com.facebook.common.references.CloseableReference
的用法示例。
在下文中一共展示了CloseableReference.get方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: createDrawable
import com.facebook.common.references.CloseableReference; //導入方法依賴的package包/類
@Override
protected Drawable createDrawable(CloseableReference<CloseableImage> image) {
Preconditions.checkState(CloseableReference.isValid(image));
CloseableImage closeableImage = image.get();
maybeUpdateDebugOverlay(closeableImage);
Drawable drawable = maybeCreateDrawableFromFactories(mCustomDrawableFactories, closeableImage);
if (drawable != null) {
return drawable;
}
drawable = maybeCreateDrawableFromFactories(mGlobalDrawableFactories, closeableImage);
if (drawable != null) {
return drawable;
}
drawable = mDefaultDrawableFactory.createDrawable(closeableImage);
if (drawable != null) {
return drawable;
}
throw new UnsupportedOperationException("Unrecognized image class: " + closeableImage);
}
示例2: convertToBitmapReferenceAndClose
import com.facebook.common.references.CloseableReference; //導入方法依賴的package包/類
/**
* Converts the given image reference to a bitmap reference
* and closes the original image reference.
*
* @param closeableImage the image to convert. It will be closed afterwards and will be invalid
* @return the closeable bitmap reference to be used
*/
@VisibleForTesting
@Nullable
static CloseableReference<Bitmap> convertToBitmapReferenceAndClose(
final @Nullable CloseableReference<CloseableImage> closeableImage) {
try {
if (CloseableReference.isValid(closeableImage) &&
closeableImage.get() instanceof CloseableStaticBitmap) {
CloseableStaticBitmap closeableStaticBitmap = (CloseableStaticBitmap) closeableImage.get();
if (closeableStaticBitmap != null) {
// We return a clone of the underlying bitmap reference that has to be manually closed
// and then close the passed CloseableStaticBitmap in order to preserve correct
// cache size calculations.
return closeableStaticBitmap.cloneUnderlyingBitmapReference();
}
}
// Not a bitmap reference, so we return null
return null;
} finally {
CloseableReference.closeSafely(closeableImage);
}
}
示例3: decodeGif
import com.facebook.common.references.CloseableReference; //導入方法依賴的package包/類
/**
* Decodes a GIF into a CloseableImage.
* @param encodedImage encoded image (native byte array holding the encoded bytes and meta data)
* @param options the options for the decode
* @param bitmapConfig the Bitmap.Config used to generate the output bitmaps
* @return a {@link CloseableImage} for the GIF image
*/
public CloseableImage decodeGif(
final EncodedImage encodedImage,
final ImageDecodeOptions options,
final Bitmap.Config bitmapConfig) {
if (sGifAnimatedImageDecoder == null) {
throw new UnsupportedOperationException("To encode animated gif please add the dependency " +
"to the animated-gif module");
}
final CloseableReference<PooledByteBuffer> bytesRef = encodedImage.getByteBufferRef();
Preconditions.checkNotNull(bytesRef);
try {
final PooledByteBuffer input = bytesRef.get();
AnimatedImage gifImage = sGifAnimatedImageDecoder.decode(input.getNativePtr(), input.size());
return getCloseableImage(options, gifImage, bitmapConfig);
} finally {
CloseableReference.closeSafely(bytesRef);
}
}
示例4: decodeWebP
import com.facebook.common.references.CloseableReference; //導入方法依賴的package包/類
/**
* Decode a WebP into a CloseableImage.
* @param encodedImage encoded image (native byte array holding the encoded bytes and meta data)
* @param options the options for the decode
* @param bitmapConfig the Bitmap.Config used to generate the output bitmaps
* @return a {@link CloseableImage} for the WebP image
*/
public CloseableImage decodeWebP(
final EncodedImage encodedImage,
final ImageDecodeOptions options,
final Bitmap.Config bitmapConfig) {
if (sWebpAnimatedImageDecoder == null) {
throw new UnsupportedOperationException("To encode animated webp please add the dependency " +
"to the animated-webp module");
}
final CloseableReference<PooledByteBuffer> bytesRef = encodedImage.getByteBufferRef();
Preconditions.checkNotNull(bytesRef);
try {
final PooledByteBuffer input = bytesRef.get();
AnimatedImage webPImage = sWebpAnimatedImageDecoder.decode(
input.getNativePtr(),
input.size());
return getCloseableImage(options, webPImage, bitmapConfig);
} finally {
CloseableReference.closeSafely(bytesRef);
}
}
示例5: createBitmap
import com.facebook.common.references.CloseableReference; //導入方法依賴的package包/類
/**
* Creates a bitmap with the specified width and height. Its initial density is
* determined from the given DisplayMetrics.
*
* @param display Display metrics for the display this bitmap will be drawn on
* @param colors The colors to write to the bitmap
* @param offset The index of the first color to read from colors[]
* @param stride The number of colors in pixels[] to skip between rows.
* @param width The width of the bitmap
* @param height The height of the bitmap
* @param config The bitmap config to create
* @param callerContext the Tag to track who create the Bitmap
* @return a reference to the bitmap
* @throws IllegalArgumentException if the width or height are <= 0
* @throws TooManyBitmapsException if the pool is full
* @throws java.lang.OutOfMemoryError if the Bitmap cannot be allocated
*/
public CloseableReference<Bitmap> createBitmap(
DisplayMetrics display,
int[] colors,
int offset,
int stride,
int width,
int height,
Bitmap.Config config,
@Nullable Object callerContext) {
CloseableReference<Bitmap> bitmapRef = createBitmap(
display,
width,
height,
config,
callerContext);
Bitmap bitmap = bitmapRef.get();
bitmap.setPixels(colors, offset, stride, 0, 0, width, height);
return bitmapRef;
}
示例6: getInputStream
import com.facebook.common.references.CloseableReference; //導入方法依賴的package包/類
/**
* Returns an InputStream from the internal InputStream Supplier if it's not null. Otherwise
* returns an InputStream for the internal buffer reference if valid and null otherwise.
*
* <p>The caller has to close the InputStream after using it.
*/
public InputStream getInputStream() {
if (mInputStreamSupplier != null) {
return mInputStreamSupplier.get();
}
CloseableReference<PooledByteBuffer> pooledByteBufferRef =
CloseableReference.cloneOrNull(mPooledByteBufferRef);
if (pooledByteBufferRef != null) {
try {
return new PooledByteBufferInputStream(pooledByteBufferRef.get());
} finally {
CloseableReference.closeSafely(pooledByteBufferRef);
}
}
return null;
}
示例7: getFirstBytesAsHexString
import com.facebook.common.references.CloseableReference; //導入方法依賴的package包/類
/**
* Returns first n bytes of encoded image as hexbytes
*
* @param length the number of bytes to return
*/
public String getFirstBytesAsHexString(int length) {
CloseableReference<PooledByteBuffer> imageBuffer = getByteBufferRef();
if (imageBuffer == null) {
return "";
}
int imageSize = getSize();
int resultSampleSize = Math.min(imageSize, length);
byte[] bytesBuffer = new byte[resultSampleSize];
try {
PooledByteBuffer pooledByteBuffer = imageBuffer.get();
if (pooledByteBuffer == null) {
return "";
}
pooledByteBuffer.read(0, bytesBuffer, 0, resultSampleSize);
} finally {
imageBuffer.close();
}
StringBuilder stringBuilder = new StringBuilder(bytesBuffer.length * 2);
for (byte b : bytesBuffer) {
stringBuilder.append(String.format("%02X", b));
}
return stringBuilder.toString();
}
示例8: decodeByteArrayAsPurgeable
import com.facebook.common.references.CloseableReference; //導入方法依賴的package包/類
/**
* Decodes a byteArray into a purgeable bitmap
*
* @param bytesRef the byte buffer that contains the encoded bytes
* @return
*/
@Override
protected Bitmap decodeByteArrayAsPurgeable(
CloseableReference<PooledByteBuffer> bytesRef,
BitmapFactory.Options options) {
final PooledByteBuffer pooledByteBuffer = bytesRef.get();
final int length = pooledByteBuffer.size();
final CloseableReference<byte[]> encodedBytesArrayRef = mFlexByteArrayPool.get(length);
try {
final byte[] encodedBytesArray = encodedBytesArrayRef.get();
pooledByteBuffer.read(0, encodedBytesArray, 0, length);
Bitmap bitmap = BitmapFactory.decodeByteArray(
encodedBytesArray,
0,
length,
options);
return Preconditions.checkNotNull(bitmap, "BitmapFactory returned null");
} finally {
CloseableReference.closeSafely(encodedBytesArrayRef);
}
}
示例9: process
import com.facebook.common.references.CloseableReference; //導入方法依賴的package包/類
@Override
public CloseableReference<Bitmap> process(
Bitmap sourceBitmap,
PlatformBitmapFactory bitmapFactory) {
final CloseableReference<Bitmap> bitmapRef = bitmapFactory.createBitmap(
sourceBitmap.getWidth() / SCALE_RATIO,
sourceBitmap.getHeight() / SCALE_RATIO);
try {
final Bitmap destBitmap = bitmapRef.get();
final Canvas canvas = new Canvas(destBitmap);
canvas.drawBitmap(
sourceBitmap,
null,
new Rect(0, 0, destBitmap.getWidth(), destBitmap.getHeight()),
mPaint);
NativeBlurFilter.iterativeBoxBlur(destBitmap, mIterations, mBlurRadius / SCALE_RATIO);
return CloseableReference.cloneOrNull(bitmapRef);
} finally {
CloseableReference.closeSafely(bitmapRef);
}
}
示例10: remove
import com.facebook.common.references.CloseableReference; //導入方法依賴的package包/類
/**
* Removes key-value from the StagingArea. Both key and value must match.
* @param key
* @param encodedImage value corresponding to key
* @return true if item was removed
*/
public synchronized boolean remove(final CacheKey key, final EncodedImage encodedImage) {
Preconditions.checkNotNull(key);
Preconditions.checkNotNull(encodedImage);
Preconditions.checkArgument(EncodedImage.isValid(encodedImage));
final EncodedImage oldValue = mMap.get(key);
if (oldValue == null) {
return false;
}
CloseableReference<PooledByteBuffer> oldRef = oldValue.getByteBufferRef();
CloseableReference<PooledByteBuffer> ref = encodedImage.getByteBufferRef();
try {
if (oldRef == null || ref == null || oldRef.get() != ref.get()) {
return false;
}
mMap.remove(key);
} finally {
CloseableReference.closeSafely(ref);
CloseableReference.closeSafely(oldRef);
EncodedImage.closeSafely(oldValue);
}
logStats();
return true;
}
示例11: internalPrepareBitmap
import com.facebook.common.references.CloseableReference; //導入方法依賴的package包/類
private void internalPrepareBitmap(CloseableReference<CloseableImage> newResult) {
if (newResult == null || !newResult.isValid()) {
return;
}
final CloseableImage closeableImage = newResult.get();
if (closeableImage == null || closeableImage.isClosed()) {
return;
}
if (closeableImage instanceof CloseableStaticBitmap) {
final CloseableStaticBitmap staticBitmap = (CloseableStaticBitmap) closeableImage;
final Bitmap bitmap = staticBitmap.getUnderlyingBitmap();
if (bitmap == null) {
return;
}
final int bitmapByteCount = bitmap.getRowBytes() * bitmap.getHeight();
if (bitmapByteCount < mMinBitmapSizeBytes) {
return;
}
if (bitmapByteCount > mMaxBitmapSizeBytes) {
return;
}
bitmap.prepareToDraw();
}
}
示例12: testGet_Realloc
import com.facebook.common.references.CloseableReference; //導入方法依賴的package包/類
@Test
public void testGet_Realloc() {
CloseableReference<byte[]> arrayRef = mArray.get(1);
final byte[] smallArray = arrayRef.get();
arrayRef.close();
arrayRef = mArray.get(7);
assertEquals(8, arrayRef.get().length);
assertSame(mArray.mByteArraySoftRef.get(), arrayRef.get());
assertNotSame(smallArray, arrayRef.get());
}
示例13: testGet_Realloc
import com.facebook.common.references.CloseableReference; //導入方法依賴的package包/類
@Test
public void testGet_Realloc() {
CloseableReference<byte[]> arrayRef = mPool.get(1);
final byte[] smallArray = arrayRef.get();
arrayRef.close();
arrayRef = mPool.get(7);
assertEquals(8, arrayRef.get().length);
assertNotSame(smallArray, arrayRef.get());
}
示例14: getImageInfo
import com.facebook.common.references.CloseableReference; //導入方法依賴的package包/類
@Override
protected ImageInfo getImageInfo(CloseableReference<CloseableImage> image) {
Preconditions.checkState(CloseableReference.isValid(image));
return image.get();
}
示例15: onNewResult
import com.facebook.common.references.CloseableReference; //導入方法依賴的package包/類
@Override
public void onNewResult(DataSource<CloseableReference<CloseableImage>> dataSource) {
if (!dataSource.isFinished()) {
// only interested in final image, no need to close the dataSource
return;
}
try {
if (mDataSource != dataSource) {
// Shouldn't ever happen, but let's be safe (dataSource got closed by callback still fired?)
return;
}
mDataSource = null;
CloseableReference<CloseableImage> imageReference = dataSource.getResult();
if (imageReference == null) {
// Shouldn't ever happen, but let's be safe (dataSource got closed by callback still fired?)
return;
}
CloseableImage image = imageReference.get();
if (!(image instanceof CloseableBitmap)) {
// only bitmaps are supported
imageReference.close();
return;
}
mImageRef = imageReference;
Bitmap bitmap = getBitmap();
if (bitmap == null) {
// Shouldn't ever happen, but let's be safe.
return;
}
BitmapUpdateListener listener = Assertions.assumeNotNull(mBitmapUpdateListener);
listener.onBitmapReady(bitmap);
listener.onImageLoadEvent(ImageLoadEvent.ON_LOAD);
listener.onImageLoadEvent(ImageLoadEvent.ON_LOAD_END);
} finally {
dataSource.close();
}
}