Search in sources :

Example 1 with BiFunction

use of io.reactivex.functions.BiFunction in project Shuttle by timusus.

the class Aesthetic method resume.

/**
 * Should be called in onResume() of each Activity.
 */
public void resume(@NonNull final AppCompatActivity activity) {
    if (instance == null) {
        return;
    }
    instance.context = activity;
    if (instance.subs != null) {
        instance.subs.clear();
    }
    instance.subs = new CompositeDisposable();
    instance.subs.add(instance.colorPrimary().compose(Rx.<Integer>distinctToMainThread()).subscribe(new Consumer<Integer>() {

        @Override
        public void accept(@io.reactivex.annotations.NonNull Integer color) {
            Util.setTaskDescriptionColor(activity, color);
        }
    }, onErrorLogAndRethrow()));
    instance.subs.add(instance.activityTheme().compose(Rx.<Integer>distinctToMainThread()).subscribe(new Consumer<Integer>() {

        @Override
        public void accept(@io.reactivex.annotations.NonNull Integer themeId) {
            if (getLastActivityTheme(activity) == themeId) {
                return;
            }
            instance.lastActivityThemes.put(activity.getClass().getName(), themeId);
            activity.recreate();
        }
    }, onErrorLogAndRethrow()));
    instance.subs.add(Observable.combineLatest(instance.colorStatusBar(), instance.lightStatusBarMode(), new BiFunction<Integer, Integer, Pair<Integer, Integer>>() {

        @Override
        public Pair<Integer, Integer> apply(Integer integer, Integer integer2) {
            return Pair.create(integer, integer2);
        }
    }).compose(Rx.<Pair<Integer, Integer>>distinctToMainThread()).subscribe(new Consumer<Pair<Integer, Integer>>() {

        @Override
        public void accept(@io.reactivex.annotations.NonNull Pair<Integer, Integer> result) {
            instance.invalidateStatusBar(activity);
        }
    }, onErrorLogAndRethrow()));
    instance.subs.add(instance.colorNavigationBar().compose(Rx.<Integer>distinctToMainThread()).subscribe(new Consumer<Integer>() {

        @Override
        public void accept(@io.reactivex.annotations.NonNull Integer color) {
            setNavBarColorCompat(activity, color);
        }
    }, onErrorLogAndRethrow()));
    instance.subs.add(instance.colorWindowBackground().compose(Rx.<Integer>distinctToMainThread()).subscribe(new Consumer<Integer>() {

        @Override
        public void accept(@io.reactivex.annotations.NonNull Integer color) {
            activity.getWindow().setBackgroundDrawable(new ColorDrawable(color));
        }
    }, onErrorLogAndRethrow()));
    if (MaterialDialogsUtil.shouldSupport()) {
        instance.subs.add(MaterialDialogsUtil.observe(instance));
    }
}
Also used : Consumer(io.reactivex.functions.Consumer) ColorDrawable(android.graphics.drawable.ColorDrawable) BiFunction(io.reactivex.functions.BiFunction) CompositeDisposable(io.reactivex.disposables.CompositeDisposable) Pair(android.support.v4.util.Pair)

Example 2 with BiFunction

use of io.reactivex.functions.BiFunction in project Shuttle by timusus.

the class AestheticCoordinatorLayout method onAttachedToWindow.

@Override
public void onAttachedToWindow() {
    super.onAttachedToWindow();
    // Find the toolbar and color view used to blend the scroll transition
    if (getChildCount() > 0 && getChildAt(0) instanceof AppBarLayout) {
        appBarLayout = (AppBarLayout) getChildAt(0);
        if (appBarLayout.getChildCount() > 0 && appBarLayout.getChildAt(0) instanceof CollapsingToolbarLayout) {
            collapsingToolbarLayout = (CollapsingToolbarLayout) appBarLayout.getChildAt(0);
            for (int i = 0; i < collapsingToolbarLayout.getChildCount(); i++) {
                if (this.toolbar != null && this.colorView != null) {
                    break;
                }
                View child = collapsingToolbarLayout.getChildAt(i);
                if (child instanceof AestheticToolbar) {
                    this.toolbar = (AestheticToolbar) child;
                } else if (child.getBackground() != null && child.getBackground() instanceof ColorDrawable) {
                    this.colorView = child;
                }
            }
        }
    }
    if (toolbar != null && colorView != null) {
        this.appBarLayout.addOnOffsetChangedListener(this);
        toolbarColorSubscription = Observable.combineLatest(toolbar.colorUpdated(), Aesthetic.get(getContext()).colorIconTitle(toolbar.colorUpdated()), new BiFunction<Integer, ActiveInactiveColors, Pair<Integer, ActiveInactiveColors>>() {

            @Override
            public Pair<Integer, ActiveInactiveColors> apply(Integer integer, ActiveInactiveColors activeInactiveColors) {
                return Pair.create(integer, activeInactiveColors);
            }
        }).compose(Rx.<Pair<Integer, ActiveInactiveColors>>distinctToMainThread()).subscribe(new Consumer<Pair<Integer, ActiveInactiveColors>>() {

            @Override
            public void accept(@NonNull Pair<Integer, ActiveInactiveColors> result) {
                toolbarColor = result.first;
                iconTextColors = result.second;
                invalidateColors();
            }
        }, onErrorLogAndRethrow());
    }
    if (collapsingToolbarLayout != null) {
        statusBarColorSubscription = Aesthetic.get(getContext()).colorStatusBar().compose(Rx.<Integer>distinctToMainThread()).subscribe(new Consumer<Integer>() {

            @Override
            public void accept(@io.reactivex.annotations.NonNull Integer color) {
                collapsingToolbarLayout.setContentScrimColor(color);
                collapsingToolbarLayout.setStatusBarScrimColor(color);
            }
        }, onErrorLogAndRethrow());
    }
}
Also used : ActionMenuView(android.support.v7.widget.ActionMenuView) ActionMenuItemView(android.support.v7.view.menu.ActionMenuItemView) View(android.view.View) ColorDrawable(android.graphics.drawable.ColorDrawable) Consumer(io.reactivex.functions.Consumer) BiFunction(io.reactivex.functions.BiFunction) NonNull(android.support.annotation.NonNull) CollapsingToolbarLayout(android.support.design.widget.CollapsingToolbarLayout) AppBarLayout(android.support.design.widget.AppBarLayout) Pair(android.support.v4.util.Pair)

