Skip to content

Instantly share code, notes, and snippets.

View alexstyl's full-sized avatar

Alex Styl alexstyl

View GitHub Profile
package com.composables.composetheme.samples
import androidx.compose.foundation.background
import androidx.compose.foundation.clickable
import androidx.compose.foundation.gestures.Orientation
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.fillMaxSize
<script type="text/javascript" src="https://project-reviews.vercel.app/js/iframeResizer.min.js"></script>
<iframe id="appreviews-iframe" src="https://project-reviews.vercel.app/iframe?id=1" frameBorder="0" scrolling="no" width="100%"></iframe>
<script type="text/javascript">iFrameResize({log: false, checkOrigin: false}, "#appreviews-iframe");</script>
@alexstyl
alexstyl / MainActivity.kt
Created May 19, 2023 13:39 — forked from amarland/SvgDsl.kt
A (very) minimal SVG DSL for Jetpack Compose on Android (inspired by https://twitter.com/alexstyl/status/1659043650238844928).
package com.amarland.simplesvgdsl
import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.darkColorScheme
@alexstyl
alexstyl / MaterialColors.kt
Created May 15, 2023 10:05
All colors found in the 2014 Material Design color palette, ready to be used in Jetpack Compose.
/**
* Contains all color defined in the 2014 Material Design color palette.
*
*
*/
object MaterialColors {
val Red50 = Color(0xFFFFEBEE)
val Red100 = Color(0xFFFFCDD2)
val Red200 = Color(0xFFEF9A9A)
val Red300 = Color(0xFFE57373)
@alexstyl
alexstyl / AutoCompleteTextComposable.kt
Created November 13, 2022 04:43
A quick and dirty way to do AutoCompleteTextViews in Jetpack Compose. Needs improvement in the UX (hide cursor when item selected) and nicer API and probably more.
var selectedOptionText by remember { mutableStateOf("") }
val options = listOf("Cupcake", "Donut", "Eclair", "Froyo", "Gingerbread")
val filtered = options
.filter { it.lowercase().contains(selectedOptionText.lowercase()) }
val expanded = selectedOptionText.isNotEmpty() && filtered.isNotEmpty()
&& options.none { it.lowercase() == selectedOptionText.lowercase() }
ExposedDropdownMenuBox(
expanded = expanded,
@alexstyl
alexstyl / MachineId.kt
Last active November 3, 2022 14:19
Get MacOS Machine ID
// Java version of node-machine-id. Used to identify a Mac, for software installation or licenses purposes.
// See the node project at https://github.com/automation-stack/node-machine-id
suspend fun machineId(): String {
val platformUUID = getPlatformUUID()
return DigestUtils.sha256Hex(platformUUID)
}
private fun expose(result: String): String {
val startIndex = result.substringAfter("IOPlatformUUID").substringBefore("\n")
@alexstyl
alexstyl / SafeContent.kt
Last active May 5, 2022 07:33
A Composable that will keep push its content so that they are not drawn behind the system bars. This is useful for when you want to work on a layout without having to worry about insets.
@Composable
fun SafeContent(
systemBarsColor: Color = Color(0xFF082A3A),
content: @Composable () -> Unit
) {
Box(
modifier = Modifier
.background(systemBarsColor)
.systemBarsPadding()
.background(MaterialTheme.colors.background)
// instead of a LinearLayout (horizontal) use:
Row {
Text("Main Header")
Spacer(Modifier.weight(1f))
Text("23 mins ago")
}
// instead of FrameLayout use:
Box {
@alexstyl
alexstyl / ConversationItem.kt
Created March 21, 2022 13:55
Code sample for composables.co
@Composable
fun ConversationItem(
modifier: Modifier = Modifier,
onClick: () -> Unit,
title: String,
snippet: String,
unread: Boolean = false,
timestamp: String,
profilePainters: List<Painter>,
) {
@alexstyl
alexstyl / CommonIntents.kt
Created February 23, 2022 19:15
Factory functions for common Intents in Android such as starting a call or sending an e-mail
import android.content.Intent
import android.net.Uri
import android.provider.CalendarContract
import android.provider.Settings
import java.util.Calendar
fun sendTextMessage(phoneNumber: String): Intent {
return Intent(
Intent.ACTION_SENDTO,
smrUri(phoneNumber)