Search in sources :

Example 1 with CompletableEmitter

use of io.reactivex.CompletableEmitter in project SimpleCropView by IsseiAoki.

the class CropImageView method loadAsCompletable.

/**
 * Load image from Uri with RxJava2
 *
 * @param sourceUri Image Uri
 *
 * @see #load(Uri)
 *
 * @return Completable of loading image
 */
public Completable loadAsCompletable(final Uri sourceUri, final boolean useThumbnail, final RectF initialFrameRect) {
    return Completable.create(new CompletableOnSubscribe() {

        @Override
        public void subscribe(@NonNull final CompletableEmitter emitter) throws Exception {
            mInitialFrameRect = initialFrameRect;
            mSourceUri = sourceUri;
            if (useThumbnail) {
                applyThumbnail(sourceUri);
            }
            final Bitmap sampled = getImage(sourceUri);
            mHandler.post(new Runnable() {

                @Override
                public void run() {
                    mAngle = mExifRotation;
                    setImageDrawableInternal(new BitmapDrawable(getResources(), sampled));
                    emitter.onComplete();
                }
            });
        }
    }).doOnSubscribe(new Consumer<Disposable>() {

        @Override
        public void accept(@NonNull Disposable disposable) throws Exception {
            mIsLoading.set(true);
        }
    }).doFinally(new Action() {

        @Override
        public void run() throws Exception {
            mIsLoading.set(false);
        }
    });
}
Also used : Disposable(io.reactivex.disposables.Disposable) Bitmap(android.graphics.Bitmap) Action(io.reactivex.functions.Action) Consumer(io.reactivex.functions.Consumer) NonNull(io.reactivex.annotations.NonNull) BitmapDrawable(android.graphics.drawable.BitmapDrawable) CompletableOnSubscribe(io.reactivex.CompletableOnSubscribe) IOException(java.io.IOException) CompletableEmitter(io.reactivex.CompletableEmitter)

Aggregations

Bitmap (android.graphics.Bitmap)1 BitmapDrawable (android.graphics.drawable.BitmapDrawable)1 CompletableEmitter (io.reactivex.CompletableEmitter)1 CompletableOnSubscribe (io.reactivex.CompletableOnSubscribe)1 NonNull (io.reactivex.annotations.NonNull)1 Disposable (io.reactivex.disposables.Disposable)1 Action (io.reactivex.functions.Action)1 Consumer (io.reactivex.functions.Consumer)1 IOException (java.io.IOException)1