Skip to content

Instantly share code, notes, and snippets.

@magillus
magillus / ContentObserverSubscriber.java
Last active April 18, 2020 21:46
RxContentObserver, wraps ContentObserver registration and on change with RxJava Observable that will emit updates.
package com.example.mat.rxutil;
import android.content.ContentResolver;
import android.database.ContentObserver;
import android.net.Uri;
import android.os.Build;
import android.os.Handler;
import android.os.HandlerThread;
import java.lang.ref.WeakReference;
@magillus
magillus / ContentObserverSubscriber.java
Last active August 16, 2021 23:28
RxContentObserver, wraps ContentObserver registration and on change with RxJava2.0 Observable that will emit updates.
package com.example.mat.rxutil;
import android.content.ContentResolver;
import android.database.ContentObserver;
import android.net.Uri;
import android.os.Build;
import android.os.Handler;
import android.os.HandlerThread;
import java.lang.ref.WeakReference;
@magillus
magillus / RxBroadcastReceiver.java
Last active August 21, 2020 22:25
RxJava2.0 Broadcast Receiver for getting intent broadcasts as Observable<Intent>
/**
* RxJava based broadcast reciever that registers its local BroadcastReceiver until end of subscription.
* Listens for update and passes Intent to the Stream (Subscriber).
*
* Copyright 2016 Mateusz Perlak - http://www.apache.org/licenses/LICENSE-2.0
* Created on 11/18/16.
*/
public class RxBroadcastReceiver implements ObservableOnSubscribe<Intent> {
protected final WeakReference<Context> contextWeakReference;
@magillus
magillus / RxBoundServcie.java
Last active March 27, 2021 15:07
Rx wrapper around bounded Android Service that emits IBinder. It binds to a service on subscription and unbinds on disposing the subscription's disposable.
package com.example.mat.rxutil;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.ServiceConnection;
import android.os.IBinder;
import java.lang.ref.WeakReference;
@magillus
magillus / RealmContext.java
Created June 7, 2017 21:57
Realm Context wrapper.
package com.example.mat.rxjavaplayground.rxutil;
import android.content.Context;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import java.util.Collections;
import java.util.List;
import io.reactivex.functions.Function;
@magillus
magillus / Function.java
Last active June 8, 2017 11:56
Realm Context wrapper, for easy opening realm and closing with action and data return (copyFromRealm).
// copied from Reactive X functions - have your own if no need for full Rx in your project.
package io.reactivex.functions;
/**
* A functional interface that takes a value and returns another value, possibly with a
* different type and allows throwing a checked exception.
*
* @param <T> the input value type
* @param <R> the output value type
*/
@magillus
magillus / LifecycleObservableTransformer.java
Last active March 29, 2018 05:54
Observable transformer that will act on event of the Lifecycle to auto dispose its subscriptions when the event occurs. By default ON_DESTROY
package com.example.playground;
import android.arch.lifecycle.Lifecycle;
import android.arch.lifecycle.LifecycleObserver;
import android.arch.lifecycle.OnLifecycleEvent;
import android.support.annotation.NonNull;
import android.util.Log;
import java.lang.ref.WeakReference;
import java.util.Map;
@magillus
magillus / BackgroundThread.kt
Created September 14, 2017 22:08
RxRealm Flowable wrappers with Looper
package com.example.playground;
import android.os.HandlerThread
import android.os.Process
/**
* Looper based BackgroundThread handler for REalm executions.
*/
class BackgroundThread : HandlerThread("Scheduler-Realm-BackgroundThread", Process.THREAD_PRIORITY_BACKGROUND)
@magillus
magillus / Medium sticky.log.txt
Created August 21, 2018 11:44
Medium on media button play opens empty notification that can't be dimissed. Here is logcat for it
08-21 06:39:54.332 1535-4176/? D/MediaSessionService: Sending KeyEvent { action=ACTION_DOWN, keyCode=KEYCODE_MEDIA_PLAY_PAUSE, scanCode=0, metaState=0, flags=0x0, repeatCount=0, eventTime=0, downTime=0, deviceId=-1, displayId=0, source=0x0 } to the last known PendingIntent PendingIntent{5b76839: PendingIntentRecord{7925b0e com.medium.reader broadcastIntent}}
08-21 06:39:54.333 1535-4176/? D/MediaSessionService: Sending KeyEvent { action=ACTION_UP, keyCode=KEYCODE_MEDIA_PLAY_PAUSE, scanCode=0, metaState=0, flags=0x0, repeatCount=0, eventTime=0, downTime=0, deviceId=-1, displayId=0, source=0x0 } to the last known PendingIntent PendingIntent{5b76839: PendingIntentRecord{7925b0e com.medium.reader broadcastIntent}}
08-21 06:39:54.335 1535-1550/? D/StorageManagerService: getExternalStorageMountMode : 1
getExternalStorageMountMode : 3
getExternalStorageMountMode : final mountMode=1, uid : 10324, packageName : com.medium.reader
08-21 06:39:54.335 1535-1550/? I/ApplicationPolicy: isApplicationExternalStorageWh
@magillus
magillus / example.dart
Last active November 2, 2018 00:26
Fimber = Timber like logging for Flutter. May extend to different trees (like native channel logging (?) TBD)
import 'package:fimber/fimber.dart';
// initialization in main.dart
Fimber.addTree(DebugTree());
// usage:
Fimber.d("Test debug $value");
Fimber.de(exIo, "Error reading file: $path");