Skip to content

Instantly share code, notes, and snippets.

View orwir's full-sized avatar

Igor Zubenko orwir

  • Epam Systems
  • Poland
View GitHub Profile
@orwir
orwir / 0_ReactiveLiveData.kt
Last active October 9, 2020 15:45
Reactive operators for LiveData
// see code files below
@orwir
orwir / ServiceSubscriber.java
Last active May 11, 2020 15:44
Make an Observable which emits Binder class when service connected.
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.ServiceConnection;
import android.os.IBinder;
import io.reactivex.SingleEmitter;
import io.reactivex.SingleOnSubscribe;
import io.reactivex.annotations.NonNull;
import io.reactivex.disposables.Disposable;
import android.util.Pair;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import org.reactivestreams.Publisher;
import java.io.File;
import java.util.Arrays;
import java.util.List;
import com.google.gson.JsonElement;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;
public class JsonUtils {
public static final int MARKERS_COUNT_MAX = 2;
import android.arch.lifecycle.LiveData
import android.content.Context
import android.net.ConnectivityManager
import android.net.Network
import android.net.NetworkRequest
class OnlineLiveData(context: Context) : LiveData<Boolean>() {
private val availableNetworks = mutableSetOf<Network>()
@orwir
orwir / SharedPreferencesExtensions.kt
Last active March 12, 2024 09:27
Kotlin extensions for shared preferences
import android.content.Context
import android.content.SharedPreferences
import kotlin.reflect.KProperty
/**
* Creates delegate for property from [prefs] with the key presented as className+propertyName.
* @param T type of the property
* @param defaultValue is used if property not set
* @return wrapper for property accessors
*/
@orwir
orwir / FontsReplacer.java
Created June 3, 2016 11:33
Android: change fonts for the whole application
public class FontsReplacer {
@SuppressWarnings("unchecked")
public static void replaceFonts(Context context) {
try {
//we need to change all static fields contains fonts:
//1. static constants
setStaticFinalField(Typeface.class, "DEFAULT", FontCache.getTypeface(context, Typeface.NORMAL));
setStaticFinalField(Typeface.class, "DEFAULT_BOLD", FontCache.getTypeface(context, Typeface.BOLD));