### Install Common Library Dependencies (Kotlin)
Source: https://context7.com/evowizz/common/llms.txt
Add the Common library artifacts to your project's Gradle build file. This example shows how to include the core, hashing, and mosaic modules.
```kotlin
dependencies {
implementation("dev.evowizz.common:core:3.0.0")
implementation("dev.evowizz.common:hashing:3.0.0")
implementation("dev.evowizz.common:mosaic:3.0.0") // Requires Jetpack Compose
}
```
--------------------------------
### String and ByteArray Hashing in Kotlin
Source: https://github.com/evowizz/common/blob/main/README.md
Provides examples of using the Hashing utility to generate MD5 and SHA1 hashes for both String and ByteArray inputs. This module is useful for data integrity checks and security-related operations.
```kotlin
Hashing.hash("Hello World!", Algorithm.MD5)
Hashing.hash("foo bar".toByteArray(), Algorithm.SHA1)
```
--------------------------------
### Providing Mosaic Instance with MosaicProvider in Kotlin
Source: https://context7.com/evowizz/common/llms.txt
Explains how to use MosaicProvider and LocalMosaic to supply a Mosaic instance throughout a Compose UI hierarchy. This ensures consistent styling and efficient resource management by providing a single instance accessible via CompositionLocal.
```kotlin
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import dev.evowizz.common.mosaic.LocalMosaic
import dev.evowizz.common.mosaic.MosaicProvider
import dev.evowizz.common.mosaic.MosaicStyles
@Composable
fun AppWithMosaic() {
// Provide custom Mosaic instance to entire subtree
val appStyles = MosaicStyles(
bold = SpanStyle(fontWeight = FontWeight.SemiBold),
italic = MosaicStyles.Default.italic,
link = TextLinkStyles(
style = SpanStyle(
color = MaterialTheme.colorScheme.primary,
textDecoration = TextDecoration.Underline
)
)
)
MosaicProvider(styles = appStyles) {
// All children can access the same Mosaic instance
ContentScreen()
}
}
@Composable
fun ContentScreen() {
// Access the provided Mosaic instance
val mosaic = LocalMosaic.current
Column {
Text(text = mosaic.parse("**Welcome** to the app!"))
Text(text = mosaic.parse("Read our [Terms](https://example.com/terms)"))
Text(text = mosaic.parse("Contact __support__ for help."))
}
}
```
--------------------------------
### Core Android Utilities in Kotlin
Source: https://github.com/evowizz/common/blob/main/README.md
Demonstrates the usage of core utilities like ApplicationContext, AndroidVersion checks, SystemProperties retrieval, and NavigationBar mode detection. These tools simplify access to common Android system features and information.
```kotlin
// ApplicationContext
val context = ApplicationContext.get()
// AndroidVersion
if (!AndroidVersion.isAtLeastT()) Log.d(TAG, "Who doesn't like Tiramisu?")
AndroidVersion.whenAtLeast(Build.VERSION_CODES.CUR_DEVELOPMENT) { Log.d(TAG, "Uhoh... Work in progress!") }
// SystemProperties
SystemProperties.getOrNull("ro.build.version.release")
SystemProperties.getOrThrow("ro.build.version.release")
SystemProperties.getOrElse("ro.build.version.release", Build.UNKNOWN)
// NavigationBar
val isGestural = NavigationBar.getMode(context) == NavigationBarMode.MODE_GESTURAL
```
--------------------------------
### Access Global Application Context (Kotlin)
Source: https://context7.com/evowizz/common/llms.txt
Utilize the ApplicationContext.get() method to obtain a global reference to the application context. This is automatically initialized via AndroidX Startup, simplifying context access throughout your application.
```kotlin
import dev.evowizz.common.init.ApplicationContext
// Access application context anywhere in your app
val context = ApplicationContext.get()
// Use it to access resources, preferences, etc.
val appName = context.getString(R.string.app_name)
val sharedPrefs = context.getSharedPreferences("my_prefs", Context.MODE_PRIVATE)
```
--------------------------------
### Gradle Dependencies for Evowizz Common Libraries
Source: https://github.com/evowizz/common/blob/main/README.md
Add these lines to your build.gradle or build.gradle.kts file to include the core, hashing, and mosaic libraries from Evowizz Common. Ensure you replace '$version' with the latest version number.
```kotlin
implementation("dev.evowizz.common:core:$version")
implementation("dev.evowizz.common:hashing:$version")
implementation("dev.evowizz.common:mosaic:$version")
```
```gradle
implementation 'dev.evowizz.common:core:$version'
implementation 'dev.evowizz.common:hashing:$version'
implementation 'dev.evowizz.common:mosaic:$version'
```
--------------------------------
### Customizing Mosaic Text Styles in Kotlin
Source: https://context7.com/evowizz/common/llms.txt
Demonstrates how to create and apply custom styles for bold, italic, and link text within the Mosaic component. It shows the creation of a MosaicStyles object with specific SpanStyle and TextLinkStyles, and then uses it to parse and render styled text.
```kotlin
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.text.SpanStyle
import androidx.compose.ui.text.TextLinkStyles
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.text.style.TextDecoration
import dev.evowizz.common.mosaic.Mosaic
import dev.evowizz.common.mosaic.MosaicStyles
@Composable
fun CustomStyledText() {
// Create custom styles
val customStyles = MosaicStyles(
bold = SpanStyle(
fontWeight = FontWeight.ExtraBold,
color = Color.Blue
),
italic = SpanStyle(
fontStyle = FontStyle.Italic,
color = Color.Gray
),
link = TextLinkStyles(
style = SpanStyle(
color = Color.Magenta,
textDecoration = TextDecoration.Underline
)
)
)
// Parse with custom styles
val mosaic = Mosaic(customStyles)
val styledText = mosaic.parse("**Important** info with __emphasis__ and [link](https://example.com)")
Text(text = styledText)
// Or use the companion function
val anotherText = Mosaic.parse("**Custom styled** text", customStyles)
Text(text = anotherText)
}
```
--------------------------------
### Markdown Parsing to Jetpack Compose AnnotatedString with Mosaic
Source: https://github.com/evowizz/common/blob/main/README.md
Shows how to use the Mosaic library to parse Markdown-inspired text into Jetpack Compose's AnnotatedString. It covers basic usage, custom styling, and resource helpers for strings and plurals, targeting Compose UI.
```kotlin
val mosaicText = "**bold**\n" +
"__italic__\n" +
"__**bold & italic**__\n" +
"**[__Link__](https://example.com)**"
Text(text = Mosaic.parse(mosaicText))
```
```kotlin
val styles = MosaicStyles(
bold = SpanStyle(fontWeight = FontWeight.SemiBold),
italic = MosaicStyles.Default.italic,
link = TextLinkStyles(style = SpanStyle(textDecoration = TextDecoration.Underline))
)
val annotated = Mosaic(styles).parse("Visit [site](https://example.org)")
```
```kotlin
// Provide a Mosaic instance app-/screen-wide, or if you need to customize styles
// `LocalMosaic` already provides a default instance using `MosaicStyles.Default`.
MosaicProvider(customStyles) {
val mosaic = LocalMosaic.current
Text(text = mosaic.parse("A **bold** inline value"))
Text(text = mosaicStringResource(R.string.mosaic_demo_bold_link))
Text(text = mosaicPluralStringResource(R.plurals.mosaic_demo_files, 2, 2))
}
```
--------------------------------
### Detect Android Preview and Canary Builds (Kotlin)
Source: https://context7.com/evowizz/common/llms.txt
Check if the device is running a preview or canary build of Android using AndroidVersion.isPreview() and AndroidVersion.isCanary(). This is useful for testing unreleased features or identifying potential instability.
```kotlin
import dev.evowizz.common.os.AndroidVersion
// Check if running a preview SDK
if (AndroidVersion.isPreview()) {
Log.d(TAG, "Running on Android Preview SDK")
}
// Check if running a canary build
if (AndroidVersion.isCanary()) {
Log.w(TAG, "Running on Canary build - expect instability")
}
// Get the current codename (e.g., "REL" for release, or preview name)
val codename = AndroidVersion.getCodename()
// Check if running at least a specific pre-release version
if (AndroidVersion.isAtLeastPreRelease("Baklava")) {
// Running on Baklava preview or later
}
```
--------------------------------
### Parsing Mosaic Markup from Android String Resources in Kotlin
Source: https://context7.com/evowizz/common/llms.txt
Illustrates how to use `mosaicStringResource` and `mosaicPluralStringResource` to parse Mosaic markup directly from Android string resources. This enables localized rich text content with support for format arguments and pluralization.
```kotlin
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import dev.evowizz.common.mosaic.MosaicProvider
import dev.evowizz.common.mosaic.mosaicPluralStringResource
import dev.evowizz.common.mosaic.mosaicStringResource
// strings.xml:
// Welcome, **%1$s**! Visit [settings](https://app.com/settings).
//
// - You have **%d** file
// - You have **%d** files
//
@Composable
fun LocalizedMosaicText() {
MosaicProvider {
Column {
// Parse string resource with Mosaic
val welcomeText = mosaicStringResource(R.string.welcome_message, "John")
Text(text = welcomeText) // "Welcome, John! Visit settings."
// Parse plurals resource with Mosaic
val fileCount = 5
val filesText = mosaicPluralStringResource(
R.plurals.file_count,
fileCount,
fileCount
)
Text(text = filesText) // "You have 5 files" with bold "5"
// Single file case
val singleFile = mosaicPluralStringResource(R.plurals.file_count, 1, 1)
Text(text = singleFile) // "You have 1 file"
}
}
}
```
--------------------------------
### Check Android API Levels with Helper Methods (Kotlin)
Source: https://context7.com/evowizz/common/llms.txt
Use the AndroidVersion.isAtLeast*() methods to easily check if the device's Android API level meets a specific requirement. These methods provide a readable way to handle version-specific logic and are lint-aware.
```kotlin
import android.os.Build
import dev.evowizz.common.os.AndroidVersion
// Check for specific API levels using named methods
if (AndroidVersion.isAtLeastT()) {
// Android 13 (Tiramisu, API 33) or higher
requestNotificationPermission()
}
if (AndroidVersion.isAtLeastS()) {
// Android 12 (Snow Cone, API 31) or higher
enableDynamicColors()
}
if (AndroidVersion.isAtLeastR()) {
// Android 11 (API 30) or higher
val display = AndroidVersion.getVersionDisplay() // Returns "13" or "12L" etc.
}
// Check for any arbitrary API level
if (AndroidVersion.isAtLeast(Build.VERSION_CODES.UPSIDE_DOWN_CAKE)) {
// Android 14 (API 34) or higher
}
// Available methods: isAtLeastBaklava(), isAtLeastV(), isAtLeastU(), isAtLeastT(),
// isAtLeastS2(), isAtLeastS(), isAtLeastR(), isAtLeastQ(), isAtLeastP(),
// isAtLeastOMR1(), isAtLeastO(), isAtLeastNMR1()
```
--------------------------------
### Parsing Markdown-like Text to AnnotatedString with Mosaic
Source: https://context7.com/evowizz/common/llms.txt
Utilize the Mosaic module to parse text containing Markdown-like syntax (bold, italic, links) into Jetpack Compose's AnnotatedString. This enables rich text rendering within Compose UI elements.
```kotlin
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import dev.evowizz.common.mosaic.Mosaic
@Composable
fun StyledTextExample() {
// Parse text with Mosaic markup
val styledText = Mosaic.parse("This is **bold** and __italic__ text!")
Text(text = styledText)
// Clickable links (uses LinkAnnotation.Url)
val linkText = Mosaic.parse("Visit [Google](https://google.com) for search!")
Text(text = linkText)
// Nested styles
val complexText = Mosaic.parse("""
**bold text**
__italic text__
__**bold and italic**__
**[__Styled Link__](https://example.com)**
""".trimIndent())
Text(text = complexText)
}
```
--------------------------------
### Conditional Code Execution by API Level (Kotlin)
Source: https://context7.com/evowizz/common/llms.txt
Employ AndroidVersion.whenAtLeast() for cleaner, lambda-based conditional execution of code based on the Android API level. This offers a more concise alternative to traditional if-else statements for version-gated operations.
```kotlin
import android.os.Build
import dev.evowizz.common.os.AndroidVersion
// Execute code only on Android 13+
AndroidVersion.whenAtLeast(Build.VERSION_CODES.TIRAMISU) {
// This block only runs on API 33+
registerNotificationChannel()
}
// Chain multiple version-gated operations
AndroidVersion.whenAtLeast(Build.VERSION_CODES.S) {
enableSplashScreenAPI()
}
AndroidVersion.whenAtLeast(Build.VERSION_CODES.R) {
useWindowInsetsController()
}
```
--------------------------------
### Hashing Files and InputStreams with Evowizz
Source: https://context7.com/evowizz/common/llms.txt
Compute SHA256 or MD5 hashes for files and input streams. This is useful for verifying data integrity, such as downloaded files. The InputStream is not closed by the hash function.
```kotlin
import dev.evowizz.common.hashing.Algorithm
import dev.evowizz.common.hashing.Hashing
import java.io.File
// Hash a file
val file = File("/path/to/document.pdf")
val fileHash = Hashing.hash(file, Algorithm.SHA256)
// Returns: hexadecimal hash of file contents
// Hash from InputStream (stream is NOT closed by this method)
val inputStream = context.assets.open("config.json")
inputStream.use {
val streamHash = Hashing.hash(it, Algorithm.MD5)
Log.d(TAG, "Config hash: $streamHash")
}
// Verify downloaded file integrity
fun verifyDownload(downloadedFile: File, expectedSha256: String): Boolean {
val actualHash = Hashing.hash(downloadedFile, Algorithm.SHA256)
return Hashing.isEqual(actualHash, expectedSha256)
}
// Example usage
val apkFile = File(context.cacheDir, "update.apk")
val isValid = verifyDownload(apkFile, "a1b2c3d4e5f6...")
```
--------------------------------
### Access Android System Properties Safely (Kotlin)
Source: https://context7.com/evowizz/common/llms.txt
Provides a safe way to access Android system properties using reflection. It allows retrieving properties with nullability, throwing exceptions, or providing default values. This utility is useful for accessing hidden APIs that are normally unavailable.
```kotlin
import android.os.Build
import dev.evowizz.common.os.SystemProperties
// Get property or null if not found
val buildId: String? = SystemProperties.getOrNull("ro.build.id")
// Returns: "AP1A.240505.005" or null
// Get property or throw if not found
val release: String = SystemProperties.getOrThrow("ro.build.version.release")
// Returns: "14" or throws IllegalStateException
// Get property with default value
val fingerprint = SystemProperties.getOrElse("ro.build.fingerprint", Build.UNKNOWN)
// Returns: property value or "unknown"
// Get property with default value from lambda
val customProp = SystemProperties.getOrElse("ro.custom.property") { key ->
Log.w(TAG, "Property $key not found, using fallback")
"default_value"
}
// Common useful properties:
// - "ro.build.id" -> Build ID
// - "ro.build.version.release" -> Android version (e.g., "14")
// - "ro.build.fingerprint" -> Full build fingerprint
// - "ro.product.model" -> Device model
// - "ro.product.brand" -> Device brand
```
--------------------------------
### Hashing ByteBuffers with Evowizz
Source: https://context7.com/evowizz/common/llms.txt
Compute hashes for ByteBuffer contents without altering the buffer's position or limit. This is particularly useful for NIO operations and memory-mapped files where buffer state needs to be preserved.
```kotlin
import dev.evowizz.common.hashing.Algorithm
import dev.evowizz.common.hashing.Hashing
import java.nio.ByteBuffer
// Hash a ByteBuffer (position and limit remain unchanged)
val buffer = ByteBuffer.allocate(1024)
buffer.put("Some binary data".toByteArray())
buffer.flip()
val bufferHash = Hashing.hash(buffer, Algorithm.SHA256)
// Buffer's position is still at 0 after hashing
// Useful for memory-mapped files or NIO operations
val channel = FileInputStream(file).channel
val mappedBuffer = channel.map(FileChannel.MapMode.READ_ONLY, 0, channel.size())
val mappedHash = Hashing.hash(mappedBuffer, Algorithm.SHA256)
```
--------------------------------
### Convert Dimensions: dp to px and px to dp (Kotlin)
Source: https://context7.com/evowizz/common/llms.txt
Provides extension functions `toPx()` and `toDp()` for `Float` and `Int` types to easily convert between density-independent pixels (dp) and physical pixels (px) within an Android context. This simplifies programmatic UI layout and sizing.
```kotlin
import dev.evowizz.common.view.toPx
import dev.evowizz.common.view.toDp
val context = ApplicationContext.get()
// Convert dp to pixels
val paddingPx: Float = 16.toPx(context) // 16dp -> pixels (e.g., 48f on xxhdpi)
val marginPx: Float = 8f.toPx(context) // 8dp -> pixels
// Convert pixels to dp
val widthDp: Float = 300.toDp(context) // 300px -> dp
val heightDp: Float = 480f.toDp(context) // 480px -> dp
// Practical usage: programmatic view sizing
val customView = CustomView(context).apply {
layoutParams = ViewGroup.LayoutParams(
100.toPx(context).toInt(), // 100dp width in pixels
50.toPx(context).toInt() // 50dp height in pixels
)
setPadding(
8.toPx(context).toInt(),
4.toPx(context).toInt(),
8.toPx(context).toInt(),
4.toPx(context).toInt()
)
}
```
--------------------------------
### Evowizz Hashing: Raw Digests and Constant-Time Comparisons
Source: https://context7.com/evowizz/common/llms.txt
Obtain raw byte array digests instead of hexadecimal strings and perform secure, constant-time comparisons of hashes to mitigate timing attacks. This is crucial for security-sensitive operations like password verification.
```kotlin
import dev.evowizz.common.hashing.Algorithm
import dev.evowizz.common.hashing.Hashing
// Get raw digest bytes (not hex string)
val digestBytes: ByteArray = Hashing.digest("password123", Algorithm.SHA256)
// Returns: 32-byte array for SHA-256
// Constant-time comparison for security (prevents timing attacks)
val storedHash = "5e884898da28047d9..."
val inputHash = Hashing.hash(userInput, Algorithm.SHA256)
val isMatch = Hashing.isEqual(storedHash, inputHash)
// Compare raw byte arrays
val hash1 = Hashing.digest("data1", Algorithm.SHA256)
val hash2 = Hashing.digest("data2", Algorithm.SHA256)
val bytesMatch = Hashing.isEqual(hash1, hash2)
// Secure password verification example
fun verifyPassword(inputPassword: String, storedHash: String): Boolean {
val inputHash = Hashing.hash(inputPassword, Algorithm.SHA256)
return Hashing.isEqual(inputHash, storedHash) // Constant-time comparison
}
```
--------------------------------
### Compute Cryptographic Hashes (Kotlin)
Source: https://context7.com/evowizz/common/llms.txt
Calculates cryptographic hashes for strings and byte arrays using various standard algorithms like MD5, SHA1, SHA256, and SHA512. The output is always a lowercase hexadecimal string, ensuring consistent representation. Supports specifying character sets for string hashing.
```kotlin
import dev.evowizz.common.hashing.Algorithm
import dev.evowizz.common.hashing.Hashing
// Hash a string with different algorithms
val md5Hash = Hashing.hash("Hello World!", Algorithm.MD5)
// Returns: "ed076287532e86365e841e92bfc50d8c"
val sha1Hash = Hashing.hash("Hello World!", Algorithm.SHA1)
// Returns: "2ef7bde608ce5404e97d5f042f95f89f1c232871"
val sha256Hash = Hashing.hash("Hello World!", Algorithm.SHA256)
// Returns: "7f83b1657ff1fc53b92dc18148a1d65dfc2d4b1fa3d677284addd200126d9069"
// Hash with specific charset
val utf16Hash = Hashing.hash("Hello", Algorithm.SHA256, Charsets.UTF_16)
// Hash a byte array
val data = "sensitive data".toByteArray()
val dataHash = Hashing.hash(data, Algorithm.SHA512)
// Available algorithms: MD2, MD5, SHA1, SHA256, SHA384, SHA512
```
--------------------------------
### Detect Navigation Bar Mode (Kotlin)
Source: https://context7.com/evowizz/common/llms.txt
Detects the current navigation bar mode (gesture, 2-button, or 3-button navigation) on an Android device. This is crucial for adjusting UI layouts and touch event handling based on the user's preferred navigation method.
```kotlin
import dev.evowizz.common.view.NavigationBar
import dev.evowizz.common.view.NavigationBarMode
val context = ApplicationContext.get()
val navMode = NavigationBar.getMode(context)
when (navMode) {
NavigationBarMode.MODE_GESTURAL -> {
// User is using gesture navigation (swipe from edges)
// Adjust edge-to-edge layouts accordingly
enableEdgeToEdgeContent()
}
NavigationBarMode.MODE_2BUTTON -> {
// Two-button navigation (pill + back gesture)
adjustBottomPadding(small = true)
}
NavigationBarMode.MODE_3BUTTON -> {
// Traditional three-button navigation
adjustBottomPadding(small = false)
}
NavigationBarMode.MODE_UNKNOWN -> {
// Could not determine navigation mode
useDefaultLayout()
}
}
// Quick check for gesture navigation
val isGestural = NavigationBar.getMode(context) == NavigationBarMode.MODE_GESTURAL
```
=== COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.