Skip to content

Instantly share code, notes, and snippets.

@chrisbanes
chrisbanes / AndroidDrawablePainter.kt
Last active Apr 27, 2021
A prototype #JetpackCompose Painter which draws an Android Drawable
View AndroidDrawablePainter.kt
/*
* Copyright 2020 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
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
View Insets.txt
Moved to https://google.github.io/accompanist/insets/
@chrisbanes
chrisbanes / bash_aliases
Created Mar 30, 2020
Shell function to set default JDK to Android Studio's bundled JDK
View bash_aliases
function set-studio-jdk() {
export JAVA_HOME=$1/Contents/jre/jdk/Contents/home/
}
@chrisbanes
chrisbanes / themes.xml
Last active Apr 27, 2021
edge_to_edge_legacy_theme
View themes.xml
<!-- values/themes.xml -->
<style name="Theme.MyApp">
<item name="android:navigationBarColor">
#B3FFFFFF
</item>
</style>
<!-- values-night/themes.xml -->
<style name="Theme.MyApp">
<item name="android:navigationBarColor">
View ScopedViewModel.kt
open class ScopedViewModel : ViewModel() {
private val job = Job()
protected val scope: CoroutineScope = job + Dispatchers.Main
override fun onCleared() {
super.onCleared()
job.cancel()
}
}
@chrisbanes
chrisbanes / CoroutineLifecycleObserver.kt
Last active May 21, 2020
LifecycleObserver which allows easy cancelling of coroutines
View CoroutineLifecycleObserver.kt
/*
* Copyright 2018 Google LLC
*
* 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
@chrisbanes
chrisbanes / Animators.kt
Last active May 6, 2020
Material Image Loading treatment for Android
View Animators.kt
/*
* Copyright 2018 Google, Inc.
*
* 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
@chrisbanes
chrisbanes / code.kt
Last active May 10, 2021
Night Mode inflater
View code.kt
/*
* Copyright 2017 Google, Inc.
*
* 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
View FixAppBarLayoutBehavior.java
/*
* Copyright (C) 2017 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
@chrisbanes
chrisbanes / KotterKnife.kt
Last active Feb 7, 2021
LifecycleAware KotterKnife
View KotterKnife.kt
package kotterknife
import android.app.Activity
import android.app.Dialog
import android.app.DialogFragment
import android.app.Fragment
import android.arch.lifecycle.Lifecycle
import android.arch.lifecycle.LifecycleObserver
import android.arch.lifecycle.LifecycleOwner
import android.arch.lifecycle.OnLifecycleEvent