Browse Source

Update examples (#967)

* Update widgets gallery examples

* Update notepad example

* Update issues example

This change updates:
* Gradle to 7.1.1;
* AGP to 7.0.0;
* Compose to 1.0.0-alpha1-rc1;
* Kotlin to 1.5.21.

* Update image viewer example
pull/972/head
Alexey Tsvetkov 3 years ago committed by GitHub
parent
commit
079a317c03
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 8
      examples/imageviewer/android/build.gradle.kts
  2. 7
      examples/imageviewer/build.gradle.kts
  3. 10
      examples/imageviewer/common/build.gradle.kts
  4. 2
      examples/imageviewer/desktop/build.gradle.kts
  5. 2
      examples/imageviewer/gradle/wrapper/gradle-wrapper.properties
  6. 8
      examples/issues/android/build.gradle.kts
  7. 6
      examples/issues/build.gradle.kts
  8. 13
      examples/issues/common/build.gradle.kts
  9. 24
      examples/issues/desktop/src/jvmMain/kotlin/androidx/ui/examples/jetissues/Main.kt
  10. 2
      examples/issues/gradle/wrapper/gradle-wrapper.properties
  11. 6
      examples/notepad/build.gradle.kts
  12. 2
      examples/notepad/gradle/wrapper/gradle-wrapper.properties
  13. 2
      examples/notepad/src/main/kotlin/NotepadApplication.kt
  14. 41
      examples/notepad/src/main/kotlin/common/AppResources.kt
  15. 3
      examples/notepad/src/main/kotlin/util/Dialogs.kt
  16. 10
      examples/notepad/src/main/kotlin/window/NotepadWindow.kt
  17. 8
      examples/widgetsgallery/android/build.gradle.kts
  18. 2
      examples/widgetsgallery/build.gradle.kts
  19. 15
      examples/widgetsgallery/common/build.gradle.kts
  20. 2
      examples/widgetsgallery/common/src/androidMain/AndroidManifest.xml
  21. 2
      examples/widgetsgallery/common/src/androidMain/kotlin/org/jetbrains/compose/demo/widgets/platform/Resources.kt
  22. 14
      examples/widgetsgallery/common/src/desktopMain/kotlin/org/jetbrains/compose/demo/widgets/platform/Mouse.kt
  23. 31
      examples/widgetsgallery/desktop/src/jvmMain/kotlin/org/jetbrains/compose/demo/widgets/main.kt
  24. 2
      examples/widgetsgallery/gradle/wrapper/gradle-wrapper.properties

8
examples/imageviewer/android/build.gradle.kts

@ -5,11 +5,11 @@ plugins {
}
android {
compileSdkVersion(30)
compileSdk = 30
defaultConfig {
minSdkVersion(21)
targetSdkVersion(30)
minSdk = 21
targetSdk = 30
versionCode = 1
versionName = "1.0"
}
@ -22,5 +22,5 @@ android {
dependencies {
implementation(project(":common"))
implementation("androidx.activity:activity-compose:1.3.0-alpha02")
implementation("androidx.activity:activity-compose:1.3.0")
}

7
examples/imageviewer/build.gradle.kts

@ -1,6 +1,4 @@
buildscript {
val composeVersion = System.getenv("COMPOSE_TEMPLATE_COMPOSE_VERSION") ?: "0.5.0-build270"
repositories {
google()
mavenCentral()
@ -8,8 +6,9 @@ buildscript {
}
dependencies {
classpath("org.jetbrains.compose:compose-gradle-plugin:$composeVersion")
classpath("com.android.tools.build:gradle:4.0.1")
// __LATEST_COMPOSE_RELEASE_VERSION__
classpath("org.jetbrains.compose:compose-gradle-plugin:1.0.0-alpha1-rc1")
classpath("com.android.tools.build:gradle:7.0.0")
classpath(kotlin("gradle-plugin", version = "1.5.21"))
}
}

10
examples/imageviewer/common/build.gradle.kts

@ -20,7 +20,7 @@ kotlin {
}
named("androidMain") {
dependencies {
api("androidx.appcompat:appcompat:1.3.0-beta01")
api("androidx.appcompat:appcompat:1.3.1")
api("androidx.core:core-ktx:1.3.1")
implementation("io.ktor:ktor-client-cio:1.4.1")
}
@ -35,13 +35,11 @@ kotlin {
}
android {
compileSdkVersion(30)
compileSdk = 30
defaultConfig {
minSdkVersion(21)
targetSdkVersion(30)
versionCode = 1
versionName = "1.0"
minSdk = 21
targetSdk = 30
}
compileOptions {

2
examples/imageviewer/desktop/build.gradle.kts

@ -28,8 +28,6 @@ compose.desktop {
targetFormats(TargetFormat.Dmg, TargetFormat.Msi, TargetFormat.Deb)
packageName = "ImageViewer"
packageVersion = "1.0.0"
modules("jdk.crypto.ec")
val iconsRoot = project.file("../common/src/desktopMain/resources/images")
macOS {

2
examples/imageviewer/gradle/wrapper/gradle-wrapper.properties vendored

@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-6.9-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-7.1.1-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists

8
examples/issues/android/build.gradle.kts

@ -5,11 +5,11 @@ plugins {
}
android {
compileSdkVersion(30)
compileSdk = 30
defaultConfig {
minSdkVersion(26)
targetSdkVersion(30)
minSdk = 26
targetSdk = 30
versionCode = 1
versionName = "1.0"
}
@ -22,5 +22,5 @@ android {
dependencies {
implementation(project(":common"))
implementation("androidx.activity:activity-compose:1.3.0-alpha02")
implementation("androidx.activity:activity-compose:1.3.0")
}

6
examples/issues/build.gradle.kts

@ -8,10 +8,10 @@ buildscript {
dependencies {
// __LATEST_COMPOSE_RELEASE_VERSION__
classpath("org.jetbrains.compose:compose-gradle-plugin:0.4.0")
classpath("com.android.tools.build:gradle:4.0.1")
classpath("org.jetbrains.compose:compose-gradle-plugin:1.0.0-alpha1-rc1")
classpath("com.android.tools.build:gradle:7.0.0")
// __KOTLIN_COMPOSE_VERSION__
classpath(kotlin("gradle-plugin", version = "1.5.10"))
classpath(kotlin("gradle-plugin", version = "1.5.21"))
}
}

13
examples/issues/common/build.gradle.kts

@ -24,7 +24,7 @@ kotlin {
named("androidMain") {
kotlin.srcDirs("src/jvmAndAndroidMain/kotlin")
dependencies {
api("androidx.appcompat:appcompat:1.3.0-beta01")
api("androidx.appcompat:appcompat:1.3.1")
api("androidx.core:core-ktx:1.3.1")
}
}
@ -40,13 +40,11 @@ apollo {
}
android {
compileSdkVersion(30)
compileSdk = 30
defaultConfig {
minSdkVersion(26)
targetSdkVersion(30)
versionCode = 1
versionName = "1.0"
minSdk = 26
targetSdk = 30
}
compileOptions {
@ -57,9 +55,6 @@ android {
sourceSets {
named("main") {
manifest.srcFile("src/androidMain/AndroidManifest.xml")
// res.srcDirs("src/androidMain/res")
}
}
}

24
examples/issues/desktop/src/jvmMain/kotlin/androidx/ui/examples/jetissues/Main.kt

@ -1,8 +1,11 @@
package androidx.ui.examples.jetissues
import androidx.compose.desktop.Window
import androidx.compose.runtime.CompositionLocalProvider
import androidx.compose.ui.unit.IntSize
import androidx.compose.ui.unit.dp
import androidx.compose.ui.window.Window
import androidx.compose.ui.window.WindowSize
import androidx.compose.ui.window.WindowState
import androidx.compose.ui.window.application
import androidx.ui.examples.jetissues.view.JetIssuesView
import androidx.ui.examples.jetissues.view.Repository
import androidx.ui.examples.jetissues.data.IssuesRepositoryImpl
@ -11,11 +14,14 @@ import androidx.ui.examples.jetissues.data.defaultRepo
val repo = IssuesRepositoryImpl(defaultRepo.first, defaultRepo.second, System.getenv("GITHUB_TOKEN") ?: defaultAuth)
fun main() = Window(
title = "JetIssues",
size = IntSize(1440, 768)
) {
CompositionLocalProvider(Repository provides repo) {
JetIssuesView()
fun main() = application {
Window(
onCloseRequest = ::exitApplication,
title = "JetIssues",
state = WindowState(size = WindowSize(1440.dp, 768.dp))
) {
CompositionLocalProvider(Repository provides repo) {
JetIssuesView()
}
}
}
}

2
examples/issues/gradle/wrapper/gradle-wrapper.properties vendored

@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-6.9-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-7.1.1-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists

6
examples/notepad/build.gradle.kts

@ -3,12 +3,13 @@ import org.jetbrains.compose.desktop.application.dsl.TargetFormat
plugins {
// __KOTLIN_COMPOSE_VERSION__
kotlin("jvm") version "1.5.10"
kotlin("jvm") version "1.5.21"
// __LATEST_COMPOSE_RELEASE_VERSION__
id("org.jetbrains.compose") version (System.getenv("COMPOSE_TEMPLATE_COMPOSE_VERSION") ?: "0.5.0-build229")
id("org.jetbrains.compose") version ("1.0.0-alpha1-rc1")
}
repositories {
google()
mavenCentral()
maven("https://maven.pkg.jetbrains.space/public/p/compose/dev")
}
@ -21,7 +22,6 @@ dependencies {
compose.desktop {
application {
mainClass = "MainKt"
jvmArgs("-Dskiko.rendering.laf.global=true")
nativeDistributions {
targetFormats(TargetFormat.Dmg, TargetFormat.Msi, TargetFormat.Deb)

2
examples/notepad/gradle/wrapper/gradle-wrapper.properties vendored

@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-6.9-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-7.1.1-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists

2
examples/notepad/src/main/kotlin/NotepadApplication.kt

@ -25,7 +25,7 @@ fun NotepadApplication(state: NotepadApplicationState) {
@Composable
private fun ApplicationTray(state: NotepadApplicationState) {
Tray(
LocalAppResources.current.icon ?: return,
LocalAppResources.current.icon,
state = state.tray,
hint = "Notepad",
menu = { ApplicationMenu(state) }

41
examples/notepad/src/main/kotlin/common/AppResources.kt

@ -3,15 +3,14 @@ package common
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.Description
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.runtime.staticCompositionLocalOf
import androidx.compose.ui.ExperimentalComposeUiApi
import androidx.compose.ui.graphics.Color
import util.toAwtImage
import java.awt.image.BufferedImage
import androidx.compose.ui.graphics.vector.ImageVector
import androidx.compose.ui.graphics.vector.RenderVectorGroup
import androidx.compose.ui.graphics.vector.VectorPainter
import androidx.compose.ui.graphics.vector.rememberVectorPainter
val LocalAppResources = staticCompositionLocalOf<AppResources> {
error("LocalNotepadResources isn't provided")
@ -19,20 +18,22 @@ val LocalAppResources = staticCompositionLocalOf<AppResources> {
@Composable
fun rememberAppResources(): AppResources {
val resources = remember { AppResources() }
LaunchedEffect(Unit) {
resources.init()
}
return resources
val icon = rememberVectorPainter(Icons.Default.Description, Color(0xFF2CA4E1))
return remember { AppResources(icon) }
}
class AppResources {
var icon: BufferedImage? by mutableStateOf(null)
private set
class AppResources(val icon: VectorPainter)
suspend fun init() {
icon = Icons.Default.Description.toAwtImage(Color(0xFF2CA4E1))
}
}
@OptIn(ExperimentalComposeUiApi::class)
@Composable
fun rememberVectorPainter(image: ImageVector, tintColor: Color) =
rememberVectorPainter(
defaultWidth = image.defaultWidth,
defaultHeight = image.defaultHeight,
viewportWidth = image.viewportWidth,
viewportHeight = image.viewportHeight,
name = image.name,
tintColor = tintColor,
tintBlendMode = image.tintBlendMode,
content = { _, _ -> RenderVectorGroup(group = image.root) }
)

3
examples/notepad/src/main/kotlin/util/Dialogs.kt

@ -4,6 +4,7 @@ import androidx.compose.runtime.Composable
import androidx.compose.runtime.DisposableEffect
import androidx.compose.ui.ExperimentalComposeUiApi
import androidx.compose.ui.window.AwtWindow
import androidx.compose.ui.window.FrameWindowScope
import androidx.compose.ui.window.WindowScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.GlobalScope
@ -16,7 +17,7 @@ import javax.swing.JOptionPane
@OptIn(ExperimentalComposeUiApi::class)
@Composable
fun WindowScope.FileDialog(
fun FrameWindowScope.FileDialog(
title: String,
isLoad: Boolean,
onResult: (result: Path?) -> Unit

10
examples/notepad/src/main/kotlin/window/NotepadWindow.kt

@ -7,11 +7,7 @@ import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.ui.ExperimentalComposeUiApi
import androidx.compose.ui.Modifier
import androidx.compose.ui.window.MenuBar
import androidx.compose.ui.window.Notification
import androidx.compose.ui.window.Window
import androidx.compose.ui.window.WindowPlacement
import androidx.compose.ui.window.WindowScope
import androidx.compose.ui.window.*
import common.LocalAppResources
import kotlinx.coroutines.flow.collect
import kotlinx.coroutines.launch
@ -28,7 +24,7 @@ fun NotepadWindow(state: NotepadWindowState) {
Window(
state = state.window,
title = titleOf(state),
icon = LocalAppResources.current.icon ?: return,
icon = LocalAppResources.current.icon,
onCloseRequest = { exit() }
) {
LaunchedEffect(Unit) { state.run() }
@ -98,7 +94,7 @@ private fun WindowNotifications(state: NotepadWindowState) {
}
@Composable
private fun WindowScope.WindowMenuBar(state: NotepadWindowState) = MenuBar {
private fun FrameWindowScope.WindowMenuBar(state: NotepadWindowState) = MenuBar {
val scope = rememberCoroutineScope()
fun save() = scope.launch { state.save() }

8
examples/widgetsgallery/android/build.gradle.kts

@ -5,11 +5,11 @@ plugins {
}
android {
compileSdkVersion(30)
compileSdk = 30
defaultConfig {
minSdkVersion(26)
targetSdkVersion(30)
minSdk = 26
targetSdk = 30
versionCode = 1
versionName = "1.0"
}
@ -22,5 +22,5 @@ android {
dependencies {
implementation(project(":common"))
implementation("androidx.activity:activity-compose:1.3.0-alpha02")
implementation("androidx.activity:activity-compose:1.3.0")
}

2
examples/widgetsgallery/build.gradle.kts

@ -9,7 +9,7 @@ buildscript {
dependencies {
// __LATEST_COMPOSE_RELEASE_VERSION__
classpath("org.jetbrains.compose:compose-gradle-plugin:1.0.0-alpha1-rc1")
classpath("com.android.tools.build:gradle:4.0.1")
classpath("com.android.tools.build:gradle:7.0.0")
// __KOTLIN_COMPOSE_VERSION__
classpath(kotlin("gradle-plugin", version = "1.5.21"))
}

15
examples/widgetsgallery/common/build.gradle.kts

@ -20,15 +20,12 @@ kotlin {
}
}
named("androidMain") {
kotlin.srcDirs("src/jvmMain/kotlin")
dependencies {
api("androidx.appcompat:appcompat:1.3.0-beta01")
api("androidx.appcompat:appcompat:1.3.1")
api("androidx.core:core-ktx:1.3.1")
}
}
named("desktopMain") {
kotlin.srcDirs("src/jvmMain/kotlin")
resources.srcDirs("src/commonMain/resources")
dependencies {
api(compose.desktop.common)
}
@ -37,13 +34,11 @@ kotlin {
}
android {
compileSdkVersion(30)
compileSdk = 30
defaultConfig {
minSdkVersion(21)
targetSdkVersion(30)
versionCode = 1
versionName = "1.0"
minSdk = 21
targetSdk = 30
}
compileOptions {
@ -57,4 +52,4 @@ android {
res.srcDirs("src/androidMain/res", "src/commonMain/resources")
}
}
}
}

2
examples/widgetsgallery/common/src/androidMain/AndroidManifest.xml

@ -1,2 +1,2 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest package="org.jetbrains.compose.demo.widgets"/>
<manifest package="org.jetbrains.compose.demo.widgets.platform"/>

2
examples/widgetsgallery/common/src/androidMain/kotlin/org/jetbrains/compose/demo/widgets/platform/Resources.kt

@ -5,7 +5,7 @@ import androidx.compose.ui.graphics.ImageBitmap
import androidx.compose.ui.graphics.vector.ImageVector
import androidx.compose.ui.res.imageResource
import androidx.compose.ui.res.vectorResource
import org.jetbrains.compose.demo.widgets.R
import org.jetbrains.compose.demo.widgets.platform.R
@Composable
actual fun imageResource(res: String): ImageBitmap {

14
examples/widgetsgallery/common/src/desktopMain/kotlin/org/jetbrains/compose/demo/widgets/platform/Mouse.kt

@ -1,13 +1,12 @@
package org.jetbrains.compose.demo.widgets.platform
import androidx.compose.runtime.*
import androidx.compose.ui.ExperimentalComposeUiApi
import androidx.compose.ui.Modifier
import androidx.compose.ui.composed
import androidx.compose.ui.geometry.Offset
import androidx.compose.ui.input.pointer.PointerIcon
import androidx.compose.ui.input.pointer.awtCursor
import androidx.compose.ui.input.pointer.pointerIcon
import androidx.compose.ui.input.pointer.pointerMoveFilter
import java.awt.Cursor
actual fun Modifier.pointerMoveFilter(
onEnter: () -> Boolean,
@ -16,10 +15,5 @@ actual fun Modifier.pointerMoveFilter(
): Modifier = this.pointerMoveFilter(onEnter = onEnter, onExit = onExit, onMove = onMove)
@OptIn(ExperimentalComposeUiApi::class)
actual fun Modifier.cursorForHorizontalResize(): Modifier = composed {
var isHover by remember { mutableStateOf(false) }
pointerMoveFilter(
onEnter = { isHover = true; true },
onExit = { isHover = false; true }
).pointerIcon(if (isHover) PointerIcon.Crosshair else PointerIcon.Default)
}
actual fun Modifier.cursorForHorizontalResize(): Modifier =
pointerIcon(awtCursor(Cursor(Cursor.E_RESIZE_CURSOR)))

31
examples/widgetsgallery/desktop/src/jvmMain/kotlin/org/jetbrains/compose/demo/widgets/main.kt

@ -1,27 +1,18 @@
package org.jetbrains.compose.demo.widgets
import androidx.compose.ui.unit.IntSize
import androidx.compose.ui.unit.dp
import androidx.compose.ui.window.*
import androidx.compose.ui.window.Window
import androidx.compose.ui.window.WindowSize
import androidx.compose.ui.window.WindowState
import androidx.compose.ui.window.application
import org.jetbrains.compose.demo.widgets.ui.MainView
import java.awt.Dimension
import java.awt.Toolkit
fun main() {
val size = getPreferredWindowSize(600, 800)
singleWindowApplication (
title = "Widgets Gallery",
state = WindowState(size = WindowSize(size.width.dp, size.height.dp)),
) {
fun main() = application {
Window(
onCloseRequest = ::exitApplication,
title = "Widgets Gallery",
state = WindowState(size = WindowSize(800.dp, 600.dp))
) {
MainView()
}
}
private fun getPreferredWindowSize(desiredWidth: Int, desiredHeight: Int): IntSize {
val screenSize: Dimension = Toolkit.getDefaultToolkit().screenSize
val preferredWidth: Int = (screenSize.width * 0.8f).toInt()
val preferredHeight: Int = (screenSize.height * 0.8f).toInt()
val width: Int = if (desiredWidth < preferredWidth) desiredWidth else preferredWidth
val height: Int = if (desiredHeight < preferredHeight) desiredHeight else preferredHeight
return IntSize(width, height)
}
}

2
examples/widgetsgallery/gradle/wrapper/gradle-wrapper.properties vendored

@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-6.9-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-7.1.1-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists

Loading…
Cancel
Save