Skip to content

Instantly share code, notes, and snippets.

@khangaldi
Created December 5, 2016 04:54
Show Gist options
  • Save khangaldi/c2ff27362361169d318f899b9d222b75 to your computer and use it in GitHub Desktop.
Save khangaldi/c2ff27362361169d318f899b9d222b75 to your computer and use it in GitHub Desktop.
Scattered scripts in Java for testing Retrolambda and Reactive Programming in Java
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.TextView;
import android.widget.Toast;
import com.jakewharton.rxbinding.view.RxView;
import java.util.ArrayList;
import rx.Observable;
import rx.android.schedulers.AndroidSchedulers;
import rx.functions.Action1;
import rx.schedulers.Schedulers;
public class MainActivity extends AppCompatActivity {
@Override protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
TextView textView = (TextView) findViewById(R.id.textView);
RxView.clicks(textView).subscribe(t -> showMessage());
}
public void showMessage() {
Toast.makeText(getApplicationContext(), "Hello World!", Toast.LENGTH_LONG).show();
Observable
.just(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)
.filter(integer -> integer % 2 == 0)
.map(this::multiple)
.takeUntil(integer -> integer.length() > 0)
.subscribeOn(Schedulers.computation())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(System.out::println);
Observable
.just(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)
.map(String::valueOf)
.forEach(this::addToArray);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment