This file contains 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
class AnimatedVectorDrawableMarkerIcon( | |
marker: Marker, | |
private val avd: AnimatedVectorDrawableCompat, | |
width: Int = avd.intrinsicWidth, | |
height: Int = avd.intrinsicHeight | |
) { | |
private val handler = Handler(Looper.getMainLooper()) | |
private val invalidateTask = Runnable { avd.invalidateSelf() } | |
private var isRunning = false | |
private var isAutoLoop = false |
This file contains 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
class OneShotGlobalLayoutListener private constructor( | |
private val view: View, | |
private val runnable: Runnable | |
) : ViewTreeObserver.OnGlobalLayoutListener, View.OnAttachStateChangeListener { | |
private var viewTreeObserver: ViewTreeObserver = view.viewTreeObserver | |
init { | |
view.viewTreeObserver.addOnGlobalLayoutListener(this) | |
view.addOnAttachStateChangeListener(this) | |
} |
This file contains 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
class CancellableDelayedTask { | |
var cancelled = false | |
func run(delay: Double, task: () -> Void ) { | |
let time = dispatch_time(DISPATCH_TIME_NOW, Int64(delay)) | |
dispatch_after(time, dispatch_get_main_queue()) { [unowned self] () -> Void in | |
if !self.cancelled { | |
task() | |
} | |
} | |
} |
This file contains 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 LocaleTimePicker extends TimePicker { | |
public LocaleTimePicker(Context context) { | |
this(context, null); | |
} | |
public LocaleTimePicker(Context context, @Nullable AttributeSet attrs) { | |
this(context, attrs, Resources.getSystem().getIdentifier("timePickerStyle", "attr", "android")); | |
} |
This file contains 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
val popup = PopupWindow(...) | |
val container = popup.contentView.takeIf { it.layoutParams is WindowManager.LayoutParams } | |
?: (popup.contentView.parent as? View)?.takeIf { it.layoutParams is WindowManager.LayoutParams } | |
?: (popup.contentView.parent.parent as? View)?.takeIf { it.layoutParams is WindowManager.LayoutParams } | |
?: throw IllegalStateException("NO WindowManager.LayoutParams!") | |
val wm = context.getSystemService(Context.WINDOW_SERVICE) as WindowManager | |
val lp = container.layoutParams as WindowManager.LayoutParams | |
lp.flags = lp.flags or WindowManager.LayoutParams.FLAG_DIM_BEHIND |
This file contains 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
interface Array<T> { | |
flatMap<E>(callback: (t: T) => Array<E>): Array<E> | |
} | |
Object.defineProperty(Array.prototype, 'flatMap', { | |
value: function(f: Function) { | |
return this.reduce((ys: any, x: any) => { | |
return ys.concat(f.call(this, x)) | |
}, []) | |
}, |
This file contains 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
extension PrimitiveSequenceType where Self: ObservableConvertibleType, Self.TraitType == SingleTrait { | |
func flatMapCompletable(_ selector: @escaping (E) -> Completable) -> Completable { | |
return self | |
.asObservable() | |
.flatMap { e -> Observable<Never> in | |
selector(e).asObservable() | |
} | |
.asCompletable() | |
} |
This file contains 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
fun <T, R> Observable<T>.mapNotNull(mapper: (T) -> R?): Observable<R> { | |
return lift { observer -> | |
object: Observer<T> { | |
override fun onNext(t: T) { | |
mapper(t)?.let { observer.onNext(it) } | |
} | |
override fun onComplete() { | |
observer.onComplete() | |
} | |
override fun onError(e: Throwable) { |
This file contains 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 io.reactivex.Flowable | |
import io.reactivex.Maybe | |
import io.reactivex.Observable | |
import io.reactivex.Single | |
import io.reactivex.rxkotlin.Flowables | |
import io.reactivex.rxkotlin.Maybes | |
import io.reactivex.rxkotlin.Observables | |
import io.reactivex.rxkotlin.Singles | |
fun <T> Observables.expand(source: Observable<T>, expander: (T) -> Observable<T>): Observable<T> { |
This file contains 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
fun <T> Collection<T>.combinations(n: Int): List<List<T>> { | |
return when { | |
n < 0 -> throw Error("combinations size cannot be negative") | |
n > size -> emptyList() | |
n == 1 -> map { mutableListOf(it) } | |
else -> foldIndexed<T, List<List<T>>>(mutableListOf()) { index, all, first -> | |
all + drop(index + 1) | |
.combinations(n - 1) | |
.map { it + first } | |
} |