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 android.Manifest | |
import android.content.Context | |
import android.content.pm.PackageManager | |
import android.net.ConnectivityManager | |
import android.net.Network | |
import android.net.NetworkCapabilities | |
import android.net.NetworkRequest | |
import android.os.Build | |
import android.support.annotation.RequiresApi | |
import android.support.v4.content.ContextCompat |
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 android.os.Handler | |
fun <T> debounced(initialValue: T, debounceMs: Long = 500L): Debounced<T> { | |
return AndroidDebounced(initialValue, debounceMs) | |
} | |
private class AndroidDebounced<T>(initialValue: T, private val debounceMs: Long) : Debounced<T> { | |
private val handler = Handler() | |
private var _value: T = initialValue |
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
/* | |
* Copyright (C) 2006 The Android Open Source Project | |
* | |
* Licensed under the Apache License, Version 2.0 (the "License"); | |
* you may not use this file except in compliance with the License. | |
* You may obtain a copy of the License at | |
* | |
* http://www.apache.org/licenses/LICENSE-2.0 | |
* | |
* Unless required by applicable law or agreed to in writing, software |
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
private abstract class CenterVerticalDrawableSpan : ReplacementSpan() { | |
abstract fun getDrawable(): Drawable? | |
private var drawableRef: WeakReference<Drawable>? = null | |
private val cachedDrawable: Drawable? | |
get() = drawableRef?.get() ?: getDrawable()?.also { drawableRef = WeakReference(it) } | |
override fun getSize(paint: Paint, text: CharSequence, |
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 View.afterLayout(block: View.() -> Unit) { | |
val originalVto = viewTreeObserver | |
originalVto.addOnPreDrawListener(object : ViewTreeObserver.OnPreDrawListener { | |
override fun onPreDraw(): Boolean { | |
if (originalVto.isAlive) originalVto.removeOnPreDrawListener(this) | |
viewTreeObserver.removeOnPreDrawListener(this) | |
block(this@afterLayout) | |
return true | |
} | |
}) |
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
@file:Suppress("RedundantVisibilityModifier", "NOTHING_TO_INLINE") | |
import kotlin.reflect.KProperty | |
public interface LazyMutable<T> { | |
public var value: T | |
public fun isInitialized(): Boolean | |
} | |
public inline operator fun <T> LazyMutable<T>.getValue(thisRef: Any?, property: KProperty<*>): 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
apply plugin: 'com.android.application' | |
apply plugin: 'kotlin-android' | |
apply plugin: 'kotlin-android-extensions' | |
android { | |
compileSdkVersion 25 | |
buildToolsVersion "25.0.2" | |
defaultConfig { | |
applicationId "com.example.kxt" | |
minSdkVersion 15 |
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 android.graphics.Bitmap; | |
import android.graphics.BitmapShader; | |
import android.graphics.Canvas; | |
import android.graphics.Matrix; | |
import android.graphics.Paint; | |
import android.graphics.Shader; | |
import com.squareup.picasso.Transformation; | |
public class CircleTransformation implements Transformation { |
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 java.io.BufferedInputStream; | |
import java.io.DataInputStream; | |
import java.io.IOException; | |
import java.io.InputStream; | |
import java.nio.Buffer; | |
import java.nio.ByteBuffer; | |
import java.nio.ByteOrder; | |
import java.nio.FloatBuffer; | |
import java.nio.ShortBuffer; | |
import java.util.ArrayList; |
NewerOlder