Browse Source

add android sample for falling balls mpp (#2275)

Co-authored-by: theapache64 <theapache64@users.noreply.github.com>
pull/2293/head
theapache64 2 years ago committed by GitHub
parent
commit
9adc93f04b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 8
      experimental/examples/falling-balls-mpp/.idea/.gitignore
  2. 8
      experimental/examples/falling-balls-mpp/.idea/artifacts/falling_balls_mpp_desktop_1_0_SNAPSHOT.xml
  3. 8
      experimental/examples/falling-balls-mpp/.idea/artifacts/falling_balls_mpp_js_1_0_SNAPSHOT.xml
  4. 6
      experimental/examples/falling-balls-mpp/.idea/compiler.xml
  5. 19
      experimental/examples/falling-balls-mpp/.idea/gradle.xml
  6. 45
      experimental/examples/falling-balls-mpp/.idea/jarRepositories.xml
  7. 5
      experimental/examples/falling-balls-mpp/.idea/misc.xml
  8. 7
      experimental/examples/falling-balls-mpp/.idea/vcs.xml
  9. 32
      experimental/examples/falling-balls-mpp/build.gradle.kts
  10. 2
      experimental/examples/falling-balls-mpp/gradle.properties
  11. 4
      experimental/examples/falling-balls-mpp/settings.gradle.kts
  12. 21
      experimental/examples/falling-balls-mpp/src/androidMain/AndroidManifest.xml
  13. 23
      experimental/examples/falling-balls-mpp/src/androidMain/kotlin/org/jetbrains/fallingballs/MainActivity.kt
  14. 3
      experimental/examples/falling-balls-mpp/src/androidMain/res/values/strings.xml
  15. 12
      experimental/examples/falling-balls-mpp/src/commonMain/kotlin/fallingBalls/FallingBalls.kt

8
experimental/examples/falling-balls-mpp/.idea/.gitignore vendored

@ -0,0 +1,8 @@
# Default ignored files
/shelf/
/workspace.xml
# Editor-based HTTP Client requests
/httpRequests/
# Datasource local storage ignored files
/dataSources/
/dataSources.local.xml

8
experimental/examples/falling-balls-mpp/.idea/artifacts/falling_balls_mpp_desktop_1_0_SNAPSHOT.xml

@ -0,0 +1,8 @@
<component name="ArtifactManager">
<artifact type="jar" name="falling-balls-mpp-desktop-1.0-SNAPSHOT">
<output-path>$PROJECT_DIR$/build/libs</output-path>
<root id="archive" name="falling-balls-mpp-desktop-1.0-SNAPSHOT.jar">
<element id="module-output" name="falling-balls-mpp.desktopMain" />
</root>
</artifact>
</component>

8
experimental/examples/falling-balls-mpp/.idea/artifacts/falling_balls_mpp_js_1_0_SNAPSHOT.xml

@ -0,0 +1,8 @@
<component name="ArtifactManager">
<artifact type="jar" name="falling-balls-mpp-js-1.0-SNAPSHOT">
<output-path>$PROJECT_DIR$/build/libs</output-path>
<root id="archive" name="falling-balls-mpp-js-1.0-SNAPSHOT.jar">
<element id="module-output" name="falling-balls-mpp.jsMain" />
</root>
</artifact>
</component>

6
experimental/examples/falling-balls-mpp/.idea/compiler.xml

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="CompilerConfiguration">
<bytecodeTargetLevel target="15" />
</component>
</project>

19
experimental/examples/falling-balls-mpp/.idea/gradle.xml

@ -0,0 +1,19 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="GradleMigrationSettings" migrationVersion="1" />
<component name="GradleSettings">
<option name="linkedExternalProjectsSettings">
<GradleProjectSettings>
<option name="testRunner" value="GRADLE" />
<option name="distributionType" value="DEFAULT_WRAPPED" />
<option name="externalProjectPath" value="$PROJECT_DIR$" />
<option name="gradleJvm" value="#JAVA_HOME" />
<option name="modules">
<set>
<option value="$PROJECT_DIR$" />
</set>
</option>
</GradleProjectSettings>
</option>
</component>
</project>

45
experimental/examples/falling-balls-mpp/.idea/jarRepositories.xml

@ -0,0 +1,45 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="RemoteRepositoriesConfiguration">
<remote-repository>
<option name="id" value="central" />
<option name="name" value="Maven Central repository" />
<option name="url" value="https://repo1.maven.org/maven2" />
</remote-repository>
<remote-repository>
<option name="id" value="jboss.community" />
<option name="name" value="JBoss Community repository" />
<option name="url" value="https://repository.jboss.org/nexus/content/repositories/public/" />
</remote-repository>
<remote-repository>
<option name="id" value="MavenRepo" />
<option name="name" value="MavenRepo" />
<option name="url" value="https://repo.maven.apache.org/maven2/" />
</remote-repository>
<remote-repository>
<option name="id" value="Gradle Central Plugin Repository" />
<option name="name" value="Gradle Central Plugin Repository" />
<option name="url" value="https://plugins.gradle.org/m2" />
</remote-repository>
<remote-repository>
<option name="id" value="MavenLocal" />
<option name="name" value="MavenLocal" />
<option name="url" value="file:$MAVEN_REPOSITORY$/" />
</remote-repository>
<remote-repository>
<option name="id" value="maven" />
<option name="name" value="maven" />
<option name="url" value="https://maven.pkg.jetbrains.space/public/p/compose/dev" />
</remote-repository>
<remote-repository>
<option name="id" value="Google" />
<option name="name" value="Google" />
<option name="url" value="https://dl.google.com/dl/android/maven2/" />
</remote-repository>
<remote-repository>
<option name="id" value="MavenLocal" />
<option name="name" value="MavenLocal" />
<option name="url" value="file:$USER_HOME$/.m2/repository/" />
</remote-repository>
</component>
</project>

5
experimental/examples/falling-balls-mpp/.idea/misc.xml

@ -0,0 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ExternalStorageConfigurationManager" enabled="true" />
<component name="ProjectRootManager" version="2" languageLevel="JDK_15_PREVIEW" project-jdk-name="15" project-jdk-type="JavaSDK" />
</project>

7
experimental/examples/falling-balls-mpp/.idea/vcs.xml

@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$/../../.." vcs="Git" />
<mapping directory="$PROJECT_DIR$/build/xcodegen-2.26.0-src" vcs="Git" />
</component>
</project>

32
experimental/examples/falling-balls-mpp/build.gradle.kts

@ -15,6 +15,7 @@ buildscript {
} }
plugins { plugins {
id("com.android.application")
kotlin("multiplatform") kotlin("multiplatform")
id("org.jetbrains.compose") id("org.jetbrains.compose")
} }
@ -29,6 +30,7 @@ repositories {
google()} google()}
kotlin { kotlin {
android()
jvm("desktop") jvm("desktop")
js(IR) { js(IR) {
browser() browser()
@ -98,6 +100,15 @@ kotlin {
} }
} }
val androidMain by getting {
dependsOn(commonMain)
kotlin.srcDirs("src/jvmMain/kotlin")
dependencies {
api("androidx.appcompat:appcompat:1.4.1")
implementation("androidx.activity:activity-compose:1.4.0")
}
}
val desktopMain by getting { val desktopMain by getting {
dependencies { dependencies {
implementation(compose.desktop.currentOs) implementation(compose.desktop.currentOs)
@ -210,3 +221,24 @@ project.tasks.withType(org.jetbrains.kotlin.gradle.dsl.KotlinJsCompile::class.ja
"-Xir-dce-runtime-diagnostic=log" "-Xir-dce-runtime-diagnostic=log"
) )
} }
android {
compileSdk = 31
defaultConfig {
minSdk = 21
targetSdk = 31
}
compileOptions {
sourceCompatibility = JavaVersion.VERSION_11
targetCompatibility = JavaVersion.VERSION_11
}
sourceSets {
named("main") {
manifest.srcFile("src/androidMain/AndroidManifest.xml")
res.srcDirs("src/androidMain/res", "src/commonMain/resources")
}
}
}

2
experimental/examples/falling-balls-mpp/gradle.properties

@ -9,3 +9,5 @@ kotlin.mpp.enableGranularSourceSetsMetadata=true
# Enable kotlin/native experimental memory model # Enable kotlin/native experimental memory model
kotlin.native.binary.memoryModel=experimental kotlin.native.binary.memoryModel=experimental
compose.desktop.verbose=true compose.desktop.verbose=true
agp.version=7.0.4
android.useAndroidX=true

4
experimental/examples/falling-balls-mpp/settings.gradle.kts

@ -10,6 +10,10 @@ pluginManagement {
plugins { plugins {
val kotlinVersion = extra["kotlin.version"] as String val kotlinVersion = extra["kotlin.version"] as String
kotlin("multiplatform").version(kotlinVersion) kotlin("multiplatform").version(kotlinVersion)
kotlin("android").version(kotlinVersion)
val agpVersion = extra["agp.version"] as String
id("com.android.application").version(agpVersion)
val composeVersion = extra["compose.version"] as String val composeVersion = extra["compose.version"] as String
id("org.jetbrains.compose").version(composeVersion) id("org.jetbrains.compose").version(composeVersion)

21
experimental/examples/falling-balls-mpp/src/androidMain/AndroidManifest.xml

@ -0,0 +1,21 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="org.jetbrains.fallingballs">
<application
android:allowBackup="true"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/Theme.AppCompat.Light.NoActionBar">
<activity
android:exported="true"
android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>

23
experimental/examples/falling-balls-mpp/src/androidMain/kotlin/org/jetbrains/fallingballs/MainActivity.kt

@ -0,0 +1,23 @@
package org.jetbrains.fallingballs
import FallingBalls
import Game
import Time
import android.os.Bundle
import androidx.activity.compose.setContent
import androidx.appcompat.app.AppCompatActivity
import androidx.compose.runtime.remember
object AndroidTime : Time {
override fun now(): Long = System.nanoTime()
}
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContent {
val game = remember { Game(AndroidTime) }
FallingBalls(game)
}
}
}

3
experimental/examples/falling-balls-mpp/src/androidMain/res/values/strings.xml

@ -0,0 +1,3 @@
<resources>
<string name="app_name">Chat app</string>
</resources>

12
experimental/examples/falling-balls-mpp/src/commonMain/kotlin/fallingBalls/FallingBalls.kt

@ -12,9 +12,7 @@ import androidx.compose.ui.graphics.Color
import androidx.compose.ui.layout.onSizeChanged import androidx.compose.ui.layout.onSizeChanged
import androidx.compose.ui.platform.LocalDensity import androidx.compose.ui.platform.LocalDensity
import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.em import androidx.compose.ui.unit.sp
import org.jetbrains.skiko.KotlinBackend
import kotlin.math.round
@Composable @Composable
fun FallingBalls(game: Game) { fun FallingBalls(game: Game) {
@ -22,10 +20,10 @@ fun FallingBalls(game: Game) {
Column { Column {
Text( Text(
"Catch balls!${if (game.finished) " Game over!" else ""}", "Catch balls!${if (game.finished) " Game over!" else ""}",
fontSize = 1.8f.em, fontSize = 20.sp,
color = Color(218, 120, 91) color = Color(218, 120, 91)
) )
Text("Score: ${game.score} Time: ${game.elapsed / 1_000_000} Blocks: ${game.numBlocks.toInt()}", fontSize = 1.8f.em) Text("Score: ${game.score} Time: ${game.elapsed / 1_000_000} Blocks: ${game.numBlocks.toInt()}", fontSize = 20.sp)
Row { Row {
if (!game.started) { if (!game.started) {
Slider( Slider(
@ -45,7 +43,7 @@ fun FallingBalls(game: Game) {
} }
} }
) { ) {
Text(if (game.started) "Stop" else "Start", fontSize = 2f.em) Text(if (game.started) "Stop" else "Start", fontSize = 25.sp)
} }
if (game.started) { if (game.started) {
Button( Button(
@ -56,7 +54,7 @@ fun FallingBalls(game: Game) {
onClick = { onClick = {
game.togglePause() game.togglePause()
}) { }) {
Text(if (game.paused) "Resume" else "Pause", fontSize = 2f.em) Text(if (game.paused) "Resume" else "Pause", fontSize = 25.sp)
} }
} }
} }

Loading…
Cancel
Save