Skip to content
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.jetskicli/
15 changes: 15 additions & 0 deletions Grid/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
*.iml
.gradle
/local.properties
/.idea/caches
/.idea/libraries
/.idea/modules.xml
/.idea/workspace.xml
/.idea/navEditor.xml
/.idea/assetWizardSettings.xml
.DS_Store
/build
/captures
.externalNativeBuild
.cxx
local.properties
7 changes: 7 additions & 0 deletions Grid/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Grid layout sample

Create responsive grid-based user interfaces using Compose `Grid` APIs.

## Features demonstrated
- **Column span adjustments:** Elements spanning multiple columns.
- **Multi-column adaptation:** Adapting elements to fit different display widths dynamically.
1 change: 1 addition & 0 deletions Grid/app/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
72 changes: 72 additions & 0 deletions Grid/app/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
plugins {
alias(libs.plugins.android.application)
alias(libs.plugins.compose.compiler)
}

android {
namespace = "com.example.gridsample"
compileSdk = 37
Comment thread
JonEckenrode marked this conversation as resolved.

defaultConfig {
applicationId = "com.example.gridsample"
minSdk = 26
targetSdk = 37
versionCode = 1
versionName = "1.0"

testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
vectorDrawables {
useSupportLibrary = true
}
}

buildTypes {
release {
isMinifyEnabled = false
proguardFiles(getDefaultProguardFile("proguard-android-optimize.txt"), "proguard-rules.pro")
}
}
compileOptions {
sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17
}
buildFeatures {
compose = true
}
packaging {
resources {
excludes += "/META-INF/{AL2.0,LGPL2.1}"
}
}
}

kotlin {
jvmToolchain(17)
}

dependencies {
val composeBom = platform(libs.androidx.compose.bom)
implementation(composeBom)
androidTestImplementation(composeBom)

// Core Android dependencies
implementation(libs.androidx.core.ktx)
implementation(libs.androidx.lifecycle.runtime.ktx)
implementation(libs.androidx.activity.compose)

// Compose
implementation(libs.androidx.compose.ui)
implementation(libs.androidx.compose.ui.tooling.preview)
implementation(libs.androidx.compose.material3)
implementation(libs.androidx.compose.foundation.layout)

// Tooling
debugImplementation(libs.androidx.compose.ui.tooling)
// Instrumented tests
androidTestImplementation(libs.androidx.compose.ui.test.junit4)
debugImplementation(libs.androidx.compose.ui.test.manifest)

testImplementation(libs.junit)
androidTestImplementation(libs.androidx.test.ext.junit)
androidTestImplementation(libs.androidx.test.espresso.core)
}
21 changes: 21 additions & 0 deletions Grid/app/proguard-rules.pro
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Add project specific ProGuard rules here.
# You can control the set of applied configuration files using the
# proguardFiles setting in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html

# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}

# Uncomment this to preserve the line number information for
# debugging stack traces.
#-keepattributes SourceFile,LineNumberTable

# If you keep the line number information, uncomment this to
# hide the original source file name.
#-renamesourcefileattribute SourceFile
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package com.example.gridsample

import androidx.activity.ComponentActivity
import androidx.compose.ui.test.junit4.createAndroidComposeRule
import androidx.compose.ui.test.onNodeWithText
import org.junit.Before
import org.junit.Rule
import org.junit.Test

class GridSampleTest {
@get:Rule val composeTestRule = createAndroidComposeRule<ComponentActivity>()

@Before
fun setup() {
composeTestRule.setContent { GridSample() }
}

@Test
fun gridSample_rendersCorrectly() {
composeTestRule.onNodeWithText("Grid sample").assertExists()
composeTestRule.onNodeWithText("Display Grid layout variations on this device.").assertExists()
}
}
28 changes: 28 additions & 0 deletions Grid/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" >

<application
android:allowBackup="true"
android:dataExtractionRules="@xml/data_extraction_rules"
android:fullBackupContent="@xml/backup_rules"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.GridSample"
tools:targetApi="31" >
<activity
android:name=".MainActivity"
android:exported="true"
android:label="@string/app_name"
android:theme="@style/Theme.GridSample" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>

</manifest>
108 changes: 108 additions & 0 deletions Grid/app/src/main/java/com/example/gridsample/GridSample.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
package com.example.gridsample

import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.ExperimentalGridApi
import androidx.compose.foundation.layout.Grid
import androidx.compose.foundation.layout.fillMaxHeight
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.safeDrawingPadding
import androidx.compose.foundation.rememberScrollState
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.foundation.verticalScroll
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.luminance
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import com.example.gridsample.ui.theme.MyApplicationTheme