Example 3 with BiFunction

use of io.reactivex.functions.BiFunction in project Offer by woshiyizhijiao.

the class RxJavaActivity method zip1.

/**
 * zip操作符
 * 将上游的两个管道按顺序合并,合并的最终长度为管道事件最少的的管道。默认是在同一个线程中完成,想要同时进行,需要设置Schedulers.io()
 */
public void zip1(View v) {
    Observable observable1 = Observable.create(new ObservableOnSubscribe<Integer>() {

        @Override
        public void subscribe(ObservableEmitter<Integer> emitter) throws Exception {
            emitter.onNext(1);
            LogUtils.e("onNext 1");
            emitter.onNext(2);
            LogUtils.e("onNext 2");
            emitter.onNext(3);
            LogUtils.e("onNext 3");
            emitter.onNext(4);
            LogUtils.e("onNext 4");
            emitter.onComplete();
            LogUtils.e("onComplete 1");
        }
    }).subscribeOn(Schedulers.io());
    Observable observable2 = Observable.create(new ObservableOnSubscribe<String>() {

        @Override
        public void subscribe(ObservableEmitter<String> emitter) throws Exception {
            emitter.onNext("A");
            LogUtils.e("onNext A");
            emitter.onNext("B");
            LogUtils.e("onNext B");
            emitter.onNext("C");
            LogUtils.e("onNext C");
            emitter.onComplete();
            LogUtils.e("onComplete 2");
        }
    }).subscribeOn(Schedulers.io());
    Observable.zip(observable1, observable2, new BiFunction<Integer, String, String>() {

        @Override
        public String apply(Integer integer, String s) throws Exception {
            return integer + s;
        }
    }).subscribe(new Observer() {

        @Override
        public void onSubscribe(Disposable d) {
            LogUtils.e("onSubscribe");
        }

        @Override
        public void onNext(Object value) {
            LogUtils.e("onNext : " + value);
        }

        @Override
        public void onError(Throwable e) {
            LogUtils.e("onError : ");
        }

        @Override
        public void onComplete() {
            LogUtils.e("onComplete : ");
        }
    });
}
Also used : Disposable(io.reactivex.disposables.Disposable) ObservableOnSubscribe(io.reactivex.ObservableOnSubscribe) BiFunction(io.reactivex.functions.BiFunction) Observer(io.reactivex.Observer) Observable(io.reactivex.Observable) ObservableEmitter(io.reactivex.ObservableEmitter)

Aggregations

BiFunction (io.reactivex.functions.BiFunction)3 ColorDrawable (android.graphics.drawable.ColorDrawable)2 Pair (android.support.v4.util.Pair)2 Consumer (io.reactivex.functions.Consumer)2 NonNull (android.support.annotation.NonNull)1 AppBarLayout (android.support.design.widget.AppBarLayout)1 CollapsingToolbarLayout (android.support.design.widget.CollapsingToolbarLayout)1 ActionMenuItemView (android.support.v7.view.menu.ActionMenuItemView)1 ActionMenuView (android.support.v7.widget.ActionMenuView)1 View (android.view.View)1 Observable (io.reactivex.Observable)1 ObservableEmitter (io.reactivex.ObservableEmitter)1 ObservableOnSubscribe (io.reactivex.ObservableOnSubscribe)1 Observer (io.reactivex.Observer)1 CompositeDisposable (io.reactivex.disposables.CompositeDisposable)1 Disposable (io.reactivex.disposables.Disposable)1