Skip to content

Instantly share code, notes, and snippets.

@Razhan
Razhan / ViewPropertyAnimator start
Created December 1, 2015 08:57
ViewPropertyAnimator start
public void start ()
Starts the currently pending property animations immediately. Calling start() is optional because all animations start automatically at the next opportunity. However, if the animations are needed to start immediately and synchronously (not at the time when the next event is processed by the hierarchy, which is when the animations would begin otherwise), then this method can be used.
Source
The only difference is that with start it starts immediately.
@Razhan
Razhan / ActivityLifecycle.md
Created April 9, 2016 03:20 — forked from kristopherjohnson/ActivityLifecycle.md
Notes about Android Activity lifecycle method ordering

Results of some experiments to determine which Activity lifecycle methods get called in certain situations.

Scenario: Launch app from home, then return home

Launch:

  • activity.onCreate()
  • activity.onStart()
  • activity.onResume()
  • activity.onWindowFocusChanged(true)
@Razhan
Razhan / DataBindingHelper.java
Created December 20, 2018 10:05 — forked from yhirano/DataBindingHelper.java
My DataBindingHelper for Android.
package your.project.view.helper;
import android.databinding.BindingAdapter;
import android.graphics.drawable.Drawable;
import android.support.annotation.ColorInt;
import android.support.annotation.DrawableRes;
import android.support.annotation.Nullable;
import android.support.v4.content.ContextCompat;
import android.support.v4.widget.SwipeRefreshLayout;
import android.text.TextUtils;
@Keep
internal class LoggingHandler : AbstractCoroutineContextElement(CoroutineExceptionHandler),
CoroutineExceptionHandler {
override fun handleException(context: CoroutineContext, exception: Throwable) {
Crashlytics.logException(exception)
// Since we don't want to crash and Coroutines will call the current thread's handler, we
// install a noop handler and then reinstall the existing one once coroutines calls the new
// handler.
Thread.currentThread().apply {
public suspend inline fun <T : Closeable?, R> T.useCancellably(
crossinline block: (T) -> R
): R = suspendCancellableCoroutine { cont ->
cont.invokeOnCancellation { this?.close() }
cont.resume(use(block))
}
@Razhan
Razhan / Async.kt
Created December 21, 2018 06:24 — forked from SUPERCILEX/Async.kt
Google Play Services Tasks API with Kotlin Coroutines support
suspend fun <T> Task<T>.await(): T {
if (isComplete) return if (isSuccessful) result else throw exception!!
return suspendCoroutine { c: Continuation<T> ->
addOnSuccessListener { c.resume(it) }
addOnFailureListener { c.resumeWithException(it) }
}
}
fun <T> Deferred<T>.asTask(): Task<T> {
val source = TaskCompletionSource<T>()
@Razhan
Razhan / txt
Created December 25, 2018 11:01
中央六套1080p版本,有图标(不喜勿下)
辽沈战役
magnet:?xt=urn:btih:44B9E52EB7C80F2C86301E37EC3D3D4EC5A6D70E&dn=%E5%A4%A7%E5%86%B3%E6%88%98%20-%20%E8%BE%BD%E6%B2%88%E6%88%98%E5%BD%B9.1990.1080p.mkv
平津战役
magnet:?xt=urn:btih:7B7BA58AC94A1172402935266BBF226B4F270769&dn=%E5%A4%A7%E5%86%B3%E6%88%98%EF%BC%8D%E5%B9%B3%E6%B4%A5%E6%88%98%E5%BD%B9.1992.1080p.mkv
淮海战役
magnet:?xt=urn:btih:DA1B57C4E3F2ADE990282C813EFF0923AC04EDF7&dn=%E5%A4%A7%E5%86%B3%E6%88%98%EF%BC%8D%E6%B7%AE%E6%B5%B7%E6%88%98%E5%BD%B9.1991.1080p.mkv
@Razhan
Razhan / build.gradle
Created April 4, 2019 07:38 — forked from KenVanHoeylandt/build.gradle
Gradle auto-installing pre-commit hook
apply from: rootProject.file('gradle/install-git-hooks.gradle')
@Razhan
Razhan / Promise.kt
Created July 15, 2019 11:47 — forked from exallium/Promise.kt
Quick and dirty Promise in Kotlin
sealed class Either<out L, out R> {
data class Left<out L>(val l: L) : Either<L, Nothing>()
data class Right<out R>(val r: R) : Either<Nothing, R>()
}
fun asdf() {
val p = Promise<Int> { resolve, reject ->
resolve(Either.Left(4))
}
class MenuViewModel {
val coffeeList: LiveData<List<Coffee>> = liveData(context = viewModelScope.coroutineContext + Dispatchers.IO) {
// if the data needs to be processed before displaying,
// this is where I usually do it
menuRepo.menu.collect(::emit)
}
}
class MenuRepository {
private val menuChannel = BroadcastChannel<List<Coffee>>(CONFLATED)