Search in sources :

Example 1 with Optional

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);
}
Also used : Bitmap(android.graphics.Bitmap) Optional(com.alexstyl.specialdates.Optional) Canvas(android.graphics.Canvas) Paint(android.graphics.Paint)

Example 2 with Optional

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();
                        }
                    });
                }
            };
        }
    };
}
Also used : Optional(com.alexstyl.specialdates.Optional) ImageSize(com.nostra13.universalimageloader.core.assist.ImageSize) Px(android.support.annotation.Px) FailReason(com.nostra13.universalimageloader.core.assist.FailReason) ImageView(android.widget.ImageView) View(android.view.View) SimpleImageLoadingListener(com.nostra13.universalimageloader.core.listener.SimpleImageLoadingListener) Bitmap(android.graphics.Bitmap) NonNull(android.support.annotation.NonNull) ImageView(android.widget.ImageView) DisplayImageOptions(com.nostra13.universalimageloader.core.DisplayImageOptions) NonNull(android.support.annotation.NonNull)

Example 3 with Optional

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();
}
Also used : Optional(com.alexstyl.specialdates.Optional) ContactEventsOnADate(com.alexstyl.specialdates.events.peopleevents.ContactEventsOnADate) Date(com.alexstyl.specialdates.date.Date)

Aggregations

Optional (com.alexstyl.specialdates.Optional)3 Bitmap (android.graphics.Bitmap)2 Canvas (android.graphics.Canvas)1 Paint (android.graphics.Paint)1 NonNull (android.support.annotation.NonNull)1 Px (android.support.annotation.Px)1 View (android.view.View)1 ImageView (android.widget.ImageView)1 Date (com.alexstyl.specialdates.date.Date)1 ContactEventsOnADate (com.alexstyl.specialdates.events.peopleevents.ContactEventsOnADate)1 DisplayImageOptions (com.nostra13.universalimageloader.core.DisplayImageOptions)1 FailReason (com.nostra13.universalimageloader.core.assist.FailReason)1 ImageSize (com.nostra13.universalimageloader.core.assist.ImageSize)1 SimpleImageLoadingListener (com.nostra13.universalimageloader.core.listener.SimpleImageLoadingListener)1