use of com.alexstyl.specialdates.Optional in project Memento-Calendar by alexstyl.
the class CircularAvatarFactory method circularAvatarFor.
Optional<Bitmap> circularAvatarFor(Contact contact, @Px int targetSize) {
Optional<Bitmap> bitmapOptional = imageLoader.load(contact.getImagePath()).withSize(targetSize, targetSize).synchronously();
if (!bitmapOptional.isPresent()) {
return Optional.Companion.absent();
}
Bitmap avatar = bitmapOptional.get();
Bitmap circleBitmap = Bitmap.createBitmap(avatar.getWidth(), avatar.getHeight(), Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(circleBitmap);
Paint paint = createPaintFrom(avatar);
canvas.drawCircle(circleBitmap.getWidth() / 2.0f, circleBitmap.getHeight() / 2.0f, circleBitmap.getWidth() / 2.0f, paint);
return new Optional<>(circleBitmap);
}
use of com.alexstyl.specialdates.Optional in project Memento-Calendar by alexstyl.
the class UILImageLoader method load.
@NonNull
@Override
public Request load(@NonNull final URI imagePath) {
final DisplayImageOptions.Builder builder = standardBuilder();
return new Request() {
@Override
public void into(@NonNull ImageView imageView) {
uil.displayImage(imagePath.toString(), imageView, builder.build());
}
@NonNull
@Override
public Request asCircle() {
builder.displayer(defaultCircleDisplayer);
return this;
}
@NonNull
@Override
public FixedSizeRequest withSize(@Px final int width, @Px final int height) {
builder.displayer(DefaultConfigurationFactory.createBitmapDisplayer());
return new FixedSizeRequest() {
@NonNull
@Override
public Optional<Bitmap> synchronously() {
Bitmap bitmap = uil.loadImageSync(imagePath.toString(), new ImageSize(width, height), builder.build());
if (bitmap == null) {
return Optional.Companion.absent();
} else {
return new Optional<>(bitmap);
}
}
@Override
public void into(@NonNull final ImageLoadedConsumer consumer) {
builder.displayer(DefaultConfigurationFactory.createBitmapDisplayer());
uil.loadImage(imagePath.toString(), builder.build(), new SimpleImageLoadingListener() {
@Override
public void onLoadingComplete(String imageUri, View view, Bitmap loadedImage) {
consumer.onImageLoaded(loadedImage);
}
@Override
public void onLoadingFailed(String imageUri, View view, FailReason failReason) {
consumer.onLoadingFailed();
}
});
}
};
}
};
}
use of com.alexstyl.specialdates.Optional in project Memento-Calendar by alexstyl.
the class QueryUpcomingPeopleEventsTask method doInBackground.
@Override
protected Optional<ContactEventsOnADate> doInBackground(Object... params) {
Date today = Date.Companion.today();
Date date = eventsProvider.findClosestEventDateOnOrAfter(today);
if (date != null) {
return new Optional<>(eventsProvider.fetchEventsOn(date));
}
return Optional.absent();
}
Aggregations