Skip to content

Instantly share code, notes, and snippets.

@vashisthg
vashisthg / TryDebounce.kt
Last active March 14, 2019 21:13
Trying coroutine. Kind of debounce.
import kotlinx.coroutines.*
/*
* Trying learning couroutine. Investigating for getting debounce effect.
* Some inspiration from https://medium.com/@pro100svitlo/edittext-debounce-with-kotlin-coroutines-fd134d54f4e9
*/
fun main() {
val list = listOf(1, 2, 3, 4, 5)
var time = java.util.Calendar.getInstance().timeInMillis
for (i in list) {
@vashisthg
vashisthg / script.sh
Last active November 21, 2018 17:18 — forked from dlew/script.sh
Simple AndroidX Migration Script
#!/usr/bin/env bash
# I've found that the "Migrate to AndroidX" converter in Android Studio doesn't work very
# well, so I wrote my own script to do the simple job of converting package names.
#
# You can download a CSV of package names here: https://developer.android.com/topic/libraries/support-library/downloads/androidx-class-mapping.csv
#
# It'll run faster on a clean build because then there are fewer files to scan over.
#
# Uses `gsed` because I'm on a Mac. Can easily replace with `sed` if you don't have `gsed`.
androidExtensions {
configure(delegateClosureOf<AndroidExtensionsExtension> {
isExperimental = true
})
}
@vashisthg
vashisthg / CropView.java
Created July 26, 2018 13:27
Sample code to see issues with Xfermode on Android P beta
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.Path;
import android.graphics.PorterDuff;
import android.graphics.PorterDuffXfermode;
import android.os.Build;
import android.util.AttributeSet;
import android.view.View;
@vashisthg
vashisthg / CropView.java
Created July 26, 2018 13:27
Issue with Xfermode in Android P beta
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.Path;
import android.graphics.PorterDuff;
import android.graphics.PorterDuffXfermode;
import android.os.Build;
import android.util.AttributeSet;
import android.view.View;
dependencies {
implementation(fileTree(mapOf("dir" to "libs", "include" to listOf("*.jar"))))
implementation(Libraries.Kotlin.stdlib)
implementation(Libraries.Support.appcompatV7)
testImplementation(Libraries.Tests.junit)
androidTestImplementation(Libraries.AndroidTests.testRunner)
androidTestImplementation(Libraries.AndroidTests.espressoCore)
}
object Libraries {
object Kotlin {
val stdlib = "org.jetbrains.kotlin:kotlin-stdlib-jdk7:${Versions.kotlinVersion}"
}
object Support {
val appcompatV7 = "com.android.support:appcompat-v7:28.0.0-alpha3"
}
object Tests {
object Libraries {
object Kotlin {
val stdlib = "org.jetbrains.kotlin:kotlin-stdlib-jdk7:${Versions.kotlinVersion}"
}
object Support {
val appcompatV7 = "com.android.support:appcompat-v7:28.0.0-alpha3"
}
object Tests {
buildTypes {
getByName("release") {
isMinifyEnabled = false
proguardFiles(getDefaultProguardFile("proguard-android.txt"), file("proguard-rules.pro"))
}
}
plugins {
id("com.android.application")
kotlin("android") // or id("kotlin-android")
id("kotlin-android-extensions")
}