Search in sources :

Example 1 with VisibleForTesting

use of com.facebook.common.internal.VisibleForTesting in project fresco by facebook.

the class DebugControllerOverlayDrawable method determineOverlayColor.

@VisibleForTesting
int determineOverlayColor(int imageWidth, int imageHeight, @Nullable ScaleType scaleType) {
    int visibleDrawnAreaWidth = getBounds().width();
    int visibleDrawnAreaHeight = getBounds().height();
    if (visibleDrawnAreaWidth <= 0 || visibleDrawnAreaHeight <= 0 || imageWidth <= 0 || imageHeight <= 0) {
        return OVERLAY_COLOR_IMAGE_NOT_OK;
    }
    if (scaleType != null) {
        // Apply optional scale type in order to get boundaries of the actual area to be filled
        mRect.left = mRect.top = 0;
        mRect.right = visibleDrawnAreaWidth;
        mRect.bottom = visibleDrawnAreaHeight;
        mMatrix.reset();
        // We can ignore the focus point as it has no influence on the scale, but only the translation
        scaleType.getTransform(mMatrix, mRect, imageWidth, imageHeight, 0f, 0f);
        mRectF.left = mRectF.top = 0;
        mRectF.right = imageWidth;
        mRectF.bottom = imageHeight;
        mMatrix.mapRect(mRectF);
        final int drawnAreaWidth = (int) mRectF.width();
        final int drawnAreaHeight = (int) mRectF.height();
        visibleDrawnAreaWidth = Math.min(visibleDrawnAreaWidth, drawnAreaWidth);
        visibleDrawnAreaHeight = Math.min(visibleDrawnAreaHeight, drawnAreaHeight);
    }
    // Update the thresholds for the overlay color
    float scaledImageWidthThresholdOk = visibleDrawnAreaWidth * IMAGE_SIZE_THRESHOLD_OK;
    float scaledImageWidthThresholdNotOk = visibleDrawnAreaWidth * IMAGE_SIZE_THRESHOLD_NOT_OK;
    float scaledImageHeightThresholdOk = visibleDrawnAreaHeight * IMAGE_SIZE_THRESHOLD_OK;
    float scaledImageHeightThresholdNotOk = visibleDrawnAreaHeight * IMAGE_SIZE_THRESHOLD_NOT_OK;
    // Calculate the dimension differences
    int absWidthDifference = Math.abs(imageWidth - visibleDrawnAreaWidth);
    int absHeightDifference = Math.abs(imageHeight - visibleDrawnAreaHeight);
    // Return corresponding color
    if (absWidthDifference < scaledImageWidthThresholdOk && absHeightDifference < scaledImageHeightThresholdOk) {
        return OVERLAY_COLOR_IMAGE_OK;
    } else if (absWidthDifference < scaledImageWidthThresholdNotOk && absHeightDifference < scaledImageHeightThresholdNotOk) {
        return OVERLAY_COLOR_IMAGE_ALMOST_OK;
    }
    return OVERLAY_COLOR_IMAGE_NOT_OK;
}
Also used : Paint(android.graphics.Paint) VisibleForTesting(com.facebook.common.internal.VisibleForTesting)

Example 2 with VisibleForTesting

use of com.facebook.common.internal.VisibleForTesting in project fresco by facebook.

the class DownsampleUtil method determineDownsampleRatio.

@VisibleForTesting
static float determineDownsampleRatio(ImageRequest imageRequest, EncodedImage encodedImage) {
    Preconditions.checkArgument(EncodedImage.isMetaDataAvailable(encodedImage));
    final ResizeOptions resizeOptions = imageRequest.getResizeOptions();
    if (resizeOptions == null || resizeOptions.height <= 0 || resizeOptions.width <= 0 || encodedImage.getWidth() == 0 || encodedImage.getHeight() == 0) {
        return 1.0f;
    }
    final int rotationAngle = getRotationAngle(imageRequest, encodedImage);
    final boolean swapDimensions = rotationAngle == 90 || rotationAngle == 270;
    final int widthAfterRotation = swapDimensions ? encodedImage.getHeight() : encodedImage.getWidth();
    final int heightAfterRotation = swapDimensions ? encodedImage.getWidth() : encodedImage.getHeight();
    final float widthRatio = ((float) resizeOptions.width) / widthAfterRotation;
    final float heightRatio = ((float) resizeOptions.height) / heightAfterRotation;
    float ratio = Math.max(widthRatio, heightRatio);
    FLog.v("DownsampleUtil", "Downsample - Specified size: %dx%d, image size: %dx%d " + "ratio: %.1f x %.1f, ratio: %.3f for %s", resizeOptions.width, resizeOptions.height, widthAfterRotation, heightAfterRotation, widthRatio, heightRatio, ratio, imageRequest.getSourceUri().toString());
    return ratio;
}
Also used : ResizeOptions(com.facebook.imagepipeline.common.ResizeOptions) VisibleForTesting(com.facebook.common.internal.VisibleForTesting)

