-
Notifications
You must be signed in to change notification settings - Fork 75
android example #1349
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
AndreiKingsley
wants to merge
3
commits into
master
Choose a base branch
from
android_example
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
android example #1349
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
This file contains hidden or 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
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 |
This file contains hidden or 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# 📱 Android Example | ||
|
||
A minimal Android project showcasing integration with **Kotlin DataFrame**. | ||
|
||
<p align="center"> | ||
<img src="screen.jpg" alt="App screenshot" height="320"/> | ||
</p> | ||
|
||
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. |
This file contains hidden or 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/build |
This file contains hidden or 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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") | ||
} |
This file contains hidden or 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
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 |
24 changes: 24 additions & 0 deletions
24
...oid-example/app/src/androidTest/java/com/example/myapplication/ExampleInstrumentedTest.kt
This file contains hidden or 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) | ||
} | ||
} |
This file contains hidden or 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<?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.MyApplication" > | ||
<activity | ||
android:name=".MainActivity" | ||
android:exported="true" | ||
android:label="@string/app_name" | ||
android:theme="@style/Theme.MyApplication" > | ||
<intent-filter> | ||
<action android:name="android.intent.action.MAIN" /> | ||
|
||
<category android:name="android.intent.category.LAUNCHER" /> | ||
</intent-filter> | ||
</activity> | ||
</application> | ||
|
||
</manifest> |
144 changes: 144 additions & 0 deletions
144
examples/android-example/app/src/main/java/com/example/myapplication/MainActivity.kt
This file contains hidden or 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<Person>() | ||
|
||
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<Person>() | ||
DataFrameScreen(df) | ||
} | ||
|
||
@Composable | ||
fun DataFrameScreen(df: DataFrame<Person>) { | ||
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<Person>() | ||
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) | ||
) | ||
} | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It may be nice to add a preview too:
That way people don't have to build+run the app on an emulator/device but they can preview what their dataframe looks like in Android Studio