Skip to content

Instantly share code, notes, and snippets.

View STAR-ZERO's full-sized avatar

Kenji Abe STAR-ZERO

View GitHub Profile
@STAR-ZERO
STAR-ZERO / MainActivity.kt
Created July 1, 2021 01:31
androidx.core:core-splashscreen の雑サンプル
class MainActivity : AppCompatActivity() {
private val viewModel: MainViewModel by viewModels()
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
val splashScreen = installSplashScreen() // ★ SplashScreenを適用
setContentView(R.layout.activity_main)
splashScreen.setKeepVisibleCondition {  // ★ ここでtrueを返してる間はSplashScreenが表示されたまま
@STAR-ZERO
STAR-ZERO / ConcatAdapterExtension.kt
Created October 15, 2020 08:47
Find an adapter from ConcatAdapter global position.
fun ConcatAdapter.findAdapter(position: Int): RecyclerView.Adapter<*>? {
var totalCount = 0
adapters.forEach { adapter ->
totalCount += adapter.itemCount
if (position < totalCount) {
return adapter
}
}
return null
}
@STAR-ZERO
STAR-ZERO / bundletool
Created May 14, 2018 05:50
shell script for bundletool
#!/bin/sh
dir=$(dirname $0)
java -jar "$dir/bundletool-all-0.3.3.jar" $@
@STAR-ZERO
STAR-ZERO / build.gradle
Last active May 2, 2018 06:40
support libraryのバージョンコンフリクト対応
def supportLibraryVersion = '27.1.1'
android {
// ...
defaultConfig {
// ...
multiDexEnabled true
}
@STAR-ZERO
STAR-ZERO / build.gradle
Created April 11, 2018 16:09
WARNING: Configuration 'compile' is obsolete and has been replaced with 'implementation'. の警告で compile を使ってるライブラリを探すGradleタスク
task searchCompileDependencies() {
doLast {
configurations.find { it.name == 'compile' }?.dependencies?.each {
println "$it.group:$it.name"
}
}
}
@STAR-ZERO
STAR-ZERO / activity_main.xml
Created March 8, 2018 05:28
BottomAppBarのサンプル
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_anchor="@id/toolbar"
tools:context=".MainActivity">
<android.support.design.widget.AppBarLayout
def robolectricDependenciesFolder = project.rootDir.path + "/.robolectric-dependencies"
configurations.create('robolectricRuntime')
dependencies {
robolectricRuntime "org.robolectric:android-all:o-preview-4-robolectric-0"
}
rootProject.task(type: Copy, overwrite: true, "downloadRobolectricDependencies") {
from configurations.robolectricRuntime
@STAR-ZERO
STAR-ZERO / AsyncLiveData.kt
Created June 19, 2017 03:00
LiveData + Kotlin Coroutine
// compile "org.jetbrains.kotlinx:kotlinx-coroutines-android:0.16"
// compile "android.arch.lifecycle:runtime:1.0.0-alpha3"
// compile "android.arch.lifecycle:extensions:1.0.0-alpha3"
// kapt "android.arch.lifecycle:compiler:1.0.0-alpha3"
class AsyncLiveData<T> private constructor(private val exec: suspend () -> T) : LiveData<T>() {
private var observer: Observer<T>? = null
private var job: Job? = null
@STAR-ZERO
STAR-ZERO / for-in.swift
Created July 7, 2016 03:42
Swiftでfor inに対応させる
class Test: SequenceType {
typealias Generator = IndexingGenerator<[String]>
func generate() -> Generator {
return ["A", "B", "C"].generate()
}
}
let test = Test()
for t in test {
@STAR-ZERO
STAR-ZERO / hoge.swift
Created June 10, 2016 03:32
もっと良い書き方無いかな?
func foo() -> String? {
return nil
}
let hoge: String
if let t = foo() {
// nilじゃなければ、その値を使いたい
hoge = t
} else {
// nilだったらデフォルト設定したい