diff --git a/examples/README.md b/examples/README.md index a76febde8d..812b2662a0 100644 --- a/examples/README.md +++ b/examples/README.md @@ -3,6 +3,8 @@ ### Idea examples * [plugin example](kotlin-dataframe-plugin-example) IDEA project with a [Kotlin DataFrame Compiler Plugin](https://kotlin.github.io/dataframe/compiler-plugin.html) example. +* [android example](android-example) A minimal Android project showcasing integration with Kotlin DataFrame. +Also includes [Kotlin DataFrame Compiler Plugin](https://kotlin.github.io/dataframe/compiler-plugin.html). * [movies](idea-examples/movies) Using extension properties [Access API](https://kotlin.github.io/dataframe/apilevels.html) to perform a data cleaning task * [titanic](idea-examples/titanic) * [youtube](idea-examples/youtube) diff --git a/examples/android-example/.gitignore b/examples/android-example/.gitignore new file mode 100644 index 0000000000..aa724b7707 --- /dev/null +++ b/examples/android-example/.gitignore @@ -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 diff --git a/examples/android-example/README.md b/examples/android-example/README.md new file mode 100644 index 0000000000..41b6c8a203 --- /dev/null +++ b/examples/android-example/README.md @@ -0,0 +1,13 @@ +# 📱 Android Example + +A minimal Android project showcasing integration with **Kotlin DataFrame**. + +

+ App screenshot +