@OptIn(ExperimentalGridApi::class)
@Composable
fun GridSample() {
val colors = listOf(
Color(0xFFF44336), // Red
Color(0xFFE91E63), // Pink
Color(0xFF9C27B0), // Purple
Color(0xFF3F51B5), // Indigo
Color(0xFF2196F3), // Blue
Color(0xFF00BCD4), // Cyan
Color(0xFF4CAF50), // Green
Color(0xFFFFEB3B), // Yellow
Color(0xFFFF9800), // Orange
Color(0xFF795548) // Brown
)

Column(modifier = Modifier.safeDrawingPadding().padding(16.dp).fillMaxSize().verticalScroll(rememberScrollState())) {
Text(
text = "Grid sample",
fontSize = 30.sp,
fontWeight = FontWeight.Bold,
color = MaterialTheme.colorScheme.onBackground,
modifier = Modifier.padding(bottom = 8.dp)
)

Text(
text = "Display Grid layout variations on this device.",
fontSize = 14.sp,
color = MaterialTheme.colorScheme.onBackground.copy(alpha = 0.7f),
modifier = Modifier.padding(bottom = 16.dp)
)

Grid(
config = {
repeat(3) { column(0.333f) }
Comment thread
chikoski marked this conversation as resolved.
gap(4.dp)
},
) {
for (index in 0 until 10) {
Comment thread
chikoski marked this conversation as resolved.
Outdated
val bgColor = colors[index % colors.size]
val isLight = bgColor.luminance() > 0.5f
val textColor = if (isLight) Color.Black else Color.White

val itemModifier = when (index) {
0 -> Modifier.gridItem(rowSpan = 2)
6 -> Modifier.gridItem(columnSpan = 2)
else -> Modifier
}

val boxModifier = itemModifier
.padding(2.dp)
.fillMaxWidth()
.background(bgColor, shape = RoundedCornerShape(16.dp))
.let {
if (index == 0) it.fillMaxHeight() else it.height(100.dp)
}

Box(
modifier = boxModifier
) {
Text(
text = "${index + 1}",
color = textColor,
modifier = Modifier.align(Alignment.Center),
fontSize = 40.sp
)
}
}
}
}
}

@Preview(showBackground = true)
@Composable
fun GridSamplePreview() {
MyApplicationTheme {
GridSample()
}
}
25 changes: 25 additions & 0 deletions Grid/app/src/main/java/com/example/gridsample/MainActivity.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package com.example.gridsample

import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.activity.enableEdgeToEdge
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Surface
import androidx.compose.ui.Modifier
import com.example.gridsample.ui.theme.MyApplicationTheme

class MainActivity : ComponentActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
enableEdgeToEdge()
setContent {
MyApplicationTheme {
Surface(modifier = Modifier.fillMaxSize(), color = MaterialTheme.colorScheme.background) {
GridSample()
}
}
}
}
}
11 changes: 11 additions & 0 deletions Grid/app/src/main/java/com/example/gridsample/ui/theme/Color.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.example.gridsample.ui.theme

import androidx.compose.ui.graphics.Color

val Purple80 = Color(0xFFD0BCFF)
val PurpleGrey80 = Color(0xFFCCC2DC)
val Pink80 = Color(0xFFEFB8C8)

val Purple40 = Color(0xFF6650a4)
val PurpleGrey40 = Color(0xFF625b71)
val Pink40 = Color(0xFF7D5260)
53 changes: 53 additions & 0 deletions Grid/app/src/main/java/com/example/gridsample/ui/theme/Theme.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package com.example.gridsample.ui.theme

import android.os.Build
import androidx.compose.foundation.isSystemInDarkTheme
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.darkColorScheme
import androidx.compose.material3.dynamicDarkColorScheme
import androidx.compose.material3.dynamicLightColorScheme
import androidx.compose.material3.lightColorScheme
import androidx.compose.runtime.Composable
import androidx.compose.ui.platform.LocalContext

private val DarkColorScheme = darkColorScheme(
primary = Purple80,
secondary = PurpleGrey80,
tertiary = Pink80
)

private val LightColorScheme = lightColorScheme(
primary = Purple40,
secondary = PurpleGrey40,
tertiary = Pink40

/* Other default colors to override
background = Color(0xFFFFFBFE),
surface = Color(0xFFFFFBFE),
onPrimary = Color.White,
onSecondary = Color.White,
onTertiary = Color.White,
onBackground = Color(0xFF1C1B1F),
onSurface = Color(0xFF1C1B1F),
*/
)

@Composable
fun MyApplicationTheme(
darkTheme: Boolean = isSystemInDarkTheme(),
// Dynamic color is available on Android 12+
dynamicColor: Boolean = true,
content: @Composable () -> Unit,
) {
val colorScheme =
when {
dynamicColor && Build.VERSION.SDK_INT >= Build.VERSION_CODES.S -> {
val context = LocalContext.current
if (darkTheme) dynamicDarkColorScheme(context) else dynamicLightColorScheme(context)
}
darkTheme -> DarkColorScheme
else -> LightColorScheme
}

MaterialTheme(colorScheme = colorScheme, typography = Typography, content = content)
}
Loading
Loading