Example 3 with VisibleForTesting

use of com.facebook.common.internal.VisibleForTesting in project fresco by facebook.

the class HttpUrlConnectionNetworkFetcher method fetchSync.

@VisibleForTesting
void fetchSync(FetchState fetchState, Callback callback) {
    HttpURLConnection connection = null;
    InputStream is = null;
    try {
        connection = downloadFrom(fetchState.getUri(), MAX_REDIRECTS);
        if (connection != null) {
            is = connection.getInputStream();
            callback.onResponse(is, -1);
        }
    } catch (IOException e) {
        callback.onFailure(e);
    } finally {
        if (is != null) {
            try {
                is.close();
            } catch (IOException e) {
            // do nothing and ignore the IOException here
            }
        }
        if (connection != null) {
            connection.disconnect();
        }
    }
}
Also used : HttpURLConnection(java.net.HttpURLConnection) InputStream(java.io.InputStream) IOException(java.io.IOException) VisibleForTesting(com.facebook.common.internal.VisibleForTesting)

Example 4 with VisibleForTesting

use of com.facebook.common.internal.VisibleForTesting in project fresco by facebook.

the class MediaVariationsIndexDatabase method getCachedVariantsSync.

@VisibleForTesting
protected MediaVariations getCachedVariantsSync(String mediaId, MediaVariations.Builder mediaVariationsBuilder) {
    synchronized (MediaVariationsIndexDatabase.class) {
        SQLiteDatabase db = mDbHelper.getWritableDatabase();
        Cursor c = null;
        try {
            String selection = IndexEntry.COLUMN_NAME_MEDIA_ID + " = ?";
            String[] selectionArgs = { mediaId };
            c = db.query(IndexEntry.TABLE_NAME, PROJECTION, selection, selectionArgs, // groupBy
            null, // having
            null, // orderBy
            null);
            if (c.getCount() == 0) {
                return mediaVariationsBuilder.build();
            }
            final int columnIndexCacheKey = c.getColumnIndexOrThrow(IndexEntry.COLUMN_NAME_CACHE_KEY);
            final int columnIndexWidth = c.getColumnIndexOrThrow(IndexEntry.COLUMN_NAME_WIDTH);
            final int columnIndexHeight = c.getColumnIndexOrThrow(IndexEntry.COLUMN_NAME_HEIGHT);
            final int columnIndexCacheChoice = c.getColumnIndexOrThrow(IndexEntry.COLUMN_NAME_CACHE_CHOICE);
            while (c.moveToNext()) {
                String cacheChoiceStr = c.getString(columnIndexCacheChoice);
                mediaVariationsBuilder.addVariant(Uri.parse(c.getString(columnIndexCacheKey)), c.getInt(columnIndexWidth), c.getInt(columnIndexHeight), TextUtils.isEmpty(cacheChoiceStr) ? null : ImageRequest.CacheChoice.valueOf(cacheChoiceStr));
            }
            return mediaVariationsBuilder.build();
        } catch (SQLException x) {
            FLog.e(TAG, x, "Error reading for %s", mediaId);
            throw x;
        } finally {
            if (c != null) {
                c.close();
            }
        }
    }
}
Also used : SQLiteDatabase(android.database.sqlite.SQLiteDatabase) SQLException(android.database.SQLException) Cursor(android.database.Cursor) VisibleForTesting(com.facebook.common.internal.VisibleForTesting)

Aggregations

VisibleForTesting (com.facebook.common.internal.VisibleForTesting)4 Cursor (android.database.Cursor)1 SQLException (android.database.SQLException)1 SQLiteDatabase (android.database.sqlite.SQLiteDatabase)1 Paint (android.graphics.Paint)1 ResizeOptions (com.facebook.imagepipeline.common.ResizeOptions)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 HttpURLConnection (java.net.HttpURLConnection)1