Skip to content

Instantly share code, notes, and snippets.

@michalkejzlar
michalkejzlar / DownloadProductPicturesUseCase.java
Created February 12, 2017 19:36
Android - Download multiple pictures from remote server at once and save them into local path using Picasso, Okio and RxJava
import android.content.Context;
import android.net.Uri;
import android.util.Log;
import com.fernandocejas.frodo.annotation.RxLogObservable;
import com.squareup.okhttp.OkHttpClient;
import com.squareup.okhttp.Request;
import com.squareup.okhttp.Response;
import okio.BufferedSink;
import okio.BufferedSource;
import okio.Okio;
@michalkejzlar
michalkejzlar / ZoneLoaderService.java
Created February 12, 2017 19:33
Android background service for fetching and syncing POJOs using RxJava
import android.app.Service;
import android.content.Context;
import android.content.Intent;
import android.os.IBinder;
import android.support.annotation.Nullable;
import rx.Observer;
import timber.log.Timber;
import javax.inject.Inject;
@michalkejzlar
michalkejzlar / CopyPictureFromGallery.java
Created February 12, 2017 19:21
Android - copy selected image from gallery to your app using Picasso and RxJava
import android.app.Application;
import android.graphics.Bitmap;
import android.net.Uri;
import android.os.Environment;
import android.os.ParcelFileDescriptor;
import com.squareup.picasso.Picasso;
import com.squareup.picasso.RequestCreator;
import rx.Observable;
import rx.Observer;
import rx.Subscriber;
@michalkejzlar
michalkejzlar / MarkerManager.java
Created February 12, 2017 19:17
Google Map marker manager - loading GoogleMap marker objects asynchronously
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.model.BitmapDescriptorFactory;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.Marker;
import com.google.android.gms.maps.model.MarkerOptions;
import rx.Observable;
import rx.Observer;
import rx.Subscription;
@michalkejzlar
michalkejzlar / CountryLoader.java
Last active February 12, 2017 19:09
Get country ISO code from device's actual position using RxJava
import android.content.Context;
import android.location.Address;
import android.location.Location;
import android.support.annotation.NonNull;
import pl.charmas.android.reactivelocation.ReactiveLocationProvider;
import rx.Observable;
import rx.Subscription;
import rx.android.schedulers.AndroidSchedulers;
import rx.functions.Action1;
import rx.functions.Func1;
@michalkejzlar
michalkejzlar / GoogleMapObjectLoader.java
Created February 12, 2017 19:04
Lazy loading of Google Map polygons
import com.google.android.gms.maps.model.LatLngBounds;
import rx.Observable;
import rx.Observer;
import rx.Subscriber;
import rx.Subscription;
import rx.android.schedulers.AndroidSchedulers;
import rx.functions.Action1;
import rx.functions.Func1;
import rx.schedulers.Schedulers;
import rx.subjects.PublishSubject;
@michalkejzlar
michalkejzlar / AISpeechActivity.java
Last active February 12, 2017 21:23
Example usage of API.ai Android SDK. This activity receives speech input from user, sends it to API.ai and reads returned response
import ai.api.AIListener;
import ai.api.android.AIConfiguration;
import ai.api.android.AIService;
import ai.api.model.AIError;
import ai.api.model.AIResponse;
import ai.api.model.Result;
import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
import android.speech.tts.TextToSpeech;