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
/* | |
Copyright (c) 2013 toshihiro yagi | |
Permission is hereby granted, free of charge, to any person obtaining a copy | |
of this software and associated documentation files (the "Software"), to deal | |
in the Software without restriction, including without limitation the rights | |
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | |
copies of the Software, and to permit persons to whom the Software is | |
furnished to do so, subject to the following conditions: |
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
// in Activity | |
override fun onCreate(savedInstanceState: Bundle?) { | |
super.onCreate(savedInstanceState) | |
lifecycleScope.launchWhenCreated { | |
editNickName.textChangeAsFlow() | |
.map { it?.isNotEmpty() ?: false } | |
.collect { | |
sendButton.isEnabled = it | |
} | |
} |
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
// deprecatedだけど新しいのは API 23からなので仕方ない | |
val intent = AccountManager.newChooseAccountIntent( | |
null, | |
null, | |
arrayOf("com.google"), | |
true, | |
null, | |
null, | |
null, | |
null |
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
fun delay(delayTime: Long, stateMachine: StateMachine) { | |
Thread.sleep(delayTime) | |
stateMachine.resume() | |
} | |
class StateMachine { | |
var state = 0 | |
var start = 0L | |
fun resume() { | |
when (state) { |
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
import android.app.IntentService | |
import android.content.Context | |
import android.content.Intent | |
import android.os.Bundle | |
import androidx.work.Data | |
import androidx.work.OneTimeWorkRequest | |
import androidx.work.WorkManager | |
import androidx.work.Worker |
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
import android.text.Editable | |
import android.text.TextWatcher | |
import android.widget.EditText | |
import kotlinx.coroutines.experimental.channels.Channel | |
import kotlinx.coroutines.experimental.channels.ReceiveChannel | |
import kotlinx.coroutines.experimental.channels.sendBlocking | |
import kotlinx.coroutines.experimental.launch | |
object EditTextChannel { | |
fun empty(editText: EditText): ReceiveChannel<Boolean> = ConflatedChannel<Boolean>().apply { |
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 StateLiveData<T> : MutableLiveData<T>() { | |
override fun onInactive() { | |
super.onInactive() | |
value = null | |
} | |
} |
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 Value(val value: Int, var output: String = "") | |
fun rule(seed: Int, print: String, next: SendChannel<Value>) = actor<Value> { | |
for (value in channel) { | |
next.send(value.apply { | |
if (value.value % seed == 0) { | |
this.output += print | |
} | |
}) | |
} |
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
fun shouldOpenShop(shopId: Long): Boolean { | |
if( shopId <= 0L ){ | |
return false | |
} | |
if( this.shop == null ) { | |
return false | |
} | |
if( this.shop.id == shopId ) { // これを return this.shop.id == shopId にしろって言われる | |
return false | |
} |
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
fun <T> async(context: CoroutineContext = CommonPool, start: CoroutineStart = CoroutineStart.DEFAULT, block: suspend CoroutineScope.() -> T) | |
= kotlinx.coroutines.experimental.async(context, start, block) | |
fun ui(start: CoroutineStart = CoroutineStart.DEFAULT, block: suspend CoroutineScope.() -> Unit) | |
= launch(UI, start, block) | |
suspend fun <T, U> parallel(c1: suspend CoroutineScope.() -> T, c2: suspend CoroutineScope.() -> U): Pair<T, U> { | |
val c1Job = async(block = c1) | |
val c2Job = async(block = c2) | |
return Pair(c1Job.await(), c2Job.await()) |
NewerOlder