use of com.facebook.imagepipeline.common.ResizeOptions in project fresco by facebook.
the class MediaVariationsFallbackProducerTest method testUsesSmallCacheIfRequestedByImageRequest.
@Test
public void testUsesSmallCacheIfRequestedByImageRequest() {
when(mImageRequest.getMediaVariations()).thenReturn(mMediaVariationsWithVariants);
whenCacheContains(mSmallImageBufferedDiskCache, CACHE_KEY_S, CACHE_KEY_M, CACHE_KEY_L);
when(mImageRequest.getResizeOptions()).thenReturn(new ResizeOptions(SIZE_S, SIZE_S));
when(mImageRequest.getCacheChoice()).thenReturn(CacheChoice.SMALL);
mMediaVariationsFallbackProducer.produceResults(mConsumer, mProducerContext);
verify(mConsumer).onNewResult(mImageS, true);
verify(mConsumer).onProgressUpdate(1L);
verify(mProducerListener).onProducerStart(mRequestId, PRODUCER_NAME);
verifySuccessSentToListener(FOUND, USED_AS_LAST, MediaVariations.SOURCE_IMAGE_REQUEST, VARIANTS_COUNT);
verifyZeroInteractions(mInputProducer, mDefaultBufferedDiskCache, mMediaIdExtractor);
}
use of com.facebook.imagepipeline.common.ResizeOptions in project fresco by facebook.
the class MediaVariationsFallbackProducerTest method testSendsLargestCachedNonFinalImageToConsumerAndStartsInputProducerIfNoCachedVariantFromRequestBigEnough.
@Test
public void testSendsLargestCachedNonFinalImageToConsumerAndStartsInputProducerIfNoCachedVariantFromRequestBigEnough() {
when(mImageRequest.getMediaVariations()).thenReturn(mMediaVariationsWithVariants);
whenCacheContains(mDefaultBufferedDiskCache, CACHE_KEY_S, CACHE_KEY_M, CACHE_KEY_L);
when(mImageRequest.getResizeOptions()).thenReturn(new ResizeOptions(SIZE_L + 80, SIZE_L + 80));
mMediaVariationsFallbackProducer.produceResults(mConsumer, mProducerContext);
verify(mConsumer).onNewResult(mImageL, false);
verify(mConsumer, never()).onProgressUpdate(anyFloat());
verifyInputProducerProduceResultsWithNewConsumer();
verify(mProducerListener).onProducerStart(mRequestId, PRODUCER_NAME);
verifySuccessSentToListener(FOUND, NOT_USED_AS_LAST, MediaVariations.SOURCE_IMAGE_REQUEST, VARIANTS_COUNT);
verifyZeroInteractions(mSmallImageBufferedDiskCache, mMediaIdExtractor);
}
use of com.facebook.imagepipeline.common.ResizeOptions in project fresco by facebook.
the class MediaVariationsFallbackProducerTest method testSendsSmallestLargerFinalImageToConsumerWhenLargerVariantsFromRequestFound.
@Test
public void testSendsSmallestLargerFinalImageToConsumerWhenLargerVariantsFromRequestFound() {
when(mImageRequest.getMediaVariations()).thenReturn(mMediaVariationsWithVariants);
whenCacheContains(mDefaultBufferedDiskCache, CACHE_KEY_S, CACHE_KEY_M, CACHE_KEY_L);
when(mImageRequest.getResizeOptions()).thenReturn(new ResizeOptions(SIZE_M - 10, SIZE_M - 10));
mMediaVariationsFallbackProducer.produceResults(mConsumer, mProducerContext);
verify(mConsumer).onNewResult(mImageM, true);
verify(mConsumer).onProgressUpdate(1L);
verify(mProducerListener).onProducerStart(mRequestId, PRODUCER_NAME);
verifySuccessSentToListener(FOUND, USED_AS_LAST, MediaVariations.SOURCE_IMAGE_REQUEST, VARIANTS_COUNT);
verifyZeroInteractions(mInputProducer, mSmallImageBufferedDiskCache, mMediaIdExtractor);
}
use of com.facebook.imagepipeline.common.ResizeOptions in project fresco by facebook.
the class MediaVariationsFallbackProducerTest method testSendsSmallestLargerFinalImageToConsumerWhenLargerVariantsFromExtractor.
@Test
public void testSendsSmallestLargerFinalImageToConsumerWhenLargerVariantsFromExtractor() {
when(mImageRequest.getMediaVariations()).thenReturn(mMediaVariationsWithVariants);
whenCacheContains(mDefaultBufferedDiskCache, CACHE_KEY_S, CACHE_KEY_M, CACHE_KEY_L);
when(mImageRequest.getResizeOptions()).thenReturn(new ResizeOptions(SIZE_M - 10, SIZE_M - 10));
mMediaVariationsFallbackProducer.produceResults(mConsumer, mProducerContext);
verify(mConsumer).onNewResult(mImageM, true);
verify(mConsumer).onProgressUpdate(1L);
verify(mProducerListener).onProducerStart(mRequestId, PRODUCER_NAME);
verifySuccessSentToListener(FOUND, USED_AS_LAST, MediaVariations.SOURCE_IMAGE_REQUEST, VARIANTS_COUNT);
verifyZeroInteractions(mInputProducer, mSmallImageBufferedDiskCache, mMediaIdExtractor);
}
use of com.facebook.imagepipeline.common.ResizeOptions in project actor-platform by actorapp.
the class DialogView method buildLayout.
@Override
public DialogLayout buildLayout(Dialog arg, int width, int height) {
if (!isStylesLoaded) {
isStylesLoaded = true;
ActorStyle style = ActorSDK.sharedActor().style;
Context context = getContext();
titlePaint = createTextPaint(Fonts.medium(), 16, style.getDialogsTitleColor());
titleSecurePaint = createTextPaint(Fonts.medium(), 16, style.getDialogsTitleSecureColor());
datePaint = createTextPaint(Fonts.regular(), 14, style.getDialogsTimeColor());
textPaint = createTextPaint(Fonts.regular(), 16, style.getDialogsTimeColor());
textActivePaint = createTextPaint(Fonts.regular(), 16, style.getDialogsActiveTextColor());
senderTextColor = style.getDialogsActiveTextColor();
groupIcon = new TintDrawable(context.getResources().getDrawable(R.drawable.ic_group_black_18dp), style.getDialogsTitleColor());
channelIcon = new TintDrawable(context.getResources().getDrawable(R.drawable.ic_megaphone_18dp_black), style.getDialogsTitleColor());
botIcon = new TintDrawable(context.getResources().getDrawable(R.drawable.ic_robot_black_18dp), style.getDialogsTitleColor());
secretIcon = new TintDrawable(context.getResources().getDrawable(R.drawable.ic_lock_black_18dp), style.getDialogsTitleSecureColor());
counterTextPaint = createTextPaint(Fonts.medium(), 14, style.getDialogsCounterTextColor());
counterTextPaint.setTextAlign(Paint.Align.CENTER);
counterBgPaint = createFilledPaint(style.getDialogsCounterBackgroundColor());
fillPaint = createFilledPaint(Color.BLACK);
placeholderColors = ActorSDK.sharedActor().style.getDefaultAvatarPlaceholders();
avatarBorder = new Paint();
avatarBorder.setStyle(Paint.Style.STROKE);
avatarBorder.setAntiAlias(true);
avatarBorder.setColor(0x19000000);
avatarBorder.setStrokeWidth(1);
avatarTextColor = createTextPaint(Fonts.regular(), 20, Color.WHITE);
avatarTextColor.setTextAlign(Paint.Align.CENTER);
typingText = messenger().getFormatter().formatTyping();
stateSent = new TintDrawable(context.getResources().getDrawable(R.drawable.msg_check_1), style.getDialogsStateSentColor());
stateReceived = new TintDrawable(context.getResources().getDrawable(R.drawable.msg_check_2), style.getDialogsStateDeliveredColor());
stateRead = new TintDrawable(context.getResources().getDrawable(R.drawable.msg_check_2), style.getDialogsStateReadColor());
}
DialogLayout res = new DialogLayout();
res.setPlaceholderIndex(Math.abs(arg.getPeer().getPeerId()) % placeholderColors.length);
res.setShortName(buildShortName(arg.getDialogTitle()));
if (arg.getDialogAvatar() != null) {
AvatarImage image = getAvatarImage(arg.getDialogAvatar());
if (image != null) {
String desc = messenger().findDownloadedDescriptor(image.getFileReference().getFileId());
if (desc != null) {
ImageRequest request = ImageRequestBuilder.newBuilderWithSource(Uri.fromFile(new File(desc))).setResizeOptions(new ResizeOptions(Screen.dp(52), Screen.dp(52))).setImageType(ImageRequest.ImageType.SMALL).build();
res.setImageRequest(request);
} else {
InvalidationContext invalidationContext = getCurrentLayoutContext();
messenger().bindRawFile(image.getFileReference(), true, new FileCallback() {
@Override
public void onNotDownloaded() {
if (invalidationContext.isCancelled()) {
messenger().unbindRawFile(image.getFileReference().getFileId(), false, this);
}
}
@Override
public void onDownloading(float progress) {
if (invalidationContext.isCancelled()) {
messenger().unbindRawFile(image.getFileReference().getFileId(), false, this);
}
}
@Override
public void onDownloaded(FileSystemReference reference) {
messenger().unbindRawFile(image.getFileReference().getFileId(), false, this);
invalidationContext.invalidate();
}
});
}
}
}
// Top Row
int maxTitleWidth = (width - Screen.dp(72)) - Screen.dp(8);
if (arg.getDate() > 0) {
String dateText = messenger().getFormatter().formatShortDate(arg.getDate());
int dateWidth = (int) datePaint.measureText(dateText);
res.setDate(dateText, dateWidth);
maxTitleWidth -= dateWidth + Screen.dp(16);
}
if (arg.getPeer().getPeerType() == PeerType.GROUP) {
if (arg.isChannel()) {
res.setTitleIcon(channelIcon);
res.setTitleIconTop(Screen.dp(33));
} else {
res.setTitleIcon(groupIcon);
res.setTitleIconTop(Screen.dp(33));
}
maxTitleWidth -= Screen.dp(16 + /*icon width*/
4);
} else if (arg.getPeer().getPeerType() == PeerType.PRIVATE_ENCRYPTED) {
res.setTitleIcon(secretIcon);
res.setTitleIconTop(Screen.dp(31));
maxTitleWidth -= Screen.dp(16 + /*icon width*/
4);
} else if (arg.getPeer().getPeerType() == PeerType.PRIVATE) {
if (arg.isBot()) {
res.setTitleIcon(botIcon);
res.setTitleIconTop(Screen.dp(33));
maxTitleWidth -= Screen.dp(16 + /*icon width*/
4);
}
}
if (arg.getSenderId() == messenger().myUid()) {
if (arg.isRead()) {
res.setState(stateRead);
} else if (arg.isReceived()) {
res.setState(stateReceived);
} else {
res.setState(stateSent);
}
maxTitleWidth -= Screen.dp(20);
}
res.setTitleLayout(singleLineText(arg.getDialogTitle(), arg.getPeer().getPeerType() == PeerType.PRIVATE_ENCRYPTED ? titleSecurePaint : titlePaint, maxTitleWidth));
// Second Row
int maxWidth = width - Screen.dp(72) - Screen.dp(8);
if (arg.getUnreadCount() > 0) {
String counterText = "" + arg.getUnreadCount();
int counterWidth = (int) counterTextPaint.measureText(counterText) + Screen.sp(10);
counterWidth = Math.max(counterWidth, Screen.dp(22));
res.setCounter(counterText, counterWidth);
maxWidth -= counterWidth + Screen.dp(8);
}
if (arg.getSenderId() > 0) {
String contentText = messenger().getFormatter().formatContentText(arg.getSenderId(), arg.getMessageType(), arg.getText().replace("\n", " "), arg.getRelatedUid(), arg.isChannel());
if (arg.getPeer().getPeerType() == PeerType.GROUP) {
if (messenger().getFormatter().isLargeDialogMessage(arg.getMessageType())) {
res.setTextLayout(singleLineText(handleEmoji(contentText), textActivePaint, maxWidth));
} else {
String senderName = messenger().getFormatter().formatPerformerName(arg.getSenderId()) + ": ";
if (arg.getMessageType() == ContentType.TEXT) {
SpannableStringBuilder builder = new SpannableStringBuilder();
builder.append(senderName);
builder.setSpan(new ForegroundColorSpan(senderTextColor), 0, senderName.length(), Spannable.SPAN_INCLUSIVE_EXCLUSIVE);
builder.append(contentText);
res.setTextLayout(singleLineText(builder, textPaint, maxWidth));
} else {
CharSequence contentResult = handleEmoji(senderName, contentText);
res.setTextLayout(singleLineText(contentResult, textActivePaint, maxWidth));
}
}
} else {
if (arg.getMessageType() == ContentType.TEXT) {
res.setTextLayout(singleLineText(handleEmoji(contentText), textPaint, maxWidth));
} else {
res.setTextLayout(singleLineText(handleEmoji(contentText), textActivePaint, maxWidth));
}
}
}
return res;
}
Aggregations