java 基于android.databinding库的原语的一些简单的Rx绑定。这允许您在r中应用,映射,过滤和所有好东西

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了java 基于android.databinding库的原语的一些简单的Rx绑定。这允许您在r中应用,映射,过滤和所有好东西相关的知识,希望对你有一定的参考价值。

/**
 * Created by marius on 1/9/15.
 *
 * @music Beware of safety - Kaura
 */
public class RxValuesSampleViewModel {

    public RxBoolean enabled = new RxBoolean();

    public void toggle() {
        enabled.set(!enabled.get());
    }

    [...]
}


public class RxValuesSampleView {

    private final RxValuesSampleViewModel viewModel = new RxValuesSampleViewModel();

    [...]

    public void bind() {
        viewModel.enabled.valueObservable().
                subscribe(button::setEnabled);
    }
}
import rx.Observable;

/**
 * Created by marius on 31/8/15.
 *
 * @music Antonia Font - Alegria
 */
public interface RxValue<T> {

    Observable<T> valueObservable();

    void valueChanged(T value);
}
import android.databinding.ObservableShort;

import rx.Observable;
import rx.subjects.BehaviorSubject;

/**
 * Created by marius on 31/8/15.
 *
 * @music Antonia Font - Alegria
 */
public class RxShort extends ObservableShort implements RxValue<Short> {

    private BehaviorSubject<Short> valueSubject = BehaviorSubject.create();

    public RxShort(short value) {
        super(value);
    }

    public RxShort() {
        super();
    }

    @Override
    public void set(short value) {
        super.set(value);
        valueSubject.onNext(value);
    }

    @Override
    public Observable<Short> valueObservable() {
        return valueSubject.asObservable();
    }

    @Override
    public void valueChanged(Short value) {
        valueSubject.onNext(value);
    }
}
import android.databinding.ObservableLong;

import rx.Observable;
import rx.subjects.BehaviorSubject;

/**
 * Created by marius on 31/8/15.
 *
 * @music Antonia Font - Vehicle Lunar
 */
public class RxLong extends ObservableLong implements RxValue<Long> {

    private BehaviorSubject<Long> valueSubject = BehaviorSubject.create();

    public RxLong(long value) {
        super(value);
    }

    public RxLong() {
        super();
    }

    @Override
    public void set(long value) {
        super.set(value);
        valueSubject.onNext(value);
    }

    @Override
    public Observable<Long> valueObservable() {
        return valueSubject.asObservable();
    }

    @Override
    public void valueChanged(Long value) {
        valueSubject.onNext(value);
    }
}
import android.databinding.ObservableInt;

import rx.Observable;
import rx.subjects.BehaviorSubject;

/**
 * Created by marius on 31/8/15.
 *
 * @music Antonia Font - Me sobren paraules
 */
public class RxInt extends ObservableInt implements RxValue<Integer> {

    private BehaviorSubject<Integer> valueSubject = BehaviorSubject.create();

    public RxInt(int value) {
        super(value);
    }

    public RxInt() {
        super();
    }

    @Override
    public void set(int value) {
        super.set(value);
        valueSubject.onNext(value);
    }

    @Override
    public Observable<Integer> valueObservable() {
        return valueSubject.asObservable();
    }

    @Override
    public void valueChanged(Integer value) {
        valueSubject.onNext(value);
    }
}
import android.databinding.ObservableFloat;

import rx.Observable;
import rx.subjects.BehaviorSubject;

/**
 * Created by marius on 31/8/15.
 *
 * @music Antonia Font - Vehicle Lunar
 */
public class RxFloat extends ObservableFloat implements RxValue<Float> {

    private BehaviorSubject<Float> valueSubject = BehaviorSubject.create();

    public RxFloat(float value) {
        super(value);
    }

    public RxFloat() {
        super();
    }

    @Override
    public void set(float value) {
        super.set(value);
        valueSubject.onNext(value);
    }

    @Override
    public Observable<Float> valueObservable() {
        return valueSubject.asObservable();
    }

    @Override
    public void valueChanged(Float value) {
        valueSubject.onNext(value);
    }
}
import android.databinding.ObservableField;

import rx.Observable;
import rx.subjects.BehaviorSubject;

/**
 * Created by marius on 31/8/15.
 *
 * @music Antonia Font - Me sobren paraules
 */
