use of androidx.annotation.VisibleForTesting in project k-9 by k9mail.
the class AutocryptGossipHeaderParser method parseAutocryptGossipHeader.
@Nullable
@VisibleForTesting
AutocryptGossipHeader parseAutocryptGossipHeader(String headerValue) {
Map<String, String> parameters = MimeUtility.getAllHeaderParameters(headerValue);
String type = parameters.remove(AutocryptHeader.AUTOCRYPT_PARAM_TYPE);
if (type != null && !type.equals(AutocryptHeader.AUTOCRYPT_TYPE_1)) {
Timber.e("autocrypt: unsupported type parameter %s", type);
return null;
}
String base64KeyData = parameters.remove(AutocryptHeader.AUTOCRYPT_PARAM_KEY_DATA);
if (base64KeyData == null) {
Timber.e("autocrypt: missing key parameter");
return null;
}
ByteString byteString = ByteString.decodeBase64(base64KeyData);
if (byteString == null) {
Timber.e("autocrypt: error parsing base64 data");
return null;
}
String addr = parameters.remove(AutocryptHeader.AUTOCRYPT_PARAM_ADDR);
if (addr == null) {
Timber.e("autocrypt: no to header!");
return null;
}
if (hasCriticalParameters(parameters)) {
return null;
}
return new AutocryptGossipHeader(addr, byteString.toByteArray());
}
use of androidx.annotation.VisibleForTesting in project k-9 by k9mail.
the class AttachmentResolver method buildCidToAttachmentUriMap.
@VisibleForTesting
static Map<String, Uri> buildCidToAttachmentUriMap(AttachmentInfoExtractor attachmentInfoExtractor, Part rootPart) {
HashMap<String, Uri> result = new HashMap<>();
Stack<Part> partsToCheck = new Stack<>();
partsToCheck.push(rootPart);
while (!partsToCheck.isEmpty()) {
Part part = partsToCheck.pop();
Body body = part.getBody();
if (body instanceof Multipart) {
Multipart multipart = (Multipart) body;
for (Part bodyPart : multipart.getBodyParts()) {
partsToCheck.push(bodyPart);
}
} else {
try {
String contentId = part.getContentId();
if (contentId != null) {
AttachmentViewInfo attachmentInfo = attachmentInfoExtractor.extractAttachmentInfo(part);
result.put(contentId, attachmentInfo.internalUri);
}
} catch (MessagingException e) {
Timber.e(e, "Error extracting attachment info");
}
}
}
return Collections.unmodifiableMap(result);
}
use of androidx.annotation.VisibleForTesting in project fresco by facebook.
the class DebugControllerOverlayDrawable method determineSizeHintColor.
@VisibleForTesting
int determineSizeHintColor(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 TEXT_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 TEXT_COLOR_IMAGE_OK;
} else if (absWidthDifference < scaledImageWidthThresholdNotOk && absHeightDifference < scaledImageHeightThresholdNotOk) {
return TEXT_COLOR_IMAGE_ALMOST_OK;
}
return TEXT_COLOR_IMAGE_NOT_OK;
}
use of androidx.annotation.VisibleForTesting in project fresco by facebook.
the class ScaleTypeDrawable method configureBounds.
/**
* Determines bounds for the underlying drawable and a matrix that should be applied on it.
* Adopted from android.widget.ImageView
*/
@VisibleForTesting
void configureBounds() {
Drawable underlyingDrawable = getCurrent();
// If there is no underlying Drawable, we do not need a draw matrix.
if (underlyingDrawable == null) {
mUnderlyingWidth = mUnderlyingHeight = 0;
mDrawMatrix = null;
return;
}
Rect bounds = getBounds();
int viewWidth = bounds.width();
int viewHeight = bounds.height();
int underlyingWidth = mUnderlyingWidth = underlyingDrawable.getIntrinsicWidth();
int underlyingHeight = mUnderlyingHeight = underlyingDrawable.getIntrinsicHeight();
// If the drawable has no intrinsic size, we just fill our entire view.
if (underlyingWidth <= 0 || underlyingHeight <= 0) {
underlyingDrawable.setBounds(bounds);
mDrawMatrix = null;
return;
}
// If the drawable fits exactly, no transform needed.
if (underlyingWidth == viewWidth && underlyingHeight == viewHeight) {
underlyingDrawable.setBounds(bounds);
mDrawMatrix = null;
return;
}
// (ScaleType.getTransform would do, but this is faster)
if (mScaleType == ScaleType.FIT_XY) {
underlyingDrawable.setBounds(bounds);
mDrawMatrix = null;
return;
}
// We need to do the scaling ourselves, so have the underlying drawable use its preferred size.
underlyingDrawable.setBounds(0, 0, underlyingWidth, underlyingHeight);
mScaleType.getTransform(mTempMatrix, bounds, underlyingWidth, underlyingHeight, (mFocusPoint != null) ? mFocusPoint.x : 0.5f, (mFocusPoint != null) ? mFocusPoint.y : 0.5f);
mDrawMatrix = mTempMatrix;
}
use of androidx.annotation.VisibleForTesting in project fresco by facebook.
the class BasePool method trimToSize.
/**
* (Try to) trim the pool until its total space falls below the max size (soft cap). This will get
* rid of values on the free list, until the free lists are empty, or we fall below the max size;
* whichever comes first. NOTE: It is NOT an error if we have eliminated all the free values, but
* the pool is still above its max size (soft cap)
*
* <p>The approach we take is to go from the smallest sized bucket down to the largest sized
* bucket. This may seem a bit counter-intuitive, but the rationale is that allocating
* larger-sized values is more expensive than the smaller-sized ones, so we want to keep them
* around for a while.
*
* @param targetSize target size to trim to
*/
@VisibleForTesting
synchronized void trimToSize(int targetSize) {
// find how much we need to free
int bytesToFree = Math.min(mUsed.mNumBytes + mFree.mNumBytes - targetSize, mFree.mNumBytes);
if (bytesToFree <= 0) {
return;
}
if (FLog.isLoggable(FLog.VERBOSE)) {
FLog.v(TAG, "trimToSize: TargetSize = %d; Initial Size = %d; Bytes to free = %d", targetSize, mUsed.mNumBytes + mFree.mNumBytes, bytesToFree);
}
logStats();
// until we've gotten to what we want
for (int i = 0; i < mBuckets.size(); ++i) {
if (bytesToFree <= 0) {
break;
}
Bucket<V> bucket = Preconditions.checkNotNull(mBuckets.valueAt(i));
while (bytesToFree > 0) {
V value = bucket.pop();
if (value == null) {
break;
}
free(value);
bytesToFree -= bucket.mItemSize;
mFree.decrement(bucket.mItemSize);
}
}
// dump stats at the end
logStats();
if (FLog.isLoggable(FLog.VERBOSE)) {
FLog.v(TAG, "trimToSize: TargetSize = %d; Final Size = %d", targetSize, mUsed.mNumBytes + mFree.mNumBytes);
}
}
Aggregations