+ +It also includes the [Kotlin DataFrame Compiler Plugin](https://kotlin.github.io/dataframe/compiler-plugin.html). + +> **Note:** The generated [extension properties](https://kotlin.github.io/dataframe/extensionpropertiesapi.html) +> may not be highlighted correctly in current stable versions of Android Studio due to limited IDE support. +> However, they work as expected at runtime and during compilation. diff --git a/examples/android-example/app/.gitignore b/examples/android-example/app/.gitignore new file mode 100644 index 0000000000..42afabfd2a --- /dev/null +++ b/examples/android-example/app/.gitignore @@ -0,0 +1 @@ +/build \ No newline at end of file diff --git a/examples/android-example/app/build.gradle.kts b/examples/android-example/app/build.gradle.kts new file mode 100644 index 0000000000..15baad46bd --- /dev/null +++ b/examples/android-example/app/build.gradle.kts @@ -0,0 +1,86 @@ +plugins { + alias(libs.plugins.android.application) + alias(libs.plugins.kotlin.android) + alias(libs.plugins.kotlin.compose) + kotlin("plugin.dataframe") version "2.2.20-Beta1" +} + +android { + namespace = "com.example.myapplication" + compileSdk = 36 + + defaultConfig { + applicationId = "com.example.myapplication" + minSdk = 26 + targetSdk = 36 + versionCode = 1 + versionName = "1.0" + + testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner" + } + + buildTypes { + release { + isMinifyEnabled = false + proguardFiles( + getDefaultProguardFile("proguard-android-optimize.txt"), + "proguard-rules.pro" + ) + } + } + compileOptions { + sourceCompatibility = JavaVersion.VERSION_1_8 + targetCompatibility = JavaVersion.VERSION_1_8 + } + kotlinOptions { + jvmTarget = "1.8" + } + buildFeatures { + compose = true + } + packaging { + resources { + pickFirsts += listOf( + "META-INF/AL2.0", + "META-INF/LGPL2.1", + "META-INF/ASL-2.0.txt", + "META-INF/LICENSE.md", + "META-INF/NOTICE.md", + "META-INF/LGPL-3.0.txt", + "META-INF/thirdparty-LICENSE", + ) + excludes += listOf( + "META-INF/kotlin-jupyter-libraries/libraries.json", + "META-INF/{INDEX.LIST,DEPENDENCIES}", + "{draftv3,draftv4}/schema", + "arrow-git.properties", + ) + } + } +} + +dependencies { + + implementation(libs.androidx.core.ktx) + implementation(libs.androidx.lifecycle.runtime.ktx) + implementation(libs.androidx.activity.compose) + implementation(platform(libs.androidx.compose.bom)) + implementation(libs.androidx.ui) + implementation(libs.androidx.ui.graphics) + implementation(libs.androidx.ui.tooling.preview) + implementation(libs.androidx.material3) + testImplementation(libs.junit) + androidTestImplementation(libs.androidx.junit) + androidTestImplementation(libs.androidx.espresso.core) + androidTestImplementation(platform(libs.androidx.compose.bom)) + androidTestImplementation(libs.androidx.ui.test.junit4) + debugImplementation(libs.androidx.ui.tooling) + debugImplementation(libs.androidx.ui.test.manifest) + + // TODO update version + // Core Kotlin DataFrame API & JSON IO. + // See custom Gradle setup: + // https://kotlin.github.io/dataframe/setupcustomgradle.html + implementation("org.jetbrains.kotlinx:dataframe-core:1.0.0-dev-7831") + implementation("org.jetbrains.kotlinx:dataframe-json:1.0.0-dev-7831") +} diff --git a/examples/android-example/app/proguard-rules.pro b/examples/android-example/app/proguard-rules.pro new file mode 100644 index 0000000000..481bb43481 --- /dev/null +++ b/examples/android-example/app/proguard-rules.pro @@ -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 \ No newline at end of file diff --git a/examples/android-example/app/src/androidTest/java/com/example/myapplication/ExampleInstrumentedTest.kt b/examples/android-example/app/src/androidTest/java/com/example/myapplication/ExampleInstrumentedTest.kt new file mode 100644 index 0000000000..e9283cf4d8 --- /dev/null +++ b/examples/android-example/app/src/androidTest/java/com/example/myapplication/ExampleInstrumentedTest.kt @@ -0,0 +1,24 @@ +package com.example.myapplication + +import androidx.test.platform.app.InstrumentationRegistry +import androidx.test.ext.junit.runners.AndroidJUnit4 + +import org.junit.Test +import org.junit.runner.RunWith + +import org.junit.Assert.* + +/** + * Instrumented test, which will execute on an Android device. + * + * See [testing documentation](http://d.android.com/tools/testing). + */ +@RunWith(AndroidJUnit4::class) +class ExampleInstrumentedTest { + @Test + fun useAppContext() { + // Context of the app under test. + val appContext = InstrumentationRegistry.getInstrumentation().targetContext + assertEquals("com.example.myapplication", appContext.packageName) + } +} \ No newline at end of file diff --git a/examples/android-example/app/src/main/AndroidManifest.xml b/examples/android-example/app/src/main/AndroidManifest.xml new file mode 100644 index 0000000000..83371c8a83 --- /dev/null +++ b/examples/android-example/app/src/main/AndroidManifest.xml @@ -0,0 +1,27 @@ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/examples/android-example/app/src/main/java/com/example/myapplication/MainActivity.kt b/examples/android-example/app/src/main/java/com/example/myapplication/MainActivity.kt new file mode 100644 index 0000000000..06397489f9 --- /dev/null +++ b/examples/android-example/app/src/main/java/com/example/myapplication/MainActivity.kt @@ -0,0 +1,144 @@ +package com.example.myapplication + +import android.os.Bundle +import androidx.activity.ComponentActivity +import androidx.activity.compose.setContent +import androidx.activity.enableEdgeToEdge +import androidx.compose.foundation.background +import androidx.compose.foundation.layout.Column +import androidx.compose.foundation.layout.Row +import androidx.compose.foundation.layout.Spacer +import androidx.compose.foundation.layout.fillMaxSize +import androidx.compose.foundation.layout.height +import androidx.compose.foundation.layout.padding +import androidx.compose.foundation.lazy.LazyColumn +import androidx.compose.foundation.lazy.items +import androidx.compose.material3.MaterialTheme +import androidx.compose.material3.Surface +import androidx.compose.material3.Text +import androidx.compose.runtime.Composable +import androidx.compose.ui.Modifier +import androidx.compose.ui.graphics.Color +import androidx.compose.ui.tooling.preview.Preview +import androidx.compose.ui.unit.dp +import org.jetbrains.kotlinx.dataframe.DataFrame +import org.jetbrains.kotlinx.dataframe.annotations.DataSchema +import org.jetbrains.kotlinx.dataframe.api.cast +import org.jetbrains.kotlinx.dataframe.api.dataFrameOf +import org.jetbrains.kotlinx.dataframe.api.filter +import org.jetbrains.kotlinx.dataframe.api.rows + +@DataSchema +data class Person( + val age: Int, + val name: String +) + +class MainActivity : ComponentActivity() { + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + enableEdgeToEdge() + + val df = dataFrameOf( + "name" to listOf("Andrei", "Nikita", "Jolan"), + "age" to listOf(22, 16, 37) + ).cast() + + setContent { + MaterialTheme { + Surface(modifier = Modifier.fillMaxSize()) { + DataFrameScreen(df) + } + } + } + } +} + +@Preview(showBackground = true) +@Composable +fun DefaultDataFrameScreenPreview() { + val df = dataFrameOf( + "name" to listOf("Andrei", "Nikita", "Jolan"), + "age" to listOf(22, 16, 37) + ).cast() + DataFrameScreen(df) +} + +@Composable +fun DataFrameScreen(df: DataFrame) { + Column( + modifier = Modifier + .fillMaxSize() + .padding(top = 48.dp, start = 16.dp, end = 16.dp) + ) { + Text( + text = "Kotlin DataFrame on Android", + style = MaterialTheme.typography.headlineSmall, + modifier = Modifier.padding(bottom = 16.dp) + ) + + Text( + text = "df", + modifier = Modifier + .background(color = Color.LightGray) + .padding(2.dp) + ) + + DataFrameTable(df) + + Text( + text = "df.filter { age >= 20 }", + modifier = Modifier + .background(color = Color.LightGray) + .padding(2.dp) + ) + + DataFrameTable(df.filter { age >= 20 }) + } +} + +@Preview(showBackground = true) +@Composable +fun DefaultDataFrameTablePreview() { + val df = dataFrameOf( + "name" to listOf("Andrei", "Nikita", "Jolan"), + "age" to listOf(22, 16, 37) + ).cast() + DataFrameTable(df) +} + +@Composable +fun DataFrameTable(df: DataFrame<*>) { + val columnNames = df.columnNames() + + // Header + Row { + for (name in columnNames) { + Text( + text = name, + modifier = Modifier + .weight(1f) + .padding(4.dp), + style = MaterialTheme.typography.labelLarge + ) + } + } + + Spacer(Modifier.height(4.dp)) + + // Rows + LazyColumn { + items(df.rows().toList()) { row -> + Row { + for (cell in row.values()) { + Text( + text = cell.toString(), + modifier = Modifier + .weight(1f) + .padding(4.dp) + ) + } + } + } + } +} diff --git a/examples/android-example/app/src/main/res/drawable/ic_launcher_background.xml b/examples/android-example/app/src/main/res/drawable/ic_launcher_background.xml new file mode 100644 index 0000000000..07d5da9cbf --- /dev/null +++ b/examples/android-example/app/src/main/res/drawable/ic_launcher_background.xml @@ -0,0 +1,170 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/examples/android-example/app/src/main/res/drawable/ic_launcher_foreground.xml b/examples/android-example/app/src/main/res/drawable/ic_launcher_foreground.xml new file mode 100644 index 0000000000..2b068d1146 --- /dev/null +++ b/examples/android-example/app/src/main/res/drawable/ic_launcher_foreground.xml @@ -0,0 +1,30 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/examples/android-example/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml b/examples/android-example/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml new file mode 100644 index 0000000000..6f3b755bf5 --- /dev/null +++ b/examples/android-example/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/examples/android-example/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml b/examples/android-example/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml new file mode 100644 index 0000000000..6f3b755bf5 --- /dev/null +++ b/examples/android-example/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/examples/android-example/app/src/main/res/mipmap-hdpi/ic_launcher.webp b/examples/android-example/app/src/main/res/mipmap-hdpi/ic_launcher.webp new file mode 100644 index 0000000000..c209e78ecd Binary files /dev/null and b/examples/android-example/app/src/main/res/mipmap-hdpi/ic_launcher.webp differ diff --git a/examples/android-example/app/src/main/res/mipmap-hdpi/ic_launcher_round.webp b/examples/android-example/app/src/main/res/mipmap-hdpi/ic_launcher_round.webp new file mode 100644 index 0000000000..b2dfe3d1ba Binary files /dev/null and b/examples/android-example/app/src/main/res/mipmap-hdpi/ic_launcher_round.webp differ diff --git a/examples/android-example/app/src/main/res/mipmap-mdpi/ic_launcher.webp b/examples/android-example/app/src/main/res/mipmap-mdpi/ic_launcher.webp new file mode 100644 index 0000000000..4f0f1d64e5 Binary files /dev/null and b/examples/android-example/app/src/main/res/mipmap-mdpi/ic_launcher.webp differ diff --git a/examples/android-example/app/src/main/res/mipmap-mdpi/ic_launcher_round.webp b/examples/android-example/app/src/main/res/mipmap-mdpi/ic_launcher_round.webp new file mode 100644 index 0000000000..62b611da08 Binary files /dev/null and b/examples/android-example/app/src/main/res/mipmap-mdpi/ic_launcher_round.webp differ diff --git a/examples/android-example/app/src/main/res/mipmap-xhdpi/ic_launcher.webp b/examples/android-example/app/src/main/res/mipmap-xhdpi/ic_launcher.webp new file mode 100644 index 0000000000..948a3070fe Binary files /dev/null and b/examples/android-example/app/src/main/res/mipmap-xhdpi/ic_launcher.webp differ diff --git a/examples/android-example/app/src/main/res/mipmap-xhdpi/ic_launcher_round.webp b/examples/android-example/app/src/main/res/mipmap-xhdpi/ic_launcher_round.webp new file mode 100644 index 0000000000..1b9a6956b3 Binary files /dev/null and b/examples/android-example/app/src/main/res/mipmap-xhdpi/ic_launcher_round.webp differ diff --git a/examples/android-example/app/src/main/res/mipmap-xxhdpi/ic_launcher.webp b/examples/android-example/app/src/main/res/mipmap-xxhdpi/ic_launcher.webp new file mode 100644 index 0000000000..28d4b77f9f Binary files /dev/null and b/examples/android-example/app/src/main/res/mipmap-xxhdpi/ic_launcher.webp differ diff --git a/examples/android-example/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.webp b/examples/android-example/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.webp new file mode 100644 index 0000000000..9287f50836 Binary files /dev/null and b/examples/android-example/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.webp differ diff --git a/examples/android-example/app/src/main/res/mipmap-xxxhdpi/ic_launcher.webp b/examples/android-example/app/src/main/res/mipmap-xxxhdpi/ic_launcher.webp new file mode 100644 index 0000000000..aa7d6427e6 Binary files /dev/null and b/examples/android-example/app/src/main/res/mipmap-xxxhdpi/ic_launcher.webp differ diff --git a/examples/android-example/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.webp b/examples/android-example/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.webp new file mode 100644 index 0000000000..9126ae37cb Binary files /dev/null and b/examples/android-example/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.webp differ diff --git a/examples/android-example/app/src/main/res/values/colors.xml b/examples/android-example/app/src/main/res/values/colors.xml new file mode 100644 index 0000000000..f8c6127d32 --- /dev/null +++ b/examples/android-example/app/src/main/res/values/colors.xml @@ -0,0 +1,10 @@ + + + #FFBB86FC + #FF6200EE + #FF3700B3 + #FF03DAC5 + #FF018786 + #FF000000 + #FFFFFFFF + \ No newline at end of file diff --git a/examples/android-example/app/src/main/res/values/strings.xml b/examples/android-example/app/src/main/res/values/strings.xml new file mode 100644 index 0000000000..19dbc39cbf --- /dev/null +++ b/examples/android-example/app/src/main/res/values/strings.xml @@ -0,0 +1,3 @@ + + Kotlin Dataframe Simple App + \ No newline at end of file diff --git a/examples/android-example/app/src/main/res/values/themes.xml b/examples/android-example/app/src/main/res/values/themes.xml new file mode 100644 index 0000000000..7c854fb1bf --- /dev/null +++ b/examples/android-example/app/src/main/res/values/themes.xml @@ -0,0 +1,4 @@ + + +