Skip to content

Instantly share code, notes, and snippets.

View yaraki's full-sized avatar
🏠
Working from home

Yuichi Araki yaraki

🏠
Working from home
View GitHub Profile
val sendIntent = Intent(Intent.ACTION_SEND)
.setType("text/plain")
.putExtra(Intent.EXTRA_TEXT, text)
val shareIntent = Intent.createChooser(sendIntent, null)
val customActions = arrayOf(
ChooserAction.Builder(
Icon.createWithResource(context, R.drawable.ic_send_to_devices),
"Send to your devices",
PendingIntent.getBroadcast(
context,
val sendIntent = Intent(Intent.ACTION_SEND)
.putExtra(Intent.EXTRA_TEXT, "This is my text to send.")
.setType("text/plain")
val shareIntent = Intent.createChooser(sendIntent, null)
context.startActivity(shareIntent)
@yaraki
yaraki / EdgeToEdge.kt
Last active July 3, 2024 19:48
Edge-to-edge setup for Android app in a backward-compatible manner.
/*
* Copyright (C) 2022 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
// Copyright 2022 Google LLC.
// SPDX-License-Identifier: Apache-2.0
@Composable
fun LifecycleEffect(event: Lifecycle.Event, action: () -> Unit) {
val lifecycleOwner = LocalLifecycleOwner.current
val observer = LifecycleEventObserver { _, e ->
if (event == e) {
action()
}
@yaraki
yaraki / Gap.kt
Created March 5, 2021 05:50
Common interface for Spacers in Column and Row
package com.example.android.codelab.animationdemo.ui
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.ColumnScope
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.RowScope
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.width
import androidx.compose.material.Text
@yaraki
yaraki / MainActivity.kt
Last active February 26, 2021 10:22
Just an idea
package com.example.android.codelab.animationdemo
import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.activity.compose.BackHandler
import androidx.activity.compose.setContent
import androidx.activity.viewModels
import androidx.compose.animation.Crossfade
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Box
package io.github.yaraki.miscex
import android.view.ViewGroup
import androidx.databinding.DataBindingUtil
import androidx.databinding.ViewDataBinding
import androidx.fragment.app.Fragment
import androidx.fragment.app.FragmentActivity
import androidx.lifecycle.Lifecycle
import androidx.lifecycle.LifecycleEventObserver
@yaraki
yaraki / CoroutineTest.kt
Created August 14, 2019 12:50
Channel vs. Flow
package com.example.playground
import com.google.common.truth.Truth.assertThat
import kotlinx.coroutines.channels.ReceiveChannel
import kotlinx.coroutines.channels.produce
import kotlinx.coroutines.channels.toList
import kotlinx.coroutines.flow.flow
import kotlinx.coroutines.flow.single
import kotlinx.coroutines.runBlocking
import kotlinx.coroutines.yield
@yaraki
yaraki / FlowTest.kt
Created August 8, 2019 07:07
Sleep sort
package com.example.android.flow
import com.google.common.truth.Truth.assertThat
import kotlinx.coroutines.async
import kotlinx.coroutines.awaitAll
import kotlinx.coroutines.delay
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.channelFlow
import kotlinx.coroutines.flow.toList
import kotlinx.coroutines.runBlocking
@yaraki
yaraki / FirestoreLiveData.kt
Created May 20, 2019 07:53
Firebase Query as LiveData
/**
* Copyright 2019 Google LLC.
* SPDX-License-Identifier: Apache-2.0
*/
package com.example.firestore
import android.util.Log
import androidx.lifecycle.LiveData
import com.google.firebase.firestore.*