Skip to content Skip to sidebar Skip to footer

Emit Objects For Drawing In The Ui In A Regular Interval Using Rxjava On Android

I am parsing SVG files in an Observable. Points are emitted as 'Path' object as the XML is parsed. Parsing happens in a separate thread and I want to draw the SVG file point by poi

Solution 1:

You need to use the .zip() operator with a .timer(). From original RxJava wiki:

  • zip():

    combine Observables together via a specified function and emit items based on the results of this function

  • timer():

    create an Observable that emits a single item after a given delay

So, if you use zip() to combine your original Observer with timer(), you can delay the output of each Path every 50 msecs:

privatevoiddrawPath(final String chars) {
    Observable.zip(
        Observable.create(newObservable.OnSubscribe<Path>() {
            // all the drawing stuff here
            ...
        }),
        Observable.timer(0, 50, TimeUnit.MILLISECONDS),
        newFunc2<Path, Long, Path>() {
            @OverridepublicPathcall(Path path, Long aLong) {
                return path;
            }
        }
    )
    .subscribeOn(Schedulers.newThread())
    .observeOn(AndroidSchedulers.mainThread())
    ...
}

Post a Comment for "Emit Objects For Drawing In The Ui In A Regular Interval Using Rxjava On Android"