Android Open Source - rxjava-android-example Properties






From Project

Back to project page rxjava-android-example.

License

The source code is released under:

Apache License

If you think the Android project rxjava-android-example listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package rx.android;
//from w w w .j  a  va 2 s.c o  m
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.TextView;

import java.util.List;

import rx.Observable;
import rx.util.functions.Action1;

public final class Properties {

    // no instances of helper class
    private Properties() { }

    /**
     * Updates the <em>enabled</em> property of a view for each event received.
     */
    public static EnabledProperty enabledFrom(View view) {
        return new EnabledProperty(view);
    }

    /**
     * Updates the <em>text</em> property of a view for each event received.
     */
    public static TextProperty textFrom(TextView view) {
        return new TextProperty(view);
    }

    /**
     * Clear, update and notify changes of dataset for {@code ArrayAdapter}.
     */
    public static <T> ArrayAdapterProperty<T> dataSetFrom(ArrayAdapter<T> adapter) {
        return new ArrayAdapterProperty<T>(adapter);
    }

    public static class EnabledProperty implements Action1<Boolean> {
        private final View view;

        private EnabledProperty(View view) {
            this.view = view;
        }

        public void set(Observable<Boolean> observable) {
            observable.subscribe(this);
        }

        @Override public void call(Boolean enabled) {
            view.setEnabled(enabled);
        }
    }

    public static class TextProperty implements Action1<String> {
        private final TextView view;

        private TextProperty(TextView view) {
            this.view = view;
        }

        public void set(Observable<String> observable) {
            observable.subscribe(this);
        }

        @Override public void call(String text) {
            view.setText(text);
        }
    }

    public static class ArrayAdapterProperty<T> implements Action1<List<T>> {
        private final ArrayAdapter<T> adapter;

        ArrayAdapterProperty(ArrayAdapter<T> adapter) {
            this.adapter = adapter;
        }

        public void set(Observable<List<T>> observable) {
            observable.subscribe(this);
        }

        @Override public void call(List<T> items) {
            adapter.clear();
            for (T item : items) {
                adapter.add(item);
            }
            adapter.notifyDataSetChanged();
        }
    }
}




Java Source Code List

com.example.rx.ComposeMessageActivity.java
com.example.rx.ComposeMessageTest.java
rx.android.Events.java
rx.android.Properties.java