public class RxField<T> extends ObservableField<T> implements RxValue<T> {

    private BehaviorSubject<T> valueSubject = BehaviorSubject.create();

    public RxField(T value) {
        super(value);
    }

    public RxField() {
        super();
    }

    @Override
    public void set(T value) {
        super.set(value);
        valueSubject.onNext(value);
    }

    @Override
    public Observable<T> valueObservable() {
        return valueSubject.asObservable();
    }

    @Override
    public void valueChanged(T value) {
        valueSubject.onNext(value);
    }
}
import android.databinding.ObservableDouble;

import rx.Observable;
import rx.subjects.BehaviorSubject;

/**
 * Created by marius on 31/8/15.
 *
 * @music Antonia Font - Vehicle Lunar
 */
public class RxDouble extends ObservableDouble implements RxValue<Double> {

    private BehaviorSubject<Double> valueSubject = BehaviorSubject.create();

    public RxDouble(double value) {
        super(value);
    }

    public RxDouble() {
        super();
    }

    @Override
    public void set(double value) {
        super.set(value);
        valueSubject.onNext(value);
    }

    @Override
    public Observable<Double> valueObservable() {
        return valueSubject.asObservable();
    }

    @Override
    public void valueChanged(Double value) {
        valueSubject.onNext(value);
    }
}
import android.databinding.ObservableChar;

import rx.Observable;
import rx.subjects.BehaviorSubject;

/**
 * Created by marius on 31/8/15.
 *
 * @music Antonia Font - Vehicle Lunar
 */
public class RxChar extends ObservableChar implements RxValue<Character> {

    private BehaviorSubject<Character> valueSubject = BehaviorSubject.create();

    public RxChar(char value) {
        super(value);
    }

    public RxChar() {
        super();
    }

    @Override
    public void set(char value) {
        super.set(value);
        valueSubject.onNext(value);
    }

    @Override
    public Observable<Character> valueObservable() {
        return valueSubject.asObservable();
    }

    @Override
    public void valueChanged(Character value) {
        valueSubject.onNext(value);
    }
}
import android.databinding.ObservableByte;

import rx.Observable;
import rx.subjects.BehaviorSubject;

/**
 * Created by marius on 31/8/15.
 *
 * @music Antonia Font - Vehicle Lunar
 */
public class RxByte extends ObservableByte implements RxValue<Byte> {

    private BehaviorSubject<Byte> valueSubject = BehaviorSubject.create();

    public RxByte(byte value) {
        super(value);
    }

    public RxByte() {
        super();
    }

    @Override
    public void set(byte value) {
        super.set(value);
        valueSubject.onNext(value);
    }

    @Override
    public Observable<Byte> valueObservable() {
        return valueSubject.asObservable();
    }

    @Override
    public void valueChanged(Byte value) {
        valueSubject.onNext(value);
    }
}
import android.databinding.ObservableBoolean;

import rx.Observable;
import rx.subjects.BehaviorSubject;

/**
 * Created by marius on 31/8/15.
 *
 * @music Antonia Font - Me sobren paraules
 */
public class RxBoolean extends ObservableBoolean implements RxValue<Boolean> {

    private BehaviorSubject<Boolean> valueSubject = BehaviorSubject.create();

    public RxBoolean(boolean value) {
        super(value);
    }

    public RxBoolean() {
        super();
    }

    @Override
    public void set(boolean value) {
        super.set(value);
        valueSubject.onNext(value);
    }

    @Override
    public Observable<Boolean> valueObservable() {
        return valueSubject.asObservable();
    }

    @Override
    public void valueChanged(Boolean value) {
        valueSubject.onNext(value);
    }
}

以上是关于java 基于android.databinding库的原语的一些简单的Rx绑定。这允许您在r中应用,映射,过滤和所有好东西的主要内容,如果未能解决你的问题,请参考以下文章

将基于 Java 的配置转换为基于 Spring XML 的配置

06.Apache Pulsar的JAVA API相关使用操作,基于Pulsar实现Topic的构建操作,使用JAVA如何管理租户/namespace/Topic,基于Pulsar实现数据生产/消费

Postman 是基于 Java 的工具吗?

Java基于对象基础 基于对象和面向对象的区别(转)

寻找基于javaweb的毕业设计代做?请找我们

用于 Java-GraphQL 服务器的 Java 中基于中继的分页