val firstName: String = "Luke"
val lastName = "Skywalker" // `String` type is inferred
val immutableInt = 20 // `val` is immutable
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 App: Application() { | |
companion object { | |
lateinit var database: MyDatabase | |
} | |
override fun onCreate() { | |
super.onCreate() | |
App.database = Room.databaseBuilder(this, MyDatabase::class.java, "my-database").build() | |
} | |
} |
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
Kotlin! (kotlinlang.org) | |
// Kotlin is... | |
// A Statically typed programming language | |
// for the JVM, | |
// Android | |
// and the browser |
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 Cacheable<T>(val key: String, val default: T, val valueSet: (value: T) -> Unit = {}) { | |
val type: Type = object : TypeToken<T>(){}.type | |
var value: T by Delegates.observable(default) { prop, old, new -> | |
new?.let { valueSet(it) } | |
} | |
operator fun getValue(thisRef: Any?, property: KProperty<*>): T { | |
if(value == null) { value = Cacher.getFromCache(key, default, type) } | |
return value ?: default |
Animator anim = ObjectAnimator.ofFloat(mainView, "translationY", 500.f);
anim.setInterpolator(new AccelerateDecelerateInterpolator());
anim.setDuration(300);
anim.setStartDelay(100);
Animator anim1 = ObjectAnimator.ofFloat(otherView, "translationY", 200.f);
anim1.setInterpolator(new AccelerateDecelerateInterpolator());
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 snapshot = try { | |
cache[key] ?: return null | |
} catch (e: IOException) { | |
// Give up because the cache cannot be read. | |
return null | |
} |
NewerOlder