Skip to content

Instantly share code, notes, and snippets.

@tfaki
tfaki / docsify-embed-gist.md
Created May 8, 2023 14:50 — forked from MichaelCurrin/docsify-embed-gist.md
Docsify - embed a gist that stays update to date
task sayDone {
doLast {
exec {
commandLine 'say', 'Ilk Turda Bitirelim'
}
}
}
task("sayDone") {
doLast {
exec {
commandLine("say", "Ilk Turda Bitirelim")
}
}
}
@tfaki
tfaki / WithThenBlock
Created March 30, 2023 20:49
Modifier Then Block
@Composable
fun WithThenBlock() {
var isExpanded by remember {
mutableStateOf(true)
}
Box(
modifier = Modifier
.height(50.dp)
.then(
@tfaki
tfaki / WithRunBlock
Created March 30, 2023 20:48
Modifier Run Block
@Composable
fun WithRunBlock() {
var isExpanded by remember {
mutableStateOf(true)
}
Box(
modifier = Modifier
.height(50.dp)
.run {
@Composable
fun CardItem() {
Card(
modifier = Modifier
.fillMaxWidth()
.height(100.dp)
.padding(horizontal = 16.dp, vertical = 8.dp),
colors = CardDefaults.cardColors(containerColor = MaterialTheme.colorScheme.primary)
) {
@Composable
fun YourTheme(darkTheme: Boolean = isSystemInDarkTheme(), content: @Composable () -> Unit) {
val dynamicColor = Build.VERSION.SDK_INT >= Build.VERSION_CODES.S
val colors = if (dynamicColor) {
val context = LocalContext.current
if (darkTheme) dynamicDarkColorScheme(context) else dynamicLightColorScheme(context)
} else {
if (darkTheme) DarkColorPalette else LightColorPalette
}
override fun onPictureInPictureModeChanged(
isInPictureInPictureMode: Boolean,
newConfig: Configuration?
) {
super.onPictureInPictureModeChanged(isInPictureInPictureMode, newConfig)
if (isInPictureInPictureMode){
Log.d(TAG, "onPictureInPictureModeChanged: Entered PIP")
pipButton.visibility = View.GONE
}
else{
override fun onUserLeaveHint() {
super.onUserLeaveHint()
//when user presses home button, if not in PIP mode, enter in PIP, requires Android N and above
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N){
Log.d(TAG, "onUserLeaveHint: was not in PIP")
pictureInPictureMode()
}
else{
Log.d(TAG, "onUserLeaveHint: Already in PIP")
}
private fun pictureInPictureMode(){
//Requires Android O and higher
Log.d(TAG, "pictureInPictureMode: Try to enter in PIP mode")
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O){
Log.d(TAG, "pictureInPictureMode: Supports PIP")
//setup PIP height width
val aspectRatio = Rational(videoView.width, videoView.height)
pictureInPictureParamsBuilder!!.setAspectRatio(aspectRatio).build()
enterPictureInPictureMode(pictureInPictureParamsBuilder!!.build())
}