This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class MainActivity extends AppCompatActivity { | |
private static final String IMAGE_URL = "https://www.android.com/static/2016/img/logo-android-green_2x.png"; | |
private ProgressBar progressIndicator; | |
private ImageView imageView; | |
private Handler handler; | |
class ImageFetcher implements Runnable { | |
final String url; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class MainActivity extends AppCompatActivity { | |
private static final String IMAGE_URL = "https://www.android.com/static/2016/img/logo-android-green_2x.png"; | |
private static final int MSG_SHOW_PROGRESS = 1; | |
private static final int MSG_SHOW_IMAGE = 2; | |
private ProgressBar progressIndicator; | |
private ImageView imageView; | |
private Handler handler; | |
class ImageFetcher implements Runnable { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
COUNT=0 | |
RENAME_FILE="enter_new_filename_%02d.png" | |
for FILE in *.png; do | |
mv "$FILE" $(printf $RENAME_FILE $COUNT) | |
let COUNT=COUNT+1 | |
done |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public void touchEventHandler(@NotNull View view) { | |
final ConnectedObservable<MotionEvent> motionEventObservable = RxView.touches(view).publish(); | |
// Capture down events | |
final Observable<MotionEvent> downEventsObservable = motionEventObservable | |
.filter(event -> event.getAction() == MotionEvent.ACTION_DOWN); | |
// Capture up events | |
final Observable<MotionEvent> upEventsObservable = motionEventObservable | |
.filter(event -> event.getAction() == MotionEvent.ACTION_UP); | |
// Show a red circle at the position where the down event ocurred |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public Observable<byte[]> readFile(@NonNull FileInputStream stream) { | |
final SyncOnSubscribe<FileInputStream, byte[]> fileReader = SyncOnSubscribe.createStateful( | |
() -> stream, | |
(stream, output) -> { | |
try { | |
final byte[] buffer = new byte[BUFFER_SIZE]; | |
int count = stream.read(buffer); | |
if (count < 0) { | |
output.onCompleted(); | |
} else { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import android.bluetooth.le.BluetoothLeScanner; | |
import android.bluetooth.le.ScanCallback; | |
import android.bluetooth.le.ScanResult; | |
import android.support.annotation.NonNull; | |
import rx.Emitter; | |
import rx.Observable; | |
import java.util.List; | |
public class RxBluetoothScanner { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public Observable<SearchResult> search(@NotNull EditText searchView) { | |
return RxTextView.textChanges(searchView) // In production, share this text view observable, don't create a new one each time | |
.map(CharSequence::toString) | |
.debounce(500, TimeUnit.MILLISECONDS) // Avoid getting spammed with key stroke changes | |
.filter(s -> s.length() > 1) // Only interested in queries of length greater than 1 | |
.observeOn(workerScheduler) // Next set of operations will be network so switch to an IO Scheduler (or worker) | |
.switchMap(query -> searchService.query(query)) // Take the latest observable from upstream and unsubscribe from any previous subscriptions | |
.onErrorResumeNext(Observable.empty()); // <-- This will terminate upstream (ie. we will stop receiving text view changes after an error!) | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public Observable<SearchResult> search(@NotNull EditText searchView) { | |
return RxTextView.textChanges(searchView) // In production, share this text view observable, don't create a new one each time | |
.map(CharSequence::toString) | |
.debounce(500, TimeUnit.MILLISECONDS) // Avoid getting spammed with key stroke changes | |
.filter(s -> s.length() > 1) // Only interested in queries of length greater than 1 | |
.observeOn(workerScheduler) // Next set of operations will be network so switch to an IO Scheduler (or worker) | |
.switchMap(query -> searchService.query(query) // Take the latest observable from upstream and unsubscribe from any previous subscriptions | |
.onErrorResumeNext(Observable.empty()); // <-- This fixes the problem since the error is not seen by the upstream observable | |
} |