id
int32
0
165k
repo
stringlengths
7
58
path
stringlengths
12
218
func_name
stringlengths
3
140
original_string
stringlengths
73
34.1k
language
stringclasses
1 value
code
stringlengths
73
34.1k
code_tokens
list
docstring
stringlengths
3
16k
docstring_tokens
list
sha
stringlengths
40
40
url
stringlengths
105
339
14,500
facebook/fresco
samples/comparison/src/main/java/com/facebook/samples/comparison/urlsfetcher/ImageUrlsFetcher.java
ImageUrlsFetcher.readAsString
private static String readAsString(InputStream stream) throws IOException { StringWriter writer = new StringWriter(); Reader reader = new BufferedReader(new InputStreamReader(stream, "UTF-8")); while (true) { int c = reader.read(); if (c < 0) { break; } writer.write(c); } return writer.toString(); }
java
private static String readAsString(InputStream stream) throws IOException { StringWriter writer = new StringWriter(); Reader reader = new BufferedReader(new InputStreamReader(stream, "UTF-8")); while (true) { int c = reader.read(); if (c < 0) { break; } writer.write(c); } return writer.toString(); }
[ "private", "static", "String", "readAsString", "(", "InputStream", "stream", ")", "throws", "IOException", "{", "StringWriter", "writer", "=", "new", "StringWriter", "(", ")", ";", "Reader", "reader", "=", "new", "BufferedReader", "(", "new", "InputStreamReader", "(", "stream", ",", "\"UTF-8\"", ")", ")", ";", "while", "(", "true", ")", "{", "int", "c", "=", "reader", ".", "read", "(", ")", ";", "if", "(", "c", "<", "0", ")", "{", "break", ";", "}", "writer", ".", "write", "(", "c", ")", ";", "}", "return", "writer", ".", "toString", "(", ")", ";", "}" ]
Reads an InputStream and converts it to a String.
[ "Reads", "an", "InputStream", "and", "converts", "it", "to", "a", "String", "." ]
0b85879d51c5036d5e46e627a6651afefc0b971a
https://github.com/facebook/fresco/blob/0b85879d51c5036d5e46e627a6651afefc0b971a/samples/comparison/src/main/java/com/facebook/samples/comparison/urlsfetcher/ImageUrlsFetcher.java#L121-L132
14,501
facebook/fresco
imagepipeline/src/main/java/com/facebook/imagepipeline/memory/SharedByteArray.java
SharedByteArray.get
public CloseableReference<byte[]> get(int size) { Preconditions.checkArgument(size > 0, "Size must be greater than zero"); Preconditions.checkArgument(size <= mMaxByteArraySize, "Requested size is too big"); mSemaphore.acquireUninterruptibly(); try { byte[] byteArray = getByteArray(size); return CloseableReference.of(byteArray, mResourceReleaser); } catch (Throwable t) { mSemaphore.release(); throw Throwables.propagate(t); } }
java
public CloseableReference<byte[]> get(int size) { Preconditions.checkArgument(size > 0, "Size must be greater than zero"); Preconditions.checkArgument(size <= mMaxByteArraySize, "Requested size is too big"); mSemaphore.acquireUninterruptibly(); try { byte[] byteArray = getByteArray(size); return CloseableReference.of(byteArray, mResourceReleaser); } catch (Throwable t) { mSemaphore.release(); throw Throwables.propagate(t); } }
[ "public", "CloseableReference", "<", "byte", "[", "]", ">", "get", "(", "int", "size", ")", "{", "Preconditions", ".", "checkArgument", "(", "size", ">", "0", ",", "\"Size must be greater than zero\"", ")", ";", "Preconditions", ".", "checkArgument", "(", "size", "<=", "mMaxByteArraySize", ",", "\"Requested size is too big\"", ")", ";", "mSemaphore", ".", "acquireUninterruptibly", "(", ")", ";", "try", "{", "byte", "[", "]", "byteArray", "=", "getByteArray", "(", "size", ")", ";", "return", "CloseableReference", ".", "of", "(", "byteArray", ",", "mResourceReleaser", ")", ";", "}", "catch", "(", "Throwable", "t", ")", "{", "mSemaphore", ".", "release", "(", ")", ";", "throw", "Throwables", ".", "propagate", "(", "t", ")", ";", "}", "}" ]
Get exclusive access to the byte array of size greater or equal to the passed one. <p> Under the hood this method acquires an exclusive lock that is released when the returned reference is closed.
[ "Get", "exclusive", "access", "to", "the", "byte", "array", "of", "size", "greater", "or", "equal", "to", "the", "passed", "one", "." ]
0b85879d51c5036d5e46e627a6651afefc0b971a
https://github.com/facebook/fresco/blob/0b85879d51c5036d5e46e627a6651afefc0b971a/imagepipeline/src/main/java/com/facebook/imagepipeline/memory/SharedByteArray.java#L86-L97
14,502
facebook/fresco
imagepipeline/src/main/java/com/facebook/imagepipeline/memory/SharedByteArray.java
SharedByteArray.trim
@Override public void trim(MemoryTrimType trimType) { if (!mSemaphore.tryAcquire()) { return; } try { mByteArraySoftRef.clear(); } finally { mSemaphore.release(); } }
java
@Override public void trim(MemoryTrimType trimType) { if (!mSemaphore.tryAcquire()) { return; } try { mByteArraySoftRef.clear(); } finally { mSemaphore.release(); } }
[ "@", "Override", "public", "void", "trim", "(", "MemoryTrimType", "trimType", ")", "{", "if", "(", "!", "mSemaphore", ".", "tryAcquire", "(", ")", ")", "{", "return", ";", "}", "try", "{", "mByteArraySoftRef", ".", "clear", "(", ")", ";", "}", "finally", "{", "mSemaphore", ".", "release", "(", ")", ";", "}", "}" ]
Responds to memory pressure by simply 'discarding' the local byte array if it is not used at the moment. @param trimType kind of trimming to perform (ignored)
[ "Responds", "to", "memory", "pressure", "by", "simply", "discarding", "the", "local", "byte", "array", "if", "it", "is", "not", "used", "at", "the", "moment", "." ]
0b85879d51c5036d5e46e627a6651afefc0b971a
https://github.com/facebook/fresco/blob/0b85879d51c5036d5e46e627a6651afefc0b971a/imagepipeline/src/main/java/com/facebook/imagepipeline/memory/SharedByteArray.java#L114-L124
14,503
facebook/fresco
drawee/src/main/java/com/facebook/drawee/drawable/ProgressBarDrawable.java
ProgressBarDrawable.getPadding
@Override public boolean getPadding(Rect padding) { padding.set(mPadding, mPadding, mPadding, mPadding); return mPadding != 0; }
java
@Override public boolean getPadding(Rect padding) { padding.set(mPadding, mPadding, mPadding, mPadding); return mPadding != 0; }
[ "@", "Override", "public", "boolean", "getPadding", "(", "Rect", "padding", ")", "{", "padding", ".", "set", "(", "mPadding", ",", "mPadding", ",", "mPadding", ",", "mPadding", ")", ";", "return", "mPadding", "!=", "0", ";", "}" ]
Gets the progress bar padding.
[ "Gets", "the", "progress", "bar", "padding", "." ]
0b85879d51c5036d5e46e627a6651afefc0b971a
https://github.com/facebook/fresco/blob/0b85879d51c5036d5e46e627a6651afefc0b971a/drawee/src/main/java/com/facebook/drawee/drawable/ProgressBarDrawable.java#L70-L74
14,504
facebook/fresco
samples/scrollperf/src/main/java/com/facebook/samples/scrollperf/util/UI.java
UI.findViewById
public static <T extends View> T findViewById(Activity act, int viewId) { View containerView = act.getWindow().getDecorView(); return findViewById(containerView, viewId); }
java
public static <T extends View> T findViewById(Activity act, int viewId) { View containerView = act.getWindow().getDecorView(); return findViewById(containerView, viewId); }
[ "public", "static", "<", "T", "extends", "View", ">", "T", "findViewById", "(", "Activity", "act", ",", "int", "viewId", ")", "{", "View", "containerView", "=", "act", ".", "getWindow", "(", ")", ".", "getDecorView", "(", ")", ";", "return", "findViewById", "(", "containerView", ",", "viewId", ")", ";", "}" ]
This method returns the reference of the View with the given Id in the layout of the Activity passed as parameter @param act The Activity that is using the layout with the given View @param viewId The id of the View we want to get a reference @return The View with the given id and type
[ "This", "method", "returns", "the", "reference", "of", "the", "View", "with", "the", "given", "Id", "in", "the", "layout", "of", "the", "Activity", "passed", "as", "parameter" ]
0b85879d51c5036d5e46e627a6651afefc0b971a
https://github.com/facebook/fresco/blob/0b85879d51c5036d5e46e627a6651afefc0b971a/samples/scrollperf/src/main/java/com/facebook/samples/scrollperf/util/UI.java#L30-L33
14,505
facebook/fresco
samples/scrollperf/src/main/java/com/facebook/samples/scrollperf/util/UI.java
UI.findViewById
@SuppressWarnings("unchecked") public static <T extends View> T findViewById(View containerView, int viewId) { View foundView = containerView.findViewById(viewId); return (T) foundView; }
java
@SuppressWarnings("unchecked") public static <T extends View> T findViewById(View containerView, int viewId) { View foundView = containerView.findViewById(viewId); return (T) foundView; }
[ "@", "SuppressWarnings", "(", "\"unchecked\"", ")", "public", "static", "<", "T", "extends", "View", ">", "T", "findViewById", "(", "View", "containerView", ",", "int", "viewId", ")", "{", "View", "foundView", "=", "containerView", ".", "findViewById", "(", "viewId", ")", ";", "return", "(", "T", ")", "foundView", ";", "}" ]
This method returns the reference of the View with the given Id in the view passed as parameter @param containerView The container View @param viewId The id of the View we want to get a reference @return The View with the given id and type
[ "This", "method", "returns", "the", "reference", "of", "the", "View", "with", "the", "given", "Id", "in", "the", "view", "passed", "as", "parameter" ]
0b85879d51c5036d5e46e627a6651afefc0b971a
https://github.com/facebook/fresco/blob/0b85879d51c5036d5e46e627a6651afefc0b971a/samples/scrollperf/src/main/java/com/facebook/samples/scrollperf/util/UI.java#L43-L47
14,506
facebook/fresco
drawee/src/main/java/com/facebook/drawee/drawable/FadeDrawable.java
FadeDrawable.resetInternal
private void resetInternal() { mTransitionState = TRANSITION_NONE; Arrays.fill(mStartAlphas, mDefaultLayerAlpha); mStartAlphas[0] = 255; Arrays.fill(mAlphas, mDefaultLayerAlpha); mAlphas[0] = 255; Arrays.fill(mIsLayerOn, mDefaultLayerIsOn); mIsLayerOn[0] = true; }
java
private void resetInternal() { mTransitionState = TRANSITION_NONE; Arrays.fill(mStartAlphas, mDefaultLayerAlpha); mStartAlphas[0] = 255; Arrays.fill(mAlphas, mDefaultLayerAlpha); mAlphas[0] = 255; Arrays.fill(mIsLayerOn, mDefaultLayerIsOn); mIsLayerOn[0] = true; }
[ "private", "void", "resetInternal", "(", ")", "{", "mTransitionState", "=", "TRANSITION_NONE", ";", "Arrays", ".", "fill", "(", "mStartAlphas", ",", "mDefaultLayerAlpha", ")", ";", "mStartAlphas", "[", "0", "]", "=", "255", ";", "Arrays", ".", "fill", "(", "mAlphas", ",", "mDefaultLayerAlpha", ")", ";", "mAlphas", "[", "0", "]", "=", "255", ";", "Arrays", ".", "fill", "(", "mIsLayerOn", ",", "mDefaultLayerIsOn", ")", ";", "mIsLayerOn", "[", "0", "]", "=", "true", ";", "}" ]
Resets internal state to the initial state.
[ "Resets", "internal", "state", "to", "the", "initial", "state", "." ]
0b85879d51c5036d5e46e627a6651afefc0b971a
https://github.com/facebook/fresco/blob/0b85879d51c5036d5e46e627a6651afefc0b971a/drawee/src/main/java/com/facebook/drawee/drawable/FadeDrawable.java#L154-L162
14,507
facebook/fresco
drawee/src/main/java/com/facebook/drawee/drawable/FadeDrawable.java
FadeDrawable.fadeToLayer
public void fadeToLayer(int index) { mTransitionState = TRANSITION_STARTING; Arrays.fill(mIsLayerOn, false); mIsLayerOn[index] = true; invalidateSelf(); }
java
public void fadeToLayer(int index) { mTransitionState = TRANSITION_STARTING; Arrays.fill(mIsLayerOn, false); mIsLayerOn[index] = true; invalidateSelf(); }
[ "public", "void", "fadeToLayer", "(", "int", "index", ")", "{", "mTransitionState", "=", "TRANSITION_STARTING", ";", "Arrays", ".", "fill", "(", "mIsLayerOn", ",", "false", ")", ";", "mIsLayerOn", "[", "index", "]", "=", "true", ";", "invalidateSelf", "(", ")", ";", "}" ]
Starts fading to the specified layer. @param index the index of the layer to fade to
[ "Starts", "fading", "to", "the", "specified", "layer", "." ]
0b85879d51c5036d5e46e627a6651afefc0b971a
https://github.com/facebook/fresco/blob/0b85879d51c5036d5e46e627a6651afefc0b971a/drawee/src/main/java/com/facebook/drawee/drawable/FadeDrawable.java#L214-L219
14,508
facebook/fresco
drawee/src/main/java/com/facebook/drawee/drawable/FadeDrawable.java
FadeDrawable.finishTransitionImmediately
public void finishTransitionImmediately() { mTransitionState = TRANSITION_NONE; for (int i = 0; i < mLayers.length; i++) { mAlphas[i] = mIsLayerOn[i] ? 255 : 0; } invalidateSelf(); }
java
public void finishTransitionImmediately() { mTransitionState = TRANSITION_NONE; for (int i = 0; i < mLayers.length; i++) { mAlphas[i] = mIsLayerOn[i] ? 255 : 0; } invalidateSelf(); }
[ "public", "void", "finishTransitionImmediately", "(", ")", "{", "mTransitionState", "=", "TRANSITION_NONE", ";", "for", "(", "int", "i", "=", "0", ";", "i", "<", "mLayers", ".", "length", ";", "i", "++", ")", "{", "mAlphas", "[", "i", "]", "=", "mIsLayerOn", "[", "i", "]", "?", "255", ":", "0", ";", "}", "invalidateSelf", "(", ")", ";", "}" ]
Finishes transition immediately.
[ "Finishes", "transition", "immediately", "." ]
0b85879d51c5036d5e46e627a6651afefc0b971a
https://github.com/facebook/fresco/blob/0b85879d51c5036d5e46e627a6651afefc0b971a/drawee/src/main/java/com/facebook/drawee/drawable/FadeDrawable.java#L259-L265
14,509
facebook/fresco
drawee/src/main/java/com/facebook/drawee/drawable/FadeDrawable.java
FadeDrawable.updateAlphas
private boolean updateAlphas(float ratio) { boolean done = true; for (int i = 0; i < mLayers.length; i++) { int dir = mIsLayerOn[i] ? +1 : -1; // determines alpha value and clamps it to [0, 255] mAlphas[i] = (int) (mStartAlphas[i] + dir * 255 * ratio); if (mAlphas[i] < 0) { mAlphas[i] = 0; } if (mAlphas[i] > 255) { mAlphas[i] = 255; } // determines whether the layer has reached its target opacity if (mIsLayerOn[i] && mAlphas[i] < 255) { done = false; } if (!mIsLayerOn[i] && mAlphas[i] > 0) { done = false; } } return done; }
java
private boolean updateAlphas(float ratio) { boolean done = true; for (int i = 0; i < mLayers.length; i++) { int dir = mIsLayerOn[i] ? +1 : -1; // determines alpha value and clamps it to [0, 255] mAlphas[i] = (int) (mStartAlphas[i] + dir * 255 * ratio); if (mAlphas[i] < 0) { mAlphas[i] = 0; } if (mAlphas[i] > 255) { mAlphas[i] = 255; } // determines whether the layer has reached its target opacity if (mIsLayerOn[i] && mAlphas[i] < 255) { done = false; } if (!mIsLayerOn[i] && mAlphas[i] > 0) { done = false; } } return done; }
[ "private", "boolean", "updateAlphas", "(", "float", "ratio", ")", "{", "boolean", "done", "=", "true", ";", "for", "(", "int", "i", "=", "0", ";", "i", "<", "mLayers", ".", "length", ";", "i", "++", ")", "{", "int", "dir", "=", "mIsLayerOn", "[", "i", "]", "?", "+", "1", ":", "-", "1", ";", "// determines alpha value and clamps it to [0, 255]", "mAlphas", "[", "i", "]", "=", "(", "int", ")", "(", "mStartAlphas", "[", "i", "]", "+", "dir", "*", "255", "*", "ratio", ")", ";", "if", "(", "mAlphas", "[", "i", "]", "<", "0", ")", "{", "mAlphas", "[", "i", "]", "=", "0", ";", "}", "if", "(", "mAlphas", "[", "i", "]", ">", "255", ")", "{", "mAlphas", "[", "i", "]", "=", "255", ";", "}", "// determines whether the layer has reached its target opacity", "if", "(", "mIsLayerOn", "[", "i", "]", "&&", "mAlphas", "[", "i", "]", "<", "255", ")", "{", "done", "=", "false", ";", "}", "if", "(", "!", "mIsLayerOn", "[", "i", "]", "&&", "mAlphas", "[", "i", "]", ">", "0", ")", "{", "done", "=", "false", ";", "}", "}", "return", "done", ";", "}" ]
Updates the current alphas based on the ratio of the elapsed time and duration. @param ratio @return whether the all layers have reached their target opacity
[ "Updates", "the", "current", "alphas", "based", "on", "the", "ratio", "of", "the", "elapsed", "time", "and", "duration", "." ]
0b85879d51c5036d5e46e627a6651afefc0b971a
https://github.com/facebook/fresco/blob/0b85879d51c5036d5e46e627a6651afefc0b971a/drawee/src/main/java/com/facebook/drawee/drawable/FadeDrawable.java#L272-L293
14,510
facebook/fresco
imagepipeline/src/main/java/com/facebook/imagepipeline/filter/IterativeBoxBlurFilter.java
IterativeBoxBlurFilter.boxBlurBitmapInPlace
public static void boxBlurBitmapInPlace( final Bitmap bitmap, final int iterations, final int radius) { Preconditions.checkNotNull(bitmap); Preconditions.checkArgument(bitmap.isMutable()); Preconditions.checkArgument(bitmap.getHeight() <= BitmapUtil.MAX_BITMAP_SIZE); Preconditions.checkArgument(bitmap.getWidth() <= BitmapUtil.MAX_BITMAP_SIZE); Preconditions.checkArgument(radius > 0 && radius <= RenderScriptBlurFilter.BLUR_MAX_RADIUS); Preconditions.checkArgument(iterations > 0); try { fastBoxBlur(bitmap, iterations, radius); } catch (OutOfMemoryError oom) { FLog.e( TAG, String.format( (Locale) null, "OOM: %d iterations on %dx%d with %d radius", iterations, bitmap.getWidth(), bitmap.getHeight(), radius)); throw oom; } }
java
public static void boxBlurBitmapInPlace( final Bitmap bitmap, final int iterations, final int radius) { Preconditions.checkNotNull(bitmap); Preconditions.checkArgument(bitmap.isMutable()); Preconditions.checkArgument(bitmap.getHeight() <= BitmapUtil.MAX_BITMAP_SIZE); Preconditions.checkArgument(bitmap.getWidth() <= BitmapUtil.MAX_BITMAP_SIZE); Preconditions.checkArgument(radius > 0 && radius <= RenderScriptBlurFilter.BLUR_MAX_RADIUS); Preconditions.checkArgument(iterations > 0); try { fastBoxBlur(bitmap, iterations, radius); } catch (OutOfMemoryError oom) { FLog.e( TAG, String.format( (Locale) null, "OOM: %d iterations on %dx%d with %d radius", iterations, bitmap.getWidth(), bitmap.getHeight(), radius)); throw oom; } }
[ "public", "static", "void", "boxBlurBitmapInPlace", "(", "final", "Bitmap", "bitmap", ",", "final", "int", "iterations", ",", "final", "int", "radius", ")", "{", "Preconditions", ".", "checkNotNull", "(", "bitmap", ")", ";", "Preconditions", ".", "checkArgument", "(", "bitmap", ".", "isMutable", "(", ")", ")", ";", "Preconditions", ".", "checkArgument", "(", "bitmap", ".", "getHeight", "(", ")", "<=", "BitmapUtil", ".", "MAX_BITMAP_SIZE", ")", ";", "Preconditions", ".", "checkArgument", "(", "bitmap", ".", "getWidth", "(", ")", "<=", "BitmapUtil", ".", "MAX_BITMAP_SIZE", ")", ";", "Preconditions", ".", "checkArgument", "(", "radius", ">", "0", "&&", "radius", "<=", "RenderScriptBlurFilter", ".", "BLUR_MAX_RADIUS", ")", ";", "Preconditions", ".", "checkArgument", "(", "iterations", ">", "0", ")", ";", "try", "{", "fastBoxBlur", "(", "bitmap", ",", "iterations", ",", "radius", ")", ";", "}", "catch", "(", "OutOfMemoryError", "oom", ")", "{", "FLog", ".", "e", "(", "TAG", ",", "String", ".", "format", "(", "(", "Locale", ")", "null", ",", "\"OOM: %d iterations on %dx%d with %d radius\"", ",", "iterations", ",", "bitmap", ".", "getWidth", "(", ")", ",", "bitmap", ".", "getHeight", "(", ")", ",", "radius", ")", ")", ";", "throw", "oom", ";", "}", "}" ]
An in-place iterative box blur algorithm that runs faster than a traditional box blur. <p>The individual box blurs are split up in vertical and horizontal direction. That allows us to use a moving average implementation for blurring individual rows and columns. <p>The runtime is: O(iterations * width * height) and therefore linear in the number of pixels <p>The required memory is: 2 * radius * 256 * 4 Bytes + max(width, height) * 4 Bytes + width * height * 4 Bytes (+constant) @param bitmap The {@link Bitmap} containing the image. The bitmap dimension need to be smaller than {@link BitmapUtil#MAX_BITMAP_SIZE} @param iterations The number of iterations of the blurring algorithm > 0. @param radius The radius of the blur with a supported range 0 < radius <= {@link RenderScriptBlurFilter#BLUR_MAX_RADIUS}
[ "An", "in", "-", "place", "iterative", "box", "blur", "algorithm", "that", "runs", "faster", "than", "a", "traditional", "box", "blur", "." ]
0b85879d51c5036d5e46e627a6651afefc0b971a
https://github.com/facebook/fresco/blob/0b85879d51c5036d5e46e627a6651afefc0b971a/imagepipeline/src/main/java/com/facebook/imagepipeline/filter/IterativeBoxBlurFilter.java#L35-L57
14,511
facebook/fresco
imagepipeline/src/main/java/com/facebook/imagepipeline/memory/BitmapCounter.java
BitmapCounter.increase
public synchronized boolean increase(Bitmap bitmap) { final int bitmapSize = BitmapUtil.getSizeInBytes(bitmap); if (mCount >= mMaxCount || mSize + bitmapSize > mMaxSize) { return false; } mCount++; mSize += bitmapSize; return true; }
java
public synchronized boolean increase(Bitmap bitmap) { final int bitmapSize = BitmapUtil.getSizeInBytes(bitmap); if (mCount >= mMaxCount || mSize + bitmapSize > mMaxSize) { return false; } mCount++; mSize += bitmapSize; return true; }
[ "public", "synchronized", "boolean", "increase", "(", "Bitmap", "bitmap", ")", "{", "final", "int", "bitmapSize", "=", "BitmapUtil", ".", "getSizeInBytes", "(", "bitmap", ")", ";", "if", "(", "mCount", ">=", "mMaxCount", "||", "mSize", "+", "bitmapSize", ">", "mMaxSize", ")", "{", "return", "false", ";", "}", "mCount", "++", ";", "mSize", "+=", "bitmapSize", ";", "return", "true", ";", "}" ]
Includes given bitmap in the bitmap count. The bitmap is included only if doing so does not violate configured limit @param bitmap to include in the count @return true if and only if bitmap is successfully included in the count
[ "Includes", "given", "bitmap", "in", "the", "bitmap", "count", ".", "The", "bitmap", "is", "included", "only", "if", "doing", "so", "does", "not", "violate", "configured", "limit" ]
0b85879d51c5036d5e46e627a6651afefc0b971a
https://github.com/facebook/fresco/blob/0b85879d51c5036d5e46e627a6651afefc0b971a/imagepipeline/src/main/java/com/facebook/imagepipeline/memory/BitmapCounter.java#L62-L70
14,512
facebook/fresco
imagepipeline/src/main/java/com/facebook/imagepipeline/memory/BitmapCounter.java
BitmapCounter.decrease
public synchronized void decrease(Bitmap bitmap) { final int bitmapSize = BitmapUtil.getSizeInBytes(bitmap); Preconditions.checkArgument(mCount > 0, "No bitmaps registered."); Preconditions.checkArgument( bitmapSize <= mSize, "Bitmap size bigger than the total registered size: %d, %d", bitmapSize, mSize); mSize -= bitmapSize; mCount--; }
java
public synchronized void decrease(Bitmap bitmap) { final int bitmapSize = BitmapUtil.getSizeInBytes(bitmap); Preconditions.checkArgument(mCount > 0, "No bitmaps registered."); Preconditions.checkArgument( bitmapSize <= mSize, "Bitmap size bigger than the total registered size: %d, %d", bitmapSize, mSize); mSize -= bitmapSize; mCount--; }
[ "public", "synchronized", "void", "decrease", "(", "Bitmap", "bitmap", ")", "{", "final", "int", "bitmapSize", "=", "BitmapUtil", ".", "getSizeInBytes", "(", "bitmap", ")", ";", "Preconditions", ".", "checkArgument", "(", "mCount", ">", "0", ",", "\"No bitmaps registered.\"", ")", ";", "Preconditions", ".", "checkArgument", "(", "bitmapSize", "<=", "mSize", ",", "\"Bitmap size bigger than the total registered size: %d, %d\"", ",", "bitmapSize", ",", "mSize", ")", ";", "mSize", "-=", "bitmapSize", ";", "mCount", "--", ";", "}" ]
Excludes given bitmap from the count. @param bitmap to be excluded from the count
[ "Excludes", "given", "bitmap", "from", "the", "count", "." ]
0b85879d51c5036d5e46e627a6651afefc0b971a
https://github.com/facebook/fresco/blob/0b85879d51c5036d5e46e627a6651afefc0b971a/imagepipeline/src/main/java/com/facebook/imagepipeline/memory/BitmapCounter.java#L77-L87
14,513
facebook/fresco
samples/scrollperf/src/main/java/com/facebook/samples/scrollperf/util/PipelineUtil.java
PipelineUtil.addOptionalFeatures
public static void addOptionalFeatures(ImageRequestBuilder imageRequestBuilder, Config config) { if (config.usePostprocessor) { final Postprocessor postprocessor; switch (config.postprocessorType) { case "use_slow_postprocessor": postprocessor = DelayPostprocessor.getMediumPostprocessor(); break; case "use_fast_postprocessor": postprocessor = DelayPostprocessor.getFastPostprocessor(); break; default: postprocessor = DelayPostprocessor.getMediumPostprocessor(); } imageRequestBuilder.setPostprocessor(postprocessor); } if (config.rotateUsingMetaData) { imageRequestBuilder.setRotationOptions(RotationOptions.autoRotateAtRenderTime()); } else { imageRequestBuilder .setRotationOptions(RotationOptions.forceRotation(config.forcedRotationAngle)); } }
java
public static void addOptionalFeatures(ImageRequestBuilder imageRequestBuilder, Config config) { if (config.usePostprocessor) { final Postprocessor postprocessor; switch (config.postprocessorType) { case "use_slow_postprocessor": postprocessor = DelayPostprocessor.getMediumPostprocessor(); break; case "use_fast_postprocessor": postprocessor = DelayPostprocessor.getFastPostprocessor(); break; default: postprocessor = DelayPostprocessor.getMediumPostprocessor(); } imageRequestBuilder.setPostprocessor(postprocessor); } if (config.rotateUsingMetaData) { imageRequestBuilder.setRotationOptions(RotationOptions.autoRotateAtRenderTime()); } else { imageRequestBuilder .setRotationOptions(RotationOptions.forceRotation(config.forcedRotationAngle)); } }
[ "public", "static", "void", "addOptionalFeatures", "(", "ImageRequestBuilder", "imageRequestBuilder", ",", "Config", "config", ")", "{", "if", "(", "config", ".", "usePostprocessor", ")", "{", "final", "Postprocessor", "postprocessor", ";", "switch", "(", "config", ".", "postprocessorType", ")", "{", "case", "\"use_slow_postprocessor\"", ":", "postprocessor", "=", "DelayPostprocessor", ".", "getMediumPostprocessor", "(", ")", ";", "break", ";", "case", "\"use_fast_postprocessor\"", ":", "postprocessor", "=", "DelayPostprocessor", ".", "getFastPostprocessor", "(", ")", ";", "break", ";", "default", ":", "postprocessor", "=", "DelayPostprocessor", ".", "getMediumPostprocessor", "(", ")", ";", "}", "imageRequestBuilder", ".", "setPostprocessor", "(", "postprocessor", ")", ";", "}", "if", "(", "config", ".", "rotateUsingMetaData", ")", "{", "imageRequestBuilder", ".", "setRotationOptions", "(", "RotationOptions", ".", "autoRotateAtRenderTime", "(", ")", ")", ";", "}", "else", "{", "imageRequestBuilder", ".", "setRotationOptions", "(", "RotationOptions", ".", "forceRotation", "(", "config", ".", "forcedRotationAngle", ")", ")", ";", "}", "}" ]
Utility method which adds optional configuration to ImageRequest @param imageRequestBuilder The Builder for ImageRequest @param config The Config
[ "Utility", "method", "which", "adds", "optional", "configuration", "to", "ImageRequest" ]
0b85879d51c5036d5e46e627a6651afefc0b971a
https://github.com/facebook/fresco/blob/0b85879d51c5036d5e46e627a6651afefc0b971a/samples/scrollperf/src/main/java/com/facebook/samples/scrollperf/util/PipelineUtil.java#L31-L52
14,514
facebook/fresco
fbcore/src/main/java/com/facebook/common/util/StreamUtil.java
StreamUtil.skip
public static long skip(final InputStream inputStream, final long bytesCount) throws IOException { Preconditions.checkNotNull(inputStream); Preconditions.checkArgument(bytesCount >= 0); long toSkip = bytesCount; while (toSkip > 0) { final long skipped = inputStream.skip(toSkip); if (skipped > 0) { toSkip -= skipped; continue; } if (inputStream.read() != -1) { toSkip--; continue; } return bytesCount - toSkip; } return bytesCount; }
java
public static long skip(final InputStream inputStream, final long bytesCount) throws IOException { Preconditions.checkNotNull(inputStream); Preconditions.checkArgument(bytesCount >= 0); long toSkip = bytesCount; while (toSkip > 0) { final long skipped = inputStream.skip(toSkip); if (skipped > 0) { toSkip -= skipped; continue; } if (inputStream.read() != -1) { toSkip--; continue; } return bytesCount - toSkip; } return bytesCount; }
[ "public", "static", "long", "skip", "(", "final", "InputStream", "inputStream", ",", "final", "long", "bytesCount", ")", "throws", "IOException", "{", "Preconditions", ".", "checkNotNull", "(", "inputStream", ")", ";", "Preconditions", ".", "checkArgument", "(", "bytesCount", ">=", "0", ")", ";", "long", "toSkip", "=", "bytesCount", ";", "while", "(", "toSkip", ">", "0", ")", "{", "final", "long", "skipped", "=", "inputStream", ".", "skip", "(", "toSkip", ")", ";", "if", "(", "skipped", ">", "0", ")", "{", "toSkip", "-=", "skipped", ";", "continue", ";", "}", "if", "(", "inputStream", ".", "read", "(", ")", "!=", "-", "1", ")", "{", "toSkip", "--", ";", "continue", ";", "}", "return", "bytesCount", "-", "toSkip", ";", "}", "return", "bytesCount", ";", "}" ]
Skips exactly bytesCount bytes in inputStream unless end of stream is reached first. @param inputStream input stream to skip bytes from @param bytesCount number of bytes to skip @return number of skipped bytes @throws IOException
[ "Skips", "exactly", "bytesCount", "bytes", "in", "inputStream", "unless", "end", "of", "stream", "is", "reached", "first", "." ]
0b85879d51c5036d5e46e627a6651afefc0b971a
https://github.com/facebook/fresco/blob/0b85879d51c5036d5e46e627a6651afefc0b971a/fbcore/src/main/java/com/facebook/common/util/StreamUtil.java#L61-L81
14,515
facebook/fresco
imagepipeline/src/main/java/com/facebook/imagepipeline/producers/JobScheduler.java
JobScheduler.clearJob
public void clearJob() { EncodedImage oldEncodedImage; synchronized (this) { oldEncodedImage = mEncodedImage; mEncodedImage = null; mStatus = 0; } EncodedImage.closeSafely(oldEncodedImage); }
java
public void clearJob() { EncodedImage oldEncodedImage; synchronized (this) { oldEncodedImage = mEncodedImage; mEncodedImage = null; mStatus = 0; } EncodedImage.closeSafely(oldEncodedImage); }
[ "public", "void", "clearJob", "(", ")", "{", "EncodedImage", "oldEncodedImage", ";", "synchronized", "(", "this", ")", "{", "oldEncodedImage", "=", "mEncodedImage", ";", "mEncodedImage", "=", "null", ";", "mStatus", "=", "0", ";", "}", "EncodedImage", ".", "closeSafely", "(", "oldEncodedImage", ")", ";", "}" ]
Clears the currently set job. <p> In case the currently set job has been scheduled but not started yet, the job won't be executed.
[ "Clears", "the", "currently", "set", "job", "." ]
0b85879d51c5036d5e46e627a6651afefc0b971a
https://github.com/facebook/fresco/blob/0b85879d51c5036d5e46e627a6651afefc0b971a/imagepipeline/src/main/java/com/facebook/imagepipeline/producers/JobScheduler.java#L95-L103
14,516
facebook/fresco
fbcore/src/main/java/com/facebook/common/statfs/StatFsHelper.java
StatFsHelper.ensureInitialized
private void ensureInitialized() { if (!mInitialized) { lock.lock(); try { if (!mInitialized) { mInternalPath = Environment.getDataDirectory(); mExternalPath = Environment.getExternalStorageDirectory(); updateStats(); mInitialized = true; } } finally { lock.unlock(); } } }
java
private void ensureInitialized() { if (!mInitialized) { lock.lock(); try { if (!mInitialized) { mInternalPath = Environment.getDataDirectory(); mExternalPath = Environment.getExternalStorageDirectory(); updateStats(); mInitialized = true; } } finally { lock.unlock(); } } }
[ "private", "void", "ensureInitialized", "(", ")", "{", "if", "(", "!", "mInitialized", ")", "{", "lock", ".", "lock", "(", ")", ";", "try", "{", "if", "(", "!", "mInitialized", ")", "{", "mInternalPath", "=", "Environment", ".", "getDataDirectory", "(", ")", ";", "mExternalPath", "=", "Environment", ".", "getExternalStorageDirectory", "(", ")", ";", "updateStats", "(", ")", ";", "mInitialized", "=", "true", ";", "}", "}", "finally", "{", "lock", ".", "unlock", "(", ")", ";", "}", "}", "}" ]
Initialization code that can sometimes take a long time.
[ "Initialization", "code", "that", "can", "sometimes", "take", "a", "long", "time", "." ]
0b85879d51c5036d5e46e627a6651afefc0b971a
https://github.com/facebook/fresco/blob/0b85879d51c5036d5e46e627a6651afefc0b971a/fbcore/src/main/java/com/facebook/common/statfs/StatFsHelper.java#L85-L99
14,517
facebook/fresco
fbcore/src/main/java/com/facebook/common/statfs/StatFsHelper.java
StatFsHelper.getFreeStorageSpace
@SuppressLint("DeprecatedMethod") public long getFreeStorageSpace(StorageType storageType) { ensureInitialized(); maybeUpdateStats(); StatFs statFS = storageType == StorageType.INTERNAL ? mInternalStatFs : mExternalStatFs; if (statFS != null) { long blockSize, availableBlocks; if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) { blockSize = statFS.getBlockSizeLong(); availableBlocks = statFS.getFreeBlocksLong(); } else { blockSize = statFS.getBlockSize(); availableBlocks = statFS.getFreeBlocks(); } return blockSize * availableBlocks; } return -1; }
java
@SuppressLint("DeprecatedMethod") public long getFreeStorageSpace(StorageType storageType) { ensureInitialized(); maybeUpdateStats(); StatFs statFS = storageType == StorageType.INTERNAL ? mInternalStatFs : mExternalStatFs; if (statFS != null) { long blockSize, availableBlocks; if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) { blockSize = statFS.getBlockSizeLong(); availableBlocks = statFS.getFreeBlocksLong(); } else { blockSize = statFS.getBlockSize(); availableBlocks = statFS.getFreeBlocks(); } return blockSize * availableBlocks; } return -1; }
[ "@", "SuppressLint", "(", "\"DeprecatedMethod\"", ")", "public", "long", "getFreeStorageSpace", "(", "StorageType", "storageType", ")", "{", "ensureInitialized", "(", ")", ";", "maybeUpdateStats", "(", ")", ";", "StatFs", "statFS", "=", "storageType", "==", "StorageType", ".", "INTERNAL", "?", "mInternalStatFs", ":", "mExternalStatFs", ";", "if", "(", "statFS", "!=", "null", ")", "{", "long", "blockSize", ",", "availableBlocks", ";", "if", "(", "Build", ".", "VERSION", ".", "SDK_INT", ">=", "Build", ".", "VERSION_CODES", ".", "JELLY_BEAN_MR2", ")", "{", "blockSize", "=", "statFS", ".", "getBlockSizeLong", "(", ")", ";", "availableBlocks", "=", "statFS", ".", "getFreeBlocksLong", "(", ")", ";", "}", "else", "{", "blockSize", "=", "statFS", ".", "getBlockSize", "(", ")", ";", "availableBlocks", "=", "statFS", ".", "getFreeBlocks", "(", ")", ";", "}", "return", "blockSize", "*", "availableBlocks", ";", "}", "return", "-", "1", ";", "}" ]
Gets the information about the free storage space, including reserved blocks, either internal or external depends on the given input @param storageType Internal or external storage type @return available space in bytes, -1 if no information is available
[ "Gets", "the", "information", "about", "the", "free", "storage", "space", "including", "reserved", "blocks", "either", "internal", "or", "external", "depends", "on", "the", "given", "input" ]
0b85879d51c5036d5e46e627a6651afefc0b971a
https://github.com/facebook/fresco/blob/0b85879d51c5036d5e46e627a6651afefc0b971a/fbcore/src/main/java/com/facebook/common/statfs/StatFsHelper.java#L128-L147
14,518
facebook/fresco
fbcore/src/main/java/com/facebook/common/statfs/StatFsHelper.java
StatFsHelper.getTotalStorageSpace
@SuppressLint("DeprecatedMethod") public long getTotalStorageSpace(StorageType storageType) { ensureInitialized(); maybeUpdateStats(); StatFs statFS = storageType == StorageType.INTERNAL ? mInternalStatFs : mExternalStatFs; if (statFS != null) { long blockSize, totalBlocks; if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) { blockSize = statFS.getBlockSizeLong(); totalBlocks = statFS.getBlockCountLong(); } else { blockSize = statFS.getBlockSize(); totalBlocks = statFS.getBlockCount(); } return blockSize * totalBlocks; } return -1; }
java
@SuppressLint("DeprecatedMethod") public long getTotalStorageSpace(StorageType storageType) { ensureInitialized(); maybeUpdateStats(); StatFs statFS = storageType == StorageType.INTERNAL ? mInternalStatFs : mExternalStatFs; if (statFS != null) { long blockSize, totalBlocks; if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) { blockSize = statFS.getBlockSizeLong(); totalBlocks = statFS.getBlockCountLong(); } else { blockSize = statFS.getBlockSize(); totalBlocks = statFS.getBlockCount(); } return blockSize * totalBlocks; } return -1; }
[ "@", "SuppressLint", "(", "\"DeprecatedMethod\"", ")", "public", "long", "getTotalStorageSpace", "(", "StorageType", "storageType", ")", "{", "ensureInitialized", "(", ")", ";", "maybeUpdateStats", "(", ")", ";", "StatFs", "statFS", "=", "storageType", "==", "StorageType", ".", "INTERNAL", "?", "mInternalStatFs", ":", "mExternalStatFs", ";", "if", "(", "statFS", "!=", "null", ")", "{", "long", "blockSize", ",", "totalBlocks", ";", "if", "(", "Build", ".", "VERSION", ".", "SDK_INT", ">=", "Build", ".", "VERSION_CODES", ".", "JELLY_BEAN_MR2", ")", "{", "blockSize", "=", "statFS", ".", "getBlockSizeLong", "(", ")", ";", "totalBlocks", "=", "statFS", ".", "getBlockCountLong", "(", ")", ";", "}", "else", "{", "blockSize", "=", "statFS", ".", "getBlockSize", "(", ")", ";", "totalBlocks", "=", "statFS", ".", "getBlockCount", "(", ")", ";", "}", "return", "blockSize", "*", "totalBlocks", ";", "}", "return", "-", "1", ";", "}" ]
Gets the information about the total storage space, either internal or external depends on the given input @param storageType Internal or external storage type @return available space in bytes, -1 if no information is available
[ "Gets", "the", "information", "about", "the", "total", "storage", "space", "either", "internal", "or", "external", "depends", "on", "the", "given", "input" ]
0b85879d51c5036d5e46e627a6651afefc0b971a
https://github.com/facebook/fresco/blob/0b85879d51c5036d5e46e627a6651afefc0b971a/fbcore/src/main/java/com/facebook/common/statfs/StatFsHelper.java#L155-L174
14,519
facebook/fresco
fbcore/src/main/java/com/facebook/common/statfs/StatFsHelper.java
StatFsHelper.getAvailableStorageSpace
@SuppressLint("DeprecatedMethod") public long getAvailableStorageSpace(StorageType storageType) { ensureInitialized(); maybeUpdateStats(); StatFs statFS = storageType == StorageType.INTERNAL ? mInternalStatFs : mExternalStatFs; if (statFS != null) { long blockSize, availableBlocks; if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) { blockSize = statFS.getBlockSizeLong(); availableBlocks = statFS.getAvailableBlocksLong(); } else { blockSize = statFS.getBlockSize(); availableBlocks = statFS.getAvailableBlocks(); } return blockSize * availableBlocks; } return 0; }
java
@SuppressLint("DeprecatedMethod") public long getAvailableStorageSpace(StorageType storageType) { ensureInitialized(); maybeUpdateStats(); StatFs statFS = storageType == StorageType.INTERNAL ? mInternalStatFs : mExternalStatFs; if (statFS != null) { long blockSize, availableBlocks; if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) { blockSize = statFS.getBlockSizeLong(); availableBlocks = statFS.getAvailableBlocksLong(); } else { blockSize = statFS.getBlockSize(); availableBlocks = statFS.getAvailableBlocks(); } return blockSize * availableBlocks; } return 0; }
[ "@", "SuppressLint", "(", "\"DeprecatedMethod\"", ")", "public", "long", "getAvailableStorageSpace", "(", "StorageType", "storageType", ")", "{", "ensureInitialized", "(", ")", ";", "maybeUpdateStats", "(", ")", ";", "StatFs", "statFS", "=", "storageType", "==", "StorageType", ".", "INTERNAL", "?", "mInternalStatFs", ":", "mExternalStatFs", ";", "if", "(", "statFS", "!=", "null", ")", "{", "long", "blockSize", ",", "availableBlocks", ";", "if", "(", "Build", ".", "VERSION", ".", "SDK_INT", ">=", "Build", ".", "VERSION_CODES", ".", "JELLY_BEAN_MR2", ")", "{", "blockSize", "=", "statFS", ".", "getBlockSizeLong", "(", ")", ";", "availableBlocks", "=", "statFS", ".", "getAvailableBlocksLong", "(", ")", ";", "}", "else", "{", "blockSize", "=", "statFS", ".", "getBlockSize", "(", ")", ";", "availableBlocks", "=", "statFS", ".", "getAvailableBlocks", "(", ")", ";", "}", "return", "blockSize", "*", "availableBlocks", ";", "}", "return", "0", ";", "}" ]
Gets the information about the available storage space either internal or external depends on the give input @param storageType Internal or external storage type @return available space in bytes, 0 if no information is available
[ "Gets", "the", "information", "about", "the", "available", "storage", "space", "either", "internal", "or", "external", "depends", "on", "the", "give", "input" ]
0b85879d51c5036d5e46e627a6651afefc0b971a
https://github.com/facebook/fresco/blob/0b85879d51c5036d5e46e627a6651afefc0b971a/fbcore/src/main/java/com/facebook/common/statfs/StatFsHelper.java#L182-L201
14,520
facebook/fresco
samples/gestures/src/main/java/com/facebook/samples/gestures/MultiPointerGestureDetector.java
MultiPointerGestureDetector.reset
public void reset() { mGestureInProgress = false; mPointerCount = 0; for (int i = 0; i < MAX_POINTERS; i++) { mId[i] = MotionEvent.INVALID_POINTER_ID; } }
java
public void reset() { mGestureInProgress = false; mPointerCount = 0; for (int i = 0; i < MAX_POINTERS; i++) { mId[i] = MotionEvent.INVALID_POINTER_ID; } }
[ "public", "void", "reset", "(", ")", "{", "mGestureInProgress", "=", "false", ";", "mPointerCount", "=", "0", ";", "for", "(", "int", "i", "=", "0", ";", "i", "<", "MAX_POINTERS", ";", "i", "++", ")", "{", "mId", "[", "i", "]", "=", "MotionEvent", ".", "INVALID_POINTER_ID", ";", "}", "}" ]
Resets the component to the initial state.
[ "Resets", "the", "component", "to", "the", "initial", "state", "." ]
0b85879d51c5036d5e46e627a6651afefc0b971a
https://github.com/facebook/fresco/blob/0b85879d51c5036d5e46e627a6651afefc0b971a/samples/gestures/src/main/java/com/facebook/samples/gestures/MultiPointerGestureDetector.java#L71-L77
14,521
facebook/fresco
samples/gestures/src/main/java/com/facebook/samples/gestures/MultiPointerGestureDetector.java
MultiPointerGestureDetector.getPressedPointerIndex
private int getPressedPointerIndex(MotionEvent event, int i) { final int count = event.getPointerCount(); final int action = event.getActionMasked(); final int index = event.getActionIndex(); if (action == MotionEvent.ACTION_UP || action == MotionEvent.ACTION_POINTER_UP) { if (i >= index) { i++; } } return (i < count) ? i : -1; }
java
private int getPressedPointerIndex(MotionEvent event, int i) { final int count = event.getPointerCount(); final int action = event.getActionMasked(); final int index = event.getActionIndex(); if (action == MotionEvent.ACTION_UP || action == MotionEvent.ACTION_POINTER_UP) { if (i >= index) { i++; } } return (i < count) ? i : -1; }
[ "private", "int", "getPressedPointerIndex", "(", "MotionEvent", "event", ",", "int", "i", ")", "{", "final", "int", "count", "=", "event", ".", "getPointerCount", "(", ")", ";", "final", "int", "action", "=", "event", ".", "getActionMasked", "(", ")", ";", "final", "int", "index", "=", "event", ".", "getActionIndex", "(", ")", ";", "if", "(", "action", "==", "MotionEvent", ".", "ACTION_UP", "||", "action", "==", "MotionEvent", ".", "ACTION_POINTER_UP", ")", "{", "if", "(", "i", ">=", "index", ")", "{", "i", "++", ";", "}", "}", "return", "(", "i", "<", "count", ")", "?", "i", ":", "-", "1", ";", "}" ]
Gets the index of the i-th pressed pointer. Normally, the index will be equal to i, except in the case when the pointer is released. @return index of the specified pointer or -1 if not found (i.e. not enough pointers are down)
[ "Gets", "the", "index", "of", "the", "i", "-", "th", "pressed", "pointer", ".", "Normally", "the", "index", "will", "be", "equal", "to", "i", "except", "in", "the", "case", "when", "the", "pointer", "is", "released", "." ]
0b85879d51c5036d5e46e627a6651afefc0b971a
https://github.com/facebook/fresco/blob/0b85879d51c5036d5e46e627a6651afefc0b971a/samples/gestures/src/main/java/com/facebook/samples/gestures/MultiPointerGestureDetector.java#L116-L127
14,522
facebook/fresco
samples/gestures/src/main/java/com/facebook/samples/gestures/MultiPointerGestureDetector.java
MultiPointerGestureDetector.onTouchEvent
public boolean onTouchEvent(final MotionEvent event) { switch (event.getActionMasked()) { case MotionEvent.ACTION_MOVE: { // update pointers updatePointersOnMove(event); // start a new gesture if not already started if (!mGestureInProgress && mPointerCount > 0 && shouldStartGesture()) { startGesture(); } // notify listener if (mGestureInProgress && mListener != null) { mListener.onGestureUpdate(this); } break; } case MotionEvent.ACTION_DOWN: case MotionEvent.ACTION_POINTER_DOWN: case MotionEvent.ACTION_POINTER_UP: case MotionEvent.ACTION_UP: { // restart gesture whenever the number of pointers changes mNewPointerCount = getPressedPointerCount(event); stopGesture(); updatePointersOnTap(event); if (mPointerCount > 0 && shouldStartGesture()) { startGesture(); } break; } case MotionEvent.ACTION_CANCEL: { mNewPointerCount = 0; stopGesture(); reset(); break; } } return true; }
java
public boolean onTouchEvent(final MotionEvent event) { switch (event.getActionMasked()) { case MotionEvent.ACTION_MOVE: { // update pointers updatePointersOnMove(event); // start a new gesture if not already started if (!mGestureInProgress && mPointerCount > 0 && shouldStartGesture()) { startGesture(); } // notify listener if (mGestureInProgress && mListener != null) { mListener.onGestureUpdate(this); } break; } case MotionEvent.ACTION_DOWN: case MotionEvent.ACTION_POINTER_DOWN: case MotionEvent.ACTION_POINTER_UP: case MotionEvent.ACTION_UP: { // restart gesture whenever the number of pointers changes mNewPointerCount = getPressedPointerCount(event); stopGesture(); updatePointersOnTap(event); if (mPointerCount > 0 && shouldStartGesture()) { startGesture(); } break; } case MotionEvent.ACTION_CANCEL: { mNewPointerCount = 0; stopGesture(); reset(); break; } } return true; }
[ "public", "boolean", "onTouchEvent", "(", "final", "MotionEvent", "event", ")", "{", "switch", "(", "event", ".", "getActionMasked", "(", ")", ")", "{", "case", "MotionEvent", ".", "ACTION_MOVE", ":", "{", "// update pointers", "updatePointersOnMove", "(", "event", ")", ";", "// start a new gesture if not already started", "if", "(", "!", "mGestureInProgress", "&&", "mPointerCount", ">", "0", "&&", "shouldStartGesture", "(", ")", ")", "{", "startGesture", "(", ")", ";", "}", "// notify listener", "if", "(", "mGestureInProgress", "&&", "mListener", "!=", "null", ")", "{", "mListener", ".", "onGestureUpdate", "(", "this", ")", ";", "}", "break", ";", "}", "case", "MotionEvent", ".", "ACTION_DOWN", ":", "case", "MotionEvent", ".", "ACTION_POINTER_DOWN", ":", "case", "MotionEvent", ".", "ACTION_POINTER_UP", ":", "case", "MotionEvent", ".", "ACTION_UP", ":", "{", "// restart gesture whenever the number of pointers changes", "mNewPointerCount", "=", "getPressedPointerCount", "(", "event", ")", ";", "stopGesture", "(", ")", ";", "updatePointersOnTap", "(", "event", ")", ";", "if", "(", "mPointerCount", ">", "0", "&&", "shouldStartGesture", "(", ")", ")", "{", "startGesture", "(", ")", ";", "}", "break", ";", "}", "case", "MotionEvent", ".", "ACTION_CANCEL", ":", "{", "mNewPointerCount", "=", "0", ";", "stopGesture", "(", ")", ";", "reset", "(", ")", ";", "break", ";", "}", "}", "return", "true", ";", "}" ]
Handles the given motion event. @param event event to handle @return whether or not the event was handled
[ "Handles", "the", "given", "motion", "event", "." ]
0b85879d51c5036d5e46e627a6651afefc0b971a
https://github.com/facebook/fresco/blob/0b85879d51c5036d5e46e627a6651afefc0b971a/samples/gestures/src/main/java/com/facebook/samples/gestures/MultiPointerGestureDetector.java#L172-L210
14,523
facebook/fresco
drawee/src/main/java/com/facebook/drawee/gestures/GestureDetector.java
GestureDetector.onTouchEvent
public boolean onTouchEvent(MotionEvent event) { switch (event.getAction()) { case MotionEvent.ACTION_DOWN: mIsCapturingGesture = true; mIsClickCandidate = true; mActionDownTime = event.getEventTime(); mActionDownX = event.getX(); mActionDownY = event.getY(); break; case MotionEvent.ACTION_MOVE: if (Math.abs(event.getX() - mActionDownX) > mSingleTapSlopPx || Math.abs(event.getY() - mActionDownY) > mSingleTapSlopPx) { mIsClickCandidate = false; } break; case MotionEvent.ACTION_CANCEL: mIsCapturingGesture = false; mIsClickCandidate = false; break; case MotionEvent.ACTION_UP: mIsCapturingGesture = false; if (Math.abs(event.getX() - mActionDownX) > mSingleTapSlopPx || Math.abs(event.getY() - mActionDownY) > mSingleTapSlopPx) { mIsClickCandidate = false; } if (mIsClickCandidate) { if (event.getEventTime() - mActionDownTime <= ViewConfiguration.getLongPressTimeout()) { if (mClickListener != null) { mClickListener.onClick(); } } else { // long click, not handled } } mIsClickCandidate = false; break; } return true; }
java
public boolean onTouchEvent(MotionEvent event) { switch (event.getAction()) { case MotionEvent.ACTION_DOWN: mIsCapturingGesture = true; mIsClickCandidate = true; mActionDownTime = event.getEventTime(); mActionDownX = event.getX(); mActionDownY = event.getY(); break; case MotionEvent.ACTION_MOVE: if (Math.abs(event.getX() - mActionDownX) > mSingleTapSlopPx || Math.abs(event.getY() - mActionDownY) > mSingleTapSlopPx) { mIsClickCandidate = false; } break; case MotionEvent.ACTION_CANCEL: mIsCapturingGesture = false; mIsClickCandidate = false; break; case MotionEvent.ACTION_UP: mIsCapturingGesture = false; if (Math.abs(event.getX() - mActionDownX) > mSingleTapSlopPx || Math.abs(event.getY() - mActionDownY) > mSingleTapSlopPx) { mIsClickCandidate = false; } if (mIsClickCandidate) { if (event.getEventTime() - mActionDownTime <= ViewConfiguration.getLongPressTimeout()) { if (mClickListener != null) { mClickListener.onClick(); } } else { // long click, not handled } } mIsClickCandidate = false; break; } return true; }
[ "public", "boolean", "onTouchEvent", "(", "MotionEvent", "event", ")", "{", "switch", "(", "event", ".", "getAction", "(", ")", ")", "{", "case", "MotionEvent", ".", "ACTION_DOWN", ":", "mIsCapturingGesture", "=", "true", ";", "mIsClickCandidate", "=", "true", ";", "mActionDownTime", "=", "event", ".", "getEventTime", "(", ")", ";", "mActionDownX", "=", "event", ".", "getX", "(", ")", ";", "mActionDownY", "=", "event", ".", "getY", "(", ")", ";", "break", ";", "case", "MotionEvent", ".", "ACTION_MOVE", ":", "if", "(", "Math", ".", "abs", "(", "event", ".", "getX", "(", ")", "-", "mActionDownX", ")", ">", "mSingleTapSlopPx", "||", "Math", ".", "abs", "(", "event", ".", "getY", "(", ")", "-", "mActionDownY", ")", ">", "mSingleTapSlopPx", ")", "{", "mIsClickCandidate", "=", "false", ";", "}", "break", ";", "case", "MotionEvent", ".", "ACTION_CANCEL", ":", "mIsCapturingGesture", "=", "false", ";", "mIsClickCandidate", "=", "false", ";", "break", ";", "case", "MotionEvent", ".", "ACTION_UP", ":", "mIsCapturingGesture", "=", "false", ";", "if", "(", "Math", ".", "abs", "(", "event", ".", "getX", "(", ")", "-", "mActionDownX", ")", ">", "mSingleTapSlopPx", "||", "Math", ".", "abs", "(", "event", ".", "getY", "(", ")", "-", "mActionDownY", ")", ">", "mSingleTapSlopPx", ")", "{", "mIsClickCandidate", "=", "false", ";", "}", "if", "(", "mIsClickCandidate", ")", "{", "if", "(", "event", ".", "getEventTime", "(", ")", "-", "mActionDownTime", "<=", "ViewConfiguration", ".", "getLongPressTimeout", "(", ")", ")", "{", "if", "(", "mClickListener", "!=", "null", ")", "{", "mClickListener", ".", "onClick", "(", ")", ";", "}", "}", "else", "{", "// long click, not handled", "}", "}", "mIsClickCandidate", "=", "false", ";", "break", ";", "}", "return", "true", ";", "}" ]
Handles the touch event
[ "Handles", "the", "touch", "event" ]
0b85879d51c5036d5e46e627a6651afefc0b971a
https://github.com/facebook/fresco/blob/0b85879d51c5036d5e46e627a6651afefc0b971a/drawee/src/main/java/com/facebook/drawee/gestures/GestureDetector.java#L80-L118
14,524
facebook/fresco
imagepipeline/src/main/java/com/facebook/imagepipeline/producers/BaseProducerContext.java
BaseProducerContext.setIsPrefetchNoCallbacks
@Nullable public synchronized List<ProducerContextCallbacks> setIsPrefetchNoCallbacks(boolean isPrefetch) { if (isPrefetch == mIsPrefetch) { return null; } mIsPrefetch = isPrefetch; return new ArrayList<>(mCallbacks); }
java
@Nullable public synchronized List<ProducerContextCallbacks> setIsPrefetchNoCallbacks(boolean isPrefetch) { if (isPrefetch == mIsPrefetch) { return null; } mIsPrefetch = isPrefetch; return new ArrayList<>(mCallbacks); }
[ "@", "Nullable", "public", "synchronized", "List", "<", "ProducerContextCallbacks", ">", "setIsPrefetchNoCallbacks", "(", "boolean", "isPrefetch", ")", "{", "if", "(", "isPrefetch", "==", "mIsPrefetch", ")", "{", "return", "null", ";", "}", "mIsPrefetch", "=", "isPrefetch", ";", "return", "new", "ArrayList", "<>", "(", "mCallbacks", ")", ";", "}" ]
Changes isPrefetch property. <p> This method does not call any callbacks. Instead, caller of this method is responsible for iterating over returned list and calling appropriate method on each callback object. {@see #callOnIsPrefetchChanged} @return list of callbacks if the value actually changes, null otherwise
[ "Changes", "isPrefetch", "property", "." ]
0b85879d51c5036d5e46e627a6651afefc0b971a
https://github.com/facebook/fresco/blob/0b85879d51c5036d5e46e627a6651afefc0b971a/imagepipeline/src/main/java/com/facebook/imagepipeline/producers/BaseProducerContext.java#L136-L143
14,525
facebook/fresco
imagepipeline/src/main/java/com/facebook/imagepipeline/producers/BaseProducerContext.java
BaseProducerContext.setPriorityNoCallbacks
@Nullable public synchronized List<ProducerContextCallbacks> setPriorityNoCallbacks(Priority priority) { if (priority == mPriority) { return null; } mPriority = priority; return new ArrayList<>(mCallbacks); }
java
@Nullable public synchronized List<ProducerContextCallbacks> setPriorityNoCallbacks(Priority priority) { if (priority == mPriority) { return null; } mPriority = priority; return new ArrayList<>(mCallbacks); }
[ "@", "Nullable", "public", "synchronized", "List", "<", "ProducerContextCallbacks", ">", "setPriorityNoCallbacks", "(", "Priority", "priority", ")", "{", "if", "(", "priority", "==", "mPriority", ")", "{", "return", "null", ";", "}", "mPriority", "=", "priority", ";", "return", "new", "ArrayList", "<>", "(", "mCallbacks", ")", ";", "}" ]
Changes priority. <p> This method does not call any callbacks. Instead, caller of this method is responsible for iterating over returned list and calling appropriate method on each callback object. {@see #callOnPriorityChanged} @return list of callbacks if the value actually changes, null otherwise
[ "Changes", "priority", "." ]
0b85879d51c5036d5e46e627a6651afefc0b971a
https://github.com/facebook/fresco/blob/0b85879d51c5036d5e46e627a6651afefc0b971a/imagepipeline/src/main/java/com/facebook/imagepipeline/producers/BaseProducerContext.java#L154-L161
14,526
facebook/fresco
imagepipeline/src/main/java/com/facebook/imagepipeline/producers/BaseProducerContext.java
BaseProducerContext.setIsIntermediateResultExpectedNoCallbacks
@Nullable public synchronized List<ProducerContextCallbacks> setIsIntermediateResultExpectedNoCallbacks( boolean isIntermediateResultExpected) { if (isIntermediateResultExpected == mIsIntermediateResultExpected) { return null; } mIsIntermediateResultExpected = isIntermediateResultExpected; return new ArrayList<>(mCallbacks); }
java
@Nullable public synchronized List<ProducerContextCallbacks> setIsIntermediateResultExpectedNoCallbacks( boolean isIntermediateResultExpected) { if (isIntermediateResultExpected == mIsIntermediateResultExpected) { return null; } mIsIntermediateResultExpected = isIntermediateResultExpected; return new ArrayList<>(mCallbacks); }
[ "@", "Nullable", "public", "synchronized", "List", "<", "ProducerContextCallbacks", ">", "setIsIntermediateResultExpectedNoCallbacks", "(", "boolean", "isIntermediateResultExpected", ")", "{", "if", "(", "isIntermediateResultExpected", "==", "mIsIntermediateResultExpected", ")", "{", "return", "null", ";", "}", "mIsIntermediateResultExpected", "=", "isIntermediateResultExpected", ";", "return", "new", "ArrayList", "<>", "(", "mCallbacks", ")", ";", "}" ]
Changes isIntermediateResultExpected property. <p> This method does not call any callbacks. Instead, caller of this method is responsible for iterating over returned list and calling appropriate method on each callback object. {@see #callOnIntermediateResultChanged} @return list of callbacks if the value actually changes, null otherwise
[ "Changes", "isIntermediateResultExpected", "property", "." ]
0b85879d51c5036d5e46e627a6651afefc0b971a
https://github.com/facebook/fresco/blob/0b85879d51c5036d5e46e627a6651afefc0b971a/imagepipeline/src/main/java/com/facebook/imagepipeline/producers/BaseProducerContext.java#L172-L180
14,527
facebook/fresco
imagepipeline/src/main/java/com/facebook/imagepipeline/producers/BaseProducerContext.java
BaseProducerContext.cancelNoCallbacks
@Nullable public synchronized List<ProducerContextCallbacks> cancelNoCallbacks() { if (mIsCancelled) { return null; } mIsCancelled = true; return new ArrayList<>(mCallbacks); }
java
@Nullable public synchronized List<ProducerContextCallbacks> cancelNoCallbacks() { if (mIsCancelled) { return null; } mIsCancelled = true; return new ArrayList<>(mCallbacks); }
[ "@", "Nullable", "public", "synchronized", "List", "<", "ProducerContextCallbacks", ">", "cancelNoCallbacks", "(", ")", "{", "if", "(", "mIsCancelled", ")", "{", "return", "null", ";", "}", "mIsCancelled", "=", "true", ";", "return", "new", "ArrayList", "<>", "(", "mCallbacks", ")", ";", "}" ]
Marks this ProducerContext as cancelled. <p> This method does not call any callbacks. Instead, caller of this method is responsible for iterating over returned list and calling appropriate method on each callback object. {@see #callOnCancellationRequested} @return list of callbacks if the value actually changes, null otherwise
[ "Marks", "this", "ProducerContext", "as", "cancelled", "." ]
0b85879d51c5036d5e46e627a6651afefc0b971a
https://github.com/facebook/fresco/blob/0b85879d51c5036d5e46e627a6651afefc0b971a/imagepipeline/src/main/java/com/facebook/imagepipeline/producers/BaseProducerContext.java#L191-L198
14,528
facebook/fresco
imagepipeline-base/src/main/java/com/facebook/imageutils/JfifUtil.java
JfifUtil.getOrientation
public static int getOrientation(InputStream is) { try { int length = moveToAPP1EXIF(is); if (length == 0) { return ExifInterface.ORIENTATION_UNDEFINED; } return TiffUtil.readOrientationFromTIFF(is, length); } catch (IOException ioe) { return ExifInterface.ORIENTATION_UNDEFINED; } }
java
public static int getOrientation(InputStream is) { try { int length = moveToAPP1EXIF(is); if (length == 0) { return ExifInterface.ORIENTATION_UNDEFINED; } return TiffUtil.readOrientationFromTIFF(is, length); } catch (IOException ioe) { return ExifInterface.ORIENTATION_UNDEFINED; } }
[ "public", "static", "int", "getOrientation", "(", "InputStream", "is", ")", "{", "try", "{", "int", "length", "=", "moveToAPP1EXIF", "(", "is", ")", ";", "if", "(", "length", "==", "0", ")", "{", "return", "ExifInterface", ".", "ORIENTATION_UNDEFINED", ";", "}", "return", "TiffUtil", ".", "readOrientationFromTIFF", "(", "is", ",", "length", ")", ";", "}", "catch", "(", "IOException", "ioe", ")", "{", "return", "ExifInterface", ".", "ORIENTATION_UNDEFINED", ";", "}", "}" ]
Get orientation information from jpeg input stream. @param is the input stream of jpeg image @return orientation: 1/8/3/6. Returns {@value android.media.ExifInterface#ORIENTATION_UNDEFINED} if there is no valid orientation information.
[ "Get", "orientation", "information", "from", "jpeg", "input", "stream", "." ]
0b85879d51c5036d5e46e627a6651afefc0b971a
https://github.com/facebook/fresco/blob/0b85879d51c5036d5e46e627a6651afefc0b971a/imagepipeline-base/src/main/java/com/facebook/imageutils/JfifUtil.java#L67-L77
14,529
facebook/fresco
imagepipeline-base/src/main/java/com/facebook/imageutils/JfifUtil.java
JfifUtil.moveToMarker
public static boolean moveToMarker(InputStream is, int markerToFind) throws IOException { Preconditions.checkNotNull(is); // ISO/IEC 10918-1:1993(E) while (StreamProcessor.readPackedInt(is, 1, false) == MARKER_FIRST_BYTE) { int marker = MARKER_FIRST_BYTE; while (marker == MARKER_FIRST_BYTE) { marker = StreamProcessor.readPackedInt(is, 1, false); } if (markerToFind == MARKER_SOFn && isSOFn(marker)) { return true; } if (marker == markerToFind) { return true; } // Check if the marker is SOI or TEM. These two don't have length field, so we skip it. if (marker == MARKER_SOI || marker == MARKER_TEM) { continue; } // Check if the marker is EOI or SOS. We will stop reading since metadata markers don't // come after these two markers. if (marker == MARKER_EOI || marker == MARKER_SOS) { return false; } // read block length // subtract 2 as length contain SIZE field we just read int length = StreamProcessor.readPackedInt(is, 2, false) - 2; // Skip other markers. is.skip(length); } return false; }
java
public static boolean moveToMarker(InputStream is, int markerToFind) throws IOException { Preconditions.checkNotNull(is); // ISO/IEC 10918-1:1993(E) while (StreamProcessor.readPackedInt(is, 1, false) == MARKER_FIRST_BYTE) { int marker = MARKER_FIRST_BYTE; while (marker == MARKER_FIRST_BYTE) { marker = StreamProcessor.readPackedInt(is, 1, false); } if (markerToFind == MARKER_SOFn && isSOFn(marker)) { return true; } if (marker == markerToFind) { return true; } // Check if the marker is SOI or TEM. These two don't have length field, so we skip it. if (marker == MARKER_SOI || marker == MARKER_TEM) { continue; } // Check if the marker is EOI or SOS. We will stop reading since metadata markers don't // come after these two markers. if (marker == MARKER_EOI || marker == MARKER_SOS) { return false; } // read block length // subtract 2 as length contain SIZE field we just read int length = StreamProcessor.readPackedInt(is, 2, false) - 2; // Skip other markers. is.skip(length); } return false; }
[ "public", "static", "boolean", "moveToMarker", "(", "InputStream", "is", ",", "int", "markerToFind", ")", "throws", "IOException", "{", "Preconditions", ".", "checkNotNull", "(", "is", ")", ";", "// ISO/IEC 10918-1:1993(E)", "while", "(", "StreamProcessor", ".", "readPackedInt", "(", "is", ",", "1", ",", "false", ")", "==", "MARKER_FIRST_BYTE", ")", "{", "int", "marker", "=", "MARKER_FIRST_BYTE", ";", "while", "(", "marker", "==", "MARKER_FIRST_BYTE", ")", "{", "marker", "=", "StreamProcessor", ".", "readPackedInt", "(", "is", ",", "1", ",", "false", ")", ";", "}", "if", "(", "markerToFind", "==", "MARKER_SOFn", "&&", "isSOFn", "(", "marker", ")", ")", "{", "return", "true", ";", "}", "if", "(", "marker", "==", "markerToFind", ")", "{", "return", "true", ";", "}", "// Check if the marker is SOI or TEM. These two don't have length field, so we skip it.", "if", "(", "marker", "==", "MARKER_SOI", "||", "marker", "==", "MARKER_TEM", ")", "{", "continue", ";", "}", "// Check if the marker is EOI or SOS. We will stop reading since metadata markers don't", "// come after these two markers.", "if", "(", "marker", "==", "MARKER_EOI", "||", "marker", "==", "MARKER_SOS", ")", "{", "return", "false", ";", "}", "// read block length", "// subtract 2 as length contain SIZE field we just read", "int", "length", "=", "StreamProcessor", ".", "readPackedInt", "(", "is", ",", "2", ",", "false", ")", "-", "2", ";", "// Skip other markers.", "is", ".", "skip", "(", "length", ")", ";", "}", "return", "false", ";", "}" ]
Reads the content of the input stream until specified marker is found. Marker will be consumed and the input stream will be positioned after the specified marker. @param is the input stream to read bytes from @param markerToFind the marker we are looking for @return boolean: whether or not we found the expected marker from input stream.
[ "Reads", "the", "content", "of", "the", "input", "stream", "until", "specified", "marker", "is", "found", ".", "Marker", "will", "be", "consumed", "and", "the", "input", "stream", "will", "be", "positioned", "after", "the", "specified", "marker", "." ]
0b85879d51c5036d5e46e627a6651afefc0b971a
https://github.com/facebook/fresco/blob/0b85879d51c5036d5e46e627a6651afefc0b971a/imagepipeline-base/src/main/java/com/facebook/imageutils/JfifUtil.java#L86-L120
14,530
facebook/fresco
imagepipeline-base/src/main/java/com/facebook/imageutils/JfifUtil.java
JfifUtil.moveToAPP1EXIF
private static int moveToAPP1EXIF(InputStream is) throws IOException { if (moveToMarker(is, MARKER_APP1)) { // read block length // subtract 2 as length contain SIZE field we just read int length = StreamProcessor.readPackedInt(is, 2, false) - 2; if (length > 6) { int magic = StreamProcessor.readPackedInt(is, 4, false); length -= 4; int zero = StreamProcessor.readPackedInt(is, 2, false); length -= 2; if (magic == APP1_EXIF_MAGIC && zero == 0) { // JEITA CP-3451 Exif Version 2.2 return length; } } } return 0; }
java
private static int moveToAPP1EXIF(InputStream is) throws IOException { if (moveToMarker(is, MARKER_APP1)) { // read block length // subtract 2 as length contain SIZE field we just read int length = StreamProcessor.readPackedInt(is, 2, false) - 2; if (length > 6) { int magic = StreamProcessor.readPackedInt(is, 4, false); length -= 4; int zero = StreamProcessor.readPackedInt(is, 2, false); length -= 2; if (magic == APP1_EXIF_MAGIC && zero == 0) { // JEITA CP-3451 Exif Version 2.2 return length; } } } return 0; }
[ "private", "static", "int", "moveToAPP1EXIF", "(", "InputStream", "is", ")", "throws", "IOException", "{", "if", "(", "moveToMarker", "(", "is", ",", "MARKER_APP1", ")", ")", "{", "// read block length", "// subtract 2 as length contain SIZE field we just read", "int", "length", "=", "StreamProcessor", ".", "readPackedInt", "(", "is", ",", "2", ",", "false", ")", "-", "2", ";", "if", "(", "length", ">", "6", ")", "{", "int", "magic", "=", "StreamProcessor", ".", "readPackedInt", "(", "is", ",", "4", ",", "false", ")", ";", "length", "-=", "4", ";", "int", "zero", "=", "StreamProcessor", ".", "readPackedInt", "(", "is", ",", "2", ",", "false", ")", ";", "length", "-=", "2", ";", "if", "(", "magic", "==", "APP1_EXIF_MAGIC", "&&", "zero", "==", "0", ")", "{", "// JEITA CP-3451 Exif Version 2.2", "return", "length", ";", "}", "}", "}", "return", "0", ";", "}" ]
Positions the given input stream to the beginning of the EXIF data in the JPEG APP1 block. @param is the input stream of jpeg image @return length of EXIF data
[ "Positions", "the", "given", "input", "stream", "to", "the", "beginning", "of", "the", "EXIF", "data", "in", "the", "JPEG", "APP1", "block", "." ]
0b85879d51c5036d5e46e627a6651afefc0b971a
https://github.com/facebook/fresco/blob/0b85879d51c5036d5e46e627a6651afefc0b971a/imagepipeline-base/src/main/java/com/facebook/imageutils/JfifUtil.java#L149-L166
14,531
facebook/fresco
samples/zoomable/src/main/java/com/facebook/samples/zoomable/ZoomableDraweeView.java
ZoomableDraweeView.setZoomableController
public void setZoomableController(ZoomableController zoomableController) { Preconditions.checkNotNull(zoomableController); mZoomableController.setListener(null); mZoomableController = zoomableController; mZoomableController.setListener(mZoomableListener); }
java
public void setZoomableController(ZoomableController zoomableController) { Preconditions.checkNotNull(zoomableController); mZoomableController.setListener(null); mZoomableController = zoomableController; mZoomableController.setListener(mZoomableListener); }
[ "public", "void", "setZoomableController", "(", "ZoomableController", "zoomableController", ")", "{", "Preconditions", ".", "checkNotNull", "(", "zoomableController", ")", ";", "mZoomableController", ".", "setListener", "(", "null", ")", ";", "mZoomableController", "=", "zoomableController", ";", "mZoomableController", ".", "setListener", "(", "mZoomableListener", ")", ";", "}" ]
Sets a custom zoomable controller, instead of using the default one.
[ "Sets", "a", "custom", "zoomable", "controller", "instead", "of", "using", "the", "default", "one", "." ]
0b85879d51c5036d5e46e627a6651afefc0b971a
https://github.com/facebook/fresco/blob/0b85879d51c5036d5e46e627a6651afefc0b971a/samples/zoomable/src/main/java/com/facebook/samples/zoomable/ZoomableDraweeView.java#L168-L173
14,532
facebook/fresco
drawee/src/main/java/com/facebook/drawee/drawable/ScaleTypeDrawable.java
ScaleTypeDrawable.setScaleType
public void setScaleType(ScaleType scaleType) { if (Objects.equal(mScaleType, scaleType)) { return; } mScaleType = scaleType; mScaleTypeState = null; configureBounds(); invalidateSelf(); }
java
public void setScaleType(ScaleType scaleType) { if (Objects.equal(mScaleType, scaleType)) { return; } mScaleType = scaleType; mScaleTypeState = null; configureBounds(); invalidateSelf(); }
[ "public", "void", "setScaleType", "(", "ScaleType", "scaleType", ")", "{", "if", "(", "Objects", ".", "equal", "(", "mScaleType", ",", "scaleType", ")", ")", "{", "return", ";", "}", "mScaleType", "=", "scaleType", ";", "mScaleTypeState", "=", "null", ";", "configureBounds", "(", ")", ";", "invalidateSelf", "(", ")", ";", "}" ]
Sets the scale type. @param scaleType scale type to set
[ "Sets", "the", "scale", "type", "." ]
0b85879d51c5036d5e46e627a6651afefc0b971a
https://github.com/facebook/fresco/blob/0b85879d51c5036d5e46e627a6651afefc0b971a/drawee/src/main/java/com/facebook/drawee/drawable/ScaleTypeDrawable.java#L90-L99
14,533
facebook/fresco
imagepipeline-base/src/main/java/com/facebook/cache/common/WriterCallbacks.java
WriterCallbacks.from
public static WriterCallback from(final byte[] data) { return new WriterCallback() { @Override public void write(OutputStream os) throws IOException { os.write(data); } }; }
java
public static WriterCallback from(final byte[] data) { return new WriterCallback() { @Override public void write(OutputStream os) throws IOException { os.write(data); } }; }
[ "public", "static", "WriterCallback", "from", "(", "final", "byte", "[", "]", "data", ")", "{", "return", "new", "WriterCallback", "(", ")", "{", "@", "Override", "public", "void", "write", "(", "OutputStream", "os", ")", "throws", "IOException", "{", "os", ".", "write", "(", "data", ")", ";", "}", "}", ";", "}" ]
Creates a writer callback that writes some byte array to the target stream. <p>This writer can be used many times. @param data the bytes to write @return the writer callback
[ "Creates", "a", "writer", "callback", "that", "writes", "some", "byte", "array", "to", "the", "target", "stream", "." ]
0b85879d51c5036d5e46e627a6651afefc0b971a
https://github.com/facebook/fresco/blob/0b85879d51c5036d5e46e627a6651afefc0b971a/imagepipeline-base/src/main/java/com/facebook/cache/common/WriterCallbacks.java#L44-L51
14,534
facebook/fresco
animated-base/src/main/java/com/facebook/imagepipeline/animated/impl/AnimatedImageCompositor.java
AnimatedImageCompositor.renderFrame
public void renderFrame(int frameNumber, Bitmap bitmap) { Canvas canvas = new Canvas(bitmap); canvas.drawColor(Color.TRANSPARENT, PorterDuff.Mode.SRC); // If blending is required, prepare the canvas with the nearest cached frame. int nextIndex; if (!isKeyFrame(frameNumber)) { // Blending is required. nextIndex points to the next index to render onto the canvas. nextIndex = prepareCanvasWithClosestCachedFrame(frameNumber - 1, canvas); } else { // Blending isn't required. Start at the frame we're trying to render. nextIndex = frameNumber; } // Iterate from nextIndex to the frame number just preceding the one we're trying to render // and composite them in order according to the Disposal Method. for (int index = nextIndex; index < frameNumber; index++) { AnimatedDrawableFrameInfo frameInfo = mAnimatedDrawableBackend.getFrameInfo(index); DisposalMethod disposalMethod = frameInfo.disposalMethod; if (disposalMethod == DisposalMethod.DISPOSE_TO_PREVIOUS) { continue; } if (frameInfo.blendOperation == BlendOperation.NO_BLEND) { disposeToBackground(canvas, frameInfo); } mAnimatedDrawableBackend.renderFrame(index, canvas); mCallback.onIntermediateResult(index, bitmap); if (disposalMethod == DisposalMethod.DISPOSE_TO_BACKGROUND) { disposeToBackground(canvas, frameInfo); } } AnimatedDrawableFrameInfo frameInfo = mAnimatedDrawableBackend.getFrameInfo(frameNumber); if (frameInfo.blendOperation == BlendOperation.NO_BLEND) { disposeToBackground(canvas, frameInfo); } // Finally, we render the current frame. We don't dispose it. mAnimatedDrawableBackend.renderFrame(frameNumber, canvas); }
java
public void renderFrame(int frameNumber, Bitmap bitmap) { Canvas canvas = new Canvas(bitmap); canvas.drawColor(Color.TRANSPARENT, PorterDuff.Mode.SRC); // If blending is required, prepare the canvas with the nearest cached frame. int nextIndex; if (!isKeyFrame(frameNumber)) { // Blending is required. nextIndex points to the next index to render onto the canvas. nextIndex = prepareCanvasWithClosestCachedFrame(frameNumber - 1, canvas); } else { // Blending isn't required. Start at the frame we're trying to render. nextIndex = frameNumber; } // Iterate from nextIndex to the frame number just preceding the one we're trying to render // and composite them in order according to the Disposal Method. for (int index = nextIndex; index < frameNumber; index++) { AnimatedDrawableFrameInfo frameInfo = mAnimatedDrawableBackend.getFrameInfo(index); DisposalMethod disposalMethod = frameInfo.disposalMethod; if (disposalMethod == DisposalMethod.DISPOSE_TO_PREVIOUS) { continue; } if (frameInfo.blendOperation == BlendOperation.NO_BLEND) { disposeToBackground(canvas, frameInfo); } mAnimatedDrawableBackend.renderFrame(index, canvas); mCallback.onIntermediateResult(index, bitmap); if (disposalMethod == DisposalMethod.DISPOSE_TO_BACKGROUND) { disposeToBackground(canvas, frameInfo); } } AnimatedDrawableFrameInfo frameInfo = mAnimatedDrawableBackend.getFrameInfo(frameNumber); if (frameInfo.blendOperation == BlendOperation.NO_BLEND) { disposeToBackground(canvas, frameInfo); } // Finally, we render the current frame. We don't dispose it. mAnimatedDrawableBackend.renderFrame(frameNumber, canvas); }
[ "public", "void", "renderFrame", "(", "int", "frameNumber", ",", "Bitmap", "bitmap", ")", "{", "Canvas", "canvas", "=", "new", "Canvas", "(", "bitmap", ")", ";", "canvas", ".", "drawColor", "(", "Color", ".", "TRANSPARENT", ",", "PorterDuff", ".", "Mode", ".", "SRC", ")", ";", "// If blending is required, prepare the canvas with the nearest cached frame.", "int", "nextIndex", ";", "if", "(", "!", "isKeyFrame", "(", "frameNumber", ")", ")", "{", "// Blending is required. nextIndex points to the next index to render onto the canvas.", "nextIndex", "=", "prepareCanvasWithClosestCachedFrame", "(", "frameNumber", "-", "1", ",", "canvas", ")", ";", "}", "else", "{", "// Blending isn't required. Start at the frame we're trying to render.", "nextIndex", "=", "frameNumber", ";", "}", "// Iterate from nextIndex to the frame number just preceding the one we're trying to render", "// and composite them in order according to the Disposal Method.", "for", "(", "int", "index", "=", "nextIndex", ";", "index", "<", "frameNumber", ";", "index", "++", ")", "{", "AnimatedDrawableFrameInfo", "frameInfo", "=", "mAnimatedDrawableBackend", ".", "getFrameInfo", "(", "index", ")", ";", "DisposalMethod", "disposalMethod", "=", "frameInfo", ".", "disposalMethod", ";", "if", "(", "disposalMethod", "==", "DisposalMethod", ".", "DISPOSE_TO_PREVIOUS", ")", "{", "continue", ";", "}", "if", "(", "frameInfo", ".", "blendOperation", "==", "BlendOperation", ".", "NO_BLEND", ")", "{", "disposeToBackground", "(", "canvas", ",", "frameInfo", ")", ";", "}", "mAnimatedDrawableBackend", ".", "renderFrame", "(", "index", ",", "canvas", ")", ";", "mCallback", ".", "onIntermediateResult", "(", "index", ",", "bitmap", ")", ";", "if", "(", "disposalMethod", "==", "DisposalMethod", ".", "DISPOSE_TO_BACKGROUND", ")", "{", "disposeToBackground", "(", "canvas", ",", "frameInfo", ")", ";", "}", "}", "AnimatedDrawableFrameInfo", "frameInfo", "=", "mAnimatedDrawableBackend", ".", "getFrameInfo", "(", "frameNumber", ")", ";", "if", "(", "frameInfo", ".", "blendOperation", "==", "BlendOperation", ".", "NO_BLEND", ")", "{", "disposeToBackground", "(", "canvas", ",", "frameInfo", ")", ";", "}", "// Finally, we render the current frame. We don't dispose it.", "mAnimatedDrawableBackend", ".", "renderFrame", "(", "frameNumber", ",", "canvas", ")", ";", "}" ]
Renders the specified frame. Only should be called on the rendering thread. @param frameNumber the frame to render @param bitmap the bitmap to render into
[ "Renders", "the", "specified", "frame", ".", "Only", "should", "be", "called", "on", "the", "rendering", "thread", "." ]
0b85879d51c5036d5e46e627a6651afefc0b971a
https://github.com/facebook/fresco/blob/0b85879d51c5036d5e46e627a6651afefc0b971a/animated-base/src/main/java/com/facebook/imagepipeline/animated/impl/AnimatedImageCompositor.java#L81-L119
14,535
facebook/fresco
animated-base/src/main/java/com/facebook/imagepipeline/animated/impl/AnimatedImageCompositor.java
AnimatedImageCompositor.prepareCanvasWithClosestCachedFrame
private int prepareCanvasWithClosestCachedFrame(int previousFrameNumber, Canvas canvas) { for (int index = previousFrameNumber; index >= 0; index--) { FrameNeededResult neededResult = isFrameNeededForRendering(index); switch (neededResult) { case REQUIRED: AnimatedDrawableFrameInfo frameInfo = mAnimatedDrawableBackend.getFrameInfo(index); CloseableReference<Bitmap> startBitmap = mCallback.getCachedBitmap(index); if (startBitmap != null) { try { canvas.drawBitmap(startBitmap.get(), 0, 0, null); if (frameInfo.disposalMethod == DisposalMethod.DISPOSE_TO_BACKGROUND) { disposeToBackground(canvas, frameInfo); } return index + 1; } finally { startBitmap.close(); } } else { if (isKeyFrame(index)) { return index; } else { // Keep going. break; } } case NOT_REQUIRED: return index + 1; case ABORT: return index; case SKIP: default: // Keep going. } } return 0; }
java
private int prepareCanvasWithClosestCachedFrame(int previousFrameNumber, Canvas canvas) { for (int index = previousFrameNumber; index >= 0; index--) { FrameNeededResult neededResult = isFrameNeededForRendering(index); switch (neededResult) { case REQUIRED: AnimatedDrawableFrameInfo frameInfo = mAnimatedDrawableBackend.getFrameInfo(index); CloseableReference<Bitmap> startBitmap = mCallback.getCachedBitmap(index); if (startBitmap != null) { try { canvas.drawBitmap(startBitmap.get(), 0, 0, null); if (frameInfo.disposalMethod == DisposalMethod.DISPOSE_TO_BACKGROUND) { disposeToBackground(canvas, frameInfo); } return index + 1; } finally { startBitmap.close(); } } else { if (isKeyFrame(index)) { return index; } else { // Keep going. break; } } case NOT_REQUIRED: return index + 1; case ABORT: return index; case SKIP: default: // Keep going. } } return 0; }
[ "private", "int", "prepareCanvasWithClosestCachedFrame", "(", "int", "previousFrameNumber", ",", "Canvas", "canvas", ")", "{", "for", "(", "int", "index", "=", "previousFrameNumber", ";", "index", ">=", "0", ";", "index", "--", ")", "{", "FrameNeededResult", "neededResult", "=", "isFrameNeededForRendering", "(", "index", ")", ";", "switch", "(", "neededResult", ")", "{", "case", "REQUIRED", ":", "AnimatedDrawableFrameInfo", "frameInfo", "=", "mAnimatedDrawableBackend", ".", "getFrameInfo", "(", "index", ")", ";", "CloseableReference", "<", "Bitmap", ">", "startBitmap", "=", "mCallback", ".", "getCachedBitmap", "(", "index", ")", ";", "if", "(", "startBitmap", "!=", "null", ")", "{", "try", "{", "canvas", ".", "drawBitmap", "(", "startBitmap", ".", "get", "(", ")", ",", "0", ",", "0", ",", "null", ")", ";", "if", "(", "frameInfo", ".", "disposalMethod", "==", "DisposalMethod", ".", "DISPOSE_TO_BACKGROUND", ")", "{", "disposeToBackground", "(", "canvas", ",", "frameInfo", ")", ";", "}", "return", "index", "+", "1", ";", "}", "finally", "{", "startBitmap", ".", "close", "(", ")", ";", "}", "}", "else", "{", "if", "(", "isKeyFrame", "(", "index", ")", ")", "{", "return", "index", ";", "}", "else", "{", "// Keep going.", "break", ";", "}", "}", "case", "NOT_REQUIRED", ":", "return", "index", "+", "1", ";", "case", "ABORT", ":", "return", "index", ";", "case", "SKIP", ":", "default", ":", "// Keep going.", "}", "}", "return", "0", ";", "}" ]
Given a frame number, prepares the canvas to render based on the nearest cached frame at or before the frame. On return the canvas will be prepared as if the nearest cached frame had been rendered and disposed. The returned index is the next frame that needs to be composited onto the canvas. @param previousFrameNumber the frame number that is ones less than the one we're rendering @param canvas the canvas to prepare @return the index of the the next frame to process
[ "Given", "a", "frame", "number", "prepares", "the", "canvas", "to", "render", "based", "on", "the", "nearest", "cached", "frame", "at", "or", "before", "the", "frame", ".", "On", "return", "the", "canvas", "will", "be", "prepared", "as", "if", "the", "nearest", "cached", "frame", "had", "been", "rendered", "and", "disposed", ".", "The", "returned", "index", "is", "the", "next", "frame", "that", "needs", "to", "be", "composited", "onto", "the", "canvas", "." ]
0b85879d51c5036d5e46e627a6651afefc0b971a
https://github.com/facebook/fresco/blob/0b85879d51c5036d5e46e627a6651afefc0b971a/animated-base/src/main/java/com/facebook/imagepipeline/animated/impl/AnimatedImageCompositor.java#L148-L183
14,536
facebook/fresco
animated-gif-lite/src/main/java/com/facebook/animated/giflite/drawable/GifAnimationBackend.java
GifAnimationBackend.scale
private void scale(int viewPortWidth, int viewPortHeight, int sourceWidth, int sourceHeight) { float inputRatio = ((float) sourceWidth) / sourceHeight; float outputRatio = ((float) viewPortWidth) / viewPortHeight; int scaledWidth = viewPortWidth; int scaledHeight = viewPortHeight; if (outputRatio > inputRatio) { // Not enough width to fill the output. (Black bars on left and right.) scaledWidth = (int) (viewPortHeight * inputRatio); scaledHeight = viewPortHeight; } else if (outputRatio < inputRatio) { // Not enough height to fill the output. (Black bars on top and bottom.) scaledHeight = (int) (viewPortWidth / inputRatio); scaledWidth = viewPortWidth; } float scale = scaledWidth / (float) sourceWidth; mMidX = ((viewPortWidth - scaledWidth) / 2f) / scale; mMidY = ((viewPortHeight - scaledHeight) / 2f) / scale; }
java
private void scale(int viewPortWidth, int viewPortHeight, int sourceWidth, int sourceHeight) { float inputRatio = ((float) sourceWidth) / sourceHeight; float outputRatio = ((float) viewPortWidth) / viewPortHeight; int scaledWidth = viewPortWidth; int scaledHeight = viewPortHeight; if (outputRatio > inputRatio) { // Not enough width to fill the output. (Black bars on left and right.) scaledWidth = (int) (viewPortHeight * inputRatio); scaledHeight = viewPortHeight; } else if (outputRatio < inputRatio) { // Not enough height to fill the output. (Black bars on top and bottom.) scaledHeight = (int) (viewPortWidth / inputRatio); scaledWidth = viewPortWidth; } float scale = scaledWidth / (float) sourceWidth; mMidX = ((viewPortWidth - scaledWidth) / 2f) / scale; mMidY = ((viewPortHeight - scaledHeight) / 2f) / scale; }
[ "private", "void", "scale", "(", "int", "viewPortWidth", ",", "int", "viewPortHeight", ",", "int", "sourceWidth", ",", "int", "sourceHeight", ")", "{", "float", "inputRatio", "=", "(", "(", "float", ")", "sourceWidth", ")", "/", "sourceHeight", ";", "float", "outputRatio", "=", "(", "(", "float", ")", "viewPortWidth", ")", "/", "viewPortHeight", ";", "int", "scaledWidth", "=", "viewPortWidth", ";", "int", "scaledHeight", "=", "viewPortHeight", ";", "if", "(", "outputRatio", ">", "inputRatio", ")", "{", "// Not enough width to fill the output. (Black bars on left and right.)", "scaledWidth", "=", "(", "int", ")", "(", "viewPortHeight", "*", "inputRatio", ")", ";", "scaledHeight", "=", "viewPortHeight", ";", "}", "else", "if", "(", "outputRatio", "<", "inputRatio", ")", "{", "// Not enough height to fill the output. (Black bars on top and bottom.)", "scaledHeight", "=", "(", "int", ")", "(", "viewPortWidth", "/", "inputRatio", ")", ";", "scaledWidth", "=", "viewPortWidth", ";", "}", "float", "scale", "=", "scaledWidth", "/", "(", "float", ")", "sourceWidth", ";", "mMidX", "=", "(", "(", "viewPortWidth", "-", "scaledWidth", ")", "/", "2f", ")", "/", "scale", ";", "mMidY", "=", "(", "(", "viewPortHeight", "-", "scaledHeight", ")", "/", "2f", ")", "/", "scale", ";", "}" ]
Measures the source, and sets the size based on them. Maintains aspect ratio of source, and ensures that screen is filled in at least one dimension. <p>Adapted from com.facebook.cameracore.common.RenderUtil#calculateFitRect @param viewPortWidth the width of the display @param viewPortHeight the height of the display @param sourceWidth the width of the video @param sourceHeight the height of the video
[ "Measures", "the", "source", "and", "sets", "the", "size", "based", "on", "them", ".", "Maintains", "aspect", "ratio", "of", "source", "and", "ensures", "that", "screen", "is", "filled", "in", "at", "least", "one", "dimension", "." ]
0b85879d51c5036d5e46e627a6651afefc0b971a
https://github.com/facebook/fresco/blob/0b85879d51c5036d5e46e627a6651afefc0b971a/animated-gif-lite/src/main/java/com/facebook/animated/giflite/drawable/GifAnimationBackend.java#L141-L161
14,537
facebook/fresco
animated-base/src/main/java/com/facebook/fresco/animation/bitmap/cache/FrescoFrameCache.java
FrescoFrameCache.convertToBitmapReferenceAndClose
@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); } }
java
@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); } }
[ "@", "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", ")", ";", "}", "}" ]
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
[ "Converts", "the", "given", "image", "reference", "to", "a", "bitmap", "reference", "and", "closes", "the", "original", "image", "reference", "." ]
0b85879d51c5036d5e46e627a6651afefc0b971a
https://github.com/facebook/fresco/blob/0b85879d51c5036d5e46e627a6651afefc0b971a/animated-base/src/main/java/com/facebook/fresco/animation/bitmap/cache/FrescoFrameCache.java#L182-L203
14,538
facebook/fresco
imagepipeline-base/src/main/java/com/facebook/cache/disk/DynamicDefaultDiskStorage.java
DynamicDefaultDiskStorage.get
@VisibleForTesting /* package protected */ synchronized DiskStorage get() throws IOException { if (shouldCreateNewStorage()) { // discard anything we created deleteOldStorageIfNecessary(); createStorage(); } return Preconditions.checkNotNull(mCurrentState.delegate); }
java
@VisibleForTesting /* package protected */ synchronized DiskStorage get() throws IOException { if (shouldCreateNewStorage()) { // discard anything we created deleteOldStorageIfNecessary(); createStorage(); } return Preconditions.checkNotNull(mCurrentState.delegate); }
[ "@", "VisibleForTesting", "/* package protected */", "synchronized", "DiskStorage", "get", "(", ")", "throws", "IOException", "{", "if", "(", "shouldCreateNewStorage", "(", ")", ")", "{", "// discard anything we created", "deleteOldStorageIfNecessary", "(", ")", ";", "createStorage", "(", ")", ";", "}", "return", "Preconditions", ".", "checkNotNull", "(", "mCurrentState", ".", "delegate", ")", ";", "}" ]
Gets a concrete disk-storage instance. If nothing has changed since the last call, then the last state is returned @return an instance of the appropriate DiskStorage class @throws IOException
[ "Gets", "a", "concrete", "disk", "-", "storage", "instance", ".", "If", "nothing", "has", "changed", "since", "the", "last", "call", "then", "the", "last", "state", "is", "returned" ]
0b85879d51c5036d5e46e627a6651afefc0b971a
https://github.com/facebook/fresco/blob/0b85879d51c5036d5e46e627a6651afefc0b971a/imagepipeline-base/src/main/java/com/facebook/cache/disk/DynamicDefaultDiskStorage.java#L151-L159
14,539
facebook/fresco
drawee/src/main/java/com/facebook/drawee/generic/WrappingUtils.java
WrappingUtils.wrapChildWithScaleType
static ScaleTypeDrawable wrapChildWithScaleType( DrawableParent parent, ScalingUtils.ScaleType scaleType) { Drawable child = parent.setDrawable(sEmptyDrawable); child = maybeWrapWithScaleType(child, scaleType); parent.setDrawable(child); Preconditions.checkNotNull(child, "Parent has no child drawable!"); return (ScaleTypeDrawable) child; }
java
static ScaleTypeDrawable wrapChildWithScaleType( DrawableParent parent, ScalingUtils.ScaleType scaleType) { Drawable child = parent.setDrawable(sEmptyDrawable); child = maybeWrapWithScaleType(child, scaleType); parent.setDrawable(child); Preconditions.checkNotNull(child, "Parent has no child drawable!"); return (ScaleTypeDrawable) child; }
[ "static", "ScaleTypeDrawable", "wrapChildWithScaleType", "(", "DrawableParent", "parent", ",", "ScalingUtils", ".", "ScaleType", "scaleType", ")", "{", "Drawable", "child", "=", "parent", ".", "setDrawable", "(", "sEmptyDrawable", ")", ";", "child", "=", "maybeWrapWithScaleType", "(", "child", ",", "scaleType", ")", ";", "parent", ".", "setDrawable", "(", "child", ")", ";", "Preconditions", ".", "checkNotNull", "(", "child", ",", "\"Parent has no child drawable!\"", ")", ";", "return", "(", "ScaleTypeDrawable", ")", "child", ";", "}" ]
Wraps the parent's child with a ScaleTypeDrawable.
[ "Wraps", "the", "parent", "s", "child", "with", "a", "ScaleTypeDrawable", "." ]
0b85879d51c5036d5e46e627a6651afefc0b971a
https://github.com/facebook/fresco/blob/0b85879d51c5036d5e46e627a6651afefc0b971a/drawee/src/main/java/com/facebook/drawee/generic/WrappingUtils.java#L124-L131
14,540
facebook/fresco
drawee/src/main/java/com/facebook/drawee/generic/WrappingUtils.java
WrappingUtils.applyRoundingParams
static void applyRoundingParams(Rounded rounded, RoundingParams roundingParams) { rounded.setCircle(roundingParams.getRoundAsCircle()); rounded.setRadii(roundingParams.getCornersRadii()); rounded.setBorder(roundingParams.getBorderColor(), roundingParams.getBorderWidth()); rounded.setPadding(roundingParams.getPadding()); rounded.setScaleDownInsideBorders(roundingParams.getScaleDownInsideBorders()); rounded.setPaintFilterBitmap(roundingParams.getPaintFilterBitmap()); }
java
static void applyRoundingParams(Rounded rounded, RoundingParams roundingParams) { rounded.setCircle(roundingParams.getRoundAsCircle()); rounded.setRadii(roundingParams.getCornersRadii()); rounded.setBorder(roundingParams.getBorderColor(), roundingParams.getBorderWidth()); rounded.setPadding(roundingParams.getPadding()); rounded.setScaleDownInsideBorders(roundingParams.getScaleDownInsideBorders()); rounded.setPaintFilterBitmap(roundingParams.getPaintFilterBitmap()); }
[ "static", "void", "applyRoundingParams", "(", "Rounded", "rounded", ",", "RoundingParams", "roundingParams", ")", "{", "rounded", ".", "setCircle", "(", "roundingParams", ".", "getRoundAsCircle", "(", ")", ")", ";", "rounded", ".", "setRadii", "(", "roundingParams", ".", "getCornersRadii", "(", ")", ")", ";", "rounded", ".", "setBorder", "(", "roundingParams", ".", "getBorderColor", "(", ")", ",", "roundingParams", ".", "getBorderWidth", "(", ")", ")", ";", "rounded", ".", "setPadding", "(", "roundingParams", ".", "getPadding", "(", ")", ")", ";", "rounded", ".", "setScaleDownInsideBorders", "(", "roundingParams", ".", "getScaleDownInsideBorders", "(", ")", ")", ";", "rounded", ".", "setPaintFilterBitmap", "(", "roundingParams", ".", "getPaintFilterBitmap", "(", ")", ")", ";", "}" ]
Applies the given rounding params on the specified rounded drawable.
[ "Applies", "the", "given", "rounding", "params", "on", "the", "specified", "rounded", "drawable", "." ]
0b85879d51c5036d5e46e627a6651afefc0b971a
https://github.com/facebook/fresco/blob/0b85879d51c5036d5e46e627a6651afefc0b971a/drawee/src/main/java/com/facebook/drawee/generic/WrappingUtils.java#L329-L336
14,541
facebook/fresco
drawee/src/main/java/com/facebook/drawee/generic/WrappingUtils.java
WrappingUtils.resetRoundingParams
static void resetRoundingParams(Rounded rounded) { rounded.setCircle(false); rounded.setRadius(0); rounded.setBorder(Color.TRANSPARENT, 0); rounded.setPadding(0); rounded.setScaleDownInsideBorders(false); rounded.setPaintFilterBitmap(false); }
java
static void resetRoundingParams(Rounded rounded) { rounded.setCircle(false); rounded.setRadius(0); rounded.setBorder(Color.TRANSPARENT, 0); rounded.setPadding(0); rounded.setScaleDownInsideBorders(false); rounded.setPaintFilterBitmap(false); }
[ "static", "void", "resetRoundingParams", "(", "Rounded", "rounded", ")", "{", "rounded", ".", "setCircle", "(", "false", ")", ";", "rounded", ".", "setRadius", "(", "0", ")", ";", "rounded", ".", "setBorder", "(", "Color", ".", "TRANSPARENT", ",", "0", ")", ";", "rounded", ".", "setPadding", "(", "0", ")", ";", "rounded", ".", "setScaleDownInsideBorders", "(", "false", ")", ";", "rounded", ".", "setPaintFilterBitmap", "(", "false", ")", ";", "}" ]
Resets the rounding params on the specified rounded drawable, so that no rounding occurs.
[ "Resets", "the", "rounding", "params", "on", "the", "specified", "rounded", "drawable", "so", "that", "no", "rounding", "occurs", "." ]
0b85879d51c5036d5e46e627a6651afefc0b971a
https://github.com/facebook/fresco/blob/0b85879d51c5036d5e46e627a6651afefc0b971a/drawee/src/main/java/com/facebook/drawee/generic/WrappingUtils.java#L341-L348
14,542
facebook/fresco
drawee/src/main/java/com/facebook/drawee/generic/WrappingUtils.java
WrappingUtils.findDrawableParentForLeaf
static DrawableParent findDrawableParentForLeaf(DrawableParent parent) { while (true) { Drawable child = parent.getDrawable(); if (child == parent || !(child instanceof DrawableParent)) { break; } parent = (DrawableParent) child; } return parent; }
java
static DrawableParent findDrawableParentForLeaf(DrawableParent parent) { while (true) { Drawable child = parent.getDrawable(); if (child == parent || !(child instanceof DrawableParent)) { break; } parent = (DrawableParent) child; } return parent; }
[ "static", "DrawableParent", "findDrawableParentForLeaf", "(", "DrawableParent", "parent", ")", "{", "while", "(", "true", ")", "{", "Drawable", "child", "=", "parent", ".", "getDrawable", "(", ")", ";", "if", "(", "child", "==", "parent", "||", "!", "(", "child", "instanceof", "DrawableParent", ")", ")", "{", "break", ";", "}", "parent", "=", "(", "DrawableParent", ")", "child", ";", "}", "return", "parent", ";", "}" ]
Finds the immediate parent of a leaf drawable.
[ "Finds", "the", "immediate", "parent", "of", "a", "leaf", "drawable", "." ]
0b85879d51c5036d5e46e627a6651afefc0b971a
https://github.com/facebook/fresco/blob/0b85879d51c5036d5e46e627a6651afefc0b971a/drawee/src/main/java/com/facebook/drawee/generic/WrappingUtils.java#L353-L362
14,543
facebook/fresco
imagepipeline/src/main/java/com/facebook/imagepipeline/platform/OreoDecoder.java
OreoDecoder.hasColorGamutMismatch
private static boolean hasColorGamutMismatch(final BitmapFactory.Options options) { return options.outColorSpace != null && options.outColorSpace.isWideGamut() && options.inPreferredConfig != Bitmap.Config.RGBA_F16; }
java
private static boolean hasColorGamutMismatch(final BitmapFactory.Options options) { return options.outColorSpace != null && options.outColorSpace.isWideGamut() && options.inPreferredConfig != Bitmap.Config.RGBA_F16; }
[ "private", "static", "boolean", "hasColorGamutMismatch", "(", "final", "BitmapFactory", ".", "Options", "options", ")", "{", "return", "options", ".", "outColorSpace", "!=", "null", "&&", "options", ".", "outColorSpace", ".", "isWideGamut", "(", ")", "&&", "options", ".", "inPreferredConfig", "!=", "Bitmap", ".", "Config", ".", "RGBA_F16", ";", "}" ]
Check if the color space has a wide color gamut and is consistent with the Bitmap config
[ "Check", "if", "the", "color", "space", "has", "a", "wide", "color", "gamut", "and", "is", "consistent", "with", "the", "Bitmap", "config" ]
0b85879d51c5036d5e46e627a6651afefc0b971a
https://github.com/facebook/fresco/blob/0b85879d51c5036d5e46e627a6651afefc0b971a/imagepipeline/src/main/java/com/facebook/imagepipeline/platform/OreoDecoder.java#L39-L43
14,544
facebook/fresco
samples/comparison/src/main/java/com/facebook/samples/comparison/configs/imagepipeline/ImagePipelineConfigFactory.java
ImagePipelineConfigFactory.getImagePipelineConfig
public static ImagePipelineConfig getImagePipelineConfig(Context context) { if (sImagePipelineConfig == null) { ImagePipelineConfig.Builder configBuilder = ImagePipelineConfig.newBuilder(context); configureCaches(configBuilder, context); configureLoggingListeners(configBuilder); configureOptions(configBuilder); sImagePipelineConfig = configBuilder.build(); } return sImagePipelineConfig; }
java
public static ImagePipelineConfig getImagePipelineConfig(Context context) { if (sImagePipelineConfig == null) { ImagePipelineConfig.Builder configBuilder = ImagePipelineConfig.newBuilder(context); configureCaches(configBuilder, context); configureLoggingListeners(configBuilder); configureOptions(configBuilder); sImagePipelineConfig = configBuilder.build(); } return sImagePipelineConfig; }
[ "public", "static", "ImagePipelineConfig", "getImagePipelineConfig", "(", "Context", "context", ")", "{", "if", "(", "sImagePipelineConfig", "==", "null", ")", "{", "ImagePipelineConfig", ".", "Builder", "configBuilder", "=", "ImagePipelineConfig", ".", "newBuilder", "(", "context", ")", ";", "configureCaches", "(", "configBuilder", ",", "context", ")", ";", "configureLoggingListeners", "(", "configBuilder", ")", ";", "configureOptions", "(", "configBuilder", ")", ";", "sImagePipelineConfig", "=", "configBuilder", ".", "build", "(", ")", ";", "}", "return", "sImagePipelineConfig", ";", "}" ]
Creates config using android http stack as network backend.
[ "Creates", "config", "using", "android", "http", "stack", "as", "network", "backend", "." ]
0b85879d51c5036d5e46e627a6651afefc0b971a
https://github.com/facebook/fresco/blob/0b85879d51c5036d5e46e627a6651afefc0b971a/samples/comparison/src/main/java/com/facebook/samples/comparison/configs/imagepipeline/ImagePipelineConfigFactory.java#L43-L52
14,545
facebook/fresco
samples/comparison/src/main/java/com/facebook/samples/comparison/configs/imagepipeline/ImagePipelineConfigFactory.java
ImagePipelineConfigFactory.getOkHttpImagePipelineConfig
public static ImagePipelineConfig getOkHttpImagePipelineConfig(Context context) { if (sOkHttpImagePipelineConfig == null) { OkHttpClient okHttpClient = new OkHttpClient.Builder() .addNetworkInterceptor(new StethoInterceptor()) .build(); ImagePipelineConfig.Builder configBuilder = OkHttpImagePipelineConfigFactory.newBuilder(context, okHttpClient); configureCaches(configBuilder, context); configureLoggingListeners(configBuilder); sOkHttpImagePipelineConfig = configBuilder.build(); } return sOkHttpImagePipelineConfig; }
java
public static ImagePipelineConfig getOkHttpImagePipelineConfig(Context context) { if (sOkHttpImagePipelineConfig == null) { OkHttpClient okHttpClient = new OkHttpClient.Builder() .addNetworkInterceptor(new StethoInterceptor()) .build(); ImagePipelineConfig.Builder configBuilder = OkHttpImagePipelineConfigFactory.newBuilder(context, okHttpClient); configureCaches(configBuilder, context); configureLoggingListeners(configBuilder); sOkHttpImagePipelineConfig = configBuilder.build(); } return sOkHttpImagePipelineConfig; }
[ "public", "static", "ImagePipelineConfig", "getOkHttpImagePipelineConfig", "(", "Context", "context", ")", "{", "if", "(", "sOkHttpImagePipelineConfig", "==", "null", ")", "{", "OkHttpClient", "okHttpClient", "=", "new", "OkHttpClient", ".", "Builder", "(", ")", ".", "addNetworkInterceptor", "(", "new", "StethoInterceptor", "(", ")", ")", ".", "build", "(", ")", ";", "ImagePipelineConfig", ".", "Builder", "configBuilder", "=", "OkHttpImagePipelineConfigFactory", ".", "newBuilder", "(", "context", ",", "okHttpClient", ")", ";", "configureCaches", "(", "configBuilder", ",", "context", ")", ";", "configureLoggingListeners", "(", "configBuilder", ")", ";", "sOkHttpImagePipelineConfig", "=", "configBuilder", ".", "build", "(", ")", ";", "}", "return", "sOkHttpImagePipelineConfig", ";", "}" ]
Creates config using OkHttp as network backed.
[ "Creates", "config", "using", "OkHttp", "as", "network", "backed", "." ]
0b85879d51c5036d5e46e627a6651afefc0b971a
https://github.com/facebook/fresco/blob/0b85879d51c5036d5e46e627a6651afefc0b971a/samples/comparison/src/main/java/com/facebook/samples/comparison/configs/imagepipeline/ImagePipelineConfigFactory.java#L57-L69
14,546
facebook/fresco
samples/comparison/src/main/java/com/facebook/samples/comparison/configs/imagepipeline/ImagePipelineConfigFactory.java
ImagePipelineConfigFactory.configureCaches
private static void configureCaches( ImagePipelineConfig.Builder configBuilder, Context context) { final MemoryCacheParams bitmapCacheParams = new MemoryCacheParams( ConfigConstants.MAX_MEMORY_CACHE_SIZE, // Max total size of elements in the cache Integer.MAX_VALUE, // Max entries in the cache ConfigConstants.MAX_MEMORY_CACHE_SIZE, // Max total size of elements in eviction queue Integer.MAX_VALUE, // Max length of eviction queue Integer.MAX_VALUE, // Max cache entry size TimeUnit.MINUTES.toMillis(5)); // Interval for checking cache parameters configBuilder .setBitmapMemoryCacheParamsSupplier( new Supplier<MemoryCacheParams>() { public MemoryCacheParams get() { return bitmapCacheParams; } }) .setMainDiskCacheConfig( DiskCacheConfig.newBuilder(context) .setBaseDirectoryPath(context.getApplicationContext().getCacheDir()) .setBaseDirectoryName(IMAGE_PIPELINE_CACHE_DIR) .setMaxCacheSize(ConfigConstants.MAX_DISK_CACHE_SIZE) .build()); }
java
private static void configureCaches( ImagePipelineConfig.Builder configBuilder, Context context) { final MemoryCacheParams bitmapCacheParams = new MemoryCacheParams( ConfigConstants.MAX_MEMORY_CACHE_SIZE, // Max total size of elements in the cache Integer.MAX_VALUE, // Max entries in the cache ConfigConstants.MAX_MEMORY_CACHE_SIZE, // Max total size of elements in eviction queue Integer.MAX_VALUE, // Max length of eviction queue Integer.MAX_VALUE, // Max cache entry size TimeUnit.MINUTES.toMillis(5)); // Interval for checking cache parameters configBuilder .setBitmapMemoryCacheParamsSupplier( new Supplier<MemoryCacheParams>() { public MemoryCacheParams get() { return bitmapCacheParams; } }) .setMainDiskCacheConfig( DiskCacheConfig.newBuilder(context) .setBaseDirectoryPath(context.getApplicationContext().getCacheDir()) .setBaseDirectoryName(IMAGE_PIPELINE_CACHE_DIR) .setMaxCacheSize(ConfigConstants.MAX_DISK_CACHE_SIZE) .build()); }
[ "private", "static", "void", "configureCaches", "(", "ImagePipelineConfig", ".", "Builder", "configBuilder", ",", "Context", "context", ")", "{", "final", "MemoryCacheParams", "bitmapCacheParams", "=", "new", "MemoryCacheParams", "(", "ConfigConstants", ".", "MAX_MEMORY_CACHE_SIZE", ",", "// Max total size of elements in the cache", "Integer", ".", "MAX_VALUE", ",", "// Max entries in the cache", "ConfigConstants", ".", "MAX_MEMORY_CACHE_SIZE", ",", "// Max total size of elements in eviction queue", "Integer", ".", "MAX_VALUE", ",", "// Max length of eviction queue", "Integer", ".", "MAX_VALUE", ",", "// Max cache entry size", "TimeUnit", ".", "MINUTES", ".", "toMillis", "(", "5", ")", ")", ";", "// Interval for checking cache parameters", "configBuilder", ".", "setBitmapMemoryCacheParamsSupplier", "(", "new", "Supplier", "<", "MemoryCacheParams", ">", "(", ")", "{", "public", "MemoryCacheParams", "get", "(", ")", "{", "return", "bitmapCacheParams", ";", "}", "}", ")", ".", "setMainDiskCacheConfig", "(", "DiskCacheConfig", ".", "newBuilder", "(", "context", ")", ".", "setBaseDirectoryPath", "(", "context", ".", "getApplicationContext", "(", ")", ".", "getCacheDir", "(", ")", ")", ".", "setBaseDirectoryName", "(", "IMAGE_PIPELINE_CACHE_DIR", ")", ".", "setMaxCacheSize", "(", "ConfigConstants", ".", "MAX_DISK_CACHE_SIZE", ")", ".", "build", "(", ")", ")", ";", "}" ]
Configures disk and memory cache not to exceed common limits
[ "Configures", "disk", "and", "memory", "cache", "not", "to", "exceed", "common", "limits" ]
0b85879d51c5036d5e46e627a6651afefc0b971a
https://github.com/facebook/fresco/blob/0b85879d51c5036d5e46e627a6651afefc0b971a/samples/comparison/src/main/java/com/facebook/samples/comparison/configs/imagepipeline/ImagePipelineConfigFactory.java#L74-L97
14,547
facebook/fresco
imagepipeline-base/src/main/java/com/facebook/imagepipeline/image/CloseableStaticBitmap.java
CloseableStaticBitmap.close
@Override public void close() { CloseableReference<Bitmap> reference = detachBitmapReference(); if (reference != null) { reference.close(); } }
java
@Override public void close() { CloseableReference<Bitmap> reference = detachBitmapReference(); if (reference != null) { reference.close(); } }
[ "@", "Override", "public", "void", "close", "(", ")", "{", "CloseableReference", "<", "Bitmap", ">", "reference", "=", "detachBitmapReference", "(", ")", ";", "if", "(", "reference", "!=", "null", ")", "{", "reference", ".", "close", "(", ")", ";", "}", "}" ]
Releases the bitmap to the pool.
[ "Releases", "the", "bitmap", "to", "the", "pool", "." ]
0b85879d51c5036d5e46e627a6651afefc0b971a
https://github.com/facebook/fresco/blob/0b85879d51c5036d5e46e627a6651afefc0b971a/imagepipeline-base/src/main/java/com/facebook/imagepipeline/image/CloseableStaticBitmap.java#L106-L112
14,548
facebook/fresco
imagepipeline/src/main/java/com/facebook/imagepipeline/memory/Bucket.java
Bucket.get
@Deprecated @Nullable public V get() { V value = pop(); if (value != null) { mInUseLength++; } return value; }
java
@Deprecated @Nullable public V get() { V value = pop(); if (value != null) { mInUseLength++; } return value; }
[ "@", "Deprecated", "@", "Nullable", "public", "V", "get", "(", ")", "{", "V", "value", "=", "pop", "(", ")", ";", "if", "(", "value", "!=", "null", ")", "{", "mInUseLength", "++", ";", "}", "return", "value", ";", "}" ]
Gets a free item if possible from the freelist. Returns null if the free list is empty Updates the bucket inUse count @return an item from the free list, if available @deprecated use {@link BasePool#getValue(Bucket)}
[ "Gets", "a", "free", "item", "if", "possible", "from", "the", "freelist", ".", "Returns", "null", "if", "the", "free", "list", "is", "empty", "Updates", "the", "bucket", "inUse", "count" ]
0b85879d51c5036d5e46e627a6651afefc0b971a
https://github.com/facebook/fresco/blob/0b85879d51c5036d5e46e627a6651afefc0b971a/imagepipeline/src/main/java/com/facebook/imagepipeline/memory/Bucket.java#L92-L100
14,549
facebook/fresco
imagepipeline/src/main/java/com/facebook/imagepipeline/memory/Bucket.java
Bucket.release
public void release(V value) { Preconditions.checkNotNull(value); if (mFixBucketsReinitialization) { // Proper way Preconditions.checkState(mInUseLength > 0); mInUseLength--; addToFreeList(value); } else { // Keep using previous adhoc if (mInUseLength > 0) { mInUseLength--; addToFreeList(value); } else { FLog.e(TAG, "Tried to release value %s from an empty bucket!", value); } } }
java
public void release(V value) { Preconditions.checkNotNull(value); if (mFixBucketsReinitialization) { // Proper way Preconditions.checkState(mInUseLength > 0); mInUseLength--; addToFreeList(value); } else { // Keep using previous adhoc if (mInUseLength > 0) { mInUseLength--; addToFreeList(value); } else { FLog.e(TAG, "Tried to release value %s from an empty bucket!", value); } } }
[ "public", "void", "release", "(", "V", "value", ")", "{", "Preconditions", ".", "checkNotNull", "(", "value", ")", ";", "if", "(", "mFixBucketsReinitialization", ")", "{", "// Proper way", "Preconditions", ".", "checkState", "(", "mInUseLength", ">", "0", ")", ";", "mInUseLength", "--", ";", "addToFreeList", "(", "value", ")", ";", "}", "else", "{", "// Keep using previous adhoc", "if", "(", "mInUseLength", ">", "0", ")", "{", "mInUseLength", "--", ";", "addToFreeList", "(", "value", ")", ";", "}", "else", "{", "FLog", ".", "e", "(", "TAG", ",", "\"Tried to release value %s from an empty bucket!\"", ",", "value", ")", ";", "}", "}", "}" ]
Releases a value to this bucket and decrements the inUse count @param value the value to release
[ "Releases", "a", "value", "to", "this", "bucket", "and", "decrements", "the", "inUse", "count" ]
0b85879d51c5036d5e46e627a6651afefc0b971a
https://github.com/facebook/fresco/blob/0b85879d51c5036d5e46e627a6651afefc0b971a/imagepipeline/src/main/java/com/facebook/imagepipeline/memory/Bucket.java#L125-L141
14,550
facebook/fresco
fbcore/src/main/java/com/facebook/datasource/IncreasingQualityDataSourceSupplier.java
IncreasingQualityDataSourceSupplier.create
public static <T> IncreasingQualityDataSourceSupplier<T> create( List<Supplier<DataSource<T>>> dataSourceSuppliers) { return create(dataSourceSuppliers, false); }
java
public static <T> IncreasingQualityDataSourceSupplier<T> create( List<Supplier<DataSource<T>>> dataSourceSuppliers) { return create(dataSourceSuppliers, false); }
[ "public", "static", "<", "T", ">", "IncreasingQualityDataSourceSupplier", "<", "T", ">", "create", "(", "List", "<", "Supplier", "<", "DataSource", "<", "T", ">", ">", ">", "dataSourceSuppliers", ")", "{", "return", "create", "(", "dataSourceSuppliers", ",", "false", ")", ";", "}" ]
Creates a new data source supplier with increasing-quality strategy. <p>Note: for performance reasons the list doesn't get cloned, so the caller of this method should not modify the list once passed in here. @param dataSourceSuppliers list of underlying suppliers
[ "Creates", "a", "new", "data", "source", "supplier", "with", "increasing", "-", "quality", "strategy", "." ]
0b85879d51c5036d5e46e627a6651afefc0b971a
https://github.com/facebook/fresco/blob/0b85879d51c5036d5e46e627a6651afefc0b971a/fbcore/src/main/java/com/facebook/datasource/IncreasingQualityDataSourceSupplier.java#L55-L58
14,551
facebook/fresco
fbcore/src/main/java/com/facebook/datasource/IncreasingQualityDataSourceSupplier.java
IncreasingQualityDataSourceSupplier.create
public static <T> IncreasingQualityDataSourceSupplier<T> create( List<Supplier<DataSource<T>>> dataSourceSuppliers, boolean dataSourceLazy) { return new IncreasingQualityDataSourceSupplier<T>(dataSourceSuppliers, dataSourceLazy); }
java
public static <T> IncreasingQualityDataSourceSupplier<T> create( List<Supplier<DataSource<T>>> dataSourceSuppliers, boolean dataSourceLazy) { return new IncreasingQualityDataSourceSupplier<T>(dataSourceSuppliers, dataSourceLazy); }
[ "public", "static", "<", "T", ">", "IncreasingQualityDataSourceSupplier", "<", "T", ">", "create", "(", "List", "<", "Supplier", "<", "DataSource", "<", "T", ">", ">", ">", "dataSourceSuppliers", ",", "boolean", "dataSourceLazy", ")", "{", "return", "new", "IncreasingQualityDataSourceSupplier", "<", "T", ">", "(", "dataSourceSuppliers", ",", "dataSourceLazy", ")", ";", "}" ]
Creates a new data source supplier with increasing-quality strategy with optional lazy state creation. <p>Note: for performance reasons the list doesn't get cloned, so the caller of this method should not modify the list once passed in here. @param dataSourceSuppliers list of underlying suppliers @param dataSourceLazy if true, the state of data source would be created only if necessary
[ "Creates", "a", "new", "data", "source", "supplier", "with", "increasing", "-", "quality", "strategy", "with", "optional", "lazy", "state", "creation", "." ]
0b85879d51c5036d5e46e627a6651afefc0b971a
https://github.com/facebook/fresco/blob/0b85879d51c5036d5e46e627a6651afefc0b971a/fbcore/src/main/java/com/facebook/datasource/IncreasingQualityDataSourceSupplier.java#L70-L73
14,552
facebook/fresco
samples/gestures/src/main/java/com/facebook/samples/gestures/TransformGestureDetector.java
TransformGestureDetector.getTranslationX
public float getTranslationX() { return calcAverage(mDetector.getCurrentX(), mDetector.getPointerCount()) - calcAverage(mDetector.getStartX(), mDetector.getPointerCount()); }
java
public float getTranslationX() { return calcAverage(mDetector.getCurrentX(), mDetector.getPointerCount()) - calcAverage(mDetector.getStartX(), mDetector.getPointerCount()); }
[ "public", "float", "getTranslationX", "(", ")", "{", "return", "calcAverage", "(", "mDetector", ".", "getCurrentX", "(", ")", ",", "mDetector", ".", "getPointerCount", "(", ")", ")", "-", "calcAverage", "(", "mDetector", ".", "getStartX", "(", ")", ",", "mDetector", ".", "getPointerCount", "(", ")", ")", ";", "}" ]
Gets the X component of the translation
[ "Gets", "the", "X", "component", "of", "the", "translation" ]
0b85879d51c5036d5e46e627a6651afefc0b971a
https://github.com/facebook/fresco/blob/0b85879d51c5036d5e46e627a6651afefc0b971a/samples/gestures/src/main/java/com/facebook/samples/gestures/TransformGestureDetector.java#L136-L139
14,553
facebook/fresco
samples/gestures/src/main/java/com/facebook/samples/gestures/TransformGestureDetector.java
TransformGestureDetector.getTranslationY
public float getTranslationY() { return calcAverage(mDetector.getCurrentY(), mDetector.getPointerCount()) - calcAverage(mDetector.getStartY(), mDetector.getPointerCount()); }
java
public float getTranslationY() { return calcAverage(mDetector.getCurrentY(), mDetector.getPointerCount()) - calcAverage(mDetector.getStartY(), mDetector.getPointerCount()); }
[ "public", "float", "getTranslationY", "(", ")", "{", "return", "calcAverage", "(", "mDetector", ".", "getCurrentY", "(", ")", ",", "mDetector", ".", "getPointerCount", "(", ")", ")", "-", "calcAverage", "(", "mDetector", ".", "getStartY", "(", ")", ",", "mDetector", ".", "getPointerCount", "(", ")", ")", ";", "}" ]
Gets the Y component of the translation
[ "Gets", "the", "Y", "component", "of", "the", "translation" ]
0b85879d51c5036d5e46e627a6651afefc0b971a
https://github.com/facebook/fresco/blob/0b85879d51c5036d5e46e627a6651afefc0b971a/samples/gestures/src/main/java/com/facebook/samples/gestures/TransformGestureDetector.java#L142-L145
14,554
facebook/fresco
samples/gestures/src/main/java/com/facebook/samples/gestures/TransformGestureDetector.java
TransformGestureDetector.getScale
public float getScale() { if (mDetector.getPointerCount() < 2) { return 1; } else { float startDeltaX = mDetector.getStartX()[1] - mDetector.getStartX()[0]; float startDeltaY = mDetector.getStartY()[1] - mDetector.getStartY()[0]; float currentDeltaX = mDetector.getCurrentX()[1] - mDetector.getCurrentX()[0]; float currentDeltaY = mDetector.getCurrentY()[1] - mDetector.getCurrentY()[0]; float startDist = (float) Math.hypot(startDeltaX, startDeltaY); float currentDist = (float) Math.hypot(currentDeltaX, currentDeltaY); return currentDist / startDist; } }
java
public float getScale() { if (mDetector.getPointerCount() < 2) { return 1; } else { float startDeltaX = mDetector.getStartX()[1] - mDetector.getStartX()[0]; float startDeltaY = mDetector.getStartY()[1] - mDetector.getStartY()[0]; float currentDeltaX = mDetector.getCurrentX()[1] - mDetector.getCurrentX()[0]; float currentDeltaY = mDetector.getCurrentY()[1] - mDetector.getCurrentY()[0]; float startDist = (float) Math.hypot(startDeltaX, startDeltaY); float currentDist = (float) Math.hypot(currentDeltaX, currentDeltaY); return currentDist / startDist; } }
[ "public", "float", "getScale", "(", ")", "{", "if", "(", "mDetector", ".", "getPointerCount", "(", ")", "<", "2", ")", "{", "return", "1", ";", "}", "else", "{", "float", "startDeltaX", "=", "mDetector", ".", "getStartX", "(", ")", "[", "1", "]", "-", "mDetector", ".", "getStartX", "(", ")", "[", "0", "]", ";", "float", "startDeltaY", "=", "mDetector", ".", "getStartY", "(", ")", "[", "1", "]", "-", "mDetector", ".", "getStartY", "(", ")", "[", "0", "]", ";", "float", "currentDeltaX", "=", "mDetector", ".", "getCurrentX", "(", ")", "[", "1", "]", "-", "mDetector", ".", "getCurrentX", "(", ")", "[", "0", "]", ";", "float", "currentDeltaY", "=", "mDetector", ".", "getCurrentY", "(", ")", "[", "1", "]", "-", "mDetector", ".", "getCurrentY", "(", ")", "[", "0", "]", ";", "float", "startDist", "=", "(", "float", ")", "Math", ".", "hypot", "(", "startDeltaX", ",", "startDeltaY", ")", ";", "float", "currentDist", "=", "(", "float", ")", "Math", ".", "hypot", "(", "currentDeltaX", ",", "currentDeltaY", ")", ";", "return", "currentDist", "/", "startDist", ";", "}", "}" ]
Gets the scale
[ "Gets", "the", "scale" ]
0b85879d51c5036d5e46e627a6651afefc0b971a
https://github.com/facebook/fresco/blob/0b85879d51c5036d5e46e627a6651afefc0b971a/samples/gestures/src/main/java/com/facebook/samples/gestures/TransformGestureDetector.java#L148-L160
14,555
facebook/fresco
samples/gestures/src/main/java/com/facebook/samples/gestures/TransformGestureDetector.java
TransformGestureDetector.getRotation
public float getRotation() { if (mDetector.getPointerCount() < 2) { return 0; } else { float startDeltaX = mDetector.getStartX()[1] - mDetector.getStartX()[0]; float startDeltaY = mDetector.getStartY()[1] - mDetector.getStartY()[0]; float currentDeltaX = mDetector.getCurrentX()[1] - mDetector.getCurrentX()[0]; float currentDeltaY = mDetector.getCurrentY()[1] - mDetector.getCurrentY()[0]; float startAngle = (float) Math.atan2(startDeltaY, startDeltaX); float currentAngle = (float) Math.atan2(currentDeltaY, currentDeltaX); return currentAngle - startAngle; } }
java
public float getRotation() { if (mDetector.getPointerCount() < 2) { return 0; } else { float startDeltaX = mDetector.getStartX()[1] - mDetector.getStartX()[0]; float startDeltaY = mDetector.getStartY()[1] - mDetector.getStartY()[0]; float currentDeltaX = mDetector.getCurrentX()[1] - mDetector.getCurrentX()[0]; float currentDeltaY = mDetector.getCurrentY()[1] - mDetector.getCurrentY()[0]; float startAngle = (float) Math.atan2(startDeltaY, startDeltaX); float currentAngle = (float) Math.atan2(currentDeltaY, currentDeltaX); return currentAngle - startAngle; } }
[ "public", "float", "getRotation", "(", ")", "{", "if", "(", "mDetector", ".", "getPointerCount", "(", ")", "<", "2", ")", "{", "return", "0", ";", "}", "else", "{", "float", "startDeltaX", "=", "mDetector", ".", "getStartX", "(", ")", "[", "1", "]", "-", "mDetector", ".", "getStartX", "(", ")", "[", "0", "]", ";", "float", "startDeltaY", "=", "mDetector", ".", "getStartY", "(", ")", "[", "1", "]", "-", "mDetector", ".", "getStartY", "(", ")", "[", "0", "]", ";", "float", "currentDeltaX", "=", "mDetector", ".", "getCurrentX", "(", ")", "[", "1", "]", "-", "mDetector", ".", "getCurrentX", "(", ")", "[", "0", "]", ";", "float", "currentDeltaY", "=", "mDetector", ".", "getCurrentY", "(", ")", "[", "1", "]", "-", "mDetector", ".", "getCurrentY", "(", ")", "[", "0", "]", ";", "float", "startAngle", "=", "(", "float", ")", "Math", ".", "atan2", "(", "startDeltaY", ",", "startDeltaX", ")", ";", "float", "currentAngle", "=", "(", "float", ")", "Math", ".", "atan2", "(", "currentDeltaY", ",", "currentDeltaX", ")", ";", "return", "currentAngle", "-", "startAngle", ";", "}", "}" ]
Gets the rotation in radians
[ "Gets", "the", "rotation", "in", "radians" ]
0b85879d51c5036d5e46e627a6651afefc0b971a
https://github.com/facebook/fresco/blob/0b85879d51c5036d5e46e627a6651afefc0b971a/samples/gestures/src/main/java/com/facebook/samples/gestures/TransformGestureDetector.java#L163-L175
14,556
facebook/fresco
tools/stetho/src/main/java/com/facebook/imagepipeline/stetho/BaseFrescoStethoPlugin.java
BaseFrescoStethoPlugin.dump
@Override public void dump(DumperContext dumpContext) throws DumpException { ensureInitialized(); List<String> args = dumpContext.getArgsAsList(); PrintStream writer = dumpContext.getStdout(); String cmd = args.isEmpty() ? null : args.get(0); List<String> rest = args.isEmpty() ? new ArrayList<String>() : args.subList(1, args.size()); if (cmd != null && cmd.equals("memcache")) { memcache(writer, rest); } else if (cmd != null && cmd.equals("diskcache")) { diskcache(mMainFileCache, "Main", writer, rest); diskcache(mSmallFileCache, "Small", writer, rest); } else { usage(writer); if (TextUtils.isEmpty(cmd)) { throw new DumpUsageException("Missing command"); } else { throw new DumpUsageException("Unknown command: " + cmd); } } }
java
@Override public void dump(DumperContext dumpContext) throws DumpException { ensureInitialized(); List<String> args = dumpContext.getArgsAsList(); PrintStream writer = dumpContext.getStdout(); String cmd = args.isEmpty() ? null : args.get(0); List<String> rest = args.isEmpty() ? new ArrayList<String>() : args.subList(1, args.size()); if (cmd != null && cmd.equals("memcache")) { memcache(writer, rest); } else if (cmd != null && cmd.equals("diskcache")) { diskcache(mMainFileCache, "Main", writer, rest); diskcache(mSmallFileCache, "Small", writer, rest); } else { usage(writer); if (TextUtils.isEmpty(cmd)) { throw new DumpUsageException("Missing command"); } else { throw new DumpUsageException("Unknown command: " + cmd); } } }
[ "@", "Override", "public", "void", "dump", "(", "DumperContext", "dumpContext", ")", "throws", "DumpException", "{", "ensureInitialized", "(", ")", ";", "List", "<", "String", ">", "args", "=", "dumpContext", ".", "getArgsAsList", "(", ")", ";", "PrintStream", "writer", "=", "dumpContext", ".", "getStdout", "(", ")", ";", "String", "cmd", "=", "args", ".", "isEmpty", "(", ")", "?", "null", ":", "args", ".", "get", "(", "0", ")", ";", "List", "<", "String", ">", "rest", "=", "args", ".", "isEmpty", "(", ")", "?", "new", "ArrayList", "<", "String", ">", "(", ")", ":", "args", ".", "subList", "(", "1", ",", "args", ".", "size", "(", ")", ")", ";", "if", "(", "cmd", "!=", "null", "&&", "cmd", ".", "equals", "(", "\"memcache\"", ")", ")", "{", "memcache", "(", "writer", ",", "rest", ")", ";", "}", "else", "if", "(", "cmd", "!=", "null", "&&", "cmd", ".", "equals", "(", "\"diskcache\"", ")", ")", "{", "diskcache", "(", "mMainFileCache", ",", "\"Main\"", ",", "writer", ",", "rest", ")", ";", "diskcache", "(", "mSmallFileCache", ",", "\"Small\"", ",", "writer", ",", "rest", ")", ";", "}", "else", "{", "usage", "(", "writer", ")", ";", "if", "(", "TextUtils", ".", "isEmpty", "(", "cmd", ")", ")", "{", "throw", "new", "DumpUsageException", "(", "\"Missing command\"", ")", ";", "}", "else", "{", "throw", "new", "DumpUsageException", "(", "\"Unknown command: \"", "+", "cmd", ")", ";", "}", "}", "}" ]
Entry point for the Stetho dumpapp script. {@link #initialize} must have been called in the app before running dumpapp.
[ "Entry", "point", "for", "the", "Stetho", "dumpapp", "script", "." ]
0b85879d51c5036d5e46e627a6651afefc0b971a
https://github.com/facebook/fresco/blob/0b85879d51c5036d5e46e627a6651afefc0b971a/tools/stetho/src/main/java/com/facebook/imagepipeline/stetho/BaseFrescoStethoPlugin.java#L79-L101
14,557
facebook/fresco
drawee/src/main/java/com/facebook/drawee/view/MultiDraweeHolder.java
MultiDraweeHolder.onAttach
public void onAttach() { if (mIsAttached) { return; } mIsAttached = true; for (int i = 0; i < mHolders.size(); ++i) { mHolders.get(i).onAttach(); } }
java
public void onAttach() { if (mIsAttached) { return; } mIsAttached = true; for (int i = 0; i < mHolders.size(); ++i) { mHolders.get(i).onAttach(); } }
[ "public", "void", "onAttach", "(", ")", "{", "if", "(", "mIsAttached", ")", "{", "return", ";", "}", "mIsAttached", "=", "true", ";", "for", "(", "int", "i", "=", "0", ";", "i", "<", "mHolders", ".", "size", "(", ")", ";", "++", "i", ")", "{", "mHolders", ".", "get", "(", "i", ")", ".", "onAttach", "(", ")", ";", "}", "}" ]
Gets the controller ready to display the images. <p>The containing view must call this method from both {@link View#onFinishTemporaryDetach()} and {@link View#onAttachedToWindow()}.
[ "Gets", "the", "controller", "ready", "to", "display", "the", "images", "." ]
0b85879d51c5036d5e46e627a6651afefc0b971a
https://github.com/facebook/fresco/blob/0b85879d51c5036d5e46e627a6651afefc0b971a/drawee/src/main/java/com/facebook/drawee/view/MultiDraweeHolder.java#L43-L51
14,558
facebook/fresco
drawee/src/main/java/com/facebook/drawee/view/MultiDraweeHolder.java
MultiDraweeHolder.onDetach
public void onDetach() { if (!mIsAttached) { return; } mIsAttached = false; for (int i = 0; i < mHolders.size(); ++i) { mHolders.get(i).onDetach(); } }
java
public void onDetach() { if (!mIsAttached) { return; } mIsAttached = false; for (int i = 0; i < mHolders.size(); ++i) { mHolders.get(i).onDetach(); } }
[ "public", "void", "onDetach", "(", ")", "{", "if", "(", "!", "mIsAttached", ")", "{", "return", ";", "}", "mIsAttached", "=", "false", ";", "for", "(", "int", "i", "=", "0", ";", "i", "<", "mHolders", ".", "size", "(", ")", ";", "++", "i", ")", "{", "mHolders", ".", "get", "(", "i", ")", ".", "onDetach", "(", ")", ";", "}", "}" ]
Releases resources used to display the image. <p>The containing view must call this method from both {@link View#onStartTemporaryDetach()} and {@link View#onDetachedFromWindow()}.
[ "Releases", "resources", "used", "to", "display", "the", "image", "." ]
0b85879d51c5036d5e46e627a6651afefc0b971a
https://github.com/facebook/fresco/blob/0b85879d51c5036d5e46e627a6651afefc0b971a/drawee/src/main/java/com/facebook/drawee/view/MultiDraweeHolder.java#L59-L67
14,559
facebook/fresco
drawee/src/main/java/com/facebook/drawee/view/MultiDraweeHolder.java
MultiDraweeHolder.draw
public void draw(Canvas canvas) { for (int i = 0; i < mHolders.size(); ++i) { Drawable drawable = get(i).getTopLevelDrawable(); if (drawable != null) { drawable.draw(canvas); } } }
java
public void draw(Canvas canvas) { for (int i = 0; i < mHolders.size(); ++i) { Drawable drawable = get(i).getTopLevelDrawable(); if (drawable != null) { drawable.draw(canvas); } } }
[ "public", "void", "draw", "(", "Canvas", "canvas", ")", "{", "for", "(", "int", "i", "=", "0", ";", "i", "<", "mHolders", ".", "size", "(", ")", ";", "++", "i", ")", "{", "Drawable", "drawable", "=", "get", "(", "i", ")", ".", "getTopLevelDrawable", "(", ")", ";", "if", "(", "drawable", "!=", "null", ")", "{", "drawable", ".", "draw", "(", "canvas", ")", ";", "}", "}", "}" ]
Convenience method to draw all the top-level drawables in this holder.
[ "Convenience", "method", "to", "draw", "all", "the", "top", "-", "level", "drawables", "in", "this", "holder", "." ]
0b85879d51c5036d5e46e627a6651afefc0b971a
https://github.com/facebook/fresco/blob/0b85879d51c5036d5e46e627a6651afefc0b971a/drawee/src/main/java/com/facebook/drawee/view/MultiDraweeHolder.java#L117-L124
14,560
facebook/fresco
drawee/src/main/java/com/facebook/drawee/view/MultiDraweeHolder.java
MultiDraweeHolder.verifyDrawable
public boolean verifyDrawable(Drawable who) { for (int i = 0; i < mHolders.size(); ++i) { if (who == get(i).getTopLevelDrawable()) { return true; } } return false; }
java
public boolean verifyDrawable(Drawable who) { for (int i = 0; i < mHolders.size(); ++i) { if (who == get(i).getTopLevelDrawable()) { return true; } } return false; }
[ "public", "boolean", "verifyDrawable", "(", "Drawable", "who", ")", "{", "for", "(", "int", "i", "=", "0", ";", "i", "<", "mHolders", ".", "size", "(", ")", ";", "++", "i", ")", "{", "if", "(", "who", "==", "get", "(", "i", ")", ".", "getTopLevelDrawable", "(", ")", ")", "{", "return", "true", ";", "}", "}", "return", "false", ";", "}" ]
Returns true if the argument is a top-level Drawable in this holder.
[ "Returns", "true", "if", "the", "argument", "is", "a", "top", "-", "level", "Drawable", "in", "this", "holder", "." ]
0b85879d51c5036d5e46e627a6651afefc0b971a
https://github.com/facebook/fresco/blob/0b85879d51c5036d5e46e627a6651afefc0b971a/drawee/src/main/java/com/facebook/drawee/view/MultiDraweeHolder.java#L127-L134
14,561
facebook/fresco
imagepipeline-base/src/main/java/com/facebook/imagepipeline/common/ImageDecodeOptionsBuilder.java
ImageDecodeOptionsBuilder.setFrom
public ImageDecodeOptionsBuilder setFrom(ImageDecodeOptions options) { mDecodePreviewFrame = options.decodePreviewFrame; mUseLastFrameForPreview = options.useLastFrameForPreview; mDecodeAllFrames = options.decodeAllFrames; mForceStaticImage = options.forceStaticImage; mBitmapConfig = options.bitmapConfig; mCustomImageDecoder = options.customImageDecoder; mBitmapTransformation = options.bitmapTransformation; mColorSpace = options.colorSpace; return this; }
java
public ImageDecodeOptionsBuilder setFrom(ImageDecodeOptions options) { mDecodePreviewFrame = options.decodePreviewFrame; mUseLastFrameForPreview = options.useLastFrameForPreview; mDecodeAllFrames = options.decodeAllFrames; mForceStaticImage = options.forceStaticImage; mBitmapConfig = options.bitmapConfig; mCustomImageDecoder = options.customImageDecoder; mBitmapTransformation = options.bitmapTransformation; mColorSpace = options.colorSpace; return this; }
[ "public", "ImageDecodeOptionsBuilder", "setFrom", "(", "ImageDecodeOptions", "options", ")", "{", "mDecodePreviewFrame", "=", "options", ".", "decodePreviewFrame", ";", "mUseLastFrameForPreview", "=", "options", ".", "useLastFrameForPreview", ";", "mDecodeAllFrames", "=", "options", ".", "decodeAllFrames", ";", "mForceStaticImage", "=", "options", ".", "forceStaticImage", ";", "mBitmapConfig", "=", "options", ".", "bitmapConfig", ";", "mCustomImageDecoder", "=", "options", ".", "customImageDecoder", ";", "mBitmapTransformation", "=", "options", ".", "bitmapTransformation", ";", "mColorSpace", "=", "options", ".", "colorSpace", ";", "return", "this", ";", "}" ]
Sets the builder to be equivalent to the specified options. @param options the options to copy from @return this builder
[ "Sets", "the", "builder", "to", "be", "equivalent", "to", "the", "specified", "options", "." ]
0b85879d51c5036d5e46e627a6651afefc0b971a
https://github.com/facebook/fresco/blob/0b85879d51c5036d5e46e627a6651afefc0b971a/imagepipeline-base/src/main/java/com/facebook/imagepipeline/common/ImageDecodeOptionsBuilder.java#L40-L50
14,562
facebook/fresco
native-filters/src/main/java/com/facebook/imagepipeline/nativecode/NativeRoundingFilter.java
NativeRoundingFilter.toCircle
public static void toCircle(Bitmap bitmap, boolean antiAliased) { Preconditions.checkNotNull(bitmap); nativeToCircleFilter(bitmap, antiAliased); }
java
public static void toCircle(Bitmap bitmap, boolean antiAliased) { Preconditions.checkNotNull(bitmap); nativeToCircleFilter(bitmap, antiAliased); }
[ "public", "static", "void", "toCircle", "(", "Bitmap", "bitmap", ",", "boolean", "antiAliased", ")", "{", "Preconditions", ".", "checkNotNull", "(", "bitmap", ")", ";", "nativeToCircleFilter", "(", "bitmap", ",", "antiAliased", ")", ";", "}" ]
This is a fast, native implementation for rounding a bitmap. It takes the given bitmap and modifies it to be circular. <p>This implementation does not change the underlying bitmap dimensions, it only sets pixels that are outside of the circle to a transparent color. @param bitmap the bitmap to modify
[ "This", "is", "a", "fast", "native", "implementation", "for", "rounding", "a", "bitmap", ".", "It", "takes", "the", "given", "bitmap", "and", "modifies", "it", "to", "be", "circular", "." ]
0b85879d51c5036d5e46e627a6651afefc0b971a
https://github.com/facebook/fresco/blob/0b85879d51c5036d5e46e627a6651afefc0b971a/native-filters/src/main/java/com/facebook/imagepipeline/nativecode/NativeRoundingFilter.java#L35-L38
14,563
facebook/fresco
imagepipeline/src/main/java/com/facebook/imagepipeline/producers/BaseConsumer.java
BaseConsumer.onProgressUpdate
@Override public synchronized void onProgressUpdate(float progress) { if (mIsFinished) { return; } try { onProgressUpdateImpl(progress); } catch (Exception e) { onUnhandledException(e); } }
java
@Override public synchronized void onProgressUpdate(float progress) { if (mIsFinished) { return; } try { onProgressUpdateImpl(progress); } catch (Exception e) { onUnhandledException(e); } }
[ "@", "Override", "public", "synchronized", "void", "onProgressUpdate", "(", "float", "progress", ")", "{", "if", "(", "mIsFinished", ")", "{", "return", ";", "}", "try", "{", "onProgressUpdateImpl", "(", "progress", ")", ";", "}", "catch", "(", "Exception", "e", ")", "{", "onUnhandledException", "(", "e", ")", ";", "}", "}" ]
Called when the progress updates. @param progress in range [0, 1]
[ "Called", "when", "the", "progress", "updates", "." ]
0b85879d51c5036d5e46e627a6651afefc0b971a
https://github.com/facebook/fresco/blob/0b85879d51c5036d5e46e627a6651afefc0b971a/imagepipeline/src/main/java/com/facebook/imagepipeline/producers/BaseConsumer.java#L134-L144
14,564
facebook/fresco
imagepipeline/src/main/java/com/facebook/imagepipeline/cache/BufferedDiskCache.java
BufferedDiskCache.contains
public Task<Boolean> contains(final CacheKey key) { if (containsSync(key)) { return Task.forResult(true); } return containsAsync(key); }
java
public Task<Boolean> contains(final CacheKey key) { if (containsSync(key)) { return Task.forResult(true); } return containsAsync(key); }
[ "public", "Task", "<", "Boolean", ">", "contains", "(", "final", "CacheKey", "key", ")", "{", "if", "(", "containsSync", "(", "key", ")", ")", "{", "return", "Task", ".", "forResult", "(", "true", ")", ";", "}", "return", "containsAsync", "(", "key", ")", ";", "}" ]
Performs a key-value look up in the disk cache. If no value is found in the staging area, then disk cache checks are scheduled on a background thread. Any error manifests itself as a cache miss, i.e. the returned Task resolves to false. @param key @return Task that resolves to true if an element is found, or false otherwise
[ "Performs", "a", "key", "-", "value", "look", "up", "in", "the", "disk", "cache", ".", "If", "no", "value", "is", "found", "in", "the", "staging", "area", "then", "disk", "cache", "checks", "are", "scheduled", "on", "a", "background", "thread", ".", "Any", "error", "manifests", "itself", "as", "a", "cache", "miss", "i", ".", "e", ".", "the", "returned", "Task", "resolves", "to", "false", "." ]
0b85879d51c5036d5e46e627a6651afefc0b971a
https://github.com/facebook/fresco/blob/0b85879d51c5036d5e46e627a6651afefc0b971a/imagepipeline/src/main/java/com/facebook/imagepipeline/cache/BufferedDiskCache.java#L82-L87
14,565
facebook/fresco
imagepipeline/src/main/java/com/facebook/imagepipeline/cache/BufferedDiskCache.java
BufferedDiskCache.get
public Task<EncodedImage> get(CacheKey key, AtomicBoolean isCancelled) { try { if (FrescoSystrace.isTracing()) { FrescoSystrace.beginSection("BufferedDiskCache#get"); } final EncodedImage pinnedImage = mStagingArea.get(key); if (pinnedImage != null) { return foundPinnedImage(key, pinnedImage); } return getAsync(key, isCancelled); } finally { if (FrescoSystrace.isTracing()) { FrescoSystrace.endSection(); } } }
java
public Task<EncodedImage> get(CacheKey key, AtomicBoolean isCancelled) { try { if (FrescoSystrace.isTracing()) { FrescoSystrace.beginSection("BufferedDiskCache#get"); } final EncodedImage pinnedImage = mStagingArea.get(key); if (pinnedImage != null) { return foundPinnedImage(key, pinnedImage); } return getAsync(key, isCancelled); } finally { if (FrescoSystrace.isTracing()) { FrescoSystrace.endSection(); } } }
[ "public", "Task", "<", "EncodedImage", ">", "get", "(", "CacheKey", "key", ",", "AtomicBoolean", "isCancelled", ")", "{", "try", "{", "if", "(", "FrescoSystrace", ".", "isTracing", "(", ")", ")", "{", "FrescoSystrace", ".", "beginSection", "(", "\"BufferedDiskCache#get\"", ")", ";", "}", "final", "EncodedImage", "pinnedImage", "=", "mStagingArea", ".", "get", "(", "key", ")", ";", "if", "(", "pinnedImage", "!=", "null", ")", "{", "return", "foundPinnedImage", "(", "key", ",", "pinnedImage", ")", ";", "}", "return", "getAsync", "(", "key", ",", "isCancelled", ")", ";", "}", "finally", "{", "if", "(", "FrescoSystrace", ".", "isTracing", "(", ")", ")", "{", "FrescoSystrace", ".", "endSection", "(", ")", ";", "}", "}", "}" ]
Performs key-value look up in disk cache. If value is not found in disk cache staging area then disk cache read is scheduled on background thread. Any error manifests itself as cache miss, i.e. the returned task resolves to null. @param key @return Task that resolves to cached element or null if one cannot be retrieved; returned task never rethrows any exception
[ "Performs", "key", "-", "value", "look", "up", "in", "disk", "cache", ".", "If", "value", "is", "not", "found", "in", "disk", "cache", "staging", "area", "then", "disk", "cache", "read", "is", "scheduled", "on", "background", "thread", ".", "Any", "error", "manifests", "itself", "as", "cache", "miss", "i", ".", "e", ".", "the", "returned", "task", "resolves", "to", "null", "." ]
0b85879d51c5036d5e46e627a6651afefc0b971a
https://github.com/facebook/fresco/blob/0b85879d51c5036d5e46e627a6651afefc0b971a/imagepipeline/src/main/java/com/facebook/imagepipeline/cache/BufferedDiskCache.java#L131-L146
14,566
facebook/fresco
imagepipeline/src/main/java/com/facebook/imagepipeline/cache/BufferedDiskCache.java
BufferedDiskCache.checkInStagingAreaAndFileCache
private boolean checkInStagingAreaAndFileCache(final CacheKey key) { EncodedImage result = mStagingArea.get(key); if (result != null) { result.close(); FLog.v(TAG, "Found image for %s in staging area", key.getUriString()); mImageCacheStatsTracker.onStagingAreaHit(key); return true; } else { FLog.v(TAG, "Did not find image for %s in staging area", key.getUriString()); mImageCacheStatsTracker.onStagingAreaMiss(); try { return mFileCache.hasKey(key); } catch (Exception exception) { return false; } } }
java
private boolean checkInStagingAreaAndFileCache(final CacheKey key) { EncodedImage result = mStagingArea.get(key); if (result != null) { result.close(); FLog.v(TAG, "Found image for %s in staging area", key.getUriString()); mImageCacheStatsTracker.onStagingAreaHit(key); return true; } else { FLog.v(TAG, "Did not find image for %s in staging area", key.getUriString()); mImageCacheStatsTracker.onStagingAreaMiss(); try { return mFileCache.hasKey(key); } catch (Exception exception) { return false; } } }
[ "private", "boolean", "checkInStagingAreaAndFileCache", "(", "final", "CacheKey", "key", ")", "{", "EncodedImage", "result", "=", "mStagingArea", ".", "get", "(", "key", ")", ";", "if", "(", "result", "!=", "null", ")", "{", "result", ".", "close", "(", ")", ";", "FLog", ".", "v", "(", "TAG", ",", "\"Found image for %s in staging area\"", ",", "key", ".", "getUriString", "(", ")", ")", ";", "mImageCacheStatsTracker", ".", "onStagingAreaHit", "(", "key", ")", ";", "return", "true", ";", "}", "else", "{", "FLog", ".", "v", "(", "TAG", ",", "\"Did not find image for %s in staging area\"", ",", "key", ".", "getUriString", "(", ")", ")", ";", "mImageCacheStatsTracker", ".", "onStagingAreaMiss", "(", ")", ";", "try", "{", "return", "mFileCache", ".", "hasKey", "(", "key", ")", ";", "}", "catch", "(", "Exception", "exception", ")", "{", "return", "false", ";", "}", "}", "}" ]
Performs key-value loop up in staging area and file cache. Any error manifests itself as a miss, i.e. returns false. @param key @return true if the image is found in staging area or File cache, false if not found
[ "Performs", "key", "-", "value", "loop", "up", "in", "staging", "area", "and", "file", "cache", ".", "Any", "error", "manifests", "itself", "as", "a", "miss", "i", ".", "e", ".", "returns", "false", "." ]
0b85879d51c5036d5e46e627a6651afefc0b971a
https://github.com/facebook/fresco/blob/0b85879d51c5036d5e46e627a6651afefc0b971a/imagepipeline/src/main/java/com/facebook/imagepipeline/cache/BufferedDiskCache.java#L154-L170
14,567
facebook/fresco
imagepipeline/src/main/java/com/facebook/imagepipeline/cache/BufferedDiskCache.java
BufferedDiskCache.put
public void put( final CacheKey key, EncodedImage encodedImage) { try { if (FrescoSystrace.isTracing()) { FrescoSystrace.beginSection("BufferedDiskCache#put"); } Preconditions.checkNotNull(key); Preconditions.checkArgument(EncodedImage.isValid(encodedImage)); // Store encodedImage in staging area mStagingArea.put(key, encodedImage); // Write to disk cache. This will be executed on background thread, so increment the ref // count. When this write completes (with success/failure), then we will bump down the // ref count again. final EncodedImage finalEncodedImage = EncodedImage.cloneOrNull(encodedImage); try { mWriteExecutor.execute( new Runnable() { @Override public void run() { try { if (FrescoSystrace.isTracing()) { FrescoSystrace.beginSection("BufferedDiskCache#putAsync"); } writeToDiskCache(key, finalEncodedImage); } finally { mStagingArea.remove(key, finalEncodedImage); EncodedImage.closeSafely(finalEncodedImage); if (FrescoSystrace.isTracing()) { FrescoSystrace.endSection(); } } } }); } catch (Exception exception) { // We failed to enqueue cache write. Log failure and decrement ref count // TODO: 3697790 FLog.w(TAG, exception, "Failed to schedule disk-cache write for %s", key.getUriString()); mStagingArea.remove(key, encodedImage); EncodedImage.closeSafely(finalEncodedImage); } } finally { if (FrescoSystrace.isTracing()) { FrescoSystrace.endSection(); } } }
java
public void put( final CacheKey key, EncodedImage encodedImage) { try { if (FrescoSystrace.isTracing()) { FrescoSystrace.beginSection("BufferedDiskCache#put"); } Preconditions.checkNotNull(key); Preconditions.checkArgument(EncodedImage.isValid(encodedImage)); // Store encodedImage in staging area mStagingArea.put(key, encodedImage); // Write to disk cache. This will be executed on background thread, so increment the ref // count. When this write completes (with success/failure), then we will bump down the // ref count again. final EncodedImage finalEncodedImage = EncodedImage.cloneOrNull(encodedImage); try { mWriteExecutor.execute( new Runnable() { @Override public void run() { try { if (FrescoSystrace.isTracing()) { FrescoSystrace.beginSection("BufferedDiskCache#putAsync"); } writeToDiskCache(key, finalEncodedImage); } finally { mStagingArea.remove(key, finalEncodedImage); EncodedImage.closeSafely(finalEncodedImage); if (FrescoSystrace.isTracing()) { FrescoSystrace.endSection(); } } } }); } catch (Exception exception) { // We failed to enqueue cache write. Log failure and decrement ref count // TODO: 3697790 FLog.w(TAG, exception, "Failed to schedule disk-cache write for %s", key.getUriString()); mStagingArea.remove(key, encodedImage); EncodedImage.closeSafely(finalEncodedImage); } } finally { if (FrescoSystrace.isTracing()) { FrescoSystrace.endSection(); } } }
[ "public", "void", "put", "(", "final", "CacheKey", "key", ",", "EncodedImage", "encodedImage", ")", "{", "try", "{", "if", "(", "FrescoSystrace", ".", "isTracing", "(", ")", ")", "{", "FrescoSystrace", ".", "beginSection", "(", "\"BufferedDiskCache#put\"", ")", ";", "}", "Preconditions", ".", "checkNotNull", "(", "key", ")", ";", "Preconditions", ".", "checkArgument", "(", "EncodedImage", ".", "isValid", "(", "encodedImage", ")", ")", ";", "// Store encodedImage in staging area", "mStagingArea", ".", "put", "(", "key", ",", "encodedImage", ")", ";", "// Write to disk cache. This will be executed on background thread, so increment the ref", "// count. When this write completes (with success/failure), then we will bump down the", "// ref count again.", "final", "EncodedImage", "finalEncodedImage", "=", "EncodedImage", ".", "cloneOrNull", "(", "encodedImage", ")", ";", "try", "{", "mWriteExecutor", ".", "execute", "(", "new", "Runnable", "(", ")", "{", "@", "Override", "public", "void", "run", "(", ")", "{", "try", "{", "if", "(", "FrescoSystrace", ".", "isTracing", "(", ")", ")", "{", "FrescoSystrace", ".", "beginSection", "(", "\"BufferedDiskCache#putAsync\"", ")", ";", "}", "writeToDiskCache", "(", "key", ",", "finalEncodedImage", ")", ";", "}", "finally", "{", "mStagingArea", ".", "remove", "(", "key", ",", "finalEncodedImage", ")", ";", "EncodedImage", ".", "closeSafely", "(", "finalEncodedImage", ")", ";", "if", "(", "FrescoSystrace", ".", "isTracing", "(", ")", ")", "{", "FrescoSystrace", ".", "endSection", "(", ")", ";", "}", "}", "}", "}", ")", ";", "}", "catch", "(", "Exception", "exception", ")", "{", "// We failed to enqueue cache write. Log failure and decrement ref count", "// TODO: 3697790", "FLog", ".", "w", "(", "TAG", ",", "exception", ",", "\"Failed to schedule disk-cache write for %s\"", ",", "key", ".", "getUriString", "(", ")", ")", ";", "mStagingArea", ".", "remove", "(", "key", ",", "encodedImage", ")", ";", "EncodedImage", ".", "closeSafely", "(", "finalEncodedImage", ")", ";", "}", "}", "finally", "{", "if", "(", "FrescoSystrace", ".", "isTracing", "(", ")", ")", "{", "FrescoSystrace", ".", "endSection", "(", ")", ";", "}", "}", "}" ]
Associates encodedImage with given key in disk cache. Disk write is performed on background thread, so the caller of this method is not blocked
[ "Associates", "encodedImage", "with", "given", "key", "in", "disk", "cache", ".", "Disk", "write", "is", "performed", "on", "background", "thread", "so", "the", "caller", "of", "this", "method", "is", "not", "blocked" ]
0b85879d51c5036d5e46e627a6651afefc0b971a
https://github.com/facebook/fresco/blob/0b85879d51c5036d5e46e627a6651afefc0b971a/imagepipeline/src/main/java/com/facebook/imagepipeline/cache/BufferedDiskCache.java#L242-L291
14,568
facebook/fresco
imagepipeline/src/main/java/com/facebook/imagepipeline/cache/BufferedDiskCache.java
BufferedDiskCache.remove
public Task<Void> remove(final CacheKey key) { Preconditions.checkNotNull(key); mStagingArea.remove(key); try { return Task.call( new Callable<Void>() { @Override public Void call() throws Exception { try { if (FrescoSystrace.isTracing()) { FrescoSystrace.beginSection("BufferedDiskCache#remove"); } mStagingArea.remove(key); mFileCache.remove(key); } finally { if (FrescoSystrace.isTracing()) { FrescoSystrace.endSection(); } } return null; } }, mWriteExecutor); } catch (Exception exception) { // Log failure // TODO: 3697790 FLog.w(TAG, exception, "Failed to schedule disk-cache remove for %s", key.getUriString()); return Task.forError(exception); } }
java
public Task<Void> remove(final CacheKey key) { Preconditions.checkNotNull(key); mStagingArea.remove(key); try { return Task.call( new Callable<Void>() { @Override public Void call() throws Exception { try { if (FrescoSystrace.isTracing()) { FrescoSystrace.beginSection("BufferedDiskCache#remove"); } mStagingArea.remove(key); mFileCache.remove(key); } finally { if (FrescoSystrace.isTracing()) { FrescoSystrace.endSection(); } } return null; } }, mWriteExecutor); } catch (Exception exception) { // Log failure // TODO: 3697790 FLog.w(TAG, exception, "Failed to schedule disk-cache remove for %s", key.getUriString()); return Task.forError(exception); } }
[ "public", "Task", "<", "Void", ">", "remove", "(", "final", "CacheKey", "key", ")", "{", "Preconditions", ".", "checkNotNull", "(", "key", ")", ";", "mStagingArea", ".", "remove", "(", "key", ")", ";", "try", "{", "return", "Task", ".", "call", "(", "new", "Callable", "<", "Void", ">", "(", ")", "{", "@", "Override", "public", "Void", "call", "(", ")", "throws", "Exception", "{", "try", "{", "if", "(", "FrescoSystrace", ".", "isTracing", "(", ")", ")", "{", "FrescoSystrace", ".", "beginSection", "(", "\"BufferedDiskCache#remove\"", ")", ";", "}", "mStagingArea", ".", "remove", "(", "key", ")", ";", "mFileCache", ".", "remove", "(", "key", ")", ";", "}", "finally", "{", "if", "(", "FrescoSystrace", ".", "isTracing", "(", ")", ")", "{", "FrescoSystrace", ".", "endSection", "(", ")", ";", "}", "}", "return", "null", ";", "}", "}", ",", "mWriteExecutor", ")", ";", "}", "catch", "(", "Exception", "exception", ")", "{", "// Log failure", "// TODO: 3697790", "FLog", ".", "w", "(", "TAG", ",", "exception", ",", "\"Failed to schedule disk-cache remove for %s\"", ",", "key", ".", "getUriString", "(", ")", ")", ";", "return", "Task", ".", "forError", "(", "exception", ")", ";", "}", "}" ]
Removes the item from the disk cache and the staging area.
[ "Removes", "the", "item", "from", "the", "disk", "cache", "and", "the", "staging", "area", "." ]
0b85879d51c5036d5e46e627a6651afefc0b971a
https://github.com/facebook/fresco/blob/0b85879d51c5036d5e46e627a6651afefc0b971a/imagepipeline/src/main/java/com/facebook/imagepipeline/cache/BufferedDiskCache.java#L296-L325
14,569
facebook/fresco
imagepipeline/src/main/java/com/facebook/imagepipeline/cache/BufferedDiskCache.java
BufferedDiskCache.clearAll
public Task<Void> clearAll() { mStagingArea.clearAll(); try { return Task.call( new Callable<Void>() { @Override public Void call() throws Exception { mStagingArea.clearAll(); mFileCache.clearAll(); return null; } }, mWriteExecutor); } catch (Exception exception) { // Log failure // TODO: 3697790 FLog.w(TAG, exception, "Failed to schedule disk-cache clear"); return Task.forError(exception); } }
java
public Task<Void> clearAll() { mStagingArea.clearAll(); try { return Task.call( new Callable<Void>() { @Override public Void call() throws Exception { mStagingArea.clearAll(); mFileCache.clearAll(); return null; } }, mWriteExecutor); } catch (Exception exception) { // Log failure // TODO: 3697790 FLog.w(TAG, exception, "Failed to schedule disk-cache clear"); return Task.forError(exception); } }
[ "public", "Task", "<", "Void", ">", "clearAll", "(", ")", "{", "mStagingArea", ".", "clearAll", "(", ")", ";", "try", "{", "return", "Task", ".", "call", "(", "new", "Callable", "<", "Void", ">", "(", ")", "{", "@", "Override", "public", "Void", "call", "(", ")", "throws", "Exception", "{", "mStagingArea", ".", "clearAll", "(", ")", ";", "mFileCache", ".", "clearAll", "(", ")", ";", "return", "null", ";", "}", "}", ",", "mWriteExecutor", ")", ";", "}", "catch", "(", "Exception", "exception", ")", "{", "// Log failure", "// TODO: 3697790", "FLog", ".", "w", "(", "TAG", ",", "exception", ",", "\"Failed to schedule disk-cache clear\"", ")", ";", "return", "Task", ".", "forError", "(", "exception", ")", ";", "}", "}" ]
Clears the disk cache and the staging area.
[ "Clears", "the", "disk", "cache", "and", "the", "staging", "area", "." ]
0b85879d51c5036d5e46e627a6651afefc0b971a
https://github.com/facebook/fresco/blob/0b85879d51c5036d5e46e627a6651afefc0b971a/imagepipeline/src/main/java/com/facebook/imagepipeline/cache/BufferedDiskCache.java#L330-L349
14,570
facebook/fresco
imagepipeline/src/main/java/com/facebook/imagepipeline/cache/BufferedDiskCache.java
BufferedDiskCache.readFromDiskCache
private @Nullable PooledByteBuffer readFromDiskCache(final CacheKey key) throws IOException { try { FLog.v(TAG, "Disk cache read for %s", key.getUriString()); final BinaryResource diskCacheResource = mFileCache.getResource(key); if (diskCacheResource == null) { FLog.v(TAG, "Disk cache miss for %s", key.getUriString()); mImageCacheStatsTracker.onDiskCacheMiss(); return null; } else { FLog.v(TAG, "Found entry in disk cache for %s", key.getUriString()); mImageCacheStatsTracker.onDiskCacheHit(key); } PooledByteBuffer byteBuffer; final InputStream is = diskCacheResource.openStream(); try { byteBuffer = mPooledByteBufferFactory.newByteBuffer(is, (int) diskCacheResource.size()); } finally { is.close(); } FLog.v(TAG, "Successful read from disk cache for %s", key.getUriString()); return byteBuffer; } catch (IOException ioe) { // TODO: 3697790 log failures // TODO: 5258772 - uncomment line below // mFileCache.remove(key); FLog.w(TAG, ioe, "Exception reading from cache for %s", key.getUriString()); mImageCacheStatsTracker.onDiskCacheGetFail(); throw ioe; } }
java
private @Nullable PooledByteBuffer readFromDiskCache(final CacheKey key) throws IOException { try { FLog.v(TAG, "Disk cache read for %s", key.getUriString()); final BinaryResource diskCacheResource = mFileCache.getResource(key); if (diskCacheResource == null) { FLog.v(TAG, "Disk cache miss for %s", key.getUriString()); mImageCacheStatsTracker.onDiskCacheMiss(); return null; } else { FLog.v(TAG, "Found entry in disk cache for %s", key.getUriString()); mImageCacheStatsTracker.onDiskCacheHit(key); } PooledByteBuffer byteBuffer; final InputStream is = diskCacheResource.openStream(); try { byteBuffer = mPooledByteBufferFactory.newByteBuffer(is, (int) diskCacheResource.size()); } finally { is.close(); } FLog.v(TAG, "Successful read from disk cache for %s", key.getUriString()); return byteBuffer; } catch (IOException ioe) { // TODO: 3697790 log failures // TODO: 5258772 - uncomment line below // mFileCache.remove(key); FLog.w(TAG, ioe, "Exception reading from cache for %s", key.getUriString()); mImageCacheStatsTracker.onDiskCacheGetFail(); throw ioe; } }
[ "private", "@", "Nullable", "PooledByteBuffer", "readFromDiskCache", "(", "final", "CacheKey", "key", ")", "throws", "IOException", "{", "try", "{", "FLog", ".", "v", "(", "TAG", ",", "\"Disk cache read for %s\"", ",", "key", ".", "getUriString", "(", ")", ")", ";", "final", "BinaryResource", "diskCacheResource", "=", "mFileCache", ".", "getResource", "(", "key", ")", ";", "if", "(", "diskCacheResource", "==", "null", ")", "{", "FLog", ".", "v", "(", "TAG", ",", "\"Disk cache miss for %s\"", ",", "key", ".", "getUriString", "(", ")", ")", ";", "mImageCacheStatsTracker", ".", "onDiskCacheMiss", "(", ")", ";", "return", "null", ";", "}", "else", "{", "FLog", ".", "v", "(", "TAG", ",", "\"Found entry in disk cache for %s\"", ",", "key", ".", "getUriString", "(", ")", ")", ";", "mImageCacheStatsTracker", ".", "onDiskCacheHit", "(", "key", ")", ";", "}", "PooledByteBuffer", "byteBuffer", ";", "final", "InputStream", "is", "=", "diskCacheResource", ".", "openStream", "(", ")", ";", "try", "{", "byteBuffer", "=", "mPooledByteBufferFactory", ".", "newByteBuffer", "(", "is", ",", "(", "int", ")", "diskCacheResource", ".", "size", "(", ")", ")", ";", "}", "finally", "{", "is", ".", "close", "(", ")", ";", "}", "FLog", ".", "v", "(", "TAG", ",", "\"Successful read from disk cache for %s\"", ",", "key", ".", "getUriString", "(", ")", ")", ";", "return", "byteBuffer", ";", "}", "catch", "(", "IOException", "ioe", ")", "{", "// TODO: 3697790 log failures", "// TODO: 5258772 - uncomment line below", "// mFileCache.remove(key);", "FLog", ".", "w", "(", "TAG", ",", "ioe", ",", "\"Exception reading from cache for %s\"", ",", "key", ".", "getUriString", "(", ")", ")", ";", "mImageCacheStatsTracker", ".", "onDiskCacheGetFail", "(", ")", ";", "throw", "ioe", ";", "}", "}" ]
Performs disk cache read. In case of any exception null is returned.
[ "Performs", "disk", "cache", "read", ".", "In", "case", "of", "any", "exception", "null", "is", "returned", "." ]
0b85879d51c5036d5e46e627a6651afefc0b971a
https://github.com/facebook/fresco/blob/0b85879d51c5036d5e46e627a6651afefc0b971a/imagepipeline/src/main/java/com/facebook/imagepipeline/cache/BufferedDiskCache.java#L362-L394
14,571
facebook/fresco
imagepipeline/src/main/java/com/facebook/imagepipeline/cache/BufferedDiskCache.java
BufferedDiskCache.writeToDiskCache
private void writeToDiskCache( final CacheKey key, final EncodedImage encodedImage) { FLog.v(TAG, "About to write to disk-cache for key %s", key.getUriString()); try { mFileCache.insert( key, new WriterCallback() { @Override public void write(OutputStream os) throws IOException { mPooledByteStreams.copy(encodedImage.getInputStream(), os); } } ); FLog.v(TAG, "Successful disk-cache write for key %s", key.getUriString()); } catch (IOException ioe) { // Log failure // TODO: 3697790 FLog.w(TAG, ioe, "Failed to write to disk-cache for key %s", key.getUriString()); } }
java
private void writeToDiskCache( final CacheKey key, final EncodedImage encodedImage) { FLog.v(TAG, "About to write to disk-cache for key %s", key.getUriString()); try { mFileCache.insert( key, new WriterCallback() { @Override public void write(OutputStream os) throws IOException { mPooledByteStreams.copy(encodedImage.getInputStream(), os); } } ); FLog.v(TAG, "Successful disk-cache write for key %s", key.getUriString()); } catch (IOException ioe) { // Log failure // TODO: 3697790 FLog.w(TAG, ioe, "Failed to write to disk-cache for key %s", key.getUriString()); } }
[ "private", "void", "writeToDiskCache", "(", "final", "CacheKey", "key", ",", "final", "EncodedImage", "encodedImage", ")", "{", "FLog", ".", "v", "(", "TAG", ",", "\"About to write to disk-cache for key %s\"", ",", "key", ".", "getUriString", "(", ")", ")", ";", "try", "{", "mFileCache", ".", "insert", "(", "key", ",", "new", "WriterCallback", "(", ")", "{", "@", "Override", "public", "void", "write", "(", "OutputStream", "os", ")", "throws", "IOException", "{", "mPooledByteStreams", ".", "copy", "(", "encodedImage", ".", "getInputStream", "(", ")", ",", "os", ")", ";", "}", "}", ")", ";", "FLog", ".", "v", "(", "TAG", ",", "\"Successful disk-cache write for key %s\"", ",", "key", ".", "getUriString", "(", ")", ")", ";", "}", "catch", "(", "IOException", "ioe", ")", "{", "// Log failure", "// TODO: 3697790", "FLog", ".", "w", "(", "TAG", ",", "ioe", ",", "\"Failed to write to disk-cache for key %s\"", ",", "key", ".", "getUriString", "(", ")", ")", ";", "}", "}" ]
Writes to disk cache @throws IOException
[ "Writes", "to", "disk", "cache" ]
0b85879d51c5036d5e46e627a6651afefc0b971a
https://github.com/facebook/fresco/blob/0b85879d51c5036d5e46e627a6651afefc0b971a/imagepipeline/src/main/java/com/facebook/imagepipeline/cache/BufferedDiskCache.java#L400-L419
14,572
facebook/fresco
imagepipeline-base/src/main/java/com/facebook/imagepipeline/cache/CountingMemoryCache.java
CountingMemoryCache.canCacheNewValue
private synchronized boolean canCacheNewValue(V value) { int newValueSize = mValueDescriptor.getSizeInBytes(value); return (newValueSize <= mMemoryCacheParams.maxCacheEntrySize) && (getInUseCount() <= mMemoryCacheParams.maxCacheEntries - 1) && (getInUseSizeInBytes() <= mMemoryCacheParams.maxCacheSize - newValueSize); }
java
private synchronized boolean canCacheNewValue(V value) { int newValueSize = mValueDescriptor.getSizeInBytes(value); return (newValueSize <= mMemoryCacheParams.maxCacheEntrySize) && (getInUseCount() <= mMemoryCacheParams.maxCacheEntries - 1) && (getInUseSizeInBytes() <= mMemoryCacheParams.maxCacheSize - newValueSize); }
[ "private", "synchronized", "boolean", "canCacheNewValue", "(", "V", "value", ")", "{", "int", "newValueSize", "=", "mValueDescriptor", ".", "getSizeInBytes", "(", "value", ")", ";", "return", "(", "newValueSize", "<=", "mMemoryCacheParams", ".", "maxCacheEntrySize", ")", "&&", "(", "getInUseCount", "(", ")", "<=", "mMemoryCacheParams", ".", "maxCacheEntries", "-", "1", ")", "&&", "(", "getInUseSizeInBytes", "(", ")", "<=", "mMemoryCacheParams", ".", "maxCacheSize", "-", "newValueSize", ")", ";", "}" ]
Checks the cache constraints to determine whether the new value can be cached or not.
[ "Checks", "the", "cache", "constraints", "to", "determine", "whether", "the", "new", "value", "can", "be", "cached", "or", "not", "." ]
0b85879d51c5036d5e46e627a6651afefc0b971a
https://github.com/facebook/fresco/blob/0b85879d51c5036d5e46e627a6651afefc0b971a/imagepipeline-base/src/main/java/com/facebook/imagepipeline/cache/CountingMemoryCache.java#L196-L201
14,573
facebook/fresco
imagepipeline-base/src/main/java/com/facebook/imagepipeline/cache/CountingMemoryCache.java
CountingMemoryCache.get
@Nullable public CloseableReference<V> get(final K key) { Preconditions.checkNotNull(key); Entry<K, V> oldExclusive; CloseableReference<V> clientRef = null; synchronized (this) { oldExclusive = mExclusiveEntries.remove(key); Entry<K, V> entry = mCachedEntries.get(key); if (entry != null) { clientRef = newClientReference(entry); } } maybeNotifyExclusiveEntryRemoval(oldExclusive); maybeUpdateCacheParams(); maybeEvictEntries(); return clientRef; }
java
@Nullable public CloseableReference<V> get(final K key) { Preconditions.checkNotNull(key); Entry<K, V> oldExclusive; CloseableReference<V> clientRef = null; synchronized (this) { oldExclusive = mExclusiveEntries.remove(key); Entry<K, V> entry = mCachedEntries.get(key); if (entry != null) { clientRef = newClientReference(entry); } } maybeNotifyExclusiveEntryRemoval(oldExclusive); maybeUpdateCacheParams(); maybeEvictEntries(); return clientRef; }
[ "@", "Nullable", "public", "CloseableReference", "<", "V", ">", "get", "(", "final", "K", "key", ")", "{", "Preconditions", ".", "checkNotNull", "(", "key", ")", ";", "Entry", "<", "K", ",", "V", ">", "oldExclusive", ";", "CloseableReference", "<", "V", ">", "clientRef", "=", "null", ";", "synchronized", "(", "this", ")", "{", "oldExclusive", "=", "mExclusiveEntries", ".", "remove", "(", "key", ")", ";", "Entry", "<", "K", ",", "V", ">", "entry", "=", "mCachedEntries", ".", "get", "(", "key", ")", ";", "if", "(", "entry", "!=", "null", ")", "{", "clientRef", "=", "newClientReference", "(", "entry", ")", ";", "}", "}", "maybeNotifyExclusiveEntryRemoval", "(", "oldExclusive", ")", ";", "maybeUpdateCacheParams", "(", ")", ";", "maybeEvictEntries", "(", ")", ";", "return", "clientRef", ";", "}" ]
Gets the item with the given key, or null if there is no such item. <p> It is the caller's responsibility to close the returned reference once not needed anymore.
[ "Gets", "the", "item", "with", "the", "given", "key", "or", "null", "if", "there", "is", "no", "such", "item", "." ]
0b85879d51c5036d5e46e627a6651afefc0b971a
https://github.com/facebook/fresco/blob/0b85879d51c5036d5e46e627a6651afefc0b971a/imagepipeline-base/src/main/java/com/facebook/imagepipeline/cache/CountingMemoryCache.java#L208-L224
14,574
facebook/fresco
imagepipeline-base/src/main/java/com/facebook/imagepipeline/cache/CountingMemoryCache.java
CountingMemoryCache.newClientReference
private synchronized CloseableReference<V> newClientReference(final Entry<K, V> entry) { increaseClientCount(entry); return CloseableReference.of( entry.valueRef.get(), new ResourceReleaser<V>() { @Override public void release(V unused) { releaseClientReference(entry); } }); }
java
private synchronized CloseableReference<V> newClientReference(final Entry<K, V> entry) { increaseClientCount(entry); return CloseableReference.of( entry.valueRef.get(), new ResourceReleaser<V>() { @Override public void release(V unused) { releaseClientReference(entry); } }); }
[ "private", "synchronized", "CloseableReference", "<", "V", ">", "newClientReference", "(", "final", "Entry", "<", "K", ",", "V", ">", "entry", ")", "{", "increaseClientCount", "(", "entry", ")", ";", "return", "CloseableReference", ".", "of", "(", "entry", ".", "valueRef", ".", "get", "(", ")", ",", "new", "ResourceReleaser", "<", "V", ">", "(", ")", "{", "@", "Override", "public", "void", "release", "(", "V", "unused", ")", "{", "releaseClientReference", "(", "entry", ")", ";", "}", "}", ")", ";", "}" ]
Creates a new reference for the client.
[ "Creates", "a", "new", "reference", "for", "the", "client", "." ]
0b85879d51c5036d5e46e627a6651afefc0b971a
https://github.com/facebook/fresco/blob/0b85879d51c5036d5e46e627a6651afefc0b971a/imagepipeline-base/src/main/java/com/facebook/imagepipeline/cache/CountingMemoryCache.java#L227-L237
14,575
facebook/fresco
imagepipeline-base/src/main/java/com/facebook/imagepipeline/cache/CountingMemoryCache.java
CountingMemoryCache.releaseClientReference
private void releaseClientReference(final Entry<K, V> entry) { Preconditions.checkNotNull(entry); boolean isExclusiveAdded; CloseableReference<V> oldRefToClose; synchronized (this) { decreaseClientCount(entry); isExclusiveAdded = maybeAddToExclusives(entry); oldRefToClose = referenceToClose(entry); } CloseableReference.closeSafely(oldRefToClose); maybeNotifyExclusiveEntryInsertion(isExclusiveAdded ? entry : null); maybeUpdateCacheParams(); maybeEvictEntries(); }
java
private void releaseClientReference(final Entry<K, V> entry) { Preconditions.checkNotNull(entry); boolean isExclusiveAdded; CloseableReference<V> oldRefToClose; synchronized (this) { decreaseClientCount(entry); isExclusiveAdded = maybeAddToExclusives(entry); oldRefToClose = referenceToClose(entry); } CloseableReference.closeSafely(oldRefToClose); maybeNotifyExclusiveEntryInsertion(isExclusiveAdded ? entry : null); maybeUpdateCacheParams(); maybeEvictEntries(); }
[ "private", "void", "releaseClientReference", "(", "final", "Entry", "<", "K", ",", "V", ">", "entry", ")", "{", "Preconditions", ".", "checkNotNull", "(", "entry", ")", ";", "boolean", "isExclusiveAdded", ";", "CloseableReference", "<", "V", ">", "oldRefToClose", ";", "synchronized", "(", "this", ")", "{", "decreaseClientCount", "(", "entry", ")", ";", "isExclusiveAdded", "=", "maybeAddToExclusives", "(", "entry", ")", ";", "oldRefToClose", "=", "referenceToClose", "(", "entry", ")", ";", "}", "CloseableReference", ".", "closeSafely", "(", "oldRefToClose", ")", ";", "maybeNotifyExclusiveEntryInsertion", "(", "isExclusiveAdded", "?", "entry", ":", "null", ")", ";", "maybeUpdateCacheParams", "(", ")", ";", "maybeEvictEntries", "(", ")", ";", "}" ]
Called when the client closes its reference.
[ "Called", "when", "the", "client", "closes", "its", "reference", "." ]
0b85879d51c5036d5e46e627a6651afefc0b971a
https://github.com/facebook/fresco/blob/0b85879d51c5036d5e46e627a6651afefc0b971a/imagepipeline-base/src/main/java/com/facebook/imagepipeline/cache/CountingMemoryCache.java#L240-L253
14,576
facebook/fresco
imagepipeline-base/src/main/java/com/facebook/imagepipeline/cache/CountingMemoryCache.java
CountingMemoryCache.maybeAddToExclusives
private synchronized boolean maybeAddToExclusives(Entry<K, V> entry) { if (!entry.isOrphan && entry.clientCount == 0) { mExclusiveEntries.put(entry.key, entry); return true; } return false; }
java
private synchronized boolean maybeAddToExclusives(Entry<K, V> entry) { if (!entry.isOrphan && entry.clientCount == 0) { mExclusiveEntries.put(entry.key, entry); return true; } return false; }
[ "private", "synchronized", "boolean", "maybeAddToExclusives", "(", "Entry", "<", "K", ",", "V", ">", "entry", ")", "{", "if", "(", "!", "entry", ".", "isOrphan", "&&", "entry", ".", "clientCount", "==", "0", ")", "{", "mExclusiveEntries", ".", "put", "(", "entry", ".", "key", ",", "entry", ")", ";", "return", "true", ";", "}", "return", "false", ";", "}" ]
Adds the entry to the exclusively owned queue if it is viable for eviction.
[ "Adds", "the", "entry", "to", "the", "exclusively", "owned", "queue", "if", "it", "is", "viable", "for", "eviction", "." ]
0b85879d51c5036d5e46e627a6651afefc0b971a
https://github.com/facebook/fresco/blob/0b85879d51c5036d5e46e627a6651afefc0b971a/imagepipeline-base/src/main/java/com/facebook/imagepipeline/cache/CountingMemoryCache.java#L256-L262
14,577
facebook/fresco
imagepipeline-base/src/main/java/com/facebook/imagepipeline/cache/CountingMemoryCache.java
CountingMemoryCache.reuse
@Nullable public CloseableReference<V> reuse(K key) { Preconditions.checkNotNull(key); CloseableReference<V> clientRef = null; boolean removed = false; Entry<K, V> oldExclusive = null; synchronized (this) { oldExclusive = mExclusiveEntries.remove(key); if (oldExclusive != null) { Entry<K, V> entry = mCachedEntries.remove(key); Preconditions.checkNotNull(entry); Preconditions.checkState(entry.clientCount == 0); // optimization: instead of cloning and then closing the original reference, // we just do a move clientRef = entry.valueRef; removed = true; } } if (removed) { maybeNotifyExclusiveEntryRemoval(oldExclusive); } return clientRef; }
java
@Nullable public CloseableReference<V> reuse(K key) { Preconditions.checkNotNull(key); CloseableReference<V> clientRef = null; boolean removed = false; Entry<K, V> oldExclusive = null; synchronized (this) { oldExclusive = mExclusiveEntries.remove(key); if (oldExclusive != null) { Entry<K, V> entry = mCachedEntries.remove(key); Preconditions.checkNotNull(entry); Preconditions.checkState(entry.clientCount == 0); // optimization: instead of cloning and then closing the original reference, // we just do a move clientRef = entry.valueRef; removed = true; } } if (removed) { maybeNotifyExclusiveEntryRemoval(oldExclusive); } return clientRef; }
[ "@", "Nullable", "public", "CloseableReference", "<", "V", ">", "reuse", "(", "K", "key", ")", "{", "Preconditions", ".", "checkNotNull", "(", "key", ")", ";", "CloseableReference", "<", "V", ">", "clientRef", "=", "null", ";", "boolean", "removed", "=", "false", ";", "Entry", "<", "K", ",", "V", ">", "oldExclusive", "=", "null", ";", "synchronized", "(", "this", ")", "{", "oldExclusive", "=", "mExclusiveEntries", ".", "remove", "(", "key", ")", ";", "if", "(", "oldExclusive", "!=", "null", ")", "{", "Entry", "<", "K", ",", "V", ">", "entry", "=", "mCachedEntries", ".", "remove", "(", "key", ")", ";", "Preconditions", ".", "checkNotNull", "(", "entry", ")", ";", "Preconditions", ".", "checkState", "(", "entry", ".", "clientCount", "==", "0", ")", ";", "// optimization: instead of cloning and then closing the original reference,", "// we just do a move", "clientRef", "=", "entry", ".", "valueRef", ";", "removed", "=", "true", ";", "}", "}", "if", "(", "removed", ")", "{", "maybeNotifyExclusiveEntryRemoval", "(", "oldExclusive", ")", ";", "}", "return", "clientRef", ";", "}" ]
Gets the value with the given key to be reused, or null if there is no such value. <p> The item can be reused only if it is exclusively owned by the cache.
[ "Gets", "the", "value", "with", "the", "given", "key", "to", "be", "reused", "or", "null", "if", "there", "is", "no", "such", "value", "." ]
0b85879d51c5036d5e46e627a6651afefc0b971a
https://github.com/facebook/fresco/blob/0b85879d51c5036d5e46e627a6651afefc0b971a/imagepipeline-base/src/main/java/com/facebook/imagepipeline/cache/CountingMemoryCache.java#L269-L291
14,578
facebook/fresco
imagepipeline-base/src/main/java/com/facebook/imagepipeline/cache/CountingMemoryCache.java
CountingMemoryCache.removeAll
public int removeAll(Predicate<K> predicate) { ArrayList<Entry<K, V>> oldExclusives; ArrayList<Entry<K, V>> oldEntries; synchronized (this) { oldExclusives = mExclusiveEntries.removeAll(predicate); oldEntries = mCachedEntries.removeAll(predicate); makeOrphans(oldEntries); } maybeClose(oldEntries); maybeNotifyExclusiveEntryRemoval(oldExclusives); maybeUpdateCacheParams(); maybeEvictEntries(); return oldEntries.size(); }
java
public int removeAll(Predicate<K> predicate) { ArrayList<Entry<K, V>> oldExclusives; ArrayList<Entry<K, V>> oldEntries; synchronized (this) { oldExclusives = mExclusiveEntries.removeAll(predicate); oldEntries = mCachedEntries.removeAll(predicate); makeOrphans(oldEntries); } maybeClose(oldEntries); maybeNotifyExclusiveEntryRemoval(oldExclusives); maybeUpdateCacheParams(); maybeEvictEntries(); return oldEntries.size(); }
[ "public", "int", "removeAll", "(", "Predicate", "<", "K", ">", "predicate", ")", "{", "ArrayList", "<", "Entry", "<", "K", ",", "V", ">", ">", "oldExclusives", ";", "ArrayList", "<", "Entry", "<", "K", ",", "V", ">", ">", "oldEntries", ";", "synchronized", "(", "this", ")", "{", "oldExclusives", "=", "mExclusiveEntries", ".", "removeAll", "(", "predicate", ")", ";", "oldEntries", "=", "mCachedEntries", ".", "removeAll", "(", "predicate", ")", ";", "makeOrphans", "(", "oldEntries", ")", ";", "}", "maybeClose", "(", "oldEntries", ")", ";", "maybeNotifyExclusiveEntryRemoval", "(", "oldExclusives", ")", ";", "maybeUpdateCacheParams", "(", ")", ";", "maybeEvictEntries", "(", ")", ";", "return", "oldEntries", ".", "size", "(", ")", ";", "}" ]
Removes all the items from the cache whose key matches the specified predicate. @param predicate returns true if an item with the given key should be removed @return number of the items removed from the cache
[ "Removes", "all", "the", "items", "from", "the", "cache", "whose", "key", "matches", "the", "specified", "predicate", "." ]
0b85879d51c5036d5e46e627a6651afefc0b971a
https://github.com/facebook/fresco/blob/0b85879d51c5036d5e46e627a6651afefc0b971a/imagepipeline-base/src/main/java/com/facebook/imagepipeline/cache/CountingMemoryCache.java#L299-L312
14,579
facebook/fresco
imagepipeline-base/src/main/java/com/facebook/imagepipeline/cache/CountingMemoryCache.java
CountingMemoryCache.clear
public void clear() { ArrayList<Entry<K, V>> oldExclusives; ArrayList<Entry<K, V>> oldEntries; synchronized (this) { oldExclusives = mExclusiveEntries.clear(); oldEntries = mCachedEntries.clear(); makeOrphans(oldEntries); } maybeClose(oldEntries); maybeNotifyExclusiveEntryRemoval(oldExclusives); maybeUpdateCacheParams(); }
java
public void clear() { ArrayList<Entry<K, V>> oldExclusives; ArrayList<Entry<K, V>> oldEntries; synchronized (this) { oldExclusives = mExclusiveEntries.clear(); oldEntries = mCachedEntries.clear(); makeOrphans(oldEntries); } maybeClose(oldEntries); maybeNotifyExclusiveEntryRemoval(oldExclusives); maybeUpdateCacheParams(); }
[ "public", "void", "clear", "(", ")", "{", "ArrayList", "<", "Entry", "<", "K", ",", "V", ">", ">", "oldExclusives", ";", "ArrayList", "<", "Entry", "<", "K", ",", "V", ">", ">", "oldEntries", ";", "synchronized", "(", "this", ")", "{", "oldExclusives", "=", "mExclusiveEntries", ".", "clear", "(", ")", ";", "oldEntries", "=", "mCachedEntries", ".", "clear", "(", ")", ";", "makeOrphans", "(", "oldEntries", ")", ";", "}", "maybeClose", "(", "oldEntries", ")", ";", "maybeNotifyExclusiveEntryRemoval", "(", "oldExclusives", ")", ";", "maybeUpdateCacheParams", "(", ")", ";", "}" ]
Removes all the items from the cache.
[ "Removes", "all", "the", "items", "from", "the", "cache", "." ]
0b85879d51c5036d5e46e627a6651afefc0b971a
https://github.com/facebook/fresco/blob/0b85879d51c5036d5e46e627a6651afefc0b971a/imagepipeline-base/src/main/java/com/facebook/imagepipeline/cache/CountingMemoryCache.java#L315-L326
14,580
facebook/fresco
imagepipeline-base/src/main/java/com/facebook/imagepipeline/cache/CountingMemoryCache.java
CountingMemoryCache.trim
@Override public void trim(MemoryTrimType trimType) { ArrayList<Entry<K, V>> oldEntries; final double trimRatio = mCacheTrimStrategy.getTrimRatio(trimType); synchronized (this) { int targetCacheSize = (int) (mCachedEntries.getSizeInBytes() * (1 - trimRatio)); int targetEvictionQueueSize = Math.max(0, targetCacheSize - getInUseSizeInBytes()); oldEntries = trimExclusivelyOwnedEntries(Integer.MAX_VALUE, targetEvictionQueueSize); makeOrphans(oldEntries); } maybeClose(oldEntries); maybeNotifyExclusiveEntryRemoval(oldEntries); maybeUpdateCacheParams(); maybeEvictEntries(); }
java
@Override public void trim(MemoryTrimType trimType) { ArrayList<Entry<K, V>> oldEntries; final double trimRatio = mCacheTrimStrategy.getTrimRatio(trimType); synchronized (this) { int targetCacheSize = (int) (mCachedEntries.getSizeInBytes() * (1 - trimRatio)); int targetEvictionQueueSize = Math.max(0, targetCacheSize - getInUseSizeInBytes()); oldEntries = trimExclusivelyOwnedEntries(Integer.MAX_VALUE, targetEvictionQueueSize); makeOrphans(oldEntries); } maybeClose(oldEntries); maybeNotifyExclusiveEntryRemoval(oldEntries); maybeUpdateCacheParams(); maybeEvictEntries(); }
[ "@", "Override", "public", "void", "trim", "(", "MemoryTrimType", "trimType", ")", "{", "ArrayList", "<", "Entry", "<", "K", ",", "V", ">", ">", "oldEntries", ";", "final", "double", "trimRatio", "=", "mCacheTrimStrategy", ".", "getTrimRatio", "(", "trimType", ")", ";", "synchronized", "(", "this", ")", "{", "int", "targetCacheSize", "=", "(", "int", ")", "(", "mCachedEntries", ".", "getSizeInBytes", "(", ")", "*", "(", "1", "-", "trimRatio", ")", ")", ";", "int", "targetEvictionQueueSize", "=", "Math", ".", "max", "(", "0", ",", "targetCacheSize", "-", "getInUseSizeInBytes", "(", ")", ")", ";", "oldEntries", "=", "trimExclusivelyOwnedEntries", "(", "Integer", ".", "MAX_VALUE", ",", "targetEvictionQueueSize", ")", ";", "makeOrphans", "(", "oldEntries", ")", ";", "}", "maybeClose", "(", "oldEntries", ")", ";", "maybeNotifyExclusiveEntryRemoval", "(", "oldEntries", ")", ";", "maybeUpdateCacheParams", "(", ")", ";", "maybeEvictEntries", "(", ")", ";", "}" ]
Trims the cache according to the specified trimming strategy and the given trim type.
[ "Trims", "the", "cache", "according", "to", "the", "specified", "trimming", "strategy", "and", "the", "given", "trim", "type", "." ]
0b85879d51c5036d5e46e627a6651afefc0b971a
https://github.com/facebook/fresco/blob/0b85879d51c5036d5e46e627a6651afefc0b971a/imagepipeline-base/src/main/java/com/facebook/imagepipeline/cache/CountingMemoryCache.java#L351-L365
14,581
facebook/fresco
imagepipeline-base/src/main/java/com/facebook/imagepipeline/cache/CountingMemoryCache.java
CountingMemoryCache.maybeEvictEntries
private void maybeEvictEntries() { ArrayList<Entry<K, V>> oldEntries; synchronized (this) { int maxCount = Math.min( mMemoryCacheParams.maxEvictionQueueEntries, mMemoryCacheParams.maxCacheEntries - getInUseCount()); int maxSize = Math.min( mMemoryCacheParams.maxEvictionQueueSize, mMemoryCacheParams.maxCacheSize - getInUseSizeInBytes()); oldEntries = trimExclusivelyOwnedEntries(maxCount, maxSize); makeOrphans(oldEntries); } maybeClose(oldEntries); maybeNotifyExclusiveEntryRemoval(oldEntries); }
java
private void maybeEvictEntries() { ArrayList<Entry<K, V>> oldEntries; synchronized (this) { int maxCount = Math.min( mMemoryCacheParams.maxEvictionQueueEntries, mMemoryCacheParams.maxCacheEntries - getInUseCount()); int maxSize = Math.min( mMemoryCacheParams.maxEvictionQueueSize, mMemoryCacheParams.maxCacheSize - getInUseSizeInBytes()); oldEntries = trimExclusivelyOwnedEntries(maxCount, maxSize); makeOrphans(oldEntries); } maybeClose(oldEntries); maybeNotifyExclusiveEntryRemoval(oldEntries); }
[ "private", "void", "maybeEvictEntries", "(", ")", "{", "ArrayList", "<", "Entry", "<", "K", ",", "V", ">", ">", "oldEntries", ";", "synchronized", "(", "this", ")", "{", "int", "maxCount", "=", "Math", ".", "min", "(", "mMemoryCacheParams", ".", "maxEvictionQueueEntries", ",", "mMemoryCacheParams", ".", "maxCacheEntries", "-", "getInUseCount", "(", ")", ")", ";", "int", "maxSize", "=", "Math", ".", "min", "(", "mMemoryCacheParams", ".", "maxEvictionQueueSize", ",", "mMemoryCacheParams", ".", "maxCacheSize", "-", "getInUseSizeInBytes", "(", ")", ")", ";", "oldEntries", "=", "trimExclusivelyOwnedEntries", "(", "maxCount", ",", "maxSize", ")", ";", "makeOrphans", "(", "oldEntries", ")", ";", "}", "maybeClose", "(", "oldEntries", ")", ";", "maybeNotifyExclusiveEntryRemoval", "(", "oldEntries", ")", ";", "}" ]
Removes the exclusively owned items until the cache constraints are met. <p> This method invokes the external {@link CloseableReference#close} method, so it must not be called while holding the <code>this</code> lock.
[ "Removes", "the", "exclusively", "owned", "items", "until", "the", "cache", "constraints", "are", "met", "." ]
0b85879d51c5036d5e46e627a6651afefc0b971a
https://github.com/facebook/fresco/blob/0b85879d51c5036d5e46e627a6651afefc0b971a/imagepipeline-base/src/main/java/com/facebook/imagepipeline/cache/CountingMemoryCache.java#L385-L399
14,582
facebook/fresco
imagepipeline-base/src/main/java/com/facebook/imagepipeline/cache/CountingMemoryCache.java
CountingMemoryCache.makeOrphan
private synchronized void makeOrphan(Entry<K, V> entry) { Preconditions.checkNotNull(entry); Preconditions.checkState(!entry.isOrphan); entry.isOrphan = true; }
java
private synchronized void makeOrphan(Entry<K, V> entry) { Preconditions.checkNotNull(entry); Preconditions.checkState(!entry.isOrphan); entry.isOrphan = true; }
[ "private", "synchronized", "void", "makeOrphan", "(", "Entry", "<", "K", ",", "V", ">", "entry", ")", "{", "Preconditions", ".", "checkNotNull", "(", "entry", ")", ";", "Preconditions", ".", "checkState", "(", "!", "entry", ".", "isOrphan", ")", ";", "entry", ".", "isOrphan", "=", "true", ";", "}" ]
Marks the entry as orphan.
[ "Marks", "the", "entry", "as", "orphan", "." ]
0b85879d51c5036d5e46e627a6651afefc0b971a
https://github.com/facebook/fresco/blob/0b85879d51c5036d5e46e627a6651afefc0b971a/imagepipeline-base/src/main/java/com/facebook/imagepipeline/cache/CountingMemoryCache.java#L469-L473
14,583
facebook/fresco
imagepipeline-base/src/main/java/com/facebook/imagepipeline/cache/CountingMemoryCache.java
CountingMemoryCache.increaseClientCount
private synchronized void increaseClientCount(Entry<K, V> entry) { Preconditions.checkNotNull(entry); Preconditions.checkState(!entry.isOrphan); entry.clientCount++; }
java
private synchronized void increaseClientCount(Entry<K, V> entry) { Preconditions.checkNotNull(entry); Preconditions.checkState(!entry.isOrphan); entry.clientCount++; }
[ "private", "synchronized", "void", "increaseClientCount", "(", "Entry", "<", "K", ",", "V", ">", "entry", ")", "{", "Preconditions", ".", "checkNotNull", "(", "entry", ")", ";", "Preconditions", ".", "checkState", "(", "!", "entry", ".", "isOrphan", ")", ";", "entry", ".", "clientCount", "++", ";", "}" ]
Increases the entry's client count.
[ "Increases", "the", "entry", "s", "client", "count", "." ]
0b85879d51c5036d5e46e627a6651afefc0b971a
https://github.com/facebook/fresco/blob/0b85879d51c5036d5e46e627a6651afefc0b971a/imagepipeline-base/src/main/java/com/facebook/imagepipeline/cache/CountingMemoryCache.java#L476-L480
14,584
facebook/fresco
imagepipeline-base/src/main/java/com/facebook/imagepipeline/cache/CountingMemoryCache.java
CountingMemoryCache.decreaseClientCount
private synchronized void decreaseClientCount(Entry<K, V> entry) { Preconditions.checkNotNull(entry); Preconditions.checkState(entry.clientCount > 0); entry.clientCount--; }
java
private synchronized void decreaseClientCount(Entry<K, V> entry) { Preconditions.checkNotNull(entry); Preconditions.checkState(entry.clientCount > 0); entry.clientCount--; }
[ "private", "synchronized", "void", "decreaseClientCount", "(", "Entry", "<", "K", ",", "V", ">", "entry", ")", "{", "Preconditions", ".", "checkNotNull", "(", "entry", ")", ";", "Preconditions", ".", "checkState", "(", "entry", ".", "clientCount", ">", "0", ")", ";", "entry", ".", "clientCount", "--", ";", "}" ]
Decreases the entry's client count.
[ "Decreases", "the", "entry", "s", "client", "count", "." ]
0b85879d51c5036d5e46e627a6651afefc0b971a
https://github.com/facebook/fresco/blob/0b85879d51c5036d5e46e627a6651afefc0b971a/imagepipeline-base/src/main/java/com/facebook/imagepipeline/cache/CountingMemoryCache.java#L483-L487
14,585
facebook/fresco
imagepipeline-base/src/main/java/com/facebook/imagepipeline/cache/CountingMemoryCache.java
CountingMemoryCache.referenceToClose
@Nullable private synchronized CloseableReference<V> referenceToClose(Entry<K, V> entry) { Preconditions.checkNotNull(entry); return (entry.isOrphan && entry.clientCount == 0) ? entry.valueRef : null; }
java
@Nullable private synchronized CloseableReference<V> referenceToClose(Entry<K, V> entry) { Preconditions.checkNotNull(entry); return (entry.isOrphan && entry.clientCount == 0) ? entry.valueRef : null; }
[ "@", "Nullable", "private", "synchronized", "CloseableReference", "<", "V", ">", "referenceToClose", "(", "Entry", "<", "K", ",", "V", ">", "entry", ")", "{", "Preconditions", ".", "checkNotNull", "(", "entry", ")", ";", "return", "(", "entry", ".", "isOrphan", "&&", "entry", ".", "clientCount", "==", "0", ")", "?", "entry", ".", "valueRef", ":", "null", ";", "}" ]
Returns the value reference of the entry if it should be closed, null otherwise.
[ "Returns", "the", "value", "reference", "of", "the", "entry", "if", "it", "should", "be", "closed", "null", "otherwise", "." ]
0b85879d51c5036d5e46e627a6651afefc0b971a
https://github.com/facebook/fresco/blob/0b85879d51c5036d5e46e627a6651afefc0b971a/imagepipeline-base/src/main/java/com/facebook/imagepipeline/cache/CountingMemoryCache.java#L490-L494
14,586
facebook/fresco
drawee/src/main/java/com/facebook/drawee/view/DraweeHolder.java
DraweeHolder.onVisibilityChange
@Override public void onVisibilityChange(boolean isVisible) { if (mIsVisible == isVisible) { return; } mEventTracker.recordEvent(isVisible ? Event.ON_DRAWABLE_SHOW : Event.ON_DRAWABLE_HIDE); mIsVisible = isVisible; attachOrDetachController(); }
java
@Override public void onVisibilityChange(boolean isVisible) { if (mIsVisible == isVisible) { return; } mEventTracker.recordEvent(isVisible ? Event.ON_DRAWABLE_SHOW : Event.ON_DRAWABLE_HIDE); mIsVisible = isVisible; attachOrDetachController(); }
[ "@", "Override", "public", "void", "onVisibilityChange", "(", "boolean", "isVisible", ")", "{", "if", "(", "mIsVisible", "==", "isVisible", ")", "{", "return", ";", "}", "mEventTracker", ".", "recordEvent", "(", "isVisible", "?", "Event", ".", "ON_DRAWABLE_SHOW", ":", "Event", ".", "ON_DRAWABLE_HIDE", ")", ";", "mIsVisible", "=", "isVisible", ";", "attachOrDetachController", "(", ")", ";", "}" ]
Callback used to notify about top-level-drawable's visibility changes.
[ "Callback", "used", "to", "notify", "about", "top", "-", "level", "-", "drawable", "s", "visibility", "changes", "." ]
0b85879d51c5036d5e46e627a6651afefc0b971a
https://github.com/facebook/fresco/blob/0b85879d51c5036d5e46e627a6651afefc0b971a/drawee/src/main/java/com/facebook/drawee/view/DraweeHolder.java#L131-L139
14,587
facebook/fresco
drawee/src/main/java/com/facebook/drawee/view/DraweeHolder.java
DraweeHolder.onDraw
@Override public void onDraw() { // draw is only expected if the controller is attached if (mIsControllerAttached) { return; } // something went wrong here; controller is not attached, yet the hierarchy has to be drawn // log error and attach the controller FLog.w( DraweeEventTracker.class, "%x: Draw requested for a non-attached controller %x. %s", System.identityHashCode(this), System.identityHashCode(mController), toString()); mIsHolderAttached = true; mIsVisible = true; attachOrDetachController(); }
java
@Override public void onDraw() { // draw is only expected if the controller is attached if (mIsControllerAttached) { return; } // something went wrong here; controller is not attached, yet the hierarchy has to be drawn // log error and attach the controller FLog.w( DraweeEventTracker.class, "%x: Draw requested for a non-attached controller %x. %s", System.identityHashCode(this), System.identityHashCode(mController), toString()); mIsHolderAttached = true; mIsVisible = true; attachOrDetachController(); }
[ "@", "Override", "public", "void", "onDraw", "(", ")", "{", "// draw is only expected if the controller is attached", "if", "(", "mIsControllerAttached", ")", "{", "return", ";", "}", "// something went wrong here; controller is not attached, yet the hierarchy has to be drawn", "// log error and attach the controller", "FLog", ".", "w", "(", "DraweeEventTracker", ".", "class", ",", "\"%x: Draw requested for a non-attached controller %x. %s\"", ",", "System", ".", "identityHashCode", "(", "this", ")", ",", "System", ".", "identityHashCode", "(", "mController", ")", ",", "toString", "(", ")", ")", ";", "mIsHolderAttached", "=", "true", ";", "mIsVisible", "=", "true", ";", "attachOrDetachController", "(", ")", ";", "}" ]
Callback used to notify about top-level-drawable being drawn.
[ "Callback", "used", "to", "notify", "about", "top", "-", "level", "-", "drawable", "being", "drawn", "." ]
0b85879d51c5036d5e46e627a6651afefc0b971a
https://github.com/facebook/fresco/blob/0b85879d51c5036d5e46e627a6651afefc0b971a/drawee/src/main/java/com/facebook/drawee/view/DraweeHolder.java#L144-L163
14,588
facebook/fresco
drawee/src/main/java/com/facebook/drawee/view/DraweeHolder.java
DraweeHolder.setHierarchy
public void setHierarchy(DH hierarchy) { mEventTracker.recordEvent(Event.ON_SET_HIERARCHY); final boolean isControllerValid = isControllerValid(); setVisibilityCallback(null); mHierarchy = Preconditions.checkNotNull(hierarchy); Drawable drawable = mHierarchy.getTopLevelDrawable(); onVisibilityChange(drawable == null || drawable.isVisible()); setVisibilityCallback(this); if (isControllerValid) { mController.setHierarchy(hierarchy); } }
java
public void setHierarchy(DH hierarchy) { mEventTracker.recordEvent(Event.ON_SET_HIERARCHY); final boolean isControllerValid = isControllerValid(); setVisibilityCallback(null); mHierarchy = Preconditions.checkNotNull(hierarchy); Drawable drawable = mHierarchy.getTopLevelDrawable(); onVisibilityChange(drawable == null || drawable.isVisible()); setVisibilityCallback(this); if (isControllerValid) { mController.setHierarchy(hierarchy); } }
[ "public", "void", "setHierarchy", "(", "DH", "hierarchy", ")", "{", "mEventTracker", ".", "recordEvent", "(", "Event", ".", "ON_SET_HIERARCHY", ")", ";", "final", "boolean", "isControllerValid", "=", "isControllerValid", "(", ")", ";", "setVisibilityCallback", "(", "null", ")", ";", "mHierarchy", "=", "Preconditions", ".", "checkNotNull", "(", "hierarchy", ")", ";", "Drawable", "drawable", "=", "mHierarchy", ".", "getTopLevelDrawable", "(", ")", ";", "onVisibilityChange", "(", "drawable", "==", "null", "||", "drawable", ".", "isVisible", "(", ")", ")", ";", "setVisibilityCallback", "(", "this", ")", ";", "if", "(", "isControllerValid", ")", "{", "mController", ".", "setHierarchy", "(", "hierarchy", ")", ";", "}", "}" ]
Sets the drawee hierarchy.
[ "Sets", "the", "drawee", "hierarchy", "." ]
0b85879d51c5036d5e46e627a6651afefc0b971a
https://github.com/facebook/fresco/blob/0b85879d51c5036d5e46e627a6651afefc0b971a/drawee/src/main/java/com/facebook/drawee/view/DraweeHolder.java#L212-L225
14,589
facebook/fresco
imagepipeline/src/main/java/com/facebook/imagepipeline/request/BasePostprocessor.java
BasePostprocessor.process
@Override public CloseableReference<Bitmap> process( Bitmap sourceBitmap, PlatformBitmapFactory bitmapFactory) { final Bitmap.Config sourceBitmapConfig = sourceBitmap.getConfig(); CloseableReference<Bitmap> destBitmapRef = bitmapFactory.createBitmapInternal( sourceBitmap.getWidth(), sourceBitmap.getHeight(), sourceBitmapConfig != null ? sourceBitmapConfig : FALLBACK_BITMAP_CONFIGURATION); try { process(destBitmapRef.get(), sourceBitmap); return CloseableReference.cloneOrNull(destBitmapRef); } finally { CloseableReference.closeSafely(destBitmapRef); } }
java
@Override public CloseableReference<Bitmap> process( Bitmap sourceBitmap, PlatformBitmapFactory bitmapFactory) { final Bitmap.Config sourceBitmapConfig = sourceBitmap.getConfig(); CloseableReference<Bitmap> destBitmapRef = bitmapFactory.createBitmapInternal( sourceBitmap.getWidth(), sourceBitmap.getHeight(), sourceBitmapConfig != null ? sourceBitmapConfig : FALLBACK_BITMAP_CONFIGURATION); try { process(destBitmapRef.get(), sourceBitmap); return CloseableReference.cloneOrNull(destBitmapRef); } finally { CloseableReference.closeSafely(destBitmapRef); } }
[ "@", "Override", "public", "CloseableReference", "<", "Bitmap", ">", "process", "(", "Bitmap", "sourceBitmap", ",", "PlatformBitmapFactory", "bitmapFactory", ")", "{", "final", "Bitmap", ".", "Config", "sourceBitmapConfig", "=", "sourceBitmap", ".", "getConfig", "(", ")", ";", "CloseableReference", "<", "Bitmap", ">", "destBitmapRef", "=", "bitmapFactory", ".", "createBitmapInternal", "(", "sourceBitmap", ".", "getWidth", "(", ")", ",", "sourceBitmap", ".", "getHeight", "(", ")", ",", "sourceBitmapConfig", "!=", "null", "?", "sourceBitmapConfig", ":", "FALLBACK_BITMAP_CONFIGURATION", ")", ";", "try", "{", "process", "(", "destBitmapRef", ".", "get", "(", ")", ",", "sourceBitmap", ")", ";", "return", "CloseableReference", ".", "cloneOrNull", "(", "destBitmapRef", ")", ";", "}", "finally", "{", "CloseableReference", ".", "closeSafely", "(", "destBitmapRef", ")", ";", "}", "}" ]
Clients should override this method only if the post-processed bitmap has to be of a different size than the source bitmap. If the post-processed bitmap is of the same size, clients should override one of the other two methods. <p> The source bitmap must not be modified as it may be shared by the other clients. The implementation must create a new bitmap that is safe to be modified and return a reference to it. Clients should use <code>bitmapFactory</code> to create a new bitmap. @param sourceBitmap The source bitmap. @param bitmapFactory The factory to create a destination bitmap. @return a reference to the newly created bitmap
[ "Clients", "should", "override", "this", "method", "only", "if", "the", "post", "-", "processed", "bitmap", "has", "to", "be", "of", "a", "different", "size", "than", "the", "source", "bitmap", ".", "If", "the", "post", "-", "processed", "bitmap", "is", "of", "the", "same", "size", "clients", "should", "override", "one", "of", "the", "other", "two", "methods", "." ]
0b85879d51c5036d5e46e627a6651afefc0b971a
https://github.com/facebook/fresco/blob/0b85879d51c5036d5e46e627a6651afefc0b971a/imagepipeline/src/main/java/com/facebook/imagepipeline/request/BasePostprocessor.java#L50-L66
14,590
facebook/fresco
imagepipeline/src/main/java/com/facebook/imagepipeline/decoder/ProgressiveJpegParser.java
ProgressiveJpegParser.doParseMoreData
private boolean doParseMoreData(final InputStream inputStream) { final int oldBestScanNumber = mBestScanNumber; try { int nextByte; while (mParserState != NOT_A_JPEG && (nextByte = inputStream.read()) != -1) { mBytesParsed++; if (mEndMarkerRead) { // There should be no more data after the EOI marker, just in case there is lets // bail out instead of trying to parse the unknown data mParserState = NOT_A_JPEG; mEndMarkerRead = false; return false; } switch (mParserState) { case READ_FIRST_JPEG_BYTE: if (nextByte == JfifUtil.MARKER_FIRST_BYTE) { mParserState = READ_SECOND_JPEG_BYTE; } else { mParserState = NOT_A_JPEG; } break; case READ_SECOND_JPEG_BYTE: if (nextByte == JfifUtil.MARKER_SOI) { mParserState = READ_MARKER_FIRST_BYTE_OR_ENTROPY_DATA; } else { mParserState = NOT_A_JPEG; } break; case READ_MARKER_FIRST_BYTE_OR_ENTROPY_DATA: if (nextByte == JfifUtil.MARKER_FIRST_BYTE) { mParserState = READ_MARKER_SECOND_BYTE; } break; case READ_MARKER_SECOND_BYTE: if (nextByte == JfifUtil.MARKER_FIRST_BYTE) { mParserState = READ_MARKER_SECOND_BYTE; } else if (nextByte == JfifUtil.MARKER_ESCAPE_BYTE) { mParserState = READ_MARKER_FIRST_BYTE_OR_ENTROPY_DATA; } else if (nextByte == JfifUtil.MARKER_EOI) { mEndMarkerRead = true; newScanOrImageEndFound(mBytesParsed - 2); // There should be no data after the EOI marker, but in case there is, let's process // the next byte as a first marker byte. mParserState = READ_MARKER_FIRST_BYTE_OR_ENTROPY_DATA; } else { if (nextByte == JfifUtil.MARKER_SOS) { newScanOrImageEndFound(mBytesParsed - 2); } if (doesMarkerStartSegment(nextByte)) { mParserState = READ_SIZE_FIRST_BYTE; } else { mParserState = READ_MARKER_FIRST_BYTE_OR_ENTROPY_DATA; } } break; case READ_SIZE_FIRST_BYTE: mParserState = READ_SIZE_SECOND_BYTE; break; case READ_SIZE_SECOND_BYTE: final int size = (mLastByteRead << 8) + nextByte; // We need to jump after the end of the segment - skip size-2 next bytes. // We might want to skip more data than is available to read, in which case we will // consume entire data in inputStream and exit this function before entering another // iteration of the loop. final int bytesToSkip = size - 2; StreamUtil.skip(inputStream, bytesToSkip); mBytesParsed += bytesToSkip; mParserState = READ_MARKER_FIRST_BYTE_OR_ENTROPY_DATA; break; case NOT_A_JPEG: default: Preconditions.checkState(false); } mLastByteRead = nextByte; } } catch (IOException ioe) { // does not happen, input stream returned by pooled byte buffer does not throw IOExceptions Throwables.propagate(ioe); } return mParserState != NOT_A_JPEG && mBestScanNumber != oldBestScanNumber; }
java
private boolean doParseMoreData(final InputStream inputStream) { final int oldBestScanNumber = mBestScanNumber; try { int nextByte; while (mParserState != NOT_A_JPEG && (nextByte = inputStream.read()) != -1) { mBytesParsed++; if (mEndMarkerRead) { // There should be no more data after the EOI marker, just in case there is lets // bail out instead of trying to parse the unknown data mParserState = NOT_A_JPEG; mEndMarkerRead = false; return false; } switch (mParserState) { case READ_FIRST_JPEG_BYTE: if (nextByte == JfifUtil.MARKER_FIRST_BYTE) { mParserState = READ_SECOND_JPEG_BYTE; } else { mParserState = NOT_A_JPEG; } break; case READ_SECOND_JPEG_BYTE: if (nextByte == JfifUtil.MARKER_SOI) { mParserState = READ_MARKER_FIRST_BYTE_OR_ENTROPY_DATA; } else { mParserState = NOT_A_JPEG; } break; case READ_MARKER_FIRST_BYTE_OR_ENTROPY_DATA: if (nextByte == JfifUtil.MARKER_FIRST_BYTE) { mParserState = READ_MARKER_SECOND_BYTE; } break; case READ_MARKER_SECOND_BYTE: if (nextByte == JfifUtil.MARKER_FIRST_BYTE) { mParserState = READ_MARKER_SECOND_BYTE; } else if (nextByte == JfifUtil.MARKER_ESCAPE_BYTE) { mParserState = READ_MARKER_FIRST_BYTE_OR_ENTROPY_DATA; } else if (nextByte == JfifUtil.MARKER_EOI) { mEndMarkerRead = true; newScanOrImageEndFound(mBytesParsed - 2); // There should be no data after the EOI marker, but in case there is, let's process // the next byte as a first marker byte. mParserState = READ_MARKER_FIRST_BYTE_OR_ENTROPY_DATA; } else { if (nextByte == JfifUtil.MARKER_SOS) { newScanOrImageEndFound(mBytesParsed - 2); } if (doesMarkerStartSegment(nextByte)) { mParserState = READ_SIZE_FIRST_BYTE; } else { mParserState = READ_MARKER_FIRST_BYTE_OR_ENTROPY_DATA; } } break; case READ_SIZE_FIRST_BYTE: mParserState = READ_SIZE_SECOND_BYTE; break; case READ_SIZE_SECOND_BYTE: final int size = (mLastByteRead << 8) + nextByte; // We need to jump after the end of the segment - skip size-2 next bytes. // We might want to skip more data than is available to read, in which case we will // consume entire data in inputStream and exit this function before entering another // iteration of the loop. final int bytesToSkip = size - 2; StreamUtil.skip(inputStream, bytesToSkip); mBytesParsed += bytesToSkip; mParserState = READ_MARKER_FIRST_BYTE_OR_ENTROPY_DATA; break; case NOT_A_JPEG: default: Preconditions.checkState(false); } mLastByteRead = nextByte; } } catch (IOException ioe) { // does not happen, input stream returned by pooled byte buffer does not throw IOExceptions Throwables.propagate(ioe); } return mParserState != NOT_A_JPEG && mBestScanNumber != oldBestScanNumber; }
[ "private", "boolean", "doParseMoreData", "(", "final", "InputStream", "inputStream", ")", "{", "final", "int", "oldBestScanNumber", "=", "mBestScanNumber", ";", "try", "{", "int", "nextByte", ";", "while", "(", "mParserState", "!=", "NOT_A_JPEG", "&&", "(", "nextByte", "=", "inputStream", ".", "read", "(", ")", ")", "!=", "-", "1", ")", "{", "mBytesParsed", "++", ";", "if", "(", "mEndMarkerRead", ")", "{", "// There should be no more data after the EOI marker, just in case there is lets", "// bail out instead of trying to parse the unknown data", "mParserState", "=", "NOT_A_JPEG", ";", "mEndMarkerRead", "=", "false", ";", "return", "false", ";", "}", "switch", "(", "mParserState", ")", "{", "case", "READ_FIRST_JPEG_BYTE", ":", "if", "(", "nextByte", "==", "JfifUtil", ".", "MARKER_FIRST_BYTE", ")", "{", "mParserState", "=", "READ_SECOND_JPEG_BYTE", ";", "}", "else", "{", "mParserState", "=", "NOT_A_JPEG", ";", "}", "break", ";", "case", "READ_SECOND_JPEG_BYTE", ":", "if", "(", "nextByte", "==", "JfifUtil", ".", "MARKER_SOI", ")", "{", "mParserState", "=", "READ_MARKER_FIRST_BYTE_OR_ENTROPY_DATA", ";", "}", "else", "{", "mParserState", "=", "NOT_A_JPEG", ";", "}", "break", ";", "case", "READ_MARKER_FIRST_BYTE_OR_ENTROPY_DATA", ":", "if", "(", "nextByte", "==", "JfifUtil", ".", "MARKER_FIRST_BYTE", ")", "{", "mParserState", "=", "READ_MARKER_SECOND_BYTE", ";", "}", "break", ";", "case", "READ_MARKER_SECOND_BYTE", ":", "if", "(", "nextByte", "==", "JfifUtil", ".", "MARKER_FIRST_BYTE", ")", "{", "mParserState", "=", "READ_MARKER_SECOND_BYTE", ";", "}", "else", "if", "(", "nextByte", "==", "JfifUtil", ".", "MARKER_ESCAPE_BYTE", ")", "{", "mParserState", "=", "READ_MARKER_FIRST_BYTE_OR_ENTROPY_DATA", ";", "}", "else", "if", "(", "nextByte", "==", "JfifUtil", ".", "MARKER_EOI", ")", "{", "mEndMarkerRead", "=", "true", ";", "newScanOrImageEndFound", "(", "mBytesParsed", "-", "2", ")", ";", "// There should be no data after the EOI marker, but in case there is, let's process", "// the next byte as a first marker byte.", "mParserState", "=", "READ_MARKER_FIRST_BYTE_OR_ENTROPY_DATA", ";", "}", "else", "{", "if", "(", "nextByte", "==", "JfifUtil", ".", "MARKER_SOS", ")", "{", "newScanOrImageEndFound", "(", "mBytesParsed", "-", "2", ")", ";", "}", "if", "(", "doesMarkerStartSegment", "(", "nextByte", ")", ")", "{", "mParserState", "=", "READ_SIZE_FIRST_BYTE", ";", "}", "else", "{", "mParserState", "=", "READ_MARKER_FIRST_BYTE_OR_ENTROPY_DATA", ";", "}", "}", "break", ";", "case", "READ_SIZE_FIRST_BYTE", ":", "mParserState", "=", "READ_SIZE_SECOND_BYTE", ";", "break", ";", "case", "READ_SIZE_SECOND_BYTE", ":", "final", "int", "size", "=", "(", "mLastByteRead", "<<", "8", ")", "+", "nextByte", ";", "// We need to jump after the end of the segment - skip size-2 next bytes.", "// We might want to skip more data than is available to read, in which case we will", "// consume entire data in inputStream and exit this function before entering another", "// iteration of the loop.", "final", "int", "bytesToSkip", "=", "size", "-", "2", ";", "StreamUtil", ".", "skip", "(", "inputStream", ",", "bytesToSkip", ")", ";", "mBytesParsed", "+=", "bytesToSkip", ";", "mParserState", "=", "READ_MARKER_FIRST_BYTE_OR_ENTROPY_DATA", ";", "break", ";", "case", "NOT_A_JPEG", ":", "default", ":", "Preconditions", ".", "checkState", "(", "false", ")", ";", "}", "mLastByteRead", "=", "nextByte", ";", "}", "}", "catch", "(", "IOException", "ioe", ")", "{", "// does not happen, input stream returned by pooled byte buffer does not throw IOExceptions", "Throwables", ".", "propagate", "(", "ioe", ")", ";", "}", "return", "mParserState", "!=", "NOT_A_JPEG", "&&", "mBestScanNumber", "!=", "oldBestScanNumber", ";", "}" ]
Parses more data from inputStream. @param inputStream instance of buffered pooled byte buffer input stream
[ "Parses", "more", "data", "from", "inputStream", "." ]
0b85879d51c5036d5e46e627a6651afefc0b971a
https://github.com/facebook/fresco/blob/0b85879d51c5036d5e46e627a6651afefc0b971a/imagepipeline/src/main/java/com/facebook/imagepipeline/decoder/ProgressiveJpegParser.java#L150-L238
14,591
facebook/fresco
imagepipeline/src/main/java/com/facebook/imagepipeline/decoder/ProgressiveJpegParser.java
ProgressiveJpegParser.doesMarkerStartSegment
private static boolean doesMarkerStartSegment(int markerSecondByte) { if (markerSecondByte == JfifUtil.MARKER_TEM) { return false; } if (markerSecondByte >= JfifUtil.MARKER_RST0 && markerSecondByte <= JfifUtil.MARKER_RST7) { return false; } return markerSecondByte != JfifUtil.MARKER_EOI && markerSecondByte != JfifUtil.MARKER_SOI; }
java
private static boolean doesMarkerStartSegment(int markerSecondByte) { if (markerSecondByte == JfifUtil.MARKER_TEM) { return false; } if (markerSecondByte >= JfifUtil.MARKER_RST0 && markerSecondByte <= JfifUtil.MARKER_RST7) { return false; } return markerSecondByte != JfifUtil.MARKER_EOI && markerSecondByte != JfifUtil.MARKER_SOI; }
[ "private", "static", "boolean", "doesMarkerStartSegment", "(", "int", "markerSecondByte", ")", "{", "if", "(", "markerSecondByte", "==", "JfifUtil", ".", "MARKER_TEM", ")", "{", "return", "false", ";", "}", "if", "(", "markerSecondByte", ">=", "JfifUtil", ".", "MARKER_RST0", "&&", "markerSecondByte", "<=", "JfifUtil", ".", "MARKER_RST7", ")", "{", "return", "false", ";", "}", "return", "markerSecondByte", "!=", "JfifUtil", ".", "MARKER_EOI", "&&", "markerSecondByte", "!=", "JfifUtil", ".", "MARKER_SOI", ";", "}" ]
Not every marker is followed by associated segment
[ "Not", "every", "marker", "is", "followed", "by", "associated", "segment" ]
0b85879d51c5036d5e46e627a6651afefc0b971a
https://github.com/facebook/fresco/blob/0b85879d51c5036d5e46e627a6651afefc0b971a/imagepipeline/src/main/java/com/facebook/imagepipeline/decoder/ProgressiveJpegParser.java#L243-L253
14,592
facebook/fresco
animated-base/src/main/java/com/facebook/fresco/animation/drawable/animator/AnimatedDrawableValueAnimatorHelper.java
AnimatedDrawableValueAnimatorHelper.createValueAnimator
@Nullable public static ValueAnimator createValueAnimator(Drawable drawable, int maxDurationMs) { if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB) { return null; } if (drawable instanceof AnimatedDrawable2) { return AnimatedDrawable2ValueAnimatorHelper.createValueAnimator( (AnimatedDrawable2) drawable, maxDurationMs); } return null; }
java
@Nullable public static ValueAnimator createValueAnimator(Drawable drawable, int maxDurationMs) { if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB) { return null; } if (drawable instanceof AnimatedDrawable2) { return AnimatedDrawable2ValueAnimatorHelper.createValueAnimator( (AnimatedDrawable2) drawable, maxDurationMs); } return null; }
[ "@", "Nullable", "public", "static", "ValueAnimator", "createValueAnimator", "(", "Drawable", "drawable", ",", "int", "maxDurationMs", ")", "{", "if", "(", "Build", ".", "VERSION", ".", "SDK_INT", "<", "Build", ".", "VERSION_CODES", ".", "HONEYCOMB", ")", "{", "return", "null", ";", "}", "if", "(", "drawable", "instanceof", "AnimatedDrawable2", ")", "{", "return", "AnimatedDrawable2ValueAnimatorHelper", ".", "createValueAnimator", "(", "(", "AnimatedDrawable2", ")", "drawable", ",", "maxDurationMs", ")", ";", "}", "return", "null", ";", "}" ]
Create a value animator for the given animation drawable and max animation duration in ms. @param drawable the drawable to create the animator for @param maxDurationMs the max duration in ms @return the animator to use
[ "Create", "a", "value", "animator", "for", "the", "given", "animation", "drawable", "and", "max", "animation", "duration", "in", "ms", "." ]
0b85879d51c5036d5e46e627a6651afefc0b971a
https://github.com/facebook/fresco/blob/0b85879d51c5036d5e46e627a6651afefc0b971a/animated-base/src/main/java/com/facebook/fresco/animation/drawable/animator/AnimatedDrawableValueAnimatorHelper.java#L31-L43
14,593
facebook/fresco
drawee/src/main/java/com/facebook/drawee/drawable/RoundedColorDrawable.java
RoundedColorDrawable.fromColorDrawable
@TargetApi(Build.VERSION_CODES.HONEYCOMB) public static RoundedColorDrawable fromColorDrawable(ColorDrawable colorDrawable) { return new RoundedColorDrawable(colorDrawable.getColor()); }
java
@TargetApi(Build.VERSION_CODES.HONEYCOMB) public static RoundedColorDrawable fromColorDrawable(ColorDrawable colorDrawable) { return new RoundedColorDrawable(colorDrawable.getColor()); }
[ "@", "TargetApi", "(", "Build", ".", "VERSION_CODES", ".", "HONEYCOMB", ")", "public", "static", "RoundedColorDrawable", "fromColorDrawable", "(", "ColorDrawable", "colorDrawable", ")", "{", "return", "new", "RoundedColorDrawable", "(", "colorDrawable", ".", "getColor", "(", ")", ")", ";", "}" ]
Creates a new instance of RoundedColorDrawable from the given ColorDrawable. @param colorDrawable color drawable to extract the color from @return a new RoundedColorDrawable
[ "Creates", "a", "new", "instance", "of", "RoundedColorDrawable", "from", "the", "given", "ColorDrawable", "." ]
0b85879d51c5036d5e46e627a6651afefc0b971a
https://github.com/facebook/fresco/blob/0b85879d51c5036d5e46e627a6651afefc0b971a/drawee/src/main/java/com/facebook/drawee/drawable/RoundedColorDrawable.java#L57-L60
14,594
facebook/fresco
drawee/src/main/java/com/facebook/drawee/drawable/RoundedColorDrawable.java
RoundedColorDrawable.setRadius
@Override public void setRadius(float radius) { Preconditions.checkArgument(radius >= 0, "radius should be non negative"); Arrays.fill(mRadii, radius); updatePath(); invalidateSelf(); }
java
@Override public void setRadius(float radius) { Preconditions.checkArgument(radius >= 0, "radius should be non negative"); Arrays.fill(mRadii, radius); updatePath(); invalidateSelf(); }
[ "@", "Override", "public", "void", "setRadius", "(", "float", "radius", ")", "{", "Preconditions", ".", "checkArgument", "(", "radius", ">=", "0", ",", "\"radius should be non negative\"", ")", ";", "Arrays", ".", "fill", "(", "mRadii", ",", "radius", ")", ";", "updatePath", "(", ")", ";", "invalidateSelf", "(", ")", ";", "}" ]
Sets the rounding radius. @param radius
[ "Sets", "the", "rounding", "radius", "." ]
0b85879d51c5036d5e46e627a6651afefc0b971a
https://github.com/facebook/fresco/blob/0b85879d51c5036d5e46e627a6651afefc0b971a/drawee/src/main/java/com/facebook/drawee/drawable/RoundedColorDrawable.java#L152-L158
14,595
facebook/fresco
fbcore/src/main/java/com/facebook/common/references/SharedReference.java
SharedReference.addLiveReference
private static void addLiveReference(Object value) { synchronized (sLiveObjects) { Integer count = sLiveObjects.get(value); if (count == null) { sLiveObjects.put(value, 1); } else { sLiveObjects.put(value, count + 1); } } }
java
private static void addLiveReference(Object value) { synchronized (sLiveObjects) { Integer count = sLiveObjects.get(value); if (count == null) { sLiveObjects.put(value, 1); } else { sLiveObjects.put(value, count + 1); } } }
[ "private", "static", "void", "addLiveReference", "(", "Object", "value", ")", "{", "synchronized", "(", "sLiveObjects", ")", "{", "Integer", "count", "=", "sLiveObjects", ".", "get", "(", "value", ")", ";", "if", "(", "count", "==", "null", ")", "{", "sLiveObjects", ".", "put", "(", "value", ",", "1", ")", ";", "}", "else", "{", "sLiveObjects", ".", "put", "(", "value", ",", "count", "+", "1", ")", ";", "}", "}", "}" ]
Increases the reference count of a live object in the static map. Adds it if it's not being held. @param value the value to add.
[ "Increases", "the", "reference", "count", "of", "a", "live", "object", "in", "the", "static", "map", ".", "Adds", "it", "if", "it", "s", "not", "being", "held", "." ]
0b85879d51c5036d5e46e627a6651afefc0b971a
https://github.com/facebook/fresco/blob/0b85879d51c5036d5e46e627a6651afefc0b971a/fbcore/src/main/java/com/facebook/common/references/SharedReference.java#L129-L138
14,596
facebook/fresco
fbcore/src/main/java/com/facebook/common/references/SharedReference.java
SharedReference.removeLiveReference
private static void removeLiveReference(Object value) { synchronized (sLiveObjects) { Integer count = sLiveObjects.get(value); if (count == null) { // Uh oh. FLog.wtf( "SharedReference", "No entry in sLiveObjects for value of type %s", value.getClass()); } else if (count == 1) { sLiveObjects.remove(value); } else { sLiveObjects.put(value, count - 1); } } }
java
private static void removeLiveReference(Object value) { synchronized (sLiveObjects) { Integer count = sLiveObjects.get(value); if (count == null) { // Uh oh. FLog.wtf( "SharedReference", "No entry in sLiveObjects for value of type %s", value.getClass()); } else if (count == 1) { sLiveObjects.remove(value); } else { sLiveObjects.put(value, count - 1); } } }
[ "private", "static", "void", "removeLiveReference", "(", "Object", "value", ")", "{", "synchronized", "(", "sLiveObjects", ")", "{", "Integer", "count", "=", "sLiveObjects", ".", "get", "(", "value", ")", ";", "if", "(", "count", "==", "null", ")", "{", "// Uh oh.", "FLog", ".", "wtf", "(", "\"SharedReference\"", ",", "\"No entry in sLiveObjects for value of type %s\"", ",", "value", ".", "getClass", "(", ")", ")", ";", "}", "else", "if", "(", "count", "==", "1", ")", "{", "sLiveObjects", ".", "remove", "(", "value", ")", ";", "}", "else", "{", "sLiveObjects", ".", "put", "(", "value", ",", "count", "-", "1", ")", ";", "}", "}", "}" ]
Decreases the reference count of live object from the static map. Removes it if it's reference count has become 0. @param value the value to remove.
[ "Decreases", "the", "reference", "count", "of", "live", "object", "from", "the", "static", "map", ".", "Removes", "it", "if", "it", "s", "reference", "count", "has", "become", "0", "." ]
0b85879d51c5036d5e46e627a6651afefc0b971a
https://github.com/facebook/fresco/blob/0b85879d51c5036d5e46e627a6651afefc0b971a/fbcore/src/main/java/com/facebook/common/references/SharedReference.java#L146-L161
14,597
facebook/fresco
fbcore/src/main/java/com/facebook/common/references/SharedReference.java
SharedReference.deleteReference
public void deleteReference() { if (decreaseRefCount() == 0) { T deleted; synchronized (this) { deleted = mValue; mValue = null; } mResourceReleaser.release(deleted); removeLiveReference(deleted); } }
java
public void deleteReference() { if (decreaseRefCount() == 0) { T deleted; synchronized (this) { deleted = mValue; mValue = null; } mResourceReleaser.release(deleted); removeLiveReference(deleted); } }
[ "public", "void", "deleteReference", "(", ")", "{", "if", "(", "decreaseRefCount", "(", ")", "==", "0", ")", "{", "T", "deleted", ";", "synchronized", "(", "this", ")", "{", "deleted", "=", "mValue", ";", "mValue", "=", "null", ";", "}", "mResourceReleaser", ".", "release", "(", "deleted", ")", ";", "removeLiveReference", "(", "deleted", ")", ";", "}", "}" ]
Decrement the reference count for the shared reference. If the reference count drops to zero, then dispose of the referenced value
[ "Decrement", "the", "reference", "count", "for", "the", "shared", "reference", ".", "If", "the", "reference", "count", "drops", "to", "zero", "then", "dispose", "of", "the", "referenced", "value" ]
0b85879d51c5036d5e46e627a6651afefc0b971a
https://github.com/facebook/fresco/blob/0b85879d51c5036d5e46e627a6651afefc0b971a/fbcore/src/main/java/com/facebook/common/references/SharedReference.java#L209-L219
14,598
facebook/fresco
drawee/src/main/java/com/facebook/drawee/view/DraweeView.java
DraweeView.init
private void init(Context context) { try { if (FrescoSystrace.isTracing()) { FrescoSystrace.beginSection("DraweeView#init"); } if (mInitialised) { return; } mInitialised = true; mDraweeHolder = DraweeHolder.create(null, context); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { ColorStateList imageTintList = getImageTintList(); if (imageTintList == null) { return; } setColorFilter(imageTintList.getDefaultColor()); } // In Android N and above, visibility handling for Drawables has been changed, which breaks // activity transitions with DraweeViews. mLegacyVisibilityHandlingEnabled = sGlobalLegacyVisibilityHandlingEnabled && context.getApplicationInfo().targetSdkVersion >= 24; // Build.VERSION_CODES.N } finally { if (FrescoSystrace.isTracing()) { FrescoSystrace.endSection(); } } }
java
private void init(Context context) { try { if (FrescoSystrace.isTracing()) { FrescoSystrace.beginSection("DraweeView#init"); } if (mInitialised) { return; } mInitialised = true; mDraweeHolder = DraweeHolder.create(null, context); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { ColorStateList imageTintList = getImageTintList(); if (imageTintList == null) { return; } setColorFilter(imageTintList.getDefaultColor()); } // In Android N and above, visibility handling for Drawables has been changed, which breaks // activity transitions with DraweeViews. mLegacyVisibilityHandlingEnabled = sGlobalLegacyVisibilityHandlingEnabled && context.getApplicationInfo().targetSdkVersion >= 24; // Build.VERSION_CODES.N } finally { if (FrescoSystrace.isTracing()) { FrescoSystrace.endSection(); } } }
[ "private", "void", "init", "(", "Context", "context", ")", "{", "try", "{", "if", "(", "FrescoSystrace", ".", "isTracing", "(", ")", ")", "{", "FrescoSystrace", ".", "beginSection", "(", "\"DraweeView#init\"", ")", ";", "}", "if", "(", "mInitialised", ")", "{", "return", ";", "}", "mInitialised", "=", "true", ";", "mDraweeHolder", "=", "DraweeHolder", ".", "create", "(", "null", ",", "context", ")", ";", "if", "(", "Build", ".", "VERSION", ".", "SDK_INT", ">=", "Build", ".", "VERSION_CODES", ".", "LOLLIPOP", ")", "{", "ColorStateList", "imageTintList", "=", "getImageTintList", "(", ")", ";", "if", "(", "imageTintList", "==", "null", ")", "{", "return", ";", "}", "setColorFilter", "(", "imageTintList", ".", "getDefaultColor", "(", ")", ")", ";", "}", "// In Android N and above, visibility handling for Drawables has been changed, which breaks", "// activity transitions with DraweeViews.", "mLegacyVisibilityHandlingEnabled", "=", "sGlobalLegacyVisibilityHandlingEnabled", "&&", "context", ".", "getApplicationInfo", "(", ")", ".", "targetSdkVersion", ">=", "24", ";", "// Build.VERSION_CODES.N", "}", "finally", "{", "if", "(", "FrescoSystrace", ".", "isTracing", "(", ")", ")", "{", "FrescoSystrace", ".", "endSection", "(", ")", ";", "}", "}", "}" ]
This method is idempotent so it only has effect the first time it's called
[ "This", "method", "is", "idempotent", "so", "it", "only", "has", "effect", "the", "first", "time", "it", "s", "called" ]
0b85879d51c5036d5e46e627a6651afefc0b971a
https://github.com/facebook/fresco/blob/0b85879d51c5036d5e46e627a6651afefc0b971a/drawee/src/main/java/com/facebook/drawee/view/DraweeView.java#L79-L106
14,599
facebook/fresco
fbcore/src/main/java/com/facebook/common/internal/Files.java
Files.readFile
static byte[] readFile( InputStream in, long expectedSize) throws IOException { if (expectedSize > Integer.MAX_VALUE) { throw new OutOfMemoryError("file is too large to fit in a byte array: " + expectedSize + " bytes"); } // some special files may return size 0 but have content, so read // the file normally in that case return expectedSize == 0 ? ByteStreams.toByteArray(in) : ByteStreams.toByteArray(in, (int) expectedSize); }
java
static byte[] readFile( InputStream in, long expectedSize) throws IOException { if (expectedSize > Integer.MAX_VALUE) { throw new OutOfMemoryError("file is too large to fit in a byte array: " + expectedSize + " bytes"); } // some special files may return size 0 but have content, so read // the file normally in that case return expectedSize == 0 ? ByteStreams.toByteArray(in) : ByteStreams.toByteArray(in, (int) expectedSize); }
[ "static", "byte", "[", "]", "readFile", "(", "InputStream", "in", ",", "long", "expectedSize", ")", "throws", "IOException", "{", "if", "(", "expectedSize", ">", "Integer", ".", "MAX_VALUE", ")", "{", "throw", "new", "OutOfMemoryError", "(", "\"file is too large to fit in a byte array: \"", "+", "expectedSize", "+", "\" bytes\"", ")", ";", "}", "// some special files may return size 0 but have content, so read", "// the file normally in that case", "return", "expectedSize", "==", "0", "?", "ByteStreams", ".", "toByteArray", "(", "in", ")", ":", "ByteStreams", ".", "toByteArray", "(", "in", ",", "(", "int", ")", "expectedSize", ")", ";", "}" ]
Reads a file of the given expected size from the given input stream, if it will fit into a byte array. This method handles the case where the file size changes between when the size is read and when the contents are read from the stream.
[ "Reads", "a", "file", "of", "the", "given", "expected", "size", "from", "the", "given", "input", "stream", "if", "it", "will", "fit", "into", "a", "byte", "array", ".", "This", "method", "handles", "the", "case", "where", "the", "file", "size", "changes", "between", "when", "the", "size", "is", "read", "and", "when", "the", "contents", "are", "read", "from", "the", "stream", "." ]
0b85879d51c5036d5e46e627a6651afefc0b971a
https://github.com/facebook/fresco/blob/0b85879d51c5036d5e46e627a6651afefc0b971a/fbcore/src/main/java/com/facebook/common/internal/Files.java#L42-L54