Answer: The primary constructor is part of the class header. Unlike Java, you don't need to declare a constructor in the body of the class. Here's an example:
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
@Composable | |
fun InteractiveCanvas(maxWidth: Int, maxHeight: Int) { | |
val random = remember { Random.Default } | |
var touchPosition by remember { mutableStateOf(Offset.Unspecified) } | |
val heartSize = 75F | |
val heartPath = createHeartPath(heartSize) | |
val heartOffsets = remember { mutableStateListOf<Offset>() } | |
val heartColors = remember { mutableStateListOf<Color>() } | |
if (heartOffsets.isEmpty()) { |
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 androidx.compose.runtime.Composable | |
import androidx.compose.runtime.DisposableEffect | |
import androidx.compose.runtime.remember | |
import androidx.compose.runtime.snapshots.MutableSnapshot | |
import androidx.compose.runtime.snapshots.Snapshot | |
import java.util.WeakHashMap | |
@PublishedApi | |
internal class DebugStateObservation(private val id: String) { | |
private val map = WeakHashMap<Any, MutableList<Exception>>() |
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
@Composable | |
actual fun PlatformColors(statusBarColor: Color, navBarColor: Color){ | |
val sysUiController = rememberSystemUiController() | |
SideEffect { | |
sysUiController.setSystemBarsColor(color = topColor) | |
sysUiController.setNavigationBarColor(color = bottomColor) | |
} | |
} |
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
/** | |
* A composable function that displays a text with a typewriter-like effect, revealing characters in chunks. | |
* | |
* @param text The input text to be displayed with the typewriter effect. | |
* @param minDelayInMillis The minimum delay in milliseconds between revealing character chunks, defaults to 10ms. | |
* @param maxDelayInMillis The maximum delay in milliseconds between revealing character chunks, defaults to 50ms. | |
* @param minCharacterChunk The minimum number of characters to reveal at once, defaults to 1. | |
* @param maxCharacterChunk The maximum number of characters to reveal at once, defaults to 5. | |
* @param onEffectCompleted A callback function invoked when the entire text has been revealed. | |
* @param displayTextComposable A composable function that receives the text to display with the typewriter effect. |
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 androidx.compose.foundation.Canvas | |
import androidx.compose.foundation.layout.fillMaxSize | |
import androidx.compose.runtime.Composable | |
import androidx.compose.ui.Modifier | |
import androidx.compose.ui.geometry.Offset | |
import androidx.compose.ui.geometry.Size | |
import androidx.compose.ui.graphics.Color | |
import androidx.compose.ui.graphics.drawscope.DrawScope | |
import androidx.compose.ui.graphics.drawscope.translate | |
import androidx.compose.ui.tooling.preview.Preview |
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
#!/usr/bin/env bash | |
# I've found that the "Migrate to AndroidX" converter in Android Studio doesn't work very | |
# well, so I wrote my own script to do the simple job of converting package names. | |
# | |
# You can download a CSV of package names here: https://developer.android.com/topic/libraries/support-library/downloads/androidx-class-mapping.csv | |
# | |
# It'll run faster on a clean build because then there are fewer files to scan over. | |
# | |
# Uses `gsed` because I'm on a Mac. Can easily replace with `sed` if you don't have `gsed`. |
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
package fi.iki.asb.android.logo; | |
/* | |
* THIS CLASS IS PROVIDED TO THE PUBLIC DOMAIN FOR FREE WITHOUT ANY | |
* RESTRICTIONS OR ANY WARRANTY. | |
*/ | |
import java.util.LinkedList; | |
import android.content.SharedPreferences; |